-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (78 loc) · 2.51 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
V ?= 0
CC = g++
TEST_COV ?= 0
CFLAGS = -Wall -fPIC
FLAGS_OPTIMIZATION ?= -O3
FLAGS_DEBUG ?= -g -ggdb -O0
ifeq ($(TEST_COV),1)
CFLAGS += -fprofile-arcs -ftest-coverage
endif
node := $(shell which node)
npm := $(shell which npm)
clang-format-bin := ./tools/node_modules/.bin/clang-format
cpplint-bin := ./tools/node_modules/.bin/cpplint
BUILDTYPE ?= Debug
RESIZABLE_BUFFER_HEADER_FILE := include/resizable_buffer.h
TEST_FILES := test/test.cc
TEST_EXE := build/test
RELEASE_FLAGS := $(FLAGS_OPTIMIZATION) $(CFLAGS)
TEST_G_EXE := build/test_g
DEBUG_FLAGS := $(FLAGS_DEBUG) $(CFLAGS)
.PHONY: all test
ifeq ($(BUILDTYPE),Release)
all: $(TEST_EXE)
test: all
$(TEST_EXE) -d
else
all: $(TEST_G_EXE)
test: all
$(TEST_G_EXE) -d
endif
.PHONY: dev-prepare clang-format cpplint
dev-prepare: .node-modules-installed
clang-format: .clang-formatted
cpplint: .cpplinted
.node-modules-installed: tools/package.json
if [ ! -a $(npm) ]; then \
echo "npm not found"; \
exit 1; \
else \
cd tools && rm -rf node_modules && $(npm) install && cd ..; \
fi
touch .node-modules-installed
$(clang-format-bin): .node-modules-installed
$(cpplint-bin): .node-modules-installed
.clang-formatted: $(clang-format-bin) $(RESIZABLE_BUFFER_HEADER_FILE) $(TEST_FILES)
$(clang-format-bin) -i --style=file $(RESIZABLE_BUFFER_HEADER_FILE) $(TEST_FILES)
touch .clang-formatted
.cpplinted: $(cpplint-bin) $(RESIZABLE_BUFFER_HEADER_FILE) $(TEST_FILES)
$(cpplint-bin) $(RESIZABLE_BUFFER_HEADER_FILE) $(TEST_FILES)
touch .cpplinted
$(TEST_EXE).o: test/* include/*.h
mkdir -p build
$(CC) $(RELEASE_FLAGS) -c test/test.cc -o $@
$(TEST_G_EXE).o: test/* include/*.h
mkdir -p build
$(CC) $(DEBUG_FLAGS) -c test/test.cc -o $@
$(TEST_EXE): $(TEST_EXE).o
$(CC) $(RELEASE_FLAGS) $(TEST_EXE).o -o $(TEST_EXE)
if [ ! -a $(TEST_EXE) ]; then \
echo "test executable not found"; \
exit 1; \
fi
$(TEST_G_EXE): $(TEST_G_EXE).o
$(CC) $(DEBUG_FLAGS) $(TEST_G_EXE).o -o $(TEST_G_EXE)
if [ ! -a $(TEST_G_EXE) ]; then \
echo "test executable not found"; \
exit 1; \
fi
.PHONY: coverage
coverage:
$(make) test TEST_COV=1
lcov --capture \
--directory $(CURDIR) \
--base-directory $(CURDIR) \
--include $(CURDIR)/include/resizable_buffer.h \
--output-file $(CURDIR)/coverage.info
genhtml $(CURDIR)/coverage.info --output-directory $(CURDIR)/coverage
rm -f $(CURDIR)/coverage.info