-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (85 loc) · 2.48 KB
/
Copy pathMakefile
File metadata and controls
111 lines (85 loc) · 2.48 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
# Config for Post-Modern C
CXX := g++
CXX_STD := --std=c++26
CXX_MOD := -fmodules-ts
CXX_EXTRA := -fno-rtti -fno-exceptions
CXXFLAGS := $(CXX_STD) $(CXX_MOD) $(CXX_EXTRA)
MODE ?= debug
# Default as many wayland users have XWayland
WINDOWING ?= X11
VALID_TARGETS := core
TARGET ?= core
# TODO: set OS target (useless for now)
OS := gnu_linux
ifeq ($(filter clean,$(MAKECMDGOALS)),)
ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
$(error TARGET must be one of: $(VALID_TARGETS))
endif
endif
BUILD_DIR := build
# Build order:
# Data Structures -> Platform Layer -> Core
OBJS :=
# We need to compile the data structures before the core engine
DATA_STRUCTURES := $(wildcard src/data_structures/*.cpp)
OBJS += $(DATA_STRUCTURES:%=$(BUILD_DIR)/%.o)
# Platform layer
PLATFORM := $(wildcard src/platform/*.cpp)
OBJS += $(PLATFORM:%=$(BUILD_DIR)/%.o)
CORE := $(wildcard src/$(TARGET)/*.cpp)
OBJS += $(CORE:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
LIBS :=
# We are not using pthreads now but we'll likely use it latter
ifeq ($(OS), gnu_linux)
LIBS += -lpthread
endif
ifeq ($(WINDOWING), X11)
CXXFLAGS += -DPLATFORM_GNU_LINUX_X11
LIBS += -lX11
else ifeq ($(WINDOWING), wayland)
CXXFLAGS += -DPLATFORM_GNU_LINUX_WAYLAND
else
$(error Unknown WINDOWING option: $(WINDOWING). Choose 'X11' or 'wayland')
endif
# Werror can be annoying but it's usefull to force reasonable code
WARN_FLAGS := -Wall -Wextra -Wpedantic -Wshadow -Werror
DBG_FLAGS := -ggdb -Og
RELEASE_FLAGS := -Ofast -flto -march=native -DNDEBUG
LDFLAGS :=
ifeq ($(filter $(MODE),debug),$(MODE))
CXXFLAGS += $(WARN_FLAGS) $(DBG_FLAGS)
else
CXXFLAGS += $(RELEASE_FLAGS)
LDFLAGS += -Wl,-s
endif
BIN := $(BUILD_DIR)/$(MODE)/$(TARGET)
# This compiles the objects in the order they are defined
$(BIN): $(OBJS)
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(OBJS) -o $@ $(LIBS) $(LDFLAGS)
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
# System headers to pre-compile as modules
# Used in release builds
SYS_HEADERS := cstdlib cstring
# Build/debug headers
SYS_HEADERS += type_traits cassert iostream
.PHONY: clean test setup
setup:
ifeq ($(wildcard gcm.cache),)
@echo "Pre-compiling system headers..."
@mkdir -p gcm.cache
@for hdr in $(SYS_HEADERS); do \
$(CXX) $(CXXFLAGS) -xc++-system-header $$hdr; \
done
else
@echo "gcm modules already exist. Skipping setup."
endif
$(OBJS): | setup
test: $(BIN)
./$(BIN)
clean:
rm -rf build gcm.cache
-include $(DEPS)