~m-grant-prg/kernel-utils/trunk

« back to all changes in this revision

Viewing changes to bootstrap.sh

  • Committer: Mark Grant
  • Date: 2018-04-10 07:38:40 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: m.grant.prg@gmail.com-20180410073840-g6ztfr6egvbptfeu
Tags: upstream-1.0.11
ImportĀ upstreamĀ versionĀ 1.0.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env bash
 
2
#########################################################################
 
3
#                                                                       #
 
4
#       bootstrap.sh is automatically generated,                        #
 
5
#               please do not modify!                                   #
 
6
#                                                                       #
 
7
#########################################################################
 
8
 
 
9
#########################################################################
 
10
#                                                                       #
 
11
# Script ID: bootstrap.sh                                               #
 
12
# Author: Copyright (C) 2014-2018  Mark Grant                           #
 
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
#                                                                       #
 
20
# Syntax:       bootstrap.sh    [ -c || --distcheck ] ||                #
 
21
#                               [ -d || --debug ] ||                    #
 
22
#                               [ -D || --dist ] ||                     #
 
23
#                               [ -f || --distcheckfake ] ||            #
 
24
#                               [ -g || --gnulib ] ||                   #
 
25
#                               [ -h || --help ] ||                     #
 
26
#                               [ -m || --make ] ||                     #
 
27
#                               [ -s || --sparse ] ||                   #
 
28
#                               [ -t || --source-tarball ] ||           #
 
29
#                               [ -V || --version-V ]                   #
 
30
#                                                                       #
 
31
# Exit Codes:   0 - success                                             #
 
32
#               1 - failure.                                            #
 
33
#                                                                       #
 
34
# Further Info:                                                         #
 
35
#                                                                       #
 
36
#########################################################################
 
37
 
 
38
#########################################################################
 
39
#                                                                       #
 
40
# Changelog                                                             #
 
41
#                                                                       #
 
42
# Date          Author  Version Description                             #
 
43
#                                                                       #
 
44
# 25/06/2014    MG      1.0.1   Created.                                #
 
45
# 02/08/2014    MG      1.0.2   Change naming from AutoTools to         #
 
46
#                               AutoConf and Make.                      #
 
47
# 27/10/2014    MG      1.0.3   Seperated each command in order to test #
 
48
#                               exit status.                            #
 
49
# 13/11/2014    MG      1.0.4   Switched from getopts to GNU getopt to  #
 
50
#                               allow long options.                     #
 
51
# 16/11/2014    MG      1.0.5   Modify getopt processing to allow for   #
 
52
#                               FreeBSD's quirk of 2 different getopt   #
 
53
#                               programs. See comments at the start of  #
 
54
#                               "Main"                                  #
 
55
# 16/11/2014    MG      1.0.6   Remove erroneous option.                #
 
56
# 18/11/2014    MG      1.0.7   Change FreeBSD specifics to *BSD and    #
 
57
#                               change Linux to be the default.         #
 
58
# 24/11/2014    MG      1.0.8   Add overall package version to -V.      #
 
59
# 28/03/2015    MG      1.0.9   Remove BSD support.                     #
 
60
# 31/01/2017    MG      1.1.1   Add debug make dist and make options.   #
 
61
# 25/02/2017    MG      1.2.0   Add distcheck & distcheckfake options.  #
 
62
# 25/06/2017    MG      1.2.1   Enforce 80 column rule.                 #
 
63
# 01/12/2017    MG      1.2.2   Add SPDX license tags to source files.  #
 
64
# 04/12/2017    MG      1.2.3   Adopt standard exit codes; 0 on success #
 
65
#                               1 on failure.                           #
 
66
# 06/02/2018    MG      1.3.1   Renamed from acmbuild.                  #
 
67
#                               Add -g option.                          #
 
68
#                               General script tidy up.                 #
 
69
# 09/02/2018    MG      1.3.2   Remove script name from -V --version    #
 
70
#                               print as this may have been invoked by  #
 
71
#                               acmbuild.sh.                            #
 
72
# 24/03/2018    MG      1.3.3   Add support for sparse CLA.             #
 
73
#                               Add stderr log file.                    #
 
74
# 07/04/2018    MG      1.3.4   Add -t --source-tarball CLA to build a  #
 
75
#                               source tarball.                         #
 
76
#                                                                       #
 
77
#########################################################################
 
78
 
 
79
##################
 
80
# Init variables #
 
81
##################
 
82
script_exit_code=0
 
83
version="1.3.4"                 # set version variable
 
84
packageversion=v1.2.7   # Version of the complete package
 
85
 
 
86
debug=""
 
87
dist=FALSE
 
88
distcheck=FALSE
 
89
distcheckfake=FALSE
 
90
gnulib=FALSE
 
91
make=FALSE
 
92
sparse=""
 
93
tarball=FALSE
 
94
basedir="."
 
95
cmdline=""
 
96
 
 
97
 
 
98
#############
 
99
# Functions #
 
100
#############
 
101
 
 
102
# Output $1 to stdout or stderr depending on $2.
 
103
output()
 
104
{
 
105
        if [ $2 = 0 ]
 
106
        then
 
107
                echo "$1"
 
108
        else
 
109
                echo "$1" 1>&2
 
110
        fi
 
111
}
 
112
 
 
113
# Standard function to test command error ($1 is $?) and exit if non-zero
 
114
std_cmd_err_handler()
 
115
{
 
116
        if [ $1 != 0 ]
 
117
        then
 
118
                script_exit_code=$1
 
119
                script_exit
 
120
        fi
 
121
}
 
122
 
 
123
# Standard function to cleanup and return exit code
 
124
script_exit()
 
125
{
 
126
        exit $script_exit_code
 
127
}
 
128
 
 
129
# Standard trap exit function
 
130
trap_exit()
 
131
{
 
132
script_exit_code=1
 
133
output "Script terminating due to trap received." 1
 
134
script_exit
 
135
}
 
136
 
 
137
# Setup trap
 
138
trap trap_exit SIGHUP SIGINT SIGTERM
 
139
 
 
140
########
 
141
# Main #
 
142
########
 
143
# Process command line arguments with GNU getopt.
 
144
tmp="getopt -o cdDfghmstV "
 
145
tmp+="--long distcheck,debug,dist,distcheckfake,gnulib,help,make,sparse,"
 
146
tmp+="source-tarball,version "
 
147
tmp+="-n $0 -- $@"
 
148
GETOPTTEMP=`eval $tmp`
 
149
eval set -- "$GETOPTTEMP"
 
150
std_cmd_err_handler $?
 
151
 
 
152
 
 
153
while true
 
154
do
 
155
        case "$1" in
 
156
        -c|--distcheck)
 
157
                if [ $dist = TRUE -o $distcheckfake = TRUE -o $make = TRUE \
 
158
                        -o $tarball = TRUE ]
 
159
                then
 
160
                        script_exit_code=1
 
161
                        msg="Options c, D, f, m and t are mutually exclusive."
 
162
                        output "$msg" 1
 
163
                        script_exit
 
164
                fi
 
165
                distcheck=TRUE
 
166
                shift
 
167
                ;;
 
168
        -d|--debug)
 
169
                debug=" --enable-debug=yes"
 
170
                shift
 
171
                ;;
 
172
        -D|--dist)
 
173
                if [ $distcheck = TRUE -o $distcheckfake = TRUE \
 
174
                        -o $make = TRUE -o $tarball = TRUE ]
 
175
                then
 
176
                        script_exit_code=1
 
177
                        msg="Options c, D, f, m and t are mutually exclusive."
 
178
                        output "$msg" 1
 
179
                        script_exit
 
180
                fi
 
181
                dist=TRUE
 
182
                shift
 
183
                ;;
 
184
        -f|--distcheckfake)
 
185
                if [ $distcheck = TRUE -o $dist = TRUE -o $make = TRUE \
 
186
                        -o $tarball = TRUE ]
 
187
                then
 
188
                        script_exit_code=1
 
189
                        msg="Options c, D, f, m and t are mutually exclusive."
 
190
                        output "$msg" 1
 
191
                        script_exit
 
192
                fi
 
193
                distcheckfake=TRUE
 
194
                shift
 
195
                ;;
 
196
        -g|--gnulib)
 
197
                gnulib=TRUE
 
198
                shift
 
199
                ;;
 
200
        -h|--help)
 
201
                echo "Usage is:-"
 
202
                echo "  -c or --distcheck perform normal distcheck"
 
203
                echo "  -d or --debug build with appropriate debug flags"
 
204
                echo "  -D or --dist perform a make dist"
 
205
                echo "  -f or --distcheckfake fake a distcheck for fixed root"
 
206
                echo "  -g or --gnulib run gnulib-tool --update"
 
207
                echo "  -h or --help displays usage information"
 
208
                echo "  -m or --make compile and link - plain make"
 
209
                echo "  -s or --sparse build using sparse"
 
210
                echo "  -t or --source-tarball create source tarball"
 
211
                echo "  -V or --version displays version information"
 
212
                shift
 
213
                script_exit_code=0
 
214
                script_exit
 
215
                ;;
 
216
        -m|--make)
 
217
                if [ $distcheck = TRUE -o $dist = TRUE \
 
218
                        -o $distcheckfake = TRUE -o $tarball = TRUE ]
 
219
                then
 
220
                        script_exit_code=1
 
221
                        msg="Options c, D, f, m and t are mutually exclusive."
 
222
                        output "$msg" 1
 
223
                        script_exit
 
224
                fi
 
225
                make=TRUE
 
226
                shift
 
227
                ;;
 
228
        -s|--sparse)
 
229
                sparse=" --enable-sparse=yes"
 
230
                shift
 
231
                ;;
 
232
        -t|--source-tarball)
 
233
                if [ $distcheck = TRUE -o $dist = TRUE \
 
234
                        -o $distcheckfake = TRUE -o $make = TRUE ]
 
235
                then
 
236
                        script_exit_code=1
 
237
                        msg="Options c, D, f, m and t are mutually exclusive."
 
238
                        output "$msg" 1
 
239
                        script_exit
 
240
                fi
 
241
                tarball=TRUE
 
242
                shift
 
243
                ;;
 
244
        -V|--version)
 
245
                echo "Script version "$version
 
246
                echo "Package version "$packageversion
 
247
                shift
 
248
                script_exit_code=0
 
249
                script_exit
 
250
                ;;
 
251
        --)     shift
 
252
                break
 
253
                ;;
 
254
        *)      script_exit_code=1
 
255
                output "Internal error." 1
 
256
                script_exit
 
257
                ;;
 
258
        esac
 
259
done
 
260
 
 
261
# Script can accept 1 other argument, the base directory.
 
262
if [ $# -gt 1 ]
 
263
then
 
264
        script_exit_code=1
 
265
        output "Invalid argument." 1
 
266
        script_exit
 
267
fi
 
268
 
 
269
if [ $# -eq 1 ]
 
270
then
 
271
        basedir=$1
 
272
fi
 
273
 
 
274
# One option has to be selected.
 
275
if [ $distcheck = FALSE -a $dist = FALSE -a $distcheckfake = FALSE \
 
276
        -a $make = FALSE -a $tarball = FALSE ]
 
277
then
 
278
        script_exit_code=1
 
279
        output "Either c, D, f, m or t must be set." 1
 
280
        script_exit
 
281
fi
 
282
 
 
283
# Create build error log.
 
284
exec 2> >(tee build-stderr.txt >&2)
 
285
 
 
286
 
 
287
# Now the main processing.
 
288
if [ $gnulib = TRUE ]
 
289
then
 
290
        if [ -f $basedir/m4/gnulib-cache.m4 ]
 
291
        then
 
292
                cmdline="gnulib-tool --update --quiet --quiet --dir="$basedir
 
293
                eval "$cmdline"
 
294
                status=$?
 
295
                output "$cmdline completed with exit status: $status" $status
 
296
                std_cmd_err_handler $status
 
297
        else
 
298
                msg="Option -g --gnulib ignored - "
 
299
                msg+="missing $basedir/m4/gnulib-cache.m4"
 
300
                output "$msg" 0
 
301
        fi
 
302
fi
 
303
 
 
304
autoreconf -if $basedir
 
305
status=$?
 
306
output "autoreconf -if "$basedir" completed with exit status: $status" $status
 
307
std_cmd_err_handler $status
 
308
 
 
309
cmdline=$basedir"/configure --enable-silent-rules=yes"$debug$sparse
 
310
 
 
311
if [ $distcheckfake = TRUE ]
 
312
then
 
313
        cmdline=$cmdline" --enable-distcheckfake=yes"
 
314
fi
 
315
 
 
316
eval "$cmdline"
 
317
status=$?
 
318
output "$cmdline completed with exit status: $status" $status
 
319
std_cmd_err_handler $status
 
320
 
 
321
cmdline="make --quiet"
 
322
if [ $distcheck = TRUE ]
 
323
then
 
324
        cmdline=$cmdline" distcheck distclean"
 
325
fi
 
326
 
 
327
if [ $dist = TRUE ]
 
328
then
 
329
        cmdline=$cmdline" dist clean distclean"
 
330
fi
 
331
 
 
332
if [ $distcheckfake = TRUE ]
 
333
then
 
334
        cmdline=$cmdline" distcheck distclean"
 
335
        cmdline=$cmdline" DISTCHECK_CONFIGURE_FLAGS=--enable-distcheckfake=yes"
 
336
fi
 
337
 
 
338
if [ $tarball = TRUE ]
 
339
then
 
340
        cmdline=$cmdline" srctarball distclean"
 
341
fi
 
342
 
 
343
eval "$cmdline"
 
344
status=$?
 
345
output "$cmdline completed with exit status: $status" $status
 
346
std_cmd_err_handler $status
 
347
 
 
348
 
 
349
script_exit_code=0
 
350
script_exit