-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
83 lines (60 loc) · 2.36 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
builddir = .build
bindir = $(builddir)/bin
binary = $(bindir)/ruek
benchbin = $(binary)_bench
buildfile = $(builddir)/build.ninja
benchdir = bench
protodir = proto
srcdir = src
sources := $(shell find $(protodir) -type f -name '*.proto')
sources += $(shell find $(srcdir) -type f -name '*.h' -o -name '*.cpp')
sources += $(shell find $(benchdir) -type f -name '*.h' -o -name '*.cpp')
lcov_output = $(builddir)/coverage.out
profdata_output = $(builddir)/coverage.profdata
testing_binaries := $(shell find $(bindir) -type f -perm -a=x -name "*_tests")
llvm-cov = $(shell which llvm-cov)
llvm-profdata = $(shell which llvm-profdata)
ifeq (, $(llvm-cov))
llvm-cov = $(shell xcrun --find llvm-cov)
endif
ifeq (, $(llvm-profdata))
llvm-profdata = $(shell xcrun --find llvm-profdata)
endif
.PHONY: $(binary) clean lint lint\:ci lint\:fix
.SILENT: coverage lint lint\:fix
%:
@:
all: $(binary)
$(binary): $(buildfile)
cmake --build $(builddir)
$(buildfile):
cmake -B $(builddir) -G Ninja
bench: $(binary)
$(benchbin) $(filter-out $@,$(MAKECMDGOALS)) $(MAKEFLAGS)
clean:
cmake --build $(builddir) --target clean
coverage: $(binary)
find $(builddir)/$(sourcedir) -type f -name "*.profraw" -exec rm {} +
LLVM_PROFILE_FILE="%p.profraw" ctest --test-dir $(builddir) --output-on-failure
echo '' # Empty line to separate outputs
-rm $(profdata_output)
find $(builddir)/$(sourcedir) -type f -name "*.profraw" -exec $(llvm-profdata) merge --sparse=true --output=$(profdata_output) {} +
$(llvm-cov) report -ignore-filename-regex='$(builddir)\/' -instr-profile=$(profdata_output) $(foreach bin, $(testing_binaries), -object=$(bin))
coverage\:lcov: coverage
$(llvm-cov) export -format=lcov -ignore-filename-regex='$(builddir)\/' -ignore-filename-regex='.*_test\.cpp' -instr-profile=$(profdata_output) $(foreach bin, $(testing_binaries), -object=$(bin)) > $(lcov_output)
@echo '' # Empty line to separate outputs
lcov --list $(lcov_output)
lint:
ifeq (, $(shell which clang-format))
echo '\033[1;41m WARN \033[0m clang-format not found, not linting files';
else
clang-format --style=file --dry-run $(sources)
endif
lint\:ci:
clang-format --style=file --dry-run --Werror $(sources)
lint\:fix:
clang-format --style=file -i $(sources)
run: $(binary)
$(binary) -4 127.0.0.1
test: $(binary)
ctest --test-dir $(builddir) --output-on-failure $(filter-out $@,$(MAKECMDGOALS))