Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (109 loc) · 5.22 KB
/
Copy pathMakefile
File metadata and controls
135 lines (109 loc) · 5.22 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
# Build for the ITB C++ binding (thin Triple Pipeline proxy).
#
# Targets:
# all (default): build/libitb3_cpp.a + build/libitb3_cpp.so + every test binary.
# libitb3.so: rebuilds the underlying Go shared library into ITB_DIST.
# test: builds + runs every tests/test_*.cpp binary (sequential).
# test-asan: the test suite under AddressSanitizer (separate build dir).
# test-ubsan: the test suite under UndefinedBehaviorSanitizer.
# test-valgrind: the test suite under valgrind --leak-check=full.
# eitb: builds the eitb CLI at eitb/eitb.
# loop: builds the loop stress harness at loop/loop.
# bench: builds + runs the benches/bench_*.cpp micro-benchmarks.
# clean: removes every generated artefact.
#
# Variables (override on the command line):
# CXX C++ compiler (default: c++)
# ITB_DIST path to libitb3.so + .h dir (default: ../../dist/linux-amd64)
CXX ?= c++
ITB_DIST ?= ../../dist/linux-amd64
BUILD ?= build
TESTBUILD ?= tests/build
BENCHBUILD ?= benches/build
SANFLAGS ?=
FORTIFY ?= -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
WARN = -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion \
-Wformat=2 -Wnull-dereference -Wold-style-cast -Wnon-virtual-dtor \
-Woverloaded-virtual -Wcast-align -Werror
CXXFLAGS = -std=c++20 -O2 -g $(WARN) $(FORTIFY) -fstack-protector-strong \
-fPIC -Iinclude -Isrc -isystem $(ITB_DIST) $(SANFLAGS)
RPATH = $(abspath $(ITB_DIST))
LDFLAGS = -L$(ITB_DIST) -Wl,-rpath,$(RPATH) $(SANFLAGS)
LIBITB3 = -litb3
# ---- Library ---------------------------------------------------------
LIB_SRCS = src/error.cpp src/opts.cpp src/pipeline.cpp src/stream.cpp \
src/runtime.cpp
LIB_OBJS = $(patsubst src/%.cpp,$(BUILD)/%.o,$(LIB_SRCS))
LIB_HDRS = include/itb3.hpp src/internal.hpp $(ITB_DIST)/libitb3.h
all: $(BUILD)/libitb3_cpp.a $(BUILD)/libitb3_cpp.so tests
$(BUILD)/%.o: src/%.cpp $(LIB_HDRS)
@mkdir -p $(BUILD)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(BUILD)/libitb3_cpp.a: $(LIB_OBJS)
$(AR) rcs $@ $(LIB_OBJS)
$(BUILD)/libitb3_cpp.so: $(LIB_OBJS)
$(CXX) -shared $(LIB_OBJS) -o $@ $(LDFLAGS) $(LIBITB3)
# ---- Underlying Go shared library -----------------------------------
libitb3.so:
cd ../.. && go build -trimpath -buildmode=c-shared \
-o dist/linux-amd64/libitb3.so ./cmd/cshared
# ---- Tests -----------------------------------------------------------
# Each tests/test_*.cpp becomes its own binary linked against the
# static library (explicit archive path so the .so next to it is not
# picked) plus libitb3.so via embedded RPATH.
TEST_SRCS := $(wildcard tests/test_*.cpp)
TEST_BINS := $(patsubst tests/test_%.cpp,$(TESTBUILD)/test_%,$(TEST_SRCS))
tests: $(BUILD)/libitb3_cpp.a $(TEST_BINS)
$(TESTBUILD)/test_%: tests/test_%.cpp tests/test_util.hpp $(BUILD)/libitb3_cpp.a
@mkdir -p $(TESTBUILD)
$(CXX) $(CXXFLAGS) -Itests $< $(BUILD)/libitb3_cpp.a -o $@ $(LDFLAGS) $(LIBITB3)
test: tests
@fail=0; \
for t in $(TEST_BINS); do \
if "$$t" >/dev/null 2>&1; then \
printf ' ok %s\n' "$$t"; \
else \
printf ' FAIL %s\n' "$$t"; "$$t"; fail=1; \
fi; \
done; \
exit $$fail
test-asan:
$(MAKE) BUILD=build/asan TESTBUILD=tests/build/asan FORTIFY= \
SANFLAGS="-fsanitize=address -fno-omit-frame-pointer" test
test-ubsan:
$(MAKE) BUILD=build/ubsan TESTBUILD=tests/build/ubsan FORTIFY= \
SANFLAGS="-fsanitize=undefined -fno-sanitize-recover=all" test
# The suppression file silences memcheck noise whose faulting frame
# lies inside libitb3.so (Go-runtime stack/heap management memcheck
# cannot model); binding-side C++ frames are never suppressed.
test-valgrind: tests
@for t in $(TEST_BINS); do \
echo "==> valgrind $$t"; \
valgrind --leak-check=full --error-exitcode=1 \
--errors-for-leak-kinds=definite \
--suppressions=tests/valgrind.supp "$$t" >/dev/null || exit 1; \
done
# ---- Eitb CLI --------------------------------------------------------
eitb: eitb/eitb
eitb/eitb: eitb/eitb.cpp $(BUILD)/libitb3_cpp.a
$(CXX) $(CXXFLAGS) eitb/eitb.cpp $(BUILD)/libitb3_cpp.a -o $@ $(LDFLAGS) $(LIBITB3)
# ---- Loop stress harness --------------------------------------------
# One binary from every loop/*.cpp; std::thread carries the workers,
# so the link needs -pthread on top of the shared binding flags.
LOOP_SRCS := $(wildcard loop/*.cpp)
loop: loop/loop
loop/loop: $(LOOP_SRCS) loop/loop.hpp $(BUILD)/libitb3_cpp.a
$(CXX) $(CXXFLAGS) -pthread $(LOOP_SRCS) $(BUILD)/libitb3_cpp.a -o $@ $(LDFLAGS) -pthread $(LIBITB3)
# ---- Benches ---------------------------------------------------------
BENCH_SRCS := $(wildcard benches/bench_*.cpp)
BENCH_BINS := $(patsubst benches/bench_%.cpp,$(BENCHBUILD)/bench_%,$(BENCH_SRCS))
$(BENCHBUILD)/bench_%: benches/bench_%.cpp benches/bench_util.hpp $(BUILD)/libitb3_cpp.a
@mkdir -p $(BENCHBUILD)
$(CXX) $(CXXFLAGS) -Ibenches $< $(BUILD)/libitb3_cpp.a -o $@ $(LDFLAGS) $(LIBITB3)
bench: $(BENCH_BINS)
@for b in $(BENCH_BINS); do "$$b" || exit 1; done
# ---- Cleanup ---------------------------------------------------------
clean:
rm -rf $(BUILD) tests/build benches/build eitb/eitb loop/loop
.PHONY: all libitb3.so tests test test-asan test-ubsan test-valgrind \
eitb loop bench clean