-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
288 lines (208 loc) · 7.86 KB
/
Copy pathMakefile
File metadata and controls
288 lines (208 loc) · 7.86 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
## default executable
DEFAULT_EXE=bin/main
## location of cxxtest
CXXTEST_HOME?=cxxtest
## various options for possible build configurations
## use one of the following sets or add your own
CXXFLAGS_BASE=
LDFLAGS_BASE=
## for optimization
CXXFLAGS_EXTRA_REL:=-O2 -DNDEBUG
LDFLAGS_EXTRA_REL:=
## for gdb or valgrind
CXXFLAGS_EXTRA_DBG:=-Og -ggdb -fno-inline -fno-omit-frame-pointer -D_DEBUG
LDFLAGS_EXTRA_DBG:=
## for gcov
CXXFLAGS_EXTRA_COV:=-Og -ggdb -fno-inline -fno-omit-frame-pointer -D_DEBUG -fprofile-arcs -ftest-coverage
LDFLAGS_EXTRA_COV:=-fprofile-arcs
## for gprof
CXXFLAGS_EXTRA_PRF:=-O2 -pg
LDFLAGS_EXTRA_PRF:=-pg
## the following should not need to change
## generic options
CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -std=c++20 -Wall -Werror -pedantic-errors -Iinclude -Isrc -Ilib
LDFLAGS_BASE:=$(LDFLAGS_BASE) -std=c++20
# ## platform-specific options for SDL2
# ifeq ($(OS),Windows_NT)
# CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -I/mingw64/include/SDL2
# LDFLAGS_BASE:=$(LDFLAGS_BASE) -lmingw32 -lSDL2main -lSDL2 -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lSDL2_net -lSDL2_ttf
# DOXYGEN=doxygen
# else ifeq ($(shell sh -c 'uname'),Darwin)
# CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -F/Library/Frameworks -I/Library/Frameworks/SDL2.framework/Headers -I/Library/Frameworks/SDL2_image.framework/Headers -I/Library/Frameworks/SDL2_mixer.framework/Headers -I/Library/Frameworks/SDL2_ttf.framework/Headers
# LDFLAGS_BASE:=$(LDFLAGS_BASE) -F/Library/Frameworks -framework SDL2 -framework SDL2_gfx -framework SDL2_image -framework SDL2_mixer -framework SDL2_net -framework SDL2_ttf
# ifneq ($(wildcard /Applications/Doxygen.app/Contents/Resources/doxygen),)
# DOXYGEN=/Applications/Doxygen.app/Contents/Resources/doxygen
# else
# DOXYGEN=doxygen
# endif
# else
# ifeq (, $(shell which sdl2-config))
# else
# CXXFLAGS_BASE:=$(CXXFLAGS_BASE) $(shell sh -c 'sdl2-config --cflags')
# LDFLAGS_BASE:=$(LDFLAGS_BASE) $(shell sh -c 'sdl2-config --libs') -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lSDL2_net -lSDL2_ttf
# endif
# DOXYGEN=doxygen
# endif
## files
DEFAULT_EXE_DBG=$(addsuffix _dbg,$(DEFAULT_EXE))
DEFAULT_EXE_COV=$(addsuffix _cov,$(DEFAULT_EXE))
DEFAULT_EXE_PRF=$(addsuffix _prf,$(DEFAULT_EXE))
EXECUTABLE_SOURCE_FILES=$(shell sh -c '/usr/bin/find src -name "main*.cpp" 2>/dev/null')
SOURCE_FILES=$(filter-out $(EXECUTABLE_SOURCE_FILES),$(shell sh -c '/usr/bin/find src -name "*.cpp" 2>/dev/null'))
HEADER_FILES=$(shell sh -c '/usr/bin/find include src lib -name "*.hpp" 2>/dev/null')
OBJECT_FILES_REL=$(SOURCE_FILES:src/%.cpp=build/exe/%.o)
OBJECT_FILES_DBG=$(SOURCE_FILES:src/%.cpp=build/exe/%_dbg.o)
OBJECT_FILES_COV=$(SOURCE_FILES:src/%.cpp=build/exe/%_cov.o)
OBJECT_FILES_PRF=$(SOURCE_FILES:src/%.cpp=build/exe/%_prf.o)
EXECUTABLES_REL=$(patsubst src/%.cpp,bin/%,$(EXECUTABLE_SOURCE_FILES))
EXECUTABLES_DBG=$(patsubst src/%.cpp,bin/%_dbg,$(EXECUTABLE_SOURCE_FILES))
EXECUTABLES_COV=$(patsubst src/%.cpp,bin/%_cov,$(EXECUTABLE_SOURCE_FILES))
EXECUTABLES_PRF=$(patsubst src/%.cpp,bin/%_prf,$(EXECUTABLE_SOURCE_FILES))
## test files
CXXTEST_GEN=$(CXXTEST_HOME)/bin/cxxtestgen
CXXTEST_INCLUDE=$(CXXTEST_HOME)
TEST_FILES=$(shell sh -c '/usr/bin/find test -name "*.cxxtest.hpp"')
TEST_SOURCE_FILES=$(TEST_FILES:test/%.cxxtest.hpp=build/test/%.cxxtest.cpp) build/test/runner.cpp
TEST_OBJECT_FILES_REL=$(TEST_SOURCE_FILES:.cpp=.o)
TEST_OBJECT_FILES_DBG=$(TEST_SOURCE_FILES:.cpp=_dbg.o)
TEST_OBJECT_FILES_COV=$(TEST_SOURCE_FILES:.cpp=_cov.o)
TEST_OBJECT_FILES_PRF=$(TEST_SOURCE_FILES:.cpp=_prf.o)
CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -I$(CXXTEST_INCLUDE)
## for optimization
CXXFLAGS_REL:=$(CXXFLAGS_BASE) $(CXXFLAGS_EXTRA_REL)
LDFLAGS_REL:=$(LDFLAGS_BASE) $(LDFLAGS_EXTRA_REL)
## for gdb or valgrind
CXXFLAGS_DBG:=$(CXXFLAGS_BASE) $(CXXFLAGS_EXTRA_DBG)
LDFLAGS_DBG:=$(LDFLAGS_BASE) $(LDFLAGS_EXTRA_DBG)
## for gcov
CXXFLAGS_COV:=$(CXXFLAGS_BASE) $(CXXFLAGS_EXTRA_COV)
LDFLAGS_COV:=$(LDFLAGS_BASE) $(LDFLAGS_EXTRA_COV)
## for gprof
CXXFLAGS_PRF:=$(CXXFLAGS_BASE) $(CXXFLAGS_EXTRA_PRF)
LDFLAGS_PRF:=$(LDFLAGS_BASE) $(LDFLAGS_EXTRA_PRF)
## rules
.PHONY: all clean doc exe exe_dbg exe_cov exe_prf tests tests_dbg tests_cov tests_prf run run_dbg run_cov run_prf run-tests run-tests_dbg run-tests_cov run-tests_prf
all: doc exe exe_dbg exe_cov exe_prf tests tests_dbg tests_cov tests_prf bench
ifeq (, $(shell which $(DOXYGEN)))
doc:
@echo "Cannot find doxygen to build documentation."
true
else
doc: $(HEADER_FILES) $(SOURCE_FILES) Makefile
$(DOXYGEN)
endif
exe: $(EXECUTABLES_REL)
exe_dbg: $(EXECUTABLES_DBG)
exe_cov: $(EXECUTABLES_COV)
exe_prf: $(EXECUTABLES_PRF)
tests: bin/test
tests_dbg: bin/test_dbg
tests_cov: bin/test_cov
tests_prf: bin/test_prf
run: $(DEFAULT_EXE)
$(DEFAULT_EXE)
run_dbg: $(DEFAULT_EXE_DBG)
$(DEFAULT_EXE_DBG)
run_cov: $(DEFAULT_EXE_COV)
$(DEFAULT_EXE_COV)
run_prf: $(DEFAULT_EXE_PRF)
$(DEFAULT_EXE_PRF)
run-tests: bin/test
bin/test
run-tests_dbg: bin/test_dbg
bin/test_dbg
run-tests_cov: bin/test_cov
bin/test_cov
run-tests_prf: bin/test_prf
bin/test_prf
$(EXECUTABLES_REL): bin/%: build/exe/%.o $(OBJECT_FILES_REL)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_REL) -o $@
$(EXECUTABLES_DBG): bin/%: build/exe/%.o $(OBJECT_FILES_DBG)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_DBG) -o $@
$(EXECUTABLES_COV): bin/%: build/exe/%.o $(OBJECT_FILES_COV)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_COV) -o $@
$(EXECUTABLES_PRF): bin/%: build/exe/%.o $(OBJECT_FILES_PRF)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_PRF) -o $@
build/exe/%.o: src/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_REL) -o $@
build/exe/%_dbg.o: src/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_DBG) -o $@
build/exe/%_cov.o: src/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_COV) -o $@
build/exe/%_prf.o: src/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_PRF) -o $@
ifneq ($(wildcard $(CXXTEST_HOME)),)
bin/test: $(TEST_OBJECT_FILES_REL) $(OBJECT_FILES_REL)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_REL) -o $@
bin/test_dbg: $(TEST_OBJECT_FILES_DBG) $(OBJECT_FILES_DBG)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_DBG) -o $@
bin/test_cov: $(TEST_OBJECT_FILES_COV) $(OBJECT_FILES_COV)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_COV) -o $@
bin/test_prf: $(TEST_OBJECT_FILES_PRF) $(OBJECT_FILES_PRF)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_PRF) -o $@
build/test/%.o: build/test/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_REL) -o $@
build/test/%_dbg.o: build/test/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_DBG) -o $@
build/test/%_cov.o: build/test/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_COV) -o $@
build/test/%_prf.o: build/test/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_PRF) -o $@
.PRECIOUS: build/test/%.cxxtest.cpp
build/test/%.cxxtest.cpp: test/%.cxxtest.hpp
mkdir -p $(dir $@)
python3 -W ignore $(CXXTEST_GEN) --part --error-printer $< -o $@
build/test/runner.cpp:
mkdir -p $(dir $@)
python3 -W ignore $(CXXTEST_GEN) --root --error-printer -o $@
else
bin/test:
@echo "Cannot find CxxTest to build tests."
true
bin/test_dbg:
@echo "Cannot find CxxTest to build tests."
true
bin/test_cov:
@echo "Cannot find CxxTest to build tests."
true
bin/test_prf:
@echo "Cannot find CxxTest to build tests."
true
endif
clean:
rm -rf bin/ build/ doc/ *.gcda *.gcno *.gcov gmon.out
build/test/runner_single.cpp:
mkdir -p $(dir $@)
python3 -W ignore $(CXXTEST_GEN) --root --error-printer -o $@
build/test/runner_single.o: build/test/runner_single.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_REL) -o $@
bin/test_%: build/test/%.cxxtest.o build/test/runner_single.o $(OBJECT_FILES_REL)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_REL) -o $@
run-test_%: bin/test_%
./bin/test_$*
.PRECIOUS: bin/test_%
.SECONDARY:
## benchmark
bin/bench: benchmark/perft_bench.cpp $(OBJECT_FILES_REL)
mkdir -p $(dir $@)
g++ $^ $(CXXFLAGS_REL) -o $@
bench: bin/bench
./bin/bench