Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
187 lines (136 loc) · 5.44 KB
/
Copy pathMakefile
File metadata and controls
187 lines (136 loc) · 5.44 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
## use to set a specific default executable
DEFAULT_EXE=bin/main
run-p: bin/platformer/main-platformer
$<
run-b: bin/breakout/main-breakout
$<
run-breakout: bin/breakout/main-breakout
$<
run-e: bin/editor/main-editor
$<
run-editor: bin/editor/main-editor
$<
run-c: bin/custom/main-custom
$<
run-custom: bin/custom/main-custom
$<
## location of cxxtest
CXXTEST_HOME=extern/cxxtest-4.4
## external libraries
EXTERN_INCLUDES=extern/box2d-2.4.1/include extern/box2d-2.4.1/src
EXTERN_SOURCES=extern/box2d-2.4.1/src
ifeq ($(OS),Windows_NT)
EXTERN_CXXFLAGS=-Wno-error=strict-aliasing -Wno-error=maybe-uninitialized -Wno-error=unused-but-set-variable -Wno-error=class-memaccess
else
EXTERN_CXXFLAGS=-Wno-error=unused-variable
endif
## various options for possible build configurations
## comment in one of the following sets or add your own
CXXFLAGS_BASE=
LDFLAGS_BASE=
## for gprof
#CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -O2 -pg
#LDFLAGS_BASE:=$(LDFLAGS_BASE) -pg
## the following should not need to change
## generic options
CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -std=c++17 -Wall -pedantic-errors -Iinclude -Isrc $(EXTERN_CXXFLAGS)
LDFLAGS_BASE:=$(LDFLAGS_BASE) -std=c++17
## platform-specific options
ifeq ($(OS),Windows_NT)
CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -I/mingw64/include/SDL2
LDFLAGS_BASE:=$(LDFLAGS_BASE) -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -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_image -framework SDL2_mixer -framework SDL2_ttf
ifneq ($(wildcard /Applications/Doxygen.app/Contents/Resources/doxygen),)
DOXYGEN=/Applications/Doxygen.app/Contents/Resources/doxygen
else
DOXYGEN=doxygen
endif
else
CXXFLAGS_BASE:=$(CXXFLAGS_BASE) $(shell sh -c 'sdl2-config --cflags')
LDFLAGS_BASE:=$(LDFLAGS_BASE) $(shell sh -c 'sdl2-config --libs') -lSDL2_image -lSDL2_mixer -lSDL2_ttf
DOXYGEN=doxygen
endif
## files
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 $(EXTERN_SOURCES) -name "*.cpp" 2>/dev/null'))
HEADER_FILES=$(shell sh -c '/usr/bin/find include src -name "*.hpp" 2>/dev/null')
OBJECT_FILES_RELEASE=$(SOURCE_FILES:%.cpp=build/obj/%.o)
OBJECT_FILES_DEBUG=$(SOURCE_FILES:%.cpp=build/obj/%_d.o)
EXECUTABLES_RELEASE=$(patsubst src/%.cpp,bin/%,$(EXECUTABLE_SOURCE_FILES))
EXECUTABLES_DEBUG=$(patsubst src/%.cpp,bin/%_d,$(EXECUTABLE_SOURCE_FILES))
DEFAULT_EXE?=$(word 1,$(EXECUTABLES_RELEASE))
DEFAULT_EXE_DEBUG=$(addsuffix _d,$(DEFAULT_EXE))
## 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_RELEASE=$(TEST_SOURCE_FILES:.cpp=.o)
TEST_OBJECT_FILES_DEBUG=$(TEST_SOURCE_FILES:.cpp=_d.o)
CXXFLAGS_BASE:=$(CXXFLAGS_BASE) -I$(CXXTEST_INCLUDE) $(EXTERN_INCLUDES:%=-I%)
## for optimization
CXXFLAGS_RELEASE:=$(CXXFLAGS_BASE) -O2 -DNDEBUG
LDFLAGS_RELEASE:=$(LDFLAGS_BASE)
## for gdb or valgrind
CXXFLAGS_DEBUG:=$(CXXFLAGS_BASE) -Og -ggdb -fno-inline -fno-omit-frame-pointer -D_DEBUG
LDFLAGS_DEBUG:=$(LDFLAGS_BASE)
## rules
.PHONY: all everything clean doc exe exe_d tests tests_d run run_d run-tests run-tests_d
all: exe
everything: doc exe exe_d tests tests_d
doc: $(HEADER_FILES) $(SOURCE_FILES) Makefile
$(DOXYGEN)
exe: $(EXECUTABLES_RELEASE)
exe_d: $(EXECUTABLES_DEBUG)
tests: bin/test
tests_d: bin/test_d
run: $(DEFAULT_EXE)
$(DEFAULT_EXE)
run_d: $(DEFAULT_EXE_DEBUG)
$(DEFAULT_EXE_DEBUG)
run-tests: bin/test
bin/test
run-tests_d: bin/test_d
bin/test_d
$(EXECUTABLES_RELEASE): bin/%: build/obj/src/%.o $(OBJECT_FILES_RELEASE)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_RELEASE) -o $@
$(EXECUTABLES_DEBUG): bin/%: build/obj/src/%.o $(OBJECT_FILES_DEBUG)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_DEBUG) -o $@
build/obj/%.o: %.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_RELEASE) -o $@
build/obj/%_d.o: %.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_DEBUG) -o $@
ifneq ($(wildcard $(CXXTEST_HOME)),)
bin/test: $(TEST_OBJECT_FILES_RELEASE) $(OBJECT_FILES_RELEASE)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_RELEASE) -o $@
bin/test_d: $(TEST_OBJECT_FILES_DEBUG) $(OBJECT_FILES_DEBUG)
mkdir -p $(dir $@)
g++ $^ $(LDFLAGS_DEBUG) -o $@
build/test/%.o: build/test/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_RELEASE) -o $@
build/test/%_d.o: build/test/%.cpp $(HEADER_FILES) Makefile
mkdir -p $(dir $@)
g++ -c $< $(CXXFLAGS_DEBUG) -o $@
.PRECIOUS: build/test/%.cxxtest.cpp
build/test/%.cxxtest.cpp: test/%.cxxtest.hpp
mkdir -p $(dir $@)
$(CXXTEST_GEN) --part --error-printer $< -o $@
build/test/runner.cpp:
mkdir -p $(dir $@)
$(CXXTEST_GEN) --root --error-printer -o $@
else
bin/test:
@echo "Cannot find CxxTest to build tests."
false
endif
clean:
rm -rf bin/ build/ doc/ *.gcda *.gcno *.gcov gmon.out