maint: remove unnecessary casts before using gnulib functions
[bison.git] / autopull.sh
blobffb4ba7cbac7733d56ab7be7a27e9df01f9a9dc8
1 #!/bin/sh
2 # Convenience script for fetching auxiliary files that are omitted from
3 # the version control repository of this package.
5 # Copyright (C) 2003-2022 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 3 of the License, or
10 # (at your option) 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 # Originally written by Paul Eggert. The canonical version of this
21 # script is maintained as top/autopull.sh in gnulib. However, to be
22 # useful to your package, you should place a copy of it under version
23 # control in the top-level directory of your package. The intent is
24 # that all customization can be done with a bootstrap.conf file also
25 # maintained in your version control; gnulib comes with a template
26 # build-aux/bootstrap.conf to get you started.
28 # Alternatively, you can use an autopull.sh script that is specific
29 # to your package.
31 scriptversion=2022-07-24.15; # UTC
33 me="$0"
34 medir=`dirname "$me"`
36 # Read the function library and the configuration.
37 . "$medir"/bootstrap-funclib.sh
39 # Ensure that CDPATH is not set. Otherwise, the output from cd
40 # would cause trouble in at least one use below.
41 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
43 usage() {
44 cat <<EOF
45 Usage: $me [OPTION]...
46 Bootstrap this package from the checked-out sources.
48 Optional environment variables:
49 GNULIB_SRCDIR Specifies the local directory where gnulib
50 sources reside. Use this if you already
51 have gnulib sources on your machine, and
52 you want to use these sources.
53 GNULIB_REFDIR Specifies the local directory where a gnulib
54 repository (with a .git subdirectory) resides.
55 Use this if you already have gnulib sources
56 and history on your machine, and do not want
57 to waste your bandwidth downloading them again.
58 GNULIB_URL Cloneable URL of the gnulib repository.
60 Options:
61 --bootstrap-sync if this bootstrap script is not identical to
62 the version in the local gnulib sources,
63 update this script, and then restart it with
64 /bin/sh or the shell \$CONFIG_SHELL
65 --no-bootstrap-sync do not check whether bootstrap is out of sync
66 --force attempt to bootstrap even if the sources seem
67 not to have been checked out
68 --no-git do not use git to update gnulib. Requires that
69 \$GNULIB_SRCDIR or the --gnulib-srcdir option
70 points to a gnulib repository with the correct
71 revision
72 --skip-po do not download po files
73 EOF
74 bootstrap_print_option_usage_hook
75 cat <<EOF
76 If the file bootstrap.conf exists in the same directory as this script, its
77 contents are read as shell variables to configure the bootstrap.
79 For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
80 are honored.
82 Gnulib sources can be fetched in various ways:
84 * If the environment variable GNULIB_SRCDIR is set (either as an
85 environment variable or via the --gnulib-srcdir option), then sources
86 are fetched from that local directory. If it is a git repository and
87 the configuration variable GNULIB_REVISION is set in bootstrap.conf,
88 then that revision is checked out.
90 * Otherwise, if this package is in a git repository with a 'gnulib'
91 submodule configured, then that submodule is initialized and updated
92 and sources are fetched from there. If GNULIB_REFDIR is set (either
93 as an environment variable or via the --gnulib-refdir option) and is
94 a git repository, then it is used as a reference.
96 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
97 are cloned into that directory using git from \$GNULIB_URL, defaulting
98 to $default_gnulib_url.
99 If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
100 then that revision is checked out.
102 * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
103 used. If it is a git repository and the configuration variable
104 GNULIB_REVISION is set in bootstrap.conf, then that revision is
105 checked out.
107 If you maintain a package and want to pin a particular revision of the
108 Gnulib sources that has been tested with your package, then there are
109 two possible approaches: either configure a 'gnulib' submodule with the
110 appropriate revision, or set GNULIB_REVISION (and if necessary
111 GNULIB_URL) in bootstrap.conf.
113 Running without arguments will suffice in most cases.
117 # Parse options.
119 # Use git to update gnulib sources
120 use_git=true
122 for option
124 case $option in
125 --help)
126 usage
127 exit;;
128 --version)
129 set -e
130 echo "autopull.sh $scriptversion"
131 echo "$copyright"
132 exit 0
134 --skip-po)
135 SKIP_PO=t;;
136 --force)
137 checkout_only_file=;;
138 --bootstrap-sync)
139 bootstrap_sync=true;;
140 --no-bootstrap-sync)
141 bootstrap_sync=false;;
142 --no-git)
143 use_git=false;;
145 bootstrap_option_hook $option || die "$option: unknown option";;
146 esac
147 done
149 $use_git || test -n "$GNULIB_SRCDIR" \
150 || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option"
151 test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
152 || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
154 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
155 die "Running this script from a non-checked-out distribution is risky."
158 check_build_prerequisites $use_git
160 if $use_gnulib || $bootstrap_sync; then
161 prepare_GNULIB_SRCDIR
162 if $bootstrap_sync; then
163 upgrade_bootstrap
167 # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
168 # Also find the compatible sha1 utility on the BSDs
169 if test x"$SKIP_PO" = x; then
170 find_tool SHA1SUM sha1sum gsha1sum shasum sha1
173 # See if we can use gnulib's git-merge-changelog merge driver.
174 if $use_git && test -d .git && check_exists git; then
175 if git config merge.merge-changelog.driver >/dev/null ; then
177 elif check_exists git-merge-changelog; then
178 echo "$0: initializing git-merge-changelog driver"
179 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
180 git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
181 else
182 echo "$0: consider installing git-merge-changelog from gnulib"
186 # ----------------------------- Get translations. -----------------------------
188 download_po_files() {
189 subdir=$1
190 domain=$2
191 echo "$me: getting translations into $subdir for $domain..."
192 cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
193 eval "$cmd"
196 # Mirror .po files to $po_dir/.reference and copy only the new
197 # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
198 # Note po files that exist locally only are left in $po_dir but will
199 # not be included in LINGUAS and hence will not be distributed.
200 update_po_files() {
201 # Directory containing primary .po files.
202 # Overwrite them only when we're sure a .po file is new.
203 po_dir=$1
204 domain=$2
206 # Mirror *.po files into this dir.
207 # Usually contains *.s1 checksum files.
208 ref_po_dir="$po_dir/.reference"
210 test -d $ref_po_dir || mkdir $ref_po_dir || return
211 download_po_files $ref_po_dir $domain \
212 && ls "$ref_po_dir"/*.po 2>/dev/null |
213 sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
215 langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
216 test "$langs" = '*' && langs=x
217 for po in $langs; do
218 case $po in x) continue;; esac
219 new_po="$ref_po_dir/$po.po"
220 cksum_file="$ref_po_dir/$po.s1"
221 if ! test -f "$cksum_file" ||
222 ! test -f "$po_dir/$po.po" ||
223 ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
224 echo "$me: updated $po_dir/$po.po..."
225 cp "$new_po" "$po_dir/$po.po" \
226 && $SHA1SUM < "$new_po" > "$cksum_file" || return
228 done
231 case $SKIP_PO in
233 if test -d po; then
234 update_po_files po $package || exit
237 if test -d runtime-po; then
238 update_po_files runtime-po $package-runtime || exit
239 fi;;
240 esac
242 # -----------------------------------------------------------------------------
244 bootstrap_post_pull_hook \
245 || die "bootstrap_post_pull_hook failed"
247 # Don't proceed if there are uninitialized submodules. In particular,
248 # autogen.sh will remove dangling links, which might be links into
249 # uninitialized submodules.
250 # But it's OK if the 'gnulib' submodule is uninitialized, as long as
251 # GNULIB_SRCDIR is set.
252 if $use_git; then
253 # Uninitialized submodules are listed with an initial dash.
254 uninitialized=`git submodule | grep '^-' | awk '{ print $2 }'`
255 if test -n "$GNULIB_SRCDIR"; then
256 uninitialized=`echo "$uninitialized" | grep -v '^gnulib$'`
258 if test -n "$uninitialized"; then
259 die "Some git submodules are not initialized: "`echo "$uninitialized" | tr '\n' ',' | sed -e 's|,$|.|'`" Either use option '--no-git', or run 'git submodule update --init' and bootstrap again."
263 echo "$0: done. Now you can run './autogen.sh'."
265 # ----------------------------------------------------------------------------
267 # Local Variables:
268 # eval: (add-hook 'before-save-hook 'time-stamp)
269 # time-stamp-start: "scriptversion="
270 # time-stamp-format: "%:y-%02m-%02d.%02H"
271 # time-stamp-time-zone: "UTC0"
272 # time-stamp-end: "; # UTC"
273 # End: