-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
254 lines (209 loc) · 8.19 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
CXXFLAGS += -std=gnu++11 -Wall -Wextra -MMD -MP -I$(abspath src)
CXXFLAGS += -Wno-non-template-friend -include config.h
LDFLAGS += $(ld_extra) -g -lsqlite3 -lgit2 -lsource-highlight -lz
LDFLAGS += -lboost_filesystem -lboost_iostreams -lboost_program_options
LDFLAGS += -lboost_system
INSTALL := install -D
PREFIX := /usr
ifneq ($(OS),Windows_NT)
bin_suffix :=
else
bin_suffix := .exe
endif
# this function of two arguments (array and element) returns index of the
# element in the array; return -1 if item not found in the list
pos = $(strip $(eval T := ) \
$(eval i := -1) \
$(foreach elem, $1, \
$(if $(filter $2,$(elem)), \
$(eval i := $(words $T)), \
$(eval T := $T $(elem)))) \
$i)
# determine output directory and build target; "." is the directory by default
# or "release"/"debug" for corresponding targets
is_release := 0
ifneq ($(call pos,release,$(MAKECMDGOALS)),-1)
is_release := 1
endif
ifneq ($(call pos,install,$(MAKECMDGOALS)),-1)
is_release := 1
endif
ifneq ($(is_release),0)
EXTRA_CXXFLAGS := -O3
# EXTRA_LDFLAGS := -Wl,--strip-all
out_dir := release
target := release
else
EXTRA_CXXFLAGS := -O0 -g
EXTRA_LDFLAGS := -g
ifneq ($(call pos,debug,$(MAKECMDGOALS)),-1)
out_dir := debug
else
ifneq ($(call pos,sanitize-basic,$(MAKECMDGOALS)),-1)
out_dir := sanitize-basic
EXTRA_CXXFLAGS += -fsanitize=address -fsanitize=undefined
EXTRA_LDFLAGS += -fsanitize=address -fsanitize=undefined -pthread
else
with_cov := 0
ifneq ($(call pos,coverage,$(MAKECMDGOALS)),-1)
with_cov := 1
endif
ifneq ($(call pos,self-coverage,$(MAKECMDGOALS)),-1)
with_cov := 1
endif
ifneq ($(with_cov),0)
out_dir := coverage
EXTRA_CXXFLAGS += --coverage
EXTRA_LDFLAGS += --coverage
else
out_dir := .
endif
endif
endif
target := debug
endif
# run all tests by default
TESTS :=
-include config.mk
# traverse directories ($1) recursively looking for a pattern ($2) to make list
# of matching files
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
$(filter $(subst *,%,$2),$d))
bin := $(out_dir)/uncov$(bin_suffix)
bin_sources := $(call rwildcard, src/, *.cpp)
bin_objects := $(bin_sources:%.cpp=$(out_dir)/%.o)
bin_depends := $(bin_objects:.o=.d)
tests_sources := $(call rwildcard, tests/, *.cpp)
tests_sources := $(filter-out tests/test-repo%, $(tests_sources))
tests_objects := $(tests_sources:%.cpp=$(out_dir)/%.o)
tests_objects += $(filter-out %/main.o,$(bin_objects))
tests_depends := $(tests_objects:%.o=%.d)
webbin := $(out_dir)/uncov-web$(bin_suffix)
web_sources := $(call rwildcard, web/, *.cpp)
web_temps := $(patsubst %.ecpp,$(out_dir)/%.cpp,$(call rwildcard, web/, *.ecpp))
web_temps += $(patsubst %.css,$(out_dir)/%.cpp,$(call rwildcard, web/, *.css))
web_temps += $(patsubst %.ico,$(out_dir)/%.cpp,$(call rwildcard, web/, *.ico))
web_temps += $(patsubst %.txt,$(out_dir)/%.cpp,$(call rwildcard, web/, *.txt))
web_objects := $(web_sources:%.cpp=$(out_dir)/%.o)
web_objects += $(web_temps:%.cpp=%.o)
web_objects += $(filter-out %/main.o,$(bin_objects))
web_depends := $(web_objects:%.o=%.d)
web_depends += $(patsubst %.ecpp,$(out_dir)/%.ecpp.d, \
$(call rwildcard, web/, *.ecpp))
out_dirs := $(sort $(dir $(bin_objects) $(web_objects) $(tests_objects)))
.PHONY: all check clean debug release sanitize-basic install uninstall
.PHONY: man doxygen
.PHONY: coverage self-coverage self-coverage-release reset-coverage
all: $(bin) $(webbin)
debug release sanitize-basic: all
coverage: check $(bin)
uncov new-gcovi --exclude tests/ --exclude web/ \
--capture-worktree $(out_dir)
self-coverage: check self-coverage-release
release/uncov new-gcovi --exclude tests/ --exclude web/ \
--capture-worktree $(out_dir)
self-coverage-release:
+$(MAKE) release
man: docs/uncov.1 docs/uncov-gcov.1 docs/uncov-web.1
# the following targets don't depend on $(wildcard docs/*/*.md) to make pandoc
# optional
docs/uncov.1: force
pandoc -V title=uncov \
-V section=1 \
-V app=uncov \
-V footer="uncov v0.5" \
-V date="$$(date +'%B %d, %Y')" \
-V author='xaizek <[email protected]>' \
-s -o $@ $(sort $(wildcard docs/uncov/*.md))
docs/uncov-gcov.1: force
pandoc -V title=uncov-gcov \
-V section=1 \
-V app=uncov-gcov \
-V footer="uncov v0.5" \
-V date="$$(date +'%B %d, %Y')" \
-V author='xaizek <[email protected]>' \
-s -o $@ $(sort $(wildcard docs/uncov-gcov/*.md))
docs/uncov-web.1: force
pandoc -V title=uncov-web \
-V section=1 \
-V app=uncov-web \
-V footer="uncov v0.5" \
-V date="$$(date +'%B %d, %Y')" \
-V author='xaizek <[email protected]>' \
-s -o $@ $(sort $(wildcard docs/uncov-web/*.md))
doxygen:
doxygen doxygen/config
ln -sr data doxygen/html/
# target that doesn't exist and used to force rebuild
force:
reset-coverage: | $(out_dirs)
ifeq ($(with_cov),1)
find $(out_dir)/ -name '*.gcda' -delete
endif
$(bin) $(webbin): | $(out_dirs)
$(bin): $(bin_objects)
$(CXX) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
ifndef NO-WEB
$(webbin): $(web_objects) | $(web_temps)
$(CXX) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS) -ltntnet -lcxxtools
else
$(webbin):
@echo '#!/bin/bash' >> $@
@echo 'echo "Uncov-web was disabled during build"' >> $@
@chmod +x $@
endif
check: $(target) $(out_dir)/tests/tests tests/test-repo-gcno/test-repo-gcno \
reset-coverage
@$(out_dir)/tests/tests $(TESTS)
tests/test-repo-gcno/test-repo-gcno: tests/test-repo-gcno/main.cpp
# this must always be compiled with GCC for gcov to be able to process
# output files (need a separate variable for it?)
cd tests/test-repo-gcno/ && g++ --coverage -o test-repo-gcno main.cpp
install: release
$(INSTALL) -t $(DESTDIR)$(PREFIX)/bin/ $(bin) $(webbin) uncov-gcov
$(INSTALL) -t $(DESTDIR)$(PREFIX)/share/uncov/srchilight/ data/srchilight/*
$(INSTALL) -m 644 docs/uncov.1 $(DESTDIR)$(PREFIX)/share/man/man1/uncov.1
$(INSTALL) -m 644 docs/uncov-gcov.1 \
$(DESTDIR)$(PREFIX)/share/man/man1/uncov-gcov.1
$(INSTALL) -m 644 docs/uncov-web.1 \
$(DESTDIR)$(PREFIX)/share/man/man1/uncov-web.1
uninstall:
$(RM) $(DESTDIR)$(PREFIX)/bin/$(basename $(bin)) \
$(DESTDIR)$(PREFIX)/bin/$(basename $(webbin)) \
$(DESTDIR)$(PREFIX)/bin/uncov-gcov \
$(DESTDIR)$(PREFIX)/share/man/man1/uncov.1 \
$(DESTDIR)$(PREFIX)/share/man/man1/uncov-gcov.1 \
$(DESTDIR)$(PREFIX)/share/man/man1/uncov-web.1
$(RM) -r $(DESTDIR)$(PREFIX)/share/uncov/
# work around parenthesis warning in tests somehow caused by ccache
$(out_dir)/tests/tests: EXTRA_CXXFLAGS += -Wno-error=parentheses -Itests/
$(out_dir)/tests/tests: $(tests_objects) tests/. | $(out_dirs)
$(CXX) -o $@ $(tests_objects) $(LDFLAGS) $(EXTRA_LDFLAGS)
config.h: | config.h.in
cp config.h.in $@
$(out_dir)/web/%.o: CXXFLAGS += -I$(abspath web)
$(out_dir)/web/%.o: $(out_dir)/web/%.cpp config.h | $(out_dirs)
$(CXX) -o $@ -c $(CXXFLAGS) $(EXTRA_CXXFLAGS) $<
$(out_dir)/%.o: %.cpp config.h | $(out_dirs)
$(CXX) -o $@ -c $(CXXFLAGS) $(EXTRA_CXXFLAGS) $<
$(out_dir)/%.cpp: %.ecpp | $(out_dirs)
ecppc -o $@ $<
ecppc -M -o $(out_dir)/$*.ecpp.d -n $* $<
$(out_dir)/%.cpp: %.css | $(out_dirs)
ecppc -b -m text/css -o $@ $<
$(out_dir)/%.cpp: %.ico | $(out_dirs)
ecppc -b -m image/x-icon -o $@ $<
$(out_dir)/%.cpp: %.txt | $(out_dirs)
ecppc -b -m text/plain -o $@ $<
$(out_dirs) $(out_dir)/docs:
mkdir -p $@
clean:
-$(RM) -r coverage/ debug/ release/
-$(RM) $(bin_objects) $(tests_objects) $(web_objects) \
$(bin_depends) $(tests_depends) $(web_depends) \
$(web_temps) \
$(bin) $(webbin) $(out_dir)/tests/tests \
tests/test-repo-gcno/test-repo-gcno \
tests/test-repo-gcno/test-repo-gcno.gcda \
tests/test-repo-gcno/test-repo-gcno.gcno
include $(wildcard $(bin_depends) $(tests_depends) $(web_depends))