-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (111 loc) · 4.08 KB
/
Makefile
File metadata and controls
148 lines (111 loc) · 4.08 KB
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
# ==============================
CPPCHECK = cppcheck
# Output Files
# ==============================
CPPCHECK_RESULTS = cppcheck-results.xml
CPPUNIT_RESULTS = cppunit-results.xml
# Compiler Settings
# ==============================
CC = gcc
CC_INCLUDES = -Isrc/common/ -I/usr/local/include/ -I/usr/include/ -Isrc/test/common
CC_FLAGS = -g -Wall --coverage
# Directories
# ==============================
SRC_DIR = src/
OBJ_DIR = obj/
BIN_DIR = bin/
VPATH = $(SRC_DIR)
# All sources and objects
# ==============================
SRCS = $(shell for file in `find src -name *.cpp`; do echo $$file; done)
OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(SRCS:.cpp=.o))
# Objects per directory
# ==============================
PROBLEM_MAIN_SRC = src/mains/problems-main.cpp
UNITTEST_MAIN_SRC = src/mains/cppunit-main.cpp
COMMON_SRCS = $(shell for file in `find src/common -name *.cpp`; do echo $$file; done)
COMMON_HDRS = $(shell for file in `find src/common -name *.h`; do echo $$file; done)
COMMON_OBJS = $(patsubst src/common%,obj/common%,$(COMMON_SRCS:.cpp=.o))
TEST_SRCS = $(shell for file in `find src/test -name *.cpp`; do echo $$file; done)
TEST_HDRS = $(shell for file in `find src/test -name *.h`; do echo $$file; done)
TEST_OBJS = $(patsubst src/test%,obj/test%,$(TEST_SRCS:.cpp=.o))
# Bin specific Objects
# ==============================
PROBLEM_MAIN_OBJS = $(COMMON_OBJS) obj/mains/problems-main.o
UNITTEST_MAIN_OBJS = $(COMMON_OBJS) $(TEST_OBJS) obj/mains/cppunit-main.o
# Targets
# ==============================
.PHONY : new fresh clean vars cppunit cppunit-ci cppcheck-ci coverage ci
new: $(BIN_DIR)problems
fresh: clean new
clean:
@echo "Cleaning $(OBJ_DIR), $(BIN_DIR) and C.I. result files."
@rm -rf $(OBJ_DIR)
@rm -rf $(BIN_DIR)
@rm -rf coverage/
@rm -f $(CPPUNIT_RESULTS)
@rm -f $(CPPCHECK_RESULTS)
@rm -f coverage.info
vars:
@echo "SRCS:"
@echo " $(SRCS)"
@echo "OBJS:"
@echo " $(OBJS)"
@echo "COMMON_OBJS:"
@echo " $(COMMON_OBJS)"
@echo "TEST_OBJS:"
@echo " $(TEST_OBJS)"
@echo "PROBLEM_MAIN_OBJS:"
@echo " $(PROBLEM_MAIN_OBJS)"
@echo "UNITTEST_MAIN_OBJS:"
@echo " $(UNITTEST_MAIN_OBJS)"
cppunit: $(BIN_DIR)cppunit
ifdef TEST_SUITE
@echo "Running $(TEST_SUITE) test suite"
./$(BIN_DIR)cppunit --suite $(TEST_SUITE)
else
@echo "Running all test suites"
./$(BIN_DIR)cppunit
endif
cppunit-ci: $(BIN_DIR)cppunit
@echo "Running unit tests."
@$(BIN_DIR)cppunit --xml
cppcheck:
@echo "Running cppcheck on sources and headers."
@$(CPPCHECK) --quiet --enable=all --suppress=missingInclude -Isrc/common/ $(PROBLEM_MAIN_SRC) $(COMMON_SRCS) $(COMMON_HDRS)
cppcheck-ci:
@echo "Running cppcheck on sources and headers."
@rm -f $(CPPCHECK_RESULTS)
@$(CPPCHECK) --quiet --enable=all --xml --suppress=missingInclude -Isrc/common/ $(PROBLEM_MAIN_SRC) $(COMMON_SRCS) $(COMMON_HDRS) 2> $(CPPCHECK_RESULTS)
coverage:
@lcov --capture --no-external --directory obj/common -base-directory . --output-file coverage.info
@genhtml coverage.info --output-directory coverage
ci: fresh cppunit-ci cppcheck-ci coverage
# Linking
# ==============================
$(BIN_DIR)problems: $(PROBLEM_MAIN_OBJS)
@echo "Linking PROBLEM_MAIN_OBJS into $@"
@mkdir -p $(BIN_DIR)
@$(CC) $(CC_FLAGS) -lstdc++ $(PROBLEM_MAIN_OBJS) -o $@
$(BIN_DIR)cppunit: $(UNITTEST_MAIN_OBJS)
@echo "Linking UNITTEST_MAIN_OBJS into $@"
@mkdir -p $(BIN_DIR)
@$(CC) $(CC_FLAGS) -lstdc++ $(UNITTEST_MAIN_OBJS) -lcppunit -o $@
# Compiling Mains
# ==============================
# Compiling mains separately as there is no header file for main files.
$(OBJ_DIR)mains/problems-main.o: $(SRC_DIR)mains/problems-main.cpp
@echo "Compling $< into $@"
@mkdir -p $(dir $@)
@$(CC) -c $(CC_FLAGS) $(CC_INCLUDES) -c $< -o $@
$(OBJ_DIR)mains/cppunit-main.o: $(SRC_DIR)mains/cppunit-main.cpp
@echo "Compling $< into $@"
@mkdir -p $(dir $@)
@$(CC) -c $(CC_FLAGS) $(CC_INCLUDES) -c $< -o $@
# Compiling Standard Classes
# ==============================
# Compiling section, using VPATH = $(SRC_DIR) to allow different obj and src dirs.
$(OBJ_DIR)%.o: %.cpp %.h
@echo "Compling $< into $@"
@mkdir -p $(dir $@)
@$(CC) -c $(CC_FLAGS) $(CC_INCLUDES) -c $< -o $@