-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (50 loc) · 1.82 KB
/
Copy pathMakefile
File metadata and controls
66 lines (50 loc) · 1.82 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
# Compiler
CXX = clang++
CXXFLAGS = -std=c++17 -g -DGL_SILENCE_DEPRECATION
# Include paths
INCLUDE_PATHS = -Isrc \
-Ibuild/external/ggpo/include \
$(shell pkg-config --cflags sdl2 sdl2_image SDL2_ttf jsoncpp) \
-Iimgui -Iimgui/impl
# Library paths and linker flags
LIBRARY_FLAGS = $(shell pkg-config --libs sdl2 sdl2_image SDL2_ttf jsoncpp)
FRAMEWORK_FLAGS = -framework OpenGL
# Output binary
OBJ_NAME = game
# Build directory for object files
BUILD_DIR = build/obj
# Precompiled header
PCH_SRC = src/pch.h
PCH_OUT = $(BUILD_DIR)/pch.h.pch
# Source files
SRC_FILES = $(shell find src -name '*.cpp')
IMGUI_FILES = imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_widgets.cpp \
imgui/impl/imgui_impl_sdl.cpp imgui/impl/imgui_impl_opengl2.cpp
# Object files: src/Foo/Bar.cpp -> build/obj/src/Foo/Bar.o
SRC_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRC_FILES))
IMGUI_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(IMGUI_FILES))
ALL_OBJS = $(SRC_OBJS) $(IMGUI_OBJS)
# Dependency files generated by -MMD
DEP_FILES = $(ALL_OBJS:.o=.d)
# Default target
all: $(OBJ_NAME)
# Link
$(OBJ_NAME): $(ALL_OBJS)
$(CXX) $(ALL_OBJS) $(LIBRARY_FLAGS) $(FRAMEWORK_FLAGS) -o $(OBJ_NAME)
# Compile PCH
$(PCH_OUT): $(PCH_SRC)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATHS) -x c++-header $< -o $@
# Compile project sources (with PCH)
$(BUILD_DIR)/src/%.o: src/%.cpp $(PCH_OUT)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATHS) -MMD -MP -include-pch $(PCH_OUT) -c $< -o $@
# Compile imgui sources (no PCH — they don't use our project headers)
$(BUILD_DIR)/imgui/%.o: imgui/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDE_PATHS) -MMD -MP -c $< -o $@
clean:
rm -rf $(BUILD_DIR) $(OBJ_NAME)
.PHONY: all clean
# Include generated dependency files (if they exist)
-include $(DEP_FILES)