-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (98 loc) · 2.63 KB
/
Makefile
File metadata and controls
134 lines (98 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
CXXFLAGS += -I.
# Generate dependency files with the object files
CXXFLAGS += -MMD -MP
# Optimization
CXXFLAGS += -O3 -march=nocona -funsafe-math-optimizations
# Warnings
CXXFLAGS += -Wall -Wextra -Wno-unused-parameter
# C++ standard
CXXFLAGS += -std=c++11
MACHINE = $(shell $(CC) -dumpmachine)
ifneq (, $(findstring apple, $(MACHINE)))
ARCH_MAC := 1
ARCH := mac
else ifneq (, $(findstring mingw, $(MACHINE)))
ARCH_WIN := 1
ARCH := win
ifneq ( ,$(findstring x86_64, $(MACHINE)))
ARCH_WIN_64 := 1
BITS := 64
else ifneq (, $(findstring i686, $(MACHINE)))
ARCH_WIN_32 := 1
BITS := 32
endif
else ifneq (, $(findstring linux, $(MACHINE)))
ARCH_LIN := 1
ARCH := lin
else
$(error Could not determine architecture of $(MACHINE).)
endif
# Architecture-dependent flags
ifdef ARCH_LIN
CXXFLAGS += -Wsuggest-override
endif
ifdef ARCH_MAC
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
MAC_SDK_FLAGS = -mmacosx-version-min=10.7
CXXFLAGS += $(MAC_SDK_FLAGS)
LDFLAGS += $(MAC_SDK_FLAGS)
endif
ifdef ARCH_WIN
CXXFLAGS += -D_USE_MATH_DEFINES
CXXFLAGS += -Wsuggest-override
endif
OBJECTS := $(patsubst %.cpp, build/%.cpp.o, $(SOURCES))
SOURCES = $(shell find test -name "*.cpp")
OBJECTS := $(patsubst %, build/%.o, $(SOURCES))
RUNNER = build/runtests
all: test
.PHONY: test vtest
test: testrunner
$(RUNNER)
vtest: testrunner
$(RUNNER) --verbose
$(RUNNER): $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)
.PHONY: testrunner
testrunner: $(RUNNER)
########################################################################
#
# Analyze and format the code
#
########################################################################
HEADERS = $(shell find dheunit -name "*.h")
.PHONY: format
format:
clang-format -i -style=file $(HEADERS) $(SOURCES)
COMPILATION_DB = compile_commands.json
COMPILATION_DB_ENTRIES := $(patsubst %, build/%.json, $(SOURCES))
$(COMPILATION_DB): $(COMPILATION_DB_ENTRIES)
sed -e '1s/^/[/' -e '$$s/,$$/]/' $^ | json_pp > $@
.PHONY: setup
setup: $(COMPILATION_DB)
.PHONY: tidy
tidy: setup
clang-tidy -p=build $(SOURCES)
IWYU := include-what-you-use
IWYU += -Xiwyu --quoted_includes_first
IWYU += -Xiwyu --mapping_file=.iwyu.libcxx.yaml
IWYU += -Xiwyu --transitive_includes_only
iwyu:
$(MAKE) -Bi CXX='$(IWYU)' $(OBJECTS)
check: tidy iwyu
########################################################################
#
# General rules
#
########################################################################
-include $(OBJECTS:.o=.d)
build/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c -o $@ $<
build/%.json: %
@mkdir -p $(@D)
clang $(CXXFLAGS) -MJ $@ -c -o build/$^.o $^
clean:
rm -rf build
rm -rf $(COMPILATION_DB)