-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
49 lines (33 loc) · 1.15 KB
/
makefile
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
TARGET_EXEC ?= main
BUILD_DIR ?= .
SRC_DIRS ?= ./src
DEFS := -DGLM_ENABLE_EXPERIMENTAL -DGLFW_INCLUDE_NONE
DEBFAGS = -fsanitize=undefined -fsanitize=address -O0
CXXFLAGS := $(DEFS) -std=c++17 -Wall -Wshadow -O3 $(DEBFAGS)
LDFLAGS := -lglfw -lGL -lX11 -lpthread -lXrandr -lXi -ldl
INCLUDE_DIRS := -I./include -I./scr
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CXX) $(OBJS) -o $@ -flto $(CXXFLAGS) $(LDFLAGS)
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $@)
$(AS) $(ASFLAGS) -c $< -o $@
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) $(INCLUDE_DIRS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDE_DIRS) -c $< -o $@
.PHONY: clean
clean:
find $(BUILD_DIR)/$(SRC_DIRS) -name "*.o" -type f -delete && find $(BUILD_DIR)/$(SRC_DIRS) -name "*.d" -type f -delete
-include $(DEPS)
MKDIR_P ?= mkdir -p