~m-grant-prg/agmaint/focal

1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
1
#! /bin/bash
1.1.16 by Mark Grant
Import upstream version 1.0.15
2
#########################################################################
3
#									#
4
#	bootstrap.sh is automatically generated,			#
5
#		please do not modify!					#
6
#									#
7
#########################################################################
8
9
#########################################################################
10
#									#
11
# Script ID: bootstrap.sh						#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
12
# Author: Copyright (C) 2014-2019  Mark Grant				#
1.1.16 by Mark Grant
Import upstream version 1.0.15
13
#									#
14
# Released under the GPLv3 only.					#
15
# SPDX-License-Identifier: GPL-3.0					#
16
#									#
17
# Purpose:								#
18
# To simplify the AutoTools distribution build.				#
19
#									#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
20
# Syntax:	bootstrap.sh	[ -a || --at-only ] ||			#
21
#				[ -b || --build ] ||			#
1.1.21 by Mark Grant
Import upstream version 1.0.19
22
#				[ -c || --config ] ||			#
23
#				[ -C || --distcheck ] ||		#
1.1.16 by Mark Grant
Import upstream version 1.0.15
24
#				[ -d || --debug ] ||			#
25
#				[ -D || --dist ] ||			#
26
#				[ -g || --gnulib ] ||			#
27
#				[ -h || --help ] ||			#
1.1.21 by Mark Grant
Import upstream version 1.0.19
28
#				[ -H || --header-check ] ||		#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
29
#				[ -K || --check ] ||			#
1.1.26 by Mark Grant
Import upstream version 1.1.1
30
#				[ -p || --parallel-jobs ] ||		#
1.1.16 by Mark Grant
Import upstream version 1.0.15
31
#				[ -s || --sparse ] ||			#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
32
#				[ -t || --testing-hacks ] ||		#
1.1.21 by Mark Grant
Import upstream version 1.0.19
33
#				[ -T || --source-tarball ] ||		#
34
#				[ -v || --verbose ] ||			#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
35
#				[ -V || --version ] ||			#
36
#				[ -- ]					#
37
#				[ non-option arguments ]		#
1.1.16 by Mark Grant
Import upstream version 1.0.15
38
#									#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
39
# Exit codes used:-							#
40
# Bash standard Exit Codes:	0 - success				#
41
#				1 - general failure			#
42
# User-defined exit code range is 64 - 113				#
43
#	C/C++ Semi-standard exit codes from sysexits.h range is 64 - 78	#
44
#		EX_USAGE	64	command line usage error	#
45
#		EX_DATAERR	65	data format error		#
46
#		EX_NOINPUT	66	cannot open input		#
47
#		EX_NOUSER	67	addressee unknown		#
48
#		EX_NOHOST	68	host name unknown		#
49
#		EX_UNAVAILABLE	69	service unavailable		#
50
#		EX_SOFTWARE	70	internal software error		#
51
#		EX_OSERR	71	system error (e.g., can't fork)	#
52
#		EX_OSFILE	72	critical OS file missing	#
53
#		EX_CANTCREAT	73	can't create (user) output file	#
54
#		EX_IOERR	74	input/output error		#
55
#		EX_TEMPFAIL	75	temp failure; user is invited	#
56
#					to retry			#
57
#		EX_PROTOCOL	76	remote error in protocol	#
58
#		EX_NOPERM	77	permission denied		#
59
#		EX_CONFIG	78	configuration error		#
60
#	User-defined (here) exit codes range 79 - 113:			#
61
#		None							#
1.1.16 by Mark Grant
Import upstream version 1.0.15
62
#									#
63
# Further Info:								#
64
#									#
65
#########################################################################
66
67
#########################################################################
68
#									#
69
# Changelog								#
70
#									#
71
# Date		Author	Version	Description				#
72
#									#
73
# 25/06/2014	MG	1.0.1	Created.				#
74
# 02/08/2014	MG	1.0.2	Change naming from AutoTools to		#
75
#				AutoConf and Make.			#
76
# 27/10/2014	MG	1.0.3	Seperated each command in order to test	#
77
#				exit status.				#
78
# 13/11/2014	MG	1.0.4	Switched from getopts to GNU getopt to	#
79
#				allow long options.			#
80
# 16/11/2014	MG	1.0.5	Modify getopt processing to allow for	#
81
#				FreeBSD's quirk of 2 different getopt	#
82
#				programs. See comments at the start of	#
83
#				"Main"					#
84
# 16/11/2014	MG	1.0.6	Remove erroneous option.		#
85
# 18/11/2014	MG	1.0.7	Change FreeBSD specifics to *BSD and	#
86
#				change Linux to be the default.		#
87
# 24/11/2014	MG	1.0.8	Add overall package version to -V.	#
88
# 28/03/2015	MG	1.0.9	Remove BSD support.			#
89
# 31/01/2017	MG	1.1.1	Add debug make dist and make options.	#
90
# 25/02/2017	MG	1.2.0	Add distcheck & distcheckfake options.	#
91
# 25/06/2017	MG	1.2.1	Enforce 80 column rule.			#
92
# 01/12/2017	MG	1.2.2	Add SPDX license tags to source files.	#
93
# 04/12/2017	MG	1.2.3	Adopt standard exit codes; 0 on success	#
94
#				1 on failure.				#
95
# 06/02/2018	MG	1.3.1	Renamed from acmbuild.			#
96
#				Add -g option.				#
97
#				General script tidy up.			#
98
# 09/02/2018	MG	1.3.2	Remove script name from -V --version	#
99
#				print as this may have been invoked by	#
100
#				acmbuild.sh.				#
101
# 24/03/2018	MG	1.3.3	Add support for sparse CLA.		#
102
#				Add stderr log file.			#
1.1.19 by Mark Grant
Import upstream version 1.0.17
103
# 07/04/2018	MG	1.3.4	Add -t --source-tarball CLA to build a	#
104
#				source tarball.				#
1.1.21 by Mark Grant
Import upstream version 1.0.19
105
# 01/07/2018	MG	1.3.5	Separate configure from build actions	#
106
#				and make options more standardised.	#
107
# 06/08/2018	MG	1.3.6	Add -H --header-check option.		#
108
#				Change error log file to build log.	#
109
# 22/08/2018	MG	1.3.7	Add verbose option.			#
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
110
# 24/03/2019	MG	1.4.1	Style if, for and while loops after C.	#
111
#				Use -proper- booleans.			#
112
#				Remove script_exit_code variable 	#
113
#				propogating the exit code as a function	#
114
#				argument instead.			#
115
#				Improve trap exit code handling.	#
116
#				Re-factor into functions.		#
117
#				Introduce more meaningful exit codes.	#
118
#				Tidy up local and global variables.	#
119
#				Add -a --at-only option.		#
120
#				Add -t --testing-hacks option.		#
121
#				Add support for non-option arguments	#
122
#				which are not option arguments being	#
123
#				passed straight through to the		#
124
#				configure command line apart from the	#
125
#				first which is the base directory. This	#
126
#				allows support for things like		#
127
#				--prefix=... etc.			#
128
#				Add missing error check after getopt.	#
129
#				Replace #! env bash with absolute path	#
130
#				via configure.				#
131
# 05/04/2019	MG	1.4.2	Just execute getopt command AOT eval.	#
132
#				Setup trap as early as possible.	#
133
# 30/04/2019	MG	1.4.3	Correct getopt CL for proper quoting.	#
134
#				Ensure variables used as input to other	#
135
#				commands are inputised and evaluated	#
136
#				with eval.				#
137
# 18/06/2019	MG	1.4.4	Add -K --check option to run		#
138
#				make --quiet check.			#
139
# 25/06/2019	MG	1.4.5	Remove distcheckfake option. Now done	#
140
#				by distcheck with configure flags in	#
141
#				top level makefile.			#
1.1.26 by Mark Grant
Import upstream version 1.1.1
142
# 28/10/2019	MG	1.4.6	Move script_exit() before it is used.	#
143
#				Cannot test for existence of file with	#
144
#				a variable which has retained quotes,	#
145
#				so introduce unquoted basedirunq.	#
146
# 01/12/2019	MG	1.4.7	Add parallel jobs option to pass to	#
147
#				make as --jobs				#
1.1.16 by Mark Grant
Import upstream version 1.0.15
148
#									#
149
#########################################################################
150
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
151
1.1.16 by Mark Grant
Import upstream version 1.0.15
152
##################
153
# Init variables #
154
##################
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
155
1.1.26 by Mark Grant
Import upstream version 1.1.1
156
readonly version=1.4.7			# set version variable
157
readonly packageversion=1.3.9	# Version of the complete package
1.1.16 by Mark Grant
Import upstream version 1.0.15
158
1.1.21 by Mark Grant
Import upstream version 1.0.19
159
# Set defaults
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
160
atonly=""
161
build=false
162
check=false
163
config=false
1.1.16 by Mark Grant
Import upstream version 1.0.15
164
debug=""
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
165
dist=false
166
distcheck=false
167
gnulib=false
1.1.21 by Mark Grant
Import upstream version 1.0.19
168
headercheck=""
1.1.26 by Mark Grant
Import upstream version 1.1.1
169
par_jobs=""
1.1.19 by Mark Grant
Import upstream version 1.0.17
170
sparse=""
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
171
tarball=false
172
testinghacks=""
173
verbose=false
1.1.21 by Mark Grant
Import upstream version 1.0.19
174
verboseconfig=" --enable-silent-rules=yes"
175
verbosemake=" --quiet"
1.1.26 by Mark Grant
Import upstream version 1.1.1
176
basedir="."			# Retain quotes
177
basedirunq=$basedir		# Without retaining quotes
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
178
configcli_extra_args=""
1.1.16 by Mark Grant
Import upstream version 1.0.15
179
180
181
#############
182
# Functions #
183
#############
184
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
185
# -h --help output.
186
# No parameters
187
# No return value
188
usage ()
189
{
190
cat << EOF
191
Usage:- acmbuild.sh / $0 [options] [-- configure options to pass on]
192
	-a or --at-only during testing and for an AutoTools-only install, some
193
		build changes are required. e.g. You may reference an external
194
		Java jar in datadir but in AT builds and installations this
195
		may expand to /usr/local/share... So a substitution is required
196
		for this scenario.
197
	-b or --build make the project
198
	-c or --config congigure the project
199
	-C or --distcheck perform normal distcheck
200
	-d or --debug build with appropriate debug flags
201
	-D or --dist perform a make dist
202
	-g or --gnulib run gnulib-tool --update
203
	-h or --help displays usage information
204
	-H or --header-check show include stack depth
205
	-K or --check run make check
1.1.26 by Mark Grant
Import upstream version 1.1.1
206
	-p[X] or --parallel-jobs[=X] number of jobs to pass to make as --jobs=
207
		If not specified make is sequential
208
		If no value X is given then defaults to nproc
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
209
	-s or --sparse build using sparse
210
	-t or --testing-hacks some build changes may be required for testing
211
		purposes. e.g. A script may invoke a project jar file which
212
		when installed will be somewhere under datadir, but during
213
		testing it is in the project tree.
214
	-T or --source-tarball create source tarball
215
	-v or --verbose emit extra information
216
	-V or --version displays version information
217
EOF
218
}
219
220
# Standard function to emit messages depending on various parameters.
221
# Parameters -	$1 What:-	The message to emit.
222
#		$2 Where:-	stdout == 0
223
#				stderr == 1
224
# No return value.
1.1.16 by Mark Grant
Import upstream version 1.0.15
225
output()
226
{
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
227
	if (( !$2 )); then
228
		printf "%s\n" "$1"
1.1.16 by Mark Grant
Import upstream version 1.0.15
229
	else
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
230
		printf "%s\n" "$1" 1>&2
1.1.16 by Mark Grant
Import upstream version 1.0.15
231
	fi
232
}
233
1.1.26 by Mark Grant
Import upstream version 1.1.1
234
# Standard function to tidy up and return exit code.
235
# Parameters - 	$1 is the exit code.
236
# No return value.
237
script_exit()
238
{
239
	exit $1
240
}
241
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
242
# Standard function to test command error and exit if non-zero.
243
# Parameters - 	$1 is the exit code, (normally $? from the preceeding command).
244
# No return value.
1.1.16 by Mark Grant
Import upstream version 1.0.15
245
std_cmd_err_handler()
246
{
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
247
	if (( $1 )); then
248
		script_exit $1
1.1.16 by Mark Grant
Import upstream version 1.0.15
249
	fi
250
}
251
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
252
# Standard trap exit function.
253
# No parameters.
254
# No return value.
1.1.16 by Mark Grant
Import upstream version 1.0.15
255
trap_exit()
256
{
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
257
	local -i exit_code=$?
258
	local msg
259
260
	msg="Script terminating with exit code $exit_code due to trap received."
261
	output "$msg" 1
262
	script_exit $exit_code
1.1.16 by Mark Grant
Import upstream version 1.0.15
263
}
264
265
# Setup trap
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
266
trap trap_exit SIGHUP SIGINT SIGQUIT SIGTERM
1.1.16 by Mark Grant
Import upstream version 1.0.15
267
268
# Process command line arguments with GNU getopt.
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
269
# Parameters -	$1 is the command line.
270
# No return value.
271
proc_CL()
272
{
273
	local GETOPTTEMP
274
	local script_name="acmbuild.sh/bootstrap.sh"
275
	local tmp
276
1.1.26 by Mark Grant
Import upstream version 1.1.1
277
	tmp="getopt -o abcCdDghHKp::stTvV "
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
278
	tmp+="--long at-only,build,check,config,distcheck,debug,dist,gnulib,"
1.1.26 by Mark Grant
Import upstream version 1.1.1
279
	tmp+="help,header-check,parallel-jobs::,sparse,source-tarball,"
280
	tmp+="testing-hacks,verbose,version"
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
281
	GETOPTTEMP=$($tmp -n "$script_name" -- "$@")
282
	std_cmd_err_handler $?
283
284
	eval set -- "$GETOPTTEMP"
285
	std_cmd_err_handler $?
286
287
	while true; do
288
		case "$1" in
289
		-a|--at-only)
290
			atonly=" --enable-atonly=yes"
291
			shift
292
			;;
293
		-b|--build)
294
			if $distcheck || $dist || $tarball; then
295
				msg="Options b, C, D and T are mutually "
296
				msg+="exclusive."
297
				output "$msg" 1
298
				script_exit 64
299
			fi
300
			build=true
301
			shift
302
			;;
303
		-c|--config)
304
			config=true
305
			shift
306
			;;
307
		-C|--distcheck)
308
			if $build || $dist || $tarball ; then
309
				msg="Options b, C, D and T are mutually "
310
				msg+="exclusive."
311
				output "$msg" 1
312
				script_exit 64
313
			fi
314
			distcheck=true
315
			shift
316
			;;
317
		-d|--debug)
318
			debug=" --enable-debug=yes"
319
			shift
320
			;;
321
		-D|--dist)
322
			if $build || $distcheck || $tarball ; then
323
				msg="Options b, C, D and T are mutually "
324
				msg+="exclusive."
325
				output "$msg" 1
326
				script_exit 64
327
			fi
328
			dist=true
329
			shift
330
			;;
331
		-g|--gnulib)
332
			gnulib=true
333
			shift
334
			;;
335
		-h|--help)
336
			usage
337
			shift
338
			script_exit 0
339
			;;
340
		-H|--header-check)
341
			headercheck=" --enable-headercheck=yes"
342
			shift
343
			;;
1.1.26 by Mark Grant
Import upstream version 1.1.1
344
		-p|--parallel-jobs)
345
			if [[ -z "$2" ]]; then
346
				par_jobs=" --jobs=$(nproc)"
347
			else
348
				par_jobs=" --jobs=$2"
349
			fi
350
			shift 2
351
			;;
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
352
		-K|--check)
353
			if $distcheck || $dist || $tarball; then
354
				msg="Options C, D, K and T are mutually "
355
				msg+="exclusive."
356
				output "$msg" 1
357
				script_exit 64
358
			fi
359
			check=true
360
			shift
361
			;;
362
		-s|--sparse)
363
			sparse=" --enable-sparse=yes"
364
			shift
365
			;;
366
		-t|--testing-hacks)
367
			testinghacks=" --enable-testinghacks=yes"
368
			shift
369
			;;
370
		-T|--source-tarball)
371
			if $build || $distcheck || $dist ; then
372
				msg="Options b, C, D and T are mutually "
373
				msg+="exclusive."
374
				output "$msg" 1
375
				script_exit 64
376
			fi
377
			tarball=true
378
			shift
379
			;;
380
		-v|--verbose)
381
			verbose=true
382
			verboseconfig=""
383
			verbosemake=""
384
			shift
385
			;;
386
		-V|--version)
387
			printf "Script version %s\n" $version
388
			printf "Package version %s\n" $packageversion
389
			shift
390
			script_exit 0
391
			;;
392
		--)	shift
393
			break
394
			;;
395
		*)	output "Internal error." 1
396
			script_exit 64
397
			;;
398
		esac
399
	done
400
401
	if [[ $atonly || $debug || $headercheck || $sparse || $testinghacks ]] \
402
		|| $verbose ; then
403
		if ! $config ; then
404
			msg="Options a, d, H, s, t and v require option c."
405
			output "$msg" 1
406
			script_exit 64
407
		fi
408
	fi
409
410
	# One option has to be selected.
411
	if ! $build && ! $check && ! $config && ! $distcheck && ! $dist \
412
		&& ! $gnulib && ! $tarball ; then
413
		output "Either b, c, C, D, g, K or T must be set." 1
414
		script_exit 64
415
	fi
416
417
	# First non-option argument which is not an option argument is the base
418
	# directory, all others are passed straight to the configure command
419
	# line, (to support things like  --prefix=... etc). Both of these need
420
	# to be inputised before they are passed on in order to maintain
421
	# original quoting. They can then be 'eval'ed.
422
	if (( $# )); then
423
		basedir=${1@Q}
1.1.26 by Mark Grant
Import upstream version 1.1.1
424
		basedirunq="$1"		# Unquoted version
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
425
		shift
426
		configcli_extra_args=" "${@@Q}
427
	fi
428
}
429
430
# Process gnulib option
431
# No parameters.
432
# No return value
433
proc_gnulib()
434
{
435
	local cmdline
436
	local msg
437
	local status
438
1.1.26 by Mark Grant
Import upstream version 1.1.1
439
	if [[ -f "$basedirunq/m4/gnulib-cache.m4" ]]; then
1.1.21 by Mark Grant
Import upstream version 1.0.19
440
		cmdline="gnulib-tool --update"$verbosemake$verbosemake
441
		cmdline+=" --dir="$basedir
1.1.16 by Mark Grant
Import upstream version 1.0.15
442
		eval "$cmdline"
443
		status=$?
444
		output "$cmdline completed with exit status: $status" $status
445
		std_cmd_err_handler $status
446
	else
447
		msg="Option -g --gnulib ignored - "
448
		msg+="missing $basedir/m4/gnulib-cache.m4"
449
		output "$msg" 0
450
	fi
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
451
}
452
453
# Process configure
454
# No parameters
455
# No return value
456
proc_config()
457
{
458
	local cmdline
459
	local msg
460
	local status
461
462
	cmdline="autoreconf -if $basedir"
463
	eval "$cmdline"
1.1.21 by Mark Grant
Import upstream version 1.0.19
464
	status=$?
465
	msg="autoreconf -if "$basedir" completed with exit status: $status"
466
	output "$msg" $status
467
	std_cmd_err_handler $status
468
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
469
	cmdline="$basedir/configure$configcli_extra_args$verboseconfig"
470
	cmdline+="$atonly$debug$headercheck$sparse$testinghacks"
471
472
	eval "$cmdline"
473
	status=$?
474
	output "$cmdline completed with exit status: $status" $status
475
	std_cmd_err_handler $status
476
}
477
478
# Process the correct make variation.
479
# No parameters.
480
# Returns 0 or command line error.
481
proc_make()
482
{
483
	local cmdline
484
	local status
485
486
	if $build ; then
1.1.26 by Mark Grant
Import upstream version 1.1.1
487
		cmdline="make"$verbosemake$par_jobs
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
488
	fi
489
490
	if $check ; then
491
		if [[ ! $cmdline ]]; then
1.1.26 by Mark Grant
Import upstream version 1.1.1
492
			cmdline="make"$verbosemake$par_jobs
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
493
		fi
494
		cmdline+=" check"
495
	fi
496
497
	if $distcheck ; then
1.1.26 by Mark Grant
Import upstream version 1.1.1
498
		cmdline="make"$verbosemake$par_jobs" distcheck clean"
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
499
	fi
500
501
	if $dist ; then
1.1.26 by Mark Grant
Import upstream version 1.1.1
502
		cmdline="make"$verbosemake$par_jobs" dist clean"
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
503
	fi
504
505
	if $tarball ; then
1.1.26 by Mark Grant
Import upstream version 1.1.1
506
		cmdline="make"$verbosemake$par_jobs" srctarball clean"
1.1.24 by Mark Grant
Import upstream version 1.0.21+rc1
507
	fi
508
509
	# May get here with cmdline empty if, for example, only the -g option
510
	# was set.
511
	if [[ ! $cmdline ]]; then
512
		return 0
513
	fi
514
515
	eval "$cmdline"
516
	status=$?
517
	output "$cmdline completed with exit status: $status" $status
518
	return $status
519
}
520
521
522
########
523
# Main #
524
########
525
526
proc_CL "$@"
527
528
# Create build log.
529
exec 1> >(tee build-output.txt) 2>&1
530
531
# Now the main processing.
532
if $gnulib ; then
533
	proc_gnulib
534
fi
535
536
if $config ; then
537
	proc_config
538
fi
539
540
proc_make
541
std_cmd_err_handler $?
542
543
script_exit 0
544