-
Notifications
You must be signed in to change notification settings - Fork 58
/
bootstrap
executable file
·369 lines (322 loc) · 12.7 KB
/
bootstrap
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
#! /bin/sh -
# Top level bootstrap file.
# This is not a standard starconf bootstrap file.
buildsupportonly=false
dryrun=false
need_gnu_m4=false
buildsupport_prefix=
USAGE="Usage: $0 [--buildsupport | --buildsupport-prefix=inst-dir | --dry-run | -n | --help]"
while test $# -gt 0
do
case $1 in
--buildsupport)
buildsupportonly=:
;;
--buildsupport-prefix=*)
buildsupport_prefix=`expr x$1 : 'x--buildsupport-prefix=\(.*\)'`
;;
--dry-run|-n)
dryrun=:
;;
--force-starconf|--buildsupport-only)
echo "Option $1 is redundant: use --buildsupport" >&2
exit 1
;;
--help)
cat <<EOD
Usage: $0 [options]
Available options:
--buildsupport Build and install the buildsupport tools, and
nothing else. Deletes any preexisting
buildsupport manifest files, to force all of
these tools to be rebuilt.
--buildsupport-prefix=<X>
The buildsupport tools should be installed or found
under directory X, rather than the default
$STARCONF_DEFAULT_PREFIX/buildsupport. You
must add X/bin to your PATH. This only specifies
the directory: if you wish the bootstrap to stop
after installing the tools, then specify
--bootstrap as well.
-n, --dry-run Show the installation locations which the
script works out, but don't actually do anything.
--help Show this help.
EOD
exit 0
;;
*)
echo $USAGE >&2
exit 1
;;
esac
shift
done
# Echo a command then run it, terminating the script if the command fails
echorun() { echo $*; eval $* || exit 1; }
# Add an exit/interrupt trap to remove temporary and generated files
removefiles=""
trap '{ for f in $removefiles dummy; do rm -f "$f"; done; }' 0 HUP INT QUIT TERM
# Starconf uses the value of STARCONF_DEFAULT_{PREFIX,STARLINK}
# during its configuration. We set these here, unless they're set
# in the environment. Starconf's configure.ac sets these anyway, and
# defaults them in a way which is similar or identical to what we do
# here, however it makes sense to make this explicit.
#
# See starconf's configure.ac and starconf.m4.in for discussion of
# these variables. Command `starconf --show --all' shows the values
# that starconf finally ends up with.
if test "X$STARCONF_DEFAULT_STARLINK" = X; then
for d in "$STARLINK" /star
do
if test -n "$d"; then
STARCONF_DEFAULT_STARLINK=$d
break
fi
done
fi
if test "X$STARCONF_DEFAULT_PREFIX" = X; then
for d in "$STARCONF_DEFAULT_STARLINK" "$STARLINK" /star
do
if test -n "$d"; then
STARCONF_DEFAULT_PREFIX=$d
break
fi
done
fi
# Test whether system m4 (or at least the first m4 in the path) is GNU m4.
# The autotools built below require features present only in GNU m4.
# Environment variable M4 overrides test for m4 in path.
if test -z "$M4"; then
for prog in gm4 gnum4 m4
do
for d in `IFS=:; echo $PATH`
do
if test -f $d/$prog; then
M4=$d/$prog
break 2
fi
done
done
fi
# We now (should) have a m4 binary in the path. Check it's GNU m4, and if it is,
# check it has frozen state files (should mean version 1.3 or better).
# Cf. macro AC_PROG_GNU_M4 in the autoconf distribution.
need_gnu_m4=true
if test "x$M4" != x; then
if test `echo 'changequote([,])ifdef([__gnu__], isgnu, notgnu)' | $M4` = isgnu; then
case `$M4 --help </dev/null 2>&1` in
*reload-state*) need_gnu_m4=false ;;
esac
fi
fi
if $need_gnu_m4; then
echo "m4 at $M4 is no good -- bootstrap will build GNU m4"
echo "You can specify a location for GNU m4 with env. variable M4"
else
# Use the m4 binary we found
echo "m4 at $M4 is OK"
export M4
fi
# Makefile.dependencies uses BUILDSUPPORT_PREFIX to configure
# the buildsupport tools
if test -n "$buildsupport_prefix"; then
BUILDSUPPORT_PREFIX=$buildsupport_prefix
else
BUILDSUPPORT_PREFIX=$STARCONF_DEFAULT_PREFIX/buildsupport
fi
# Let the user know what we've decided
echo "Bootstrapping with"
echo " STARCONF_DEFAULT_STARLINK = $STARCONF_DEFAULT_STARLINK"
echo " STARCONF_DEFAULT_PREFIX = $STARCONF_DEFAULT_PREFIX"
echo " BUILDSUPPORT_PREFIX = $BUILDSUPPORT_PREFIX"
echo " Do we need to build GNU m4? $need_gnu_m4"
if $buildsupportonly; then
echo " Buildsupport only -- deleting buildsupport manifests"
fi
# Test whether important paths have spaces in them
# (this is a natural thing to do on OSX or Windows boxes).
# Autoconf has grave problems with this, so we should exit cleanly now,
# rather than in a heap later, and get the user to change directory. Pity.
for d in PWD STARCONF_DEFAULT_STARLINK STARCONF_DEFAULT_PREFIX
do
eval expr "\"\$$d\"" : "'.* '" >/dev/null
if test $? = 0; then
eval echo "\"Environment variable $d=\\\"\$$d\\\" has a space in it\""
echo "This causes unavoidable problems with the autoconf system,"
echo "so, unfortunately, we can't proceed."
# exit immediately
exit 1
fi
done
if $dryrun; then
exit 0
fi
# The git repository contains various submodules that must be available
# before we can proceed. Make sure that these are up-to-date.
./update-modules
if test $? -ne 0; then
echo ""
echo "The './update-modules' script has failed to complete."
echo ""
echo "Check that git is available and can run on this system and that it"
echo "is able to download submodules. Note you can just run the "
echo "'./update-modules' command directly while checking the problem."
echo ""
echo "It may now be necessary to clean up the repository before you can"
echo "proceed. See the 'Notes' section in the './update-modules' script."
exit 1
fi
# We invoke autoconf below, so must make sure it's on the path,
# and this directory must be on the path before bootstrapping the
# buildsupport directories below
PATH=$BUILDSUPPORT_PREFIX/bin:$PATH
# Configure and build the bootstrap utilities.
# Make sure that componentinfo.dtd exists.
# Link to the uninstalled version of the file.
# (we just have to hope that `ln -s' works on this platform...).
test -f componentinfo.dtd ||
echorun ln -s buildsupport/starconf/componentinfo.dtd componentinfo.dtd
# Create the $STARCONF_DEFAULT_PREFIX/bin directory if we can, but
# don't worry if we can't. If this exists, then the starconf
# installation adds convenience links from there to some of its
# applications in $BUILDSUPPORT_PREFIX/bin.
test -d $STARCONF_DEFAULT_PREFIX/bin || \
mkdir -p $STARCONF_DEFAULT_PREFIX/bin 2>/dev/null
# We make a temporary makefile from Makefile.in. This can be used,
# unconfigured, below.
tempmakefile=Makefile.tmp
removefiles="$removefiles $tempmakefile"
rm -f $tempmakefile
sed -e 's/@JAVA@/NOJAVA/' -e 's/@[a-zA-Z0-9_]*@/#DUMMY/' Makefile.in >$tempmakefile
# Now invoke 'make buildsupport', using this temporary makefile, and
# setting environment variables appropriately. These variables have
# to be exported, so contain them in a subshell.
(
MISSING_SUPPRESS_RUN=true
if test -n "$buildsupport_prefix"; then
# this was not defaulted, so install the manifests next to the
# installation binary location
STAR_MANIFEST_DIR=$BUILDSUPPORT_PREFIX/manifests
else
STAR_MANIFEST_DIR=$STARCONF_DEFAULT_PREFIX/manifests
fi
# Export these to subprocesses.
# These are referred to in configure scripts
export STARCONF_DEFAULT_STARLINK STARCONF_DEFAULT_PREFIX STAR_MANIFEST_DIR
# Referred to in (Starlink-specific) `missing' scripts
export MISSING_SUPPRESS_RUN
# Referred to in Makefile.dependencies for buildsupport tools
export BUILDSUPPORT_PREFIX
# The commands run within makefiles must use the correct buildsupport tools
export PATH
# If the option --buildsupport was given, then delete all of
# the buildsupport manifests, to force the tools to be rebuilt.
# This probably does more than is strictly necessary, but that
# does no harm.
if $buildsupportonly; then
echo "Cleaning buildsupport:"
echo " make -f $tempmakefile \\"
echo " MANIFESTS=$STAR_MANIFEST_DIR \\"
echo " clean-buildsupport"
make -f $tempmakefile \
MANIFESTS=$STAR_MANIFEST_DIR \
clean-buildsupport || {
echo "Can't clean buildsupport">&2
exit 1
}
fi
if $need_gnu_m4; then
echo "Building GNU m4:"
echorun make -f $tempmakefile \
prefix=$BUILDSUPPORT_PREFIX \
MANIFESTS=$STAR_MANIFEST_DIR \
$STAR_MANIFEST_DIR/m4
fi
echo "Bootstrapping buildsupport:"
echo " make -f $tempmakefile \\"
echo " prefix=$BUILDSUPPORT_PREFIX \\"
echo " MANIFESTS=$STAR_MANIFEST_DIR \\"
echo " buildsupport"
make -f $tempmakefile \
prefix=$BUILDSUPPORT_PREFIX \
MANIFESTS=$STAR_MANIFEST_DIR \
buildsupport
) || { echo "Failed to make buildsupport">&2; exit 1; }
# rm -f $tempmakefile # removed by exit trap
if $buildsupportonly; then
exit 0
fi
# Substitute the correct prefix in to a temporary configure.ac file.
#
# The default prefix in the ./configure script MUST be consistent with
# that in starconf, which has it set to $STARCONF_DEFAULT_PREFIX.
# File configure.ac.in has the default prefix set to %%PREFIX%%,
# which is not a directory.
# 1. substitute %%PREFIX%% with the correct value, to create
# configure.ac from configure.ac.in;
# 2. bootstrap each of the AC_CONFIG_SUBDIRS in configure.ac;
# 3. then use autoreconf to generate ./configure from configure.ac.
# To discourage folk from running auto(re)conf by hand, we make sure
# that configure.ac does not normally exist.
rm -f configure.ac
removefiles="$removefiles configure.ac temp-file"
echorun "sed -e 's,%%PREFIX%%,$STARCONF_DEFAULT_PREFIX,' configure.ac.in >temp-file && mv -f temp-file configure.ac"
# Bootstrap any child directories (before running autoreconf). Each
# bootstrap file potentially calls autoreconf, and this can take a
# while. It's unnecessary, too, since we're about to call autoreconf
# here, and that will work in all the children. So set
# STAR_SUPPRESS_AUTORECONF and export it: all the (standard, starconf)
# bootstrap files are written so as to suppress their call of
# autoreconf if that variable is true in the environment.
STAR_SUPPRESS_AUTORECONF=true
export STAR_SUPPRESS_AUTORECONF
for d in `autoconf --trace=AC_CONFIG_SUBDIRS:$% configure.ac` DUMMY
do
if test -n "$d" -a -d "$d"; then
echo "BOOTSTRAPPING $d..."
(cd $d && ./bootstrap)
fi
done
# NOW do the autoreconf in all the children
# (Re)configure, installing missing files
echo "GENERATING configure SCRIPTS..."
echorun autoreconf --install --symlink
# Because buildsupport is not mentioned in AC_CONFIG_SUBDIRS in
# configure.ac (because we don't want ./configure to recurse into
# them), the autoreconf above did not run autoreconf in buildsupport.
# Do that now (partly because we want buildsupport/install-sh from
# there, but mostly for symmetry). The --force appears to be necessary,
# though I don't have a convincing explanation of why, since there
# shouldn't be anything there already.
(cd buildsupport && autoreconf --install --symlink --force) || {
echo "Failed to autoreconf buildsupport">&2
exit 1
}
# autoreconf/automake does _not_ add an install-sh link, because there's no
# Makefile.am in this directory, so automake thinks we don't need one. We
# do, however, because the child directories have Makefile.am's, and
# want to refer to one here. So copy the link that automake _did_
# put into the buildsupport directory.
get_install_sh=buildsupport/install-sh
test -f $get_install_sh || {
echo "Ooops: ./bootstrap can't find $get_install_sh" >&2
exit 1
}
echo cp $get_install_sh .
cp $get_install_sh .
# Run configure WITHOUT RECURSION to create a basic Makefile which
# will allow us to invoke 'make configure-deps'. NOTE: This option isn't
# advertised in the help, so it may not be public.
./configure --no-recursion || {
echo "Failed to configure top-level directory">&2
exit 1
}
# If there is a non-empty list of configure-deps in Makefile.dependencies,
# then remind the user to make them.
if grep '^configure-deps: *\\' Makefile.dependencies >/dev/null; then
echo "Run 'make configure-deps' before configuration"
echo "Then run './configure -C'"
else
echo "Run './configure -C' to configure the entire tree"
fi
exit 0