-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (48 loc) · 2.19 KB
/
Copy pathMakefile
File metadata and controls
66 lines (48 loc) · 2.19 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
# This Makefile uses code from https://gist.github.com/mihaitodor/bfb8e7ad908489fdf3ceb496573f306a
# Need to use a C++ compiler because GTest is a C++ library
# g++ can compile C code just fine, although there are some minor behavior differences compared to gcc (mostly good differences)
CXX := g++
GTEST_DIR := googletest/googletest
# Pre-processor flags
CPPFLAGS := -isystem $(GTEST_DIR)/include
# Flags passed to C++ compiler
CXXFLAGS := -g -Wall -Werror -pthread
# All test executables produced by this Makefile
# If necessary, add new executables you create to the list
TESTS := tests
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers
GTEST_HEADERS := $(GTEST_DIR)/include/gtest/*.h \
$(GTEST_DIR)/include/gtest/internal/*.h
GTEST_SRCS_ := $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
# https://stackoverflow.com/questions/2145590/what-is-the-purpose-of-phony-in-a-makefile
.PHONY: all test main clean valgrind
all: $(TESTS) main
test: all
./tests
main.o: main.c shell.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c main.c
main: main.o shell.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
shell.o: shell.c shell.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c shell.c
tests.o: tests.cpp $(GTEST_HEADERS) *.h *.hpp
$(CXX) $(CPPFLAGS) -DTEST_MODE $(CXXFLAGS) -c tests.cpp
tests: tests.o shell.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
valgrind: $(TESTS)
valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=definite --errors-for-leak-kinds=definite ./tests >/dev/null
# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized. This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
gtest-all.o: $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest-all.cc
gtest_main.o: $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest_main.cc
gtest.a: gtest-all.o
ar rcs $@ $^
gtest_main.a: gtest-all.o gtest_main.o
ar rcs $@ $^
clean:
rm -f $(TESTS) gtest.a gtest_main.a *.o *.out main test_detail.json