forked from mapbox/protozero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
144 lines (110 loc) · 5.42 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
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
# first inherit from env
CXX := $(CXX)
CXXFLAGS := $(CXXFLAGS)
LDFLAGS := $(LDFLAGS)
# Installation directory
DESTDIR ?= /usr
WARNING_FLAGS := -Wall -Wextra -pedantic -Wsign-compare -Wsign-conversion -Wunused-parameter -Wno-float-equal -Wno-covered-switch-default -Wshadow
ifneq ($(findstring clang,$(CXX)),)
WARNING_FLAGS += -Wno-reserved-id-macro -Weverything -Wno-weak-vtables -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-exit-time-destructors -Wno-switch-enum -Wno-padded -Wno-documentation-unknown-command
endif
COMMON_FLAGS := -fvisibility-inlines-hidden -std=c++11 $(WARNING_FLAGS)
RELEASE_FLAGS := -O3 -DNDEBUG -march=native
DEBUG_FLAGS := -O0 -g -fno-inline-functions
PTHREAD_FLAGS =
CLANG_TIDY := clang-tidy-3.8
OS:=$(shell uname -s)
ifeq ($(OS),Linux)
PTHREAD_FLAGS = -pthread
endif
ifeq ($(OS),Darwin)
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif
TEST_CASES := $(wildcard test/t/*/test_cases.cpp)
TEST_CASES_O := $(subst .cpp,.o,$(TEST_CASES))
WRITER_TEST_CASES := $(wildcard test/t/*/writer_test_cases.cpp)
WRITER_TEST_CASES_O := $(subst .cpp,.o,$(WRITER_TEST_CASES))
PROTO_FILES := $(subst writer_test_cases.cpp,testcase.proto,$(WRITER_TEST_CASES))
PROTO_FILES_CC := $(subst .proto,.pb.cc,$(PROTO_FILES))
PROTO_FILES_H := $(subst .proto,.pb.h,$(PROTO_FILES))
PROTO_FILES_O := $(subst .proto,.pb.o,$(PROTO_FILES))
HPP_FILES := include/protozero/byteswap.hpp \
include/protozero/config.hpp \
include/protozero/exception.hpp \
include/protozero/iterators.hpp \
include/protozero/pbf_builder.hpp \
include/protozero/pbf_message.hpp \
include/protozero/pbf_reader.hpp \
include/protozero/pbf_writer.hpp \
include/protozero/types.hpp \
include/protozero/varint.hpp \
include/protozero/version.hpp
DOC_FILES = doc/advanced.md doc/cheatsheet.md doc/tutorial.md
CFLAGS_PROTOBUF := $(subst -I,-isystem ,$(shell pkg-config protobuf --cflags))
LDFLAGS_PROTOBUF := $(shell pkg-config protobuf --libs-only-L)
all: ./test/tests test/writer_tests
./test/t/%/test_cases.o: test/t/%/test_cases.cpp test/include/test.hpp test/include/scalar_access.hpp test/include/packed_access.hpp $(HPP_FILES)
$(CXX) -c -Iinclude -Itest/include $(CXXFLAGS) $(COMMON_FLAGS) $(DEBUG_FLAGS) $< -o $@
./test/tests.o: test/tests.cpp $(HPP_FILES)
$(CXX) -c -Iinclude -Itest/include $(CXXFLAGS) $(COMMON_FLAGS) $(DEBUG_FLAGS) $< -o $@
./test/tests: test/tests.o $(TEST_CASES_O)
$(CXX) $(LDFLAGS) $^ -o $@
./test/t/%/testcase.pb.cc: ./test/t/%/testcase.proto
protoc --cpp_out=. $^
./test/t/%/testcase.pb.o: ./test/t/%/testcase.pb.cc
$(CXX) -c -I. -Iinclude -Itest/include $(CXXFLAGS) $(CFLAGS_PROTOBUF) -std=c++11 $(DEBUG_FLAGS) $< -o $@
./test/t/%/writer_test_cases.o: ./test/t/%/writer_test_cases.cpp $(HPP_FILES)
$(CXX) -c -I. -Iinclude -Itest/include $(CXXFLAGS) $(CFLAGS_PROTOBUF) $(COMMON_FLAGS) $(DEBUG_FLAGS) $< -o $@
./test/writer_tests.o: test/writer_tests.cpp $(HPP_FILES) $(PROTO_FILES_CC)
$(CXX) -c -I. -Iinclude -Itest/include $(CXXFLAGS) $(COMMON_FLAGS) $(DEBUG_FLAGS) $< -o $@
./test/writer_tests: test/writer_tests.o $(PROTO_FILES_O) $(WRITER_TEST_CASES_O)
$(CXX) $(LDFLAGS) $(LDFLAGS_PROTOBUF) $^ -lprotobuf-lite $(PTHREAD_FLAGS) -o $@
test: all
./test/tests
./test/writer_tests
iwyu: $(HPP_FILES) test/tests.cpp test/writer_tests.cpp
iwyu -Xiwyu -- -std=c++11 -Iinclude include/protozero/exception.hpp || true
iwyu -Xiwyu -- -std=c++11 -Iinclude include/protozero/types.hpp || true
iwyu -Xiwyu -- -std=c++11 -Iinclude include/protozero/varint.hpp || true
iwyu -Xiwyu -- -std=c++11 -Iinclude include/protozero/pbf_reader.hpp || true
iwyu -Xiwyu -- -std=c++11 -Iinclude include/protozero/pbf_writer.hpp || true
iwyu -Xiwyu -- -std=c++11 -Iinclude -Itest/include test/tests.cpp || true
iwyu -Xiwyu -- -std=c++11 -Iinclude -Itest/include test/writer_tests.cpp || true
check: $(HPP_FILES) test/tests.cpp test/include/test.hpp test/include/testcase.hpp test/t/*/testcase.cpp $(TEST_CASES)
cppcheck -Uassert --std=c++11 --enable=all --suppress=incorrectStringBooleanError $^
doc: doc/Doxyfile README.md UPGRADING.md $(DOC_FILES) $(HPP_FILES)
doxygen doc/Doxyfile
clean:
rm -f ./test/tests
rm -f ./test/tests.o
rm -f ./test/tests.gc*
rm -f ./test/writer_tests
rm -f ./test/writer_tests.o
rm -f ./test/writer_tests.gc*
rm -f ./test/t/*/testcase.pb.cc
rm -f ./test/t/*/testcase.pb.h
rm -f ./test/t/*/testcase.pb.o
rm -f ./test/t/*/testcase.pb.gc*
rm -f ./test/t/*/testcase.o
rm -f ./test/t/*/testcase
rm -f ./test/t/*/test_cases.o
rm -f ./test/t/*/test_cases.gc*
rm -f ./test/t/*/writer_test_cases.o
rm -f ./test/t/*/writer_test_cases.gc*
rm -f ./*.gcov
rm -fr doc/doxygen_sqlite3.db doc/html coverage
testpack:
rm -f ./*tgz
npm pack
tar -ztvf *tgz
rm -f ./*tgz
install:
install -m 0755 -o root -g root -d $(DESTDIR)/include/protozero
install -m 0644 -o root -g root include/protozero/* $(DESTDIR)/include/protozero
clang-tidy: clean
bear make -j4 # create compile_commands.json compilation database
# some checks disabled because they are triggered by Catch unit test framework,
# they are too strict, or produce false positives
$(CLANG_TIDY) -header-filter='.*' -checks='*,-cert-err58-cpp,-cert-dcl59-cpp,-google-build-namespaces,-misc-definitions-in-headers,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-clang-analyzer-alpha.*' $(TEST_CASES)
.PHONY: all test iwyu check doc