-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (154 loc) · 7.24 KB
/
Copy pathMakefile
File metadata and controls
186 lines (154 loc) · 7.24 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
# quickbloom Makefile
#
# Targets:
# make -- build the static and shared libraries (default)
# make lib -- build build/libquickbloom.{a,so}
# make test -- build and run the native C test binary
# make example -- build the hello_quickbloom example
# make bench -- run the Python benchmark sweep
# make bench-hash -- per-hash kernel cost (wymum / XXH64 / SipHash-1-3)
# make bench-qb -- native C bench of the qb_* kernels (no ctypes overhead)
# make install -- install header + libs + pkg-config to $(PREFIX) (default /usr/local)
# make clean -- remove build artefacts
#
# Variables (override on the command line):
# CC=clang -- C compiler (default: cc)
# PREFIX=... -- install root (default: /usr/local)
# DESTDIR=... -- staging root prepended to install paths
# CFLAGS_EXTRA=.. -- additional compiler flags
CC ?= cc
PREFIX ?= /usr/local
BUILD := build
VERSION := 0.2.0
SOVERSION := 0
# Architecture-specific flags. x86_64 needs explicit AVX2+BMI2; aarch64
# (Apple Silicon, Graviton 2/3/4) gets NEON from baseline ARMv8-A. The
# Graviton-3-specific spike to armv8.2-a / SVE lives in a separate
# follow-up; baseline NEON works across the whole AArch64 fleet.
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
CFLAGS_ARCH := -mavx2 -mbmi2 -mfma -maes
else ifeq ($(UNAME_M),amd64)
CFLAGS_ARCH := -mavx2 -mbmi2 -mfma -maes
else ifeq ($(UNAME_M),arm64)
CFLAGS_ARCH :=
else ifeq ($(UNAME_M),aarch64)
CFLAGS_ARCH :=
else
$(error Unsupported architecture: $(UNAME_M) — quickbloom supports x86_64 (AVX2) and aarch64 (NEON))
endif
# OS-specific shared-library naming. Linux uses libfoo.so.MAJOR.MINOR
# with an soname symlink chain; macOS uses libfoo.MAJOR.MINOR.dylib
# with an -install_name. Other Unixes default to the Linux shape.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SOEXT := dylib
LIB_SO_REAL := $(BUILD)/libquickbloom.$(VERSION).$(SOEXT)
LIB_SO_SO := $(BUILD)/libquickbloom.$(SOVERSION).$(SOEXT)
LIB_SO := $(BUILD)/libquickbloom.$(SOEXT)
SHARED_FLAGS := -dynamiclib -install_name @rpath/libquickbloom.$(SOVERSION).$(SOEXT) \
-compatibility_version $(SOVERSION) -current_version $(VERSION)
else
SOEXT := so
LIB_SO_REAL := $(BUILD)/libquickbloom.$(SOEXT).$(VERSION)
LIB_SO_SO := $(BUILD)/libquickbloom.$(SOEXT).$(SOVERSION)
LIB_SO := $(BUILD)/libquickbloom.$(SOEXT)
SHARED_FLAGS := -shared -Wl,-soname,libquickbloom.$(SOEXT).$(SOVERSION)
endif
CFLAGS_BASE := -O3 $(CFLAGS_ARCH) -fPIC -Wall -Wextra -std=c11
CFLAGS := $(CFLAGS_BASE) $(CFLAGS_EXTRA)
OBJS := \
$(BUILD)/quickbloom.o
# Shared-library naming is set above per OS. Linux:
# libquickbloom.so.$(VERSION) (real) -> libquickbloom.so.$(SOVERSION) (soname) -> libquickbloom.so
# Darwin:
# libquickbloom.$(VERSION).dylib (real) -> libquickbloom.$(SOVERSION).dylib (compat) -> libquickbloom.dylib
LIB_A := $(BUILD)/libquickbloom.a
LIB_PC := $(BUILD)/quickbloom.pc
.PHONY: all lib test example bench bench-hash bench-qb fuzz install clean
all: lib
lib: $(LIB_SO) $(LIB_A) $(LIB_PC)
$(BUILD):
mkdir -p $(BUILD)
$(BUILD)/quickbloom.o: quickbloom.c quickbloom.h | $(BUILD)
$(CC) $(CFLAGS) -I. -c quickbloom.c -o $@
$(LIB_SO_REAL): $(OBJS)
$(CC) $(SHARED_FLAGS) -o $@ $(OBJS) -lm
$(LIB_SO): $(LIB_SO_REAL)
ifeq ($(UNAME_S),Darwin)
cd $(BUILD) && ln -sf libquickbloom.$(VERSION).$(SOEXT) libquickbloom.$(SOVERSION).$(SOEXT)
cd $(BUILD) && ln -sf libquickbloom.$(SOVERSION).$(SOEXT) libquickbloom.$(SOEXT)
else
cd $(BUILD) && ln -sf libquickbloom.$(SOEXT).$(VERSION) libquickbloom.$(SOEXT).$(SOVERSION)
cd $(BUILD) && ln -sf libquickbloom.$(SOEXT).$(SOVERSION) libquickbloom.$(SOEXT)
endif
$(LIB_A): $(OBJS)
ar rcs $@ $(OBJS)
$(LIB_PC): quickbloom.pc.in | $(BUILD)
sed -e 's|@PREFIX@|$(PREFIX)|g' \
-e 's|@VERSION@|$(VERSION)|g' \
quickbloom.pc.in > $@
# Native C tests. Links against the static library so a system without
# the shared lib installed can still run them. -lm for qb_estimate_bits.
$(BUILD)/test_quickbloom: test/test_quickbloom.c $(LIB_A) quickbloom.h | $(BUILD)
$(CC) $(CFLAGS) -I. -o $@ test/test_quickbloom.c $(LIB_A) -lm
test: $(BUILD)/test_quickbloom
$<
# Example. Same linkage shape as a consumer would use.
$(BUILD)/hello_quickbloom: examples/hello_quickbloom.c $(LIB_A) quickbloom.h | $(BUILD)
$(CC) $(CFLAGS) -I. -o $@ examples/hello_quickbloom.c $(LIB_A) -lm
example: $(BUILD)/hello_quickbloom
$<
# Python benchmark sweep. Compiles each candidate's .c separately the
# way it always has — independent of the library build above.
bench:
python3 tools/bench_all.py
# Per-hash cost bench. Measures wymum16 / XXH64 / SipHash-1-3 over
# 16-byte keys with the same compile flags as the rest of the
# project, so the numbers can be compared directly against the
# prehash bloom benches.
$(BUILD)/bench_hash: tools/bench_hash.c | $(BUILD)
$(CC) $(CFLAGS) -o $@ tools/bench_hash.c
bench-hash: $(BUILD)/bench_hash
$<
# Native C bench of the qb_* kernels. Links against the static library
# so timings reflect the same -O3 inlining a downstream user gets.
$(BUILD)/bench_qb: tools/bench_qb.c $(LIB_A) quickbloom.h | $(BUILD)
$(CC) $(CFLAGS) -I. -o $@ tools/bench_qb.c $(LIB_A) -lm
bench-qb: $(BUILD)/bench_qb
$<
# libFuzzer harnesses. Require clang. Build the library with the
# fuzzer sanitizer so the bloom code is instrumented too, then link
# each harness into a standalone fuzzer binary.
FUZZ_CFLAGS := -O1 -g -fsanitize=fuzzer,address,undefined -fno-sanitize-recover=all \
$(CFLAGS_ARCH) -Wall -Wextra -std=c11
$(BUILD)/fuzz_insert: tools/fuzz_insert.c quickbloom.c quickbloom.h | $(BUILD)
$(CC) $(FUZZ_CFLAGS) -I. -o $@ tools/fuzz_insert.c quickbloom.c -lm
$(BUILD)/fuzz_fasthash_var: tools/fuzz_fasthash_var.c quickbloom.c quickbloom.h | $(BUILD)
$(CC) $(FUZZ_CFLAGS) -I. -o $@ tools/fuzz_fasthash_var.c quickbloom.c -lm
$(BUILD)/fuzz_deserialize: tools/fuzz_deserialize.c quickbloom.c quickbloom.h | $(BUILD)
$(CC) $(FUZZ_CFLAGS) -I. -o $@ tools/fuzz_deserialize.c quickbloom.c -lm
fuzz: $(BUILD)/fuzz_insert $(BUILD)/fuzz_fasthash_var $(BUILD)/fuzz_deserialize
install: lib
install -d $(DESTDIR)$(PREFIX)/include
install -d $(DESTDIR)$(PREFIX)/lib
install -d $(DESTDIR)$(PREFIX)/lib/pkgconfig
install -m 644 quickbloom.h $(DESTDIR)$(PREFIX)/include/
install -m 644 $(LIB_A) $(DESTDIR)$(PREFIX)/lib/
install -m 755 $(LIB_SO_REAL) $(DESTDIR)$(PREFIX)/lib/
# Regenerate the pc file with the install-time PREFIX so the
# distro/Nix/vcpkg pattern `make && make install PREFIX=...` does
# not bake the build-time PREFIX into the installed pkg-config.
sed -e 's|@PREFIX@|$(PREFIX)|g' \
-e 's|@VERSION@|$(VERSION)|g' \
quickbloom.pc.in > $(DESTDIR)$(PREFIX)/lib/pkgconfig/quickbloom.pc
chmod 644 $(DESTDIR)$(PREFIX)/lib/pkgconfig/quickbloom.pc
ifeq ($(UNAME_S),Darwin)
cd $(DESTDIR)$(PREFIX)/lib && ln -sf libquickbloom.$(VERSION).$(SOEXT) libquickbloom.$(SOVERSION).$(SOEXT)
cd $(DESTDIR)$(PREFIX)/lib && ln -sf libquickbloom.$(SOVERSION).$(SOEXT) libquickbloom.$(SOEXT)
else
cd $(DESTDIR)$(PREFIX)/lib && ln -sf libquickbloom.$(SOEXT).$(VERSION) libquickbloom.$(SOEXT).$(SOVERSION)
cd $(DESTDIR)$(PREFIX)/lib && ln -sf libquickbloom.$(SOEXT).$(SOVERSION) libquickbloom.$(SOEXT)
endif
clean:
rm -rf $(BUILD)