-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
121 lines (82 loc) · 3.7 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
112
113
114
115
116
117
118
119
120
121
# Practical makefiles, by example: http://nuclear.mutantstargoat.com/articles/make/
# Automatic variables: https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
CXX := /usr/local/gcc-10.2.0/bin/g++-10.2
CXXFLAGS := -MMD
CPPFLAGS := -std=c++20
ROOT := /home/mike/projects/languages/proto/repo
INCLUDES := -I/usr/local/gcc-10.2.0/include/c++/10.2.0/ -I$(ROOT)/external -I$(ROOT)/source
COMPILE := $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES)
# Set the display of the time command. See https://man7.org/linux/man-pages/man1/time.1.html
TIME_FORMAT="%E elapsed (%U user %S system) | %P CPU | %Xk text %Dk data %Mk max | %I inputs %O outputs | %F major + %R minor pagefaults | %W swaps\n"
.PHONY: error
error:
@echo "Error: no default make rule provided"
.PHONY: all
all:
$(MAKE) tests
$(MAKE) examples
$(MAKE) docs
# ======================================================================================================================
# Tests
# ======================================================================================================================
TEST_SRCS = $(filter-out tests/main.test.cpp,$(shell find tests/ -name "*.test.cpp"))
TEST_EXES = $(addprefix build/,$(TEST_SRCS:.cpp=.out))
.PHONY: tests
tests: build/tests/main.test.o $(TEST_EXES)
# Uses -ggdb so that VSCode C++ TestMate doesn't need to recompile first when debugging. Would it be better to remove?
build/%.test.out: %.test.cpp
@echo "building $(@F) ..."
@mkdir -p $(@D)
@time -f $(TIME_FORMAT) -- $(COMPILE) -ggdb build/tests/main.test.o $< -o $@
build/tests/main.test.o: tests/main.test.cpp
@echo "building $(@F) ..."
@mkdir -p $(@D)
@time -f $(TIME_FORMAT) -- $(COMPILE) -O3 -ggdb $< -c -o $@
# Dependency rules included at bottom of file
# Recompiles on change, so the test harness can autorun. Pass relative src= on the command line.
.PHONY: watch-test
watch-test: exe=build/$(basename $(src)).out
watch-test:
@if [ -f "$(ROOT)/$(src)" ]; then \
while true; do \
clear; \
$(MAKE) $(exe) --no-print-directory; \
\
echo "watching $(notdir $(src)) ..."; \
inotifywait -qq -e modify $(ROOT)/$(src); \
done; \
else \
echo "file doesn't exist: $(src)"; \
fi
# ======================================================================================================================
# Examples
# ======================================================================================================================
.PHONY: examples
examples:
# Each example should have a file example.expected for testing its output
# Create a driver for comparing example.out to example.expected
# ======================================================================================================================
# Docs
# ======================================================================================================================
.PHONY: docs
docs:
$(MAKE) -C docs html
# ======================================================================================================================
# Misc
# ======================================================================================================================
.PHONY: clean-all clean-tests clean-examples clean-docs
clean-all:
rm -rf build/
clean-tests:
rm -rf build/tests
clean-examples:
rm -rf build/examples
clean-docs:
rm -rf build/docs
.PHONY: troubleshoot
troubleshoot:
@echo $(TEST_SRCS)
@echo $(TEST_EXES)
@echo $(TEST_DEPS)
TEST_DEPS := $(TEST_EXES:.out=.d)
-include $(TEST_DEPS)