maint: summarize highlights of 1.4.18 release
[m4/ericb.git] / bootstrap
blob8984cfd9514cfa7f78ce299ec695ca17cc589003
1 #! /bin/sh
2 ## DO NOT EDIT - This file generated from build-aux/bootstrap.in
3 ## by inline-source v2014-01-03.01
5 # Bootstrap an Autotooled package from checked-out sources.
6 # Written by Gary V. Vaughan, 2010
8 # Copyright (C) 2010-2014, 2017 Free Software Foundation, Inc.
9 # This is free software; see the source for copying conditions. There is NO
10 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # Originally written by Paul Eggert. The canonical version of this
26 # script is maintained as build-aux/bootstrap in gnulib, however, to
27 # be useful to your project, you should place a copy of it under
28 # version control in the top-level directory of your project. The
29 # intent is that all customization can be done with a bootstrap.conf
30 # file also maintained in your version control; gnulib comes with a
31 # template build-aux/bootstrap.conf to get you started.
33 # Please report bugs or propose patches to bug-gnulib@gnu.org.
36 ## ------ ##
37 ## Usage. ##
38 ## ------ ##
40 # Most GNUish projects do not keep all of the generated Autotool
41 # files under version control, but running all of the right tools
42 # with the right arguments, in the correct order to regenerate
43 # all of those files in readiness for configuration and building
44 # can be surprisingly involved! Many projects have a 'bootstrap'
45 # script under version control to invoke Autotools and perform
46 # other assorted book-keeping with version numbers and the like.
48 # This bootstrap script aims to probe the configure.ac and top
49 # Makefile.am of your project to automatically determine what
50 # the correct ordering and arguments are and then run the tools for
51 # you. In order to use it, you can generate an initial standalone
52 # script with:
54 # gl/build-aux/inline-source gl/build-aux/bootstrap.in > bootstrap
56 # You should then store than script in version control for other
57 # developers in you project. It will give you instructions about
58 # how to keep it up to date if the sources change.
60 # See gl/doc/bootstrap.texi for documentation on how to write
61 # a bootstrap.conf to customize it for your project's
62 # idiosyncracies.
65 ## ================================================================== ##
66 ## ##
67 ## DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF ##
68 ## ##
69 ## ================================================================== ##
71 ## ------------------------------- ##
72 ## User overridable command paths. ##
73 ## ------------------------------- ##
75 # All uppercase denotes values stored in the environment. These
76 # variables should generally be overridden by the user - however, we do
77 # set them to 'true' in some parts of this script to prevent them being
78 # called at the wrong time by other tools that we call ('autoreconf',
79 # for example).
81 # We also allow 'LIBTOOLIZE', 'M4', 'SHA1SUM' and some others to be
82 # overridden, and export the result for child processes, but they are
83 # handled by the function 'func_find_tool' and not defaulted in this
84 # section.
86 : ${ACLOCAL="aclocal"}
87 : ${AUTOCONF="autoconf"}
88 : ${AUTOHEADER="autoheader"}
89 : ${AUTOM4TE="autom4te"}
90 : ${AUTOHEADER="autoheader"}
91 : ${AUTOMAKE="automake"}
92 : ${AUTOPOINT="autopoint"}
93 : ${AUTORECONF="autoreconf"}
94 : ${CMP="cmp"}
95 : ${CONFIG_SHELL="/bin/sh"}
96 : ${DIFF="diff"}
97 : ${GIT="git"}
98 : ${LN_S="ln -s"}
99 : ${RM="rm"}
101 export ACLOCAL
102 export AUTOCONF
103 export AUTOHEADER
104 export AUTOM4TE
105 export AUTOHEADER
106 export AUTOMAKE
107 export AUTOPOINT
108 export AUTORECONF
109 export CONFIG_SHELL
112 ## -------------- ##
113 ## Configuration. ##
114 ## -------------- ##
116 # A newline delimited list of triples of programs (that respond to
117 # --version), the minimum version numbers required (or just '-' in the
118 # version field if any version will be sufficient) and homepage URLs
119 # to help locate missing packages.
120 buildreq=
122 # Name of a file containing instructions on installing missing packages
123 # required in 'buildreq'.
124 buildreq_readme=README-hacking
126 # These are extracted from AC_INIT in configure.ac, though you can
127 # override those values in 'bootstrap.conf' if you prefer.
128 build_aux=
129 macro_dir=
130 package=
131 package_name=
132 package_version=
133 package_bugreport=
135 # These are extracted from 'gnulib-cache.m4', or else fall-back
136 # automatically on the gnulib defaults; unless you set the values
137 # manually in 'bootstrap.conf'.
138 doc_base=
139 gnulib_mk=
140 gnulib_name=
141 local_gl_dir=
142 source_base=
143 tests_base=
145 # The list of gnulib modules required at 'gnulib-tool' time. If you
146 # check 'gnulib-cache.m4' into your repository, then this list will be
147 # extracted automatically.
148 gnulib_modules=
150 # Extra gnulib files that are not in modules, which override files of
151 # the same name installed by other bootstrap tools.
152 gnulib_non_module_files="
153 build-aux/compile
154 build-aux/install-sh
155 build-aux/mdate-sh
156 build-aux/texinfo.tex
157 build-aux/depcomp
158 build-aux/config.guess
159 build-aux/config.sub
160 doc/INSTALL
163 # Relative path to the local gnulib submodule, and url to the upstream
164 # git repository. If you have a gnulib entry in your .gitmodules file,
165 # these values are ignored.
166 gnulib_path=
167 gnulib_url=
169 # Additional gnulib-tool options to use.
170 gnulib_tool_options="
171 --no-changelog
174 # bootstrap removes any macro-files that are not included by aclocal.m4,
175 # except for files listed in this variable that are always kept.
176 gnulib_precious="
177 gnulib-tool.m4
180 # When truncating long commands for display, always allow at least this
181 # many characters before truncating.
182 min_cmd_len=160
184 # The command to download all .po files for a specified domain into
185 # a specified directory. Fill in the first %s is the domain name, and
186 # the second with the destination directory. Use rsync's -L and -r
187 # options because the latest/%s directory and the .po files within are
188 # all symlinks.
189 po_download_command_format=\
190 "rsync --delete --exclude '*.s1' -Lrtvz \
191 'translationproject.org::tp/latest/%s/' '%s'"
193 # Other locale categories that need message catalogs.
194 extra_locale_categories=
196 # Additional xgettext options to use. Gnulib might provide you with an
197 # extensive list of additional options to append to this, but gettext
198 # 0.16.1 and newer appends them automaticaly, so you can safely ignore
199 # the complaints from 'gnulib-tool' if your $configure_ac states:
201 # AM_GNU_GETTEXT_VERSION([0.16.1])
202 xgettext_options="
203 --flag=_:1:pass-c-format
204 --flag=N_:1:pass-c-format
207 # Package copyright holder for gettext files. Defaults to FSF if unset.
208 copyright_holder=
210 # File that should exist in the top directory of a checked out hierarchy,
211 # but not in a distribution tarball.
212 checkout_only_file=
214 # Whether to use copies instead of symlinks by default (if set to true,
215 # the --copy option has no effect).
216 copy=false
218 # Set this to ".cvsignore .gitignore" in 'bootstrap.conf' if you want
219 # those files to be generated in directories like 'lib/', 'm4/', and 'po/',
220 # or set it to "auto" to make this script select what to use based
221 # on what version control system (if any) is used in the source directory.
222 # Or set it to "none" to ignore VCS ignore files entirely. Default is
223 # "auto".
224 vc_ignore=
227 ## ------------------- ##
228 ## External Libraries. ##
229 ## ------------------- ##
231 # Source required external libraries:
232 # Set a version string for this script.
233 scriptversion=2014-01-03.01; # UTC
235 # General shell script boiler plate, and helper functions.
236 # Written by Gary V. Vaughan, 2004
238 # Copyright (C) 2004-2014, 2017 Free Software Foundation, Inc.
239 # This is free software; see the source for copying conditions. There is NO
240 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
242 # This program is free software; you can redistribute it and/or modify
243 # it under the terms of the GNU General Public License as published by
244 # the Free Software Foundation; either version 3 of the License, or
245 # (at your option) any later version.
247 # As a special exception to the GNU General Public License, if you distribute
248 # this file as part of a program or library that is built using GNU Libtool,
249 # you may include this file under the same distribution terms that you use
250 # for the rest of that program.
252 # This program is distributed in the hope that it will be useful,
253 # but WITHOUT ANY WARRANTY; without even the implied warranty of
254 # MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
255 # General Public License for more details.
257 # You should have received a copy of the GNU General Public License
258 # along with this program. If not, see <http://www.gnu.org/licenses/>.
260 # Please report bugs or propose patches to gary@gnu.org.
263 ## ------ ##
264 ## Usage. ##
265 ## ------ ##
267 # Evaluate this file near the top of your script to gain access to
268 # the functions and variables defined here:
270 # . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
272 # If you need to override any of the default environment variable
273 # settings, do that before evaluating this file.
276 ## -------------------- ##
277 ## Shell normalisation. ##
278 ## -------------------- ##
280 # Some shells need a little help to be as Bourne compatible as possible.
281 # Before doing anything else, make sure all that help has been provided!
283 DUALCASE=1; export DUALCASE # for MKS sh
284 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
285 emulate sh
286 NULLCMD=:
287 # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
288 # is contrary to our usage. Disable this feature.
289 alias -g '${1+"$@"}'='"$@"'
290 setopt NO_GLOB_SUBST
291 else
292 case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
295 # NLS nuisances: We save the old values in case they are required later.
296 _G_user_locale=
297 _G_safe_locale=
298 for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
300 eval "if test set = \"\${$_G_var+set}\"; then
301 save_$_G_var=\$$_G_var
302 $_G_var=C
303 export $_G_var
304 _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
305 _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
307 done
309 # CDPATH.
310 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
312 # Make sure IFS has a sensible default
313 sp=' '
314 nl='
316 IFS="$sp $nl"
318 # There are apparently some retarded systems that use ';' as a PATH separator!
319 if test "${PATH_SEPARATOR+set}" != set; then
320 PATH_SEPARATOR=:
321 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
322 (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
323 PATH_SEPARATOR=';'
329 ## ------------------------- ##
330 ## Locate command utilities. ##
331 ## ------------------------- ##
334 # func_executable_p FILE
335 # ----------------------
336 # Check that FILE is an executable regular file.
337 func_executable_p ()
339 test -f "$1" && test -x "$1"
343 # func_path_progs PROGS_LIST CHECK_FUNC [PATH]
344 # --------------------------------------------
345 # Search for either a program that responds to --version with output
346 # containing "GNU", or else returned by CHECK_FUNC otherwise, by
347 # trying all the directories in PATH with each of the elements of
348 # PROGS_LIST.
350 # CHECK_FUNC should accept the path to a candidate program, and
351 # set $func_check_prog_result if it truncates its output less than
352 # $_G_path_prog_max characters.
353 func_path_progs ()
355 _G_progs_list=$1
356 _G_check_func=$2
357 _G_PATH=${3-"$PATH"}
359 _G_path_prog_max=0
360 _G_path_prog_found=false
361 _G_save_IFS=$IFS; IFS=$PATH_SEPARATOR
362 for _G_dir in $_G_PATH; do
363 IFS=$_G_save_IFS
364 test -z "$_G_dir" && _G_dir=.
365 for _G_prog_name in $_G_progs_list; do
366 for _exeext in '' .EXE; do
367 _G_path_prog=$_G_dir/$_G_prog_name$_exeext
368 func_executable_p "$_G_path_prog" || continue
369 case `"$_G_path_prog" --version 2>&1` in
370 *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
371 *) $_G_check_func $_G_path_prog
372 func_path_progs_result=$func_check_prog_result
374 esac
375 $_G_path_prog_found && break 3
376 done
377 done
378 done
379 IFS=$_G_save_IFS
380 test -z "$func_path_progs_result" && {
381 echo "no acceptable sed could be found in \$PATH" >&2
382 exit 1
387 # We want to be able to use the functions in this file before configure
388 # has figured out where the best binaries are kept, which means we have
389 # to search for them ourselves - except when the results are already set
390 # where we skip the searches.
392 # Unless the user overrides by setting SED, search the path for either GNU
393 # sed, or the sed that truncates its output the least.
394 test -z "$SED" && {
395 _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
396 for _G_i in 1 2 3 4 5 6 7; do
397 _G_sed_script=$_G_sed_script$nl$_G_sed_script
398 done
399 echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
400 _G_sed_script=
402 func_check_prog_sed ()
404 _G_path_prog=$1
406 _G_count=0
407 printf 0123456789 >conftest.in
408 while :
410 cat conftest.in conftest.in >conftest.tmp
411 mv conftest.tmp conftest.in
412 cp conftest.in conftest.nl
413 echo '' >> conftest.nl
414 "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
415 diff conftest.out conftest.nl >/dev/null 2>&1 || break
416 _G_count=`expr $_G_count + 1`
417 if test "$_G_count" -gt "$_G_path_prog_max"; then
418 # Best one so far, save it but keep looking for a better one
419 func_check_prog_result=$_G_path_prog
420 _G_path_prog_max=$_G_count
422 # 10*(2^10) chars as input seems more than enough
423 test 10 -lt "$_G_count" && break
424 done
425 rm -f conftest.in conftest.tmp conftest.nl conftest.out
428 func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
429 rm -f conftest.sed
430 SED=$func_path_progs_result
434 # Unless the user overrides by setting GREP, search the path for either GNU
435 # grep, or the grep that truncates its output the least.
436 test -z "$GREP" && {
437 func_check_prog_grep ()
439 _G_path_prog=$1
441 _G_count=0
442 _G_path_prog_max=0
443 printf 0123456789 >conftest.in
444 while :
446 cat conftest.in conftest.in >conftest.tmp
447 mv conftest.tmp conftest.in
448 cp conftest.in conftest.nl
449 echo 'GREP' >> conftest.nl
450 "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
451 diff conftest.out conftest.nl >/dev/null 2>&1 || break
452 _G_count=`expr $_G_count + 1`
453 if test "$_G_count" -gt "$_G_path_prog_max"; then
454 # Best one so far, save it but keep looking for a better one
455 func_check_prog_result=$_G_path_prog
456 _G_path_prog_max=$_G_count
458 # 10*(2^10) chars as input seems more than enough
459 test 10 -lt "$_G_count" && break
460 done
461 rm -f conftest.in conftest.tmp conftest.nl conftest.out
464 func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
465 GREP=$func_path_progs_result
469 ## ------------------------------- ##
470 ## User overridable command paths. ##
471 ## ------------------------------- ##
473 # All uppercase variable names are used for environment variables. These
474 # variables can be overridden by the user before calling a script that
475 # uses them if a suitable command of that name is not already available
476 # in the command search PATH.
478 : ${CP="cp -f"}
479 : ${ECHO="printf %s\n"}
480 : ${EGREP="$GREP -E"}
481 : ${FGREP="$GREP -F"}
482 : ${LN_S="ln -s"}
483 : ${MAKE="make"}
484 : ${MKDIR="mkdir"}
485 : ${MV="mv -f"}
486 : ${RM="rm -f"}
487 : ${SHELL="${CONFIG_SHELL-/bin/sh}"}
490 ## -------------------- ##
491 ## Useful sed snippets. ##
492 ## -------------------- ##
494 sed_dirname='s|/[^/]*$||'
495 sed_basename='s|^.*/||'
497 # Sed substitution that helps us do robust quoting. It backslashifies
498 # metacharacters that are still active within double-quoted strings.
499 sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
501 # Same as above, but do not quote variable references.
502 sed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
504 # Sed substitution that turns a string into a regex matching for the
505 # string literally.
506 sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
508 # Sed substitution that converts a w32 file name or path
509 # that contains forward slashes, into one that contains
510 # (escaped) backslashes. A very naive implementation.
511 sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
513 # Re-'\' parameter expansions in output of sed_double_quote_subst that
514 # were '\'-ed in input to the same. If an odd number of '\' preceded a
515 # '$' in input to sed_double_quote_subst, that '$' was protected from
516 # expansion. Since each input '\' is now two '\'s, look for any number
517 # of runs of four '\'s followed by two '\'s and then a '$'. '\' that '$'.
518 _G_bs='\\'
519 _G_bs2='\\\\'
520 _G_bs4='\\\\\\\\'
521 _G_dollar='\$'
522 sed_double_backslash="\
523 s/$_G_bs4/&\\
525 s/^$_G_bs2$_G_dollar/$_G_bs&/
526 s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
527 s/\n//g"
530 ## ----------------- ##
531 ## Global variables. ##
532 ## ----------------- ##
534 # Except for the global variables explicitly listed below, the following
535 # functions in the '^func_' namespace, and the '^require_' namespace
536 # variables initialised in the 'Resource management' section, sourcing
537 # this file will not pollute your global namespace with anything
538 # else. There's no portable way to scope variables in Bourne shell
539 # though, so actually running these functions will sometimes place
540 # results into a variable named after the function, and often use
541 # temporary variables in the '^_G_' namespace. If you are careful to
542 # avoid using those namespaces casually in your sourcing script, things
543 # should continue to work as you expect. And, of course, you can freely
544 # overwrite any of the functions or variables defined here before
545 # calling anything to customize them.
547 EXIT_SUCCESS=0
548 EXIT_FAILURE=1
549 EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing.
550 EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake.
552 # Allow overriding, eg assuming that you follow the convention of
553 # putting '$debug_cmd' at the start of all your functions, you can get
554 # bash to show function call trace with:
556 # debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
557 debug_cmd=${debug_cmd-":"}
558 exit_cmd=:
560 # By convention, finish your script with:
562 # exit $exit_status
564 # so that you can set exit_status to non-zero if you want to indicate
565 # something went wrong during execution without actually bailing out at
566 # the point of failure.
567 exit_status=$EXIT_SUCCESS
569 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
570 # is ksh but when the shell is invoked as "sh" and the current value of
571 # the _XPG environment variable is not equal to 1 (one), the special
572 # positional parameter $0, within a function call, is the name of the
573 # function.
574 progpath=$0
576 # The name of this program.
577 progname=`$ECHO "$progpath" |$SED "$sed_basename"`
579 # Make sure we have an absolute progpath for reexecution:
580 case $progpath in
581 [\\/]*|[A-Za-z]:\\*) ;;
582 *[\\/]*)
583 progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
584 progdir=`cd "$progdir" && pwd`
585 progpath=$progdir/$progname
588 _G_IFS=$IFS
589 IFS=${PATH_SEPARATOR-:}
590 for progdir in $PATH; do
591 IFS=$_G_IFS
592 test -x "$progdir/$progname" && break
593 done
594 IFS=$_G_IFS
595 test -n "$progdir" || progdir=`pwd`
596 progpath=$progdir/$progname
598 esac
601 ## ----------------- ##
602 ## Standard options. ##
603 ## ----------------- ##
605 # The following options affect the operation of the functions defined
606 # below, and should be set appropriately depending on run-time para-
607 # meters passed on the command line.
609 opt_dry_run=false
610 opt_quiet=false
611 opt_verbose=false
613 # Categories 'all' and 'none' are always available. Append any others
614 # you will pass as the first argument to func_warning from your own
615 # code.
616 warning_categories=
618 # By default, display warnings according to 'opt_warning_types'. Set
619 # 'warning_func' to ':' to elide all warnings, or func_fatal_error to
620 # treat the next displayed warning as a fatal error.
621 warning_func=func_warn_and_continue
623 # Set to 'all' to display all warnings, 'none' to suppress all
624 # warnings, or a space delimited list of some subset of
625 # 'warning_categories' to display only the listed warnings.
626 opt_warning_types=all
629 ## -------------------- ##
630 ## Resource management. ##
631 ## -------------------- ##
633 # This section contains definitions for functions that each ensure a
634 # particular resource (a file, or a non-empty configuration variable for
635 # example) is available, and if appropriate to extract default values
636 # from pertinent package files. Call them using their associated
637 # 'require_*' variable to ensure that they are executed, at most, once.
639 # It's entirely deliberate that calling these functions can set
640 # variables that don't obey the namespace limitations obeyed by the rest
641 # of this file, in order that that they be as useful as possible to
642 # callers.
645 # require_term_colors
646 # -------------------
647 # Allow display of bold text on terminals that support it.
648 require_term_colors=func_require_term_colors
649 func_require_term_colors ()
651 $debug_cmd
653 test -t 1 && {
654 # COLORTERM and USE_ANSI_COLORS environment variables take
655 # precedence, because most terminfo databases neglect to describe
656 # whether color sequences are supported.
657 test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
659 if test 1 = "$USE_ANSI_COLORS"; then
660 # Standard ANSI escape sequences
661 tc_reset='\e[0m'
662 tc_bold='\e[1m'; tc_standout='\e[7m'
663 tc_red='\e[31m'; tc_green='\e[32m'
664 tc_blue='\e[34m'; tc_cyan='\e[36m'
665 else
666 # Otherwise trust the terminfo database after all.
667 test -n "`tput sgr0 2>/dev/null`" && {
668 tc_reset=`tput sgr0`
669 test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
670 tc_standout=$tc_bold
671 test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
672 test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
673 test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
674 test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
675 test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
680 require_term_colors=:
684 ## ----------------- ##
685 ## Function library. ##
686 ## ----------------- ##
688 # This section contains a variety of useful functions to call in your
689 # scripts. Take note of the portable wrappers for features provided by
690 # some modern shells, which will fall back to slower equivalents on
691 # less featureful shells.
694 # func_append VAR VALUE
695 # ---------------------
696 # Append VALUE onto the existing contents of VAR.
698 # We should try to minimise forks, especially on Windows where they are
699 # unreasonably slow, so skip the feature probes when bash or zsh are
700 # being used:
701 if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
702 : ${_G_HAVE_ARITH_OP="yes"}
703 : ${_G_HAVE_XSI_OPS="yes"}
704 # The += operator was introduced in bash 3.1
705 case $BASH_VERSION in
706 [12].* | 3.0 | 3.0*) ;;
708 : ${_G_HAVE_PLUSEQ_OP="yes"}
710 esac
713 # _G_HAVE_PLUSEQ_OP
714 # Can be empty, in which case the shell is probed, "yes" if += is
715 # useable or anything else if it does not work.
716 test -z "$_G_HAVE_PLUSEQ_OP" \
717 && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
718 && _G_HAVE_PLUSEQ_OP=yes
720 if test yes = "$_G_HAVE_PLUSEQ_OP"
721 then
722 # This is an XSI compatible shell, allowing a faster implementation...
723 eval 'func_append ()
725 $debug_cmd
727 eval "$1+=\$2"
729 else
730 # ...otherwise fall back to using expr, which is often a shell builtin.
731 func_append ()
733 $debug_cmd
735 eval "$1=\$$1\$2"
740 # func_append_quoted VAR VALUE
741 # ----------------------------
742 # Quote VALUE and append to the end of shell variable VAR, separated
743 # by a space.
744 if test yes = "$_G_HAVE_PLUSEQ_OP"; then
745 eval 'func_append_quoted ()
747 $debug_cmd
749 func_quote_for_eval "$2"
750 eval "$1+=\\ \$func_quote_for_eval_result"
752 else
753 func_append_quoted ()
755 $debug_cmd
757 func_quote_for_eval "$2"
758 eval "$1=\$$1\\ \$func_quote_for_eval_result"
763 # func_append_uniq VAR VALUE
764 # --------------------------
765 # Append unique VALUE onto the existing contents of VAR, assuming
766 # entries are delimited by the first character of VALUE. For example:
768 # func_append_uniq options " --another-option option-argument"
770 # will only append to $options if " --another-option option-argument "
771 # is not already present somewhere in $options already (note spaces at
772 # each end implied by leading space in second argument).
773 func_append_uniq ()
775 $debug_cmd
777 eval _G_current_value='`$ECHO $'$1'`'
778 _G_delim=`expr "$2" : '\(.\)'`
780 case $_G_delim$_G_current_value$_G_delim in
781 *"$2$_G_delim"*) ;;
782 *) func_append "$@" ;;
783 esac
787 # func_arith TERM...
788 # ------------------
789 # Set func_arith_result to the result of evaluating TERMs.
790 test -z "$_G_HAVE_ARITH_OP" \
791 && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
792 && _G_HAVE_ARITH_OP=yes
794 if test yes = "$_G_HAVE_ARITH_OP"; then
795 eval 'func_arith ()
797 $debug_cmd
799 func_arith_result=$(( $* ))
801 else
802 func_arith ()
804 $debug_cmd
806 func_arith_result=`expr "$@"`
811 # func_basename FILE
812 # ------------------
813 # Set func_basename_result to FILE with everything up to and including
814 # the last / stripped.
815 if test yes = "$_G_HAVE_XSI_OPS"; then
816 # If this shell supports suffix pattern removal, then use it to avoid
817 # forking. Hide the definitions single quotes in case the shell chokes
818 # on unsupported syntax...
819 _b='func_basename_result=${1##*/}'
820 _d='case $1 in
821 */*) func_dirname_result=${1%/*}$2 ;;
822 * ) func_dirname_result=$3 ;;
823 esac'
825 else
826 # ...otherwise fall back to using sed.
827 _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
828 _d='func_dirname_result=`$ECHO "$1" |$SED "$sed_dirname"`
829 if test "X$func_dirname_result" = "X$1"; then
830 func_dirname_result=$3
831 else
832 func_append func_dirname_result "$2"
836 eval 'func_basename ()
838 $debug_cmd
840 '"$_b"'
844 # func_dirname FILE APPEND NONDIR_REPLACEMENT
845 # -------------------------------------------
846 # Compute the dirname of FILE. If nonempty, add APPEND to the result,
847 # otherwise set result to NONDIR_REPLACEMENT.
848 eval 'func_dirname ()
850 $debug_cmd
852 '"$_d"'
856 # func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
857 # --------------------------------------------------------
858 # Perform func_basename and func_dirname in a single function
859 # call:
860 # dirname: Compute the dirname of FILE. If nonempty,
861 # add APPEND to the result, otherwise set result
862 # to NONDIR_REPLACEMENT.
863 # value returned in "$func_dirname_result"
864 # basename: Compute filename of FILE.
865 # value retuned in "$func_basename_result"
866 # For efficiency, we do not delegate to the functions above but instead
867 # duplicate the functionality here.
868 eval 'func_dirname_and_basename ()
870 $debug_cmd
872 '"$_b"'
873 '"$_d"'
877 # func_echo ARG...
878 # ----------------
879 # Echo program name prefixed message.
880 func_echo ()
882 $debug_cmd
884 _G_message=$*
886 func_echo_IFS=$IFS
887 IFS=$nl
888 for _G_line in $_G_message; do
889 IFS=$func_echo_IFS
890 $ECHO "$progname: $_G_line"
891 done
892 IFS=$func_echo_IFS
896 # func_echo_all ARG...
897 # --------------------
898 # Invoke $ECHO with all args, space-separated.
899 func_echo_all ()
901 $ECHO "$*"
905 # func_echo_infix_1 INFIX ARG...
906 # ------------------------------
907 # Echo program name, followed by INFIX on the first line, with any
908 # additional lines not showing INFIX.
909 func_echo_infix_1 ()
911 $debug_cmd
913 $require_term_colors
915 _G_infix=$1; shift
916 _G_indent=$_G_infix
917 _G_prefix="$progname: $_G_infix: "
918 _G_message=$*
920 # Strip color escape sequences before counting printable length
921 for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
923 test -n "$_G_tc" && {
924 _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
925 _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
927 done
928 _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes
930 func_echo_infix_1_IFS=$IFS
931 IFS=$nl
932 for _G_line in $_G_message; do
933 IFS=$func_echo_infix_1_IFS
934 $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
935 _G_prefix=$_G_indent
936 done
937 IFS=$func_echo_infix_1_IFS
941 # func_error ARG...
942 # -----------------
943 # Echo program name prefixed message to standard error.
944 func_error ()
946 $debug_cmd
948 $require_term_colors
950 func_echo_infix_1 " $tc_standout${tc_red}error$tc_reset" "$*" >&2
954 # func_fatal_error ARG...
955 # -----------------------
956 # Echo program name prefixed message to standard error, and exit.
957 func_fatal_error ()
959 $debug_cmd
961 func_error "$*"
962 exit $EXIT_FAILURE
966 # func_grep EXPRESSION FILENAME
967 # -----------------------------
968 # Check whether EXPRESSION matches any line of FILENAME, without output.
969 func_grep ()
971 $debug_cmd
973 $GREP "$1" "$2" >/dev/null 2>&1
977 # func_len STRING
978 # ---------------
979 # Set func_len_result to the length of STRING. STRING may not
980 # start with a hyphen.
981 test -z "$_G_HAVE_XSI_OPS" \
982 && (eval 'x=a/b/c;
983 test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
984 && _G_HAVE_XSI_OPS=yes
986 if test yes = "$_G_HAVE_XSI_OPS"; then
987 eval 'func_len ()
989 $debug_cmd
991 func_len_result=${#1}
993 else
994 func_len ()
996 $debug_cmd
998 func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
1003 # func_mkdir_p DIRECTORY-PATH
1004 # ---------------------------
1005 # Make sure the entire path to DIRECTORY-PATH is available.
1006 func_mkdir_p ()
1008 $debug_cmd
1010 _G_directory_path=$1
1011 _G_dir_list=
1013 if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
1015 # Protect directory names starting with '-'
1016 case $_G_directory_path in
1017 -*) _G_directory_path=./$_G_directory_path ;;
1018 esac
1020 # While some portion of DIR does not yet exist...
1021 while test ! -d "$_G_directory_path"; do
1022 # ...make a list in topmost first order. Use a colon delimited
1023 # list incase some portion of path contains whitespace.
1024 _G_dir_list=$_G_directory_path:$_G_dir_list
1026 # If the last portion added has no slash in it, the list is done
1027 case $_G_directory_path in */*) ;; *) break ;; esac
1029 # ...otherwise throw away the child directory and loop
1030 _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
1031 done
1032 _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
1034 func_mkdir_p_IFS=$IFS; IFS=:
1035 for _G_dir in $_G_dir_list; do
1036 IFS=$func_mkdir_p_IFS
1037 # mkdir can fail with a 'File exist' error if two processes
1038 # try to create one of the directories concurrently. Don't
1039 # stop in that case!
1040 $MKDIR "$_G_dir" 2>/dev/null || :
1041 done
1042 IFS=$func_mkdir_p_IFS
1044 # Bail out if we (or some other process) failed to create a directory.
1045 test -d "$_G_directory_path" || \
1046 func_fatal_error "Failed to create '$1'"
1051 # func_mktempdir [BASENAME]
1052 # -------------------------
1053 # Make a temporary directory that won't clash with other running
1054 # libtool processes, and avoids race conditions if possible. If
1055 # given, BASENAME is the basename for that directory.
1056 func_mktempdir ()
1058 $debug_cmd
1060 _G_template=${TMPDIR-/tmp}/${1-$progname}
1062 if test : = "$opt_dry_run"; then
1063 # Return a directory name, but don't create it in dry-run mode
1064 _G_tmpdir=$_G_template-$$
1065 else
1067 # If mktemp works, use that first and foremost
1068 _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
1070 if test ! -d "$_G_tmpdir"; then
1071 # Failing that, at least try and use $RANDOM to avoid a race
1072 _G_tmpdir=$_G_template-${RANDOM-0}$$
1074 func_mktempdir_umask=`umask`
1075 umask 0077
1076 $MKDIR "$_G_tmpdir"
1077 umask $func_mktempdir_umask
1080 # If we're not in dry-run mode, bomb out on failure
1081 test -d "$_G_tmpdir" || \
1082 func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
1085 $ECHO "$_G_tmpdir"
1089 # func_normal_abspath PATH
1090 # ------------------------
1091 # Remove doubled-up and trailing slashes, "." path components,
1092 # and cancel out any ".." path components in PATH after making
1093 # it an absolute path.
1094 func_normal_abspath ()
1096 $debug_cmd
1098 # These SED scripts presuppose an absolute path with a trailing slash.
1099 _G_pathcar='s|^/\([^/]*\).*$|\1|'
1100 _G_pathcdr='s|^/[^/]*||'
1101 _G_removedotparts=':dotsl
1102 s|/\./|/|g
1103 t dotsl
1104 s|/\.$|/|'
1105 _G_collapseslashes='s|/\{1,\}|/|g'
1106 _G_finalslash='s|/*$|/|'
1108 # Start from root dir and reassemble the path.
1109 func_normal_abspath_result=
1110 func_normal_abspath_tpath=$1
1111 func_normal_abspath_altnamespace=
1112 case $func_normal_abspath_tpath in
1114 # Empty path, that just means $cwd.
1115 func_stripname '' '/' "`pwd`"
1116 func_normal_abspath_result=$func_stripname_result
1117 return
1119 # The next three entries are used to spot a run of precisely
1120 # two leading slashes without using negated character classes;
1121 # we take advantage of case's first-match behaviour.
1122 ///*)
1123 # Unusual form of absolute path, do nothing.
1125 //*)
1126 # Not necessarily an ordinary path; POSIX reserves leading '//'
1127 # and for example Cygwin uses it to access remote file shares
1128 # over CIFS/SMB, so we conserve a leading double slash if found.
1129 func_normal_abspath_altnamespace=/
1132 # Absolute path, do nothing.
1135 # Relative path, prepend $cwd.
1136 func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1138 esac
1140 # Cancel out all the simple stuff to save iterations. We also want
1141 # the path to end with a slash for ease of parsing, so make sure
1142 # there is one (and only one) here.
1143 func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1144 -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1145 while :; do
1146 # Processed it all yet?
1147 if test / = "$func_normal_abspath_tpath"; then
1148 # If we ascended to the root using ".." the result may be empty now.
1149 if test -z "$func_normal_abspath_result"; then
1150 func_normal_abspath_result=/
1152 break
1154 func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1155 -e "$_G_pathcar"`
1156 func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1157 -e "$_G_pathcdr"`
1158 # Figure out what to do with it
1159 case $func_normal_abspath_tcomponent in
1161 # Trailing empty path component, ignore it.
1164 # Parent dir; strip last assembled component from result.
1165 func_dirname "$func_normal_abspath_result"
1166 func_normal_abspath_result=$func_dirname_result
1169 # Actual path component, append it.
1170 func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1172 esac
1173 done
1174 # Restore leading double-slash if one was found on entry.
1175 func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1179 # func_notquiet ARG...
1180 # --------------------
1181 # Echo program name prefixed message only when not in quiet mode.
1182 func_notquiet ()
1184 $debug_cmd
1186 $opt_quiet || func_echo ${1+"$@"}
1188 # A bug in bash halts the script if the last line of a function
1189 # fails when set -e is in force, so we need another command to
1190 # work around that:
1195 # func_relative_path SRCDIR DSTDIR
1196 # --------------------------------
1197 # Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1198 func_relative_path ()
1200 $debug_cmd
1202 func_relative_path_result=
1203 func_normal_abspath "$1"
1204 func_relative_path_tlibdir=$func_normal_abspath_result
1205 func_normal_abspath "$2"
1206 func_relative_path_tbindir=$func_normal_abspath_result
1208 # Ascend the tree starting from libdir
1209 while :; do
1210 # check if we have found a prefix of bindir
1211 case $func_relative_path_tbindir in
1212 $func_relative_path_tlibdir)
1213 # found an exact match
1214 func_relative_path_tcancelled=
1215 break
1217 $func_relative_path_tlibdir*)
1218 # found a matching prefix
1219 func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1220 func_relative_path_tcancelled=$func_stripname_result
1221 if test -z "$func_relative_path_result"; then
1222 func_relative_path_result=.
1224 break
1227 func_dirname $func_relative_path_tlibdir
1228 func_relative_path_tlibdir=$func_dirname_result
1229 if test -z "$func_relative_path_tlibdir"; then
1230 # Have to descend all the way to the root!
1231 func_relative_path_result=../$func_relative_path_result
1232 func_relative_path_tcancelled=$func_relative_path_tbindir
1233 break
1235 func_relative_path_result=../$func_relative_path_result
1237 esac
1238 done
1240 # Now calculate path; take care to avoid doubling-up slashes.
1241 func_stripname '' '/' "$func_relative_path_result"
1242 func_relative_path_result=$func_stripname_result
1243 func_stripname '/' '/' "$func_relative_path_tcancelled"
1244 if test -n "$func_stripname_result"; then
1245 func_append func_relative_path_result "/$func_stripname_result"
1248 # Normalisation. If bindir is libdir, return '.' else relative path.
1249 if test -n "$func_relative_path_result"; then
1250 func_stripname './' '' "$func_relative_path_result"
1251 func_relative_path_result=$func_stripname_result
1254 test -n "$func_relative_path_result" || func_relative_path_result=.
1260 # func_quote_for_eval ARG...
1261 # --------------------------
1262 # Aesthetically quote ARGs to be evaled later.
1263 # This function returns two values:
1264 # i) func_quote_for_eval_result
1265 # double-quoted, suitable for a subsequent eval
1266 # ii) func_quote_for_eval_unquoted_result
1267 # has all characters that are still active within double
1268 # quotes backslashified.
1269 func_quote_for_eval ()
1271 $debug_cmd
1273 func_quote_for_eval_unquoted_result=
1274 func_quote_for_eval_result=
1275 while test 0 -lt $#; do
1276 case $1 in
1277 *[\\\`\"\$]*)
1278 _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
1280 _G_unquoted_arg=$1 ;;
1281 esac
1282 if test -n "$func_quote_for_eval_unquoted_result"; then
1283 func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1284 else
1285 func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1288 case $_G_unquoted_arg in
1289 # Double-quote args containing shell metacharacters to delay
1290 # word splitting, command substitution and variable expansion
1291 # for a subsequent eval.
1292 # Many Bourne shells cannot handle close brackets correctly
1293 # in scan sets, so we specify it separately.
1294 *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
1295 _G_quoted_arg=\"$_G_unquoted_arg\"
1298 _G_quoted_arg=$_G_unquoted_arg
1300 esac
1302 if test -n "$func_quote_for_eval_result"; then
1303 func_append func_quote_for_eval_result " $_G_quoted_arg"
1304 else
1305 func_append func_quote_for_eval_result "$_G_quoted_arg"
1307 shift
1308 done
1312 # func_quote_for_expand ARG
1313 # -------------------------
1314 # Aesthetically quote ARG to be evaled later; same as above,
1315 # but do not quote variable references.
1316 func_quote_for_expand ()
1318 $debug_cmd
1320 case $1 in
1321 *[\\\`\"]*)
1322 _G_arg=`$ECHO "$1" | $SED \
1323 -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
1325 _G_arg=$1 ;;
1326 esac
1328 case $_G_arg in
1329 # Double-quote args containing shell metacharacters to delay
1330 # word splitting and command substitution for a subsequent eval.
1331 # Many Bourne shells cannot handle close brackets correctly
1332 # in scan sets, so we specify it separately.
1333 *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
1334 _G_arg=\"$_G_arg\"
1336 esac
1338 func_quote_for_expand_result=$_G_arg
1342 # func_stripname PREFIX SUFFIX NAME
1343 # ---------------------------------
1344 # strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1345 # PREFIX and SUFFIX must not contain globbing or regex special
1346 # characters, hashes, percent signs, but SUFFIX may contain a leading
1347 # dot (in which case that matches only a dot).
1348 if test yes = "$_G_HAVE_XSI_OPS"; then
1349 eval 'func_stripname ()
1351 $debug_cmd
1353 # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1354 # positional parameters, so assign one to ordinary variable first.
1355 func_stripname_result=$3
1356 func_stripname_result=${func_stripname_result#"$1"}
1357 func_stripname_result=${func_stripname_result%"$2"}
1359 else
1360 func_stripname ()
1362 $debug_cmd
1364 case $2 in
1365 .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1366 *) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1367 esac
1372 # func_show_eval CMD [FAIL_EXP]
1373 # -----------------------------
1374 # Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is
1375 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
1376 # is given, then evaluate it.
1377 func_show_eval ()
1379 $debug_cmd
1381 _G_cmd=$1
1382 _G_fail_exp=${2-':'}
1384 func_quote_for_expand "$_G_cmd"
1385 eval "func_notquiet $func_quote_for_expand_result"
1387 $opt_dry_run || {
1388 eval "$_G_cmd"
1389 _G_status=$?
1390 if test 0 -ne "$_G_status"; then
1391 eval "(exit $_G_status); $_G_fail_exp"
1397 # func_show_eval_locale CMD [FAIL_EXP]
1398 # ------------------------------------
1399 # Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is
1400 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
1401 # is given, then evaluate it. Use the saved locale for evaluation.
1402 func_show_eval_locale ()
1404 $debug_cmd
1406 _G_cmd=$1
1407 _G_fail_exp=${2-':'}
1409 $opt_quiet || {
1410 func_quote_for_expand "$_G_cmd"
1411 eval "func_echo $func_quote_for_expand_result"
1414 $opt_dry_run || {
1415 eval "$_G_user_locale
1416 $_G_cmd"
1417 _G_status=$?
1418 eval "$_G_safe_locale"
1419 if test 0 -ne "$_G_status"; then
1420 eval "(exit $_G_status); $_G_fail_exp"
1426 # func_tr_sh
1427 # ----------
1428 # Turn $1 into a string suitable for a shell variable name.
1429 # Result is stored in $func_tr_sh_result. All characters
1430 # not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1431 # if $1 begins with a digit, a '_' is prepended as well.
1432 func_tr_sh ()
1434 $debug_cmd
1436 case $1 in
1437 [0-9]* | *[!a-zA-Z0-9_]*)
1438 func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1441 func_tr_sh_result=$1
1443 esac
1447 # func_verbose ARG...
1448 # -------------------
1449 # Echo program name prefixed message in verbose mode only.
1450 func_verbose ()
1452 $debug_cmd
1454 $opt_verbose && func_echo "$*"
1460 # func_warn_and_continue ARG...
1461 # -----------------------------
1462 # Echo program name prefixed warning message to standard error.
1463 func_warn_and_continue ()
1465 $debug_cmd
1467 $require_term_colors
1469 func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1473 # func_warning CATEGORY ARG...
1474 # ----------------------------
1475 # Echo program name prefixed warning message to standard error. Warning
1476 # messages can be filtered according to CATEGORY, where this function
1477 # elides messages where CATEGORY is not listed in the global variable
1478 # 'opt_warning_types'.
1479 func_warning ()
1481 $debug_cmd
1483 # CATEGORY must be in the warning_categories list!
1484 case " $warning_categories " in
1485 *" $1 "*) ;;
1486 *) func_internal_error "invalid warning category '$1'" ;;
1487 esac
1489 _G_category=$1
1490 shift
1492 case " $opt_warning_types " in
1493 *" $_G_category "*) $warning_func ${1+"$@"} ;;
1494 esac
1498 # func_sort_ver VER1 VER2
1499 # -----------------------
1500 # 'sort -V' is not generally available.
1501 # Note this deviates from the version comparison in automake
1502 # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1503 # but this should suffice as we won't be specifying old
1504 # version formats or redundant trailing .0 in bootstrap.conf.
1505 # If we did want full compatibility then we should probably
1506 # use m4_version_compare from autoconf.
1507 func_sort_ver ()
1509 $debug_cmd
1511 printf '%s\n%s\n' "$1" "$2" \
1512 | 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
1515 # func_lt_ver PREV CURR
1516 # ---------------------
1517 # Return true if PREV and CURR are in the correct order according to
1518 # func_sort_ver, otherwise false. Use it like this:
1520 # func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1521 func_lt_ver ()
1523 $debug_cmd
1525 test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1529 # Local variables:
1530 # mode: shell-script
1531 # sh-indentation: 2
1532 # eval: (add-hook 'before-save-hook 'time-stamp)
1533 # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1534 # time-stamp-time-zone: "UTC"
1535 # End:
1536 #! /bin/sh
1538 # Set a version string for this script.
1539 scriptversion=2014-01-07.03; # UTC
1541 # A portable, pluggable option parser for Bourne shell.
1542 # Written by Gary V. Vaughan, 2010
1544 # Copyright (C) 2010-2014, 2017 Free Software Foundation, Inc.
1545 # This is free software; see the source for copying conditions. There is NO
1546 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1548 # This program is free software: you can redistribute it and/or modify
1549 # it under the terms of the GNU General Public License as published by
1550 # the Free Software Foundation, either version 3 of the License, or
1551 # (at your option) any later version.
1553 # This program is distributed in the hope that it will be useful,
1554 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1555 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1556 # GNU General Public License for more details.
1558 # You should have received a copy of the GNU General Public License
1559 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1561 # Please report bugs or propose patches to gary@gnu.org.
1564 ## ------ ##
1565 ## Usage. ##
1566 ## ------ ##
1568 # This file is a library for parsing options in your shell scripts along
1569 # with assorted other useful supporting features that you can make use
1570 # of too.
1572 # For the simplest scripts you might need only:
1574 # #!/bin/sh
1575 # . relative/path/to/funclib.sh
1576 # . relative/path/to/options-parser
1577 # scriptversion=1.0
1578 # func_options ${1+"$@"}
1579 # eval set dummy "$func_options_result"; shift
1580 # ...rest of your script...
1582 # In order for the '--version' option to work, you will need to have a
1583 # suitably formatted comment like the one at the top of this file
1584 # starting with '# Written by ' and ending with '# warranty; '.
1586 # For '-h' and '--help' to work, you will also need a one line
1587 # description of your script's purpose in a comment directly above the
1588 # '# Written by ' line, like the one at the top of this file.
1590 # The default options also support '--debug', which will turn on shell
1591 # execution tracing (see the comment above debug_cmd below for another
1592 # use), and '--verbose' and the func_verbose function to allow your script
1593 # to display verbose messages only when your user has specified
1594 # '--verbose'.
1596 # After sourcing this file, you can plug processing for additional
1597 # options by amending the variables from the 'Configuration' section
1598 # below, and following the instructions in the 'Option parsing'
1599 # section further down.
1601 ## -------------- ##
1602 ## Configuration. ##
1603 ## -------------- ##
1605 # You should override these variables in your script after sourcing this
1606 # file so that they reflect the customisations you have added to the
1607 # option parser.
1609 # The usage line for option parsing errors and the start of '-h' and
1610 # '--help' output messages. You can embed shell variables for delayed
1611 # expansion at the time the message is displayed, but you will need to
1612 # quote other shell meta-characters carefully to prevent them being
1613 # expanded when the contents are evaled.
1614 usage='$progpath [OPTION]...'
1616 # Short help message in response to '-h' and '--help'. Add to this or
1617 # override it after sourcing this library to reflect the full set of
1618 # options your script accepts.
1619 usage_message="\
1620 --debug enable verbose shell tracing
1621 -W, --warnings=CATEGORY
1622 report the warnings falling in CATEGORY [all]
1623 -v, --verbose verbosely report processing
1624 --version print version information and exit
1625 -h, --help print short or long help message and exit
1628 # Additional text appended to 'usage_message' in response to '--help'.
1629 long_help_message="
1630 Warning categories include:
1631 'all' show all warnings
1632 'none' turn off all the warnings
1633 'error' warnings are treated as fatal errors"
1635 # Help message printed before fatal option parsing errors.
1636 fatal_help="Try '\$progname --help' for more information."
1640 ## ------------------------- ##
1641 ## Hook function management. ##
1642 ## ------------------------- ##
1644 # This section contains functions for adding, removing, and running hooks
1645 # to the main code. A hook is just a named list of of function, that can
1646 # be run in order later on.
1648 # func_hookable FUNC_NAME
1649 # -----------------------
1650 # Declare that FUNC_NAME will run hooks added with
1651 # 'func_add_hook FUNC_NAME ...'.
1652 func_hookable ()
1654 $debug_cmd
1656 func_append hookable_fns " $1"
1660 # func_add_hook FUNC_NAME HOOK_FUNC
1661 # ---------------------------------
1662 # Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must
1663 # first have been declared "hookable" by a call to 'func_hookable'.
1664 func_add_hook ()
1666 $debug_cmd
1668 case " $hookable_fns " in
1669 *" $1 "*) ;;
1670 *) func_fatal_error "'$1' does not accept hook functions." ;;
1671 esac
1673 eval func_append ${1}_hooks '" $2"'
1677 # func_remove_hook FUNC_NAME HOOK_FUNC
1678 # ------------------------------------
1679 # Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1680 func_remove_hook ()
1682 $debug_cmd
1684 eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1688 # func_run_hooks FUNC_NAME [ARG]...
1689 # ---------------------------------
1690 # Run all hook functions registered to FUNC_NAME.
1691 # It is assumed that the list of hook functions contains nothing more
1692 # than a whitespace-delimited list of legal shell function names, and
1693 # no effort is wasted trying to catch shell meta-characters or preserve
1694 # whitespace.
1695 func_run_hooks ()
1697 $debug_cmd
1699 case " $hookable_fns " in
1700 *" $1 "*) ;;
1701 *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1702 esac
1704 eval _G_hook_fns=\$$1_hooks; shift
1706 for _G_hook in $_G_hook_fns; do
1707 eval $_G_hook '"$@"'
1709 # store returned options list back into positional
1710 # parameters for next 'cmd' execution.
1711 eval _G_hook_result=\$${_G_hook}_result
1712 eval set dummy "$_G_hook_result"; shift
1713 done
1715 func_quote_for_eval ${1+"$@"}
1716 func_run_hooks_result=$func_quote_for_eval_result
1721 ## --------------- ##
1722 ## Option parsing. ##
1723 ## --------------- ##
1725 # In order to add your own option parsing hooks, you must accept the
1726 # full positional parameter list in your hook function, remove any
1727 # options that you action, and then pass back the remaining unprocessed
1728 # options in '<hooked_function_name>_result', escaped suitably for
1729 # 'eval'. Like this:
1731 # my_options_prep ()
1733 # $debug_cmd
1735 # # Extend the existing usage message.
1736 # usage_message=$usage_message'
1737 # -s, --silent don'\''t print informational messages
1740 # func_quote_for_eval ${1+"$@"}
1741 # my_options_prep_result=$func_quote_for_eval_result
1743 # func_add_hook func_options_prep my_options_prep
1746 # my_silent_option ()
1748 # $debug_cmd
1750 # # Note that for efficiency, we parse as many options as we can
1751 # # recognise in a loop before passing the remainder back to the
1752 # # caller on the first unrecognised argument we encounter.
1753 # while test $# -gt 0; do
1754 # opt=$1; shift
1755 # case $opt in
1756 # --silent|-s) opt_silent=: ;;
1757 # # Separate non-argument short options:
1758 # -s*) func_split_short_opt "$_G_opt"
1759 # set dummy "$func_split_short_opt_name" \
1760 # "-$func_split_short_opt_arg" ${1+"$@"}
1761 # shift
1762 # ;;
1763 # *) set dummy "$_G_opt" "$*"; shift; break ;;
1764 # esac
1765 # done
1767 # func_quote_for_eval ${1+"$@"}
1768 # my_silent_option_result=$func_quote_for_eval_result
1770 # func_add_hook func_parse_options my_silent_option
1773 # my_option_validation ()
1775 # $debug_cmd
1777 # $opt_silent && $opt_verbose && func_fatal_help "\
1778 # '--silent' and '--verbose' options are mutually exclusive."
1780 # func_quote_for_eval ${1+"$@"}
1781 # my_option_validation_result=$func_quote_for_eval_result
1783 # func_add_hook func_validate_options my_option_validation
1785 # You'll alse need to manually amend $usage_message to reflect the extra
1786 # options you parse. It's preferable to append if you can, so that
1787 # multiple option parsing hooks can be added safely.
1790 # func_options [ARG]...
1791 # ---------------------
1792 # All the functions called inside func_options are hookable. See the
1793 # individual implementations for details.
1794 func_hookable func_options
1795 func_options ()
1797 $debug_cmd
1799 func_options_prep ${1+"$@"}
1800 eval func_parse_options \
1801 ${func_options_prep_result+"$func_options_prep_result"}
1802 eval func_validate_options \
1803 ${func_parse_options_result+"$func_parse_options_result"}
1805 eval func_run_hooks func_options \
1806 ${func_validate_options_result+"$func_validate_options_result"}
1808 # save modified positional parameters for caller
1809 func_options_result=$func_run_hooks_result
1813 # func_options_prep [ARG]...
1814 # --------------------------
1815 # All initialisations required before starting the option parse loop.
1816 # Note that when calling hook functions, we pass through the list of
1817 # positional parameters. If a hook function modifies that list, and
1818 # needs to propogate that back to rest of this script, then the complete
1819 # modified list must be put in 'func_run_hooks_result' before
1820 # returning.
1821 func_hookable func_options_prep
1822 func_options_prep ()
1824 $debug_cmd
1826 # Option defaults:
1827 opt_verbose=false
1828 opt_warning_types=
1830 func_run_hooks func_options_prep ${1+"$@"}
1832 # save modified positional parameters for caller
1833 func_options_prep_result=$func_run_hooks_result
1837 # func_parse_options [ARG]...
1838 # ---------------------------
1839 # The main option parsing loop.
1840 func_hookable func_parse_options
1841 func_parse_options ()
1843 $debug_cmd
1845 func_parse_options_result=
1847 # this just eases exit handling
1848 while test $# -gt 0; do
1849 # Defer to hook functions for initial option parsing, so they
1850 # get priority in the event of reusing an option name.
1851 func_run_hooks func_parse_options ${1+"$@"}
1853 # Adjust func_parse_options positional parameters to match
1854 eval set dummy "$func_run_hooks_result"; shift
1856 # Break out of the loop if we already parsed every option.
1857 test $# -gt 0 || break
1859 _G_opt=$1
1860 shift
1861 case $_G_opt in
1862 --debug|-x) debug_cmd='set -x'
1863 func_echo "enabling shell trace mode"
1864 $debug_cmd
1867 --no-warnings|--no-warning|--no-warn)
1868 set dummy --warnings none ${1+"$@"}
1869 shift
1872 --warnings|--warning|-W)
1873 test $# = 0 && func_missing_arg $_G_opt && break
1874 case " $warning_categories $1" in
1875 *" $1 "*)
1876 # trailing space prevents matching last $1 above
1877 func_append_uniq opt_warning_types " $1"
1879 *all)
1880 opt_warning_types=$warning_categories
1882 *none)
1883 opt_warning_types=none
1884 warning_func=:
1886 *error)
1887 opt_warning_types=$warning_categories
1888 warning_func=func_fatal_error
1891 func_fatal_error \
1892 "unsupported warning category: '$1'"
1894 esac
1895 shift
1898 --verbose|-v) opt_verbose=: ;;
1899 --version) func_version ;;
1900 -\?|-h) func_usage ;;
1901 --help) func_help ;;
1903 # Separate optargs to long options (plugins may need this):
1904 --*=*) func_split_equals "$_G_opt"
1905 set dummy "$func_split_equals_lhs" \
1906 "$func_split_equals_rhs" ${1+"$@"}
1907 shift
1910 # Separate optargs to short options:
1911 -W*)
1912 func_split_short_opt "$_G_opt"
1913 set dummy "$func_split_short_opt_name" \
1914 "$func_split_short_opt_arg" ${1+"$@"}
1915 shift
1918 # Separate non-argument short options:
1919 -\?*|-h*|-v*|-x*)
1920 func_split_short_opt "$_G_opt"
1921 set dummy "$func_split_short_opt_name" \
1922 "-$func_split_short_opt_arg" ${1+"$@"}
1923 shift
1926 --) break ;;
1927 -*) func_fatal_help "unrecognised option: '$_G_opt'" ;;
1928 *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1929 esac
1930 done
1932 # save modified positional parameters for caller
1933 func_quote_for_eval ${1+"$@"}
1934 func_parse_options_result=$func_quote_for_eval_result
1938 # func_validate_options [ARG]...
1939 # ------------------------------
1940 # Perform any sanity checks on option settings and/or unconsumed
1941 # arguments.
1942 func_hookable func_validate_options
1943 func_validate_options ()
1945 $debug_cmd
1947 # Display all warnings if -W was not given.
1948 test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1950 func_run_hooks func_validate_options ${1+"$@"}
1952 # Bail if the options were screwed!
1953 $exit_cmd $EXIT_FAILURE
1955 # save modified positional parameters for caller
1956 func_validate_options_result=$func_run_hooks_result
1961 ## ----------------- ##
1962 ## Helper functions. ##
1963 ## ----------------- ##
1965 # This section contains the helper functions used by the rest of the
1966 # hookable option parser framework in ascii-betical order.
1969 # func_fatal_help ARG...
1970 # ----------------------
1971 # Echo program name prefixed message to standard error, followed by
1972 # a help hint, and exit.
1973 func_fatal_help ()
1975 $debug_cmd
1977 eval \$ECHO \""Usage: $usage"\"
1978 eval \$ECHO \""$fatal_help"\"
1979 func_error ${1+"$@"}
1980 exit $EXIT_FAILURE
1984 # func_help
1985 # ---------
1986 # Echo long help message to standard output and exit.
1987 func_help ()
1989 $debug_cmd
1991 func_usage_message
1992 $ECHO "$long_help_message"
1993 exit 0
1997 # func_missing_arg ARGNAME
1998 # ------------------------
1999 # Echo program name prefixed message to standard error and set global
2000 # exit_cmd.
2001 func_missing_arg ()
2003 $debug_cmd
2005 func_error "Missing argument for '$1'."
2006 exit_cmd=exit
2010 # func_split_equals STRING
2011 # ------------------------
2012 # Set func_split_equals_lhs and func_split_equals_rhs shell variables after
2013 # splitting STRING at the '=' sign.
2014 test -z "$_G_HAVE_XSI_OPS" \
2015 && (eval 'x=a/b/c;
2016 test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2017 && _G_HAVE_XSI_OPS=yes
2019 if test yes = "$_G_HAVE_XSI_OPS"
2020 then
2021 # This is an XSI compatible shell, allowing a faster implementation...
2022 eval 'func_split_equals ()
2024 $debug_cmd
2026 func_split_equals_lhs=${1%%=*}
2027 func_split_equals_rhs=${1#*=}
2028 test "x$func_split_equals_lhs" = "x$1" \
2029 && func_split_equals_rhs=
2031 else
2032 # ...otherwise fall back to using expr, which is often a shell builtin.
2033 func_split_equals ()
2035 $debug_cmd
2037 func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2038 func_split_equals_rhs=
2039 test "x$func_split_equals_lhs" = "x$1" \
2040 || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2042 fi #func_split_equals
2045 # func_split_short_opt SHORTOPT
2046 # -----------------------------
2047 # Set func_split_short_opt_name and func_split_short_opt_arg shell
2048 # variables after splitting SHORTOPT after the 2nd character.
2049 if test yes = "$_G_HAVE_XSI_OPS"
2050 then
2051 # This is an XSI compatible shell, allowing a faster implementation...
2052 eval 'func_split_short_opt ()
2054 $debug_cmd
2056 func_split_short_opt_arg=${1#??}
2057 func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2059 else
2060 # ...otherwise fall back to using expr, which is often a shell builtin.
2061 func_split_short_opt ()
2063 $debug_cmd
2065 func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
2066 func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2068 fi #func_split_short_opt
2071 # func_usage
2072 # ----------
2073 # Echo short help message to standard output and exit.
2074 func_usage ()
2076 $debug_cmd
2078 func_usage_message
2079 $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2080 exit 0
2084 # func_usage_message
2085 # ------------------
2086 # Echo short help message to standard output.
2087 func_usage_message ()
2089 $debug_cmd
2091 eval \$ECHO \""Usage: $usage"\"
2092 echo
2093 $SED -n 's|^# ||
2094 /^Written by/{
2095 x;p;x
2098 /^Written by/q' < "$progpath"
2099 echo
2100 eval \$ECHO \""$usage_message"\"
2104 # func_version
2105 # ------------
2106 # Echo version message to standard output and exit.
2107 func_version ()
2109 $debug_cmd
2111 printf '%s\n' "$progname $scriptversion"
2112 $SED -n '
2113 /(C)/!b go
2114 :more
2115 /\./!{
2117 s|\n# | |
2118 b more
2121 /^# Written by /,/# warranty; / {
2122 s|^# ||
2123 s|^# *$||
2124 s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2127 /^# Written by / {
2128 s|^# ||
2131 /^warranty; /q' < "$progpath"
2133 exit $?
2137 # Local variables:
2138 # mode: shell-script
2139 # sh-indentation: 2
2140 # eval: (add-hook 'before-save-hook 'time-stamp)
2141 # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2142 # time-stamp-time-zone: "UTC"
2143 # End:
2144 #! /bin/sh
2146 # Extract macro arguments from autotools input with GNU M4.
2147 # Written by Gary V. Vaughan, 2010
2149 # Copyright (C) 2010-2014, 2017 Free Software Foundation, Inc.
2150 # This is free software; see the source for copying conditions. There is NO
2151 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2153 # Make sure we've evaluated scripts we depend on.
2154 test -z "$progpath" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/funclib.sh
2155 test extract-trace = "$progname" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/options-parser
2157 # Set a version string.
2158 scriptversion=2014-01-04.01; # UTC
2160 # This program is free software: you can redistribute it and/or modify
2161 # it under the terms of the GNU General Public License as published by
2162 # the Free Software Foundation, either version 3 of the License, or
2163 # (at your option) any later version.
2165 # This program is distributed in the hope that it will be useful,
2166 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2167 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2168 # GNU General Public License for more details.
2170 # You should have received a copy of the GNU General Public License
2171 # along with this program. If not, see <http://www.gnu.org/licenses/>.
2173 # Please report bugs or propose patches to gary@gnu.org.
2176 ## ------ ##
2177 ## Usage. ##
2178 ## ------ ##
2180 # Run './extract-trace --help' for help with using this script from the
2181 # command line.
2183 # Or source first 'options-parser' and then this file into your own
2184 # scripts in order to make use of the function and variable framework
2185 # they define, and also to avoid the overhead of forking to run this
2186 # script in its own process on every call.
2190 ## ----------------- ##
2191 ## Helper functions. ##
2192 ## ----------------- ##
2194 # This section contains the helper functions used by the rest of
2195 # 'extract-trace'.
2198 # func_autoconf_configure MAYBE-CONFIGURE-FILE
2199 # --------------------------------------------
2200 # Ensure that MAYBE-CONFIGURE-FILE is the name of a file in the current
2201 # directory that contains an uncommented call to AC_INIT.
2202 func_autoconf_configure ()
2204 $debug_cmd
2206 _G_sed_no_comment='
2207 s|#.*$||
2208 s|^dnl .*$||
2209 s| dnl .*$||'
2210 _G_ac_init=
2212 # If we were passed a genuine file, make sure it calls AC_INIT.
2213 test -f "$1" \
2214 && _G_ac_init=`$SED "$_G_sed_no_comment" "$1" |$GREP AC_INIT`
2216 # Otherwise it is not a genuine Autoconf input file.
2217 test -n "$_G_ac_init"
2218 _G_status=$?
2220 test 0 -ne "$_G_status" \
2221 && func_verbose "'$1' not using Autoconf"
2223 (exit $_G_status)
2227 # func_find_tool ENVVAR NAMES...
2228 # ------------------------------
2229 # Search for a required program. Use the value of ENVVAR, if set,
2230 # otherwise find the first of the NAMES that can be run (i.e.,
2231 # supports --version). If found, set ENVVAR to the program name,
2232 # die otherwise.
2233 func_find_tool ()
2235 $debug_cmd
2237 _G_find_tool_envvar=$1
2238 shift
2239 _G_find_tool_names=$@
2240 eval "_G_find_tool_res=\$$_G_find_tool_envvar"
2241 if test -n "$_G_find_tool_res"; then
2242 _G_find_tool_error_prefix="\$$find_tool_envvar: "
2243 else
2244 for _G_prog
2246 if func_tool_version_output $_G_prog >/dev/null; then
2247 _G_find_tool_res=$_G_prog
2248 break
2250 done
2252 if test -n "$_G_find_tool_res"; then
2253 func_tool_version_output >/dev/null $_G_find_tool_res "\
2254 ${_G_find_tool_error_prefix}Cannot run '$_G_find_tool_res --version'"
2256 # Make sure the result is exported to the environment for children
2257 # to use.
2258 eval "$_G_find_tool_envvar=\$_G_find_tool_res"
2259 eval "export $_G_find_tool_envvar"
2260 else
2261 func_error "\
2262 One of these is required:
2263 $_G_find_tool_names"
2268 # func_tool_version_output CMD [FATAL-ERROR-MSG]
2269 # ----------------------------------------------
2270 # Attempt to run 'CMD --version', discarding errors. The output can be
2271 # ignored by redirecting stdout, and this function used simply to test
2272 # whether the command exists and exits normally when passed a
2273 # '--version' argument.
2274 # When FATAL-ERROR-MSG is given, then this function will display the
2275 # message and exit if running 'CMD --version' returns a non-zero exit
2276 # status.
2277 func_tool_version_output ()
2279 $debug_cmd
2281 _G_cmd=$1
2282 _G_fatal_error_msg=$2
2284 # Some tools, like 'git2cl' produce thousands of lines of output
2285 # unless stdin is /dev/null - in that case we want to return
2286 # successfully without saving all of that output. Other tools,
2287 # such as 'help2man' exit with a non-zero status when stdin comes
2288 # from /dev/null, so we re-execute without /dev/null if that
2289 # happens. This means that occasionally, the output from both calls
2290 # ends up in the result, but the alternative would be to discard the
2291 # output from one call, and hope the other produces something useful.
2292 { $_G_cmd --version </dev/null || $_G_cmd --version; } 2>/dev/null
2293 _G_status=$?
2295 test 0 -ne "$_G_status" && test -n "$_G_fatal_error_msg" \
2296 && func_fatal_error "$_G_fatal_error_msg"
2298 (exit $_G_status)
2302 ## -------------------- ##
2303 ## Resource management. ##
2304 ## -------------------- ##
2306 # This section contains definitions for functions that each ensure a
2307 # particular resource (a file, or a non-empty configuration variable for
2308 # example) is available, and if appropriate to extract default values
2309 # from pertinent package files. Where a variable already has a non-
2310 # empty value (as set by the package's 'bootstrap.conf'), that value is
2311 # used in preference to deriving the default. Call them using their
2312 # associated 'require_*' variable to ensure that they are executed, at
2313 # most, once.
2315 # It's entirely deliberate that calling these functions can set
2316 # variables that don't obey the namespace limitations obeyed by the rest
2317 # of this file, in order that that they be as useful as possible to
2318 # callers.
2321 # require_configure_ac
2322 # --------------------
2323 # Ensure that there is a 'configure.ac' or 'configure.in' file in the
2324 # current directory that contains an uncommented call to AC_INIT, and
2325 # that '$configure_ac' contains its name.
2326 require_configure_ac=func_require_configure_ac
2327 func_require_configure_ac ()
2329 $debug_cmd
2331 test -z "$configure_ac" \
2332 && func_autoconf_configure configure.ac && configure_ac=configure.ac
2333 test -z "$configure_ac" \
2334 && func_autoconf_configure configure.in && configure_ac=configure.in
2335 test -z "$configure_ac" \
2336 || func_verbose "found '$configure_ac'"
2338 require_configure_ac=:
2342 # require_gnu_m4
2343 # --------------
2344 # Search for GNU M4, and export it in $M4.
2345 require_gnu_m4=func_require_gnu_m4
2346 func_require_gnu_m4 ()
2348 $debug_cmd
2350 test -n "$M4" || {
2351 # Find the first m4 binary that responds to --version.
2352 func_find_tool M4 gm4 gnum4 m4
2355 test -n "$M4" || func_fatal_error "\
2356 Please install GNU M4, or 'export M4=/path/to/gnu/m4'."
2358 func_verbose "export M4='$M4'"
2360 # Make sure the search result is visible to subshells
2361 export M4
2363 require_gnu_m4=:
2367 ## --------------- ##
2368 ## Core functions. ##
2369 ## --------------- ##
2371 # This section contains the high level functions used when calling this
2372 # file as a script. 'func_extract_trace' is probably the only one that you
2373 # won't want to replace if you source this file into your own script.
2376 # func_extract_trace MACRO_NAMES [FILENAME]...
2377 # --------------------------------------------
2378 # set '$func_extract_trace_result' to a colon delimited list of arguments
2379 # to any of the comma separated list of MACRO_NAMES in FILENAME. If no
2380 # FILENAME is given, then '$configure_ac' is assumed.
2381 func_extract_trace ()
2383 $debug_cmd
2385 $require_configure_ac
2386 $require_gnu_m4
2388 _G_m4_traces=`$ECHO "--trace=$1" |$SED 's%,% --trace=%g'`
2389 _G_re_macros=`$ECHO "($1)" |$SED 's%,%|%g'`
2390 _G_macros="$1"; shift
2391 test $# -gt 0 || {
2392 set dummy $configure_ac
2393 shift
2396 # Generate an error if the first file is missing
2397 <"$1"
2399 # Sadly, we can't use 'autom4te' tracing to extract macro arguments,
2400 # because it complains about things we want to ignore at bootstrap
2401 # time - like missing m4_include files; AC_PREREQ being newer than
2402 # the installed autoconf; and returns nothing when tracing
2403 # 'AM_INIT_AUTOMAKE' when aclocal hasn't been generated yet.
2405 # The following tries to emulate a less persnickety version of (and
2406 # due to not having to wait for Perl startup on every invocation,
2407 # it's probably faster too):
2409 # autom4te --language=Autoconf --trace=$my_macro:\$% "$@"
2411 # First we give a minimal set of macro declarations to M4 to prime
2412 # it for reading Autoconf macros, while still providing some of the
2413 # functionality generally used at m4-time to supply dynamic
2414 # arguments to Autocof functions, but without following
2415 # 'm4_s?include' files.
2416 _G_mini='
2417 # Initialisation.
2418 m4_changequote([,])
2419 m4_define([m4_copy], [m4_define([$2], m4_defn([$1]))])
2420 m4_define([m4_rename], [m4_copy([$1], [$2])m4_undefine([$1])])
2422 # Disable these macros.
2423 m4_undefine([m4_dnl])
2424 m4_undefine([m4_include])
2425 m4_undefine([m4_m4exit])
2426 m4_undefine([m4_m4wrap])
2427 m4_undefine([m4_maketemp])
2429 # Copy and rename macros not handled by "m4 --prefix".
2430 m4_define([dnl], [m4_builtin([dnl])])
2431 m4_copy([m4_define], [m4_defun])
2432 m4_rename([m4_ifelse], [m4_if])
2433 m4_ifdef([m4_mkstemp], [m4_undefine([m4_mkstemp])])
2434 m4_rename([m4_patsubst], [m4_bpatsubst])
2435 m4_rename([m4_regexp], [m4_bregexp])
2437 # "m4sugar.mini" - useful m4-time macros for dynamic arguments.
2438 # If we discover packages that need more m4 macros defined in
2439 # order to bootstrap correctly, add them here:
2440 m4_define([m4_bmatch],
2441 [m4_if([$#], 0, [], [$#], 1, [], [$#], 2, [$2],
2442 [m4_if(m4_bregexp([$1], [$2]), -1,
2443 [$0([$1], m4_shift3($@))], [$3])])])
2444 m4_define([m4_ifndef], [m4_ifdef([$1], [$3], [$2])])
2445 m4_define([m4_ifset],
2446 [m4_ifdef([$1], [m4_ifval(m4_defn([$1]), [$2], [$3])], [$3])])
2447 m4_define([m4_require], [$1])
2448 m4_define([m4_shift3], [m4_shift(m4shift(m4shift($@)))])
2450 # "autoconf.mini" - things from autoconf macros we care about.
2451 m4_copy([m4_defun], [AC_DEFUN])
2453 # Dummy definitions for the macros we want to trace.
2454 # AM_INIT_AUTOMAKE at least produces no trace without this.
2457 _G_save=$IFS
2458 IFS=,
2459 for _G_macro in $_G_macros; do
2460 IFS=$_G_save
2461 func_append _G_mini "AC_DEFUN([$_G_macro])$nl"
2462 done
2463 IFS=$_G_save
2465 # We discard M4's stdout, but the M4 trace output from reading our
2466 # "autoconf.mini" followed by any other files passed to this
2467 # function is then scanned by sed to transform it into a colon
2468 # delimited argument list assigned to a shell variable.
2469 _G_transform='s|#.*$||; s|^dnl .*$||; s| dnl .*$||;'
2471 # Unfortunately, alternation in regexp addresses doesn't work in at
2472 # least BSD (and hence Mac OS X) sed, so we have to append a capture
2473 # and print block for each traced macro to the sed transform script.
2474 _G_save=$IFS
2475 IFS=,
2476 for _G_macro in $_G_macros; do
2477 IFS=$_G_save
2478 func_append _G_transform '
2479 /^m4trace: -1- '"$_G_macro"'/ {
2480 s|^m4trace: -1- '"$_G_macro"'[([]*||
2481 s|], [[]|:|g
2482 s|[])]*$|:|
2483 s|\(.\):$|\1|
2486 done
2487 IFS=$_G_save
2489 # Save the command pipeline results for further use by callers of
2490 # this function.
2491 func_extract_trace_result=`$ECHO "$_G_mini" \
2492 |$M4 -daq --prefix $_G_m4_traces - "$@" 2>&1 1>/dev/null \
2493 |$SED -n -e "$_G_transform"`
2497 # func_extract_trace_first MACRO_NAMES [FILENAME]...
2498 # --------------------------------------------------
2499 # Exactly like func_extract_trace, except that only the first argument
2500 # to the first invocation of one of the comma separated MACRO_NAMES is
2501 # returned in '$func_extract_trace_first_result'.
2502 func_extract_trace_first ()
2504 $debug_cmd
2506 func_extract_trace ${1+"$@"}
2507 func_extract_trace_first_result=`$ECHO "$func_extract_trace_result" \
2508 |$SED -e 's|:.*$||g' -e 1q`
2512 # func_main [ARG]...
2513 # ------------------
2514 func_main ()
2516 $debug_cmd
2518 # Configuration.
2519 usage='$progname MACRO_NAME FILE [...]'
2521 long_help_message='
2522 The first argument to this program is the name of an autotools macro
2523 whose arguments you want to extract by examining the files listed in the
2524 remaining arguments using the same tool that Autoconf and Automake use,
2525 GNU M4.
2527 The arguments are returned separated by colons, with each traced call
2528 on a separate line.'
2530 # Option processing.
2531 func_options "$@"
2532 eval set dummy "$func_options_result"; shift
2534 # Validate remaining non-option arguments.
2535 test $# -gt 1 \
2536 || func_fatal_help "not enough arguments"
2538 # Pass non-option arguments to extraction function.
2539 func_extract_trace "$@"
2541 # Display results.
2542 test -n "$func_extract_trace_result" \
2543 && $ECHO "$func_extract_trace_result"
2545 # The End.
2546 exit $EXIT_SUCCESS
2550 ## --------------------------- ##
2551 ## Actually perform the trace. ##
2552 ## --------------------------- ##
2554 # Only call 'func_main' if this script was called directly.
2555 test extract-trace = "$progname" && func_main "$@"
2557 # Local variables:
2558 # mode: shell-script
2559 # sh-indentation: 2
2560 # eval: (add-hook 'before-save-hook 'time-stamp)
2561 # time-stamp-pattern: "20/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2562 # time-stamp-time-zone: "UTC"
2563 # End:
2565 # Set a version string for *this* script.
2566 scriptversion=2014-11-04.13; # UTC
2569 ## ------------------- ##
2570 ## Hookable functions. ##
2571 ## ------------------- ##
2573 # After 'bootstrap.conf' has been sourced, execution proceeds by calling
2574 # 'func_bootstrap'. Wherever a function is decorated with
2575 # 'func_hookable func_name', you will find a matching 'func_run_hooks
2576 # func_name', which executes all functions added with 'func_add_hook
2577 # func_name my_func'.
2579 # You might notice that many of these functions begin with a series of
2580 # '$require_foo' lines. See the docu-comments at the start of the
2581 # 'Resource management' section for a description of what these are.
2584 # func_bootstrap [ARG]...
2585 # -----------------------
2586 # All the functions called inside func_bootstrap are hookable. See the
2587 # the individual implementations for details.
2588 func_bootstrap ()
2590 $debug_cmd
2592 # Save the current positional parameters to prevent them being
2593 # corrupted by calls to 'set' in 'func_init'.
2594 func_quote_for_eval ${1+"$@"}
2595 _G_saved_positional_parameters=$func_quote_for_eval_result
2597 # Initialisation.
2598 func_init
2600 # Option processing.
2601 eval func_options "$_G_saved_positional_parameters"
2603 # Post-option preparation.
2604 func_prep
2606 # Reconfigure the package.
2607 func_reconfigure
2609 # Ensure .version is up-to-date.
2610 func_update_dotversion
2612 # Finalisation.
2613 func_fini
2617 # func_init
2618 # ---------
2619 # Any early initialisations can be hooked to this function. Consider
2620 # whether you can hook onto 'func_prep' instead, because if you hook
2621 # any slow to execute code in here, it will also add to the time before
2622 # './bootstrap --version' can respond.
2623 func_hookable func_init
2624 func_init ()
2626 $debug_cmd
2628 func_run_hooks func_init
2632 # func_prep
2633 # ---------
2634 # Function to perform preparation for remaining bootstrap process. If
2635 # your hooked code relies on the outcome of 'func_options' hook it here
2636 # rather than to 'func_init'.
2638 # All the functions called inside func_prep are hookable. See the
2639 # individual implementations for details.
2640 func_hookable func_prep
2641 func_prep ()
2643 $debug_cmd
2645 $require_buildtools_uptodate
2646 $require_checkout_only_file
2648 $require_gnulib_merge_changelog
2650 # Report the results of SED and GREP searches from funclib.sh.
2651 func_verbose "GREP='$GREP'"
2652 func_verbose "SED='$SED'"
2654 # fetch update files from the translation project
2655 func_update_translations
2657 func_run_hooks func_prep
2661 # func_update_translations
2662 # ------------------------
2663 # Update package po files and translations.
2664 func_hookable func_update_translations
2665 func_update_translations ()
2667 $debug_cmd
2669 $opt_skip_po || {
2670 test -d po && {
2671 $require_package
2673 func_update_po_files po $package || exit $?
2676 func_run_hooks func_update_translations
2681 # func_reconfigure
2682 # ----------------
2683 # Reconfigure the current package by running the appropriate autotools in a
2684 # suitable order.
2685 func_hookable func_reconfigure
2686 func_reconfigure ()
2688 $debug_cmd
2690 $require_automake_options
2692 # Automake (without 'foreign' option) requires that README exists.
2693 case " $automake_options " in
2694 " foreign ") ;;
2695 *) func_ensure_README ;;
2696 esac
2698 # Ensure ChangeLog presence.
2699 if test -n "$gnulib_modules"; then
2700 func_ifcontains "$gnulib_modules" gitlog-to-changelog \
2701 func_ensure_changelog
2702 else
2703 $require_gnulib_cache
2704 if $SED -n '/^gl_MODULES(\[/,/^])$/p' $gnulib_cache 2>/dev/null |
2705 func_grep_q gitlog-to-changelog
2706 then
2707 func_ensure_changelog
2711 # Released 'autopoint' has the tendency to install macros that have
2712 # been obsoleted in current 'gnulib', so run this before 'gnulib-tool'.
2713 func_autopoint
2715 # Autoreconf runs 'aclocal' before 'libtoolize', which causes spurious
2716 # warnings if the initial 'aclocal' is confused by the libtoolized
2717 # (or worse: out-of-date) macro directory.
2718 func_libtoolize
2720 # If you need to do anything after 'gnulib-tool' is done, but before
2721 # 'autoreconf' runs, you don't need to override this whole function,
2722 # because 'func_gnulib_tool' is hookable.
2723 func_gnulib_tool
2725 func_autoreconf
2727 func_run_hooks func_reconfigure
2731 # func_gnulib_tool
2732 # ----------------
2733 # Run 'gnulib-tool' to fetch gnulib modules into the current package.
2735 # It's assumed that since you are using gnulib's 'bootstrap' script,
2736 # you're also using gnulib elsewhere in your package. If not, then
2737 # you can replace this function in 'bootstrap.conf' with:
2739 # func_gnulib_tool () { :; }
2741 # (although the function returns immediately if $gnulib_tool is set to
2742 # true in any case).
2743 func_hookable func_gnulib_tool
2744 func_gnulib_tool ()
2746 $debug_cmd
2748 $require_gnulib_tool
2749 $require_libtoolize
2751 test true = "$gnulib_tool" || {
2752 # bootstrap.conf written for gnulib bootstrap expects
2753 # gnulib_tool_option_extras to which --no-changelog is appended,
2754 # but libtool bootstrap expects you to append to gnulib_tool_options
2755 # so that you can override the --no-changelog default: make sure we
2756 # support both styles so users can migrate between them easily.
2757 gnulib_tool_all_options="$gnulib_tool_options $gnulib_tool_option_extras"
2759 if test -n "$gnulib_modules"; then
2760 $require_gnulib_cache
2761 $require_gnulib_tool_base_options
2763 gnulib_mode=--import
2765 # Try not to pick up any stale values from 'gnulib-cache.m4'.
2766 rm -f "$gnulib_cache"
2768 test -n "$gnulib_tool_base_options" \
2769 && func_append_uniq gnulib_tool_all_options " $gnulib_tool_base_options"
2770 test -n "$gnulib_mk" \
2771 && func_append_uniq gnulib_tool_all_options " --makefile-name=$gnulib_mk"
2772 test -n "$tests_base" && {
2773 func_append_uniq gnulib_tool_all_options " --tests-base=$tests_base"
2774 func_append_uniq gnulib_tool_all_options " --with-tests"
2776 else
2778 # 'gnulib_modules' and others are cached in 'gnulib-cache.m4':
2779 # Use 'gnulib --update' to fetch gnulib modules.
2780 gnulib_mode=--update
2783 # Add a sensible default libtool option to gnulib_tool_options.
2784 # The embedded echo is to squash whitespace before globbing.
2785 case `echo " "$gnulib_tool_all_options" "` in
2786 *" --no-libtool "*|*" --libtool "*) ;;
2787 *) if test true = "$LIBTOOLIZE"; then
2788 func_append_uniq gnulib_tool_all_options " --no-libtool"
2789 else
2790 func_append_uniq gnulib_tool_all_options " --libtool"
2793 esac
2795 $opt_copy || func_append_uniq gnulib_tool_all_options " --symlink"
2797 func_append_uniq gnulib_tool_all_options " $gnulib_mode"
2798 func_append gnulib_tool_all_options " $gnulib_modules"
2800 # The embedded echo is to squash whitespace before display.
2801 gnulib_cmd=`echo $gnulib_tool $gnulib_tool_all_options`
2803 func_show_eval "$gnulib_cmd" 'exit $?'
2805 # Use 'gnulib-tool --copy-file' to install non-module files.
2806 func_install_gnulib_non_module_files
2809 func_run_hooks func_gnulib_tool
2813 # func_fini
2814 # ---------
2815 # Function to perform all finalisation for the bootstrap process.
2816 func_hookable func_fini
2817 func_fini ()
2819 $debug_cmd
2821 func_gettext_configuration
2822 func_clean_dangling_symlinks
2823 func_clean_unused_macros
2824 func_skip_po_recommendation
2826 func_run_hooks func_fini
2828 $require_bootstrap_uptodate
2830 func_echo "Done. Now you can run './configure'."
2834 # func_gettext_configuration
2835 # --------------------------
2836 # Edit configuration values into po/Makevars.
2837 func_hookable func_gettext_configuration
2838 func_gettext_configuration ()
2840 $debug_cmd
2842 $require_autopoint
2844 test true = "$AUTOPOINT" || {
2845 $require_copyright_holder
2846 $require_extra_locale_categories
2847 $require_package_bugreport
2849 # Escape xgettext options for sed Makevars generation below.
2850 # We have to delete blank lines in a separate script so that we don't
2851 # append \\\ to the penultimate line, and then delete the last empty
2852 # line, which messes up the variable substitution later in this
2853 # function. Note that adding a literal \\\ requires double escaping
2854 # here, once for the execution subshell, and again for the assignment,
2855 # which is why there are actually 12 (!!) backslashes in the script.
2856 _G_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED '
2858 s|$| \\\\\\\\\\\\|'`
2860 # Create gettext configuration.
2861 func_echo "Creating po/Makevars from po/Makevars.template ..."
2862 $RM -f po/Makevars
2863 $SED '
2864 /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'|
2865 /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'|
2866 /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'|
2867 /^XGETTEXT_OPTIONS *=/{
2868 s|$| \\|
2870 '"$_G_xgettext_options"' \\\
2871 $${end_of_xgettext_options+}
2873 ' po/Makevars.template >po/Makevars || exit 1
2876 func_run_hooks func_gettext_configuration
2881 ## --------------- ##
2882 ## Core functions. ##
2883 ## --------------- ##
2885 # This section contains the main functions called from the 'Hookable
2886 # functions' (shown above), and are the ones you're most likely
2887 # to want to replace with your own implementations in 'bootstrap.conf'.
2890 # func_autopoint
2891 # --------------
2892 # If this package uses gettext, then run 'autopoint'.
2893 func_autopoint ()
2895 $debug_cmd
2897 $require_autopoint
2899 test true = "$AUTOPOINT" \
2900 || func_show_eval "$AUTOPOINT --force" 'exit $?'
2904 # func_libtoolize
2905 # ---------------
2906 # If this package uses libtool, then run 'libtoolize'.
2907 func_libtoolize ()
2909 $debug_cmd
2911 $require_libtoolize
2913 test true = "$LIBTOOLIZE" || {
2914 _G_libtoolize_options=
2915 $opt_copy && func_append _G_libtoolize_options " --copy"
2916 $opt_force && func_append _G_libtoolize_options " --force"
2917 $opt_verbose || func_append _G_libtoolize_options " --quiet"
2918 func_show_eval "$LIBTOOLIZE$_G_libtoolize_options" 'exit $?'
2923 # func_gnulib_tool_copy_file SRC DEST
2924 # -----------------------------------
2925 # Copy SRC, a path relative to the gnulib sub-tree, to DEST, a path
2926 # relative to the top-level source directory using gnulib-tool so that
2927 # any patches or replacements in $local_gl_dir are applied.
2928 func_gnulib_tool_copy_file ()
2930 $debug_cmd
2932 $require_gnulib_tool
2933 $require_patch
2935 if test true = "$gnulib_tool"; then
2936 # If gnulib-tool is not available (e.g. bootstrapping in a
2937 # distribution tarball), make sure that at least we have some
2938 # version of the required file already in place.
2939 test -f "$2" || func_fatal_error "\
2940 Can't find, copy or download '$2', a required
2941 gnulib supplied file, please provide the location of a
2942 complete 'gnulib' tree by setting 'gnulib_path' in your
2943 'bootstrap.conf' or with the '--gnulib-srcdir' option -
2944 or else specify the location of your 'git' binary by
2945 setting 'GIT' in the environment so that a fresh
2946 'gnulib' submodule can be cloned."
2947 else
2948 $require_gnulib_copy_cmd
2950 $gnulib_copy_cmd $1 $2 2>/dev/null || {
2951 $require_gnulib_path
2953 func_error "'$gnulib_path/$1' does not exist"
2954 return 1
2960 # func_install_gnulib_non_module_files
2961 # ------------------------------------
2962 # Get additional non-module files from gnulib, overriding existing files.
2963 func_install_gnulib_non_module_files ()
2965 $debug_cmd
2967 $require_build_aux
2968 $require_gnulib_tool
2970 test -n "$gnulib_non_module_files" && {
2971 maybe_exit_cmd=:
2973 for file in $gnulib_non_module_files; do
2974 case $file in
2975 */COPYING*) dest=COPYING;;
2976 */INSTALL) dest=INSTALL;;
2977 build-aux/missing) dest=
2978 func_warning settings "\
2979 Please remove build-aux/missing from gnulib_module_files in
2980 'bootstrap.conf', as it may clash with Automake's version."
2982 build-aux/*) dest=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
2983 *) dest=$file;;
2984 esac
2986 # Be sure to show all copying errors before bailing out
2987 test -z "$dest" \
2988 || func_gnulib_tool_copy_file "$file" "$dest" \
2989 || maybe_exit_cmd="exit $EXIT_FAILURE"
2990 done
2992 $maybe_exit_cmd
2997 # func_ensure_changelog
2998 # ---------------------
2999 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3000 # will not run to completion with no ChangeLog file.
3001 func_ensure_changelog ()
3003 $debug_cmd
3005 test -f ChangeLog && mv -f ChangeLog ChangeLog~
3007 cat >ChangeLog <<'EOT'
3008 ## ---------------------- ##
3009 ## DO NOT EDIT THIS FILE! ##
3010 ## ---------------------- ##
3012 ChangeLog is generated by gitlog-to-changelog.
3015 _G_message="creating dummy 'ChangeLog'"
3016 test -f ChangeLog~ \
3017 && func_append _G_message ' (backup in ChangeLog~)'
3018 func_verbose "$_G_message"
3020 return 0
3024 # func_ensure_README
3025 # ------------------
3026 # Without AM_INIT_AUTOMAKE([foreign]), automake will not run to
3027 # completion with no README file, even though README.md or README.txt
3028 # is often preferable.
3029 func_ensure_README ()
3031 $debug_cmd
3033 test -f README || {
3034 _G_README=
3035 for _G_readme in README.txt README.md README.rst; do
3036 test -f "$_G_readme" && break
3037 done
3039 test -f "$_G_readme" && $LN_S $_G_readme README
3040 func_verbose "$LN_S $_G_readme README"
3043 return 0
3047 # func_autoreconf [SUBDIR]
3048 # ------------------------
3049 # Being careful not to re-run 'autopoint' or 'libtoolize', and not to
3050 # try to run 'autopoint', 'libtoolize' or 'autoheader' on packages that
3051 # don't use them, defer to 'autoreconf' for execution of the remaining
3052 # autotools to bootstrap this package.
3054 # Projects with multiple trees to reconfigure can hook another call to
3055 # this function onto func_reconfigure:
3057 # my_autoreconf_foo ()
3059 # func_autoreconf foo
3061 # func_add_hook func_reconfigure my_autoreconf_foo
3062 func_autoreconf ()
3064 $debug_cmd
3066 $require_autoheader
3067 $require_build_aux # automake and others put files in here
3068 $require_macro_dir # aclocal and others put files in here
3070 # We ran these manually already, and autoreconf won't exec ':'
3071 save_AUTOPOINT=$AUTOPOINT; AUTOPOINT=true
3072 save_LIBTOOLIZE=$LIBTOOLIZE; LIBTOOLIZE=true
3074 _G_autoreconf_options=
3075 $opt_copy || func_append _G_autoreconf_options " --symlink"
3076 $opt_force && func_append _G_autoreconf_options " --force"
3077 $opt_verbose && func_append _G_autoreconf_options " --verbose"
3078 func_show_eval "$AUTORECONF$_G_autoreconf_options --install${1+ $1}" 'exit $?'
3080 AUTOPOINT=$save_AUTOPOINT
3081 LIBTOOLIZE=$save_LIBTOOLIZE
3085 # func_check_configuration VARNAME [CONFIGURE_MACRO]
3086 # --------------------------------------------------
3087 # Exit with a suitable diagnostic for an important configuration change
3088 # that needs to be made before bootstrap can run correctly.
3089 func_check_configuration ()
3091 $debug_cmd
3093 $require_configure_ac
3095 eval 'test -n "$'$1'"' || {
3096 _G_error_msg="please set '$1' in 'bootstrap.conf'"
3097 if test -n "$configure_ac" && test -n "$2"; then
3098 func_append _G_error_msg "
3099 or add the following (or similar) to your '$configure_ac':
3103 func_fatal_error "$_G_error_msg"
3108 # func_clean_dangling_symlinks
3109 # ----------------------------
3110 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
3111 # gnulib-populated directories. Such .m4 files would cause aclocal to
3112 # fail. The following requires GNU find 4.2.3 or newer. Considering
3113 # the usual portability constraints of this script, that may seem a very
3114 # demanding requirement, but it should be ok. Ignore any failure,
3115 # which is fine, since this is only a convenience to help developers
3116 # avoid the relatively unusual case where a symlinked-to .m4 file is
3117 # git-removed from gnulib between successive runs of this script.
3118 func_clean_dangling_symlinks ()
3120 $debug_cmd
3122 $require_macro_dir
3123 $require_source_base
3125 func_verbose "cleaning dangling symlinks"
3127 find "$macro_dir" "$source_base" \
3128 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
3129 -type l -xtype l -delete > /dev/null 2>&1
3133 # func_clean_unused_macros
3134 # ------------------------
3135 # Autopoint can result in over-zealously adding macros into $macro_dir
3136 # even though they are not actually used, for example tests to help
3137 # build the 'intl' directory even though you have specified
3138 # 'AM_GNU_GETTEXT([external])' in your configure.ac. This function
3139 # looks removes any macro files that can be found in gnulib, but
3140 # are not 'm4_include'd by 'aclocal.m4'.
3141 func_clean_unused_macros ()
3143 $debug_cmd
3145 $require_gnulib_path
3146 $require_macro_dir
3148 test -n "$gnulib_path" && test -f aclocal.m4 && {
3149 aclocal_m4s=`find . -name aclocal.m4 -print`
3151 # We use 'ls|grep' instead of 'ls *.m4' to avoid exceeding
3152 # command line length limits in some shells.
3153 for file in `cd "$macro_dir" && ls -1 |$GREP '\.m4$'`; do
3155 # Remove a macro file when aclocal.m4 does not m4_include it...
3156 func_grep_q 'm4_include([[]'$macro_dir/$file'])' $aclocal_m4s \
3157 || test ! -f "$gnulib_path/m4/$file" || {
3159 # ...and there is an identical file in gnulib...
3160 if func_cmp_s "$gnulib_path/m4/$file" "$macro_dir/$file"; then
3162 # ...and it's not in the precious list ('echo' is needed
3163 # here to squash whitespace for the match expression).
3164 case " "`echo $gnulib_precious`" " in
3165 *" $file "*) ;;
3166 *) rm -f "$macro_dir/$file"
3167 func_verbose \
3168 "removing unused gnulib file '$macro_dir/$file'"
3169 esac
3172 done
3177 # func_skip_po_recommendation
3178 # ---------------------------
3179 # If there is a po directory, and '--skip-po' wasn't passed, let the
3180 # user know that they can use '--skip-po' on subsequent invocations.
3181 func_skip_po_recommendation ()
3183 $debug_cmd
3185 test ! -d po \
3186 || $opt_skip_po \
3187 || func_warning recommend "\
3188 If your pofiles are up-to-date, you can rerun bootstrap
3189 as '$progname --skip-po' to avoid redownloading."
3193 # func_update_dotversion
3194 # ----------------------
3195 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3196 # will not run to completion with no ChangeLog file.
3197 func_update_dotversion ()
3199 $debug_cmd
3201 test -f "$build_aux/git-version-gen" && {
3202 _G_message="updating .version"
3203 test -f .version && {
3204 mv .version .version~
3205 func_append _G_message " (backup in .version~)"
3207 func_verbose "updating .version"
3209 $build_aux/git-version-gen dummy-arg > .version
3215 ## -------------------- ##
3216 ## Resource management. ##
3217 ## -------------------- ##
3219 # This section contains definitions for functions that each ensure a
3220 # particular resource (a file, or a non-empty configuration variable for
3221 # example) is available, and if appropriate to extract default values
3222 # from pertinent package files. Where a variable already has a non-
3223 # empty value (as set by the package's 'bootstrap.conf'), that value is
3224 # used in preference to deriving the default. Call them using their
3225 # associated 'require_*' variable to ensure that they are executed, at
3226 # most, once.
3229 # require_checkout_only_file
3230 # --------------------------
3231 # Bail out if this package only bootstraps properly from a repository
3232 # checkout.
3233 require_checkout_only_file=func_require_checkout_only_file
3234 func_require_checkout_only_file ()
3236 $debug_cmd
3238 $opt_force || {
3239 test -n "$checkout_only_file" && test ! -f "$checkout_only_file" \
3240 && func_fatal_error "\
3241 Bootstrapping from a non-checked-out distribution is risky.
3242 If you wish to bootstrap anyway, use the '--force' option."
3245 require_checkout_only_file=:
3249 # require_aclocal_amflags
3250 # -----------------------
3251 # Ensure '$aclocal_amflags' has a sensible default, extracted from
3252 # 'Makefile.am' if necessary.
3253 require_aclocal_amflags=func_require_aclocal_amflags
3254 func_require_aclocal_amflags ()
3256 $debug_cmd
3258 $require_makefile_am
3260 _G_sed_extract_aclocal_amflags='s|#.*$||
3261 /^[ ]*ACLOCAL_AMFLAGS[ ]*=/ {
3262 s|^.*=[ ]*\(.*\)|aclocal_amflags="\1"|
3266 _G_aclocal_flags_cmd=`$SED -n "$_G_sed_extract_aclocal_amflags" \
3267 "$makefile_am"`
3268 eval "$_G_aclocal_flags_cmd"
3270 func_verbose "ACLOCAL_AMFLAGS='$aclocal_amflags'"
3272 require_aclocal_amflags=:
3276 # require_autoheader
3277 # ------------------
3278 # Skip autoheader if it's not needed.
3279 require_autoheader=func_require_autoheader
3280 func_require_autoheader ()
3282 $debug_cmd
3284 test true = "$AUTOHEADER" || {
3285 func_extract_trace AC_CONFIG_HEADERS
3286 test -n "$func_extract_trace_result" \
3287 || func_extract_trace AC_CONFIG_HEADER
3289 test -n "$func_extract_trace_result" || {
3290 AUTOHEADER=true
3292 func_verbose "export AUTOHEADER='$AUTOHEADER'"
3294 # Make sure the search result is visible to subshells
3295 export AUTOHEADER
3299 require_autoheader=:
3303 # require_automake_options
3304 # ------------------------
3305 # Extract options from AM_AUTOMAKE_INIT.
3306 require_automake_options=func_require_automake_options
3307 func_require_automake_options ()
3309 $debug_cmd
3311 func_extract_trace AM_INIT_AUTOMAKE
3312 automake_options=$func_extract_trace_result
3314 require_automake_options=:
3318 # require_autopoint
3319 # -----------------
3320 # Skip autopoint if it's not needed.
3321 require_autopoint=func_require_autopoint
3322 func_require_autopoint ()
3324 $debug_cmd
3326 test true = "$AUTOPOINT" || {
3327 func_extract_trace AM_GNU_GETTEXT_VERSION
3329 test -n "$func_extract_trace_result" || {
3330 AUTOPOINT=true
3332 func_verbose "export AUTOPOINT='$AUTOPOINT'"
3334 # Make sure the search result is visible to subshells
3335 export AUTOPOINT
3339 require_autopoint=:
3343 # require_bootstrap_uptodate
3344 # --------------------------
3345 # Complain if the version of bootstrap in the gnulib directory differs
3346 # from the one we are running.
3347 require_bootstrap_uptodate=func_require_bootstrap_uptodate
3348 func_require_bootstrap_uptodate ()
3350 $debug_cmd
3352 $require_build_aux
3354 _G_bootstrap_sources="
3355 $build_aux/bootstrap.in
3356 $build_aux/extract-trace
3357 $build_aux/funclib.sh
3358 $build_aux/options-parser
3361 _G_missing_bootstrap_sources=false
3362 for _G_src in $_G_bootstrap_sources; do
3363 test -f "$_G_src" || _G_missing_bootstrap_sources=:
3364 done
3366 if $_G_missing_bootstrap_sources; then
3367 func_warning upgrade "\
3368 Please add bootstrap to your gnulib_modules list in
3369 'bootstrap.conf', so that I can tell you when there are
3370 updates available."
3371 else
3372 rm -f bootstrap.new
3373 $build_aux/inline-source $build_aux/bootstrap.in > bootstrap.new
3375 if func_cmp_s "$progpath" bootstrap.new; then
3376 rm -f bootstrap.new
3377 func_verbose "bootstrap script up to date"
3378 else
3379 chmod 555 bootstrap.new
3380 func_warning upgrade "\
3381 An updated bootstrap script has been generated for you in
3382 'bootstrap.new'. After you've verified that you want
3383 the changes, you can update with:
3384 mv -f bootstrap.new $progname
3385 ./$progname
3387 Or you can disable this check permanently by adding the
3388 following to 'bootstrap.conf':
3389 require_bootstrap_uptodate=:"
3393 require_bootstrap_uptodate=:
3397 # require_build_aux
3398 # -----------------
3399 # Ensure that '$build_aux' is set, and if it doesn't already point to an
3400 # existing directory, create one.
3401 require_build_aux=func_require_build_aux
3402 func_require_build_aux ()
3404 $debug_cmd
3406 test -n "$build_aux" || {
3407 func_extract_trace_first AC_CONFIG_AUX_DIR
3408 build_aux=$func_extract_trace_first_result
3409 func_check_configuration build_aux \
3410 "AC_CONFIG_AUX_DIR([name of a directory for build scripts])"
3412 func_verbose "build_aux='$build_aux'"
3415 $require_vc_ignore_files
3417 # If the build_aux directory doesn't exist, create it now, and mark it
3418 # as ignored for the VCS.
3419 if test ! -d "$build_aux"; then
3420 func_show_eval "mkdir '$build_aux'"
3422 test -n "$vc_ignore_files" \
3423 || func_insert_if_absent "$build_aux" $vc_ignore_files
3426 require_build_aux=:
3430 # require_buildreq_autobuild
3431 # --------------------------
3432 # Try to find whether the bootstrap requires autobuild.
3433 require_buildreq_autobuild=func_require_buildreq_autobuild
3434 func_require_buildreq_autobuild ()
3436 $debug_cmd
3438 $require_macro_dir
3440 test -f "$macro_dir/autobuild.m4" \
3441 || printf '%s\n' "$buildreq" |func_grep_q '^[ ]*autobuild' \
3442 || {
3443 func_extract_trace AB_INIT
3444 test -n "$func_extract_trace_result" && {
3445 func_append buildreq 'autobuild - http://josefsson.org/autobuild/
3447 func_verbose "auto-adding 'autobuild' to build requirements"
3451 require_buildreq_autobuild=:
3455 # require_buildreq_autoconf
3456 # require_buildreq_autopoint
3457 # require_buildreq_libtoolize
3458 # ---------------------------
3459 # Try to find the minimum compatible version of autoconf/libtool
3460 # required to bootstrap successfully, and add it to '$buildreq'.
3461 for tool in autoconf libtoolize autopoint; do
3462 b=$tool
3463 v=require_buildreq_${tool}
3464 f=func_$v
3465 case $tool in
3466 autoconf) m=AC_PREREQ ;;
3467 libtoolize) m=LT_PREREQ; b=libtool ;;
3468 autopoint) m=AM_GNU_GETTEXT_VERSION b=gettext ;;
3469 esac
3471 eval $v'='$f'
3472 '$f' ()
3474 $debug_cmd
3476 # The following is ignored if undefined, but might be necessary
3477 # in order for `func_find_tool` to run.
3478 ${require_'$tool'-:}
3480 printf '\''%s\n'\'' "$buildreq" |func_grep_q '\''^[ ]*'$tool\'' || {
3481 func_extract_trace '$m'
3482 _G_version=$func_extract_trace_result
3483 test -n "$_G_version" && {
3484 func_append buildreq "\
3485 '$tool' $_G_version http://www.gnu.org/s/'$b'
3487 func_verbose \
3488 "auto-adding '\'$tool'-$_G_version'\'' to build requirements"
3492 '$v'=:
3495 done
3498 # require_buildreq_automake
3499 # -------------------------
3500 # Try to find the minimum compatible version of automake required to
3501 # bootstrap successfully, and add it to '$buildreq'.
3502 require_buildreq_automake=func_require_buildreq_automake
3503 func_require_buildreq_automake ()
3505 $debug_cmd
3507 # if automake is not already listed in $buildreq...
3508 printf '%s\n' "$buildreq" |func_grep_q automake || {
3509 func_extract_trace AM_INIT_AUTOMAKE
3511 # ...and AM_INIT_AUTOMAKE is declared...
3512 test -n "$func_extract_trace_result" && {
3513 automake_version=`$ECHO "$func_extract_trace_result" \
3514 |$SED -e 's|[^0-9]*||' -e 's| .*$||'`
3515 test -n "$automake_version" || automake_version=-
3517 func_append buildreq "\
3518 automake $automake_version http://www.gnu.org/s/automake
3520 func_verbose \
3521 "auto-adding 'automake-$automake_version' to build requirements"
3525 require_buildreq_automake=:
3529 # require_buildreq_patch
3530 # ----------------------
3531 # Automatically add a patch build-requirement if there are diff files
3532 # in $local_gl_dir.
3533 require_buildreq_patch=func_require_buildreq_patch
3534 func_require_buildreq_patch ()
3536 $debug_cmd
3538 $require_local_gl_dir
3540 # This ensures PATCH is set appropriately by the time
3541 # func_check_versions enforces $buildreq.
3542 $require_patch
3544 # If patch is not already listed in $buildreq...
3545 printf '%s\n' "$buildreq" |func_grep_q '^[ ]*patch' || {
3546 # The ugly find invocation is necessary to exit with non-zero
3547 # status for old find binaries that don't support -exec fully.
3548 if test ! -d "$local_gl_dir" \
3549 || find "$local_gl_dir" -name "*.diff" -exec false {} \; ; then :
3550 else
3551 func_append buildreq 'patch - http://www.gnu.org/s/patch
3556 require_buildreq_patch=:
3560 # require_buildtools_uptodate
3561 # ---------------------------
3562 # Ensure all the packages listed in BUILDREQS are available on the build
3563 # machine at the minimum versions or better.
3564 require_buildtools_uptodate=func_require_buildtools_uptodate
3565 func_require_buildtools_uptodate ()
3567 $debug_cmd
3569 $require_buildreq_autobuild
3570 $require_buildreq_autoconf
3571 $require_buildreq_automake
3572 $require_buildreq_libtoolize
3573 $require_buildreq_autopoint
3574 $require_buildreq_patch
3576 test -n "$buildreq" && {
3577 _G_error_hdr=
3579 func_check_versions $buildreq
3580 $func_check_versions_result || {
3581 test -n "$buildreq_readme" \
3582 && test -f "$buildreq_readme" \
3583 && _G_error_hdr="\
3584 $buildreq_readme explains how to obtain these prerequisite programs:
3586 func_strtable 0 11 12 36 \
3587 "Program" "Min_version" "Homepage" $buildreq
3588 func_fatal_error "$_G_error_hdr$func_strtable_result"
3592 require_buildtools_uptodate=:
3596 # require_copyright_holder
3597 # ------------------------
3598 # Ensure there is a sensible non-empty default value in '$copyright_holder'.
3599 require_copyright_holder=func_require_copyright_holder
3600 func_require_copyright_holder ()
3602 $debug_cmd
3604 test -n "$copyright_holder" || {
3605 copyright_holder='Free Software Foundation, Inc.'
3606 func_warning settings "\
3607 Please set copyright_holder explicitly in 'bootstrap.conf';
3608 defaulting to '$copyright_holder'."
3611 require_copyright_holder=:
3615 # require_doc_base
3616 # ----------------
3617 # Ensure doc_base has a sensible value, extracted from 'gnulib-cache.m4'
3618 # if possible, otherwise letting 'gnulib-tool' pick a default.
3619 require_doc_base=func_require_doc_base
3620 func_require_doc_base ()
3622 $debug_cmd
3624 $require_gnulib_cache
3626 test -f "$gnulib_cache" && test -z "$doc_base" && {
3627 func_extract_trace_first "gl_DOC_BASE" "$gnulib_cache"
3628 doc_base=$func_extract_trace_first_result
3630 test -n "$doc_base" && func_verbose "doc_base='$doc_base'"
3633 require_doc_base=:
3637 # require_dotgitmodules
3638 # ---------------------
3639 # Ensure we have a '.gitmodules' file, with appropriate 'gnulib' settings.
3640 require_dotgitmodules=func_require_dotgitmodules
3641 func_require_dotgitmodules ()
3643 $debug_cmd
3645 $require_git
3647 test true = "$GIT" || {
3648 # A gnulib entry in .gitmodules always takes precedence.
3649 _G_path=`$GIT config --file .gitmodules submodule.gnulib.path 2>/dev/null`
3651 test -n "$_G_path" || {
3652 $require_vc_ignore_files
3654 func_verbose "creating '.gitmodules'"
3656 # If the .gitmodules file doesn't exist, create it now, and mark
3657 # it as ignored for the VCS.
3658 test -n "$gnulib_path" || gnulib_path=gnulib
3659 test -n "$gnulib_url" || gnulib_url=git://git.sv.gnu.org/gnulib
3662 echo '[submodule "gnulib"]'
3663 echo " path = $gnulib_path"
3664 echo " url = $gnulib_url"
3665 } >> .gitmodules
3667 test -n "$vc_ignore_files" \
3668 || func_insert_if_absent ".gitmodules" $vc_ignore_files
3672 require_dotgitmodules=:
3676 # require_extra_locale_categories
3677 # -------------------------------
3678 # Ensure there is a default value in '$extra_locale_categories'
3679 require_extra_locale_categories=func_require_extra_locale_categories
3680 func_require_extra_locale_categories ()
3682 $debug_cmd
3684 # Defaults to empty, so run with whatever value may have been set in
3685 # 'bootstrap.conf'.
3686 require_extra_locale_categories=:
3690 # require_git
3691 # -----------
3692 # Ignore git if it's not available, or we're not in a git checkout tree.
3693 require_git=func_require_git
3694 func_require_git ()
3696 $debug_cmd
3698 $opt_skip_git && GIT=true
3700 test true = "$GIT" || {
3701 if test -d .git/.; then
3702 ($GIT --version) >/dev/null 2>&1 || GIT=true
3706 func_verbose "GIT='$GIT'"
3708 require_git=:
3712 # require_gnulib_cache
3713 # --------------------
3714 # Ensure there is a non-empty default for '$gnulib_cache', and that it
3715 # names an existing file.
3716 require_gnulib_cache=func_require_gnulib_cache
3717 func_require_gnulib_cache ()
3719 $debug_cmd
3721 $require_macro_dir
3723 test -n "$gnulib_cache" \
3724 || gnulib_cache=$macro_dir/gnulib-cache.m4
3726 func_verbose "found '$gnulib_cache'"
3728 require_gnulib_cache=:
3732 # require_gnulib_copy_cmd
3733 # -----------------------
3734 # Only calculate the options for copying files with gnulib once.
3735 require_gnulib_copy_cmd=func_require_gnulib_copy_cmd
3736 func_require_gnulib_copy_cmd ()
3738 $debug_cmd
3740 $require_gnulib_tool
3741 $require_gnulib_tool_base_options
3743 gnulib_copy_cmd="$gnulib_tool $gnulib_tool_base_options --copy-file"
3744 $opt_copy || func_append gnulib_copy_cmd " --symlink"
3745 $opt_quiet || func_append gnulib_copy_cmd " --verbose"
3747 require_gnulib_copy_cmd=:
3751 # require_gnulib_merge_changelog
3752 # ------------------------------
3753 # See if we can use gnulib's git-merge-changelog merge driver.
3754 require_gnulib_merge_changelog=func_require_gnulib_merge_changelog
3755 func_require_gnulib_merge_changelog ()
3757 $debug_cmd
3759 test -f ChangeLog && {
3760 $require_git
3762 func_grep_q '^\(/\|\)ChangeLog$' .gitignore || test true = "$GIT" || {
3763 if $GIT config merge.merge-changelog.driver >/dev/null; then
3765 elif (git-merge-changelog --version) >/dev/null 2>&1; then
3766 func_echo "initializing git-merge-changelog driver"
3767 $GIT config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
3768 $GIT config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
3769 else
3770 func_warning recommend \
3771 "Consider installing git-merge-changelog from gnulib."
3776 require_gnulib_merge_changelog=:
3780 # require_gnulib_mk
3781 # -----------------
3782 # Ensure gnulib_mk has a sensible value, extracted from 'gnulib-cache.m4'
3783 # if possible, otherwise letting 'gnulib-tool' pick a default.
3784 require_gnulib_mk=func_require_gnulib_mk
3785 func_require_gnulib_mk ()
3787 $debug_cmd
3789 $require_gnulib_cache
3791 test -f "$gnulib_cache" && test -z "$gnulib_mk" && {
3792 func_extract_trace_first "gl_MAKEFILE_NAME" "$gnulib_cache"
3793 gnulib_mk=$func_extract_trace_first_result
3795 test -n "$gnulib_mk" && func_verbose "gnulib_mk='$gnulib_mk'"
3798 require_gnulib_mk=:
3802 # require_gnulib_name
3803 # -------------------
3804 # Ensure gnulib_name has a sensible value, extracted from 'gnulib-cache.m4'
3805 # if possible, otherwise letting 'gnulib-tool' pick a default.
3806 require_gnulib_name=func_require_gnulib_name
3807 func_require_gnulib_name ()
3809 $debug_cmd
3811 $require_gnulib_cache
3813 test -f "$gnulib_cache" && test -z "$gnulib_name" && {
3814 func_extract_trace_first "gl_LIB" "$gnulib_cache"
3815 gnulib_name=$func_extract_trace_first_result
3817 test -n "$gnulib_name" && func_verbose "gnulib_name='$gnulib_name'"
3820 require_gnulib_name=:
3824 # require_gnulib_path
3825 # require_gnulib_url
3826 # -------------------
3827 # Ensure 'gnulib_path' and 'gnulib_url' are set.
3828 require_gnulib_path=func_require_dotgitmodules_parameters
3829 require_gnulib_url=func_require_dotgitmodules_parameters
3830 func_require_dotgitmodules_parameters ()
3832 $debug_cmd
3834 $require_git
3836 test true = "$GIT" && {
3837 # If we can't find git (or if the user specified '--skip-git'),
3838 # then use an existing gnulib directory specified with
3839 # '--gnulib-srcdir' if possible.
3840 test -n "$gnulib_path" \
3841 || test ! -x "$opt_gnulib_srcdir/gnulib-tool" \
3842 || gnulib_path=$opt_gnulib_srcdir
3846 $require_dotgitmodules
3848 test -f .gitmodules && {
3849 # Extract the parameters with sed, since git may be missing
3850 test -n "$gnulib_path" \
3851 || gnulib_path=`$SED -e '/^.submodule "gnulib".$/,${
3852 /[ ]*path *= */{
3853 s|[ ]*||g;s|^[^=]*=||;p
3856 d' .gitmodules |$SED 1q`
3857 test -n "$gnulib_url" \
3858 || gnulib_url=`$SED -e '/^.submodule "gnulib".$/,${
3859 /[ ]*url *= */{
3860 s|[ ]*||g;s|^[^=]*=||;p
3863 d' .gitmodules |$SED 1q`
3865 func_verbose "gnulib_path='$gnulib_path'"
3866 func_verbose "gnulib_url='$gnulib_url'"
3869 require_gnulib_path=:
3870 require_gnulib_url=:
3874 # require_gnulib_submodule
3875 # ------------------------
3876 # Ensure that there is a current gnulib submodule at '$gnulib_path'.
3877 require_gnulib_submodule=func_require_gnulib_submodule
3878 func_require_gnulib_submodule ()
3880 $debug_cmd
3882 $require_git
3884 if test true = "$GIT"; then
3885 func_warning recommend \
3886 "No 'git' found; imported gnulib modules may be outdated."
3887 else
3888 $require_gnulib_path
3889 $require_gnulib_url
3891 if test -f .gitmodules && test -f "$gnulib_path/gnulib-tool"; then
3892 : All present and correct.
3894 elif test -n "$opt_gnulib_srcdir"; then
3895 # Older git can't clone into an empty directory.
3896 rmdir "$gnulib_path" 2>/dev/null
3897 func_show_eval "$GIT clone --reference '$opt_gnulib_srcdir' \
3898 '$gnulib_url' '$gnulib_path'" \
3899 || func_fatal_error "Unable to fetch gnulib submodule."
3901 # Without --gnulib-srcdir, and no existing checked out submodule, we
3902 # create a new shallow clone of the remote gnulib repository.
3903 else
3904 trap func_cleanup_gnulib 1 2 13 15
3906 shallow=
3907 $GIT clone -h 2>&1 |func_grep_q -- --depth \
3908 && shallow='--depth 365'
3910 func_show_eval "$GIT clone $shallow '$gnulib_url' '$gnulib_path'" \
3911 func_cleanup_gnulib
3913 # FIXME: Solaris /bin/sh will try to execute '-' if any of
3914 # these signals are caught after this.
3915 trap - 1 2 13 15
3918 # Make sure we've checked out the correct revision of gnulib.
3919 func_show_eval "$GIT submodule init -- $gnulib_path" \
3920 && func_show_eval "$GIT submodule update -- $gnulib_path" \
3921 || func_fatal_error "Unable to update gnulib submodule."
3924 require_gnulib_submodule=:
3928 # require_gnulib_tool
3929 # -------------------
3930 # Ensure that '$gnulib_tool' is set, and points to an executable file,
3931 # or else fall back to using the binary 'true' if the main gnulib
3932 # files appear to have been imported already.
3933 require_gnulib_tool=func_require_gnulib_tool
3934 func_require_gnulib_tool ()
3936 $debug_cmd
3938 test true = "$gnulib_tool" || {
3939 $require_gnulib_submodule
3940 $require_gnulib_path
3942 test -n "$gnulib_tool" \
3943 || gnulib_tool=$gnulib_path/gnulib-tool
3945 test -x "$gnulib_tool" || {
3946 gnulib_tool=true
3947 func_warning recommend \
3948 "No 'gnulib-tool' found; gnulib modules may be missing."
3951 test true = "$gnulib_tool" \
3952 || func_verbose "found '$gnulib_tool'"
3955 require_gnulib_tool=:
3959 # require_gnulib_tool_base_options
3960 # --------------------------------
3961 # Ensure that '$gnulib_tool_base_options' contains all the base options
3962 # required according to user configuration from bootstrap.conf.
3963 require_gnulib_tool_base_options=func_require_gnulib_tool_base_options
3964 func_require_gnulib_tool_base_options ()
3966 $debug_cmd
3968 $require_gnulib_tool
3970 gnulib_tool_base_options=
3972 test true = "$gnulib_tool" || {
3973 # 'gnulib_modules' and others are maintained in 'bootstrap.conf':
3974 # Use 'gnulib --import' to fetch gnulib modules.
3975 $require_build_aux
3976 test -n "$build_aux" \
3977 && func_append_uniq gnulib_tool_base_options " --aux-dir=$build_aux"
3978 $require_macro_dir
3979 test -n "$macro_dir" \
3980 && func_append_uniq gnulib_tool_base_options " --m4-base=$macro_dir"
3981 $require_doc_base
3982 test -n "$doc_base" \
3983 && func_append_uniq gnulib_tool_base_options " --doc-base=$doc_base"
3984 $require_gnulib_name
3985 test -n "$gnulib_name" \
3986 && func_append_uniq gnulib_tool_base_options " --lib=$gnulib_name"
3987 $require_local_gl_dir
3988 test -n "$local_gl_dir" \
3989 && func_append_uniq gnulib_tool_base_options " --local-dir=$local_gl_dir"
3990 $require_source_base
3991 test -n "$source_base" \
3992 && func_append_uniq gnulib_tool_base_options " --source-base=$source_base"
3995 require_gnulib_tool_base_options=:
3999 # require_libtoolize
4000 # ------------------
4001 # Skip libtoolize if it's not needed.
4002 require_libtoolize=func_require_libtoolize
4003 func_require_libtoolize ()
4005 $debug_cmd
4007 # Unless we're not searching for libtool use by this package, set
4008 # LIBTOOLIZE to true if none of 'LT_INIT', 'AC_PROG_LIBTOOL' and
4009 # 'AM_PROG_LIBTOOL' are used in configure.
4010 test true = "$LIBTOOLIZE" || {
4011 func_extract_trace LT_INIT
4012 test -n "$func_extract_trace_result" || func_extract_trace AC_PROG_LIBTOOL
4013 test -n "$func_extract_trace_result" || func_extract_trace AM_PROG_LIBTOOL
4014 test -n "$func_extract_trace_result" || LIBTOOLIZE=true
4017 test -n "$LIBTOOLIZE" || {
4018 # Find libtoolize, named glibtoolize in Mac Ports, but prefer
4019 # user-installed libtoolize to ancient glibtoolize shipped by
4020 # Apple with Mac OS X when Mac Ports is not installed.
4021 func_find_tool LIBTOOLIZE libtoolize glibtoolize
4024 test -n "$LIBTOOLIZE" || func_fatal_error "\
4025 Please install GNU Libtool, or 'export LIBTOOLIZE=/path/to/libtoolize'."
4027 func_verbose "export LIBTOOLIZE='$LIBTOOLIZE'"
4029 # Make sure the search result is visible to subshells
4030 export LIBTOOLIZE
4032 require_libtoolize=:
4036 # require_local_gl_dir
4037 # --------------------
4038 # Ensure local_gl_dir has a sensible value, extracted from 'gnulib-cache.m4'
4039 # if possible, otherwise letting 'gnulib-tool' pick a default.
4040 require_local_gl_dir=func_require_local_gl_dir
4041 func_require_local_gl_dir ()
4043 $debug_cmd
4045 $require_gnulib_cache
4047 test -f "$gnulib_cache" && test -z "$local_gl_dir" && {
4048 func_extract_trace_first "gl_LOCAL_DIR" "$gnulib_cache"
4049 local_gl_dir=$func_extract_trace_first_result
4051 test -n "$local_gl_dir" && func_verbose "local_gl_dir='$local_gl_dir'"
4054 require_local_gl_dir=:
4058 # require_macro_dir
4059 # -----------------
4060 # Ensure that '$macro_dir' is set, and if it doesn't already point to an
4061 # existing directory, create one.
4062 require_macro_dir=func_require_macro_dir
4063 func_require_macro_dir ()
4065 $debug_cmd
4067 # Sometimes this is stored in 'configure.ac'.
4068 test -n "$macro_dir" || {
4069 # AC_CONFIG_MACRO_DIRS takes a space delimited list of directories,
4070 # but we only care about the first one in bootstrap.
4071 func_extract_trace_first AC_CONFIG_MACRO_DIRS
4072 macro_dir=`expr "x$func_extract_trace_first_result" : 'x\([^ ]*\)'`
4074 test -n "$macro_dir" || {
4075 func_extract_trace_first AC_CONFIG_MACRO_DIR
4076 macro_dir=$func_extract_trace_first_result
4079 # Otherwise we might find it in 'Makefile.am'.
4080 test -n "$macro_dir" || {
4081 $require_aclocal_amflags
4083 # Take the argument following the first '-I', if any.
4084 _G_minus_I_seen=false
4085 for _G_arg in $aclocal_amflags; do
4086 case $_G_minus_I_seen,$_G_arg in
4087 :,*) macro_dir=$_G_arg; break ;;
4088 *,-I) _G_minus_I_seen=: ;;
4089 *,-I*) macro_dir=`expr x$_G_arg : 'x-I\(.*\)$'`; break ;;
4090 esac
4091 done
4094 func_verbose "macro_dir='$macro_dir'"
4096 func_check_configuration macro_dir \
4097 "AC_CONFIG_MACRO_DIRS([name of a directory for configure m4 files])"
4099 $require_vc_ignore_files
4101 # If the macro_dir directory doesn't exist, create it now, and mark it
4102 # as ignored for the VCS.
4103 if test ! -d "$macro_dir"; then
4104 mkdir "$macro_dir" || func_permissions_error "$macro_dir"
4106 test -n "$vc_ignore_files" \
4107 || func_insert_if_absent "$macro_dir" $vc_ignore_files
4110 require_macro_dir=:
4114 # require_makefile_am
4115 # -------------------
4116 # Ensure there is a 'Makefile.am' in the current directory.
4117 require_makefile_am=func_require_makefile_am
4118 func_require_makefile_am ()
4120 $debug_cmd
4122 test -n "$makefile_am" \
4123 || makefile_am=Makefile.am
4125 <"$makefile_am"
4127 func_verbose "found '$makefile_am'"
4129 require_makefile_am=:
4133 # require_package
4134 # ---------------
4135 # Ensure that '$package' contains a sensible default value.
4136 require_package=func_require_package
4137 func_require_package ()
4139 $debug_cmd
4141 test -n "$package" || {
4142 $require_package_name
4144 package=`echo "$package_name" \
4145 |$SED -e 's/GNU //' \
4146 -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
4149 func_verbose "package='$package'"
4151 require_package=:
4155 # require_package_bugreport
4156 # -------------------------
4157 # Ensure that this has a sensible value, extracted from 'configure.ac'
4158 # if appropriate (and possible!).
4159 require_package_bugreport=func_require_package_bugreport
4160 func_require_package_bugreport ()
4162 $debug_cmd
4164 func_extract_trace AC_INIT
4166 save_ifs=$IFS
4167 IFS=:
4168 set dummy $func_extract_trace_result
4169 IFS=$save_ifs
4170 shift
4172 test -n "$package_bugreport" || package_bugreport=$3
4173 func_check_configuration package_bugreport \
4174 "AC_INIT([$package_name], [$package_version], [bug-$package@gnu.org])"
4175 func_verbose "package_bugreport='$package_bugreport'"
4177 require_package_bugreport=:
4181 # require_package_name
4182 # --------------------
4183 # Ensure that this has a sensible value, extracted from 'configure.ac'
4184 # if appropriate (and possible!).
4185 require_package_name=func_require_package_name
4186 func_require_package_name ()
4188 $debug_cmd
4190 func_extract_trace AC_INIT
4192 save_ifs=$IFS
4193 IFS=:
4194 set dummy $func_extract_trace_result
4195 IFS=$save_ifs
4196 shift
4198 test -n "$package_name" || package_name=$1
4199 func_check_configuration package_name \
4200 "AC_INIT([name of your package], [package version number])"
4201 func_verbose "package_name='$package_name'"
4203 require_package_name=:
4207 # require_package_version
4208 # -----------------------
4209 # Ensure that this has a sensible value, extracted from 'configure.ac'
4210 # if appropriate (and possible!). While we might have set all the
4211 # parameters extracted from AC_INIT at once, 'package_version' in
4212 # particular is not necessarily available as early as the others, since
4213 # 'git-version-gen' is often involved, and until then we can't rely on
4214 # getting a correct version number from an AC_INIT extraction.
4215 require_package_version=func_require_package_version
4216 func_require_package_version ()
4218 $debug_cmd
4220 func_extract_trace AC_INIT
4222 save_ifs=$IFS
4223 IFS=:
4224 set dummy $func_extract_trace_result
4225 IFS=$save_ifs
4226 shift
4228 test -n "$package_version" || package_version=$2
4229 test -n "$package_version" || {
4230 # The embedded echo is to squash whitespace before globbing.
4231 case " "`echo $gnulib_modules`" " in
4232 *" git-version-gen "*)
4233 func_fatal_error "\
4234 cannot \$require_package_version in bootstrap.conf before
4235 func_gnulib_tool has installed the 'git-version-gen' script."
4238 func_check_configuration package_version \
4239 "AC_INIT([name of your package], [package version number])"
4241 esac
4243 func_verbose "package_version='$package_version'"
4245 require_package_version=:
4249 # require_patch
4250 # -------------
4251 # Find patch, according to the PATCH environment variable, or else
4252 # searching the user's PATH.
4253 require_patch=func_require_patch
4254 func_require_patch ()
4256 $debug_cmd
4258 test -n "$PATCH" || {
4259 # Find a patch program, preferring gpatch, which is usually better
4260 # than the vendor patch.
4261 func_find_tool PATCH gpatch patch
4264 test -n "$PATCH" || func_fatal_error "\
4265 Please install GNU Patch, or 'export PATCH=/path/to/gnu/patch'."
4267 func_verbose "export PATCH='$PATCH'"
4269 # Make sure the search result is visible to subshells
4270 export PATCH
4272 require_patch=:
4276 # require_source_base
4277 # -------------------
4278 # Ensure that source_base has a sensible value, extracted from
4279 # 'gnulib-cache.m4' if possible.
4280 require_source_base=func_require_source_base
4281 func_require_source_base ()
4283 $debug_cmd
4285 $require_gnulib_cache
4287 test -f "$gnulib_cache" && test -z "$source_base" && {
4288 func_extract_trace_first "gl_SOURCE_BASE" "$gnulib_cache"
4290 source_base=$func_extract_trace_first_result
4292 func_verbose "source_base='$source_base'"
4295 require_source_base=:
4299 # require_vc_ignore_files
4300 # -----------------------
4301 # Ensure that '$vc_ignore' has been processed to list VCS ignore files
4302 # in '$vc_ignore_files'
4303 require_vc_ignore_files=func_require_vc_ignore_files
4304 func_require_vc_ignore_files ()
4306 $debug_cmd
4308 test -n "$vc_ignore" || vc_ignore=auto
4310 if test auto = "$vc_ignore" && test -z "$vc_ignore_files"; then
4311 vc_ignore_files=
4312 test -d .git && vc_ignore_files=.gitignore
4313 test -d CVS && vc_ignore_files="$vc_ignore_files .cvsignore"
4314 else
4315 vc_ignore_files=$vc_ignore
4318 func_verbose "vc_ignore_files='$vc_ignore_files'"
4320 require_vc_ignore_files=:
4324 ## ----------------- ##
4325 ## Helper functions. ##
4326 ## ----------------- ##
4328 # This section contains the helper functions used by the rest of 'bootstrap'.
4330 # func_len STRING
4331 # ---------------
4332 # STRING may not start with a hyphen.
4333 if (eval 'x=123; test x${#x} = "x3"') 2>/dev/null
4334 then
4335 # This is an XSI compatible shell, allowing a faster implementation...
4336 eval 'func_len ()
4338 $debug_cmd
4340 func_len_result=${#1}
4342 else
4343 # ...otherwise fall back to using expr, which is often a shell builtin.
4344 func_len ()
4346 $debug_cmd
4348 func_len_result=`expr "$1" : ".*" 2>/dev/null || echo 0`
4353 # func_unset VAR
4354 # --------------
4355 # Portably unset VAR.
4356 # In some shells, an 'unset VAR' statement leaves a non-zero return
4357 # status if VAR is already unset, which might be problematic if the
4358 # statement is used at the end of a function (thus poisoning its return
4359 # value) or when 'set -e' is active (causing even a spurious abort of
4360 # the script in this case).
4361 func_unset ()
4363 { eval $1=; unset $1; }
4365 unset=func_unset
4368 # func_cmp_s FILE1 FILE2
4369 # ----------------------
4370 # Return non-zero exit status unless FILE1 and FILE2 are identical, without
4371 # any output at all, even error messages.
4372 func_cmp_s ()
4374 $debug_cmd
4376 # This function relies on non-zero exit status, which will cause the
4377 # program to exit when running in 'set -e' mode.
4378 $CMP "$@" >/dev/null 2>&1
4382 # func_grep_q EXPRESSION [FILENAME..]
4383 # -----------------------------------
4384 # Check whether EXPRESSION matches any line of any listed FILENAME,
4385 # without any output at all, even error messages.
4386 func_grep_q ()
4388 $debug_cmd
4390 # This function relies on non-zero exit status, which will cause the
4391 # program to exit when running in 'set -e' mode.
4392 $GREP "$@" >/dev/null 2>&1
4396 # func_ifcontains LIST MEMBER YES-CMD [NO-CMD]
4397 # --------------------------------------------
4398 # If whitespace-separated LIST contains MEMBER then execute YES-CMD,
4399 # otherwise if NO-CMD was given, execute that.
4400 func_ifcontains ()
4402 $debug_cmd
4404 _G_wslist=$1
4405 _G_member=$2
4406 _G_yes_cmd=$3
4407 _G_no_cmd=${4-":"}
4409 _G_found=false
4410 for _G_item in $_G_wslist; do
4411 test "x$_G_item" = "x$_G_member" && {
4412 _G_found=:
4413 break
4415 done
4416 if $_G_found; then
4417 eval "$_G_yes_cmd"
4418 _G_status=$?
4419 else
4420 eval "$_G_no_cmd"
4421 _G_status=$?
4424 test 0 -eq "$_G_status" || exit $_G_status
4428 # func_strpad STR WIDTH CHAR
4429 # --------------------------
4430 # Trim STR, or pad with CHAR to force a total length of WIDTH.
4431 func_strpad ()
4433 $debug_cmd
4435 _G_width=`expr "$2" - 1`
4436 func_strpad_result=`$ECHO "$1" |$SED '
4438 s|^.\{0,'"$_G_width"'\}$|&'"$3"'|
4444 # func_strrpad STR WIDTH CHAR
4445 # ---------------------------
4446 # Trim STR, or right-justify-pad with CHAR to force a total length of
4447 # WIDTH.
4448 func_strrpad ()
4450 $debug_cmd
4452 _G_width=`expr "$2" - 1`
4453 func_strrpad_result=`$ECHO "$1" |$SED '
4455 s|^.\{0,'"$_G_width"'\}$|'"$3"'&|
4461 # func_strrow INDENT FIELD WIDTH [FIELDn WIDTHn]...
4462 # -------------------------------------------------
4463 # Return a string containing each FIELD left justified to WIDTH, with
4464 # the whole thing indented by INDENT spaces. This function is used to
4465 # render one row of aligned columns for a table by func_strtable().
4466 func_strrow ()
4468 $debug_cmd
4470 func_strrow_linelen=$1; shift
4472 _G_row=
4473 while test $# -gt 0; do
4474 func_strrow_linelen=`expr $func_strrow_linelen + $2`
4475 func_strpad "$1" $2 " "
4476 func_append _G_row "$func_strpad_result"
4477 shift; shift
4478 done
4480 func_strrpad "$_G_row" $func_strrow_linelen " "
4481 func_strrow_result=$func_strrpad_result
4485 # func_strtable INDENT WIDTH1...WIDTHn HEADER1...HEADERn FIELD1...FIELDn
4486 # ----------------------------------------------------------------------
4487 # Generate a string of newline-separated rows arranged in lined-up
4488 # columns of the given WIDTHs, with the entire table indented by INDENT
4489 # spaces. The number of columns is determined by the number of integer
4490 # valued WIDTH arguments following INDENT. The next set (i.e. a number
4491 # of arguments equal to the number of WIDTH arguments) of fields are
4492 # treated as the table's column HEADERs, and are separated from the
4493 # remainder of the table by an indented row of '-' characters. Remaining
4494 # arguments are each aligned below the next available header, wrapping
4495 # to a new row as necessary. Finally another row of '-' characters is
4496 # added to mark the end of the table.
4498 # For example an unindented 3 column table with 2 rows of data would be
4499 # generated by this call:
4501 # func_strtable 3 20 10 25 \
4502 # Header1 Header2 Header3 \
4503 # Row1Col1 Row1Col2 Row1Col3 \
4504 # Row2Col1 Row2Col2 Row2Col3
4506 # returning the following string:
4508 # " Header1 Header2 Header3
4509 # -------------------------------------------------------
4510 # Row1Col1 Row1Col2 Row1Col3
4511 # Row2Col1 Row2Col2 Row2Col3
4512 # -------------------------------------------------------"
4513 func_strtable ()
4515 $debug_cmd
4517 # Save the indent value, we'll need it for each row we render.
4518 _G_indent=$1; shift
4520 # Collect remaining numeric args into a list for reuse between
4521 # members of each row when we call func_strrow later.
4522 _G_widths=$1; shift
4523 while test 0 -lt `expr "$1" : '[1-9][0-9]*$'`; do
4524 func_append _G_widths " $1"; shift
4525 done
4527 # Extract the same number of positional parameters as there are
4528 # width elements - we'll do the header rows separately so that
4529 # we can insert a divider line.
4530 _G_header=$_G_indent
4531 for _G_width in $_G_widths; do
4532 func_append _G_header " $1 $_G_width"; shift
4533 done
4534 func_strrow $_G_header
4536 # Strip off the indent, and make a divider with '-' chars, then
4537 # reindent.
4538 _G_divider=`$ECHO "$func_strrow_result" \
4539 |$SED 's|[^ ]|-|g
4541 s|- |--|g
4545 # Append the header and divider to the running result.
4546 func_append func_strtable_result "\
4547 $func_strrow_result
4548 $_G_divider
4551 # The remaining rows are zipped between the width values we
4552 # unwound earlier just like the header row above.
4553 while test $# -gt 0; do
4554 _G_row=$_G_indent
4555 for _G_width in $_G_widths; do
4556 func_append _G_row " $1 $_G_width"; shift
4557 done
4558 func_strrow $_G_row
4559 func_append func_strtable_result "\
4560 $func_strrow_result
4562 done
4564 # Mark the end of the table with a final divider line.
4565 func_append func_strtable_result "$_G_divider"
4569 # func_internal_error ARG...
4570 # --------------------------
4571 # Echo program name prefixed message to standard error, and exit.
4572 func_internal_error ()
4574 func_fatal_error "\
4575 INTERNAL: " ${1+"$@"} "
4576 Please report this bug to 'bug-gnulib@gnu.org'
4577 in as much detail as possible."
4581 # func_permissions_error FILE-OR-DIRECTORY
4582 # ----------------------------------------
4583 # Echo program name prefixed permissions error message to standard
4584 # error, and exit.
4585 func_permissions_error ()
4587 $debug_cmd
4589 func_fatal_error "Failed to create '$1', check permissions."
4593 # func_show_eval CMD [FAIL_EXP]
4594 # -----------------------------
4595 # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is
4596 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
4597 # is given, then evaluate it.
4598 func_show_eval ()
4600 $debug_cmd
4602 $require_term_colors
4604 _G_cmd=$1
4605 _G_fail_exp=${2-':'}
4607 ${opt_silent-'false'} || {
4608 func_quote_for_eval $_G_cmd
4609 eval func_truncate_cmd $func_quote_for_eval_result
4610 func_echo "running: $tc_bold$func_truncate_cmd_result$tc_reset"
4613 ${opt_dry_run-'false'} || {
4614 eval "$_G_cmd"
4615 _G_status=$?
4616 test 0 -eq "$_G_status" || eval "(exit $_G_status); $_G_fail_exp"
4621 # func_truncate_cmd CMD [ARG]...
4622 # ------------------------------
4623 # For unreasonably long commands (such as a gnulib-tool invocation with
4624 # the full module list for import), truncate CMD after the second non-
4625 # option ARG.
4626 func_truncate_cmd ()
4628 $debug_cmd
4630 _G_last_arg_opt_p=false
4631 func_truncate_cmd_result=
4633 set dummy "$@"; shift
4635 while test $# -gt 0; do
4636 _G_opt=$1; shift
4638 test -n "$func_truncate_cmd_result" \
4639 && func_append func_truncate_cmd_result ' '
4640 func_append func_truncate_cmd_result "$_G_opt"
4642 func_len "x$func_truncate_cmd_result"
4644 case $_G_opt in
4645 -*) _G_last_arg_opt_p=: ;;
4646 *) $_G_last_arg_opt_p \
4647 || test "$min_cmd_len" -gt "$func_len_result" \
4648 || break
4649 _G_last_arg_opt_p=false
4651 esac
4652 done
4654 test $# -gt 0 && func_append func_truncate_cmd_result "..."
4658 # func_gitignore_entries FILE...
4659 # ------------------------------
4660 # Strip blank and comment lines to leave significant entries.
4661 func_gitignore_entries ()
4663 $debug_cmd
4665 $SED -e '/^#/d' -e '/^$/d' "$@"
4669 # func_insert_if_absent STR FILE...
4670 # ---------------------------------
4671 # If $STR is not already on a line by itself in $FILE, insert it, at the
4672 # start. Entries are inserted at the start of the ignore list to ensure
4673 # existing entries starting with ! are not overridden. Such entries
4674 # support whilelisting exceptions after a more generic blacklist pattern.
4675 # sorting the new contents of the file and replacing $FILE with the result.
4676 func_insert_if_absent ()
4678 $debug_cmd
4680 str=$1
4681 shift
4683 for file
4685 test -f "$file" || touch "$file"
4687 duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
4688 test -n "$duplicate_entries" \
4689 && func_error "duplicate entries in $file: " $duplicate_entries
4691 func_grep_q "^$str\$" "$file" \
4692 || func_verbose "inserting '$str' into '$file'"
4694 linesold=`func_gitignore_entries "$file" |wc -l`
4695 linesnew=`{ $ECHO "$str"; cat "$file"; } \
4696 |func_gitignore_entries |sort -u |wc -l`
4697 test "$linesold" -eq "$linesnew" \
4698 || { $SED "1i\\$nl$str$nl" "$file" >"$file"T && mv "$file"T "$file"; } \
4699 || func_permissions_error "$file"
4700 done
4704 # func_get_version APP
4705 # --------------------
4706 # echo the version number (if any) of APP, which is looked up along your
4707 # PATH.
4708 func_get_version ()
4710 $debug_cmd
4712 _G_app=$1
4714 # Rather than uncomment the sed script in-situ, strip the comments
4715 # programatically before passing the result to $SED for evaluation.
4716 sed_get_version=`$ECHO '# extract version within line
4717 s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4718 t done
4720 # extract version at start of line
4721 s|^\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4722 t done
4726 :done
4727 # the following essentially does s|5.005|5.5|
4728 s|\.0*\([1-9]\)|.\1|g
4730 q' \
4731 |$SED '/^[ ]*#.*$/d'`
4733 func_tool_version_output $_G_app >/dev/null
4734 _G_status=$?
4736 test 0 -ne "$_G_status" \
4737 || $_G_app --version 2>&1 |$SED -n "$sed_get_version"
4739 (exit $_G_status)
4743 # func_check_tool APP
4744 # -------------------
4745 # Search PATH for an executable at APP.
4746 func_check_tool ()
4748 $debug_cmd
4750 func_check_tool_result=
4752 case $1 in
4753 *[\\/]*)
4754 test -x "$1" && func_check_tool_result=$1
4757 save_IFS=$IFS
4758 IFS=${PATH_SEPARATOR-:}
4759 for _G_check_tool_path in $PATH; do
4760 IFS=$save_IFS
4761 if test -x "$_G_check_tool_path/$1"; then
4762 func_check_tool_result=$_G_check_tool_path/$1
4763 break
4765 done
4766 IFS=$save_IFS
4768 esac
4772 # func_check_versions APP1 VER1 URL1 ...[APPN VERN URLN]
4773 # ------------------------------------------------------
4774 func_check_versions ()
4776 $debug_cmd
4778 func_check_versions_result=:
4780 while test $# -gt 0; do
4781 _G_app=$1; shift
4782 _G_reqver=$1; shift
4783 _G_url=$1; shift
4785 # Diagnose bad buildreq formatting.
4786 case $_G_url in
4787 [a-z]*://*) ;; # looks like a url
4788 *) func_fatal_error "\
4789 '$_G_url' from the buildreq table in
4790 'bootstrap.conf' does not look like the URL for downloading
4791 $_G_app. Please ensure that buildreq is a strict newline
4792 delimited list of triples; 'program min-version url'."
4794 esac
4796 # Honor $APP variables ($TAR, $AUTOCONF, etc.)
4797 _G_appvar=`echo $_G_app |tr '[a-z]' '[A-Z]'`
4798 test TAR = "$_G_appvar" && _G_appvar=AMTAR
4799 eval "_G_app=\${$_G_appvar-$_G_app}"
4801 # Fail if no version specified, but the program can't be found.
4802 if test x- = "x$_G_reqver"; then
4803 func_check_tool $_G_app
4804 if test -z "$func_check_tool_result"; then
4805 func_error "Prerequisite '$_G_app' not not found. Please install it, or
4806 'export $_G_appvar=/path/to/$_G_app'."
4807 func_check_versions_result=false
4808 else
4809 func_verbose "found '$func_check_tool_result' for $_G_appvar."
4811 else
4812 _G_instver=`func_get_version $_G_app`
4814 # Fail if --version didn't work.
4815 if test -z "$_G_instver"; then
4816 func_error "Prerequisite '$_G_app' not found. Please install it, or
4817 'export $_G_appvar=/path/to/$_G_app'."
4818 func_check_versions_result=false
4820 # Fail if a newer version than what we have is required.
4821 else
4822 func_verbose "found '$_G_app' version $_G_instver."
4824 case $_G_reqver in
4826 # If $buildreq version starts with '=', version must
4827 # match the installed program exactly.
4828 test "x$_G_reqver" = "x=$_G_instver" || {
4829 func_error "\
4830 '$_G_app' version == $_G_instver is too old
4831 'exactly $_G_app-$_G_reqver is required"
4832 func_check_versions_result=false
4836 # Otherwise, anything that is not older is a match.
4837 func_lt_ver "$_G_reqver" "$_G_instver" || {
4838 func_error "\
4839 '$_G_app' version == $_G_instver is too old
4840 '$_G_app' version >= $_G_reqver is required"
4841 func_check_versions_result=false
4844 esac
4847 done
4851 # func_cleanup_gnulib
4852 # -------------------
4853 # Recursively delete everything below the path in the global variable
4854 # GNULIB_PATH.
4855 func_cleanup_gnulib ()
4857 $debug_cmd
4859 _G_status=$?
4860 $RM -fr "$gnulib_path"
4861 exit $_G_status
4865 # func_download_po_files SUBDIR DOMAIN
4866 # ------------------------------------
4867 func_download_po_files ()
4869 $debug_cmd
4871 func_echo "getting translations into $1 for $2..."
4872 _G_cmd=`printf "$po_download_command_format" "$2" "$1"`
4873 eval "$_G_cmd"
4877 # func_update_po_files PO_DIR DOMAIN
4878 # ----------------------------------
4879 # Mirror .po files to $po_dir/.reference and copy only the new
4880 # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
4881 # Note po files that exist locally only are left in $po_dir but will
4882 # not be included in LINGUAS and hence will not be distributed.
4883 func_update_po_files ()
4885 $debug_cmd
4887 # Directory containing primary .po files.
4888 # Overwrite them only when we're sure a .po file is new.
4889 _G_po_dir=$1
4890 _G_domain=$2
4892 # Mirror *.po files into this dir.
4893 # Usually contains *.s1 checksum files.
4894 _G_ref_po_dir=$_G_po_dir/.reference
4896 test -d "$_G_ref_po_dir" || mkdir $_G_ref_po_dir || return
4897 func_download_po_files $_G_ref_po_dir $_G_domain \
4898 && ls "$_G_ref_po_dir"/*.po 2>/dev/null \
4899 |$SED -e 's|.*/||' -e 's|\.po$||' > "$_G_po_dir/LINGUAS" || return
4901 # Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6+.
4902 func_find_tool SHA1SUM sha1sum gsha1sum shasum sha1
4904 test -n "$SHA1SUM" || func_fatal_error "\
4905 Please install GNU Coreutils, or 'export SHA1SUM=/path/to/sha1sum'."
4907 _G_langs=`cd $_G_ref_po_dir && echo *.po|$SED 's|\.po||g'`
4908 test '*' = "$_G_langs" && _G_langs=x
4909 for _G_po in $_G_langs; do
4910 case $_G_po in x) continue;; esac
4911 _G_new_po=$_G_ref_po_dir/$_G_po.po
4912 _G_cksum_file=$_G_ref_po_dir/$_G_po.s1
4913 if ! test -f "$_G_cksum_file" ||
4914 ! test -f "$_G_po_dir/$_G_po.po" ||
4915 ! $SHA1SUM -c "$_G_cksum_file" \
4916 < "$_G_new_po" > /dev/null; then
4917 echo "updated $_G_po_dir/$_G_po.po..."
4918 cp "$_G_new_po" "$_G_po_dir/$_G_po.po" \
4919 && $SHA1SUM < "$_G_new_po" > "$_G_cksum_file" || return
4921 done
4926 ## --------------- ##
4927 ## Option parsing. ##
4928 ## --------------- ##
4930 # Hook in the functions to make sure our own options are parsed during
4931 # the option parsing loop.
4933 usage='$progpath [OPTION]...'
4935 # Short help message in response to '-h'. Add to this in 'bootstrap.conf'
4936 # if you accept any additional options.
4937 usage_message="Common Bootstrap Options:
4938 -c, --copy copy files instead of creating symbolic links.
4939 --debug enable verbose shell tracing
4940 -n, --dry-run print commands rather than running them
4941 -f, --force attempt to bootstrap even if the sources seem not
4942 to have been checked out.
4943 --gnulib-srcdir=DIRNAME
4944 specify a local directory where gnulib sources
4945 reside. Use this if you already have the gnulib
4946 sources on your machine, and don't want to waste
4947 your bandwidth downloading them again. Defaults to
4948 \$GNULIB_SRCDIR.
4949 --no-warnings equivalent to '-Wnone'
4950 --skip-git do not fetch files from remote repositories
4951 --skip-po do not download po files.
4952 -v, --verbose verbosely report processing
4953 --version print version information and exit
4954 -W, --warnings=CATEGORY
4955 report the warnings falling in CATEGORY [all]
4956 -h, --help print short or long help message and exit
4959 # Additional text appended to 'usage_message' in response to '--help'.
4960 long_help_message=$long_help_message"
4961 'recommend' show warnings about missing recommended packages
4962 'settings' show warnings about missing '$progname.conf' settings
4963 'upgrade' show warnings about out-dated files
4965 If the file '$progname.conf' exists in the same directory as this
4966 script, its contents are read as shell variables to configure the
4967 bootstrap.
4969 For build prerequisites, environment variables like \$AUTOCONF and
4970 \$AMTAR are honored.
4972 Running without arguments will suffice in most cases.
4975 # Warning categories used by 'bootstrap', append others if you use them
4976 # in your 'bootstrap.conf'.
4977 warning_categories='recommend settings upgrade'
4980 # bootstrap_options_prep [ARG]...
4981 # -------------------------------
4982 # Preparation for options parsed by Bootstrap.
4983 bootstrap_options_prep ()
4985 $debug_cmd
4987 # Option defaults:
4988 opt_copy=${copy-'false'}
4989 opt_dry_run=false
4990 opt_force=false
4991 opt_gnulib_srcdir=$GNULIB_SRCDIR
4992 opt_skip_git=false
4993 opt_skip_po=false
4995 # Pass back the list of options we consumed.
4996 func_quote_for_eval ${1+"$@"}
4997 bootstrap_options_prep_result=$func_quote_for_eval_result
4999 func_add_hook func_options_prep bootstrap_options_prep
5002 # bootstrap_parse_options [ARG]...
5003 # --------------------------------
5004 # Provide handling for Bootstrap specific options.
5005 bootstrap_parse_options ()
5007 $debug_cmd
5009 # Perform our own loop to consume as many options as possible in
5010 # each iteration.
5011 while test $# -gt 0; do
5012 _G_opt=$1
5013 shift
5014 case $_G_opt in
5015 --dry-run|--dryrun|-n)
5016 opt_dry_run=: ;;
5017 --copy|-c) opt_copy=: ;;
5018 --force|-f) opt_force=: ;;
5020 --gnulib-srcdir)
5021 test $# = 0 && func_missing_arg $_G_opt && break
5022 opt_gnulib_srcdir=$1
5023 shift
5026 --skip-git|--no-git)
5027 opt_skip_git=:
5030 --skip-po|--no-po)
5031 opt_skip_po=:
5034 # Separate non-argument short options:
5035 -c*|-f*|-n*)
5036 func_split_short_opt "$_G_opt"
5037 set dummy "$func_split_short_opt_name" \
5038 "-$func_split_short_opt_arg" ${1+"$@"}
5039 shift
5042 *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
5043 esac
5044 done
5046 # save modified positional parameters for caller
5047 func_quote_for_eval ${1+"$@"}
5048 bootstrap_parse_options_result=$func_quote_for_eval_result
5050 func_add_hook func_parse_options bootstrap_parse_options
5053 # bootstrap_validate_options [ARG]...
5054 # -----------------------------------
5055 # Perform any sanity checks on option settings and/or unconsumed
5056 # arguments.
5057 bootstrap_validate_options ()
5059 $debug_cmd
5061 # Validate options.
5062 test $# -gt 0 \
5063 && func_fatal_help "too many arguments"
5065 # Pass back the (empty) list of unconsumed options.
5066 func_quote_for_eval ${1+"$@"}
5067 bootstrap_validate_options_result=$func_quote_for_eval_result
5069 func_add_hook func_validate_options bootstrap_validate_options
5072 ## -------------------------------------------------- ##
5073 ## Source package customisations in 'bootstrap.conf'. ##
5074 ## -------------------------------------------------- ##
5076 # Override the default configuration, if necessary.
5077 # Make sure that bootstrap.conf is sourced from the current directory
5078 # if we were invoked as "sh bootstrap".
5079 case $0 in
5080 */*) test -r "$0.conf" && . "$0.conf" ;;
5081 *) test -r "$0.conf" && . ./"$0.conf" ;;
5082 esac
5085 ## ------------------------------- ##
5086 ## Actually perform the bootstrap. ##
5087 ## ------------------------------- ##
5089 func_bootstrap ${1+"$@"}
5091 # The End.
5092 exit ${exit_status-$EXIT_SUCCESS}
5094 # Local variables:
5095 # mode: shell-script
5096 # sh-indentation: 2
5097 # eval: (add-hook 'before-save-hook 'time-stamp)
5098 # time-stamp-pattern: "500/scriptversion=%:y-%02m-%02d.%02H; # UTC"
5099 # time-stamp-time-zone: "UTC"
5100 # End: