configury: install headers correctly.
[m4/ericb.git] / bootstrap
blob3188a8772e0d00754f41663efec0ea4946751783
1 #! /bin/sh
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.
42 ## ------ ##
43 ## Usage. ##
44 ## ------ ##
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 :
64 emulate sh
65 NULLCMD=:
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+"$@"}'='"$@"'
69 setopt NO_GLOB_SUBST
70 else
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.
75 _G_user_locale=
76 _G_safe_locale=
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
81 $_G_var=C
82 export $_G_var
83 _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
84 _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
85 fi"
86 done
88 # CDPATH.
89 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
91 # Make sure IFS has a sensible default
92 sp=' '
93 nl='
95 IFS="$sp $nl"
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'
115 else
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'
119 else
120 bs_echo_body='eval expr "X$1" : "X\\(.*\\)"'
121 bs_echo_n_body='eval
122 arg=$1;
123 case $arg in #(
124 *"$nl"*)
125 expr "X$arg" : "X\\(.*\\)$nl";
126 arg=`expr "X$arg" : ".*$nl\\(.*\\)"`;;
127 esac;
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'
133 export bs_echo_body
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.
147 : ${CP="cp -f"}
148 : ${ECHO="$bs_echo"}
149 : ${EGREP="grep -E"}
150 : ${FGREP="grep -F"}
151 : ${GREP="grep"}
152 : ${LN_S="ln -s"}
153 : ${MAKE="make"}
154 : ${MKDIR="mkdir"}
155 : ${MV="mv -f"}
156 : ${RM="rm -f"}
157 : ${SED="sed"}
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
176 # string literally.
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 '$'.
189 _G_bs='\\'
190 _G_bs2='\\\\'
191 _G_bs4='\\\\\\\\'
192 _G_dollar='\$'
193 sed_double_backslash="\
194 s/$_G_bs4/&\\
196 s/^$_G_bs2$_G_dollar/$_G_bs&/
197 s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
198 s/\n//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.
218 EXIT_SUCCESS=0
219 EXIT_FAILURE=1
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-":"}
229 exit_cmd=:
231 # By convention, finish your script with:
233 # exit $exit_status
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
244 # function.
245 progpath=$0
247 # The name of this program.
248 progname=`$bs_echo "$progpath" |$SED "$sed_basename"`
250 # Make sure we have an absolute progpath for reexecution:
251 case $progpath in
252 [\\/]*|[A-Za-z]:\\*) ;;
253 *[\\/]*)
254 progdir=`$bs_echo "$progpath" |$SED "$sed_dirname"`
255 progdir=`cd "$progdir" && pwd`
256 progpath=$progdir/$progname
259 _G_IFS=$IFS
260 IFS=${PATH_SEPARATOR-:}
261 for progdir in $PATH; do
262 IFS=$_G_IFS
263 test -x "$progdir/$progname" && break
264 done
265 IFS=$_G_IFS
266 test -n "$progdir" || progdir=`pwd`
267 progpath=$progdir/$progname
269 esac
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.
280 opt_dry_run=false
281 opt_quiet=false
282 opt_verbose=false
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
286 # code.
287 warning_categories=
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
313 # callers.
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 ()
322 $debug_cmd
324 test -t 1 && {
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
332 tc_reset='\e[0m'
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'
336 else
337 # Otherwise trust the terminfo database after all.
338 test -n "`tput sgr0 2>/dev/null`" && {
339 tc_reset=`tput sgr0`
340 test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
341 tc_standout=$tc_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
371 # being used:
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"}
381 esac
384 # _G_HAVE_PLUSEQ_OP
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"
392 then
393 # This is an XSI compatible shell, allowing a faster implementation...
394 eval 'func_append ()
396 $debug_cmd
398 eval "$1+=\$2"
400 else
401 # ...otherwise fall back to using expr, which is often a shell builtin.
402 func_append ()
404 $debug_cmd
406 eval "$1=\$$1\$2"
411 # func_append_quoted VAR VALUE
412 # ----------------------------
413 # Quote VALUE and append to the end of shell variable VAR, separated
414 # by a space.
415 if test yes = "$_G_HAVE_PLUSEQ_OP"; then
416 eval 'func_append_quoted ()
418 $debug_cmd
420 func_quote_for_eval "$2"
421 eval "$1+=\\ \$func_quote_for_eval_result"
423 else
424 func_append_quoted ()
426 $debug_cmd
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).
444 func_append_uniq ()
446 $debug_cmd
448 eval _G_current_value='`$bs_echo $'$1'`'
449 _G_delim=`expr "$2" : '\(.\)'`
451 case $_G_delim$_G_current_value$_G_delim in
452 *"$2$_G_delim"*) ;;
453 *) func_append "$@" ;;
454 esac
458 # func_arith TERM...
459 # ------------------
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
466 eval 'func_arith ()
468 $debug_cmd
470 func_arith_result=$(( $* ))
472 else
473 func_arith ()
475 $debug_cmd
477 func_arith_result=`expr "$@"`
482 # func_basename FILE
483 # ------------------
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##*/}'
491 _d='case $1 in
492 */*) func_dirname_result=${1%/*}$2 ;;
493 * ) func_dirname_result=$3 ;;
494 esac'
496 else
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
502 else
503 func_append func_dirname_result "$2"
507 eval 'func_basename ()
509 $debug_cmd
511 '"$_b"'
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 ()
521 $debug_cmd
523 '"$_d"'
527 # func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
528 # --------------------------------------------------------
529 # Perform func_basename and func_dirname in a single function
530 # call:
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 ()
541 $debug_cmd
543 '"$_b"'
544 '"$_d"'
548 # func_echo ARG...
549 # ----------------
550 # Echo program name prefixed message.
551 func_echo ()
553 $debug_cmd
555 _G_message=$*
557 func_echo_IFS=$IFS
558 IFS=$nl
559 for _G_line in $_G_message; do
560 IFS=$func_echo_IFS
561 $bs_echo "$progname: $_G_line"
562 done
563 IFS=$func_echo_IFS
567 # func_echo_all ARG...
568 # --------------------
569 # Invoke $ECHO with all args, space-separated.
570 func_echo_all ()
572 $ECHO "$*"
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.
580 func_echo_infix_1 ()
582 $debug_cmd
584 $require_term_colors
586 _G_infix=$1; shift
587 _G_indent=$_G_infix
588 _G_prefix="$progname: $_G_infix: "
589 _G_message=$*
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"`
598 done
599 _G_indent="$progname: "`echo "$_G_indent" | sed 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes
601 func_echo_infix_1_IFS=$IFS
602 IFS=$nl
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
606 _G_prefix=$_G_indent
607 done
608 IFS=$func_echo_infix_1_IFS
612 # func_error ARG...
613 # -----------------
614 # Echo program name prefixed message to standard error.
615 func_error ()
617 $debug_cmd
619 $require_term_colors
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.
628 func_fatal_error ()
630 $debug_cmd
632 func_error "$*"
633 exit $EXIT_FAILURE
637 # func_grep EXPRESSION FILENAME
638 # -----------------------------
639 # Check whether EXPRESSION matches any line of FILENAME, without output.
640 func_grep ()
642 $debug_cmd
644 $GREP "$1" "$2" >/dev/null 2>&1
648 # func_len STRING
649 # ---------------
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" \
653 && (eval 'x=a/b/c;
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
658 eval 'func_len ()
660 $debug_cmd
662 func_len_result=${#1}
664 else
665 func_len ()
667 $debug_cmd
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.
677 func_mkdir_p ()
679 $debug_cmd
681 _G_directory_path=$1
682 _G_dir_list=
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 ;;
689 esac
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"`
702 done
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
710 # stop in that case!
711 $MKDIR "$_G_dir" 2>/dev/null || :
712 done
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.
727 func_mktempdir ()
729 $debug_cmd
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-$$
736 else
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`
746 umask 0077
747 $MKDIR "$_G_tmpdir"
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'"
756 $ECHO "$_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 ()
767 $debug_cmd
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
773 s|/\./|/|g
774 t dotsl
775 s|/\.$|/|'
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
788 return
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.
793 ///*)
794 # Unusual form of absolute path, do nothing.
796 //*)
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
809 esac
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"`
816 while :; do
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=/
823 break
825 func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
826 -e "$_G_pathcar"`
827 func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
828 -e "$_G_pathcdr"`
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"
843 esac
844 done
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.
853 func_notquiet ()
855 $debug_cmd
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
861 # work around that:
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 ()
871 $debug_cmd
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
880 while :; do
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=
886 break
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=.
895 break
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
904 break
906 func_relative_path_result=../$func_relative_path_result
908 esac
909 done
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 ()
942 $debug_cmd
944 func_quote_for_eval_unquoted_result=
945 func_quote_for_eval_result=
946 while test 0 -lt $#; do
947 case $1 in
948 *[\\\`\"\$]*)
949 _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
951 _G_unquoted_arg=$1 ;;
952 esac
953 if test -n "$func_quote_for_eval_unquoted_result"; then
954 func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
955 else
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
971 esac
973 if test -n "$func_quote_for_eval_result"; then
974 func_append func_quote_for_eval_result " $_G_quoted_arg"
975 else
976 func_append func_quote_for_eval_result "$_G_quoted_arg"
978 shift
979 done
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 ()
989 $debug_cmd
991 case $1 in
992 *[\\\`\"]*)
993 _G_arg=`$ECHO "$1" | $SED \
994 -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
996 _G_arg=$1 ;;
997 esac
999 case $_G_arg in
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 *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
1005 _G_arg=\"$_G_arg\"
1007 esac
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 ()
1022 $debug_cmd
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"}
1030 else
1031 func_stripname ()
1033 $debug_cmd
1035 case $2 in
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\$%%"`;;
1038 esac
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.
1048 func_show_eval ()
1050 $debug_cmd
1052 _G_cmd=$1
1053 _G_fail_exp=${2-':'}
1055 func_quote_for_expand "$_G_cmd"
1056 eval "func_notquiet $func_quote_for_expand_result"
1058 $opt_dry_run || {
1059 eval "$_G_cmd"
1060 _G_status=$?
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 ()
1075 $debug_cmd
1077 _G_cmd=$1
1078 _G_fail_exp=${2-':'}
1080 $opt_quiet || {
1081 func_quote_for_expand "$_G_cmd"
1082 eval "func_echo $func_quote_for_expand_result"
1085 $opt_dry_run || {
1086 eval "$_G_user_locale
1087 $_G_cmd"
1088 _G_status=$?
1089 eval "$_G_safe_locale"
1090 if test 0 -ne "$_G_status"; then
1091 eval "(exit $_G_status); $_G_fail_exp"
1097 # func_tr_sh
1098 # ----------
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.
1103 func_tr_sh ()
1105 $debug_cmd
1107 case $1 in
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
1114 esac
1118 # func_verbose ARG...
1119 # -------------------
1120 # Echo program name prefixed message in verbose mode only.
1121 func_verbose ()
1123 $debug_cmd
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 ()
1136 $debug_cmd
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'.
1150 func_warning ()
1152 $debug_cmd
1154 # CATEGORY must be in the warning_categories list!
1155 case " $warning_categories " in
1156 *" $1 "*) ;;
1157 *) func_internal_error "invalid warning category '$1'" ;;
1158 esac
1160 _G_category=$1
1161 shift
1163 case " $opt_warning_types " in
1164 *" $_G_category "*) $warning_func ${1+"$@"} ;;
1165 esac
1169 # Local variables:
1170 # mode: shell-script
1171 # sh-indentation: 2
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"
1175 # End:
1176 #! /bin/sh
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.
1204 ## ------ ##
1205 ## Usage. ##
1206 ## ------ ##
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
1210 # of too.
1212 # For the simplest scripts you might need only:
1214 # #!/bin/sh
1215 # . relative/path/to/funclib.sh
1216 # . relative/path/to/options-parser
1217 # scriptversion=1.0
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
1234 # '--verbose'.
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
1247 # option parser.
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.
1259 usage_message="\
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'.
1269 long_help_message="
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 ...'.
1292 func_hookable ()
1294 $debug_cmd
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'.
1304 func_add_hook ()
1306 $debug_cmd
1308 case " $hookable_fns " in
1309 *" $1 "*) ;;
1310 *) func_fatal_error "'$1' does not accept hook functions." ;;
1311 esac
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.
1320 func_remove_hook ()
1322 $debug_cmd
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
1334 # whitespace.
1335 func_run_hooks ()
1337 $debug_cmd
1339 case " $hookable_fns " in
1340 *" $1 "*) ;;
1341 *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1342 esac
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
1353 done
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 ()
1373 # $debug_cmd
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 ()
1388 # $debug_cmd
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
1394 # opt=$1; shift
1395 # case $opt in
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+"$@"}
1401 # shift
1402 # ;;
1403 # *) set dummy "$_G_opt" "$*"; shift; break ;;
1404 # esac
1405 # done
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 ()
1415 # $debug_cmd
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
1435 func_options ()
1437 $debug_cmd
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
1460 # returning.
1461 func_hookable func_options_prep
1462 func_options_prep ()
1464 $debug_cmd
1466 # Option defaults:
1467 opt_verbose=false
1468 opt_warning_types=
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 ()
1483 $debug_cmd
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
1499 _G_opt=$1
1500 shift
1501 case $_G_opt in
1502 --debug|-x) debug_cmd='set -x'
1503 func_echo "enabling shell trace mode"
1504 $debug_cmd
1507 --no-warnings|--no-warning|--no-warn)
1508 set dummy --warnings none ${1+"$@"}
1509 shift
1512 --warnings|--warning|-W)
1513 test $# = 0 && func_missing_arg $_G_opt && break
1514 case " $warning_categories $1" in
1515 *" $1 "*)
1516 # trailing space prevents matching last $1 above
1517 func_append_uniq opt_warning_types " $1"
1519 *all)
1520 opt_warning_types=$warning_categories
1522 *none)
1523 opt_warning_types=none
1524 warning_func=:
1526 *error)
1527 opt_warning_types=$warning_categories
1528 warning_func=func_fatal_error
1531 func_fatal_error \
1532 "unsupported warning category: '$1'"
1534 esac
1535 shift
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+"$@"}
1547 shift
1550 # Separate optargs to short options:
1551 -W*)
1552 func_split_short_opt "$_G_opt"
1553 set dummy "$func_split_short_opt_name" \
1554 "$func_split_short_opt_arg" ${1+"$@"}
1555 shift
1558 # Separate non-argument short options:
1559 -\?*|-h*|-v*|-x*)
1560 func_split_short_opt "$_G_opt"
1561 set dummy "$func_split_short_opt_name" \
1562 "-$func_split_short_opt_arg" ${1+"$@"}
1563 shift
1566 --) break ;;
1567 -*) func_fatal_help "unrecognised option: '$_G_opt'" ;;
1568 *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1569 esac
1570 done
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
1581 # arguments.
1582 func_hookable func_validate_options
1583 func_validate_options ()
1585 $debug_cmd
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.
1613 func_fatal_help ()
1615 $debug_cmd
1617 eval \$bs_echo \""Usage: $usage"\"
1618 eval \$bs_echo \""$fatal_help"\"
1619 func_error ${1+"$@"}
1620 exit $EXIT_FAILURE
1624 # func_help
1625 # ---------
1626 # Echo long help message to standard output and exit.
1627 func_help ()
1629 $debug_cmd
1631 func_usage_message
1632 $bs_echo "$long_help_message"
1633 exit 0
1637 # func_missing_arg ARGNAME
1638 # ------------------------
1639 # Echo program name prefixed message to standard error and set global
1640 # exit_cmd.
1641 func_missing_arg ()
1643 $debug_cmd
1645 func_error "Missing argument for '$1'."
1646 exit_cmd=exit
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" \
1655 && (eval 'x=a/b/c;
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"
1660 then
1661 # This is an XSI compatible shell, allowing a faster implementation...
1662 eval 'func_split_equals ()
1664 $debug_cmd
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=
1671 else
1672 # ...otherwise fall back to using expr, which is often a shell builtin.
1673 func_split_equals ()
1675 $debug_cmd
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"
1690 then
1691 # This is an XSI compatible shell, allowing a faster implementation...
1692 eval 'func_split_short_opt ()
1694 $debug_cmd
1696 func_split_short_opt_arg=${1#??}
1697 func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1699 else
1700 # ...otherwise fall back to using expr, which is often a shell builtin.
1701 func_split_short_opt ()
1703 $debug_cmd
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
1711 # func_usage
1712 # ----------
1713 # Echo short help message to standard output and exit.
1714 func_usage ()
1716 $debug_cmd
1718 func_usage_message
1719 $bs_echo "Run '$progname --help |${PAGER-more}' for full usage"
1720 exit 0
1724 # func_usage_message
1725 # ------------------
1726 # Echo short help message to standard output.
1727 func_usage_message ()
1729 $debug_cmd
1731 eval \$bs_echo \""Usage: $usage"\"
1732 echo
1733 $SED -n 's|^# ||
1734 /^Written by/{
1735 x;p;x
1738 /^Written by/q' < "$progpath"
1739 echo
1740 eval \$bs_echo \""$usage_message"\"
1744 # func_version
1745 # ------------
1746 # Echo version message to standard output and exit.
1747 func_version ()
1749 $debug_cmd
1751 printf '%s\n' "$progname $scriptversion"
1752 $SED -n '/^##/q
1753 /(C)/!b go
1754 :more
1755 /\./!{
1757 s|\n# | |
1758 b more
1761 /^# Written by /,/# warranty; / {
1762 s|^# ||
1763 s|^# *$||
1764 s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1767 /^# Written by / {
1768 s|^# ||
1771 /^warranty; /q' < "$progpath"
1773 exit $?
1777 # Local variables:
1778 # mode: shell-script
1779 # sh-indentation: 2
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"
1783 # End:
1784 #! /bin/sh
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.
1816 ## ------ ##
1817 ## Usage. ##
1818 ## ------ ##
1820 # Run './extract-trace --help' for help with using this script from the
1821 # command line.
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
1835 # 'extract-trace'.
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 ()
1844 $debug_cmd
1846 _G_sed_no_comment='
1847 s|#.*$||
1848 s|^dnl .*$||
1849 s| dnl .*$||'
1850 _G_ac_init=
1852 # If we were passed a genuine file, make sure it calls AC_INIT.
1853 test -f "$1" \
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"
1858 _G_status=$?
1860 test 0 -ne "$_G_status" \
1861 && func_verbose "'$1' not using Autoconf"
1863 (exit $_G_status)
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,
1872 # die otherwise.
1873 func_find_tool ()
1875 $debug_cmd
1877 _G_find_tool_envvar=$1
1878 shift
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: "
1883 else
1884 for _G_prog
1886 if func_tool_version_output $_G_prog >/dev/null; then
1887 _G_find_tool_res=$_G_prog
1888 break
1890 done
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
1897 # to use.
1898 eval "$_G_find_tool_envvar=\$_G_find_tool_res"
1899 eval "export $_G_find_tool_envvar"
1900 else
1901 func_error "\
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
1916 # status.
1917 func_tool_version_output ()
1919 $debug_cmd
1921 _G_cmd=$1
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
1933 _G_status=$?
1935 test 0 -ne "$_G_status" && test -n "$_G_fatal_error_msg" \
1936 && func_fatal_error "$_G_fatal_error_msg"
1938 (exit $_G_status)
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
1953 # most, once.
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
1958 # callers.
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 ()
1969 $debug_cmd
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=:
1982 # require_gnu_m4
1983 # --------------
1984 # Search for GNU M4, and export it in $M4.
1985 require_gnu_m4=func_require_gnu_m4
1986 func_require_gnu_m4 ()
1988 $debug_cmd
1990 test -n "$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
2001 export M4
2003 require_gnu_m4=:
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 ()
2023 $debug_cmd
2025 $require_configure_ac
2026 $require_gnu_m4
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
2031 test $# -gt 0 || {
2032 set dummy $configure_ac
2033 shift
2036 # Generate an error if the first file is missing
2037 <"$1"
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.
2056 _G_mini='
2057 # Initialisation.
2058 m4_changequote([,])
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.
2097 _G_save=$IFS
2098 IFS=,
2099 for _G_macro in $_G_macros; do
2100 IFS=$_G_save
2101 func_append _G_mini "AC_DEFUN([$_G_macro])$nl"
2102 done
2103 IFS=$_G_save
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.
2114 _G_save=$IFS
2115 IFS=,
2116 for _G_macro in $_G_macros; do
2117 IFS=$_G_save
2118 func_append _G_transform '
2119 /^m4trace: -1- '"$_G_macro"'/ {
2120 s|^m4trace: -1- '"$_G_macro"'[([]*||
2121 s|], [[]|:|g
2122 s|[])]*$|:|
2123 s|\(.\):$|\1|
2126 done
2127 IFS=$_G_save
2129 # Save the command pipeline results for further use by callers of
2130 # this function.
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 ()
2144 $debug_cmd
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 # ------------------
2154 func_main ()
2156 $debug_cmd
2158 # Configuration.
2159 usage='$progname MACRO_NAME FILE [...]'
2161 long_help_message='
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,
2165 GNU M4.
2167 The arguments are returned separated by colons, with each traced call
2168 on a separate line.'
2170 # Option processing.
2171 func_options "$@"
2172 eval set dummy "$func_options_result"; shift
2174 # Validate remaining non-option arguments.
2175 test $# -gt 1 \
2176 || func_fatal_help "not enough arguments"
2178 # Pass non-option arguments to extraction function.
2179 func_extract_trace "$@"
2181 # Display results.
2182 test -n "$func_extract_trace_result" \
2183 && $bs_echo "$func_extract_trace_result"
2185 # The End.
2186 exit $EXIT_SUCCESS
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 "$@"
2197 # Local variables:
2198 # mode: shell-script
2199 # sh-indentation: 2
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"
2203 # End:
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.
2232 ## ------ ##
2233 ## Usage. ##
2234 ## ------ ##
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
2248 # script with:
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
2258 # idiosyncracies.
2261 ## ================================================================== ##
2262 ## ##
2263 ## DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF ##
2264 ## ##
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',
2275 # for example).
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
2280 # section.
2282 : ${ACLOCAL="aclocal"}
2283 : ${AUTOCONF="autoconf"}
2284 : ${AUTOHEADER="autoheader"}
2285 : ${AUTOM4TE="autom4te"}
2286 : ${AUTOHEADER="autoheader"}
2287 : ${AUTOMAKE="automake"}
2288 : ${AUTOPOINT="autopoint"}
2289 : ${AUTORECONF="autoreconf"}
2290 : ${CMP="cmp"}
2291 : ${CONFIG_SHELL="/bin/sh"}
2292 : ${DIFF="diff"}
2293 : ${EGREP="grep -E"}
2294 : ${FGREP="grep -F"}
2295 : ${GIT="git"}
2296 : ${GREP="grep"}
2297 : ${LN_S="ln -s"}
2298 : ${RM="rm"}
2299 : ${SED="sed"}
2301 export ACLOCAL
2302 export AUTOCONF
2303 export AUTOHEADER
2304 export AUTOM4TE
2305 export AUTOHEADER
2306 export AUTOMAKE
2307 export AUTOPOINT
2308 export AUTORECONF
2309 export CONFIG_SHELL
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.
2320 buildreq=
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.
2328 build_aux=
2329 macro_dir=
2330 package=
2331 package_name=
2332 package_version=
2333 package_bugreport=
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'.
2338 doc_base=
2339 gnulib_mk=
2340 gnulib_name=
2341 local_gl_dir=
2342 source_base=
2343 tests_base=
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.
2348 gnulib_modules=
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="
2353 build-aux/compile
2354 build-aux/install-sh
2355 build-aux/mdate-sh
2356 build-aux/texinfo.tex
2357 build-aux/depcomp
2358 build-aux/config.guess
2359 build-aux/config.sub
2360 doc/INSTALL
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.
2366 gnulib_path=
2367 gnulib_url=
2369 # Additional gnulib-tool options to use.
2370 gnulib_tool_options="
2371 --no-changelog
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.
2376 gnulib_precious="
2377 gnulib-tool.m4
2380 # When truncating long commands for display, always allow at least this
2381 # many characters before truncating.
2382 min_cmd_len=160
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
2388 # all symlinks.
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])
2402 xgettext_options="
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.
2408 copyright_holder=
2410 # File that should exist in the top directory of a checked out hierarchy,
2411 # but not in a distribution tarball.
2412 checkout_only_file=
2414 # Whether to use copies instead of symlinks by default (if set to true,
2415 # the --copy option has no effect).
2416 copy=false
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
2423 # "auto".
2424 vc_ignore=
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.
2446 func_bootstrap ()
2448 $debug_cmd
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
2455 # Initialisation.
2456 func_init
2458 # Option processing.
2459 eval func_options "$_G_saved_positional_parameters"
2461 # Post-option preparation.
2462 func_prep
2464 # Reconfigure the package.
2465 func_reconfigure
2467 # Ensure .version is up-to-date.
2468 func_update_dotversion
2470 # Finalisation.
2471 func_fini
2475 # func_init
2476 # ---------
2477 # Any early initialisations can be hooked to this function. Consider
2478 # whether you can hook onto 'func_prep' instead, because if you hook
2479 # any slow to execute code in here, it will also add to the time before
2480 # './bootstrap --version' can respond.
2481 func_hookable func_init
2482 func_init ()
2484 $debug_cmd
2486 func_run_hooks func_init
2490 # func_prep
2491 # ---------
2492 # Function to perform preparation for remaining bootstrap process. If
2493 # your hooked code relies on the outcome of 'func_options' hook it here
2494 # rather than to 'func_init'.
2496 # All the functions called inside func_prep are hookable. See the
2497 # individual implementations for details.
2498 func_hookable func_prep
2499 func_prep ()
2501 $debug_cmd
2503 $require_buildtools_uptodate
2504 $require_checkout_only_file
2506 $require_gnulib_merge_changelog
2508 # fetch update files from the translation project
2509 func_update_translations
2511 func_run_hooks func_prep
2515 # func_update_translations
2516 # ------------------------
2517 # Update package po files and translations.
2518 func_hookable func_update_translations
2519 func_update_translations ()
2521 $debug_cmd
2523 $opt_skip_po || {
2524 test -d po && {
2525 $require_package
2527 func_update_po_files po $package || exit $?
2530 func_run_hooks func_update_translations
2535 # func_reconfigure
2536 # ----------------
2537 # Reconfigure the current package by running the appropriate autotools in a
2538 # suitable order.
2539 func_hookable func_reconfigure
2540 func_reconfigure ()
2542 $debug_cmd
2544 # Ensure ChangeLog presence.
2545 if test -n "$gnulib_modules"; then
2546 func_ifcontains "$gnulib_modules" gitlog-to-changelog \
2547 func_ensure_changelog
2548 else
2549 $require_gnulib_cache
2550 if sed -n '/^gl_MODULES(\[/,/^])$/p' $gnulib_cache 2>/dev/null |
2551 func_grep_q gitlog-to-changelog
2552 then
2553 func_ensure_changelog
2557 # Released 'autopoint' has the tendency to install macros that have
2558 # been obsoleted in current 'gnulib., so run this before 'gnulib-tool'.
2559 func_autopoint
2561 # Autoreconf runs 'aclocal' before 'libtoolize', which causes spurious
2562 # warnings if the initial 'aclocal' is confused by the libtoolized
2563 # (or worse: out-of-date) macro directory.
2564 func_libtoolize
2566 # If you need to do anything after 'gnulib-tool' is done, but before
2567 # 'autoreconf' runs, you don't need to override this whole function,
2568 # because 'func_gnulib_tool' is hookable.
2569 func_gnulib_tool
2571 func_autoreconf
2573 func_run_hooks func_reconfigure
2577 # func_gnulib_tool
2578 # ----------------
2579 # Run 'gnulib-tool' to fetch gnulib modules into the current package.
2581 # It's assumed that since you are using gnulib's 'bootstrap' script,
2582 # you're also using gnulib elsewhere in your package. If not, then
2583 # you can replace this function in 'bootstrap.conf' with:
2585 # func_gnulib_tool () { :; }
2587 # (although the function returns immediately if $gnulib_tool is set to
2588 # true in any case).
2589 func_hookable func_gnulib_tool
2590 func_gnulib_tool ()
2592 $debug_cmd
2594 $require_gnulib_tool
2595 $require_libtoolize
2597 test true = "$gnulib_tool" || {
2598 # bootstrap.conf written for gnulib bootstrap expects
2599 # gnulib_tool_option_extras to which --no-changelog is appended,
2600 # but libtool bootstrap expects you to append to gnulib_tool_options
2601 # so that you can override the --no-changelog default: make sure we
2602 # support both styles so users can migrate between them easily.
2603 gnulib_tool_all_options="$gnulib_tool_options $gnulib_tool_option_extras"
2605 if test -n "$gnulib_modules"; then
2606 $require_gnulib_cache
2607 $require_gnulib_tool_base_options
2609 gnulib_mode=--import
2611 # Try not to pick up any stale values from 'gnulib-cache.m4'.
2612 rm -f "$gnulib_cache"
2614 test -n "$gnulib_tool_base_options" \
2615 && func_append_uniq gnulib_tool_all_options " $gnulib_tool_base_options"
2616 test -n "$gnulib_mk" \
2617 && func_append_uniq gnulib_tool_all_options " --makefile-name=$gnulib_mk"
2618 test -n "$tests_base" && {
2619 func_append_uniq gnulib_tool_all_options " --tests-base=$tests_base"
2620 func_append_uniq gnulib_tool_all_options " --with-tests"
2622 else
2624 # 'gnulib_modules' and others are cached in 'gnulib-cache.m4':
2625 # Use 'gnulib --update' to fetch gnulib modules.
2626 gnulib_mode=--update
2629 # Add a sensible default libtool option to gnulib_tool_options.
2630 # The embedded echo is to squash whitespace before globbing.
2631 case `echo " "$gnulib_tool_all_options" "` in
2632 *" --no-libtool "*|*" --libtool "*) ;;
2633 *) if test true = "$LIBTOOLIZE"; then
2634 func_append_uniq gnulib_tool_all_options " --no-libtool"
2635 else
2636 func_append_uniq gnulib_tool_all_options " --libtool"
2639 esac
2641 $opt_copy || func_append_uniq gnulib_tool_all_options " --symlink"
2643 func_append_uniq gnulib_tool_all_options " $gnulib_mode"
2644 func_append gnulib_tool_all_options " $gnulib_modules"
2646 # The embedded echo is to squash whitespace before display.
2647 gnulib_cmd=`echo $gnulib_tool $gnulib_tool_all_options`
2649 func_show_eval "$gnulib_cmd" 'exit $?'
2651 # Use 'gnulib-tool --copy-file' to install non-module files.
2652 func_install_gnulib_non_module_files
2655 func_run_hooks func_gnulib_tool
2659 # func_fini
2660 # ---------
2661 # Function to perform all finalisation for the bootstrap process.
2662 func_hookable func_fini
2663 func_fini ()
2665 $debug_cmd
2667 func_gettext_configuration
2668 func_clean_dangling_symlinks
2669 func_clean_unused_macros
2670 func_skip_po_recommendation
2672 func_run_hooks func_fini
2674 $require_bootstrap_uptodate
2676 func_echo "Done. Now you can run './configure'."
2680 # func_gettext_configuration
2681 # --------------------------
2682 # Edit configuration values into po/Makevars.
2683 func_hookable func_gettext_configuration
2684 func_gettext_configuration ()
2686 $debug_cmd
2688 $require_autopoint
2690 test true = "$AUTOPOINT" || {
2691 $require_copyright_holder
2692 $require_extra_locale_categories
2693 $require_package_bugreport
2695 # Escape xgettext options for sed Makevars generation below.
2696 # We have to delete blank lines in a separate script so that we don't
2697 # append \\\ to the penultimate line, and then delete the last empty
2698 # line, which messes up the variable substitution later in this
2699 # function. Note that adding a literal \\\ requires double escaping
2700 # here, once for the execution subshell, and again for the assignment,
2701 # which is why there are actually 12 (!!) backslashes in the script.
2702 _G_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED '
2704 s|$| \\\\\\\\\\\\|'`
2706 # Create gettext configuration.
2707 func_echo "Creating po/Makevars from po/Makevars.template ..."
2708 $RM -f po/Makevars
2709 $SED '
2710 /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'|
2711 /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'|
2712 /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'|
2713 /^XGETTEXT_OPTIONS *=/{
2714 s|$| \\|
2716 '"$_G_xgettext_options"' \\\
2717 $${end_of_xgettext_options+}
2719 ' po/Makevars.template >po/Makevars || exit 1
2722 func_run_hooks func_gettext_configuration
2727 ## --------------- ##
2728 ## Core functions. ##
2729 ## --------------- ##
2731 # This section contains the main functions called from the 'Hookable
2732 # functions' (shown above), and are the ones you're most likely
2733 # to want to replace with your own implementations in 'bootstrap.conf'.
2736 # func_autopoint
2737 # --------------
2738 # If this package uses gettext, then run 'autopoint'.
2739 func_autopoint ()
2741 $debug_cmd
2743 $require_autopoint
2745 test true = "$AUTOPOINT" \
2746 || func_show_eval "$AUTOPOINT --force" 'exit $?'
2750 # func_libtoolize
2751 # ---------------
2752 # If this package uses libtool, then run 'libtoolize'.
2753 func_libtoolize ()
2755 $debug_cmd
2757 $require_libtoolize
2759 test true = "$LIBTOOLIZE" || {
2760 _G_libtoolize_options=
2761 $opt_copy && func_append _G_libtoolize_options " --copy"
2762 $opt_force && func_append _G_libtoolize_options " --force"
2763 $opt_verbose || func_append _G_libtoolize_options " --quiet"
2764 func_show_eval "$LIBTOOLIZE$_G_libtoolize_options" 'exit $?'
2769 # func_gnulib_tool_copy_file SRC DEST
2770 # -----------------------------------
2771 # Copy SRC, a path relative to the gnulib sub-tree, to DEST, a path
2772 # relative to the top-level source directory using gnulib-tool so that
2773 # any patches or replacements in $local_gl_dir are applied.
2774 func_gnulib_tool_copy_file ()
2776 $debug_cmd
2778 $require_gnulib_tool
2779 $require_patch
2781 if test true = "$gnulib_tool"; then
2782 # If gnulib-tool is not available (e.g. bootstrapping in a
2783 # distribution tarball), make sure that at least we have some
2784 # version of the required file already in place.
2785 test -f "$2" || func_fatal_error "\
2786 Can't find, copy or download '$2', a required
2787 gnulib supplied file, please provide the location of a
2788 complete 'gnulib' tree by setting 'gnulib_path' in your
2789 'bootstrap.conf' or with the '--gnulib-srcdir' option -
2790 or else specify the location of your 'git' binary by
2791 setting 'GIT' in the environment so that a fresh
2792 'gnulib' submodule can be cloned."
2793 else
2794 $require_gnulib_copy_cmd
2796 $gnulib_copy_cmd $1 $2 2>/dev/null || {
2797 $require_gnulib_path
2799 func_error "'$gnulib_path/$1' does not exist"
2800 return 1
2806 # func_install_gnulib_non_module_files
2807 # ------------------------------------
2808 # Get additional non-module files from gnulib, overriding existing files.
2809 func_install_gnulib_non_module_files ()
2811 $debug_cmd
2813 $require_build_aux
2814 $require_gnulib_tool
2816 test -n "$gnulib_non_module_files" && {
2817 maybe_exit_cmd=:
2819 for file in $gnulib_non_module_files; do
2820 case $file in
2821 */COPYING*) dest=COPYING;;
2822 */INSTALL) dest=INSTALL;;
2823 build-aux/missing) dest=
2824 func_warning settings "\
2825 Please remove build-aux/missing from gnulib_module_files in
2826 'bootstrap.conf', as it may clash with Automake's version."
2828 build-aux/*) dest=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
2829 *) dest=$file;;
2830 esac
2832 # Be sure to show all copying errors before bailing out
2833 test -z "$dest" \
2834 || func_gnulib_tool_copy_file "$file" "$dest" \
2835 || maybe_exit_cmd="exit $EXIT_FAILURE"
2836 done
2838 $maybe_exit_cmd
2843 # func_ensure_changelog
2844 # ---------------------
2845 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
2846 # will not run to completion with no ChangeLog file.
2847 func_ensure_changelog ()
2849 $debug_cmd
2851 test -f ChangeLog && mv -f ChangeLog ChangeLog~
2853 cat >ChangeLog <<'EOT'
2854 ## ---------------------- ##
2855 ## DO NOT EDIT THIS FILE! ##
2856 ## ---------------------- ##
2858 ChangeLog is generated by gitlog-to-changelog.
2861 _G_message="creating dummy 'ChangeLog'"
2862 test -f ChangeLog~ \
2863 && func_append _G_message ' (backup in ChangeLog~)'
2864 func_verbose "$_G_message"
2866 return 0
2870 # func_autoreconf
2871 # ---------------
2872 # Being careful not to re-run 'autopoint' or 'libtoolize', and not to
2873 # try to run 'autopoint', 'libtoolize' or 'autoheader' on packages that
2874 # don't use them, defer to 'autoreconf' for execution of the remaining
2875 # autotools to bootstrap this package.
2876 func_autoreconf ()
2878 $debug_cmd
2880 $require_autoheader
2881 $require_build_aux # automake and others put files in here
2882 $require_macro_dir # aclocal and others put files in here
2884 # We ran these manually already, and autoreconf won't exec ':'
2885 save_AUTOPOINT=$AUTOPOINT; AUTOPOINT=true
2886 save_LIBTOOLIZE=$LIBTOOLIZE; LIBTOOLIZE=true
2888 _G_autoreconf_options=
2889 $opt_copy || func_append _G_autoreconf_options " --symlink"
2890 $opt_force && func_append _G_autoreconf_options " --force"
2891 $opt_verbose && func_append _G_autoreconf_options " --verbose"
2892 func_show_eval "$AUTORECONF$_G_autoreconf_options --install" 'exit $?'
2894 AUTOPOINT=$save_AUTOPOINT
2895 LIBTOOLIZE=$save_LIBTOOLIZE
2899 # func_check_configuration VARNAME [CONFIGURE_MACRO]
2900 # --------------------------------------------------
2901 # Exit with a suitable diagnostic for an important configuration change
2902 # that needs to be made before bootstrap can run correctly.
2903 func_check_configuration ()
2905 $debug_cmd
2907 $require_configure_ac
2909 eval 'test -n "$'$1'"' || {
2910 _G_error_msg="please set '$1' in 'bootstrap.conf'"
2911 if test -n "$configure_ac" && test -n "$2"; then
2912 func_append _G_error_msg "
2913 or add the following (or similar) to your '$configure_ac':
2917 func_fatal_error "$_G_error_msg"
2922 # func_clean_dangling_symlinks
2923 # ----------------------------
2924 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
2925 # gnulib-populated directories. Such .m4 files would cause aclocal to
2926 # fail. The following requires GNU find 4.2.3 or newer. Considering
2927 # the usual portability constraints of this script, that may seem a very
2928 # demanding requirement, but it should be ok. Ignore any failure,
2929 # which is fine, since this is only a convenience to help developers
2930 # avoid the relatively unusual case where a symlinked-to .m4 file is
2931 # git-removed from gnulib between successive runs of this script.
2932 func_clean_dangling_symlinks ()
2934 $debug_cmd
2936 $require_macro_dir
2937 $require_source_base
2939 func_verbose "cleaning dangling symlinks"
2941 find "$macro_dir" "$source_base" \
2942 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
2943 -type l -xtype l -delete > /dev/null 2>&1
2947 # func_clean_unused_macros
2948 # ------------------------
2949 # Autopoint can result in over-zealously adding macros into $macro_dir
2950 # even though they are not actually used, for example tests to help
2951 # build the 'intl' directory even though you have specified
2952 # 'AM_GNU_GETTEXT([external])' in your configure.ac. This function
2953 # looks removes any macro files that can be found in gnulib, but
2954 # are not 'm4_include'd by 'aclocal.m4'.
2955 func_clean_unused_macros ()
2957 $debug_cmd
2959 $require_gnulib_path
2960 $require_macro_dir
2962 test -n "$gnulib_path" && test -f aclocal.m4 && {
2963 aclocal_m4s=`find . -name aclocal.m4 -print`
2965 # We use 'ls|grep' instead of 'ls *.m4' to avoid exceeding
2966 # command line length limits in some shells.
2967 for file in `cd "$macro_dir" && ls -1 |grep '\.m4$'`; do
2969 # Remove a macro file when aclocal.m4 does not m4_include it...
2970 func_grep_q 'm4_include([[]'$macro_dir/$file'])' $aclocal_m4s \
2971 || test ! -f "$gnulib_path/m4/$file" || {
2973 # ...and there is an identical file in gnulib...
2974 if func_cmp_s "$gnulib_path/m4/$file" "$macro_dir/$file"; then
2976 # ...and it's not in the precious list ('echo' is needed
2977 # here to squash whitespace for the match expression).
2978 case " "`echo $gnulib_precious`" " in
2979 *" $file "*) ;;
2980 *) rm -f "$macro_dir/$file"
2981 func_verbose \
2982 "removing unused gnulib file '$macro_dir/$file'"
2983 esac
2986 done
2991 # func_skip_po_recommendation
2992 # ---------------------------
2993 # If there is a po directory, and '--skip-po' wasn't passed, let the
2994 # user know that they can use '--skip-po' on subsequent invocations.
2995 func_skip_po_recommendation ()
2997 $debug_cmd
2999 test ! -d po \
3000 || $opt_skip_po \
3001 || func_warning recommend "\
3002 If your pofiles are up-to-date, you can rerun bootstrap
3003 as '$progname --skip-po' to avoid redownloading."
3007 # func_update_dotversion
3008 # ----------------------
3009 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3010 # will not run to completion with no ChangeLog file.
3011 func_update_dotversion ()
3013 $debug_cmd
3015 test -f "$build_aux/git-version-gen" && {
3016 _G_message="updating .version"
3017 test -f .version && {
3018 mv .version .version~
3019 func_append _G_message " (backup in .version~)"
3021 func_verbose "updating .version"
3023 $build_aux/git-version-gen dummy-arg > .version
3029 ## -------------------- ##
3030 ## Resource management. ##
3031 ## -------------------- ##
3033 # This section contains definitions for functions that each ensure a
3034 # particular resource (a file, or a non-empty configuration variable for
3035 # example) is available, and if appropriate to extract default values
3036 # from pertinent package files. Where a variable already has a non-
3037 # empty value (as set by the package's 'bootstrap.conf'), that value is
3038 # used in preference to deriving the default. Call them using their
3039 # associated 'require_*' variable to ensure that they are executed, at
3040 # most, once.
3043 # require_checkout_only_file
3044 # --------------------------
3045 # Bail out if this package only bootstraps properly from a repository
3046 # checkout.
3047 require_checkout_only_file=func_require_checkout_only_file
3048 func_require_checkout_only_file ()
3050 $debug_cmd
3052 $opt_force || {
3053 test -n "$checkout_only_file" && test ! -f "$checkout_only_file" \
3054 && func_fatal_error "\
3055 Bootstrapping from a non-checked-out distribution is risky.
3056 If you wish to bootstrap anyway, use the '--force' option."
3059 require_checkout_only_file=:
3063 # require_aclocal_amflags
3064 # -----------------------
3065 # Ensure '$aclocal_amflags' has a sensible default, extracted from
3066 # 'Makefile.am' if necessary.
3067 require_aclocal_amflags=func_require_aclocal_amflags
3068 func_require_aclocal_amflags ()
3070 $debug_cmd
3072 $require_makefile_am
3074 _G_sed_extract_aclocal_amflags='s|#.*$||
3075 /^[ ]*ACLOCAL_AMFLAGS[ ]*=/ {
3076 s|^.*=[ ]*\(.*\)|aclocal_amflags="\1"|
3080 _G_aclocal_flags_cmd=`$SED -n "$_G_sed_extract_aclocal_amflags" \
3081 "$makefile_am"`
3082 eval "$_G_aclocal_flags_cmd"
3084 func_verbose "ACLOCAL_AMFLAGS='$aclocal_amflags'"
3086 require_aclocal_amflags=:
3090 # require_autoheader
3091 # ------------------
3092 # Skip autoheader if it's not needed.
3093 require_autoheader=func_require_autoheader
3094 func_require_autoheader ()
3096 $debug_cmd
3098 test true = "$AUTOHEADER" || {
3099 func_extract_trace AC_CONFIG_HEADERS
3100 test -n "$func_extract_trace_result" \
3101 || func_extract_trace AC_CONFIG_HEADER
3103 test -n "$func_extract_trace_result" || {
3104 AUTOHEADER=true
3106 func_verbose "export AUTOHEADER='$AUTOHEADER'"
3108 # Make sure the search result is visible to subshells
3109 export AUTOHEADER
3113 require_autoheader=:
3117 # require_autopoint
3118 # -----------------
3119 # Skip autopoint if it's not needed.
3120 require_autopoint=func_require_autopoint
3121 func_require_autopoint ()
3123 $debug_cmd
3125 test true = "$AUTOPOINT" || {
3126 func_extract_trace AM_GNU_GETTEXT_VERSION
3128 test -n "$func_extract_trace_result" || {
3129 AUTOPOINT=true
3131 func_verbose "export AUTOPOINT='$AUTOPOINT'"
3133 # Make sure the search result is visible to subshells
3134 export AUTOPOINT
3138 require_autopoint=:
3142 # require_bootstrap_uptodate
3143 # --------------------------
3144 # Complain if the version of bootstrap in the gnulib directory differs
3145 # from the one we are running.
3146 require_bootstrap_uptodate=func_require_bootstrap_uptodate
3147 func_require_bootstrap_uptodate ()
3149 $debug_cmd
3151 $require_build_aux
3153 _G_bootstrap_sources="
3154 $build_aux/bootstrap.in
3155 $build_aux/extract-trace
3156 $build_aux/funclib.sh
3157 $build_aux/options-parser
3160 _G_missing_bootstrap_sources=false
3161 for _G_src in $_G_bootstrap_sources; do
3162 test -f "$_G_src" || _G_missing_bootstrap_sources=:
3163 done
3165 if $_G_missing_bootstrap_sources; then
3166 func_warning upgrade "\
3167 Please add bootstrap to your gnulib_modules list in
3168 'bootstrap.conf', so that I can tell you when there are
3169 updates available."
3170 else
3171 $build_aux/inline-source $build_aux/bootstrap.in > bootstrap.new
3173 if func_cmp_s "$progpath" bootstrap.new; then
3174 rm -f bootstrap.new
3175 func_verbose "bootstrap script up to date"
3176 else
3177 func_warning upgrade "\
3178 An updated bootstrap script has been generated for you in
3179 'bootstrap.new'. After you've verified that you want
3180 the changes, you can update with:
3181 cat bootstrap.new > $progname
3182 ./$progname
3184 Or you can disable this check permanently by adding the
3185 following to 'bootstrap.conf':
3186 require_bootstrap_uptodate=:"
3190 require_bootstrap_uptodate=:
3194 # require_build_aux
3195 # -----------------
3196 # Ensure that '$build_aux' is set, and if it doesn't already point to an
3197 # existing directory, create one.
3198 require_build_aux=func_require_build_aux
3199 func_require_build_aux ()
3201 $debug_cmd
3203 test -n "$build_aux" || {
3204 func_extract_trace_first AC_CONFIG_AUX_DIR
3205 build_aux=$func_extract_trace_first_result
3206 func_check_configuration build_aux \
3207 "AC_CONFIG_AUX_DIR([name of a directory for build scripts])"
3209 func_verbose "build_aux='$build_aux'"
3212 $require_vc_ignore_files
3214 # If the build_aux directory doesn't exist, create it now, and mark it
3215 # as ignored for the VCS.
3216 if test ! -d "$build_aux"; then
3217 func_show_eval "mkdir '$build_aux'"
3219 test -n "$vc_ignore_files" \
3220 || func_insert_if_absent "$build_aux" $vc_ignore_files
3223 require_build_aux=:
3227 # require_buildreq_autobuild
3228 # --------------------------
3229 # Try to find whether the bootstrap requires autobuild.
3230 require_buildreq_autobuild=func_require_buildreq_autobuild
3231 func_require_buildreq_autobuild ()
3233 $debug_cmd
3235 $require_macro_dir
3237 test -f "$macro_dir/autobuild.m4" \
3238 || printf '%s\n' "$buildreq" |func_grep_q '^[ ]*autobuild' \
3239 || {
3240 func_extract_trace AB_INIT
3241 test -n "$func_extract_trace_result" && {
3242 func_append buildreq 'autobuild - http://josefsson.org/autobuild/
3244 func_verbose "auto-adding 'autobuild' to build requirements"
3248 require_buildreq_autobuild=:
3252 # require_buildreq_autoconf
3253 # require_buildreq_autopoint
3254 # require_buildreq_libtoolize
3255 # ---------------------------
3256 # Try to find the minimum compatible version of autoconf/libtool
3257 # required to bootstrap successfully, and add it to '$buildreq'.
3258 for tool in autoconf libtoolize autopoint; do
3259 b=$tool
3260 v=require_buildreq_${tool}
3261 f=func_$v
3262 case $tool in
3263 autoconf) m=AC_PREREQ ;;
3264 libtoolize) m=LT_PREREQ; b=libtool ;;
3265 autopoint) m=AM_GNU_GETTEXT_VERSION b=gettext ;;
3266 esac
3268 eval $v'='$f'
3269 '$f' ()
3271 $debug_cmd
3273 # The following is ignored if undefined, but might be necessary
3274 # in order for `func_find_tool` to run.
3275 ${require_'$tool'-:}
3277 printf '\''%s\n'\'' "$buildreq" |func_grep_q '\''^[ ]*'$tool\'' || {
3278 func_extract_trace '$m'
3279 _G_version=$func_extract_trace_result
3280 test -n "$_G_version" && {
3281 func_append buildreq "\
3282 '$tool' $_G_version http://www.gnu.org/s/'$b'
3284 func_verbose \
3285 "auto-adding '\'$tool'-'$_G_version\'' to build requirements"
3289 '$v'=:
3292 done
3295 # require_buildreq_automake
3296 # -------------------------
3297 # Try to find the minimum compatible version of automake required to
3298 # bootstrap successfully, and add it to '$buildreq'.
3299 require_buildreq_automake=func_require_buildreq_automake
3300 func_require_buildreq_automake ()
3302 $debug_cmd
3304 # if automake is not already listed in $buildreq...
3305 printf '%s\n' "$buildreq" |func_grep_q automake || {
3306 func_extract_trace AM_INIT_AUTOMAKE
3308 # ...and AM_INIT_AUTOMAKE is declared...
3309 test -n "$func_extract_trace_result" && {
3310 automake_version=`$bs_echo "$func_extract_trace_result" \
3311 |$SED -e 's|[^0-9]*||' -e 's| .*$||'`
3312 test -n "$automake_version" || automake_version=-
3314 func_append buildreq "\
3315 automake $automake_version http://www.gnu.org/s/automake
3317 func_verbose \
3318 "auto-adding 'automake-$automake_version' to build requirements"
3322 require_buildreq_automake=:
3326 # require_buildreq_patch
3327 # ----------------------
3328 # Automatically add a patch build-requirement if there are diff files
3329 # in $local_gl_dir.
3330 require_buildreq_patch=func_require_buildreq_patch
3331 func_require_buildreq_patch ()
3333 $debug_cmd
3335 $require_local_gl_dir
3337 # This ensures PATCH is set appropriately by the time
3338 # func_check_versions enforces $buildreq.
3339 $require_patch
3341 # If patch is not already listed in $buildreq...
3342 printf '%s\n' "$buildreq" |func_grep_q '^[ ]*patch' || {
3343 # The ugly find invocation is necessary to exit with non-zero
3344 # status for old find binaries that don't support -exec fully.
3345 if test ! -d "$local_gl_dir" \
3346 || find "$local_gl_dir" -name *.diff -exec false {} \; ; then :
3347 else
3348 func_append buildreq 'patch - http://www.gnu.org/s/patch
3353 require_buildreq_patch=:
3357 # require_buildtools_uptodate
3358 # ---------------------------
3359 # Ensure all the packages listed in BUILDREQS are available on the build
3360 # machine at the minimum versions or better.
3361 require_buildtools_uptodate=func_require_buildtools_uptodate
3362 func_require_buildtools_uptodate ()
3364 $debug_cmd
3366 $require_buildreq_autobuild
3367 $require_buildreq_autoconf
3368 $require_buildreq_automake
3369 $require_buildreq_libtoolize
3370 $require_buildreq_autopoint
3371 $require_buildreq_patch
3373 test -n "$buildreq" && {
3374 _G_error_hdr=
3376 func_check_versions $buildreq
3377 $func_check_versions_result || {
3378 test -n "$buildreq_readme" \
3379 && test -f "$buildreq_readme" \
3380 && _G_error_hdr="\
3381 $buildreq_readme explains how to obtain these prerequisite programs:
3383 func_strtable 0 11 12 36 \
3384 "Program" "Min_version" "Homepage" $buildreq
3385 func_fatal_error "$_G_error_hdr$func_strtable_result"
3389 require_buildtools_uptodate=:
3393 # require_copyright_holder
3394 # ------------------------
3395 # Ensure there is a sensible non-empty default value in '$copyright_holder'.
3396 require_copyright_holder=func_require_copyright_holder
3397 func_require_copyright_holder ()
3399 $debug_cmd
3401 test -n "$copyright_holder" || {
3402 copyright_holder='Free Software Foundation, Inc.'
3403 func_warning settings "\
3404 Please set copyright_holder explicitly in 'bootstrap.conf';
3405 defaulting to '$copyright_holder'."
3408 require_copyright_holder=:
3412 # require_doc_base
3413 # ----------------
3414 # Ensure doc_base has a sensible value, extracted from 'gnulib-cache.m4'
3415 # if possible, otherwise letting 'gnulib-tool' pick a default.
3416 require_doc_base=func_require_doc_base
3417 func_require_doc_base ()
3419 $debug_cmd
3421 $require_gnulib_cache
3423 test -f "$gnulib_cache" && test -z "$doc_base" && {
3424 func_extract_trace_first "gl_DOC_BASE" "$gnulib_cache"
3425 doc_base=$func_extract_trace_first_result
3427 test -n "$doc_base" && func_verbose "doc_base='$doc_base'"
3430 require_doc_base=:
3434 # require_dotgitmodules
3435 # ---------------------
3436 # Ensure we have a '.gitmodules' file, with appropriate 'gnulib' settings.
3437 require_dotgitmodules=func_require_dotgitmodules
3438 func_require_dotgitmodules ()
3440 $debug_cmd
3442 $require_git
3444 test true = "$GIT" || {
3445 # A gnulib entry in .gitmodules always takes precedence.
3446 _G_path=`$GIT config --file .gitmodules submodule.gnulib.path 2>/dev/null`
3448 test -n "$_G_path" || {
3449 $require_vc_ignore_files
3451 func_verbose "creating '.gitmodules'"
3453 # If the .gitmodules file doesn't exist, create it now, and mark
3454 # it as ignored for the VCS.
3455 test -n "$gnulib_path" || gnulib_path=gnulib
3456 test -n "$gnulib_url" || gnulib_url=git://git.sv.gnu.org/gnulib
3459 echo '[submodule "gnulib"]'
3460 echo " path = $gnulib_path"
3461 echo " url = $gnulib_url"
3462 } >> .gitmodules
3464 test -n "$vc_ignore_files" \
3465 || func_insert_if_absent ".gitmodules" $vc_ignore_files
3469 require_dotgitmodules=:
3473 # require_extra_locale_categories
3474 # -------------------------------
3475 # Ensure there is a default value in '$extra_locale_categories'
3476 require_extra_locale_categories=func_require_extra_locale_categories
3477 func_require_extra_locale_categories ()
3479 $debug_cmd
3481 # Defaults to empty, so run with whatever value may have been set in
3482 # 'bootstrap.conf'.
3483 require_extra_locale_categories=:
3487 # require_git
3488 # -----------
3489 # Ignore git if it's not available, or we're not in a git checkout tree.
3490 require_git=func_require_git
3491 func_require_git ()
3493 $debug_cmd
3495 $opt_skip_git && GIT=true
3497 test true = "$GIT" || {
3498 if test -f .gitignore && ($GIT --version) >/dev/null 2>&1; then :; else
3499 GIT=true
3503 func_verbose "GIT='$GIT'"
3505 require_git=:
3509 # require_gnulib_cache
3510 # --------------------
3511 # Ensure there is a non-empty default for '$gnulib_cache', and that it
3512 # names an existing file.
3513 require_gnulib_cache=func_require_gnulib_cache
3514 func_require_gnulib_cache ()
3516 $debug_cmd
3518 $require_macro_dir
3520 test -n "$gnulib_cache" \
3521 || gnulib_cache=$macro_dir/gnulib-cache.m4
3523 func_verbose "found '$gnulib_cache'"
3525 require_gnulib_cache=:
3529 # require_gnulib_copy_cmd
3530 # -----------------------
3531 # Only calculate the options for copying files with gnulib once.
3532 require_gnulib_copy_cmd=func_require_gnulib_copy_cmd
3533 func_require_gnulib_copy_cmd ()
3535 $debug_cmd
3537 $require_gnulib_tool
3538 $require_gnulib_tool_base_options
3540 gnulib_copy_cmd="$gnulib_tool $gnulib_tool_base_options --copy-file"
3541 $opt_copy || func_append gnulib_copy_cmd " --symlink"
3542 $opt_quiet || func_append gnulib_copy_cmd " --verbose"
3544 require_gnulib_copy_cmd=:
3548 # require_gnulib_merge_changelog
3549 # ------------------------------
3550 # See if we can use gnulib's git-merge-changelog merge driver.
3551 require_gnulib_merge_changelog=func_require_gnulib_merge_changelog
3552 func_require_gnulib_merge_changelog ()
3554 $debug_cmd
3556 test -f ChangeLog && {
3557 $require_git
3559 func_grep_q '^\(/\|\)ChangeLog$' .gitignore || test true = "$GIT" || {
3560 if $GIT config merge.merge-changelog.driver >/dev/null; then
3562 elif (git-merge-changelog --version) >/dev/null 2>&1; then
3563 func_echo "initializing git-merge-changelog driver"
3564 $GIT config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
3565 $GIT config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
3566 else
3567 func_warning recommend \
3568 "Consider installing git-merge-changelog from gnulib."
3573 require_gnulib_merge_changelog=:
3577 # require_gnulib_mk
3578 # -----------------
3579 # Ensure gnulib_mk has a sensible value, extracted from 'gnulib-cache.m4'
3580 # if possible, otherwise letting 'gnulib-tool' pick a default.
3581 require_gnulib_mk=func_require_gnulib_mk
3582 func_require_gnulib_mk ()
3584 $debug_cmd
3586 $require_gnulib_cache
3588 test -f "$gnulib_cache" && test -z "$gnulib_mk" && {
3589 func_extract_trace_first "gl_MAKEFILE_NAME" "$gnulib_cache"
3590 gnulib_mk=$func_extract_trace_first_result
3592 test -n "$gnulib_mk" && func_verbose "gnulib_mk='$gnulib_mk'"
3595 require_gnulib_mk=:
3599 # require_gnulib_name
3600 # -------------------
3601 # Ensure gnulib_name has a sensible value, extracted from 'gnulib-cache.m4'
3602 # if possible, otherwise letting 'gnulib-tool' pick a default.
3603 require_gnulib_name=func_require_gnulib_name
3604 func_require_gnulib_name ()
3606 $debug_cmd
3608 $require_gnulib_cache
3610 test -f "$gnulib_cache" && test -z "$gnulib_name" && {
3611 func_extract_trace_first "gl_LIB" "$gnulib_cache"
3612 gnulib_name=$func_extract_trace_first_result
3614 test -n "$gnulib_name" && func_verbose "gnulib_name='$gnulib_name'"
3617 require_gnulib_name=:
3621 # require_gnulib_path
3622 # require_gnulib_url
3623 # -------------------
3624 # Ensure 'gnulib_path' and 'gnulib_url' are set.
3625 require_gnulib_path=func_require_dotgitmodules_parameters
3626 require_gnulib_url=func_require_dotgitmodules_parameters
3627 func_require_dotgitmodules_parameters ()
3629 $debug_cmd
3631 $require_git
3633 test true = "$GIT" && {
3634 # If we can't find git (or if the user specified '--skip-git'),
3635 # then use an existing gnulib directory specified with
3636 # '--gnulib-srcdir' if possible.
3637 test -n "$gnulib_path" \
3638 || test ! -x "$opt_gnulib_srcdir/gnulib-tool" \
3639 || gnulib_path=$opt_gnulib_srcdir
3643 $require_dotgitmodules
3645 test -f .gitmodules && {
3646 # Extract the parameters with sed, since git may be missing
3647 test -n "$gnulib_path" \
3648 || gnulib_path=`$SED -e '/^.submodule "gnulib".$/,${
3649 /[ ]*path *= */{
3650 s|[ ]*||g;s|^[^=]*=||;p
3653 d' .gitmodules |$SED 1q`
3654 test -n "$gnulib_url" \
3655 || gnulib_url=`$SED -e '/^.submodule "gnulib".$/,${
3656 /[ ]*url *= */{
3657 s|[ ]*||g;s|^[^=]*=||;p
3660 d' .gitmodules |$SED 1q`
3662 func_verbose "gnulib_path='$gnulib_path'"
3663 func_verbose "gnulib_url='$gnulib_url'"
3666 require_gnulib_path=:
3667 require_gnulib_url=:
3671 # require_gnulib_submodule
3672 # ------------------------
3673 # Ensure that there is a current gnulib submodule at '$gnulib_path'.
3674 require_gnulib_submodule=func_require_gnulib_submodule
3675 func_require_gnulib_submodule ()
3677 $debug_cmd
3679 $require_git
3681 if test true = "$GIT"; then
3682 func_warning recommend \
3683 "No 'git' found; imported gnulib modules may be outdated."
3684 else
3685 $require_gnulib_path
3686 $require_gnulib_url
3688 if test -f .gitmodules && test -f "$gnulib_path/gnulib-tool"; then
3689 : All present and correct.
3691 elif test -n "$opt_gnulib_srcdir"; then
3692 # Older git can't clone into an empty directory.
3693 rmdir "$gnulib_path" 2>/dev/null
3694 func_show_eval "$GIT clone --reference '$opt_gnulib_srcdir' \
3695 '$gnulib_url' '$gnulib_path'" \
3696 || func_fatal_error "Unable to fetch gnulib submodule."
3698 # Without --gnulib-srcdir, and no existing checked out submodule, we
3699 # create a new shallow clone of the remote gnulib repository.
3700 else
3701 trap func_cleanup_gnulib 1 2 13 15
3703 shallow=
3704 $GIT clone -h 2>&1 |func_grep_q -- --depth \
3705 && shallow='--depth 365'
3707 func_show_eval "$GIT clone $shallow '$gnulib_url' '$gnulib_path'" \
3708 func_cleanup_gnulib
3710 # FIXME: Solaris /bin/sh will try to execute '-' if any of
3711 # these signals are caught after this.
3712 trap - 1 2 13 15
3715 # Make sure we've checked out the correct revision of gnulib.
3716 func_show_eval "$GIT submodule init" \
3717 && func_show_eval "$GIT submodule update" \
3718 || func_fatal_error "Unable to update gnulib submodule."
3721 require_gnulib_submodule=:
3725 # require_gnulib_tool
3726 # -------------------
3727 # Ensure that '$gnulib_tool' is set, and points to an executable file,
3728 # or else fall back to using the binary 'true' if the main gnulib
3729 # files appear to have been imported already.
3730 require_gnulib_tool=func_require_gnulib_tool
3731 func_require_gnulib_tool ()
3733 $debug_cmd
3735 test true = "$gnulib_tool" || {
3736 $require_gnulib_submodule
3737 $require_gnulib_path
3739 test -n "$gnulib_tool" \
3740 || gnulib_tool=$gnulib_path/gnulib-tool
3742 test -x "$gnulib_tool" || {
3743 gnulib_tool=true
3744 func_warning recommend \
3745 "No 'gnulib-tool' found; gnulib modules may be missing."
3748 test true = "$gnulib_tool" \
3749 || func_verbose "found '$gnulib_tool'"
3752 require_gnulib_tool=:
3756 # require_gnulib_tool_base_options
3757 # --------------------------------
3758 # Ensure that '$gnulib_tool_base_options' contains all the base options
3759 # required according to user configuration from bootstrap.conf.
3760 require_gnulib_tool_base_options=func_require_gnulib_tool_base_options
3761 func_require_gnulib_tool_base_options ()
3763 $debug_cmd
3765 $require_gnulib_tool
3767 gnulib_tool_base_options=
3769 test true = "$gnulib_tool" || {
3770 # 'gnulib_modules' and others are maintained in 'bootstrap.conf':
3771 # Use 'gnulib --import' to fetch gnulib modules.
3772 $require_build_aux
3773 test -n "$build_aux" \
3774 && func_append_uniq gnulib_tool_base_options " --aux-dir=$build_aux"
3775 $require_macro_dir
3776 test -n "$macro_dir" \
3777 && func_append_uniq gnulib_tool_base_options " --m4-base=$macro_dir"
3778 $require_doc_base
3779 test -n "$doc_base" \
3780 && func_append_uniq gnulib_tool_base_options " --doc-base=$doc_base"
3781 $require_gnulib_name
3782 test -n "$gnulib_name" \
3783 && func_append_uniq gnulib_tool_base_options " --lib=$gnulib_name"
3784 $require_local_gl_dir
3785 test -n "$local_gl_dir" \
3786 && func_append_uniq gnulib_tool_base_options " --local-dir=$local_gl_dir"
3787 $require_source_base
3788 test -n "$source_base" \
3789 && func_append_uniq gnulib_tool_base_options " --source-base=$source_base"
3792 require_gnulib_tool_base_options=:
3796 # require_libtoolize
3797 # ------------------
3798 # Skip libtoolize if it's not needed.
3799 require_libtoolize=func_require_libtoolize
3800 func_require_libtoolize ()
3802 $debug_cmd
3804 # Unless we're not searching for libtool use by this package, set
3805 # LIBTOOLIZE to true if none of 'LT_INIT', 'AC_PROG_LIBTOOL' and
3806 # 'AM_PROG_LIBTOOL' are used in configure.
3807 test true = "$LIBTOOLIZE" || {
3808 func_extract_trace LT_INIT
3809 test -n "$func_extract_trace_result" || func_extract_trace AC_PROG_LIBTOOL
3810 test -n "$func_extract_trace_result" || func_extract_trace AM_PROG_LIBTOOL
3811 test -n "$func_extract_trace_result" || LIBTOOLIZE=true
3814 test -n "$LIBTOOLIZE" || {
3815 # Find libtoolize, named glibtoolize in Mac Ports, but prefer
3816 # user-installed libtoolize to ancient glibtoolize shipped by
3817 # Apple with Mac OS X when Mac Ports is not installed.
3818 func_find_tool LIBTOOLIZE libtoolize glibtoolize
3821 func_verbose "export LIBTOOLIZE='$LIBTOOLIZE'"
3823 # Make sure the search result is visible to subshells
3824 export LIBTOOLIZE
3826 require_libtoolize=:
3830 # require_local_gl_dir
3831 # --------------------
3832 # Ensure local_gl_dir has a sensible value, extracted from 'gnulib-cache.m4'
3833 # if possible, otherwise letting 'gnulib-tool' pick a default.
3834 require_local_gl_dir=func_require_local_gl_dir
3835 func_require_local_gl_dir ()
3837 $debug_cmd
3839 $require_gnulib_cache
3841 test -f "$gnulib_cache" && test -z "$local_gl_dir" && {
3842 func_extract_trace_first "gl_LOCAL_DIR" "$gnulib_cache"
3843 local_gl_dir=$func_extract_trace_first_result
3845 test -n "$local_gl_dir" && func_verbose "local_gl_dir='$local_gl_dir'"
3848 require_local_gl_dir=:
3852 # require_macro_dir
3853 # -----------------
3854 # Ensure that '$macro_dir' is set, and if it doesn't already point to an
3855 # existing directory, create one.
3856 require_macro_dir=func_require_macro_dir
3857 func_require_macro_dir ()
3859 $debug_cmd
3861 # Sometimes this is stored in 'configure.ac'.
3862 test -n "$macro_dir" || {
3863 # AC_CONFIG_MACRO_DIRS takes a space delimited list of directories,
3864 # but we only care about the first one in bootstrap.
3865 func_extract_trace_first AC_CONFIG_MACRO_DIRS
3866 macro_dir=`expr "x$func_extract_trace_first_result" : 'x\([^ ]*\)'`
3868 test -n "$macro_dir" || {
3869 func_extract_trace_first AC_CONFIG_MACRO_DIR
3870 macro_dir=$func_extract_trace_first_result
3873 # Otherwise we might find it in 'Makefile.am'.
3874 test -n "$macro_dir" || {
3875 $require_aclocal_amflags
3877 # Take the argument following the first '-I', if any.
3878 _G_minus_I_seen=false
3879 for _G_arg in $aclocal_amflags; do
3880 case $_G_minus_I_seen,$_G_arg in
3881 :,*) macro_dir=$_G_arg; break ;;
3882 *,-I) _G_minus_I_seen=: ;;
3883 *,-I*) macro_dir=`expr x$_G_arg : 'x-I\(.*\)$'`; break ;;
3884 esac
3885 done
3888 func_verbose "macro_dir='$macro_dir'"
3890 func_check_configuration macro_dir \
3891 "AC_CONFIG_MACRO_DIRS([name of a directory for configure m4 files])"
3893 $require_vc_ignore_files
3895 # If the macro_dir directory doesn't exist, create it now, and mark it
3896 # as ignored for the VCS.
3897 if test ! -d "$macro_dir"; then
3898 mkdir "$macro_dir" || func_permissions_error "$macro_dir"
3900 test -n "$vc_ignore_files" \
3901 || func_insert_if_absent "$macro_dir" $vc_ignore_files
3904 require_macro_dir=:
3908 # require_makefile_am
3909 # -------------------
3910 # Ensure there is a 'Makefile.am' in the current directory.
3911 # names an existing file.
3912 require_makefile_am=func_require_makefile_am
3913 func_require_makefile_am ()
3915 $debug_cmd
3917 test -n "$makefile_am" \
3918 || makefile_am=Makefile.am
3920 <"$makefile_am"
3922 func_verbose "found '$makefile_am'"
3924 require_makefile_am=:
3928 # require_package
3929 # ---------------
3930 # Ensure that '$package' contains a sensible default value.
3931 require_package=func_require_package
3932 func_require_package ()
3934 $debug_cmd
3936 test -n "$package" || {
3937 $require_package_name
3939 package=`echo "$package_name" \
3940 |$SED -e 's/GNU //' \
3941 -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
3944 func_verbose "package='$package'"
3946 require_package=:
3950 # require_package_bugreport
3951 # -------------------------
3952 # Ensure that this has a sensible value, extracted from 'configure.ac'
3953 # if appropriate (and possible!).
3954 require_package_bugreport=func_require_package_bugreport
3955 func_require_package_bugreport ()
3957 $debug_cmd
3959 func_extract_trace AC_INIT
3961 save_ifs=$IFS
3962 IFS=:
3963 set dummy $func_extract_trace_result
3964 IFS=$save_ifs
3965 shift
3967 test -n "$package_bugreport" || package_bugreport=$3
3968 func_check_configuration package_bugreport \
3969 "AC_INIT([$package_name], [$package_version], [bug-$package@gnu.org])"
3970 func_verbose "package_bugreport='$package_bugreport'"
3972 require_package_bugreport=:
3976 # require_package_name
3977 # --------------------
3978 # Ensure that this has a sensible value, extracted from 'configure.ac'
3979 # if appropriate (and possible!).
3980 require_package_name=func_require_package_name
3981 func_require_package_name ()
3983 $debug_cmd
3985 func_extract_trace AC_INIT
3987 save_ifs=$IFS
3988 IFS=:
3989 set dummy $func_extract_trace_result
3990 IFS=$save_ifs
3991 shift
3993 test -n "$package_name" || package_name=$1
3994 func_check_configuration package_name \
3995 "AC_INIT([name of your package], [package version number])"
3996 func_verbose "package_name='$package_name'"
3998 require_package_name=:
4002 # require_package_version
4003 # -----------------------
4004 # Ensure that this has a sensible value, extracted from 'configure.ac'
4005 # if appropriate (and possible!). While we might have set all the
4006 # parameters extracted from AC_INIT at once, 'package_version' in
4007 # particular is not necessarily available as early as the others, since
4008 # 'git-version-gen' is often involved, and until then we can't rely on
4009 # getting a correct version number from an AC_INIT extraction.
4010 require_package_version=func_require_package_version
4011 func_require_package_version ()
4013 $debug_cmd
4015 func_extract_trace AC_INIT
4017 save_ifs=$IFS
4018 IFS=:
4019 set dummy $func_extract_trace_result
4020 IFS=$save_ifs
4021 shift
4023 test -n "$package_version" || package_version=$2
4024 test -n "$package_version" || {
4025 # The embedded echo is to squash whitespace before globbing.
4026 case " "`echo $gnulib_modules`" " in
4027 *" git-version-gen "*)
4028 func_fatal_error "\
4029 cannot \$require_package_version in bootstrap.conf before
4030 func_gnulib_tool has installed the 'git-version-gen' script."
4033 func_check_configuration package_version \
4034 "AC_INIT([name of your package], [package version number])"
4036 esac
4038 func_verbose "package_version='$package_version'"
4040 require_package_version=:
4044 # require_patch
4045 # -------------
4046 # Find patch, according to the PATCH environment variable, or else
4047 # searching the user's PATH.
4048 require_patch=func_require_patch
4049 func_require_patch ()
4051 $debug_cmd
4053 test -n "$PATCH" || {
4054 # Find a patch program, preferring gpatch, which is usually better
4055 # than the vendor patch.
4056 func_find_tool PATCH gpatch patch
4059 func_verbose "export PATCH='$PATCH'"
4061 # Make sure the search result is visible to subshells
4062 export PATCH
4064 require_patch=:
4068 # require_source_base
4069 # -------------------
4070 # Ensure that source_base has a sensible value, extracted from
4071 # 'gnulib-cache.m4' if possible.
4072 require_source_base=func_require_source_base
4073 func_require_source_base ()
4075 $debug_cmd
4077 $require_gnulib_cache
4079 test -f "$gnulib_cache" && test -z "$source_base" && {
4080 func_extract_trace_first "gl_SOURCE_BASE" "$gnulib_cache"
4082 source_base=$func_extract_trace_first_result
4084 func_verbose "source_base='$source_base'"
4087 require_source_base=:
4091 # require_vc_ignore_files
4092 # -----------------------
4093 # Ensure that '$vc_ignore' has been processed to list VCS ignore files
4094 # in '$vc_ignore_files'
4095 require_vc_ignore_files=func_require_vc_ignore_files
4096 func_require_vc_ignore_files ()
4098 $debug_cmd
4100 test -n "$vc_ignore" || vc_ignore=auto
4102 if test auto = "$vc_ignore" && test -z "$vc_ignore_files"; then
4103 vc_ignore_files=
4104 test -d .git && vc_ignore_files=.gitignore
4105 test -d CVS && vc_ignore_files="$vc_ignore_files .cvsignore"
4106 else
4107 vc_ignore_files=$vc_ignore
4110 func_verbose "vc_ignore_files='$vc_ignore_files'"
4112 require_vc_ignore_files=:
4116 ## ------------------##
4117 ## Helper functions. ##
4118 ## ------------------##
4120 # This section contains the helper functions used by the rest of 'bootstrap'.
4122 # func_len STRING
4123 # ---------------
4124 # STRING may not start with a hyphen.
4125 if (eval 'x=123; test x${#x} = "x3"') 2>/dev/null
4126 then
4127 # This is an XSI compatible shell, allowing a faster implementation...
4128 eval 'func_len ()
4130 $debug_cmd
4132 func_len_result=${#1}
4134 else
4135 # ...otherwise fall back to using expr, which is often a shell builtin.
4136 func_len ()
4138 $debug_cmd
4140 func_len_result=`expr "$1" : ".*" 2>/dev/null || echo 0`
4145 # func_unset VAR
4146 # --------------
4147 # Portably unset VAR.
4148 # In some shells, an 'unset VAR' statement leaves a non-zero return
4149 # status if VAR is already unset, which might be problematic if the
4150 # statement is used at the end of a function (thus poisoning its return
4151 # value) or when 'set -e' is active (causing even a spurious abort of
4152 # the script in this case).
4153 func_unset ()
4155 { eval $1=; unset $1; }
4157 unset=func_unset
4160 # func_cmp_s FILE1 FILE2
4161 # ----------------------
4162 # Return non-zero exit status unless FILE1 and FILE2 are identical, without
4163 # any output at all, even error messages.
4164 func_cmp_s ()
4166 $debug_cmd
4168 # This function relies on non-zero exit status, which will cause the
4169 # program to exit when running in 'set -e' mode.
4170 $CMP "$@" >/dev/null 2>&1
4174 # func_grep_q EXPRESSION [FILENAME..]
4175 # -----------------------------------
4176 # Check whether EXPRESSION matches any line of any listed FILENAME,
4177 # without any output at all, even error messages.
4178 func_grep_q ()
4180 $debug_cmd
4182 # This function relies on non-zero exit status, which will cause the
4183 # program to exit when running in 'set -e' mode.
4184 $GREP "$@" >/dev/null 2>&1
4188 # func_ifcontains LIST MEMBER YES-CMD [NO-CMD]
4189 # --------------------------------------------
4190 # If whitespace-separated LIST contains MEMBER then execute YES-CMD,
4191 # otherwise if NO-CMD was give, execute that.
4192 func_ifcontains ()
4194 $debug_cmd
4196 # The embedded echo is to squash whitespace before globbing.
4197 _G_wslist=`$bs_echo " "$1" "`
4198 _G_member=$2
4199 _G_yes_cmd=$3
4200 _G_no_cmd=${4-":"}
4202 case $_G_wslist in
4203 *" $_G_member "*)
4204 eval "$_G_yes_cmd"
4205 _G_status=$?
4208 eval "$_G_no_cmd"
4209 _G_status=$?
4211 esac
4213 test 0 -eq "$_G_status" || exit $_G_status
4217 # func_strpad STR WIDTH CHAR
4218 # --------------------------
4219 # Trim STR, or pad with CHAR to force a total length of WIDTH.
4220 func_strpad ()
4222 $debug_cmd
4224 _G_width=`expr "$2" - 1`
4225 func_strpad_result=`$bs_echo "$1" |$SED '
4227 s|^.\{0,'"$_G_width"'\}$|&'"$3"'|
4233 # func_strrpad STR WIDTH CHAR
4234 # ---------------------------
4235 # Trim STR, or right-justify-pad with CHAR to force a total length of
4236 # WIDTH.
4237 func_strrpad ()
4239 $debug_cmd
4241 _G_width=`expr "$2" - 1`
4242 func_strrpad_result=`$bs_echo "$1" |$SED '
4244 s|^.\{0,'"$_G_width"'\}$|'"$3"'&|
4250 # func_strrow INDENT FIELD WIDTH [FIELDn WIDTHn]...
4251 # -------------------------------------------------
4252 # Return a string containing each FIELD left justified to WIDTH, with
4253 # the whole thing indented by INDENT spaces. This function is used to
4254 # render one row of aligned columns for a table by func_strtable().
4255 func_strrow ()
4257 $debug_cmd
4259 func_strrow_linelen=$1; shift
4261 _G_row=
4262 while test $# -gt 0; do
4263 func_strrow_linelen=`expr $func_strrow_linelen + $2`
4264 func_strpad "$1" $2 " "
4265 func_append _G_row "$func_strpad_result"
4266 shift; shift
4267 done
4269 func_strrpad "$_G_row" $func_strrow_linelen " "
4270 func_strrow_result=$func_strrpad_result
4274 # func_strtable INDENT WIDTH1...WIDTHn HEADER1...HEADERn FIELD1...FIELDn
4275 # ----------------------------------------------------------------------
4276 # Generate a string of newline-separated rows arranged in lined-up
4277 # columns of the given WIDTHs, with the entire table indented by INDENT
4278 # spaces. The number of columns is determined by the number of integer
4279 # valued WIDTH arguments following INDENT. The next set (i.e. a number
4280 # of arguments equal to the number of WIDTH arguments) of fields are
4281 # treated as the table's column HEADERs, and are separated from the
4282 # remainder of the table by an indented row of '-' characters. Remaining
4283 # arguments are each aligned below the next available header, wrapping
4284 # to a new row as necessary. Finally another row of '-' characters is
4285 # added to mark the end of the table.
4287 # For example an unindented 3 column table with 2 rows of data would be
4288 # generated by this call:
4290 # func_strtable 3 20 10 25 \
4291 # Header1 Header2 Header3 \
4292 # Row1Col1 Row1Col2 Row1Col3 \
4293 # Row2Col1 Row2Col2 Row2Col3
4295 # returning the following string:
4297 # " Header1 Header2 Header3
4298 # -------------------------------------------------------
4299 # Row1Col1 Row1Col2 Row1Col3
4300 # Row2Col1 Row2Col2 Row2Col3
4301 # -------------------------------------------------------"
4302 func_strtable ()
4304 $debug_cmd
4306 # Save the indent value, we'll need it for each row we render.
4307 _G_indent=$1; shift
4309 # Collect remaining numeric args into a list for reuse between
4310 # members of each row when we call func_strrow later.
4311 _G_widths=$1; shift
4312 while test 0 -lt `expr "$1" : '[1-9][0-9]*$'`; do
4313 func_append _G_widths " $1"; shift
4314 done
4316 # Extract the same number of positional parameters as there are
4317 # width elements - we'll do the header rows separately so that
4318 # we can insert a divider line.
4319 _G_header=$_G_indent
4320 for _G_width in $_G_widths; do
4321 func_append _G_header " $1 $_G_width"; shift
4322 done
4323 func_strrow $_G_header
4325 # Strip off the indent, and make a divider with '-' chars, then
4326 # reindent.
4327 _G_divider=`$bs_echo "$func_strrow_result" \
4328 |$SED 's|[^ ]|-|g
4330 s|- |--|g
4334 # Append the header and divider to the running result.
4335 func_append func_strtable_result "\
4336 $func_strrow_result
4337 $_G_divider
4340 # The remaining rows are zipped between the width values we
4341 # unwound earlier just like the header row above.
4342 while test $# -gt 0; do
4343 _G_row=$_G_indent
4344 for _G_width in $_G_widths; do
4345 func_append _G_row " $1 $_G_width"; shift
4346 done
4347 func_strrow $_G_row
4348 func_append func_strtable_result "\
4349 $func_strrow_result
4351 done
4353 # Mark the end of the table with a final divider line.
4354 func_append func_strtable_result "$_G_divider"
4358 # func_internal_error ARG...
4359 # --------------------------
4360 # Echo program name prefixed message to standard error, and exit.
4361 func_internal_error ()
4363 func_fatal_error "\
4364 INTERNAL: " ${1+"$@"} "
4365 Please report this bug to 'bug-gnulib@gnu.org'
4366 in as much detail as possible."
4370 # func_permissions_error FILE-OR-DIRECTORY
4371 # ----------------------------------------
4372 # Echo program name prefixed permissions error message to standard
4373 # error, and exit.
4374 func_permissions_error ()
4376 $debug_cmd
4378 func_fatal_error "Failed to create '$1', check permissions."
4382 # func_show_eval CMD [FAIL_EXP]
4383 # -----------------------------
4384 # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is
4385 # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP
4386 # is given, then evaluate it.
4387 func_show_eval ()
4389 $debug_cmd
4391 $require_term_colors
4393 _G_cmd=$1
4394 _G_fail_exp=${2-':'}
4396 ${opt_silent-'false'} || {
4397 func_quote_for_eval $_G_cmd
4398 eval func_truncate_cmd $func_quote_for_eval_result
4399 func_echo "running: $tc_bold$func_truncate_cmd_result$tc_reset"
4402 ${opt_dry_run-'false'} || {
4403 eval "$_G_cmd"
4404 _G_status=$?
4405 test 0 -eq "$_G_status" || eval "(exit $_G_status); $_G_fail_exp"
4410 # func_truncate_cmd CMD [ARG]...
4411 # ------------------------------
4412 # For unreasonably long commands (such as a gnulib-tool invocation with
4413 # the full module list for import), truncate CMD after the second non-
4414 # option ARG.
4415 func_truncate_cmd ()
4417 $debug_cmd
4419 _G_last_arg_opt_p=false
4420 func_truncate_cmd_result=
4422 set dummy "$@"; shift
4424 while test $# -gt 0; do
4425 _G_opt=$1; shift
4427 test -n "$func_truncate_cmd_result" \
4428 && func_append func_truncate_cmd_result ' '
4429 func_append func_truncate_cmd_result "$_G_opt"
4431 func_len "x$func_truncate_cmd_result"
4433 case $_G_opt in
4434 -*) _G_last_arg_opt_p=: ;;
4435 *) $_G_last_arg_opt_p \
4436 || test "$min_cmd_len" -gt "$func_len_result" \
4437 || break
4438 _G_last_arg_opt_p=false
4440 esac
4441 done
4443 test $# -gt 0 && func_append func_truncate_cmd_result "..."
4447 # func_gitignore_entries FILE...
4448 # ------------------------------
4449 # Strip blank and comment lines to leave significant entries.
4450 func_gitignore_entries ()
4452 $debug_cmd
4454 sed -e '/^#/d' -e '/^$/d' "$@"
4458 # func_insert_if_absent STR FILE...
4459 # ---------------------------------
4460 # If $STR is not already on a line by itself in $FILE, insert it, at the
4461 # start. Entries are inserted at the start of the ignore list to ensure
4462 # existing entries starting with ! are not overridden. Such entries
4463 # support whilelisting exceptions after a more generic blacklist pattern.
4464 # sorting the new contents of the file and replacing $FILE with the result.
4465 func_insert_if_absent ()
4467 $debug_cmd
4469 str=$1
4470 shift
4472 for file
4474 test -f "$file" || touch "$file"
4476 duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
4477 test -n "$duplicate_entries" \
4478 && func_error "duplicate entries in $file: " $duplicate_entries
4480 func_grep_q "^$str\$" "$file" \
4481 || func_verbose "inserting '$str' into '$file'"
4483 linesold=`func_gitignore_entries "$file" |wc -l`
4484 linesnew=`{ $bs_echo "$str"; cat "$file"; } \
4485 |func_gitignore_entries |sort -u |wc -l`
4486 test "$linesold" -eq "$linesnew" \
4487 || { sed "1i\\$nl$str$nl" "$file" >"$file"T && mv "$file"T "$file"; } \
4488 || func_permissions_error "$file"
4489 done
4493 # func_sort_ver VER1 VER2
4494 # -----------------------
4495 # 'sort -V' is not generally available.
4496 # Note this deviates from the version comparison in automake
4497 # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
4498 # but this should suffice as we won't be specifying old
4499 # version formats or redundant trailing .0 in bootstrap.conf.
4500 # If we did want full compatibility then we should probably
4501 # use m4_version_compare from autoconf.
4502 func_sort_ver ()
4504 $debug_cmd
4506 ver1=$1
4507 ver2=$2
4509 # Split on '.' and compare each component.
4511 while :; do
4512 p1=`echo "$ver1" |cut -d. -f$i`
4513 p2=`echo "$ver2" |cut -d. -f$i`
4514 if test ! "$p1"; then
4515 echo "$1 $2"
4516 break
4517 elif test ! "$p2"; then
4518 echo "$2 $1"
4519 break
4520 elif test ! "$p1" = "$p2"; then
4521 if test "$p1" -gt "$p2" 2>/dev/null; then # numeric comparison
4522 echo "$2 $1"
4523 elif test "$p2" -gt "$p1" 2>/dev/null; then # numeric comparison
4524 echo "$1 $2"
4525 else # numeric, then lexicographic comparison
4526 lp=`printf "$p1\n$p2\n" |sort -n |tail -n1`
4527 if test "$lp" = "$p2"; then
4528 echo "$1 $2"
4529 else
4530 echo "$2 $1"
4533 break
4535 i=`expr $i + 1`
4536 done
4540 # func_get_version APP
4541 # --------------------
4542 # echo the version number (if any) of APP, which is looked up along your
4543 # PATH.
4544 func_get_version ()
4546 $debug_cmd
4548 _G_app=$1
4550 # Rather than uncomment the sed script in-situ, strip the comments
4551 # programatically before passing the result to $SED for evaluation.
4552 sed_get_version=`$bs_echo '# extract version within line
4553 s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4554 t done
4556 # extract version at start of line
4557 s|^\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4558 t done
4562 :done
4563 # the following essentially does s|5.005|5.5|
4564 s|\.0*\([1-9]\)|.\1|g
4566 q' \
4567 |$SED '/^[ ]*#.*$/d'`
4569 func_tool_version_output $_G_app >/dev/null
4570 _G_status=$?
4572 test 0 -ne "$_G_status" \
4573 || $_G_app --version 2>&1 |$SED -n "$sed_get_version"
4575 (exit $_G_status)
4579 # func_check_tool APP
4580 # -------------------
4581 # Search PATH for an executable at APP.
4582 func_check_tool ()
4584 $debug_cmd
4586 func_check_tool_result=
4588 case $1 in
4589 *[\\/]*)
4590 test -x "$1" && func_check_tool_result=$1
4593 save_IFS=$IFS
4594 IFS=:
4595 for _G_check_tool_path in $PATH; do
4596 IFS=$save_IFS
4597 if test -x "$_G_check_tool_path/$1"; then
4598 func_check_tool_result=$_G_check_tool_path/$1
4599 break
4601 done
4602 IFS=$save_IFS
4604 esac
4608 # func_check_versions APP1 VER1 URL1 ...[APPN VERN URLN]
4609 # ------------------------------------------------------
4610 func_check_versions ()
4612 $debug_cmd
4614 func_check_versions_result=:
4616 while test $# -gt 0; do
4617 _G_app=$1; shift
4618 _G_reqver=$1; shift
4619 _G_url=$1; shift
4621 # Diagnose bad buildreq formatting.
4622 case $_G_url in
4623 [a-z]*://*) ;; # looks like a url
4624 *) func_fatal_error "\
4625 '$_G_url' from the buildreq table in
4626 'bootstrap.conf' does not look like the URL for downloading
4627 $_G_app. Please ensure that buildreq is a strict newline
4628 delimited list of triples; 'program min-version url'."
4630 esac
4632 # Honor $APP variables ($TAR, $AUTOCONF, etc.)
4633 _G_appvar=`echo $_G_app |tr '[a-z]' '[A-Z]'`
4634 test TAR = "$_G_appvar" && _G_appvar=AMTAR
4635 eval "_G_app=\${$_G_appvar-$_G_app}"
4637 # Fail if no version specified, but the program can't be found.
4638 if test x- = "x$_G_reqver"; then
4639 func_check_tool $_G_app
4640 if test -z "$func_check_tool_result"; then
4641 func_error "Prerequisite '$_G_app' not not found. Please install it, or
4642 'export $_G_appvar=/path/to/$_G_app'."
4643 func_check_versions_result=false
4644 else
4645 func_verbose "found '$func_check_tool_result' for $_G_appvar."
4647 else
4648 _G_instver=`func_get_version $_G_app`
4650 test -z "$_G_instver" \
4651 || func_verbose "found '$_G_app' version $_G_instver."
4653 # Fail if --version didn't work.
4654 if test -z "$_G_instver"; then
4655 func_error "Prerequisite '$_G_app' not found. Please install it, or
4656 'export $_G_appvar=/path/to/$_G_app'."
4657 func_check_versions_result=false
4659 # Fail if a newer version than what we have is required.
4660 else
4661 _G_newer=`func_sort_ver $_G_reqver $_G_instver |cut -d' ' -f2`
4662 test "$_G_newer" != "$_G_instver" && {
4663 func_error "\
4664 '$_G_app' version == $_G_instver is too old
4665 '$_G_app' version >= $_G_reqver is required"
4666 func_check_versions_result=false
4670 done
4674 # func_cleanup_gnulib
4675 # -------------------
4676 # Recursively delete everything below the path in the global variable
4677 # GNULIB_PATH.
4678 func_cleanup_gnulib ()
4680 $debug_cmd
4682 _G_status=$?
4683 $RM -fr "$gnulib_path"
4684 exit $_G_status
4688 # func_download_po_files SUBDIR DOMAIN
4689 # ------------------------------------
4690 func_download_po_files ()
4692 $debug_cmd
4694 func_echo "getting translations into $1 for $2..."
4695 _G_cmd=`printf "$po_download_command_format" "$2" "$1"`
4696 eval "$_G_cmd"
4700 # func_update_po_files PO_DIR DOMAIN
4701 # ----------------------------------
4702 # Mirror .po files to $po_dir/.reference and copy only the new
4703 # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
4704 # Note po files that exist locally only are left in $po_dir but will
4705 # not be included in LINGUAS and hence will not be distributed.
4706 func_update_po_files ()
4708 $debug_cmd
4710 # Directory containing primary .po files.
4711 # Overwrite them only when we're sure a .po file is new.
4712 _G_po_dir=$1
4713 _G_domain=$2
4715 # Mirror *.po files into this dir.
4716 # Usually contains *.s1 checksum files.
4717 _G_ref_po_dir=$_G_po_dir/.reference
4719 test -d "$_G_ref_po_dir" || mkdir $_G_ref_po_dir || return
4720 func_download_po_files $_G_ref_po_dir $_G_domain \
4721 && ls "$_G_ref_po_dir"/*.po 2>/dev/null \
4722 |$SED -e 's|.*/||' -e 's|\.po$||' > "$_G_po_dir/LINGUAS" || return
4724 # Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6+.
4725 func_find_tool SHA1SUM sha1sum gsha1sum shasum sha1
4727 _G_langs=`cd $_G_ref_po_dir && echo *.po|$SED 's|\.po||g'`
4728 test '*' = "$_G_langs" && _G_langs=x
4729 for _G_po in $_G_langs; do
4730 case $_G_po in x) continue;; esac
4731 _G_new_po=$_G_ref_po_dir/$_G_po.po
4732 _G_cksum_file=$_G_ref_po_dir/$_G_po.s1
4733 if ! test -f "$_G_cksum_file" ||
4734 ! test -f "$_G_po_dir/$_G_po.po" ||
4735 ! $SHA1SUM -c "$_G_cksum_file" \
4736 < "$_G_new_po" > /dev/null; then
4737 echo "updated $_G_po_dir/$_G_po.po..."
4738 cp "$_G_new_po" "$_G_po_dir/$_G_po.po" \
4739 && $SHA1SUM < "$_G_new_po" > "$_G_cksum_file" || return
4741 done
4746 ## --------------- ##
4747 ## Option parsing. ##
4748 ## --------------- ##
4750 # Hook in the functions to make sure our own options are parsed during
4751 # the option parsing loop.
4753 usage='$progpath [OPTION]...'
4755 # Short help message in response to '-h'. Add to this in 'bootstrap.conf'
4756 # if you accept any additional options.
4757 usage_message="Common Bootstrap Options:
4758 -c, --copy copy files instead of creating symbolic links.
4759 --debug enable verbose shell tracing
4760 -n, --dry-run print commands rather than running them
4761 -f, --force attempt to bootstrap even if the sources seem not
4762 to have been checked out.
4763 --gnulib-srcdir=DIRNAME
4764 specify a local directory where gnulib sources
4765 reside. Use this if you already have the gnulib
4766 sources on your machine, and don't want to waste
4767 your bandwidth downloading them again. Defaults to
4768 \$GNULIB_SRCDIR.
4769 --no-warnings equivalent to '-Wnone'
4770 --skip-git do not fetch files from remote repositories
4771 --skip-po do not download po files.
4772 -v, --verbose verbosely report processing
4773 --version print version information and exit
4774 -W, --warnings=CATEGORY
4775 report the warnings falling in CATEGORY [all]
4776 -h, --help print short or long help message and exit
4779 # Additional text appended to 'usage_message' in response to '--help'.
4780 long_help_message=$long_help_message"
4781 'recommend' show warnings about missing recommended packages
4782 'settings' show warnings about missing '$progname.conf' settings
4783 'upgrade' show warnings about out-dated files
4785 If the file '$progname.conf' exists in the same directory as this
4786 script, its contents are read as shell variables to configure the
4787 bootstrap.
4789 For build prerequisites, environment variables like \$AUTOCONF and
4790 \$AMTAR are honored.
4792 Running without arguments will suffice in most cases.
4795 # Warning categories used by 'bootstrap', append others if you use them
4796 # in your 'bootstrap.conf'.
4797 warning_categories='recommend settings upgrade'
4800 # bootstrap_options_prep [ARG]...
4801 # -------------------------------
4802 # Preparation for options parsed by Bootstrap.
4803 bootstrap_options_prep ()
4805 $debug_cmd
4807 # Option defaults:
4808 opt_copy=${copy-'false'}
4809 opt_dry_run=false
4810 opt_force=false
4811 opt_gnulib_srcdir=$GNULIB_SRCDIR
4812 opt_skip_git=false
4813 opt_skip_po=false
4815 # Pass back the list of options we consumed.
4816 func_quote_for_eval ${1+"$@"}
4817 bootstrap_options_prep_result=$func_quote_for_eval_result
4819 func_add_hook func_options_prep bootstrap_options_prep
4822 # bootstrap_parse_options [ARG]...
4823 # --------------------------------
4824 # Provide handling for Bootstrap specific options.
4825 bootstrap_parse_options ()
4827 $debug_cmd
4829 # Perform our own loop to consume as many options as possible in
4830 # each iteration.
4831 while test $# -gt 0; do
4832 _G_opt=$1
4833 shift
4834 case $_G_opt in
4835 --dry-run|--dryrun|-n)
4836 opt_dry_run=: ;;
4837 --copy|-c) opt_copy=: ;;
4838 --force|-f) opt_force=: ;;
4840 --gnulib-srcdir)
4841 test $# = 0 && func_missing_arg $_G_opt && break
4842 opt_gnulib_srcdir=$1
4843 shift
4846 --skip-git|--no-git)
4847 opt_skip_git=:
4850 --skip-po|--no-po)
4851 opt_skip_po=:
4854 # Separate non-argument short options:
4855 -c*|-f*|-n*)
4856 func_split_short_opt "$_G_opt"
4857 set dummy "$func_split_short_opt_name" \
4858 "-$func_split_short_opt_arg" ${1+"$@"}
4859 shift
4862 *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
4863 esac
4864 done
4866 # save modified positional parameters for caller
4867 func_quote_for_eval ${1+"$@"}
4868 bootstrap_parse_options_result=$func_quote_for_eval_result
4870 func_add_hook func_parse_options bootstrap_parse_options
4873 # bootstrap_validate_options [ARG]...
4874 # -----------------------------------
4875 # Perform any sanity checks on option settings and/or unconsumed
4876 # arguments.
4877 bootstrap_validate_options ()
4879 $debug_cmd
4881 # Validate options.
4882 test $# -gt 0 \
4883 && func_fatal_help "too many arguments"
4885 # Pass back the (empty) list of unconsumed options.
4886 func_quote_for_eval ${1+"$@"}
4887 bootstrap_validate_options_result=$func_quote_for_eval_result
4889 func_add_hook func_validate_options bootstrap_validate_options
4892 ## -------------------------------------------------- ##
4893 ## Source package customisations in 'bootstrap.conf'. ##
4894 ## -------------------------------------------------- ##
4896 # Override the default configuration, if necessary.
4897 # Make sure that bootstrap.conf is sourced from the current directory
4898 # if we were invoked as "sh bootstrap".
4899 case $0 in
4900 */*) test -r "$0.conf" && . "$0.conf" ;;
4901 *) test -r "$0.conf" && . ./"$0.conf" ;;
4902 esac
4905 ## ------------------------------- ##
4906 ## Actually perform the bootstrap. ##
4907 ## ------------------------------- ##
4909 func_bootstrap ${1+"$@"}
4911 # The End.
4912 exit ${exit_status-$EXIT_SUCCESS}
4914 # Local variables:
4915 # mode: shell-script
4916 # sh-indentation: 2
4917 # eval: (add-hook 'write-file-hooks 'time-stamp)
4918 # time-stamp-pattern: "20/scriptversion=%:y-%02m-%02d.%02H; # UTC"
4919 # time-stamp-time-zone: "UTC"
4920 # End: