forked from logicalclocks/rondis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
188 lines (152 loc) · 4.9 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
CLEAN_FILES = # deliberately empty, so we can append below.
CXX=g++
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LDFLAGS= -lpthread
else
LDFLAGS= -lpthread -lrt
endif
CXXFLAGS= -g -std=c++11 -fno-builtin-memcmp -pipe -fPIC
ifeq ($(shell uname -m), x86_64)
CXXFLAGS += -msse -msse4.2
endif
ifeq ($(UNAME_S),Darwin)
CXXFLAGS += -I/opt/homebrew/include
endif
PROFILING_FLAGS=-pg
ARFLAGS = rs
OPT=
# Set the default DEBUG_LEVEL to 0
DEBUG_LEVEL?=0
NO_PB?=0
ifeq ($(NO_PB),0)
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -L/opt/homebrew/lib
else
LDFLAGS+= -lprotobuf
endif
endif
ifeq ($(MAKECMDGOALS),dbg)
DEBUG_LEVEL=2 # compatible with rocksdb
endif
ifeq ($(ENABLE_SSL),1)
OPT += -D__ENABLE_SSL
endif
OPT += -std=c++17
# 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 -D__XDEBUG__ $(PROFILING_FLAGS)
endif
#-----------------------------------------------
SRC_DIR=src
VERSION_CC=$(SRC_DIR)/build_version.cc
LIB_SOURCES := $(VERSION_CC) \
$(filter-out $(VERSION_CC), $(wildcard $(SRC_DIR)/*.cc))
ifeq ($(NO_PB),1)
LIB_SOURCES = $(VERSION_CC) \
$(filter-out $(VERSION_CC) $(wildcard $(SRC_DIR)/pb_*), $(wildcard $(SRC_DIR)/*.cc))
endif
SLASH_PATH=$(CURDIR)/third/slash
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$(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 pink in production with DEBUG_LEVEL 0
ifeq ($(DEBUG_LEVEL),0)
LIBNAME=libpink
else
LIBNAME=libpink_debug
endif
endif
LIBOUTPUT = ./lib
dummy := $(shell mkdir -p $(LIBOUTPUT))
LIBRARY = $(LIBOUTPUT)/${LIBNAME}.a
TESTS = test/pink_thread_test
.PHONY: clean dbg static_lib all rondis example
all: $(LIBRARY) rondis
static_lib: $(LIBRARY)
example:
@make -C examples PINK_PATH=$(CURDIR)/.. SLASH_PATH=$(SLASH_PATH) DEBUG_LEVEL=$(DEBUG_LEVEL)
rondis:
@make -C rondis PINK_PATH=$(CURDIR)/.. SLASH_PATH=$(SLASH_PATH) DEBUG_LEVEL=$(DEBUG_LEVEL)
check: $(LIBRARY)
@make -C test PINK_PATH=$(CURDIR)/.. SLASH_PATH=$(SLASH_PATH)
for t in $(notdir $(TESTS)); do echo "***** Running $$t"; ./test/$$t || exit 1; done
dbg: $(LIBRARY)
$(LIBRARY): $(LIBOBJECTS)
$(AM_V_AR)rm -f $@
$(AM_V_at)$(AR) $(ARFLAGS) $@ $(LIBOBJECTS)
clean:
make -C ./examples clean
make -C ./rondis clean
rm -f $(LIBRARY)
rm -rf $(CLEAN_FILES)
rm -rf $(LIBOUTPUT)
rm -f $(TESTS)
find . -name "*.[oda]*" ! -path "./third/*" -exec rm -f {} \;
find . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \;
%.o: %.cc
$(AM_V_CXX)$(CXX) $(CXXFLAGS) -c $< -o $@
%.d: %.cc
@set -e; rm -f $@; $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$; \
sed 's,\($(notdir $*)\)\.o[ :]*,$(SRC_DIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
ifneq ($(MAKECMDGOALS),clean)
-include $(LIBOBJECTS:.o=.d)
endif