119 lines
3.8 KiB
Makefile
119 lines
3.8 KiB
Makefile
TARGET = A5
|
|
SRC_FILES = main.cpp Coordinate.cpp Triangle.cpp Polygon.cpp ScaleneTriangle.cpp GeometryUtils.cpp IsoscelesTriangle.cpp EquilateralTriangle.cpp Quadrilateral.cpp Rhombus.cpp
|
|
|
|
# Tyler's custom makefile extensions for CSCI200 (anyone can use these if they want)
|
|
.DEFAULT_GOAL := all # Necessary so `make` doesn't run the "pack" target, as it is declared before "all"
|
|
.PHONY: pack clean-run c run fmt
|
|
|
|
## Adds only the necessary files for build into a .tar.gz file, named appropriately
|
|
ARCHIVED_FILES = Makefile $(SRC_FILES) $(SRC_FILES:.cpp=.h) $(SRC_FILES:.cpp=.hpp)
|
|
pack: fmtc
|
|
tar --ignore-failed-read -czvf $(TARGET).tar.gz $(shell echo $(ARCHIVED_FILES) | xargs ls -d 2>/dev/null)
|
|
|
|
## Runs the pack target and then attempts to build & run the program to make sure it functions correctly
|
|
pack-test: pack
|
|
$(eval TMP := $(shell mktemp -d))
|
|
tar -xvzf $(TARGET).tar.gz --directory $(TMP)
|
|
make -C $(TMP)
|
|
$(TMP)/$(TARGET)
|
|
rm -rf $(TMP)
|
|
|
|
## An extension of the clean command that is shorter to type and removes a potential .tar.gz file
|
|
c: clean
|
|
$(DEL) -f $(TARGET).tar.gz Makefile.bak
|
|
|
|
## Simply builds and then executes the program
|
|
run: all
|
|
./$(TARGET)
|
|
|
|
## Formats all cpp, h, and hpp files with clang-format, using my personal clang-format config
|
|
fmt:
|
|
find . -iname '*.hpp' -o -iname '*.h' -o -iname '*.cpp' | xargs clang-format --style=file:.clang-format -i
|
|
|
|
## Formats all cpp, h, and hpp files with clang-format, using the class clang-format config
|
|
fmtc:
|
|
find . -iname '*.hpp' -o -iname '*.h' -o -iname '*.cpp' | xargs clang-format --style=file:.class-clang-format -i
|
|
|
|
## Modifies the SRC_FILES variable to have all .cpp files in the repo
|
|
setupsrc:
|
|
sed -i "0,/SRC_FILE.\{0\}S = .*/ s//SRC_FILES = $(shell find . -iname '*.cpp' -printf '%P\n')/" Makefile
|
|
|
|
## Alias to setup SRC_FILES and then dependencies
|
|
setup: setupsrc depend
|
|
|
|
# NO EDITS NEEDED BELOW THIS LINE
|
|
|
|
CXX = g++
|
|
CXXFLAGS = -O2
|
|
CXXFLAGS_DEBUG = -g
|
|
CXXFLAGS_WARN = -Wall -Wextra -Wunreachable-code -Wshadow -Wpedantic
|
|
CPPVERSION = -std=c++17
|
|
|
|
OBJECTS = $(SRC_FILES:.cpp=.o)
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
TARGET := $(TARGET).exe
|
|
DEL = del
|
|
Q =
|
|
|
|
INC_PATH = Z:/CSCI200/include/
|
|
LIB_PATH = Z:/CSCI200/lib/
|
|
|
|
RPATH =
|
|
else
|
|
DEL = rm -f
|
|
Q = "
|
|
|
|
INC_PATH = /usr/local/include/
|
|
LIB_PATH = /usr/local/lib/
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
ifeq ($(UNAME_S),Linux)
|
|
CXXFLAGS += -D LINUX
|
|
RPATH =
|
|
endif
|
|
ifeq ($(UNAME_S),Darwin)
|
|
CXXFLAGS += -D OSX
|
|
RPATH = -Wl,-rpath,/Library/Frameworks
|
|
endif
|
|
|
|
UNAME_P := $(shell uname -p)
|
|
endif
|
|
|
|
LIBS = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lsfml-network
|
|
|
|
all: $(TARGET)
|
|
|
|
$(TARGET): $(OBJECTS)
|
|
$(CXX) -o $@ $^ $(RPATH) -L$(LIB_PATH) $(LIBS)
|
|
|
|
.cpp.o:
|
|
$(CXX) $(CXXFLAGS) $(CPPVERSION) $(CXXFLAGS_DEBUG) $(CXXFLAGS_WARN) -o $@ -c $< -I$(INC_PATH)
|
|
|
|
clean:
|
|
$(DEL) $(TARGET) $(OBJECTS)
|
|
|
|
depend:
|
|
@sed -i.bak '/^# DEPENDENCIES/,$$d' Makefile
|
|
@$(DEL) sed*
|
|
@echo $(Q)# DEPENDENCIES$(Q) >> Makefile
|
|
@$(CXX) -MM $(SRC_FILES) >> Makefile
|
|
|
|
.PHONY: all clean depend
|
|
|
|
# DEPENDENCIES
|
|
main.o: main.cpp Coordinate.h EquilateralTriangle.h Triangle.h Polygon.h \
|
|
IsoscelesTriangle.h Rhombus.h Quadrilateral.h ScaleneTriangle.h
|
|
Coordinate.o: Coordinate.cpp Coordinate.h
|
|
Triangle.o: Triangle.cpp Triangle.h Polygon.h Coordinate.h
|
|
Polygon.o: Polygon.cpp Coordinate.h Polygon.h
|
|
ScaleneTriangle.o: ScaleneTriangle.cpp ScaleneTriangle.h Triangle.h \
|
|
Polygon.h Coordinate.h GeometryUtils.h
|
|
GeometryUtils.o: GeometryUtils.cpp GeometryUtils.h Coordinate.h
|
|
IsoscelesTriangle.o: IsoscelesTriangle.cpp IsoscelesTriangle.h Triangle.h \
|
|
Polygon.h Coordinate.h GeometryUtils.h
|
|
EquilateralTriangle.o: EquilateralTriangle.cpp EquilateralTriangle.h \
|
|
Triangle.h Polygon.h Coordinate.h GeometryUtils.h
|
|
Quadrilateral.o: Quadrilateral.cpp Quadrilateral.h Polygon.h Coordinate.h
|
|
Rhombus.o: Rhombus.cpp Rhombus.h Quadrilateral.h Polygon.h Coordinate.h \
|
|
GeometryUtils.h IsoscelesTriangle.h Triangle.h
|