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