-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
111 lines (89 loc) · 2.63 KB
/
Copy pathmakefile
File metadata and controls
111 lines (89 loc) · 2.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
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
CC = gcc
CXX = g++
MODE ?= DEBUG
INCLUDE_DIR = include
.PHONY: all
all:
$(MAKE) --no-print-directory MODE=DEBUG build
$(MAKE) --no-print-directory MODE=RELEASE build
CFLAGS += -Wall -Wextra -Werror
CFLAGS += -Wno-error=unused-parameter
CFLAGS += -Wno-error=unused-variable
CFLAGS += -Wno-error=unused-but-set-variable
CFLAGS += -I$(INCLUDE_DIR)
CFLAGS += -std=c99
CXXFLAGS += -Wall -Wextra -Werror
CXXFLAGS += -Wno-error=unused-parameter
CXXFLAGS += -Wno-error=unused-variable
CXXFLAGS += -Wno-error=unused-but-set-variable
CXXFLAGS += -I$(INCLUDE_DIR)
CXXFLAGS += -std=c++17
ifeq ($(MODE), DEBUG)
include debug.mk
endif
ifeq ($(MODE), RELEASE)
include release.mk
endif
ifndef BUILD_DIR
$(error BUILD_DIR is not defined)
endif
ifndef TARGET_DIR
$(error TARGET_DIR is not defined)
endif
include targets.mk
ifndef TARGETS
$(error TARGETS are not defined)
endif
OUTPUT_OPTION = -MMD -MF $(@:.o=.d) -o $@
DEPS := $(shell find $(BUILD_DIR) -name "*.d" 2>/dev/null)
-include ${DEPS}
.PHONY: build
build: $(TARGETS)
.PHONY: b
b: build
.PHONY: run
run: $(TARGETS)
@for target in $(TARGETS); do (set -x; ./$$target) ; done
.PHONY: r
r: run
$(BUILD_DIR)/%.o: %.cpp
@mkdir --parents $(shell dirname $@)
$(CXX) $(CXXFLAGS) -MMD -MF $(@:.o=.d) -c -o $@ $<
$(BUILD_DIR)/%.o: %.c
@mkdir --parents $(shell dirname $@)
$(CC) $(CFLAGS) -MMD -MF $(@:.o=.d) -c -o $@ $<
.PHONY: clean
clean:
rm --force --recursive $(BUILD_DIR) $(TARGET_DIR)
.PHONY: help
help:
@echo Examples:
@echo '$$ make -j4 # Compile all targets in all modes'
@echo '$$ make MODE=DEBUG build # Build debug targets'
@echo '$$ make MODE=DEBUG b # Build debug targets'
@echo '$$ make MODE=RELEASE build # Build release targets'
@echo '$$ make MODE=RELEASE b # Build release targets'
@echo '$$ make r # Run all targets'
@echo '$$ make run # Run all targets'
@echo '$$ make MODE=DEBUG r # Run debug targets'
@echo '$$ make MODE=DEBUG run # Run debug targets'
@echo '$$ make MODE=RELEASE r # Run release targets'
@echo '$$ make MODE=RELEASE r # Run release targets'
@echo '$$ make clean # Clean intermidiate files'
@echo '$$ make vars # Print vars'
@echo '$$ make MODE=RELEASE compile_flags.txt # Regenerate compile_flags.txt for clangd'
.PHONY: vars
vars:
@echo BUILD_DIR=$(BUILD_DIR)
@echo TARGET_DIR=$(TARGET_DIR)
@echo CC=$(CC)
@echo CFLAGS=$(CFLAGS)
@echo CXX=$(CXX)
@echo CXXFLAGS=$(CXXFLAGS)
@echo INCLUDE_DIR=$(INCLUDE_DIR)
@echo LDFLAGS=$(LDFLAGS)
@echo MODE=$(MODE)
@echo TARGETS=$(TARGETS)
.PHONY: compile_flags.txt
compile_flags.txt:
@echo $(CFLAGS) | tr ' ' '\n' | tee $@