-
Notifications
You must be signed in to change notification settings - Fork 117
/
Makefile
279 lines (225 loc) · 7.86 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
276
277
278
279
-include config.mk
### Options ###
DEBUG ?= 0
CHECK_INVARIANTS ?= 0
# 0 = libc malloc
# 1 = jemalloc
# 2 = tcmalloc
# 3 = flow
USE_MALLOC_MODE ?= 1
MYSQL ?= 1
MYSQL_SHARE_DIR ?= /x/stephentu/mysql-5.5.29/build/sql/share
# Available modes
# * perf
# * backoff
# * factor-gc
# * factor-gc-nowriteinplace
# * factor-fake-compression
# * sandbox
MODE ?= perf
# run with 'MASSTREE=0' to turn off masstree
MASSTREE ?= 1
###############
DEBUG_S=$(strip $(DEBUG))
CHECK_INVARIANTS_S=$(strip $(CHECK_INVARIANTS))
EVENT_COUNTERS_S=$(strip $(EVENT_COUNTERS))
USE_MALLOC_MODE_S=$(strip $(USE_MALLOC_MODE))
MODE_S=$(strip $(MODE))
MASSTREE_S=$(strip $(MASSTREE))
MASSTREE_CONFIG:=--enable-max-key-len=1024
ifeq ($(DEBUG_S),1)
OSUFFIX_D=.debug
MASSTREE_CONFIG+=--enable-assertions
else
MASSTREE_CONFIG+=--disable-assertions
endif
ifeq ($(CHECK_INVARIANTS_S),1)
OSUFFIX_S=.check
MASSTREE_CONFIG+=--enable-invariants --enable-preconditions
else
MASSTREE_CONFIG+=--disable-invariants --disable-preconditions
endif
ifeq ($(EVENT_COUNTERS_S),1)
OSUFFIX_E=.ectrs
endif
OSUFFIX=$(OSUFFIX_D)$(OSUFFIX_S)$(OSUFFIX_E)
ifeq ($(MODE_S),perf)
O := out-perf$(OSUFFIX)
CONFIG_H = config/config-perf.h
else ifeq ($(MODE_S),backoff)
O := out-backoff$(OSUFFIX)
CONFIG_H = config/config-backoff.h
else ifeq ($(MODE_S),factor-gc)
O := out-factor-gc$(OSUFFIX)
CONFIG_H = config/config-factor-gc.h
else ifeq ($(MODE_S),factor-gc-nowriteinplace)
O := out-factor-gc-nowriteinplace$(OSUFFIX)
CONFIG_H = config/config-factor-gc-nowriteinplace.h
else ifeq ($(MODE_S),factor-fake-compression)
O := out-factor-fake-compression$(OSUFFIX)
CONFIG_H = config/config-factor-fake-compression.h
else ifeq ($(MODE_S),sandbox)
O := out-sandbox$(OSUFFIX)
CONFIG_H = config/config-sandbox.h
else
$(error invalid mode)
endif
CXXFLAGS := -g -Wall -std=c++0x
CXXFLAGS += -MD -Ithird-party/lz4 -DCONFIG_H=\"$(CONFIG_H)\"
ifeq ($(DEBUG_S),1)
CXXFLAGS += -fno-omit-frame-pointer -DDEBUG
else
CXXFLAGS += -Werror -O2 -funroll-loops -fno-omit-frame-pointer
endif
ifeq ($(CHECK_INVARIANTS_S),1)
CXXFLAGS += -DCHECK_INVARIANTS
endif
ifeq ($(EVENT_COUNTERS_S),1)
CXXFLAGS += -DENABLE_EVENT_COUNTERS
endif
ifeq ($(MASSTREE_S),1)
CXXFLAGS += -DNDB_MASSTREE -include masstree/config.h
OBJDEP += masstree/config.h
O := $(O).masstree
else
O := $(O).silotree
endif
TOP := $(shell echo $${PWD-`pwd`})
LDFLAGS := -lpthread -lnuma -lrt
LZ4LDFLAGS := -Lthird-party/lz4 -llz4 -Wl,-rpath,$(TOP)/third-party/lz4
ifeq ($(USE_MALLOC_MODE_S),1)
CXXFLAGS+=-DUSE_JEMALLOC
LDFLAGS+=-ljemalloc
MASSTREE_CONFIG+=--with-malloc=jemalloc
else ifeq ($(USE_MALLOC_MODE_S),2)
CXXFLAGS+=-DUSE_TCMALLOC
LDFLAGS+=-ltcmalloc
MASSTREE_CONFIG+=--with-malloc=tcmalloc
else ifeq ($(USE_MALLOC_MODE_S),3)
CXXFLAGS+=-DUSE_FLOW
LDFLAGS+=-lflow
MASSTREE_CONFIG+=--with-malloc=flow
else
MASSTREE_CONFIG+=--with-malloc=malloc
endif
ifneq ($(strip $(CUSTOM_LDPATH)), )
LDFLAGS+=$(CUSTOM_LDPATH)
endif
SRCFILES = allocator.cc \
btree.cc \
core.cc \
counter.cc \
memory.cc \
rcu.cc \
stats_server.cc \
thread.cc \
ticker.cc \
tuple.cc \
txn_btree.cc \
txn.cc \
txn_proto2_impl.cc \
varint.cc
ifeq ($(MASSTREE_S),1)
MASSTREE_SRCFILES = masstree/compiler.cc \
masstree/str.cc \
masstree/string.cc \
masstree/straccum.cc \
masstree/json.cc
endif
OBJFILES := $(patsubst %.cc, $(O)/%.o, $(SRCFILES))
MASSTREE_OBJFILES := $(patsubst masstree/%.cc, $(O)/%.o, $(MASSTREE_SRCFILES))
BENCH_CXXFLAGS := $(CXXFLAGS)
BENCH_LDFLAGS := $(LDFLAGS) -ldb_cxx -lz -lrt -lcrypt -laio -ldl -lssl -lcrypto
BENCH_SRCFILES = benchmarks/bdb_wrapper.cc \
benchmarks/bench.cc \
benchmarks/encstress.cc \
benchmarks/bid.cc \
benchmarks/masstree/kvrandom.cc \
benchmarks/queue.cc \
benchmarks/tpcc.cc \
benchmarks/ycsb.cc
ifeq ($(MYSQL_S),1)
BENCH_CXXFLAGS += -DMYSQL_SHARE_DIR=\"$(MYSQL_SHARE_DIR)\"
BENCH_LDFLAGS := -L/usr/lib/mysql -lmysqld $(BENCH_LDFLAGS)
BENCH_SRCFILES += benchmarks/mysql_wrapper.cc
else
BENCH_CXXFLAGS += -DNO_MYSQL
endif
BENCH_OBJFILES := $(patsubst %.cc, $(O)/%.o, $(BENCH_SRCFILES))
NEWBENCH_SRCFILES = new-benchmarks/bench.cc \
new-benchmarks/tpcc.cc
NEWBENCH_OBJFILES := $(patsubst %.cc, $(O)/%.o, $(NEWBENCH_SRCFILES))
all: $(O)/test
$(O)/benchmarks/%.o: benchmarks/%.cc $(O)/buildstamp $(O)/buildstamp.bench $(OBJDEP)
@mkdir -p $(@D)
$(CXX) $(BENCH_CXXFLAGS) -c $< -o $@
$(O)/benchmarks/masstree/%.o: benchmarks/masstree/%.cc $(O)/buildstamp $(O)/buildstamp.bench $(OBJDEP)
@mkdir -p $(@D)
$(CXX) $(BENCH_CXXFLAGS) -c $< -o $@
$(O)/new-benchmarks/%.o: new-benchmarks/%.cc $(O)/buildstamp $(O)/buildstamp.bench $(OBJDEP)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(O)/%.o: %.cc $(O)/buildstamp $(OBJDEP)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(MASSTREE_OBJFILES) : $(O)/%.o: masstree/%.cc masstree/config.h
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -include masstree/config.h -c $< -o $@
third-party/lz4/liblz4.so:
make -C third-party/lz4 library
.PHONY: test
test: $(O)/test
$(O)/test: $(O)/test.o $(OBJFILES) $(MASSTREE_OBJFILES) third-party/lz4/liblz4.so
$(CXX) -o $(O)/test $^ $(LDFLAGS) $(LZ4LDFLAGS)
.PHONY: persist_test
persist_test: $(O)/persist_test
$(O)/persist_test: $(O)/persist_test.o third-party/lz4/liblz4.so
$(CXX) -o $(O)/persist_test $(O)/persist_test.o $(LDFLAGS) $(LZ4LDFLAGS)
.PHONY: stats_client
stats_client: $(O)/stats_client
$(O)/stats_client: $(O)/stats_client.o
$(CXX) -o $(O)/stats_client $(O)/stats_client.o $(LDFLAGS)
masstree/config.h: $(O)/buildstamp.masstree masstree/configure masstree/config.h.in
rm -f $@
cd masstree; ./configure $(MASSTREE_CONFIG)
if test -f $@; then touch $@; fi
masstree/configure masstree/config.h.in: masstree/configure.ac
cd masstree && autoreconf -i && touch configure config.h.in
.PHONY: dbtest
dbtest: $(O)/benchmarks/dbtest
$(O)/benchmarks/dbtest: $(O)/benchmarks/dbtest.o $(OBJFILES) $(MASSTREE_OBJFILES) $(BENCH_OBJFILES) third-party/lz4/liblz4.so
$(CXX) -o $(O)/benchmarks/dbtest $^ $(BENCH_LDFLAGS) $(LZ4LDFLAGS)
.PHONY: kvtest
kvtest: $(O)/benchmarks/masstree/kvtest
$(O)/benchmarks/masstree/kvtest: $(O)/benchmarks/masstree/kvtest.o $(OBJFILES) $(BENCH_OBJFILES)
$(CXX) -o $(O)/benchmarks/masstree/kvtest $^ $(BENCH_LDFLAGS)
.PHONY: newdbtest
newdbtest: $(O)/new-benchmarks/dbtest
$(O)/new-benchmarks/dbtest: $(O)/new-benchmarks/dbtest.o $(OBJFILES) $(MASSTREE_OBJFILES) $(NEWBENCH_OBJFILES) third-party/lz4/liblz4.so
$(CXX) -o $(O)/new-benchmarks/dbtest $^ $(LDFLAGS) $(LZ4LDFLAGS)
DEPFILES := $(wildcard $(O)/*.d $(O)/*/*.d $(O)/*/*/*.d masstree/_masstree_config.d)
ifneq ($(DEPFILES),)
-include $(DEPFILES)
endif
ifeq ($(wildcard masstree/GNUmakefile.in),)
INSTALL_MASSTREE := $(shell git submodule init; git submodule update)
endif
ifeq ($(MASSTREE_S),1)
UPDATE_MASSTREE := $(shell cd ./`git rev-parse --show-cdup` && cur=`git submodule status --cached masstree | head -c 41 | tail -c +2` && if test -z `cd masstree; git rev-list -n1 $$cur^..HEAD 2>/dev/null`; then (echo Updating masstree... 1>&2; cd masstree; git checkout -f master >/dev/null; git pull; cd ..; git submodule update masstree); fi)
endif
ifneq ($(strip $(DEBUG_S).$(CHECK_INVARIANTS_S).$(EVENT_COUNTERS_S)),$(strip $(DEP_MAIN_CONFIG)))
DEP_MAIN_CONFIG := $(shell mkdir -p $(O); echo >$(O)/buildstamp; echo "DEP_MAIN_CONFIG:=$(DEBUG_S).$(CHECK_INVARIANTS_S).$(EVENT_COUNTERS_S)" >$(O)/_main_config.d)
endif
ifneq ($(strip $(MYSQL_S)),$(strip $(DEP_BENCH_CONFIG)))
DEP_BENCH_CONFIG := $(shell mkdir -p $(O); echo >$(O)/buildstamp.bench; echo "DEP_BENCH_CONFIG:=$(MYSQL_S)" >$(O)/_bench_config.d)
endif
ifneq ($(strip $(MASSTREE_CONFIG)),$(strip $(DEP_MASSTREE_CONFIG)))
DEP_MASSTREE_CONFIG := $(shell mkdir -p $(O); echo >$(O)/buildstamp.masstree; echo "DEP_MASSTREE_CONFIG:=$(MASSTREE_CONFIG)" >masstree/_masstree_config.d)
endif
$(O)/buildstamp $(O)/buildstamp.bench $(O)/buildstamp.masstree:
@mkdir -p $(@D)
@echo >$@
.PHONY: clean
clean:
rm -rf out-*
make -C third-party/lz4 clean