-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
74 lines (56 loc) · 1.8 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
MKDIR := mkdir
RMDIR := rm -r -f
CC := gcc
CXX := g++
BIN := ./bin
OBJ := ./obj
INCLUDE := ./include
SRC := ./src
TEST := ./test
REPORT := ./report
REPORT_HTML := ./report/html
SRCS := $(wildcard $(SRC)/*.c)
OBJS := $(patsubst $(SRC)/%.c,$(OBJ)/%.o,$(SRCS))
CAFFLIBNAME := caffparser
CAFFLIB := $(BIN)/lib$(CAFFLIBNAME).so
TEST_SRC := $(TEST)/test.cpp
TEST_EXE := $(BIN)/test
COV_CFLAGS := -fprofile-arcs -ftest-coverage
COV_LDLIBS := -lgcov
CFLAGS := -Wall -W -pedantic -fPIC -fstack-protector-all
TEST_CFLAGS := -Wall -W -pedantic
LDFLAGS :=
TEST_LDFLAGS:=
LDLIBS :=
TEST_TARGETS = all ciff
define make-test-target
test-$1: $$(TEST_EXE) | $$(REPORT)
$$(TEST_EXE) $1
endef
define make-coverage-target
coverage-$1: CFLAGS += $$(COV_CFLAGS)
coverage-$1: LDLIBS += $$(COV_LDLIBS)
coverage-$1: test-$1 | $$(REPORT_HTML)
lcov --capture --directory $$(OBJ) --output-file $$(REPORT)/coverage.info && \
genhtml $$(REPORT)/coverage.info --output-directory $$(REPORT_HTML)
endef
define echo-target
echo-$1:
@echo $1
endef
.PHONY: all $(addprefix test-, $(TEST_TARGETS)) $(addprefix coverage-, $(TEST_TARGETS)) clean
all: $(CAFFLIB) $(TEST_EXE)
$(CAFFLIB): $(OBJS) | $(BIN)
$(CC) $(LDFLAGS) -shared -Wl,-soname,lib$(CAFFLIBNAME).so $^ -o $@ $(LDLIBS)
$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)
$(CC) $(CFLAGS) -I$(INCLUDE) -c $< -o $@
$(BIN) $(OBJ) $(REPORT) $(REPORT_HTML):
$(MKDIR) $@
$(TEST_EXE): $(TEST_SRC) | $(CAFFLIB)
$(CXX) $(TEST_LDFLAGS) $(TEST_CFLAGS) -I$(INCLUDE) $< -o $@ $(LDLIBS) -lcppunit -Wl,-rpath,'$$ORIGIN' -L$(BIN) -l$(CAFFLIBNAME)
$(foreach element, $(TEST_TARGETS), $(eval $(call make-test-target,$(element))))
$(foreach element, $(TEST_TARGETS), $(eval $(call make-coverage-target,$(element))))
test-all:
coverage-all:
clean:
$(RMDIR) $(OBJ)/ $(BIN)/ $(REPORT)/