[CVE-2009-5155] Diagnose ERE '()|\1'
[platform/upstream/m4.git] / bootstrap
1 #! /bin/sh
2
3 # Bootstrap an Autotooled package from checked-out sources.
4 # Written by Gary V. Vaughan, 2010
5
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.
9
10 # Source required external libraries:
11 # Set a version string for this script.
12 scriptversion=2013-08-23.20; # UTC
13
14 # General shell script boiler plate, and helper functions.
15 # Written by Gary V. Vaughan, 2004
16
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.
20
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.
25
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.
30
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.
35
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/>.
38
39 # Please report bugs or propose patches to gary@gnu.org.
40
41
42 ## ------ ##
43 ## Usage. ##
44 ## ------ ##
45
46 # Evaluate this file near the top of your script to gain access to
47 # the functions and variables defined here:
48 #
49 #   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
50 #
51 # If you need to override any of the default environment variable
52 # settings, do that before evaluating this file.
53
54
55 ## -------------------- ##
56 ## Shell normalisation. ##
57 ## -------------------- ##
58
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!
61
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
72 fi
73
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
78 do
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
87
88 # CDPATH.
89 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
90
91 # Make sure IFS has a sensible default
92 sp=' '
93 nl='
94 '
95 IFS="$sp        $nl"
96
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)
101
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"
129     '
130     export bs_echo_n_body
131     bs_echo_n='sh -c $bs_echo_n_body bs_echo'
132   fi
133   export bs_echo_body
134   bs_echo='sh -c $bs_echo_body bs_echo'
135 fi
136
137
138 ## ------------------------------- ##
139 ## User overridable command paths. ##
140 ## ------------------------------- ##
141
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.
146
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}"}
159
160
161 ## -------------------- ##
162 ## Useful sed snippets. ##
163 ## -------------------- ##
164
165 sed_dirname='s|/[^/]*$||'
166 sed_basename='s|^.*/||'
167
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'
171
172 # Same as above, but do not quote variable references.
173 sed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
174
175 # Sed substitution that turns a string into a regex matching for the
176 # string literally.
177 sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
178
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'
183
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/&\\
195 /g
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"
199
200
201 ## ----------------- ##
202 ## Global variables. ##
203 ## ----------------- ##
204
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.
217
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.
222
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:
226 #
227 #    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
228 debug_cmd=${debug_cmd-":"}
229 exit_cmd=:
230
231 # By convention, finish your script with:
232 #
233 #    exit $exit_status
234 #
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
239
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
246
247 # The name of this program.
248 progname=`$bs_echo "$progpath" |$SED "$sed_basename"`
249
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
257      ;;
258   *)
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
268      ;;
269 esac
270
271
272 ## ----------------- ##
273 ## Standard options. ##
274 ## ----------------- ##
275
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.
279
280 opt_dry_run=false
281 opt_quiet=false
282 opt_verbose=false
283
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=
288
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
293
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
298
299
300 ## -------------------- ##
301 ## Resource management. ##
302 ## -------------------- ##
303
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.
309 #
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.
314
315
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 ()
321 {
322     $debug_cmd
323
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"}
329
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`
347         }
348       fi
349     }
350
351     require_term_colors=:
352 }
353
354
355 ## ----------------- ##
356 ## Function library. ##
357 ## ----------------- ##
358
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.
363
364
365 # func_append VAR VALUE
366 # ---------------------
367 # Append VALUE onto the existing contents of VAR.
368
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*) ;;
378       *)
379         : ${_G_HAVE_PLUSEQ_OP="yes"}
380         ;;
381     esac
382   fi
383
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
390
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 ()
395   {
396     $debug_cmd
397
398     eval "$1+=\$2"
399   }'
400 else
401   # ...otherwise fall back to using expr, which is often a shell builtin.
402   func_append ()
403   {
404     $debug_cmd
405
406     eval "$1=\$$1\$2"
407   }
408 fi
409
410
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 ()
417   {
418     $debug_cmd
419
420     func_quote_for_eval "$2"
421     eval "$1+=\\ \$func_quote_for_eval_result"
422   }'
423 else
424   func_append_quoted ()
425   {
426     $debug_cmd
427
428     func_quote_for_eval "$2"
429     eval "$1=\$$1\\ \$func_quote_for_eval_result"
430   }
431 fi
432
433
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:
438 #
439 #   func_append_uniq options " --another-option option-argument"
440 #
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 ()
445 {
446     $debug_cmd
447
448     eval _G_current_value='`$bs_echo $'$1'`'
449     _G_delim=`expr "$2" : '\(.\)'`
450
451     case $_G_delim$_G_current_value$_G_delim in
452       *"$2$_G_delim"*) ;;
453       *) func_append "$@" ;;
454     esac
455 }
456
457
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
464
465 if test yes = "$_G_HAVE_ARITH_OP"; then
466   eval 'func_arith ()
467   {
468     $debug_cmd
469
470     func_arith_result=$(( $* ))
471   }'
472 else
473   func_arith ()
474   {
475     $debug_cmd
476
477     func_arith_result=`expr "$@"`
478   }
479 fi
480
481
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'
495
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"
504       fi'
505 fi
506
507 eval 'func_basename ()
508 {
509     $debug_cmd
510
511     '"$_b"'
512 }'
513
514
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 ()
520 {
521     $debug_cmd
522
523     '"$_d"'
524 }'
525
526
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 ()
540 {
541     $debug_cmd
542
543     '"$_b"'
544     '"$_d"'
545 }'
546
547
548 # func_echo ARG...
549 # ----------------
550 # Echo program name prefixed message.
551 func_echo ()
552 {
553     $debug_cmd
554
555     _G_message=$*
556
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
564 }
565
566
567 # func_echo_all ARG...
568 # --------------------
569 # Invoke $ECHO with all args, space-separated.
570 func_echo_all ()
571 {
572     $ECHO "$*"
573 }
574
575
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 ()
581 {
582     $debug_cmd
583
584     $require_term_colors
585
586     _G_infix=$1; shift
587     _G_indent=$_G_infix
588     _G_prefix="$progname: $_G_infix: "
589     _G_message=$*
590
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"
593     do
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"`
597       }
598     done
599     _G_indent="$progname: "`echo "$_G_indent" | sed 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
600
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
609 }
610
611
612 # func_error ARG...
613 # -----------------
614 # Echo program name prefixed message to standard error.
615 func_error ()
616 {
617     $debug_cmd
618
619     $require_term_colors
620
621     func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
622 }
623
624
625 # func_fatal_error ARG...
626 # -----------------------
627 # Echo program name prefixed message to standard error, and exit.
628 func_fatal_error ()
629 {
630     $debug_cmd
631
632     func_error "$*"
633     exit $EXIT_FAILURE
634 }
635
636
637 # func_grep EXPRESSION FILENAME
638 # -----------------------------
639 # Check whether EXPRESSION matches any line of FILENAME, without output.
640 func_grep ()
641 {
642     $debug_cmd
643
644     $GREP "$1" "$2" >/dev/null 2>&1
645 }
646
647
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
656
657 if test yes = "$_G_HAVE_XSI_OPS"; then
658   eval 'func_len ()
659   {
660     $debug_cmd
661
662     func_len_result=${#1}
663   }'
664 else
665   func_len ()
666   {
667     $debug_cmd
668
669     func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
670   }
671 fi
672
673
674 # func_mkdir_p DIRECTORY-PATH
675 # ---------------------------
676 # Make sure the entire path to DIRECTORY-PATH is available.
677 func_mkdir_p ()
678 {
679     $debug_cmd
680
681     _G_directory_path=$1
682     _G_dir_list=
683
684     if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
685
686       # Protect directory names starting with '-'
687       case $_G_directory_path in
688         -*) _G_directory_path=./$_G_directory_path ;;
689       esac
690
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
696
697         # If the last portion added has no slash in it, the list is done
698         case $_G_directory_path in */*) ;; *) break ;; esac
699
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|:*$||'`
704
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
714
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'"
718     fi
719 }
720
721
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 ()
728 {
729     $debug_cmd
730
731     _G_template=${TMPDIR-/tmp}/${1-$progname}
732
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
737
738       # If mktemp works, use that first and foremost
739       _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
740
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}$$
744
745         func_mktempdir_umask=`umask`
746         umask 0077
747         $MKDIR "$_G_tmpdir"
748         umask $func_mktempdir_umask
749       fi
750
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'"
754     fi
755
756     $ECHO "$_G_tmpdir"
757 }
758
759
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 ()
766 {
767     $debug_cmd
768
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|/*$|/|'
778
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
784       "")
785         # Empty path, that just means $cwd.
786         func_stripname '' '/' "`pwd`"
787         func_normal_abspath_result=$func_stripname_result
788         return
789         ;;
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.
795         ;;
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=/
801         ;;
802       /*)
803         # Absolute path, do nothing.
804         ;;
805       *)
806         # Relative path, prepend $cwd.
807         func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
808         ;;
809     esac
810
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=/
822         fi
823         break
824       fi
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
831         "")
832           # Trailing empty path component, ignore it.
833           ;;
834         ..)
835           # Parent dir; strip last assembled component from result.
836           func_dirname "$func_normal_abspath_result"
837           func_normal_abspath_result=$func_dirname_result
838           ;;
839         *)
840           # Actual path component, append it.
841           func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
842           ;;
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
847 }
848
849
850 # func_notquiet ARG...
851 # --------------------
852 # Echo program name prefixed message only when not in quiet mode.
853 func_notquiet ()
854 {
855     $debug_cmd
856
857     $opt_quiet || func_echo ${1+"$@"}
858
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:
862     :
863 }
864
865
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 ()
870 {
871     $debug_cmd
872
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
878
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
887           ;;
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=.
894           fi
895           break
896           ;;
897         *)
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
905           fi
906           func_relative_path_result=../$func_relative_path_result
907           ;;
908       esac
909     done
910
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"
917     fi
918
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
923     fi
924
925     test -n "$func_relative_path_result" || func_relative_path_result=.
926
927     :
928 }
929
930
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 ()
941 {
942     $debug_cmd
943
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"` ;;
950         *)
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"
957       fi
958
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\"
967           ;;
968         *)
969           _G_quoted_arg=$_G_unquoted_arg
970           ;;
971       esac
972
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"
977       fi
978       shift
979     done
980 }
981
982
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 ()
988 {
989     $debug_cmd
990
991     case $1 in
992       *[\\\`\"]*)
993         _G_arg=`$ECHO "$1" | $SED \
994             -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
995       *)
996         _G_arg=$1 ;;
997     esac
998
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\"
1006         ;;
1007     esac
1008
1009     func_quote_for_expand_result=$_G_arg
1010 }
1011
1012
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 ()
1021   {
1022     $debug_cmd
1023
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"}
1029   }'
1030 else
1031   func_stripname ()
1032   {
1033     $debug_cmd
1034
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
1039   }
1040 fi
1041
1042
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 ()
1049 {
1050     $debug_cmd
1051
1052     _G_cmd=$1
1053     _G_fail_exp=${2-':'}
1054
1055     func_quote_for_expand "$_G_cmd"
1056     eval "func_notquiet $func_quote_for_expand_result"
1057
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"
1063       fi
1064     }
1065 }
1066
1067
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 ()
1074 {
1075     $debug_cmd
1076
1077     _G_cmd=$1
1078     _G_fail_exp=${2-':'}
1079
1080     $opt_quiet || {
1081       func_quote_for_expand "$_G_cmd"
1082       eval "func_echo $func_quote_for_expand_result"
1083     }
1084
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"
1092       fi
1093     }
1094 }
1095
1096
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 ()
1104 {
1105     $debug_cmd
1106
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'`
1110       ;;
1111     * )
1112       func_tr_sh_result=$1
1113       ;;
1114     esac
1115 }
1116
1117
1118 # func_verbose ARG...
1119 # -------------------
1120 # Echo program name prefixed message in verbose mode only.
1121 func_verbose ()
1122 {
1123     $debug_cmd
1124
1125     $opt_verbose && func_echo "$*"
1126
1127     :
1128 }
1129
1130
1131 # func_warn_and_continue ARG...
1132 # -----------------------------
1133 # Echo program name prefixed warning message to standard error.
1134 func_warn_and_continue ()
1135 {
1136     $debug_cmd
1137
1138     $require_term_colors
1139
1140     func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1141 }
1142
1143
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 ()
1151 {
1152     $debug_cmd
1153
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
1159
1160     _G_category=$1
1161     shift
1162
1163     case " $opt_warning_types " in
1164       *" $_G_category "*) $warning_func ${1+"$@"} ;;
1165     esac
1166 }
1167
1168
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
1177
1178 # Set a version string for this script.
1179 scriptversion=2012-10-21.11; # UTC
1180
1181 # A portable, pluggable option parser for Bourne shell.
1182 # Written by Gary V. Vaughan, 2010
1183
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.
1187
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.
1192
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.
1197
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/>.
1200
1201 # Please report bugs or propose patches to gary@gnu.org.
1202
1203
1204 ## ------ ##
1205 ## Usage. ##
1206 ## ------ ##
1207
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.
1211 #
1212 # For the simplest scripts you might need only:
1213 #
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...
1221 #
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; '.
1225 #
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.
1229 #
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'.
1235 #
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.
1240
1241 ## -------------- ##
1242 ## Configuration. ##
1243 ## -------------- ##
1244
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.
1248
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]...'
1255
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
1266 "
1267
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"
1274
1275 # Help message printed before fatal option parsing errors.
1276 fatal_help="Try '\$progname --help' for more information."
1277
1278
1279
1280 ## ------------------------- ##
1281 ## Hook function management. ##
1282 ## ------------------------- ##
1283
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.
1287
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 ()
1293 {
1294     $debug_cmd
1295
1296     func_append hookable_fns " $1"
1297 }
1298
1299
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 ()
1305 {
1306     $debug_cmd
1307
1308     case " $hookable_fns " in
1309       *" $1 "*) ;;
1310       *) func_fatal_error "'$1' does not accept hook functions." ;;
1311     esac
1312
1313     eval func_append ${1}_hooks '" $2"'
1314 }
1315
1316
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 ()
1321 {
1322     $debug_cmd
1323
1324     eval ${1}_hooks='`$bs_echo "\$'$1'_hooks" |$SED "s| '$2'||"`'
1325 }
1326
1327
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 ()
1336 {
1337     $debug_cmd
1338
1339     case " $hookable_fns " in
1340       *" $1 "*) ;;
1341       *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1342     esac
1343
1344     eval _G_hook_fns=\$$1_hooks; shift
1345
1346     for _G_hook in $_G_hook_fns; do
1347       eval $_G_hook '"$@"'
1348
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
1354
1355     func_quote_for_eval ${1+"$@"}
1356     func_run_hooks_result=$func_quote_for_eval_result
1357 }
1358
1359
1360
1361 ## --------------- ##
1362 ## Option parsing. ##
1363 ## --------------- ##
1364
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:
1370 #
1371 #    my_options_prep ()
1372 #    {
1373 #        $debug_cmd
1374 #
1375 #        # Extend the existing usage message.
1376 #        usage_message=$usage_message'
1377 #      -s, --silent       don'\''t print informational messages
1378 #    '
1379 #
1380 #        func_quote_for_eval ${1+"$@"}
1381 #        my_options_prep_result=$func_quote_for_eval_result
1382 #    }
1383 #    func_add_hook func_options_prep my_options_prep
1384 #
1385 #
1386 #    my_silent_option ()
1387 #    {
1388 #        $debug_cmd
1389 #
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
1406 #
1407 #        func_quote_for_eval ${1+"$@"}
1408 #        my_silent_option_result=$func_quote_for_eval_result
1409 #    }
1410 #    func_add_hook func_parse_options my_silent_option
1411 #
1412 #
1413 #    my_option_validation ()
1414 #    {
1415 #        $debug_cmd
1416 #
1417 #        $opt_silent && $opt_verbose && func_fatal_help "\
1418 #    '--silent' and '--verbose' options are mutually exclusive."
1419 #
1420 #        func_quote_for_eval ${1+"$@"}
1421 #        my_option_validation_result=$func_quote_for_eval_result
1422 #    }
1423 #    func_add_hook func_validate_options my_option_validation
1424 #
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.
1428
1429
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 ()
1436 {
1437     $debug_cmd
1438
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"}
1444
1445     eval func_run_hooks func_options \
1446         ${func_validate_options_result+"$func_validate_options_result"}
1447
1448     # save modified positional parameters for caller
1449     func_options_result=$func_run_hooks_result
1450 }
1451
1452
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 ()
1463 {
1464     $debug_cmd
1465
1466     # Option defaults:
1467     opt_verbose=false
1468     opt_warning_types=
1469
1470     func_run_hooks func_options_prep ${1+"$@"}
1471
1472     # save modified positional parameters for caller
1473     func_options_prep_result=$func_run_hooks_result
1474 }
1475
1476
1477 # func_parse_options [ARG]...
1478 # ---------------------------
1479 # The main option parsing loop.
1480 func_hookable func_parse_options
1481 func_parse_options ()
1482 {
1483     $debug_cmd
1484
1485     func_parse_options_result=
1486
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+"$@"}
1492
1493       # Adjust func_parse_options positional parameters to match
1494       eval set dummy "$func_run_hooks_result"; shift
1495
1496       # Break out of the loop if we already parsed every option.
1497       test $# -gt 0 || break
1498
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
1505                       ;;
1506
1507         --no-warnings|--no-warning|--no-warn)
1508                       set dummy --warnings none ${1+"$@"}
1509                       shift
1510                       ;;
1511
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"
1518                           ;;
1519                         *all)
1520                           opt_warning_types=$warning_categories
1521                           ;;
1522                         *none)
1523                           opt_warning_types=none
1524                           warning_func=:
1525                           ;;
1526                         *error)
1527                           opt_warning_types=$warning_categories
1528                           warning_func=func_fatal_error
1529                           ;;
1530                         *)
1531                           func_fatal_error \
1532                              "unsupported warning category: '$1'"
1533                           ;;
1534                       esac
1535                       shift
1536                       ;;
1537
1538         --verbose|-v) opt_verbose=: ;;
1539         --version)    func_version ;;
1540         -\?|-h)       func_usage ;;
1541         --help)       func_help ;;
1542
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
1548                       ;;
1549
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
1556                       ;;
1557
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
1564                       ;;
1565
1566         --)           break ;;
1567         -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1568         *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1569       esac
1570     done
1571
1572     # save modified positional parameters for caller
1573     func_quote_for_eval ${1+"$@"}
1574     func_parse_options_result=$func_quote_for_eval_result
1575 }
1576
1577
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 ()
1584 {
1585     $debug_cmd
1586
1587     # Display all warnings if -W was not given.
1588     test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1589
1590     func_run_hooks func_validate_options ${1+"$@"}
1591
1592     # Bail if the options were screwed!
1593     $exit_cmd $EXIT_FAILURE
1594
1595     # save modified positional parameters for caller
1596     func_validate_options_result=$func_run_hooks_result
1597 }
1598
1599
1600
1601 ## ------------------##
1602 ## Helper functions. ##
1603 ## ------------------##
1604
1605 # This section contains the helper functions used by the rest of the
1606 # hookable option parser framework in ascii-betical order.
1607
1608
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 ()
1614 {
1615     $debug_cmd
1616
1617     eval \$bs_echo \""Usage: $usage"\"
1618     eval \$bs_echo \""$fatal_help"\"
1619     func_error ${1+"$@"}
1620     exit $EXIT_FAILURE
1621 }
1622
1623
1624 # func_help
1625 # ---------
1626 # Echo long help message to standard output and exit.
1627 func_help ()
1628 {
1629     $debug_cmd
1630
1631     func_usage_message
1632     $bs_echo "$long_help_message"
1633     exit 0
1634 }
1635
1636
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 ()
1642 {
1643     $debug_cmd
1644
1645     func_error "Missing argument for '$1'."
1646     exit_cmd=exit
1647 }
1648
1649
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
1658
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 ()
1663   {
1664       $debug_cmd
1665
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=
1670   }'
1671 else
1672   # ...otherwise fall back to using expr, which is often a shell builtin.
1673   func_split_equals ()
1674   {
1675       $debug_cmd
1676
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[^=]*=\(.*\)$'`
1681   }
1682 fi #func_split_equals
1683
1684
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 ()
1693   {
1694       $debug_cmd
1695
1696       func_split_short_opt_arg=${1#??}
1697       func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1698   }'
1699 else
1700   # ...otherwise fall back to using expr, which is often a shell builtin.
1701   func_split_short_opt ()
1702   {
1703       $debug_cmd
1704
1705       func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1706       func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1707   }
1708 fi #func_split_short_opt
1709
1710
1711 # func_usage
1712 # ----------
1713 # Echo short help message to standard output and exit.
1714 func_usage ()
1715 {
1716     $debug_cmd
1717
1718     func_usage_message
1719     $bs_echo "Run '$progname --help |${PAGER-more}' for full usage"
1720     exit 0
1721 }
1722
1723
1724 # func_usage_message
1725 # ------------------
1726 # Echo short help message to standard output.
1727 func_usage_message ()
1728 {
1729     $debug_cmd
1730
1731     eval \$bs_echo \""Usage: $usage"\"
1732     echo
1733     $SED -n 's|^# ||
1734         /^Written by/{
1735           x;p;x
1736         }
1737         h
1738         /^Written by/q' < "$progpath"
1739     echo
1740     eval \$bs_echo \""$usage_message"\"
1741 }
1742
1743
1744 # func_version
1745 # ------------
1746 # Echo version message to standard output and exit.
1747 func_version ()
1748 {
1749     $debug_cmd
1750
1751     printf '%s\n' "$progname $scriptversion"
1752     $SED -n '/^##/q
1753         /(C)/!b go
1754         :more
1755         /\./!{
1756           N
1757           s|\n# | |
1758           b more
1759         }
1760         :go
1761         /^# Written by /,/# warranty; / {
1762           s|^# ||
1763           s|^# *$||
1764           s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1765           p
1766         }
1767         /^# Written by / {
1768           s|^# ||
1769           p
1770         }
1771         /^warranty; /q' < "$progpath"
1772
1773     exit $?
1774 }
1775
1776
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
1785
1786 # Extract macro arguments from autotools input with GNU M4.
1787 # Written by Gary V. Vaughan, 2010
1788 #
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.
1792
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
1796
1797 # Set a version string.
1798 scriptversion=2013-08-22.10; # UTC
1799
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.
1804
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.
1809
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/>.
1812
1813 # Please report bugs or propose patches to gary@gnu.org.
1814
1815
1816 ## ------ ##
1817 ## Usage. ##
1818 ## ------ ##
1819
1820 # Run './extract-trace --help' for help with using this script from the
1821 # command line.
1822 #
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.
1827
1828
1829
1830 ## ------------------##
1831 ## Helper functions. ##
1832 ## ------------------##
1833
1834 # This section contains the helper functions used by the rest of
1835 # 'extract-trace'.
1836
1837
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 ()
1843 {
1844     $debug_cmd
1845
1846     _G_sed_no_comment='
1847       s|#.*$||
1848       s|^dnl .*$||
1849       s| dnl .*$||'
1850     _G_ac_init=
1851
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`
1855
1856     # Otherwise it is not a genuine Autoconf input file.
1857     test -n "$_G_ac_init"
1858     _G_status=$?
1859
1860     test 0 -ne "$_G_status" \
1861       && func_verbose "'$1' not using Autoconf"
1862
1863     (exit $_G_status)
1864 }
1865
1866
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 ()
1874 {
1875     $debug_cmd
1876
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
1885       do
1886         if func_tool_version_output $_G_prog >/dev/null; then
1887           _G_find_tool_res=$_G_prog
1888           break
1889         fi
1890       done
1891     fi
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'"
1895
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"
1904     fi
1905 }
1906
1907
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 ()
1918 {
1919     $debug_cmd
1920
1921     _G_cmd=$1
1922     _G_fatal_error_msg=$2
1923
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=$?
1934
1935     test 0 -ne "$_G_status" && test -n "$_G_fatal_error_msg" \
1936         && func_fatal_error "$_G_fatal_error_msg"
1937
1938     (exit $_G_status)
1939 }
1940
1941
1942 ## -------------------- ##
1943 ## Resource management. ##
1944 ## -------------------- ##
1945
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.
1954 #
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.
1959
1960
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 ()
1968 {
1969     $debug_cmd
1970
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'"
1977
1978     require_configure_ac=:
1979 }
1980
1981
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 ()
1987 {
1988     $debug_cmd
1989
1990     test -n "$M4" || {
1991       # Find the first m4 binary that responds to --version.
1992       func_find_tool M4 gm4 gnum4 m4
1993     }
1994
1995     test -n "$M4" || func_fatal_error "\
1996 Please install GNU M4, or 'export M4=/path/to/gnu/m4'."
1997
1998     func_verbose "export M4='$M4'"
1999
2000     # Make sure the search result is visible to subshells
2001     export M4
2002
2003     require_gnu_m4=:
2004 }
2005
2006
2007 ## --------------- ##
2008 ## Core functions. ##
2009 ## --------------- ##
2010
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.
2014
2015
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 ()
2022 {
2023     $debug_cmd
2024
2025     $require_configure_ac
2026     $require_gnu_m4
2027
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
2034     }
2035
2036     # Generate an error if the first file is missing
2037     <"$1"
2038
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.
2044     #
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):
2048     #
2049     #    autom4te --language=Autoconf --trace=$my_macro:\$% "$@"
2050     #
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])])
2061
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])
2068
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])
2076
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($@)))])
2089
2090         # "autoconf.mini" - things from autoconf macros we care about.
2091         m4_copy([m4_defun], [AC_DEFUN])
2092
2093         # Dummy definitions for the macros we want to trace.
2094         # AM_INIT_AUTOMAKE at least produces no trace without this.
2095     '
2096
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
2104
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 .*$||;'
2110
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|
2124           p
2125         }'
2126     done
2127     IFS=$_G_save
2128
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"`
2134 }
2135
2136
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 ()
2143 {
2144     $debug_cmd
2145
2146     func_extract_trace ${1+"$@"}
2147     func_extract_trace_first_result=`$bs_echo "$func_extract_trace_result" \
2148       |$SED -e 's|:.*$||g' -e 1q`
2149 }
2150
2151
2152 # func_main [ARG]...
2153 # ------------------
2154 func_main ()
2155 {
2156     $debug_cmd
2157
2158     # Configuration.
2159     usage='$progname MACRO_NAME FILE [...]'
2160
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.
2166
2167 The arguments are returned separated by colons, with each traced call
2168 on a separate line.'
2169
2170     # Option processing.
2171     func_options "$@"
2172     eval set dummy "$func_options_result"; shift
2173
2174     # Validate remaining non-option arguments.
2175     test $# -gt 1 \
2176         || func_fatal_help "not enough arguments"
2177
2178     # Pass non-option arguments to extraction function.
2179     func_extract_trace "$@"
2180
2181     # Display results.
2182     test -n "$func_extract_trace_result" \
2183         && $bs_echo "$func_extract_trace_result"
2184
2185     # The End.
2186     exit $EXIT_SUCCESS
2187 }
2188
2189
2190 ## --------------------------- ##
2191 ## Actually perform the trace. ##
2192 ## --------------------------- ##
2193
2194 # Only call 'func_main' if this script was called directly.
2195 test extract-trace = "$progname" && func_main "$@"
2196
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:
2204
2205 # Set a version string for *this* script.
2206 scriptversion=2013-09-15.06; # UTC
2207
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.
2212
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.
2217
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/>.
2220
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.
2228
2229 # Please report bugs or propose patches to bug-gnulib@gnu.org.
2230
2231
2232 ## ------ ##
2233 ## Usage. ##
2234 ## ------ ##
2235
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.
2243 #
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:
2249 #
2250 #   gl/build-aux/inline-source gl/build-aux/bootstrap.in > bootstrap
2251 #
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.
2255 #
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.
2259
2260
2261 ## ================================================================== ##
2262 ##                                                                    ##
2263 ##     DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF     ##
2264 ##                                                                    ##
2265 ## ================================================================== ##
2266
2267 ## ------------------------------- ##
2268 ## User overridable command paths. ##
2269 ## ------------------------------- ##
2270
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).
2276 #
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.
2281
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"}
2300
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
2310
2311
2312 ## -------------- ##
2313 ## Configuration. ##
2314 ## -------------- ##
2315
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=
2321
2322 # Name of a file containing instructions on installing missing packages
2323 # required in 'buildreq'.
2324 buildreq_readme=README-hacking
2325
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=
2334
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=
2344
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=
2349
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
2361 "
2362
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=
2368
2369 # Additional gnulib-tool options to use.
2370 gnulib_tool_options="
2371         --no-changelog
2372 "
2373
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
2378 "
2379
2380 # When truncating long commands for display, always allow at least this
2381 # many characters before truncating.
2382 min_cmd_len=160
2383
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'"
2392
2393 # Other locale categories that need message catalogs.
2394 extra_locale_categories=
2395
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:
2400 #
2401 #    AM_GNU_GETTEXT_VERSION([0.16.1])
2402 xgettext_options="
2403         --flag=_:1:pass-c-format
2404         --flag=N_:1:pass-c-format
2405 "
2406
2407 # Package copyright holder for gettext files.  Defaults to FSF if unset.
2408 copyright_holder=
2409
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=
2413
2414 # Whether to use copies instead of symlinks by default (if set to true,
2415 # the --copy option has no effect).
2416 copy=false
2417
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=
2425
2426
2427 ## ------------------- ##
2428 ## Hookable functions. ##
2429 ## ------------------- ##
2430
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'.
2436 #
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.
2440
2441
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 ()
2447 {
2448     $debug_cmd
2449
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
2454
2455     # Initialisation.
2456     func_init
2457
2458     # Option processing.
2459     eval func_options "$_G_saved_positional_parameters"
2460
2461     # Post-option preparation.
2462     func_prep
2463
2464     # Ensure ChangeLog presence.
2465     func_ifcontains "$gnulib_modules" gitlog-to-changelog \
2466       func_ensure_changelog
2467
2468     # Reconfigure the package.
2469     func_reconfigure
2470
2471     # Ensure .version is up-to-date.
2472     func_update_dotversion
2473
2474     # Finalisation.
2475     func_fini
2476 }
2477
2478
2479 # func_init
2480 # ---------
2481 # Any early initialisations can be hooked to this function.  Consider
2482 # whether you can hook onto 'func_prep' instead, because if you hook
2483 # any slow to execute code in here, it will also add to the time before
2484 # './bootstrap --version' can respond.
2485 func_hookable func_init
2486 func_init ()
2487 {
2488     $debug_cmd
2489
2490     func_run_hooks func_init
2491 }
2492
2493
2494 # func_prep
2495 # ---------
2496 # Function to perform preparation for remaining bootstrap process. If
2497 # your hooked code relies on the outcome of 'func_options' hook it here
2498 # rather than to 'func_init'.
2499 #
2500 # All the functions called inside func_prep are hookable. See the
2501 # individual implementations for details.
2502 func_hookable func_prep
2503 func_prep ()
2504 {
2505     $debug_cmd
2506
2507     $require_buildtools_uptodate
2508     $require_checkout_only_file
2509
2510     $require_gnulib_merge_changelog
2511
2512     # fetch update files from the translation project
2513     func_update_translations
2514
2515     func_run_hooks func_prep
2516 }
2517
2518
2519 # func_update_translations
2520 # ------------------------
2521 # Update package po files and translations.
2522 func_hookable func_update_translations
2523 func_update_translations ()
2524 {
2525     $debug_cmd
2526
2527     $opt_skip_po || {
2528       test -d po && {
2529         $require_package
2530
2531         func_update_po_files po $package || exit $?
2532       }
2533
2534       func_run_hooks func_update_translations
2535     }
2536 }
2537
2538
2539 # func_reconfigure
2540 # ----------------
2541 # Reconfigure the current package by running the appropriate autotools in a
2542 # suitable order.
2543 func_hookable func_reconfigure
2544 func_reconfigure ()
2545 {
2546     $debug_cmd
2547
2548     # Released 'autopoint' has the tendency to install macros that have
2549     # been obsoleted in current 'gnulib., so run this before 'gnulib-tool'.
2550     func_autopoint
2551
2552     # Autoreconf runs 'aclocal' before 'libtoolize', which causes spurious
2553     # warnings if the initial 'aclocal' is confused by the libtoolized
2554     # (or worse: out-of-date) macro directory.
2555     func_libtoolize
2556
2557     # If you need to do anything after 'gnulib-tool' is done, but before
2558     # 'autoreconf' runs, you don't need to override this whole function,
2559     # because 'func_gnulib_tool' is hookable.
2560     func_gnulib_tool
2561
2562     func_autoreconf
2563
2564     func_run_hooks func_reconfigure
2565 }
2566
2567
2568 # func_gnulib_tool
2569 # ----------------
2570 # Run 'gnulib-tool' to fetch gnulib modules into the current package.
2571 #
2572 # It's assumed that since you are using gnulib's 'bootstrap' script,
2573 # you're also using gnulib elsewhere in your package.  If not, then
2574 # you can replace this function in 'bootstrap.conf' with:
2575 #
2576 #   func_gnulib_tool () { :; }
2577 #
2578 # (although the function returns immediately if $gnulib_tool is set to
2579 # true in any case).
2580 func_hookable func_gnulib_tool
2581 func_gnulib_tool ()
2582 {
2583     $debug_cmd
2584
2585     $require_gnulib_tool
2586     $require_libtoolize
2587
2588     test true = "$gnulib_tool" || {
2589       # bootstrap.conf written for gnulib bootstrap expects
2590       # gnulib_tool_option_extras to which --no-changelog is appended,
2591       # but libtool bootstrap expects you to append to gnulib_tool_options
2592       # so that you can override the --no-changelog default: make sure we
2593       # support both styles so users can migrate between them easily.
2594       gnulib_tool_all_options="$gnulib_tool_options $gnulib_tool_option_extras"
2595
2596       if test -n "$gnulib_modules"; then
2597         $require_gnulib_cache
2598         $require_gnulib_tool_base_options
2599
2600         gnulib_mode=--import
2601
2602         # Try not to pick up any stale values from 'gnulib-cache.m4'.
2603         rm -f "$gnulib_cache"
2604
2605         test -n "$gnulib_tool_base_options" \
2606             && func_append_uniq gnulib_tool_all_options " $gnulib_tool_base_options"
2607         test -n "$gnulib_mk" \
2608             && func_append_uniq gnulib_tool_all_options " --makefile-name=$gnulib_mk"
2609         test -n "$tests_base" && {
2610           func_append_uniq gnulib_tool_all_options " --tests-base=$tests_base"
2611           func_append_uniq gnulib_tool_all_options " --with-tests"
2612         }
2613       else
2614
2615         # 'gnulib_modules' and others are cached in 'gnulib-cache.m4':
2616         # Use 'gnulib --update' to fetch gnulib modules.
2617         gnulib_mode=--update
2618       fi
2619
2620       # Add a sensible default libtool option to gnulib_tool_options.
2621       # The embedded echo is to squash whitespace before globbing.
2622       case `echo " "$gnulib_tool_all_options" "` in
2623         *" --no-libtool "*|*" --libtool "*) ;;
2624         *)  if test true = "$LIBTOOLIZE"; then
2625               func_append_uniq gnulib_tool_all_options " --no-libtool"
2626             else
2627               func_append_uniq gnulib_tool_all_options " --libtool"
2628             fi
2629             ;;
2630       esac
2631
2632       $opt_copy || func_append_uniq gnulib_tool_all_options " --symlink"
2633
2634       func_append_uniq gnulib_tool_all_options " $gnulib_mode"
2635       func_append gnulib_tool_all_options " $gnulib_modules"
2636
2637       # The embedded echo is to squash whitespace before display.
2638       gnulib_cmd=`echo $gnulib_tool $gnulib_tool_all_options`
2639
2640       func_show_eval "$gnulib_cmd" 'exit $?'
2641
2642       # Use 'gnulib-tool --copy-file' to install non-module files.
2643       func_install_gnulib_non_module_files
2644     }
2645
2646     func_run_hooks func_gnulib_tool
2647 }
2648
2649
2650 # func_fini
2651 # ---------
2652 # Function to perform all finalisation for the bootstrap process.
2653 func_hookable func_fini
2654 func_fini ()
2655 {
2656     $debug_cmd
2657
2658     func_gettext_configuration
2659     func_clean_dangling_symlinks
2660     func_clean_unused_macros
2661     func_skip_po_recommendation
2662
2663     func_run_hooks func_fini
2664
2665     $require_bootstrap_uptodate
2666
2667     func_echo "Done.  Now you can run './configure'."
2668 }
2669
2670
2671 # func_gettext_configuration
2672 # --------------------------
2673 # Edit configuration values into po/Makevars.
2674 func_hookable func_gettext_configuration
2675 func_gettext_configuration ()
2676 {
2677     $debug_cmd
2678
2679     $require_autopoint
2680
2681     test true = "$AUTOPOINT" || {
2682       $require_copyright_holder
2683       $require_extra_locale_categories
2684       $require_package_bugreport
2685
2686       # Escape xgettext options for sed Makevars generation below.
2687       # We have to delete blank lines in a separate script so that we don't
2688       # append \\\ to the penultimate line, and then delete the last empty
2689       # line, which messes up the variable substitution later in this
2690       # function.  Note that adding a literal \\\ requires double escaping
2691       # here, once for the execution subshell, and again for the assignment,
2692       # which is why there are actually 12 (!!) backslashes in the script.
2693       _G_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED '
2694           $b
2695           s|$| \\\\\\\\\\\\|'`
2696
2697       # Create gettext configuration.
2698       func_echo "Creating po/Makevars from po/Makevars.template ..."
2699       $RM -f po/Makevars
2700       $SED '
2701         /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'|
2702         /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'|
2703         /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'|
2704         /^XGETTEXT_OPTIONS *=/{
2705           s|$| \\|
2706           a\
2707              '"$_G_xgettext_options"' \\\
2708              $${end_of_xgettext_options+}
2709         }
2710       ' po/Makevars.template >po/Makevars || exit 1
2711     }
2712
2713     func_run_hooks func_gettext_configuration
2714 }
2715
2716
2717
2718 ## --------------- ##
2719 ## Core functions. ##
2720 ## --------------- ##
2721
2722 # This section contains the main functions called from the 'Hookable
2723 # functions' (shown above), and are the ones you're  most likely
2724 # to want to replace with your own implementations in 'bootstrap.conf'.
2725
2726
2727 # func_autopoint
2728 # --------------
2729 # If this package uses gettext, then run 'autopoint'.
2730 func_autopoint ()
2731 {
2732     $debug_cmd
2733
2734     $require_autopoint
2735
2736     test true = "$AUTOPOINT" \
2737         || func_show_eval "$AUTOPOINT --force" 'exit $?'
2738 }
2739
2740
2741 # func_libtoolize
2742 # ---------------
2743 # If this package uses libtool, then run 'libtoolize'.
2744 func_libtoolize ()
2745 {
2746     $debug_cmd
2747
2748     $require_libtoolize
2749
2750     test true = "$LIBTOOLIZE" || {
2751       _G_libtoolize_options=
2752       $opt_copy && func_append _G_libtoolize_options " --copy"
2753       $opt_force && func_append _G_libtoolize_options " --force"
2754       $opt_verbose || func_append _G_libtoolize_options " --quiet"
2755       func_show_eval "$LIBTOOLIZE$_G_libtoolize_options" 'exit $?'
2756     }
2757 }
2758
2759
2760 # func_gnulib_tool_copy_file SRC DEST
2761 # -----------------------------------
2762 # Copy SRC, a path relative to the gnulib sub-tree, to DEST, a path
2763 # relative to the top-level source directory using gnulib-tool so that
2764 # any patches or replacements in $local_gl_dir are applied.
2765 func_gnulib_tool_copy_file ()
2766 {
2767     $debug_cmd
2768
2769     $require_gnulib_tool
2770     $require_patch
2771
2772     if test true = "$gnulib_tool"; then
2773       # If gnulib-tool is not available (e.g. bootstrapping in a
2774       # distribution tarball), make sure that at least we have some
2775       # version of the required file already in place.
2776       test -f "$2" || func_fatal_error "\
2777 Can't find, copy or download '$2', a required
2778 gnulib supplied file, please provide the location of a
2779 complete 'gnulib' tree by setting 'gnulib_path' in your
2780 'bootstrap.conf' or with the '--gnulib-srcdir' option -
2781 or else specify the location of your 'git' binary by
2782 setting 'GIT' in the environment so that a fresh
2783 'gnulib' submodule can be cloned."
2784     else
2785       $require_gnulib_copy_cmd
2786
2787       $gnulib_copy_cmd $1 $2 2>/dev/null || {
2788         $require_gnulib_path
2789
2790         func_error "'$gnulib_path/$1' does not exist"
2791         return 1
2792       }
2793     fi
2794 }
2795
2796
2797 # func_install_gnulib_non_module_files
2798 # ------------------------------------
2799 # Get additional non-module files from gnulib, overriding existing files.
2800 func_install_gnulib_non_module_files ()
2801 {
2802     $debug_cmd
2803
2804     $require_build_aux
2805     $require_gnulib_tool
2806
2807     test -n "$gnulib_non_module_files" && {
2808       maybe_exit_cmd=:
2809
2810       for file in $gnulib_non_module_files; do
2811         case $file in
2812           */COPYING*) dest=COPYING;;
2813           */INSTALL) dest=INSTALL;;
2814           build-aux/missing) dest=
2815             func_warning settings "\
2816 Please remove build-aux/missing from gnulib_module_files in
2817 'bootstrap.conf', as it may clash with Automake's version."
2818             ;;
2819           build-aux/*) dest=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
2820           *) dest=$file;;
2821         esac
2822
2823         # Be sure to show all copying errors before bailing out
2824         test -z "$dest" \
2825             || func_gnulib_tool_copy_file "$file" "$dest" \
2826             || maybe_exit_cmd="exit $EXIT_FAILURE"
2827       done
2828
2829       $maybe_exit_cmd
2830     }
2831 }
2832
2833
2834 # func_ensure_changelog
2835 # ---------------------
2836 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
2837 # will not run to completion with no ChangeLog file.
2838 func_ensure_changelog ()
2839 {
2840     $debug_cmd
2841
2842     test -f ChangeLog && mv -f ChangeLog ChangeLog~
2843
2844     cat >ChangeLog <<'EOT'
2845 ## ---------------------- ##
2846 ## DO NOT EDIT THIS FILE! ##
2847 ## ---------------------- ##
2848
2849 ChangeLog is generated by gitlog-to-changelog.
2850 EOT
2851
2852     _G_message="creating dummy 'ChangeLog'"
2853     test -f ChangeLog~ \
2854       && func_append _G_message ' (backup in ChangeLog~)'
2855     func_verbose "$_G_message"
2856
2857     return 0
2858 }
2859
2860
2861 # func_autoreconf
2862 # ---------------
2863 # Being careful not to re-run 'autopoint' or 'libtoolize', and not to
2864 # try to run 'autopoint', 'libtoolize' or 'autoheader' on packages that
2865 # don't use them, defer to 'autoreconf' for execution of the remaining
2866 # autotools to bootstrap this package.
2867 func_autoreconf ()
2868 {
2869     $debug_cmd
2870
2871     $require_autoheader
2872     $require_build_aux  # automake and others put files in here
2873     $require_macro_dir  # aclocal and others put files in here
2874
2875     # We ran these manually already, and autoreconf won't exec ':'
2876     save_AUTOPOINT=$AUTOPOINT; AUTOPOINT=true
2877     save_LIBTOOLIZE=$LIBTOOLIZE; LIBTOOLIZE=true
2878
2879     _G_autoreconf_options=
2880     $opt_copy || func_append _G_autoreconf_options " --symlink"
2881     $opt_force && func_append _G_autoreconf_options " --force"
2882     $opt_verbose && func_append _G_autoreconf_options " --verbose"
2883     func_show_eval "$AUTORECONF$_G_autoreconf_options --install" 'exit $?'
2884
2885     AUTOPOINT=$save_AUTOPOINT
2886     LIBTOOLIZE=$save_LIBTOOLIZE
2887 }
2888
2889
2890 # func_check_configuration VARNAME [CONFIGURE_MACRO]
2891 # --------------------------------------------------
2892 # Exit with a suitable diagnostic for an important configuration change
2893 # that needs to be made before bootstrap can run correctly.
2894 func_check_configuration ()
2895 {
2896     $debug_cmd
2897
2898     $require_configure_ac
2899
2900     eval 'test -n "$'$1'"' || {
2901       _G_error_msg="please set '$1' in 'bootstrap.conf'"
2902       if test -n "$configure_ac" && test -n "$2"; then
2903         func_append _G_error_msg "
2904 or add the following (or similar) to your '$configure_ac':
2905 $2"
2906       fi
2907
2908       func_fatal_error "$_G_error_msg"
2909     }
2910 }
2911
2912
2913 # func_clean_dangling_symlinks
2914 # ----------------------------
2915 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
2916 # gnulib-populated directories. Such .m4 files would cause aclocal to
2917 # fail.  The following requires GNU find 4.2.3 or newer. Considering
2918 # the usual portability constraints of this script, that may seem a very
2919 # demanding requirement, but it should be ok.  Ignore any failure,
2920 # which is fine, since this is only a convenience to help developers
2921 # avoid the relatively unusual case where a symlinked-to .m4 file is
2922 # git-removed from gnulib between successive runs of this script.
2923 func_clean_dangling_symlinks ()
2924 {
2925     $debug_cmd
2926
2927     $require_macro_dir
2928     $require_source_base
2929
2930     func_verbose "cleaning dangling symlinks"
2931
2932     find "$macro_dir" "$source_base" \
2933         -depth \( -name '*.m4' -o -name '*.[ch]' \) \
2934         -type l -xtype l -delete > /dev/null 2>&1
2935 }
2936
2937
2938 # func_clean_unused_macros
2939 # ------------------------
2940 # Autopoint can result in over-zealously adding macros into $macro_dir
2941 # even though they are not actually used, for example tests to help
2942 # build the 'intl' directory even though you have specified
2943 # 'AM_GNU_GETTEXT([external])' in your configure.ac.  This function
2944 # looks removes any macro files that can be found in gnulib,  but
2945 # are not 'm4_include'd by 'aclocal.m4'.
2946 func_clean_unused_macros ()
2947 {
2948     $debug_cmd
2949
2950     $require_gnulib_path
2951     $require_macro_dir
2952
2953     test -n "$gnulib_path" && test -f aclocal.m4 && {
2954       aclocal_m4s=`find . -name aclocal.m4 -print`
2955
2956       # We use 'ls|grep' instead of 'ls *.m4' to avoid exceeding
2957       # command line length limits in some shells.
2958       for file in `cd "$macro_dir" && ls -1 |grep '\.m4$'`; do
2959
2960         # Remove a macro file when aclocal.m4 does not m4_include it...
2961         func_grep_q 'm4_include([[]'$macro_dir/$file'])' $aclocal_m4s \
2962             || test ! -f "$gnulib_path/m4/$file" || {
2963
2964               # ...and there is an identical file in gnulib...
2965               if func_cmp_s "$gnulib_path/m4/$file" "$macro_dir/$file"; then
2966
2967                 # ...and it's not in the precious list ('echo' is needed
2968                 # here to squash whitespace for the match expression).
2969                 case " "`echo $gnulib_precious`" " in
2970                   *" $file "*) ;;
2971                   *) rm -f "$macro_dir/$file"
2972                      func_verbose \
2973                        "removing unused gnulib file '$macro_dir/$file'"
2974                 esac
2975               fi
2976         }
2977       done
2978     }
2979 }
2980
2981
2982 # func_skip_po_recommendation
2983 # ---------------------------
2984 # If there is a po directory, and '--skip-po' wasn't passed, let the
2985 # user know that they can use '--skip-po' on subsequent invocations.
2986 func_skip_po_recommendation ()
2987 {
2988     $debug_cmd
2989
2990     test ! -d po \
2991         || $opt_skip_po \
2992         || func_warning recommend "\
2993 If your pofiles are up-to-date, you can rerun bootstrap
2994 as '$progname --skip-po' to avoid redownloading."
2995 }
2996
2997
2998 # func_update_dotversion
2999 # ----------------------
3000 # Even with 'gitlog-to-changelog' generated ChangeLogs, automake
3001 # will not run to completion with no ChangeLog file.
3002 func_update_dotversion ()
3003 {
3004     $debug_cmd
3005
3006     test -f "$build_aux/git-version-gen" && {
3007       _G_message="updating .version"
3008       test -f .version && {
3009         mv .version .version~
3010         func_append _G_message " (backup in .version~)"
3011       }
3012       func_verbose "updating .version"
3013
3014       $build_aux/git-version-gen dummy-arg > .version
3015     }
3016 }
3017
3018
3019
3020 ## -------------------- ##
3021 ## Resource management. ##
3022 ## -------------------- ##
3023
3024 # This section contains definitions for functions that each ensure a
3025 # particular resource (a file, or a non-empty configuration variable for
3026 # example) is available, and if appropriate to extract default values
3027 # from pertinent package files.  Where a variable already has a non-
3028 # empty value (as set by the package's 'bootstrap.conf'), that value is
3029 # used in preference to deriving the default. Call them using their
3030 # associated 'require_*' variable to ensure that they are executed, at
3031 # most, once.
3032
3033
3034 # require_checkout_only_file
3035 # --------------------------
3036 # Bail out  if this package only bootstraps properly from a repository
3037 # checkout.
3038 require_checkout_only_file=func_require_checkout_only_file
3039 func_require_checkout_only_file ()
3040 {
3041     $debug_cmd
3042
3043     $opt_force || {
3044       test -n "$checkout_only_file" && test ! -f "$checkout_only_file" \
3045           && func_fatal_error "\
3046 Bootstrapping from a non-checked-out distribution is risky.
3047 If you wish to bootstrap anyway, use the '--force' option."
3048     }
3049
3050     require_checkout_only_file=:
3051 }
3052
3053
3054 # require_aclocal_amflags
3055 # -----------------------
3056 # Ensure '$aclocal_amflags' has a sensible default, extracted from
3057 # 'Makefile.am' if necessary.
3058 require_aclocal_amflags=func_require_aclocal_amflags
3059 func_require_aclocal_amflags ()
3060 {
3061     $debug_cmd
3062
3063     $require_makefile_am
3064
3065     _G_sed_extract_aclocal_amflags='s|#.*$||
3066         /^[      ]*ACLOCAL_AMFLAGS[      ]*=/ {
3067             s|^.*=[      ]*\(.*\)|aclocal_amflags="\1"|
3068             p
3069         }'
3070
3071     _G_aclocal_flags_cmd=`$SED -n "$_G_sed_extract_aclocal_amflags" \
3072         "$makefile_am"`
3073     eval "$_G_aclocal_flags_cmd"
3074
3075     func_verbose "ACLOCAL_AMFLAGS='$aclocal_amflags'"
3076
3077     require_aclocal_amflags=:
3078 }
3079
3080
3081 # require_autoheader
3082 # ------------------
3083 # Skip autoheader if it's not needed.
3084 require_autoheader=func_require_autoheader
3085 func_require_autoheader ()
3086 {
3087     $debug_cmd
3088
3089     test true = "$AUTOHEADER" || {
3090       func_extract_trace AC_CONFIG_HEADERS
3091       test -n "$func_extract_trace_result" \
3092           || func_extract_trace AC_CONFIG_HEADER
3093
3094       test -n "$func_extract_trace_result" || {
3095         AUTOHEADER=true
3096
3097         func_verbose "export AUTOHEADER='$AUTOHEADER'"
3098
3099         # Make sure the search result is visible to subshells
3100         export AUTOHEADER
3101       }
3102     }
3103
3104     require_autoheader=:
3105 }
3106
3107
3108 # require_autopoint
3109 # -----------------
3110 # Skip autopoint if it's not needed.
3111 require_autopoint=func_require_autopoint
3112 func_require_autopoint ()
3113 {
3114     $debug_cmd
3115
3116     test true = "$AUTOPOINT" || {
3117       func_extract_trace AM_GNU_GETTEXT_VERSION
3118
3119       test -n "$func_extract_trace_result" || {
3120         AUTOPOINT=true
3121
3122         func_verbose "export AUTOPOINT='$AUTOPOINT'"
3123
3124         # Make sure the search result is visible to subshells
3125         export AUTOPOINT
3126       }
3127     }
3128
3129     require_autopoint=:
3130 }
3131
3132
3133 # require_bootstrap_uptodate
3134 # --------------------------
3135 # Complain if the version of bootstrap in the gnulib directory differs
3136 # from the one we are running.
3137 require_bootstrap_uptodate=func_require_bootstrap_uptodate
3138 func_require_bootstrap_uptodate ()
3139 {
3140     $debug_cmd
3141
3142     $require_build_aux
3143
3144     _G_bootstrap_sources="
3145       $build_aux/bootstrap.in
3146       $build_aux/extract-trace
3147       $build_aux/funclib.sh
3148       $build_aux/options-parser
3149     "
3150
3151     _G_missing_bootstrap_sources=false
3152     for _G_src in $_G_bootstrap_sources; do
3153       test -f "$_G_src" || _G_missing_bootstrap_sources=:
3154     done
3155
3156     if $_G_missing_bootstrap_sources; then
3157       func_warning upgrade "\
3158 Please add bootstrap to your gnulib_modules list in
3159 'bootstrap.conf', so that I can tell you when there are
3160 updates available."
3161     else
3162       $build_aux/inline-source $build_aux/bootstrap.in > bootstrap.new
3163
3164       if func_cmp_s "$progpath" bootstrap.new; then
3165         rm -f bootstrap.new
3166         func_verbose "bootstrap script up to date"
3167       else
3168         func_warning upgrade "\
3169 An updated bootstrap script has been generated for you in
3170 'bootstrap.new'.  After you've verified that you want
3171 the changes, you can update with:
3172     cat bootstrap.new > $progname
3173     ./$progname
3174
3175 Or you can disable this check permanently by adding the
3176 following to 'bootstrap.conf':
3177     require_bootstrap_uptodate=:"
3178       fi
3179     fi
3180
3181     require_bootstrap_uptodate=:
3182 }
3183
3184
3185 # require_build_aux
3186 # -----------------
3187 # Ensure that '$build_aux' is set, and if it doesn't already point to an
3188 # existing directory, create one.
3189 require_build_aux=func_require_build_aux
3190 func_require_build_aux ()
3191 {
3192     $debug_cmd
3193
3194     test -n "$build_aux" || {
3195       func_extract_trace_first AC_CONFIG_AUX_DIR
3196       build_aux=$func_extract_trace_first_result
3197       func_check_configuration build_aux \
3198           "AC_CONFIG_AUX_DIR([name of a directory for build scripts])"
3199
3200       func_verbose "build_aux='$build_aux'"
3201     }
3202
3203     $require_vc_ignore_files
3204
3205     # If the build_aux directory doesn't exist, create it now, and mark it
3206     # as ignored for the VCS.
3207     if test ! -d "$build_aux"; then
3208       func_show_eval "mkdir '$build_aux'"
3209
3210       test -n "$vc_ignore_files" \
3211           || func_insert_if_absent "$build_aux" $vc_ignore_files
3212     fi
3213
3214     require_build_aux=:
3215 }
3216
3217
3218 # require_buildreq_autobuild
3219 # --------------------------
3220 # Try to find whether the bootstrap requires autobuild.
3221 require_buildreq_autobuild=func_require_buildreq_autobuild
3222 func_require_buildreq_autobuild ()
3223 {
3224     $debug_cmd
3225
3226     $require_macro_dir
3227
3228     test -f "$macro_dir/autobuild.m4" \
3229         || printf '%s\n' "$buildreq" |func_grep_q '^[    ]*autobuild' \
3230         || {
3231       func_extract_trace AB_INIT
3232       test -n "$func_extract_trace_result" && {
3233         func_append buildreq 'autobuild - http://josefsson.org/autobuild/
3234 '
3235         func_verbose "auto-adding 'autobuild' to build requirements"
3236       }
3237     }
3238
3239     require_buildreq_autobuild=:
3240 }
3241
3242
3243 # require_buildreq_autoconf
3244 # require_buildreq_autopoint
3245 # require_buildreq_libtoolize
3246 # ---------------------------
3247 # Try to find the minimum compatible version of autoconf/libtool
3248 # required to bootstrap successfully, and add it to '$buildreq'.
3249 for tool in autoconf libtoolize autopoint; do
3250   b=$tool
3251   v=require_buildreq_${tool}
3252   f=func_$v
3253   case $tool in
3254     autoconf) m=AC_PREREQ ;;
3255     libtoolize) m=LT_PREREQ; b=libtool ;;
3256     autopoint) m=AM_GNU_GETTEXT_VERSION b=gettext ;;
3257   esac
3258
3259   eval $v'='$f'
3260   '$f' ()
3261   {
3262     $debug_cmd
3263
3264     # The following is ignored if undefined, but might be necessary
3265     # in order for `func_find_tool` to run.
3266     ${require_'$tool'-:}
3267
3268     printf '\''%s\n'\'' "$buildreq" |func_grep_q '\''^[  ]*'$tool\'' || {
3269       func_extract_trace '$m'
3270       _G_version=$func_extract_trace_result
3271       test -n "$_G_version" && {
3272         func_append buildreq "\
3273             '$tool' $_G_version http://www.gnu.org/s/'$b'
3274 "
3275         func_verbose \
3276             "auto-adding '\'$tool'-'$_G_version\'' to build requirements"
3277       }
3278     }
3279
3280     '$v'=:
3281   }
3282 '
3283 done
3284
3285
3286 # require_buildreq_automake
3287 # -------------------------
3288 # Try to find the minimum compatible version of automake required to
3289 # bootstrap successfully, and add it to '$buildreq'.
3290 require_buildreq_automake=func_require_buildreq_automake
3291 func_require_buildreq_automake ()
3292 {
3293     $debug_cmd
3294
3295     # if automake is not already listed in $buildreq...
3296     printf '%s\n' "$buildreq" |func_grep_q automake || {
3297       func_extract_trace AM_INIT_AUTOMAKE
3298
3299       # ...and AM_INIT_AUTOMAKE is declared...
3300       test -n "$func_extract_trace_result" && {
3301         automake_version=`$bs_echo "$func_extract_trace_result" \
3302            |$SED -e 's|[^0-9]*||' -e 's| .*$||'`
3303         test -n "$automake_version" || automake_version=-
3304
3305         func_append buildreq "\
3306             automake $automake_version http://www.gnu.org/s/automake
3307 "
3308         func_verbose \
3309             "auto-adding 'automake-$automake_version' to build requirements"
3310       }
3311     }
3312
3313     require_buildreq_automake=:
3314 }
3315
3316
3317 # require_buildreq_patch
3318 # ----------------------
3319 # Automatically add a patch build-requirement if there are diff files
3320 # in $local_gl_dir.
3321 require_buildreq_patch=func_require_buildreq_patch
3322 func_require_buildreq_patch ()
3323 {
3324     $debug_cmd
3325
3326     $require_local_gl_dir
3327
3328     # This ensures PATCH is set appropriately by the time
3329     # func_check_versions enforces $buildreq.
3330     $require_patch
3331
3332     # If patch is not already listed in $buildreq...
3333     printf '%s\n' "$buildreq" |func_grep_q '^[   ]*patch' || {
3334       # The ugly find invocation is necessary to exit with non-zero
3335       # status for old find binaries that don't support -exec fully.
3336       if test ! -d "$local_gl_dir" \
3337           || find "$local_gl_dir" -name *.diff -exec false {} \; ; then :
3338       else
3339           func_append buildreq 'patch - http://www.gnu.org/s/patch
3340 '
3341       fi
3342     }
3343
3344     require_buildreq_patch=:
3345 }
3346
3347
3348 # require_buildtools_uptodate
3349 # ---------------------------
3350 # Ensure all the packages listed in BUILDREQS are available on the build
3351 # machine at the minimum versions or better.
3352 require_buildtools_uptodate=func_require_buildtools_uptodate
3353 func_require_buildtools_uptodate ()
3354 {
3355     $debug_cmd
3356
3357     $require_buildreq_autobuild
3358     $require_buildreq_autoconf
3359     $require_buildreq_automake
3360     $require_buildreq_libtoolize
3361     $require_buildreq_autopoint
3362     $require_buildreq_patch
3363
3364     test -n "$buildreq" && {
3365       _G_error_hdr=
3366
3367       func_check_versions $buildreq
3368       $func_check_versions_result || {
3369         test -n "$buildreq_readme" \
3370             && test -f "$buildreq_readme" \
3371             && _G_error_hdr="\
3372 $buildreq_readme explains how to obtain these prerequisite programs:
3373 "
3374         func_strtable 0 11 12 36 \
3375             "Program" "Min_version" "Homepage" $buildreq
3376         func_fatal_error "$_G_error_hdr$func_strtable_result"
3377       }
3378     }
3379
3380     require_buildtools_uptodate=:
3381 }
3382
3383
3384 # require_copyright_holder
3385 # ------------------------
3386 # Ensure there is a sensible non-empty default value in '$copyright_holder'.
3387 require_copyright_holder=func_require_copyright_holder
3388 func_require_copyright_holder ()
3389 {
3390     $debug_cmd
3391
3392     test -n "$copyright_holder" || {
3393       copyright_holder='Free Software Foundation, Inc.'
3394       func_warning settings "\
3395 Please set copyright_holder explicitly in 'bootstrap.conf';
3396 defaulting to '$copyright_holder'."
3397     }
3398
3399     require_copyright_holder=:
3400 }
3401
3402
3403 # require_doc_base
3404 # ----------------
3405 # Ensure doc_base has a sensible value, extracted from 'gnulib-cache.m4'
3406 # if possible, otherwise letting 'gnulib-tool' pick a default.
3407 require_doc_base=func_require_doc_base
3408 func_require_doc_base ()
3409 {
3410     $debug_cmd
3411
3412     $require_gnulib_cache
3413
3414     test -f "$gnulib_cache" && test -z "$doc_base" && {
3415       func_extract_trace_first "gl_DOC_BASE" "$gnulib_cache"
3416       doc_base=$func_extract_trace_first_result
3417
3418       test -n "$doc_base" && func_verbose "doc_base='$doc_base'"
3419     }
3420
3421     require_doc_base=:
3422 }
3423
3424
3425 # require_dotgitmodules
3426 # ---------------------
3427 # Ensure we have a '.gitmodules' file, with appropriate 'gnulib' settings.
3428 require_dotgitmodules=func_require_dotgitmodules
3429 func_require_dotgitmodules ()
3430 {
3431     $debug_cmd
3432
3433     $require_git
3434
3435     test true = "$GIT" || {
3436       # A gnulib entry in .gitmodules always takes precedence.
3437       _G_path=`$GIT config --file .gitmodules submodule.gnulib.path 2>/dev/null`
3438
3439       test -n "$_G_path" || {
3440         $require_vc_ignore_files
3441
3442         func_verbose "creating '.gitmodules'"
3443
3444         # If the .gitmodules file doesn't exist, create it now, and mark
3445         # it as ignored for the VCS.
3446         test -n "$gnulib_path" || gnulib_path=gnulib
3447         test -n "$gnulib_url"  || gnulib_url=git://git.sv.gnu.org/gnulib
3448
3449         {
3450           echo '[submodule "gnulib"]'
3451           echo "        path = $gnulib_path"
3452           echo "        url = $gnulib_url"
3453         } >> .gitmodules
3454
3455         test -n "$vc_ignore_files" \
3456           || func_insert_if_absent ".gitmodules" $vc_ignore_files
3457       }
3458     }
3459
3460     require_dotgitmodules=:
3461 }
3462
3463
3464 # require_extra_locale_categories
3465 # -------------------------------
3466 # Ensure there is a default value in '$extra_locale_categories'
3467 require_extra_locale_categories=func_require_extra_locale_categories
3468 func_require_extra_locale_categories ()
3469 {
3470     $debug_cmd
3471
3472     # Defaults to empty, so run with whatever value may have been set in
3473     # 'bootstrap.conf'.
3474     require_extra_locale_categories=:
3475 }
3476
3477
3478 # require_git
3479 # -----------
3480 # Ignore git if it's not available, or we're not in a git checkout tree.
3481 require_git=func_require_git
3482 func_require_git ()
3483 {
3484     $debug_cmd
3485
3486     $opt_skip_git && GIT=true
3487
3488     test true = "$GIT" || {
3489       if test -f .gitignore && ($GIT --version) >/dev/null 2>&1; then :; else
3490       GIT=true
3491       fi
3492     }
3493
3494     func_verbose "GIT='$GIT'"
3495
3496     require_git=:
3497 }
3498
3499
3500 # require_gnulib_cache
3501 # --------------------
3502 # Ensure there is a non-empty default for '$gnulib_cache', and that it
3503 # names an existing file.
3504 require_gnulib_cache=func_require_gnulib_cache
3505 func_require_gnulib_cache ()
3506 {
3507     $debug_cmd
3508
3509     $require_macro_dir
3510
3511     test -n "$gnulib_cache" \
3512       || gnulib_cache=$macro_dir/gnulib-cache.m4
3513
3514     func_verbose "found '$gnulib_cache'"
3515
3516     require_gnulib_cache=:
3517 }
3518
3519
3520 # require_gnulib_copy_cmd
3521 # -----------------------
3522 # Only calculate the options for copying files with gnulib once.
3523 require_gnulib_copy_cmd=func_require_gnulib_copy_cmd
3524 func_require_gnulib_copy_cmd ()
3525 {
3526     $debug_cmd
3527
3528     $require_gnulib_tool
3529     $require_gnulib_tool_base_options
3530
3531     gnulib_copy_cmd="$gnulib_tool $gnulib_tool_base_options --copy-file"
3532     $opt_copy || func_append gnulib_copy_cmd " --symlink"
3533     $opt_quiet || func_append gnulib_copy_cmd " --verbose"
3534
3535     require_gnulib_copy_cmd=:
3536 }
3537
3538
3539 # require_gnulib_merge_changelog
3540 # ------------------------------
3541 # See if we can use gnulib's git-merge-changelog merge driver.
3542 require_gnulib_merge_changelog=func_require_gnulib_merge_changelog
3543 func_require_gnulib_merge_changelog ()
3544 {
3545     $debug_cmd
3546
3547     test -f ChangeLog && {
3548       $require_git
3549
3550       func_grep_q '^\(/\|\)ChangeLog$' .gitignore || test true = "$GIT" || {
3551         if $GIT config merge.merge-changelog.driver >/dev/null; then
3552           :
3553         elif (git-merge-changelog --version) >/dev/null 2>&1; then
3554           func_echo "initializing git-merge-changelog driver"
3555           $GIT config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
3556           $GIT config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
3557         else
3558           func_warning recommend \
3559               "Consider installing git-merge-changelog from gnulib."
3560         fi
3561       }
3562     }
3563
3564     require_gnulib_merge_changelog=:
3565 }
3566
3567
3568 # require_gnulib_mk
3569 # -----------------
3570 # Ensure gnulib_mk has a sensible value, extracted from 'gnulib-cache.m4'
3571 # if possible, otherwise letting 'gnulib-tool' pick a default.
3572 require_gnulib_mk=func_require_gnulib_mk
3573 func_require_gnulib_mk ()
3574 {
3575     $debug_cmd
3576
3577     $require_gnulib_cache
3578
3579     test -f "$gnulib_cache" && test -z "$gnulib_mk" && {
3580       func_extract_trace_first "gl_MAKEFILE_NAME" "$gnulib_cache"
3581       gnulib_mk=$func_extract_trace_first_result
3582
3583       test -n "$gnulib_mk" && func_verbose "gnulib_mk='$gnulib_mk'"
3584     }
3585
3586     require_gnulib_mk=:
3587 }
3588
3589
3590 # require_gnulib_name
3591 # -------------------
3592 # Ensure gnulib_name has a sensible value, extracted from 'gnulib-cache.m4'
3593 # if possible, otherwise letting 'gnulib-tool' pick a default.
3594 require_gnulib_name=func_require_gnulib_name
3595 func_require_gnulib_name ()
3596 {
3597     $debug_cmd
3598
3599     $require_gnulib_cache
3600
3601     test -f "$gnulib_cache" && test -z "$gnulib_name" && {
3602       func_extract_trace_first "gl_LIB" "$gnulib_cache"
3603       gnulib_name=$func_extract_trace_first_result
3604
3605       test -n "$gnulib_name" && func_verbose "gnulib_name='$gnulib_name'"
3606     }
3607
3608     require_gnulib_name=:
3609 }
3610
3611
3612 # require_gnulib_path
3613 # require_gnulib_url
3614 # -------------------
3615 # Ensure 'gnulib_path' and 'gnulib_url' are set.
3616 require_gnulib_path=func_require_dotgitmodules_parameters
3617 require_gnulib_url=func_require_dotgitmodules_parameters
3618 func_require_dotgitmodules_parameters ()
3619 {
3620     $debug_cmd
3621
3622     $require_git
3623
3624     test true = "$GIT" && {
3625       # If we can't find git (or if the user specified '--skip-git'),
3626       # then use an existing gnulib directory specified with
3627       # '--gnulib-srcdir' if possible.
3628       test -n "$gnulib_path" \
3629           || test ! -x "$opt_gnulib_srcdir/gnulib-tool" \
3630           || gnulib_path=$opt_gnulib_srcdir
3631     }
3632
3633
3634     $require_dotgitmodules
3635
3636     test -f .gitmodules && {
3637       # Extract the parameters with sed, since git may be missing
3638       test -n "$gnulib_path" \
3639         || gnulib_path=`$SED -e '/^.submodule "gnulib".$/,${
3640                                    /[    ]*path *= */{
3641                                      s|[   ]*||g;s|^[^=]*=||;p
3642                                    }
3643                                  }
3644                                  d' .gitmodules |$SED 1q`
3645       test -n "$gnulib_url" \
3646         || gnulib_url=`$SED -e '/^.submodule "gnulib".$/,${
3647                                   /[     ]*url *= */{
3648                                     s|[   ]*||g;s|^[^=]*=||;p
3649                                   }
3650                                 }
3651                                 d' .gitmodules |$SED 1q`
3652
3653       func_verbose "gnulib_path='$gnulib_path'"
3654       func_verbose "gnulib_url='$gnulib_url'"
3655     }
3656
3657     require_gnulib_path=:
3658     require_gnulib_url=:
3659 }
3660
3661
3662 # require_gnulib_submodule
3663 # ------------------------
3664 # Ensure that there is a current gnulib submodule at '$gnulib_path'.
3665 require_gnulib_submodule=func_require_gnulib_submodule
3666 func_require_gnulib_submodule ()
3667 {
3668     $debug_cmd
3669
3670     $require_git
3671
3672     if test true = "$GIT"; then
3673       func_warning recommend \
3674           "No 'git' found; imported gnulib modules may be outdated."
3675     else
3676       $require_gnulib_path
3677       $require_gnulib_url
3678
3679       if test -f .gitmodules && test -f "$gnulib_path/gnulib-tool"; then
3680         : All present and correct.
3681
3682       elif test -n "$opt_gnulib_srcdir"; then
3683         # Older git can't clone into an empty directory.
3684         rmdir "$gnulib_path" 2>/dev/null
3685         func_show_eval "$GIT clone --reference '$opt_gnulib_srcdir' \
3686                 '$gnulib_url' '$gnulib_path'" \
3687             || func_fatal_error "Unable to fetch gnulib submodule."
3688
3689       # Without --gnulib-srcdir, and no existing checked out submodule, we
3690       # create a new shallow clone of the remote gnulib repository.
3691       else
3692         trap func_cleanup_gnulib 1 2 13 15
3693
3694         shallow=
3695         $GIT clone -h 2>&1 |func_grep_q -- --depth \
3696             && shallow='--depth 365'
3697
3698         func_show_eval "$GIT clone $shallow '$gnulib_url' '$gnulib_path'" \
3699           func_cleanup_gnulib
3700
3701         # FIXME: Solaris /bin/sh will try to execute '-' if any of
3702         #        these signals are caught after this.
3703         trap - 1 2 13 15
3704       fi
3705
3706       # Make sure we've checked out the correct revision of gnulib.
3707       func_show_eval "$GIT submodule init" \
3708           && func_show_eval "$GIT submodule update" \
3709           ||  func_fatal_error "Unable to update gnulib submodule."
3710     fi
3711
3712     require_gnulib_submodule=:
3713 }
3714
3715
3716 # require_gnulib_tool
3717 # -------------------
3718 # Ensure that '$gnulib_tool' is set, and points to an executable file,
3719 # or else fall back to using the binary 'true' if the main gnulib
3720 # files appear to have been imported already.
3721 require_gnulib_tool=func_require_gnulib_tool
3722 func_require_gnulib_tool ()
3723 {
3724     $debug_cmd
3725
3726     test true = "$gnulib_tool" || {
3727       $require_gnulib_submodule
3728       $require_gnulib_path
3729
3730       test -n "$gnulib_tool" \
3731         || gnulib_tool=$gnulib_path/gnulib-tool
3732
3733       test -x "$gnulib_tool" || {
3734         gnulib_tool=true
3735         func_warning recommend \
3736             "No 'gnulib-tool' found; gnulib modules may be missing."
3737       }
3738
3739       test true = "$gnulib_tool" \
3740           || func_verbose "found '$gnulib_tool'"
3741     }
3742
3743     require_gnulib_tool=:
3744 }
3745
3746
3747 # require_gnulib_tool_base_options
3748 # --------------------------------
3749 # Ensure that '$gnulib_tool_base_options' contains all the base options
3750 # required according to user configuration from bootstrap.conf.
3751 require_gnulib_tool_base_options=func_require_gnulib_tool_base_options
3752 func_require_gnulib_tool_base_options ()
3753 {
3754     $debug_cmd
3755
3756     $require_gnulib_tool
3757
3758     gnulib_tool_base_options=
3759
3760     test true = "$gnulib_tool" || {
3761       # 'gnulib_modules' and others are maintained in 'bootstrap.conf':
3762       # Use 'gnulib --import' to fetch gnulib modules.
3763       $require_build_aux
3764       test -n "$build_aux" \
3765           && func_append_uniq gnulib_tool_base_options " --aux-dir=$build_aux"
3766       $require_macro_dir
3767       test -n "$macro_dir" \
3768           && func_append_uniq gnulib_tool_base_options " --m4-base=$macro_dir"
3769       $require_doc_base
3770       test -n "$doc_base" \
3771           && func_append_uniq gnulib_tool_base_options " --doc-base=$doc_base"
3772       $require_gnulib_name
3773       test -n "$gnulib_name" \
3774           && func_append_uniq gnulib_tool_base_options " --lib=$gnulib_name"
3775       $require_local_gl_dir
3776       test -n "$local_gl_dir" \
3777           && func_append_uniq gnulib_tool_base_options " --local-dir=$local_gl_dir"
3778       $require_source_base
3779       test -n "$source_base" \
3780           && func_append_uniq gnulib_tool_base_options " --source-base=$source_base"
3781     }
3782
3783     require_gnulib_tool_base_options=:
3784 }
3785
3786
3787 # require_libtoolize
3788 # ------------------
3789 # Skip libtoolize if it's not needed.
3790 require_libtoolize=func_require_libtoolize
3791 func_require_libtoolize ()
3792 {
3793     $debug_cmd
3794
3795     # Unless we're not searching for libtool use by this package, set
3796     # LIBTOOLIZE to true if none of 'LT_INIT', 'AC_PROG_LIBTOOL' and
3797     # 'AM_PROG_LIBTOOL' are used in configure.
3798     test true = "$LIBTOOLIZE" || {
3799       func_extract_trace LT_INIT
3800       test -n "$func_extract_trace_result" || func_extract_trace AC_PROG_LIBTOOL
3801       test -n "$func_extract_trace_result" || func_extract_trace AM_PROG_LIBTOOL
3802       test -n "$func_extract_trace_result" || LIBTOOLIZE=true
3803     }
3804
3805     test -n "$LIBTOOLIZE" || {
3806       # Find libtoolize, named glibtoolize in Mac Ports, but prefer
3807       # user-installed libtoolize to ancient glibtoolize shipped by
3808       # Apple with Mac OS X when Mac Ports is not installed.
3809       func_find_tool LIBTOOLIZE libtoolize glibtoolize
3810     }
3811
3812     func_verbose "export LIBTOOLIZE='$LIBTOOLIZE'"
3813
3814     # Make sure the search result is visible to subshells
3815     export LIBTOOLIZE
3816
3817     require_libtoolize=:
3818 }
3819
3820
3821 # require_local_gl_dir
3822 # --------------------
3823 # Ensure local_gl_dir has a sensible value, extracted from 'gnulib-cache.m4'
3824 # if possible, otherwise letting 'gnulib-tool' pick a default.
3825 require_local_gl_dir=func_require_local_gl_dir
3826 func_require_local_gl_dir ()
3827 {
3828     $debug_cmd
3829
3830     $require_gnulib_cache
3831
3832     test -f "$gnulib_cache" && test -z "$local_gl_dir" && {
3833       func_extract_trace_first "gl_LOCAL_DIR" "$gnulib_cache"
3834       local_gl_dir=$func_extract_trace_first_result
3835
3836       test -n "$local_gl_dir" && func_verbose "local_gl_dir='$local_gl_dir'"
3837     }
3838
3839     require_local_gl_dir=:
3840 }
3841
3842
3843 # require_macro_dir
3844 # -----------------
3845 # Ensure that '$macro_dir' is set, and if it doesn't already point to an
3846 # existing directory, create one.
3847 require_macro_dir=func_require_macro_dir
3848 func_require_macro_dir ()
3849 {
3850     $debug_cmd
3851
3852     # Sometimes this is stored in 'configure.ac'.
3853     test -n "$macro_dir" || {
3854       # AC_CONFIG_MACRO_DIRS takes a space delimited list of directories,
3855       # but we only care about the first one in bootstrap.
3856       func_extract_trace_first AC_CONFIG_MACRO_DIRS
3857       macro_dir=`expr "x$func_extract_trace_first_result" : 'x\([^       ]*\)'`
3858     }
3859     test -n "$macro_dir" || {
3860       func_extract_trace_first AC_CONFIG_MACRO_DIR
3861       macro_dir=$func_extract_trace_first_result
3862     }
3863
3864     # Otherwise we might find it in 'Makefile.am'.
3865     test -n "$macro_dir" || {
3866       $require_aclocal_amflags
3867
3868       # Take the argument following the first '-I', if any.
3869       _G_minus_I_seen=false
3870       for _G_arg in $aclocal_amflags; do
3871         case $_G_minus_I_seen,$_G_arg in
3872           :,*)   macro_dir=$_G_arg; break ;;
3873           *,-I)  _G_minus_I_seen=: ;;
3874           *,-I*) macro_dir=`expr x$_G_arg : 'x-I\(.*\)$'`; break ;;
3875         esac
3876       done
3877     }
3878
3879     func_verbose "macro_dir='$macro_dir'"
3880
3881     func_check_configuration macro_dir \
3882         "AC_CONFIG_MACRO_DIRS([name of a directory for configure m4 files])"
3883
3884     $require_vc_ignore_files
3885
3886     # If the macro_dir directory doesn't exist, create it now, and mark it
3887     # as ignored for the VCS.
3888     if test ! -d "$macro_dir"; then
3889       mkdir "$macro_dir" || func_permissions_error "$macro_dir"
3890
3891       test -n "$vc_ignore_files" \
3892         || func_insert_if_absent "$macro_dir" $vc_ignore_files
3893     fi
3894
3895     require_macro_dir=:
3896 }
3897
3898
3899 # require_makefile_am
3900 # -------------------
3901 # Ensure there is a 'Makefile.am' in the current directory.
3902 # names an existing file.
3903 require_makefile_am=func_require_makefile_am
3904 func_require_makefile_am ()
3905 {
3906     $debug_cmd
3907
3908     test -n "$makefile_am" \
3909       || makefile_am=Makefile.am
3910
3911     <"$makefile_am"
3912
3913     func_verbose "found '$makefile_am'"
3914
3915     require_makefile_am=:
3916 }
3917
3918
3919 # require_package
3920 # ---------------
3921 # Ensure that '$package' contains a sensible default value.
3922 require_package=func_require_package
3923 func_require_package ()
3924 {
3925     $debug_cmd
3926
3927     test -n "$package" || {
3928       $require_package_name
3929
3930       package=`echo "$package_name" \
3931         |$SED -e 's/GNU //' \
3932               -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
3933     }
3934
3935     func_verbose "package='$package'"
3936
3937     require_package=:
3938 }
3939
3940
3941 # require_package_bugreport
3942 # -------------------------
3943 # Ensure that this has a sensible value, extracted from 'configure.ac'
3944 # if appropriate (and possible!).
3945 require_package_bugreport=func_require_package_bugreport
3946 func_require_package_bugreport ()
3947 {
3948     $debug_cmd
3949
3950     func_extract_trace AC_INIT
3951
3952     save_ifs=$IFS
3953     IFS=:
3954     set dummy $func_extract_trace_result
3955     IFS=$save_ifs
3956     shift
3957
3958     test -n "$package_bugreport" || package_bugreport=$3
3959     func_check_configuration package_bugreport \
3960       "AC_INIT([$package_name], [$package_version], [bug-$package@gnu.org])"
3961     func_verbose "package_bugreport='$package_bugreport'"
3962
3963     require_package_bugreport=:
3964 }
3965
3966
3967 # require_package_name
3968 # --------------------
3969 # Ensure that this has a sensible value, extracted from 'configure.ac'
3970 # if appropriate (and possible!).
3971 require_package_name=func_require_package_name
3972 func_require_package_name ()
3973 {
3974     $debug_cmd
3975
3976     func_extract_trace AC_INIT
3977
3978     save_ifs=$IFS
3979     IFS=:
3980     set dummy $func_extract_trace_result
3981     IFS=$save_ifs
3982     shift
3983
3984     test -n "$package_name" || package_name=$1
3985     func_check_configuration package_name \
3986       "AC_INIT([name of your package], [package version number])"
3987     func_verbose "package_name='$package_name'"
3988
3989     require_package_name=:
3990 }
3991
3992
3993 # require_package_version
3994 # -----------------------
3995 # Ensure that this has a sensible value, extracted from 'configure.ac'
3996 # if appropriate (and possible!).  While we might have set all the
3997 # parameters extracted from AC_INIT at once, 'package_version' in
3998 # particular is not necessarily available as early as the others, since
3999 # 'git-version-gen' is often involved, and until then we can't rely on
4000 # getting a correct version number from an AC_INIT extraction.
4001 require_package_version=func_require_package_version
4002 func_require_package_version ()
4003 {
4004     $debug_cmd
4005
4006     func_extract_trace AC_INIT
4007
4008     save_ifs=$IFS
4009     IFS=:
4010     set dummy $func_extract_trace_result
4011     IFS=$save_ifs
4012     shift
4013
4014     test -n "$package_version" || package_version=$2
4015     test -n "$package_version" || {
4016       # The embedded echo is to squash whitespace before globbing.
4017       case " "`echo $gnulib_modules`" " in
4018         *" git-version-gen "*)
4019           func_fatal_error "\
4020 cannot \$require_package_version in bootstrap.conf before
4021 func_gnulib_tool has installed the 'git-version-gen' script."
4022           ;;
4023         *)
4024           func_check_configuration package_version \
4025             "AC_INIT([name of your package], [package version number])"
4026           ;;
4027       esac
4028     }
4029     func_verbose "package_version='$package_version'"
4030
4031     require_package_version=:
4032 }
4033
4034
4035 # require_patch
4036 # -------------
4037 # Find patch, according to the PATCH environment variable, or else
4038 # searching the user's PATH.
4039 require_patch=func_require_patch
4040 func_require_patch ()
4041 {
4042     $debug_cmd
4043
4044     test -n "$PATCH" || {
4045       # Find a patch program, preferring gpatch, which is usually better
4046       # than the vendor patch.
4047       func_find_tool PATCH gpatch patch
4048     }
4049
4050     func_verbose "export PATCH='$PATCH'"
4051
4052     # Make sure the search result is visible to subshells
4053     export PATCH
4054
4055     require_patch=:
4056 }
4057
4058
4059 # require_source_base
4060 # -------------------
4061 # Ensure that source_base has a sensible value, extracted from
4062 # 'gnulib-cache.m4' if possible.
4063 require_source_base=func_require_source_base
4064 func_require_source_base ()
4065 {
4066     $debug_cmd
4067
4068     $require_gnulib_cache
4069
4070     test -f "$gnulib_cache" && test -z "$source_base" && {
4071       func_extract_trace_first "gl_SOURCE_BASE" "$gnulib_cache"
4072
4073       source_base=$func_extract_trace_first_result
4074
4075       func_verbose "source_base='$source_base'"
4076     }
4077
4078     require_source_base=:
4079 }
4080
4081
4082 # require_vc_ignore_files
4083 # -----------------------
4084 # Ensure that '$vc_ignore' has been processed to list VCS ignore files
4085 # in '$vc_ignore_files'
4086 require_vc_ignore_files=func_require_vc_ignore_files
4087 func_require_vc_ignore_files ()
4088 {
4089     $debug_cmd
4090
4091     test -n "$vc_ignore" || vc_ignore=auto
4092
4093     if test auto = "$vc_ignore" && test -z "$vc_ignore_files"; then
4094       vc_ignore_files=
4095       test -d .git && vc_ignore_files=.gitignore
4096       test -d CVS && vc_ignore_files="$vc_ignore_files .cvsignore"
4097     else
4098       vc_ignore_files=$vc_ignore
4099     fi
4100
4101     func_verbose "vc_ignore_files='$vc_ignore_files'"
4102
4103     require_vc_ignore_files=:
4104 }
4105
4106
4107 ## ------------------##
4108 ## Helper functions. ##
4109 ## ------------------##
4110
4111 # This section contains the helper functions used by the rest of 'bootstrap'.
4112
4113 # func_len STRING
4114 # ---------------
4115 # STRING may not start with a hyphen.
4116 if (eval 'x=123; test x${#x} = "x3"') 2>/dev/null
4117 then
4118   # This is an XSI compatible shell, allowing a faster implementation...
4119   eval 'func_len ()
4120   {
4121     $debug_cmd
4122
4123     func_len_result=${#1}
4124   }'
4125 else
4126   # ...otherwise fall back to using expr, which is often a shell builtin.
4127   func_len ()
4128   {
4129     $debug_cmd
4130
4131     func_len_result=`expr "$1" : ".*" 2>/dev/null || echo 0`
4132   }
4133 fi
4134
4135
4136 # func_unset VAR
4137 # --------------
4138 # Portably unset VAR.
4139 # In some shells, an 'unset VAR' statement leaves a non-zero return
4140 # status if VAR is already unset, which might be problematic if the
4141 # statement is used at the end of a function (thus poisoning its return
4142 # value) or when 'set -e' is active (causing even a spurious abort of
4143 # the script in this case).
4144 func_unset ()
4145 {
4146     { eval $1=; unset $1; }
4147 }
4148 unset=func_unset
4149
4150
4151 # func_cmp_s FILE1 FILE2
4152 # ----------------------
4153 # Return non-zero exit status unless FILE1 and FILE2 are identical, without
4154 # any output at all, even error messages.
4155 func_cmp_s ()
4156 {
4157     $debug_cmd
4158
4159     # This function relies on non-zero exit status, which will cause the
4160     # program to exit when running in 'set -e' mode.
4161     $CMP "$@" >/dev/null 2>&1
4162 }
4163
4164
4165 # func_grep_q EXPRESSION [FILENAME..]
4166 # -----------------------------------
4167 # Check whether EXPRESSION matches any line of any listed FILENAME,
4168 # without any output at all, even error messages.
4169 func_grep_q ()
4170 {
4171     $debug_cmd
4172
4173     # This function relies on non-zero exit status, which will cause the
4174     # program to exit when running in 'set -e' mode.
4175     $GREP "$@" >/dev/null 2>&1
4176 }
4177
4178
4179 # func_ifcontains LIST MEMBER YES-CMD [NO-CMD]
4180 # --------------------------------------------
4181 # If whitespace-separated LIST contains MEMBER then execute YES-CMD,
4182 # otherwise if NO-CMD was give, execute that.
4183 func_ifcontains ()
4184 {
4185     $debug_cmd
4186
4187     # The embedded echo is to squash whitespace before globbing.
4188     _G_wslist=`$bs_echo " "$1" "`
4189     _G_member=$2
4190     _G_yes_cmd=$3
4191     _G_no_cmd=${4-":"}
4192
4193     case $_G_wslist in
4194       *" $_G_member "*)
4195         eval "$_G_yes_cmd"
4196         _G_status=$?
4197         ;;
4198       *)
4199         eval "$_G_no_cmd"
4200         _G_status=$?
4201         ;;
4202     esac
4203
4204     test 0 -eq "$_G_status" || exit $_G_status
4205 }
4206
4207
4208 # func_strpad STR WIDTH CHAR
4209 # --------------------------
4210 # Trim STR, or pad with CHAR to force a total length of WIDTH.
4211 func_strpad ()
4212 {
4213     $debug_cmd
4214
4215     _G_width=`expr "$2" - 1`
4216     func_strpad_result=`$bs_echo "$1" |$SED '
4217         :a
4218         s|^.\{0,'"$_G_width"'\}$|&'"$3"'|
4219         ta
4220     '`
4221 }
4222
4223
4224 # func_strrpad STR WIDTH CHAR
4225 # ---------------------------
4226 # Trim STR, or right-justify-pad with CHAR to force a total length of
4227 # WIDTH.
4228 func_strrpad ()
4229 {
4230     $debug_cmd
4231
4232     _G_width=`expr "$2" - 1`
4233     func_strrpad_result=`$bs_echo "$1" |$SED '
4234         :a
4235         s|^.\{0,'"$_G_width"'\}$|'"$3"'&|
4236         ta
4237     '`
4238 }
4239
4240
4241 # func_strrow INDENT FIELD WIDTH [FIELDn WIDTHn]...
4242 # -------------------------------------------------
4243 # Return a string containing each FIELD left justified to WIDTH, with
4244 # the whole thing indented by INDENT spaces.  This function is used to
4245 # render one row of aligned columns for a table by func_strtable().
4246 func_strrow ()
4247 {
4248     $debug_cmd
4249
4250     func_strrow_linelen=$1; shift
4251
4252     _G_row=
4253     while test $# -gt 0; do
4254       func_strrow_linelen=`expr $func_strrow_linelen + $2`
4255       func_strpad "$1" $2 " "
4256       func_append _G_row "$func_strpad_result"
4257       shift; shift
4258     done
4259
4260     func_strrpad "$_G_row" $func_strrow_linelen " "
4261     func_strrow_result=$func_strrpad_result
4262 }
4263
4264
4265 # func_strtable INDENT WIDTH1...WIDTHn HEADER1...HEADERn FIELD1...FIELDn
4266 # ----------------------------------------------------------------------
4267 # Generate a string of newline-separated rows arranged in lined-up
4268 # columns of the given WIDTHs, with the entire table indented by INDENT
4269 # spaces.  The number of columns is determined by the number of integer
4270 # valued WIDTH arguments following INDENT.  The next set (i.e. a number
4271 # of arguments equal to the number of WIDTH arguments) of fields are
4272 # treated as the table's column HEADERs, and are separated from the
4273 # remainder of the table by an indented row of '-' characters. Remaining
4274 # arguments are each aligned below the next available header, wrapping
4275 # to a new row as necessary.  Finally another row of '-' characters is
4276 # added to mark the end of the table.
4277 #
4278 # For example an unindented 3 column table with 2 rows of data would be
4279 # generated by this call:
4280 #
4281 #    func_strtable 3 20 10 25 \
4282 #        Header1 Header2 Header3 \
4283 #        Row1Col1 Row1Col2 Row1Col3 \
4284 #        Row2Col1 Row2Col2 Row2Col3
4285 #
4286 # returning the following string:
4287 #
4288 # "   Header1             Header2   Header3
4289 #     -------------------------------------------------------
4290 #     Row1Col1            Row1Col2  Row1Col3
4291 #     Row2Col1            Row2Col2  Row2Col3
4292 #     -------------------------------------------------------"
4293 func_strtable ()
4294 {
4295     $debug_cmd
4296
4297     # Save the indent value, we'll need it for each row we render.
4298     _G_indent=$1; shift
4299
4300     # Collect remaining numeric args into a list for reuse between
4301     # members of each row when we call func_strrow later.
4302     _G_widths=$1; shift
4303     while test 0 -lt `expr "$1" : '[1-9][0-9]*$'`; do
4304       func_append _G_widths " $1"; shift
4305     done
4306
4307     # Extract the same number of positional parameters as there are
4308     # width elements - we'll do the header rows separately so that
4309     # we can insert a divider line.
4310     _G_header=$_G_indent
4311     for _G_width in $_G_widths; do
4312       func_append _G_header " $1 $_G_width"; shift
4313     done
4314     func_strrow $_G_header
4315
4316     # Strip off the indent, and make a divider with '-' chars, then
4317     # reindent.
4318     _G_divider=`$bs_echo "$func_strrow_result" \
4319         |$SED 's|[^ ]|-|g
4320             :a
4321             s|- |--|g
4322             ta
4323         '`
4324
4325     # Append the header and divider to the running result.
4326     func_append func_strtable_result "\
4327 $func_strrow_result
4328 $_G_divider
4329 "
4330
4331     # The remaining rows are zipped between the width values we
4332     # unwound earlier just like the header row above.
4333     while test $# -gt 0; do
4334       _G_row=$_G_indent
4335       for _G_width in $_G_widths; do
4336         func_append _G_row " $1 $_G_width"; shift
4337       done
4338       func_strrow $_G_row
4339       func_append func_strtable_result "\
4340 $func_strrow_result
4341 "
4342     done
4343
4344     # Mark the end of the table with a final divider line.
4345     func_append func_strtable_result "$_G_divider"
4346 }
4347
4348
4349 # func_internal_error ARG...
4350 # --------------------------
4351 # Echo program name prefixed message to standard error, and exit.
4352 func_internal_error ()
4353 {
4354     func_fatal_error "\
4355 INTERNAL: " ${1+"$@"} "
4356           Please report this bug to 'bug-gnulib@gnu.org'
4357           in as much detail as possible."
4358 }
4359
4360
4361 # func_permissions_error FILE-OR-DIRECTORY
4362 # ----------------------------------------
4363 # Echo program name prefixed permissions error message to standard
4364 # error, and exit.
4365 func_permissions_error ()
4366 {
4367     $debug_cmd
4368
4369     func_fatal_error "Failed to create '$1', check permissions."
4370 }
4371
4372
4373 # func_show_eval CMD [FAIL_EXP]
4374 # -----------------------------
4375 # Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
4376 # not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
4377 # is given, then evaluate it.
4378 func_show_eval ()
4379 {
4380     $debug_cmd
4381
4382     $require_term_colors
4383
4384     _G_cmd=$1
4385     _G_fail_exp=${2-':'}
4386
4387     ${opt_silent-'false'} || {
4388       func_quote_for_eval $_G_cmd
4389       eval func_truncate_cmd $func_quote_for_eval_result
4390       func_echo "running: $tc_bold$func_truncate_cmd_result$tc_reset"
4391     }
4392
4393     ${opt_dry_run-'false'} || {
4394       eval "$_G_cmd"
4395       _G_status=$?
4396       test 0 -eq "$_G_status" || eval "(exit $_G_status); $_G_fail_exp"
4397     }
4398 }
4399
4400
4401 # func_truncate_cmd CMD [ARG]...
4402 # ------------------------------
4403 # For unreasonably long commands (such as a gnulib-tool invocation with
4404 # the full module list for import), truncate CMD after the second non-
4405 # option ARG.
4406 func_truncate_cmd ()
4407 {
4408     $debug_cmd
4409
4410     _G_last_arg_opt_p=false
4411     func_truncate_cmd_result=
4412
4413     set dummy "$@"; shift
4414
4415     while test $# -gt 0; do
4416       _G_opt=$1; shift
4417
4418       test -n "$func_truncate_cmd_result" \
4419           && func_append func_truncate_cmd_result ' '
4420       func_append func_truncate_cmd_result "$_G_opt"
4421
4422       func_len "x$func_truncate_cmd_result"
4423
4424       case $_G_opt in
4425         -*) _G_last_arg_opt_p=: ;;
4426         *)  $_G_last_arg_opt_p \
4427                 || test "$min_cmd_len" -gt "$func_len_result" \
4428                 || break
4429             _G_last_arg_opt_p=false
4430             ;;
4431       esac
4432     done
4433
4434     test $# -gt 0 && func_append func_truncate_cmd_result "..."
4435 }
4436
4437
4438 # func_gitignore_entries FILE...
4439 # ------------------------------
4440 # Strip blank and comment lines to leave significant entries.
4441 func_gitignore_entries ()
4442 {
4443     $debug_cmd
4444
4445     sed -e '/^#/d' -e '/^$/d' "$@"
4446 }
4447
4448
4449 # func_insert_if_absent STR FILE...
4450 # ---------------------------------
4451 # If $STR is not already on a line by itself in $FILE, insert it, at the
4452 # start.  Entries are inserted at the start of the ignore list to ensure
4453 # existing entries starting with ! are not overridden.  Such entries
4454 # support whilelisting exceptions after a more generic blacklist pattern.
4455 # sorting the new contents of the file and replacing $FILE with the result.
4456 func_insert_if_absent ()
4457 {
4458     $debug_cmd
4459
4460     str=$1
4461     shift
4462
4463     for file
4464     do
4465       test -f "$file" || touch "$file"
4466
4467       duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
4468       test -n "$duplicate_entries" \
4469           && func_error "duplicate entries in $file: " $duplicate_entries
4470
4471       func_grep_q "^$str\$" "$file" \
4472           || func_verbose "inserting '$str' into '$file'"
4473
4474       linesold=`func_gitignore_entries "$file" |wc -l`
4475       linesnew=`{ $bs_echo "$str"; cat "$file"; } \
4476                 |func_gitignore_entries |sort -u |wc -l`
4477       test "$linesold" -eq "$linesnew" \
4478         || { sed "1i\\$nl$str$nl" "$file" >"$file"T && mv "$file"T "$file"; } \
4479         || func_permissions_error "$file"
4480     done
4481 }
4482
4483
4484 # func_sort_ver VER1 VER2
4485 # -----------------------
4486 # 'sort -V' is not generally available.
4487 # Note this deviates from the version comparison in automake
4488 # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
4489 # but this should suffice as we won't be specifying old
4490 # version formats or redundant trailing .0 in bootstrap.conf.
4491 # If we did want full compatibility then we should probably
4492 # use m4_version_compare from autoconf.
4493 func_sort_ver ()
4494 {
4495     $debug_cmd
4496
4497     ver1=$1
4498     ver2=$2
4499
4500     # Split on '.' and compare each component.
4501     i=1
4502     while :; do
4503       p1=`echo "$ver1" |cut -d. -f$i`
4504       p2=`echo "$ver2" |cut -d. -f$i`
4505       if test ! "$p1"; then
4506         echo "$1 $2"
4507         break
4508       elif test ! "$p2"; then
4509         echo "$2 $1"
4510         break
4511       elif test ! "$p1" = "$p2"; then
4512         if test "$p1" -gt "$p2" 2>/dev/null; then # numeric comparison
4513           echo "$2 $1"
4514         elif test "$p2" -gt "$p1" 2>/dev/null; then # numeric comparison
4515           echo "$1 $2"
4516         else # numeric, then lexicographic comparison
4517           lp=`printf "$p1\n$p2\n" |sort -n |tail -n1`
4518           if test "$lp" = "$p2"; then
4519             echo "$1 $2"
4520           else
4521             echo "$2 $1"
4522           fi
4523         fi
4524         break
4525       fi
4526       i=`expr $i + 1`
4527     done
4528 }
4529
4530
4531 # func_get_version APP
4532 # --------------------
4533 # echo the version number (if any) of APP, which is looked up along your
4534 # PATH.
4535 func_get_version ()
4536 {
4537     $debug_cmd
4538
4539     _G_app=$1
4540
4541     # Rather than uncomment the sed script in-situ, strip the comments
4542     # programatically before passing the result to $SED for evaluation.
4543     sed_get_version=`$bs_echo '# extract version within line
4544           s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4545           t done
4546
4547           # extract version at start of line
4548           s|^\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
4549           t done
4550
4551           d
4552
4553           :done
4554           # the following essentially does s|5.005|5.5|
4555           s|\.0*\([1-9]\)|.\1|g
4556           p
4557           q' \
4558     |$SED '/^[   ]*#.*$/d'`
4559
4560     func_tool_version_output $_G_app >/dev/null
4561     _G_status=$?
4562
4563     test 0 -ne "$_G_status" \
4564       || $_G_app --version 2>&1 |$SED -n "$sed_get_version"
4565
4566     (exit $_G_status)
4567 }
4568
4569
4570 # func_check_tool APP
4571 # -------------------
4572 # Search PATH for an executable at APP.
4573 func_check_tool ()
4574 {
4575     $debug_cmd
4576
4577     func_check_tool_result=
4578
4579     case $1 in
4580     *[\\/]*)
4581       test -x "$1" && func_check_tool_result=$1
4582       ;;
4583     *)
4584       save_IFS=$IFS
4585       IFS=:
4586       for _G_check_tool_path in $PATH; do
4587         IFS=$save_IFS
4588         if test -x "$_G_check_tool_path/$1"; then
4589           func_check_tool_result=$_G_check_tool_path/$1
4590           break
4591         fi
4592       done
4593       IFS=$save_IFS
4594       ;;
4595     esac
4596 }
4597
4598
4599 # func_check_versions APP1 VER1 URL1 ...[APPN VERN URLN]
4600 # ------------------------------------------------------
4601 func_check_versions ()
4602 {
4603     $debug_cmd
4604
4605     func_check_versions_result=:
4606
4607     while test $# -gt 0; do
4608       _G_app=$1; shift
4609       _G_reqver=$1; shift
4610       _G_url=$1; shift
4611
4612       # Diagnose bad buildreq formatting.
4613       case $_G_url in
4614       [a-z]*://*) ;; # looks like a url
4615       *) func_fatal_error "\
4616 '$_G_url' from the buildreq table in
4617 'bootstrap.conf' does not look like the URL for downloading
4618 $_G_app. Please ensure that buildreq is a strict newline
4619 delimited list of triples; 'program min-version url'."
4620         ;;
4621       esac
4622
4623       # Honor $APP variables ($TAR, $AUTOCONF, etc.)
4624       _G_appvar=`echo $_G_app |tr '[a-z]' '[A-Z]'`
4625       test TAR = "$_G_appvar" && _G_appvar=AMTAR
4626       eval "_G_app=\${$_G_appvar-$_G_app}"
4627
4628       # Fail if no version specified, but the program can't be found.
4629       if test x- = "x$_G_reqver"; then
4630         func_check_tool $_G_app
4631         if test -z "$func_check_tool_result"; then
4632           func_error "Prerequisite '$_G_app' not not found. Please install it, or
4633 'export $_G_appvar=/path/to/$_G_app'."
4634           func_check_versions_result=false
4635         else
4636           func_verbose "found '$func_check_tool_result' for $_G_appvar."
4637         fi
4638       else
4639         _G_instver=`func_get_version $_G_app`
4640
4641         test -z "$_G_instver" \
4642             || func_verbose "found '$_G_app' version $_G_instver."
4643
4644         # Fail if --version didn't work.
4645         if test -z "$_G_instver"; then
4646           func_error "Prerequisite '$_G_app' not found. Please install it, or
4647 'export $_G_appvar=/path/to/$_G_app'."
4648           func_check_versions_result=false
4649
4650         # Fail if a newer version than what we have is required.
4651         else
4652           _G_newer=`func_sort_ver $_G_reqver $_G_instver |cut -d' ' -f2`
4653           test "$_G_newer" != "$_G_instver" && {
4654             func_error "\
4655   '$_G_app' version == $_G_instver is too old
4656   '$_G_app' version >= $_G_reqver is required"
4657             func_check_versions_result=false
4658           }
4659         fi
4660       fi
4661     done
4662 }
4663
4664
4665 # func_cleanup_gnulib
4666 # -------------------
4667 # Recursively delete everything below the path in the global variable
4668 # GNULIB_PATH.
4669 func_cleanup_gnulib ()
4670 {
4671     $debug_cmd
4672
4673     _G_status=$?
4674     $RM -fr "$gnulib_path"
4675     exit $_G_status
4676 }
4677
4678
4679 # func_download_po_files SUBDIR DOMAIN
4680 # ------------------------------------
4681 func_download_po_files ()
4682 {
4683     $debug_cmd
4684
4685     func_echo "getting translations into $1 for $2..."
4686     _G_cmd=`printf "$po_download_command_format" "$2" "$1"`
4687     eval "$_G_cmd"
4688 }
4689
4690
4691 # func_update_po_files PO_DIR DOMAIN
4692 # ----------------------------------
4693 # Mirror .po files to $po_dir/.reference and copy only the new
4694 # or modified ones into $po_dir.  Also update $po_dir/LINGUAS.
4695 # Note po files that exist locally only are left in $po_dir but will
4696 # not be included in LINGUAS and hence will not be distributed.
4697 func_update_po_files ()
4698 {
4699     $debug_cmd
4700
4701     # Directory containing primary .po files.
4702     # Overwrite them only when we're sure a .po file is new.
4703     _G_po_dir=$1
4704     _G_domain=$2
4705
4706     # Mirror *.po files into this dir.
4707     # Usually contains *.s1 checksum files.
4708     _G_ref_po_dir=$_G_po_dir/.reference
4709
4710     test -d "$_G_ref_po_dir" || mkdir $_G_ref_po_dir || return
4711     func_download_po_files $_G_ref_po_dir $_G_domain \
4712       && ls "$_G_ref_po_dir"/*.po 2>/dev/null \
4713          |$SED -e 's|.*/||' -e 's|\.po$||' > "$_G_po_dir/LINGUAS" || return
4714
4715     # Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6+.
4716     func_find_tool SHA1SUM sha1sum gsha1sum shasum sha1
4717
4718     _G_langs=`cd $_G_ref_po_dir && echo *.po|$SED 's|\.po||g'`
4719     test '*' = "$_G_langs" && _G_langs=x
4720     for _G_po in $_G_langs; do
4721       case $_G_po in x) continue;; esac
4722       _G_new_po=$_G_ref_po_dir/$_G_po.po
4723       _G_cksum_file=$_G_ref_po_dir/$_G_po.s1
4724       if ! test -f "$_G_cksum_file" ||
4725           ! test -f "$_G_po_dir/$_G_po.po" ||
4726           ! $SHA1SUM -c "$_G_cksum_file" \
4727               < "$_G_new_po" > /dev/null; then
4728         echo "updated $_G_po_dir/$_G_po.po..."
4729         cp "$_G_new_po" "$_G_po_dir/$_G_po.po" \
4730           && $SHA1SUM < "$_G_new_po" > "$_G_cksum_file" || return
4731       fi
4732     done
4733 }
4734
4735
4736
4737 ## --------------- ##
4738 ## Option parsing. ##
4739 ## --------------- ##
4740
4741 # Hook in the functions to make sure our own options are parsed during
4742 # the option parsing loop.
4743
4744 usage='$progpath [OPTION]...'
4745
4746 # Short help message in response to '-h'.  Add to this in 'bootstrap.conf'
4747 # if you accept any additional options.
4748 usage_message="Common Bootstrap Options:
4749    -c, --copy         copy files instead of creating symbolic links.
4750        --debug        enable verbose shell tracing
4751    -n, --dry-run      print commands rather than running them
4752    -f, --force        attempt to bootstrap even if the sources seem not
4753                       to have been checked out.
4754        --gnulib-srcdir=DIRNAME
4755                       specify a local directory where gnulib sources
4756                       reside. Use this if you already have the gnulib
4757                       sources on your machine, and don't want to waste
4758                       your bandwidth downloading them again.  Defaults to
4759                       \$GNULIB_SRCDIR.
4760        --no-warnings  equivalent to '-Wnone'
4761        --skip-git     do not fetch files from remote repositories
4762        --skip-po      do not download po files.
4763    -v, --verbose      verbosely report processing
4764        --version      print version information and exit
4765    -W, --warnings=CATEGORY
4766                       report the warnings falling in CATEGORY [all]
4767    -h, --help         print short or long help message and exit
4768 "
4769
4770 # Additional text appended to 'usage_message' in response to '--help'.
4771 long_help_message=$long_help_message"
4772        'recommend'    show warnings about missing recommended packages
4773        'settings'     show warnings about missing '$progname.conf' settings
4774        'upgrade'      show warnings about out-dated files
4775
4776 If the file '$progname.conf' exists in the same directory as this
4777 script, its contents are read as shell variables to configure the
4778 bootstrap.
4779
4780 For build prerequisites, environment variables like \$AUTOCONF and
4781 \$AMTAR are honored.
4782
4783 Running without arguments will suffice in most cases.
4784 "
4785
4786 # Warning categories used by 'bootstrap', append others if you use them
4787 # in your 'bootstrap.conf'.
4788 warning_categories='recommend settings upgrade'
4789
4790
4791 # bootstrap_options_prep [ARG]...
4792 # -------------------------------
4793 # Preparation for options parsed by Bootstrap.
4794 bootstrap_options_prep ()
4795 {
4796     $debug_cmd
4797
4798     # Option defaults:
4799     opt_copy=${copy-'false'}
4800     opt_dry_run=false
4801     opt_force=false
4802     opt_gnulib_srcdir=$GNULIB_SRCDIR
4803     opt_skip_git=false
4804     opt_skip_po=false
4805
4806     # Pass back the list of options we consumed.
4807     func_quote_for_eval ${1+"$@"}
4808     bootstrap_options_prep_result=$func_quote_for_eval_result
4809 }
4810 func_add_hook func_options_prep bootstrap_options_prep
4811
4812
4813 # bootstrap_parse_options [ARG]...
4814 # --------------------------------
4815 # Provide handling for Bootstrap specific options.
4816 bootstrap_parse_options ()
4817 {
4818     $debug_cmd
4819
4820     # Perform our own loop to consume as many options as possible in
4821     # each iteration.
4822     while test $# -gt 0; do
4823       _G_opt=$1
4824       shift
4825       case $_G_opt in
4826         --dry-run|--dryrun|-n)
4827                       opt_dry_run=: ;;
4828         --copy|-c)    opt_copy=: ;;
4829         --force|-f)   opt_force=: ;;
4830
4831         --gnulib-srcdir)
4832                       test $# = 0 && func_missing_arg $_G_opt && break
4833                       opt_gnulib_srcdir=$1
4834                       shift
4835                       ;;
4836
4837         --skip-git|--no-git)
4838                       opt_skip_git=:
4839                       ;;
4840
4841         --skip-po|--no-po)
4842                       opt_skip_po=:
4843                       ;;
4844
4845         # Separate non-argument short options:
4846         -c*|-f*|-n*)
4847                       func_split_short_opt "$_G_opt"
4848                       set dummy "$func_split_short_opt_name" \
4849                           "-$func_split_short_opt_arg" ${1+"$@"}
4850                       shift
4851                       ;;
4852
4853         *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
4854       esac
4855     done
4856
4857     # save modified positional parameters for caller
4858     func_quote_for_eval ${1+"$@"}
4859     bootstrap_parse_options_result=$func_quote_for_eval_result
4860 }
4861 func_add_hook func_parse_options bootstrap_parse_options
4862
4863
4864 # bootstrap_validate_options [ARG]...
4865 # -----------------------------------
4866 # Perform any sanity checks on option settings and/or unconsumed
4867 # arguments.
4868 bootstrap_validate_options ()
4869 {
4870     $debug_cmd
4871
4872     # Validate options.
4873     test $# -gt 0 \
4874         && func_fatal_help "too many arguments"
4875
4876     # Pass back the (empty) list of unconsumed options.
4877     func_quote_for_eval ${1+"$@"}
4878     bootstrap_validate_options_result=$func_quote_for_eval_result
4879 }
4880 func_add_hook func_validate_options bootstrap_validate_options
4881
4882
4883 ## -------------------------------------------------- ##
4884 ## Source package customisations in 'bootstrap.conf'. ##
4885 ## -------------------------------------------------- ##
4886
4887 # Override the default configuration, if necessary.
4888 # Make sure that bootstrap.conf is sourced from the current directory
4889 # if we were invoked as "sh bootstrap".
4890 case $0 in
4891   */*) test -r "$0.conf" && . "$0.conf" ;;
4892   *) test -r "$0.conf" && . ./"$0.conf" ;;
4893 esac
4894
4895
4896 ## ------------------------------- ##
4897 ## Actually perform the bootstrap. ##
4898 ## ------------------------------- ##
4899
4900 func_bootstrap ${1+"$@"}
4901
4902 # The End.
4903 exit ${exit_status-$EXIT_SUCCESS}
4904
4905 # Local variables:
4906 # mode: shell-script
4907 # sh-indentation: 2
4908 # eval: (add-hook 'write-file-hooks 'time-stamp)
4909 # time-stamp-pattern: "20/scriptversion=%:y-%02m-%02d.%02H; # UTC"
4910 # time-stamp-time-zone: "UTC"
4911 # End: