-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathMakefile
190 lines (158 loc) · 5.25 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
#
# Copyright (c) 2012-2022, Jyri J. Virkki
# All rights reserved.
#
# This file is under BSD license. See LICENSE file.
#
# Requires GNU Make, so invoke appropriately (make or gmake)
#
# Other build options:
#
# DEBUG=1 make to build debug instead of optimized
#
# Other build targets:
#
# make test to build and run test code
# make release_test to build and run larger tests
# make gcov to build with code coverage and run gcov
# make clean the usual
#
BLOOM_VERSION_MAJOR=2
BLOOM_VERSION_MINOR=0
#
# Shared library names - these definitions work on most platforms but can
# be overridden in the platform-specific sections below.
#
BLOOM_VERSION=$(BLOOM_VERSION_MAJOR).$(BLOOM_VERSION_MINOR)
BLOOM_SONAME=libbloom.so.$(BLOOM_VERSION_MAJOR)
SO_VERSIONED=libbloom.so.$(BLOOM_VERSION)
LD_SONAME=-Wl,-soname,$(BLOOM_SONAME)
SO=so
TOP := $(shell /bin/pwd)
BUILD_OS := $(shell uname)
BINDIR=$(TOP)/build
TESTDIR=$(TOP)/misc/test
INC+=-I$(TOP) -I$(TOP)/murmur2
LIB+=-lm
CFLAGS+=-Wall
CFLAGS+=-fPIC
CFLAGS+=-DBLOOM_VERSION=$(BLOOM_VERSION)
CFLAGS+=-DBLOOM_VERSION_MAJOR=$(BLOOM_VERSION_MAJOR)
CFLAGS+=-DBLOOM_VERSION_MINOR=$(BLOOM_VERSION_MINOR)
ifeq ($(DEBUG),1)
OPT=-g $(DEBUGOPT)
else
OPT?=-O3
endif
ifeq ($(BUILD_OS),$(filter $(BUILD_OS), GNU/kFreeBSD GNU Linux))
RPATH=-Wl,-rpath,$(BINDIR)
endif
ifeq ($(BUILD_OS),SunOS)
RPATH=-R$(BINDIR)
CC=gcc
endif
ifeq ($(BUILD_OS),OpenBSD)
RPATH=-R$(BINDIR)
endif
ifeq ($(BUILD_OS),Darwin)
MAC=-install_name $(BINDIR)/libbloom.dylib \
-compatibility_version $(BLOOM_VERSION_MAJOR) \
-current_version $(BLOOM_VERSION)
RPATH=-Xlinker -rpath -Xlinker $(BINDIR)
SO=dylib
BLOOM_SONAME=libbloom.$(BLOOM_VERSION_MAJOR).$(SO)
SO_VERSIONED=libbloom.$(BLOOM_VERSION).$(SO)
LD_SONAME=
endif
all: $(BINDIR)/$(SO_VERSIONED) $(BINDIR)/libbloom.a
$(BINDIR)/$(SO_VERSIONED): $(BINDIR)/murmurhash2.o $(BINDIR)/bloom.o
(cd $(BINDIR) && \
$(CC) $(OPT) $(LDFLAGS) bloom.o murmurhash2.o -shared \
$(LIB) $(MAC) $(LD_SONAME) -o $(SO_VERSIONED) && \
rm -f $(BLOOM_SONAME) && \
ln -s $(SO_VERSIONED) $(BLOOM_SONAME) && \
rm -f libbloom.$(SO) && \
ln -s $(BLOOM_SONAME) libbloom.$(SO) )
$(BINDIR)/libbloom.a: $(BINDIR)/murmurhash2.o $(BINDIR)/bloom.o
(cd $(BINDIR) && ar rcs libbloom.a bloom.o murmurhash2.o)
$(BINDIR)/test-libbloom: $(TESTDIR)/test.c $(BINDIR)/$(SO_VERSIONED)
$(CC) $(CFLAGS) $(OPT) $(INC) -c $(TESTDIR)/test.c -o \
$(BINDIR)/test.o
(cd $(BINDIR) && \
$(CC) $(CFLAGS) $(OPT) -L$(BINDIR) $(RPATH) test.o \
-lbloom -o test-libbloom)
$(BINDIR)/test-perf: $(TESTDIR)/perf.c $(BINDIR)/$(SO_VERSIONED)
$(CC) $(CFLAGS) $(OPT) $(INC) -c $(TESTDIR)/perf.c -o $(BINDIR)/perf.o
(cd $(BINDIR) && \
$(CC) perf.o -L$(BINDIR) $(RPATH) -lbloom -o test-perf)
$(BINDIR)/test-basic: $(TESTDIR)/basic.c $(BINDIR)/libbloom.a
$(CC) $(CFLAGS) $(OPT) $(INC) $(TESTDIR)/basic.c \
$(BINDIR)/libbloom.a $(LIB) -o $(BINDIR)/test-basic
$(BINDIR)/visualize: $(TESTDIR)/visualize.c $(BINDIR)/libbloom.a
$(CC) $(CFLAGS) $(OPT) $(INC) $(TESTDIR)/visualize.c \
$(BINDIR)/libbloom.a $(LIB) -lgd -o $(BINDIR)/visualize
$(BINDIR)/%.o: %.c
mkdir -p $(BINDIR)
$(CC) $(CFLAGS) $(OPT) $(INC) -c $< -o $@
$(BINDIR)/murmurhash2.o: murmur2/MurmurHash2.c murmur2/murmurhash2.h
mkdir -p $(BINDIR)
$(CC) $(CFLAGS) $(OPT) $(INC) \
-c murmur2/MurmurHash2.c -o $(BINDIR)/murmurhash2.o
clean:
rm -rf $(BINDIR)
test: $(BINDIR)/test-libbloom $(BINDIR)/test-basic
$(BINDIR)/test-basic
$(BINDIR)/test-libbloom
perf: $(BINDIR)/test-perf
$(BINDIR)/test-perf
#
# Builds the visualize program into $BINDIR
# This is not built by default as it requires the GD library
# (on Debian: libgd3 and libgd-dev) to be present.
#
visualize: $(BINDIR)/visualize
vtest: $(BINDIR)/test-libbloom
valgrind --tool=memcheck --leak-check=full --show-reachable=yes \
--track-origins=yes $(BINDIR)/test-libbloom
gcov:
$(MAKE) clean
DEBUG=1 DEBUGOPT="-fprofile-arcs -ftest-coverage" \
$(MAKE) $(BINDIR)/test-libbloom
(cd $(BINDIR) && \
cp ../*.c . && \
./test-libbloom && \
gcov -bf bloom.c)
@echo Remember to make clean to remove instrumented objects
lcov: gcov
lcov --capture --directory build --output-file lcov.info
lcov --remove lcov.info MurmurHash2.c --output-file lcov.info
lcov --remove lcov.info test.c --output-file lcov.info
genhtml lcov.info \
--output-directory $(LCOV_OUTPUT_DIR)
rm -f lcov.info
$(MAKE) clean
#
# This target runs a test which creates a filter of capacity N and inserts
# N elements, for N in 100,000 to 1,000,000 with an expected error of 0.001.
# To preserve and graph the output, move it to ./misc/collisions and use
# the ./misc/collisions/dograph script to plot it.
#
# WARNING: This can take a very long time (on a slow machine, multiple days)
# to run.
#
collision_test: $(BINDIR)/test-libbloom
$(BINDIR)/test-libbloom -G 100000 1000000 10 0.001 \
| tee collision_data_v$(BLOOM_VERSION)
#
# This target should be run when preparing a release, includes more tests
# than the 'test' target.
# For a final release, should run the collision_test target above as well,
# not included here as it takes so long.
#
release_test:
$(MAKE) test
$(MAKE) vtest
$(BINDIR)/test-libbloom -G 100000 1000000 50000 0.001 \
| tee short_coll_data
gzip short_coll_data
./misc/collisions/dograph short_coll_data.gz