-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (56 loc) · 2.2 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
EXE_FILE:=patexp
SRC_FILES:= Expander.o Helpers.o
MAIN_FILE:= main.o
TEST_FILES:= TestExpander.o TestHelpers.o
# Build directories - allows for separate release and debug executables
DEBUG_DIR = build/debug
RELEASE_DIR = build/release
TEST_DIR = build/test
DEBUG_OBJS = $(addprefix $(DEBUG_DIR)/, $(SRC_FILES))
DEBUG_MAIN_OBJ = $(addprefix $(DEBUG_DIR)/, $(MAIN_FILE))
RELEASE_OBJS = $(addprefix $(RELEASE_DIR)/, $(SRC_FILES) $(MAIN_FILE) )
TEST_OBJS = $(addprefix $(TEST_DIR)/, $(TEST_FILES))
CXXFLAGS += -c -Wall -Wextra -Isrc/
.PHONY: .default clean release install debug test coverage report
.default: release
$(RELEASE_DIR)/%.o: src/%.cpp
@mkdir -p $(@D)
g++ $(CXXFLAGS) -o $@ $<
$(DEBUG_DIR)/%.o: src/%.cpp
@mkdir -p $(@D)
g++ $(CXXFLAGS) -o $@ $<
$(TEST_DIR)/%.o: test/%.cpp
@mkdir -p $(@D)
g++ $(CXXFLAGS) -o $@ $<
# Builds the release executable
release: CXXFLAGS += -O3
release: $(RELEASE_OBJS)
-mkdir bin
g++ $(RELEASE_OBJS) -o bin/$(EXE_FILE)
clean:
@find . -name "*.o" -delete
@rm bin/* coverage/* report/* 2> /dev/null || true
@rm -rf bin/ build/
@find . -name "*.gcno" -delete
@find . -name "*.gcda" -delete
@find . -name "*.gcov" -delete
# Builds with debug data and coverage enabled
debug: CXXFLAGS += -DDEBUG -g -O0 -fPIC -fprofile-arcs -ftest-coverage
debug: $(DEBUG_OBJS) $(DEBUG_MAIN_OBJ)
-@mkdir bin
g++ $(DEBUG_OBJS) $(DEBUG_MAIN_OBJ) -Lgcov -fPIC -fprofile-arcs -ftest-coverage -o bin/$(EXE_FILE)d
# Builds the test using the debug objects - debug data is useful when debugging failing unit tests
test: CXXFLAGS += -DDEBUG -g -fPIC -fprofile-arcs -ftest-coverage
test: $(DEBUG_OBJS) $(TEST_OBJS)
-mkdir bin
g++ $(DEBUG_OBJS) $(TEST_OBJS) -lgtest -Lgoogletest/build/lib -Lgcov -fPIC -fprofile-arcs -ftest-coverage -o bin/unittests
bin/unittests
coverage: test ## Run code coverage
@gcov -r -v src/Expander.cpp src/main.cpp test/TestExpander.cpp -o $(DEBUG_DIR) -o $(TEST_DIR)
report: coverage ## Generate gcovr report
@mkdir gcovr-report 2> /dev/null || true
@gcovr --root . --html --html-details --output gcovr-report/coverage.html
deps: ## Install dependencies
sudo apt-get install build-essential libgtest-dev gcovr
install: build
sudo cp ./bin/$(EXE_FILE) /usr/local/bin/