-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (83 loc) · 2.65 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
SOURCEDIR:=./src
DOCSDIR:=./docs
REPORTDIR:=./report
OUTPUTDIR:=./build
OBJECTDIR:=$(OUTPUTDIR)/obj
INCLUDEDIR:=./include
LIBDIR:=./lib
# blgh
TESTSOURCEDIR:=./test
TESTOUTPUTDIR:=./test/build
TESTOBJECTDIR:=$(TESTOUTPUTDIR)/obj
TESTLIBDIR:=./test/catch2
WARNINGS:=all extra pedantic
# A little hacky but what can we dooo
override DEBUGFLAGS:=-g3 -O0 $(DEBUGFLAGS)
FFLAGS:=no-omit-frame-pointer
STANDARD:=c++20
ifeq ($(OS), Windows_NT)
EXTENSION:=.exe
CXXFLAGS+=-static-libstdc++
else
# Gucci stuff onli on linix
FFLAGS+=sanitize=address,undefined
EXTENSION:=
endif
SOURCES:=$(wildcard $(SOURCEDIR)/*.cpp)
DEFAULTTARGETS:=$(patsubst $(SOURCEDIR)/%.cpp, $(OUTPUTDIR)/%$(EXTENSION), $(SOURCES))
LIBSOURCES:=$(wildcard $(LIBDIR)/*.cpp)
LIBHEADERS:=$(wildcard $(INCLUDEDIR)/*.hpp)
OBJECTS:=$(patsubst $(LIBDIR)/%.cpp, $(OBJECTDIR)/%.o, $(LIBSOURCES))
# kinda repetitve...
TESTSOURCES:=$(wildcard $(TESTSOURCEDIR)/*.cpp)
TESTTARGETS:=$(patsubst $(TESTSOURCEDIR)/%.cpp, $(TESTOUTPUTDIR)/%$(EXTENSION), $(TESTSOURCES))
TESTLIBSOURCES:=$(wildcard $(TESTLIBDIR)/*.cpp)
TESTLIBHEADERS:=$(wildcard $(TESTLIBDIR)/*.hpp)
TESTOBJECTS:=$(patsubst $(TESTLIBDIR)/%.cpp, $(TESTOBJECTDIR)/%.o, $(TESTLIBSOURCES))
CXXFLAGS+=-I$(INCLUDEDIR) -I$(TESTLIBDIR) $(WARNINGS:%=-W%) $(FFLAGS:%=-f%) $(DEBUGFLAGS) -std=$(STANDARD)
.PHONY: all clean report report-clean docs docs-clean tests run-tests
.SECONDARY: $(TESTOBJECTS)
.DELETE_ON_ERROR:
ifndef VERBOSE
.SILENT:
endif
$(OBJECTDIR)/%.o: $(LIBDIR)/%.cpp $(LIBHEADERS)
mkdir -pv $(OBJECTDIR)
printf "=== %s -> %s ===\n" "$<" "$@"
$(CXX) $(CXXFLAGS) -c $< -o $@
all: $(DEFAULTTARGETS)
$(OUTPUTDIR)/%$(EXTENSION): $(SOURCEDIR)/%.cpp $(OBJECTS) $(LIBHEADERS)
mkdir -pv $(OUTPUTDIR)
printf "=== %s -> %s ===\n" "$<" "$@"
$(CXX) $(CXXFLAGS) $(OBJECTS) $< -o $@
$(TESTOBJECTDIR)/%.o: $(TESTLIBDIR)/%.cpp $(TESTLIBHEADERS)
mkdir -pv $(TESTOBJECTDIR)
printf "=== %s -> %s ===\n" "$<" "$@"
$(CXX) $(CXXFLAGS) -c $< -o $@
tests: $(TESTTARGETS)
$(TESTOUTPUTDIR)/%$(EXTENSION): $(TESTSOURCEDIR)/%.cpp $(OBJECTS) $(TESTOBJECTS)
mkdir -pv $(TESTOUTPUTDIR)
printf "=== %s -> %s ===\n" "$<" "$@"
$(CXX) $(CXXFLAGS) $(OBJECTS) $(TESTOBJECTS) $< -o $@
# slightly goofy
run-tests: tests
RESULT=0 ; \
for test in $(TESTTARGETS) ; do \
printf "===\n\033[0;30;46mTESTING\033[0m %s\n===\n\n" "$$test" ; \
command ./$$test $(TESTFLAGS) ; \
RESULT=$$((RESULT | $$?)) ; \
done ; \
exit $$RESULT
report:
make -C $(REPORTDIR)
report-clean:
make -C $(REPORTDIR) clean
docs:
doxygen
make -C $(DOCSDIR)/latex
printf "\n\033[0;30;42mOKAY!\033[0m\n"
# nukes are simpler than surgeries:
clean:
rm -rfv $(OUTPUTDIR) $(TESTOUTPUTDIR)
docs-clean:
rm -rfv $(DOCSDIR)