-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
275 lines (221 loc) · 8.21 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
-include conanbuildinfo.mak
PREFIX ?= /usr/local
EXCEPTIONS ?= 1
COVERAGE ?= 0
DEBUG ?= 0
RELDEBUG ?= 0
PIC ?= 0
LTO ?= 1
URING ?= auto
GOOGLE_BENCH_CPPFLAGS = $(addprefix -isystem, $(CONAN_INCLUDE_DIRS_BENCHMARK) $(GOOGLE_BENCH_INCLUDE_DIR))
GOOGLE_BENCH_LDFLAGS = $(addprefix -L, $(CONAN_LIB_DIRS_BENCHMARK) $(GOOGLE_BENCH_LIB_DIR))
CATCH2_CPPFLAGS = $(addprefix -isystem, $(CONAN_INCLUDE_DIRS_CATCH2) $(CATCH2_INCLUDE_DIR))
FMT_CPPFLAGS = $(addprefix -isystem, $(CONAN_INCLUDE_DIRS_FMT) $(FMT_INCLUDE_DIR))
FMT_LDFLAGS = $(addprefix -L, $(CONAN_LIB_DIRS_FMT) $(FMT_LIB_DIR))
LIBURING_CPPFLAGS = $(addprefix -isystem, $(CONAN_INCLUDE_DIRS_LIBURING) $(LIBURING_INCLUDE_DIR))
LIBURING_LDFLAGS = $(addprefix -L, $(CONAN_LIB_DIRS_LIBURING) $(LIBURING_LIB_DIR))
BUILD_DIR := build/$(notdir $(CXX))
# CXXFLAGS may be set by Conan or other tools, so only set debug/optimization
# flags if CXXFLAGS is not set.
ifeq ($(CXXFLAGS),)
DEBUG_CXXFLAGS = -O0 -ggdb
DEBUG_CPPFLAGS = -DXTR_ENABLE_TEST_STATIC_ASSERTIONS
OPT_CXXFLAGS = -O3 -march=native
OPT_CPPFLAGS = -DNDEBUG
endif
CXXFLAGS += \
-std=c++20 -Wall -Wextra -Wconversion -Wshadow -Wcast-qual -Wformat=2 \
-pedantic -pipe -pthread
CPPFLAGS += -MMD -MP -I include $(FMT_CPPFLAGS) $(LIBURING_CPPFLAGS) -DXTR_FUNC=
LDFLAGS += -fuse-ld=gold
LDLIBS += -lxtr
TEST_CPPFLAGS = $(CATCH2_CPPFLAGS)
TEST_LDFLAGS = -L $(BUILD_DIR) $(FMT_LDFLAGS) $(LIBURING_LDFLAGS)
TEST_LDLIBS = -ldl $(addprefix -l, $(CONAN_LIBS_LIBURING))
BENCH_CPPFLAGS = $(GOOGLE_BENCH_CPPFLAGS)
BENCH_LDFLAGS = -L $(BUILD_DIR) $(GOOGLE_BENCH_LDFLAGS) $(FMT_LDFLAGS) $(LIBURING_LDFLAGS)
BENCH_LDLIBS = -lbenchmark $(addprefix -l, $(CONAN_LIBS_LIBURING))
XTRCTL_LDFLAGS = -L $(BUILD_DIR) $(FMT_LDFLAGS)
COVERAGE_CXXFLAGS = --coverage -DNDEBUG
ifeq ($(FMT_CPPFLAGS),)
# Use the libfmt submodule if it is present and no include directory for
# libfmt has been configured (including via Conan).
ifneq ($(wildcard third_party/fmt/include),)
SUBMODULES_FLAG := 1
endif
ifneq (,$(wildcard /usr/lib/x86_64-linux-gnu/liburing.so))
LDLIBS += -luring
endif
endif
ifneq ($(SUBMODULES_FLAG),)
FMT_CPPFLAGS += -DFMT_HEADER_ONLY
CPPFLAGS += -isystem third_party/include
else ifneq ($(CONAN_LIBS_FMT),)
LDLIBS += -l$(CONAN_LIBS_FMT)
else
LDLIBS += -lfmt
endif
ifneq (,$(findstring clang,$(CXX)))
RANLIB ?= llvm-ranlib
AR ?= llvm-ar
else
RANLIB ?= gcc-ranlib
AR ?= gcc-ar
endif
ifeq ($(PIC), 1)
CXXFLAGS += -fPIC
BUILD_DIR := $(BUILD_DIR)-pic
endif
ifeq ($(LTO), 1)
CXXFLAGS += -flto
BUILD_DIR := $(BUILD_DIR)-lto
endif
ifneq ($(URING), auto)
CXXFLAGS += -DXTR_USE_IO_URING=$(URING)
ifeq ($(URING), 1)
ifneq ($(SUBMODULES_FLAG),)
LDLIBS += -luring
else
LDLIBS += $(addprefix -l, $(CONAN_LIBS_LIBURING))
endif
BUILD_DIR := $(BUILD_DIR)-uring
else
BUILD_DIR := $(BUILD_DIR)-no-uring
endif
endif
ifeq ($(COVERAGE), 1)
CXXFLAGS += $(COVERAGE_CXXFLAGS)
BUILD_DIR := $(BUILD_DIR)-coverage
COVERAGE_DATA = \
$(SRCS:%=$(BUILD_DIR)/%.gcno) $(SRCS:%=$(BUILD_DIR)/%.gcda) \
$(TEST_SRCS:%=$(BUILD_DIR)/%.gcno) $(TEST_SRCS:%=$(BUILD_DIR)/%.gcda)
endif
ifeq ($(RELDEBUG), 1)
CXXFLAGS += $(DEBUG_CXXFLAGS) $(OPT_CXXFLAGS)
CPPFLAGS += $(DEBUG_CPPFLAGS) $(OPT_CPPFLAGS)
BUILD_DIR := $(BUILD_DIR)-reldebug
else ifeq ($(DEBUG), 1)
CXXFLAGS += $(DEBUG_CXXFLAGS)
CPPFLAGS += $(DEBUG_CPPFLAGS)
BUILD_DIR := $(BUILD_DIR)-debug
else
CXXFLAGS += $(OPT_CXXFLAGS)
CPPFLAGS += $(OPT_CPPFLAGS)
BUILD_DIR := $(BUILD_DIR)-release
endif
ifneq ($(SANITIZER),)
CXXFLAGS += -fno-omit-frame-pointer -fsanitize=$(SANITIZER) -fno-sanitize-recover=all
LDFLAGS += -fsanitize=$(SANITIZER)
BUILD_DIR := $(BUILD_DIR)-$(SANITIZER)-sanitizer
endif
ifeq ($(EXCEPTIONS), 0)
CXXFLAGS += -fno-exceptions
BUILD_DIR := $(BUILD_DIR)-no-exceptions
endif
TARGET = $(BUILD_DIR)/libxtr.a
SRCS := \
src/command_dispatcher.cpp src/command_path.cpp src/consumer.cpp \
src/buffer.cpp src/fd_storage.cpp src/fd_storage_base.cpp \
src/file_descriptor.cpp src/io_uring_fd_storage.cpp src/logger.cpp \
src/log_level.cpp src/matcher.cpp src/memory_mapping.cpp \
src/mirrored_memory_mapping.cpp src/pagesize.cpp src/posix_fd_storage.cpp \
src/regex_matcher.cpp src/sink.cpp src/throw.cpp \
src/tsc.cpp src/wildcard_matcher.cpp
OBJS = $(SRCS:%=$(BUILD_DIR)/%.o)
TEST_TARGET = $(BUILD_DIR)/test/test
TEST_SRCS := \
test/align.cpp test/command_client.cpp test/command_dispatcher.cpp \
test/fd_storage.cpp test/file_descriptor.cpp test/logger.cpp \
test/main.cpp test/memory_mapping.cpp test/mirrored_memory_mapping.cpp \
test/pagesize.cpp test/synchronized_ring_buffer.cpp test/throw.cpp
TEST_OBJS = $(TEST_SRCS:%=$(BUILD_DIR)/%.o)
BENCH_TARGET = $(BUILD_DIR)/benchmark/benchmark
BENCH_SRCS := benchmark/logger.cpp benchmark/main.cpp
BENCH_OBJS = $(BENCH_SRCS:%=$(BUILD_DIR)/%.o)
XTRCTL_TARGET = $(BUILD_DIR)/xtrctl
XTRCTL_SRCS := src/xtrctl.cpp
XTRCTL_OBJS = $(XTRCTL_SRCS:%=$(BUILD_DIR)/%.o)
DOCS_SRCS := \
docs-src/index.rst docs-src/quickstart.rst \
docs-src/guide.rst docs-src/api.rst \
docs-src/xtrctl.rst docs-src/conf.py
MAN1_PAGES := docs/xtrctl.1
MAN3_PAGES := docs/libxtr.3 docs/libxtr-quickstart.3 docs/libxtr-userguide.3
MAN_PAGES := $(MAN1_PAGES) $(MAN3_PAGES)
HTML_DOC_PAGES := \
docs/api.html docs/genindex.html docs/guide.html docs/index.html \
docs/quickstart.html docs/search.html docs/xtrctl.html
DEPS = $(OBJS:.o=.d) $(TEST_OBJS:.o=.d) $(BENCH_OBJS:.o=.d) $(XTRCTL_OBJS:.o=.d)
INCLUDES = \
$(wildcard include/xtr/*.hpp) \
$(wildcard include/xtr/detail/*.hpp) \
$(wildcard include/xtr/detail/commands/*.hpp \
$(wildcard include/xtr/io/*.hpp) \
$(wildcard include/xtr/io/detail/*.hpp))
$(TARGET): $(OBJS)
$(AR) rc $@ $^
$(RANLIB) $@
$(TEST_TARGET): $(TARGET) $(TEST_OBJS)
$(LINK.cc) -o $@ $(TEST_LDFLAGS) $(TEST_OBJS) $(LDLIBS) $(TEST_LDLIBS)
$(BENCH_TARGET): $(TARGET) $(BENCH_OBJS)
$(LINK.cc) -o $@ $(BENCH_LDFLAGS) $(BENCH_OBJS) $(LDLIBS) $(BENCH_LDLIBS)
$(XTRCTL_TARGET): $(TARGET) $(XTRCTL_OBJS)
$(LINK.cc) -o $@ $(XTRCTL_LDFLAGS) $(XTRCTL_OBJS) $(LDLIBS)
$(OBJS): $(BUILD_DIR)/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) -o $@ -c $(CPPFLAGS) $(CXXFLAGS) $<
$(TEST_OBJS): $(BUILD_DIR)/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) -o $@ -c $(CPPFLAGS) $(TEST_CPPFLAGS) $(CXXFLAGS) $<
$(BENCH_OBJS): $(BUILD_DIR)/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) -o $@ -c $(CPPFLAGS) $(BENCH_CPPFLAGS) $(CXXFLAGS) $<
$(XTRCTL_OBJS): $(BUILD_DIR)/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) -o $@ -c $(CPPFLAGS) $(CXXFLAGS) $<
all: $(TARGET) $(TEST_TARGET) $(BENCH_TARGET) $(XTRCTL_TARGET) single_include
check: $(TEST_TARGET)
$< --order rand
benchmark: $(BENCH_TARGET)
$<
benchmark_cpu: $(BENCH_TARGET)
sudo cpupower --cpu $(PRODUCER_CPU),$(CONSUMER_CPU) frequency-set --governor performance
$<
sudo cpupower --cpu $(PRODUCER_CPU),$(CONSUMER_CPU) frequency-set --governor schedutil
xtrctl: $(XTRCTL_TARGET)
single_include/xtr/logger.hpp: $(SRCS) $(INCLUDES)
scripts/make_single_include.sh
single_include: single_include/xtr/logger.hpp
install: $(TARGET) $(XTRCTL_TARGET) docs
mkdir -p $(PREFIX)/lib $(PREFIX)/bin $(PREFIX)/include/xtr/detail $(PREFIX)/man/man1 $(PREFIX)/man/man3
install $(TARGET) $(PREFIX)/lib
install $(XTRCTL_TARGET) $(PREFIX)/bin
install --mode=644 include/xtr/*.hpp $(PREFIX)/include/xtr/
install --mode=644 include/xtr/detail/*.hpp $(PREFIX)/include/xtr/detail/
install --mode=644 $(MAN3_PAGES) $(PREFIX)/man/man3
install --mode=644 $(MAN1_PAGES) $(PREFIX)/man/man1
clean:
$(RM) $(TARGET) $(TEST_TARGET) $(BENCH_TARGET) $(XTRCTL_TARGET) \
$(OBJS) $(TEST_OBJS) $(BENCH_OBJS) $(XTRCTL_OBJS) \
$(DEPS) $(COVERAGE_DATA)
coverage_report: $(BUILD_DIR)/coverage_report/index.html
xdg-open $< 2> /dev/null
build/doxygen/xml/index.xml: docs-src/Doxyfile $(INCLUDES)
@mkdir -p $(@D)
doxygen $<
$(HTML_DOC_PAGES): $(DOCS_SRCS) build/doxygen/xml/index.xml
sphinx-build -W -b html docs-src docs
$(MAN_PAGES): $(DOCS_SRCS) build/doxygen/xml/index.xml
sphinx-build -W -b man docs-src docs
docs: $(HTML_DOC_PAGES) $(MAN_PAGES)
clean-docs:
$(RM) build/doxygen/xml/index.xml $(HTML_DOC_PAGES) $(MAN_PAGES)
$(BUILD_DIR)/coverage_report/index.html: $(TEST_TARGET)
ifeq ($(COVERAGE), 0)
$(error COVERAGE=1 option required)
endif
$<
@mkdir -p $(@D)
gcovr --exclude test --exclude third_party --html-details $@ -r .
-include $(DEPS)
.PHONY: all check benchmark single_include install clean coverage_report docs