forked from google/libnop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
140 lines (103 loc) · 2.79 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
what_to_build:: all
-include local.mk
TOOLCHAIN ?=
HOST_OS := $(shell uname -s)
WITH_COVERAGE ?= false
# Location of gtest in case it's not installed in a default path for the compiler.
GTEST_INSTALL ?= /opt/local
GTEST_LIB ?= $(GTEST_INSTALL)/lib
GTEST_INCLUDE ?= $(GTEST_INSTALL)/include
HOST_CFLAGS := -g -O2 -Wall -Werror -Wextra -Iinclude
HOST_CXXFLAGS := -std=c++14
HOST_LDFLAGS :=
ifeq ($(HOST_OS),Linux)
HOST_LDFLAGS := -lpthread
endif
OUT := out
OUT_HOST_OBJ := $(OUT)/host-obj
ALL :=
DEPS :=
# Determine whether the compiler can find gtest.
HAS_GTEST := $(shell \
echo "\#include <gtest/gtest.h>" \
| $(CXX) -I$(GTEST_INCLUDE) -x c++ -E - > /dev/null 2>&1 \
&& echo yes)
# Print warning if gtest is not found.
ifneq ("$(HAS_GTEST)","yes")
$(warning libgtest not found in default compiler paths.)
$(warning To build tests either install libgtest in a default location)
$(warning or specify with the environment variable GTEST_INSTALL.)
else
# Build tests if gtest is found.
M_NAME := test
M_CFLAGS := -I$(GTEST_INCLUDE) -O0 -g
M_LDFLAGS := -L$(GTEST_LIB) -lgtest -lgmock
M_OBJS := \
test/nop_tests.o \
test/encoding_tests.o \
test/serializer_tests.o \
test/utility_tests.o \
test/variant_tests.o \
test/handle_tests.o \
test/thread_local_tests.o \
test/enum_flags_tests.o \
test/sip_hash_tests.o \
test/interface_tests.o \
test/fungible_tests.o \
test/optional_tests.o \
test/result_tests.o \
test/endian_tests.o \
test/constexpr_tests.o \
ifeq ($(WITH_COVERAGE),true)
M_CFLAGS += --coverage
endif
include build/host-executable.mk
ifeq ($(WITH_COVERAGE),true)
# Generate coverage report with lcov and genhtml. A bit hacky but works okay.
$(OUT)/coverage.info: $(OUT)/test
$(QUIET)find $(OUT) -name "*.gcda" -exec rm {} \+
$(QUIET)$(OUT)/test
lcov --capture --directory $(OUT_HOST_OBJ)/test/test/ --output-file $@ --no-external --base-directory .
mkdir -p $(OUT)/coverage
genhtml -o $(OUT)/coverage $@
coverage:: $(OUT)/coverage.info
endif
endif
# Build examples.
M_NAME := stream_example
M_OBJS := \
examples/stream.o
include build/host-executable.mk
M_NAME := simple_protocol_example
M_OBJS := \
examples/simple_protocol.o
include build/host-executable.mk
M_NAME := interface_example
M_OBJS := \
examples/interface.o
include build/host-executable.mk
M_NAME := pipe_example
M_OBJS := \
examples/pipe.o
include build/host-executable.mk
M_NAME := table_example
M_OBJS := \
examples/table.o
include build/host-executable.mk
M_NAME := variant_example
M_OBJS := \
examples/variant.o
include build/host-executable.mk
M_NAME := shared_protocol.so
M_CFLAGS := -fPIC
M_LDFLAGS := --shared
M_OBJS := \
examples/shared.o
include build/host-executable.mk
clean::
@echo clean
@rm -rf $(OUT)
all:: $(ALL)
# we generate .d as a side-effect of compiling. override generic rule:
%.d:
-include $(DEPS)