maint: remove unnecessary casts before using gnulib functions
[bison.git] / bootstrap
blobcf8d007f64bdf9cdc08647fb9d98090be54ac2ff
1 #! /bin/sh
2 # Bootstrap this package from checked-out sources.
4 # Copyright (C) 2003-2022 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # Originally written by Paul Eggert. The canonical version of this
20 # script is maintained as top/bootstrap in gnulib. However, to be
21 # useful to your package, you should place a copy of it under version
22 # control in the top-level directory of your package. The intent is
23 # that all customization can be done with a bootstrap.conf file also
24 # maintained in your version control; gnulib comes with a template
25 # build-aux/bootstrap.conf to get you started.
27 # Please report bugs or propose patches to bug-gnulib@gnu.org.
29 scriptversion=2022-07-29.23; # UTC
31 me="$0"
32 medir=`dirname "$me"`
34 # Read the function library and the configuration.
35 . "$medir"/bootstrap-funclib.sh
37 usage() {
38 cat <<EOF
39 Usage: $me [OPTION]...
40 Bootstrap this package from the checked-out sources.
42 Optional environment variables:
43 GNULIB_SRCDIR Specifies the local directory where gnulib
44 sources reside. Use this if you already
45 have gnulib sources on your machine, and
46 do not want to waste your bandwidth downloading
47 them again.
48 GNULIB_URL Cloneable URL of the gnulib repository.
50 Options:
51 --gnulib-srcdir=DIRNAME specify the local directory where gnulib
52 sources reside. Use this if you already
53 have gnulib sources on your machine, and
54 you want to use these sources. Defaults
55 to \$GNULIB_SRCDIR
56 --gnulib-refdir=DIRNAME specify the local directory where a gnulib
57 repository (with a .git subdirectory) resides.
58 Use this if you already have gnulib sources
59 and history on your machine, and do not want
60 to waste your bandwidth downloading them again.
61 Defaults to \$GNULIB_REFDIR
62 --bootstrap-sync if this bootstrap script is not identical to
63 the version in the local gnulib sources,
64 update this script, and then restart it with
65 /bin/sh or the shell \$CONFIG_SHELL
66 --no-bootstrap-sync do not check whether bootstrap is out of sync
67 --copy copy files instead of creating symbolic links
68 --force attempt to bootstrap even if the sources seem
69 not to have been checked out
70 --no-git do not use git to update gnulib. Requires that
71 \$GNULIB_SRCDIR or the --gnulib-srcdir option
72 points to a gnulib repository with the correct
73 revision
74 --skip-po do not download po files
75 EOF
76 bootstrap_print_option_usage_hook
77 cat <<EOF
78 If the file bootstrap.conf exists in the same directory as this script, its
79 contents are read as shell variables to configure the bootstrap.
81 For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
82 are honored.
84 Gnulib sources can be fetched in various ways:
86 * If the environment variable GNULIB_SRCDIR is set (either as an
87 environment variable or via the --gnulib-srcdir option), then sources
88 are fetched from that local directory. If it is a git repository and
89 the configuration variable GNULIB_REVISION is set in bootstrap.conf,
90 then that revision is checked out.
92 * Otherwise, if this package is in a git repository with a 'gnulib'
93 submodule configured, then that submodule is initialized and updated
94 and sources are fetched from there. If GNULIB_REFDIR is set (either
95 as an environment variable or via the --gnulib-refdir option) and is
96 a git repository, then it is used as a reference.
98 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
99 are cloned into that directory using git from \$GNULIB_URL, defaulting
100 to $default_gnulib_url.
101 If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
102 then that revision is checked out.
104 * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
105 used. If it is a git repository and the configuration variable
106 GNULIB_REVISION is set in bootstrap.conf, then that revision is
107 checked out.
109 If you maintain a package and want to pin a particular revision of the
110 Gnulib sources that has been tested with your package, then there are
111 two possible approaches: either configure a 'gnulib' submodule with the
112 appropriate revision, or set GNULIB_REVISION (and if necessary
113 GNULIB_URL) in bootstrap.conf.
115 Running without arguments will suffice in most cases.
119 # Parse options.
121 # Whether to use copies instead of symlinks.
122 copy=false
124 # Use git to update gnulib sources
125 use_git=true
127 for option
129 case $option in
130 --help)
131 usage
132 exit;;
133 --version)
134 set -e
135 echo "bootstrap $scriptversion"
136 echo "$copyright"
137 exit 0
139 --gnulib-srcdir=*)
140 GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
141 --gnulib-refdir=*)
142 GNULIB_REFDIR=${option#--gnulib-refdir=};;
143 --skip-po)
144 SKIP_PO=t;;
145 --force)
146 checkout_only_file=;;
147 --copy)
148 copy=true;;
149 --bootstrap-sync)
150 bootstrap_sync=true;;
151 --no-bootstrap-sync)
152 bootstrap_sync=false;;
153 --no-git)
154 use_git=false;;
156 bootstrap_option_hook $option || die "$option: unknown option";;
157 esac
158 done
160 $use_git || test -n "$GNULIB_SRCDIR" \
161 || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option"
162 test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
163 || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
165 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
166 die "Bootstrapping from a non-checked-out distribution is risky."
169 check_build_prerequisites $use_git
171 if ! test -f "$medir"/bootstrap-funclib.sh; then
172 # We have only completed the first phase of an upgrade from a bootstrap
173 # version < 2022-07-24. Need to do the second phase now.
174 bootstrap_sync=true
177 if $bootstrap_sync; then
178 prepare_GNULIB_SRCDIR
179 upgrade_bootstrap
180 # Since we have now upgraded if needed, no need to try it a second time below.
181 bootstrap_sync=false
184 echo "$0: Bootstrapping from checked-out $package sources..."
186 # Pass GNULIB_SRCDIR to autopull.sh and autogen.sh.
187 export GNULIB_SRCDIR
189 # Pass GNULIB_REFDIR to autopull.sh.
190 export GNULIB_REFDIR
192 if $use_git || test -z "$SKIP_PO"; then
193 "$medir"/autopull.sh \
194 `if $bootstrap_sync; then echo ' --bootstrap-sync'; else echo ' --no-bootstrap-sync'; fi` \
195 `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
196 `if ! $use_git; then echo ' --no-git'; fi` \
197 `if test -n "$SKIP_PO"; then echo ' --skip-po'; fi` \
198 || die "autopull.sh failed."
201 "$medir"/autogen.sh \
202 `if $copy; then echo ' --copy'; fi` \
203 `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
204 || die "autogen.sh failed."
206 # ----------------------------------------------------------------------------
208 # Local Variables:
209 # eval: (add-hook 'before-save-hook 'time-stamp)
210 # time-stamp-start: "scriptversion="
211 # time-stamp-format: "%:y-%02m-%02d.%02H"
212 # time-stamp-time-zone: "UTC0"
213 # time-stamp-end: "; # UTC"
214 # End: