]> git.ipfire.org Git - thirdparty/tar.git/blame - bootstrap
tar: fix current_block confusion
[thirdparty/tar.git] / bootstrap
CommitLineData
88ffc135 1#! /bin/sh
0f289d72
PE
2# DO NOT EDIT! GENERATED AUTOMATICALLY!
3
ac6caa71 4# Bootstrap this package from checked-out sources.
88ffc135 5
0f289d72
PE
6scriptversion=2022-12-27.07; # UTC
7
c6f0ad51 8# Copyright (C) 2003-2024 Free Software Foundation, Inc.
0f289d72
PE
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <https://www.gnu.org/licenses/>.
22
23# Originally written by Paul Eggert. The canonical version of this
24# script is maintained as top/bootstrap in gnulib. However, to be
25# useful to your package, you should place a copy of it under version
26# control in the top-level directory of your package. The intent is
27# that all customization can be done with a bootstrap.conf file also
28# maintained in your version control; gnulib comes with a template
29# build-aux/bootstrap.conf to get you started.
30
31# Please report bugs or propose patches to bug-gnulib@gnu.org.
32
33me="$0"
34medir=`dirname "$me"`
35
36# Read the function library and the configuration.
37
38# A library of shell functions for autopull.sh, autogen.sh, and bootstrap.
39
8ccfc4e4 40scriptlibversion=2023-06-06.21; # UTC
0f289d72 41
c6f0ad51 42# Copyright (C) 2003-2024 Free Software Foundation, Inc.
5c4f8cad 43#
ac6caa71 44# This program is free software: you can redistribute it and/or modify
88ffc135 45# it under the terms of the GNU General Public License as published by
ac6caa71
SP
46# the Free Software Foundation, either version 3 of the License, or
47# (at your option) any later version.
5c4f8cad 48#
88ffc135
PE
49# This program is distributed in the hope that it will be useful,
50# but WITHOUT ANY WARRANTY; without even the implied warranty of
51# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52# GNU General Public License for more details.
5c4f8cad 53#
88ffc135 54# You should have received a copy of the GNU General Public License
1f73735b 55# along with this program. If not, see <https://www.gnu.org/licenses/>.
88ffc135 56
241b72ff 57# Originally written by Paul Eggert. The canonical version of this
0f289d72 58# script is maintained as top/bootstrap-funclib.sh in gnulib. However,
5c4f8cad
PE
59# to be useful to your package, you should place a copy of it under
60# version control in the top-level directory of your package. The
241b72ff
PE
61# intent is that all customization can be done with a bootstrap.conf
62# file also maintained in your version control; gnulib comes with a
63# template build-aux/bootstrap.conf to get you started.
64
0f289d72
PE
65nl='
66'
88ffc135 67
0f289d72
PE
68# Ensure file names are sorted consistently across platforms.
69LC_ALL=C
70export LC_ALL
6cb94e37 71
0f289d72
PE
72# Honor $PERL, but work even if there is none.
73PERL="${PERL-perl}"
ac6caa71 74
0f289d72
PE
75default_gnulib_url=https://git.savannah.gnu.org/git/gnulib.git
76
77# Copyright year, for the --version output.
78copyright_year=`echo "$scriptlibversion" | sed -e 's/[^0-9].*//'`
79copyright="Copyright (C) ${copyright_year} Free Software Foundation, Inc.
80License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
81This is free software: you are free to change and redistribute it.
82There is NO WARRANTY, to the extent permitted by law."
83
84# warnf_ FORMAT-STRING ARG1...
85warnf_ ()
86{
87 warnf_format_=$1
88 shift
89 nl='
90'
91 case $* in
92 *$nl*) me_=$(printf "$me"|tr "$nl|" '??')
93 printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
94 *) printf "$me: $warnf_format_" "$@" ;;
95 esac >&2
96}
97
98# warn_ WORD1...
99warn_ ()
100{
101 # If IFS does not start with ' ', set it and emit the warning in a subshell.
102 case $IFS in
103 ' '*) warnf_ '%s\n' "$*";;
104 *) (IFS=' '; warn_ "$@");;
105 esac
106}
107
108# die WORD1...
109die() { warn_ "$@"; exit 1; }
110
111# ------------------------------ Configuration. ------------------------------
112
113# Directory that contains package-specific gnulib modules and/or overrides.
114local_gl_dir=gl
115
116# Name of the Makefile.am
117# XXX Not used.
118gnulib_mk=gnulib.mk
119
120# List of gnulib modules needed.
121gnulib_modules=
122
123# Any gnulib files needed that are not in modules.
124gnulib_files=
125
126# A function to be called for each unrecognized option. Returns 0 if
127# the option in $1 has been processed by the function. Returns 1 if
128# the option has not been processed by the function. Override it via
129# your own definition in bootstrap.conf
130bootstrap_option_hook() { return 1; }
131
132# A function to be called in order to print the --help information
133# corresponding to user-defined command-line options.
134bootstrap_print_option_usage_hook() { :; }
135
136# A function to be called at the end of autopull.sh.
137# Override it via your own definition in bootstrap.conf.
138bootstrap_post_pull_hook() { :; }
139
140# A function to be called right after gnulib-tool is run.
141# Override it via your own definition in bootstrap.conf.
142bootstrap_post_import_hook() { :; }
143
144# A function to be called after everything else in this script.
145# Override it via your own definition in bootstrap.conf.
146bootstrap_epilogue() { :; }
147
148# The command to download all .po files for a specified domain into a
149# specified directory. Fill in the first %s with the destination
150# directory and the second with the domain name.
151po_download_command_format=\
152"wget --mirror --level=1 -nd -nv -A.po -P '%s' \
153 https://translationproject.org/latest/%s/"
154
155# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
156# fall back to the package name (1st argument with munging).
157extract_package_name='
158 /^AC_INIT(\[*/{
159 s///
160 /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
161 s//\1/
162 s/[],)].*//
163 p
164 q
165 }
166 s/[],)].*//
167 s/^GNU //
168 y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
169 s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
170 p
171 }
172'
173package=$(${AUTOCONF:-autoconf} --trace AC_INIT:\$4 configure.ac 2>/dev/null)
174if test -z "$package"; then
175 package=$(sed -n "$extract_package_name" configure.ac) \
176 || die 'cannot find package name in configure.ac'
177fi
178gnulib_name=lib$package
179
180build_aux=build-aux
181source_base=lib
182m4_base=m4
183doc_base=doc
184tests_base=tests
185gnulib_extra_files="
186 build-aux/install-sh
187 build-aux/mdate-sh
188 build-aux/texinfo.tex
189 build-aux/depcomp
190 build-aux/config.guess
191 build-aux/config.sub
192 doc/INSTALL
193"
194
195# Additional gnulib-tool options to use. Use "\newline" to break lines.
196gnulib_tool_option_extras=
197
198# Other locale categories that need message catalogs.
199EXTRA_LOCALE_CATEGORIES=
200
201# Additional xgettext options to use. Use "\\\newline" to break lines.
202XGETTEXT_OPTIONS='\\\
203 --flag=_:1:pass-c-format\\\
204 --flag=N_:1:pass-c-format\\\
205 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
206'
207
208# Package bug report address and copyright holder for gettext files
209COPYRIGHT_HOLDER='Free Software Foundation, Inc.'
210MSGID_BUGS_ADDRESS=bug-$package@gnu.org
211
212# Files we don't want to import.
213# XXX Not used.
214excluded_files=
215
216# File that should exist in the top directory of a checked out hierarchy,
217# but not in a distribution tarball.
218checkout_only_file=README-hacking
219
220# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
221# those files to be generated in directories like lib/, m4/, and po/.
222# Or set it to 'auto' to make this script select which to use based
223# on which version control system (if any) is used in the source directory.
224vc_ignore=auto
225
226# Set this to true in bootstrap.conf to enable --bootstrap-sync by
227# default.
228bootstrap_sync=false
229
230# Override the default configuration, if necessary.
231# Make sure that bootstrap.conf is sourced from the current directory
232# if we were invoked as "sh bootstrap".
233conffile=`dirname "$me"`/bootstrap.conf
234test -r "$conffile" && . "$conffile"
235
236# ------------------------- Build-time prerequisites -------------------------
237
238check_exists() {
239 if test "$1" = "--verbose"; then
240 ($2 --version </dev/null) >/dev/null 2>&1
241 if test $? -ge 126; then
242 # If not found, run with diagnostics as one may be
243 # presented with env variables to set to find the right version
244 ($2 --version </dev/null)
245 fi
246 else
247 ($1 --version </dev/null) >/dev/null 2>&1
248 fi
249
250 test $? -lt 126
251}
252
253# Note this deviates from the version comparison in automake
254# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
255# but this should suffice as we won't be specifying old
256# version formats or redundant trailing .0 in bootstrap.conf.
257# If we did want full compatibility then we should probably
258# use m4_version_compare from autoconf.
259sort_ver() { # sort -V is not generally available
260 ver1="$1"
261 ver2="$2"
262
263 # split on '.' and compare each component
264 i=1
265 while : ; do
266 p1=$(echo "$ver1" | cut -d. -f$i)
267 p2=$(echo "$ver2" | cut -d. -f$i)
268 if [ ! "$p1" ]; then
269 echo "$1 $2"
270 break
271 elif [ ! "$p2" ]; then
272 echo "$2 $1"
273 break
274 elif [ ! "$p1" = "$p2" ]; then
275 if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
276 echo "$2 $1"
277 elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
278 echo "$1 $2"
279 else # numeric, then lexicographic comparison
280 lp=$(printf "%s\n%s\n" "$p1" "$p2" | LANG=C sort -n | tail -n1)
281 if [ "$lp" = "$p2" ]; then
282 echo "$1 $2"
283 else
284 echo "$2 $1"
285 fi
286 fi
287 break
288 fi
289 i=$(($i+1))
290 done
291}
292
293get_version_sed='
294# Move version to start of line.
295s/.*[v ]\([0-9]\)/\1/
296
297# Skip lines that do not start with version.
298/^[0-9]/!d
299
300# Remove characters after the version.
301s/[^.a-z0-9-].*//
302
303# The first component must be digits only.
304s/^\([0-9]*\)[a-z-].*/\1/
305
306#the following essentially does s/5.005/5.5/
307s/\.0*\([1-9]\)/.\1/g
308p
309q'
310
311get_version() {
312 app=$1
313
314 $app --version >/dev/null 2>&1 || { $app --version; return 1; }
315
316 $app --version 2>&1 | sed -n "$get_version_sed"
317}
318
319check_versions() {
320 ret=0
321
322 while read app req_ver; do
323 # We only need libtoolize from the libtool package.
324 if test "$app" = libtool; then
325 app=libtoolize
326 fi
327 # Exempt git if git is not needed.
328 if test "$app" = git; then
329 $check_git || continue
330 fi
331 # Honor $APP variables ($TAR, $AUTOCONF, etc.)
332 appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
333 test "$appvar" = TAR && appvar=AMTAR
334 case $appvar in
335 GZIP) ;; # Do not use $GZIP: it contains gzip options.
336 PERL::*) ;; # Keep perl modules as-is
337 *) eval "app=\${$appvar-$app}" ;;
338 esac
339
340 # Handle the still-experimental Automake-NG programs specially.
341 # They remain named as the mainstream Automake programs ("automake",
342 # and "aclocal") to avoid gratuitous incompatibilities with
8ccfc4e4 343 # preexisting usages (by, say, autoreconf, or custom autogen.sh
0f289d72
PE
344 # scripts), but correctly identify themselves (as being part of
345 # "GNU automake-ng") when asked their version.
346 case $app in
347 automake-ng|aclocal-ng)
348 app=${app%-ng}
349 ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
350 warn_ "Error: '$app' not found or not from Automake-NG"
351 ret=1
352 continue
353 } ;;
354 # Another check is for perl modules. These can be written as
355 # e.g. perl::XML::XPath in case of XML::XPath module, etc.
356 perl::*)
357 # Extract module name
358 app="${app#perl::}"
359 if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
360 warn_ "Error: perl module '$app' not found"
361 ret=1
362 fi
363 continue
364 ;;
365 esac
366 if [ "$req_ver" = "-" ]; then
367 # Merely require app to exist; not all prereq apps are well-behaved
368 # so we have to rely on $? rather than get_version.
369 if ! check_exists --verbose $app; then
370 warn_ "Error: '$app' not found"
371 ret=1
372 fi
373 else
374 # Require app to produce a new enough version string.
375 inst_ver=$(get_version $app)
376 if [ ! "$inst_ver" ]; then
377 warn_ "Error: '$app' not found"
378 ret=1
379 else
380 latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
381 if [ ! "$latest_ver" = "$inst_ver" ]; then
382 warnf_ '%s\n' \
383 "Error: '$app' version == $inst_ver is too old" \
384 " '$app' version >= $req_ver is required"
385 ret=1
386 fi
387 fi
388 fi
389 done
390
391 return $ret
392}
393
394print_versions() {
395 echo "Program Min_version"
396 echo "----------------------"
397 printf %s "$buildreq"
398 echo "----------------------"
399 # can't depend on column -t
400}
401
402# check_build_prerequisites check_git
403check_build_prerequisites()
404{
405 check_git="$1"
406
407 # gnulib-tool requires at least automake and autoconf.
408 # If either is not listed, add it (with minimum version) as a prerequisite.
409 case $buildreq in
410 *automake*) ;;
411 *) buildreq="automake 1.9
412$buildreq" ;;
413 esac
414 case $buildreq in
415 *autoconf*) ;;
416 *) buildreq="autoconf 2.59
417$buildreq" ;;
418 esac
419
420 # When we can deduce that gnulib-tool will require patch,
421 # and when patch is not already listed as a prerequisite, add it, too.
422 if test -d "$local_gl_dir" \
423 && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
424 case $buildreq in
425 *patch*) ;;
426 *) buildreq="patch -
427$buildreq" ;;
428 esac
429 fi
430
431 if ! printf '%s' "$buildreq" | check_versions; then
432 echo >&2
433 if test -f README-prereq; then
434 die "See README-prereq for how to get the prerequisite programs"
435 else
436 die "Please install the prerequisite programs"
437 fi
438 fi
439
440 # Warn the user if autom4te appears to be broken; this causes known
441 # issues with at least gettext 0.18.3.
442 probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
443 if test "x$probe" != xhi; then
444 warn_ "WARNING: your autom4te wrapper eats stdin;"
445 warn_ "if bootstrap fails, consider upgrading your autotools"
446 fi
447}
448
449# find_tool ENVVAR NAMES...
450# -------------------------
451# Search for a required program. Use the value of ENVVAR, if set,
452# otherwise find the first of the NAMES that can be run.
453# If found, set ENVVAR to the program name, die otherwise.
454#
455# FIXME: code duplication, see also gnu-web-doc-update.
456find_tool ()
457{
458 find_tool_envvar=$1
459 shift
460 find_tool_names=$@
461 eval "find_tool_res=\$$find_tool_envvar"
462 if test x"$find_tool_res" = x; then
463 for i; do
464 if check_exists $i; then
465 find_tool_res=$i
466 break
467 fi
468 done
469 fi
470 if test x"$find_tool_res" = x; then
471 warn_ "one of these is required: $find_tool_names;"
472 die "alternatively set $find_tool_envvar to a compatible tool"
473 fi
474 eval "$find_tool_envvar=\$find_tool_res"
475 eval "export $find_tool_envvar"
476}
477
478# --------------------- Preparing GNULIB_SRCDIR for use. ---------------------
479# This is part of autopull.sh, but bootstrap needs it too, for self-upgrading.
480
481cleanup_gnulib() {
482 status=$?
483 # XXX It's a bad idea to erase the submodule directory if it contains local
484 # modifications.
485 rm -fr "$gnulib_path"
486 exit $status
487}
488
489git_modules_config () {
490 test -f .gitmodules && git config --file .gitmodules "$@"
491}
492
493prepare_GNULIB_SRCDIR ()
494{
495 if test -n "$GNULIB_SRCDIR"; then
496 # Use GNULIB_SRCDIR directly.
497 # We already checked that $GNULIB_SRCDIR references a directory.
498 # Verify that it contains a gnulib checkout.
499 test -f "$GNULIB_SRCDIR/gnulib-tool" \
500 || die "Error: --gnulib-srcdir or \$GNULIB_SRCDIR is specified, but does not contain gnulib-tool"
501 elif $use_git; then
502 gnulib_path=$(git_modules_config submodule.gnulib.path)
503 test -z "$gnulib_path" && gnulib_path=gnulib
504
505 # Get gnulib files. Populate $gnulib_path, possibly updating a
506 # submodule, for use in the rest of the script.
507
508 if test -n "$GNULIB_REFDIR" && test -d "$GNULIB_REFDIR"/.git \
509 && git_modules_config submodule.gnulib.url >/dev/null; then
510 # Use GNULIB_REFDIR as a reference.
511 echo "$0: getting gnulib files..."
512 if git submodule -h|grep -- --reference > /dev/null; then
513 # Prefer the one-liner available in git 1.6.4 or newer.
514 git submodule update --init --reference "$GNULIB_REFDIR" \
515 "$gnulib_path" || exit $?
516 else
517 # This fallback allows at least git 1.5.5.
518 if test -f "$gnulib_path"/gnulib-tool; then
519 # Since file already exists, assume submodule init already complete.
520 git submodule update -- "$gnulib_path" || exit $?
521 else
522 # Older git can't clone into an empty directory.
523 rmdir "$gnulib_path" 2>/dev/null
524 git clone --reference "$GNULIB_REFDIR" \
525 "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
526 && git submodule init -- "$gnulib_path" \
527 && git submodule update -- "$gnulib_path" \
528 || exit $?
529 fi
530 fi
531 else
532 # GNULIB_REFDIR is not set or not usable. Ignore it.
533 if git_modules_config submodule.gnulib.url >/dev/null; then
534 echo "$0: getting gnulib files..."
535 git submodule init -- "$gnulib_path" || exit $?
536 git submodule update -- "$gnulib_path" || exit $?
537
538 elif [ ! -d "$gnulib_path" ]; then
539 echo "$0: getting gnulib files..."
540
541 trap cleanup_gnulib HUP INT PIPE TERM
542
543 shallow=
544 if test -z "$GNULIB_REVISION"; then
545 if git clone -h 2>&1 | grep -- --depth > /dev/null; then
546 shallow='--depth 2'
547 fi
548 git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
549 || cleanup_gnulib
550 else
551 if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
552 shallow='--depth 2'
553 fi
554 mkdir -p "$gnulib_path"
555 # Only want a shallow checkout of $GNULIB_REVISION, but git does not
556 # support cloning by commit hash. So attempt a shallow fetch by commit
557 # hash to minimize the amount of data downloaded and changes needed to
558 # be processed, which can drastically reduce download and processing
559 # time for checkout. If the fetch by commit fails, a shallow fetch can
560 # not be performed because we do not know what the depth of the commit
561 # is without fetching all commits. So fallback to fetching all commits.
562 git -C "$gnulib_path" init
563 git -C "$gnulib_path" remote add origin \
564 ${GNULIB_URL:-$default_gnulib_url}
565 git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
566 || git -C "$gnulib_path" fetch origin \
567 || cleanup_gnulib
568 git -C "$gnulib_path" reset --hard FETCH_HEAD
569 fi
570
571 trap - HUP INT PIPE TERM
572 fi
573 fi
574 GNULIB_SRCDIR=$gnulib_path
575 # Verify that the submodule contains a gnulib checkout.
576 test -f "$gnulib_path/gnulib-tool" \
577 || die "Error: $gnulib_path is supposed to contain a gnulib checkout, but does not contain gnulib-tool"
578 fi
579
580 # XXX Should this be done if $use_git is false?
581 if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \
582 && ! git_modules_config submodule.gnulib.url >/dev/null; then
583 (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib
584 fi
585
586 # $GNULIB_SRCDIR now points to the version of gnulib to use, and
587 # we no longer need to use git or $gnulib_path below here.
588}
589
590# -------- Upgrading bootstrap to the version found in GNULIB_SRCDIR. --------
591
592upgrade_bootstrap ()
593{
594 if test -f "$medir"/bootstrap-funclib.sh; then
595 update_lib=true
596 { cmp -s "$medir"/bootstrap "$GNULIB_SRCDIR/top/bootstrap" \
597 && cmp -s "$medir"/bootstrap-funclib.sh "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" \
598 && cmp -s "$medir"/autopull.sh "$GNULIB_SRCDIR/top/autopull.sh" \
599 && cmp -s "$medir"/autogen.sh "$GNULIB_SRCDIR/top/autogen.sh"; \
600 }
601 else
602 update_lib=false
603 cmp -s "$medir"/bootstrap "$GNULIB_SRCDIR/build-aux/bootstrap"
604 fi || {
605 if $update_lib; then
606 echo "$0: updating bootstrap & companions and restarting..."
607 else
608 echo "$0: updating bootstrap and restarting..."
609 fi
610 case $(sh -c 'echo "$1"' -- a) in
611 a) ignored=--;;
612 *) ignored=ignored;;
613 esac
614 exec sh -c \
615 '{ if '$update_lib' && test -f "$1"; then cp "$1" "$3"; else cp "$2" "$3"; fi; } && { if '$update_lib' && test -f "$4"; then cp "$4" "$5"; else rm -f "$5"; fi; } && { if '$update_lib' && test -f "$6"; then cp "$6" "$7"; else rm -f "$7"; fi; } && { if '$update_lib' && test -f "$8"; then cp "$8" "$9"; else rm -f "$9"; fi; } && shift && shift && shift && shift && shift && shift && shift && shift && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
616 $ignored \
617 "$GNULIB_SRCDIR/top/bootstrap" "$GNULIB_SRCDIR/build-aux/bootstrap" "$medir/bootstrap" \
618 "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" "$medir/bootstrap-funclib.sh" \
619 "$GNULIB_SRCDIR/top/autopull.sh" "$medir/autopull.sh" \
620 "$GNULIB_SRCDIR/top/autogen.sh" "$medir/autogen.sh" \
621 "$0" "$@" --no-bootstrap-sync
622 }
623}
624
625# ----------------------------------------------------------------------------
626
627if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then
628 use_gnulib=false
629else
630 use_gnulib=true
631fi
632
633# -------- Fetch auxiliary files from the network. --------------------------
634
635autopull_usage() {
636 cat <<EOF
637Usage: $me [OPTION]...
638Bootstrap this package from the checked-out sources.
639
640Optional environment variables:
641 GNULIB_SRCDIR Specifies the local directory where gnulib
642 sources reside. Use this if you already
643 have gnulib sources on your machine, and
644 you want to use these sources.
645 GNULIB_REFDIR Specifies the local directory where a gnulib
646 repository (with a .git subdirectory) resides.
647 Use this if you already have gnulib sources
648 and history on your machine, and do not want
649 to waste your bandwidth downloading them again.
650 GNULIB_URL Cloneable URL of the gnulib repository.
651
652Options:
653 --bootstrap-sync if this bootstrap script is not identical to
654 the version in the local gnulib sources,
655 update this script, and then restart it with
656 /bin/sh or the shell \$CONFIG_SHELL
657 --no-bootstrap-sync do not check whether bootstrap is out of sync
658 --force attempt to bootstrap even if the sources seem
659 not to have been checked out
660 --no-git do not use git to update gnulib. Requires that
661 \$GNULIB_SRCDIR or the --gnulib-srcdir option
662 points to a gnulib repository with the correct
663 revision
664 --skip-po do not download po files
665EOF
666 bootstrap_print_option_usage_hook
667 cat <<EOF
668If the file bootstrap.conf exists in the same directory as this script, its
669contents are read as shell variables to configure the bootstrap.
670
671For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
672are honored.
673
674Gnulib sources can be fetched in various ways:
675
676 * If the environment variable GNULIB_SRCDIR is set (either as an
677 environment variable or via the --gnulib-srcdir option), then sources
678 are fetched from that local directory. If it is a git repository and
679 the configuration variable GNULIB_REVISION is set in bootstrap.conf,
680 then that revision is checked out.
681
682 * Otherwise, if this package is in a git repository with a 'gnulib'
683 submodule configured, then that submodule is initialized and updated
684 and sources are fetched from there. If GNULIB_REFDIR is set (either
685 as an environment variable or via the --gnulib-refdir option) and is
686 a git repository, then it is used as a reference.
687
688 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
689 are cloned into that directory using git from \$GNULIB_URL, defaulting
690 to $default_gnulib_url.
691 If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
692 then that revision is checked out.
693
694 * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
695 used. If it is a git repository and the configuration variable
696 GNULIB_REVISION is set in bootstrap.conf, then that revision is
697 checked out.
698
699If you maintain a package and want to pin a particular revision of the
700Gnulib sources that has been tested with your package, then there are
701two possible approaches: either configure a 'gnulib' submodule with the
702appropriate revision, or set GNULIB_REVISION (and if necessary
703GNULIB_URL) in bootstrap.conf.
704
705Running without arguments will suffice in most cases.
706EOF
707}
708
709# Fetch auxiliary files that are omitted from the version control
710# repository of this package.
711autopull()
712{
713 # Ensure that CDPATH is not set. Otherwise, the output from cd
714 # would cause trouble in at least one use below.
715 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
716
717 # Parse options.
718
719 # Use git to update gnulib sources
720 use_git=true
721
722 for option
723 do
724 case $option in
725 --help)
726 autopull_usage
727 return;;
728 --version)
729 set -e
730 echo "autopull.sh $scriptlibversion"
731 echo "$copyright"
732 return 0
733 ;;
734 --skip-po)
735 SKIP_PO=t;;
736 --force)
737 checkout_only_file=;;
738 --bootstrap-sync)
739 bootstrap_sync=true;;
740 --no-bootstrap-sync)
741 bootstrap_sync=false;;
742 --no-git)
743 use_git=false;;
744 *)
745 bootstrap_option_hook $option || die "$option: unknown option";;
746 esac
747 done
748
749 $use_git || test -n "$GNULIB_SRCDIR" \
750 || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option"
751 test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
752 || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
753
754 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
755 die "Running this script from a non-checked-out distribution is risky."
756 fi
757
758 check_build_prerequisites $use_git
759
760 if $use_gnulib || $bootstrap_sync; then
761 prepare_GNULIB_SRCDIR
762 if $bootstrap_sync; then
763 upgrade_bootstrap
764 fi
765 fi
766
767 # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
768 # Also find the compatible sha1 utility on the BSDs
769 if test x"$SKIP_PO" = x; then
770 find_tool SHA1SUM sha1sum gsha1sum shasum sha1
771 fi
772
773 # See if we can use gnulib's git-merge-changelog merge driver.
774 if $use_git && test -d .git && check_exists git; then
775 if git config merge.merge-changelog.driver >/dev/null ; then
776 :
777 elif check_exists git-merge-changelog; then
778 echo "$0: initializing git-merge-changelog driver"
779 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
780 git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
781 else
782 echo "$0: consider installing git-merge-changelog from gnulib"
783 fi
784 fi
785
786 case $SKIP_PO in
787 '')
788 if test -d po; then
789 update_po_files po $package || return
790 fi
791
792 if test -d runtime-po; then
793 update_po_files runtime-po $package-runtime || return
794 fi;;
795 esac
796
797 # ---------------------------------------------------------------------------
798
799 bootstrap_post_pull_hook \
800 || die "bootstrap_post_pull_hook failed"
801
802 # Don't proceed if there are uninitialized submodules. In particular,
803 # autogen.sh will remove dangling links, which might be links into
804 # uninitialized submodules.
805 # But it's OK if the 'gnulib' submodule is uninitialized, as long as
806 # GNULIB_SRCDIR is set.
807 if $use_git; then
808 # Uninitialized submodules are listed with an initial dash.
809 uninitialized=`git submodule | grep '^-' | awk '{ print $2 }'`
810 if test -n "$GNULIB_SRCDIR"; then
811 uninitialized=`echo "$uninitialized" | grep -v '^gnulib$'`
812 fi
813 if test -n "$uninitialized"; then
814 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."
815 fi
816 fi
817
818 if test -f "$medir"/autogen.sh; then
819 echo "$0: done. Now you can run '$medir/autogen.sh'."
820 fi
821}
822
823# ----------------------------- Get translations. -----------------------------
824
825download_po_files() {
826 subdir=$1
827 domain=$2
828 echo "$me: getting translations into $subdir for $domain..."
829 cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
830 eval "$cmd"
831}
832
833# Mirror .po files to $po_dir/.reference and copy only the new
834# or modified ones into $po_dir. Also update $po_dir/LINGUAS.
835# Note po files that exist locally only are left in $po_dir but will
836# not be included in LINGUAS and hence will not be distributed.
837update_po_files() {
838 # Directory containing primary .po files.
839 # Overwrite them only when we're sure a .po file is new.
840 po_dir=$1
841 domain=$2
842
843 # Mirror *.po files into this dir.
844 # Usually contains *.s1 checksum files.
845 ref_po_dir="$po_dir/.reference"
846
847 test -d $ref_po_dir || mkdir $ref_po_dir || return
848 download_po_files $ref_po_dir $domain \
849 && ls "$ref_po_dir"/*.po 2>/dev/null |
850 sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
851
852 langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
853 test "$langs" = '*' && langs=x
854 for po in $langs; do
855 case $po in x) continue;; esac
856 new_po="$ref_po_dir/$po.po"
857 cksum_file="$ref_po_dir/$po.s1"
858 if ! test -f "$cksum_file" ||
859 ! test -f "$po_dir/$po.po" ||
860 ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
861 echo "$me: updated $po_dir/$po.po..."
862 cp "$new_po" "$po_dir/$po.po" \
863 && $SHA1SUM < "$new_po" > "$cksum_file" || return
864 fi
865 done
866}
867
868# -------- Generate files automatically from existing sources. --------------
869
870autogen_usage() {
871 cat <<EOF
872Usage: $me [OPTION]...
873Bootstrap this package from the checked-out sources.
874
875Optional environment variables:
876 GNULIB_SRCDIR Specifies the local directory where gnulib
877 sources reside. Use this if you already
878 have gnulib sources on your machine, and
879 you want to use these sources.
880
881Options:
882 --copy copy files instead of creating symbolic links
883 --force attempt to bootstrap even if the sources seem
884 not to have been checked out
885EOF
886 bootstrap_print_option_usage_hook
887 cat <<EOF
888If the file bootstrap.conf exists in the same directory as this script, its
889contents are read as shell variables to configure the bootstrap.
890
891For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
892are honored.
893
894Gnulib sources are assumed to be present:
895 * in \$GNULIB_SRCDIR, if that environment variable is set,
896 * otherwise, in the 'gnulib' submodule, if such a submodule is configured,
897 * otherwise, in the 'gnulib' subdirectory.
898
899Running without arguments will suffice in most cases.
900EOF
901}
902
903
904version_controlled_file() {
905 parent=$1
906 file=$2
907 if test -d .git; then
908 git rm -n "$file" > /dev/null 2>&1
909 elif test -d .svn; then
910 svn log -r HEAD "$file" > /dev/null 2>&1
911 elif test -d CVS; then
912 grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
913 grep '^/[^/]*/[0-9]' > /dev/null
914 else
915 warn_ "no version control for $file?"
916 false
917 fi
918}
919
920# Strip blank and comment lines to leave significant entries.
921gitignore_entries() {
922 sed '/^#/d; /^$/d' "$@"
923}
924
925# If $STR is not already on a line by itself in $FILE, insert it at the start.
926# Entries are inserted at the start of the ignore list to ensure existing
927# entries starting with ! are not overridden. Such entries support
928# whitelisting exceptions after a more generic blacklist pattern.
929insert_if_absent() {
930 file=$1
931 str=$2
932 test -f $file || touch $file
933 test -r $file || die "Error: failed to read ignore file: $file"
934 duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
935 if [ "$duplicate_entries" ] ; then
936 die "Error: Duplicate entries in $file: " $duplicate_entries
937 fi
938 linesold=$(gitignore_entries $file | wc -l)
939 linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
940 if [ $linesold != $linesnew ] ; then
941 { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
942 || die "insert_if_absent $file $str: failed"
943 fi
944}
945
946# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
947# insert_if_absent.
948insert_vc_ignore() {
949 vc_ignore_file="$1"
950 pattern="$2"
951 case $vc_ignore_file in
952 *.gitignore)
953 # A .gitignore entry that does not start with '/' applies
954 # recursively to subdirectories, so prepend '/' to every
955 # .gitignore entry.
956 pattern=$(echo "$pattern" | sed s,^,/,);;
957 esac
958 insert_if_absent "$vc_ignore_file" "$pattern"
959}
960
961symlink_to_dir()
962{
963 src=$1/$2
964 dst=${3-$2}
965
966 test -f "$src" && {
967
968 # If the destination directory doesn't exist, create it.
969 # This is required at least for "lib/uniwidth/cjk.h".
970 dst_dir=$(dirname "$dst")
971 if ! test -d "$dst_dir"; then
972 mkdir -p "$dst_dir"
973
974 # If we've just created a directory like lib/uniwidth,
975 # tell version control system(s) it's ignorable.
976 # FIXME: for now, this does only one level
977 parent=$(dirname "$dst_dir")
978 for dot_ig in x $vc_ignore; do
979 test $dot_ig = x && continue
980 ig=$parent/$dot_ig
8ccfc4e4 981 insert_vc_ignore $ig "${dst_dir##*/}/"
0f289d72
PE
982 done
983 fi
984
985 if $copy; then
986 {
987 test ! -h "$dst" || {
988 echo "$me: rm -f $dst" &&
989 rm -f "$dst"
990 }
991 } &&
992 test -f "$dst" &&
993 cmp -s "$src" "$dst" || {
994 echo "$me: cp -fp $src $dst" &&
995 cp -fp "$src" "$dst"
996 }
997 else
998 # Leave any existing symlink alone, if it already points to the source,
999 # so that broken build tools that care about symlink times
1000 # aren't confused into doing unnecessary builds. Conversely, if the
1001 # existing symlink's timestamp is older than the source, make it afresh,
1002 # so that broken tools aren't confused into skipping needed builds. See
1003 # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
1004 test -h "$dst" &&
1005 src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
1006 dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
1007 test "$src_i" = "$dst_i" &&
1008 both_ls=$(ls -dt "$src" "$dst") &&
1009 test "X$both_ls" = "X$dst$nl$src" || {
1010 dot_dots=
1011 case $src in
1012 /*) ;;
1013 *)
1014 case /$dst/ in
1015 *//* | */../* | */./* | /*/*/*/*/*/)
1016 die "invalid symlink calculation: $src -> $dst";;
1017 /*/*/*/*/) dot_dots=../../../;;
1018 /*/*/*/) dot_dots=../../;;
1019 /*/*/) dot_dots=../;;
1020 esac;;
1021 esac
1022
1023 echo "$me: ln -fs $dot_dots$src $dst" &&
1024 ln -fs "$dot_dots$src" "$dst"
1025 }
1026 fi
1027 }
1028}
1029
1030# Regenerate all autogeneratable files that are omitted from the
1031# version control repository. In particular, regenerate all
1032# aclocal.m4, config.h.in, Makefile.in, configure files with new
1033# versions of autoconf or automake.
1034autogen()
1035{
1036 # Ensure that CDPATH is not set. Otherwise, the output from cd
1037 # would cause trouble in at least one use below.
1038 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
1039
1040 # Environment variables that may be set by the user.
1041 : "${AUTOPOINT=autopoint}"
1042 : "${AUTORECONF=autoreconf}"
1043
1044 if test "$vc_ignore" = auto; then
1045 vc_ignore=
1046 test -d .git && vc_ignore=.gitignore
1047 test -d CVS && vc_ignore="$vc_ignore .cvsignore"
1048 fi
1049
1050
1051 # Parse options.
1052
1053 # Whether to use copies instead of symlinks.
1054 copy=false
1055
1056 for option
1057 do
1058 case $option in
1059 --help)
1060 autogen_usage
1061 return;;
1062 --version)
1063 set -e
1064 echo "autogen.sh $scriptlibversion"
1065 echo "$copyright"
1066 return 0
1067 ;;
1068 --force)
1069 checkout_only_file=;;
1070 --copy)
1071 copy=true;;
1072 *)
1073 bootstrap_option_hook $option || die "$option: unknown option";;
1074 esac
1075 done
1076
1077 test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
1078 || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
1079
1080 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
1081 die "Running this script from a non-checked-out distribution is risky."
1082 fi
1083
1084 if $use_gnulib; then
1085 if test -z "$GNULIB_SRCDIR"; then
1086 gnulib_path=$(test -f .gitmodules && git config --file .gitmodules submodule.gnulib.path)
1087 test -z "$gnulib_path" && gnulib_path=gnulib
1088 GNULIB_SRCDIR=$gnulib_path
1089 fi
1090 fi
1091
1092 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
1093 found_aux_dir=no
1094 grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'])' configure.ac \
1095 >/dev/null && found_aux_dir=yes
1096 grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
1097 >/dev/null && found_aux_dir=yes
1098 test $found_aux_dir = yes \
1099 || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
1100
1101 # If $build_aux doesn't exist, create it now, otherwise some bits
1102 # below will malfunction. If creating it, also mark it as ignored.
1103 if test ! -d $build_aux; then
1104 mkdir $build_aux
1105 for dot_ig in x $vc_ignore; do
1106 test $dot_ig = x && continue
8ccfc4e4 1107 insert_vc_ignore $dot_ig $build_aux/
0f289d72
PE
1108 done
1109 fi
1110
1111 check_build_prerequisites false
1112
1113 use_libtool=0
1114 # We'd like to use grep -E, to see if any of LT_INIT,
1115 # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
1116 # but that's not portable enough (e.g., for Solaris).
1117 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
1118 && use_libtool=1
1119 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
1120 && use_libtool=1
1121 if test $use_libtool = 1; then
1122 find_tool LIBTOOLIZE glibtoolize libtoolize
1123 fi
1124
1125 if $use_gnulib; then
1126 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
1127 <$gnulib_tool || return
1128 fi
1129
1130 # NOTE: we have to be careful to run both autopoint and libtoolize
1131 # before gnulib-tool, since gnulib-tool is likely to provide newer
1132 # versions of files "installed" by these two programs.
1133 # Then, *after* gnulib-tool (see below), we have to be careful to
1134 # run autoreconf in such a way that it does not run either of these
1135 # two just-pre-run programs.
1136
1137 # Import from gettext.
1138 with_gettext=yes
1139 grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
1140 with_gettext=no
1141
1142 if test $with_gettext = yes || test $use_libtool = 1; then
1143
1144 tempbase=.bootstrap$$
1145 trap "rm -f $tempbase.0 $tempbase.1" HUP INT PIPE TERM
1146
1147 > $tempbase.0 > $tempbase.1 &&
1148 find . ! -type d -print | sort > $tempbase.0 || return
1149
1150 if test $with_gettext = yes; then
1151 # Released autopoint has the tendency to install macros that have been
1152 # obsoleted in current gnulib, so run this before gnulib-tool.
1153 echo "$0: $AUTOPOINT --force"
1154 $AUTOPOINT --force || return
1155 fi
1156
1157 # Autoreconf runs aclocal before libtoolize, which causes spurious
1158 # warnings if the initial aclocal is confused by the libtoolized
1159 # (or worse out-of-date) macro directory.
1160 # libtoolize 1.9b added the --install option; but we support back
1161 # to libtoolize 1.5.22, where the install action was default.
1162 if test $use_libtool = 1; then
1163 install=
1164 case $($LIBTOOLIZE --help) in
1165 *--install*) install=--install ;;
1166 esac
1167 echo "running: $LIBTOOLIZE $install --copy"
1168 $LIBTOOLIZE $install --copy
1169 fi
1170
1171 find . ! -type d -print | sort >$tempbase.1
1172 old_IFS=$IFS
1173 IFS=$nl
1174 for file in $(comm -13 $tempbase.0 $tempbase.1); do
1175 IFS=$old_IFS
1176 parent=${file%/*}
1177 version_controlled_file "$parent" "$file" || {
1178 for dot_ig in x $vc_ignore; do
1179 test $dot_ig = x && continue
1180 ig=$parent/$dot_ig
1181 insert_vc_ignore "$ig" "${file##*/}"
1182 done
1183 }
1184 done
1185 IFS=$old_IFS
1186
1187 rm -f $tempbase.0 $tempbase.1
1188 trap - HUP INT PIPE TERM
1189 fi
1190
1191 # Import from gnulib.
1192
1193 if $use_gnulib; then
1194 gnulib_tool_options="\
1195 --no-changelog\
1196 --aux-dir=$build_aux\
1197 --doc-base=$doc_base\
1198 --lib=$gnulib_name\
1199 --m4-base=$m4_base/\
1200 --source-base=$source_base/\
1201 --tests-base=$tests_base\
1202 --local-dir=$local_gl_dir\
1203 $gnulib_tool_option_extras\
1204 "
1205 if test $use_libtool = 1; then
1206 case "$gnulib_tool_options " in
1207 *' --libtool '*) ;;
1208 *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
1209 esac
1210 fi
1211 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
1212 $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
1213 || die "gnulib-tool failed"
1214
1215 for file in $gnulib_files; do
1216 symlink_to_dir "$GNULIB_SRCDIR" $file \
1217 || die "failed to symlink $file"
1218 done
1219 fi
1220
1221 bootstrap_post_import_hook \
1222 || die "bootstrap_post_import_hook failed"
1223
1224 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
1225 # gnulib-populated directories. Such .m4 files would cause aclocal to fail.
1226 # The following requires GNU find 4.2.3 or newer. Considering the usual
1227 # portability constraints of this script, that may seem a very demanding
1228 # requirement, but it should be ok. Ignore any failure, which is fine,
1229 # since this is only a convenience to help developers avoid the relatively
1230 # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
1231 # between successive runs of this script.
1232 find "$m4_base" "$source_base" \
1233 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
1234 -type l -xtype l -delete > /dev/null 2>&1
1235
1236 # Invoke autoreconf with --force --install to ensure upgrades of tools
1237 # such as ylwrap.
1238 AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
8ccfc4e4 1239 AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive"
0f289d72
PE
1240
1241 # Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
1242 echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
1243 AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
1244 || die "autoreconf failed"
1245
1246 # Get some extra files from gnulib, overriding existing files.
1247 for file in $gnulib_extra_files; do
1248 case $file in
1249 */INSTALL) dst=INSTALL;;
1250 build-aux/*) dst=$build_aux/${file#build-aux/};;
1251 *) dst=$file;;
1252 esac
1253 symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
1254 || die "failed to symlink $file"
1255 done
1256
1257 if test $with_gettext = yes; then
1258 # Create gettext configuration.
1259 echo "$0: Creating po/Makevars from po/Makevars.template ..."
1260 rm -f po/Makevars
1261 sed '
1262 /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
1263 /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
1264 /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
1265 /^XGETTEXT_OPTIONS *=/{
1266 s/$/ \\/
1267 a\
1268 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
1269 }
1270 ' po/Makevars.template >po/Makevars \
1271 || die 'cannot generate po/Makevars'
1272
1273 # If the 'gettext' module is in use, grab the latest Makefile.in.in.
1274 # If only the 'gettext-h' module is in use, assume autopoint already
1275 # put the correct version of this file into place.
1276 case $gnulib_modules in
1277 *gettext-h*) ;;
1278 *gettext*)
1279 cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
1280 || die "cannot create po/Makefile.in.in"
1281 ;;
1282 esac
1283
1284 if test -d runtime-po; then
1285 # Similarly for runtime-po/Makevars, but not quite the same.
1286 rm -f runtime-po/Makevars
1287 sed '
1288 /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
1289 /^subdir *=.*/s/=.*/= runtime-po/
1290 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
1291 /^XGETTEXT_OPTIONS *=/{
1292 s/$/ \\/
1293 a\
1294 '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
1295 }
1296 ' po/Makevars.template >runtime-po/Makevars \
1297 || die 'cannot generate runtime-po/Makevars'
1298
1299 # Copy identical files from po to runtime-po.
1300 (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
1301 fi
1302 fi
1303
1304 bootstrap_epilogue
1305
1306 echo "$0: done. Now you can run './configure'."
1307}
1308
1309# ----------------------------------------------------------------------------
1310
1311# Local Variables:
1312# eval: (add-hook 'before-save-hook 'time-stamp)
1313# time-stamp-start: "scriptlibversion="
1314# time-stamp-format: "%:y-%02m-%02d.%02H"
1315# time-stamp-time-zone: "UTC0"
1316# time-stamp-end: "; # UTC"
1317# End:
1f73735b 1318
9771467d 1319usage() {
241b72ff 1320 cat <<EOF
6cb94e37 1321Usage: $me [OPTION]...
c930802f
PE
1322Bootstrap this package from the checked-out sources.
1323
5c4f8cad
PE
1324Optional environment variables:
1325 GNULIB_SRCDIR Specifies the local directory where gnulib
1326 sources reside. Use this if you already
1327 have gnulib sources on your machine, and
1328 do not want to waste your bandwidth downloading
1329 them again.
1330 GNULIB_URL Cloneable URL of the gnulib repository.
1331
c930802f 1332Options:
0f289d72
PE
1333
1334 --pull Do phase 1: pull files from network
1335 --gen Do phase 2: generate from local files.
1336 (The default is to do both phases.)
1337
5c4f8cad
PE
1338 --gnulib-srcdir=DIRNAME specify the local directory where gnulib
1339 sources reside. Use this if you already
1340 have gnulib sources on your machine, and
1341 you want to use these sources. Defaults
1342 to \$GNULIB_SRCDIR
1343 --gnulib-refdir=DIRNAME specify the local directory where a gnulib
1344 repository (with a .git subdirectory) resides.
1345 Use this if you already have gnulib sources
1346 and history on your machine, and do not want
1347 to waste your bandwidth downloading them again.
1348 Defaults to \$GNULIB_REFDIR
5c4f8cad
PE
1349
1350 --bootstrap-sync if this bootstrap script is not identical to
1351 the version in the local gnulib sources,
1352 update this script, and then restart it with
1353 /bin/sh or the shell \$CONFIG_SHELL
1354 --no-bootstrap-sync do not check whether bootstrap is out of sync
0f289d72 1355
5c4f8cad
PE
1356 --copy copy files instead of creating symbolic links
1357 --force attempt to bootstrap even if the sources seem
1358 not to have been checked out
1359 --no-git do not use git to update gnulib. Requires that
1360 \$GNULIB_SRCDIR or the --gnulib-srcdir option
1361 points to a gnulib repository with the correct
1362 revision
1363 --skip-po do not download po files
1f73735b
PE
1364EOF
1365 bootstrap_print_option_usage_hook
1366 cat <<EOF
5c4f8cad 1367If the file bootstrap.conf exists in the same directory as this script, its
c930802f
PE
1368contents are read as shell variables to configure the bootstrap.
1369
241b72ff
PE
1370For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
1371are honored.
1372
1f73735b
PE
1373Gnulib sources can be fetched in various ways:
1374
5c4f8cad
PE
1375 * If the environment variable GNULIB_SRCDIR is set (either as an
1376 environment variable or via the --gnulib-srcdir option), then sources
1377 are fetched from that local directory. If it is a git repository and
1378 the configuration variable GNULIB_REVISION is set in bootstrap.conf,
1379 then that revision is checked out.
1f73735b
PE
1380
1381 * Otherwise, if this package is in a git repository with a 'gnulib'
5c4f8cad
PE
1382 submodule configured, then that submodule is initialized and updated
1383 and sources are fetched from there. If GNULIB_REFDIR is set (either
1384 as an environment variable or via the --gnulib-refdir option) and is
1385 a git repository, then it is used as a reference.
1f73735b 1386
5c4f8cad
PE
1387 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
1388 are cloned into that directory using git from \$GNULIB_URL, defaulting
1389 to $default_gnulib_url.
1390 If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
1391 then that revision is checked out.
1f73735b
PE
1392
1393 * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
5c4f8cad
PE
1394 used. If it is a git repository and the configuration variable
1395 GNULIB_REVISION is set in bootstrap.conf, then that revision is
1396 checked out.
1f73735b
PE
1397
1398If you maintain a package and want to pin a particular revision of the
5c4f8cad
PE
1399Gnulib sources that has been tested with your package, then there are
1400two possible approaches: either configure a 'gnulib' submodule with the
1401appropriate revision, or set GNULIB_REVISION (and if necessary
1402GNULIB_URL) in bootstrap.conf.
1f73735b 1403
c930802f 1404Running without arguments will suffice in most cases.
241b72ff 1405EOF
9771467d 1406}
88ffc135 1407
5c4f8cad 1408# Parse options.
c930802f 1409
0f289d72
PE
1410# Whether to pull and generate.
1411pull=false
1412gen=false
1413
c930802f
PE
1414# Whether to use copies instead of symlinks.
1415copy=false
1416
6cb94e37
SP
1417# Use git to update gnulib sources
1418use_git=true
1419
54e32211
PE
1420for option
1421do
88ffc135
PE
1422 case $option in
1423 --help)
9771467d 1424 usage
88ffc135 1425 exit;;
1f73735b
PE
1426 --version)
1427 set -e
0f289d72 1428 echo "bootstrap $scriptversion lib $scriptlibversion"
1f73735b
PE
1429 echo "$copyright"
1430 exit 0
1431 ;;
0f289d72
PE
1432 --pull)
1433 pull=true;;
1434 --gen)
1435 gen=true;;
ac6caa71 1436 --gnulib-srcdir=*)
6cb94e37 1437 GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
5c4f8cad
PE
1438 --gnulib-refdir=*)
1439 GNULIB_REFDIR=${option#--gnulib-refdir=};;
ac6caa71
SP
1440 --skip-po)
1441 SKIP_PO=t;;
c930802f 1442 --force)
ac6caa71 1443 checkout_only_file=;;
c930802f
PE
1444 --copy)
1445 copy=true;;
6cb94e37
SP
1446 --bootstrap-sync)
1447 bootstrap_sync=true;;
1448 --no-bootstrap-sync)
0f289d72 1449 bootstrap_sync=false;;
6cb94e37
SP
1450 --no-git)
1451 use_git=false;;
88ffc135 1452 *)
1f73735b 1453 bootstrap_option_hook $option || die "$option: unknown option";;
88ffc135
PE
1454 esac
1455done
1456
0f289d72
PE
1457# Default is to do both.
1458$pull || $gen || pull=true gen=true
1459
5c4f8cad
PE
1460$use_git || test -n "$GNULIB_SRCDIR" \
1461 || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option"
1462test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
1463 || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
6cb94e37 1464
ac6caa71 1465if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
6cb94e37 1466 die "Bootstrapping from a non-checked-out distribution is risky."
c930802f 1467fi
94de7c4c 1468
5c4f8cad 1469check_build_prerequisites $use_git
241b72ff 1470
5c4f8cad
PE
1471if $bootstrap_sync; then
1472 prepare_GNULIB_SRCDIR
1473 upgrade_bootstrap
1474 # Since we have now upgraded if needed, no need to try it a second time below.
1475 bootstrap_sync=false
241b72ff
PE
1476fi
1477
ac6caa71
SP
1478echo "$0: Bootstrapping from checked-out $package sources..."
1479
0f289d72 1480# Pass GNULIB_SRCDIR and GNULIB_REFDIR to any subsidiary commands that care.
5c4f8cad 1481export GNULIB_SRCDIR
5c4f8cad 1482export GNULIB_REFDIR
c930802f 1483
0f289d72
PE
1484if $pull && { $use_git || test -z "$SKIP_PO"; }; then
1485 autopull \
5c4f8cad
PE
1486 `if $bootstrap_sync; then echo ' --bootstrap-sync'; else echo ' --no-bootstrap-sync'; fi` \
1487 `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
1488 `if ! $use_git; then echo ' --no-git'; fi` \
1489 `if test -n "$SKIP_PO"; then echo ' --skip-po'; fi` \
0f289d72 1490 || die "could not fetch auxiliary files"
c930802f 1491fi
ac6caa71 1492
0f289d72
PE
1493if $gen; then
1494 autogen \
5c4f8cad
PE
1495 `if $copy; then echo ' --copy'; fi` \
1496 `if test -z "$checkout_only_file"; then echo ' --force'; fi` \
0f289d72
PE
1497 || die "could not generate auxiliary files"
1498fi
241b72ff 1499
5c4f8cad 1500# ----------------------------------------------------------------------------
241b72ff 1501
5209d1df 1502# Local Variables:
1f73735b 1503# eval: (add-hook 'before-save-hook 'time-stamp)
241b72ff
PE
1504# time-stamp-start: "scriptversion="
1505# time-stamp-format: "%:y-%02m-%02d.%02H"
1f73735b 1506# time-stamp-time-zone: "UTC0"
241b72ff
PE
1507# time-stamp-end: "; # UTC"
1508# End: