-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (140 loc) · 4.85 KB
/
Makefile
File metadata and controls
166 lines (140 loc) · 4.85 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
MAKEFLAGS += -j10
CC = c++
CFLAGS = -Werror -Wextra -Wall -std=c++98 -Iinclude -MMD -MP -Wfatal-errors $(EXTRA_CFLAGS)
COVERAGE_FLAGS = --coverage
TESTER_STD_FLAG = -DSTD
TESTER_BAD_FLAG = -DBAD
VALGRIND_FLAGS = --leak-check=full \
--error-exitcode=1 \
--log-file=$(VALGRIND_LOG)
BUILD_DIR = target
COVERAGE_DIR = $(BUILD_DIR)/coverage
INCLUDE_DIR = include
TESTER_DIR = tests/stamim_tester
DEP = $(patsubst %.cpp,$(BUILD_DIR)/%.d,$(SRC)) \
$(patsubst %.cpp,$(BUILD_DIR)/%.std.d,$(SRC)) \
$(patsubst %.cpp,$(BUILD_DIR)/%.bad.d,$(SRC_BAD))
OBJ = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRC))
OBJ_STD = $(patsubst %.cpp,$(BUILD_DIR)/%.std.o,$(SRC))
OBJ_BAD = $(patsubst %.cpp,$(BUILD_DIR)/%.bad.o,$(SRC_BAD))
SRC = $(TESTER_DIR)/main.cpp \
$(TESTER_DIR)/vector/constructor.cpp \
$(TESTER_DIR)/vector/cplusplus_examples.cpp \
$(TESTER_DIR)/deque/cplusplus_examples.cpp \
$(TESTER_DIR)/deque/main.cpp \
$(TESTER_DIR)/list/cplusplus_examples.cpp
SRC_BAD = $(TESTER_DIR)/vector/constructor.cpp
GCDA_FILES = $(patsubst %.cpp,$(BUILD_DIR)/%.gcda,$(SRC))
GCNO_FILES = $(patsubst %.cpp,$(BUILD_DIR)/%.gcno,$(SRC))
LCOV_FILE = $(COVERAGE_DIR)/coverage.info
TEST_LOG_FT = $(BUILD_DIR)/test_ft.txt
TEST_LOG_STD = $(BUILD_DIR)/test_std.txt
VALGRIND_LOG = $(BUILD_DIR)/suppressions.supp
NAME = $(BUILD_DIR)/ft_tester
NAME_STD = $(BUILD_DIR)/std_tester
PHC = $(INCLUDE_DIR)/_phc.hpp
PHC_GCH = $(BUILD_DIR)/$(INCLUDE_DIR)/_phc.hpp.gch
.PHONY: all \
test \
test-bad \
test-leaks \
cov \
std \
std-test \
lint-staged \
lint \
clean-cov \
clean-dep \
clean-obj \
clean-log \
clean \
fclean \
re
# all: test
all: build
build: $(NAME)
$(NAME): $(OBJ) | $(BUILD_DIR)
@echo "\033[1;34m[Linking] $@\033[0m"
@$(CC) $(CFLAGS) $^ -o $@
$(PHC_GCH): $(PHC) | $(BUILD_DIR)/$(INCLUDE_DIR)
@echo "\033[1;33m[Building] PHC Header File\033[0m"
@$(CC) $(CFLAGS) -x c++-header $< -o $@
$(BUILD_DIR)/%.o: %.cpp $(PHC_GCH) | $(BUILD_DIR)
@mkdir -p $(dir $@)
@echo "\033[1;33m[Building] $@\033[0m"
@$(CC) $(CFLAGS) -include $(PHC) -c $< -o $@
test-bad: $(OBJ_BAD)
@echo "\033[1;32m[Testing] OK. Bad files did not compile as expected.\033[0m"
$(BUILD_DIR)/%.bad.o: %.cpp | $(BUILD_DIR)
@mkdir -p $(dir $@)
@if $(CC) $(CFLAGS) $(TESTER_BAD_FLAG) -c $< -o $@ 2>/dev/null; \
then \
echo "\033[1;31m$< should not compile after defining BAD macro\033[0m" && \
exit 1; \
fi
test: test-bad build std-test
@$(NAME) > $(TEST_LOG_FT)
@echo "\033[1;32m[Testing] Test logs can be found $(TEST_LOG_FT)\033[0m"
@diff -c $(TEST_LOG_FT) $(TEST_LOG_STD)
@echo "\033[1;32m[Testing] Passed All Tests.\033[0m"
test-leaks: CFLAGS+=-g
test-leaks: build
valgrind $(VALGRIND_FLAGS) $(NAME)
cov: CFLAGS+=$(COVERAGE_FLAGS)
cov: build
@echo "\033[1;34m[Coverage] Generating coverage report...\033[0m"
@$(NAME)
@echo "\033[1;32m[Coverage] Coverage report generated.\033[0m"
@mkdir -p $(COVERAGE_DIR)
@echo "\033[1;34m[Coverage] Generating .gcov files...\033[0m"
@gcov -r $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRC)) > /dev/null
@echo "\033[1;32m[Coverage] .gcov files generated.\033[0m"
@mv *.gcov $(COVERAGE_DIR)
@echo "\033[1;34m[Coverage] Generating lcov report...\033[0m"
@lcov --capture --directory . --output-file $(LCOV_FILE) 2>/dev/null
@lcov --remove $(LCOV_FILE) "/usr/*" --output-file $(COVERAGE_DIR)/filtered.info
@genhtml $(COVERAGE_DIR)/filtered.info --output-directory $(COVERAGE_DIR)/html --title "Coverage Report"
@echo "\033[1;32m[Coverage] Include-only coverage report: $(COVERAGE_DIR)/html/index.html\033[0m"
std: CFLAGS+=$(TESTER_STD_FLAG)
std: $(NAME_STD)
std-test: std
@$(NAME_STD) > $(TEST_LOG_STD)
@echo "\033[1;32m[Testing] Test logs can be found $(TEST_LOG_STD)\033[0m"
$(NAME_STD): $(OBJ_STD) | $(BUILD_DIR)
@echo "\033[1;34m[Linking] $@\033[0m"
@$(CC) $(CFLAGS) $^ -o $@
$(BUILD_DIR)/%.std.o: %.cpp | $(BUILD_DIR)
@mkdir -p $(dir $@)
@echo "\033[1;33m[Building] $@\033[0m"
@$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/$(INCLUDE_DIR):
@mkdir -p $(BUILD_DIR)/$(INCLUDE_DIR)
lint-staged:
@git diff --cached --name-only | \
grep -E '\.(cpp|hpp|tpp)$$' | \
xargs -i sh -c 'clang-format -i --verbose {} && git add {}'
lint:
@clang-format -i --verbose \
$(shell find $(INCLUDE_DIR) $(TESTER_DIR) -name "*.tpp" \
-o -name "*.hpp" -o -name "*.cpp")
clean-cov:
@echo "[Cleaning] Coverage Files."
@rm -rf $(GCNO_FILES) $(GCDA_FILES) $(LCOV_FILE) $(COVERAGE_DIR)
clean-dep:
@echo "[Cleaning] Dependency Files."
@rm -f $(DEP)
clean-obj:
@echo "[Cleaning] Object Files."
@rm -f $(OBJ) $(OBJ_STD) $(OBJ_BAD) $(PHC_GCH)
clean-log:
@echo "[Cleaning] Log Files."
@rm -f $(VALGRIND_LOG) $(TEST_LOG_STD) $(TEST_LOG_FT)
clean: clean-obj clean-dep clean-log clean-cov
fclean: clean
@echo "[Cleaning] Program Files."
@rm -f $(NAME) $(NAME_STD)
@rm -rf $(BUILD_DIR)
re: fclean build
-include $(DEP)