3 # Bootstrap an Autotooled package from checked-out sources.
4 # Written by Gary V. Vaughan, 2010
6 # Copyright (C) 2010-2013 Free Software Foundation, Inc.
7 # This is free software; see the source for copying conditions. There is NO
8 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # Source required external libraries:
11 # Set a version string for this script.
12 scriptversion=2013-08-23.20; # UTC
14 # General shell script boiler plate, and helper functions.
15 # Written by Gary V. Vaughan, 2004
17 # Copyright (C) 2004-2013 Free Software Foundation, Inc.
18 # This is free software; see the source for copying conditions. There is NO
19 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 # This program is free software; you can redistribute it and/or modify
22 # it under the terms of the GNU General Public License as published by
23 # the Free Software Foundation; either version 3 of the License, or
24 # (at your option) any later version.
26 # As a special exception to the GNU General Public License, if you distribute
27 # this file as part of a program or library that is built using GNU Libtool,
28 # you may include this file under the same distribution terms that you use
29 # for the rest of that program.
31 # This program is distributed in the hope that it will be useful,
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
33 # MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
34 # General Public License for more details.
36 # You should have received a copy of the GNU General Public License
37 # along with this program. If not, see <http://www.gnu.org/licenses/>.
39 # Please report bugs or propose patches to gary@gnu.org.
46 # Evaluate this file near the top of your script to gain access to
47 # the functions and variables defined here:
49 # . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
51 # If you need to override any of the default environment variable
52 # settings, do that before evaluating this file.
55 ## -------------------- ##
56 ## Shell normalisation. ##
57 ## -------------------- ##
59 # Some shells need a little help to be as Bourne compatible as possible.
60 # Before doing anything else, make sure all that help has been provided!
62 DUALCASE=1; export DUALCASE # for MKS sh
63 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
66 # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
67 # is contrary to our usage. Disable this feature.
68 alias -g '${1+"$@"}'='"$@"'
71 case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
74 # NLS nuisances: We save the old values in case they are required later.
77 for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
79 eval "if test set = \"\${$_G_var+set}\"; then
80 save_$_G_var=\$$_G_var
83 _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
84 _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
89 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
91 # Make sure IFS has a sensible default
97 # There are still modern systems that have problems with 'echo' mis-
98 # handling backslashes, among others, so make sure $bs_echo is set to a
99 # command that correctly interprets backslashes.
100 # (this code from Autoconf 2.68)
102 # Printing a long string crashes Solaris 7 /usr/bin/printf.
103 bs_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
104 bs_echo=$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo
105 bs_echo=$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo
106 # Prefer a ksh shell builtin over an external printf program on Solaris,
107 # but without wasting forks for bash or zsh.
108 if test -z "$BASH_VERSION$ZSH_VERSION" \
109 && (test "X`print -r -- $bs_echo`" = "X$bs_echo") 2>/dev/null; then
110 bs_echo='print -r --'
111 bs_echo_n='print -rn --'
112 elif (test "X`printf %s $bs_echo`" = "X$bs_echo") 2>/dev/null; then
113 bs_echo='printf %s\n'
114 bs_echo_n='printf %s'
116 if test "X`(/usr/ucb/echo -n -n $bs_echo) 2>/dev/null`" = "X-n $bs_echo"; then
117 bs_echo_body='eval /usr/ucb/echo -n "$1$nl"'
118 bs_echo_n='/usr/ucb/echo -n'
120 bs_echo_body='eval expr "X$1" : "X\\(.*\\)"'
125 expr "X$arg" : "X\\(.*\\)$nl";
126 arg=`expr "X$arg" : ".*$nl\\(.*\\)"`;;
128 expr "X$arg" : "X\\(.*\\)" | tr -d "$nl"
130 export bs_echo_n_body
131 bs_echo_n='sh -c $bs_echo_n_body bs_echo'
134 bs_echo='sh -c $bs_echo_body bs_echo'
138 ## ------------------------------- ##
139 ## User overridable command paths. ##
140 ## ------------------------------- ##
142 # All uppercase variable names are used for environment variables. These
143 # variables can be overridden by the user before calling a script that
144 # uses them if a suitable command of that name is not already available
145 # in the command search PATH.
158 : ${SHELL="${CONFIG_SHELL-/bin/sh}"}
161 ## -------------------- ##
162 ## Useful sed snippets. ##
163 ## -------------------- ##
165 sed_dirname='s|/[^/]*$||'
166 sed_basename='s|^.*/||'
168 # Sed substitution that helps us do robust quoting. It backslashifies
169 # metacharacters that are still active within double-quoted strings.
170 sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
172 # Same as above, but do not quote variable references.
173 sed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
175 # Sed substitution that turns a string into a regex matching for the
177 sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
179 # Sed substitution that converts a w32 file name or path
180 # that contains forward slashes, into one that contains
181 # (escaped) backslashes. A very naive implementation.
182 sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
184 # Re-'\' parameter expansions in output of sed_double_quote_subst that
185 # were '\'-ed in input to the same. If an odd number of '\' preceded a
186 # '$' in input to sed_double_quote_subst, that '$' was protected from
187 # expansion. Since each input '\' is now two '\'s, look for any number
188 # of runs of four '\'s followed by two '\'s and then a '$'. '\' that '$'.
193 sed_double_backslash="\
196 s/^$_G_bs2$_G_dollar/$_G_bs&/
197 s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
201 ## ----------------- ##
202 ## Global variables. ##
203 ## ----------------- ##
205 # Except for the global variables explicitly listed below, the following
206 # functions in the '^func_' namespace, and the '^require_' namespace
207 # variables initialised in the 'Resource management' section, sourcing
208 # this file will not pollute your global namespace with anything
209 # else. There's no portable way to scope variables in Bourne shell
210 # though, so actually running these functions will sometimes place
211 # results into a variable named after the function, and often use
212 # temporary variables in the '^_G_' namespace. If you are careful to
213 # avoid using those namespaces casually in your sourcing script, things
214 # should continue to work as you expect. And, of course, you can freely
215 # overwrite any of the functions or variables defined here before
216 # calling anything to customize them.
220 EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing.
221 EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake.
223 # Allow overriding, eg assuming that you follow the convention of
224 # putting '$debug_cmd' at the start of all your functions, you can get
225 # bash to show function call trace with:
227 # debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
228 debug_cmd=${debug_cmd-":"}
231 # By convention, finish your script with:
235 # so that you can set exit_status to non-zero if you want to indicate
236 # something went wrong during execution without actually bailing out at
237 # the point of failure.
238 exit_status=$EXIT_SUCCESS
240 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
241 # is ksh but when the shell is invoked as "sh" and the current value of
242 # the _XPG environment variable is not equal to 1 (one), the special
243 # positional parameter $0, within a function call, is the name of the
247 # The name of this program.
248 progname=`$bs_echo "$progpath" |$SED "$sed_basename"`
250 # Make sure we have an absolute progpath for reexecution:
252 [\\/]*|[A-Za-z]:\\*) ;;
254 progdir=`$bs_echo "$progpath" |$SED "$sed_dirname"`
255 progdir=`cd "$progdir" && pwd`
256 progpath=$progdir/$progname
260 IFS=${PATH_SEPARATOR-:}
261 for progdir in $PATH; do
263 test -x "$progdir/$progname" && break
266 test -n "$progdir" || progdir=`pwd`
267 progpath=$progdir/$progname
272 ## ----------------- ##
273 ## Standard options. ##
274 ## ----------------- ##
276 # The following options affect the operation of the functions defined
277 # below, and should be set appropriately depending on run-time para-
278 # meters passed on the command line.
284 # Categories 'all' and 'none' are always available. Append any others
285 # you will pass as the first argument to func_warning from your own
289 # By default, display warnings according to 'opt_warning_types'. Set
290 # 'warning_func' to ':' to elide all warnings, or func_fatal_error to
291 # treat the next displayed warning as a fatal error.
292 warning_func=func_warn_and_continue
294 # Set to 'all' to display all warnings, 'none' to suppress all
295 # warnings, or a space delimited list of some subset of
296 # 'warning_categories' to display only the listed warnings.
297 opt_warning_types=all
300 ## -------------------- ##
301 ## Resource management. ##
302 ## -------------------- ##
304 # This section contains definitions for functions that each ensure a
305 # particular resource (a file, or a non-empty configuration variable for
306 # example) is available, and if appropriate to extract default values
307 # from pertinent package files. Call them using their associated
308 # 'require_*' variable to ensure that they are executed, at most, once.
310 # It's entirely deliberate that calling these functions can set
311 # variables that don't obey the namespace limitations obeyed by the rest
312 # of this file, in order that that they be as useful as possible to
316 # require_term_colors
317 # -------------------
318 # Allow display of bold text on terminals that support it.
319 require_term_colors=func_require_term_colors
320 func_require_term_colors ()
325 # COLORTERM and USE_ANSI_COLORS environment variables take
326 # precedence, because most terminfo databases neglect to describe
327 # whether color sequences are supported.
328 test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
330 if test 1 = "$USE_ANSI_COLORS"; then
331 # Standard ANSI escape sequences
333 tc_bold='
\e[1m'; tc_standout='
\e[7m'
334 tc_red='
\e[31m'; tc_green='
\e[32m'
335 tc_blue='
\e[34m'; tc_cyan='
\e[36m'
337 # Otherwise trust the terminfo database after all.
338 test -n "`tput sgr0 2>/dev/null`" && {
340 test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
342 test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
343 test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
344 test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
345 test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
346 test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
351 require_term_colors=:
355 ## ----------------- ##
356 ## Function library. ##
357 ## ----------------- ##
359 # This section contains a variety of useful functions to call in your
360 # scripts. Take note of the portable wrappers for features provided by
361 # some modern shells, which will fall back to slower equivalents on
362 # less featureful shells.
365 # func_append VAR VALUE
366 # ---------------------
367 # Append VALUE onto the existing contents of VAR.
369 # We should try to minimise forks, especially on Windows where they are
370 # unreasonably slow, so skip the feature probes when bash or zsh are
372 if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
373 : ${_G_HAVE_ARITH_OP="yes"}
374 : ${_G_HAVE_XSI_OPS="yes"}
375 # The += operator was introduced in bash 3.1
376 case $BASH_VERSION in
377 [12].* | 3.0 | 3.0*) ;;
379 : ${_G_HAVE_PLUSEQ_OP="yes"}
385 # Can be empty, in which case the shell is probed, "yes" if += is
386 # useable or anything else if it does not work.
387 test -z "$_G_HAVE_PLUSEQ_OP" \
388 && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
389 && _G_HAVE_PLUSEQ_OP=yes
391 if test yes = "$_G_HAVE_PLUSEQ_OP"
393 # This is an XSI compatible shell, allowing a faster implementation...
401 # ...otherwise fall back to using expr, which is often a shell builtin.
411 # func_append_quoted VAR VALUE
412 # ----------------------------
413 # Quote VALUE and append to the end of shell variable VAR, separated
415 if test yes = "$_G_HAVE_PLUSEQ_OP"; then
416 eval 'func_append_quoted ()
420 func_quote_for_eval "$2"
421 eval "$1+=\\ \$func_quote_for_eval_result"
424 func_append_quoted ()
428 func_quote_for_eval "$2"
429 eval "$1=\$$1\\ \$func_quote_for_eval_result"
434 # func_append_uniq VAR VALUE
435 # --------------------------
436 # Append unique VALUE onto the existing contents of VAR, assuming
437 # entries are delimited by the first character of VALUE. For example:
439 # func_append_uniq options " --another-option option-argument"
441 # will only append to $options if " --another-option option-argument "
442 # is not already present somewhere in $options already (note spaces at
443 # each end implied by leading space in second argument).
448 eval _G_current_value='`$bs_echo $'$1'`'
449 _G_delim=`expr "$2" : '\(.\)'`
451 case $_G_delim$_G_current_value$_G_delim in
453 *) func_append "$@" ;;
460 # Set func_arith_result to the result of evaluating TERMs.
461 test -z "$_G_HAVE_ARITH_OP" \
462 && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
463 && _G_HAVE_ARITH_OP=yes
465 if test yes = "$_G_HAVE_ARITH_OP"; then
470 func_arith_result=$(( $* ))
477 func_arith_result=`expr "$@"`
484 # Set func_basename_result to FILE with everything up to and including
485 # the last / stripped.
486 if test yes = "$_G_HAVE_XSI_OPS"; then
487 # If this shell supports suffix pattern removal, then use it to avoid
488 # forking. Hide the definitions single quotes in case the shell chokes
489 # on unsupported syntax...
490 _b='func_basename_result=${1##*/}'
492 */*) func_dirname_result=${1%/*}$2 ;;
493 * ) func_dirname_result=$3 ;;
497 # ...otherwise fall back to using sed.
498 _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
499 _d='func_dirname_result=`$ECHO "$1" |$SED "$sed_dirname"`
500 if test "X$func_dirname_result" = "X$1"; then
501 func_dirname_result=$3
503 func_append func_dirname_result "$2"
507 eval 'func_basename ()
515 # func_dirname FILE APPEND NONDIR_REPLACEMENT
516 # -------------------------------------------
517 # Compute the dirname of FILE. If nonempty, add APPEND to the result,
518 # otherwise set result to NONDIR_REPLACEMENT.
519 eval 'func_dirname ()
527 # func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
528 # --------------------------------------------------------
529 # Perform func_basename and func_dirname in a single function
531 # dirname: Compute the dirname of FILE. If nonempty,
532 # add APPEND to the result, otherwise set result
533 # to NONDIR_REPLACEMENT.
534 # value returned in "$func_dirname_result"
535 # basename: Compute filename of FILE.
536 # value retuned in "$func_basename_result"
537 # For efficiency, we do not delegate to the functions above but instead
538 # duplicate the functionality here.
539 eval 'func_dirname_and_basename ()
550 # Echo program name prefixed message.
559 for _G_line in $_G_message; do
561 $bs_echo "$progname: $_G_line"
567 # func_echo_all ARG...
568 # --------------------
569 # Invoke $ECHO with all args, space-separated.
576 # func_echo_infix_1 INFIX ARG...
577 # ------------------------------
578 # Echo program name, followed by INFIX on the first line, with any
579 # additional lines not showing INFIX.
588 _G_prefix="$progname: $_G_infix: "
591 # Strip color escape sequences before counting printable length
592 for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
594 test -n "$_G_tc" && {
595 _G_esc_tc=`$bs_echo "$_G_tc" | sed "$sed_make_literal_regex"`
596 _G_indent=`$bs_echo "$_G_indent" | sed "s|$_G_esc_tc||g"`
599 _G_indent="$progname: "`echo "$_G_indent" | sed 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes
601 func_echo_infix_1_IFS=$IFS
603 for _G_line in $_G_message; do
604 IFS=$func_echo_infix_1_IFS
605 $bs_echo "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
608 IFS=$func_echo_infix_1_IFS
614 # Echo program name prefixed message to standard error.
621 func_echo_infix_1 " $tc_standout${tc_red}error$tc_reset" "$*" >&2
625 # func_fatal_error ARG...
626 # -----------------------
627 # Echo program name prefixed message to standard error, and exit.
637 # func_grep EXPRESSION FILENAME
638 # -----------------------------
639 # Check whether EXPRESSION matches any line of FILENAME, without output.
644 $GREP "$1" "$2" >/dev/null 2>&1
650 # Set func_len_result to the length of STRING. STRING may not
651 # start with a hyphen.
652 test -z "$_G_HAVE_XSI_OPS" \
654 test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
655 && _G_HAVE_XSI_OPS=yes
657 if test yes = "$_G_HAVE_XSI_OPS"; then
662 func_len_result=${#1}
669 func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
674 # func_mkdir_p DIRECTORY-PATH
675 # ---------------------------
676 # Make sure the entire path to DIRECTORY-PATH is available.
684 if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
686 # Protect directory names starting with '-'
687 case $_G_directory_path in
688 -*) _G_directory_path=./$_G_directory_path ;;
691 # While some portion of DIR does not yet exist...
692 while test ! -d "$_G_directory_path"; do
693 # ...make a list in topmost first order. Use a colon delimited
694 # list incase some portion of path contains whitespace.
695 _G_dir_list=$_G_directory_path:$_G_dir_list
697 # If the last portion added has no slash in it, the list is done
698 case $_G_directory_path in */*) ;; *) break ;; esac
700 # ...otherwise throw away the child directory and loop
701 _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
703 _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
705 func_mkdir_p_IFS=$IFS; IFS=:
706 for _G_dir in $_G_dir_list; do
707 IFS=$func_mkdir_p_IFS
708 # mkdir can fail with a 'File exist' error if two processes
709 # try to create one of the directories concurrently. Don't
711 $MKDIR "$_G_dir" 2>/dev/null || :
713 IFS=$func_mkdir_p_IFS
715 # Bail out if we (or some other process) failed to create a directory.
716 test -d "$_G_directory_path" || \
717 func_fatal_error "Failed to create '$1'"
722 # func_mktempdir [BASENAME]
723 # -------------------------
724 # Make a temporary directory that won't clash with other running
725 # libtool processes, and avoids race conditions if possible. If
726 # given, BASENAME is the basename for that directory.
731 _G_template=${TMPDIR-/tmp}/${1-$progname}
733 if test : = "$opt_dry_run"; then
734 # Return a directory name, but don't create it in dry-run mode
735 _G_tmpdir=$_G_template-$$
738 # If mktemp works, use that first and foremost
739 _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
741 if test ! -d "$_G_tmpdir"; then
742 # Failing that, at least try and use $RANDOM to avoid a race
743 _G_tmpdir=$_G_template-${RANDOM-0}$$
745 func_mktempdir_umask=`umask`
748 umask $func_mktempdir_umask
751 # If we're not in dry-run mode, bomb out on failure
752 test -d "$_G_tmpdir" || \
753 func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
760 # func_normal_abspath PATH
761 # ------------------------
762 # Remove doubled-up and trailing slashes, "." path components,
763 # and cancel out any ".." path components in PATH after making
764 # it an absolute path.
765 func_normal_abspath ()
769 # These SED scripts presuppose an absolute path with a trailing slash.
770 _G_pathcar='s|^/\([^/]*\).*$|\1|'
771 _G_pathcdr='s|^/[^/]*||'
772 _G_removedotparts=':dotsl
776 _G_collapseslashes='s|/\{1,\}|/|g'
777 _G_finalslash='s|/*$|/|'
779 # Start from root dir and reassemble the path.
780 func_normal_abspath_result=
781 func_normal_abspath_tpath=$1
782 func_normal_abspath_altnamespace=
783 case $func_normal_abspath_tpath in
785 # Empty path, that just means $cwd.
786 func_stripname '' '/' "`pwd`"
787 func_normal_abspath_result=$func_stripname_result
790 # The next three entries are used to spot a run of precisely
791 # two leading slashes without using negated character classes;
792 # we take advantage of case's first-match behaviour.
794 # Unusual form of absolute path, do nothing.
797 # Not necessarily an ordinary path; POSIX reserves leading '//'
798 # and for example Cygwin uses it to access remote file shares
799 # over CIFS/SMB, so we conserve a leading double slash if found.
800 func_normal_abspath_altnamespace=/
803 # Absolute path, do nothing.
806 # Relative path, prepend $cwd.
807 func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
811 # Cancel out all the simple stuff to save iterations. We also want
812 # the path to end with a slash for ease of parsing, so make sure
813 # there is one (and only one) here.
814 func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
815 -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
817 # Processed it all yet?
818 if test / = "$func_normal_abspath_tpath"; then
819 # If we ascended to the root using ".." the result may be empty now.
820 if test -z "$func_normal_abspath_result"; then
821 func_normal_abspath_result=/
825 func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
827 func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
829 # Figure out what to do with it
830 case $func_normal_abspath_tcomponent in
832 # Trailing empty path component, ignore it.
835 # Parent dir; strip last assembled component from result.
836 func_dirname "$func_normal_abspath_result"
837 func_normal_abspath_result=$func_dirname_result
840 # Actual path component, append it.
841 func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
845 # Restore leading double-slash if one was found on entry.
846 func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
850 # func_notquiet ARG...
851 # --------------------
852 # Echo program name prefixed message only when not in quiet mode.
857 $opt_quiet || func_echo ${1+"$@"}
859 # A bug in bash halts the script if the last line of a function
860 # fails when set -e is in force, so we need another command to
866 # func_relative_path SRCDIR DSTDIR
867 # --------------------------------
868 # Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
869 func_relative_path ()
873 func_relative_path_result=
874 func_normal_abspath "$1"
875 func_relative_path_tlibdir=$func_normal_abspath_result
876 func_normal_abspath "$2"
877 func_relative_path_tbindir=$func_normal_abspath_result
879 # Ascend the tree starting from libdir
881 # check if we have found a prefix of bindir
882 case $func_relative_path_tbindir in
883 $func_relative_path_tlibdir)
884 # found an exact match
885 func_relative_path_tcancelled=
888 $func_relative_path_tlibdir*)
889 # found a matching prefix
890 func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
891 func_relative_path_tcancelled=$func_stripname_result
892 if test -z "$func_relative_path_result"; then
893 func_relative_path_result=.
898 func_dirname $func_relative_path_tlibdir
899 func_relative_path_tlibdir=$func_dirname_result
900 if test -z "$func_relative_path_tlibdir"; then
901 # Have to descend all the way to the root!
902 func_relative_path_result=../$func_relative_path_result
903 func_relative_path_tcancelled=$func_relative_path_tbindir
906 func_relative_path_result=../$func_relative_path_result
911 # Now calculate path; take care to avoid doubling-up slashes.
912 func_stripname '' '/' "$func_relative_path_result"
913 func_relative_path_result=$func_stripname_result
914 func_stripname '/' '/' "$func_relative_path_tcancelled"
915 if test -n "$func_stripname_result"; then
916 func_append func_relative_path_result "/$func_stripname_result"
919 # Normalisation. If bindir is libdir, return '.' else relative path.
920 if test -n "$func_relative_path_result"; then
921 func_stripname './' '' "$func_relative_path_result"
922 func_relative_path_result=$func_stripname_result
925 test -n "$func_relative_path_result" || func_relative_path_result=.
931 # func_quote_for_eval ARG...
932 # --------------------------
933 # Aesthetically quote ARGs to be evaled later.
934 # This function returns two values:
935 # i) func_quote_for_eval_result
936 # double-quoted, suitable for a subsequent eval
937 # ii) func_quote_for_eval_unquoted_result
938 # has all characters that are still active within double
939 # quotes backslashified.
940 func_quote_for_eval ()
944 func_quote_for_eval_unquoted_result=
945 func_quote_for_eval_result=
946 while test 0 -lt $#; do
949 _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
951 _G_unquoted_arg=$1 ;;
953 if test -n "$func_quote_for_eval_unquoted_result"; then
954 func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
956 func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
959 case $_G_unquoted_arg in
960 # Double-quote args containing shell metacharacters to delay
961 # word splitting, command substitution and variable expansion
962 # for a subsequent eval.
963 # Many Bourne shells cannot handle close brackets correctly
964 # in scan sets, so we specify it separately.
965 *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
966 _G_quoted_arg=\"$_G_unquoted_arg\"
969 _G_quoted_arg=$_G_unquoted_arg
973 if test -n "$func_quote_for_eval_result"; then
974 func_append func_quote_for_eval_result " $_G_quoted_arg"
976 func_append func_quote_for_eval_result "$_G_quoted_arg"
983 # func_quote_for_expand ARG
984 # -------------------------
985 # Aesthetically quote ARG to be evaled later; same as above,
986 # but do not quote variable references.
987 func_quote_for_expand ()
993 _G_arg=`$ECHO "$1" | $SED \
994 -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
1000 # Double-quote args containing shell metacharacters to delay
1001 # word splitting and command substitution for a subsequent eval.
1002 # Many Bourne shells cannot handle close brackets correctly
1003 # in scan sets, so we specify it separately.
1004 *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
1009 func_quote_for_expand_result=$_G_arg
1013 # func_stripname PREFIX SUFFIX NAME
1014 # ---------------------------------
1015 # strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1016 # PREFIX and SUFFIX must not contain globbing or regex special
1017 # characters, hashes, percent signs, but SUFFIX may contain a leading
1018 # dot (in which case that matches only a dot).
1019 if test yes = "$_G_HAVE_XSI_OPS"; then
1020 eval 'func_stripname ()
1024 # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1025 # positional parameters, so assign one to ordinary variable first.
1026 func_stripname_result=$3
1027 func_stripname_result=${func_stripname_result#"$1"}
1028 func_stripname_result=${func_stripname_result%"$2"}
1036 .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1037 *) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1043 # func_show_eval CMD [FAIL_EXP]
1044 # -----------------------------
1045 # Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is
1046 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
1047 # is given, then evaluate it.
1053 _G_fail_exp=${2-':'}
1055 func_quote_for_expand "$_G_cmd"
1056 eval "func_notquiet $func_quote_for_expand_result"
1061 if test 0 -ne "$_G_status"; then
1062 eval "(exit $_G_status); $_G_fail_exp"
1068 # func_show_eval_locale CMD [FAIL_EXP]
1069 # ------------------------------------
1070 # Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is
1071 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
1072 # is given, then evaluate it. Use the saved locale for evaluation.
1073 func_show_eval_locale ()
1078 _G_fail_exp=${2-':'}
1081 func_quote_for_expand "$_G_cmd"
1082 eval "func_echo $func_quote_for_expand_result"
1086 eval "$_G_user_locale
1089 eval "$_G_safe_locale"
1090 if test 0 -ne "$_G_status"; then
1091 eval "(exit $_G_status); $_G_fail_exp"
1099 # Turn $1 into a string suitable for a shell variable name.
1100 # Result is stored in $func_tr_sh_result. All characters
1101 # not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1102 # if $1 begins with a digit, a '_' is prepended as well.
1108 [0-9]* | *[!a-zA-Z0-9_]*)
1109 func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1112 func_tr_sh_result=$1
1118 # func_verbose ARG...
1119 # -------------------
1120 # Echo program name prefixed message in verbose mode only.
1125 $opt_verbose && func_echo "$*"
1131 # func_warn_and_continue ARG...
1132 # -----------------------------
1133 # Echo program name prefixed warning message to standard error.
1134 func_warn_and_continue ()
1138 $require_term_colors
1140 func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1144 # func_warning CATEGORY ARG...
1145 # ----------------------------
1146 # Echo program name prefixed warning message to standard error. Warning
1147 # messages can be filtered according to CATEGORY, where this function
1148 # elides messages where CATEGORY is not listed in the global variable
1149 # 'opt_warning_types'.
1154 # CATEGORY must be in the warning_categories list!
1155 case " $warning_categories " in
1157 *) func_internal_error "invalid warning category '$1'" ;;
1163 case " $opt_warning_types " in
1164 *" $_G_category "*) $warning_func ${1+"$@"} ;;
1170 # mode: shell-script
1172 # eval: (add-hook 'write-file-hooks 'time-stamp)
1173 # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1174 # time-stamp-time-zone: "UTC"
1178 # Set a version string for this script.
1179 scriptversion=2012-10-21.11; # UTC
1181 # A portable, pluggable option parser for Bourne shell.
1182 # Written by Gary V. Vaughan, 2010
1184 # Copyright (C) 2010-2013 Free Software Foundation, Inc.
1185 # This is free software; see the source for copying conditions. There is NO
1186 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1188 # This program is free software: you can redistribute it and/or modify
1189 # it under the terms of the GNU General Public License as published by
1190 # the Free Software Foundation, either version 3 of the License, or
1191 # (at your option) any later version.
1193 # This program is distributed in the hope that it will be useful,
1194 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1195 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1196 # GNU General Public License for more details.
1198 # You should have received a copy of the GNU General Public License
1199 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1201 # Please report bugs or propose patches to gary@gnu.org.
1208 # This file is a library for parsing options in your shell scripts along
1209 # with assorted other useful supporting features that you can make use
1212 # For the simplest scripts you might need only:
1215 # . relative/path/to/funclib.sh
1216 # . relative/path/to/options-parser
1218 # func_options ${1+"$@"}
1219 # eval set dummy "$func_options_result"; shift
1220 # ...rest of your script...
1222 # In order for the '--version' option to work, you will need to have a
1223 # suitably formatted comment like the one at the top of this file
1224 # starting with '# Written by ' and ending with '# warranty; '.
1226 # For '-h' and '--help' to work, you will also need a one line
1227 # description of your script's purpose in a comment directly above the
1228 # '# Written by ' line, like the one at the top of this file.
1230 # The default options also support '--debug', which will turn on shell
1231 # execution tracing (see the comment above debug_cmd below for another
1232 # use), and '--verbose' and the func_verbose function to allow your script
1233 # to display verbose messages only when your user has specified
1236 # After sourcing this file, you can plug processing for additional
1237 # options by amending the variables from the 'Configuration' section
1238 # below, and following the instructions in the 'Option parsing'
1239 # section further down.
1241 ## -------------- ##
1242 ## Configuration. ##
1243 ## -------------- ##
1245 # You should override these variables in your script after sourcing this
1246 # file so that they reflect the customisations you have added to the
1249 # The usage line for option parsing errors and the start of '-h' and
1250 # '--help' output messages. You can embed shell variables for delayed
1251 # expansion at the time the message is displayed, but you will need to
1252 # quote other shell meta-characters carefully to prevent them being
1253 # expanded when the contents are evaled.
1254 usage='$progpath [OPTION]...'
1256 # Short help message in response to '-h' and '--help'. Add to this or
1257 # override it after sourcing this library to reflect the full set of
1258 # options your script accepts.
1260 --debug enable verbose shell tracing
1261 -W, --warnings=CATEGORY
1262 report the warnings falling in CATEGORY [all]
1263 -v, --verbose verbosely report processing
1264 --version print version information and exit
1265 -h, --help print short or long help message and exit
1268 # Additional text appended to 'usage_message' in response to '--help'.
1270 Warning categories include:
1271 'all' show all warnings
1272 'none' turn off all the warnings
1273 'error' warnings are treated as fatal errors"
1275 # Help message printed before fatal option parsing errors.
1276 fatal_help="Try '\$progname --help' for more information."
1280 ## ------------------------- ##
1281 ## Hook function management. ##
1282 ## ------------------------- ##
1284 # This section contains functions for adding, removing, and running hooks
1285 # to the main code. A hook is just a named list of of function, that can
1286 # be run in order later on.
1288 # func_hookable FUNC_NAME
1289 # -----------------------
1290 # Declare that FUNC_NAME will run hooks added with
1291 # 'func_add_hook FUNC_NAME ...'.
1296 func_append hookable_fns " $1"
1300 # func_add_hook FUNC_NAME HOOK_FUNC
1301 # ---------------------------------
1302 # Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must
1303 # first have been declared "hookable" by a call to 'func_hookable'.
1308 case " $hookable_fns " in
1310 *) func_fatal_error "'$1' does not accept hook functions." ;;
1313 eval func_append ${1}_hooks '" $2"'
1317 # func_remove_hook FUNC_NAME HOOK_FUNC
1318 # ------------------------------------
1319 # Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1324 eval ${1}_hooks='`$bs_echo "\$'$1'_hooks" |$SED "s| '$2'||"`'
1328 # func_run_hooks FUNC_NAME [ARG]...
1329 # ---------------------------------
1330 # Run all hook functions registered to FUNC_NAME.
1331 # It is assumed that the list of hook functions contains nothing more
1332 # than a whitespace-delimited list of legal shell function names, and
1333 # no effort is wasted trying to catch shell meta-characters or preserve
1339 case " $hookable_fns " in
1341 *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1344 eval _G_hook_fns=\$$1_hooks; shift
1346 for _G_hook in $_G_hook_fns; do
1347 eval $_G_hook '"$@"'
1349 # store returned options list back into positional
1350 # parameters for next 'cmd' execution.
1351 eval _G_hook_result=\$${_G_hook}_result
1352 eval set dummy "$_G_hook_result"; shift
1355 func_quote_for_eval ${1+"$@"}
1356 func_run_hooks_result=$func_quote_for_eval_result
1361 ## --------------- ##
1362 ## Option parsing. ##
1363 ## --------------- ##
1365 # In order to add your own option parsing hooks, you must accept the
1366 # full positional parameter list in your hook function, remove any
1367 # options that you action, and then pass back the remaining unprocessed
1368 # options in '<hooked_function_name>_result', escaped suitably for
1369 # 'eval'. Like this:
1371 # my_options_prep ()
1375 # # Extend the existing usage message.
1376 # usage_message=$usage_message'
1377 # -s, --silent don'\''t print informational messages
1380 # func_quote_for_eval ${1+"$@"}
1381 # my_options_prep_result=$func_quote_for_eval_result
1383 # func_add_hook func_options_prep my_options_prep
1386 # my_silent_option ()
1390 # # Note that for efficiency, we parse as many options as we can
1391 # # recognise in a loop before passing the remainder back to the
1392 # # caller on the first unrecognised argument we encounter.
1393 # while test $# -gt 0; do
1396 # --silent|-s) opt_silent=: ;;
1397 # # Separate non-argument short options:
1398 # -s*) func_split_short_opt "$_G_opt"
1399 # set dummy "$func_split_short_opt_name" \
1400 # "-$func_split_short_opt_arg" ${1+"$@"}
1403 # *) set dummy "$_G_opt" "$*"; shift; break ;;
1407 # func_quote_for_eval ${1+"$@"}
1408 # my_silent_option_result=$func_quote_for_eval_result
1410 # func_add_hook func_parse_options my_silent_option
1413 # my_option_validation ()
1417 # $opt_silent && $opt_verbose && func_fatal_help "\
1418 # '--silent' and '--verbose' options are mutually exclusive."
1420 # func_quote_for_eval ${1+"$@"}
1421 # my_option_validation_result=$func_quote_for_eval_result
1423 # func_add_hook func_validate_options my_option_validation
1425 # You'll alse need to manually amend $usage_message to reflect the extra
1426 # options you parse. It's preferable to append if you can, so that
1427 # multiple option parsing hooks can be added safely.
1430 # func_options [ARG]...
1431 # ---------------------
1432 # All the functions called inside func_options are hookable. See the
1433 # individual implementations for details.
1434 func_hookable func_options
1439 func_options_prep ${1+"$@"}
1440 eval func_parse_options \
1441 ${func_options_prep_result+"$func_options_prep_result"}
1442 eval func_validate_options \
1443 ${func_parse_options_result+"$func_parse_options_result"}
1445 eval func_run_hooks func_options \
1446 ${func_validate_options_result+"$func_validate_options_result"}
1448 # save modified positional parameters for caller
1449 func_options_result=$func_run_hooks_result
1453 # func_options_prep [ARG]...
1454 # --------------------------
1455 # All initialisations required before starting the option parse loop.
1456 # Note that when calling hook functions, we pass through the list of
1457 # positional parameters. If a hook function modifies that list, and
1458 # needs to propogate that back to rest of this script, then the complete
1459 # modified list must be put in 'func_run_hooks_result' before
1461 func_hookable func_options_prep
1462 func_options_prep ()
1470 func_run_hooks func_options_prep ${1+"$@"}
1472 # save modified positional parameters for caller
1473 func_options_prep_result=$func_run_hooks_result
1477 # func_parse_options [ARG]...
1478 # ---------------------------
1479 # The main option parsing loop.
1480 func_hookable func_parse_options
1481 func_parse_options ()
1485 func_parse_options_result=
1487 # this just eases exit handling
1488 while test $# -gt 0; do
1489 # Defer to hook functions for initial option parsing, so they
1490 # get priority in the event of reusing an option name.
1491 func_run_hooks func_parse_options ${1+"$@"}
1493 # Adjust func_parse_options positional parameters to match
1494 eval set dummy "$func_run_hooks_result"; shift
1496 # Break out of the loop if we already parsed every option.
1497 test $# -gt 0 || break
1502 --debug|-x) debug_cmd='set -x'
1503 func_echo "enabling shell trace mode"
1507 --no-warnings|--no-warning|--no-warn)
1508 set dummy --warnings none ${1+"$@"}
1512 --warnings|--warning|-W)
1513 test $# = 0 && func_missing_arg $_G_opt && break
1514 case " $warning_categories $1" in
1516 # trailing space prevents matching last $1 above
1517 func_append_uniq opt_warning_types " $1"
1520 opt_warning_types=$warning_categories
1523 opt_warning_types=none
1527 opt_warning_types=$warning_categories
1528 warning_func=func_fatal_error
1532 "unsupported warning category: '$1'"
1538 --verbose|-v) opt_verbose=: ;;
1539 --version) func_version ;;
1540 -\?|-h) func_usage ;;
1541 --help) func_help ;;
1543 # Separate optargs to long options (plugins may need this):
1544 --*=*) func_split_equals "$_G_opt"
1545 set dummy "$func_split_equals_lhs" \
1546 "$func_split_equals_rhs" ${1+"$@"}
1550 # Separate optargs to short options:
1552 func_split_short_opt "$_G_opt"
1553 set dummy "$func_split_short_opt_name" \
1554 "$func_split_short_opt_arg" ${1+"$@"}
1558 # Separate non-argument short options:
1560 func_split_short_opt "$_G_opt"
1561 set dummy "$func_split_short_opt_name" \
1562 "-$func_split_short_opt_arg" ${1+"$@"}
1567 -*) func_fatal_help "unrecognised option: '$_G_opt'" ;;
1568 *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1572 # save modified positional parameters for caller
1573 func_quote_for_eval ${1+"$@"}
1574 func_parse_options_result=$func_quote_for_eval_result
1578 # func_validate_options [ARG]...
1579 # ------------------------------
1580 # Perform any sanity checks on option settings and/or unconsumed
1582 func_hookable func_validate_options
1583 func_validate_options ()
1587 # Display all warnings if -W was not given.
1588 test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1590 func_run_hooks func_validate_options ${1+"$@"}
1592 # Bail if the options were screwed!
1593 $exit_cmd $EXIT_FAILURE
1595 # save modified positional parameters for caller
1596 func_validate_options_result=$func_run_hooks_result
1601 ## ------------------##
1602 ## Helper functions. ##
1603 ## ------------------##
1605 # This section contains the helper functions used by the rest of the
1606 # hookable option parser framework in ascii-betical order.
1609 # func_fatal_help ARG...
1610 # ----------------------
1611 # Echo program name prefixed message to standard error, followed by
1612 # a help hint, and exit.
1617 eval \$bs_echo \""Usage: $usage"\"
1618 eval \$bs_echo \""$fatal_help"\"
1619 func_error ${1+"$@"}
1626 # Echo long help message to standard output and exit.
1632 $bs_echo "$long_help_message"
1637 # func_missing_arg ARGNAME
1638 # ------------------------
1639 # Echo program name prefixed message to standard error and set global
1645 func_error "Missing argument for '$1'."
1650 # func_split_equals STRING
1651 # ------------------------
1652 # Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1653 # splitting STRING at the '=' sign.
1654 test -z "$_G_HAVE_XSI_OPS" \
1656 test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1657 && _G_HAVE_XSI_OPS=yes
1659 if test yes = "$_G_HAVE_XSI_OPS"
1661 # This is an XSI compatible shell, allowing a faster implementation...
1662 eval 'func_split_equals ()
1666 func_split_equals_lhs=${1%%=*}
1667 func_split_equals_rhs=${1#*=}
1668 test "x$func_split_equals_lhs" = "x$1" \
1669 && func_split_equals_rhs=
1672 # ...otherwise fall back to using expr, which is often a shell builtin.
1673 func_split_equals ()
1677 func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1678 func_split_equals_rhs=
1679 test "x$func_split_equals_lhs" = "x$1" \
1680 || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1682 fi #func_split_equals
1685 # func_split_short_opt SHORTOPT
1686 # -----------------------------
1687 # Set func_split_short_opt_name and func_split_short_opt_arg shell
1688 # variables after splitting SHORTOPT after the 2nd character.
1689 if test yes = "$_G_HAVE_XSI_OPS"
1691 # This is an XSI compatible shell, allowing a faster implementation...
1692 eval 'func_split_short_opt ()
1696 func_split_short_opt_arg=${1#??}
1697 func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1700 # ...otherwise fall back to using expr, which is often a shell builtin.
1701 func_split_short_opt ()
1705 func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1706 func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1708 fi #func_split_short_opt
1713 # Echo short help message to standard output and exit.
1719 $bs_echo "Run '$progname --help |${PAGER-more}' for full usage"
1724 # func_usage_message
1725 # ------------------
1726 # Echo short help message to standard output.
1727 func_usage_message ()
1731 eval \$bs_echo \""Usage: $usage"\"
1738 /^Written by/q' < "$progpath"
1740 eval \$bs_echo \""$usage_message"\"
1746 # Echo version message to standard output and exit.
1751 printf '%s\n' "$progname $scriptversion"
1761 /^# Written by /,/# warranty; / {
1764 s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1771 /^warranty; /q' < "$progpath"
1778 # mode: shell-script
1780 # eval: (add-hook 'write-file-hooks 'time-stamp)
1781 # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1782 # time-stamp-time-zone: "UTC"
1786 # Extract macro arguments from autotools input with GNU M4.
1787 # Written by Gary V. Vaughan, 2010
1789 # Copyright (C) 2010-2013 Free Software Foundation, Inc.
1790 # This is free software; see the source for copying conditions. There is NO
1791 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1793 # Make sure we've evaluated scripts we depend on.
1794 test -z "$progpath" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/funclib.sh
1795 test extract-trace = "$progname" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/options-parser
1797 # Set a version string.
1798 scriptversion=2013-08-22.10; # UTC
1800 # This program is free software: you can redistribute it and/or modify
1801 # it under the terms of the GNU General Public License as published by
1802 # the Free Software Foundation, either version 3 of the License, or
1803 # (at your option) any later version.
1805 # This program is distributed in the hope that it will be useful,
1806 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1807 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1808 # GNU General Public License for more details.
1810 # You should have received a copy of the GNU General Public License
1811 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1813 # Please report bugs or propose patches to gary@gnu.org.
1820 # Run './extract-trace --help' for help with using this script from the
1823 # Or source first 'options-parser' and then this file into your own
1824 # scripts in order to make use of the function and variable framework
1825 # they define, and also to avoid the overhead of forking to run this
1826 # script in its own process on every call.
1830 ## ------------------##
1831 ## Helper functions. ##
1832 ## ------------------##
1834 # This section contains the helper functions used by the rest of
1838 # func_autoconf_configure MAYBE-CONFIGURE-FILE
1839 # --------------------------------------------
1840 # Ensure that MAYBE-CONFIGURE-FILE is the name of a file in the current
1841 # directory that contains an uncommented call to AC_INIT.
1842 func_autoconf_configure ()
1852 # If we were passed a genuine file, make sure it calls AC_INIT.
1854 && _G_ac_init=`$SED "$_G_sed_no_comment" "$1" |grep AC_INIT`
1856 # Otherwise it is not a genuine Autoconf input file.
1857 test -n "$_G_ac_init"
1860 test 0 -ne "$_G_status" \
1861 && func_verbose "'$1' not using Autoconf"
1867 # func_find_tool ENVVAR NAMES...
1868 # ------------------------------
1869 # Search for a required program. Use the value of ENVVAR, if set,
1870 # otherwise find the first of the NAMES that can be run (i.e.,
1871 # supports --version). If found, set ENVVAR to the program name,
1877 _G_find_tool_envvar=$1
1879 _G_find_tool_names=$@
1880 eval "_G_find_tool_res=\$$_G_find_tool_envvar"
1881 if test -n "$_G_find_tool_res"; then
1882 _G_find_tool_error_prefix="\$$find_tool_envvar: "
1886 if func_tool_version_output $_G_prog >/dev/null; then
1887 _G_find_tool_res=$_G_prog
1892 if test -n "$_G_find_tool_res"; then
1893 func_tool_version_output >/dev/null $_G_find_tool_res "\
1894 ${_G_find_tool_error_prefix}Cannot run '$_G_find_tool_res --version'"
1896 # Make sure the result is exported to the environment for children
1898 eval "$_G_find_tool_envvar=\$_G_find_tool_res"
1899 eval "export $_G_find_tool_envvar"
1902 One of these is required:
1903 $_G_find_tool_names"
1908 # func_tool_version_output CMD [FATAL-ERROR-MSG]
1909 # ----------------------------------------------
1910 # Attempt to run 'CMD --version', discarding errors. The output can be
1911 # ignored by redirecting stdout, and this function used simply to test
1912 # whether the command exists and exits normally when passed a
1913 # '--version' argument.
1914 # When FATAL-ERROR-MSG is given, then this function will display the
1915 # message and exit if running 'CMD --version' returns a non-zero exit
1917 func_tool_version_output ()
1922 _G_fatal_error_msg=$2
1924 # Some tools, like 'git2cl' produce thousands of lines of output
1925 # unless stdin is /dev/null - in that case we want to return
1926 # successfully without saving all of that output. Other tools,
1927 # such as 'help2man' exit with a non-zero status when stdin comes
1928 # from /dev/null, so we re-execute without /dev/null if that
1929 # happens. This means that occasionally, the output from both calls
1930 # ends up in the result, but the alternative would be to discard the
1931 # output from one call, and hope the other produces something useful.
1932 { $_G_cmd --version </dev/null || $_G_cmd --version; } 2>/dev/null
1935 test 0 -ne "$_G_status" && test -n "$_G_fatal_error_msg" \
1936 && func_fatal_error "$_G_fatal_error_msg"
1942 ## -------------------- ##
1943 ## Resource management. ##
1944 ## -------------------- ##
1946 # This section contains definitions for functions that each ensure a
1947 # particular resource (a file, or a non-empty configuration variable for
1948 # example) is available, and if appropriate to extract default values
1949 # from pertinent package files. Where a variable already has a non-
1950 # empty value (as set by the package's 'bootstrap.conf'), that value is
1951 # used in preference to deriving the default. Call them using their
1952 # associated 'require_*' variable to ensure that they are executed, at
1955 # It's entirely deliberate that calling these functions can set
1956 # variables that don't obey the namespace limitations obeyed by the rest
1957 # of this file, in order that that they be as useful as possible to
1961 # require_configure_ac
1962 # --------------------
1963 # Ensure that there is a 'configure.ac' or 'configure.in' file in the
1964 # current directory that contains an uncommented call to AC_INIT, and
1965 # that '$configure_ac' contains its name.
1966 require_configure_ac=func_require_configure_ac
1967 func_require_configure_ac ()
1971 test -z "$configure_ac" \
1972 && func_autoconf_configure configure.ac && configure_ac=configure.ac
1973 test -z "$configure_ac" \
1974 && func_autoconf_configure configure.in && configure_ac=configure.in
1975 test -z "$configure_ac" \
1976 || func_verbose "found '$configure_ac'"
1978 require_configure_ac=:
1984 # Search for GNU M4, and export it in $M4.
1985 require_gnu_m4=func_require_gnu_m4
1986 func_require_gnu_m4 ()
1991 # Find the first m4 binary that responds to --version.
1992 func_find_tool M4 gm4 gnum4 m4
1995 test -n "$M4" || func_fatal_error "\
1996 Please install GNU M4, or 'export M4=/path/to/gnu/m4'."
1998 func_verbose "export M4='$M4'"
2000 # Make sure the search result is visible to subshells
2007 ## --------------- ##
2008 ## Core functions. ##
2009 ## --------------- ##
2011 # This section contains the high level functions used when calling this
2012 # file as a script. 'func_extract_trace' is probably the only one that you
2013 # won't want to replace if you source this file into your own script.
2016 # func_extract_trace MACRO_NAMES [FILENAME]...
2017 # --------------------------------------------
2018 # set '$func_extract_trace_result' to a colon delimited list of arguments
2019 # to any of the comma separated list of MACRO_NAMES in FILENAME. If no
2020 # FILENAME is given, then '$configure_ac' is assumed.
2021 func_extract_trace ()
2025 $require_configure_ac
2028 _G_m4_traces=`$bs_echo "--trace=$1" |$SED 's%,% --trace=%g'`
2029 _G_re_macros=`$bs_echo "($1)" |$SED 's%,%|%g'`
2030 _G_macros="$1"; shift
2032 set dummy $configure_ac
2036 # Generate an error if the first file is missing
2039 # Sadly, we can't use 'autom4te' tracing to extract macro arguments,
2040 # because it complains about things we want to ignore at bootstrap
2041 # time - like missing m4_include files; AC_PREREQ being newer than
2042 # the installed autoconf; and returns nothing when tracing
2043 # 'AM_INIT_AUTOMAKE' when aclocal hasn't been generated yet.
2045 # The following tries to emulate a less persnickety version of (and
2046 # due to not having to wait for Perl startup on every invocation,
2047 # it's probably faster too):
2049 # autom4te --language=Autoconf --trace=$my_macro:\$% "$@"
2051 # First we give a minimal set of macro declarations to M4 to prime
2052 # it for reading Autoconf macros, while still providing some of the
2053 # functionality generally used at m4-time to supply dynamic
2054 # arguments to Autocof functions, but without following
2055 # 'm4_s?include' files.
2059 m4_define([m4_copy], [m4_define([$2], m4_defn([$1]))])
2060 m4_define([m4_rename], [m4_copy([$1], [$2])m4_undefine([$1])])
2062 # Disable these macros.
2063 m4_undefine([m4_dnl])
2064 m4_undefine([m4_include])
2065 m4_undefine([m4_m4exit])
2066 m4_undefine([m4_m4wrap])
2067 m4_undefine([m4_maketemp])
2069 # Copy and rename macros not handled by "m4 --prefix".
2070 m4_define([dnl], [m4_builtin([dnl])])
2071 m4_copy([m4_define], [m4_defun])
2072 m4_rename([m4_ifelse], [m4_if])
2073 m4_ifdef([m4_mkstemp], [m4_undefine([m4_mkstemp])])
2074 m4_rename([m4_patsubst], [m4_bpatsubst])
2075 m4_rename([m4_regexp], [m4_bregexp])
2077 # "m4sugar.mini" - useful m4-time macros for dynamic arguments.
2078 # If we discover packages that need more m4 macros defined in
2079 # order to bootstrap correctly, add them here:
2080 m4_define([m4_bmatch],
2081 [m4_if([$#], 0, [], [$#], 1, [], [$#], 2, [$2],
2082 [m4_if(m4_bregexp([$1], [$2]), -1,
2083 [$0([$1], m4_shift3($@))], [$3])])])
2084 m4_define([m4_ifndef], [m4_ifdef([$1], [$3], [$2])])
2085 m4_define([m4_ifset],
2086 [m4_ifdef([$1], [m4_ifval(m4_defn([$1]), [$2], [$3])], [$3])])
2087 m4_define([m4_require], [$1])
2088 m4_define([m4_shift3], [m4_shift(m4shift(m4shift($@)))])
2090 # "autoconf.mini" - things from autoconf macros we care about.
2091 m4_copy([m4_defun], [AC_DEFUN])
2093 # Dummy definitions for the macros we want to trace.
2094 # AM_INIT_AUTOMAKE at least produces no trace without this.
2099 for _G_macro in $_G_macros; do
2101 func_append _G_mini "AC_DEFUN([$_G_macro])$nl"
2105 # We discard M4's stdout, but the M4 trace output from reading our
2106 # "autoconf.mini" followed by any other files passed to this
2107 # function is then scanned by sed to transform it into a colon
2108 # delimited argument list assigned to a shell variable.
2109 _G_transform='s|#.*$||; s|^dnl .*$||; s| dnl .*$||;'
2111 # Unfortunately, alternation in regexp addresses doesn't work in at
2112 # least BSD (and hence Mac OS X) sed, so we have to append a capture
2113 # and print block for each traced macro to the sed transform script.
2116 for _G_macro in $_G_macros; do
2118 func_append _G_transform '
2119 /^m4trace: -1- '"$_G_macro"'/ {
2120 s|^m4trace: -1- '"$_G_macro"'[([]*||
2129 # Save the command pipeline results for further use by callers of
2131 func_extract_trace_result=`$bs_echo "$_G_mini" \
2132 |$M4 -daq --prefix $_G_m4_traces - "$@" 2>&1 1>/dev/null \
2133 |$SED -n -e "$_G_transform"`
2137 # func_extract_trace_first MACRO_NAMES [FILENAME]...
2138 # --------------------------------------------------
2139 # Exactly like func_extract_trace, except that only the first argument
2140 # to the first invocation of one of the comma separated MACRO_NAMES is
2141 # returned in '$func_extract_trace_first_result'.
2142 func_extract_trace_first ()
2146 func_extract_trace ${1+"$@"}
2147 func_extract_trace_first_result=`$bs_echo "$func_extract_trace_result" \
2148 |$SED -e 's|:.*$||g' -e 1q`
2152 # func_main [ARG]...
2153 # ------------------
2159 usage='$progname MACRO_NAME FILE [...]'
2162 The first argument to this program is the name of an autotools macro
2163 whose arguments you want to extract by examining the files listed in the
2164 remaining arguments using the same tool that Autoconf and Automake use,
2167 The arguments are returned separated by colons, with each traced call
2168 on a separate line.'
2170 # Option processing.
2172 eval set dummy "$func_options_result"; shift
2174 # Validate remaining non-option arguments.
2176 || func_fatal_help "not enough arguments"
2178 # Pass non-option arguments to extraction function.
2179 func_extract_trace "$@"
2182 test -n "$func_extract_trace_result" \
2183 && $bs_echo "$func_extract_trace_result"
2190 ## --------------------------- ##
2191 ## Actually perform the trace. ##
2192 ## --------------------------- ##
2194 # Only call 'func_main' if this script was called directly.
2195 test extract-trace = "$progname" && func_main "$@"
2198 # mode: shell-script
2200 # eval: (add-hook 'write-file-hooks 'time-stamp)
2201 # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2202 # time-stamp-time-zone: "UTC"
2205 # Set a version string for *this* script.
2206 scriptversion=2013-09-15.06; # UTC
2208 # This program is free software: you can redistribute it and/or modify
2209 # it under the terms of the GNU General Public License as published by
2210 # the Free Software Foundation, either version 3 of the License, or
2211 # (at your option) any later version.
2213 # This program is distributed in the hope that it will be useful,
2214 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2215 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2216 # GNU General Public License for more details.
2218 # You should have received a copy of the GNU General Public License
2219 # along with this program. If not, see <http://www.gnu.org/licenses/>.
2221 # Originally written by Paul Eggert. The canonical version of this
2222 # script is maintained as build-aux/bootstrap in gnulib, however, to
2223 # be useful to your project, you should place a copy of it under
2224 # version control in the top-level directory of your project. The
2225 # intent is that all customization can be done with a bootstrap.conf
2226 # file also maintained in your version control; gnulib comes with a
2227 # template build-aux/bootstrap.conf to get you started.
2229 # Please report bugs or propose patches to bug-gnulib@gnu.org.
2236 # Most GNUish projects do not keep all of the generated Autotool
2237 # files under version control, but running all of the right tools
2238 # with the right arguments, in the correct order to regenerate
2239 # all of those files in readiness for configuration and building
2240 # can be surprisingly involved! Many projects have a 'bootstrap'
2241 # script under version control to invoke Autotools and perform
2242 # other assorted book-keeping with version numbers and the like.
2244 # This bootstrap script aims to probe the configure.ac and top
2245 # Makefile.am of your project to automatically determine what
2246 # the correct ordering and arguments are and then run the tools for
2247 # you. In order to use it, you can generate an initial standalone
2250 # gl/build-aux/inline-source gl/build-aux/bootstrap.in > bootstrap
2252 # You should then store than script in version control for other
2253 # developers in you project. It will give you instructions about
2254 # how to keep it up to date if the sources change.
2256 # See gl/doc/bootstrap.texi for documentation on how to write
2257 # a bootstrap.conf to customize it for your project's
2261 ## ================================================================== ##
2263 ## DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF ##
2265 ## ================================================================== ##
2267 ## ------------------------------- ##
2268 ## User overridable command paths. ##
2269 ## ------------------------------- ##
2271 # All uppercase denotes values stored in the environment. These
2272 # variables should generally be overridden by the user - however, we do
2273 # set them to 'true' in some parts of this script to prevent them being
2274 # called at the wrong time by other tools that we call ('autoreconf',
2277 # We also allow 'LIBTOOLIZE', 'M4', 'SHA1SUM' and some others to be
2278 # overridden, and export the result for child processes, but they are
2279 # handled by the function 'func_find_tool' and not defaulted in this
2282 : ${ACLOCAL="aclocal"}
2283 : ${AUTOCONF="autoconf"}
2284 : ${AUTOHEADER="autoheader"}
2285 : ${AUTOM4TE="autom4te"}
2286 : ${AUTOHEADER="autoheader"}
2287 : ${AUTOMAKE="automake"}
2288 : ${AUTOPOINT="autopoint"}
2289 : ${AUTORECONF="autoreconf"}
2291 : ${CONFIG_SHELL="/bin/sh"}
2293 : ${EGREP="grep -E"}
2294 : ${FGREP="grep -F"}
2312 ## -------------- ##
2313 ## Configuration. ##
2314 ## -------------- ##
2316 # A newline delimited list of triples of programs (that respond to
2317 # --version), the minimum version numbers required (or just '-' in the
2318 # version field if any version will be sufficient) and homepage URLs
2319 # to help locate missing packages.
2322 # Name of a file containing instructions on installing missing packages
2323 # required in 'buildreq'.
2324 buildreq_readme=README-hacking
2326 # These are extracted from AC_INIT in configure.ac, though you can
2327 # override those values in 'bootstrap.conf' if you prefer.
2335 # These are extracted from 'gnulib-cache.m4', or else fall-back
2336 # automatically on the gnulib defaults; unless you set the values
2337 # manually in 'bootstrap.conf'.
2345 # The list of gnulib modules required at 'gnulib-tool' time. If you
2346 # check 'gnulib-cache.m4' into your repository, then this list will be
2347 # extracted automatically.
2350 # Extra gnulib files that are not in modules, which override files of
2351 # the same name installed by other bootstrap tools.
2352 gnulib_non_module_files="
2354 build-aux/install-sh
2356 build-aux/texinfo.tex
2358 build-aux/config.guess
2359 build-aux/config.sub
2363 # Relative path to the local gnulib submodule, and url to the upstream
2364 # git repository. If you have a gnulib entry in your .gitmodules file,
2365 # these values are ignored.
2369 # Additional gnulib-tool options to use.
2370 gnulib_tool_options="
2374 # bootstrap removes any macro-files that are not included by aclocal.m4,
2375 # except for files listed in this variable that are always kept.
2380 # When truncating long commands for display, always allow at least this
2381 # many characters before truncating.
2384 # The command to download all .po files for a specified domain into
2385 # a specified directory. Fill in the first %s is the domain name, and
2386 # the second with the destination directory. Use rsync's -L and -r
2387 # options because the latest/%s directory and the .po files within are
2389 po_download_command_format=\
2390 "rsync --delete --exclude '*.s1' -Lrtvz \
2391 'translationproject.org::tp/latest/%s/' '%s'"
2393 # Other locale categories that need message catalogs.
2394 extra_locale_categories=
2396 # Additional xgettext options to use. Gnulib might provide you with an
2397 # extensive list of additional options to append to this, but gettext
2398 # 0.16.1 and newer appends them automaticaly, so you can safely ignore
2399 # the complaints from 'gnulib-tool' if your $configure_ac states:
2401 # AM_GNU_GETTEXT_VERSION([0.16.1])
2403 --flag=_:1:pass-c-format
2404 --flag=N_:1:pass-c-format
2407 # Package copyright holder for gettext files. Defaults to FSF if unset.
2410 # File that should exist in the top directory of a checked out hierarchy,
2411 # but not in a distribution tarball.
2414 # Whether to use copies instead of symlinks by default (if set to true,
2415 # the --copy option has no effect).
2418 # Set this to ".cvsignore .gitignore" in 'bootstrap.conf' if you want
2419 # those files to be generated in directories like 'lib/', 'm4/', and 'po/',
2420 # or set it to "auto" to make this script select what to use based
2421 # on what version control system (if any) is used in the source directory.
2422 # Or set it to "none" to ignore VCS ignore files entirely. Default is
2427 ## ------------------- ##
2428 ## Hookable functions. ##
2429 ## ------------------- ##
2431 # After 'bootstrap.conf' has been sourced, execution proceeds by calling
2432 # 'func_bootstrap'. Wherever a function is decorated with
2433 # 'func_hookable func_name', you will find a matching 'func_run_hooks
2434 # func_name', which executes all functions added with 'func_add_hook
2435 # func_name my_func'.
2437 # You might notice that many of these functions begin with a series of
2438 # '$require_foo' lines. See the docu-comments at the start of the
2439 # 'Resource management' section for a description of what these are.
2442 # func_bootstrap [ARG]...
2443 # -----------------------
2444 # All the functions called inside func_bootstrap are hookable. See the
2445 # the individual implementations for details.
2450 # Save the current positional parameters to prevent them being
2451 # corrupted by calls to 'set' in 'func_init'.
2452 func_quote_for_eval ${1+"$@"}
2453 _G_saved_positional_parameters=$func_quote_for_eval_result
2458 # Option processing.
2459 eval func_options "$_G_saved_positional_parameters"
2461 # Post-option preparation.
2464 # Ensure ChangeLog presence.
2465 func_ifcontains "$gnulib_modules" gitlog-to-changelog \
2466 func_ensure_changelog
2468 # Reconfigure the package.
2471 # Ensure .version is up-to-date.
2472 func_update_dotversion
2481 # Any early initialisations can be hooked to this function. Consider
2482 # whether you can hook onto 'func_prep' instead, because if you hook
2483 # any slow to execute code in here, it will also add to the time before
2484 # './bootstrap --version' can respond.
2485 func_hookable func_init
2490 func_run_hooks func_init
2496 # Function to perform preparation for remaining bootstrap process. If
2497 # your hooked code relies on the outcome of 'func_options' hook it here
2498 # rather than to 'func_init'.
2500 # All the functions called inside func_prep are hookable. See the
2501 # individual implementations for details.
2502 func_hookable func_prep
2507 $require_buildtools_uptodate
2508 $require_checkout_only_file
2510 $require_gnulib_merge_changelog
2512 # fetch update files from the translation project
2513 func_update_translations
2515 func_run_hooks func_prep
2519 # func_update_translations
2520 # ------------------------
2521 # Update package po files and translations.
2522 func_hookable func_update_translations
2523 func_update_translations ()
2531 func_update_po_files po $package || exit $?
2534 func_run_hooks func_update_translations
2541 # Reconfigure the current package by running the appropriate autotools in a
2543 func_hookable func_reconfigure
2548 # Released 'autopoint' has the tendency to install macros that have
2549 # been obsoleted in current 'gnulib., so run this before 'gnulib-tool'.
2552 # Autoreconf runs 'aclocal' before 'libtoolize', which causes spurious
2553 # warnings if the initial 'aclocal' is confused by the libtoolized
2554 # (or worse: out-of-date) macro directory.
2557 # If you need to do anything after 'gnulib-tool' is done, but before
2558 # 'autoreconf' runs, you don't need to override this whole function,
2559 # because 'func_gnulib_tool' is hookable.
2564 func_run_hooks func_reconfigure
2570 # Run 'gnulib-tool' to fetch gnulib modules into the current package.
2572 # It's assumed that since you are using gnulib's 'bootstrap' script,
2573 # you're also using gnulib elsewhere in your package. If not, then
2574 # you can replace this function in 'bootstrap.conf' with:
2576 # func_gnulib_tool () { :; }
2578 # (although the function returns immediately if $gnulib_tool is set to
2579 # true in any case).
2580 func_hookable func_gnulib_tool
2585 $require_gnulib_tool
2588 test true = "$gnulib_tool" || {
2589 # bootstrap.conf written for gnulib bootstrap expects
2590 # gnulib_tool_option_extras to which --no-changelog is appended,
2591 # but libtool bootstrap expects you to append to gnulib_tool_options
2592 # so that you can override the --no-changelog default: make sure we
2593 # support both styles so users can migrate between them easily.
2594 gnulib_tool_all_options="$gnulib_tool_options $gnulib_tool_option_extras"
2596 if test -n "$gnulib_modules"; then
2597 $require_gnulib_cache
2598 $require_gnulib_tool_base_options
2600 gnulib_mode=--import
2602 # Try not to pick up any stale values from 'gnulib-cache.m4'.
2603 rm -f "$gnulib_cache"
2605 test -n "$gnulib_tool_base_options" \
2606 && func_append_uniq gnulib_tool_all_options " $gnulib_tool_base_options"
2607 test -n "$gnulib_mk" \
2608 && func_append_uniq gnulib_tool_all_options " --makefile-name=$gnulib_mk"
2609 test -n "$tests_base" && {
2610 func_append_uniq gnulib_tool_all_options " --tests-base=$tests_base"
2611 func_append_uniq gnulib_tool_all_options " --with-tests"
2615 # 'gnulib_modules' and others are cached in 'gnulib-cache.m4':
2616 # Use 'gnulib --update' to fetch gnulib modules.
2617 gnulib_mode=--update
2620 # Add a sensible default libtool option to gnulib_tool_options.
2621 # The embedded echo is to squash whitespace before globbing.
2622 case `echo " "$gnulib_tool_all_options" "` in
2623 *" --no-libtool "*|*" --libtool "*) ;;
2624 *) if test true = "$LIBTOOLIZE"; then
2625 func_append_uniq gnulib_tool_all_options " --no-libtool"
2627 func_append_uniq gnulib_tool_all_options " --libtool"
2632 $opt_copy || func_append_uniq gnulib_tool_all_options " --symlink"
2634 func_append_uniq gnulib_tool_all_options " $gnulib_mode"
2635 func_append gnulib_tool_all_options " $gnulib_modules"
2637 # The embedded echo is to squash whitespace before display.
2638 gnulib_cmd=`echo $gnulib_tool $gnulib_tool_all_options`
2640 func_show_eval "$gnulib_cmd" 'exit $?'
2642 # Use 'gnulib-tool --copy-file' to install non-module files.
2643 func_install_gnulib_non_module_files
2646 func_run_hooks func_gnulib_tool
2652 # Function to perform all finalisation for the bootstrap process.
2653 func_hookable func_fini
2658 func_gettext_configuration
2659 func_clean_dangling_symlinks
2660 func_clean_unused_macros
2661 func_skip_po_recommendation
2663 func_run_hooks func_fini
2665 $require_bootstrap_uptodate
2667 func_echo "Done. Now you can run './configure'."
2671 # func_gettext_configuration
2672 # --------------------------
2673 # Edit configuration values into po/Makevars.
2674 func_hookable func_gettext_configuration
2675 func_gettext_configuration ()
2681 test true = "$AUTOPOINT" || {
2682 $require_copyright_holder
2683 $require_extra_locale_categories
2684 $require_package_bugreport
2686 # Escape xgettext options for sed Makevars generation below.
2687 # We have to delete blank lines in a separate script so that we don't
2688 # append \\\ to the penultimate line, and then delete the last empty
2689 # line, which messes up the variable substitution later in this
2690 # function. Note that adding a literal \\\ requires double escaping
2691 # here, once for the execution subshell, and again for the assignment,
2692 # which is why there are actually 12 (!!) backslashes in the script.
2693 _G_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED '
2695 s|$| \\\\\\\\\\\\|'`
2697 # Create gettext configuration.
2698 func_echo "Creating po/Makevars from po/Makevars.template ..."
2701 /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'|
2702 /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'|
2703 /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'|
2704 /^XGETTEXT_OPTIONS *=/{
2707 '"$_G_xgettext_options"' \\\
2708 $${end_of_xgettext_options+}
2710 ' po/Makevars.template >po/Makevars || exit 1
2713 func_run_hooks func_gettext_configuration
2718 ## --------------- ##
2719 ## Core functions. ##
2720 ## --------------- ##
2722 # This section contains the main functions called from the 'Hookable
2723 # functions' (shown above), and are the ones you're most likely
2724 # to want to replace with your own implementations in 'bootstrap.conf'.
2729 # If this package uses gettext, then run 'autopoint'.
2736 test true = "$AUTOPOINT" \
2737 || func_show_eval "$AUTOPOINT --force" 'exit $?'
2743 # If this package uses libtool, then run 'libtoolize'.
2750 test true = "$LIBTOOLIZE" || {
2751 _G_libtoolize_options=
2752 $opt_copy && func_append _G_libtoolize_options " --copy"
2753 $opt_force && func_append _G_libtoolize_options " --force"
2754 $opt_verbose || func_append _G_libtoolize_options " --quiet"
2755 func_show_eval "$LIBTOOLIZE$_G_libtoolize_options" 'exit $?'
2760 # func_gnulib_tool_copy_file SRC DEST
2761 # -----------------------------------
2762 # Copy SRC, a path relative to the gnulib sub-tree, to DEST, a path
2763 # relative to the top-level source directory using gnulib-tool so that
2764 # any patches or replacements in $local_gl_dir are applied.
2765 func_gnulib_tool_copy_file ()
2769 $require_gnulib_tool
2772 if test true = "$gnulib_tool"; then
2773 # If gnulib-tool is not available (e.g. bootstrapping in a
2774 # distribution tarball), make sure that at least we have some
2775 # version of the required file already in place.
2776 test -f "$2" || func_fatal_error "\
2777 Can't find, copy or download '$2', a required
2778 gnulib supplied file, please provide the location of a
2779 complete 'gnulib' tree by setting 'gnulib_path' in your
2780 'bootstrap.conf' or with the '--gnulib-srcdir' option -
2781 or else specify the location of your 'git' binary by
2782 setting 'GIT' in the environment so that a fresh
2783 'gnulib' submodule can be cloned."
2785 $require_gnulib_copy_cmd
2787 $gnulib_copy_cmd $1 $2 2>/dev/null || {
2788 $require_gnulib_path
2790 func_error "'$gnulib_path/$1' does not exist"
2797 # func_install_gnulib_non_module_files
2798 # ------------------------------------
2799 # Get additional non-module files from gnulib, overriding existing files.
2800 func_install_gnulib_non_module_files ()
2805 $require_gnulib_tool
2807 test -n "$gnulib_non_module_files" && {
2810 for file in $gnulib_non_module_files; do
2812 */COPYING*) dest=COPYING;;
2813 */INSTALL) dest=INSTALL;;
2814 build-aux/missing) dest=
2815 func_warning settings "\
2816 Please remove build-aux/missing from gnulib_module_files in
2817 'bootstrap.conf', as it may clash with Automake's version."
2819 build-aux/*) dest=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
2823 # Be sure to show all copying errors before bailing out
2825 || func_gnulib_tool_copy_file "$file" "$dest" \
2826 || maybe_exit_cmd="exit $EXIT_FAILURE"
2834 # func_ensure_changelog
2835 # ---------------------
2836 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
2837 # will not run to completion with no ChangeLog file.
2838 func_ensure_changelog ()
2842 test -f ChangeLog && mv -f ChangeLog ChangeLog~
2844 cat >ChangeLog <<'EOT'
2845 ## ---------------------- ##
2846 ## DO NOT EDIT THIS FILE! ##
2847 ## ---------------------- ##
2849 ChangeLog is generated by gitlog-to-changelog.
2852 _G_message="creating dummy 'ChangeLog'"
2853 test -f ChangeLog~ \
2854 && func_append _G_message ' (backup in ChangeLog~)'
2855 func_verbose "$_G_message"
2863 # Being careful not to re-run 'autopoint' or 'libtoolize', and not to
2864 # try to run 'autopoint', 'libtoolize' or 'autoheader' on packages that
2865 # don't use them, defer to 'autoreconf' for execution of the remaining
2866 # autotools to bootstrap this package.
2872 $require_build_aux # automake and others put files in here
2873 $require_macro_dir # aclocal and others put files in here
2875 # We ran these manually already, and autoreconf won't exec ':'
2876 save_AUTOPOINT=$AUTOPOINT; AUTOPOINT=true
2877 save_LIBTOOLIZE=$LIBTOOLIZE; LIBTOOLIZE=true
2879 _G_autoreconf_options=
2880 $opt_copy || func_append _G_autoreconf_options " --symlink"
2881 $opt_force && func_append _G_autoreconf_options " --force"
2882 $opt_verbose && func_append _G_autoreconf_options " --verbose"
2883 func_show_eval "$AUTORECONF$_G_autoreconf_options --install" 'exit $?'
2885 AUTOPOINT=$save_AUTOPOINT
2886 LIBTOOLIZE=$save_LIBTOOLIZE
2890 # func_check_configuration VARNAME [CONFIGURE_MACRO]
2891 # --------------------------------------------------
2892 # Exit with a suitable diagnostic for an important configuration change
2893 # that needs to be made before bootstrap can run correctly.
2894 func_check_configuration ()
2898 $require_configure_ac
2900 eval 'test -n "$'$1'"' || {
2901 _G_error_msg="please set '$1' in 'bootstrap.conf'"
2902 if test -n "$configure_ac" && test -n "$2"; then
2903 func_append _G_error_msg "
2904 or add the following (or similar) to your '$configure_ac':
2908 func_fatal_error "$_G_error_msg"
2913 # func_clean_dangling_symlinks
2914 # ----------------------------
2915 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
2916 # gnulib-populated directories. Such .m4 files would cause aclocal to
2917 # fail. The following requires GNU find 4.2.3 or newer. Considering
2918 # the usual portability constraints of this script, that may seem a very
2919 # demanding requirement, but it should be ok. Ignore any failure,
2920 # which is fine, since this is only a convenience to help developers
2921 # avoid the relatively unusual case where a symlinked-to .m4 file is
2922 # git-removed from gnulib between successive runs of this script.
2923 func_clean_dangling_symlinks ()
2928 $require_source_base
2930 func_verbose "cleaning dangling symlinks"
2932 find "$macro_dir" "$source_base" \
2933 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
2934 -type l -xtype l -delete > /dev/null 2>&1
2938 # func_clean_unused_macros
2939 # ------------------------
2940 # Autopoint can result in over-zealously adding macros into $macro_dir
2941 # even though they are not actually used, for example tests to help
2942 # build the 'intl' directory even though you have specified
2943 # 'AM_GNU_GETTEXT([external])' in your configure.ac. This function
2944 # looks removes any macro files that can be found in gnulib, but
2945 # are not 'm4_include'd by 'aclocal.m4'.
2946 func_clean_unused_macros ()
2950 $require_gnulib_path
2953 test -n "$gnulib_path" && test -f aclocal.m4 && {
2954 aclocal_m4s=`find . -name aclocal.m4 -print`
2956 # We use 'ls|grep' instead of 'ls *.m4' to avoid exceeding
2957 # command line length limits in some shells.
2958 for file in `cd "$macro_dir" && ls -1 |grep '\.m4$'`; do
2960 # Remove a macro file when aclocal.m4 does not m4_include it...
2961 func_grep_q 'm4_include([[]'$macro_dir/$file'])' $aclocal_m4s \
2962 || test ! -f "$gnulib_path/m4/$file" || {
2964 # ...and there is an identical file in gnulib...
2965 if func_cmp_s "$gnulib_path/m4/$file" "$macro_dir/$file"; then
2967 # ...and it's not in the precious list ('echo' is needed
2968 # here to squash whitespace for the match expression).
2969 case " "`echo $gnulib_precious`" " in
2971 *) rm -f "$macro_dir/$file"
2973 "removing unused gnulib file '$macro_dir/$file'"
2982 # func_skip_po_recommendation
2983 # ---------------------------
2984 # If there is a po directory, and '--skip-po' wasn't passed, let the
2985 # user know that they can use '--skip-po' on subsequent invocations.
2986 func_skip_po_recommendation ()
2992 || func_warning recommend "\
2993 If your pofiles are up-to-date, you can rerun bootstrap
2994 as '$progname --skip-po' to avoid redownloading."
2998 # func_update_dotversion
2999 # ----------------------
3000 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3001 # will not run to completion with no ChangeLog file.
3002 func_update_dotversion ()
3006 test -f "$build_aux/git-version-gen" && {
3007 _G_message="updating .version"
3008 test -f .version && {
3009 mv .version .version~
3010 func_append _G_message " (backup in .version~)"
3012 func_verbose "updating .version"
3014 $build_aux/git-version-gen dummy-arg > .version
3020 ## -------------------- ##
3021 ## Resource management. ##
3022 ## -------------------- ##
3024 # This section contains definitions for functions that each ensure a
3025 # particular resource (a file, or a non-empty configuration variable for
3026 # example) is available, and if appropriate to extract default values
3027 # from pertinent package files. Where a variable already has a non-
3028 # empty value (as set by the package's 'bootstrap.conf'), that value is
3029 # used in preference to deriving the default. Call them using their
3030 # associated 'require_*' variable to ensure that they are executed, at
3034 # require_checkout_only_file
3035 # --------------------------
3036 # Bail out if this package only bootstraps properly from a repository
3038 require_checkout_only_file=func_require_checkout_only_file
3039 func_require_checkout_only_file ()
3044 test -n "$checkout_only_file" && test ! -f "$checkout_only_file" \
3045 && func_fatal_error "\
3046 Bootstrapping from a non-checked-out distribution is risky.
3047 If you wish to bootstrap anyway, use the '--force' option."
3050 require_checkout_only_file=:
3054 # require_aclocal_amflags
3055 # -----------------------
3056 # Ensure '$aclocal_amflags' has a sensible default, extracted from
3057 # 'Makefile.am' if necessary.
3058 require_aclocal_amflags=func_require_aclocal_amflags
3059 func_require_aclocal_amflags ()
3063 $require_makefile_am
3065 _G_sed_extract_aclocal_amflags='s|#.*$||
3066 /^[ ]*ACLOCAL_AMFLAGS[ ]*=/ {
3067 s|^.*=[ ]*\(.*\)|aclocal_amflags="\1"|
3071 _G_aclocal_flags_cmd=`$SED -n "$_G_sed_extract_aclocal_amflags" \
3073 eval "$_G_aclocal_flags_cmd"
3075 func_verbose "ACLOCAL_AMFLAGS='$aclocal_amflags'"
3077 require_aclocal_amflags=:
3081 # require_autoheader
3082 # ------------------
3083 # Skip autoheader if it's not needed.
3084 require_autoheader=func_require_autoheader
3085 func_require_autoheader ()
3089 test true = "$AUTOHEADER" || {
3090 func_extract_trace AC_CONFIG_HEADERS
3091 test -n "$func_extract_trace_result" \
3092 || func_extract_trace AC_CONFIG_HEADER
3094 test -n "$func_extract_trace_result" || {
3097 func_verbose "export AUTOHEADER='$AUTOHEADER'"
3099 # Make sure the search result is visible to subshells
3104 require_autoheader=:
3110 # Skip autopoint if it's not needed.
3111 require_autopoint=func_require_autopoint
3112 func_require_autopoint ()
3116 test true = "$AUTOPOINT" || {
3117 func_extract_trace AM_GNU_GETTEXT_VERSION
3119 test -n "$func_extract_trace_result" || {
3122 func_verbose "export AUTOPOINT='$AUTOPOINT'"
3124 # Make sure the search result is visible to subshells
3133 # require_bootstrap_uptodate
3134 # --------------------------
3135 # Complain if the version of bootstrap in the gnulib directory differs
3136 # from the one we are running.
3137 require_bootstrap_uptodate=func_require_bootstrap_uptodate
3138 func_require_bootstrap_uptodate ()
3144 _G_bootstrap_sources="
3145 $build_aux/bootstrap.in
3146 $build_aux/extract-trace
3147 $build_aux/funclib.sh
3148 $build_aux/options-parser
3151 _G_missing_bootstrap_sources=false
3152 for _G_src in $_G_bootstrap_sources; do
3153 test -f "$_G_src" || _G_missing_bootstrap_sources=:
3156 if $_G_missing_bootstrap_sources; then
3157 func_warning upgrade "\
3158 Please add bootstrap to your gnulib_modules list in
3159 'bootstrap.conf', so that I can tell you when there are
3162 $build_aux/inline-source $build_aux/bootstrap.in > bootstrap.new
3164 if func_cmp_s "$progpath" bootstrap.new; then
3166 func_verbose "bootstrap script up to date"
3168 func_warning upgrade "\
3169 An updated bootstrap script has been generated for you in
3170 'bootstrap.new'. After you've verified that you want
3171 the changes, you can update with:
3172 cat bootstrap.new > $progname
3175 Or you can disable this check permanently by adding the
3176 following to 'bootstrap.conf':
3177 require_bootstrap_uptodate=:"
3181 require_bootstrap_uptodate=:
3187 # Ensure that '$build_aux' is set, and if it doesn't already point to an
3188 # existing directory, create one.
3189 require_build_aux=func_require_build_aux
3190 func_require_build_aux ()
3194 test -n "$build_aux" || {
3195 func_extract_trace_first AC_CONFIG_AUX_DIR
3196 build_aux=$func_extract_trace_first_result
3197 func_check_configuration build_aux \
3198 "AC_CONFIG_AUX_DIR([name of a directory for build scripts])"
3200 func_verbose "build_aux='$build_aux'"
3203 $require_vc_ignore_files
3205 # If the build_aux directory doesn't exist, create it now, and mark it
3206 # as ignored for the VCS.
3207 if test ! -d "$build_aux"; then
3208 func_show_eval "mkdir '$build_aux'"
3210 test -n "$vc_ignore_files" \
3211 || func_insert_if_absent "$build_aux" $vc_ignore_files
3218 # require_buildreq_autobuild
3219 # --------------------------
3220 # Try to find whether the bootstrap requires autobuild.
3221 require_buildreq_autobuild=func_require_buildreq_autobuild
3222 func_require_buildreq_autobuild ()
3228 test -f "$macro_dir/autobuild.m4" \
3229 || printf '%s\n' "$buildreq" |func_grep_q '^[ ]*autobuild' \
3231 func_extract_trace AB_INIT
3232 test -n "$func_extract_trace_result" && {
3233 func_append buildreq 'autobuild - http://josefsson.org/autobuild/
3235 func_verbose "auto-adding 'autobuild' to build requirements"
3239 require_buildreq_autobuild=:
3243 # require_buildreq_autoconf
3244 # require_buildreq_autopoint
3245 # require_buildreq_libtoolize
3246 # ---------------------------
3247 # Try to find the minimum compatible version of autoconf/libtool
3248 # required to bootstrap successfully, and add it to '$buildreq'.
3249 for tool in autoconf libtoolize autopoint; do
3251 v=require_buildreq_${tool}
3254 autoconf) m=AC_PREREQ ;;
3255 libtoolize) m=LT_PREREQ; b=libtool ;;
3256 autopoint) m=AM_GNU_GETTEXT_VERSION b=gettext ;;
3264 # The following is ignored if undefined, but might be necessary
3265 # in order for `func_find_tool` to run.
3266 ${require_'$tool'-:}
3268 printf '\''%s\n'\'' "$buildreq" |func_grep_q '\''^[ ]*'$tool\'' || {
3269 func_extract_trace '$m'
3270 _G_version=$func_extract_trace_result
3271 test -n "$_G_version" && {
3272 func_append buildreq "\
3273 '$tool' $_G_version http://www.gnu.org/s/'$b'
3276 "auto-adding '\'$tool'-'$_G_version\'' to build requirements"
3286 # require_buildreq_automake
3287 # -------------------------
3288 # Try to find the minimum compatible version of automake required to
3289 # bootstrap successfully, and add it to '$buildreq'.
3290 require_buildreq_automake=func_require_buildreq_automake
3291 func_require_buildreq_automake ()
3295 # if automake is not already listed in $buildreq...
3296 printf '%s\n' "$buildreq" |func_grep_q automake || {
3297 func_extract_trace AM_INIT_AUTOMAKE
3299 # ...and AM_INIT_AUTOMAKE is declared...
3300 test -n "$func_extract_trace_result" && {
3301 automake_version=`$bs_echo "$func_extract_trace_result" \
3302 |$SED -e 's|[^0-9]*||' -e 's| .*$||'`
3303 test -n "$automake_version" || automake_version=-
3305 func_append buildreq "\
3306 automake $automake_version http://www.gnu.org/s/automake
3309 "auto-adding 'automake-$automake_version' to build requirements"
3313 require_buildreq_automake=:
3317 # require_buildreq_patch
3318 # ----------------------
3319 # Automatically add a patch build-requirement if there are diff files
3321 require_buildreq_patch=func_require_buildreq_patch
3322 func_require_buildreq_patch ()
3326 $require_local_gl_dir
3328 # This ensures PATCH is set appropriately by the time
3329 # func_check_versions enforces $buildreq.
3332 # If patch is not already listed in $buildreq...
3333 printf '%s\n' "$buildreq" |func_grep_q '^[ ]*patch' || {
3334 # The ugly find invocation is necessary to exit with non-zero
3335 # status for old find binaries that don't support -exec fully.
3336 if test ! -d "$local_gl_dir" \
3337 || find "$local_gl_dir" -name *.diff -exec false {} \; ; then :
3339 func_append buildreq 'patch - http://www.gnu.org/s/patch
3344 require_buildreq_patch=:
3348 # require_buildtools_uptodate
3349 # ---------------------------
3350 # Ensure all the packages listed in BUILDREQS are available on the build
3351 # machine at the minimum versions or better.
3352 require_buildtools_uptodate=func_require_buildtools_uptodate
3353 func_require_buildtools_uptodate ()
3357 $require_buildreq_autobuild
3358 $require_buildreq_autoconf
3359 $require_buildreq_automake
3360 $require_buildreq_libtoolize
3361 $require_buildreq_autopoint
3362 $require_buildreq_patch
3364 test -n "$buildreq" && {
3367 func_check_versions $buildreq
3368 $func_check_versions_result || {
3369 test -n "$buildreq_readme" \
3370 && test -f "$buildreq_readme" \
3372 $buildreq_readme explains how to obtain these prerequisite programs:
3374 func_strtable 0 11 12 36 \
3375 "Program" "Min_version" "Homepage" $buildreq
3376 func_fatal_error "$_G_error_hdr$func_strtable_result"
3380 require_buildtools_uptodate=:
3384 # require_copyright_holder
3385 # ------------------------
3386 # Ensure there is a sensible non-empty default value in '$copyright_holder'.
3387 require_copyright_holder=func_require_copyright_holder
3388 func_require_copyright_holder ()
3392 test -n "$copyright_holder" || {
3393 copyright_holder='Free Software Foundation, Inc.'
3394 func_warning settings "\
3395 Please set copyright_holder explicitly in 'bootstrap.conf';
3396 defaulting to '$copyright_holder'."
3399 require_copyright_holder=:
3405 # Ensure doc_base has a sensible value, extracted from 'gnulib-cache.m4'
3406 # if possible, otherwise letting 'gnulib-tool' pick a default.
3407 require_doc_base=func_require_doc_base
3408 func_require_doc_base ()
3412 $require_gnulib_cache
3414 test -f "$gnulib_cache" && test -z "$doc_base" && {
3415 func_extract_trace_first "gl_DOC_BASE" "$gnulib_cache"
3416 doc_base=$func_extract_trace_first_result
3418 test -n "$doc_base" && func_verbose "doc_base='$doc_base'"
3425 # require_dotgitmodules
3426 # ---------------------
3427 # Ensure we have a '.gitmodules' file, with appropriate 'gnulib' settings.
3428 require_dotgitmodules=func_require_dotgitmodules
3429 func_require_dotgitmodules ()
3435 test true = "$GIT" || {
3436 # A gnulib entry in .gitmodules always takes precedence.
3437 _G_path=`$GIT config --file .gitmodules submodule.gnulib.path 2>/dev/null`
3439 test -n "$_G_path" || {
3440 $require_vc_ignore_files
3442 func_verbose "creating '.gitmodules'"
3444 # If the .gitmodules file doesn't exist, create it now, and mark
3445 # it as ignored for the VCS.
3446 test -n "$gnulib_path" || gnulib_path=gnulib
3447 test -n "$gnulib_url" || gnulib_url=git://git.sv.gnu.org/gnulib
3450 echo '[submodule "gnulib"]'
3451 echo " path = $gnulib_path"
3452 echo " url = $gnulib_url"
3455 test -n "$vc_ignore_files" \
3456 || func_insert_if_absent ".gitmodules" $vc_ignore_files
3460 require_dotgitmodules=:
3464 # require_extra_locale_categories
3465 # -------------------------------
3466 # Ensure there is a default value in '$extra_locale_categories'
3467 require_extra_locale_categories=func_require_extra_locale_categories
3468 func_require_extra_locale_categories ()
3472 # Defaults to empty, so run with whatever value may have been set in
3474 require_extra_locale_categories=:
3480 # Ignore git if it's not available, or we're not in a git checkout tree.
3481 require_git=func_require_git
3486 $opt_skip_git && GIT=true
3488 test true = "$GIT" || {
3489 if test -f .gitignore && ($GIT --version) >/dev/null 2>&1; then :; else
3494 func_verbose "GIT='$GIT'"
3500 # require_gnulib_cache
3501 # --------------------
3502 # Ensure there is a non-empty default for '$gnulib_cache', and that it
3503 # names an existing file.
3504 require_gnulib_cache=func_require_gnulib_cache
3505 func_require_gnulib_cache ()
3511 test -n "$gnulib_cache" \
3512 || gnulib_cache=$macro_dir/gnulib-cache.m4
3514 func_verbose "found '$gnulib_cache'"
3516 require_gnulib_cache=:
3520 # require_gnulib_copy_cmd
3521 # -----------------------
3522 # Only calculate the options for copying files with gnulib once.
3523 require_gnulib_copy_cmd=func_require_gnulib_copy_cmd
3524 func_require_gnulib_copy_cmd ()
3528 $require_gnulib_tool
3529 $require_gnulib_tool_base_options
3531 gnulib_copy_cmd="$gnulib_tool $gnulib_tool_base_options --copy-file"
3532 $opt_copy || func_append gnulib_copy_cmd " --symlink"
3533 $opt_quiet || func_append gnulib_copy_cmd " --verbose"
3535 require_gnulib_copy_cmd=:
3539 # require_gnulib_merge_changelog
3540 # ------------------------------
3541 # See if we can use gnulib's git-merge-changelog merge driver.
3542 require_gnulib_merge_changelog=func_require_gnulib_merge_changelog
3543 func_require_gnulib_merge_changelog ()
3547 test -f ChangeLog && {
3550 func_grep_q '^\(/\|\)ChangeLog$' .gitignore || test true = "$GIT" || {
3551 if $GIT config merge.merge-changelog.driver >/dev/null; then
3553 elif (git-merge-changelog --version) >/dev/null 2>&1; then
3554 func_echo "initializing git-merge-changelog driver"
3555 $GIT config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
3556 $GIT config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
3558 func_warning recommend \
3559 "Consider installing git-merge-changelog from gnulib."
3564 require_gnulib_merge_changelog=:
3570 # Ensure gnulib_mk has a sensible value, extracted from 'gnulib-cache.m4'
3571 # if possible, otherwise letting 'gnulib-tool' pick a default.
3572 require_gnulib_mk=func_require_gnulib_mk
3573 func_require_gnulib_mk ()
3577 $require_gnulib_cache
3579 test -f "$gnulib_cache" && test -z "$gnulib_mk" && {
3580 func_extract_trace_first "gl_MAKEFILE_NAME" "$gnulib_cache"
3581 gnulib_mk=$func_extract_trace_first_result
3583 test -n "$gnulib_mk" && func_verbose "gnulib_mk='$gnulib_mk'"
3590 # require_gnulib_name
3591 # -------------------
3592 # Ensure gnulib_name has a sensible value, extracted from 'gnulib-cache.m4'
3593 # if possible, otherwise letting 'gnulib-tool' pick a default.
3594 require_gnulib_name=func_require_gnulib_name
3595 func_require_gnulib_name ()
3599 $require_gnulib_cache
3601 test -f "$gnulib_cache" && test -z "$gnulib_name" && {
3602 func_extract_trace_first "gl_LIB" "$gnulib_cache"
3603 gnulib_name=$func_extract_trace_first_result
3605 test -n "$gnulib_name" && func_verbose "gnulib_name='$gnulib_name'"
3608 require_gnulib_name=:
3612 # require_gnulib_path
3613 # require_gnulib_url
3614 # -------------------
3615 # Ensure 'gnulib_path' and 'gnulib_url' are set.
3616 require_gnulib_path=func_require_dotgitmodules_parameters
3617 require_gnulib_url=func_require_dotgitmodules_parameters
3618 func_require_dotgitmodules_parameters ()
3624 test true = "$GIT" && {
3625 # If we can't find git (or if the user specified '--skip-git'),
3626 # then use an existing gnulib directory specified with
3627 # '--gnulib-srcdir' if possible.
3628 test -n "$gnulib_path" \
3629 || test ! -x "$opt_gnulib_srcdir/gnulib-tool" \
3630 || gnulib_path=$opt_gnulib_srcdir
3634 $require_dotgitmodules
3636 test -f .gitmodules && {
3637 # Extract the parameters with sed, since git may be missing
3638 test -n "$gnulib_path" \
3639 || gnulib_path=`$SED -e '/^.submodule "gnulib".$/,${
3641 s|[ ]*||g;s|^[^=]*=||;p
3644 d' .gitmodules |$SED 1q`
3645 test -n "$gnulib_url" \
3646 || gnulib_url=`$SED -e '/^.submodule "gnulib".$/,${
3648 s|[ ]*||g;s|^[^=]*=||;p
3651 d' .gitmodules |$SED 1q`
3653 func_verbose "gnulib_path='$gnulib_path'"
3654 func_verbose "gnulib_url='$gnulib_url'"
3657 require_gnulib_path=:
3658 require_gnulib_url=:
3662 # require_gnulib_submodule
3663 # ------------------------
3664 # Ensure that there is a current gnulib submodule at '$gnulib_path'.
3665 require_gnulib_submodule=func_require_gnulib_submodule
3666 func_require_gnulib_submodule ()
3672 if test true = "$GIT"; then
3673 func_warning recommend \
3674 "No 'git' found; imported gnulib modules may be outdated."
3676 $require_gnulib_path
3679 if test -f .gitmodules && test -f "$gnulib_path/gnulib-tool"; then
3680 : All present and correct.
3682 elif test -n "$opt_gnulib_srcdir"; then
3683 # Older git can't clone into an empty directory.
3684 rmdir "$gnulib_path" 2>/dev/null
3685 func_show_eval "$GIT clone --reference '$opt_gnulib_srcdir' \
3686 '$gnulib_url' '$gnulib_path'" \
3687 || func_fatal_error "Unable to fetch gnulib submodule."
3689 # Without --gnulib-srcdir, and no existing checked out submodule, we
3690 # create a new shallow clone of the remote gnulib repository.
3692 trap func_cleanup_gnulib 1 2 13 15
3695 $GIT clone -h 2>&1 |func_grep_q -- --depth \
3696 && shallow='--depth 365'
3698 func_show_eval "$GIT clone $shallow '$gnulib_url' '$gnulib_path'" \
3701 # FIXME: Solaris /bin/sh will try to execute '-' if any of
3702 # these signals are caught after this.
3706 # Make sure we've checked out the correct revision of gnulib.
3707 func_show_eval "$GIT submodule init" \
3708 && func_show_eval "$GIT submodule update" \
3709 || func_fatal_error "Unable to update gnulib submodule."
3712 require_gnulib_submodule=:
3716 # require_gnulib_tool
3717 # -------------------
3718 # Ensure that '$gnulib_tool' is set, and points to an executable file,
3719 # or else fall back to using the binary 'true' if the main gnulib
3720 # files appear to have been imported already.
3721 require_gnulib_tool=func_require_gnulib_tool
3722 func_require_gnulib_tool ()
3726 test true = "$gnulib_tool" || {
3727 $require_gnulib_submodule
3728 $require_gnulib_path
3730 test -n "$gnulib_tool" \
3731 || gnulib_tool=$gnulib_path/gnulib-tool
3733 test -x "$gnulib_tool" || {
3735 func_warning recommend \
3736 "No 'gnulib-tool' found; gnulib modules may be missing."
3739 test true = "$gnulib_tool" \
3740 || func_verbose "found '$gnulib_tool'"
3743 require_gnulib_tool=:
3747 # require_gnulib_tool_base_options
3748 # --------------------------------
3749 # Ensure that '$gnulib_tool_base_options' contains all the base options
3750 # required according to user configuration from bootstrap.conf.
3751 require_gnulib_tool_base_options=func_require_gnulib_tool_base_options
3752 func_require_gnulib_tool_base_options ()
3756 $require_gnulib_tool
3758 gnulib_tool_base_options=
3760 test true = "$gnulib_tool" || {
3761 # 'gnulib_modules' and others are maintained in 'bootstrap.conf':
3762 # Use 'gnulib --import' to fetch gnulib modules.
3764 test -n "$build_aux" \
3765 && func_append_uniq gnulib_tool_base_options " --aux-dir=$build_aux"
3767 test -n "$macro_dir" \
3768 && func_append_uniq gnulib_tool_base_options " --m4-base=$macro_dir"
3770 test -n "$doc_base" \
3771 && func_append_uniq gnulib_tool_base_options " --doc-base=$doc_base"
3772 $require_gnulib_name
3773 test -n "$gnulib_name" \
3774 && func_append_uniq gnulib_tool_base_options " --lib=$gnulib_name"
3775 $require_local_gl_dir
3776 test -n "$local_gl_dir" \
3777 && func_append_uniq gnulib_tool_base_options " --local-dir=$local_gl_dir"
3778 $require_source_base
3779 test -n "$source_base" \
3780 && func_append_uniq gnulib_tool_base_options " --source-base=$source_base"
3783 require_gnulib_tool_base_options=:
3787 # require_libtoolize
3788 # ------------------
3789 # Skip libtoolize if it's not needed.
3790 require_libtoolize=func_require_libtoolize
3791 func_require_libtoolize ()
3795 # Unless we're not searching for libtool use by this package, set
3796 # LIBTOOLIZE to true if none of 'LT_INIT', 'AC_PROG_LIBTOOL' and
3797 # 'AM_PROG_LIBTOOL' are used in configure.
3798 test true = "$LIBTOOLIZE" || {
3799 func_extract_trace LT_INIT
3800 test -n "$func_extract_trace_result" || func_extract_trace AC_PROG_LIBTOOL
3801 test -n "$func_extract_trace_result" || func_extract_trace AM_PROG_LIBTOOL
3802 test -n "$func_extract_trace_result" || LIBTOOLIZE=true
3805 test -n "$LIBTOOLIZE" || {
3806 # Find libtoolize, named glibtoolize in Mac Ports, but prefer
3807 # user-installed libtoolize to ancient glibtoolize shipped by
3808 # Apple with Mac OS X when Mac Ports is not installed.
3809 func_find_tool LIBTOOLIZE libtoolize glibtoolize
3812 func_verbose "export LIBTOOLIZE='$LIBTOOLIZE'"
3814 # Make sure the search result is visible to subshells
3817 require_libtoolize=:
3821 # require_local_gl_dir
3822 # --------------------
3823 # Ensure local_gl_dir has a sensible value, extracted from 'gnulib-cache.m4'
3824 # if possible, otherwise letting 'gnulib-tool' pick a default.
3825 require_local_gl_dir=func_require_local_gl_dir
3826 func_require_local_gl_dir ()
3830 $require_gnulib_cache
3832 test -f "$gnulib_cache" && test -z "$local_gl_dir" && {
3833 func_extract_trace_first "gl_LOCAL_DIR" "$gnulib_cache"
3834 local_gl_dir=$func_extract_trace_first_result
3836 test -n "$local_gl_dir" && func_verbose "local_gl_dir='$local_gl_dir'"
3839 require_local_gl_dir=:
3845 # Ensure that '$macro_dir' is set, and if it doesn't already point to an
3846 # existing directory, create one.
3847 require_macro_dir=func_require_macro_dir
3848 func_require_macro_dir ()
3852 # Sometimes this is stored in 'configure.ac'.
3853 test -n "$macro_dir" || {
3854 # AC_CONFIG_MACRO_DIRS takes a space delimited list of directories,
3855 # but we only care about the first one in bootstrap.
3856 func_extract_trace_first AC_CONFIG_MACRO_DIRS
3857 macro_dir=`expr "x$func_extract_trace_first_result" : 'x\([^ ]*\)'`
3859 test -n "$macro_dir" || {
3860 func_extract_trace_first AC_CONFIG_MACRO_DIR
3861 macro_dir=$func_extract_trace_first_result
3864 # Otherwise we might find it in 'Makefile.am'.
3865 test -n "$macro_dir" || {
3866 $require_aclocal_amflags
3868 # Take the argument following the first '-I', if any.
3869 _G_minus_I_seen=false
3870 for _G_arg in $aclocal_amflags; do
3871 case $_G_minus_I_seen,$_G_arg in
3872 :,*) macro_dir=$_G_arg; break ;;
3873 *,-I) _G_minus_I_seen=: ;;
3874 *,-I*) macro_dir=`expr x$_G_arg : 'x-I\(.*\)$'`; break ;;
3879 func_verbose "macro_dir='$macro_dir'"
3881 func_check_configuration macro_dir \
3882 "AC_CONFIG_MACRO_DIRS([name of a directory for configure m4 files])"
3884 $require_vc_ignore_files
3886 # If the macro_dir directory doesn't exist, create it now, and mark it
3887 # as ignored for the VCS.
3888 if test ! -d "$macro_dir"; then
3889 mkdir "$macro_dir" || func_permissions_error "$macro_dir"
3891 test -n "$vc_ignore_files" \
3892 || func_insert_if_absent "$macro_dir" $vc_ignore_files
3899 # require_makefile_am
3900 # -------------------
3901 # Ensure there is a 'Makefile.am' in the current directory.
3902 # names an existing file.
3903 require_makefile_am=func_require_makefile_am
3904 func_require_makefile_am ()
3908 test -n "$makefile_am" \
3909 || makefile_am=Makefile.am
3913 func_verbose "found '$makefile_am'"
3915 require_makefile_am=:
3921 # Ensure that '$package' contains a sensible default value.
3922 require_package=func_require_package
3923 func_require_package ()
3927 test -n "$package" || {
3928 $require_package_name
3930 package=`echo "$package_name" \
3931 |$SED -e 's/GNU //' \
3932 -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
3935 func_verbose "package='$package'"
3941 # require_package_bugreport
3942 # -------------------------
3943 # Ensure that this has a sensible value, extracted from 'configure.ac'
3944 # if appropriate (and possible!).
3945 require_package_bugreport=func_require_package_bugreport
3946 func_require_package_bugreport ()
3950 func_extract_trace AC_INIT
3954 set dummy $func_extract_trace_result
3958 test -n "$package_bugreport" || package_bugreport=$3
3959 func_check_configuration package_bugreport \
3960 "AC_INIT([$package_name], [$package_version], [bug-$package@gnu.org])"
3961 func_verbose "package_bugreport='$package_bugreport'"
3963 require_package_bugreport=:
3967 # require_package_name
3968 # --------------------
3969 # Ensure that this has a sensible value, extracted from 'configure.ac'
3970 # if appropriate (and possible!).
3971 require_package_name=func_require_package_name
3972 func_require_package_name ()
3976 func_extract_trace AC_INIT
3980 set dummy $func_extract_trace_result
3984 test -n "$package_name" || package_name=$1
3985 func_check_configuration package_name \
3986 "AC_INIT([name of your package], [package version number])"
3987 func_verbose "package_name='$package_name'"
3989 require_package_name=:
3993 # require_package_version
3994 # -----------------------
3995 # Ensure that this has a sensible value, extracted from 'configure.ac'
3996 # if appropriate (and possible!). While we might have set all the
3997 # parameters extracted from AC_INIT at once, 'package_version' in
3998 # particular is not necessarily available as early as the others, since
3999 # 'git-version-gen' is often involved, and until then we can't rely on
4000 # getting a correct version number from an AC_INIT extraction.
4001 require_package_version=func_require_package_version
4002 func_require_package_version ()
4006 func_extract_trace AC_INIT
4010 set dummy $func_extract_trace_result
4014 test -n "$package_version" || package_version=$2
4015 test -n "$package_version" || {
4016 # The embedded echo is to squash whitespace before globbing.
4017 case " "`echo $gnulib_modules`" " in
4018 *" git-version-gen "*)
4020 cannot \$require_package_version in bootstrap.conf before
4021 func_gnulib_tool has installed the 'git-version-gen' script."
4024 func_check_configuration package_version \
4025 "AC_INIT([name of your package], [package version number])"
4029 func_verbose "package_version='$package_version'"
4031 require_package_version=:
4037 # Find patch, according to the PATCH environment variable, or else
4038 # searching the user's PATH.
4039 require_patch=func_require_patch
4040 func_require_patch ()
4044 test -n "$PATCH" || {
4045 # Find a patch program, preferring gpatch, which is usually better
4046 # than the vendor patch.
4047 func_find_tool PATCH gpatch patch
4050 func_verbose "export PATCH='$PATCH'"
4052 # Make sure the search result is visible to subshells
4059 # require_source_base
4060 # -------------------
4061 # Ensure that source_base has a sensible value, extracted from
4062 # 'gnulib-cache.m4' if possible.
4063 require_source_base=func_require_source_base
4064 func_require_source_base ()
4068 $require_gnulib_cache
4070 test -f "$gnulib_cache" && test -z "$source_base" && {
4071 func_extract_trace_first "gl_SOURCE_BASE" "$gnulib_cache"
4073 source_base=$func_extract_trace_first_result
4075 func_verbose "source_base='$source_base'"
4078 require_source_base=:
4082 # require_vc_ignore_files
4083 # -----------------------
4084 # Ensure that '$vc_ignore' has been processed to list VCS ignore files
4085 # in '$vc_ignore_files'
4086 require_vc_ignore_files=func_require_vc_ignore_files
4087 func_require_vc_ignore_files ()
4091 test -n "$vc_ignore" || vc_ignore=auto
4093 if test auto = "$vc_ignore" && test -z "$vc_ignore_files"; then
4095 test -d .git && vc_ignore_files=.gitignore
4096 test -d CVS && vc_ignore_files="$vc_ignore_files .cvsignore"
4098 vc_ignore_files=$vc_ignore
4101 func_verbose "vc_ignore_files='$vc_ignore_files'"
4103 require_vc_ignore_files=:
4107 ## ------------------##
4108 ## Helper functions. ##
4109 ## ------------------##
4111 # This section contains the helper functions used by the rest of 'bootstrap'.
4115 # STRING may not start with a hyphen.
4116 if (eval 'x=123; test x${#x} = "x3"') 2>/dev/null
4118 # This is an XSI compatible shell, allowing a faster implementation...
4123 func_len_result=${#1}
4126 # ...otherwise fall back to using expr, which is often a shell builtin.
4131 func_len_result=`expr "$1" : ".*" 2>/dev/null || echo 0`
4138 # Portably unset VAR.
4139 # In some shells, an 'unset VAR' statement leaves a non-zero return
4140 # status if VAR is already unset, which might be problematic if the
4141 # statement is used at the end of a function (thus poisoning its return
4142 # value) or when 'set -e' is active (causing even a spurious abort of
4143 # the script in this case).
4146 { eval $1=; unset $1; }
4151 # func_cmp_s FILE1 FILE2
4152 # ----------------------
4153 # Return non-zero exit status unless FILE1 and FILE2 are identical, without
4154 # any output at all, even error messages.
4159 # This function relies on non-zero exit status, which will cause the
4160 # program to exit when running in 'set -e' mode.
4161 $CMP "$@" >/dev/null 2>&1
4165 # func_grep_q EXPRESSION [FILENAME..]
4166 # -----------------------------------
4167 # Check whether EXPRESSION matches any line of any listed FILENAME,
4168 # without any output at all, even error messages.
4173 # This function relies on non-zero exit status, which will cause the
4174 # program to exit when running in 'set -e' mode.
4175 $GREP "$@" >/dev/null 2>&1
4179 # func_ifcontains LIST MEMBER YES-CMD [NO-CMD]
4180 # --------------------------------------------
4181 # If whitespace-separated LIST contains MEMBER then execute YES-CMD,
4182 # otherwise if NO-CMD was give, execute that.
4187 # The embedded echo is to squash whitespace before globbing.
4188 _G_wslist=`$bs_echo " "$1" "`
4204 test 0 -eq "$_G_status" || exit $_G_status
4208 # func_strpad STR WIDTH CHAR
4209 # --------------------------
4210 # Trim STR, or pad with CHAR to force a total length of WIDTH.
4215 _G_width=`expr "$2" - 1`
4216 func_strpad_result=`$bs_echo "$1" |$SED '
4218 s|^.\{0,'"$_G_width"'\}$|&'"$3"'|
4224 # func_strrpad STR WIDTH CHAR
4225 # ---------------------------
4226 # Trim STR, or right-justify-pad with CHAR to force a total length of
4232 _G_width=`expr "$2" - 1`
4233 func_strrpad_result=`$bs_echo "$1" |$SED '
4235 s|^.\{0,'"$_G_width"'\}$|'"$3"'&|
4241 # func_strrow INDENT FIELD WIDTH [FIELDn WIDTHn]...
4242 # -------------------------------------------------
4243 # Return a string containing each FIELD left justified to WIDTH, with
4244 # the whole thing indented by INDENT spaces. This function is used to
4245 # render one row of aligned columns for a table by func_strtable().
4250 func_strrow_linelen=$1; shift
4253 while test $# -gt 0; do
4254 func_strrow_linelen=`expr $func_strrow_linelen + $2`
4255 func_strpad "$1" $2 " "
4256 func_append _G_row "$func_strpad_result"
4260 func_strrpad "$_G_row" $func_strrow_linelen " "
4261 func_strrow_result=$func_strrpad_result
4265 # func_strtable INDENT WIDTH1...WIDTHn HEADER1...HEADERn FIELD1...FIELDn
4266 # ----------------------------------------------------------------------
4267 # Generate a string of newline-separated rows arranged in lined-up
4268 # columns of the given WIDTHs, with the entire table indented by INDENT
4269 # spaces. The number of columns is determined by the number of integer
4270 # valued WIDTH arguments following INDENT. The next set (i.e. a number
4271 # of arguments equal to the number of WIDTH arguments) of fields are
4272 # treated as the table's column HEADERs, and are separated from the
4273 # remainder of the table by an indented row of '-' characters. Remaining
4274 # arguments are each aligned below the next available header, wrapping
4275 # to a new row as necessary. Finally another row of '-' characters is
4276 # added to mark the end of the table.
4278 # For example an unindented 3 column table with 2 rows of data would be
4279 # generated by this call:
4281 # func_strtable 3 20 10 25 \
4282 # Header1 Header2 Header3 \
4283 # Row1Col1 Row1Col2 Row1Col3 \
4284 # Row2Col1 Row2Col2 Row2Col3
4286 # returning the following string:
4288 # " Header1 Header2 Header3
4289 # -------------------------------------------------------
4290 # Row1Col1 Row1Col2 Row1Col3
4291 # Row2Col1 Row2Col2 Row2Col3
4292 # -------------------------------------------------------"
4297 # Save the indent value, we'll need it for each row we render.
4300 # Collect remaining numeric args into a list for reuse between
4301 # members of each row when we call func_strrow later.
4303 while test 0 -lt `expr "$1" : '[1-9][0-9]*$'`; do
4304 func_append _G_widths " $1"; shift
4307 # Extract the same number of positional parameters as there are
4308 # width elements - we'll do the header rows separately so that
4309 # we can insert a divider line.
4310 _G_header=$_G_indent
4311 for _G_width in $_G_widths; do
4312 func_append _G_header " $1 $_G_width"; shift
4314 func_strrow $_G_header
4316 # Strip off the indent, and make a divider with '-' chars, then
4318 _G_divider=`$bs_echo "$func_strrow_result" \
4325 # Append the header and divider to the running result.
4326 func_append func_strtable_result "\
4331 # The remaining rows are zipped between the width values we
4332 # unwound earlier just like the header row above.
4333 while test $# -gt 0; do
4335 for _G_width in $_G_widths; do
4336 func_append _G_row " $1 $_G_width"; shift
4339 func_append func_strtable_result "\
4344 # Mark the end of the table with a final divider line.
4345 func_append func_strtable_result "$_G_divider"
4349 # func_internal_error ARG...
4350 # --------------------------
4351 # Echo program name prefixed message to standard error, and exit.
4352 func_internal_error ()
4355 INTERNAL: " ${1+"$@"} "
4356 Please report this bug to 'bug-gnulib@gnu.org'
4357 in as much detail as possible."
4361 # func_permissions_error FILE-OR-DIRECTORY
4362 # ----------------------------------------
4363 # Echo program name prefixed permissions error message to standard
4365 func_permissions_error ()
4369 func_fatal_error "Failed to create '$1', check permissions."
4373 # func_show_eval CMD [FAIL_EXP]
4374 # -----------------------------
4375 # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is
4376 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
4377 # is given, then evaluate it.
4382 $require_term_colors
4385 _G_fail_exp=${2-':'}
4387 ${opt_silent-'false'} || {
4388 func_quote_for_eval $_G_cmd
4389 eval func_truncate_cmd $func_quote_for_eval_result
4390 func_echo "running: $tc_bold$func_truncate_cmd_result$tc_reset"
4393 ${opt_dry_run-'false'} || {
4396 test 0 -eq "$_G_status" || eval "(exit $_G_status); $_G_fail_exp"
4401 # func_truncate_cmd CMD [ARG]...
4402 # ------------------------------
4403 # For unreasonably long commands (such as a gnulib-tool invocation with
4404 # the full module list for import), truncate CMD after the second non-
4406 func_truncate_cmd ()
4410 _G_last_arg_opt_p=false
4411 func_truncate_cmd_result=
4413 set dummy "$@"; shift
4415 while test $# -gt 0; do
4418 test -n "$func_truncate_cmd_result" \
4419 && func_append func_truncate_cmd_result ' '
4420 func_append func_truncate_cmd_result "$_G_opt"
4422 func_len "x$func_truncate_cmd_result"
4425 -*) _G_last_arg_opt_p=: ;;
4426 *) $_G_last_arg_opt_p \
4427 || test "$min_cmd_len" -gt "$func_len_result" \
4429 _G_last_arg_opt_p=false
4434 test $# -gt 0 && func_append func_truncate_cmd_result "..."
4438 # func_gitignore_entries FILE...
4439 # ------------------------------
4440 # Strip blank and comment lines to leave significant entries.
4441 func_gitignore_entries ()
4445 sed -e '/^#/d' -e '/^$/d' "$@"
4449 # func_insert_if_absent STR FILE...
4450 # ---------------------------------
4451 # If $STR is not already on a line by itself in $FILE, insert it, at the
4452 # start. Entries are inserted at the start of the ignore list to ensure
4453 # existing entries starting with ! are not overridden. Such entries
4454 # support whilelisting exceptions after a more generic blacklist pattern.
4455 # sorting the new contents of the file and replacing $FILE with the result.
4456 func_insert_if_absent ()
4465 test -f "$file" || touch "$file"
4467 duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
4468 test -n "$duplicate_entries" \
4469 && func_error "duplicate entries in $file: " $duplicate_entries
4471 func_grep_q "^$str\$" "$file" \
4472 || func_verbose "inserting '$str' into '$file'"
4474 linesold=`func_gitignore_entries "$file" |wc -l`
4475 linesnew=`{ $bs_echo "$str"; cat "$file"; } \
4476 |func_gitignore_entries |sort -u |wc -l`
4477 test "$linesold" -eq "$linesnew" \
4478 || { sed "1i\\$nl$str$nl" "$file" >"$file"T && mv "$file"T "$file"; } \
4479 || func_permissions_error "$file"
4484 # func_sort_ver VER1 VER2
4485 # -----------------------
4486 # 'sort -V' is not generally available.
4487 # Note this deviates from the version comparison in automake
4488 # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
4489 # but this should suffice as we won't be specifying old
4490 # version formats or redundant trailing .0 in bootstrap.conf.
4491 # If we did want full compatibility then we should probably
4492 # use m4_version_compare from autoconf.
4500 # Split on '.' and compare each component.
4503 p1=`echo "$ver1" |cut -d. -f$i`
4504 p2=`echo "$ver2" |cut -d. -f$i`
4505 if test ! "$p1"; then
4508 elif test ! "$p2"; then
4511 elif test ! "$p1" = "$p2"; then
4512 if test "$p1" -gt "$p2" 2>/dev/null; then # numeric comparison
4514 elif test "$p2" -gt "$p1" 2>/dev/null; then # numeric comparison
4516 else # numeric, then lexicographic comparison
4517 lp=`printf "$p1\n$p2\n" |sort -n |tail -n1`
4518 if test "$lp" = "$p2"; then
4531 # func_get_version APP
4532 # --------------------
4533 # echo the version number (if any) of APP, which is looked up along your
4541 # Rather than uncomment the sed script in-situ, strip the comments
4542 # programatically before passing the result to $SED for evaluation.
4543 sed_get_version=`$bs_echo '# extract version within line
4544 s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4547 # extract version at start of line
4548 s|^\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4554 # the following essentially does s|5.005|5.5|
4555 s|\.0*\([1-9]\)|.\1|g
4558 |$SED '/^[ ]*#.*$/d'`
4560 func_tool_version_output $_G_app >/dev/null
4563 test 0 -ne "$_G_status" \
4564 || $_G_app --version 2>&1 |$SED -n "$sed_get_version"
4570 # func_check_tool APP
4571 # -------------------
4572 # Search PATH for an executable at APP.
4577 func_check_tool_result=
4581 test -x "$1" && func_check_tool_result=$1
4586 for _G_check_tool_path in $PATH; do
4588 if test -x "$_G_check_tool_path/$1"; then
4589 func_check_tool_result=$_G_check_tool_path/$1
4599 # func_check_versions APP1 VER1 URL1 ...[APPN VERN URLN]
4600 # ------------------------------------------------------
4601 func_check_versions ()
4605 func_check_versions_result=:
4607 while test $# -gt 0; do
4612 # Diagnose bad buildreq formatting.
4614 [a-z]*://*) ;; # looks like a url
4615 *) func_fatal_error "\
4616 '$_G_url' from the buildreq table in
4617 'bootstrap.conf' does not look like the URL for downloading
4618 $_G_app. Please ensure that buildreq is a strict newline
4619 delimited list of triples; 'program min-version url'."
4623 # Honor $APP variables ($TAR, $AUTOCONF, etc.)
4624 _G_appvar=`echo $_G_app |tr '[a-z]' '[A-Z]'`
4625 test TAR = "$_G_appvar" && _G_appvar=AMTAR
4626 eval "_G_app=\${$_G_appvar-$_G_app}"
4628 # Fail if no version specified, but the program can't be found.
4629 if test x- = "x$_G_reqver"; then
4630 func_check_tool $_G_app
4631 if test -z "$func_check_tool_result"; then
4632 func_error "Prerequisite '$_G_app' not not found. Please install it, or
4633 'export $_G_appvar=/path/to/$_G_app'."
4634 func_check_versions_result=false
4636 func_verbose "found '$func_check_tool_result' for $_G_appvar."
4639 _G_instver=`func_get_version $_G_app`
4641 test -z "$_G_instver" \
4642 || func_verbose "found '$_G_app' version $_G_instver."
4644 # Fail if --version didn't work.
4645 if test -z "$_G_instver"; then
4646 func_error "Prerequisite '$_G_app' not found. Please install it, or
4647 'export $_G_appvar=/path/to/$_G_app'."
4648 func_check_versions_result=false
4650 # Fail if a newer version than what we have is required.
4652 _G_newer=`func_sort_ver $_G_reqver $_G_instver |cut -d' ' -f2`
4653 test "$_G_newer" != "$_G_instver" && {
4655 '$_G_app' version == $_G_instver is too old
4656 '$_G_app' version >= $_G_reqver is required"
4657 func_check_versions_result=false
4665 # func_cleanup_gnulib
4666 # -------------------
4667 # Recursively delete everything below the path in the global variable
4669 func_cleanup_gnulib ()
4674 $RM -fr "$gnulib_path"
4679 # func_download_po_files SUBDIR DOMAIN
4680 # ------------------------------------
4681 func_download_po_files ()
4685 func_echo "getting translations into $1 for $2..."
4686 _G_cmd=`printf "$po_download_command_format" "$2" "$1"`
4691 # func_update_po_files PO_DIR DOMAIN
4692 # ----------------------------------
4693 # Mirror .po files to $po_dir/.reference and copy only the new
4694 # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
4695 # Note po files that exist locally only are left in $po_dir but will
4696 # not be included in LINGUAS and hence will not be distributed.
4697 func_update_po_files ()
4701 # Directory containing primary .po files.
4702 # Overwrite them only when we're sure a .po file is new.
4706 # Mirror *.po files into this dir.
4707 # Usually contains *.s1 checksum files.
4708 _G_ref_po_dir=$_G_po_dir/.reference
4710 test -d "$_G_ref_po_dir" || mkdir $_G_ref_po_dir || return
4711 func_download_po_files $_G_ref_po_dir $_G_domain \
4712 && ls "$_G_ref_po_dir"/*.po 2>/dev/null \
4713 |$SED -e 's|.*/||' -e 's|\.po$||' > "$_G_po_dir/LINGUAS" || return
4715 # Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6+.
4716 func_find_tool SHA1SUM sha1sum gsha1sum shasum sha1
4718 _G_langs=`cd $_G_ref_po_dir && echo *.po|$SED 's|\.po||g'`
4719 test '*' = "$_G_langs" && _G_langs=x
4720 for _G_po in $_G_langs; do
4721 case $_G_po in x) continue;; esac
4722 _G_new_po=$_G_ref_po_dir/$_G_po.po
4723 _G_cksum_file=$_G_ref_po_dir/$_G_po.s1
4724 if ! test -f "$_G_cksum_file" ||
4725 ! test -f "$_G_po_dir/$_G_po.po" ||
4726 ! $SHA1SUM -c "$_G_cksum_file" \
4727 < "$_G_new_po" > /dev/null; then
4728 echo "updated $_G_po_dir/$_G_po.po..."
4729 cp "$_G_new_po" "$_G_po_dir/$_G_po.po" \
4730 && $SHA1SUM < "$_G_new_po" > "$_G_cksum_file" || return
4737 ## --------------- ##
4738 ## Option parsing. ##
4739 ## --------------- ##
4741 # Hook in the functions to make sure our own options are parsed during
4742 # the option parsing loop.
4744 usage='$progpath [OPTION]...'
4746 # Short help message in response to '-h'. Add to this in 'bootstrap.conf'
4747 # if you accept any additional options.
4748 usage_message="Common Bootstrap Options:
4749 -c, --copy copy files instead of creating symbolic links.
4750 --debug enable verbose shell tracing
4751 -n, --dry-run print commands rather than running them
4752 -f, --force attempt to bootstrap even if the sources seem not
4753 to have been checked out.
4754 --gnulib-srcdir=DIRNAME
4755 specify a local directory where gnulib sources
4756 reside. Use this if you already have the gnulib
4757 sources on your machine, and don't want to waste
4758 your bandwidth downloading them again. Defaults to
4760 --no-warnings equivalent to '-Wnone'
4761 --skip-git do not fetch files from remote repositories
4762 --skip-po do not download po files.
4763 -v, --verbose verbosely report processing
4764 --version print version information and exit
4765 -W, --warnings=CATEGORY
4766 report the warnings falling in CATEGORY [all]
4767 -h, --help print short or long help message and exit
4770 # Additional text appended to 'usage_message' in response to '--help'.
4771 long_help_message=$long_help_message"
4772 'recommend' show warnings about missing recommended packages
4773 'settings' show warnings about missing '$progname.conf' settings
4774 'upgrade' show warnings about out-dated files
4776 If the file '$progname.conf' exists in the same directory as this
4777 script, its contents are read as shell variables to configure the
4780 For build prerequisites, environment variables like \$AUTOCONF and
4781 \$AMTAR are honored.
4783 Running without arguments will suffice in most cases.
4786 # Warning categories used by 'bootstrap', append others if you use them
4787 # in your 'bootstrap.conf'.
4788 warning_categories='recommend settings upgrade'
4791 # bootstrap_options_prep [ARG]...
4792 # -------------------------------
4793 # Preparation for options parsed by Bootstrap.
4794 bootstrap_options_prep ()
4799 opt_copy=${copy-'false'}
4802 opt_gnulib_srcdir=$GNULIB_SRCDIR
4806 # Pass back the list of options we consumed.
4807 func_quote_for_eval ${1+"$@"}
4808 bootstrap_options_prep_result=$func_quote_for_eval_result
4810 func_add_hook func_options_prep bootstrap_options_prep
4813 # bootstrap_parse_options [ARG]...
4814 # --------------------------------
4815 # Provide handling for Bootstrap specific options.
4816 bootstrap_parse_options ()
4820 # Perform our own loop to consume as many options as possible in
4822 while test $# -gt 0; do
4826 --dry-run|--dryrun|-n)
4828 --copy|-c) opt_copy=: ;;
4829 --force|-f) opt_force=: ;;
4832 test $# = 0 && func_missing_arg $_G_opt && break
4833 opt_gnulib_srcdir=$1
4837 --skip-git|--no-git)
4845 # Separate non-argument short options:
4847 func_split_short_opt "$_G_opt"
4848 set dummy "$func_split_short_opt_name" \
4849 "-$func_split_short_opt_arg" ${1+"$@"}
4853 *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
4857 # save modified positional parameters for caller
4858 func_quote_for_eval ${1+"$@"}
4859 bootstrap_parse_options_result=$func_quote_for_eval_result
4861 func_add_hook func_parse_options bootstrap_parse_options
4864 # bootstrap_validate_options [ARG]...
4865 # -----------------------------------
4866 # Perform any sanity checks on option settings and/or unconsumed
4868 bootstrap_validate_options ()
4874 && func_fatal_help "too many arguments"
4876 # Pass back the (empty) list of unconsumed options.
4877 func_quote_for_eval ${1+"$@"}
4878 bootstrap_validate_options_result=$func_quote_for_eval_result
4880 func_add_hook func_validate_options bootstrap_validate_options
4883 ## -------------------------------------------------- ##
4884 ## Source package customisations in 'bootstrap.conf'. ##
4885 ## -------------------------------------------------- ##
4887 # Override the default configuration, if necessary.
4888 # Make sure that bootstrap.conf is sourced from the current directory
4889 # if we were invoked as "sh bootstrap".
4891 */*) test -r "$0.conf" && . "$0.conf" ;;
4892 *) test -r "$0.conf" && . ./"$0.conf" ;;
4896 ## ------------------------------- ##
4897 ## Actually perform the bootstrap. ##
4898 ## ------------------------------- ##
4900 func_bootstrap ${1+"$@"}
4903 exit ${exit_status-$EXIT_SUCCESS}
4906 # mode: shell-script
4908 # eval: (add-hook 'write-file-hooks 'time-stamp)
4909 # time-stamp-pattern: "20/scriptversion=%:y-%02m-%02d.%02H; # UTC"
4910 # time-stamp-time-zone: "UTC"