Makefile 79.5 KB
Newer Older
jorlow@chromium.org's avatar
jorlow@chromium.org committed
1
2
3
4
# Copyright (c) 2011 The LevelDB Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. See the AUTHORS file for names of contributors.

5
# Inherit some settings from environment variables, if available
jorlow@chromium.org's avatar
jorlow@chromium.org committed
6

7
#-----------------------------------------------
8

Jonathan Lee's avatar
Jonathan Lee committed
9
10
BASH_EXISTS := $(shell which bash)
SHELL := $(shell which bash)
11
# Default to python3. Some distros like CentOS 8 do not have `python`.
12
13
14
ifeq ($(origin PYTHON), undefined)
	PYTHON := $(shell which python3 || which python || echo python3)
endif
15
export PYTHON
Jonathan Lee's avatar
Jonathan Lee committed
16

17
CLEAN_FILES = # deliberately empty, so we can append below.
18
19
20
21
CFLAGS += ${EXTRA_CFLAGS}
CXXFLAGS += ${EXTRA_CXXFLAGS}
LDFLAGS += $(EXTRA_LDFLAGS)
MACHINE ?= $(shell uname -m)
Tomas Kolda's avatar
Tomas Kolda committed
22
23
ARFLAGS = ${EXTRA_ARFLAGS} rs
STRIPFLAGS = -S -x
24

25
26
# Transform parallel LOG output into something more readable.
perl_command = perl -n \
27
28
29
  -e '@a=split("\t",$$_,-1); $$t=$$a[8];'				\
  -e '$$t =~ /.*if\s\[\[\s"(.*?\.[\w\/]+)/ and $$t=$$1;'		\
  -e '$$t =~ s,^\./,,;'							\
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
30
31
32
  -e '$$t =~ s, >.*,,; chomp $$t;'					\
  -e '$$t =~ /.*--gtest_filter=(.*?\.[\w\/]+)/ and $$t=$$1;'		\
  -e 'printf "%7.3f %s %s\n", $$a[3], $$a[6] == 0 ? "PASS" : "FAIL", $$t'
33
34
quoted_perl_command = $(subst ','\'',$(perl_command))

35
36
37
38
39
40
41
42
43
# DEBUG_LEVEL can have three values:
# * DEBUG_LEVEL=2; this is the ultimate debug mode. It will compile rocksdb
# without any optimizations. To compile with level 2, issue `make dbg`
# * DEBUG_LEVEL=1; debug level 1 enables all assertions and debug code, but
# compiles rocksdb with -O2 optimizations. this is the default debug level.
# `make all` or `make <binary_target>` compile RocksDB with debug level 1.
# We use this debug level when developing RocksDB.
# * DEBUG_LEVEL=0; this is the debug level we use for release. If you're
# running rocksdb in production you most definitely want to compile RocksDB
agiardullo's avatar
agiardullo committed
44
# with debug level 0. To compile with level 0, run `make shared_lib`,
45
46
# `make install-shared`, `make static_lib`, `make install-static` or
# `make install`
47
48
49

# Set the default DEBUG_LEVEL to 1
DEBUG_LEVEL?=1
50
51

ifeq ($(MAKECMDGOALS),dbg)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
52
	DEBUG_LEVEL=2
53
endif
54

55
56
57
58
59
60
61
62
ifeq ($(MAKECMDGOALS),clean)
	DEBUG_LEVEL=0
endif

ifeq ($(MAKECMDGOALS),release)
	DEBUG_LEVEL=0
endif

63
ifeq ($(MAKECMDGOALS),shared_lib)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
64
	DEBUG_LEVEL=0
Igor Canadi's avatar
Igor Canadi committed
65
endif
66

Igor Canadi's avatar
Igor Canadi committed
67
ifeq ($(MAKECMDGOALS),install-shared)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
68
	DEBUG_LEVEL=0
Igor Canadi's avatar
Igor Canadi committed
69
70
endif

Igor Canadi's avatar
Igor Canadi committed
71
ifeq ($(MAKECMDGOALS),static_lib)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
72
	DEBUG_LEVEL=0
73
endif
Igor Canadi's avatar
Igor Canadi committed
74

Igor Canadi's avatar
Igor Canadi committed
75
ifeq ($(MAKECMDGOALS),install-static)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
76
	DEBUG_LEVEL=0
Igor Canadi's avatar
Igor Canadi committed
77
78
79
endif

ifeq ($(MAKECMDGOALS),install)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
80
	DEBUG_LEVEL=0
81
82
endif

83
ifeq ($(MAKECMDGOALS),rocksdbjavastatic)
84
85
86
	ifneq ($(DEBUG_LEVEL),2)
		DEBUG_LEVEL=0
	endif
87
88
endif

Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
89
ifeq ($(MAKECMDGOALS),rocksdbjavastaticrelease)
90
91
92
	ifneq ($(DEBUG_LEVEL),2)
		DEBUG_LEVEL=0
	endif
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
93
94
endif

95
ifeq ($(MAKECMDGOALS),rocksdbjavastaticreleasedocker)
96
	ifneq ($(DEBUG_LEVEL),2)
97
		DEBUG_LEVEL=0
98
	endif
99
100
endif

Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
101
102
103
104
ifeq ($(MAKECMDGOALS),rocksdbjavastaticpublish)
	DEBUG_LEVEL=0
endif

105
106
$(info $$DEBUG_LEVEL is ${DEBUG_LEVEL})

Yi Wu's avatar
Yi Wu committed
107
108
# Lite build flag.
LITE ?= 0
109
110
111
112
113
114
115
116
ifeq ($(LITE), 0)
ifneq ($(filter -DROCKSDB_LITE,$(OPT)),)
  # Be backward compatible and support older format where OPT=-DROCKSDB_LITE is
  # specified instead of LITE=1 on the command line.
  LITE=1
endif
else ifeq ($(LITE), 1)
ifeq ($(filter -DROCKSDB_LITE,$(OPT)),)
Yi Wu's avatar
Yi Wu committed
117
118
	OPT += -DROCKSDB_LITE
endif
119
endif
Yi Wu's avatar
Yi Wu committed
120
121
122
123
124
125
126
127
128
129

# Figure out optimize level.
ifneq ($(DEBUG_LEVEL), 2)
ifeq ($(LITE), 0)
	OPT += -O2
else
	OPT += -Os
endif
endif

130
131
# compile with -O2 if debug level is not 2
ifneq ($(DEBUG_LEVEL), 2)
Yi Wu's avatar
Yi Wu committed
132
OPT += -fno-omit-frame-pointer
133
134
# Skip for archs that don't support -momit-leaf-frame-pointer
ifeq (,$(shell $(CXX) -fsyntax-only -momit-leaf-frame-pointer -xc /dev/null 2>&1))
135
136
137
138
OPT += -momit-leaf-frame-pointer
endif
endif

139
140
141
142
143
144
145
146
147
148
149
150
ifeq (,$(shell $(CXX) -fsyntax-only -maltivec -xc /dev/null 2>&1))
CXXFLAGS += -DHAS_ALTIVEC
CFLAGS += -DHAS_ALTIVEC
HAS_ALTIVEC=1
endif

ifeq (,$(shell $(CXX) -fsyntax-only -mcpu=power8 -xc /dev/null 2>&1))
CXXFLAGS += -DHAVE_POWER8
CFLAGS +=  -DHAVE_POWER8
HAVE_POWER8=1
endif

151
ifeq (,$(shell $(CXX) -fsyntax-only -march=armv8-a+crc+crypto -xc /dev/null 2>&1))
152
153
CXXFLAGS += -march=armv8-a+crc+crypto
CFLAGS += -march=armv8-a+crc+crypto
154
155
156
ARMCRC_SOURCE=1
endif

157
# if we're compiling for release, compile without debug code (-DNDEBUG)
158
ifeq ($(DEBUG_LEVEL),0)
Igor Canadi's avatar
Igor Canadi committed
159
OPT += -DNDEBUG
Siying Dong's avatar
Siying Dong committed
160
161
162
163
164
165

ifneq ($(USE_RTTI), 1)
	CXXFLAGS += -fno-rtti
else
	CXXFLAGS += -DROCKSDB_USE_RTTI
endif
166
else
Siying Dong's avatar
Siying Dong committed
167
168
169
170
171
172
ifneq ($(USE_RTTI), 0)
	CXXFLAGS += -DROCKSDB_USE_RTTI
else
	CXXFLAGS += -fno-rtti
endif

173
174
175
176
177
178
ifdef ASSERT_STATUS_CHECKED
ifeq ($(filter -DROCKSDB_ASSERT_STATUS_CHECKED,$(OPT)),)
	OPT += -DROCKSDB_ASSERT_STATUS_CHECKED
endif
endif

179
$(warning Warning: Compiling in debug mode. Don't use the resulting binary in production)
Igor Canadi's avatar
Igor Canadi committed
180
181
endif

182
#-----------------------------------------------
183
include src.mk
184

185
186
187
188
189
190
AM_DEFAULT_VERBOSITY = 0

AM_V_GEN = $(am__v_GEN_$(V))
am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
am__v_GEN_0 = @echo "  GEN     " $@;
am__v_GEN_1 =
191
192
193
194
AM_V_at = $(am__v_at_$(V))
am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
am__v_at_0 = @
am__v_at_1 =
195
196
197
198
199

AM_V_CC = $(am__v_CC_$(V))
am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
am__v_CC_0 = @echo "  CC      " $@;
am__v_CC_1 =
200

201
202
AM_V_CCLD = $(am__v_CCLD_$(V))
am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
203
ifneq ($(SKIP_LINK), 1)
204
205
am__v_CCLD_0 = @echo "  CCLD    " $@;
am__v_CCLD_1 =
206
207
208
209
else
am__v_CCLD_0 = @echo "  !CCLD   " $@; true skip
am__v_CCLD_1 = true skip
endif
210
211
212
213
AM_V_AR = $(am__v_AR_$(V))
am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY))
am__v_AR_0 = @echo "  AR      " $@;
am__v_AR_1 =
214

215
216
217
218
ifdef ROCKSDB_USE_LIBRADOS
LIB_SOURCES += utilities/env_librados.cc
LDFLAGS += -lrados
endif
219

220
AM_LINK = $(AM_V_CCLD)$(CXX) $^ $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS)
221

222
223
224
225
226
227
228
229
230
231
232
# Detect what platform we're building on.
# Export some common variables that might have been passed as Make variables
# instead of environment variables.
dummy := $(shell (export ROCKSDB_ROOT="$(CURDIR)"; \
                  export COMPILE_WITH_ASAN="$(COMPILE_WITH_ASAN)"; \
                  export COMPILE_WITH_TSAN="$(COMPILE_WITH_TSAN)"; \
                  export COMPILE_WITH_UBSAN="$(COMPILE_WITH_UBSAN)"; \
                  export PORTABLE="$(PORTABLE)"; \
                  export ROCKSDB_NO_FBCODE="$(ROCKSDB_NO_FBCODE)"; \
                  export USE_CLANG="$(USE_CLANG)"; \
                  "$(CURDIR)/build_tools/build_detect_platform" "$(CURDIR)/make_config.mk"))
Sanjay Ghemawat's avatar
Sanjay Ghemawat committed
233
# this file is generated by the previous line to set build flags and sources
Igor Canadi's avatar
Igor Canadi committed
234
include make_config.mk
235
export JAVAC_ARGS
236
CLEAN_FILES += make_config.mk
jorlow@chromium.org's avatar
jorlow@chromium.org committed
237

238
missing_make_config_paths := $(shell				\
239
	grep "\./\S*\|/\S*" -o $(CURDIR)/make_config.mk | 	\
240
241
242
243
244
	while read path;					\
		do [ -e $$path ] || echo $$path; 		\
	done | sort | uniq)

$(foreach path, $(missing_make_config_paths), \
245
	$(warning Warning: $(path) does not exist))
246

Tomas Kolda's avatar
Tomas Kolda committed
247
248
249
ifeq ($(PLATFORM), OS_AIX)
# no debug info
else ifneq ($(PLATFORM), IOS)
Igor Canadi's avatar
Igor Canadi committed
250
251
252
253
254
255
256
CFLAGS += -g
CXXFLAGS += -g
else
# no debug info for IOS, that will make our library big
OPT += -DNDEBUG
endif

Tomas Kolda's avatar
Tomas Kolda committed
257
258
259
260
261
ifeq ($(PLATFORM), OS_AIX)
ARFLAGS = -X64 rs
STRIPFLAGS = -X64 -x
endif

David Bernard's avatar
David Bernard committed
262
263
264
ifeq ($(PLATFORM), OS_SOLARIS)
	PLATFORM_CXXFLAGS += -D _GLIBCXX_USE_C99
endif
265
ifneq ($(filter -DROCKSDB_LITE,$(OPT)),)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
266
267
268
	# found
	CFLAGS += -fno-exceptions
	CXXFLAGS += -fno-exceptions
269
270
	# LUA is not supported under ROCKSDB_LITE
	LUA_PATH =
271
272
endif

Igor Canadi's avatar
Igor Canadi committed
273
274
# ASAN doesn't work well with jemalloc. If we're compiling with ASAN, we should use regular malloc.
ifdef COMPILE_WITH_ASAN
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
275
276
277
278
	DISABLE_JEMALLOC=1
	EXEC_LDFLAGS += -fsanitize=address
	PLATFORM_CCFLAGS += -fsanitize=address
	PLATFORM_CXXFLAGS += -fsanitize=address
Igor Canadi's avatar
Igor Canadi committed
279
280
281
282
endif

# TSAN doesn't work well with jemalloc. If we're compiling with TSAN, we should use regular malloc.
ifdef COMPILE_WITH_TSAN
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
283
	DISABLE_JEMALLOC=1
Siying Dong's avatar
Siying Dong committed
284
	EXEC_LDFLAGS += -fsanitize=thread
285
286
	PLATFORM_CCFLAGS += -fsanitize=thread -fPIC -DFOLLY_SANITIZE_THREAD
	PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC -DFOLLY_SANITIZE_THREAD
287
288
        # Turn off -pg when enabling TSAN testing, because that induces
        # a link failure.  TODO: find the root cause
dx9's avatar
dx9 committed
289
	PROFILING_FLAGS =
290
291
	# LUA is not supported under TSAN
	LUA_PATH =
292
293
294
	# Limit keys for crash test under TSAN to avoid error:
	# "ThreadSanitizer: DenseSlabAllocator overflow. Dying."
	CRASH_TEST_EXT_ARGS += --max_key=1000000
Igor Canadi's avatar
Igor Canadi committed
295
296
endif

Tomas Kolda's avatar
Tomas Kolda committed
297
298
299
300
301
# AIX doesn't work with -pg
ifeq ($(PLATFORM), OS_AIX)
	PROFILING_FLAGS =
endif

302
303
304
# USAN doesn't work well with jemalloc. If we're compiling with USAN, we should use regular malloc.
ifdef COMPILE_WITH_UBSAN
	DISABLE_JEMALLOC=1
Siying Dong's avatar
Siying Dong committed
305
306
307
308
	# Suppress alignment warning because murmurhash relies on casting unaligned
	# memory to integer. Fixing it may cause performance regression. 3-way crc32
	# relies on it too, although it can be rewritten to eliminate with minimal
	# performance regression.
309
310
311
	EXEC_LDFLAGS += -fsanitize=undefined -fno-sanitize-recover=all
	PLATFORM_CCFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -DROCKSDB_UBSAN_RUN
	PLATFORM_CXXFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -DROCKSDB_UBSAN_RUN
312
313
endif

314
315
316
317
318
ifdef ROCKSDB_VALGRIND_RUN
	PLATFORM_CCFLAGS += -DROCKSDB_VALGRIND_RUN
	PLATFORM_CXXFLAGS += -DROCKSDB_VALGRIND_RUN
endif

Igor Canadi's avatar
Igor Canadi committed
319
ifndef DISABLE_JEMALLOC
320
	ifdef JEMALLOC
Tamir Duberstein's avatar
Tamir Duberstein committed
321
322
		PLATFORM_CXXFLAGS += -DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE
		PLATFORM_CCFLAGS  += -DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE
323
	endif
324
325
326
327
	ifdef WITH_JEMALLOC_FLAG
		PLATFORM_LDFLAGS += -ljemalloc
		JAVA_LDFLAGS += -ljemalloc
	endif
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
328
329
330
	EXEC_LDFLAGS := $(JEMALLOC_LIB) $(EXEC_LDFLAGS)
	PLATFORM_CXXFLAGS += $(JEMALLOC_INCLUDE)
	PLATFORM_CCFLAGS += $(JEMALLOC_INCLUDE)
Igor Canadi's avatar
Igor Canadi committed
331
332
endif

333
334
335
336
ifndef USE_FOLLY_DISTRIBUTED_MUTEX
	USE_FOLLY_DISTRIBUTED_MUTEX=0
endif

Tamir Duberstein's avatar
Tamir Duberstein committed
337
338
export GTEST_THROW_ON_FAILURE=1
export GTEST_HAS_EXCEPTIONS=1
339
GTEST_DIR = third-party/gtest-1.8.1/fused-src
Tomas Kolda's avatar
Tomas Kolda committed
340
341
342
343
344
345
346
347
# AIX: pre-defined system headers are surrounded by an extern "C" block
ifeq ($(PLATFORM), OS_AIX)
	PLATFORM_CCFLAGS += -I$(GTEST_DIR)
	PLATFORM_CXXFLAGS += -I$(GTEST_DIR)
else
	PLATFORM_CCFLAGS += -isystem $(GTEST_DIR)
	PLATFORM_CXXFLAGS += -isystem $(GTEST_DIR)
endif
Igor Sugak's avatar
Igor Sugak committed
348

349
ifeq ($(USE_FOLLY_DISTRIBUTED_MUTEX),1)
350
351
352
353
354
355
356
357
358
359
	FOLLY_DIR = ./third-party/folly
	# AIX: pre-defined system headers are surrounded by an extern "C" block
	ifeq ($(PLATFORM), OS_AIX)
		PLATFORM_CCFLAGS += -I$(FOLLY_DIR)
		PLATFORM_CXXFLAGS += -I$(FOLLY_DIR)
	else
		PLATFORM_CCFLAGS += -isystem $(FOLLY_DIR)
		PLATFORM_CXXFLAGS += -isystem $(FOLLY_DIR)
	endif
endif
360
361
362
363
364

ifdef TEST_CACHE_LINE_SIZE
  PLATFORM_CCFLAGS += -DTEST_CACHE_LINE_SIZE=$(TEST_CACHE_LINE_SIZE)
  PLATFORM_CXXFLAGS += -DTEST_CACHE_LINE_SIZE=$(TEST_CACHE_LINE_SIZE)
endif
365

366
367
368
# This (the first rule) must depend on "all".
default: all

369
WARNING_FLAGS = -W -Wextra -Wall -Wsign-compare -Wshadow \
370
  -Wunused-parameter
371

372
373
374
375
ifeq ($(PLATFORM), OS_OPENBSD)
	WARNING_FLAGS += -Wno-unused-lambda-capture
endif

376
ifndef DISABLE_WARNING_AS_ERROR
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
377
	WARNING_FLAGS += -Werror
378
379
endif

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

ifdef LUA_PATH

ifndef LUA_INCLUDE
LUA_INCLUDE=$(LUA_PATH)/include
endif

LUA_INCLUDE_FILE=$(LUA_INCLUDE)/lualib.h

ifeq ("$(wildcard $(LUA_INCLUDE_FILE))", "")
# LUA_INCLUDE_FILE does not exist
$(error Cannot find lualib.h under $(LUA_INCLUDE).  Try to specify both LUA_PATH and LUA_INCLUDE manually)
endif
LUA_FLAGS = -I$(LUA_INCLUDE) -DLUA -DLUA_COMPAT_ALL
CFLAGS += $(LUA_FLAGS)
CXXFLAGS += $(LUA_FLAGS)

ifndef LUA_LIB
LUA_LIB = $(LUA_PATH)/lib/liblua.a
endif
ifeq ("$(wildcard $(LUA_LIB))", "") # LUA_LIB does not exist
$(error $(LUA_LIB) does not exist.  Try to specify both LUA_PATH and LUA_LIB manually)
endif
403
EXEC_LDFLAGS += $(LUA_LIB)
404
405
406

endif

407
408
409
ifeq ($(NO_THREEWAY_CRC32C), 1)
	CXXFLAGS += -DNO_THREEWAY_CRC32C
endif
410

Igor Canadi's avatar
Igor Canadi committed
411
CFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
Islam AbdelRahman's avatar
Islam AbdelRahman committed
412
CXXFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers
413

Sanjay Ghemawat's avatar
Sanjay Ghemawat committed
414
LDFLAGS += $(PLATFORM_LDFLAGS)
jorlow@chromium.org's avatar
jorlow@chromium.org committed
415

416
417
418
# If NO_UPDATE_BUILD_VERSION is set we don't update util/build_version.cc, but
# the file needs to already exist or else the build will fail
ifndef NO_UPDATE_BUILD_VERSION
419
date := $(shell date +%F)
Igor Canadi's avatar
Igor Canadi committed
420
ifdef FORCE_GIT_SHA
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
421
	git_sha := $(FORCE_GIT_SHA)
Igor Canadi's avatar
Igor Canadi committed
422
else
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
423
	git_sha := $(shell git rev-parse HEAD 2>/dev/null)
Igor Canadi's avatar
Igor Canadi committed
424
endif
425
gen_build_version = sed -e s/@@GIT_SHA@@/$(git_sha)/ -e s/@@GIT_DATE_TIME@@/$(date)/ util/build_version.cc.in
426
427
428
429
430
431

# Record the version of the source that we are compiling.
# We keep a record of the git revision in this file.  It is then built
# as a regular source file as part of the compilation process.
# One can run "strings executable_filename | grep _build_" to find
# the version of the source that we used to build the executable file.
432
433
FORCE:
util/build_version.cc: FORCE
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
434
435
436
437
438
	$(AM_V_GEN)rm -f $@-t
	$(AM_V_at)$(gen_build_version) > $@-t
	$(AM_V_at)if test -f $@; then					\
	  cmp -s $@-t $@ && rm -f $@-t || mv -f $@-t $@;		\
	else mv -f $@-t $@; fi
439
endif
440

441
LIBOBJECTS = $(LIB_SOURCES:.cc=.o)
442
443
444
445
ifeq ($(HAVE_POWER8),1)
LIB_CC_OBJECTS = $(LIB_SOURCES:.cc=.o)
LIBOBJECTS += $(LIB_SOURCES_C:.c=.o)
LIBOBJECTS += $(LIB_SOURCES_ASM:.S=.o)
Andrew Kryczka's avatar
Andrew Kryczka committed
446
447
else
LIB_CC_OBJECTS = $(LIB_SOURCES:.cc=.o)
448
449
endif

450
451
LIBOBJECTS += $(TOOL_LIB_SOURCES:.cc=.o)
MOCKOBJECTS = $(MOCK_LIB_SOURCES:.cc=.o)
452
453
454
ifeq ($(USE_FOLLY_DISTRIBUTED_MUTEX),1)
  FOLLYOBJECTS = $(FOLLY_SOURCES:.cpp=.o)
endif
jorlow@chromium.org's avatar
jorlow@chromium.org committed
455

Igor Sugak's avatar
Igor Sugak committed
456
GTEST = $(GTEST_DIR)/gtest/gtest-all.o
457
458
TESTUTIL = ./test_util/testutil.o
TESTHARNESS = ./test_util/testharness.o $(TESTUTIL) $(MOCKOBJECTS) $(GTEST)
459
VALGRIND_ERROR = 2
460
VALGRIND_VER := $(join $(VALGRIND_VER),valgrind)
461

462
VALGRIND_OPTS = --error-exitcode=$(VALGRIND_ERROR) --leak-check=full
463

omegaga's avatar
omegaga committed
464
BENCHTOOLOBJECTS = $(BENCH_LIB_SOURCES:.cc=.o) $(LIBOBJECTS) $(TESTUTIL)
465

466
467
ANALYZETOOLOBJECTS = $(ANALYZER_LIB_SOURCES:.cc=.o)

anand76's avatar
anand76 committed
468
ifeq ($(DEBUG_LEVEL),0)
469
STRESSTOOLOBJECTS = $(STRESS_LIB_SOURCES:.cc=.o) $(LIBOBJECTS) $(TESTUTIL)
anand76's avatar
anand76 committed
470
471
472
473
else
STRESSTOOLOBJECTS = $(STRESS_LIB_SOURCES:.cc=.o) $(LIBOBJECTS) $(TESTUTIL) \
	$(TESTHARNESS)
endif
474

Siying Dong's avatar
Siying Dong committed
475
EXPOBJECTS = $(LIBOBJECTS) $(TESTUTIL)
476

jorlow@chromium.org's avatar
jorlow@chromium.org committed
477
TESTS = \
478
	db_basic_test \
479
	db_with_timestamp_basic_test \
Ewout Prangsma's avatar
Ewout Prangsma committed
480
	db_encryption_test \
481
	db_test2 \
Siying Dong's avatar
Siying Dong committed
482
	external_sst_file_basic_test \
Siying Dong's avatar
Siying Dong committed
483
484
485
486
487
488
489
490
491
492
	auto_roll_logger_test \
	bloom_test \
	dynamic_bloom_test \
	c_test \
	checkpoint_test \
	crc32c_test \
	coding_test \
	inlineskiplist_test \
	env_basic_test \
	env_test \
493
	env_logger_test \
494
	io_posix_test \
495
	hash_test \
496
	random_test \
Siying Dong's avatar
Siying Dong committed
497
	thread_local_test \
498
	work_queue_test \
Siying Dong's avatar
Siying Dong committed
499
500
501
502
	rate_limiter_test \
	perf_context_test \
	iostats_context_test \
	db_wal_test \
503
	db_block_cache_test \
504
	db_test \
505
	db_logical_block_size_cache_test \
Yi Wu's avatar
Yi Wu committed
506
	db_blob_index_test \
507
	db_iter_test \
508
	db_iter_stress_test \
509
	db_log_iter_test \
510
	db_bloom_filter_test \
511
	db_compaction_filter_test \
512
	db_compaction_test \
513
	db_dynamic_level_test \
514
	db_flush_test \
515
	db_inplace_update_test \
Yi Wu's avatar
Yi Wu committed
516
	db_iterator_test \
517
	db_memtable_test \
518
	db_merge_operator_test \
519
	db_merge_operand_test \
520
	db_options_test \
521
	db_range_del_test \
522
	db_secondary_test \
Yi Wu's avatar
Yi Wu committed
523
	db_sst_test \
524
	db_tailing_iter_test \
525
	db_io_failure_test \
526
	db_properties_test \
527
	db_table_properties_test \
528
	db_statistics_test \
529
	db_write_test \
530
	error_handler_fs_test \
531
	autovector_test \
Yi Wu's avatar
Yi Wu committed
532
	blob_db_test \
Maysam Yabandeh's avatar
Maysam Yabandeh committed
533
	cleanable_test \
534
535
536
	column_family_test \
	table_properties_collector_test \
	arena_test \
537
	memkind_kmem_allocator_test \
538
	block_test \
539
	data_block_hash_index_test \
540
541
	cache_test \
	corruption_test \
542
	slice_test \
543
544
545
546
547
	slice_transform_test \
	dbformat_test \
	fault_injection_test \
	filelock_test \
	filename_test \
548
	random_access_file_reader_test \
549
	file_reader_writer_test \
550
	block_based_filter_block_test \
551
	block_based_table_reader_test \
552
	full_filter_block_test \
Maysam Yabandeh's avatar
Maysam Yabandeh committed
553
	partitioned_filter_block_test \
554
	hash_table_test \
555
556
557
558
559
560
	histogram_test \
	log_test \
	manual_compaction_test \
	mock_env_test \
	memtable_list_test \
	merge_helper_test \
561
	memory_test \
562
563
	merge_test \
	merger_test \
564
	util_merge_operators_test \
565
	options_file_test \
566
567
568
	reduce_levels_test \
	plain_table_db_test \
	comparator_db_test \
569
	external_sst_file_test \
570
	import_column_family_test \
571
572
	prefix_test \
	skiplist_test \
573
	write_buffer_manager_test \
574
	stringappend_test \
575
	cassandra_format_test \
576
	cassandra_functional_test \
577
578
	cassandra_row_merge_test \
	cassandra_serialize_test \
579
580
	ttl_test \
	backupable_db_test \
581
	cache_simulator_test \
582
	sim_cache_test \
583
584
585
586
587
588
589
590
591
	version_edit_test \
	version_set_test \
	compaction_picker_test \
	version_builder_test \
	file_indexer_test \
	write_batch_test \
	write_batch_with_index_test \
	write_controller_test\
	deletefile_test \
592
	obsolete_files_test \
593
	table_test \
594
	block_fetcher_test \
595
	delete_scheduler_test \
596
	options_test \
597
	options_settable_test \
598
	options_util_test \
599
	event_logger_test \
Anirban Rahut's avatar
Anirban Rahut committed
600
	timer_queue_test \
601
602
603
604
605
606
	cuckoo_table_builder_test \
	cuckoo_table_reader_test \
	cuckoo_table_db_test \
	flush_job_test \
	wal_manager_test \
	listener_test \
Andres Noetzli's avatar
Andres Noetzli committed
607
	compaction_iterator_test \
608
609
610
611
612
613
	compaction_job_test \
	thread_list_test \
	sst_dump_test \
	compact_files_test \
	optimistic_transaction_test \
	write_callback_test \
614
615
	heap_test \
	compact_on_deletion_collector_test \
agiardullo's avatar
agiardullo committed
616
	compaction_job_stats_test \
617
	option_change_migration_test \
618
	transaction_test \
619
	transaction_lock_mgr_test \
620
	ldb_cmd_test \
621
	persistent_cache_test \
622
	statistics_test \
623
	stats_history_test \
Yi Wu's avatar
Yi Wu committed
624
	lru_cache_test \
625
	object_registry_test \
Andrew Kryczka's avatar
Andrew Kryczka committed
626
	repair_test \
Andrew Kryczka's avatar
Andrew Kryczka committed
627
	env_timed_test \
628
	write_prepared_transaction_test \
629
	write_unprepared_transaction_test \
Zhongyi Xie's avatar
Zhongyi Xie committed
630
	db_universal_compaction_test \
Zhichao Cao's avatar
Zhichao Cao committed
631
	trace_analyzer_test \
632
	repeatable_thread_test \
633
	range_tombstone_fragmenter_test \
634
	range_del_aggregator_test \
635
	sst_file_reader_test \
636
	db_secondary_test \
haoyuhuang's avatar
haoyuhuang committed
637
	block_cache_tracer_test \
638
	block_cache_trace_analyzer_test \
Cheng Chang's avatar
Cheng Chang committed
639
	defer_test \
640
641
	blob_file_addition_test \
	blob_file_garbage_test \
642
	timer_test \
643
	db_with_timestamp_compaction_test \
644
	testutil_test \
645

Yi Wu's avatar
Yi Wu committed
646
647
PARALLEL_TEST = \
	backupable_db_test \
648
	db_bloom_filter_test \
Yi Wu's avatar
Yi Wu committed
649
650
	db_compaction_filter_test \
	db_compaction_test \
651
	db_merge_operator_test \
652
	db_sst_test \
Yi Wu's avatar
Yi Wu committed
653
654
	db_test \
	db_universal_compaction_test \
655
656
	db_wal_test \
	external_sst_file_test \
657
	import_column_family_test \
Yi Wu's avatar
Yi Wu committed
658
	fault_injection_test \
659
	file_reader_writer_test \
Yi Wu's avatar
Yi Wu committed
660
661
	inlineskiplist_test \
	manual_compaction_test \
662
663
	persistent_cache_test \
	table_test \
664
	transaction_test \
665
	transaction_lock_mgr_test \
666
	write_prepared_transaction_test \
667
	write_unprepared_transaction_test \
Yi Wu's avatar
Yi Wu committed
668

669
670
671
672
673
ifeq ($(USE_FOLLY_DISTRIBUTED_MUTEX),1)
	TESTS += folly_synchronization_distributed_mutex_test
	PARALLEL_TEST += folly_synchronization_distributed_mutex_test
endif

674
675
676
677
# options_settable_test doesn't pass with UBSAN as we use hack in the test
ifdef COMPILE_WITH_UBSAN
        TESTS := $(shell echo $(TESTS) | sed 's/\boptions_settable_test\b//g')
endif
678
679
680
ifdef ASSERT_STATUS_CHECKED
	# This is a new check for which we will add support incrementally. The
	# whitelist can be removed once support is fully added.
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
	TESTS_WHITELIST = \
		arena_test \
		autovector_test \
		blob_file_addition_test \
		blob_file_garbage_test \
		bloom_test \
		cassandra_format_test \
		cassandra_row_merge_test \
		cassandra_serialize_test \
		cleanable_test \
		coding_test \
		crc32c_test \
		dbformat_test \
		defer_test \
		dynamic_bloom_test \
		event_logger_test \
		file_indexer_test \
		folly_synchronization_distributed_mutex_test \
		hash_table_test \
		hash_test \
		heap_test \
		histogram_test \
		inlineskiplist_test \
		io_posix_test \
		iostats_context_test \
		memkind_kmem_allocator_test \
		merger_test \
		mock_env_test \
		object_registry_test \
710
		options_settable_test \
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
		options_test \
		random_test \
		range_del_aggregator_test \
		range_tombstone_fragmenter_test \
		repeatable_thread_test \
		skiplist_test \
		slice_test \
		statistics_test \
		thread_local_test \
		timer_queue_test \
		timer_test \
		util_merge_operators_test \
		version_edit_test \
		work_queue_test \
		write_controller_test \

	TESTS := $(filter $(TESTS_WHITELIST),$(TESTS))
	PARALLEL_TEST := $(filter $(TESTS_WHITELIST),$(PARALLEL_TEST))
729
endif
Islam AbdelRahman's avatar
Islam AbdelRahman committed
730
731
732
733
734
735
736
737
SUBSET := $(TESTS)
ifdef ROCKSDBTESTS_START
        SUBSET := $(shell echo $(SUBSET) | sed 's/^.*$(ROCKSDBTESTS_START)/$(ROCKSDBTESTS_START)/')
endif

ifdef ROCKSDBTESTS_END
        SUBSET := $(shell echo $(SUBSET) | sed 's/$(ROCKSDBTESTS_END).*//')
endif
738

739
TOOLS = \
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
740
741
742
	sst_dump \
	db_sanity_test \
	db_stress \
Igor Canadi's avatar
Igor Canadi committed
743
	write_stress \
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
744
745
746
	ldb \
	db_repl_stress \
	rocksdb_dump \
Yi Wu's avatar
Yi Wu committed
747
748
	rocksdb_undump \
	blob_dump \
Zhichao Cao's avatar
Zhichao Cao committed
749
	trace_analyzer \
750
	block_cache_trace_analyzer \
jorlow@chromium.org's avatar
jorlow@chromium.org committed
751

752
753
754
TEST_LIBS = \
	librocksdb_env_basic_test.a

755
# TODO: add back forward_iterator_bench, after making it build in all environemnts.
756
BENCHMARKS = db_bench table_reader_bench cache_bench memtablerep_bench filter_bench persistent_cache_bench range_del_aggregator_bench
jorlow@chromium.org's avatar
jorlow@chromium.org committed
757

758
# if user didn't config LIBNAME, set the default
759
ifeq ($(LIBNAME),)
760
761
# we should only run rocksdb in production with DEBUG_LEVEL 0
ifeq ($(DEBUG_LEVEL),0)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
762
        LIBNAME=librocksdb
763
764
765
else
        LIBNAME=librocksdb_debug
endif
766
endif
767
LIBRARY = ${LIBNAME}.a
768
TOOLS_LIBRARY = ${LIBNAME}_tools.a
769
STRESS_LIBRARY = ${LIBNAME}_stress.a
770

771
772
773
ROCKSDB_MAJOR = $(shell egrep "ROCKSDB_MAJOR.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_MINOR = $(shell egrep "ROCKSDB_MINOR.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_PATCH = $(shell egrep "ROCKSDB_PATCH.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
774

775
776
default: all

777
778
779
#-----------------------------------------------
# Create platform independent shared libraries.
#-----------------------------------------------
780
ifneq ($(PLATFORM_SHARED_EXT),)
heyongqiang's avatar
heyongqiang committed
781
782

ifneq ($(PLATFORM_SHARED_VERSIONED),true)
783
SHARED1 = ${LIBNAME}.$(PLATFORM_SHARED_EXT)
heyongqiang's avatar
heyongqiang committed
784
785
SHARED2 = $(SHARED1)
SHARED3 = $(SHARED1)
786
SHARED4 = $(SHARED1)
heyongqiang's avatar
heyongqiang committed
787
788
SHARED = $(SHARED1)
else
789
790
SHARED_MAJOR = $(ROCKSDB_MAJOR)
SHARED_MINOR = $(ROCKSDB_MINOR)
791
SHARED_PATCH = $(ROCKSDB_PATCH)
792
SHARED1 = ${LIBNAME}.$(PLATFORM_SHARED_EXT)
793
794
795
796
797
798
ifeq ($(PLATFORM), OS_MACOSX)
SHARED_OSX = $(LIBNAME).$(SHARED_MAJOR)
SHARED2 = $(SHARED_OSX).$(PLATFORM_SHARED_EXT)
SHARED3 = $(SHARED_OSX).$(SHARED_MINOR).$(PLATFORM_SHARED_EXT)
SHARED4 = $(SHARED_OSX).$(SHARED_MINOR).$(SHARED_PATCH).$(PLATFORM_SHARED_EXT)
else
799
800
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
801
SHARED4 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR).$(SHARED_PATCH)
802
endif
803
804
SHARED = $(SHARED1) $(SHARED2) $(SHARED3) $(SHARED4)
$(SHARED1): $(SHARED4)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
805
	ln -fs $(SHARED4) $(SHARED1)
806
$(SHARED2): $(SHARED4)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
807
	ln -fs $(SHARED4) $(SHARED2)
808
$(SHARED3): $(SHARED4)
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
809
	ln -fs $(SHARED4) $(SHARED3)
810
endif
811
812
813
814
815
816
817
ifeq ($(HAVE_POWER8),1)
SHARED_C_OBJECTS = $(LIB_SOURCES_C:.c=.o)
SHARED_ASM_OBJECTS = $(LIB_SOURCES_ASM:.S=.o)
SHARED_C_LIBOBJECTS = $(patsubst %.o,shared-objects/%.o,$(SHARED_C_OBJECTS))
SHARED_ASM_LIBOBJECTS = $(patsubst %.o,shared-objects/%.o,$(SHARED_ASM_OBJECTS))
shared_libobjects = $(patsubst %,shared-objects/%,$(LIB_CC_OBJECTS))
else
818
shared_libobjects = $(patsubst %,shared-objects/%,$(LIBOBJECTS))
819
820
endif

821
CLEAN_FILES += shared-objects
822
shared_all_libobjects = $(shared_libobjects)
823

824
825
826
827
828
829
830
831
832
ifeq ($(HAVE_POWER8),1)
shared-ppc-objects = $(SHARED_C_LIBOBJECTS) $(SHARED_ASM_LIBOBJECTS)

shared-objects/util/crc32c_ppc.o: util/crc32c_ppc.c
	$(AM_V_CC)$(CC) $(CFLAGS) -c $< -o $@

shared-objects/util/crc32c_ppc_asm.o: util/crc32c_ppc_asm.S
	$(AM_V_CC)$(CC) $(CFLAGS) -c $< -o $@
endif
833
$(shared_libobjects): shared-objects/%.o: %.cc
834
835
	$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@

836
837
838
839
ifeq ($(HAVE_POWER8),1)
shared_all_libobjects = $(shared_libobjects) $(shared-ppc-objects)
endif
$(SHARED4): $(shared_all_libobjects)
zhsj's avatar
zhsj committed
840
	$(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(shared_all_libobjects) $(LDFLAGS) -o $@
heyongqiang's avatar
heyongqiang committed
841
842
843

endif  # PLATFORM_SHARED_EXT

844
.PHONY: blackbox_crash_test check clean coverage crash_test ldb_tests package \
845
	release tags tags0 valgrind_check whitebox_crash_test format static_lib shared_lib all \
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
846
	dbg rocksdbjavastatic rocksdbjava install install-static install-shared uninstall \
847
	analyze tools tools_lib \
848
	blackbox_crash_test_with_atomic_flush whitebox_crash_test_with_atomic_flush  \
849
	blackbox_crash_test_with_txn whitebox_crash_test_with_txn
850

maurice barnum's avatar
maurice barnum committed
851

852
all: $(LIBRARY) $(BENCHMARKS) tools tools_lib test_libs $(TESTS)
853

854
855
all_but_some_tests: $(LIBRARY) $(BENCHMARKS) tools tools_lib test_libs $(SUBSET)

Igor Canadi's avatar
Igor Canadi committed
856
857
858
859
static_lib: $(LIBRARY)

shared_lib: $(SHARED)

860
861
stress_lib: $(STRESS_LIBRARY)

maurice barnum's avatar
maurice barnum committed
862
863
tools: $(TOOLS)

864
865
tools_lib: $(TOOLS_LIBRARY)

866
867
test_libs: $(TEST_LIBS)

maurice barnum's avatar
maurice barnum committed
868
dbg: $(LIBRARY) $(BENCHMARKS) tools $(TESTS)
869

870
# creates static library and programs
871
release:
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
872
	$(MAKE) clean
873
	DEBUG_LEVEL=0 $(MAKE) static_lib tools db_bench
874
875

coverage:
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
876
877
878
879
	$(MAKE) clean
	COVERAGEFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS+="-lgcov" $(MAKE) J=1 all check
	cd coverage && ./coverage_test.sh
        # Delete intermediate files
880
	$(FIND) . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \;
jorlow@chromium.org's avatar
jorlow@chromium.org committed
881

Yi Wu's avatar
Yi Wu committed
882
883
884
885
886
ifneq (,$(filter check parallel_check,$(MAKECMDGOALS)),)
# Use /dev/shm if it has the sticky bit set (otherwise, /tmp),
# and create a randomly-named rocksdb.XXXX directory therein.
# We'll use that directory in the "make check" rules.
ifeq ($(TMPD),)
Tomas Kolda's avatar
Tomas Kolda committed
887
888
TMPDIR := $(shell echo $${TMPDIR:-/tmp})
TMPD := $(shell f=/dev/shm; test -k $$f || f=$(TMPDIR);     \
Yi Wu's avatar
Yi Wu committed
889
890
891
892
893
894
895
896
897
898
899
900
901
902
  perl -le 'use File::Temp "tempdir";'					\
    -e 'print tempdir("'$$f'/rocksdb.XXXX", CLEANUP => 0)')
endif
endif

# Run all tests in parallel, accumulating per-test logs in t/log-*.
#
# Each t/run-* file is a tiny generated bourne shell script that invokes one of
# sub-tests. Why use a file for this?  Because that makes the invocation of
# parallel below simpler, which in turn makes the parsing of parallel's
# LOG simpler (the latter is for live monitoring as parallel
# tests run).
#
# Test names are extracted by running tests with --gtest_list_tests.
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
# This filter removes the "#"-introduced comments, and expands to
# fully-qualified names by changing input like this:
#
#   DBTest.
#     Empty
#     WriteEmptyBatch
#   MultiThreaded/MultiThreadedDBTest.
#     MultiThreaded/0  # GetParam() = 0
#     MultiThreaded/1  # GetParam() = 1
#
# into this:
#
#   DBTest.Empty
#   DBTest.WriteEmptyBatch
#   MultiThreaded/MultiThreadedDBTest.MultiThreaded/0
#   MultiThreaded/MultiThreadedDBTest.MultiThreaded/1
#

Yi Wu's avatar
Yi Wu committed
921
922
923
924
925
926
927
928
929
930
931
parallel_tests = $(patsubst %,parallel_%,$(PARALLEL_TEST))
.PHONY: gen_parallel_tests $(parallel_tests)
$(parallel_tests): $(PARALLEL_TEST)
	$(AM_V_at)TEST_BINARY=$(patsubst parallel_%,%,$@); \
  TEST_NAMES=` \
    ./$$TEST_BINARY --gtest_list_tests \
    | perl -n \
      -e 's/ *\#.*//;' \
      -e '/^(\s*)(\S+)/; !$$1 and do {$$p=$$2; break};'	\
      -e 'print qq! $$p$$2!'`; \
	for TEST_NAME in $$TEST_NAMES; do \
932
		TEST_SCRIPT=t/run-$$TEST_BINARY-$${TEST_NAME//\//-}; \
Yi Wu's avatar
Yi Wu committed
933
934
935
936
937
		echo "  GEN     " $$TEST_SCRIPT; \
    printf '%s\n' \
      '#!/bin/sh' \
      "d=\$(TMPD)$$TEST_SCRIPT" \
      'mkdir -p $$d' \
938
      "TEST_TMPDIR=\$$d $(DRIVER) ./$$TEST_BINARY --gtest_filter=$$TEST_NAME" \
Yi Wu's avatar
Yi Wu committed
939
940
941
942
943
944
945
946
		> $$TEST_SCRIPT; \
		chmod a=rx $$TEST_SCRIPT; \
	done

gen_parallel_tests:
	$(AM_V_at)mkdir -p t
	$(AM_V_at)rm -f t/run-*
	$(MAKE) $(parallel_tests)
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964

# Reorder input lines (which are one per test) so that the
# longest-running tests appear first in the output.
# Do this by prefixing each selected name with its duration,
# sort the resulting names, and remove the leading numbers.
# FIXME: the "100" we prepend is a fake time, for now.
# FIXME: squirrel away timings from each run and use them
# (when present) on subsequent runs to order these tests.
#
# Without this reordering, these two tests would happen to start only
# after almost all other tests had completed, thus adding 100 seconds
# to the duration of parallel "make check".  That's the difference
# between 4 minutes (old) and 2m20s (new).
#
# 152.120 PASS t/DBTest.FileCreationRandomFailure
# 107.816 PASS t/DBTest.EncodeDecompressedBlockSizeTest
#
slow_test_regexp = \
Yi Wu's avatar
Yi Wu committed
965
	^.*SnapshotConcurrentAccessTest.*$$|^t/run-table_test-HarnessTest.Randomized$$|^t/run-db_test-.*(?:FileCreationRandomFailure|EncodeDecompressedBlockSizeTest)$$|^.*RecoverFromCorruptedWALWithoutFlush$$
966
prioritize_long_running_tests =						\
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
967
968
969
  perl -pe 's,($(slow_test_regexp)),100 $$1,'				\
    | sort -k1,1gr							\
    | sed 's/^[.0-9]* //'
970
971
972
973
974
975

# "make check" uses
# Run with "make J=1 check" to disable parallelism in "make check".
# Run with "make J=200% check" to run two parallel jobs per core.
# The default is to run one job per core (J=100%).
# See "man parallel" for its "-j ..." option.
Yi Wu's avatar
Yi Wu committed
976
J ?= 100%
977

978
979
980
# Use this regexp to select the subset of tests whose names match.
tests-regexp = .

981
982
983
984
985
986
ifeq ($(PRINT_PARALLEL_OUTPUTS), 1)	
	parallel_com = '{}'
else
	parallel_com = '{} >& t/log-{/}'
endif

987
.PHONY: check_0
Yi Wu's avatar
Yi Wu committed
988
989
check_0:
	$(AM_V_GEN)export TEST_TMPDIR=$(TMPD); \
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
990
991
992
	printf '%s\n' ''						\
	  'To monitor subtest <duration,pass/fail,name>,'		\
	  '  run "make watch-log" in a separate window' '';		\
Yi Wu's avatar
Yi Wu committed
993
994
995
	test -t 1 && eta=--eta || eta=; \
	{ \
		printf './%s\n' $(filter-out $(PARALLEL_TEST),$(TESTS)); \
996
		find t -name 'run-*' -print; \
Yi Wu's avatar
Yi Wu committed
997
	} \
Yueh-Hsuan Chiang's avatar
Yueh-Hsuan Chiang committed
998
999
	  | $(prioritize_long_running_tests)				\
	  | grep -E '$(tests-regexp)'					\
1000
	  | build_tools/gnu_parallel -j$(J) --plain --joblog=LOG $$eta --gnu  $(parallel_com) ; \
For faster browsing, not all history is shown. View entire blame