glr.c: reorder routines
[bison.git] / bootstrap
blob5f1b1b70c08cb94d688a3eff934c7ba96462c64c
1 #! /bin/sh
2 # Print a version string.
3 scriptversion=2020-11-18.17; # UTC
5 # Bootstrap this package from checked-out sources.
7 # Copyright (C) 2003-2020 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 # Originally written by Paul Eggert. The canonical version of this
23 # script is maintained as build-aux/bootstrap in gnulib, however, to
24 # be useful to your project, you should place a copy of it under
25 # version control in the top-level directory of your project. The
26 # intent is that all customization can be done with a bootstrap.conf
27 # file also maintained in your version control; gnulib comes with a
28 # template build-aux/bootstrap.conf to get you started.
30 # Please report bugs or propose patches to bug-gnulib@gnu.org.
32 nl='
35 # Ensure file names are sorted consistently across platforms.
36 LC_ALL=C
37 export LC_ALL
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 local_gl_dir=gl
45 # Honor $PERL, but work even if there is none.
46 PERL="${PERL-perl}"
48 me=$0
50 default_gnulib_url=git://git.sv.gnu.org/gnulib
52 usage() {
53 cat <<EOF
54 Usage: $me [OPTION]...
55 Bootstrap this package from the checked-out sources.
57 Options:
58 --gnulib-srcdir=DIRNAME specify the local directory where gnulib
59 sources reside. Use this if you already
60 have gnulib sources on your machine, and
61 do not want to waste your bandwidth downloading
62 them again. Defaults to \$GNULIB_SRCDIR
63 --bootstrap-sync if this bootstrap script is not identical to
64 the version in the local gnulib sources,
65 update this script, and then restart it with
66 /bin/sh or the shell \$CONFIG_SHELL
67 --no-bootstrap-sync do not check whether bootstrap is out of sync
68 --copy copy files instead of creating symbolic links
69 --force attempt to bootstrap even if the sources seem
70 not to have been checked out
71 --no-git do not use git to update gnulib. Requires that
72 --gnulib-srcdir point to a correct gnulib snapshot
73 --skip-po do not download po files
74 EOF
75 bootstrap_print_option_usage_hook
76 cat <<EOF
77 If the file $me.conf exists in the same directory as this script, its
78 contents are read as shell variables to configure the bootstrap.
80 For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
81 are honored.
83 Gnulib sources can be fetched in various ways:
85 * If this package is in a git repository with a 'gnulib' submodule
86 configured, then that submodule is initialized and updated and sources
87 are fetched from there. If \$GNULIB_SRCDIR is set (directly or via
88 --gnulib-srcdir) and is a git repository, then it is used as a reference.
90 * Otherwise, if \$GNULIB_SRCDIR is set (directly or via --gnulib-srcdir),
91 then sources are fetched from that local directory. If it is a git
92 repository and \$GNULIB_REVISION is set, then that revision is checked
93 out.
95 * Otherwise, if this package is in a git repository with a 'gnulib'
96 submodule configured, then that submodule is initialized and updated and
97 sources are fetched from there.
99 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources are
100 cloned into that directory using git from \$GNULIB_URL, defaulting to
101 $default_gnulib_url.
102 If \$GNULIB_REVISION is set, 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 \$GNULIB_REVISION is set, then that
106 revision is checked out.
108 If you maintain a package and want to pin a particular revision of the
109 Gnulib sources that has been tested with your package, then there are two
110 possible approaches: either configure a 'gnulib' submodule with the
111 appropriate revision, or set \$GNULIB_REVISION (and if necessary
112 \$GNULIB_URL) in $me.conf.
114 Running without arguments will suffice in most cases.
118 # warnf_ FORMAT-STRING ARG1...
119 warnf_ ()
121 warnf_format_=$1
122 shift
123 nl='
125 case $* in
126 *$nl*) me_=$(printf "$me"|tr "$nl|" '??')
127 printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
128 *) printf "$me: $warnf_format_" "$@" ;;
129 esac >&2
132 # warn_ WORD1...
133 warn_ ()
135 # If IFS does not start with ' ', set it and emit the warning in a subshell.
136 case $IFS in
137 ' '*) warnf_ '%s\n' "$*";;
138 *) (IFS=' '; warn_ "$@");;
139 esac
142 # die WORD1...
143 die() { warn_ "$@"; exit 1; }
145 # Configuration.
147 # Name of the Makefile.am
148 gnulib_mk=gnulib.mk
150 # List of gnulib modules needed.
151 gnulib_modules=
153 # Any gnulib files needed that are not in modules.
154 gnulib_files=
156 : ${AUTOPOINT=autopoint}
157 : ${AUTORECONF=autoreconf}
159 # A function to be called for each unrecognized option. Returns 0 if
160 # the option in $1 has been processed by the function. Returns 1 if
161 # the option has not been processed by the function. Override it via
162 # your own definition in bootstrap.conf
164 bootstrap_option_hook() { return 1; }
166 # A function to be called in order to print the --help information
167 # corresponding to user-defined command-line options.
169 bootstrap_print_option_usage_hook() { :; }
171 # A function to be called right after gnulib-tool is run.
172 # Override it via your own definition in bootstrap.conf.
173 bootstrap_post_import_hook() { :; }
175 # A function to be called after everything else in this script.
176 # Override it via your own definition in bootstrap.conf.
177 bootstrap_epilogue() { :; }
179 # The command to download all .po files for a specified domain into a
180 # specified directory. Fill in the first %s with the destination
181 # directory and the second with the domain name.
182 po_download_command_format=\
183 "wget --mirror --level=1 -nd -nv -A.po -P '%s' \
184 https://translationproject.org/latest/%s/"
186 # Prefer a non-empty tarname (4th argument of AC_INIT if given), else
187 # fall back to the package name (1st argument with munging)
188 extract_package_name='
189 /^AC_INIT(\[*/{
190 s///
191 /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
192 s//\1/
193 s/[],)].*//
197 s/[],)].*//
198 s/^GNU //
199 y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
200 s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
204 package=$(sed -n "$extract_package_name" configure.ac) \
205 || die 'cannot find package name in configure.ac'
206 gnulib_name=lib$package
208 build_aux=build-aux
209 source_base=lib
210 m4_base=m4
211 doc_base=doc
212 tests_base=tests
213 gnulib_extra_files="
214 build-aux/install-sh
215 build-aux/mdate-sh
216 build-aux/texinfo.tex
217 build-aux/depcomp
218 build-aux/config.guess
219 build-aux/config.sub
220 doc/INSTALL
223 # Additional gnulib-tool options to use. Use "\newline" to break lines.
224 gnulib_tool_option_extras=
226 # Other locale categories that need message catalogs.
227 EXTRA_LOCALE_CATEGORIES=
229 # Additional xgettext options to use. Use "\\\newline" to break lines.
230 XGETTEXT_OPTIONS='\\\
231 --flag=_:1:pass-c-format\\\
232 --flag=N_:1:pass-c-format\\\
233 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
236 # Package bug report address and copyright holder for gettext files
237 COPYRIGHT_HOLDER='Free Software Foundation, Inc.'
238 MSGID_BUGS_ADDRESS=bug-$package@gnu.org
240 # Files we don't want to import.
241 excluded_files=
243 # File that should exist in the top directory of a checked out hierarchy,
244 # but not in a distribution tarball.
245 checkout_only_file=README-hacking
247 # Whether to use copies instead of symlinks.
248 copy=false
250 # Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
251 # those files to be generated in directories like lib/, m4/, and po/.
252 # Or set it to 'auto' to make this script select which to use based
253 # on which version control system (if any) is used in the source directory.
254 vc_ignore=auto
256 # Set this to true in bootstrap.conf to enable --bootstrap-sync by
257 # default.
258 bootstrap_sync=false
260 # Use git to update gnulib sources
261 use_git=true
263 check_exists() {
264 if test "$1" = "--verbose"; then
265 ($2 --version </dev/null) >/dev/null 2>&1
266 if test $? -ge 126; then
267 # If not found, run with diagnostics as one may be
268 # presented with env variables to set to find the right version
269 ($2 --version </dev/null)
271 else
272 ($1 --version </dev/null) >/dev/null 2>&1
275 test $? -lt 126
278 # find_tool ENVVAR NAMES...
279 # -------------------------
280 # Search for a required program. Use the value of ENVVAR, if set,
281 # otherwise find the first of the NAMES that can be run.
282 # If found, set ENVVAR to the program name, die otherwise.
284 # FIXME: code duplication, see also gnu-web-doc-update.
285 find_tool ()
287 find_tool_envvar=$1
288 shift
289 find_tool_names=$@
290 eval "find_tool_res=\$$find_tool_envvar"
291 if test x"$find_tool_res" = x; then
292 for i; do
293 if check_exists $i; then
294 find_tool_res=$i
295 break
297 done
299 if test x"$find_tool_res" = x; then
300 warn_ "one of these is required: $find_tool_names;"
301 die "alternatively set $find_tool_envvar to a compatible tool"
303 eval "$find_tool_envvar=\$find_tool_res"
304 eval "export $find_tool_envvar"
307 # Override the default configuration, if necessary.
308 # Make sure that bootstrap.conf is sourced from the current directory
309 # if we were invoked as "sh bootstrap".
310 case "$0" in
311 */*) test -r "$0.conf" && . "$0.conf" ;;
312 *) test -r "$0.conf" && . ./"$0.conf" ;;
313 esac
315 if test "$vc_ignore" = auto; then
316 vc_ignore=
317 test -d .git && vc_ignore=.gitignore
318 test -d CVS && vc_ignore="$vc_ignore .cvsignore"
321 if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then
322 use_gnulib=false
323 else
324 use_gnulib=true
327 # Translate configuration into internal form.
329 # Parse options.
331 for option
333 case $option in
334 --help)
335 usage
336 exit;;
337 --gnulib-srcdir=*)
338 GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
339 --skip-po)
340 SKIP_PO=t;;
341 --force)
342 checkout_only_file=;;
343 --copy)
344 copy=true;;
345 --bootstrap-sync)
346 bootstrap_sync=true;;
347 --no-bootstrap-sync)
348 bootstrap_sync=false;;
349 --no-git)
350 use_git=false;;
352 bootstrap_option_hook $option || die "$option: unknown option";;
353 esac
354 done
356 $use_git || test -d "$GNULIB_SRCDIR" \
357 || die "Error: --no-git requires --gnulib-srcdir"
359 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
360 die "Bootstrapping from a non-checked-out distribution is risky."
363 # Strip blank and comment lines to leave significant entries.
364 gitignore_entries() {
365 sed '/^#/d; /^$/d' "$@"
368 # If $STR is not already on a line by itself in $FILE, insert it at the start.
369 # Entries are inserted at the start of the ignore list to ensure existing
370 # entries starting with ! are not overridden. Such entries support
371 # whitelisting exceptions after a more generic blacklist pattern.
372 insert_if_absent() {
373 file=$1
374 str=$2
375 test -f $file || touch $file
376 test -r $file || die "Error: failed to read ignore file: $file"
377 duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
378 if [ "$duplicate_entries" ] ; then
379 die "Error: Duplicate entries in $file: " $duplicate_entries
381 linesold=$(gitignore_entries $file | wc -l)
382 linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
383 if [ $linesold != $linesnew ] ; then
384 { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
385 || die "insert_if_absent $file $str: failed"
389 # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
390 # insert_if_absent.
391 insert_vc_ignore() {
392 vc_ignore_file="$1"
393 pattern="$2"
394 case $vc_ignore_file in
395 *.gitignore)
396 # A .gitignore entry that does not start with '/' applies
397 # recursively to subdirectories, so prepend '/' to every
398 # .gitignore entry.
399 pattern=$(echo "$pattern" | sed s,^,/,);;
400 esac
401 insert_if_absent "$vc_ignore_file" "$pattern"
404 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
405 found_aux_dir=no
406 grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
407 >/dev/null && found_aux_dir=yes
408 grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
409 >/dev/null && found_aux_dir=yes
410 test $found_aux_dir = yes \
411 || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
413 # If $build_aux doesn't exist, create it now, otherwise some bits
414 # below will malfunction. If creating it, also mark it as ignored.
415 if test ! -d $build_aux; then
416 mkdir $build_aux
417 for dot_ig in x $vc_ignore; do
418 test $dot_ig = x && continue
419 insert_vc_ignore $dot_ig $build_aux
420 done
423 # Note this deviates from the version comparison in automake
424 # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
425 # but this should suffice as we won't be specifying old
426 # version formats or redundant trailing .0 in bootstrap.conf.
427 # If we did want full compatibility then we should probably
428 # use m4_version_compare from autoconf.
429 sort_ver() { # sort -V is not generally available
430 ver1="$1"
431 ver2="$2"
433 # split on '.' and compare each component
435 while : ; do
436 p1=$(echo "$ver1" | cut -d. -f$i)
437 p2=$(echo "$ver2" | cut -d. -f$i)
438 if [ ! "$p1" ]; then
439 echo "$1 $2"
440 break
441 elif [ ! "$p2" ]; then
442 echo "$2 $1"
443 break
444 elif [ ! "$p1" = "$p2" ]; then
445 if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
446 echo "$2 $1"
447 elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
448 echo "$1 $2"
449 else # numeric, then lexicographic comparison
450 lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
451 if [ "$lp" = "$p2" ]; then
452 echo "$1 $2"
453 else
454 echo "$2 $1"
457 break
459 i=$(($i+1))
460 done
463 get_version_sed='
464 # Move version to start of line.
465 s/.*[v ]\([0-9]\)/\1/
467 # Skip lines that do not start with version.
468 /^[0-9]/!d
470 # Remove characters after the version.
471 s/[^.a-z0-9-].*//
473 # The first component must be digits only.
474 s/^\([0-9]*\)[a-z-].*/\1/
476 #the following essentially does s/5.005/5.5/
477 s/\.0*\([1-9]\)/.\1/g
481 get_version() {
482 app=$1
484 $app --version >/dev/null 2>&1 || { $app --version; return 1; }
486 $app --version 2>&1 | sed -n "$get_version_sed"
489 check_versions() {
490 ret=0
492 while read app req_ver; do
493 # We only need libtoolize from the libtool package.
494 if test "$app" = libtool; then
495 app=libtoolize
497 # Exempt git if --no-git is in effect.
498 if test "$app" = git; then
499 $use_git || continue
501 # Honor $APP variables ($TAR, $AUTOCONF, etc.)
502 appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
503 test "$appvar" = TAR && appvar=AMTAR
504 case $appvar in
505 GZIP) ;; # Do not use $GZIP: it contains gzip options.
506 PERL::*) ;; # Keep perl modules as-is
507 *) eval "app=\${$appvar-$app}" ;;
508 esac
510 # Handle the still-experimental Automake-NG programs specially.
511 # They remain named as the mainstream Automake programs ("automake",
512 # and "aclocal") to avoid gratuitous incompatibilities with
513 # pre-existing usages (by, say, autoreconf, or custom autogen.sh
514 # scripts), but correctly identify themselves (as being part of
515 # "GNU automake-ng") when asked their version.
516 case $app in
517 automake-ng|aclocal-ng)
518 app=${app%-ng}
519 ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
520 warn_ "Error: '$app' not found or not from Automake-NG"
521 ret=1
522 continue
523 } ;;
524 # Another check is for perl modules. These can be written as
525 # e.g. perl::XML::XPath in case of XML::XPath module, etc.
526 perl::*)
527 # Extract module name
528 app="${app#perl::}"
529 if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
530 warn_ "Error: perl module '$app' not found"
531 ret=1
533 continue
535 esac
536 if [ "$req_ver" = "-" ]; then
537 # Merely require app to exist; not all prereq apps are well-behaved
538 # so we have to rely on $? rather than get_version.
539 if ! check_exists --verbose $app; then
540 warn_ "Error: '$app' not found"
541 ret=1
543 else
544 # Require app to produce a new enough version string.
545 inst_ver=$(get_version $app)
546 if [ ! "$inst_ver" ]; then
547 warn_ "Error: '$app' not found"
548 ret=1
549 else
550 latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
551 if [ ! "$latest_ver" = "$inst_ver" ]; then
552 warnf_ '%s\n' \
553 "Error: '$app' version == $inst_ver is too old" \
554 " '$app' version >= $req_ver is required"
555 ret=1
559 done
561 return $ret
564 print_versions() {
565 echo "Program Min_version"
566 echo "----------------------"
567 printf %s "$buildreq"
568 echo "----------------------"
569 # can't depend on column -t
572 # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
573 # Also find the compatible sha1 utility on the BSDs
574 if test x"$SKIP_PO" = x; then
575 find_tool SHA1SUM sha1sum gsha1sum shasum sha1
578 use_libtool=0
579 # We'd like to use grep -E, to see if any of LT_INIT,
580 # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
581 # but that's not portable enough (e.g., for Solaris).
582 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
583 && use_libtool=1
584 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
585 && use_libtool=1
586 if test $use_libtool = 1; then
587 find_tool LIBTOOLIZE glibtoolize libtoolize
590 # gnulib-tool requires at least automake and autoconf.
591 # If either is not listed, add it (with minimum version) as a prerequisite.
592 case $buildreq in
593 *automake*) ;;
594 *) buildreq="automake 1.9
595 $buildreq" ;;
596 esac
597 case $buildreq in
598 *autoconf*) ;;
599 *) buildreq="autoconf 2.59
600 $buildreq" ;;
601 esac
603 # When we can deduce that gnulib-tool will require patch,
604 # and when patch is not already listed as a prerequisite, add it, too.
605 if test -d "$local_gl_dir" \
606 && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
607 case $buildreq in
608 *patch*) ;;
609 *) buildreq="patch -
610 $buildreq" ;;
611 esac
614 if ! printf "$buildreq" | check_versions; then
615 echo >&2
616 if test -f README-prereq; then
617 die "See README-prereq for how to get the prerequisite programs"
618 else
619 die "Please install the prerequisite programs"
623 # Warn the user if autom4te appears to be broken; this causes known
624 # issues with at least gettext 0.18.3.
625 probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
626 if test "x$probe" != xhi; then
627 warn_ "WARNING: your autom4te wrapper eats stdin;"
628 warn_ "if bootstrap fails, consider upgrading your autotools"
631 echo "$0: Bootstrapping from checked-out $package sources..."
633 # See if we can use gnulib's git-merge-changelog merge driver.
634 if $use_git && test -d .git && check_exists git; then
635 if git config merge.merge-changelog.driver >/dev/null ; then
637 elif check_exists git-merge-changelog; then
638 echo "$0: initializing git-merge-changelog driver"
639 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
640 git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
641 else
642 echo "$0: consider installing git-merge-changelog from gnulib"
647 cleanup_gnulib() {
648 status=$?
649 rm -fr "$gnulib_path"
650 exit $status
653 git_modules_config () {
654 test -f .gitmodules && git config --file .gitmodules "$@"
657 if $use_gnulib; then
658 if $use_git; then
659 gnulib_path=$(git_modules_config submodule.gnulib.path)
660 test -z "$gnulib_path" && gnulib_path=gnulib
663 # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a
664 # submodule, for use in the rest of the script.
666 case ${GNULIB_SRCDIR--} in
668 # Note that $use_git is necessarily true in this case.
669 if git_modules_config submodule.gnulib.url >/dev/null; then
670 echo "$0: getting gnulib files..."
671 git submodule init -- "$gnulib_path" || exit $?
672 git submodule update -- "$gnulib_path" || exit $?
674 elif [ ! -d "$gnulib_path" ]; then
675 echo "$0: getting gnulib files..."
677 trap cleanup_gnulib 1 2 13 15
679 shallow=
680 if test -z "$GNULIB_REVISION"; then
681 git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
683 git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
684 || cleanup_gnulib
686 trap - 1 2 13 15
688 GNULIB_SRCDIR=$gnulib_path
691 # Use GNULIB_SRCDIR directly or as a reference.
692 if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
693 git_modules_config submodule.gnulib.url >/dev/null; then
694 echo "$0: getting gnulib files..."
695 if git submodule -h|grep -- --reference > /dev/null; then
696 # Prefer the one-liner available in git 1.6.4 or newer.
697 git submodule update --init --reference "$GNULIB_SRCDIR" \
698 "$gnulib_path" || exit $?
699 else
700 # This fallback allows at least git 1.5.5.
701 if test -f "$gnulib_path"/gnulib-tool; then
702 # Since file already exists, assume submodule init already complete.
703 git submodule update -- "$gnulib_path" || exit $?
704 else
705 # Older git can't clone into an empty directory.
706 rmdir "$gnulib_path" 2>/dev/null
707 git clone --reference "$GNULIB_SRCDIR" \
708 "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
709 && git submodule init -- "$gnulib_path" \
710 && git submodule update -- "$gnulib_path" \
711 || exit $?
714 GNULIB_SRCDIR=$gnulib_path
717 esac
719 if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \
720 && ! git_modules_config submodule.gnulib.url >/dev/null; then
721 (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib
724 # $GNULIB_SRCDIR now points to the version of gnulib to use, and
725 # we no longer need to use git or $gnulib_path below here.
727 if $bootstrap_sync; then
728 cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
729 echo "$0: updating bootstrap and restarting..."
730 case $(sh -c 'echo "$1"' -- a) in
731 a) ignored=--;;
732 *) ignored=ignored;;
733 esac
734 exec sh -c \
735 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
736 $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
737 "$0" "$@" --no-bootstrap-sync
741 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
742 <$gnulib_tool || exit $?
745 # Get translations.
747 download_po_files() {
748 subdir=$1
749 domain=$2
750 echo "$me: getting translations into $subdir for $domain..."
751 cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
752 eval "$cmd"
755 # Mirror .po files to $po_dir/.reference and copy only the new
756 # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
757 # Note po files that exist locally only are left in $po_dir but will
758 # not be included in LINGUAS and hence will not be distributed.
759 update_po_files() {
760 # Directory containing primary .po files.
761 # Overwrite them only when we're sure a .po file is new.
762 po_dir=$1
763 domain=$2
765 # Mirror *.po files into this dir.
766 # Usually contains *.s1 checksum files.
767 ref_po_dir="$po_dir/.reference"
769 test -d $ref_po_dir || mkdir $ref_po_dir || return
770 download_po_files $ref_po_dir $domain \
771 && ls "$ref_po_dir"/*.po 2>/dev/null |
772 sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
774 langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
775 test "$langs" = '*' && langs=x
776 for po in $langs; do
777 case $po in x) continue;; esac
778 new_po="$ref_po_dir/$po.po"
779 cksum_file="$ref_po_dir/$po.s1"
780 if ! test -f "$cksum_file" ||
781 ! test -f "$po_dir/$po.po" ||
782 ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
783 echo "$me: updated $po_dir/$po.po..."
784 cp "$new_po" "$po_dir/$po.po" \
785 && $SHA1SUM < "$new_po" > "$cksum_file" || return
787 done
790 case $SKIP_PO in
792 if test -d po; then
793 update_po_files po $package || exit
796 if test -d runtime-po; then
797 update_po_files runtime-po $package-runtime || exit
798 fi;;
799 esac
801 symlink_to_dir()
803 src=$1/$2
804 dst=${3-$2}
806 test -f "$src" && {
808 # If the destination directory doesn't exist, create it.
809 # This is required at least for "lib/uniwidth/cjk.h".
810 dst_dir=$(dirname "$dst")
811 if ! test -d "$dst_dir"; then
812 mkdir -p "$dst_dir"
814 # If we've just created a directory like lib/uniwidth,
815 # tell version control system(s) it's ignorable.
816 # FIXME: for now, this does only one level
817 parent=$(dirname "$dst_dir")
818 for dot_ig in x $vc_ignore; do
819 test $dot_ig = x && continue
820 ig=$parent/$dot_ig
821 insert_vc_ignore $ig "${dst_dir##*/}"
822 done
825 if $copy; then
827 test ! -h "$dst" || {
828 echo "$me: rm -f $dst" &&
829 rm -f "$dst"
831 } &&
832 test -f "$dst" &&
833 cmp -s "$src" "$dst" || {
834 echo "$me: cp -fp $src $dst" &&
835 cp -fp "$src" "$dst"
837 else
838 # Leave any existing symlink alone, if it already points to the source,
839 # so that broken build tools that care about symlink times
840 # aren't confused into doing unnecessary builds. Conversely, if the
841 # existing symlink's timestamp is older than the source, make it afresh,
842 # so that broken tools aren't confused into skipping needed builds. See
843 # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
844 test -h "$dst" &&
845 src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
846 dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
847 test "$src_i" = "$dst_i" &&
848 both_ls=$(ls -dt "$src" "$dst") &&
849 test "X$both_ls" = "X$dst$nl$src" || {
850 dot_dots=
851 case $src in
852 /*) ;;
854 case /$dst/ in
855 *//* | */../* | */./* | /*/*/*/*/*/)
856 die "invalid symlink calculation: $src -> $dst";;
857 /*/*/*/*/) dot_dots=../../../;;
858 /*/*/*/) dot_dots=../../;;
859 /*/*/) dot_dots=../;;
860 esac;;
861 esac
863 echo "$me: ln -fs $dot_dots$src $dst" &&
864 ln -fs "$dot_dots$src" "$dst"
870 version_controlled_file() {
871 parent=$1
872 file=$2
873 if test -d .git; then
874 git rm -n "$file" > /dev/null 2>&1
875 elif test -d .svn; then
876 svn log -r HEAD "$file" > /dev/null 2>&1
877 elif test -d CVS; then
878 grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
879 grep '^/[^/]*/[0-9]' > /dev/null
880 else
881 warn_ "no version control for $file?"
882 false
886 # NOTE: we have to be careful to run both autopoint and libtoolize
887 # before gnulib-tool, since gnulib-tool is likely to provide newer
888 # versions of files "installed" by these two programs.
889 # Then, *after* gnulib-tool (see below), we have to be careful to
890 # run autoreconf in such a way that it does not run either of these
891 # two just-pre-run programs.
893 # Import from gettext.
894 with_gettext=yes
895 grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
896 with_gettext=no
898 if test $with_gettext = yes || test $use_libtool = 1; then
900 tempbase=.bootstrap$$
901 trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
903 > $tempbase.0 > $tempbase.1 &&
904 find . ! -type d -print | sort > $tempbase.0 || exit
906 if test $with_gettext = yes; then
907 # Released autopoint has the tendency to install macros that have been
908 # obsoleted in current gnulib, so run this before gnulib-tool.
909 echo "$0: $AUTOPOINT --force"
910 $AUTOPOINT --force || exit
913 # Autoreconf runs aclocal before libtoolize, which causes spurious
914 # warnings if the initial aclocal is confused by the libtoolized
915 # (or worse out-of-date) macro directory.
916 # libtoolize 1.9b added the --install option; but we support back
917 # to libtoolize 1.5.22, where the install action was default.
918 if test $use_libtool = 1; then
919 install=
920 case $($LIBTOOLIZE --help) in
921 *--install*) install=--install ;;
922 esac
923 echo "running: $LIBTOOLIZE $install --copy"
924 $LIBTOOLIZE $install --copy
927 find . ! -type d -print | sort >$tempbase.1
928 old_IFS=$IFS
929 IFS=$nl
930 for file in $(comm -13 $tempbase.0 $tempbase.1); do
931 IFS=$old_IFS
932 parent=${file%/*}
933 version_controlled_file "$parent" "$file" || {
934 for dot_ig in x $vc_ignore; do
935 test $dot_ig = x && continue
936 ig=$parent/$dot_ig
937 insert_vc_ignore "$ig" "${file##*/}"
938 done
940 done
941 IFS=$old_IFS
943 rm -f $tempbase.0 $tempbase.1
944 trap - 1 2 13 15
947 # Import from gnulib.
949 if $use_gnulib; then
950 gnulib_tool_options="\
951 --no-changelog\
952 --aux-dir=$build_aux\
953 --doc-base=$doc_base\
954 --lib=$gnulib_name\
955 --m4-base=$m4_base/\
956 --source-base=$source_base/\
957 --tests-base=$tests_base\
958 --local-dir=$local_gl_dir\
959 $gnulib_tool_option_extras\
961 if test $use_libtool = 1; then
962 case "$gnulib_tool_options " in
963 *' --libtool '*) ;;
964 *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
965 esac
967 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
968 $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
969 || die "gnulib-tool failed"
971 for file in $gnulib_files; do
972 symlink_to_dir "$GNULIB_SRCDIR" $file \
973 || die "failed to symlink $file"
974 done
977 bootstrap_post_import_hook \
978 || die "bootstrap_post_import_hook failed"
980 # Don't proceed if there are uninitialized submodules. In particular,
981 # the next step will remove dangling links, which might be links into
982 # uninitialized submodules.
984 # Uninitialized submodules are listed with an initial dash.
985 if $use_git && git submodule | grep '^-' >/dev/null; then
986 die "some git submodules are not initialized. " \
987 "Run 'git submodule update --init' and bootstrap again."
990 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
991 # gnulib-populated directories. Such .m4 files would cause aclocal to fail.
992 # The following requires GNU find 4.2.3 or newer. Considering the usual
993 # portability constraints of this script, that may seem a very demanding
994 # requirement, but it should be ok. Ignore any failure, which is fine,
995 # since this is only a convenience to help developers avoid the relatively
996 # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
997 # between successive runs of this script.
998 find "$m4_base" "$source_base" \
999 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
1000 -type l -xtype l -delete > /dev/null 2>&1
1002 # Invoke autoreconf with --force --install to ensure upgrades of tools
1003 # such as ylwrap.
1004 AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
1006 # Some systems (RHEL 5) are using ancient autotools, for which the
1007 # --no-recursive option had not been invented. Detect that lack and
1008 # omit the option when it's not supported. FIXME in 2017: remove this
1009 # hack when RHEL 5 autotools are updated, or when they become irrelevant.
1010 case $($AUTORECONF --help) in
1011 *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
1012 esac
1014 # Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
1015 echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
1016 AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
1017 || die "autoreconf failed"
1019 # Get some extra files from gnulib, overriding existing files.
1020 for file in $gnulib_extra_files; do
1021 case $file in
1022 */INSTALL) dst=INSTALL;;
1023 build-aux/*) dst=$build_aux/${file#build-aux/};;
1024 *) dst=$file;;
1025 esac
1026 symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
1027 || die "failed to symlink $file"
1028 done
1030 if test $with_gettext = yes; then
1031 # Create gettext configuration.
1032 echo "$0: Creating po/Makevars from po/Makevars.template ..."
1033 rm -f po/Makevars
1034 sed '
1035 /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
1036 /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
1037 /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
1038 /^XGETTEXT_OPTIONS *=/{
1039 s/$/ \\/
1041 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
1043 ' po/Makevars.template >po/Makevars \
1044 || die 'cannot generate po/Makevars'
1046 # If the 'gettext' module is in use, grab the latest Makefile.in.in.
1047 # If only the 'gettext-h' module is in use, assume autopoint already
1048 # put the correct version of this file into place.
1049 case $gnulib_modules in
1050 *gettext-h*) ;;
1051 *gettext*)
1052 cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
1053 || die "cannot create po/Makefile.in.in"
1055 esac
1057 if test -d runtime-po; then
1058 # Similarly for runtime-po/Makevars, but not quite the same.
1059 rm -f runtime-po/Makevars
1060 sed '
1061 /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
1062 /^subdir *=.*/s/=.*/= runtime-po/
1063 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
1064 /^XGETTEXT_OPTIONS *=/{
1065 s/$/ \\/
1067 '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
1069 ' po/Makevars.template >runtime-po/Makevars \
1070 || die 'cannot generate runtime-po/Makevars'
1072 # Copy identical files from po to runtime-po.
1073 (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
1077 bootstrap_epilogue
1079 echo "$0: done. Now you can run './configure'."
1081 # Local variables:
1082 # eval: (add-hook 'before-save-hook 'time-stamp)
1083 # time-stamp-start: "scriptversion="
1084 # time-stamp-format: "%:y-%02m-%02d.%02H"
1085 # time-stamp-time-zone: "UTC0"
1086 # time-stamp-end: "; # UTC"
1087 # End: