-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·599 lines (541 loc) · 14.2 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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#! /bin/bash
#########################################################################
# #
# bootstrap.sh is automatically generated, #
# please do not modify! #
# #
#########################################################################
#########################################################################
# #
# Author: Copyright (C) 2014-2019, 2021-2023 Mark Grant #
# #
# Released under the GPLv3 only. #
# SPDX-License-Identifier: GPL-3.0-only #
# #
# Purpose: #
# To simplify the AutoTools distribution build. #
# #
# Syntax: See usage(). #
# #
# Exit codes used:- #
# Bash standard Exit Codes: 0 - success #
# 1 - general failure #
# User-defined exit code range is 64 - 113 #
# C/C++ Semi-standard exit codes from sysexits.h range is 64 - 78 #
# EX_USAGE 64 command line usage error #
# EX_DATAERR 65 data format error #
# EX_NOINPUT 66 cannot open input #
# EX_NOUSER 67 addressee unknown #
# EX_NOHOST 68 host name unknown #
# EX_UNAVAILABLE 69 service unavailable #
# EX_SOFTWARE 70 internal software error #
# EX_OSERR 71 system error (e.g., can't fork) #
# EX_OSFILE 72 critical OS file missing #
# EX_CANTCREAT 73 can't create (user) output file #
# EX_IOERR 74 input/output error #
# EX_TEMPFAIL 75 temp failure; user is invited #
# to retry #
# EX_PROTOCOL 76 remote error in protocol #
# EX_NOPERM 77 permission denied #
# EX_CONFIG 78 configuration error #
# User-defined (here) exit codes range 79 - 113: #
# None #
# #
# Further Info: #
# #
#########################################################################
set -o pipefail
##################
# Init variables #
##################
readonly version=1.6.0 # set version variable
readonly packageversion=1.6.2 # Version of the complete package
# Set defaults
atonly=""
analyzer=""
build=false
cc=""
cc_cli=""
check=false
config=false
debug=""
dist=false
distcheck=false
gnulib=false
headercheck=""
iwyu=""
menuconfig=false
par_jobs=""
scan_build=""
sparse=""
tarball=false
testinghacks=""
verbose=false
verboseconfig=" --enable-silent-rules=yes"
verbosemake=" --quiet"
basedir="." # Retain quotes
basedirunq=$basedir # Without retaining quotes
configcli_extra_args=()
#############
# Functions #
#############
# -h --help output.
# No parameters
# No return value
usage()
{
cat << EOF
Usage is also true for acmbuild
Usage is:-
${0##*/} -b [-c [-a] [-A] [{--CC=COMPILER|-s}] [-d] [-H] [-m] [-t] [-v]]
[-g] [-K] [-pX] [-- PASS_THRU_OPTIONS ...]
${0##*/} -c [-a] [-A] [{--CC=COMPILER|-s}] [-d] [-H] [-m] [-pX] [-t] [-v]
[-- PASS_THRU_OPTIONS ...]
${0##*/} -c {-i|-S} [--CC=COMPILER] [-pX] [-v] [-- PASS_THRU_OPTIONS ...]
${0##*/} {-C|-D|-T} [-c] [-g] [-pX] [-- PASS_THRU_OPTIONS ...]
${0##*/} -g [-b]
[-c [-a] [-A] [{--CC=COMPILER|-s}] [-d] [-H] [-m] [-t] [-v]]
[-K] [-pX] [-- PASS_THRU_OPTIONS ...]
${0##*/} {-h|-V}
${0##*/} -K [-b]
[-c [-a] [-A] [{--CC=COMPILER|-s}] [-d] [-H] [-m] [-t] [-v]]
[-g] [-pX] [-- PASS_THRU_OPTIONS ...]
Usage is:-
${0##*/} [OPTIONS] [-- PASS_THRU_OPTIONS ...]
-a or --at-only during testing and for an AutoTools-only install, some
build changes are required. e.g. You may reference an external
Java jar in datadir but in AT builds and installations this
may expand to /usr/local/share... So a substitution is required
for this scenario.
-A or --analyzer enable compiler analyzer output
-b or --build make the project
-c or --config congigure the project
-C or --distcheck perform normal distcheck
--CC=compiler Compiler to use, eg gcc, clang etc
-d or --debug build with appropriate debug flags
-D or --dist perform a make dist
-g or --gnulib run gnulib-tool --update
-h or --help displays usage information
-H or --header-check show include stack depth
-i or --iwyu Use clang's include-what-you-use
-K or --check run make check
-m or --menu-config Invoke menu of configurable options
-p[X] or --parallel-jobs[=X] number of jobs to pass to make as --jobs=
If not specified make is sequential
If no value X is given then defaults to nproc
-s or --sparse build using sparse
-S or --scan-build Use clang's scan-build static analyser
-t or --testing-hacks some build changes may be required for testing
purposes. e.g. A script may invoke a project jar file which
when installed will be somewhere under datadir, but during
testing it is in the project tree.
-T or --source-tarball create source tarball
-v or --verbose emit extra information
-V or --version displays version information
-- PASS_THRU_OPTIONS The -- stops processing command line arguments and
instead passes subsequent arguments on, as-is, to AutoTools
EOF
}
# Standard function to emit messages depending on various parameters.
# Parameters - $1 What:- The message to emit.
# $2 Where:- stdout == 0
# stderr == 1
# No return value.
output()
{
if (( !$2 )); then
printf "%s\n" "$1"
else
printf "%s\n" "$1" 1>&2
fi
}
# Standard function to tidy up and return exit code.
# Parameters - $1 is the exit code.
# No return value.
script_exit()
{
exit "$1"
}
# Standard function to test command error and exit if non-zero.
# Parameters - $1 is the exit code, (normally $? from the preceeding command).
# No return value.
std_cmd_err_handler()
{
if (( $1 )); then
script_exit "$1"
fi
}
# Standard trap exit function.
# No parameters.
# No return value.
# shellcheck disable=SC2317 # Do not warn about unreachable commands in trap
# functions, they are legitimate.
trap_exit()
{
local -i exit_code=$?
local msg
msg="Script terminating with exit code $exit_code due to trap received."
output "$msg" 1
script_exit "$exit_code"
}
# Setup trap
trap trap_exit SIGHUP SIGINT SIGQUIT SIGTERM
# Process command line arguments with GNU getopt.
# Parameters - $1 is the command line.
# No return value.
proc_CL()
{
local GETOPTTEMP
local script_name="acmbuild/bootstrap.sh"
local tmp
tmp="getopt -o aAbcCdDghHiKmp::sStTvV "
tmp+="--long at-only,analyzer,build,CC:,check,config,distcheck,debug"
tmp+=",dist,gnulib,help,header-check,iwyu,menu-config,parallel-jobs::"
tmp+=",sparse,scan-build,source-tarball,testing-hacks,verbose,version"
GETOPTTEMP=$($tmp -n "$script_name" -- "$@")
std_cmd_err_handler $?
eval set -- "$GETOPTTEMP"
std_cmd_err_handler $?
while true; do
case "$1" in
-a|--at-only)
atonly=" --enable-atonly=yes"
shift
;;
-A|--analyzer)
analyzer=" --enable-analyzer=yes"
shift
;;
-b|--build)
if $distcheck || $dist || $tarball; then
msg="Options b, C, D and T are mutually "
msg+="exclusive."
output "$msg" 1
script_exit 64
fi
build=true
shift
;;
-c|--config)
config=true
shift
;;
-C|--distcheck)
if $build || $dist || $tarball ; then
msg="Options b, C, D and T are mutually "
msg+="exclusive."
output "$msg" 1
script_exit 64
fi
distcheck=true
shift
;;
--CC)
cc="$2"
cc_cli=" CC=$2"
shift 2
;;
-d|--debug)
debug=" --enable-debug=yes"
shift
;;
-D|--dist)
if $build || $distcheck || $tarball ; then
msg="Options b, C, D and T are mutually "
msg+="exclusive."
output "$msg" 1
script_exit 64
fi
dist=true
shift
;;
-g|--gnulib)
gnulib=true
shift
;;
-h|--help)
usage
shift
script_exit 0
;;
-H|--header-check)
headercheck=" --enable-headercheck=yes"
shift
;;
-i| --iwyu)
iwyu=" --enable-iwyu=yes"
shift
;;
-K|--check)
if $distcheck || $dist || $tarball; then
msg="Options C, D, K and T are mutually "
msg+="exclusive."
output "$msg" 1
script_exit 64
fi
check=true
shift
;;
-m|--menu-config)
which whiptail > /dev/null
status=$?
if (( status != 0 )); then
output "Please first install whiptail." 1
script_exit 64
fi
menuconfig=true
shift
;;
-p|--parallel-jobs)
if [[ -z "$2" ]]; then
par_jobs=" --jobs=$(nproc)"
else
par_jobs=" --jobs=$2"
fi
shift 2
;;
-s|--sparse)
sparse=" --enable-sparse=yes"
shift
;;
-S| --scan-build)
scan_build=" --enable-scan-build=yes"
shift
;;
-t|--testing-hacks)
testinghacks=" --enable-testinghacks=yes"
shift
;;
-T|--source-tarball)
if $build || $distcheck || $dist ; then
msg="Options b, C, D and T are mutually "
msg+="exclusive."
output "$msg" 1
script_exit 64
fi
tarball=true
shift
;;
-v|--verbose)
verbose=true
verboseconfig=""
verbosemake=""
shift
;;
-V|--version)
printf "Script version %s\n" $version
printf "Package version %s\n" $packageversion
shift
script_exit 0
;;
--) shift
break
;;
*) output "Internal error." 1
script_exit 64
;;
esac
done
if [[ $atonly || $analyzer || $cc || $debug || $headercheck \
|| $iwyu || $sparse || $scan_build || $testinghacks ]] \
|| $verbose ; then
if ! $config ; then
msg="Options a, A, CC, d, H, i, s, S, t and v require"
msg+=" option c."
output "$msg" 1
script_exit 64
fi
fi
# include-what-you-use cannot be used with a number of other options.
if [[ $atonly || $analyzer || $debug || $headercheck || $scan_build \
|| $sparse || $testinghacks ]] || $build || $check || $dist \
|| $distcheck || $gnulib || $menuconfig || $tarball ; then
if [[ $iwyu ]]; then
msg="Options a, A, b, C, d, D, g, H, k, m, s, S, t and"
msg+=" T cannot be used with option i"
output "$msg" 1
script_exit 64
fi
fi
# scan-build cannot be used with a number of other options.
if [[ $atonly || $analyzer || $debug || $headercheck || $iwyu \
|| $sparse || $testinghacks ]] || $build || $check || $dist \
|| $distcheck || $gnulib || $menuconfig || $tarball ; then
if [[ $scan_build ]] ; then
msg="Options a, A, b, C, d, D, g, H, i, k, m, s, t"
msg+=" and T cannot be used with option S"
output "$msg" 1
script_exit 64
fi
fi
# Sparse and CC conflict, both setting the CC variable.
if [[ $cc && $sparse ]]; then
msg="Options CC and s are mutually exclusive."
output "$msg" 1
script_exit 64
fi
# include-what-you-use needs clang as compiler.
if [[ $iwyu && -z $cc ]]; then
cc="clang"
cc_cli=" CC=clang"
fi
# One option has to be selected.
if ! $build && ! $check && ! $config && ! $distcheck && ! $dist \
&& ! $gnulib && ! $tarball \
&& [[ ! $iwyu || ! $scan_build ]]; then
output "Either b, c, C, D, g, i, K, S or T must be set." 1
script_exit 64
fi
# menu-config can only be selected with config
if $menuconfig && ! $config; then
output "Option c must be selected with option m." 1
script_exit 64
fi
# First non-option argument which is not an option argument is the base
# directory, all others are passed straight to the configure command
# line, (to support things like --prefix=... etc). Both of these need
# to be inputised before they are passed on in order to maintain
# original quoting. They can then be 'eval'ed.
if (( $# )); then
basedir=${1@Q}
basedirunq="$1" # Unquoted version
shift
configcli_extra_args+=( ' ' "$@" )
fi
}
# Process gnulib option
# No parameters.
# No return value
proc_gnulib()
{
local cmdline
local msg
local status
if [[ -f "$basedirunq/m4/gnulib-cache.m4" ]]; then
cmdline="gnulib-tool --update"$verbosemake$verbosemake
cmdline+=" --dir="$basedir
eval "$cmdline"
status=$?
output "$cmdline completed with exit status: $status" $status
std_cmd_err_handler $status
else
msg="Option -g --gnulib ignored - "
msg+="missing $basedir/m4/gnulib-cache.m4"
output "$msg" 0
fi
}
# Process the configurable options menu
# No parameters
# No return value
proc_menuconfig()
{
local msg
local tmp_extra_args=()
local tmp_file
tmp_file=/tmp/$$.$(basename "$0").tmp
readonly tmp_file
if [[ ! -f $basedirunq/configurable-options.sh \
|| ! -r $basedirunq/configurable-options.sh \
|| ! -x $basedirunq/configurable-options.sh ]]; then
msg="The script configurable-options.sh must; exist in the"
msg+=" project root directory, be readable and be executable."
output "$msg" 1
script_exit 77
fi
"$basedirunq"/configurable-options.sh "$tmp_file"
std_cmd_err_handler $?
mapfile -t tmp_extra_args < <( head -n 1 "$tmp_file" )
std_cmd_err_handler $?
configcli_extra_args+=( "${tmp_extra_args[@]}" )
std_cmd_err_handler $?
rm -f "$tmp_file"
std_cmd_err_handler $?
}
# Process configure
# No parameters
# No return value
proc_config()
{
local cmdline
local msg
local status
cmdline="autoreconf -if $basedir"
eval "$cmdline"
status=$?
msg="autoreconf -if $basedir completed with exit status: $status"
output "$msg" $status
std_cmd_err_handler $status
cmdline="$basedir/configure$cc_cli${configcli_extra_args[*]}"
cmdline+="$verboseconfig$atonly$analyzer$debug$headercheck$iwyu$sparse"
cmdline+="$scan_build$testinghacks"
eval "$cmdline"
status=$?
output "$cmdline completed with exit status: $status" $status
std_cmd_err_handler $status
}
# Process the correct make variation.
# No parameters.
# Returns 0 or command line error.
proc_make()
{
local cmdline
local status
if $build ; then
cmdline="make"$verbosemake$par_jobs
fi
if $check ; then
if [[ ! $cmdline ]]; then
cmdline="make"$verbosemake$par_jobs
fi
cmdline+=" check"
fi
if $distcheck ; then
cmdline="make"$verbosemake$par_jobs" distcheck clean"
fi
if $dist ; then
cmdline="make"$verbosemake$par_jobs" dist clean"
fi
if [[ $iwyu ]]; then
cmdline="make"$verbosemake$par_jobs" -k"
cmdline+=" CC=include-what-you-use"
fi
if [[ $scan_build ]]; then
if [[ $cc ]]; then
cmdline="scan-build --use-cc=$cc make"$verbosemake
cmdline+=$par_jobs" -k"
else
cmdline="scan-build make"$verbosemake$par_jobs" -k"
fi
fi
if $tarball ; then
cmdline="make"$verbosemake$par_jobs" srctarball clean"
fi
# May get here with cmdline empty if, for example, only the -g option
# was set.
if [[ ! $cmdline ]]; then
return 0
fi
eval "$cmdline"
status=$?
output "$cmdline completed with exit status: $status" $status
return $status
}
########
# Main #
########
proc_CL "$@"
# Now the main processing.
if $menuconfig; then
proc_menuconfig
fi
# Create build log after menuconfig which may use dialog and redirections.
exec 1> >(tee build-output.txt) 2>&1
if $gnulib ; then
proc_gnulib
fi
if $config ; then
proc_config
fi
proc_make
std_cmd_err_handler $?
script_exit 0