-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
206 lines (178 loc) · 4.75 KB
/
Makefile
File metadata and controls
206 lines (178 loc) · 4.75 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Copyright (c) 2020 by Terry Greeniaus. All rights reserved.
# List of target binaries to build.
# Each target, T, should provide the following fields in their module.mk file:
# T.REQ_DEFS - list of required linker variables
# T.LIB - list of .a dependencies
# T.OBJ - list of .o dependencies
# T.LD - linker file to use
TARGETS := \
tsdbcli2 \
tsdbclienttest \
tsdbreflector \
tsdbserver \
tsdbtest
# Build options.
OPT_LEVEL := -O2
# Where to install binaries.
INSTALL_DIR := /usr/local/bin
INSTALL_BINS := \
tsdbcli2 \
tsdbreflector \
tsdbserver
# Standard directories.
SRC_DIR := src
BIN_DIR := bin
BUILD_DIR := build
THIRD_PARTY := third_party
# Root modules.
MODULES := $(sort $(wildcard $(SRC_DIR)/*))
MODULES := $(MODULES:$(SRC_DIR)/%=%)
# Directories to delete when cleaning.
CLEAN_DIRS := $(BIN_DIR) $(BUILD_DIR)
# Build directories.
BUILD_O_DIR := $(BUILD_DIR)/obj
BUILD_TO_DIR := $(BUILD_DIR)/objt
BUILD_ITO_DIR := $(BUILD_DIR)/objit
LIB_DIR := $(BUILD_DIR)/lib
INCLUDE_DIR := $(BUILD_DIR)/include
TESTS_DIR := $(BUILD_DIR)/unittests
ITESTS_DIR := $(BUILD_DIR)/integration_tests
# Architecture flags.
ARCH_FLAGS :=
# Target C++ flags.
COMMON_CXXFLAGS := \
$(OPT_LEVEL) \
-std=gnu++20 \
-ggdb \
-gstrict-dwarf \
-fno-math-errno \
-freciprocal-math \
-fno-signed-zeros \
-Wall \
-Werror \
-Wundef \
-Wno-invalid-offsetof \
-Wno-c99-designator \
-fno-use-cxa-atexit \
-ffunction-sections \
-fdata-sections \
-D_GNU_SOURCE \
-I$(SRC_DIR) \
-I$(INCLUDE_DIR) \
-I$(THIRD_PARTY)
COMMON_LDFLAGS :=
# Unittest C++ flags.
TEST_CXXFLAGS := \
$(OPT_LEVEL) \
-std=gnu++20 \
-Wall \
-Werror \
-Wno-invalid-offsetof \
-Wno-multichar \
-ggdb \
-ffunction-sections \
-fdata-sections \
-DUNITTEST \
-I$(SRC_DIR) \
-I$(INCLUDE_DIR) \
-I$(THIRD_PARTY)
TEST_LDFLAGS :=
# Integration test C++ flags.
ITEST_CXXFLAGS := \
$(OPT_LEVEL) \
-std=gnu++20 \
-Wall \
-Werror \
-Wno-invalid-offsetof \
-Wno-multichar \
-ggdb \
-ffunction-sections \
-fdata-sections \
-DINTEGRATION_TEST \
-I$(SRC_DIR) \
-I$(INCLUDE_DIR) \
-I$(THIRD_PARTY)
ITEST_LDFLAGS :=
# OS-specific include directories.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
COMMON_CXXFLAGS += -I$(HOMEBREW_PREFIX)/opt/openssl/include
TEST_CXXFLAGS += -I$(HOMEBREW_PREFIX)/opt/openssl/include
ITEST_CXXFLAGS += -I$(HOMEBREW_PREFIX)/opt/openssl/include
COMMON_LDFLAGS += -Wl,-dead_strip -L$(HOMEBREW_PREFIX)/opt/openssl/lib
TEST_LDFLAGS += -Wl,-dead_strip -L$(HOMEBREW_PREFIX)/opt/openssl/lib
ITEST_LDFLAGS += -Wl,-dead_strip -L$(HOMEBREW_PREFIX)/opt/openssl/lib
else
COMMON_LDFLAGS += -Wl,--gc-sections
TEST_LDFLAGS += -Wl,--gc-sections
ITEST_LDFLAGS += -Wl,--gc-sections
endif
# Flags for archive tool
ARFLAGS = rc
# Target build tools.
GCC_PREFIX := /usr/bin/
GCC_CC := $(GCC_PREFIX)gcc
GCC_CXX := $(GCC_PREFIX)g++
GCC_STRIP := $(GCC_PREFIX)strip
GCC_AS := $(GCC_PREFIX)as
GCC_LD := $(GCC_PREFIX)ld
GCC_AR := $(GCC_PREFIX)ar
# Native build tools for unittests and integration tests.
TEST_CXX := /usr/bin/g++
ITEST_CXX := /usr/bin/g++
# Test directories and expected outputs.
TEST_RES_DIR := $(TESTS_DIR)/.results
ALL_TESTS :=
ITEST_RES_DIR := $(ITESTS_DIR)/.results
ALL_ITESTS :=
# Create the GIT commit version header.
$(shell scripts/make_version.sh $(INCLUDE_DIR))
# Rule to build everything.
.PHONY: all
all: $(TARGETS:%=$(BIN_DIR)/%) test itest
@:
# Rule to clean everything.
.PHONY: clean
clean:
@rm -rf $(CLEAN_DIRS)
@find . -name "*.pyc" | xargs rm 2>/dev/null || true
# Rule to build everything and install binaries.
.PHONY: install
install: all
sudo cp $(INSTALL_BINS:%=$(BIN_DIR)/%) $(INSTALL_DIR)/
# Rule to build an object file from a %.cc file.
# We can't use $^ for the list of source files because that will also pull in
# all the other header dependencies generated by the .d files.
$(BUILD_O_DIR)/%.o: $(SRC_DIR)/%.cc Makefile | version headers
@echo Compiling object $(SRC_DIR)/$*.cc...
@mkdir -p $(dir $@)
@$(GCC_CXX) \
-MMD \
-MP \
-MF $(BUILD_O_DIR)/$*.d \
-c \
$(COMMON_CXXFLAGS) \
$(SRC_DIR)/$*.cc \
-o $@
ifneq ($(MAKECMDGOALS),clean)
# Defines for building libraries.
-include scripts/libs.mk
# Rules for third-party code.
-include scripts/third_party.mk
# Pull in all of the defined modules.
-include scripts/modules.mk
$(call include_modules,$(MODULES),)
# Rules for making unittests using tmock.
-include scripts/test_defs.mk
$(call define_all_tests)
-include scripts/itest_defs.mk
$(call define_all_integration_tests)
# Define a build rule for each target.
-include scripts/targets.mk
$(call define_target_rules,$(TARGETS))
# Rules for making header directory symlinks.
-include scripts/headers.mk
# Rule to execute all tests.
-include scripts/tests.mk
-include scripts/itests.mk
endif