forked from yahoo/mdbm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.base
271 lines (230 loc) · 8.51 KB
/
Makefile.base
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
# define a default target (expected to be in each makefile that includes us)
# otherwise, the first explicit rule defined here would arbitrarily be the default
default: default-make-target
############################################################
## Configuration section ##
############################################################
UNAME := $(shell uname)
# Uncomment to disable TSC (TimeStamp Counter) clock source.
DISABLE_TSC=1
# Enable 64-bit off_t
COMP_FLAGS += -D_FILE_OFFSET_BITS=64
# For Linux, use openssl.
COMP_FLAGS += -DUSE_OPENSSL
# To provide internal MD5 and SHA1 hash functions
#COMP_FLAGS += -DPROVIDE_SSL_HASHES
COMP_FLAGS += -DALLOW_MLOCK_RESET
# if uncommented, scales partitioned lock-count by the number of CPUs
#COMP_FLAGS += -DPARTITION_LOCK_CPU_MULTIPLIER=16
# if uncommented, sets the exact number of partitioned locks
# Overrides PARTITION_LOCK_CPU_MULTIPLIER
#COMP_FLAGS += -DPARTITION_LOCK_COUNT=128
ifeq ($(OS),Windows_NT)
SHLIB_EXT := dll
else ifeq ($(UNAME),Darwin)
SHLIB_EXT := dylib
else
SHLIB_EXT := so
endif
ifeq ($(UNAME), Linux)
# NOTE: we need to check RHEL6 or greater for robust-pthreads
COMP_FLAGS += -DHAVE_ROBUST_PTHREADS
# NOTE: windowed mode depends on linux-only remap_file_pages()
COMP_FLAGS += -DHAVE_WINDOWED_MODE
# add real-time lib for clock_gettime
LIBRT = -lrt
endif
ifneq ($(UNAME), Darwin)
# OSX doesn't have /proc, TODO check BSD
COMP_FLAGS += -DHAVE_PROC_FILESYS
endif
# readline support is for mash only
LINK_READLINE=-lreadline
LDADD += -lm -lpthread -lcrypto -lstdc++
ifeq ($(UNAME), Linux)
LIBDIR=/usr/local/lib64
else
LIBDIR=/usr/local/lib
endif
INCDIR=/usr/local/include
PERL=perl
TRUECMD=true # not /bin/true on OSX
# command for building reST documentation
SPHINXBUILD = /usr/bin/sphinx-build
INSTALL=install
ifeq ($(UNAME), Darwin) # homebrew
INSTALL=ginstall
endif
# NOTE: This is not double assignment. It creates an expression that the
# unit tests (e.g.) can evaulate to dynamically set LD_LIBRARY_PATH or
# DYLD_LIBRARY_PATH to use the locally build libs as they run the tests.
ifeq ($(UNAME), Darwin) # homebrew
LD_LIB_PATH=DYLD_LIBRARY_PATH=$(TOPDIR)/src/lib/$(OBJDIR):$(LD_LIBRARY_PATH)
else
LD_LIB_PATH=LD_LIBRARY_PATH=$(TOPDIR)/src/lib/$(OBJDIR):$(LD_LIBRARY_PATH)
endif
# Uncomment to set rpath to LIBDIR
#USE_RPATH=1
# assume 64-bit, comment out for 32-bit
# TODO auto-detect
ifneq ($(UNAME), Darwin)
ARCH_SUFFIX=64
endif
# where to install files:
#PREFIX=/usr/local
PREFIX ?= /tmp/install
BIN_PREFIX ?= $(PREFIX)/bin
PERL_PREFIX ?= $(PREFIX)
MAN_PREFIX ?= $(PREFIX)/share/man
INC_PREFIX ?= $(PREFIX)/include
############################################################
ifeq ($(strip $(YROOT_NAME)),)
# do nothing
else
# '-' because we don't care if it doesn't exist
-include $(TOPDIR)/yahoo/Makefile.base
endif
# Makefile debugging helper. Use `make echo_FOO' to display `FOO = $(FOO)'.
echo_%:
@echo "$* = ${$*}"
# Makefile debugging helper. Can also be used during package
# generation to extract information from the build environment.
# Use `make value_FOO' to display `$(FOO)'.
value_%:
@echo "${$*}"
make-recursive-%::
$(foreach DIR,$(SUBDIRS), $(MAKE) -C $(DIR) $(patsubst make-recursive-%,%,$@) && ) $(TRUECMD)
# automaticly perform some actions recursively
default-make-target: make-recursive-default-make-target
clean:: make-recursive-clean
test:: make-recursive-test
valg:: make-recursive-valg
profile::
$(MAKE) MODE=profile make-recursive-default-make-target
test-prof::
$(MAKE) MODE=profile make-recursive-test
test-fast::
$(MAKE) FAST=1 make-recursive-test
valg-fast::
$(MAKE) FAST=1 make-recursive-valg
test-prof-fast::
$(MAKE) MODE=profile FAST=1 make-recursive-test
install:: default-make-target make-recursive-install
OBJDIR_BASE=object
OBJDIR_PROF=$(OBJDIR_BASE).prof
ifeq ($(MODE),profile)
OBJDIR=$(OBJDIR_PROF)
COMP_FLAGS += -pg
else
OBJDIR=$(OBJDIR_BASE)
endif
LOCAL_LDADD = -L$(TOPDIR)/src/lib/$(OBJDIR)
COMP_FLAGS += -g -O2 -I/usr/include -I$(INCDIR) -I$(TOPDIR)/include -I. -Wall -fPIC
# OpenSSL is installed by default on macOS, but the library and headers are not.
# Thus here we'll check for an installation of OpenSSL with Homebrew,
# an unofficial but widely used package manager for macOS.
ifeq ($(UNAME),Darwin)
ifneq (,$(shell command -v brew))
ifneq (,$(shell brew ls --versions openssl))
COMP_FLAGS += -I$(shell brew --prefix openssl)/include
LDADD += -L$(shell brew --prefix openssl)/lib
endif # OpenSSL installed via Homebrew
endif # Homebrew installed
endif # Darwin
# get gcc version (space-separated components)
GCC_VER_SPC=$(shell gcc -dumpversion | tr '.' ' ')
# turn it into an integer, zero-padding minor and patch versions to 4 digits
GCC_VER_INT=$(shell printf "%d%04d%04d" $(GCC_VER_SPC))
# compare to minimum version 4.8.0
GCC_GTE_48=$(shell expr $(GCC_VER_INT) \>= 400080000)
PEDANTIC = -Wall -pedantic -Wno-variadic-macros -Wno-long-long -Wno-overlength-strings
# For clang, we need to ignore c99 extensions warnings it seems ...
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
PEDANTIC += -Wno-format-security -Wno-c99-extensions
else
PEDANTIC += -Wno-format-security -Wno-unused-result
endif
#PEDANTIC += -Wno-unused-value
# stop dead on warnings...
PEDANTIC += -Werror
ifeq ($(UNAME), Darwin)
PEDANTIC += -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-format
endif
# why doesn't gcc turn -Wunreachable-code on from -Wall....
# it turns out that gcc 4.4.6 (RHEL6) has false positives, 4.8.2 works
ifeq ("$(GCC_GTE_48)", "1")
PEDANTIC += -Wunreachable-code
endif
ifeq ($(DISABLE_TSC),1)
COMP_FLAGS += -DDISABLE_TSC
endif
# Add common compiler flags to both C and C++
CFLAGS += $(COMP_FLAGS)
CXXFLAGS += $(COMP_FLAGS)
ifneq (,$(shell $(CC) --version | grep clang))
# allow for empty macro args, etc. under clang compiler
CFLAGS += -std=gnu99
CXXFLAGS += -std=c++11
endif
# implicit rules to make object files from source
$(OBJDIR)/%.o: %.c
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) $(PEDANTIC) -c $< -o $@
$(OBJDIR)/%.o: %.cc
@mkdir -p $(OBJDIR)
$(CC) $(CXXFLAGS) $(PEDANTIC) -c $< -o $@
#$(OBJDIR)/%.o: %.cpp
# @mkdir -p $(OBJDIR)
# $(CC) $(CFLAGS) $(PEDANTIC) -c $< -o $@
# TODO ensure we have all gcov generated files
CLEAN_OBJECTS:=*.o *.d *.lib *.$(SHLIB_EXT).* *.xml *.gcov *.gcda
CLEAN_OB_DIRS=. $(OBJDIR_BASE) $(OBJDIR_PROF)
.PHONY: clean-objs
clean-objs:
$(foreach DIR,$(CLEAN_OB_DIRS), rm -f $(foreach OB,$(CLEAN_OBJECTS),$(DIR)/$(OB));)
# Because this routine is eval'd, it cannot use local variables. Local
# variable evaluation will produce the previous setting instead of the
# new setting.
# The double escaping of dollar signs `$$$$' is requied due to the
# caller eval'ing the generated result.
# $1 - exe name -- The caller must ensure that there is no whitespace
# $2 - any extra object files to be built/linked
# $3 - any extra build options
define ExeTargetRules
#.PHONY: $(OBJDIR)/$(1)
$(OBJDIR)/$(1): $(COMMON_SOURCES:%.c=$(OBJDIR)/%.o) $(2) $(HEADERS) $(1).c
@mkdir -p $(OBJDIR)
@#@echo 'building '$(1)' from ('$$^') common=('$(COMMON_SOURCES:.cc=.o)')';
@# NOTE: we have to explicitly protect filter-out and ^ from immediate expansion
@# with a double-dollar sign
$(CC) $(CFLAGS) $(PEDANTIC) $$(filter-out %.h %.hh,$$^) $(LDADD) $(3) -fPIC -o $(OBJDIR)/$(1)
.PHONY: clean-exe-$(1)
clean-exe-$(1):
$(foreach DIR,. $(OBJDIR_BASE) $(OBJDIR_PROF), rm -f $(DIR)/$(1);)
.PHONY: run-$(1)
run-$(1): $(OBJDIR)/$(1)
@echo; echo "###### Running " $(1) "######"; echo
$(LD_LIB_PATH) $(RUN_PREFIX) $(OBJDIR)/$(strip $1) $(RUN_ARGS)
valg-$(1): $(OBJDIR)/$(1)
@echo; echo "###### Running " $(1) " (valgrind) ######"; echo
$(LD_LIB_PATH) VALG=1 $(RUN_PREFIX) ./valgrind_runner.sh $(OBJDIR)/$(strip $1) $(RUN_ARGS)
endef
define CppExeTargetRules
#.PHONY: $(OBJDIR)/$(1)
$(OBJDIR)/$(1): $(COMMON_SOURCES:%.c=$(OBJDIR)/%.o) $(2) $(HEADERS) $(1).cc
@mkdir -p $(OBJDIR)
@#@echo 'building '$(1)' from ('$$^') common=('$(COMMON_SOURCES:.cc=.o)')';
@# NOTE: we have to explicitly protect filter-out and ^ from immediate expansion
@# with a double-dollar sign
$(CXX) $(CXXFLAGS) $(PEDANTIC) $$(filter-out %.h %.hh,$$^) $(LDADD) $(3) -fPIC -o $(OBJDIR)/$(1)
.PHONY: clean-exe-$(1)
clean-exe-$(1):
$(foreach DIR,. $(OBJDIR_BASE) $(OBJDIR_PROF), rm -f $(DIR)/$(1);)
.PHONY: run-$(1)
run-$(1): $(OBJDIR)/$(1)
@echo; echo "###### Running " $(1) "######"; echo
$(LD_LIB_PATH) $(RUN_PREFIX) $(OBJDIR)/$(strip $1) $(RUN_ARGS)
valg-$(1): $(OBJDIR)/$(1)
@echo; echo "###### Running " $(1) " (valgrind) ######"; echo
$(LD_LIB_PATH) VALG=1 $(RUN_PREFIX) ./valgrind_runner.sh $(OBJDIR)/$(strip $1) $(RUN_ARGS)
endef