-
Notifications
You must be signed in to change notification settings - Fork 5
/
deps.sh
executable file
·363 lines (327 loc) · 10 KB
/
deps.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
#!/usr/bin/env bash
function printUsage(){
cat <<EOF
Usage: $0 [options]
-h| --help Show this help and exit.
-c| --ccompiler CC Use CC compiler
--cppcompiler CXX Use CXX compiler
-j| --jobs J Compile with J jobs (default=4)
--purify Build OpenSSL with the --purify option, to suppress valgrind pain
--clean DEP Clean dependency DEP
-w| --with DEP Build dependency DEP if not found
-r| --rebuild DEP Clean and Build dependency DEP
Options (case insensitive) for --with --rebuild --clean:
Cynnypp
GoogleTest
NgHttp2
OpenSSL
SpdLog
All
Note: if called with no parameters all dependencies will be built
EOF
}
function toLower(){
local str="$@"
local output=$(tr '[A-Z]' '[a-z]'<<<"${str}")
echo ${output}
}
function sharedLibraryExtension(){
local Kernel=`uname -s`
if [ ${Kernel}=="Linux" ]; then
echo "so"
elif [ ${Kernel}=="Darwin" ]; then
echo "dylib"
fi
}
function staticLibraryExtension(){
local Kernel=`uname -s`
if [ ${Kernel}=="Linux" ]; then
echo "a"
elif [ ${Kernel}=="Darwin" ]; then
echo "a"
fi
}
function getDir(){
# google docet - jump within the directory which contains this script
local SOURCE="${BASH_SOURCE[0]}"
local DIR=""
while [ -h "${SOURCE}" ]; do
DIR="$(cd -P "$(dirname "${SOURCE}")" && pwd)"
SOURCE="$(readlink "${SOURCE}")"
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}"
done
# set aside the base dir for future references
DIR="$(cd -P "$(dirname "${SOURCE}")" && pwd)"
echo ${DIR}
}
function setWith(){
local arg="$1"
arg=$(toLower ${arg})
case ${arg} in
cynnypp)
buildCynnyppFlag=true
;;
googletest)
buildGoogleTestFlag=true
;;
nghttp2)
buildNgHttp2Flag=true
;;
openssl)
buildOpenSSLFlag=true
;;
spdlog)
buildSpdLogFlag=true
;;
all)
buildCynnyppFlag=true
buildGoogleTestFlag=true
buildNgHttp2Flag=true
buildOpenSSLFlag=true
buildSpdLogFlag=true
;;
*)
echo "Unrecognized parameter for \"--with\""
printUsage
exit 1
;;
esac
}
function setClean(){
local arg="$1"
arg=$(toLower ${arg})
case ${arg} in
cynnypp)
cleanCynnyppFlag=true
;;
googletest)
cleanGoogleTestFlag=true
;;
nghttp2)
cleanNghttp2Flag=true
;;
openssl)
cleanOpensslFlag=true
;;
spdlog)
cleanSpdlogFlag=true
;;
all)
cleanCynnyppFlag=true
cleanGoogleTestFlag=true
cleanNghttp2Flag=true
cleanOpensslFlag=true
cleanSpdlogFlag=true
;;
*)
echo "Unrecognized parameter for \"--clean\""
printUsage
exit 1
;;
esac
}
function cleanRepo(){
local repo_dir="$1"
local flag=$2
if ${flag}; then
if [ -d ${repo_dir}/build ]; then
rm -rf ${repo_dir}/build/*
fi
if [ -f ${repo_dir}/deps.sh ]; then
cd ${repo_dir} && ./deps.sh --clean all
fi
fi
cd ${DIR}
}
function cleanOpenSSL(){
local repo_dir="$1"
local flag=$2
if ${flag}; then
cd ${repo_dir} && make clean
fi
cd ${DIR}
}
function buildCynnypp(){
local repo_dir="$1"
local flag=$2
local cmake_fwd_args="$3"
local JOBS=$4
if ${flag}; then
cd ${repo_dir} && git fetch -p &&
if [ -f "build/lib/libcynpp_async_fs.$(sharedLibraryExtension)" ]; then
echo "Cynnypp already built, skip rebuilding..."
else
echo "Cynnypp not found, building..."
mkdir -p ${repo_dir}/build && cd ${repo_dir}/build && rm -rf * &&
LIBRARY_TYPE=shared cmake ${cmake_fwd_args} .. && make -j${JOBS} async_fs_shared
fi
fi
cd ${DIR}
}
function buildNgHttp2(){
local repo_dir="$1"
local flag=$2
local cmake_fwd_args="$3"
local JOBS=$4
if ${flag}; then
cd ${repo_dir} && git fetch -p &&
if [ -f "INSTALL/lib/libnghttp2.$(sharedLibraryExtension)" ] &&
[ -f "INSTALL/lib/libnghttp2_asio.$(sharedLibraryExtension)" ]; then
echo "NgHttp2 already built, skip rebuilding..."
else
buildOpenSSL ${DIR}/deps/openssl true "${cmake_fwd_args}" ${JOBS}
echo "NgHttp2 not found, building..."
cd ${repo_dir}
autoreconf -i
automake
autoconf
rm -rf ${repo_dir}/INSTALL
OPENSSL_CFLAGS="-I${OPENSSL_ROOT_DIR}/include/" OPENSSL_LIBS="-L${OPENSSL_ROOT_DIR} -lssl -lcrypto" \
./configure --enable-asio-lib=yes --enable-lib-only --prefix="${repo_dir}/INSTALL"
make -j${JOBS} || ( echo "fatal: nghttp2 build failed"; exit )
make install
fi
fi
cd ${DIR}
}
function buildGoogleTest(){
local repo_dir="$1"
local flag=$2
local cmake_fwd_args="$3"
local JOBS=$4
if ${flag}; then
cd ${repo_dir} && mkdir -p build && cd build
local STATIC_LIB_EXT=$(staticLibraryExtension)
if [ -f "googlemock/libgmock.${STATIC_LIB_EXT}" ] &&
[ -f "googlemock/libgmock_main.${STATIC_LIB_EXT}" ] &&
[ -f "googlemock/gtest/libgtest.${STATIC_LIB_EXT}" ] &&
[ -f "googlemock/gtest/libgtest_main.${STATIC_LIB_EXT}" ]; then
echo "GoogleTest already built, skip rebuilding..."
else
echo "GoogleTest not found, building..."
cmake ${cmake_fwd_args} .. && make -j${JOBS}
fi
fi
cd ${DIR}
}
function buildOpenSSL(){
local repo_dir="$1"
local flag=$2
local cmake_fwd_args="$3"
local JOBS=$4
if ${flag}; then
cd ${repo_dir}
if [ -L "libssl.$(sharedLibraryExtension)" ] &&
[ -L "libcrypto.$(sharedLibraryExtension)" ]; then
echo "OpenSSL already built, skip rebuilding..."
else
echo "OpenSSL not found, building..."
./config "shared ${OPENSSL_PURIFY}"
make -j${JOBS} || ( echo "fatal: openssl build failed"; exit )
fi
fi
cd ${DIR}
}
function buildSpdLog(){
local repo_dir="$1"
local flag=$2
local deps_fwd_args="$3"
local JOBS=$4
if ${flag}; then
cd ${repo_dir} && git fetch -p
# Header only
fi
cd ${DIR}
}
function showStatus(){
echo "=================================="
echo "${name} Dependency Status: "
echo "=================================="
echo " Clean Cynnypp: $cleanCynnyppFlag"
echo " Clean GoogleTest: $cleanGoogleTestFlag"
echo " Clean NgHttp2: $cleanNghttp2Flag"
echo " Clean OpenSSL: $cleanOpensslFlag"
echo " Clean SpdLog: $cleanSpdlogFlag"
echo ""
echo " Build (if necessary) Cynnypp: $buildCynnyppFlag"
echo " Build (if necessary) GoogleTest: $buildGoogleTestFlag"
echo " Build (if necessary) NgHttp2: $buildNgHttp2Flag"
echo " Build (if necessary) OpenSSL: $buildOpenSSLFlag"
echo " Build (if necessary) SpdLog: $buildSpdLogFlag"
echo ""
}
### Start
JOBS=4
buildCynnyppFlag=false
buildGoogleTestFlag=false
buildNgHttp2Flag=false
buildOpenSSLFlag=false
buildSpdLogFlag=false
cleanCynnyppFlag=false
cleanGoogleTestFlag=false
cleanNghttp2Flag=false
cleanOpensslFlag=false
cleanSpdlogFlag=false
FORWARD_JOBS="-j ${JOBS}"
FORWARD_CC=""
FORWARD_CXX=""
if [ $# -le 0 ]; then
echo "No parameters -> Everything necessary will be built"
echo ""
setWith "all"
fi
while [ "$1" != "" ]; do
case $1 in
-j | --jobs ) shift
JOBS=$1
FORWARD_JOBS="-j $1"
;;
-c | --ccompiler ) shift
CC="-DCMAKE_C_COMPILER=$1"
FORWARD_CC="-c $1"
;;
--cppcompiler ) shift
CXX="-DCMAKE_CXX_COMPILER=$1"
FORWARD_CXX="-p $1"
;;
--purify ) shift
OPENSSL_PURIFY="-DPURIFY"
;;
-r | --rebuild) shift
setClean $1
setWith $1
;;
-w | --with) shift
setWith $1
;;
--clean) shift
setClean $1
;;
-h | --help)
printUsage
exit 1
;;
* )
printUsage
exit 1
esac
shift
done
DIR=$(getDir)
OPENSSL_ROOT_DIR=${DIR}/deps/openssl
cd ${DIR}
showStatus
FWD_DEPS_ARGUMENTS="$FORWARD_CXX $FORWARD_CC $FORWARD_JOBS"
FWD_CMAKE_ARGUMENTS="$CC $CXX -DCMAKE_BUILD_TYPE=Release"
### Apply submodules
git submodule update --init && git submodule sync
cleanRepo ${DIR}/deps/cynnypp ${cleanCynnyppFlag}
cleanRepo ${DIR}/deps/gtest ${cleanGoogleTestFlag}
cleanRepo ${DIR}/deps/nghttp2 ${cleanNghttp2Flag}
cleanOpenSSL ${OPENSSL_ROOT_DIR} ${cleanOpensslFlag}
buildCynnypp ${DIR}/deps/cynnypp ${buildCynnyppFlag} "${FWD_CMAKE_ARGUMENTS}" ${JOBS}
buildGoogleTest ${DIR}/deps/gtest ${buildGoogleTestFlag} "${FWD_CMAKE_ARGUMENTS}" ${JOBS}
buildNgHttp2 ${DIR}/deps/nghttp2 ${buildNgHttp2Flag} "${FWD_CMAKE_ARGUMENTS}" ${JOBS}
buildOpenSSL ${DIR}/deps/openssl ${buildOpenSSLFlag} "${FWD_CMAKE_ARGUMENTS}" ${JOBS}
buildSpdLog ${DIR}/deps/spdlog ${buildSpdLogFlag} "${FWD_CMAKE_ARGUMENTS}" ${JOBS}
cd ${DIR}