3 CPPCHECK = cppcheck -q --std=c++11 \
4 --enable=warning,style,performance,portability,unusedFunction,missingInclude \
7 LIBS = sdl2 SDL2_image SDL2_net SDL2_ttf glew openal freealut zlib
9 PKGFLAGS := $(shell pkg-config --cflags $(LIBS))
10 PKGLIBS := $(shell pkg-config --libs $(LIBS))
11 TESTFLAGS := $(shell pkg-config --cflags cppunit)
12 TESTLIBS := $(shell pkg-config --libs cppunit)
15 CPPFLAGS += $(PKGFLAGS)
17 CXXFLAGS += -Wall -Wextra -Werror
18 #CXXFLAGS += -march=native
20 LDXXFLAGS += $(PKGLIBS)
26 # build configurations
31 # unoptimized and maximally annotated
34 # somewhat optimized and maximally annotated
35 # for use with valgrind
37 # optimized, without debugging instructions and minimally
38 # annotated (mainly for stack traces)
41 # same flags as release, but with main replaced by cppunit
42 # test runner and tests (from tst dir) built in
44 COVER_FLAGS = -g -O0 --coverage -I$(SOURCE_DIR) $(TESTFLAGS)
46 PROFILE_FLAGS = -DNDEBUG -O1 -g3 -DBLANK_PROFILING
47 RELEASE_FLAGS = -DNDEBUG -O2 -g1
48 TEST_FLAGS = -g -O2 -I$(SOURCE_DIR) $(TESTFLAGS)
51 COVER_DIR := build/cover
52 DEBUG_DIR := build/debug
53 PROFILE_DIR := build/profile
54 RELEASE_DIR := build/release
55 TEST_DIR := build/test
57 DIR := $(RELEASE_DIR) $(COVER_DIR) $(DEBUG_DIR) $(PROFILE_DIR) $(TEST_DIR) build
60 ASSET_DEP := $(ASSET_DIR)/.git
62 LIB_SRC := $(wildcard $(SOURCE_DIR)/*/*.cpp)
63 BIN_SRC := $(wildcard $(SOURCE_DIR)/*.cpp)
64 SRC := $(LIB_SRC) $(BIN_SRC)
65 TEST_SRC := $(wildcard $(TEST_SRC_DIR)/*.cpp) $(wildcard $(TEST_SRC_DIR)/*/*.cpp)
67 COVER_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cpp, $(COVER_DIR)/%.o, $(TEST_SRC)) $(patsubst $(SOURCE_DIR)/%.cpp, $(COVER_DIR)/src/%.o, $(LIB_SRC))
68 COVER_DEP := $(COVER_OBJ:.o=.d)
69 COVER_BIN := blank.cover
71 DEBUG_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(SRC))
72 DEBUG_LIB_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(LIB_SRC))
73 DEBUG_DEP := $(DEBUG_OBJ:.o=.d)
74 DEBUG_BIN := blank.debug
76 PROFILE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(SRC))
77 PROFILE_LIB_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(LIB_SRC))
78 PROFILE_DEP := $(PROFILE_OBJ:.o=.d)
79 PROFILE_BIN := blank.profile generate.profile
81 RELEASE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(SRC))
82 RELEASE_LIB_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(LIB_SRC))
83 RELEASE_DEP := $(RELEASE_OBJ:.o=.d)
86 TEST_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cpp, $(TEST_DIR)/%.o, $(TEST_SRC)) $(patsubst $(SOURCE_DIR)/%.cpp, $(TEST_DIR)/src/%.o, $(LIB_SRC))
87 TEST_DEP := $(TEST_OBJ:.o=.d)
88 TEST_BIN := blank.test
90 OBJ := $(COVER_OBJ) $(DEBUG_OBJ) $(PROFILE_OBJ) $(RELEASE_OBJ) $(TEST_OBJ)
91 DEP := $(COVER_DEP) $(DEBUG_DEP) $(PROFILE_DEP) $(RELEASE_DEP) $(TEST_DEP)
92 BIN := $(COVER_BIN) $(DEBUG_BIN) $(PROFILE_BIN) $(RELEASE_BIN) $(TEST_BIN)
94 release: $(RELEASE_BIN)
100 @echo "LIBS: $(LIBS)"
102 @echo "CPPFLAGS: $(CPPFLAGS)"
103 @echo "CXXFLAGS: $(CXXFLAGS)"
104 @echo "LDXXFLAGS: $(LDXXFLAGS)"
105 @echo "TESTFLAGS: $(TESTFLAGS)"
106 @echo "TESTLIBS: $(TESTLIBS)"
118 profile: $(PROFILE_BIN)
122 run: $(ASSET_DEP) blank
123 ./blank --save-path saves/
125 server: $(ASSET_DEP) blank
126 ./blank --server --save-path saves/
128 client: $(ASSET_DEP) blank
129 ./blank --client --save-path saves/
131 gdb: $(ASSET_DEP) blank.debug
134 cachegrind: $(ASSET_DEP) blank.profile
135 valgrind ./blank.profile --save-path saves/
137 callgrind: $(ASSET_DEP) blank.profile
138 valgrind --tool=callgrind \
139 --collect-atstart=no --toggle-collect="blank::Runtime::RunStandalone()" \
140 --branch-sim=yes --cacheuse=yes --cache-sim=yes \
141 --collect-bus=yes --collect-systime=yes --collect-jumps=yes \
142 --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \
143 ./blank.profile -n 256 -t 16 --no-keyboard --no-mouse -d --no-vsync --save-path saves/
146 @echo run: blank.test
149 coverage: blank.cover
150 @echo run: blank.cover
154 @echo run: codecov.io
155 @bash -c 'bash <(curl -s https://codecov.io/bash) -Z'
159 @$(CPPCHECK) $(SOURCE_DIR)
161 @$(CPPCHECK) -I $(SOURCE_DIR) $(TEST_SRC_DIR)
166 find build -type d -empty -delete
169 rm -f $(BIN) cachegrind.out.* callgrind.out.*
170 rm -Rf build client-saves saves
172 .PHONY: all release cover debug profile tests run gdb cachegrind callgrind test coverage codecov lint clean distclean
177 $(COVER_BIN): $(COVER_OBJ)
179 @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(TESTLIBS) $(COVER_FLAGS)
181 $(COVER_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(COVER_DIR)
184 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(COVER_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
186 $(COVER_DIR)/src/%.o: $(SOURCE_DIR)/%.cpp | $(COVER_DIR)
189 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(COVER_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
192 $(DEBUG_BIN): %.debug: $(DEBUG_DIR)/%.o $(DEBUG_LIB_OBJ)
194 @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(DEBUG_FLAGS)
196 $(DEBUG_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(DEBUG_DIR)
199 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(DEBUG_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
202 $(PROFILE_BIN): %.profile: $(PROFILE_DIR)/%.o $(PROFILE_LIB_OBJ)
204 @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(PROFILE_FLAGS)
206 $(PROFILE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(PROFILE_DIR)
209 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(PROFILE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
212 $(RELEASE_BIN): %: $(RELEASE_DIR)/%.o $(RELEASE_LIB_OBJ)
214 @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(RELEASE_FLAGS)
216 $(RELEASE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(RELEASE_DIR)
219 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
222 $(TEST_BIN): $(TEST_OBJ)
224 @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(TESTLIBS) $(TEST_FLAGS)
226 $(TEST_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(TEST_DIR)
229 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
231 $(TEST_DIR)/src/%.o: $(SOURCE_DIR)/%.cpp | $(TEST_DIR)
234 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
237 $(ASSET_DEP): .git/$(shell git symbolic-ref HEAD 2>/dev/null || echo HEAD)
239 @git submodule update --init >/dev/null