Support more special chars in $(LIBDIR) etc
[autoconf.git] / bootstrap
blobb2da1a0c8571f2115959eb5bb1f71f35d6225cb7
1 #! /bin/sh
3 # This script helps bootstrap autoconf, when checked out from git.
5 # Copyright (C) 2021-2024 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 # Autoconf's own configure script is generated using Autoconf. This
21 # script does what running `autoreconf -i` in an Autoconf git checkout
22 # would do, except that it uses autoconf from the source tree we are
23 # preparing, not any version of autoconf that might or might not be
24 # installed already. Note that automake, Perl, and GNU M4 _are_
25 # required to be installed already.
27 # Don't ignore failures.
28 set -e
29 (set -o pipefail 2> /dev/null) && set -o pipefail
31 # Avoid problems due to various shell wrinkles.
32 # We assume we have a shell new enough to implement unset correctly.
33 (set -o posix 2> /dev/null) && set -o posix
35 PS1='$ '
36 PS2='> '
37 PS4='+ '
38 unset BASH_ENV CDPATH ENV IFS MAIL MAILPATH POSIXLY_CORRECT
39 unset LANG LANGUAGE LC_ADDRESS LC_COLLATE LC_CTYPE LC_IDENTIFICATION
40 unset LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER
41 unset LC_TELEPHONE LC_TIME
43 LC_ALL=C
44 export LC_ALL
46 # Set program basename.
47 me=${0##*/}
48 usage="usage: $me [options]
50 Prepare to build a git checkout of autoconf.
51 Functionally equivalent to \`autoreconf -i\`, but uses autoconf code
52 from the git checkout itself to create \`configure\`.
54 Options:
55 -f, --force consider all files to be obsolete
56 -v, --verbose verbosely report processing (repeat for more detail)
59 # Options.
60 verbose=
61 subverbose=
62 force=
63 while [ $# -gt 0 ]; do
64 case "$1" in
65 (-v | --verbose)
66 if [ -n "$verbose" ]; then
67 subverbose=--verbose
68 else
69 verbose=--verbose
72 (-f | --force)
73 force=--force
75 (-h | --help)
76 printf '%s' "$usage"
77 exit 0
79 (*)
80 printf '%s' "$usage" >&2
81 exit 1
83 esac
84 shift
85 done
88 # Let the user choose which version of aclocal, automake, m4, and perl to use.
89 : ${ACLOCAL=aclocal}
90 : ${AUTOMAKE=automake}
91 : ${M4=m4}
92 : ${PERL=perl}
93 export ACLOCAL AUTOMAKE M4 PERL
95 # Allow 'ln -s' to be overridden by the user.
96 : ${LN_S="ln -s"}
97 export LN_S
99 # $PERL needs to be an absolute path because we're going to substitute it
100 # into #! lines.
101 set fnord $PERL
102 shift
103 PERL=$(command -v $1)
104 shift
105 if [ $# -gt 0 ]; then
106 PERL="$PERL $*"
109 # Override SHELL. This is required on DJGPP so that Perl's system()
110 # uses bash, not COMMAND.COM which doesn't quote arguments properly.
111 # It's not used otherwise.
112 if test -n "$DJDIR"; then
113 BOOTSTRAP_SHELL=/dev/env/DJDIR/bin/bash.exe
114 else
115 BOOTSTRAP_SHELL=/bin/sh
118 # Determine whether we have a usable version of M4.
119 # This rule is pickier than the rule in autoconf's actual configure script.
120 m4_version="$($M4 --version | head -1)"
121 case "$m4_version" in
122 ( *\ 0.* \
123 | *\ 1.[0123] \
124 | *\ 1.[0123].* \
125 | *\ 1.4.[0123456789] \
126 | *\ 1.4.1[012345] \
128 printf '%s\n' "$me: $M4 ($m4_version) is too old" >&2
129 exit 1
131 esac
133 # Substitutions related to the version of M4 available.
134 M4_DEBUGFILE=
135 M4_GNU=
136 m4_help=$($M4 --help)
137 case "$m4_help" in
138 (*--debugfile*)
139 M4_DEBUGFILE=--debugfile ;;
140 (*--error-output*)
141 M4_DEBUGFILE=--error-output ;;
142 esac
143 case "$m4_help" in
144 (*--gnu*)
145 M4_GNU=--gnu ;;
146 esac
148 # Autoconf's version number and identifiers.
149 RELEASE_YEAR=$(sed -ne 's/^RELEASE_YEAR=\([0-9][0-9]*\)$/\1/p' configure.ac)
150 VERSION=$(build-aux/git-version-gen .tarball-version)
152 # PACKAGE_NAME and PACKAGE_BUGREPORT from the bootstrap autoconf can
153 # get copied into the generated configure script, so we need to get them
154 # right. Caution: there is a hard tab in one of the regexes below.
155 PACKAGE_NAME=$(sed -n < configure.ac \
156 -e 's/^m4_define(\[autoconf_PACKAGE_NAME], \[\([^]]*\)])$/\1/p')
157 PACKAGE_BUGREPORT=$(sed -n < configure.ac \
158 -e 's/^m4_define(\[autoconf_PACKAGE_BUGREPORT], \[\([^]]*\)])$/\1/p')
160 if [ -z "$RELEASE_YEAR" ]; then
161 echo "$me: error: could not extract RELEASE_YEAR from configure.ac" >&2
162 exit 1
164 if [ -z "$VERSION" ]; then
165 echo "$me: error: could not compute VERSION" >&2
166 exit 1
168 if [ -z "$PACKAGE_NAME" ]; then
169 echo "$me: error: could not extract PACKAGE_NAME from configure.ac" >&2
170 exit 1
172 if [ -z "$PACKAGE_BUGREPORT" ]; then
173 echo "$me: error: could not extract PACKAGE_BUGREPORT from configure.ac" >&2
174 exit 1
177 # PACKAGE_TARNAME and PACKAGE_URL from the bootstrap autoconf should not
178 # get copied into the configure script.
179 PACKAGE_URL='<<not available>>'
180 PACKAGE_TARNAME='<<not available>>'
182 # Root for temporary partial installation tree.
183 ACBOOTDIR=$(mktemp -d acboot.XXXXXXXXXX)
184 ACBOOTDIR=$(realpath $ACBOOTDIR)
186 # dosubst options infile outfile -- performs the substitutions that
187 # config.status would perform on INFILE, creating OUTFILE. INFILE is
188 # relative to the source directory, OUTFILE is relative to $ACBOOTDIR.
189 # If OPTIONS is the letter 'x', OUTFILE is made executable after creation.
190 dosubst ()
192 in=${2##*/}
193 out="$ACBOOTDIR/$3"
194 if [ -n "$verbose" ]; then
195 printf '%s: creating %s\n' "$me" "$out"
197 rm -f "$out"
198 sed -e "s%@configure_input@%Generated from $in; do not edit by hand.%g" \
199 -e "s%@M4@%$M4%g" \
200 -e "s%@M4_DEBUGFILE@%$M4_DEBUGFILE%g" \
201 -e "s%@M4_GNU@%$M4_GNU%g" \
202 -e "s%@PACKAGE_BUGREPORT@%$PACKAGE_BUGREPORT%g" \
203 -e "s%@PACKAGE_NAME@%$PACKAGE_NAME%g" \
204 -e "s%@PACKAGE_STRING@%$PACKAGE_NAME $VERSION%g" \
205 -e "s%@PACKAGE_TARNAME@%$PACKAGE_TARNAME%g" \
206 -e "s%@PACKAGE_URL@%$PACKAGE_URL%g" \
207 -e "s%@PACKAGE_VERSION@%$VERSION%g" \
208 -e "s%@PERL@%$PERL%g" \
209 -e "s%@PERL_FLOCK@%0%g" \
210 -e "s%@RELEASE_YEAR@%$RELEASE_YEAR%g" \
211 -e "s%@SHELL@%$BOOTSTRAP_SHELL%g" \
212 -e "s%@VERSION@%$VERSION%g" \
213 -e "s%@pkgdatadir@%$ACBOOTDIR/lib%g" \
214 "$2" > "$out"
215 if [ "$1" = "x" ]; then
216 chmod +x "$out"
220 # Create the bootstrap installation.
221 mkdir "$ACBOOTDIR"/bin "$ACBOOTDIR"/lib "$ACBOOTDIR"/tmp
223 cd "$ACBOOTDIR"/lib
224 for sub in Autom4te autoconf m4sugar ; do
225 if [ -n "$verbose" ]; then
226 printf '%s: creating %s\n' "$me" "$ACBOOTDIR/lib/$sub"
228 $LN_S ../../lib/$sub .
229 done
232 # automake invokes autoconf, and autoconf and aclocal both invoke autom4te,
233 # so we need to create both of them.
234 dosubst x bin/autoconf.in bin/autoconf
235 dosubst x bin/autom4te.in bin/autom4te
236 dosubst . lib/autom4te.in lib/autom4te.cfg
237 dosubst . lib/version.in lib/version.m4
239 AUTOCONF="$ACBOOTDIR"/bin/autoconf
240 AUTOM4TE="$ACBOOTDIR/bin/autom4te -M -C $ACBOOTDIR/tmp/autom4te.cache"
241 export AUTOCONF AUTOM4TE
243 # We can now do what autoreconf would have done.
244 # Order is critical -- first aclocal, then autoconf, then automake.
245 run ()
247 if [ -n "$verbose" ]; then
248 printf '%s: running %s\n' "$me" "$*"
250 "$@"
253 run $ACLOCAL -I m4 -Wall -Werror $subverbose $force
254 run $AUTOCONF -Wall -Werror $subverbose $force
255 run $AUTOMAKE --add-missing --copy -Wall -Werror $subverbose $force
257 # Clean up.
258 rm -rf "$ACBOOTDIR"