Fix dependency issue for autoscan.list
[autoconf.git] / bootstrap
blobc148bcbfc4b38834340c870defdac516b257b243
1 #! /bin/sh
3 # This script helps bootstrap autoconf, when checked out from git.
5 # Copyright (C) 2021-2025 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 # Error on undefined variables.
32 (set -u 2> /dev/null) && set -u
34 # Avoid problems due to various shell wrinkles.
35 # We assume we have a shell new enough to implement unset correctly.
36 (set -o posix 2> /dev/null) && set -o posix
38 PS1='$ '
39 PS2='> '
40 PS4='+ '
41 unset BASH_ENV CDPATH ENV IFS MAIL MAILPATH POSIXLY_CORRECT
42 unset LANG LANGUAGE LC_ADDRESS LC_COLLATE LC_CTYPE LC_IDENTIFICATION
43 unset LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER
44 unset LC_TELEPHONE LC_TIME
46 LC_ALL=C
47 export LC_ALL
49 # Set program basename.
50 me=${0##*/}
51 usage="usage: $me [options]
53 Prepare to build a git checkout of autoconf.
54 Functionally equivalent to \`autoreconf -i\`, but uses autoconf code
55 from the git checkout itself to create \`configure\`.
57 Options:
58 -f, --force consider all files to be obsolete
59 -v, --verbose verbosely report processing (repeat for more detail)
62 # Options.
63 verbose=
64 subverbose=
65 force=
66 while [ $# -gt 0 ]; do
67 case "$1" in
68 (-v | --verbose)
69 if [ -n "$verbose" ]; then
70 subverbose=--verbose
71 else
72 verbose=--verbose
75 (-f | --force)
76 force=--force
78 (-h | --help)
79 printf '%s' "$usage"
80 exit 0
82 (*)
83 printf '%s' "$usage" >&2
84 exit 1
86 esac
87 shift
88 done
91 # Let the user choose which version of aclocal, automake, m4, and perl to use.
92 : ${ACLOCAL=aclocal}
93 : ${AUTOMAKE=automake}
94 : ${M4=m4}
95 : ${PERL=perl}
96 export ACLOCAL AUTOMAKE M4 PERL
98 # Allow 'ln -s' to be overridden by the user.
99 : ${LN_S="ln -s"}
100 export LN_S
102 # $PERL needs to be an absolute path because we're going to substitute it
103 # into #! lines.
104 set fnord $PERL
105 shift
106 PERL=$(command -v $1)
107 shift
108 if [ $# -gt 0 ]; then
109 PERL="$PERL $*"
112 # Override SHELL. This is required on DJGPP so that Perl's system()
113 # uses bash, not COMMAND.COM which doesn't quote arguments properly.
114 # It's not used otherwise.
115 if test -n "${DJDIR-}"; then
116 BOOTSTRAP_SHELL=/dev/env/DJDIR/bin/bash.exe
117 else
118 BOOTSTRAP_SHELL=/bin/sh
121 # Determine whether we have a usable version of M4.
122 # This rule is pickier than the rule in autoconf's actual configure script.
123 m4_version="$($M4 --version | head -1)"
124 case "$m4_version" in
125 ( *\ 0.* \
126 | *\ 1.[0123] \
127 | *\ 1.[0123].* \
128 | *\ 1.4.[0123456789] \
129 | *\ 1.4.1[012345] \
131 printf '%s\n' "$me: $M4 ($m4_version) is too old" >&2
132 exit 1
134 esac
136 # Substitutions related to the version of M4 available.
137 M4_DEBUGFILE=
138 M4_GNU=
139 m4_help=$($M4 --help)
140 case "$m4_help" in
141 (*--debugfile*)
142 M4_DEBUGFILE=--debugfile ;;
143 (*--error-output*)
144 M4_DEBUGFILE=--error-output ;;
145 esac
146 case "$m4_help" in
147 (*--gnu*)
148 M4_GNU=--gnu ;;
149 esac
151 # Autoconf's version number and identifiers.
152 RELEASE_YEAR=$(sed -ne 's/^RELEASE_YEAR=\([0-9][0-9]*\)$/\1/p' configure.ac)
153 VERSION=$(build-aux/git-version-gen .tarball-version)
155 # PACKAGE_NAME and PACKAGE_BUGREPORT from the bootstrap autoconf can
156 # get copied into the generated configure script, so we need to get them
157 # right. Caution: there is a hard tab in one of the regexes below.
158 PACKAGE_NAME=$(sed -n < configure.ac \
159 -e 's/^m4_define(\[autoconf_PACKAGE_NAME], \[\([^]]*\)])$/\1/p')
160 PACKAGE_BUGREPORT=$(sed -n < configure.ac \
161 -e 's/^m4_define(\[autoconf_PACKAGE_BUGREPORT], \[\([^]]*\)])$/\1/p')
163 if [ -z "$RELEASE_YEAR" ]; then
164 printf >&2 '%s\n' \
165 "$me: error: could not extract RELEASE_YEAR from configure.ac"
166 exit 1
168 if [ -z "$VERSION" ]; then
169 printf >&2 '%s\n' "$me: error: could not compute VERSION"
170 exit 1
172 if [ -z "$PACKAGE_NAME" ]; then
173 printf >&2 '%s\n' \
174 "$me: error: could not extract PACKAGE_NAME from configure.ac"
175 exit 1
177 if [ -z "$PACKAGE_BUGREPORT" ]; then
178 printf >&2 '%s\n' \
179 "$me: error: could not extract PACKAGE_BUGREPORT from configure.ac"
180 exit 1
183 # PACKAGE_TARNAME and PACKAGE_URL from the bootstrap autoconf should not
184 # get copied into the configure script.
185 PACKAGE_URL='<<not available>>'
186 PACKAGE_TARNAME='<<not available>>'
188 # Root for temporary partial installation tree.
189 ACBOOTDIR=$(mktemp -d acboot.XXXXXXXXXX)
190 ACBOOTDIR=$(realpath $ACBOOTDIR)
192 # dosubst options infile outfile -- performs the substitutions that
193 # config.status would perform on INFILE, creating OUTFILE. INFILE is
194 # relative to the source directory, OUTFILE is relative to $ACBOOTDIR.
195 # If OPTIONS is the letter 'x', OUTFILE is made executable after creation.
196 dosubst ()
198 in=${2##*/}
199 out="$ACBOOTDIR/$3"
200 if [ -n "$verbose" ]; then
201 printf '%s: creating %s\n' "$me" "$out"
203 rm -f "$out"
204 sed -e "s%@configure_input@%Generated from $in; do not edit by hand.%g" \
205 -e "s%@M4@%$M4%g" \
206 -e "s%@M4_DEBUGFILE@%$M4_DEBUGFILE%g" \
207 -e "s%@M4_GNU@%$M4_GNU%g" \
208 -e "s%@PACKAGE_BUGREPORT@%$PACKAGE_BUGREPORT%g" \
209 -e "s%@PACKAGE_NAME@%$PACKAGE_NAME%g" \
210 -e "s%@PACKAGE_STRING@%$PACKAGE_NAME $VERSION%g" \
211 -e "s%@PACKAGE_TARNAME@%$PACKAGE_TARNAME%g" \
212 -e "s%@PACKAGE_URL@%$PACKAGE_URL%g" \
213 -e "s%@PACKAGE_VERSION@%$VERSION%g" \
214 -e "s%@PERL@%$PERL%g" \
215 -e "s%@PERL_FLOCK@%0%g" \
216 -e "s%@RELEASE_YEAR@%$RELEASE_YEAR%g" \
217 -e "s%@SHELL@%$BOOTSTRAP_SHELL%g" \
218 -e "s%@VERSION@%$VERSION%g" \
219 -e "s%@pkgdatadir@%$ACBOOTDIR/lib%g" \
220 "$2" > "$out"
221 if [ "$1" = "x" ]; then
222 chmod +x "$out"
226 # Create the bootstrap installation.
227 mkdir "$ACBOOTDIR"/bin "$ACBOOTDIR"/lib "$ACBOOTDIR"/tmp
229 cd "$ACBOOTDIR"/lib
230 for sub in Autom4te autoconf m4sugar ; do
231 if [ -n "$verbose" ]; then
232 printf '%s: creating %s\n' "$me" "$ACBOOTDIR/lib/$sub"
234 $LN_S ../../lib/$sub .
235 done
238 # automake invokes autoconf, and autoconf and aclocal both invoke autom4te,
239 # so we need to create both of them.
240 dosubst x bin/autoconf.in bin/autoconf
241 dosubst x bin/autom4te.in bin/autom4te
242 dosubst . lib/autom4te.in lib/autom4te.cfg
243 dosubst . lib/version.in lib/version.m4
245 AUTOCONF="$ACBOOTDIR"/bin/autoconf
246 AUTOM4TE="$ACBOOTDIR/bin/autom4te -M -C $ACBOOTDIR/tmp/autom4te.cache"
247 export AUTOCONF AUTOM4TE
249 # We can now do what autoreconf would have done.
250 # Order is critical -- first aclocal, then autoconf, then automake.
251 run ()
253 if [ -n "$verbose" ]; then
254 printf '%s: running %s\n' "$me" "$*"
256 "$@"
259 run $ACLOCAL -I m4 -Wall -Werror $subverbose $force
260 run $AUTOCONF -Wall -Werror $subverbose $force
261 run $AUTOMAKE --add-missing --copy -Wall -Werror $subverbose $force
263 # Clean up.
264 rm -rf "$ACBOOTDIR"