-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
158 lines (129 loc) · 4.29 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
CLEAN_FILES = # deliberately empty, so we can append below.
CXX=g++
LDFLAGS= -lpthread -lrt
CXXFLAGS= -g -std=c++11 -fno-builtin-memcmp -msse -msse4.2 -pipe -fPIC
PROFILING_FLAGS=-pg
ARFLAGS = rs
OPT=
# Set the default DEBUG_LEVEL to 0
DEBUG_LEVEL?=0
ifeq ($(MAKECMDGOALS),dbg)
DEBUG_LEVEL=2 # compatible with rocksdb
endif
# compile with -O2 if for release
# if we're compiling for release, compile without debug code (-DNDEBUG) and
# don't treat warnings as errors
ifeq ($(DEBUG_LEVEL),0)
DISABLE_WARNING_AS_ERROR=1
OPT += -O2 -fno-omit-frame-pointer -DNDEBUG
else
$(warning Warning: Compiling in debug mode. Don't use the resulting binary in production)
OPT += -O0 $(PROFILING_FLAGS)
endif
# if complie with lockless, the security of the same Key operation is guaranteed
# by the upper layer
ifeq ($(LOCKLESS),true)
OPT += -DLOCKLESS
endif
#-----------------------------------------------
SRC_DIR=./src
DEPS_DIR=./deps
VERSION_CC=$(SRC_DIR)/build_version.cc
LIB_SOURCES := $(VERSION_CC) \
$(filter-out $(VERSION_CC), $(wildcard $(SRC_DIR)/*.cc))
ifndef ROCKSDB_PATH
$(warning Warning: missing rocksdb path, using default)
ROCKSDB_PATH=$(DEPS_DIR)/rocksdb
endif
ROCKSDB_INCLUDE_DIR=$(ROCKSDB_PATH)/include
ROCKSDB_LIBRARY=$(ROCKSDB_PATH)/librocksdb.a
ifndef SLASH_PATH
$(warning Warning: missing slash path, using default)
SLASH_PATH=$(DEPS_DIR)/slash
endif
SLASH_INCLUDE_DIR=$(SLASH_PATH)
SLASH_LIBRARY=$(SLASH_PATH)/slash/lib/libslash.a
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 =
AM_V_at = $(am__v_at_$(V))
am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
am__v_at_0 = @
am__v_at_1 =
AM_V_CXX = $(am__v_CXX_$(V))
am__v_CXX_ = $(am__v_CXX_$(AM_DEFAULT_VERBOSITY))
am__v_CXX_0 = @echo " CXX " $@;
am__v_CXX_1 =
LD = $(CXX)
AM_V_LD = $(am__v_LD_$(V))
am__v_LD_ = $(am__v_LD_$(AM_DEFAULT_VERBOSITY))
am__v_LD_0 = @echo " LD " $@;
am__v_LD_1 =
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 =
AM_LINK = $(AM_V_LD)$(CXX) $^ -o $@ $(LDFLAGS)
# This (the first rule) must depend on "all".
default: all
WARNING_FLAGS = -W -Wextra -Wall -Wsign-compare \
-Wno-unused-parameter -Wno-redundant-decls -Wwrite-strings \
-Wpointer-arith -Wreorder -Wswitch -Wsign-promo \
-Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers
ifndef DISABLE_WARNING_AS_ERROR
WARNING_FLAGS += -Werror
endif
CXXFLAGS += $(WARNING_FLAGS) -I. -I./include -I$(ROCKSDB_INCLUDE_DIR) -I$(ROCKSDB_PATH) -I$(SLASH_INCLUDE_DIR) $(OPT)
date := $(shell date +%F)
git_sha := $(shell git rev-parse HEAD 2>/dev/null)
gen_build_version = sed -e s/@@GIT_SHA@@/$(git_sha)/ -e s/@@GIT_DATE_TIME@@/$(date)/ $(SRC_DIR)/build_version.cc.in
# 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.
CLEAN_FILES += $(SRC_DIR)/build_version.cc
$(SRC_DIR)/build_version.cc: FORCE
$(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
FORCE:
LIBOBJECTS = $(LIB_SOURCES:.cc=.o)
# if user didn't config LIBNAME, set the default
ifeq ($(LIBNAME),)
# we should only run blackwidow in production with DEBUG_LEVEL 0
LIBNAME=libblackwidow
ifeq ($(DEBUG_LEVEL),0)
LIBNAME=libblackwidow
else
LIBNAME=libblackwidow_debug
endif
endif
LIBOUTPUT = ./lib
dummy := $(shell mkdir -p $(LIBOUTPUT))
LIBRARY = $(LIBOUTPUT)/${LIBNAME}.a
.PHONY: clean dbg static_lib all example
all: $(LIBRARY)
static_lib: $(LIBRARY)
dbg: $(LIBRARY)
test:
make test -C ./tests
example:
make -C ./examples
$(LIBRARY): $(LIBOBJECTS)
$(AM_V_AR)rm -f $@
$(AM_V_at)$(AR) $(ARFLAGS) $@ $(LIBOBJECTS)
clean:
make -C ./examples clean
make -C ./tests clean
rm -f $(LIBRARY)
rm -rf $(CLEAN_FILES)
rm -rf $(LIBOUTPUT)
find . -name "*.[oda]*" -path "$(SRC_DIR)/*" -exec rm -rf {} \;
find . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \;
%.o: %.cc
$(AM_V_CXX)$(CXX) $(CXXFLAGS) -c $< -o $@