-
Notifications
You must be signed in to change notification settings - Fork 160
/
build.sh
executable file
·532 lines (497 loc) · 14.5 KB
/
build.sh
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
basepath=$(
cd $(dirname $0)
pwd
)
declare down_dir="${basepath}/tmp_down_dir"
declare build_dir="${basepath}/tmp_build_dir"
declare packet_dir="${basepath}/tmp_packet_dir"
declare install_lib_dir="${basepath}/bin"
declare static_package_dir="${basepath}/tmp_static_package_dir"
declare fname_openssl="openssl*.tar.gz"
declare fname_libevent="libevent*.zip"
declare fname_jsoncpp="jsoncpp*.zip"
declare fname_boost="boost*.tar.gz"
declare fname_openssl_down="openssl-1.1.1d.tar.gz"
declare fname_libevent_down="release-2.1.11-stable.zip"
declare fname_jsoncpp_down="0.10.7.zip"
declare fname_boost_down="1.78.0/boost_1_78_0.tar.gz"
PrintParams() {
echo "=========================================one key build help============================================"
echo "sh build.sh [no build libevent:noEvent] [no build json:noJson] [no build boost:noBoost] [ execution test:test]"
echo "usage: sh build.sh noJson noEvent noBoost test"
echo "=========================================one key build help============================================"
echo ""
}
if test "$(uname)" = "Linux"; then
declare cpu_num=$(cat /proc/cpuinfo | grep "processor" | wc -l)
elif test "$(uname)" = "Darwin" ; then
declare cpu_num=$(sysctl -n machdep.cpu.thread_count)
fi
declare need_build_openssl=1
declare need_build_libevent=1
declare need_build_jsoncpp=1
declare need_build_boost=1
declare enable_asan=0
declare enable_lsan=0
declare verbose=1
declare codecov=0
declare debug=0
declare test=0
pasres_arguments() {
for var in "$@"; do
case "$var" in
noOpenSSL)
need_build_openssl=0
;;
noEvent)
need_build_libevent=0
;;
noJson)
need_build_jsoncpp=0
;;
noBoost)
need_build_boost=0
;;
asan)
enable_asan=1
;;
lsan)
enable_lsan=1
;;
noVerbose)
verbose=0
;;
codecov)
codecov=1
;;
debug)
debug=1
;;
test)
test=1
;;
esac
done
}
pasres_arguments $@
PrintParams() {
echo "###########################################################################"
if [ $need_build_openssl -eq 0 ]; then
echo "no need build openssl lib"
else
echo "need build openssl lib"
fi
if [ $need_build_jsoncpp -eq 0 ]; then
echo "no need build jsoncpp lib"
else
echo "need build jsoncpp lib"
fi
if [ $need_build_libevent -eq 0 ]; then
echo "no need build libevent lib"
else
echo "need build libevent lib"
fi
if [ $need_build_boost -eq 0 ]; then
echo "no need build boost lib"
else
echo "need build boost lib"
fi
if [ $enable_asan -eq 1 ]; then
echo "enable asan reporting"
else
echo "disable asan reporting"
fi
if [ $enable_lsan -eq 1 ]; then
echo "enable lsan reporting"
else
echo "disable lsan reporting"
fi
if [ $verbose -eq 0 ]; then
echo "no need print detail logs"
else
echo "need print detail logs"
fi
if [ $codecov -eq 1 ]; then
echo "run unit tests with code coverage"
else
echo "run unit tests without code coverage"
fi
if [ $debug -eq 1 ]; then
echo "enable debug"
else
echo "disable debug"
fi
if [ $test -eq 1 ]; then
echo "build unit tests"
else
echo "without build unit tests"
fi
echo "###########################################################################"
echo ""
}
Prepare() {
if [ -e ${down_dir} ]; then
echo "${down_dir} exists"
#cd ${down_dir}
#ls |grep -v ${fname_libevent} |grep -v ${fname_jsoncpp} | grep -v ${fname_boost} |xargs rm -rf
else
mkdir -p ${down_dir}
fi
cd ${basepath}
if [ -e ${fname_openssl} ]; then
mv -f ${basepath}/${fname_openssl} ${down_dir}
fi
if [ -e ${fname_libevent} ]; then
mv -f ${basepath}/${fname_libevent} ${down_dir}
fi
if [ -e ${fname_jsoncpp} ]; then
mv -f ${basepath}/${fname_jsoncpp} ${down_dir}
fi
if [ -e ${fname_boost} ]; then
mv -f ${basepath}/${fname_boost} ${down_dir}
fi
if [ -e ${build_dir} ]; then
echo "${build_dir} exists"
#rm -rf ${build_dir}/*
else
mkdir -p ${build_dir}
fi
if [ -e ${packet_dir} ]; then
echo "${packet_dir} exists"
#rm -rf ${packet_dir}/*
else
mkdir -p ${packet_dir}
fi
if [ -e ${install_lib_dir} ]; then
echo "${install_lib_dir} exists"
else
mkdir -p ${install_lib_dir}
fi
}
BuildOpenSSL() {
if [ $need_build_openssl -eq 0 ]; then
echo "no need build openssl lib"
return 0
fi
cd ${down_dir}
if [ -e ${fname_openssl} ]; then
echo "${fname_openssl} exists"
else
wget https://www.openssl.org/source/old/1.1.1/${fname_openssl_down} -O ${fname_openssl_down} --no-check-certificate
fi
tar -zxvf ${fname_openssl} &> unzipopenssl.txt
if [ $? -ne 0 ]; then
exit 1
fi
openssl_dir=$(ls | grep ^openssl | grep .*[^gz]$)
cd ${openssl_dir}
if [ $? -ne 0 ]; then
exit 1
fi
echo "build openssl static #####################"
if [ $verbose -eq 0 ]; then
./config shared CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} --openssldir=${install_lib_dir} &> opensslconfig.txt
else
./config shared CFLAGS=-fPIC CPPFLAGS=-fPIC --prefix=${install_lib_dir} --openssldir=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
if [ $verbose -eq 0 ]; then
echo "build openssl without detail log."
make depend &> opensslbuild.txt
make -j $cpu_num &> opensslbuild.txt
else
make depend
make -j $cpu_num
fi
if [ $? -ne 0 ]; then
exit 1
fi
make install
echo "build openssl success."
}
BuildLibevent() {
if [ $need_build_libevent -eq 0 ]; then
echo "no need build libevent lib"
return 0
fi
cd ${down_dir}
if [ -e ${fname_libevent} ]; then
echo "${fname_libevent} exists"
else
wget https://github.com/libevent/libevent/archive/${fname_libevent_down} -O libevent-${fname_libevent_down}
fi
unzip -o ${fname_libevent} &> unziplibevent.txt
if [ $? -ne 0 ]; then
exit 1
fi
libevent_dir=$(ls | grep ^libevent | grep .*[^zip^txt]$)
cd ${libevent_dir}
if [ $? -ne 0 ]; then
exit 1
fi
./autogen.sh
if [ $? -ne 0 ]; then
exit 1
fi
echo "build libevent static #####################"
if [ $verbose -eq 0 ]; then
./configure --enable-static=yes --enable-shared=no CFLAGS="-fPIC -I${install_lib_dir}/include" CPPFLAGS="-fPIC -I${install_lib_dir}/include" LDFLAGS="-L${install_lib_dir}/lib" --prefix=${install_lib_dir} &> libeventconfig.txt
else
./configure --enable-static=yes --enable-shared=no CFLAGS="-fPIC -I${install_lib_dir}/include" CPPFLAGS="-fPIC -I${install_lib_dir}/include" LDFLAGS="-L${install_lib_dir}/lib" --prefix=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
if [ $verbose -eq 0 ]; then
echo "build libevent without detail log."
make -j $cpu_num &> libeventbuild.txt
else
make -j $cpu_num
fi
if [ $? -ne 0 ]; then
exit 1
fi
make install
echo "build linevent success."
}
BuildJsonCPP() {
if [ $need_build_jsoncpp -eq 0 ]; then
echo "no need build jsoncpp lib"
return 0
fi
cd ${down_dir}
if [ -e ${fname_jsoncpp} ]; then
echo "${fname_jsoncpp} exists"
else
wget https://github.com/open-source-parsers/jsoncpp/archive/${fname_jsoncpp_down} -O jsoncpp-${fname_jsoncpp_down}
fi
unzip -o ${fname_jsoncpp} &> unzipjsoncpp.txt
if [ $? -ne 0 ]; then
exit 1
fi
jsoncpp_dir=$(ls | grep ^jsoncpp | grep .*[^zip]$)
cd ${jsoncpp_dir}
if [ $? -ne 0 ]; then
exit 1
fi
mkdir build
cd build
echo "build jsoncpp static ######################"
if [ $verbose -eq 0 ]; then
echo "build jsoncpp without detail log."
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} &> jsoncppbuild.txt
else
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
if [ $verbose -eq 0 ]; then
make -j $cpu_num &> jsoncppbuild.txt
else
make -j $cpu_num
fi
if [ $? -ne 0 ]; then
exit 1
fi
make install
echo "build jsoncpp success."
if [ ! -f ${install_lib_dir}/lib/libjsoncpp.a ]; then
echo " ./bin/lib directory is not libjsoncpp.a"
cp ${install_lib_dir}/lib/x86_64-linux-gnu/libjsoncpp.a ${install_lib_dir}/lib/
fi
}
BuildBoost() {
if [ $need_build_boost -eq 0 ]; then
echo "no need build boost lib"
return 0
fi
cd ${down_dir}
if [ -e ${fname_boost} ]; then
echo "${fname_boost} exists"
else
wget http://sourceforge.net/projects/boost/files/boost/${fname_boost_down} --no-check-certificate
fi
tar -zxvf ${fname_boost} &> unzipboost.txt
boost_dir=$(ls | grep ^boost | grep .*[^gz]$)
cd ${boost_dir}
if [ $? -ne 0 ]; then
exit 1
fi
./bootstrap.sh
if [ $? -ne 0 ]; then
exit 1
fi
echo "build boost static #####################"
pwd
if [ $verbose -eq 0 ]; then
echo "build boost without detail log."
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir} &> boostbuild.txt
else
./b2 -j$cpu_num cflags=-fPIC cxxflags=-fPIC --with-atomic --with-thread --with-system --with-chrono --with-date_time --with-log --with-regex --with-serialization --with-filesystem --with-locale --with-iostreams threading=multi link=static release install --prefix=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
}
BuildRocketMQClient() {
cd ${build_dir}
echo "============start to build rocketmq client cpp.========="
local ROCKETMQ_CMAKE_FLAG=""
if [ $test -eq 1 ]; then
if [ $codecov -eq 1 ]; then
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON"
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=OFF"
fi
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DRUN_UNIT_TEST=OFF -DCODE_COVERAGE=OFF"
fi
if [ $enable_asan -eq 1 ]; then
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_ASAN=ON"
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_ASAN=OFF"
fi
if [ $enable_lsan -eq 1 ]; then
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_LSAN=ON"
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DENABLE_LSAN=OFF"
fi
if [ $debug -eq 1 ]; then
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DCMAKE_BUILD_TYPE=Debug"
else
ROCKETMQ_CMAKE_FLAG=$ROCKETMQ_CMAKE_FLAG" -DCMAKE_BUILD_TYPE=Release"
fi
cmake .. $ROCKETMQ_CMAKE_FLAG
if [ $verbose -eq 0 ]; then
echo "build rocketmq without detail log."
make -j $cpu_num &> buildclient.txt
else
make -j $cpu_num
fi
if [ $? -ne 0 ]; then
echo "build error....."
exit 1
fi
#sudo make install
PackageRocketMQStatic
}
BuildGoogleTest() {
if [ $test -eq 0 ]; then
echo "no need build google test lib"
return 0
fi
if [ -f ./bin/lib/libgtest.a ]; then
echo "GTest already exists, no need build"
return 0
fi
cd ${down_dir}
if [ -e release-1.8.1.tar.gz ]; then
echo "${fname_boost} exists"
else
wget https://github.com/abseil/googletest/archive/release-1.8.1.tar.gz
fi
if [ ! -d "googletest-release-1.8.1" ]; then
tar -zxvf release-1.8.1.tar.gz &> googletest.txt
fi
cd googletest-release-1.8.1
mkdir -p build
cd build
echo "build googletest static #####################"
if [ $verbose -eq 0 ]; then
echo "build googletest without detail log."
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir} &> googletestbuild.txt
else
cmake .. -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${install_lib_dir}
fi
if [ $? -ne 0 ]; then
exit 1
fi
if [ $verbose -eq 0 ]; then
make -j $cpu_num &> gtestbuild.txt
else
make -j $cpu_num
fi
if [ $? -ne 0 ]; then
exit 1
fi
make install
if [ ! -f ${install_lib_dir}/lib/libgtest.a ]; then
echo " ./bin/lib directory is not libgtest.a"
cp ${install_lib_dir}/lib64/lib* ${install_lib_dir}/lib
fi
}
ExecutionTesting() {
if [ $test -eq 0 ]; then
echo "Build success without executing unit tests."
return 0
fi
echo "############# unit test start ###########"
cd ${build_dir}
if [ $verbose -eq 0 ]; then
ctest
else
ctest -V
fi
if [ $? -ne 0 ]; then
echo "############# unit test failed ###########"
exit 1
fi
echo "############# unit test finish ###########"
}
PackageRocketMQStatic() {
echo "############# Start package static rocketmq library. #############"
if test "$(uname)" = "Linux"; then
#packet libevent,jsoncpp,boost,rocketmq,Signature to one librocketmq.a
cp -f ${basepath}/libs/signature/lib/libSignature.a ${install_lib_dir}/lib
ar -M <${basepath}/package_rocketmq.mri
cp -f librocketmq.a ${install_lib_dir}
elif test "$(uname)" = "Darwin" ; then
mkdir -p ${static_package_dir}
cd ${static_package_dir}
cp -f ${basepath}/libs/signature/lib/libSignature.a .
cp -f ${install_lib_dir}/lib/lib*.a .
cp -f ${install_lib_dir}/librocketmq.a .
echo "Md5 Hash RocketMQ Before:"
md5sum librocketmq.a
local dir=`ls *.a | grep -E 'gtest|gmock'`
for i in $dir
do
rm -rf $i
done
libtool -no_warning_for_no_symbols -static -o librocketmq.a *.a
echo "Md5 Hash RocketMQ After:"
md5sum librocketmq.a
echo "Try to copy $(pwd)/librocketmq.a to ${install_lib_dir}/"
cp -f librocketmq.a ${install_lib_dir}/
cd ${basepath}
rm -rf ${static_package_dir}
fi
echo "############# Package static rocketmq library success.#############"
}
PrintParams
Prepare
BuildOpenSSL
BuildLibevent
BuildJsonCPP
BuildBoost
BuildGoogleTest
BuildRocketMQClient
ExecutionTesting