-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
147 lines (107 loc) · 4.38 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
CC = g++
RM = rm -rf
# Currently code coverage build invoked by make command line
# GCOV = 1
DBG_ENABLE = 1
SRC_PATH := .
TEST_DIR := ./test
# Targeted products
TARGET_SHRED := shredder
TARGET_UNSHRED := unshredder
ALLTARGETS := $(TARGET_SHRED) $(TARGET_UNSHRED)
# Unit test targeted products
TEST_TARGET_SHRED := $(TEST_DIR)/UT$(TARGET_SHRED)
TEST_TARGET_UNSHRED := $(TEST_DIR)/UT$(TARGET_UNSHRED)
TEST_ALLTARGETS := $(TEST_TARGET_SHRED) $(TEST_TARGET_UNSHRED)
# This object supports two versions with one source file.
# One version is for single thread use (i.e. shredder), which will be generated by default,
# and the other version is for multi-threads use (i.e. unshredder), will be supported here.
MULTI_THREAD_OBJ_NAME = singleton_random
ALLSRCS := $(wildcard $(SRC_PATH)/*.cpp)
ALLOBJS := $(ALLSRCS:.cpp=.o)
ALLOBJS += $(MULTI_THREAD_OBJ_NAME)_multi.o
OBJS_SHRED := common_classes.o singleton_random.o text_shredder.o shred_main.o
OBJS_UNSHRED := common_classes.o singleton_random_multi.o singleton_diction.o column_match_manager.o column_select_manager.o text_unshredder.o thread_controller.o unshred_main.o
# Code to support unit test based on Boost framework
UT_TEST_ALLSRCS := $(wildcard $(TEST_DIR)/*.cpp)
UT_TEST_SRCS_SRHED := $(TEST_TARGET_SHRED).cpp
UT_TEST_SRCS_UNSRHED := $(TEST_TARGET_UNSHRED).cpp
# Objective files to support unit test
UT_TEST_ALLOBJS := $(UT_TEST_ALLSRCS:.cpp=_utest.o)
UT_TEST_OBJS_SHRED := $(UT_TEST_SRCS_SRHED:.cpp=_utest.o)
UT_TEST_OBJS_UNSHRED := $(UT_TEST_SRCS_UNSRHED:.cpp=_utest.o)
# Objective files built by regular code (which is to be tested) for unit test purpose.
TEST_ALLOBJS := $(ALLOBJS:.o=_test.o)
TEST_OBJS_SHRED := $(OBJS_SHRED:.o=_test.o)
TEST_OBJS_UNSHRED := $(OBJS_UNSHRED:.o=_test.o)
INCLUDE_PATH += /usr/include
INCLUDE_PATH += /usr/local/include
LIBRARY_PATH += /usr/lib
LIBRARY_PATH += /usr/local/lib
CFLAGS += -std=gnu++11
DUTFLAG := -DUTFLAG
MULTI_THREAD_FLAG := -DMULTI_THREAD_FLAG
CFLAGS += $(foreach dir, $(INCLUDE_PATH), -I$(dir))
LDFLAGS += $(foreach lib, $(LIBRARY_PATH), -L$(lib))
# For executables using multi-threads
LIBS += pthread
LIBS += boost_regex
LIBFLAGS += $(foreach lib, $(LIBS), -l$(lib))
ifeq (${DBG_ENABLE}, 1)
CFLAGS += -D_DEBUG -O0 -g -DDEBUG=1
endif
# Configure code coverage building
ifeq (${GCOV}, 1)
COV_FILE = coverage.info
GCDA_FILES = $(TEST_ALLOBJS:.o=.gcda)
GCNO_FILES = $(TEST_ALLOBJS:.o=.gcno)
DIR_NAME = $(shell pwd )
WORK_DIR = $(shell basename $(DIR_NAME) )
GCOV_RESULT = ut_coverage
GCOV_CFLAGS += -fprofile-arcs
GCOV_CFLAGS += -ftest-coverage
GCOV_LDFLAGS += -fprofile-arcs
GCOV_LDFLAGS += -ftest-coverage
GCOV_LDFLAGS += -lgcov
endif
.PHONY: bld ut clean
all: bld ut
# Build code coverage
ut_cover: clean ut run_ut collect_cov
# Build targeted products
bld: $(ALLTARGETS)
# Build targeted products for unit test
ut: $(TEST_ALLTARGETS)
$(TARGET_SHRED): $(OBJS_SHRED)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
$(TARGET_UNSHRED): $(OBJS_UNSHRED)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBFLAGS)
$(TEST_TARGET_SHRED): $(TEST_OBJS_SHRED) $(UT_TEST_OBJS_SHRED)
$(CC) $(CFLAGS) $(LDFLAGS) $(GCOV_LDFLAGS) $^ -o $@
$(TEST_TARGET_UNSHRED): $(TEST_OBJS_UNSHRED) $(UT_TEST_OBJS_UNSHRED)
$(CC) $(CFLAGS) $(LDFLAGS) $(GCOV_LDFLAGS) $^ -o $@ $(LIBFLAGS)
%.o:%.cpp
$(CC) $(CFLAGS) -o $@ -c $<
$(MULTI_THREAD_OBJ_NAME)_multi.o: $(MULTI_THREAD_OBJ_NAME).cpp
$(CC) $(CFLAGS) $(MULTI_THREAD_FLAG) -o $@ -c $<
%_test.o:%.cpp
$(CC) $(DUTFLAG) $(CFLAGS) $(GCOV_CFLAGS) -o $@ -c $<
$(MULTI_THREAD_OBJ_NAME)_multi_test.o: $(MULTI_THREAD_OBJ_NAME).cpp
$(CC) $(DUTFLAG) $(CFLAGS) $(MULTI_THREAD_FLAG) $(GCOV_CFLAGS) -o $@ -c $<
%_utest.o:%.cpp
$(CC) $(DUTFLAG) $(CFLAGS) -o $@ -c $<
# Execute unit test
run_ut: ut
$(TEST_TARGET_SHRED) --run_test=SingletonRandom_test --log_level=warning;echo
$(TEST_TARGET_SHRED) --log_level=warning;echo
$(TEST_TARGET_UNSHRED) --run_test=TESTSingleton_test --log_level=warning;echo
$(TEST_TARGET_UNSHRED) --log_level=warning;echo
collect_cov:
lcov --rc lcov_branch_coverage=1 -d . -b . -c -o $(COV_FILE)
lcov --rc lcov_branch_coverage=1 -e $(COV_FILE) "*/$(WORK_DIR)*" -o $(COV_FILE)
genhtml --rc lcov_branch_coverage=1 -o $(GCOV_RESULT) $(COV_FILE)
# Execute acceptance test
acceptance_test: bld
/bin/bash $(TEST_DIR)/acceptance_test.sh
clean:
$(RM) $(ALLOBJS) $(TEST_ALLOBJS) $(UT_TEST_ALLOBJS) $(ALLTARGETS) $(TEST_ALLTARGETS) $(GCDA_FILES) $(GCNO_FILES) $(COV_FILE) $(TEST_DIR)/SToutput