forked from apache/nifi-minifi-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·536 lines (442 loc) · 14.5 KB
/
bootstrap.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
533
534
535
536
#!/bin/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.
script_directory="$(cd "$(dirname "$0")" && pwd)"
CMAKE_GLOBAL_MIN_VERSION_MAJOR=3
CMAKE_GLOBAL_MIN_VERSION_MINOR=7
CMAKE_GLOBAL_MIN_VERSION_REVISION=0
export RED='\033[0;101m'
export NO_COLOR='\033[0;0;39m'
export TRUE="Enabled"
export FALSE="Disabled"
export DEPLOY="false"
export NO_PROMPT="false"
export FEATURES_SELECTED="false"
export ALL_FEATURES_ENABLED=${FALSE}
export BUILD_DIR="build"
export BUILD_IDENTIFIER=""
export OPTIONS=()
export CMAKE_OPTIONS_ENABLED=()
export CMAKE_OPTIONS_DISABLED=()
export CMAKE_MIN_VERSION=()
export INCOMPATIBLE_WITH=()
export DEPLOY_LIMITS=()
export DEPENDENCIES=()
CORES=1
BUILD="false"
PACKAGE="false"
USER_DISABLE_TESTS="${FALSE}"
USE_NINJA="false"
. "${script_directory}/bstrp_functions.sh"
SKIP_CMAKE=${FALSE}
MENU="features"
GUIDED_INSTALL=${FALSE}
while :; do
case $1 in
-n|--noprompt)
NO_PROMPT="true"
;;
-s|--skiptests)
USER_DISABLE_TESTS="${TRUE}"
;;
-g|--useninja)
USE_NINJA="${TRUE}"
;;
-e|--enableall)
NO_PROMPT="true"
FEATURES_SELECTED="true"
EnableAllFeatures
;;
-c|--clear)
rm "${script_directory}/bt_state" > /dev/null 2>&1
;;
-d|--deploy)
NO_PROMPT="true"
DEPLOY="true"
FEATURES_SELECTED="true"
EnableAllFeatures
;;
"--build_dir="* )
BUILD_DIR="${1#*=}"
;;
-t|--continous-integration)
NO_PROMPT="true"
FEATURES_SELECTED="true"
SKIP_CMAKE="${TRUE}"
;;
-p|--package)
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
BUILD="true"
PACKAGE="true"
;;
-i|--install)
GUIDED_INSTALL="Enabled"
EnableAllFeatures
MENU="main"
ALL_FEATURES_ENABLED=${TRUE}
;;
-b|--build)
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
BUILD="true"
;;
"--build_identifier="* )
BUILD_IDENTIFIER="${1#*=}"
;;
*) break
esac
shift
done
if [ -x "$(command -v hostname)" ]; then
HOSTNAME=$(hostname)
PING_RESULT=$(ping -c 1 "${HOSTNAME}" 2>&1)
if [[ "$PING_RESULT" = *unknown* ]]; then
cntinu="N"
read -r -p "Cannot resolve your host name -- ${HOSTNAME} -- tests may fail, Continue? [ Y/N ] " cntinu
if [ "$cntinu" = "Y" ] || [ "$cntinu" = "y" ]; then
echo "Continuing..."
else
exit
fi
fi
fi
if [ "$NO_PROMPT" = "true" ]; then
echo "****************************************"
echo "Welcome, this bootstrap script will update your system to install MiNiFi C++"
echo "You have opted to skip prompts. "
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SUSE-brand ]; then
VER=$(tr '\n' ' ' < /etc/SUSE-brand | sed s/.*=\ //)
OS=$(tr '\n' ' ' < /etc/SUSE-brand | sed s/VERSION.*//)
elif [ -f /etc/SUSE-release ]; then
VER=$(tr '\n' ' ' < /etc/SUSE-release | sed s/.*=\ //)
OS=$(tr '\n' ' ' < /etc/SUSE-release | sed s/VERSION.*//)
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
...
else
OS=$(uname -s)
VER=$(uname -r)
fi
OS_MAJOR=$(echo "$VER" | cut -d. -f1)
export OS_MAJOR
OS_MINOR=$(echo "$VER" | cut -d. -f2)
export OS_MINOR
OS_REVISION=$(echo "$EVR" | cut -d. -f3)
export OS_REVISION
### Verify the compiler version
COMPILER_VERSION="0.0.0"
COMPILER_COMMAND=""
if [ -x "$(command -v g++)" ]; then
COMPILER_COMMAND="g++"
COMPILER_VERSION=$(${COMPILER_COMMAND} -dumpversion)
fi
COMPILER_MAJOR=$(echo "$COMPILER_VERSION" | cut -d. -f1)
export COMPILER_MAJOR
COMPILER_MINOR=$(echo "$COMPILER_VERSION" | cut -d. -f2)
export COMPILER_MINOR
COMPILER_REVISION=$(echo "$COMPILER_VERSION" | cut -d. -f3)
export COMPILER_REVISION
if [[ "$OS" = "Darwin" ]]; then
. "${script_directory}/darwin.sh"
else
. "${script_directory}/linux.sh"
if [[ "$OS" = Deb* ]]; then
. "${script_directory}/debian.sh"
elif [[ "$OS" = Rasp* ]]; then
. "${script_directory}/aptitude.sh"
elif [[ "$OS" = Pop* ]]; then
. "${script_directory}/aptitude.sh"
elif [[ "$OS" = Ubuntu* ]]; then
. "${script_directory}/aptitude.sh"
elif [[ "$OS" = *SUSE* ]]; then
. "${script_directory}/suse.sh"
elif [[ "$OS" = *SLE* ]]; then
if [[ "$VER" = 11* ]]; then
echo "Please install SLES11 manually...exiting"
exit
else
. "${script_directory}/suse.sh"
fi
elif [[ "$OS" = Red* ]]; then
. "${script_directory}/rheldistro.sh"
elif [[ "$OS" = Amazon* ]]; then
. "${script_directory}/centos.sh"
elif [[ "$OS" = CentOS* ]]; then
. "${script_directory}/centos.sh"
elif [[ "$OS" = Fedora* ]]; then
. "${script_directory}/fedora.sh"
elif [[ "$OS" = Manjaro* ]]; then
. "${script_directory}/arch.sh"
elif [[ "$OS" = Arch* ]]; then
. "${script_directory}/arch.sh"
fi
fi
### verify the cmake version
CMAKE_COMMAND=""
if [ -x "$(command -v cmake3)" ]; then
CMAKE_COMMAND="cmake3"
elif [ -x "$(command -v cmake)" ]; then
CMAKE_COMMAND="cmake"
fi
if [ -n "${CMAKE_COMMAND}" ]; then
get_cmake_version
fi
if [ -z "${CMAKE_COMMAND}" ] ||
[ "$CMAKE_MAJOR" -lt "$CMAKE_GLOBAL_MIN_VERSION_MAJOR" ] ||
[ "$CMAKE_MINOR" -lt "$CMAKE_GLOBAL_MIN_VERSION_MINOR" ] ||
[ "$CMAKE_REVISION" -lt "$CMAKE_GLOBAL_MIN_VERSION_REVISION" ]; then
echo "CMake is not installed or too old, attempting to install it..."
bootstrap_cmake
if [ -x "$(command -v cmake3)" ]; then
CMAKE_COMMAND="cmake3"
elif [ -x "$(command -v cmake)" ]; then
CMAKE_COMMAND="cmake"
fi
get_cmake_version
fi
if [ "$CMAKE_MAJOR" -lt "$CMAKE_GLOBAL_MIN_VERSION_MAJOR" ] ||
[ "$CMAKE_MINOR" -lt "$CMAKE_GLOBAL_MIN_VERSION_MINOR" ] ||
[ "$CMAKE_REVISION" -lt "$CMAKE_GLOBAL_MIN_VERSION_REVISION" ]; then
echo "Failed to install or update CMake, exiting..."
exit
fi
add_cmake_option PORTABLE_BUILD ${TRUE}
add_cmake_option DEBUG_SYMBOLS ${FALSE}
add_cmake_option BUILD_ROCKSDB ${TRUE}
## uses the source from the third party directory
add_enabled_option ROCKSDB_ENABLED ${TRUE} "DISABLE_ROCKSDB"
## need libcurl installed
add_enabled_option HTTP_CURL_ENABLED ${TRUE} "DISABLE_CURL"
# third party directory
add_enabled_option LIBARCHIVE_ENABLED ${TRUE} "DISABLE_LIBARCHIVE"
add_dependency LIBARCHIVE_ENABLED "libarchive"
add_enabled_option EXECUTE_SCRIPT_ENABLED ${TRUE} "DISABLE_SCRIPTING"
add_dependency EXECUTE_SCRIPT_ENABLED "python"
add_dependency EXECUTE_SCRIPT_ENABLED "lua"
add_enabled_option EXPRESSION_LANGAUGE_ENABLED ${TRUE} "DISABLE_EXPRESSION_LANGUAGE"
add_dependency EXPRESSION_LANGAUGE_ENABLED "bison"
add_dependency EXPRESSION_LANGAUGE_ENABLED "flex"
add_disabled_option PCAP_ENABLED ${FALSE} "ENABLE_PCAP"
add_dependency PCAP_ENABLED "libpcap"
add_disabled_option USB_ENABLED ${FALSE} "ENABLE_USB_CAMERA"
add_dependency USB_ENABLED "libusb"
add_dependency USB_ENABLED "libpng"
add_disabled_option GPS_ENABLED ${FALSE} "ENABLE_GPS"
add_dependency GPS_ENABLED "gpsd"
add_disabled_option AWS_ENABLED ${FALSE} "ENABLE_AWS"
add_disabled_option KAFKA_ENABLED ${FALSE} "ENABLE_LIBRDKAFKA"
add_disabled_option MQTT_ENABLED ${FALSE} "ENABLE_MQTT"
add_disabled_option PYTHON_ENABLED ${FALSE} "ENABLE_PYTHON"
add_dependency PYTHON_ENABLED "python"
add_disabled_option COAP_ENABLED ${FALSE} "ENABLE_COAP"
add_dependency COAP_ENABLED "automake"
add_dependency COAP_ENABLED "autoconf"
add_dependency COAP_ENABLED "libtool"
add_disabled_option JNI_ENABLED ${FALSE} "ENABLE_JNI"
add_dependency JNI_ENABLED "jnibuild"
add_disabled_option OPENCV_ENABLED ${FALSE} "ENABLE_OPENCV"
add_disabled_option OPENCV_ENABLED ${FALSE} "ENABLE_OPENCV"
add_disabled_option SFTP_ENABLED ${FALSE} "ENABLE_SFTP"
add_dependency SFTP_ENABLED "libssh2"
add_disabled_option SQL_ENABLED ${FALSE} "ENABLE_SQL"
add_disabled_option OPENWSMAN_ENABLED ${FALSE} "ENABLE_OPENWSMAN"
# Since the following extensions have limitations on
add_disabled_option BUSTACHE_ENABLED ${FALSE} "ENABLE_BUSTACHE" "2.6" ${TRUE}
add_dependency BUSTACHE_ENABLED "boost"
## currently need to limit on certain platforms
add_disabled_option TENSORFLOW_ENABLED ${FALSE} "ENABLE_TENSORFLOW" "2.6" ${TRUE}
add_dependency TENSORFLOW_ENABLED "tensorflow"
add_disabled_option OPC_ENABLED ${FALSE} "ENABLE_OPC"
add_dependency OPC_ENABLED "mbedtls"
add_disabled_option AZURE_ENABLED ${FALSE} "ENABLE_AZURE"
USE_SHARED_LIBS=${TRUE}
ASAN_ENABLED=${FALSE}
FAIL_ON_WARNINGS=${FALSE}
TESTS_ENABLED=${TRUE}
## name, default, values
add_multi_option BUILD_PROFILE "RelWithDebInfo" "RelWithDebInfo" "Debug" "MinSizeRel" "Release"
if [ "$GUIDED_INSTALL" == "${TRUE}" ]; then
EnableAllFeatures
ALL_FEATURES_ENABLED=${TRUE}
fi
BUILD_DIR_D=${BUILD_DIR}
OVERRIDE_BUILD_IDENTIFIER=${BUILD_IDENTIFIER}
load_state
if [ "$USER_DISABLE_TESTS" == "${TRUE}" ]; then
ToggleFeature TESTS_ENABLED
fi
if [ "${OVERRIDE_BUILD_IDENTIFIER}" != "${BUILD_IDENTIFIER}" ]; then
BUILD_IDENTIFIER=${OVERRIDE_BUILD_IDENTIFIER}
fi
if [ "$BUILD_DIR_D" != "build" ] && [ "$BUILD_DIR_D" != "$BUILD_DIR" ]; then
read -r -p "Build dir will override stored state, $BUILD_DIR. Press any key to continue " overwrite
BUILD_DIR=$BUILD_DIR_D
fi
if [ ! -d "${BUILD_DIR}" ]; then
mkdir "${BUILD_DIR}/"
else
overwrite="Y"
if [ "$NO_PROMPT" = "false" ] && [ "$FEATURES_SELECTED" = "false" ]; then
echo "CMAKE Build dir (${BUILD_DIR}) exists, should we overwrite your build directory before we begin?"
read -r -p "If you have already bootstrapped, bootstrapping again isn't necessary to run make [ Y/N ] " overwrite
fi
if [ "$overwrite" = "N" ] || [ "$overwrite" = "n" ]; then
echo "Exiting ...."
exit
else
rm "${BUILD_DIR}/CMakeCache.txt" > /dev/null 2>&1
fi
fi
## change to the directory
pushd "${BUILD_DIR}" || exit 1
while [ ! "$FEATURES_SELECTED" == "true" ]
do
if [ "$MENU" == "main" ]; then
show_main_menu
read_main_menu_options
elif [ "$MENU" == "advanced" ]; then
show_advanced_features_menu
read_advanced_menu_options
else
show_supported_features
read_feature_options
fi
done
### ensure we have all dependencies
save_state
build_deps
## just in case
CMAKE_VERSION=$(${CMAKE_COMMAND} --version | head -n 1 | awk '{print $3}')
CMAKE_MAJOR=$(echo "$CMAKE_VERSION" | cut -d. -f1)
CMAKE_MINOR=$(echo "$CMAKE_VERSION" | cut -d. -f2)
CMAKE_REVISION=$(echo "$CMAKE_VERSION" | cut -d. -f3)
CMAKE_BUILD_COMMAND="${CMAKE_COMMAND} "
if [ "${USE_NINJA}" = "${TRUE}" ]; then
echo "use ninja"
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DFORCE_COLORED_OUTPUT=ON -GNinja "
fi
build_cmake_command(){
for option in "${OPTIONS[@]}" ; do
option_value="${!option}"
if [ "$option_value" = "${TRUE}" ]; then
# option is enabled
FOUND=""
FOUND_VALUE=""
for cmake_opt in "${CMAKE_OPTIONS_ENABLED[@]}" ; do
KEY=${cmake_opt%%:*}
VALUE=${cmake_opt#*:}
if [ "$KEY" = "$option" ]; then
FOUND="1"
FOUND_VALUE="$VALUE"
fi
done
if [ "$FOUND" = "1" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -D${FOUND_VALUE}=ON"
fi
else
FOUND=""
FOUND_VALUE=""
if [ -z "$FOUND" ]; then
for cmake_opt in "${CMAKE_OPTIONS_DISABLED[@]}" ; do
KEY=${cmake_opt%%:*}
VALUE=${cmake_opt#*:}
if [ "$KEY" = "$option" ]; then
FOUND="1"
FOUND_VALUE="$VALUE"
fi
done
fi
if [ "$FOUND" = "1" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -D${FOUND_VALUE}=ON"
fi
fi
done
if [ "${DEBUG_SYMBOLS}" = "${TRUE}" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
fi
if [ "${TESTS_ENABLED}" = "${TRUE}" ]; then
# user may have disabled tests previously, so let's force them to be re-enabled
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DSKIP_TESTS= "
else
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DSKIP_TESTS=true "
fi
if [ "${ASAN_ENABLED}" = "${TRUE}" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DASAN_BUILD=ON "
else
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DASAN_BUILD=OFF"
fi
if [ "${USE_SHARED_LIBS}" = "${TRUE}" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DUSE_SHARED_LIBS=ON "
else
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DUSE_SHARED_LIBS= "
fi
if [ "${PORTABLE_BUILD}" = "${TRUE}" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DPORTABLE=ON "
else
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DPORTABLE=OFF "
fi
if [ "${BUILD_ROCKSDB}" = "${TRUE}" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DBUILD_ROCKSDB=ON "
else
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DBUILD_ROCKSDB= "
fi
if [ "${FAIL_ON_WARNINGS}" = "${TRUE}" ]; then
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DFAIL_ON_WARNINGS=ON "
else
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DFAIL_ON_WARNINGS=OFF"
fi
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DBUILD_IDENTIFIER=${BUILD_IDENTIFIER}"
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} -DCMAKE_BUILD_TYPE=${BUILD_PROFILE}"
add_os_flags
CMAKE_BUILD_COMMAND="${CMAKE_BUILD_COMMAND} .."
continue_with_plan="Y"
if [ ! "$NO_PROMPT" = "true" ]; then
read -r -p "Command will be '${CMAKE_BUILD_COMMAND}', run this? [ Y/N ] " continue_with_plan
fi
if [ "$continue_with_plan" = "N" ] || [ "$continue_with_plan" = "n" ]; then
echo "Exiting ...."
exit
fi
}
build_cmake_command
### run the cmake command
if [ "${SKIP_CMAKE}" = "${TRUE}" ]; then
echo "Not running ${CMAKE_BUILD_COMMAND} "
else
${CMAKE_BUILD_COMMAND}
fi
if [ "$BUILD" = "true" ]; then
make -j"${CORES}"
fi
if [ "$PACKAGE" = "true" ]; then
make package
fi
popd || exit 2