make fetch
[autoconf.git] / bootstrap
blob50861367792507b5d703de4f7f140ca9b6058d96
1 #! /bin/sh
3 # This script helps bootstrap autoconf, when checked out from git.
5 # Copyright (C) 2021-2023 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 # $PERL needs to be an absolute path because we're going to substitute it
96 # into #! lines.
97 set fnord $PERL
98 shift
99 PERL=$(command -v $1)
100 shift
101 if [ $# -gt 0 ]; then
102 PERL="$PERL $*"
105 # Override SHELL. This is required on DJGPP so that Perl's system()
106 # uses bash, not COMMAND.COM which doesn't quote arguments properly.
107 # It's not used otherwise.
108 if test -n "$DJDIR"; then
109 BOOTSTRAP_SHELL=/dev/env/DJDIR/bin/bash.exe
110 else
111 BOOTSTRAP_SHELL=/bin/sh
114 # Determine whether we have a usable version of M4.
115 # This rule is pickier than the rule in autoconf's actual configure script.
116 m4_version="$($M4 --version | head -1)"
117 case "$m4_version" in
118 ( *\ 0.* \
119 | *\ 1.[0123] \
120 | *\ 1.[0123].* \
121 | *\ 1.4.[0123456789] \
122 | *\ 1.4.1[012345] \
124 printf '%s\n' "$me: $M4 ($m4_version) is too old" >&2
125 exit 1
127 esac
129 # Substitutions related to the version of M4 available.
130 M4_DEBUGFILE=
131 M4_GNU=
132 m4_help=$($M4 --help)
133 case "$m4_help" in
134 (*--debugfile*)
135 M4_DEBUGFILE=--debugfile ;;
136 (*--error-output*)
137 M4_DEBUGFILE=--error-output ;;
138 esac
139 case "$m4_help" in
140 (*--gnu*)
141 M4_GNU=--gnu ;;
142 esac
144 # Autoconf's version number and identifiers.
145 RELEASE_YEAR=$(sed -ne 's/^RELEASE_YEAR=\([0-9][0-9]*\)$/\1/p' configure.ac)
146 VERSION=$(build-aux/git-version-gen .tarball-version)
148 # PACKAGE_NAME and PACKAGE_BUGREPORT from the bootstrap autoconf can
149 # get copied into the generated configure script, so we need to get them
150 # right. Caution: there is a hard tab in one of the regexes below.
151 PACKAGE_NAME=$(sed -n < configure.ac \
152 -e 's/^m4_define(\[autoconf_PACKAGE_NAME], \[\([^]]*\)])$/\1/p')
153 PACKAGE_BUGREPORT=$(sed -n < configure.ac \
154 -e 's/^m4_define(\[autoconf_PACKAGE_BUGREPORT], \[\([^]]*\)])$/\1/p')
156 if [ -z "$RELEASE_YEAR" ]; then
157 echo "$me: error: could not extract RELEASE_YEAR from configure.ac" >&2
158 exit 1
160 if [ -z "$VERSION" ]; then
161 echo "$me: error: could not compute VERSION" >&2
162 exit 1
164 if [ -z "$PACKAGE_NAME" ]; then
165 echo "$me: error: could not extract PACKAGE_NAME from configure.ac" >&2
166 exit 1
168 if [ -z "$PACKAGE_BUGREPORT" ]; then
169 echo "$me: error: could not extract PACKAGE_BUGREPORT from configure.ac" >&2
170 exit 1
173 # PACKAGE_TARNAME and PACKAGE_URL from the bootstrap autoconf should not
174 # get copied into the configure script.
175 PACKAGE_URL='<<not available>>'
176 PACKAGE_TARNAME='<<not available>>'
178 # Root for temporary partial installation tree.
179 ACBOOTDIR=$(mktemp -d acboot.XXXXXXXXXX)
181 # dosubst options infile outfile -- performs the substitutions that
182 # config.status would perform on INFILE, creating OUTFILE. INFILE is
183 # relative to the source directory, OUTFILE is relative to $ACBOOTDIR.
184 # If OPTIONS is the letter 'x', OUTFILE is made executable after creation.
185 dosubst ()
187 in=${2##*/}
188 out="$ACBOOTDIR/$3"
189 if [ -n "$verbose" ]; then
190 printf '%s: creating %s\n' "$me" "$out"
192 rm -f "$out"
193 sed -e "s%@configure_input@%Generated from $in; do not edit by hand.%g" \
194 -e "s%@M4@%$M4%g" \
195 -e "s%@M4_DEBUGFILE@%$M4_DEBUGFILE%g" \
196 -e "s%@M4_GNU@%$M4_GNU%g" \
197 -e "s%@PACKAGE_BUGREPORT@%$PACKAGE_BUGREPORT%g" \
198 -e "s%@PACKAGE_NAME@%$PACKAGE_NAME%g" \
199 -e "s%@PACKAGE_STRING@%$PACKAGE_NAME $VERSION%g" \
200 -e "s%@PACKAGE_TARNAME@%$PACKAGE_TARNAME%g" \
201 -e "s%@PACKAGE_URL@%$PACKAGE_URL%g" \
202 -e "s%@PACKAGE_VERSION@%$VERSION%g" \
203 -e "s%@PERL@%$PERL%g" \
204 -e "s%@PERL_FLOCK@%0%g" \
205 -e "s%@RELEASE_YEAR@%$RELEASE_YEAR%g" \
206 -e "s%@SHELL@%$BOOTSTRAP_SHELL%g" \
207 -e "s%@VERSION@%$VERSION%g" \
208 -e "s%@pkgdatadir@%$ACBOOTDIR/lib%g" \
209 "$2" > "$out"
210 if [ "$1" = "x" ]; then
211 chmod +x "$out"
215 # Create the bootstrap installation.
216 mkdir "$ACBOOTDIR"/bin "$ACBOOTDIR"/lib "$ACBOOTDIR"/tmp
218 cd "$ACBOOTDIR"/lib
219 for sub in Autom4te autoconf m4sugar ; do
220 if [ -n "$verbose" ]; then
221 printf '%s: creating %s\n' "$me" "$ACBOOTDIR/lib/$sub"
223 ln -s ../../lib/$sub .
224 done
227 # automake invokes autoconf, and autoconf and aclocal both invoke autom4te,
228 # so we need to create both of them.
229 dosubst x bin/autoconf.in bin/autoconf
230 dosubst x bin/autom4te.in bin/autom4te
231 dosubst . lib/autom4te.in lib/autom4te.cfg
232 dosubst . lib/version.in lib/version.m4
234 AUTOCONF="$ACBOOTDIR"/bin/autoconf
235 AUTOM4TE="$ACBOOTDIR/bin/autom4te -M -C $ACBOOTDIR/tmp/autom4te.cache"
236 export AUTOCONF AUTOM4TE
238 # We can now do what autoreconf would have done.
239 # Order is critical -- first aclocal, then autoconf, then automake.
240 run ()
242 if [ -n "$verbose" ]; then
243 printf '%s: running %s\n' "$me" "$*"
245 "$@"
248 run $ACLOCAL -I m4 -Wall -Werror $subverbose $force
249 run $AUTOCONF -Wall -Werror $subverbose $force
250 run $AUTOMAKE --add-missing --copy -Wall -Werror $subverbose $force
252 # Clean up.
253 rm -rf "$ACBOOTDIR"