4 LIBS = sdl2 SDL2_image glew
6 PKGFLAGS := $(shell pkg-config --cflags $(LIBS))
7 PKGLIBS := $(shell pkg-config --libs $(LIBS))
10 CPPFLAGS += $(PKGFLAGS)
14 LDXXFLAGS += $(PKGLIBS)
17 PROFILE_FLAGS = -DNDEBUG -O1 -g3
18 RELEASE_FLAGS = -DNDEBUG -O2
21 DEBUG_DIR := build/debug
22 PROFILE_DIR := build/profile
23 RELEASE_DIR := build/release
24 DIR := $(RELEASE_DIR) $(DEBUG_DIR) $(PROFILE_DIR) build
26 SRC := $(wildcard $(SOURCE_DIR)/*.cpp)
27 RELEASE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(SRC))
28 DEBUG_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(SRC))
29 PROFILE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(SRC))
30 RELEASE_DEP := $(RELEASE_OBJ:.o=.d)
31 DEBUG_DEP := $(DEBUG_OBJ:.o=.d)
32 PROFILE_DEP := $(PROFILE_OBJ:.o=.d)
34 DEBUG_BIN := blank.debug
35 PROFILE_BIN := blank.profile
36 OBJ := $(RELEASE_OBJ) $(DEBUG_OBJ) $(PROFILE_OBJ)
37 DEP := $(RELEASE_DEP) $(DEBUG_DEP) $(PROFILE_DEP)
38 BIN := $(RELEASE_BIN) $(DEBUG_BIN) $(PROFILE_BIN)
40 release: $(RELEASE_BIN)
46 profile: $(PROFILE_BIN)
54 cachegrind: blank.profile
55 valgrind ./blank.profile
57 callgrind: blank.profile
58 valgrind --tool=callgrind \
59 --branch-sim=yes --cacheuse=yes --cache-sim=yes \
60 --collect-bus=yes --collect-systime=yes --collect-jumps=yes \
61 --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \
65 rm -df $(OBJ) $(DEP) $(DIR)
68 rm -f $(BIN) cachegrind.out.* callgrind.out.*
70 .PHONY: all release debug profile run gdb cachegrind callgrind clean distclean
74 $(RELEASE_BIN): $(RELEASE_OBJ)
76 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(RELEASE_FLAGS) $^
78 $(DEBUG_BIN): $(DEBUG_OBJ)
80 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(DEBUG_FLAGS) $^
82 $(PROFILE_BIN): $(PROFILE_OBJ)
84 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(PROFILE_FLAGS) $^
86 $(RELEASE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(RELEASE_DIR)
88 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
90 $(DEBUG_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(DEBUG_DIR)
92 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(DEBUG_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
94 $(PROFILE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(PROFILE_DIR)
96 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(PROFILE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<