This repository was archived by the owner on Jul 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (58 loc) · 1.63 KB
/
Copy pathMakefile
File metadata and controls
77 lines (58 loc) · 1.63 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
# Config for Post-Modern C
CXX := g++
CXX_STD := --std=c++26
CXX_EXTRA = -fno-rtti -fno-exceptions
CXX_FLAGS := $(CXX_STD) $(CXX_EXTRA)
CXX_FLAGS += -Isrc
MODE ?= debug
# Default X11 as many Wayland users have XWayland
WINDOWING ?= X11
VALID_TARGETS := editor test benchmark
TARGET ?= editor
# Other OS targets
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
SRCS := src/main.cpp
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
LIBS :=
# We are not using pthreads now but we'll likely use it latter
ifeq ($(OS), gnu_linux)
LIBS += -lpthread
CXX_FLAGS += -DPLATFORM_GNU_LINUX
endif
ifeq ($(WINDOWING), X11)
CXX_FLAGS += -DPLATFORM_GNU_LINUX_X11
LIBS += -lX11
else ifeq ($(WINDOWING), Wayland)
CXX_FLAGS += -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
ifeq ($(filter $(MODE),debug),$(MODE))
CXX_FLAGS += $(WARN_FLAGS) $(DBG_FLAGS)
else
CXX_FLAGS += $(RELEASE_FLAGS)
LDFLAGS += -Wl,-s
endif
BIN := $(BUILD_DIR)/$(MODE)/$(WINDOWING)/$(TARGET)
.PHONY: all clean_build clean_gcm
all: $(BIN)
$(BIN): $(OBJS)
mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(OBJS) -o $@ $(LIBS)
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) -c $< -o $@
clean_build:
rm -rf $(BUILD_DIR)
clean_gcm:
rm -rf gcm.cache