4 LIBS = sdl2 SDL2_image glew
6 PKGFLAGS := $(shell pkg-config --cflags $(LIBS))
7 PKGLIBS := $(shell pkg-config --libs $(LIBS))
8 TESTFLAGS := $(shell pkg-config --cflags cppunit)
9 TESTLIBS := $(shell pkg-config --libs cppunit)
12 CPPFLAGS += $(PKGFLAGS)
16 LDXXFLAGS += $(PKGLIBS)
19 PROFILE_FLAGS = -DNDEBUG -O1 -g3
20 RELEASE_FLAGS = -DNDEBUG -O2
21 TEST_FLAGS = -g -O2 -I./src $(TESTFLAGS)
25 DEBUG_DIR := build/debug
26 PROFILE_DIR := build/profile
27 RELEASE_DIR := build/release
28 TEST_DIR := build/test
29 DIR := $(RELEASE_DIR) $(DEBUG_DIR) $(PROFILE_DIR) $(TEST_DIR) build
31 LIB_SRC := $(wildcard $(SOURCE_DIR)/*/*.cpp)
32 BIN_SRC := $(wildcard $(SOURCE_DIR)/*.cpp)
33 SRC := $(LIB_SRC) $(BIN_SRC)
34 TEST_SRC := $(wildcard $(TEST_SRC_DIR)/*.cpp) $(wildcard $(TEST_SRC_DIR)/*/*.cpp)
35 RELEASE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(SRC))
36 DEBUG_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(SRC))
37 PROFILE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(SRC))
38 TEST_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cpp, $(TEST_DIR)/%.o, $(TEST_SRC)) $(patsubst $(SOURCE_DIR)/%.cpp, $(TEST_DIR)/src/%.o, $(LIB_SRC))
39 RELEASE_DEP := $(RELEASE_OBJ:.o=.d)
40 DEBUG_DEP := $(DEBUG_OBJ:.o=.d)
41 PROFILE_DEP := $(PROFILE_OBJ:.o=.d)
42 TEST_DEP := $(TEST_OBJ:.o=.d)
44 DEBUG_BIN := blank.debug
45 PROFILE_BIN := blank.profile
46 TEST_BIN := blank.test
47 OBJ := $(RELEASE_OBJ) $(DEBUG_OBJ) $(PROFILE_OBJ) $(TEST_OBJ)
48 DEP := $(RELEASE_DEP) $(DEBUG_DEP) $(PROFILE_DEP) $(TEST_DEP)
49 BIN := $(RELEASE_BIN) $(DEBUG_BIN) $(PROFILE_BIN) $(TEST_BIN)
51 release: $(RELEASE_BIN)
57 profile: $(PROFILE_BIN)
67 cachegrind: blank.profile
68 valgrind ./blank.profile
70 callgrind: blank.profile
71 valgrind --tool=callgrind \
72 --branch-sim=yes --cacheuse=yes --cache-sim=yes \
73 --collect-bus=yes --collect-systime=yes --collect-jumps=yes \
74 --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \
75 ./blank.profile -n 128 -t 16 --no-keyboard --no-mouse -d --no-vsync
81 rm -df $(OBJ) $(DEP) $(DIR)
84 rm -f $(BIN) cachegrind.out.* callgrind.out.*
86 .PHONY: all release debug profile tests run gdb cachegrind callgrind test clean distclean
90 $(RELEASE_BIN): $(RELEASE_OBJ)
92 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(RELEASE_FLAGS) $^
94 $(DEBUG_BIN): $(DEBUG_OBJ)
96 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(DEBUG_FLAGS) $^
98 $(PROFILE_BIN): $(PROFILE_OBJ)
100 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(PROFILE_FLAGS) $^
102 $(TEST_BIN): $(TEST_OBJ)
104 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(TESTLIBS) $(TEST_FLAGS) $^
106 $(RELEASE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(RELEASE_DIR)
109 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
111 $(DEBUG_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(DEBUG_DIR)
114 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(DEBUG_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
116 $(PROFILE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(PROFILE_DIR)
119 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(PROFILE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
121 $(TEST_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(TEST_DIR)
124 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
126 $(TEST_DIR)/src/%.o: $(SOURCE_DIR)/%.cpp | $(TEST_DIR)
129 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<