Imported Upstream version 1.4.19
[platform/upstream/m4.git] / bootstrap
1 #! /bin/sh
2 ## DO NOT EDIT - This file generated from build-aux/bootstrap.in
3 ##               by inline-source v2019-02-19.15
4
5 # Bootstrap an Autotooled package from checked-out sources.
6 # Written by Gary V. Vaughan, 2010
7 # Inspired by a script written by Paul Eggert.
8
9 # This is free software.  There is NO warranty; not even for
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 #
12 # Copyright (C) 2010-2019 Bootstrap Authors
13 #
14 # This file is dual licensed under the terms of the MIT license
15 # <https://opensource.org/license/MIT>, and GPL version 2 or later
16 # <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
17 # these licenses when using or redistributing this software or any of
18 # the files within it.  See the URLs above, or the file `LICENSE`
19 # included in the Bootstrap distribution for the full license texts.
20
21 # You should place a copy of this script under version control in the
22 # top-level directory of your project.  The intent is that all
23 # customization can be done with a `bootstrap.conf` file also maintained
24 # in your version control.
25
26 # Please report bugs or propose patches to:
27 # <https://github.com/gnulib-modules/bootstrap/issues>
28
29
30 ## ------ ##
31 ## Usage. ##
32 ## ------ ##
33
34 # Most GNUish projects do not keep all of the generated Autotool
35 # files under version control, but running all of the right tools
36 # with the right arguments, in the correct order to regenerate
37 # all of those files in readiness for configuration and building
38 # can be surprisingly involved!  Many projects have a 'bootstrap'
39 # script under version control to invoke Autotools and perform
40 # other assorted book-keeping with version numbers and the like.
41 #
42 # This bootstrap script aims to probe the configure.ac and top
43 # Makefile.am of your project to automatically determine what
44 # the correct ordering and arguments are and then run the tools for
45 # you.  In order to use it, you can generate an initial standalone
46 # script with:
47 #
48 #   gl/build-aux/inline-source gl/build-aux/bootstrap.in > bootstrap
49 #
50 # You should then store than script in version control for other
51 # developers in you project.  It will give you instructions about
52 # how to keep it up to date if the sources change.
53 #
54 # See gl/doc/bootstrap.texi for documentation on how to write
55 # a bootstrap.conf to customize it for your project's
56 # idiosyncracies.
57
58
59 ## ================================================================== ##
60 ##                                                                    ##
61 ##     DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF     ##
62 ##                                                                    ##
63 ## ================================================================== ##
64
65 ## ------------------------------- ##
66 ## User overridable command paths. ##
67 ## ------------------------------- ##
68
69 # All uppercase denotes values stored in the environment.  These
70 # variables should generally be overridden by the user - however, we do
71 # set them to 'true' in some parts of this script to prevent them being
72 # called at the wrong time by other tools that we call ('autoreconf',
73 # for example).
74 #
75 # We also allow 'LIBTOOLIZE', 'M4', 'SHA1SUM' and some others to be
76 # overridden, and export the result for child processes, but they are
77 # handled by the function 'func_find_tool' and not defaulted in this
78 # section.
79
80 : ${ACLOCAL="aclocal"}
81 : ${AUTOCONF="autoconf"}
82 : ${AUTOHEADER="autoheader"}
83 : ${AUTOM4TE="autom4te"}
84 : ${AUTOHEADER="autoheader"}
85 : ${AUTOMAKE="automake"}
86 : ${AUTOPOINT="autopoint"}
87 : ${AUTORECONF="autoreconf"}
88 : ${CMP="cmp"}
89 : ${CONFIG_SHELL="/bin/sh"}
90 : ${DIFF="diff"}
91 : ${GIT="git"}
92 : ${LN_S="ln -s"}
93 : ${RM="rm"}
94
95 export ACLOCAL
96 export AUTOCONF
97 export AUTOHEADER
98 export AUTOM4TE
99 export AUTOHEADER
100 export AUTOMAKE
101 export AUTOPOINT
102 export AUTORECONF
103 export CONFIG_SHELL
104
105
106 ## -------------- ##
107 ## Configuration. ##
108 ## -------------- ##
109
110 # A newline delimited list of triples of programs (that respond to
111 # --version), the minimum version numbers required (or just '-' in the
112 # version field if any version will be sufficient) and homepage URLs
113 # to help locate missing packages.
114 buildreq=
115
116 # Name of a file containing instructions on installing missing packages
117 # required in 'buildreq'.
118 buildreq_readme=README-hacking
119
120 # These are extracted from AC_INIT in configure.ac, though you can
121 # override those values in 'bootstrap.conf' if you prefer.
122 build_aux=
123 macro_dir=
124 package=
125 package_name=
126 package_version=
127 package_bugreport=
128
129 # These are extracted from 'gnulib-cache.m4', or else fall-back
130 # automatically on the gnulib defaults; unless you set the values
131 # manually in 'bootstrap.conf'.
132 doc_base=
133 gnulib_mk=
134 gnulib_name=
135 local_gl_path=
136 source_base=
137 tests_base=
138
139 # The list of gnulib modules required at 'gnulib-tool' time.  If you
140 # check 'gnulib-cache.m4' into your repository, then this list will be
141 # extracted automatically.
142 gnulib_modules=
143
144 # Extra gnulib files that are not in modules, which override files of
145 # the same name installed by other bootstrap tools.
146 gnulib_non_module_files="
147         build-aux/compile
148         build-aux/install-sh
149         build-aux/mdate-sh
150         build-aux/texinfo.tex
151         build-aux/depcomp
152         build-aux/config.guess
153         build-aux/config.sub
154         doc/INSTALL
155 "
156
157 # Relative path to the local gnulib submodule, and url to the upstream
158 # git repository. If you have a gnulib entry in your .gitmodules file,
159 # these values are ignored.
160 gnulib_path=
161 gnulib_url=
162
163 # Date from which to clone github, to avoid a full clone.
164 gnulib_clone_since=
165
166 # Additional gnulib-tool options to use.
167 gnulib_tool_options="
168         --no-changelog
169 "
170
171 # bootstrap removes any macro-files that are not included by aclocal.m4,
172 # except for files listed in this variable that are always kept.
173 gnulib_precious="
174         gnulib-tool.m4
175 "
176
177 # When truncating long commands for display, always allow at least this
178 # many characters before truncating.
179 min_cmd_len=160
180
181 # The command to download all .po files for a specified domain into
182 # a specified directory.  Fill in the first %s is the domain name, and
183 # the second with the destination directory.  Use rsync's -L and -r
184 # options because the latest/%s directory and the .po files within are
185 # all symlinks.
186 po_download_command_format=\
187 "rsync --delete --exclude '*.s1' -Lrtvz \
188 'translationproject.org::tp/latest/%s/' '%s'"
189
190 # Other locale categories that need message catalogs.
191 extra_locale_categories=
192
193 # Additional xgettext options to use.  Gnulib might provide you with an
194 # extensive list of additional options to append to this, but gettext
195 # 0.16.1 and newer appends them automaticaly, so you can safely ignore
196 # the complaints from 'gnulib-tool' if your $configure_ac states:
197 #
198 #    AM_GNU_GETTEXT_VERSION([0.16.1])
199 xgettext_options="
200         --flag=_:1:pass-c-format
201         --flag=N_:1:pass-c-format
202 "
203
204 # Package copyright holder for gettext files.  Defaults to FSF if unset.
205 copyright_holder=
206
207 # File that should exist in the top directory of a checked out hierarchy,
208 # but not in a distribution tarball.
209 checkout_only_file=
210
211 # Whether to use copies instead of symlinks by default (if set to true,
212 # the --copy option has no effect).
213 copy=false
214
215 # Set this to ".cvsignore .gitignore" in 'bootstrap.conf' if you want
216 # those files to be generated in directories like 'lib/', 'm4/', and 'po/',
217 # or set it to "auto" to make this script select what to use based
218 # on what version control system (if any) is used in the source directory.
219 # Or set it to "none" to ignore VCS ignore files entirely.  Default is
220 # "auto".
221 vc_ignore=
222
223
224 ## ------------------- ##
225 ## External Libraries. ##
226 ## ------------------- ##
227
228 # Source required external libraries:
229 # Set a version string for this script.
230 scriptversion=2019-02-19.15; # UTC
231
232 # General shell script boiler plate, and helper functions.
233 # Written by Gary V. Vaughan, 2004
234
235 # This is free software.  There is NO warranty; not even for
236 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
237 #
238 # Copyright (C) 2004-2019 Bootstrap Authors
239 #
240 # This file is dual licensed under the terms of the MIT license
241 # <https://opensource.org/license/MIT>, and GPL version 2 or later
242 # <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
243 # these licenses when using or redistributing this software or any of
244 # the files within it.  See the URLs above, or the file `LICENSE`
245 # included in the Bootstrap distribution for the full license texts.
246
247 # Please report bugs or propose patches to:
248 # <https://github.com/gnulib-modules/bootstrap/issues>
249
250
251 ## ------ ##
252 ## Usage. ##
253 ## ------ ##
254
255 # Evaluate this file near the top of your script to gain access to
256 # the functions and variables defined here:
257 #
258 #   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
259 #
260 # If you need to override any of the default environment variable
261 # settings, do that before evaluating this file.
262
263
264 ## -------------------- ##
265 ## Shell normalisation. ##
266 ## -------------------- ##
267
268 # Some shells need a little help to be as Bourne compatible as possible.
269 # Before doing anything else, make sure all that help has been provided!
270
271 DUALCASE=1; export DUALCASE # for MKS sh
272 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
273   emulate sh
274   NULLCMD=:
275   # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
276   # is contrary to our usage.  Disable this feature.
277   alias -g '${1+"$@"}'='"$@"'
278   setopt NO_GLOB_SUBST
279 else
280   case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
281 fi
282
283 # NLS nuisances: We save the old values in case they are required later.
284 _G_user_locale=
285 _G_safe_locale=
286 for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
287 do
288   eval "if test set = \"\${$_G_var+set}\"; then
289           save_$_G_var=\$$_G_var
290           $_G_var=C
291           export $_G_var
292           _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
293           _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
294         fi"
295 done
296
297 # Make sure IFS has a sensible default
298 sp=' '
299 nl='
300 '
301 IFS="$sp        $nl"
302
303 # There are apparently some retarded systems that use ';' as a PATH separator!
304 if test "${PATH_SEPARATOR+set}" != set; then
305   PATH_SEPARATOR=:
306   (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
307     (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
308       PATH_SEPARATOR=';'
309   }
310 fi
311
312
313 # func_unset VAR
314 # --------------
315 # Portably unset VAR.
316 # In some shells, an 'unset VAR' statement leaves a non-zero return
317 # status if VAR is already unset, which might be problematic if the
318 # statement is used at the end of a function (thus poisoning its return
319 # value) or when 'set -e' is active (causing even a spurious abort of
320 # the script in this case).
321 func_unset ()
322 {
323     { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
324 }
325
326
327 # Make sure CDPATH doesn't cause `cd` commands to output the target dir.
328 func_unset CDPATH
329
330 # Make sure ${,E,F}GREP behave sanely.
331 func_unset GREP_OPTIONS
332
333
334 ## ------------------------- ##
335 ## Locate command utilities. ##
336 ## ------------------------- ##
337
338
339 # func_executable_p FILE
340 # ----------------------
341 # Check that FILE is an executable regular file.
342 func_executable_p ()
343 {
344     test -f "$1" && test -x "$1"
345 }
346
347
348 # func_path_progs PROGS_LIST CHECK_FUNC [PATH]
349 # --------------------------------------------
350 # Search for either a program that responds to --version with output
351 # containing "GNU", or else returned by CHECK_FUNC otherwise, by
352 # trying all the directories in PATH with each of the elements of
353 # PROGS_LIST.
354 #
355 # CHECK_FUNC should accept the path to a candidate program, and
356 # set $func_check_prog_result if it truncates its output less than
357 # $_G_path_prog_max characters.
358 func_path_progs ()
359 {
360     _G_progs_list=$1
361     _G_check_func=$2
362     _G_PATH=${3-"$PATH"}
363
364     _G_path_prog_max=0
365     _G_path_prog_found=false
366     _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
367     for _G_dir in $_G_PATH; do
368       IFS=$_G_save_IFS
369       test -z "$_G_dir" && _G_dir=.
370       for _G_prog_name in $_G_progs_list; do
371         for _exeext in '' .EXE; do
372           _G_path_prog=$_G_dir/$_G_prog_name$_exeext
373           func_executable_p "$_G_path_prog" || continue
374           case `"$_G_path_prog" --version 2>&1` in
375             *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
376             *)     $_G_check_func $_G_path_prog
377                    func_path_progs_result=$func_check_prog_result
378                    ;;
379           esac
380           $_G_path_prog_found && break 3
381         done
382       done
383     done
384     IFS=$_G_save_IFS
385     test -z "$func_path_progs_result" && {
386       echo "no acceptable sed could be found in \$PATH" >&2
387       exit 1
388     }
389 }
390
391
392 # We want to be able to use the functions in this file before configure
393 # has figured out where the best binaries are kept, which means we have
394 # to search for them ourselves - except when the results are already set
395 # where we skip the searches.
396
397 # Unless the user overrides by setting SED, search the path for either GNU
398 # sed, or the sed that truncates its output the least.
399 test -z "$SED" && {
400   _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
401   for _G_i in 1 2 3 4 5 6 7; do
402     _G_sed_script=$_G_sed_script$nl$_G_sed_script
403   done
404   echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
405   _G_sed_script=
406
407   func_check_prog_sed ()
408   {
409     _G_path_prog=$1
410
411     _G_count=0
412     printf 0123456789 >conftest.in
413     while :
414     do
415       cat conftest.in conftest.in >conftest.tmp
416       mv conftest.tmp conftest.in
417       cp conftest.in conftest.nl
418       echo '' >> conftest.nl
419       "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
420       diff conftest.out conftest.nl >/dev/null 2>&1 || break
421       _G_count=`expr $_G_count + 1`
422       if test "$_G_count" -gt "$_G_path_prog_max"; then
423         # Best one so far, save it but keep looking for a better one
424         func_check_prog_result=$_G_path_prog
425         _G_path_prog_max=$_G_count
426       fi
427       # 10*(2^10) chars as input seems more than enough
428       test 10 -lt "$_G_count" && break
429     done
430     rm -f conftest.in conftest.tmp conftest.nl conftest.out
431   }
432
433   func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
434   rm -f conftest.sed
435   SED=$func_path_progs_result
436 }
437
438
439 # Unless the user overrides by setting GREP, search the path for either GNU
440 # grep, or the grep that truncates its output the least.
441 test -z "$GREP" && {
442   func_check_prog_grep ()
443   {
444     _G_path_prog=$1
445
446     _G_count=0
447     _G_path_prog_max=0
448     printf 0123456789 >conftest.in
449     while :
450     do
451       cat conftest.in conftest.in >conftest.tmp
452       mv conftest.tmp conftest.in
453       cp conftest.in conftest.nl
454       echo 'GREP' >> conftest.nl
455       "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
456       diff conftest.out conftest.nl >/dev/null 2>&1 || break
457       _G_count=`expr $_G_count + 1`
458       if test "$_G_count" -gt "$_G_path_prog_max"; then
459         # Best one so far, save it but keep looking for a better one
460         func_check_prog_result=$_G_path_prog
461         _G_path_prog_max=$_G_count
462       fi
463       # 10*(2^10) chars as input seems more than enough
464       test 10 -lt "$_G_count" && break
465     done
466     rm -f conftest.in conftest.tmp conftest.nl conftest.out
467   }
468
469   func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
470   GREP=$func_path_progs_result
471 }
472
473
474 ## ------------------------------- ##
475 ## User overridable command paths. ##
476 ## ------------------------------- ##
477
478 # All uppercase variable names are used for environment variables.  These
479 # variables can be overridden by the user before calling a script that
480 # uses them if a suitable command of that name is not already available
481 # in the command search PATH.
482
483 : ${CP="cp -f"}
484 : ${ECHO="printf %s\n"}
485 : ${EGREP="$GREP -E"}
486 : ${FGREP="$GREP -F"}
487 : ${LN_S="ln -s"}
488 : ${MAKE="make"}
489 : ${MKDIR="mkdir"}
490 : ${MV="mv -f"}
491 : ${RM="rm -f"}
492 : ${SHELL="${CONFIG_SHELL-/bin/sh}"}
493
494
495 ## -------------------- ##
496 ## Useful sed snippets. ##
497 ## -------------------- ##
498
499 sed_dirname='s|/[^/]*$||'
500 sed_basename='s|^.*/||'
501
502 # Sed substitution that helps us do robust quoting.  It backslashifies
503 # metacharacters that are still active within double-quoted strings.
504 sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
505
506 # Same as above, but do not quote variable references.
507 sed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
508
509 # Sed substitution that turns a string into a regex matching for the
510 # string literally.
511 sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
512
513 # Sed substitution that converts a w32 file name or path
514 # that contains forward slashes, into one that contains
515 # (escaped) backslashes.  A very naive implementation.
516 sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
517
518 # Re-'\' parameter expansions in output of sed_double_quote_subst that
519 # were '\'-ed in input to the same.  If an odd number of '\' preceded a
520 # '$' in input to sed_double_quote_subst, that '$' was protected from
521 # expansion.  Since each input '\' is now two '\'s, look for any number
522 # of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
523 _G_bs='\\'
524 _G_bs2='\\\\'
525 _G_bs4='\\\\\\\\'
526 _G_dollar='\$'
527 sed_double_backslash="\
528   s/$_G_bs4/&\\
529 /g
530   s/^$_G_bs2$_G_dollar/$_G_bs&/
531   s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
532   s/\n//g"
533
534
535 ## ----------------- ##
536 ## Global variables. ##
537 ## ----------------- ##
538
539 # Except for the global variables explicitly listed below, the following
540 # functions in the '^func_' namespace, and the '^require_' namespace
541 # variables initialised in the 'Resource management' section, sourcing
542 # this file will not pollute your global namespace with anything
543 # else. There's no portable way to scope variables in Bourne shell
544 # though, so actually running these functions will sometimes place
545 # results into a variable named after the function, and often use
546 # temporary variables in the '^_G_' namespace. If you are careful to
547 # avoid using those namespaces casually in your sourcing script, things
548 # should continue to work as you expect. And, of course, you can freely
549 # overwrite any of the functions or variables defined here before
550 # calling anything to customize them.
551
552 EXIT_SUCCESS=0
553 EXIT_FAILURE=1
554 EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
555 EXIT_SKIP=77      # $? = 77 is used to indicate a skipped test to automake.
556
557 # Allow overriding, eg assuming that you follow the convention of
558 # putting '$debug_cmd' at the start of all your functions, you can get
559 # bash to show function call trace with:
560 #
561 #    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
562 debug_cmd=${debug_cmd-":"}
563 exit_cmd=:
564
565 # By convention, finish your script with:
566 #
567 #    exit $exit_status
568 #
569 # so that you can set exit_status to non-zero if you want to indicate
570 # something went wrong during execution without actually bailing out at
571 # the point of failure.
572 exit_status=$EXIT_SUCCESS
573
574 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
575 # is ksh but when the shell is invoked as "sh" and the current value of
576 # the _XPG environment variable is not equal to 1 (one), the special
577 # positional parameter $0, within a function call, is the name of the
578 # function.
579 progpath=$0
580
581 # The name of this program.
582 progname=`$ECHO "$progpath" |$SED "$sed_basename"`
583
584 # Make sure we have an absolute progpath for reexecution:
585 case $progpath in
586   [\\/]*|[A-Za-z]:\\*) ;;
587   *[\\/]*)
588      progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
589      progdir=`cd "$progdir" && pwd`
590      progpath=$progdir/$progname
591      ;;
592   *)
593      _G_IFS=$IFS
594      IFS=${PATH_SEPARATOR-:}
595      for progdir in $PATH; do
596        IFS=$_G_IFS
597        test -x "$progdir/$progname" && break
598      done
599      IFS=$_G_IFS
600      test -n "$progdir" || progdir=`pwd`
601      progpath=$progdir/$progname
602      ;;
603 esac
604
605
606 ## ----------------- ##
607 ## Standard options. ##
608 ## ----------------- ##
609
610 # The following options affect the operation of the functions defined
611 # below, and should be set appropriately depending on run-time para-
612 # meters passed on the command line.
613
614 opt_dry_run=false
615 opt_quiet=false
616 opt_verbose=false
617
618 # Categories 'all' and 'none' are always available.  Append any others
619 # you will pass as the first argument to func_warning from your own
620 # code.
621 warning_categories=
622
623 # By default, display warnings according to 'opt_warning_types'.  Set
624 # 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
625 # treat the next displayed warning as a fatal error.
626 warning_func=func_warn_and_continue
627
628 # Set to 'all' to display all warnings, 'none' to suppress all
629 # warnings, or a space delimited list of some subset of
630 # 'warning_categories' to display only the listed warnings.
631 opt_warning_types=all
632
633
634 ## -------------------- ##
635 ## Resource management. ##
636 ## -------------------- ##
637
638 # This section contains definitions for functions that each ensure a
639 # particular resource (a file, or a non-empty configuration variable for
640 # example) is available, and if appropriate to extract default values
641 # from pertinent package files. Call them using their associated
642 # 'require_*' variable to ensure that they are executed, at most, once.
643 #
644 # It's entirely deliberate that calling these functions can set
645 # variables that don't obey the namespace limitations obeyed by the rest
646 # of this file, in order that that they be as useful as possible to
647 # callers.
648
649
650 # require_term_colors
651 # -------------------
652 # Allow display of bold text on terminals that support it.
653 require_term_colors=func_require_term_colors
654 func_require_term_colors ()
655 {
656     $debug_cmd
657
658     test -t 1 && {
659       # COLORTERM and USE_ANSI_COLORS environment variables take
660       # precedence, because most terminfo databases neglect to describe
661       # whether color sequences are supported.
662       test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
663
664       if test 1 = "$USE_ANSI_COLORS"; then
665         # Standard ANSI escape sequences
666         tc_reset='\e[0m'
667         tc_bold='\e[1m';   tc_standout='\e[7m'
668         tc_red='\e[31m';   tc_green='\e[32m'
669         tc_blue='\e[34m';  tc_cyan='\e[36m'
670       else
671         # Otherwise trust the terminfo database after all.
672         test -n "`tput sgr0 2>/dev/null`" && {
673           tc_reset=`tput sgr0`
674           test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
675           tc_standout=$tc_bold
676           test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
677           test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
678           test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
679           test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
680           test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
681         }
682       fi
683     }
684
685     require_term_colors=:
686 }
687
688
689 ## ----------------- ##
690 ## Function library. ##
691 ## ----------------- ##
692
693 # This section contains a variety of useful functions to call in your
694 # scripts. Take note of the portable wrappers for features provided by
695 # some modern shells, which will fall back to slower equivalents on
696 # less featureful shells.
697
698
699 # func_append VAR VALUE
700 # ---------------------
701 # Append VALUE onto the existing contents of VAR.
702
703   # We should try to minimise forks, especially on Windows where they are
704   # unreasonably slow, so skip the feature probes when bash or zsh are
705   # being used:
706   if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
707     : ${_G_HAVE_ARITH_OP="yes"}
708     : ${_G_HAVE_XSI_OPS="yes"}
709     # The += operator was introduced in bash 3.1
710     case $BASH_VERSION in
711       [12].* | 3.0 | 3.0*) ;;
712       *)
713         : ${_G_HAVE_PLUSEQ_OP="yes"}
714         ;;
715     esac
716   fi
717
718   # _G_HAVE_PLUSEQ_OP
719   # Can be empty, in which case the shell is probed, "yes" if += is
720   # useable or anything else if it does not work.
721   test -z "$_G_HAVE_PLUSEQ_OP" \
722     && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
723     && _G_HAVE_PLUSEQ_OP=yes
724
725 if test yes = "$_G_HAVE_PLUSEQ_OP"
726 then
727   # This is an XSI compatible shell, allowing a faster implementation...
728   eval 'func_append ()
729   {
730     $debug_cmd
731
732     eval "$1+=\$2"
733   }'
734 else
735   # ...otherwise fall back to using expr, which is often a shell builtin.
736   func_append ()
737   {
738     $debug_cmd
739
740     eval "$1=\$$1\$2"
741   }
742 fi
743
744
745 # func_append_quoted VAR VALUE
746 # ----------------------------
747 # Quote VALUE and append to the end of shell variable VAR, separated
748 # by a space.
749 if test yes = "$_G_HAVE_PLUSEQ_OP"; then
750   eval 'func_append_quoted ()
751   {
752     $debug_cmd
753
754     func_quote_arg pretty "$2"
755     eval "$1+=\\ \$func_quote_arg_result"
756   }'
757 else
758   func_append_quoted ()
759   {
760     $debug_cmd
761
762     func_quote_arg pretty "$2"
763     eval "$1=\$$1\\ \$func_quote_arg_result"
764   }
765 fi
766
767
768 # func_append_uniq VAR VALUE
769 # --------------------------
770 # Append unique VALUE onto the existing contents of VAR, assuming
771 # entries are delimited by the first character of VALUE.  For example:
772 #
773 #   func_append_uniq options " --another-option option-argument"
774 #
775 # will only append to $options if " --another-option option-argument "
776 # is not already present somewhere in $options already (note spaces at
777 # each end implied by leading space in second argument).
778 func_append_uniq ()
779 {
780     $debug_cmd
781
782     eval _G_current_value='`$ECHO $'$1'`'
783     _G_delim=`expr "$2" : '\(.\)'`
784
785     case $_G_delim$_G_current_value$_G_delim in
786       *"$2$_G_delim"*) ;;
787       *) func_append "$@" ;;
788     esac
789 }
790
791
792 # func_arith TERM...
793 # ------------------
794 # Set func_arith_result to the result of evaluating TERMs.
795   test -z "$_G_HAVE_ARITH_OP" \
796     && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
797     && _G_HAVE_ARITH_OP=yes
798
799 if test yes = "$_G_HAVE_ARITH_OP"; then
800   eval 'func_arith ()
801   {
802     $debug_cmd
803
804     func_arith_result=$(( $* ))
805   }'
806 else
807   func_arith ()
808   {
809     $debug_cmd
810
811     func_arith_result=`expr "$@"`
812   }
813 fi
814
815
816 # func_basename FILE
817 # ------------------
818 # Set func_basename_result to FILE with everything up to and including
819 # the last / stripped.
820 if test yes = "$_G_HAVE_XSI_OPS"; then
821   # If this shell supports suffix pattern removal, then use it to avoid
822   # forking. Hide the definitions single quotes in case the shell chokes
823   # on unsupported syntax...
824   _b='func_basename_result=${1##*/}'
825   _d='case $1 in
826         */*) func_dirname_result=${1%/*}$2 ;;
827         *  ) func_dirname_result=$3        ;;
828       esac'
829
830 else
831   # ...otherwise fall back to using sed.
832   _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
833   _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
834       if test "X$func_dirname_result" = "X$1"; then
835         func_dirname_result=$3
836       else
837         func_append func_dirname_result "$2"
838       fi'
839 fi
840
841 eval 'func_basename ()
842 {
843     $debug_cmd
844
845     '"$_b"'
846 }'
847
848
849 # func_dirname FILE APPEND NONDIR_REPLACEMENT
850 # -------------------------------------------
851 # Compute the dirname of FILE.  If nonempty, add APPEND to the result,
852 # otherwise set result to NONDIR_REPLACEMENT.
853 eval 'func_dirname ()
854 {
855     $debug_cmd
856
857     '"$_d"'
858 }'
859
860
861 # func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
862 # --------------------------------------------------------
863 # Perform func_basename and func_dirname in a single function
864 # call:
865 #   dirname:  Compute the dirname of FILE.  If nonempty,
866 #             add APPEND to the result, otherwise set result
867 #             to NONDIR_REPLACEMENT.
868 #             value returned in "$func_dirname_result"
869 #   basename: Compute filename of FILE.
870 #             value retuned in "$func_basename_result"
871 # For efficiency, we do not delegate to the functions above but instead
872 # duplicate the functionality here.
873 eval 'func_dirname_and_basename ()
874 {
875     $debug_cmd
876
877     '"$_b"'
878     '"$_d"'
879 }'
880
881
882 # func_echo ARG...
883 # ----------------
884 # Echo program name prefixed message.
885 func_echo ()
886 {
887     $debug_cmd
888
889     _G_message=$*
890
891     func_echo_IFS=$IFS
892     IFS=$nl
893     for _G_line in $_G_message; do
894       IFS=$func_echo_IFS
895       $ECHO "$progname: $_G_line"
896     done
897     IFS=$func_echo_IFS
898 }
899
900
901 # func_echo_all ARG...
902 # --------------------
903 # Invoke $ECHO with all args, space-separated.
904 func_echo_all ()
905 {
906     $ECHO "$*"
907 }
908
909
910 # func_echo_infix_1 INFIX ARG...
911 # ------------------------------
912 # Echo program name, followed by INFIX on the first line, with any
913 # additional lines not showing INFIX.
914 func_echo_infix_1 ()
915 {
916     $debug_cmd
917
918     $require_term_colors
919
920     _G_infix=$1; shift
921     _G_indent=$_G_infix
922     _G_prefix="$progname: $_G_infix: "
923     _G_message=$*
924
925     # Strip color escape sequences before counting printable length
926     for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
927     do
928       test -n "$_G_tc" && {
929         _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
930         _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
931       }
932     done
933     _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
934
935     func_echo_infix_1_IFS=$IFS
936     IFS=$nl
937     for _G_line in $_G_message; do
938       IFS=$func_echo_infix_1_IFS
939       $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
940       _G_prefix=$_G_indent
941     done
942     IFS=$func_echo_infix_1_IFS
943 }
944
945
946 # func_error ARG...
947 # -----------------
948 # Echo program name prefixed message to standard error.
949 func_error ()
950 {
951     $debug_cmd
952
953     $require_term_colors
954
955     func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
956 }
957
958
959 # func_fatal_error ARG...
960 # -----------------------
961 # Echo program name prefixed message to standard error, and exit.
962 func_fatal_error ()
963 {
964     $debug_cmd
965
966     func_error "$*"
967     exit $EXIT_FAILURE
968 }
969
970
971 # func_grep EXPRESSION FILENAME
972 # -----------------------------
973 # Check whether EXPRESSION matches any line of FILENAME, without output.
974 func_grep ()
975 {
976     $debug_cmd
977
978     $GREP "$1" "$2" >/dev/null 2>&1
979 }
980
981
982 # func_len STRING
983 # ---------------
984 # Set func_len_result to the length of STRING. STRING may not
985 # start with a hyphen.
986   test -z "$_G_HAVE_XSI_OPS" \
987     && (eval 'x=a/b/c;
988       test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
989     && _G_HAVE_XSI_OPS=yes
990
991 if test yes = "$_G_HAVE_XSI_OPS"; then
992   eval 'func_len ()
993   {
994     $debug_cmd
995
996     func_len_result=${#1}
997   }'
998 else
999   func_len ()
1000   {
1001     $debug_cmd
1002
1003     func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
1004   }
1005 fi
1006
1007
1008 # func_mkdir_p DIRECTORY-PATH
1009 # ---------------------------
1010 # Make sure the entire path to DIRECTORY-PATH is available.
1011 func_mkdir_p ()
1012 {
1013     $debug_cmd
1014
1015     _G_directory_path=$1
1016     _G_dir_list=
1017
1018     if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
1019
1020       # Protect directory names starting with '-'
1021       case $_G_directory_path in
1022         -*) _G_directory_path=./$_G_directory_path ;;
1023       esac
1024
1025       # While some portion of DIR does not yet exist...
1026       while test ! -d "$_G_directory_path"; do
1027         # ...make a list in topmost first order.  Use a colon delimited
1028         # list incase some portion of path contains whitespace.
1029         _G_dir_list=$_G_directory_path:$_G_dir_list
1030
1031         # If the last portion added has no slash in it, the list is done
1032         case $_G_directory_path in */*) ;; *) break ;; esac
1033
1034         # ...otherwise throw away the child directory and loop
1035         _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
1036       done
1037       _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
1038
1039       func_mkdir_p_IFS=$IFS; IFS=:
1040       for _G_dir in $_G_dir_list; do
1041         IFS=$func_mkdir_p_IFS
1042         # mkdir can fail with a 'File exist' error if two processes
1043         # try to create one of the directories concurrently.  Don't
1044         # stop in that case!
1045         $MKDIR "$_G_dir" 2>/dev/null || :
1046       done
1047       IFS=$func_mkdir_p_IFS
1048
1049       # Bail out if we (or some other process) failed to create a directory.
1050       test -d "$_G_directory_path" || \
1051         func_fatal_error "Failed to create '$1'"
1052     fi
1053 }
1054
1055
1056 # func_mktempdir [BASENAME]
1057 # -------------------------
1058 # Make a temporary directory that won't clash with other running
1059 # libtool processes, and avoids race conditions if possible.  If
1060 # given, BASENAME is the basename for that directory.
1061 func_mktempdir ()
1062 {
1063     $debug_cmd
1064
1065     _G_template=${TMPDIR-/tmp}/${1-$progname}
1066
1067     if test : = "$opt_dry_run"; then
1068       # Return a directory name, but don't create it in dry-run mode
1069       _G_tmpdir=$_G_template-$$
1070     else
1071
1072       # If mktemp works, use that first and foremost
1073       _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
1074
1075       if test ! -d "$_G_tmpdir"; then
1076         # Failing that, at least try and use $RANDOM to avoid a race
1077         _G_tmpdir=$_G_template-${RANDOM-0}$$
1078
1079         func_mktempdir_umask=`umask`
1080         umask 0077
1081         $MKDIR "$_G_tmpdir"
1082         umask $func_mktempdir_umask
1083       fi
1084
1085       # If we're not in dry-run mode, bomb out on failure
1086       test -d "$_G_tmpdir" || \
1087         func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
1088     fi
1089
1090     $ECHO "$_G_tmpdir"
1091 }
1092
1093
1094 # func_normal_abspath PATH
1095 # ------------------------
1096 # Remove doubled-up and trailing slashes, "." path components,
1097 # and cancel out any ".." path components in PATH after making
1098 # it an absolute path.
1099 func_normal_abspath ()
1100 {
1101     $debug_cmd
1102
1103     # These SED scripts presuppose an absolute path with a trailing slash.
1104     _G_pathcar='s|^/\([^/]*\).*$|\1|'
1105     _G_pathcdr='s|^/[^/]*||'
1106     _G_removedotparts=':dotsl
1107                 s|/\./|/|g
1108                 t dotsl
1109                 s|/\.$|/|'
1110     _G_collapseslashes='s|/\{1,\}|/|g'
1111     _G_finalslash='s|/*$|/|'
1112
1113     # Start from root dir and reassemble the path.
1114     func_normal_abspath_result=
1115     func_normal_abspath_tpath=$1
1116     func_normal_abspath_altnamespace=
1117     case $func_normal_abspath_tpath in
1118       "")
1119         # Empty path, that just means $cwd.
1120         func_stripname '' '/' "`pwd`"
1121         func_normal_abspath_result=$func_stripname_result
1122         return
1123         ;;
1124       # The next three entries are used to spot a run of precisely
1125       # two leading slashes without using negated character classes;
1126       # we take advantage of case's first-match behaviour.
1127       ///*)
1128         # Unusual form of absolute path, do nothing.
1129         ;;
1130       //*)
1131         # Not necessarily an ordinary path; POSIX reserves leading '//'
1132         # and for example Cygwin uses it to access remote file shares
1133         # over CIFS/SMB, so we conserve a leading double slash if found.
1134         func_normal_abspath_altnamespace=/
1135         ;;
1136       /*)
1137         # Absolute path, do nothing.
1138         ;;
1139       *)
1140         # Relative path, prepend $cwd.
1141         func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1142         ;;
1143     esac
1144
1145     # Cancel out all the simple stuff to save iterations.  We also want
1146     # the path to end with a slash for ease of parsing, so make sure
1147     # there is one (and only one) here.
1148     func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1149           -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1150     while :; do
1151       # Processed it all yet?
1152       if test / = "$func_normal_abspath_tpath"; then
1153         # If we ascended to the root using ".." the result may be empty now.
1154         if test -z "$func_normal_abspath_result"; then
1155           func_normal_abspath_result=/
1156         fi
1157         break
1158       fi
1159       func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1160           -e "$_G_pathcar"`
1161       func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1162           -e "$_G_pathcdr"`
1163       # Figure out what to do with it
1164       case $func_normal_abspath_tcomponent in
1165         "")
1166           # Trailing empty path component, ignore it.
1167           ;;
1168         ..)
1169           # Parent dir; strip last assembled component from result.
1170           func_dirname "$func_normal_abspath_result"
1171           func_normal_abspath_result=$func_dirname_result
1172           ;;
1173         *)
1174           # Actual path component, append it.
1175           func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1176           ;;
1177       esac
1178     done
1179     # Restore leading double-slash if one was found on entry.
1180     func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1181 }
1182
1183
1184 # func_notquiet ARG...
1185 # --------------------
1186 # Echo program name prefixed message only when not in quiet mode.
1187 func_notquiet ()
1188 {
1189     $debug_cmd
1190
1191     $opt_quiet || func_echo ${1+"$@"}
1192
1193     # A bug in bash halts the script if the last line of a function
1194     # fails when set -e is in force, so we need another command to
1195     # work around that:
1196     :
1197 }
1198
1199
1200 # func_relative_path SRCDIR DSTDIR
1201 # --------------------------------
1202 # Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1203 func_relative_path ()
1204 {
1205     $debug_cmd
1206
1207     func_relative_path_result=
1208     func_normal_abspath "$1"
1209     func_relative_path_tlibdir=$func_normal_abspath_result
1210     func_normal_abspath "$2"
1211     func_relative_path_tbindir=$func_normal_abspath_result
1212
1213     # Ascend the tree starting from libdir
1214     while :; do
1215       # check if we have found a prefix of bindir
1216       case $func_relative_path_tbindir in
1217         $func_relative_path_tlibdir)
1218           # found an exact match
1219           func_relative_path_tcancelled=
1220           break
1221           ;;
1222         $func_relative_path_tlibdir*)
1223           # found a matching prefix
1224           func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1225           func_relative_path_tcancelled=$func_stripname_result
1226           if test -z "$func_relative_path_result"; then
1227             func_relative_path_result=.
1228           fi
1229           break
1230           ;;
1231         *)
1232           func_dirname $func_relative_path_tlibdir
1233           func_relative_path_tlibdir=$func_dirname_result
1234           if test -z "$func_relative_path_tlibdir"; then
1235             # Have to descend all the way to the root!
1236             func_relative_path_result=../$func_relative_path_result
1237             func_relative_path_tcancelled=$func_relative_path_tbindir
1238             break
1239           fi
1240           func_relative_path_result=../$func_relative_path_result
1241           ;;
1242       esac
1243     done
1244
1245     # Now calculate path; take care to avoid doubling-up slashes.
1246     func_stripname '' '/' "$func_relative_path_result"
1247     func_relative_path_result=$func_stripname_result
1248     func_stripname '/' '/' "$func_relative_path_tcancelled"
1249     if test -n "$func_stripname_result"; then
1250       func_append func_relative_path_result "/$func_stripname_result"
1251     fi
1252
1253     # Normalisation. If bindir is libdir, return '.' else relative path.
1254     if test -n "$func_relative_path_result"; then
1255       func_stripname './' '' "$func_relative_path_result"
1256       func_relative_path_result=$func_stripname_result
1257     fi
1258
1259     test -n "$func_relative_path_result" || func_relative_path_result=.
1260
1261     :
1262 }
1263
1264
1265 # func_quote_portable EVAL ARG
1266 # ----------------------------
1267 # Internal function to portably implement func_quote_arg.  Note that we still
1268 # keep attention to performance here so we as much as possible try to avoid
1269 # calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1270 func_quote_portable ()
1271 {
1272     $debug_cmd
1273
1274     func_quote_portable_result=$2
1275
1276     # one-time-loop (easy break)
1277     while true
1278     do
1279       if $1; then
1280         func_quote_portable_result=`$ECHO "$2" | $SED \
1281           -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1282         break
1283       fi
1284
1285       # Quote for eval.
1286       case $func_quote_portable_result in
1287         *[\\\`\"\$]*)
1288           case $func_quote_portable_result in
1289             *[\[\*\?]*)
1290               func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1291                   | $SED "$sed_quote_subst"`
1292               break
1293               ;;
1294           esac
1295
1296           func_quote_portable_old_IFS=$IFS
1297           for _G_char in '\' '`' '"' '$'
1298           do
1299             # STATE($1) PREV($2) SEPARATOR($3)
1300             set start "" ""
1301             func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1302             IFS=$_G_char
1303             for _G_part in $func_quote_portable_result
1304             do
1305               case $1 in
1306               quote)
1307                 func_append func_quote_portable_result "$3$2"
1308                 set quote "$_G_part" "\\$_G_char"
1309                 ;;
1310               start)
1311                 set first "" ""
1312                 func_quote_portable_result=
1313                 ;;
1314               first)
1315                 set quote "$_G_part" ""
1316                 ;;
1317               esac
1318             done
1319           done
1320           IFS=$func_quote_portable_old_IFS
1321           ;;
1322         *) ;;
1323       esac
1324       break
1325     done
1326
1327     func_quote_portable_unquoted_result=$func_quote_portable_result
1328     case $func_quote_portable_result in
1329       # double-quote args containing shell metacharacters to delay
1330       # word splitting, command substitution and variable expansion
1331       # for a subsequent eval.
1332       # many bourne shells cannot handle close brackets correctly
1333       # in scan sets, so we specify it separately.
1334       *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \     ]*|*]*|"")
1335         func_quote_portable_result=\"$func_quote_portable_result\"
1336         ;;
1337     esac
1338 }
1339
1340
1341 # func_quotefast_eval ARG
1342 # -----------------------
1343 # Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1344 # but optimized for speed.  Result is stored in $func_quotefast_eval.
1345 if test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1346   printf -v _GL_test_printf_tilde %q '~'
1347   if test '\~' = "$_GL_test_printf_tilde"; then
1348     func_quotefast_eval ()
1349     {
1350       printf -v func_quotefast_eval_result %q "$1"
1351     }
1352   else
1353     # Broken older Bash implementations.  Make those faster too if possible.
1354     func_quotefast_eval ()
1355     {
1356       case $1 in
1357         '~'*)
1358           func_quote_portable false "$1"
1359           func_quotefast_eval_result=$func_quote_portable_result
1360           ;;
1361         *)
1362           printf -v func_quotefast_eval_result %q "$1"
1363           ;;
1364       esac
1365     }
1366   fi
1367 else
1368   func_quotefast_eval ()
1369   {
1370     func_quote_portable false "$1"
1371     func_quotefast_eval_result=$func_quote_portable_result
1372   }
1373 fi
1374
1375
1376 # func_quote_arg MODEs ARG
1377 # ------------------------
1378 # Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1379 # specifiers listed below separated by ',' character.  This function returns two
1380 # values:
1381 #   i) func_quote_arg_result
1382 #      double-quoted (when needed), suitable for a subsequent eval
1383 #  ii) func_quote_arg_unquoted_result
1384 #      has all characters that are still active within double
1385 #      quotes backslashified.  Available only if 'unquoted' is specified.
1386 #
1387 # Available modes:
1388 # ----------------
1389 # 'eval' (default)
1390 #       - escape shell special characters
1391 # 'expand'
1392 #       - the same as 'eval';  but do not quote variable references
1393 # 'pretty'
1394 #       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1395 #         be used later in func_quote to get output like: 'echo "a b"' instead
1396 #         of 'echo a\ b'.  This is slower than default on some shells.
1397 # 'unquoted'
1398 #       - produce also $func_quote_arg_unquoted_result which does not contain
1399 #         wrapping double-quotes.
1400 #
1401 # Examples for 'func_quote_arg pretty,unquoted string':
1402 #
1403 #   string      | *_result              | *_unquoted_result
1404 #   ------------+-----------------------+-------------------
1405 #   "           | \"                    | \"
1406 #   a b         | "a b"                 | a b
1407 #   "a b"       | "\"a b\""             | \"a b\"
1408 #   *           | "*"                   | *
1409 #   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1410 #
1411 # Examples for 'func_quote_arg pretty,unquoted,expand string':
1412 #
1413 #   string        |   *_result          |  *_unquoted_result
1414 #   --------------+---------------------+--------------------
1415 #   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1416 func_quote_arg ()
1417 {
1418     _G_quote_expand=false
1419     case ,$1, in
1420       *,expand,*)
1421         _G_quote_expand=:
1422         ;;
1423     esac
1424
1425     case ,$1, in
1426       *,pretty,*|*,expand,*|*,unquoted,*)
1427         func_quote_portable $_G_quote_expand "$2"
1428         func_quote_arg_result=$func_quote_portable_result
1429         func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1430         ;;
1431       *)
1432         # Faster quote-for-eval for some shells.
1433         func_quotefast_eval "$2"
1434         func_quote_arg_result=$func_quotefast_eval_result
1435         ;;
1436     esac
1437 }
1438
1439
1440 # func_quote MODEs ARGs...
1441 # ------------------------
1442 # Quote all ARGs to be evaled later and join them into single command.  See
1443 # func_quote_arg's description for more info.
1444 func_quote ()
1445 {
1446     $debug_cmd
1447     _G_func_quote_mode=$1 ; shift
1448     func_quote_result=
1449     while test 0 -lt $#; do
1450       func_quote_arg "$_G_func_quote_mode" "$1"
1451       if test -n "$func_quote_result"; then
1452         func_append func_quote_result " $func_quote_arg_result"
1453       else
1454         func_append func_quote_result "$func_quote_arg_result"
1455       fi
1456       shift
1457     done
1458 }
1459
1460
1461 # func_stripname PREFIX SUFFIX NAME
1462 # ---------------------------------
1463 # strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1464 # PREFIX and SUFFIX must not contain globbing or regex special
1465 # characters, hashes, percent signs, but SUFFIX may contain a leading
1466 # dot (in which case that matches only a dot).
1467 if test yes = "$_G_HAVE_XSI_OPS"; then
1468   eval 'func_stripname ()
1469   {
1470     $debug_cmd
1471
1472     # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1473     # positional parameters, so assign one to ordinary variable first.
1474     func_stripname_result=$3
1475     func_stripname_result=${func_stripname_result#"$1"}
1476     func_stripname_result=${func_stripname_result%"$2"}
1477   }'
1478 else
1479   func_stripname ()
1480   {
1481     $debug_cmd
1482
1483     case $2 in
1484       .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1485       *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1486     esac
1487   }
1488 fi
1489
1490
1491 # func_show_eval CMD [FAIL_EXP]
1492 # -----------------------------
1493 # Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1494 # not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1495 # is given, then evaluate it.
1496 func_show_eval ()
1497 {
1498     $debug_cmd
1499
1500     _G_cmd=$1
1501     _G_fail_exp=${2-':'}
1502
1503     func_quote_arg pretty,expand "$_G_cmd"
1504     eval "func_notquiet $func_quote_arg_result"
1505
1506     $opt_dry_run || {
1507       eval "$_G_cmd"
1508       _G_status=$?
1509       if test 0 -ne "$_G_status"; then
1510         eval "(exit $_G_status); $_G_fail_exp"
1511       fi
1512     }
1513 }
1514
1515
1516 # func_show_eval_locale CMD [FAIL_EXP]
1517 # ------------------------------------
1518 # Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1519 # not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1520 # is given, then evaluate it.  Use the saved locale for evaluation.
1521 func_show_eval_locale ()
1522 {
1523     $debug_cmd
1524
1525     _G_cmd=$1
1526     _G_fail_exp=${2-':'}
1527
1528     $opt_quiet || {
1529       func_quote_arg expand,pretty "$_G_cmd"
1530       eval "func_echo $func_quote_arg_result"
1531     }
1532
1533     $opt_dry_run || {
1534       eval "$_G_user_locale
1535             $_G_cmd"
1536       _G_status=$?
1537       eval "$_G_safe_locale"
1538       if test 0 -ne "$_G_status"; then
1539         eval "(exit $_G_status); $_G_fail_exp"
1540       fi
1541     }
1542 }
1543
1544
1545 # func_tr_sh
1546 # ----------
1547 # Turn $1 into a string suitable for a shell variable name.
1548 # Result is stored in $func_tr_sh_result.  All characters
1549 # not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1550 # if $1 begins with a digit, a '_' is prepended as well.
1551 func_tr_sh ()
1552 {
1553     $debug_cmd
1554
1555     case $1 in
1556     [0-9]* | *[!a-zA-Z0-9_]*)
1557       func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1558       ;;
1559     * )
1560       func_tr_sh_result=$1
1561       ;;
1562     esac
1563 }
1564
1565
1566 # func_verbose ARG...
1567 # -------------------
1568 # Echo program name prefixed message in verbose mode only.
1569 func_verbose ()
1570 {
1571     $debug_cmd
1572
1573     $opt_verbose && func_echo "$*"
1574
1575     :
1576 }
1577
1578
1579 # func_warn_and_continue ARG...
1580 # -----------------------------
1581 # Echo program name prefixed warning message to standard error.
1582 func_warn_and_continue ()
1583 {
1584     $debug_cmd
1585
1586     $require_term_colors
1587
1588     func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1589 }
1590
1591
1592 # func_warning CATEGORY ARG...
1593 # ----------------------------
1594 # Echo program name prefixed warning message to standard error. Warning
1595 # messages can be filtered according to CATEGORY, where this function
1596 # elides messages where CATEGORY is not listed in the global variable
1597 # 'opt_warning_types'.
1598 func_warning ()
1599 {
1600     $debug_cmd
1601
1602     # CATEGORY must be in the warning_categories list!
1603     case " $warning_categories " in
1604       *" $1 "*) ;;
1605       *) func_internal_error "invalid warning category '$1'" ;;
1606     esac
1607
1608     _G_category=$1
1609     shift
1610
1611     case " $opt_warning_types " in
1612       *" $_G_category "*) $warning_func ${1+"$@"} ;;
1613     esac
1614 }
1615
1616
1617 # func_sort_ver VER1 VER2
1618 # -----------------------
1619 # 'sort -V' is not generally available.
1620 # Note this deviates from the version comparison in automake
1621 # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1622 # but this should suffice as we won't be specifying old
1623 # version formats or redundant trailing .0 in bootstrap.conf.
1624 # If we did want full compatibility then we should probably
1625 # use m4_version_compare from autoconf.
1626 func_sort_ver ()
1627 {
1628     $debug_cmd
1629
1630     printf '%s\n%s\n' "$1" "$2" \
1631       | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n
1632 }
1633
1634 # func_lt_ver PREV CURR
1635 # ---------------------
1636 # Return true if PREV and CURR are in the correct order according to
1637 # func_sort_ver, otherwise false.  Use it like this:
1638 #
1639 #  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1640 func_lt_ver ()
1641 {
1642     $debug_cmd
1643
1644     test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1645 }
1646
1647
1648 # Local variables:
1649 # mode: shell-script
1650 # sh-indentation: 2
1651 # eval: (add-hook 'before-save-hook 'time-stamp)
1652 # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1653 # time-stamp-time-zone: "UTC"
1654 # End:
1655 #! /bin/sh
1656
1657 # A portable, pluggable option parser for Bourne shell.
1658 # Written by Gary V. Vaughan, 2010
1659
1660 # This is free software.  There is NO warranty; not even for
1661 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1662 #
1663 # Copyright (C) 2010-2019 Bootstrap Authors
1664 #
1665 # This file is dual licensed under the terms of the MIT license
1666 # <https://opensource.org/license/MIT>, and GPL version 2 or later
1667 # <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1668 # these licenses when using or redistributing this software or any of
1669 # the files within it.  See the URLs above, or the file `LICENSE`
1670 # included in the Bootstrap distribution for the full license texts.
1671
1672 # Please report bugs or propose patches to:
1673 # <https://github.com/gnulib-modules/bootstrap/issues>
1674
1675 # Set a version string for this script.
1676 scriptversion=2019-02-19.15; # UTC
1677
1678
1679 ## ------ ##
1680 ## Usage. ##
1681 ## ------ ##
1682
1683 # This file is a library for parsing options in your shell scripts along
1684 # with assorted other useful supporting features that you can make use
1685 # of too.
1686 #
1687 # For the simplest scripts you might need only:
1688 #
1689 #   #!/bin/sh
1690 #   . relative/path/to/funclib.sh
1691 #   . relative/path/to/options-parser
1692 #   scriptversion=1.0
1693 #   func_options ${1+"$@"}
1694 #   eval set dummy "$func_options_result"; shift
1695 #   ...rest of your script...
1696 #
1697 # In order for the '--version' option to work, you will need to have a
1698 # suitably formatted comment like the one at the top of this file
1699 # starting with '# Written by ' and ending with '# Copyright'.
1700 #
1701 # For '-h' and '--help' to work, you will also need a one line
1702 # description of your script's purpose in a comment directly above the
1703 # '# Written by ' line, like the one at the top of this file.
1704 #
1705 # The default options also support '--debug', which will turn on shell
1706 # execution tracing (see the comment above debug_cmd below for another
1707 # use), and '--verbose' and the func_verbose function to allow your script
1708 # to display verbose messages only when your user has specified
1709 # '--verbose'.
1710 #
1711 # After sourcing this file, you can plug in processing for additional
1712 # options by amending the variables from the 'Configuration' section
1713 # below, and following the instructions in the 'Option parsing'
1714 # section further down.
1715
1716 ## -------------- ##
1717 ## Configuration. ##
1718 ## -------------- ##
1719
1720 # You should override these variables in your script after sourcing this
1721 # file so that they reflect the customisations you have added to the
1722 # option parser.
1723
1724 # The usage line for option parsing errors and the start of '-h' and
1725 # '--help' output messages. You can embed shell variables for delayed
1726 # expansion at the time the message is displayed, but you will need to
1727 # quote other shell meta-characters carefully to prevent them being
1728 # expanded when the contents are evaled.
1729 usage='$progpath [OPTION]...'
1730
1731 # Short help message in response to '-h' and '--help'.  Add to this or
1732 # override it after sourcing this library to reflect the full set of
1733 # options your script accepts.
1734 usage_message="\
1735        --debug        enable verbose shell tracing
1736    -W, --warnings=CATEGORY
1737                       report the warnings falling in CATEGORY [all]
1738    -v, --verbose      verbosely report processing
1739        --version      print version information and exit
1740    -h, --help         print short or long help message and exit
1741 "
1742
1743 # Additional text appended to 'usage_message' in response to '--help'.
1744 long_help_message="
1745 Warning categories include:
1746        'all'          show all warnings
1747        'none'         turn off all the warnings
1748        'error'        warnings are treated as fatal errors"
1749
1750 # Help message printed before fatal option parsing errors.
1751 fatal_help="Try '\$progname --help' for more information."
1752
1753
1754
1755 ## ------------------------- ##
1756 ## Hook function management. ##
1757 ## ------------------------- ##
1758
1759 # This section contains functions for adding, removing, and running hooks
1760 # in the main code.  A hook is just a list of function names that can be
1761 # run in order later on.
1762
1763 # func_hookable FUNC_NAME
1764 # -----------------------
1765 # Declare that FUNC_NAME will run hooks added with
1766 # 'func_add_hook FUNC_NAME ...'.
1767 func_hookable ()
1768 {
1769     $debug_cmd
1770
1771     func_append hookable_fns " $1"
1772 }
1773
1774
1775 # func_add_hook FUNC_NAME HOOK_FUNC
1776 # ---------------------------------
1777 # Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1778 # first have been declared "hookable" by a call to 'func_hookable'.
1779 func_add_hook ()
1780 {
1781     $debug_cmd
1782
1783     case " $hookable_fns " in
1784       *" $1 "*) ;;
1785       *) func_fatal_error "'$1' does not accept hook functions." ;;
1786     esac
1787
1788     eval func_append ${1}_hooks '" $2"'
1789 }
1790
1791
1792 # func_remove_hook FUNC_NAME HOOK_FUNC
1793 # ------------------------------------
1794 # Remove HOOK_FUNC from the list of hook functions to be called by
1795 # FUNC_NAME.
1796 func_remove_hook ()
1797 {
1798     $debug_cmd
1799
1800     eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1801 }
1802
1803
1804 # func_propagate_result FUNC_NAME_A FUNC_NAME_B
1805 # ---------------------------------------------
1806 # If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1807 # *_result variable of FUNC_NAME_B.
1808 func_propagate_result ()
1809 {
1810     $debug_cmd
1811
1812     func_propagate_result_result=:
1813     if eval "test \"\${${1}_result+set}\" = set"
1814     then
1815       eval "${2}_result=\$${1}_result"
1816     else
1817       func_propagate_result_result=false
1818     fi
1819 }
1820
1821
1822 # func_run_hooks FUNC_NAME [ARG]...
1823 # ---------------------------------
1824 # Run all hook functions registered to FUNC_NAME.
1825 # It's assumed that the list of hook functions contains nothing more
1826 # than a whitespace-delimited list of legal shell function names, and
1827 # no effort is wasted trying to catch shell meta-characters or preserve
1828 # whitespace.
1829 func_run_hooks ()
1830 {
1831     $debug_cmd
1832
1833     case " $hookable_fns " in
1834       *" $1 "*) ;;
1835       *) func_fatal_error "'$1' does not support hook functions." ;;
1836     esac
1837
1838     eval _G_hook_fns=\$$1_hooks; shift
1839
1840     for _G_hook in $_G_hook_fns; do
1841       func_unset "${_G_hook}_result"
1842       eval $_G_hook '${1+"$@"}'
1843       func_propagate_result $_G_hook func_run_hooks
1844       if $func_propagate_result_result; then
1845         eval set dummy "$func_run_hooks_result"; shift
1846       fi
1847     done
1848 }
1849
1850
1851
1852 ## --------------- ##
1853 ## Option parsing. ##
1854 ## --------------- ##
1855
1856 # In order to add your own option parsing hooks, you must accept the
1857 # full positional parameter list from your hook function.  You may remove
1858 # or edit any options that you action, and then pass back the remaining
1859 # unprocessed options in '<hooked_function_name>_result', escaped
1860 # suitably for 'eval'.
1861 #
1862 # The '<hooked_function_name>_result' variable is automatically unset
1863 # before your hook gets called; for best performance, only set the
1864 # *_result variable when necessary (i.e. don't call the 'func_quote'
1865 # function unnecessarily because it can be an expensive operation on some
1866 # machines).
1867 #
1868 # Like this:
1869 #
1870 #    my_options_prep ()
1871 #    {
1872 #        $debug_cmd
1873 #
1874 #        # Extend the existing usage message.
1875 #        usage_message=$usage_message'
1876 #      -s, --silent       don'\''t print informational messages
1877 #    '
1878 #        # No change in '$@' (ignored completely by this hook).  Leave
1879 #        # my_options_prep_result variable intact.
1880 #    }
1881 #    func_add_hook func_options_prep my_options_prep
1882 #
1883 #
1884 #    my_silent_option ()
1885 #    {
1886 #        $debug_cmd
1887 #
1888 #        args_changed=false
1889 #
1890 #        # Note that, for efficiency, we parse as many options as we can
1891 #        # recognise in a loop before passing the remainder back to the
1892 #        # caller on the first unrecognised argument we encounter.
1893 #        while test $# -gt 0; do
1894 #          opt=$1; shift
1895 #          case $opt in
1896 #            --silent|-s) opt_silent=:
1897 #                         args_changed=:
1898 #                         ;;
1899 #            # Separate non-argument short options:
1900 #            -s*)         func_split_short_opt "$_G_opt"
1901 #                         set dummy "$func_split_short_opt_name" \
1902 #                             "-$func_split_short_opt_arg" ${1+"$@"}
1903 #                         shift
1904 #                         args_changed=:
1905 #                         ;;
1906 #            *)           # Make sure the first unrecognised option "$_G_opt"
1907 #                         # is added back to "$@" in case we need it later,
1908 #                         # if $args_changed was set to 'true'.
1909 #                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1910 #          esac
1911 #        done
1912 #
1913 #        # Only call 'func_quote' here if we processed at least one argument.
1914 #        if $args_changed; then
1915 #          func_quote eval ${1+"$@"}
1916 #          my_silent_option_result=$func_quote_result
1917 #        fi
1918 #    }
1919 #    func_add_hook func_parse_options my_silent_option
1920 #
1921 #
1922 #    my_option_validation ()
1923 #    {
1924 #        $debug_cmd
1925 #
1926 #        $opt_silent && $opt_verbose && func_fatal_help "\
1927 #    '--silent' and '--verbose' options are mutually exclusive."
1928 #    }
1929 #    func_add_hook func_validate_options my_option_validation
1930 #
1931 # You'll also need to manually amend $usage_message to reflect the extra
1932 # options you parse.  It's preferable to append if you can, so that
1933 # multiple option parsing hooks can be added safely.
1934
1935
1936 # func_options_finish [ARG]...
1937 # ----------------------------
1938 # Finishing the option parse loop (call 'func_options' hooks ATM).
1939 func_options_finish ()
1940 {
1941     $debug_cmd
1942
1943     func_run_hooks func_options ${1+"$@"}
1944     func_propagate_result func_run_hooks func_options_finish
1945 }
1946
1947
1948 # func_options [ARG]...
1949 # ---------------------
1950 # All the functions called inside func_options are hookable. See the
1951 # individual implementations for details.
1952 func_hookable func_options
1953 func_options ()
1954 {
1955     $debug_cmd
1956
1957     _G_options_quoted=false
1958
1959     for my_func in options_prep parse_options validate_options options_finish
1960     do
1961       func_unset func_${my_func}_result
1962       func_unset func_run_hooks_result
1963       eval func_$my_func '${1+"$@"}'
1964       func_propagate_result func_$my_func func_options
1965       if $func_propagate_result_result; then
1966         eval set dummy "$func_options_result"; shift
1967         _G_options_quoted=:
1968       fi
1969     done
1970
1971     $_G_options_quoted || {
1972       # As we (func_options) are top-level options-parser function and
1973       # nobody quoted "$@" for us yet, we need to do it explicitly for
1974       # caller.
1975       func_quote eval ${1+"$@"}
1976       func_options_result=$func_quote_result
1977     }
1978 }
1979
1980
1981 # func_options_prep [ARG]...
1982 # --------------------------
1983 # All initialisations required before starting the option parse loop.
1984 # Note that when calling hook functions, we pass through the list of
1985 # positional parameters.  If a hook function modifies that list, and
1986 # needs to propagate that back to rest of this script, then the complete
1987 # modified list must be put in 'func_run_hooks_result' before returning.
1988 func_hookable func_options_prep
1989 func_options_prep ()
1990 {
1991     $debug_cmd
1992
1993     # Option defaults:
1994     opt_verbose=false
1995     opt_warning_types=
1996
1997     func_run_hooks func_options_prep ${1+"$@"}
1998     func_propagate_result func_run_hooks func_options_prep
1999 }
2000
2001
2002 # func_parse_options [ARG]...
2003 # ---------------------------
2004 # The main option parsing loop.
2005 func_hookable func_parse_options
2006 func_parse_options ()
2007 {
2008     $debug_cmd
2009
2010     _G_parse_options_requote=false
2011     # this just eases exit handling
2012     while test $# -gt 0; do
2013       # Defer to hook functions for initial option parsing, so they
2014       # get priority in the event of reusing an option name.
2015       func_run_hooks func_parse_options ${1+"$@"}
2016       func_propagate_result func_run_hooks func_parse_options
2017       if $func_propagate_result_result; then
2018         eval set dummy "$func_parse_options_result"; shift
2019         # Even though we may have changed "$@", we passed the "$@" array
2020         # down into the hook and it quoted it for us (because we are in
2021         # this if-branch).  No need to quote it again.
2022         _G_parse_options_requote=false
2023       fi
2024
2025       # Break out of the loop if we already parsed every option.
2026       test $# -gt 0 || break
2027
2028       # We expect that one of the options parsed in this function matches
2029       # and thus we remove _G_opt from "$@" and need to re-quote.
2030       _G_match_parse_options=:
2031       _G_opt=$1
2032       shift
2033       case $_G_opt in
2034         --debug|-x)   debug_cmd='set -x'
2035                       func_echo "enabling shell trace mode" >&2
2036                       $debug_cmd
2037                       ;;
2038
2039         --no-warnings|--no-warning|--no-warn)
2040                       set dummy --warnings none ${1+"$@"}
2041                       shift
2042                       ;;
2043
2044         --warnings|--warning|-W)
2045                       if test $# = 0 && func_missing_arg $_G_opt; then
2046                         _G_parse_options_requote=:
2047                         break
2048                       fi
2049                       case " $warning_categories $1" in
2050                         *" $1 "*)
2051                           # trailing space prevents matching last $1 above
2052                           func_append_uniq opt_warning_types " $1"
2053                           ;;
2054                         *all)
2055                           opt_warning_types=$warning_categories
2056                           ;;
2057                         *none)
2058                           opt_warning_types=none
2059                           warning_func=:
2060                           ;;
2061                         *error)
2062                           opt_warning_types=$warning_categories
2063                           warning_func=func_fatal_error
2064                           ;;
2065                         *)
2066                           func_fatal_error \
2067                              "unsupported warning category: '$1'"
2068                           ;;
2069                       esac
2070                       shift
2071                       ;;
2072
2073         --verbose|-v) opt_verbose=: ;;
2074         --version)    func_version ;;
2075         -\?|-h)       func_usage ;;
2076         --help)       func_help ;;
2077
2078         # Separate optargs to long options (plugins may need this):
2079         --*=*)        func_split_equals "$_G_opt"
2080                       set dummy "$func_split_equals_lhs" \
2081                           "$func_split_equals_rhs" ${1+"$@"}
2082                       shift
2083                       ;;
2084
2085        # Separate optargs to short options:
2086         -W*)
2087                       func_split_short_opt "$_G_opt"
2088                       set dummy "$func_split_short_opt_name" \
2089                           "$func_split_short_opt_arg" ${1+"$@"}
2090                       shift
2091                       ;;
2092
2093         # Separate non-argument short options:
2094         -\?*|-h*|-v*|-x*)
2095                       func_split_short_opt "$_G_opt"
2096                       set dummy "$func_split_short_opt_name" \
2097                           "-$func_split_short_opt_arg" ${1+"$@"}
2098                       shift
2099                       ;;
2100
2101         --)           _G_parse_options_requote=: ; break ;;
2102         -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
2103         *)            set dummy "$_G_opt" ${1+"$@"}; shift
2104                       _G_match_parse_options=false
2105                       break
2106                       ;;
2107       esac
2108
2109       if $_G_match_parse_options; then
2110         _G_parse_options_requote=:
2111       fi
2112     done
2113
2114     if $_G_parse_options_requote; then
2115       # save modified positional parameters for caller
2116       func_quote eval ${1+"$@"}
2117       func_parse_options_result=$func_quote_result
2118     fi
2119 }
2120
2121
2122 # func_validate_options [ARG]...
2123 # ------------------------------
2124 # Perform any sanity checks on option settings and/or unconsumed
2125 # arguments.
2126 func_hookable func_validate_options
2127 func_validate_options ()
2128 {
2129     $debug_cmd
2130
2131     # Display all warnings if -W was not given.
2132     test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2133
2134     func_run_hooks func_validate_options ${1+"$@"}
2135     func_propagate_result func_run_hooks func_validate_options
2136
2137     # Bail if the options were screwed!
2138     $exit_cmd $EXIT_FAILURE
2139 }
2140
2141
2142
2143 ## ----------------- ##
2144 ## Helper functions. ##
2145 ## ----------------- ##
2146
2147 # This section contains the helper functions used by the rest of the
2148 # hookable option parser framework in ascii-betical order.
2149
2150
2151 # func_fatal_help ARG...
2152 # ----------------------
2153 # Echo program name prefixed message to standard error, followed by
2154 # a help hint, and exit.
2155 func_fatal_help ()
2156 {
2157     $debug_cmd
2158
2159     eval \$ECHO \""Usage: $usage"\"
2160     eval \$ECHO \""$fatal_help"\"
2161     func_error ${1+"$@"}
2162     exit $EXIT_FAILURE
2163 }
2164
2165
2166 # func_help
2167 # ---------
2168 # Echo long help message to standard output and exit.
2169 func_help ()
2170 {
2171     $debug_cmd
2172
2173     func_usage_message
2174     $ECHO "$long_help_message"
2175     exit 0
2176 }
2177
2178
2179 # func_missing_arg ARGNAME
2180 # ------------------------
2181 # Echo program name prefixed message to standard error and set global
2182 # exit_cmd.
2183 func_missing_arg ()
2184 {
2185     $debug_cmd
2186
2187     func_error "Missing argument for '$1'."
2188     exit_cmd=exit
2189 }
2190
2191
2192 # func_split_equals STRING
2193 # ------------------------
2194 # Set func_split_equals_lhs and func_split_equals_rhs shell variables
2195 # after splitting STRING at the '=' sign.
2196 test -z "$_G_HAVE_XSI_OPS" \
2197     && (eval 'x=a/b/c;
2198       test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2199     && _G_HAVE_XSI_OPS=yes
2200
2201 if test yes = "$_G_HAVE_XSI_OPS"
2202 then
2203   # This is an XSI compatible shell, allowing a faster implementation...
2204   eval 'func_split_equals ()
2205   {
2206       $debug_cmd
2207
2208       func_split_equals_lhs=${1%%=*}
2209       func_split_equals_rhs=${1#*=}
2210       if test "x$func_split_equals_lhs" = "x$1"; then
2211         func_split_equals_rhs=
2212       fi
2213   }'
2214 else
2215   # ...otherwise fall back to using expr, which is often a shell builtin.
2216   func_split_equals ()
2217   {
2218       $debug_cmd
2219
2220       func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2221       func_split_equals_rhs=
2222       test "x$func_split_equals_lhs" = "x$1" \
2223         || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2224   }
2225 fi #func_split_equals
2226
2227
2228 # func_split_short_opt SHORTOPT
2229 # -----------------------------
2230 # Set func_split_short_opt_name and func_split_short_opt_arg shell
2231 # variables after splitting SHORTOPT after the 2nd character.
2232 if test yes = "$_G_HAVE_XSI_OPS"
2233 then
2234   # This is an XSI compatible shell, allowing a faster implementation...
2235   eval 'func_split_short_opt ()
2236   {
2237       $debug_cmd
2238
2239       func_split_short_opt_arg=${1#??}
2240       func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2241   }'
2242 else
2243   # ...otherwise fall back to using expr, which is often a shell builtin.
2244   func_split_short_opt ()
2245   {
2246       $debug_cmd
2247
2248       func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
2249       func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2250   }
2251 fi #func_split_short_opt
2252
2253
2254 # func_usage
2255 # ----------
2256 # Echo short help message to standard output and exit.
2257 func_usage ()
2258 {
2259     $debug_cmd
2260
2261     func_usage_message
2262     $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2263     exit 0
2264 }
2265
2266
2267 # func_usage_message
2268 # ------------------
2269 # Echo short help message to standard output.
2270 func_usage_message ()
2271 {
2272     $debug_cmd
2273
2274     eval \$ECHO \""Usage: $usage"\"
2275     echo
2276     $SED -n 's|^# ||
2277         /^Written by/{
2278           x;p;x
2279         }
2280         h
2281         /^Written by/q' < "$progpath"
2282     echo
2283     eval \$ECHO \""$usage_message"\"
2284 }
2285
2286
2287 # func_version
2288 # ------------
2289 # Echo version message to standard output and exit.
2290 # The version message is extracted from the calling file's header
2291 # comments, with leading '# ' stripped:
2292 #   1. First display the progname and version
2293 #   2. Followed by the header comment line matching  /^# Written by /
2294 #   3. Then a blank line followed by the first following line matching
2295 #      /^# Copyright /
2296 #   4. Immediately followed by any lines between the previous matches,
2297 #      except lines preceding the intervening completely blank line.
2298 # For example, see the header comments of this file.
2299 func_version ()
2300 {
2301     $debug_cmd
2302
2303     printf '%s\n' "$progname $scriptversion"
2304     $SED -n '
2305         /^# Written by /!b
2306         s|^# ||; p; n
2307
2308         :fwd2blnk
2309         /./ {
2310           n
2311           b fwd2blnk
2312         }
2313         p; n
2314
2315         :holdwrnt
2316         s|^# ||
2317         s|^# *$||
2318         /^Copyright /!{
2319           /./H
2320           n
2321           b holdwrnt
2322         }
2323
2324         s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2325         G
2326         s|\(\n\)\n*|\1|g
2327         p; q' < "$progpath"
2328
2329     exit $?
2330 }
2331
2332
2333 # Local variables:
2334 # mode: shell-script
2335 # sh-indentation: 2
2336 # eval: (add-hook 'before-save-hook 'time-stamp)
2337 # time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2338 # time-stamp-time-zone: "UTC"
2339 # End:
2340 #! /bin/sh
2341
2342 # Extract macro arguments from autotools input with GNU M4.
2343 # Written by Gary V. Vaughan, 2010
2344 #
2345 # This is free software.  There is NO warranty; not even for
2346 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2347 #
2348 # Copyright (C) 2010-2019 Bootstrap Authors
2349 #
2350 # This file is dual licensed under the terms of the MIT license
2351 # <https://opensource.org/license/MIT>, and GPL version 2 or later
2352 # <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
2353 # these licenses when using or redistributing this software or any of
2354 # the files within it.  See the URLs above, or the file `LICENSE`
2355 # included in the Bootstrap distribution for the full license texts.
2356
2357 # Please report bugs or propose patches to:
2358 # <https://github.com/gnulib-modules/bootstrap/issues>
2359
2360 # Make sure we've evaluated scripts we depend on.
2361 test -z "$progpath" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/funclib.sh
2362 test extract-trace = "$progname" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/options-parser
2363
2364 # Set a version string.
2365 scriptversion=2019-02-19.15; # UTC
2366
2367
2368 ## ------ ##
2369 ## Usage. ##
2370 ## ------ ##
2371
2372 # Run './extract-trace --help' for help with using this script from the
2373 # command line.
2374 #
2375 # Or source first 'options-parser' and then this file into your own
2376 # scripts in order to make use of the function and variable framework
2377 # they define, and also to avoid the overhead of forking to run this
2378 # script in its own process on every call.
2379
2380
2381
2382 ## ----------------- ##
2383 ## Helper functions. ##
2384 ## ----------------- ##
2385
2386 # This section contains the helper functions used by the rest of
2387 # 'extract-trace'.
2388
2389
2390 # func_autoconf_configure MAYBE-CONFIGURE-FILE
2391 # --------------------------------------------
2392 # Ensure that MAYBE-CONFIGURE-FILE is the name of a file in the current
2393 # directory that contains an uncommented call to AC_INIT.
2394 func_autoconf_configure ()
2395 {
2396     $debug_cmd
2397
2398     _G_sed_no_comment='
2399       s|#.*$||
2400       s|^dnl .*$||
2401       s| dnl .*$||'
2402     _G_ac_init=
2403
2404     # If we were passed a genuine file, make sure it calls AC_INIT.
2405     test -f "$1" \
2406       && _G_ac_init=`$SED "$_G_sed_no_comment" "$1" |$GREP AC_INIT`
2407
2408     # Otherwise it is not a genuine Autoconf input file.
2409     test -n "$_G_ac_init"
2410     _G_status=$?
2411
2412     test 0 -ne "$_G_status" \
2413       && func_verbose "'$1' not using Autoconf"
2414
2415     (exit $_G_status)
2416 }
2417
2418
2419 # func_tool_version_output CMD [FATAL-ERROR-MSG]
2420 # ----------------------------------------------
2421 # Attempt to run 'CMD --version', discarding errors.  The output can be
2422 # ignored by redirecting stdout, and this function used simply to test
2423 # whether the command exists and exits normally when passed a
2424 # '--version' argument.
2425 # When FATAL-ERROR-MSG is given, then this function will display the
2426 # message and exit if running 'CMD --version' returns a non-zero exit
2427 # status.
2428 func_tool_version_output ()
2429 {
2430     $debug_cmd
2431
2432     _G_cmd=$1
2433     _G_fatal_error_msg=$2
2434
2435     # Some tools, like 'git2cl' produce thousands of lines of output
2436     # unless stdin is /dev/null - in that case we want to return
2437     # successfully without saving all of that output.  Other tools,
2438     # such as 'help2man' exit with a non-zero status when stdin comes
2439     # from /dev/null, so we re-execute without /dev/null if that
2440     # happens.  This means that occasionally, the output from both calls
2441     # ends up in the result, but the alternative would be to discard the
2442     # output from one call, and hope the other produces something useful.
2443     { $_G_cmd --version </dev/null || $_G_cmd --version; } 2>/dev/null
2444     _G_status=$?
2445
2446     test 0 -ne "$_G_status" && test -n "$_G_fatal_error_msg" \
2447         && func_fatal_error "$_G_fatal_error_msg"
2448
2449     (exit $_G_status)
2450 }
2451
2452
2453 # func_tool_version_number CMD [FATAL-ERROR-MSG]
2454 # ----------------------------------------------
2455 # Pass arguments to func_tool_version_output, but set
2456 # $func_tool_version_number_result to the last dot delimited digit string
2457 # on the first line of output.
2458 func_tool_version_number ()
2459 {
2460     $debug_cmd
2461
2462     _G_verout=`func_tool_version_output "$@"`
2463     _G_status=$?
2464
2465     # A version number starts with a digit following a space on the first
2466     # line of output from `--version`.
2467     _G_verout=`echo "$_G_verout" |sed 1q`
2468     if test -n "$_G_verout"; then
2469       _G_vernum=`expr "$_G_verout" : '.* \([0-9][^ ]*\)'`
2470     fi
2471
2472     if test -n "$_G_vernum"; then
2473       printf '%s\n' "$_G_vernum"
2474     else
2475       printf '%s\n' "$_G_verout"
2476     fi
2477
2478     (exit $_G_status)
2479 }
2480
2481
2482 # func_find_tool ENVVAR NAMES...
2483 # ------------------------------
2484 # Search for a required program.  Use the value of ENVVAR, if set,
2485 # otherwise find the first of the NAMES that can be run (i.e.,
2486 # supports --version).  If found, set ENVVAR to the program name,
2487 # die otherwise.
2488 func_find_tool ()
2489 {
2490     $debug_cmd
2491
2492     _G_find_tool_envvar=$1
2493     shift
2494     _G_find_tool_names=$@
2495     eval "_G_find_tool_res=\$$_G_find_tool_envvar"
2496     if test -n "$_G_find_tool_res"; then
2497       _G_find_tool_error_prefix="\$$find_tool_envvar: "
2498     else
2499       _G_find_tool_res=
2500       _G_bestver=
2501       for _G_prog
2502       do
2503         _G_find_tool_save_IFS=$IFS
2504         IFS=${PATH_SEPARATOR-:}
2505         for _G_dir in $PATH; do
2506           IFS=$_G_find_tool_save_IFS
2507           _G_progpath=$_G_dir/$_G_prog
2508           test -r "$_G_progpath" && {
2509             _G_curver=`func_tool_version_number $_G_progpath`
2510             case $_G_bestver,$_G_curver in
2511             ,)
2512               # first non--version responsive prog sticks!
2513               test -n "$_G_progpath" || _G_find_tool_res=$_G_progpath
2514               ;;
2515             ,*)
2516               # first --version responsive prog beats non--version responsive!
2517               _G_find_tool_res=$_G_progpath
2518               _G_bestver=$_G_curver
2519               ;;
2520             *,*)
2521               # another --version responsive prog must be newer to beat previous one!
2522               test "x$_G_curver" = "x$_G_bestver" \
2523                 || func_lt_ver "$_G_curver" "$_G_bestver" \
2524                 || {
2525                      _G_find_tool_res=$_G_progpath
2526                      _G_bestver=$_G_curver
2527                    }
2528               ;;
2529             esac
2530           }
2531         done
2532         IFS=$_G_find_tool_save_IFS
2533       done
2534     fi
2535     if test -n "$_G_find_tool_res"; then
2536       func_tool_version_number >/dev/null $_G_find_tool_res "\
2537 ${_G_find_tool_error_prefix}Cannot run '$_G_find_tool_res --version'"
2538
2539       # Make sure the result is exported to the environment for children
2540       # to use.
2541       eval "$_G_find_tool_envvar=\$_G_find_tool_res"
2542       eval "export $_G_find_tool_envvar"
2543     else
2544       func_error "\
2545 One of these is required:
2546        $_G_find_tool_names"
2547     fi
2548 }
2549
2550
2551
2552 ## -------------------- ##
2553 ## Resource management. ##
2554 ## -------------------- ##
2555
2556 # This section contains definitions for functions that each ensure a
2557 # particular resource (a file, or a non-empty configuration variable for
2558 # example) is available, and if appropriate to extract default values
2559 # from pertinent package files.  Where a variable already has a non-
2560 # empty value (as set by the package's 'bootstrap.conf'), that value is
2561 # used in preference to deriving the default. Call them using their
2562 # associated 'require_*' variable to ensure that they are executed, at
2563 # most, once.
2564 #
2565 # It's entirely deliberate that calling these functions can set
2566 # variables that don't obey the namespace limitations obeyed by the rest
2567 # of this file, in order that that they be as useful as possible to
2568 # callers.
2569
2570
2571 # require_configure_ac
2572 # --------------------
2573 # Ensure that there is a 'configure.ac' or 'configure.in' file in the
2574 # current directory that contains an uncommented call to AC_INIT, and
2575 # that '$configure_ac' contains its name.
2576 require_configure_ac=func_require_configure_ac
2577 func_require_configure_ac ()
2578 {
2579     $debug_cmd
2580
2581     test -z "$configure_ac" \
2582       && func_autoconf_configure configure.ac && configure_ac=configure.ac
2583     test -z "$configure_ac" \
2584       && func_autoconf_configure configure.in && configure_ac=configure.in
2585     test -z "$configure_ac" \
2586       || func_verbose "found '$configure_ac'"
2587
2588     require_configure_ac=:
2589 }
2590
2591
2592 # require_gnu_m4
2593 # --------------
2594 # Search for GNU M4, and export it in $M4.
2595 require_gnu_m4=func_require_gnu_m4
2596 func_require_gnu_m4 ()
2597 {
2598     $debug_cmd
2599
2600     test -n "$M4" || {
2601       # Find the first m4 binary that responds to --version.
2602       func_find_tool M4 gm4 gnum4 m4
2603     }
2604
2605     test -n "$M4" || func_fatal_error "\
2606 Please install GNU M4, or 'export M4=/path/to/gnu/m4'."
2607
2608     func_verbose "export M4='$M4'"
2609
2610     # Make sure the search result is visible to subshells
2611     export M4
2612
2613     require_gnu_m4=:
2614 }
2615
2616
2617 ## --------------- ##
2618 ## Core functions. ##
2619 ## --------------- ##
2620
2621 # This section contains the high level functions used when calling this
2622 # file as a script. 'func_extract_trace' is probably the only one that you
2623 # won't want to replace if you source this file into your own script.
2624
2625
2626 # func_extract_trace MACRO_NAMES [FILENAME]...
2627 # --------------------------------------------
2628 # set '$func_extract_trace_result' to a colon delimited list of arguments
2629 # to any of the comma separated list of MACRO_NAMES in FILENAME. If no
2630 # FILENAME is given, then '$configure_ac' is assumed.
2631 func_extract_trace ()
2632 {
2633     $debug_cmd
2634
2635     $require_configure_ac
2636     $require_gnu_m4
2637
2638     _G_m4_traces=`$ECHO "--trace=$1" |$SED 's%,% --trace=%g'`
2639     _G_re_macros=`$ECHO "($1)" |$SED 's%,%|%g'`
2640     _G_macros="$1"; shift
2641     test $# -gt 0 || {
2642       set dummy $configure_ac
2643       shift
2644     }
2645
2646     # Generate an error if the first file is missing
2647     <"$1"
2648
2649     # Sadly, we can't use 'autom4te' tracing to extract macro arguments,
2650     # because it complains about things we want to ignore at bootstrap
2651     # time - like missing m4_include files; AC_PREREQ being newer than
2652     # the installed autoconf; and returns nothing when tracing
2653     # 'AM_INIT_AUTOMAKE' when aclocal hasn't been generated yet.
2654     #
2655     # The following tries to emulate a less persnickety version of (and
2656     # due to not having to wait for Perl startup on every invocation,
2657     # it's probably faster too):
2658     #
2659     #    autom4te --language=Autoconf --trace=$my_macro:\$% "$@"
2660     #
2661     # First we give a minimal set of macro declarations to M4 to prime
2662     # it for reading Autoconf macros, while still providing some of the
2663     # functionality generally used at m4-time to supply dynamic
2664     # arguments to Autocof functions, but without following
2665     # 'm4_s?include' files.
2666     _G_mini='
2667         dnl  Initialisation.
2668         m4_changequote([,])
2669         m4_define([m4_copy],   [m4_define([$2], m4_defn([$1]))])
2670         m4_define([m4_rename], [m4_copy([$1], [$2])m4_undefine([$1])])
2671
2672         dnl  Replace macros which may abort m4 with a no-op variant.
2673         m4_pushdef([m4_assert])
2674         m4_pushdef([m4_exit])
2675         m4_pushdef([m4_fatal])
2676         m4_pushdef([m4_m4exit])
2677
2678         dnl  Replace macros that might break stderr of m4.
2679         m4_pushdef([m4_errprint])
2680         m4_pushdef([m4_errprintn])
2681         m4_pushdef([m4_include])
2682         m4_pushdef([m4_warn])
2683
2684         dnl  Avoid side-effects of tracing by extract-trace.
2685         m4_pushdef([m4_maketemp])
2686         m4_pushdef([m4_mkstemp])
2687
2688         dnl  TODO: reasons for this
2689         m4_pushdef([m4_dnl])
2690         m4_pushdef([m4_m4wrap])
2691
2692         dnl  Copy and rename macros not handled by "m4 --prefix".
2693         m4_define([dnl],         [m4_builtin([dnl])])
2694         m4_copy([m4_define],     [m4_defun])
2695         m4_rename([m4_ifelse],   [m4_if])
2696         m4_rename([m4_patsubst], [m4_bpatsubst])
2697         m4_rename([m4_regexp],   [m4_bregexp])
2698
2699         dnl  "m4sugar.mini" - useful m4-time macros for dynamic arguments.
2700         dnl  If we discover packages that need more m4 macros defined in
2701         dnl  order to bootstrap correctly, add them here:
2702         m4_define([m4_bmatch],
2703             [m4_if([$#], 0, [], [$#], 1, [], [$#], 2, [$2],
2704                    [m4_if(m4_bregexp([$1], [$2]), -1,
2705                           [$0([$1], m4_shift3($@))], [$3])])])
2706         m4_define([m4_ifndef], [m4_ifdef([$1], [$3], [$2])])
2707         m4_define([m4_ifset],
2708             [m4_ifdef([$1], [m4_ifval(m4_defn([$1]), [$2], [$3])], [$3])])
2709         m4_define([m4_require], [$1])
2710         m4_define([m4_shift3], [m4_shift(m4shift(m4shift($@)))])
2711
2712         dnl  "autoconf.mini" - things from autoconf macros we care about.
2713         m4_copy([m4_defun], [AC_DEFUN])
2714
2715         dnl  Dummy definitions for the macros we want to trace.
2716         dnl  AM_INIT_AUTOMAKE at least produces no trace without this.
2717     '
2718
2719     _G_save=$IFS
2720     IFS=,
2721     for _G_macro in $_G_macros; do
2722       IFS=$_G_save
2723       func_append _G_mini "AC_DEFUN([$_G_macro])$nl"
2724     done
2725     IFS=$_G_save
2726
2727     # We discard M4's stdout, but the M4 trace output from reading our
2728     # "autoconf.mini" followed by any other files passed to this
2729     # function is then scanned by sed to transform it into a colon
2730     # delimited argument list assigned to a shell variable.
2731     _G_transform='s|#.*$||; s|^dnl .*$||; s| dnl .*$||;'
2732
2733     # Unfortunately, alternation in regexp addresses doesn't work in at
2734     # least BSD (and hence Mac OS X) sed, so we have to append a capture
2735     # and print block for each traced macro to the sed transform script.
2736     _G_save=$IFS
2737     IFS=,
2738     for _G_macro in $_G_macros; do
2739       IFS=$_G_save
2740       func_append _G_transform '
2741         /^m4trace: -1- '"$_G_macro"'/ {
2742           s|^m4trace: -1- '"$_G_macro"'[([]*||
2743           s|], [[]|:|g
2744           s|[])]*$|:|
2745           s|\(.\):$|\1|
2746           p
2747         }'
2748     done
2749     IFS=$_G_save
2750
2751     # Save the command pipeline results for further use by callers of
2752     # this function.
2753     func_extract_trace_result=`$ECHO "$_G_mini" \
2754       |$M4 -daq --prefix $_G_m4_traces - "$@" 2>&1 1>/dev/null \
2755       |$SED -n -e "$_G_transform"`
2756 }
2757
2758
2759 # func_extract_trace_first MACRO_NAMES [FILENAME]...
2760 # --------------------------------------------------
2761 # Exactly like func_extract_trace, except that only the first argument
2762 # to the first invocation of one of the comma separated MACRO_NAMES is
2763 # returned in '$func_extract_trace_first_result'.
2764 func_extract_trace_first ()
2765 {
2766     $debug_cmd
2767
2768     func_extract_trace ${1+"$@"}
2769     func_extract_trace_first_result=`$ECHO "$func_extract_trace_result" \
2770       |$SED -e 's|:.*$||g' -e 1q`
2771 }
2772
2773
2774 # func_main [ARG]...
2775 # ------------------
2776 func_main ()
2777 {
2778     $debug_cmd
2779
2780     # Configuration.
2781     usage='$progname MACRO_NAME FILE [...]'
2782
2783     long_help_message='
2784 The first argument to this program is the name of an autotools macro
2785 whose arguments you want to extract by examining the files listed in the
2786 remaining arguments using the same tool that Autoconf and Automake use,
2787 GNU M4.
2788
2789 The arguments are returned separated by colons, with each traced call
2790 on a separate line.'
2791
2792     # Option processing.
2793     func_options "$@"
2794     eval set dummy "$func_options_result"; shift
2795
2796     # Validate remaining non-option arguments.
2797     test $# -gt 1 \
2798         || func_fatal_help "not enough arguments"
2799
2800     # Pass non-option arguments to extraction function.
2801     func_extract_trace "$@"
2802
2803     # Display results.
2804     test -n "$func_extract_trace_result" \
2805         && $ECHO "$func_extract_trace_result"
2806
2807     # The End.
2808     exit $EXIT_SUCCESS
2809 }
2810
2811
2812 ## --------------------------- ##
2813 ## Actually perform the trace. ##
2814 ## --------------------------- ##
2815
2816 # Only call 'func_main' if this script was called directly.
2817 test extract-trace = "$progname" && func_main "$@"
2818
2819 # Local variables:
2820 # mode: shell-script
2821 # sh-indentation: 2
2822 # eval: (add-hook 'before-save-hook 'time-stamp)
2823 # time-stamp-pattern: "50/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2824 # time-stamp-time-zone: "UTC"
2825 # End:
2826
2827 # Set a version string for *this* script.
2828 scriptversion=2019-03-22.11; # UTC
2829
2830
2831 ## ------------------- ##
2832 ## Hookable functions. ##
2833 ## ------------------- ##
2834
2835 # After 'bootstrap.conf' has been sourced, execution proceeds by calling
2836 # 'func_bootstrap'.  Wherever a function is decorated with
2837 # 'func_hookable func_name', you will find a matching 'func_run_hooks
2838 # func_name', which executes all functions added with 'func_add_hook
2839 # func_name my_func'.
2840 #
2841 # You might notice that many of these functions begin with a series of
2842 # '$require_foo' lines.  See the docu-comments at the start of the
2843 # 'Resource management' section for a description of what these are.
2844
2845
2846 # func_bootstrap [ARG]...
2847 # -----------------------
2848 # All the functions called inside func_bootstrap are hookable. See the
2849 # the individual implementations for details.
2850 func_bootstrap ()
2851 {
2852     $debug_cmd
2853
2854     # Save the current positional parameters to prevent them being
2855     # corrupted by calls to 'set' in 'func_init'.
2856     func_quote eval ${1+"$@"}
2857     _G_saved_positional_parameters=$func_quote_result
2858
2859     # Initialisation.
2860     func_init
2861
2862     # Option processing.
2863     eval func_options "$_G_saved_positional_parameters"
2864
2865     # Post-option preparation.
2866     func_prep
2867
2868     # Reconfigure the package.
2869     func_reconfigure
2870
2871     # Ensure .version is up-to-date.
2872     func_update_dotversion
2873
2874     # Finalisation.
2875     func_fini
2876 }
2877
2878
2879 # func_init
2880 # ---------
2881 # Any early initialisations can be hooked to this function.  Consider
2882 # whether you can hook onto 'func_prep' instead, because if you hook
2883 # any slow to execute code in here, it will also add to the time before
2884 # './bootstrap --version' can respond.
2885 func_hookable func_init
2886 func_init ()
2887 {
2888     $debug_cmd
2889
2890     func_run_hooks func_init
2891 }
2892
2893
2894 # func_prep
2895 # ---------
2896 # Function to perform preparation for remaining bootstrap process. If
2897 # your hooked code relies on the outcome of 'func_options' hook it here
2898 # rather than to 'func_init'.
2899 #
2900 # All the functions called inside func_prep are hookable. See the
2901 # individual implementations for details.
2902 func_hookable func_prep
2903 func_prep ()
2904 {
2905     $debug_cmd
2906
2907     $require_buildtools_uptodate
2908     $require_checkout_only_file
2909
2910     $require_gnulib_merge_changelog
2911
2912     # Report the results of SED and GREP searches from funclib.sh.
2913     func_verbose "GREP='$GREP'"
2914     func_verbose "SED='$SED'"
2915
2916     # fetch update files from the translation project
2917     func_update_translations
2918
2919     func_run_hooks func_prep
2920 }
2921
2922
2923 # func_update_translations
2924 # ------------------------
2925 # Update package po files and translations.
2926 func_hookable func_update_translations
2927 func_update_translations ()
2928 {
2929     $debug_cmd
2930
2931     $opt_skip_po || {
2932       test -d po && {
2933         $require_package
2934
2935         func_update_po_files po $package || exit $?
2936       }
2937
2938       func_run_hooks func_update_translations
2939     }
2940 }
2941
2942
2943 # func_reconfigure
2944 # ----------------
2945 # Reconfigure the current package by running the appropriate autotools in a
2946 # suitable order.
2947 func_hookable func_reconfigure
2948 func_reconfigure ()
2949 {
2950     $debug_cmd
2951
2952     $require_automake_options
2953
2954     # Automake (without 'foreign' option) requires that NEWS & README exist.
2955     case " $automake_options " in
2956       " foreign ") ;;
2957       *)
2958         func_ensure_NEWS
2959         func_ensure_README
2960         ;;
2961     esac
2962
2963     # Ensure ChangeLog presence.
2964     if test -n "$gnulib_modules"; then
2965       func_ifcontains "$gnulib_modules" gitlog-to-changelog \
2966         func_ensure_changelog
2967     else
2968       $require_gnulib_cache
2969       if $SED -n '/^gl_MODULES(\[/,/^])$/p' $gnulib_cache 2>/dev/null |
2970          func_grep_q gitlog-to-changelog
2971       then
2972         func_ensure_changelog
2973       fi
2974     fi
2975
2976     # Released 'autopoint' has the tendency to install macros that have
2977     # been obsoleted in current 'gnulib', so run this before 'gnulib-tool'.
2978     func_autopoint
2979
2980     # Autoreconf runs 'aclocal' before 'libtoolize', which causes spurious
2981     # warnings if the initial 'aclocal' is confused by the libtoolized
2982     # (or worse: out-of-date) macro directory.
2983     func_libtoolize
2984
2985     # If you need to do anything after 'gnulib-tool' is done, but before
2986     # 'autoreconf' runs, you don't need to override this whole function,
2987     # because 'func_gnulib_tool' is hookable.
2988     func_gnulib_tool
2989
2990     func_autoreconf
2991
2992     func_run_hooks func_reconfigure
2993 }
2994
2995
2996 # func_gnulib_tool
2997 # ----------------
2998 # Run 'gnulib-tool' to fetch gnulib modules into the current package.
2999 #
3000 # It's assumed that since you are using gnulib's 'bootstrap' script,
3001 # you're also using gnulib elsewhere in your package.  If not, then
3002 # you can replace this function in 'bootstrap.conf' with:
3003 #
3004 #   func_gnulib_tool () { :; }
3005 #
3006 # (although the function returns immediately if $gnulib_tool is set to
3007 # true in any case).
3008 func_hookable func_gnulib_tool
3009 func_gnulib_tool ()
3010 {
3011     $debug_cmd
3012
3013     $require_gnulib_tool
3014     $require_libtoolize
3015
3016     test true = "$gnulib_tool" || {
3017       $require_gnulib_git_submodules
3018
3019       # bootstrap.conf written for gnulib bootstrap expects
3020       # gnulib_tool_option_extras to which --no-changelog is appended,
3021       # but libtool bootstrap expects you to append to gnulib_tool_options
3022       # so that you can override the --no-changelog default: make sure we
3023       # support both styles so users can migrate between them easily.
3024       gnulib_tool_all_options="$gnulib_tool_options $gnulib_tool_option_extras"
3025
3026       if test -n "$gnulib_modules"; then
3027         $require_gnulib_cache
3028         $require_gnulib_tool_base_options
3029
3030         gnulib_mode=--import
3031
3032         # Try not to pick up any stale values from 'gnulib-cache.m4'.
3033         rm -f "$gnulib_cache"
3034
3035         test -n "$gnulib_tool_base_options" \
3036             && func_append_uniq gnulib_tool_all_options " $gnulib_tool_base_options"
3037         test -n "$gnulib_mk" \
3038             && func_append_uniq gnulib_tool_all_options " --makefile-name=$gnulib_mk"
3039         test -n "$tests_base" && {
3040           func_append_uniq gnulib_tool_all_options " --tests-base=$tests_base"
3041           func_append_uniq gnulib_tool_all_options " --with-tests"
3042         }
3043       else
3044
3045         # 'gnulib_modules' and others are cached in 'gnulib-cache.m4':
3046         # Use 'gnulib --update' to fetch gnulib modules.
3047         gnulib_mode=--update
3048       fi
3049
3050       # Add a sensible default libtool option to gnulib_tool_options.
3051       # The embedded echo is to squash whitespace before globbing.
3052       case `echo " "$gnulib_tool_all_options" "` in
3053         *" --no-libtool "*|*" --libtool "*) ;;
3054         *)  if test true = "$LIBTOOLIZE"; then
3055               func_append_uniq gnulib_tool_all_options " --no-libtool"
3056             else
3057               func_append_uniq gnulib_tool_all_options " --libtool"
3058             fi
3059             ;;
3060       esac
3061
3062       $opt_copy || func_append_uniq gnulib_tool_all_options " --symlink"
3063
3064       func_append_uniq gnulib_tool_all_options " $gnulib_mode"
3065       func_append gnulib_tool_all_options " $gnulib_modules"
3066
3067       # The embedded echo is to squash whitespace before display.
3068       gnulib_cmd=`echo $gnulib_tool $gnulib_tool_all_options`
3069
3070       func_show_eval "$gnulib_cmd" 'exit $?'
3071
3072       # Use 'gnulib-tool --copy-file' to install non-module files.
3073       func_install_gnulib_non_module_files
3074     }
3075
3076     func_run_hooks func_gnulib_tool
3077 }
3078
3079
3080 # func_fini
3081 # ---------
3082 # Function to perform all finalisation for the bootstrap process.
3083 func_hookable func_fini
3084 func_fini ()
3085 {
3086     $debug_cmd
3087
3088     func_gettext_configuration
3089     func_clean_dangling_symlinks
3090     func_clean_unused_macros
3091     func_skip_po_recommendation
3092
3093     func_run_hooks func_fini
3094
3095     $require_bootstrap_uptodate
3096
3097     func_echo "Done.  Now you can run './configure'."
3098 }
3099
3100
3101 # func_gettext_configuration
3102 # --------------------------
3103 # Edit configuration values into po/Makevars.
3104 func_hookable func_gettext_configuration
3105 func_gettext_configuration ()
3106 {
3107     $debug_cmd
3108
3109     $require_autopoint
3110
3111     test true = "$AUTOPOINT" || {
3112       $require_copyright_holder
3113       $require_extra_locale_categories
3114       $require_package_bugreport
3115
3116       # Escape xgettext options for sed Makevars generation below.
3117       # We have to delete blank lines in a separate script so that we don't
3118       # append \\\ to the penultimate line, and then delete the last empty
3119       # line, which messes up the variable substitution later in this
3120       # function.  Note that adding a literal \\\ requires double escaping
3121       # here, once for the execution subshell, and again for the assignment,
3122       # which is why there are actually 12 (!!) backslashes in the script.
3123       _G_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED '
3124           $b
3125           s|$| \\\\\\\\\\\\|'`
3126
3127       # Create gettext configuration.
3128       func_echo "Creating po/Makevars from po/Makevars.template ..."
3129       $RM -f po/Makevars
3130       $SED '
3131         /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'|
3132         /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'|
3133         /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'|
3134         /^XGETTEXT_OPTIONS *=/{
3135           s|$| \\|
3136           a\
3137              '"$_G_xgettext_options"' \\\
3138              $${end_of_xgettext_options+}
3139         }
3140         s/ *$//
3141       ' po/Makevars.template >po/Makevars || exit 1
3142     }
3143
3144     func_run_hooks func_gettext_configuration
3145 }
3146
3147
3148
3149 ## --------------- ##
3150 ## Core functions. ##
3151 ## --------------- ##
3152
3153 # This section contains the main functions called from the 'Hookable
3154 # functions' (shown above), and are the ones you're  most likely
3155 # to want to replace with your own implementations in 'bootstrap.conf'.
3156
3157
3158 # func_autopoint
3159 # --------------
3160 # If this package uses gettext, then run 'autopoint'.
3161 func_autopoint ()
3162 {
3163     $debug_cmd
3164
3165     $require_autopoint
3166
3167     test true = "$AUTOPOINT" \
3168         || func_show_eval "$AUTOPOINT --force" 'exit $?'
3169 }
3170
3171
3172 # func_libtoolize
3173 # ---------------
3174 # If this package uses libtool, then run 'libtoolize'.
3175 func_libtoolize ()
3176 {
3177     $debug_cmd
3178
3179     $require_libtoolize
3180
3181     test true = "$LIBTOOLIZE" || {
3182       _G_libtoolize_options=
3183       $opt_copy && func_append _G_libtoolize_options " --copy"
3184       $opt_force && func_append _G_libtoolize_options " --force"
3185       $opt_verbose || func_append _G_libtoolize_options " --quiet"
3186       func_show_eval "$LIBTOOLIZE$_G_libtoolize_options" 'exit $?'
3187     }
3188 }
3189
3190
3191 # func_gnulib_tool_copy_file SRC DEST
3192 # -----------------------------------
3193 # Copy SRC, a path relative to the gnulib sub-tree, to DEST, a path
3194 # relative to the top-level source directory using gnulib-tool so that
3195 # any patches or replacements in $local_gl_path are applied.
3196 func_gnulib_tool_copy_file ()
3197 {
3198     $debug_cmd
3199
3200     $require_gnulib_tool
3201     $require_patch
3202
3203     if test true = "$gnulib_tool"; then
3204       # If gnulib-tool is not available (e.g. bootstrapping in a
3205       # distribution tarball), make sure that at least we have some
3206       # version of the required file already in place.
3207       test -f "$2" || func_fatal_error "\
3208 Can't find, copy or download '$2', a required
3209 gnulib supplied file, please provide the location of a
3210 complete 'gnulib' tree by setting 'gnulib_path' in your
3211 'bootstrap.conf' or with the '--gnulib-srcdir' option -
3212 or else specify the location of your 'git' binary by
3213 setting 'GIT' in the environment so that a fresh
3214 'gnulib' submodule can be cloned."
3215     else
3216       $require_gnulib_copy_cmd
3217
3218       $gnulib_copy_cmd $1 $2 2>/dev/null || {
3219         $require_gnulib_path
3220
3221         func_error "'$gnulib_path/$1' does not exist"
3222         return 1
3223       }
3224     fi
3225 }
3226
3227
3228 # func_install_gnulib_non_module_files
3229 # ------------------------------------
3230 # Get additional non-module files from gnulib, overriding existing files.
3231 func_install_gnulib_non_module_files ()
3232 {
3233     $debug_cmd
3234
3235     $require_build_aux
3236     $require_gnulib_tool
3237
3238     test -n "$gnulib_non_module_files" && {
3239       maybe_exit_cmd=:
3240
3241       for file in $gnulib_non_module_files; do
3242         case $file in
3243           */COPYING*) dest=COPYING;;
3244           */INSTALL) dest=INSTALL;;
3245           build-aux/missing) dest=
3246             func_warning settings "\
3247 Please remove build-aux/missing from gnulib_module_files in
3248 'bootstrap.conf', as it may clash with Automake's version."
3249             ;;
3250           build-aux/*) dest=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
3251           *) dest=$file;;
3252         esac
3253
3254         # Be sure to show all copying errors before bailing out
3255         test -z "$dest" \
3256             || func_gnulib_tool_copy_file "$file" "$dest" \
3257             || maybe_exit_cmd="exit $EXIT_FAILURE"
3258       done
3259
3260       $maybe_exit_cmd
3261     }
3262 }
3263
3264
3265 # func_ensure_changelog
3266 # ---------------------
3267 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3268 # will not run to completion with no ChangeLog file.
3269 func_ensure_changelog ()
3270 {
3271     $debug_cmd
3272
3273     test -f ChangeLog && mv -f ChangeLog ChangeLog~
3274
3275     cat >ChangeLog <<'EOT'
3276 ## ---------------------- ##
3277 ## DO NOT EDIT THIS FILE! ##
3278 ## ---------------------- ##
3279
3280 ChangeLog is generated by gitlog-to-changelog.
3281 EOT
3282
3283     _G_message="creating dummy 'ChangeLog'"
3284     test -f ChangeLog~ \
3285       && func_append _G_message ' (backup in ChangeLog~)'
3286     func_verbose "$_G_message"
3287
3288     return 0
3289 }
3290
3291
3292 # func_ensure_NEWS
3293 # ----------------
3294 # Without AM_INIT_AUTOMAKE([foreign]), automake will not run to
3295 # completion with no NEWS file, even though NEWS.md or NEWS.txt
3296 # is often preferable.
3297 func_ensure_NEWS ()
3298 {
3299     $debug_cmd
3300
3301     test -f NEWS || {
3302       _G_NEWS=
3303       for _G_news in NEWS.txt NEWS.md NEWS.rst; do
3304         test -f "$_G_news" && break
3305       done
3306
3307       test -f "$_G_news" && $LN_S $_G_news NEWS
3308       func_verbose "$LN_S $_G_news NEWS"
3309     }
3310
3311     return 0
3312 }
3313
3314
3315 # func_ensure_README
3316 # ------------------
3317 # Without AM_INIT_AUTOMAKE([foreign]), automake will not run to
3318 # completion with no README file, even though README.md or README.txt
3319 # is often preferable.
3320 func_ensure_README ()
3321 {
3322     $debug_cmd
3323
3324     test -f README || {
3325       _G_README=
3326       for _G_readme in README.txt README.md README.rst; do
3327         test -f "$_G_readme" && break
3328       done
3329
3330       test -f "$_G_readme" && $LN_S $_G_readme README
3331       func_verbose "$LN_S $_G_readme README"
3332     }
3333
3334     return 0
3335 }
3336
3337
3338 # func_autoreconf [SUBDIR]
3339 # ------------------------
3340 # Being careful not to re-run 'autopoint' or 'libtoolize', and not to
3341 # try to run 'autopoint', 'libtoolize' or 'autoheader' on packages that
3342 # don't use them, defer to 'autoreconf' for execution of the remaining
3343 # autotools to bootstrap this package.
3344 #
3345 # Projects with multiple trees to reconfigure can hook another call to
3346 # this function onto func_reconfigure:
3347 #
3348 #    my_autoreconf_foo ()
3349 #    {
3350 #        func_autoreconf foo
3351 #    }
3352 #    func_add_hook func_reconfigure my_autoreconf_foo
3353 func_autoreconf ()
3354 {
3355     $debug_cmd
3356
3357     $require_autoheader
3358     $require_build_aux  # automake and others put files in here
3359     $require_macro_dir  # aclocal and others put files in here
3360
3361     # We ran these manually already, and autoreconf won't exec ':'
3362     save_AUTOPOINT=$AUTOPOINT; AUTOPOINT=true
3363     save_LIBTOOLIZE=$LIBTOOLIZE; LIBTOOLIZE=true
3364
3365     _G_autoreconf_options=
3366     $opt_copy || func_append _G_autoreconf_options " --symlink"
3367     $opt_force && func_append _G_autoreconf_options " --force"
3368     $opt_verbose && func_append _G_autoreconf_options " --verbose"
3369     func_show_eval "$AUTORECONF$_G_autoreconf_options --install${1+ $1}" 'exit $?'
3370
3371     AUTOPOINT=$save_AUTOPOINT
3372     LIBTOOLIZE=$save_LIBTOOLIZE
3373 }
3374
3375
3376 # func_check_configuration VARNAME [CONFIGURE_MACRO]
3377 # --------------------------------------------------
3378 # Exit with a suitable diagnostic for an important configuration change
3379 # that needs to be made before bootstrap can run correctly.
3380 func_check_configuration ()
3381 {
3382     $debug_cmd
3383
3384     $require_configure_ac
3385
3386     eval 'test -n "$'$1'"' || {
3387       _G_error_msg="please set '$1' in 'bootstrap.conf'"
3388       if test -n "$configure_ac" && test -n "$2"; then
3389         func_append _G_error_msg "
3390 or add the following (or similar) to your '$configure_ac':
3391 $2"
3392       fi
3393
3394       func_fatal_error "$_G_error_msg"
3395     }
3396 }
3397
3398
3399 # func_clean_dangling_symlinks
3400 # ----------------------------
3401 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
3402 # gnulib-populated directories. Such .m4 files would cause aclocal to
3403 # fail.  The following requires GNU find 4.2.3 or newer. Considering
3404 # the usual portability constraints of this script, that may seem a very
3405 # demanding requirement, but it should be ok.  Ignore any failure,
3406 # which is fine, since this is only a convenience to help developers
3407 # avoid the relatively unusual case where a symlinked-to .m4 file is
3408 # git-removed from gnulib between successive runs of this script.
3409 func_clean_dangling_symlinks ()
3410 {
3411     $debug_cmd
3412
3413     $require_macro_dir
3414     $require_source_base
3415
3416     func_verbose "cleaning dangling symlinks"
3417
3418     find "$macro_dir" "$source_base" \
3419         -depth \( -name '*.m4' -o -name '*.[ch]' \) \
3420         -type l -xtype l -delete > /dev/null 2>&1
3421 }
3422
3423
3424 # func_clean_unused_macros
3425 # ------------------------
3426 # Autopoint can result in over-zealously adding macros into $macro_dir
3427 # even though they are not actually used, for example tests to help
3428 # build the 'intl' directory even though you have specified
3429 # 'AM_GNU_GETTEXT([external])' in your configure.ac.  This function
3430 # looks removes any macro files that can be found in gnulib,  but
3431 # are not 'm4_include'd by 'aclocal.m4'.
3432 func_clean_unused_macros ()
3433 {
3434     $debug_cmd
3435
3436     $require_gnulib_path
3437     $require_macro_dir
3438
3439     test -n "$gnulib_path" && test -f aclocal.m4 && {
3440       aclocal_m4s=`find . -name aclocal.m4 -print`
3441
3442       # We use 'ls|grep' instead of 'ls *.m4' to avoid exceeding
3443       # command line length limits in some shells.
3444       for file in `cd "$macro_dir" && ls -1 |$GREP '\.m4$'`; do
3445
3446         # Remove a macro file when aclocal.m4 does not m4_include it...
3447         func_grep_q 'm4_include([[]'$macro_dir/$file'])' $aclocal_m4s \
3448             || test ! -f "$gnulib_path/m4/$file" || {
3449
3450               # ...and there is an identical file in gnulib...
3451               if func_cmp_s "$gnulib_path/m4/$file" "$macro_dir/$file"; then
3452
3453                 # ...and it's not in the precious list ('echo' is needed
3454                 # here to squash whitespace for the match expression).
3455                 case " "`echo $gnulib_precious`" " in
3456                   *" $file "*) ;;
3457                   *) rm -f "$macro_dir/$file"
3458                      func_verbose \
3459                        "removing unused gnulib file '$macro_dir/$file'"
3460                 esac
3461               fi
3462         }
3463       done
3464     }
3465 }
3466
3467
3468 # func_skip_po_recommendation
3469 # ---------------------------
3470 # If there is a po directory, and '--skip-po' wasn't passed, let the
3471 # user know that they can use '--skip-po' on subsequent invocations.
3472 func_skip_po_recommendation ()
3473 {
3474     $debug_cmd
3475
3476     test ! -d po \
3477         || $opt_skip_po \
3478         || func_warning recommend "\
3479 If your pofiles are up-to-date, you can rerun bootstrap
3480 as '$progname --skip-po' to avoid redownloading."
3481 }
3482
3483
3484 # func_update_dotversion
3485 # ----------------------
3486 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3487 # will not run to completion with no ChangeLog file.
3488 func_update_dotversion ()
3489 {
3490     $debug_cmd
3491
3492     test -f "$build_aux/git-version-gen" && {
3493       _G_message="updating .version"
3494       test -f .version && {
3495         mv .version .version~
3496         func_append _G_message " (backup in .version~)"
3497       }
3498       func_verbose "updating .version"
3499
3500       $build_aux/git-version-gen dummy-arg > .version
3501     }
3502 }
3503
3504
3505
3506 ## -------------------- ##
3507 ## Resource management. ##
3508 ## -------------------- ##
3509
3510 # This section contains definitions for functions that each ensure a
3511 # particular resource (a file, or a non-empty configuration variable for
3512 # example) is available, and if appropriate to extract default values
3513 # from pertinent package files.  Where a variable already has a non-
3514 # empty value (as set by the package's 'bootstrap.conf'), that value is
3515 # used in preference to deriving the default. Call them using their
3516 # associated 'require_*' variable to ensure that they are executed, at
3517 # most, once.
3518
3519
3520 # require_gnulib_git_submodules
3521 # -----------------------------
3522 # Initialize all git modules from $gnulib_git_submodules before we
3523 # run 'gnulib-tool'.
3524 require_gnulib_git_submodules=func_require_gnulib_git_submodules
3525 func_require_gnulib_git_submodules ()
3526 {
3527     test -n "$gnulib_git_submodules" && {
3528       for _G_submodule in $gnulib_git_submodules
3529       do
3530         func_show_eval "git submodule init -- $_G_submodule" \
3531             && func_show_eval "git submodule update -- $_G_submodule" \
3532             || func_fatal_error "Unable to init git module '$_G_submodule'."
3533       done
3534     }
3535
3536     require_gnulib_git_submodules=:
3537 }
3538
3539
3540 # require_checkout_only_file
3541 # --------------------------
3542 # Bail out  if this package only bootstraps properly from a repository
3543 # checkout.
3544 require_checkout_only_file=func_require_checkout_only_file
3545 func_require_checkout_only_file ()
3546 {
3547     $debug_cmd
3548
3549     $opt_force || {
3550       test -n "$checkout_only_file" && test ! -f "$checkout_only_file" \
3551           && func_fatal_error "\
3552 Bootstrapping from a non-checked-out distribution is risky.
3553 If you wish to bootstrap anyway, use the '--force' option."
3554     }
3555
3556     require_checkout_only_file=:
3557 }
3558
3559
3560 # require_aclocal_amflags
3561 # -----------------------
3562 # Ensure '$aclocal_amflags' has a sensible default, extracted from
3563 # 'Makefile.am' if necessary.
3564 require_aclocal_amflags=func_require_aclocal_amflags
3565 func_require_aclocal_amflags ()
3566 {
3567     $debug_cmd
3568
3569     $require_makefile_am
3570
3571     _G_sed_extract_aclocal_amflags='s|#.*$||
3572         /^[      ]*ACLOCAL_AMFLAGS[      ]*=/ {
3573             s|^.*=[      ]*\(.*\)|aclocal_amflags="\1"|
3574             p
3575         }'
3576
3577     _G_aclocal_flags_cmd=`$SED -n "$_G_sed_extract_aclocal_amflags" \
3578         "$makefile_am"`
3579     eval "$_G_aclocal_flags_cmd"
3580
3581     func_verbose "ACLOCAL_AMFLAGS='$aclocal_amflags'"
3582
3583     require_aclocal_amflags=:
3584 }
3585
3586
3587 # require_autoheader
3588 # ------------------
3589 # Skip autoheader if it's not needed.
3590 require_autoheader=func_require_autoheader
3591 func_require_autoheader ()
3592 {
3593     $debug_cmd
3594
3595     test true = "$AUTOHEADER" || {
3596       func_extract_trace AC_CONFIG_HEADERS
3597       test -n "$func_extract_trace_result" \
3598           || func_extract_trace AC_CONFIG_HEADER
3599
3600       test -n "$func_extract_trace_result" || {
3601         AUTOHEADER=true
3602
3603         func_verbose "export AUTOHEADER='$AUTOHEADER'"
3604
3605         # Make sure the search result is visible to subshells
3606         export AUTOHEADER
3607       }
3608     }
3609
3610     require_autoheader=:
3611 }
3612
3613
3614 # require_automake_options
3615 # ------------------------
3616 # Extract options from AM_AUTOMAKE_INIT.
3617 require_automake_options=func_require_automake_options
3618 func_require_automake_options ()
3619 {
3620     $debug_cmd
3621
3622     func_extract_trace AM_INIT_AUTOMAKE
3623     automake_options=$func_extract_trace_result
3624
3625     require_automake_options=:
3626 }
3627
3628
3629 # require_autopoint
3630 # -----------------
3631 # Skip autopoint if it's not needed.
3632 require_autopoint=func_require_autopoint
3633 func_require_autopoint ()
3634 {
3635     $debug_cmd
3636
3637     test true = "$AUTOPOINT" || {
3638       func_extract_trace AM_GNU_GETTEXT_VERSION
3639
3640       test -n "$func_extract_trace_result" || {
3641         AUTOPOINT=true
3642
3643         func_verbose "export AUTOPOINT='$AUTOPOINT'"
3644
3645         # Make sure the search result is visible to subshells
3646         export AUTOPOINT
3647       }
3648     }
3649
3650     require_autopoint=:
3651 }
3652
3653
3654 # require_bootstrap_uptodate
3655 # --------------------------
3656 # Complain if the version of bootstrap in the gnulib directory differs
3657 # from the one we are running.
3658 require_bootstrap_uptodate=func_require_bootstrap_uptodate
3659 func_require_bootstrap_uptodate ()
3660 {
3661     $debug_cmd
3662
3663     $require_build_aux
3664
3665     _G_bootstrap_sources="
3666       $build_aux/bootstrap.in
3667       $build_aux/extract-trace
3668       $build_aux/funclib.sh
3669       $build_aux/options-parser
3670     "
3671
3672     _G_missing_bootstrap_sources=false
3673     for _G_src in $_G_bootstrap_sources; do
3674       test -f "$_G_src" || _G_missing_bootstrap_sources=:
3675     done
3676
3677     if $_G_missing_bootstrap_sources; then
3678       func_warning upgrade "\
3679 Please add bootstrap to your gnulib_modules list in
3680 'bootstrap.conf', so that I can tell you when there are
3681 updates available."
3682     else
3683       rm -f bootstrap.new
3684       $build_aux/inline-source $build_aux/bootstrap.in > bootstrap.new
3685
3686       if func_cmp_s "$progpath" bootstrap.new; then
3687         rm -f bootstrap.new
3688         func_verbose "bootstrap script up to date"
3689       else
3690         chmod 555 bootstrap.new
3691         func_warning upgrade "\
3692 An updated bootstrap script has been generated for you in
3693 'bootstrap.new'.  After you've verified that you want
3694 the changes, you can update with:
3695     mv -f bootstrap.new $progname
3696     ./$progname
3697
3698 Or you can disable this check permanently by adding the
3699 following to 'bootstrap.conf':
3700     require_bootstrap_uptodate=:"
3701       fi
3702     fi
3703
3704     require_bootstrap_uptodate=:
3705 }
3706
3707
3708 # require_build_aux
3709 # -----------------
3710 # Ensure that '$build_aux' is set, and if it doesn't already point to an
3711 # existing directory, create one.
3712 require_build_aux=func_require_build_aux
3713 func_require_build_aux ()
3714 {
3715     $debug_cmd
3716
3717     test -n "$build_aux" || {
3718       func_extract_trace_first AC_CONFIG_AUX_DIR
3719       build_aux=$func_extract_trace_first_result
3720       func_check_configuration build_aux \
3721           "AC_CONFIG_AUX_DIR([name of a directory for build scripts])"
3722
3723       func_verbose "build_aux='$build_aux'"
3724     }
3725
3726     $require_vc_ignore_files
3727
3728     # If the build_aux directory doesn't exist, create it now, and mark it
3729     # as ignored for the VCS.
3730     if test ! -d "$build_aux"; then
3731       func_show_eval "mkdir '$build_aux'"
3732
3733       test -n "$vc_ignore_files" \
3734           || func_insert_if_absent "$build_aux" $vc_ignore_files
3735     fi
3736
3737     require_build_aux=:
3738 }
3739
3740
3741 # require_buildreq_autobuild
3742 # --------------------------
3743 # Try to find whether the bootstrap requires autobuild.
3744 require_buildreq_autobuild=func_require_buildreq_autobuild
3745 func_require_buildreq_autobuild ()
3746 {
3747     $debug_cmd
3748
3749     $require_macro_dir
3750
3751     test -f "$macro_dir/autobuild.m4" \
3752         || printf '%s\n' "$buildreq" |func_grep_q '^[    ]*autobuild' \
3753         || {
3754       func_extract_trace AB_INIT
3755       test -n "$func_extract_trace_result" && {
3756         func_append buildreq 'autobuild - http://josefsson.org/autobuild/
3757 '
3758         func_verbose "auto-adding 'autobuild' to build requirements"
3759       }
3760     }
3761
3762     require_buildreq_autobuild=:
3763 }
3764
3765
3766 # require_buildreq_autoconf
3767 # require_buildreq_autopoint
3768 # require_buildreq_libtoolize
3769 # ---------------------------
3770 # Try to find the minimum compatible version of autoconf/libtool
3771 # required to bootstrap successfully, and add it to '$buildreq'.
3772 for tool in autoconf libtoolize autopoint; do
3773   b=$tool
3774   v=require_buildreq_${tool}
3775   f=func_$v
3776   case $tool in
3777     autoconf) m=AC_PREREQ ;;
3778     libtoolize) m=LT_PREREQ; b=libtool ;;
3779     autopoint) m=AM_GNU_GETTEXT_VERSION b=gettext ;;
3780   esac
3781
3782   eval $v'='$f'
3783   '$f' ()
3784   {
3785     $debug_cmd
3786
3787     # The following is ignored if undefined, but might be necessary
3788     # in order for `func_find_tool` to run.
3789     ${require_'$tool'-:}
3790
3791     printf '\''%s\n'\'' "$buildreq" |func_grep_q '\''^[  ]*'$tool\'' || {
3792       func_extract_trace '$m'
3793       _G_version=$func_extract_trace_result
3794       test -n "$_G_version" && {
3795         func_append buildreq "\
3796             '$tool' $_G_version http://www.gnu.org/s/'$b'
3797 "
3798         func_verbose \
3799             "auto-adding '\'$tool'-$_G_version'\'' to build requirements"
3800       }
3801     }
3802
3803     '$v'=:
3804   }
3805 '
3806 done
3807
3808
3809 # require_buildreq_automake
3810 # -------------------------
3811 # Try to find the minimum compatible version of automake required to
3812 # bootstrap successfully, and add it to '$buildreq'.
3813 require_buildreq_automake=func_require_buildreq_automake
3814 func_require_buildreq_automake ()
3815 {
3816     $debug_cmd
3817
3818     # if automake is not already listed in $buildreq...
3819     printf '%s\n' "$buildreq" |func_grep_q automake || {
3820       func_extract_trace AM_INIT_AUTOMAKE
3821
3822       # ...and AM_INIT_AUTOMAKE is declared...
3823       test -n "$func_extract_trace_result" && {
3824         automake_version=`$ECHO "$func_extract_trace_result" \
3825            |$SED -e 's|[^0-9]*||' -e 's| .*$||'`
3826         test -n "$automake_version" || automake_version=-
3827
3828         func_append buildreq "\
3829             automake $automake_version http://www.gnu.org/s/automake
3830 "
3831         func_verbose \
3832             "auto-adding 'automake-$automake_version' to build requirements"
3833       }
3834     }
3835
3836     require_buildreq_automake=:
3837 }
3838
3839
3840 # require_buildreq_patch
3841 # ----------------------
3842 # Automatically add a patch build-requirement if there are diff files
3843 # in $local_gl_path.
3844 require_buildreq_patch=func_require_buildreq_patch
3845 func_require_buildreq_patch ()
3846 {
3847     $debug_cmd
3848
3849     $require_local_gl_path
3850
3851     # This ensures PATCH is set appropriately by the time
3852     # func_check_versions enforces $buildreq.
3853     $require_patch
3854
3855     # If patch is not already listed in $buildreq...
3856     printf '%s\n' "$buildreq" |func_grep_q '^[   ]*patch' || {
3857       eval "set dummy $local_gl_path_quoted" ; shift
3858
3859       for _G_dir
3860       do
3861         # The ugly find invocation is necessary to exit with non-zero
3862         # status for old find binaries that don't support -exec fully.
3863         if test ! -d "$_G_dir" \
3864             || find "$_G_dir" -name "*.diff" -exec false {} \; ; then :
3865         else
3866           func_append buildreq "patch - http://www.gnu.org/s/patch$nl"
3867           break
3868         fi
3869       done
3870     }
3871
3872     require_buildreq_patch=:
3873 }
3874
3875
3876 # require_buildtools_uptodate
3877 # ---------------------------
3878 # Ensure all the packages listed in BUILDREQS are available on the build
3879 # machine at the minimum versions or better.
3880 require_buildtools_uptodate=func_require_buildtools_uptodate
3881 func_require_buildtools_uptodate ()
3882 {
3883     $debug_cmd
3884
3885     $require_buildreq_autobuild
3886     $require_buildreq_autoconf
3887     $require_buildreq_automake
3888     $require_buildreq_libtoolize
3889     $require_buildreq_autopoint
3890     $require_buildreq_patch
3891
3892     test -n "$buildreq" && {
3893       _G_error_hdr=
3894
3895       func_check_versions $buildreq
3896       $func_check_versions_result || {
3897         test -n "$buildreq_readme" \
3898             && test -f "$buildreq_readme" \
3899             && _G_error_hdr="\
3900 $buildreq_readme explains how to obtain these prerequisite programs:
3901 "
3902         func_strtable 0 11 12 36 \
3903             "Program" "Min_version" "Homepage" $buildreq
3904         func_fatal_error "$_G_error_hdr$func_strtable_result"
3905       }
3906     }
3907
3908     require_buildtools_uptodate=:
3909 }
3910
3911
3912 # require_copyright_holder
3913 # ------------------------
3914 # Ensure there is a sensible non-empty default value in '$copyright_holder'.
3915 require_copyright_holder=func_require_copyright_holder
3916 func_require_copyright_holder ()
3917 {
3918     $debug_cmd
3919
3920     test -n "$copyright_holder" || {
3921       copyright_holder='Free Software Foundation, Inc.'
3922       func_warning settings "\
3923 Please set copyright_holder explicitly in 'bootstrap.conf';
3924 defaulting to '$copyright_holder'."
3925     }
3926
3927     require_copyright_holder=:
3928 }
3929
3930
3931 # require_doc_base
3932 # ----------------
3933 # Ensure doc_base has a sensible value, extracted from 'gnulib-cache.m4'
3934 # if possible, otherwise letting 'gnulib-tool' pick a default.
3935 require_doc_base=func_require_doc_base
3936 func_require_doc_base ()
3937 {
3938     $debug_cmd
3939
3940     $require_gnulib_cache
3941
3942     test -f "$gnulib_cache" && test -z "$doc_base" && {
3943       func_extract_trace_first "gl_DOC_BASE" "$gnulib_cache"
3944       doc_base=$func_extract_trace_first_result
3945
3946       test -n "$doc_base" && func_verbose "doc_base='$doc_base'"
3947     }
3948
3949     require_doc_base=:
3950 }
3951
3952
3953 # require_dotgitmodules
3954 # ---------------------
3955 # Ensure we have a '.gitmodules' file, with appropriate 'gnulib' settings.
3956 require_dotgitmodules=func_require_dotgitmodules
3957 func_require_dotgitmodules ()
3958 {
3959     $debug_cmd
3960
3961     $require_git
3962
3963     test true = "$GIT" || {
3964       # A gnulib entry in .gitmodules always takes precedence.
3965       _G_path=`$GIT config --file .gitmodules submodule.gnulib.path 2>/dev/null`
3966
3967       test -n "$_G_path" || {
3968         $require_vc_ignore_files
3969
3970         func_verbose "creating '.gitmodules'"
3971
3972         # If the .gitmodules file doesn't exist, create it now, and mark
3973         # it as ignored for the VCS.
3974         test -n "$gnulib_path" || gnulib_path=gnulib
3975         test -n "$gnulib_url"  || gnulib_url=git://git.sv.gnu.org/gnulib
3976
3977         {
3978           echo '[submodule "gnulib"]'
3979           echo "        path = $gnulib_path"
3980           echo "        url = $gnulib_url"
3981         } >> .gitmodules
3982
3983         test -n "$vc_ignore_files" \
3984           || func_insert_if_absent ".gitmodules" $vc_ignore_files
3985       }
3986     }
3987
3988     require_dotgitmodules=:
3989 }
3990
3991
3992 # require_extra_locale_categories
3993 # -------------------------------
3994 # Ensure there is a default value in '$extra_locale_categories'
3995 require_extra_locale_categories=func_require_extra_locale_categories
3996 func_require_extra_locale_categories ()
3997 {
3998     $debug_cmd
3999
4000     # Defaults to empty, so run with whatever value may have been set in
4001     # 'bootstrap.conf'.
4002     require_extra_locale_categories=:
4003 }
4004
4005
4006 # require_git
4007 # -----------
4008 # Ignore git if it's not available, or we're not in a git checkout tree.
4009 require_git=func_require_git
4010 func_require_git ()
4011 {
4012     $debug_cmd
4013
4014     $opt_skip_git && GIT=true
4015
4016     test true = "$GIT" || {
4017       if test -d .git/.; then
4018         ($GIT --version) >/dev/null 2>&1 || GIT=true
4019       fi
4020     }
4021
4022     func_verbose "GIT='$GIT'"
4023
4024     require_git=:
4025 }
4026
4027
4028 # require_gnulib_cache
4029 # --------------------
4030 # Ensure there is a non-empty default for '$gnulib_cache', and that it
4031 # names an existing file.
4032 require_gnulib_cache=func_require_gnulib_cache
4033 func_require_gnulib_cache ()
4034 {
4035     $debug_cmd
4036
4037     $require_macro_dir
4038
4039     test -n "$gnulib_cache" \
4040       || gnulib_cache=$macro_dir/gnulib-cache.m4
4041
4042     func_verbose "found '$gnulib_cache'"
4043
4044     require_gnulib_cache=:
4045 }
4046
4047
4048 # require_gnulib_copy_cmd
4049 # -----------------------
4050 # Only calculate the options for copying files with gnulib once.
4051 require_gnulib_copy_cmd=func_require_gnulib_copy_cmd
4052 func_require_gnulib_copy_cmd ()
4053 {
4054     $debug_cmd
4055
4056     $require_gnulib_tool
4057     $require_gnulib_tool_base_options
4058
4059     gnulib_copy_cmd="$gnulib_tool $gnulib_tool_base_options --copy-file"
4060     $opt_copy || func_append gnulib_copy_cmd " --symlink"
4061     $opt_quiet || func_append gnulib_copy_cmd " --verbose"
4062
4063     require_gnulib_copy_cmd=:
4064 }
4065
4066
4067 # require_gnulib_merge_changelog
4068 # ------------------------------
4069 # See if we can use gnulib's git-merge-changelog merge driver.
4070 require_gnulib_merge_changelog=func_require_gnulib_merge_changelog
4071 func_require_gnulib_merge_changelog ()
4072 {
4073     $debug_cmd
4074
4075     test -f ChangeLog && {
4076       $require_git
4077
4078       func_grep_q '^\(/\|\)ChangeLog$' .gitignore || test true = "$GIT" || {
4079         if $GIT config merge.merge-changelog.driver >/dev/null; then
4080           :
4081         elif (git-merge-changelog --version) >/dev/null 2>&1; then
4082           func_echo "initializing git-merge-changelog driver"
4083           $GIT config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
4084           $GIT config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
4085         else
4086           func_warning recommend \
4087               "Consider installing git-merge-changelog from gnulib."
4088         fi
4089       }
4090     }
4091
4092     require_gnulib_merge_changelog=:
4093 }
4094
4095
4096 # require_gnulib_mk
4097 # -----------------
4098 # Ensure gnulib_mk has a sensible value, extracted from 'gnulib-cache.m4'
4099 # if possible, otherwise letting 'gnulib-tool' pick a default.
4100 require_gnulib_mk=func_require_gnulib_mk
4101 func_require_gnulib_mk ()
4102 {
4103     $debug_cmd
4104
4105     $require_gnulib_cache
4106
4107     test -f "$gnulib_cache" && test -z "$gnulib_mk" && {
4108       func_extract_trace_first "gl_MAKEFILE_NAME" "$gnulib_cache"
4109       gnulib_mk=$func_extract_trace_first_result
4110
4111       test -n "$gnulib_mk" && func_verbose "gnulib_mk='$gnulib_mk'"
4112     }
4113
4114     require_gnulib_mk=:
4115 }
4116
4117
4118 # require_gnulib_name
4119 # -------------------
4120 # Ensure gnulib_name has a sensible value, extracted from 'gnulib-cache.m4'
4121 # if possible, otherwise letting 'gnulib-tool' pick a default.
4122 require_gnulib_name=func_require_gnulib_name
4123 func_require_gnulib_name ()
4124 {
4125     $debug_cmd
4126
4127     $require_gnulib_cache
4128
4129     test -f "$gnulib_cache" && test -z "$gnulib_name" && {
4130       func_extract_trace_first "gl_LIB" "$gnulib_cache"
4131       gnulib_name=$func_extract_trace_first_result
4132
4133       test -n "$gnulib_name" && func_verbose "gnulib_name='$gnulib_name'"
4134     }
4135
4136     require_gnulib_name=:
4137 }
4138
4139
4140 # require_gnulib_path
4141 # require_gnulib_url
4142 # -------------------
4143 # Ensure 'gnulib_path' and 'gnulib_url' are set.
4144 require_gnulib_path=func_require_dotgitmodules_parameters
4145 require_gnulib_url=func_require_dotgitmodules_parameters
4146 func_require_dotgitmodules_parameters ()
4147 {
4148     $debug_cmd
4149
4150     $require_git
4151
4152     test true = "$GIT" && {
4153       # If we can't find git (or if the user specified '--skip-git'),
4154       # then use an existing gnulib directory specified with
4155       # '--gnulib-srcdir' if possible.
4156       test -n "$gnulib_path" \
4157           || test ! -x "$opt_gnulib_srcdir/gnulib-tool" \
4158           || gnulib_path=$opt_gnulib_srcdir
4159     }
4160
4161
4162     $require_dotgitmodules
4163
4164     test -f .gitmodules && {
4165       # Extract the parameters with sed, since git may be missing
4166       test -n "$gnulib_path" \
4167         || gnulib_path=`$SED -e '/^.submodule "gnulib".$/,${
4168                                    /[    ]*path *= */{
4169                                      s|[   ]*||g;s|^[^=]*=||;p
4170                                    }
4171                                  }
4172                                  d' .gitmodules |$SED 1q`
4173       test -n "$gnulib_url" \
4174         || gnulib_url=`$SED -e '/^.submodule "gnulib".$/,${
4175                                   /[     ]*url *= */{
4176                                     s|[   ]*||g;s|^[^=]*=||;p
4177                                   }
4178                                 }
4179                                 d' .gitmodules |$SED 1q`
4180
4181       func_verbose "gnulib_path='$gnulib_path'"
4182       func_verbose "gnulib_url='$gnulib_url'"
4183     }
4184
4185     require_gnulib_path=:
4186     require_gnulib_url=:
4187 }
4188
4189
4190 # require_gnulib_submodule
4191 # ------------------------
4192 # Ensure that there is a current gnulib submodule at '$gnulib_path'.
4193 require_gnulib_submodule=func_require_gnulib_submodule
4194 func_require_gnulib_submodule ()
4195 {
4196     $debug_cmd
4197
4198     $require_git
4199
4200     if test true = "$GIT"; then
4201       func_warning recommend \
4202           "No 'git' found; imported gnulib modules may be outdated."
4203     else
4204       $require_gnulib_path
4205       $require_gnulib_url
4206
4207       if test -f .gitmodules && test -f "$gnulib_path/gnulib-tool"; then
4208         : All present and correct.
4209
4210       elif test -n "$opt_gnulib_srcdir"; then
4211         # Older git can't clone into an empty directory.
4212         rmdir "$gnulib_path" 2>/dev/null
4213         func_show_eval "$GIT clone --reference '$opt_gnulib_srcdir' \
4214                 '$gnulib_url' '$gnulib_path'" \
4215             || func_fatal_error "Unable to fetch gnulib submodule."
4216
4217       # Without --gnulib-srcdir, and no existing checked out submodule, we
4218       # create a new shallow clone of the remote gnulib repository.
4219       else
4220         trap func_cleanup_gnulib 1 2 13 15
4221
4222         shallow=
4223         test -n "$gnulib_clone_since" && \
4224             $GIT clone -h 2>&1 |func_grep_q -- --shallow-since \
4225             && shallow="--shallow-since=$gnulib_clone_since"
4226
4227         func_show_eval "$GIT clone $shallow '$gnulib_url' '$gnulib_path'" \
4228           func_cleanup_gnulib
4229
4230         # FIXME: Solaris /bin/sh will try to execute '-' if any of
4231         #        these signals are caught after this.
4232         trap - 1 2 13 15
4233       fi
4234
4235       # Make sure we've checked out the correct revision of gnulib.
4236       func_show_eval "$GIT submodule init -- $gnulib_path" \
4237           && func_show_eval "$GIT submodule update -- $gnulib_path" \
4238           ||  func_fatal_error "Unable to update gnulib submodule."
4239     fi
4240
4241     require_gnulib_submodule=:
4242 }
4243
4244
4245 # require_gnulib_tool
4246 # -------------------
4247 # Ensure that '$gnulib_tool' is set, and points to an executable file,
4248 # or else fall back to using the binary 'true' if the main gnulib
4249 # files appear to have been imported already.
4250 require_gnulib_tool=func_require_gnulib_tool
4251 func_require_gnulib_tool ()
4252 {
4253     $debug_cmd
4254
4255     test true = "$gnulib_tool" || {
4256       $require_gnulib_submodule
4257       $require_gnulib_path
4258
4259       test -n "$gnulib_tool" \
4260         || gnulib_tool=$gnulib_path/gnulib-tool
4261
4262       test -x "$gnulib_tool" || {
4263         gnulib_tool=true
4264         func_warning recommend \
4265             "No 'gnulib-tool' found; gnulib modules may be missing."
4266       }
4267
4268       test true = "$gnulib_tool" \
4269           || func_verbose "found '$gnulib_tool'"
4270     }
4271
4272     require_gnulib_tool=:
4273 }
4274
4275
4276 # require_gnulib_tool_base_options
4277 # --------------------------------
4278 # Ensure that '$gnulib_tool_base_options' contains all the base options
4279 # required according to user configuration from bootstrap.conf.
4280 require_gnulib_tool_base_options=func_require_gnulib_tool_base_options
4281 func_require_gnulib_tool_base_options ()
4282 {
4283     $debug_cmd
4284
4285     $require_gnulib_tool
4286
4287     gnulib_tool_base_options=
4288
4289     test true = "$gnulib_tool" || {
4290       # 'gnulib_modules' and others are maintained in 'bootstrap.conf':
4291       # Use 'gnulib --import' to fetch gnulib modules.
4292       $require_build_aux
4293       test -n "$build_aux" \
4294           && func_append_uniq gnulib_tool_base_options " --aux-dir=$build_aux"
4295       $require_macro_dir
4296       test -n "$macro_dir" \
4297           && func_append_uniq gnulib_tool_base_options " --m4-base=$macro_dir"
4298       $require_doc_base
4299       test -n "$doc_base" \
4300           && func_append_uniq gnulib_tool_base_options " --doc-base=$doc_base"
4301       $require_gnulib_name
4302       test -n "$gnulib_name" \
4303           && func_append_uniq gnulib_tool_base_options " --lib=$gnulib_name"
4304       $require_local_gl_path
4305       test -n "$local_gl_path" && {
4306         eval "set dummy $local_gl_path_quoted" ; shift
4307         for _G_dir
4308         do
4309           func_append_uniq gnulib_tool_base_options " --local-dir=$_G_dir"
4310         done
4311       }
4312       $require_source_base
4313       test -n "$source_base" \
4314           && func_append_uniq gnulib_tool_base_options " --source-base=$source_base"
4315     }
4316
4317     require_gnulib_tool_base_options=:
4318 }
4319
4320
4321 # require_libtoolize
4322 # ------------------
4323 # Skip libtoolize if it's not needed.
4324 require_libtoolize=func_require_libtoolize
4325 func_require_libtoolize ()
4326 {
4327     $debug_cmd
4328
4329     # Unless we're not searching for libtool use by this package, set
4330     # LIBTOOLIZE to true if none of 'LT_INIT', 'AC_PROG_LIBTOOL' and
4331     # 'AM_PROG_LIBTOOL' are used in configure.
4332     test true = "$LIBTOOLIZE" || {
4333       func_extract_trace LT_INIT
4334       test -n "$func_extract_trace_result" || func_extract_trace AC_PROG_LIBTOOL
4335       test -n "$func_extract_trace_result" || func_extract_trace AM_PROG_LIBTOOL
4336       test -n "$func_extract_trace_result" || LIBTOOLIZE=true
4337     }
4338
4339     test -n "$LIBTOOLIZE" || {
4340       # Find libtoolize, named glibtoolize in Mac Ports, but prefer
4341       # user-installed libtoolize to ancient glibtoolize shipped by
4342       # Apple with Mac OS X when Mac Ports is not installed.
4343       func_find_tool LIBTOOLIZE libtoolize glibtoolize
4344     }
4345
4346     test -n "$LIBTOOLIZE" || func_fatal_error "\
4347 Please install GNU Libtool, or 'export LIBTOOLIZE=/path/to/libtoolize'."
4348
4349     func_verbose "export LIBTOOLIZE='$LIBTOOLIZE'"
4350
4351     # Make sure the search result is visible to subshells
4352     export LIBTOOLIZE
4353
4354     require_libtoolize=:
4355 }
4356
4357
4358 # require_local_gl_path
4359 # ---------------------
4360 # Ensure local_gl_path has a sensible value, extracted from 'gnulib-cache.m4' if
4361 # possible, otherwise letting 'gnulib-tool' pick a default.
4362 require_local_gl_path=func_require_local_gl_path
4363 func_require_local_gl_path ()
4364 {
4365     $debug_cmd
4366
4367     $require_gnulib_cache
4368
4369     # Compat with older bootstrap versions.
4370     test -n "$local_gl_dir" && {
4371       func_warning settings "\
4372 Please use 'local_gl_path' instead of 'local_gl_dir' in your
4373 'bootstrap.conf' file."
4374       local_gl_path=$local_gl_dir
4375       local_gl_dir=
4376     }
4377
4378     test -f "$gnulib_cache" && test -z "$local_gl_path" && {
4379       func_extract_trace_first "gl_LOCAL_DIR" "$gnulib_cache"
4380       local_gl_path=$func_extract_trace_first_result
4381       test -n "$local_gl_path" && func_verbose "local_gl_path='$local_gl_path'"
4382     }
4383
4384     test -z "$local_gl_path_quoted" && test -n "$local_gl_path" && {
4385       save_IFS=$IFS
4386       set dummy
4387       # Don't use PATH_SEPARATOR here, gnulib must be fixed to store only ':' as
4388       # path separator into gnulib-cache.m4 (consistency reasons among systems).
4389       IFS=:
4390       for _G_dir in $local_gl_path
4391       do
4392         set "$@" "$_G_dir"
4393       done
4394       shift
4395       IFS=$save_IFS
4396       func_quote eval "$@"
4397       local_gl_path_quoted=$func_quote_result
4398     }
4399
4400     require_local_gl_path=:
4401 }
4402
4403
4404 # require_macro_dir
4405 # -----------------
4406 # Ensure that '$macro_dir' is set, and if it doesn't already point to an
4407 # existing directory, create one.
4408 require_macro_dir=func_require_macro_dir
4409 func_require_macro_dir ()
4410 {
4411     $debug_cmd
4412
4413     # Sometimes this is stored in 'configure.ac'.
4414     test -n "$macro_dir" || {
4415       # AC_CONFIG_MACRO_DIRS takes a space delimited list of directories,
4416       # but we only care about the first one in bootstrap.
4417       func_extract_trace_first AC_CONFIG_MACRO_DIRS
4418       macro_dir=`expr "x$func_extract_trace_first_result" : 'x\([^       ]*\)'`
4419     }
4420     test -n "$macro_dir" || {
4421       func_extract_trace_first AC_CONFIG_MACRO_DIR
4422       macro_dir=$func_extract_trace_first_result
4423     }
4424
4425     # Otherwise we might find it in 'Makefile.am'.
4426     test -n "$macro_dir" || {
4427       $require_aclocal_amflags
4428
4429       # Take the argument following the first '-I', if any.
4430       _G_minus_I_seen=false
4431       for _G_arg in $aclocal_amflags; do
4432         case $_G_minus_I_seen,$_G_arg in
4433           :,*)   macro_dir=$_G_arg; break ;;
4434           *,-I)  _G_minus_I_seen=: ;;
4435           *,-I*) macro_dir=`expr x$_G_arg : 'x-I\(.*\)$'`; break ;;
4436         esac
4437       done
4438     }
4439
4440     func_verbose "macro_dir='$macro_dir'"
4441
4442     func_check_configuration macro_dir \
4443         "AC_CONFIG_MACRO_DIRS([name of a directory for configure m4 files])"
4444
4445     $require_vc_ignore_files
4446
4447     # If the macro_dir directory doesn't exist, create it now, and mark it
4448     # as ignored for the VCS.
4449     if test ! -d "$macro_dir"; then
4450       mkdir "$macro_dir" || func_permissions_error "$macro_dir"
4451
4452       test -n "$vc_ignore_files" \
4453         || func_insert_if_absent "$macro_dir" $vc_ignore_files
4454     fi
4455
4456     require_macro_dir=:
4457 }
4458
4459
4460 # require_makefile_am
4461 # -------------------
4462 # Ensure there is a 'Makefile.am' in the current directory.
4463 require_makefile_am=func_require_makefile_am
4464 func_require_makefile_am ()
4465 {
4466     $debug_cmd
4467
4468     test -n "$makefile_am" \
4469       || makefile_am=Makefile.am
4470
4471     <"$makefile_am"
4472
4473     func_verbose "found '$makefile_am'"
4474
4475     require_makefile_am=:
4476 }
4477
4478
4479 # require_package
4480 # ---------------
4481 # Ensure that '$package' contains a sensible default value.
4482 require_package=func_require_package
4483 func_require_package ()
4484 {
4485     $debug_cmd
4486
4487     test -n "$package" || {
4488       $require_package_name
4489
4490       package=`echo "$package_name" \
4491         |$SED -e 's/GNU //' \
4492               -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
4493     }
4494
4495     func_verbose "package='$package'"
4496
4497     require_package=:
4498 }
4499
4500
4501 # require_package_bugreport
4502 # -------------------------
4503 # Ensure that this has a sensible value, extracted from 'configure.ac'
4504 # if appropriate (and possible!).
4505 require_package_bugreport=func_require_package_bugreport
4506 func_require_package_bugreport ()
4507 {
4508     $debug_cmd
4509
4510     func_extract_trace AC_INIT
4511
4512     save_ifs=$IFS
4513     IFS=:
4514     set dummy $func_extract_trace_result
4515     IFS=$save_ifs
4516     shift
4517
4518     test -n "$package_bugreport" || package_bugreport=$3
4519     func_check_configuration package_bugreport \
4520       "AC_INIT([$package_name], [$package_version], [bug-$package@gnu.org])"
4521     func_verbose "package_bugreport='$package_bugreport'"
4522
4523     require_package_bugreport=:
4524 }
4525
4526
4527 # require_package_name
4528 # --------------------
4529 # Ensure that this has a sensible value, extracted from 'configure.ac'
4530 # if appropriate (and possible!).
4531 require_package_name=func_require_package_name
4532 func_require_package_name ()
4533 {
4534     $debug_cmd
4535
4536     func_extract_trace AC_INIT
4537
4538     save_ifs=$IFS
4539     IFS=:
4540     set dummy $func_extract_trace_result
4541     IFS=$save_ifs
4542     shift
4543
4544     test -n "$package_name" || package_name=$1
4545     func_check_configuration package_name \
4546       "AC_INIT([name of your package], [package version number])"
4547     func_verbose "package_name='$package_name'"
4548
4549     require_package_name=:
4550 }
4551
4552
4553 # require_package_version
4554 # -----------------------
4555 # Ensure that this has a sensible value, extracted from 'configure.ac'
4556 # if appropriate (and possible!).  While we might have set all the
4557 # parameters extracted from AC_INIT at once, 'package_version' in
4558 # particular is not necessarily available as early as the others, since
4559 # 'git-version-gen' is often involved, and until then we can't rely on
4560 # getting a correct version number from an AC_INIT extraction.
4561 require_package_version=func_require_package_version
4562 func_require_package_version ()
4563 {
4564     $debug_cmd
4565
4566     func_extract_trace AC_INIT
4567
4568     save_ifs=$IFS
4569     IFS=:
4570     set dummy $func_extract_trace_result
4571     IFS=$save_ifs
4572     shift
4573
4574     test -n "$package_version" || package_version=$2
4575     test -n "$package_version" || {
4576       # The embedded echo is to squash whitespace before globbing.
4577       case " "`echo $gnulib_modules`" " in
4578         *" git-version-gen "*)
4579           func_fatal_error "\
4580 cannot \$require_package_version in bootstrap.conf before
4581 func_gnulib_tool has installed the 'git-version-gen' script."
4582           ;;
4583         *)
4584           func_check_configuration package_version \
4585             "AC_INIT([name of your package], [package version number])"
4586           ;;
4587       esac
4588     }
4589     func_verbose "package_version='$package_version'"
4590
4591     require_package_version=:
4592 }
4593
4594
4595 # require_patch
4596 # -------------
4597 # Find patch, according to the PATCH environment variable, or else
4598 # searching the user's PATH.
4599 require_patch=func_require_patch
4600 func_require_patch ()
4601 {
4602     $debug_cmd
4603
4604     test -n "$PATCH" || {
4605       # Find a patch program, preferring gpatch, which is usually better
4606       # than the vendor patch.
4607       func_find_tool PATCH gpatch patch
4608     }
4609
4610     test -n "$PATCH" || func_fatal_error "\
4611 Please install GNU Patch, or 'export PATCH=/path/to/gnu/patch'."
4612
4613     func_verbose "export PATCH='$PATCH'"
4614
4615     # Make sure the search result is visible to subshells
4616     export PATCH
4617
4618     require_patch=:
4619 }
4620
4621
4622 # require_source_base
4623 # -------------------
4624 # Ensure that source_base has a sensible value, extracted from
4625 # 'gnulib-cache.m4' if possible.
4626 require_source_base=func_require_source_base
4627 func_require_source_base ()
4628 {
4629     $debug_cmd
4630
4631     $require_gnulib_cache
4632
4633     test -f "$gnulib_cache" && test -z "$source_base" && {
4634       func_extract_trace_first "gl_SOURCE_BASE" "$gnulib_cache"
4635
4636       source_base=$func_extract_trace_first_result
4637
4638       func_verbose "source_base='$source_base'"
4639     }
4640
4641     require_source_base=:
4642 }
4643
4644
4645 # require_vc_ignore_files
4646 # -----------------------
4647 # Ensure that '$vc_ignore' has been processed to list VCS ignore files
4648 # in '$vc_ignore_files'
4649 require_vc_ignore_files=func_require_vc_ignore_files
4650 func_require_vc_ignore_files ()
4651 {
4652     $debug_cmd
4653
4654     test -n "$vc_ignore" || vc_ignore=auto
4655
4656     if test auto = "$vc_ignore" && test -z "$vc_ignore_files"; then
4657       vc_ignore_files=
4658       test -d .git && vc_ignore_files=.gitignore
4659       test -d CVS && vc_ignore_files="$vc_ignore_files .cvsignore"
4660     else
4661       vc_ignore_files=$vc_ignore
4662     fi
4663
4664     func_verbose "vc_ignore_files='$vc_ignore_files'"
4665
4666     require_vc_ignore_files=:
4667 }
4668
4669
4670 ## ----------------- ##
4671 ## Helper functions. ##
4672 ## ----------------- ##
4673
4674 # This section contains the helper functions used by the rest of 'bootstrap'.
4675
4676 # func_len STRING
4677 # ---------------
4678 # STRING may not start with a hyphen.
4679 if (eval 'x=123; test x${#x} = "x3"') 2>/dev/null
4680 then
4681   # This is an XSI compatible shell, allowing a faster implementation...
4682   eval 'func_len ()
4683   {
4684     $debug_cmd
4685
4686     func_len_result=${#1}
4687   }'
4688 else
4689   # ...otherwise fall back to using expr, which is often a shell builtin.
4690   func_len ()
4691   {
4692     $debug_cmd
4693
4694     func_len_result=`expr "$1" : ".*" 2>/dev/null || echo 0`
4695   }
4696 fi
4697
4698
4699 # func_cmp_s FILE1 FILE2
4700 # ----------------------
4701 # Return non-zero exit status unless FILE1 and FILE2 are identical, without
4702 # any output at all, even error messages.
4703 func_cmp_s ()
4704 {
4705     $debug_cmd
4706
4707     # This function relies on non-zero exit status, which will cause the
4708     # program to exit when running in 'set -e' mode.
4709     $CMP "$@" >/dev/null 2>&1
4710 }
4711
4712
4713 # func_grep_q EXPRESSION [FILENAME..]
4714 # -----------------------------------
4715 # Check whether EXPRESSION matches any line of any listed FILENAME,
4716 # without any output at all, even error messages.
4717 func_grep_q ()
4718 {
4719     $debug_cmd
4720
4721     # This function relies on non-zero exit status, which will cause the
4722     # program to exit when running in 'set -e' mode.
4723     $GREP "$@" >/dev/null 2>&1
4724 }
4725
4726
4727 # func_ifcontains LIST MEMBER YES-CMD [NO-CMD]
4728 # --------------------------------------------
4729 # If whitespace-separated LIST contains MEMBER then execute YES-CMD,
4730 # otherwise if NO-CMD was given, execute that.
4731 func_ifcontains ()
4732 {
4733     $debug_cmd
4734
4735     _G_wslist=$1
4736     _G_member=$2
4737     _G_yes_cmd=$3
4738     _G_no_cmd=${4-":"}
4739
4740     _G_found=false
4741     for _G_item in $_G_wslist; do
4742       test "x$_G_item" = "x$_G_member" && {
4743         _G_found=:
4744         break
4745       }
4746     done
4747     if $_G_found; then
4748       eval "$_G_yes_cmd"
4749       _G_status=$?
4750     else
4751       eval "$_G_no_cmd"
4752       _G_status=$?
4753     fi
4754
4755     test 0 -eq "$_G_status" || exit $_G_status
4756 }
4757
4758
4759 # func_strpad STR WIDTH CHAR
4760 # --------------------------
4761 # Trim STR, or pad with CHAR to force a total length of WIDTH.
4762 func_strpad ()
4763 {
4764     $debug_cmd
4765
4766     _G_width=`expr "$2" - 1`
4767     func_strpad_result=`$ECHO "$1" |$SED '
4768         :a
4769         s|^.\{0,'"$_G_width"'\}$|&'"$3"'|
4770         ta
4771     '`
4772 }
4773
4774
4775 # func_strrpad STR WIDTH CHAR
4776 # ---------------------------
4777 # Trim STR, or right-justify-pad with CHAR to force a total length of
4778 # WIDTH.
4779 func_strrpad ()
4780 {
4781     $debug_cmd
4782
4783     _G_width=`expr "$2" - 1`
4784     func_strrpad_result=`$ECHO "$1" |$SED '
4785         :a
4786         s|^.\{0,'"$_G_width"'\}$|'"$3"'&|
4787         ta
4788     '`
4789 }
4790
4791
4792 # func_strrow INDENT FIELD WIDTH [FIELDn WIDTHn]...
4793 # -------------------------------------------------
4794 # Return a string containing each FIELD left justified to WIDTH, with
4795 # the whole thing indented by INDENT spaces.  This function is used to
4796 # render one row of aligned columns for a table by func_strtable().
4797 func_strrow ()
4798 {
4799     $debug_cmd
4800
4801     func_strrow_linelen=$1; shift
4802
4803     _G_row=
4804     while test $# -gt 0; do
4805       func_strrow_linelen=`expr $func_strrow_linelen + $2`
4806       func_strpad "$1" $2 " "
4807       func_append _G_row "$func_strpad_result"
4808       shift; shift
4809     done
4810
4811     func_strrpad "$_G_row" $func_strrow_linelen " "
4812     func_strrow_result=$func_strrpad_result
4813 }
4814
4815
4816 # func_strtable INDENT WIDTH1...WIDTHn HEADER1...HEADERn FIELD1...FIELDn
4817 # ----------------------------------------------------------------------
4818 # Generate a string of newline-separated rows arranged in lined-up
4819 # columns of the given WIDTHs, with the entire table indented by INDENT
4820 # spaces.  The number of columns is determined by the number of integer
4821 # valued WIDTH arguments following INDENT.  The next set (i.e. a number
4822 # of arguments equal to the number of WIDTH arguments) of fields are
4823 # treated as the table's column HEADERs, and are separated from the
4824 # remainder of the table by an indented row of '-' characters. Remaining
4825 # arguments are each aligned below the next available header, wrapping
4826 # to a new row as necessary.  Finally another row of '-' characters is
4827 # added to mark the end of the table.
4828 #
4829 # For example an unindented 3 column table with 2 rows of data would be
4830 # generated by this call:
4831 #
4832 #    func_strtable 3 20 10 25 \
4833 #        Header1 Header2 Header3 \
4834 #        Row1Col1 Row1Col2 Row1Col3 \
4835 #        Row2Col1 Row2Col2 Row2Col3
4836 #
4837 # returning the following string:
4838 #
4839 # "   Header1             Header2   Header3
4840 #     -------------------------------------------------------
4841 #     Row1Col1            Row1Col2  Row1Col3
4842 #     Row2Col1            Row2Col2  Row2Col3
4843 #     -------------------------------------------------------"
4844 func_strtable ()
4845 {
4846     $debug_cmd
4847
4848     # Save the indent value, we'll need it for each row we render.
4849     _G_indent=$1; shift
4850
4851     # Collect remaining numeric args into a list for reuse between
4852     # members of each row when we call func_strrow later.
4853     _G_widths=$1; shift
4854     while test 0 -lt `expr "$1" : '[1-9][0-9]*$'`; do
4855       func_append _G_widths " $1"; shift
4856     done
4857
4858     # Extract the same number of positional parameters as there are
4859     # width elements - we'll do the header rows separately so that
4860     # we can insert a divider line.
4861     _G_header=$_G_indent
4862     for _G_width in $_G_widths; do
4863       func_append _G_header " $1 $_G_width"; shift
4864     done
4865     func_strrow $_G_header
4866
4867     # Strip off the indent, and make a divider with '-' chars, then
4868     # reindent.
4869     _G_divider=`$ECHO "$func_strrow_result" \
4870         |$SED 's|[^ ]|-|g
4871             :a
4872             s|- |--|g
4873             ta
4874         '`
4875
4876     # Append the header and divider to the running result.
4877     func_append func_strtable_result "\
4878 $func_strrow_result
4879 $_G_divider
4880 "
4881
4882     # The remaining rows are zipped between the width values we
4883     # unwound earlier just like the header row above.
4884     while test $# -gt 0; do
4885       _G_row=$_G_indent
4886       for _G_width in $_G_widths; do
4887         func_append _G_row " $1 $_G_width"; shift
4888       done
4889       func_strrow $_G_row
4890       func_append func_strtable_result "\
4891 $func_strrow_result
4892 "
4893     done
4894
4895     # Mark the end of the table with a final divider line.
4896     func_append func_strtable_result "$_G_divider"
4897 }
4898
4899
4900 # func_internal_error ARG...
4901 # --------------------------
4902 # Echo program name prefixed message to standard error, and exit.
4903 func_internal_error ()
4904 {
4905     func_fatal_error "\
4906 INTERNAL: " ${1+"$@"} "
4907           Please report this bug to 'bug-gnulib@gnu.org'
4908           in as much detail as possible."
4909 }
4910
4911
4912 # func_permissions_error FILE-OR-DIRECTORY
4913 # ----------------------------------------
4914 # Echo program name prefixed permissions error message to standard
4915 # error, and exit.
4916 func_permissions_error ()
4917 {
4918     $debug_cmd
4919
4920     func_fatal_error "Failed to create '$1', check permissions."
4921 }
4922
4923
4924 # func_show_eval CMD [FAIL_EXP]
4925 # -----------------------------
4926 # Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
4927 # not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
4928 # is given, then evaluate it.
4929 func_show_eval ()
4930 {
4931     $debug_cmd
4932
4933     $require_term_colors
4934
4935     _G_cmd=$1
4936     _G_fail_exp=${2-':'}
4937
4938     ${opt_silent-'false'} || {
4939       func_quote eval $_G_cmd
4940       eval func_truncate_cmd $func_quote_result
4941       func_echo "running: $tc_bold$func_truncate_cmd_result$tc_reset"
4942     }
4943
4944     ${opt_dry_run-'false'} || {
4945       eval "$_G_cmd"
4946       _G_status=$?
4947       test 0 -eq "$_G_status" || eval "(exit $_G_status); $_G_fail_exp"
4948     }
4949 }
4950
4951
4952 # func_truncate_cmd CMD [ARG]...
4953 # ------------------------------
4954 # For unreasonably long commands (such as a gnulib-tool invocation with
4955 # the full module list for import), truncate CMD after the second non-
4956 # option ARG.
4957 func_truncate_cmd ()
4958 {
4959     $debug_cmd
4960
4961     _G_last_arg_opt_p=false
4962     func_truncate_cmd_result=
4963
4964     set dummy "$@"; shift
4965
4966     while test $# -gt 0; do
4967       _G_opt=$1; shift
4968
4969       test -n "$func_truncate_cmd_result" \
4970           && func_append func_truncate_cmd_result ' '
4971       func_append func_truncate_cmd_result "$_G_opt"
4972
4973       func_len "x$func_truncate_cmd_result"
4974
4975       case $_G_opt in
4976         -*) _G_last_arg_opt_p=: ;;
4977         *)  $_G_last_arg_opt_p \
4978                 || test "$min_cmd_len" -gt "$func_len_result" \
4979                 || break
4980             _G_last_arg_opt_p=false
4981             ;;
4982       esac
4983     done
4984
4985     test $# -gt 0 && func_append func_truncate_cmd_result "..."
4986 }
4987
4988
4989 # func_gitignore_entries FILE...
4990 # ------------------------------
4991 # Strip blank and comment lines to leave significant entries.
4992 func_gitignore_entries ()
4993 {
4994     $debug_cmd
4995
4996     $SED -e '/^#/d' -e '/^$/d' "$@"
4997 }
4998
4999
5000 # func_insert_if_absent STR FILE...
5001 # ---------------------------------
5002 # If $STR is not already on a line by itself in $FILE, insert it, at the
5003 # start.  Entries are inserted at the start of the ignore list to ensure
5004 # existing entries starting with ! are not overridden.  Such entries
5005 # support whilelisting exceptions after a more generic blacklist pattern.
5006 # sorting the new contents of the file and replacing $FILE with the result.
5007 func_insert_if_absent ()
5008 {
5009     $debug_cmd
5010
5011     str=$1
5012     shift
5013
5014     for file
5015     do
5016       test -f "$file" || touch "$file"
5017
5018       duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
5019       test -n "$duplicate_entries" \
5020           && func_error "duplicate entries in $file: " $duplicate_entries
5021
5022       func_grep_q "^$str\$" "$file" \
5023           || func_verbose "inserting '$str' into '$file'"
5024
5025       linesold=`func_gitignore_entries "$file" |wc -l`
5026       linesnew=`{ $ECHO "$str"; cat "$file"; } \
5027                 |func_gitignore_entries |sort -u |wc -l`
5028       test "$linesold" -eq "$linesnew" \
5029         || { $SED "1i\\$nl$str$nl" "$file" >"$file"T && mv "$file"T "$file"; } \
5030         || func_permissions_error "$file"
5031     done
5032 }
5033
5034
5035 # func_get_version APP
5036 # --------------------
5037 # echo the version number (if any) of APP, which is looked up along your
5038 # PATH.
5039 func_get_version ()
5040 {
5041     $debug_cmd
5042
5043     _G_app=$1
5044
5045     # Rather than uncomment the sed script in-situ, strip the comments
5046     # programatically before passing the result to $SED for evaluation.
5047     sed_get_version=`$ECHO '# extract version within line
5048           s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
5049           t done
5050
5051           # extract version at start of line
5052           s|^\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
5053           t done
5054
5055           d
5056
5057           :done
5058           # the following essentially does s|5.005|5.5|
5059           s|\.0*\([1-9]\)|.\1|g
5060           p
5061           q' \
5062     |$SED '/^[   ]*#.*$/d'`
5063
5064     func_tool_version_output $_G_app >/dev/null
5065     _G_status=$?
5066
5067     test 0 -ne "$_G_status" \
5068       || $_G_app --version 2>&1 |$SED -n "$sed_get_version"
5069
5070     (exit $_G_status)
5071 }
5072
5073
5074 # func_check_tool APP
5075 # -------------------
5076 # Search PATH for an executable at APP.
5077 func_check_tool ()
5078 {
5079     $debug_cmd
5080
5081     func_check_tool_result=
5082
5083     case $1 in
5084     *[\\/]*)
5085       test -x "$1" && func_check_tool_result=$1
5086       ;;
5087     *)
5088       save_IFS=$IFS
5089       IFS=${PATH_SEPARATOR-:}
5090       for _G_check_tool_path in $PATH; do
5091         IFS=$save_IFS
5092         if test -x "$_G_check_tool_path/$1"; then
5093           func_check_tool_result=$_G_check_tool_path/$1
5094           break
5095         fi
5096       done
5097       IFS=$save_IFS
5098       ;;
5099     esac
5100 }
5101
5102
5103 # func_check_versions APP1 VER1 URL1 ...[APPN VERN URLN]
5104 # ------------------------------------------------------
5105 func_check_versions ()
5106 {
5107     $debug_cmd
5108
5109     func_check_versions_result=:
5110
5111     while test $# -gt 0; do
5112       _G_app=$1; shift
5113       _G_reqver=$1; shift
5114       _G_url=$1; shift
5115
5116       # Diagnose bad buildreq formatting.
5117       case $_G_url in
5118       [a-z]*://*) ;; # looks like a url
5119       *) func_fatal_error "\
5120 '$_G_url' from the buildreq table in
5121 'bootstrap.conf' does not look like the URL for downloading
5122 $_G_app. Please ensure that buildreq is a strict newline
5123 delimited list of triples; 'program min-version url'."
5124         ;;
5125       esac
5126
5127       # Honor $APP variables ($TAR, $AUTOCONF, etc.)
5128       _G_appvar=`echo $_G_app |tr '[a-z]' '[A-Z]'`
5129       test TAR = "$_G_appvar" && _G_appvar=AMTAR
5130       eval "_G_app=\${$_G_appvar-$_G_app}"
5131
5132       # Fail if no version specified, but the program can't be found.
5133       if test x- = "x$_G_reqver"; then
5134         func_check_tool $_G_app
5135         if test -z "$func_check_tool_result"; then
5136           func_error "Prerequisite '$_G_app' not not found. Please install it, or
5137 'export $_G_appvar=/path/to/$_G_app'."
5138           func_check_versions_result=false
5139         else
5140           func_verbose "found '$func_check_tool_result' for $_G_appvar."
5141         fi
5142       else
5143         _G_instver=`func_get_version $_G_app`
5144
5145         # Fail if --version didn't work.
5146         if test -z "$_G_instver"; then
5147           func_error "Prerequisite '$_G_app' not found. Please install it, or
5148 'export $_G_appvar=/path/to/$_G_app'."
5149           func_check_versions_result=false
5150
5151         # Fail if a newer version than what we have is required.
5152         else
5153           func_verbose "found '$_G_app' version $_G_instver."
5154
5155           case $_G_reqver in
5156             =*)
5157               # If $buildreq version starts with '=', version must
5158               # match the installed program exactly.
5159               test "x$_G_reqver" = "x=$_G_instver" || {
5160                 func_error "\
5161   '$_G_app' version == $_G_instver is too old
5162   'exactly $_G_app-$_G_reqver is required"
5163                 func_check_versions_result=false
5164               }
5165               ;;
5166             *)
5167               # Otherwise, anything that is not older is a match.
5168               func_lt_ver "$_G_reqver" "$_G_instver" || {
5169                 func_error "\
5170   '$_G_app' version == $_G_instver is too old
5171   '$_G_app' version >= $_G_reqver is required"
5172             func_check_versions_result=false
5173               }
5174               ;;
5175           esac
5176         fi
5177       fi
5178     done
5179 }
5180
5181
5182 # func_cleanup_gnulib
5183 # -------------------
5184 # Recursively delete everything below the path in the global variable
5185 # GNULIB_PATH.
5186 func_cleanup_gnulib ()
5187 {
5188     $debug_cmd
5189
5190     _G_status=$?
5191     $RM -fr "$gnulib_path"
5192     exit $_G_status
5193 }
5194
5195
5196 # func_download_po_files SUBDIR DOMAIN
5197 # ------------------------------------
5198 func_download_po_files ()
5199 {
5200     $debug_cmd
5201
5202     func_echo "getting translations into $1 for $2..."
5203     _G_cmd=`printf "$po_download_command_format" "$2" "$1"`
5204     eval "$_G_cmd"
5205 }
5206
5207
5208 # func_update_po_files PO_DIR DOMAIN
5209 # ----------------------------------
5210 # Mirror .po files to $po_dir/.reference and copy only the new
5211 # or modified ones into $po_dir.  Also update $po_dir/LINGUAS.
5212 # Note po files that exist locally only are left in $po_dir but will
5213 # not be included in LINGUAS and hence will not be distributed.
5214 func_update_po_files ()
5215 {
5216     $debug_cmd
5217
5218     # Directory containing primary .po files.
5219     # Overwrite them only when we're sure a .po file is new.
5220     _G_po_dir=$1
5221     _G_domain=$2
5222
5223     # Mirror *.po files into this dir.
5224     # Usually contains *.s1 checksum files.
5225     _G_ref_po_dir=$_G_po_dir/.reference
5226
5227     test -d "$_G_ref_po_dir" || mkdir $_G_ref_po_dir || return
5228     func_download_po_files $_G_ref_po_dir $_G_domain \
5229       && ls "$_G_ref_po_dir"/*.po 2>/dev/null \
5230          |$SED -e 's|.*/||' -e 's|\.po$||' > "$_G_po_dir/LINGUAS" || return
5231
5232     # Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6+.
5233     func_find_tool SHA1SUM sha1sum gsha1sum shasum sha1
5234
5235     test -n "$SHA1SUM" || func_fatal_error "\
5236 Please install GNU Coreutils, or 'export SHA1SUM=/path/to/sha1sum'."
5237
5238     _G_langs=`cd $_G_ref_po_dir && echo *.po|$SED 's|\.po||g'`
5239     test '*' = "$_G_langs" && _G_langs=x
5240     for _G_po in $_G_langs; do
5241       case $_G_po in x) continue;; esac
5242       _G_new_po=$_G_ref_po_dir/$_G_po.po
5243       _G_cksum_file=$_G_ref_po_dir/$_G_po.s1
5244       if ! test -f "$_G_cksum_file" ||
5245           ! test -f "$_G_po_dir/$_G_po.po" ||
5246           ! $SHA1SUM -c "$_G_cksum_file" \
5247               < "$_G_new_po" > /dev/null; then
5248         echo "updated $_G_po_dir/$_G_po.po..."
5249         cp "$_G_new_po" "$_G_po_dir/$_G_po.po" \
5250           && $SHA1SUM < "$_G_new_po" > "$_G_cksum_file" || return
5251       fi
5252     done
5253 }
5254
5255
5256
5257 ## --------------- ##
5258 ## Option parsing. ##
5259 ## --------------- ##
5260
5261 # Hook in the functions to make sure our own options are parsed during
5262 # the option parsing loop.
5263
5264 usage='$progpath [OPTION]...'
5265
5266 # Short help message in response to '-h'.  Add to this in 'bootstrap.conf'
5267 # if you accept any additional options.
5268 usage_message="Common Bootstrap Options:
5269    -c, --copy         copy files instead of creating symbolic links.
5270        --debug        enable verbose shell tracing
5271    -n, --dry-run      print commands rather than running them
5272    -f, --force        attempt to bootstrap even if the sources seem not
5273                       to have been checked out.
5274        --gnulib-srcdir=DIRNAME
5275                       specify a local directory where gnulib sources
5276                       reside. Use this if you already have the gnulib
5277                       sources on your machine, and don't want to waste
5278                       your bandwidth downloading them again.  Defaults to
5279                       \$GNULIB_SRCDIR.
5280        --no-warnings  equivalent to '-Wnone'
5281        --skip-git     do not fetch files from remote repositories
5282        --skip-po      do not download po files.
5283    -v, --verbose      verbosely report processing
5284        --version      print version information and exit
5285    -W, --warnings=CATEGORY
5286                       report the warnings falling in CATEGORY [all]
5287    -h, --help         print short or long help message and exit
5288 "
5289
5290 # Additional text appended to 'usage_message' in response to '--help'.
5291 long_help_message=$long_help_message"
5292        'recommend'    show warnings about missing recommended packages
5293        'settings'     show warnings about missing '$progname.conf' settings
5294        'upgrade'      show warnings about out-dated files
5295
5296 If the file '$progname.conf' exists in the same directory as this
5297 script, its contents are read as shell variables to configure the
5298 bootstrap.
5299
5300 For build prerequisites, environment variables like \$AUTOCONF and
5301 \$AMTAR are honored.
5302
5303 Running without arguments will suffice in most cases.
5304 "
5305
5306 # Warning categories used by 'bootstrap', append others if you use them
5307 # in your 'bootstrap.conf'.
5308 warning_categories='recommend settings upgrade'
5309
5310
5311 # bootstrap_options_prep [ARG]...
5312 # -------------------------------
5313 # Preparation for options parsed by Bootstrap.
5314 bootstrap_options_prep ()
5315 {
5316     $debug_cmd
5317
5318     # Option defaults:
5319     opt_copy=${copy-'false'}
5320     opt_dry_run=false
5321     opt_force=false
5322     opt_gnulib_srcdir=$GNULIB_SRCDIR
5323     opt_skip_git=false
5324     opt_skip_po=false
5325
5326     # Pass back the list of options we consumed.
5327     func_quote eval ${1+"$@"}
5328     bootstrap_options_prep_result=$func_quote_result
5329 }
5330 func_add_hook func_options_prep bootstrap_options_prep
5331
5332
5333 # bootstrap_parse_options [ARG]...
5334 # --------------------------------
5335 # Provide handling for Bootstrap specific options.
5336 bootstrap_parse_options ()
5337 {
5338     $debug_cmd
5339
5340     # Perform our own loop to consume as many options as possible in
5341     # each iteration.
5342     while test $# -gt 0; do
5343       _G_opt=$1
5344       shift
5345       case $_G_opt in
5346         --dry-run|--dryrun|-n)
5347                       opt_dry_run=: ;;
5348         --copy|-c)    opt_copy=: ;;
5349         --force|-f)   opt_force=: ;;
5350
5351         --gnulib-srcdir)
5352                       test $# = 0 && func_missing_arg $_G_opt && break
5353                       opt_gnulib_srcdir=$1
5354                       shift
5355                       ;;
5356
5357         --skip-git|--no-git)
5358                       opt_skip_git=:
5359                       ;;
5360
5361         --skip-po|--no-po)
5362                       opt_skip_po=:
5363                       ;;
5364
5365         # Separate non-argument short options:
5366         -c*|-f*|-n*)
5367                       func_split_short_opt "$_G_opt"
5368                       set dummy "$func_split_short_opt_name" \
5369                           "-$func_split_short_opt_arg" ${1+"$@"}
5370                       shift
5371                       ;;
5372
5373         *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
5374       esac
5375     done
5376
5377     # save modified positional parameters for caller
5378     func_quote eval ${1+"$@"}
5379     bootstrap_parse_options_result=$func_quote_result
5380 }
5381 func_add_hook func_parse_options bootstrap_parse_options
5382
5383
5384 # bootstrap_validate_options [ARG]...
5385 # -----------------------------------
5386 # Perform any sanity checks on option settings and/or unconsumed
5387 # arguments.
5388 bootstrap_validate_options ()
5389 {
5390     $debug_cmd
5391
5392     # Validate options.
5393     test $# -gt 0 \
5394         && func_fatal_help "too many arguments"
5395
5396     # Pass back the (empty) list of unconsumed options.
5397     func_quote eval ${1+"$@"}
5398     bootstrap_validate_options_result=$func_quote_result
5399 }
5400 func_add_hook func_validate_options bootstrap_validate_options
5401
5402
5403 ## -------------------------------------------------- ##
5404 ## Source package customisations in 'bootstrap.conf'. ##
5405 ## -------------------------------------------------- ##
5406
5407 # Override the default configuration, if necessary.
5408 # Make sure that bootstrap.conf is sourced from the current directory
5409 # if we were invoked as "sh bootstrap".
5410 case $0 in
5411   */*) test -r "$0.conf" && . "$0.conf" ;;
5412   *) test -r "$0.conf" && . ./"$0.conf" ;;
5413 esac
5414
5415
5416 ## ------------------------------- ##
5417 ## Actually perform the bootstrap. ##
5418 ## ------------------------------- ##
5419
5420 func_bootstrap ${1+"$@"}
5421
5422 # The End.
5423 exit ${exit_status-$EXIT_SUCCESS}
5424
5425 # Local variables:
5426 # mode: shell-script
5427 # sh-indentation: 2
5428 # eval: (add-hook 'before-save-hook 'time-stamp)
5429 # time-stamp-pattern: "500/scriptversion=%:y-%02m-%02d.%02H; # UTC"
5430 # time-stamp-time-zone: "UTC"
5431 # End: