forked from rockeet/nark-serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
292 lines (234 loc) · 8.26 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
280
281
282
283
284
285
286
287
288
289
290
291
DBG_FLAGS ?= -g3 -D_DEBUG
RLS_FLAGS ?= -O3 -DNDEBUG
ifeq "$(origin LD)" "default"
LD := ${CXX}
endif
COMPILER := $(shell ${CXX} --version | head -1 | awk '{split($$3, Ver, "."); printf("%s-%d.%d", $$1, Ver[1], Ver[2]);}')
#$(error COMPILER=${COMPILER})
UNAME_MachineSystem := $(shell uname -m -s | sed 's:[ /]:-:g')
BUILD_ROOT := build/${COMPILER}-${UNAME_MachineSystem}
ddir:=${BUILD_ROOT}/dbg
rdir:=${BUILD_ROOT}/rls
gen_sh := $(dir $(lastword ${MAKEFILE_LIST}))gen_env_conf.sh
err := $(shell env BOOST_INC=${BOOST_INC} bash ${gen_sh} "${CXX}" ${COMPILER} ${BUILD_ROOT}/env.mk; echo $$?)
ifneq "${err}" "0"
$(error err = ${err} MAKEFILE_LIST = ${MAKEFILE_LIST}, PWD = ${PWD}, gen_sh = ${gen_sh} "${CXX}" ${COMPILER} ${BUILD_ROOT}/env.mk)
endif
FEBIRD_INC := -Isrc
FEBIRD_INC += -I../nark-bone/src
include ${BUILD_ROOT}/env.mk
UNAME_System := $(shell uname | sed 's/^\([0-9a-zA-Z]*\).*/\1/')
ifeq (CYGWIN, ${UNAME_System})
FPIC =
# lazy expansion
CYGWIN_LDFLAGS = -Wl,--out-implib=$@ \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import
DLL_SUFFIX = .dll.a
CYG_DLL_FILE = $(shell echo $@ | sed 's:\(.*\)/lib\([^/]*\)\.a$$:\1/cyg\2:')
else
FPIC = -fPIC
DLL_SUFFIX = .so
CYG_DLL_FILE = $@
endif
override CFLAGS += ${FPIC}
override CXXFLAGS += ${FPIC}
override LDFLAGS += ${FPIC}
ifeq "$(shell expr substr ${COMPILER} 1 3)" "g++"
override LDFLAGS += -rdynamic
override CXXFLAGS += -time
ifeq "$(shell echo ${COMPILER} | awk -F- '{if ($$2 >= 4.8) print 1;}')" "1"
CXX_STD := -std=gnu++1y
endif
endif
ifeq "${CXX_STD}" ""
CXX_STD := -std=gnu++11
endif
# icc or icpc
ifeq "$(shell expr substr ${COMPILER} 1 2)" "ic"
override CXXFLAGS += -xHost -fasm-blocks
CPU = -xHost
else
CPU = -march=native
COMMON_C_FLAGS += -Wno-deprecated-declarations
COMMON_C_FLAGS += -fstrict-aliasing
COMMON_C_FLAGS += -Wstrict-aliasing=3
endif
COMMON_C_FLAGS = -Wformat=2 -Wcomment
COMMON_C_FLAGS += -Wall -Wextra
COMMON_C_FLAGS += -Wno-unused-parameter
COMMON_C_FLAGS += -D_GNU_SOURCE
#-v #-Wall -Wparentheses
#COMMON_C_FLAGS += ${COMMON_C_FLAGS} -Wpacked -Wpadded -v
#COMMON_C_FLAGS += ${COMMON_C_FLAGS} -Winvalid-pch
#COMMON_C_FLAGS += ${COMMON_C_FLAGS} -fmem-report
ifeq "$(shell expr substr ${COMPILER} 1 5)" "clang"
COMMON_C_FLAGS += -fcolor-diagnostics
endif
#CXXFLAGS +=
#CXXFLAGS += -fpermissive
#CXXFLAGS += -fexceptions
#CXXFLAGS += -fdump-translation-unit -fdump-class-hierarchy
override CFLAGS += ${COMMON_C_FLAGS}
override CXXFLAGS += ${COMMON_C_FLAGS}
DEFS := -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
override CFLAGS += ${DEFS}
override CXXFLAGS += ${DEFS}
override INCS := ${FEBIRD_INC} ${INCS}
ifeq (, $(findstring ${BOOST_INC}, ${INCS} /usr/include /usr/local/include))
override INCS += -I${BOOST_INC}
endif
ifeq (, $(findstring ${BOOST_LIB}, /usr/lib64 /usr/lib /usr/local/lib))
override LIBS += -L${BOOST_LIB}
endif
override LIBS += -L../nark-bone/lib
#override INCS += -I/usr/include
LIBS += -L/usr/local/lib64 -L/usr/local/lib
LIBS += -L/usr/lib64 -L/usr/lib
extf = -pie -fno-stack-protector
#extf+=-fno-stack-protector-all
override CFLAGS += ${extf}
#override CFLAGS += -g3
override CXXFLAGS += ${extf}
#override CXXFLAGS += -g3
#CXXFLAGS += -fnothrow-opt
ifeq (, ${prefix})
ifeq (root, ${USER})
prefix := /usr
else
prefix := /home/${USER}
endif
endif
zip_src := \
src/nark/io/BzipStream.cpp \
src/nark/io/GzipStream.cpp
serialization_src := \
$(wildcard src/nark/*.cpp) \
$(wildcard src/nark/io/*.cpp) \
$(wildcard src/nark/util/*.cpp) \
${obsoleted_src}
serialization_src := $(filter-out ${zip_src}, ${serialization_src})
#function definition
#@param:${1} -- targets var prefix, such as bdb_util | serialization
#@param:${2} -- build type: d | r
objs = $(addprefix ${${2}dir}/, $(addsuffix .o, $(basename ${${1}_src})))
re2_d_o := $(call objs,re2,d)
re2_r_o := $(call objs,re2,r)
serialization_d_o := $(call objs,serialization,d)
serialization_r_o := $(call objs,serialization,r)
serialization_d := lib/libnark-serialization-${COMPILER}-d${DLL_SUFFIX}
serialization_r := lib/libnark-serialization-${COMPILER}-r${DLL_SUFFIX}
static_serialization_d := lib/libnark-serialization-${COMPILER}-d.a
static_serialization_r := lib/libnark-serialization-${COMPILER}-r.a
ALL_TARGETS = serialization
DBG_TARGETS = ${serialization_d}
RLS_TARGETS = ${serialization_r}
.PHONY : serialization
serialization: ${serialization_d} ${serialization_r} ${static_serialization_d} ${static_serialization_r}
allsrc = ${serialization_src}
alldep = $(addprefix ${rdir}/, $(addsuffix .dep, $(basename ${allsrc}))) \
$(addprefix ${ddir}/, $(addsuffix .dep, $(basename ${allsrc})))
.PHONY : dbg rls
dbg: ${DBG_TARGETS}
rls: ${RLS_TARGETS}
${serialization_d} : LIBS += -lnark-bone-d
${serialization_r} : LIBS += -lnark-bone-d
${serialization_d} ${serialization_r} : LIBS += -lrt
${serialization_d}:${serialization_d_o}
${serialization_r}:${serialization_r_o}
${static_serialization_d}:${serialization_d_o}
${static_serialization_r}:${serialization_r_o}
%${DLL_SUFFIX}:
@echo "----------------------------------------------------------------------------------"
@echo "Creating dynamic library: $@"
@echo BOOST_INC=${BOOST_INC} BOOST_SUFFIX=${BOOST_SUFFIX}
@echo -e "OBJS:" $(addprefix "\n ",$(sort $(filter %.o,$^)))
@echo -e "LIBS:" $(addprefix "\n ",${LIBS})
@mkdir -p lib
@ln -sfT $(notdir $@) $(subst -${COMPILER},, $@)
@${LD} -shared $(sort $(filter %.o,$^)) ${LDFLAGS} ${LIBS} -o ${CYG_DLL_FILE} ${CYGWIN_LDFLAGS}
ifeq (CYGWIN, ${UNAME_System})
@cp -l -f ${CYG_DLL_FILE} /usr/bin
endif
%.a:
@echo "----------------------------------------------------------------------------------"
@echo "Creating static library: $@"
@echo BOOST_INC=${BOOST_INC} BOOST_SUFFIX=${BOOST_SUFFIX}
@echo -e "OBJS:" $(addprefix "\n ",$(sort $(filter %.o,$^)))
@echo -e "LIBS:" $(addprefix "\n ",${LIBS})
@mkdir -p lib
@ln -sfT $(notdir $@) $(subst -${COMPILER},, $@)
@${AR} rcs $@ $(filter %.o,$^)
.PHONY : install
install : serialization
cp lib/* ${prefix}/lib/
.PHONY : clean
clean:
-rm -rf lib/libnark* ${BUILD_ROOT} ${PRECOMPILED_HEADER_GCH}
.PHONY : depends
depends : ${alldep}
-include ${alldep}
${ddir}/%.o: %.cpp
@echo file: $< "->" $@
@echo FEBIRD_INC=${FEBIRD_INC}
@echo BOOST_INC=${BOOST_INC} BOOST_SUFFIX=${BOOST_SUFFIX}
mkdir -p $(dir $@)
${CXX} ${CXX_STD} ${CPU} -c ${DBG_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${rdir}/%.o: %.cpp
@echo file: $< "->" $@
@echo FEBIRD_INC=${FEBIRD_INC}
@echo BOOST_INC=${BOOST_INC} BOOST_SUFFIX=${BOOST_SUFFIX}
mkdir -p $(dir $@)
${CXX} ${CXX_STD} ${CPU} -c ${RLS_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${ddir}/%.o: %.cc
@echo file: $< "->" $@
@echo FEBIRD_INC=${FEBIRD_INC}
@echo BOOST_INC=${BOOST_INC} BOOST_SUFFIX=${BOOST_SUFFIX}
mkdir -p $(dir $@)
${CXX} ${CXX_STD} ${CPU} -c ${DBG_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${rdir}/%.o: %.cc
@echo file: $< "->" $@
@echo FEBIRD_INC=${FEBIRD_INC}
@echo BOOST_INC=${BOOST_INC} BOOST_SUFFIX=${BOOST_SUFFIX}
mkdir -p $(dir $@)
${CXX} ${CXX_STD} ${CPU} -c ${RLS_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${ddir}/%.o : %.c
@echo file: $< "->" $@
mkdir -p $(dir $@)
${CC} -c ${CPU} ${DBG_FLAGS} ${CFLAGS} ${INCS} $< -o $@
${rdir}/%.o : %.c
@echo file: $< "->" $@
mkdir -p $(dir $@)
${CC} -c ${CPU} ${RLS_FLAGS} ${CFLAGS} ${INCS} $< -o $@
${ddir}/%.s : %.cpp ${PRECOMPILED_HEADER_GCH}
@echo file: $< "->" $@
${CXX} -S ${CPU} ${DBG_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${rdir}/%.s : %.cpp ${PRECOMPILED_HEADER_GCH}
@echo file: $< "->" $@
${CXX} -S ${CPU} ${RLS_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${ddir}/%.s : %.c ${PRECOMPILED_HEADER_GCH}
@echo file: $< "->" $@
${CC} -S ${CPU} ${DBG_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${rdir}/%.s : %.c ${PRECOMPILED_HEADER_GCH}
@echo file: $< "->" $@
${CC} -S ${CPU} ${RLS_FLAGS} ${CXXFLAGS} ${INCS} $< -o $@
${rdir}/%.dep : %.c
@echo file: $< "->" $@
@echo INCS = ${INCS}
mkdir -p $(dir $@)
${CC} -M -MT $(basename $@).o ${INCS} $< > $@
${ddir}/%.dep : %.c
@echo file: $< "->" $@
@echo INCS = ${INCS}
mkdir -p $(dir $@)
${CC} -M -MT $(basename $@).o ${INCS} $< > $@
${rdir}/%.dep : %.cpp
@echo file: $< "->" $@
@echo INCS = ${INCS}
mkdir -p $(dir $@)
${CXX} -M -MT $(basename $@).o ${INCS} $< > $@
${ddir}/%.dep : %.cpp
@echo file: $< "->" $@
@echo INCS = ${INCS}
mkdir -p $(dir $@)
${CXX} -M -MT $(basename $@).o ${INCS} $< > $@