DetectorGraph  2.0
makefile
Go to the documentation of this file.
1 # Copyright 2017 Nest Labs, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 # Configure the compiler.
16 CXX ?= g++
17 CPPSTD ?= -std=c++11
18 # Other options: -std=c++0x -stdlib=libstdc++
19 
20 # Sometimes it's worth trying -nostdinc++ to see what leaked.
21 LITE_CONFIG ?= -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE -fno-exceptions -fno-rtti -Os
22 FULL_CONFIG ?=
23 
24 # Enables std::static_asserts for checking library usage patterns.
25 LITE_CONFIG += -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_STATIC_ASSERTS -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_PERFECT_FORWARDING
26 
27 # Uses own implementation of 64bit % 64bit operator (this is used on TimeoutPublisherService)
28 # LITE_CONFIG += -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_NO_64BIT_REMAINDER
29 
30 # To use the lite version of the library in the examples swap the config below
31 CONFIG ?= $(FULL_CONFIG)
32 # CONFIG=$(LITE_CONFIG)
33 
34 # Enables a bunch of debug logs that help understand Graph and TimeoutPublisherService resource usage.
35 # CONFIG += -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_INSTRUMENT_RESOURCE_USAGE
36 
37 CXXFLAGS ?=-Wall -Werror -Wno-error=deprecated -Werror=sign-compare
38 
39 # The core library will work fine without C++11 but some examples rely on it
40 # CPPSTD=-stdlib=libstdc++
41 
42 # Core Library Include folder and sources
43 CORE_INCLUDE=./include
44 CORE_SRCS=src/graph.cpp \
45  src/detector.cpp \
46  src/timeoutpublisherservice.cpp \
47  $(NULL)
48 
49 # TODO(DGRAPH-10): TimeoutPublisherService on lite.
50 FULL_SRCS=$(CORE_SRCS) \
51  src/statesnapshot.cpp \
52  src/graphstatestore.cpp \
53  $(NULL)
54 
55 
56 # Platform-specific headers and implementations
57 PLATFORM=./platform_standalone
58 PLATFORM_SRCS=$(PLATFORM)/dglogging.cpp
59 
60 # Graph Analysis and Tools
61 UTIL=./util
62 UTIL_SRCS=$(UTIL)/graphanalyzer.cpp \
63  $(UTIL)/nodenameutils.cpp \
64  $(NULL)
65 
66 # Test Utilities
67 TEST_UTIL=./test-util
68 TEST_UTIL_SRCS=$(TEST_UTIL)/testtimeoutpublisherservice.cpp \
69  $(TEST_UTIL)/graphtestutils.cpp \
70  $(NULL)
71 
72 # Unit Test Framework
73 NLUNITTEST=./third_party/nltest/repo/src/
74 NLUNITTEST_SRCS=$(NLUNITTEST)/nltest.c
75 
76 COMMON_TESTS=./unit-test/common
77 FULL_TESTS=./unit-test/full
78 LITE_TESTS=./unit-test/lite
79 COMMON_TESTS_SRCS=$(wildcard $(COMMON_TESTS)/*.cpp)
80 FULL_TESTS_SRCS=$(wildcard $(FULL_TESTS)/*.cpp)
81 LITE_TESTS_SRCS=$(wildcard $(LITE_TESTS)/*.cpp)
82 
83 .PHONY: docs
84 docs:
85  doxygen ./doxygen/Doxyfile
86 
87 unit-test/test_all: unit-test/test_full unit-test/test_lite
88  @echo Ran unit tests for the Vanilla and Lite configs of the library
89 
90 unit-test/test_full:
91  $(CXX) $(CPPSTD) $(CXXFLAGS) $(FULL_CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) -I$(TEST_UTIL) -I$(NLUNITTEST) -I$(COMMON_TESTS) -I$(FULL_TESTS) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) $(TEST_UTIL_SRCS) $(NLUNITTEST_SRCS) $(COMMON_TESTS_SRCS) $(FULL_TESTS_SRCS) -o test_full.out && ./test_full.out
92 
93 unit-test/test_lite:
94  $(CXX) $(CPPSTD) $(CXXFLAGS) $(LITE_CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(TEST_UTIL) -I$(NLUNITTEST) -I$(COMMON_TESTS) -I$(LITE_TESTS) $(CORE_SRCS) $(PLATFORM_SRCS) $(TEST_UTIL_SRCS) $(NLUNITTEST_SRCS) $(COMMON_TESTS_SRCS) $(LITE_TESTS_SRCS) -o test_lite.out && ./test_lite.out
95 
96 examples/helloworld:
97  # Minimal Include & Sources dependencies
98  $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) $(FULL_SRCS) $(PLATFORM_SRCS) examples/helloworld.cpp -o helloworld.out && ./helloworld.out
99 
100 examples/robotlocalization:
101  # Note that this example depends on the Eigen library. For more info see
102  # https://eigen.tuxfamily.org/dox/GettingStarted.html
103  # If Eigen is not installed in your default include path you may need to
104  # add it (e.g. -I/usr/include/eigen3 ).
105  # Additionally, some versions of Eigen3 throw a bunch of warnings when
106  # compiling so you may need to turn off -Werror in CXXFLAGS at the top of this
107  # file.
108  $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) examples/robotlocalization.cpp -o robotlocalization.out && ./robotlocalization.out
109 
110 examples/beatmachine:
111  # Keeping a separate rule for this example so that we don't run it as it
112  # takes way too long to run it (2mins!)
113  $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) examples/beatmachine.cpp -o beatmachine.out
114 
115 examples/%:
116  # General Purpose Example building rule.
117  $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) $@.cpp -o $(@:examples/%=%.out) && ./$(@:examples/%=%.out)
118 
119 examples/all: $(basename $(wildcard examples/*.cpp))
120  @echo Built and Ran all Examples
121 
122 unit-test/test_coverage: cleancoverage
123  $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) --coverage -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) -I$(TEST_UTIL) -I$(NLUNITTEST) -I$(COMMON_TESTS) -I$(FULL_TESTS) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) $(TEST_UTIL_SRCS) $(NLUNITTEST_SRCS) $(COMMON_TESTS_SRCS) $(FULL_TESTS_SRCS) -o test_coverage && ./test_coverage
124  mkdir -p coverage/
125  lcov --capture --directory . --no-external \
126  -q --output-file coverage/coverage.info
127  lcov --remove coverage/coverage.info "*/third_party/*" \
128  -q --output-file coverage/coverage.info
129  lcov --extract coverage/coverage.info "*/src/*" \
130  --extract coverage/coverage.info "*/include/*" \
131  --extract coverage/coverage.info "*/unit-test/*" \
132  --extract coverage/coverage.info "*/test-util/*" \
133  -q --output-file coverage/coverage.info
134  lcov -l coverage/coverage.info > coverage/coverage.txt
135  genhtml coverage/coverage.info --output-directory coverage/.
136 
137 code_size_benchmark/%:
138  $(CXX) $(CPPSTD) $(CXXFLAGS) -DNDEBUG $(LITE_CONFIG) -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(dir $@) $(CORE_SRCS) $(PLATFORM_SRCS) $@.cpp -o $(@:code_size_benchmark/%/main=%.out) \
139  && ./$(@:code_size_benchmark/%/main=%.out) \
140  && size $(@:code_size_benchmark/%/main=%.out) \
141  && objdump -h $(@:code_size_benchmark/%/main=%.out)
142 
143 code_size_benchmark/all: $(basename $(wildcard code_size_benchmark/*/main.cpp))
144  @echo Built and Ran all Benchmarks
145 
146 all: unit-test/test_all docs examples/all unit-test/test_coverage
147 
148 cleandocs:
149  rm -rf ./docs/html
150 
151 cleancoverage:
152  rm -fr *.gcda *.gcno coverage
153 
154 clean: cleancoverage cleandocs
155  rm -rf *.out* test_all* test_coverage* *.gcda *.gcno *.o coverage