gnulib-tool.py: Reduce code duplication in file name transformations.
[gnulib.git] / top / bootstrap
blob4beae0e912625fa618d1fb4a785c3719d5e058be
1 #! /bin/sh
2 # Bootstrap this package from checked-out sources.
4 scriptversion=2024-04-13.15; # UTC
6 # Copyright (C) 2003-2024 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 # Originally written by Paul Eggert. The canonical version of this
22 # script is maintained as top/bootstrap in gnulib. However, to be
23 # useful to your package, you should place a copy of it under version
24 # control in the top-level directory of your package. The intent is
25 # that all customization can be done with a bootstrap.conf file also
26 # maintained in your version control; gnulib comes with a template
27 # build-aux/bootstrap.conf to get you started.
29 # Please report bugs or propose patches to bug-gnulib@gnu.org.
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 you want to use these sources.
47 GNULIB_REFDIR Specifies the local directory where a gnulib
48 repository (with a .git subdirectory) resides.
49 Use this if you already have gnulib sources
50 and history on your machine, and do not want
51 to waste your bandwidth downloading them again.
52 Only used for phase 1 (--pull).
53 GNULIB_URL URL of the gnulib repository. The default is
54 $default_gnulib_url,
55 which is Gnulib's upstream repository.
56 Only used for phase 1 (--pull).
58 Options:
60 --pull Do phase 1: Pull files from the network.
61 --gen Do phase 2: Generate files from local files
62 (no network access).
63 (The default is to do both phases.)
65 --gnulib-srcdir=DIRNAME Specifies the local directory where gnulib
66 sources reside. Use this if you already
67 have gnulib sources on your machine, and
68 you want to use these sources. Defaults
69 to \$GNULIB_SRCDIR.
70 --gnulib-refdir=DIRNAME Specifies the local directory where a gnulib
71 repository (with a .git subdirectory) resides.
72 Use this if you already have gnulib sources
73 and history on your machine, and do not want
74 to waste your bandwidth downloading them again.
75 Defaults to \$GNULIB_REFDIR.
76 Only used for phase 1 (--pull).
78 --bootstrap-sync If this bootstrap script is not identical to
79 the version in the local gnulib sources,
80 update this script, and then restart it with
81 /bin/sh or the shell \$CONFIG_SHELL.
82 --no-bootstrap-sync Do not check whether bootstrap is out of sync.
84 --copy Copy files instead of creating symbolic links.
85 Only used for phase 2 (--gen).
86 --force Attempt to bootstrap even if the sources seem
87 not to have been checked out.
88 --no-git Do not use git to update gnulib. Requires that
89 \$GNULIB_SRCDIR or the --gnulib-srcdir option
90 points to a gnulib repository with the correct
91 revision.
92 Only used for phase 1 (--pull).
93 --skip-po Do not download *.po files.
94 Only used for phase 1 (--pull).
95 EOF
96 bootstrap_print_option_usage_hook
97 cat <<EOF
98 If the file bootstrap.conf exists in the same directory as this script, its
99 contents are read as shell variables to configure the bootstrap.
101 For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
102 are honored.
104 Gnulib sources can be fetched in various ways:
106 * If GNULIB_SRCDIR is set (either as an environment variable or via the
107 --gnulib-srcdir option), then sources are fetched from that local
108 directory. If it is a git repository and the configuration variable
109 GNULIB_REVISION is set in bootstrap.conf, then that revision is
110 checked out.
112 * Otherwise, if this package is in a git repository with a 'gnulib'
113 submodule configured, then that submodule is initialized and updated
114 and sources are fetched from there. If GNULIB_REFDIR is set (either
115 as an environment variable or via the --gnulib-refdir option) and is
116 a git repository, then it is used as a reference.
118 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
119 are cloned into that directory using git from \$GNULIB_URL, defaulting
120 to $default_gnulib_url.
121 If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
122 then that revision is checked out.
124 * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
125 used. If it is a git repository and the configuration variable
126 GNULIB_REVISION is set in bootstrap.conf, then that revision is
127 checked out.
129 If you maintain a package and want to pin a particular revision of the
130 Gnulib sources that has been tested with your package, then there are
131 two possible approaches: either configure a 'gnulib' submodule with the
132 appropriate revision, or set GNULIB_REVISION (and if necessary
133 GNULIB_URL) in bootstrap.conf.
135 Running without arguments will suffice in most cases.
139 # Parse options.
141 # Whether to pull and generate.
142 pull=false
143 gen=false
145 # Whether to use copies instead of symlinks.
146 copy=false
148 # Use git to update gnulib sources
149 use_git=true
151 for option
153 case $option in
154 --help)
155 usage
156 exit;;
157 --version)
158 set -e
159 echo "bootstrap $scriptversion lib $scriptlibversion"
160 echo "$copyright"
161 exit 0
163 --pull)
164 pull=true;;
165 --gen)
166 gen=true;;
167 --gnulib-srcdir=*)
168 GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
169 --gnulib-refdir=*)
170 GNULIB_REFDIR=${option#--gnulib-refdir=};;
171 --skip-po)
172 SKIP_PO=t;;
173 --force)
174 checkout_only_file=;;
175 --copy)
176 copy=true;;
177 --bootstrap-sync)
178 bootstrap_sync=true;;
179 --no-bootstrap-sync)
180 bootstrap_sync=false;;
181 --no-git)
182 use_git=false;;
184 bootstrap_option_hook $option || die "$option: unknown option";;
185 esac
186 done
188 # Default is to do both.
189 $pull || $gen || pull=true gen=true
191 $use_git || test -n "$GNULIB_SRCDIR" \
192 || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable" \
193 "or --gnulib-srcdir option"
194 test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
195 || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir" \
196 "option is specified, but does not denote a directory"
198 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
199 die "Bootstrapping from a non-checked-out distribution is risky."
202 check_build_prerequisites $use_git
204 if $bootstrap_sync; then
205 prepare_GNULIB_SRCDIR
206 upgrade_bootstrap "$@"
207 # Since we have now upgraded if needed, no need to try it a second time below.
208 bootstrap_sync=false
211 echo "$0: Bootstrapping from checked-out $package sources..."
213 # Pass GNULIB_SRCDIR and GNULIB_REFDIR to any subsidiary commands that care.
214 export GNULIB_SRCDIR
215 export GNULIB_REFDIR
217 if $pull && { $use_git || test -z "$SKIP_PO"; }; then
218 autopull \
219 `if $bootstrap_sync; then
220 echo ' --bootstrap-sync'
221 else
222 echo ' --no-bootstrap-sync'
223 fi` \
224 `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
225 `if ! $use_git; then echo ' --no-git'; fi` \
226 `if test -n "$SKIP_PO"; then echo ' --skip-po'; fi` \
227 || die "could not fetch auxiliary files"
230 if $gen; then
231 autogen \
232 `if $copy; then echo ' --copy'; fi` \
233 `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
234 || die "could not generate auxiliary files"
237 # ----------------------------------------------------------------------------
239 # Local Variables:
240 # eval: (add-hook 'before-save-hook 'time-stamp)
241 # time-stamp-start: "scriptversion="
242 # time-stamp-format: "%:y-%02m-%02d.%02H"
243 # time-stamp-time-zone: "UTC0"
244 # time-stamp-end: "; # UTC"
245 # End: