-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (48 loc) · 1.56 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
PROJECT_DIR = $(shell pwd)
CPPCHECKEXE=cppcheck
CPPLINTEXE=cpplint
SIMIANEXE=simian
INCDIRS:=-I src/include
SRCS:=$(shell find src/ -type f -name '*.cpp' ! -path 'src/test/*')
OBJS:=$(addprefix obj/,$(notdir $(SRCS:.cpp=.o)))
EXE=bin/hello_world
TEST_SRCS:=$(shell find test/src/ -type f -name '*.cpp')
TEST_OBJS:=$(addprefix test/obj/,$(notdir $(TEST_SRCS:.cpp=.o)))
TESTS:=$(addprefix test/bin/,$(notdir $(TEST_SRCS:_unittest.cpp=.test)))
CXXFLAGS:=-Wall -Wextra -pedantic -Werror -Weffc++ --std=c++11
CXXFLAGS+=$(INCDIRS)
CPPLINT_FILTER:=--filter=-legal/copyright,-readability/streams
ifeq ($(SANITIZE), thread)
CXXFLAGS += -fPIC -fPIE -fsanitize=thread
LDFLAGS += -fsanitize=thread -fPIE LDLIBS += -pie
else
ifeq ($(SANITIZE), address)
CXXFLAGS += -fsanitize=address
LDFLAGS += -fsanitize=address
endif
endif
all: $(EXE)
debug: CXXFLAGS += -g
debug: CXXFLAGS += -fsanitize=undefined
debug: LDFLAGS += -fsanitize=undefined
debug: $(EXE)
$(EXE): $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
obj/%.o: src/%.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
gtest: LDLIBS += -lgtest -lgtest_main
gtest: $(TESTS)
test/bin/%.test: obj/%.o test/obj/%_unittest.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test/obj/%.o: test/src/%.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) obj/*.o test/obj/* test/bin/* $(EXE)
cppcheck:
$(CPPCHECKEXE) $(INCDIRS) --enable=all --force src/
$(CPPCHECKEXE) $(INCDIRS) --enable=all --force test/src/
cpplint:
$(CPPLINTEXE) $(CPPLINT_FILTER) $(SRCS)
$(CPPLINTEXE) $(CPPLINT_FILTER) $(TEST_SRCS)
simian:
$(SIMIANEXE) **/*.cpp **/*.hpp