-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (75 loc) · 2.4 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
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
.PHONY: all clean run compile release debug fast fast-debug doc perf-compile fast-perf report benchmark directories test-compile fast-test test binaries
.DEFAULT_GOAL = all
PROJECT = ascii-art
VERSION = v0.1.2
SOURCE_EXT = .cpp
HEADER_EXT = .h
SOURCE_DIR = src
OUT_DIR = build
LIB_DIR = lib
BIN_DIR = bin
DOC_DIR = doc
MAKE_INCLUDE = Makefile.d
CXX = g++
LD = g++
LIBS = -ljpeg -lncurses -lncursesw -lpng -lz -lstdc++fs -lform
CXXFLAGS = -Wall -Wextra -pedantic -std=c++17 $(INCLUDE_DIR)
LDFLAGS = $(LIBS) $(LIBPATH)
SOURCE_FILES = $(wildcard $(SOURCE_DIR)/*$(SOURCE_EXT) $(SOURCE_DIR)/*/*$(SOURCE_EXT) $(SOURCE_DIR)/*/*/*$(SOURCE_EXT) $(SOURCE_DIR)/*/*/*/*$(SOURCE_EXT) $(SOURCE_DIR)/*/*/*/*/*$(SOURCE_EXT))
OBJECTS = $(patsubst %$(SOURCE_EXT),$(OUT_DIR)/%.o,$(notdir $(SOURCE_FILES)))
fast:
$(MAKE) -j12 release
fast-debug:
$(MAKE) -j12 debug
fast-perf:
$(MAKE) -j12 perf-compile
fast-test:
$(MAKE) -j12 test-compile
all: release doc
doc: Doxyfile
doxygen Doxyfile
debug: CXXFLAGS += -g -pg -O0 -DDEBUG -DLOG_LEVEL=0 -fPIE -fno-omit-frame-pointer # -fsanitize=address
debug: LDFLAGS +=
debug: compile
perf-compile: CXXFLAGS += -g -pg -O2 -fno-omit-frame-pointer
perf-compile: LDFLAGS +=
perf-compile: compile
release: CXXFLAGS += -O2
release: compile
test-compile: CXXFLAGS += -rdynamic -D __TESTING__ -fsanitize=address
test-compile: compile
compile: directories binaries
ifeq (run,$(firstword $(MAKECMDGOALS)))
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
endif
run: fast
./$(BIN_DIR)/$(PROJECT) $(RUN_ARGS)
test: fast-test
./$(BIN_DIR)/$(PROJECT)
benchmark: fast-perf
perf record -g ./$(BIN_DIR)/$(PROJECT) ./examples
$(OUT_DIR)/%.o:
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(BIN_DIR)/$(PROJECT): $(OBJECTS)
$(LD) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
binaries: $(BIN_DIR)/$(PROJECT)
clean:
rm -rf $(MAKE_INCLUDE)
rm -rf $(OUT_DIR)
rm -rf $(BIN_DIR)/$(PROJECT)
rm -rf $(DOC_DIR)
directories: $(OUT_DIR) $(BIN_DIR) $(MAKE_INCLUDE)
$(MAKE_INCLUDE):
mkdir -p $(MAKE_INCLUDE)
$(OUT_DIR):
mkdir -p $(OUT_DIR)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
define execute-command
$(1)
endef
$(MAKE_INCLUDE)/deps: $(MAKE_INCLUDE) $(SOURCE_DIR) $(SOURCE_FILES)
: > $(MAKE_INCLUDE)/deps
$(foreach SOURCE_FILE,$(SOURCE_FILES),$(call execute-command,$(CXX) -MT $(OUT_DIR)/$(notdir $(basename $(SOURCE_FILE))).o -MM $(SOURCE_FILE) >> $(MAKE_INCLUDE)/deps))
include $(MAKE_INCLUDE)/deps