Bump to 1.14.1
[platform/upstream/augeas.git] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2016 Free Software Foundation, Inc.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 # This program is meant for authors or maintainers which want to import
20 # modules from gnulib into their packages.
21
22 progname=$0
23 package=gnulib
24 nl='
25 '
26 IFS=" ""        $nl"
27
28 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
29 AUTOCONFPATH=
30 #case $USER in
31 #  bruno )
32 #    AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
33 #    AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
34 #    ;;
35 #esac
36
37 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
38 AUTOMAKEPATH=
39
40 # You can set GETTEXTPATH to empty if autopoint 0.15 is already in your PATH.
41 GETTEXTPATH=
42
43 # You can set LIBTOOLPATH to empty if libtoolize 2.x is already in your PATH.
44 LIBTOOLPATH=
45
46 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
47 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
48 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
49   AUTOCONF="${AUTOCONFPATH}autoconf"
50 fi
51 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
52   AUTOHEADER="${AUTOCONFPATH}autoheader"
53 fi
54 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
55   ACLOCAL="${AUTOMAKEPATH}aclocal"
56 fi
57 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
58   AUTOMAKE="${AUTOMAKEPATH}automake"
59 fi
60 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
61   AUTORECONF="${AUTOCONFPATH}autoreconf"
62 fi
63
64 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
65 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
66   AUTOPOINT="${GETTEXTPATH}autopoint"
67 fi
68
69 # If you didn't set LIBTOOLPATH, you can also set the variable LIBTOOLIZE.
70 if test -z "${LIBTOOLIZE}" || test -n "${LIBTOOLPATH}"; then
71   LIBTOOLIZE="${LIBTOOLPATH}libtoolize"
72 fi
73
74 # You can set MAKE.
75 if test -z "${MAKE}"; then
76   MAKE=make
77 fi
78
79 # When using GNU sed, turn off as many GNU extensions as possible,
80 # to minimize the risk of accidentally using non-portable features.
81 # However, do this only for gnulib-tool itself, not for the code that
82 # gnulib-tool generates, since we don't want "sed --posix" to leak
83 # into makefiles. And do it only for sed versions 4.2 or newer,
84 # because "sed --posix" is buggy in GNU sed 4.1.5, see
85 # <http://lists.gnu.org/archive/html/bug-gnulib/2009-02/msg00225.html>.
86 if (alias) > /dev/null 2>&1 \
87    && echo | sed --posix -e d >/dev/null 2>&1 \
88    && case `sed --version | sed -e 's/^[^0-9]*//' -e 1q` in \
89         [1-3]* | 4.[01]*) false;; \
90         *) true;; \
91       esac \
92    ; then
93   # Define sed as an alias.
94   # It is not always possible to use aliases. Aliases are guaranteed to work
95   # if the executing shell is bash and either it is invoked as /bin/sh or
96   # is a version >= 2.0, supporting shopt. This is the common case.
97   # Two other approaches (use of a variable $sed or of a function func_sed
98   # instead of an alias) require massive, fragile code changes.
99   # An other approach (use of function sed) requires `which sed` - but
100   # 'which' is hard to emulate, due to missing "test -x" on some platforms.
101   if test -n "$BASH_VERSION"; then
102     shopt -s expand_aliases >/dev/null 2>&1
103   fi
104   alias sed='sed --posix'
105 fi
106
107 # sed_noop is a sed expression that does nothing.
108 # An empty expression does not work with the native 'sed' on AIX 6.1.
109 sed_noop='s,x,x,'
110
111 # sed_comments is true or false, depending whether 'sed' supports comments.
112 # AIX 5.3 sed barfs over indented comments.
113 if echo fo | sed -e 's/f/g/
114 # s/o/u/
115  # indented comment
116 s/o/e/' 2>/dev/null | grep ge > /dev/null; then
117   sed_comments=true
118 else
119   sed_comments=false
120 fi
121
122 # func_usage
123 # outputs to stdout the --help usage message.
124 func_usage ()
125 {
126   echo "\
127 Usage: gnulib-tool --list
128        gnulib-tool --find filename
129        gnulib-tool --import [module1 ... moduleN]
130        gnulib-tool --add-import [module1 ... moduleN]
131        gnulib-tool --remove-import [module1 ... moduleN]
132        gnulib-tool --update
133        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
134        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
135        gnulib-tool --test --dir=directory module1 ... moduleN
136        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
137        gnulib-tool --extract-description module
138        gnulib-tool --extract-comment module
139        gnulib-tool --extract-status module
140        gnulib-tool --extract-notice module
141        gnulib-tool --extract-applicability module
142        gnulib-tool --extract-filelist module
143        gnulib-tool --extract-dependencies module
144        gnulib-tool --extract-autoconf-snippet module
145        gnulib-tool --extract-automake-snippet module
146        gnulib-tool --extract-include-directive module
147        gnulib-tool --extract-link-directive module
148        gnulib-tool --extract-license module
149        gnulib-tool --extract-maintainer module
150        gnulib-tool --extract-tests-module module
151        gnulib-tool --copy-file file [destination]
152
153 Operation modes:
154
155       --list                print the available module names
156       --find                find the modules which contain the specified file
157       --import              import the given modules into the current package
158       --add-import          augment the list of imports from gnulib into the
159                             current package, by adding the given modules;
160                             if no modules are specified, update the current
161                             package from the current gnulib
162       --remove-import       reduce the list of imports from gnulib into the
163                             current package, by removing the given modules
164       --update              update the current package, restore files omitted
165                             from version control
166       --create-testdir      create a scratch package with the given modules
167       --create-megatestdir  create a mega scratch package with the given modules
168                             one by one and all together
169       --test                test the combination of the given modules
170                             (recommended to use CC=\"gcc -Wall\" here)
171       --megatest            test the given modules one by one and all together
172                             (recommended to use CC=\"gcc -Wall\" here)
173       --extract-description        extract the description
174       --extract-comment            extract the comment
175       --extract-status             extract the status (obsolete etc.)
176       --extract-notice             extract the notice or banner
177       --extract-applicability      extract the applicability
178       --extract-filelist           extract the list of files
179       --extract-dependencies       extract the dependencies
180       --extract-autoconf-snippet   extract the snippet for configure.ac
181       --extract-automake-snippet   extract the snippet for library makefile
182       --extract-include-directive  extract the #include directive
183       --extract-link-directive     extract the linker directive
184       --extract-license            report the license terms of the source files
185                                    under lib/
186       --extract-maintainer         report the maintainer(s) inside gnulib
187       --extract-tests-module       report the unit test module, if it exists
188       --copy-file                  copy a file that is not part of any module
189       --help                Show this help text.
190       --version             Show version and authorship information.
191
192 General options:
193
194       --dir=DIRECTORY       Specify the target directory.
195                             For --import, this specifies where your
196                             configure.ac can be found.  Defaults to current
197                             directory.
198       --local-dir=DIRECTORY  Specify a local override directory where to look
199                             up files before looking in gnulib's directory.
200       --cache-modules       Enable module caching optimization.
201       --no-cache-modules    Disable module caching optimization.
202       --verbose             Increase verbosity. May be repeated.
203       --quiet               Decrease verbosity. May be repeated.
204
205 Options for --import, --add/remove-import, --update:
206
207       --dry-run             Only print what would have been done.
208
209 Options for --import, --add/remove-import:
210
211       --with-tests          Include unit tests for the included modules.
212
213 Options for --create-[mega]testdir, --[mega]test:
214
215       --without-tests       Don't include unit tests for the included modules.
216
217 Options for --import, --add/remove-import,
218             --create-[mega]testdir, --[mega]test:
219
220       --with-obsolete       Include obsolete modules when they occur among the
221                             dependencies. By default, dependencies to obsolete
222                             modules are ignored.
223       --with-c++-tests      Include even unit tests for C++ interoperability.
224       --without-c++-tests   Exclude unit tests for C++ interoperability.
225       --with-longrunning-tests
226                             Include even unit tests that are long-runners.
227       --without-longrunning-tests
228                             Exclude unit tests that are long-runners.
229       --with-privileged-tests
230                             Include even unit tests that require root
231                             privileges.
232       --without-privileged-tests
233                             Exclude unit tests that require root privileges.
234       --with-unportable-tests
235                             Include even unit tests that fail on some platforms.
236       --without-unportable-tests
237                             Exclude unit tests that fail on some platforms.
238       --with-all-tests      Include all kinds of problematic unit tests.
239       --avoid=MODULE        Avoid including the given MODULE. Useful if you
240                             have code that provides equivalent functionality.
241                             This option can be repeated.
242       --conditional-dependencies
243                             Support conditional dependencies (may save configure
244                             time and object code).
245       --no-conditional-dependencies
246                             Don't use conditional dependencies.
247       --libtool             Use libtool rules.
248       --no-libtool          Don't use libtool rules.
249
250 Options for --import, --add/remove-import:
251
252       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
253       --source-base=DIRECTORY
254                             Directory relative to --dir where source code is
255                             placed (default \"lib\").
256       --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
257                             placed (default \"m4\").
258       --po-base=DIRECTORY   Directory relative to --dir where *.po files are
259                             placed (default \"po\").
260       --doc-base=DIRECTORY  Directory relative to --dir where doc files are
261                             placed (default \"doc\").
262       --tests-base=DIRECTORY
263                             Directory relative to --dir where unit tests are
264                             placed (default \"tests\").
265       --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
266                             tools are placed (default comes from configure.ac).
267       --lgpl[=2|=3]         Abort if modules aren't available under the LGPL.
268                             Also modify license template from GPL to LGPL.
269                             The version number of the LGPL can be specified;
270                             the default is currently LGPLv3.
271       --makefile-name=NAME  Name of makefile in automake syntax in the
272                             source-base and tests-base directories
273                             (default \"Makefile.am\").
274       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
275                             'gl_INIT'. Default is 'gl'.
276       --po-domain=NAME      Specify the prefix of the i18n domain. Usually use
277                             the package name. A suffix '-gnulib' is appended.
278       --witness-c-macro=NAME  Specify the C macro that is defined when the
279                             sources in this directory are compiled or used.
280       --vc-files            Update version control related files.
281       --no-vc-files         Don't update version control related files
282                             (.gitignore and/or .cvsignore).
283
284 Options for --create-[mega]testdir, --[mega]test:
285
286       --single-configure    Generate a single configure file, not a separate
287                             configure file for the tests directory.
288
289 Options for --import, --add/remove-import, --update,
290             --create-[mega]testdir, --[mega]test:
291
292   -s, --symbolic, --symlink Make symbolic links instead of copying files.
293       --local-symlink       Make symbolic links instead of copying files, only
294                             for files from the local override directory.
295
296 Options for --import, --add/remove-import, --update:
297
298   -S, --more-symlinks       Make symbolic links instead of copying files, and
299                             don't replace copyright notices.
300
301 Report bugs to <bug-gnulib@gnu.org>."
302 }
303
304 # func_version
305 # outputs to stdout the --version message.
306 func_version ()
307 {
308   func_gnulib_dir
309   if test -d "$gnulib_dir"/.git \
310      && (git --version) >/dev/null 2>/dev/null \
311      && (date --version) >/dev/null 2>/dev/null; then
312     # gnulib checked out from git.
313     sed_extract_first_date='/^Date/{
314 s/^Date:[        ]*//p
315 q
316 }'
317     date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
318     # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
319     sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
320     date=`echo "$date" | sed -e "$sed_year_before_time"`
321     # Use GNU date to compute the time in GMT.
322     date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
323     version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
324   else
325     # gnulib copy without versioning information.
326     date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
327     version=
328   fi
329   year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed -e 's,^.* ,,'`
330   echo "\
331 gnulib-tool (GNU $package $date)$version
332 Copyright (C) $year Free Software Foundation, Inc.
333 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
334 This is free software: you are free to change and redistribute it.
335 There is NO WARRANTY, to the extent permitted by law.
336 "
337   printf "Written by %s, %s, and %s.\n" "Bruno Haible" "Paul Eggert" "Simon Josefsson"
338 }
339
340 # func_emit_copyright_notice
341 # outputs to stdout a header for a generated file.
342 func_emit_copyright_notice ()
343 {
344   sed -n -e '/Copyright/ {
345                p
346                q
347              }' < "$self_abspathname"
348   echo "#"
349   echo "# This file is free software; you can redistribute it and/or modify"
350   echo "# it under the terms of the GNU General Public License as published by"
351   echo "# the Free Software Foundation; either version 3 of the License, or"
352   echo "# (at your option) any later version."
353   echo "#"
354   echo "# This file is distributed in the hope that it will be useful,"
355   echo "# but WITHOUT ANY WARRANTY; without even the implied warranty of"
356   echo "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
357   echo "# GNU General Public License for more details."
358   echo "#"
359   echo "# You should have received a copy of the GNU General Public License"
360   echo "# along with this file.  If not, see <http://www.gnu.org/licenses/>."
361   echo "#"
362   echo "# As a special exception to the GNU General Public License,"
363   echo "# this file may be distributed as part of a program that"
364   echo "# contains a configuration script generated by Autoconf, under"
365   echo "# the same distribution terms as the rest of that program."
366   echo "#"
367   echo "# Generated by gnulib-tool."
368 }
369
370 # func_exit STATUS
371 # exits with a given status.
372 # This function needs to be used, rather than 'exit', when a 'trap' handler is
373 # in effect that refers to $?.
374 func_exit ()
375 {
376   (exit $1); exit $1
377 }
378
379 # func_gnulib_dir
380 # locates the directory where the gnulib repository lives
381 # Input:
382 # - progname                 name of this program
383 # Sets variables
384 # - self_abspathname         absolute pathname of gnulib-tool
385 # - gnulib_dir               absolute pathname of gnulib repository
386 func_gnulib_dir ()
387 {
388   case "$progname" in
389     /* | ?:*) self_abspathname="$progname" ;;
390     */*) self_abspathname=`pwd`/"$progname" ;;
391     *)
392       # Look in $PATH.
393       # Iterate through the elements of $PATH.
394       # We use IFS=: instead of
395       #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
396       # because the latter does not work when some PATH element contains spaces.
397       # We use a canonicalized $pathx instead of $PATH, because empty PATH
398       # elements are by definition equivalent to '.', however field splitting
399       # according to IFS=: loses empty fields in many shells:
400       #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
401       #     beginning, at the end, and in the middle),
402       #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
403       #     at the beginning and at the end,
404       #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
405       #     Solaris lose empty fields at the end.
406       # The 'case' statement is an optimization, to avoid evaluating the
407       # explicit canonicalization command when $PATH contains no empty fields.
408       self_abspathname=
409       if test "$PATH_SEPARATOR" = ";"; then
410         # On Windows, programs are searched in "." before $PATH.
411         pathx=".;$PATH"
412       else
413         # On Unix, we have to convert empty PATH elements to ".".
414         pathx="$PATH"
415         case :$PATH: in
416           *::*)
417             pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
418             ;;
419         esac
420       fi
421       save_IFS="$IFS"
422       IFS="$PATH_SEPARATOR"
423       for d in $pathx; do
424         IFS="$save_IFS"
425         test -z "$d" && d=.
426         if test -x "$d/$progname" && test ! -d "$d/$progname"; then
427           self_abspathname="$d/$progname"
428           break
429         fi
430       done
431       IFS="$save_IFS"
432       if test -z "$self_abspathname"; then
433         func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
434       fi
435       ;;
436   esac
437   while test -h "$self_abspathname"; do
438     # Resolve symbolic link.
439     linkval=`func_readlink "$self_abspathname"`
440     test -n "$linkval" || break
441     case "$linkval" in
442       /* | ?:* ) self_abspathname="$linkval" ;;
443       * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
444     esac
445   done
446   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
447 }
448
449 # func_tmpdir
450 # creates a temporary directory.
451 # Input:
452 # - progname                 name of this program
453 # Sets variable
454 # - tmp             pathname of freshly created temporary directory
455 func_tmpdir ()
456 {
457   # Use the environment variable TMPDIR, falling back to /tmp. This allows
458   # users to specify a different temporary directory, for example, if their
459   # /tmp is filled up or too small.
460   : ${TMPDIR=/tmp}
461   {
462     # Use the mktemp program if available. If not available, hide the error
463     # message.
464     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
465     test -n "$tmp" && test -d "$tmp"
466   } ||
467   {
468     # Use a simple mkdir command. It is guaranteed to fail if the directory
469     # already exists.  $RANDOM is bash specific and expands to empty in shells
470     # other than bash, ksh and zsh.  Its use does not increase security;
471     # rather, it minimizes the probability of failure in a very cluttered /tmp
472     # directory.
473     tmp=$TMPDIR/gl$$-$RANDOM
474     (umask 077 && mkdir "$tmp")
475   } ||
476   {
477     echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
478     func_exit 1
479   }
480 }
481
482 # func_append var value
483 # appends the given value to the shell variable var.
484 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
485   # Use bash's += operator. It reduces complexity of appending repeatedly to
486   # a single variable from O(n^2) to O(n).
487   func_append ()
488   {
489     eval "$1+=\"\$2\""
490   }
491   fast_func_append=true
492 else
493   func_append ()
494   {
495     eval "$1=\"\$$1\$2\""
496   }
497   fast_func_append=false
498 fi
499
500 # func_remove_prefix var prefix
501 # removes the given prefix from the value of the shell variable var.
502 # var should be the name of a shell variable.
503 # Its value should not contain a newline and not start or end with whitespace.
504 # prefix should not contain the characters "$`\{}[]^|.
505 if ( foo=bar; eval 'test "${foo#b}" = ar' ) >/dev/null 2>&1; then
506   func_remove_prefix ()
507   {
508     eval "$1=\${$1#\$2}"
509   }
510   fast_func_remove_prefix=true
511 else
512   func_remove_prefix ()
513   {
514     eval "value=\"\$$1\""
515     prefix="$2"
516     case "$prefix" in
517       *.*)
518         sed_escape_dots='s/\([.]\)/\\\1/g'
519         prefix=`echo "$prefix" | sed -e "$sed_escape_dots"`
520         ;;
521     esac
522     value=`echo "$value" | sed -e "s|^${prefix}||"`
523     eval "$1=\"\$value\""
524   }
525   fast_func_remove_prefix=false
526 fi
527
528 # Determine whether we should use ':' or ';' as PATH_SEPARATOR.
529 func_determine_path_separator ()
530 {
531   if test "${PATH_SEPARATOR+set}" != set; then
532     # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
533     # contains only /bin. Note that ksh looks also at the FPATH variable,
534     # so we have to set that as well for the test.
535     PATH_SEPARATOR=:
536     (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
537       && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
538              || PATH_SEPARATOR=';'
539          }
540   fi
541 }
542
543 # func_path_prepend pathvar directory
544 # puts directory before pathvar, delimiting directories by PATH_SEPARATOR.
545 # Newly added directory into pathvar has the highest priority.
546 func_path_prepend ()
547 {
548   if eval "test -n \"\$$1\""; then
549     eval "$1=\$2\$PATH_SEPARATOR\$$1"
550   else
551     eval "$1=\$2"
552   fi
553 }
554
555 # func_path_append pathvar directory
556 # Similar to func_path_prepend except that the newest directory has the lowest
557 # priority.
558 func_path_append ()
559 {
560   if eval "test -n \"\$$1\""; then
561     func_append "$1" "$PATH_SEPARATOR$2"
562   else
563     eval "$1=\$2"
564   fi
565 }
566
567 # func_path_foreach_inner
568 # helper for func_path_foreach because we need new 'args' array
569 # Input:
570 # - fpf_dir     directory from local_gnulib_path
571 # - fpf_cb      callback to be run for fpf_dir
572 func_path_foreach_inner ()
573 {
574   set %start% "$@"
575   for _fpf_arg
576   do
577     case $_fpf_arg in
578       %start%)
579         set dummy
580         ;;
581       %dir%)
582         set "$@" "$fpf_dir"
583         ;;
584       *)
585         set "$@" "$_fpf_arg"
586         ;;
587     esac
588   done
589   shift
590
591   "$fpf_cb" "$@"
592 }
593
594 # func_path_foreach path method args
595 # Execute method for each directory in path.  The method will be called
596 # like `method args` while any argument '%dir%' within args will be replaced
597 # with processed directory from path.
598 func_path_foreach ()
599 {
600   fpf_save_IFS=$IFS
601   fpf_dirs=$1 ; shift
602   fpf_cb=$1 ; shift
603   fpf_rc=false
604
605   IFS=$PATH_SEPARATOR
606   for fpf_dir in $fpf_dirs
607   do
608     func_path_foreach_inner "$@" && fpf_rc=:
609   done
610   IFS=$fpf_save_IFS
611   $fpf_rc
612 }
613
614 # func_remove_suffix var suffix
615 # removes the given suffix from the value of the shell variable var.
616 # var should be the name of a shell variable.
617 # Its value should not contain a newline and not start or end with whitespace.
618 # suffix should not contain the characters "$`\{}[]^|.
619 if ( foo=bar; eval 'test "${foo%r}" = ba' ) >/dev/null 2>&1; then
620   func_remove_suffix ()
621   {
622     eval "$1=\${$1%\$2}"
623   }
624   fast_func_remove_suffix=true
625 else
626   func_remove_suffix ()
627   {
628     eval "value=\"\$$1\""
629     suffix="$2"
630     case "$suffix" in
631       *.*)
632         sed_escape_dots='s/\([.]\)/\\\1/g'
633         suffix=`echo "$suffix" | sed -e "$sed_escape_dots"`
634         ;;
635     esac
636     value=`echo "$value" | sed -e "s|${suffix}\$||"`
637     eval "$1=\"\$value\""
638   }
639   fast_func_remove_suffix=false
640 fi
641
642 # func_fatal_error message
643 # outputs to stderr a fatal error message, and terminates the program.
644 # Input:
645 # - progname                 name of this program
646 func_fatal_error ()
647 {
648   echo "$progname: *** $1" 1>&2
649   echo "$progname: *** Stop." 1>&2
650   func_exit 1
651 }
652
653 # func_warning message
654 # Outputs to stderr a warning message,
655 func_warning ()
656 {
657   echo "gnulib-tool: warning: $1" 1>&2
658 }
659
660 # func_readlink SYMLINK
661 # outputs the target of the given symlink.
662 if (type readlink) > /dev/null 2>&1; then
663   func_readlink ()
664   {
665     # Use the readlink program from GNU coreutils.
666     readlink "$1"
667   }
668 else
669   func_readlink ()
670   {
671     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
672     # would do the wrong thing if the link target contains " -> ".
673     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
674   }
675 fi
676
677 # func_relativize DIR1 DIR2
678 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
679 # Input:
680 # - DIR1            relative pathname, relative to the current directory
681 # - DIR2            relative pathname, relative to the current directory
682 # Output:
683 # - reldir          relative pathname of DIR2, relative to DIR1
684 func_relativize ()
685 {
686   dir0=`pwd`
687   dir1="$1"
688   dir2="$2"
689   sed_first='s,^\([^/]*\)/.*$,\1,'
690   sed_rest='s,^[^/]*/*,,'
691   sed_last='s,^.*/\([^/]*\)$,\1,'
692   sed_butlast='s,/*[^/]*$,,'
693   while test -n "$dir1"; do
694     first=`echo "$dir1" | sed -e "$sed_first"`
695     if test "$first" != "."; then
696       if test "$first" = ".."; then
697         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
698         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
699       else
700         first2=`echo "$dir2" | sed -e "$sed_first"`
701         if test "$first2" = "$first"; then
702           dir2=`echo "$dir2" | sed -e "$sed_rest"`
703         else
704           dir2="../$dir2"
705         fi
706         dir0="$dir0"/"$first"
707       fi
708     fi
709     dir1=`echo "$dir1" | sed -e "$sed_rest"`
710   done
711   reldir="$dir2"
712 }
713
714 # func_relconcat DIR1 DIR2
715 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
716 # Input:
717 # - DIR1            relative pathname, relative to the current directory
718 # - DIR2            relative pathname, relative to DIR1
719 # Output:
720 # - relconcat       DIR1/DIR2, relative to the current directory
721 func_relconcat ()
722 {
723   dir1="$1"
724   dir2="$2"
725   sed_first='s,^\([^/]*\)/.*$,\1,'
726   sed_rest='s,^[^/]*/*,,'
727   sed_last='s,^.*/\([^/]*\)$,\1,'
728   sed_butlast='s,/*[^/]*$,,'
729   while true; do
730     first=`echo "$dir2" | sed -e "$sed_first"`
731     if test "$first" = "."; then
732       dir2=`echo "$dir2" | sed -e "$sed_rest"`
733       if test -z "$dir2"; then
734         relconcat="$dir1"
735         break
736       fi
737     else
738       last=`echo "$dir1" | sed -e "$sed_last"`
739       while test "$last" = "."; do
740         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
741         last=`echo "$dir1" | sed -e "$sed_last"`
742       done
743       if test -z "$dir1"; then
744         relconcat="$dir2"
745         break
746       fi
747       if test "$first" = ".."; then
748         if test "$last" = ".."; then
749           relconcat="$dir1/$dir2"
750           break
751         fi
752         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
753         dir2=`echo "$dir2" | sed -e "$sed_rest"`
754         if test -z "$dir1"; then
755           relconcat="$dir2"
756           break
757         fi
758         if test -z "$dir2"; then
759           relconcat="$dir1"
760           break
761         fi
762       else
763         relconcat="$dir1/$dir2"
764         break
765       fi
766     fi
767   done
768 }
769
770 # func_ln_s SRC DEST
771 # Like ln -s, except use cp -p if ln -s fails.
772 func_ln_s ()
773 {
774   ln -s "$1" "$2" || {
775     echo "$progname: ln -s failed; falling back on cp -p" >&2
776
777     case "$1" in
778       /* | ?:*) # SRC is absolute.
779         cp_src=$1 ;;
780       *) # SRC is relative to the directory of DEST.
781         cp_src=${2%/*}/$1 ;;
782     esac
783
784     cp -p "$cp_src" "$2"
785   }
786 }
787
788 # func_ln SRC DEST
789 # Like func_ln_s, except that SRC is given relative to the current directory (or
790 # absolute), not given relative to the directory of DEST.
791 func_ln ()
792 {
793   case "$1" in
794     /* | ?:*)
795       func_ln_s "$1" "$2" ;;
796     *) # SRC is relative.
797       case "$2" in
798         /* | ?:*)
799           func_ln_s "`pwd`/$1" "$2" ;;
800         *) # DEST is relative too.
801           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
802           test -n "$ln_destdir" || ln_destdir="."
803           func_relativize "$ln_destdir" "$1"
804           func_ln_s "$reldir" "$2"
805           ;;
806       esac
807       ;;
808   esac
809 }
810
811 # func_ln_if_changed SRC DEST
812 # Like func_ln, but avoids munging timestamps if the link is correct.
813 func_ln_if_changed ()
814 {
815   if test $# -ne 2; then
816     echo "usage: func_ln_if_changed SRC DEST" >&2
817   fi
818   ln_target=`func_readlink "$2"`
819   if test -h "$2" && test "$1" = "$ln_target"; then
820     :
821   else
822     rm -f "$2"
823     func_ln "$1" "$2"
824   fi
825 }
826
827 # Ensure an 'echo' command that
828 #   1. does not interpret backslashes and
829 #   2. does not print an error message "broken pipe" when writing into a pipe
830 #      with no writers.
831 #
832 # Test cases for problem 1:
833 #   echo '\n' | wc -l                 prints 1 when OK, 2 when KO
834 #   echo '\t' | grep t > /dev/null    has return code 0 when OK, 1 when KO
835 # Test cases for problem 2:
836 #   echo hi | true                    frequently prints
837 #                                     "bash: echo: write error: Broken pipe"
838 #                                     to standard error in bash 3.2.
839 #
840 # Problem 1 is a weird heritage from SVR4. BSD got it right (except that
841 # BSD echo interprets '-n' as an option, which is also not desirable).
842 # Nowadays the problem occurs in 4 situations:
843 # - in bash, when the shell option xpg_echo is set (bash >= 2.04)
844 #            or when it was built with --enable-usg-echo-default (bash >= 2.0)
845 #            or when it was built with DEFAULT_ECHO_TO_USG (bash < 2.0),
846 # - in zsh, when sh-emulation is not set,
847 # - in ksh (e.g. AIX /bin/sh and Solaris /usr/xpg4/bin/sh are ksh instances,
848 #           and HP-UX /bin/sh and IRIX /bin/sh behave similarly),
849 # - in Solaris /bin/sh and OSF/1 /bin/sh.
850 # We try the following workarounds:
851 # - for all: respawn using $CONFIG_SHELL if that is set and works.
852 # - for bash >= 2.04: unset the shell option xpg_echo.
853 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
854 # - for bash < 2.0: define echo to a function that uses cat of a here document.
855 # - for zsh: turn sh-emulation on.
856 # - for ksh: alias echo to 'print -r'.
857 # - for ksh: alias echo to a function that uses cat of a here document.
858 # - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
859 #   the ksh workaround.
860 # - otherwise: respawn using /bin/sh and rely on the workarounds.
861 # When respawning, we pass --no-reexec as first argument, so as to avoid
862 # turning this script into a fork bomb in unlucky situations.
863 #
864 # Problem 2 is specific to bash 3.2 and affects the 'echo' built-in, but not
865 # the 'printf' built-in. See
866 #   <http://lists.gnu.org/archive/html/bug-bash/2008-12/msg00050.html>
867 #   <http://lists.gnu.org/archive/html/bug-gnulib/2010-02/msg00154.html>
868 # The workaround is: define echo to a function that uses the printf built-in.
869 have_echo=
870 if echo '\t' | grep t > /dev/null; then
871   have_echo=yes # Lucky!
872 fi
873 # Try the workarounds.
874 # Respawn using $CONFIG_SHELL if that is set and works.
875 if test -z "$have_echo" \
876    && test "X$1" != "X--no-reexec" \
877    && test -n "$CONFIG_SHELL" \
878    && test -f "$CONFIG_SHELL" \
879    && $CONFIG_SHELL -c "echo '\\t' | grep t > /dev/null"; then
880   exec $CONFIG_SHELL "$0" --no-reexec "$@"
881   exit 127
882 fi
883 # For bash >= 2.04: unset the shell option xpg_echo.
884 if test -z "$have_echo" \
885    && test -n "$BASH_VERSION" \
886    && (shopt -o xpg_echo; echo '\t' | grep t > /dev/null) 2>/dev/null; then
887   shopt -o xpg_echo
888   have_echo=yes
889 fi
890 # For bash >= 2.0: define echo to a function that uses the printf built-in.
891 # For bash < 2.0: define echo to a function that uses cat of a here document.
892 # (There is no win in using 'printf' over 'cat' if it is not a shell built-in.)
893 # Also handle problem 2, specific to bash 3.2, here.
894 if { test -z "$have_echo" \
895      || case "$BASH_VERSION" in 3.2*) true;; *) false;; esac; \
896    } \
897    && test -n "$BASH_VERSION"; then \
898   if type printf 2>/dev/null | grep / > /dev/null; then
899     # 'printf' is not a shell built-in.
900 echo ()
901 {
902 cat <<EOF
903 $*
904 EOF
905 }
906   else
907     # 'printf' is a shell built-in.
908 echo ()
909 {
910   printf '%s\n' "$*"
911 }
912   fi
913   if echo '\t' | grep t > /dev/null; then
914     have_echo=yes
915   fi
916 fi
917 # For zsh: turn sh-emulation on.
918 if test -z "$have_echo" \
919    && test -n "$ZSH_VERSION" \
920    && (emulate sh) >/dev/null 2>&1; then
921   emulate sh
922 fi
923 # For ksh: alias echo to 'print -r'.
924 if test -z "$have_echo" \
925    && (type print) >/dev/null 2>&1; then
926   # A 'print' command exists.
927   if type print 2>/dev/null | grep / > /dev/null; then
928     :
929   else
930     # 'print' is a shell built-in.
931     if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
932       # 'print' is the ksh shell built-in.
933       alias echo='print -r'
934     fi
935   fi
936 fi
937 if test -z "$have_echo" \
938    && echo '\t' | grep t > /dev/null; then
939   have_echo=yes
940 fi
941 # For ksh: alias echo to a function that uses cat of a here document.
942 # The ksh manual page says:
943 #   "Aliasing is performed when scripts are read, not while they are executed.
944 #    Therefore, for an alias to take effect, the alias definition command has
945 #    to be executed before the command which references the alias is read."
946 # Because of this, we have to play strange tricks with have_echo, to ensure
947 # that the top-level statement containing the test starts after the 'alias'
948 # command.
949 if test -z "$have_echo"; then
950   bsd_echo ()
951 {
952 cat <<EOF
953 $*
954 EOF
955 }
956   if (alias echo=bsd_echo) 2>/dev/null; then
957     alias echo=bsd_echo 2>/dev/null
958   fi
959 fi
960 if test -z "$have_echo" \
961    && echo '\t' | grep t > /dev/null; then
962   have_echo=yes
963 fi
964 if test -z "$have_echo"; then
965   if (alias echo=bsd_echo) 2>/dev/null; then
966     unalias echo 2>/dev/null
967   fi
968 fi
969 # For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
970 if test -z "$have_echo" \
971    && test "X$1" != "X--no-reexec" \
972    && test -f /bin/ksh; then
973   exec /bin/ksh "$0" --no-reexec "$@"
974   exit 127
975 fi
976 # Otherwise: respawn using /bin/sh.
977 if test -z "$have_echo" \
978    && test "X$1" != "X--no-reexec" \
979    && test -f /bin/sh; then
980   exec /bin/sh "$0" --no-reexec "$@"
981   exit 127
982 fi
983 if test -z "$have_echo"; then
984   func_fatal_error "Shell does not support 'echo' correctly. Please install GNU bash and set the environment variable CONFIG_SHELL to point to it."
985 fi
986 if echo '\t' | grep t > /dev/null; then
987   : # Works fine now.
988 else
989   func_fatal_error "Shell does not support 'echo' correctly. Workaround does not work. Please report this as a bug to bug-gnulib@gnu.org."
990 fi
991 if test "X$1" = "X--no-reexec"; then
992   shift
993 fi
994
995 # Unset CDPATH.  Otherwise, output from 'cd dir' can surprise callers.
996 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
997
998 # Determine the path separator early because the following option parsing code
999 # requires that.
1000 func_determine_path_separator
1001
1002 # Command-line option processing.
1003 # Removes the OPTIONS from the arguments. Sets the variables:
1004 # - mode            one of: list, find, import, add-import, remove-import,
1005 #                   update, create-testdir, create-megatestdir, test, megatest,
1006 #                   copy-file
1007 # - destdir         from --dir
1008 # - local_gnulib_path  from --local-dir
1009 # - modcache        true or false, from --cache-modules/--no-cache-modules
1010 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1011 # - libname, supplied_libname  from --lib
1012 # - sourcebase      from --source-base
1013 # - m4base          from --m4-base
1014 # - pobase          from --po-base
1015 # - docbase         from --doc-base
1016 # - testsbase       from --tests-base
1017 # - auxdir          from --aux-dir
1018 # - inctests        true if --with-tests was given, false if --without-tests
1019 #                   was given, blank otherwise
1020 # - incobsolete     true if --with-obsolete was given, blank otherwise
1021 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
1022 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
1023 #                          otherwise
1024 # - inc_privileged_tests  true if --with-privileged-tests was given, blank
1025 #                         otherwise
1026 # - inc_unportable_tests  true if --with-unportable-tests was given, blank
1027 #                         otherwise
1028 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
1029 # - excl_cxx_tests  true if --without-c++-tests was given, blank otherwise
1030 # - excl_longrunning_tests  true if --without-longrunning-tests was given,
1031 #                           blank otherwise
1032 # - excl_privileged_tests  true if --without-privileged-tests was given, blank
1033 #                          otherwise
1034 # - excl_unportable_tests  true if --without-unportable-tests was given, blank
1035 #                          otherwise
1036 # - single_configure  true if --single-configure was given, false otherwise
1037 # - avoidlist       list of modules to avoid, from --avoid
1038 # - cond_dependencies  true if --conditional-dependencies was given, false if
1039 #                      --no-conditional-dependencies was given, blank otherwise
1040 # - lgpl            yes or a number if --lgpl was given, blank otherwise
1041 # - makefile_name   from --makefile-name
1042 # - libtool         true if --libtool was given, false if --no-libtool was
1043 #                   given, blank otherwise
1044 # - macro_prefix    from --macro-prefix
1045 # - po_domain       from --po-domain
1046 # - witness_c_macro  from --witness-c-macro
1047 # - vc_files        true if --vc-files was given, false if --no-vc-files was
1048 #                   given, blank otherwise
1049 # - autoconf_minversion  minimum supported autoconf version
1050 # - doit            : if actions shall be executed, false if only to be printed
1051 # - symbolic        true if --symlink or --more-symlinks was given, blank
1052 #                   otherwise
1053 # - lsymbolic       true if --local-symlink was given, blank otherwise
1054 # - do_copyrights   blank if --more-symlinks was given, true otherwise
1055 {
1056   mode=
1057   destdir=
1058   local_gnulib_path=
1059   modcache=true
1060   verbose=0
1061   libname=libgnu
1062   supplied_libname=
1063   sourcebase=
1064   m4base=
1065   pobase=
1066   docbase=
1067   testsbase=
1068   auxdir=
1069   inctests=
1070   incobsolete=
1071   inc_cxx_tests=
1072   inc_longrunning_tests=
1073   inc_privileged_tests=
1074   inc_unportable_tests=
1075   inc_all_tests=
1076   excl_cxx_tests=
1077   excl_longrunning_tests=
1078   excl_privileged_tests=
1079   excl_unportable_tests=
1080   single_configure=false
1081   avoidlist=
1082   cond_dependencies=
1083   lgpl=
1084   makefile_name=
1085   libtool=
1086   macro_prefix=
1087   po_domain=
1088   witness_c_macro=
1089   vc_files=
1090   doit=:
1091   symbolic=
1092   lsymbolic=
1093   do_copyrights=true
1094
1095   supplied_opts="$@"
1096
1097   while test $# -gt 0; do
1098     case "$1" in
1099       --list | --lis )
1100         mode=list
1101         shift ;;
1102       --find | --fin | --fi | --f )
1103         mode=find
1104         shift ;;
1105       --import | --impor | --impo | --imp | --im | --i )
1106         mode=import
1107         shift ;;
1108       --add-import | --add-impor | --add-impo | --add-imp | --add-im | --add-i | --add- | --add | --ad )
1109         mode=add-import
1110         shift ;;
1111       --remove-import | --remove-impor | --remove-impo | --remove-imp | --remove-im | --remove-i | --remove- | --remove | --remov | --remo | --rem | --re | --r )
1112         mode=remove-import
1113         shift ;;
1114       --update | --updat | --upda | --upd | --up | --u )
1115         mode=update
1116         shift ;;
1117       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
1118         mode=create-testdir
1119         shift ;;
1120       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
1121         mode=create-megatestdir
1122         shift ;;
1123       --test | --tes | --te | --t )
1124         mode=test
1125         shift ;;
1126       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
1127         mode=megatest
1128         shift ;;
1129       --extract-* )
1130         mode=`echo "X$1" | sed -e 's/^X--//'`
1131         shift ;;
1132       --copy-file | --copy-fil | --copy-fi | --copy-f | --copy- | --copy | --cop )
1133         mode=copy-file
1134         shift ;;
1135       --dir )
1136         shift
1137         if test $# = 0; then
1138           func_fatal_error "missing argument for --dir"
1139         fi
1140         destdir=$1
1141         shift ;;
1142       --dir=* )
1143         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
1144         shift ;;
1145       --local-dir )
1146         shift
1147         if test $# = 0; then
1148           func_fatal_error "missing argument for --local-dir"
1149         fi
1150         func_path_prepend local_gnulib_path "$1"
1151         shift ;;
1152       --local-dir=* )
1153         local_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
1154         func_path_prepend local_gnulib_path "$local_dir"
1155         shift ;;
1156       --cache-modules | --cache-module | --cache-modul | --cache-modu | --cache-mod | --cache-mo | --cache-m | --cache- | --cache | --cach | --cac | --ca )
1157         modcache=true
1158         shift ;;
1159       --no-cache-modules | --no-cache-module | --no-cache-modul | --no-cache-modu | --no-cache-mod | --no-cache-mo | --no-cache-m | --no-cache- | --no-cache | --no-cach | --no-cac | --no-ca )
1160         modcache=false
1161         shift ;;
1162       --verbose | --verbos | --verbo | --verb )
1163         verbose=`expr $verbose + 1`
1164         shift ;;
1165       --quiet | --quie | --qui | --qu | --q )
1166         verbose=`expr $verbose - 1`
1167         shift ;;
1168       --lib )
1169         shift
1170         if test $# = 0; then
1171           func_fatal_error "missing argument for --lib"
1172         fi
1173         libname=$1
1174         supplied_libname=true
1175         shift ;;
1176       --lib=* )
1177         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
1178         supplied_libname=true
1179         shift ;;
1180       --source-base )
1181         shift
1182         if test $# = 0; then
1183           func_fatal_error "missing argument for --source-base"
1184         fi
1185         sourcebase=$1
1186         shift ;;
1187       --source-base=* )
1188         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
1189         shift ;;
1190       --m4-base )
1191         shift
1192         if test $# = 0; then
1193           func_fatal_error "missing argument for --m4-base"
1194         fi
1195         m4base=$1
1196         shift ;;
1197       --m4-base=* )
1198         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
1199         shift ;;
1200       --po-base )
1201         shift
1202         if test $# = 0; then
1203           func_fatal_error "missing argument for --po-base"
1204         fi
1205         pobase=$1
1206         shift ;;
1207       --po-base=* )
1208         pobase=`echo "X$1" | sed -e 's/^X--po-base=//'`
1209         shift ;;
1210       --doc-base )
1211         shift
1212         if test $# = 0; then
1213           func_fatal_error "missing argument for --doc-base"
1214         fi
1215         docbase=$1
1216         shift ;;
1217       --doc-base=* )
1218         docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
1219         shift ;;
1220       --tests-base )
1221         shift
1222         if test $# = 0; then
1223           func_fatal_error "missing argument for --tests-base"
1224         fi
1225         testsbase=$1
1226         shift ;;
1227       --tests-base=* )
1228         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
1229         shift ;;
1230       --aux-dir )
1231         shift
1232         if test $# = 0; then
1233           func_fatal_error "missing argument for --aux-dir"
1234         fi
1235         auxdir=$1
1236         shift ;;
1237       --aux-dir=* )
1238         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
1239         shift ;;
1240       --with-tests | --with-test | --with-tes | --with-te | --with-t)
1241         inctests=true
1242         shift ;;
1243       --with-obsolete | --with-obsolet | --with-obsole | --with-obsol | --with-obso | --with-obs | --with-ob | --with-o)
1244         incobsolete=true
1245         shift ;;
1246       --with-c++-tests | --with-c++-test | --with-c++-tes | --with-c++-te | --with-c++-t | --with-c++- | --with-c++ | --with-c+ | --with-c)
1247         inc_cxx_tests=true
1248         shift ;;
1249       --with-longrunning-tests | --with-longrunning-test | --with-longrunning-tes | --with-longrunning-te | --with-longrunning-t | --with-longrunning- | --with-longrunning | --with-longrunnin | --with-longrunni | --with-longrunn | --with-longrun | --with-longru | --with-longr | --with-long | --with-lon | --with-lo | --with-l)
1250         inc_longrunning_tests=true
1251         shift ;;
1252       --with-privileged-tests | --with-privileged-test | --with-privileged-tes | --with-privileged-te | --with-privileged-t | --with-privileged- | --with-privileged | --with-privilege | --with-privileg | --with-privile | --with-privil | --with-privi | --with-priv | --with-pri | --with-pr | --with-p)
1253         inc_privileged_tests=true
1254         shift ;;
1255       --with-unportable-tests | --with-unportable-test | --with-unportable-tes | --with-unportable-te | --with-unportable-t | --with-unportable- | --with-unportable | --with-unportabl | --with-unportab | --with-unporta | --with-unport | --with-unpor | --with-unpo | --with-unp | --with-un | --with-u)
1256         inc_unportable_tests=true
1257         shift ;;
1258       --with-all-tests | --with-all-test | --with-all-tes | --with-all-te | --with-all-t | --with-all- | --with-all | --with-al | --with-a)
1259         inc_all_tests=true
1260         shift ;;
1261       --without-tests | --without-test | --without-tes | --without-te | --without-t)
1262         inctests=false
1263         shift ;;
1264       --without-c++-tests | --without-c++-test | --without-c++-tes | --without-c++-te | --without-c++-t | --without-c++- | --without-c++ | --without-c+ | --without-c)
1265         excl_cxx_tests=true
1266         shift ;;
1267       --without-longrunning-tests | --without-longrunning-test | --without-longrunning-tes | --without-longrunning-te | --without-longrunning-t | --without-longrunning- | --without-longrunning | --without-longrunnin | --without-longrunni | --without-longrunn | --without-longrun | --without-longru | --without-longr | --without-long | --without-lon | --without-lo | --without-l)
1268         excl_longrunning_tests=true
1269         shift ;;
1270       --without-privileged-tests | --without-privileged-test | --without-privileged-tes | --without-privileged-te | --without-privileged-t | --without-privileged- | --without-privileged | --without-privilege | --without-privileg | --without-privile | --without-privil | --without-privi | --without-priv | --without-pri | --without-pr | --without-p)
1271         excl_privileged_tests=true
1272         shift ;;
1273       --without-unportable-tests | --without-unportable-test | --without-unportable-tes | --without-unportable-te | --without-unportable-t | --without-unportable- | --without-unportable | --without-unportabl | --without-unportab | --without-unporta | --without-unport | --without-unpor | --without-unpo | --without-unp | --without-un | --without-u)
1274         excl_unportable_tests=true
1275         shift ;;
1276       --single-configure | --single-configur | --single-configu | --single-config | --single-confi | --single-conf | --single-con | --single-con | --single-co | --single-c | --single- | --single | --singl | --sing | --sin | --si)
1277         single_configure=true
1278         shift ;;
1279       --avoid )
1280         shift
1281         if test $# = 0; then
1282           func_fatal_error "missing argument for --avoid"
1283         fi
1284         func_append avoidlist " $1"
1285         shift ;;
1286       --avoid=* )
1287         arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
1288         func_append avoidlist " $arg"
1289         shift ;;
1290       --conditional-dependencies | --conditional-dependencie | --conditional-dependenci | --conditional-dependenc | --conditional-dependen | --conditional-depende | --conditional-depend | --conditional-depen | --conditional-depe | --conditional-dep | --conditional-de | --conditional-d | --conditional- | --conditional | --conditiona | --condition | --conditio | --conditi | --condit | --condi | --cond | --con)
1291         cond_dependencies=true
1292         shift ;;
1293       --no-conditional-dependencies | --no-conditional-dependencie | --no-conditional-dependenci | --no-conditional-dependenc | --no-conditional-dependen | --no-conditional-depende | --no-conditional-depend | --no-conditional-depen | --no-conditional-depe | --no-conditional-dep | --no-conditional-de | --no-conditional-d | --no-conditional- | --no-conditional | --no-conditiona | --no-condition | --no-conditio | --no-conditi | --no-condit | --no-condi | --no-cond | --no-con | --no-co)
1294         cond_dependencies=false
1295         shift ;;
1296       --lgpl )
1297         lgpl=yes
1298         shift ;;
1299       --lgpl=* )
1300         arg=`echo "X$1" | sed -e 's/^X--lgpl=//'`
1301         case "$arg" in
1302           2 | 3) ;;
1303           *) func_fatal_error "invalid LGPL version number for --lgpl" ;;
1304         esac
1305         lgpl=$arg
1306         shift ;;
1307       --makefile-name )
1308         shift
1309         if test $# = 0; then
1310           func_fatal_error "missing argument for --makefile-name"
1311         fi
1312         makefile_name="$1"
1313         shift ;;
1314       --makefile-name=* )
1315         makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
1316         shift ;;
1317       --libtool )
1318         libtool=true
1319         shift ;;
1320       --no-libtool )
1321         libtool=false
1322         shift ;;
1323       --macro-prefix )
1324         shift
1325         if test $# = 0; then
1326           func_fatal_error "missing argument for --macro-prefix"
1327         fi
1328         macro_prefix="$1"
1329         shift ;;
1330       --macro-prefix=* )
1331         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
1332         shift ;;
1333       --po-domain )
1334         shift
1335         if test $# = 0; then
1336           func_fatal_error "missing argument for --po-domain"
1337         fi
1338         po_domain="$1"
1339         shift ;;
1340       --po-domain=* )
1341         po_domain=`echo "X$1" | sed -e 's/^X--po-domain=//'`
1342         shift ;;
1343       --witness-c-macro )
1344         shift
1345         if test $# = 0; then
1346           func_fatal_error "missing argument for --witness-c-macro"
1347         fi
1348         witness_c_macro="$1"
1349         shift ;;
1350       --witness-c-macro=* )
1351         witness_c_macro=`echo "X$1" | sed -e 's/^X--witness-c-macro=//'`
1352         shift ;;
1353       --vc-files )
1354         vc_files=true
1355         shift ;;
1356       --no-vc-files )
1357         vc_files=false
1358         shift ;;
1359       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch )
1360         # A no-op for backward compatibility.
1361         shift ;;
1362       --dry-run )
1363         doit=false
1364         shift ;;
1365       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
1366         symbolic=true
1367         shift ;;
1368       --local-symlink | --local-symlin | --local-symli | --local-syml | --local-sym | --local-sy | --local-s )
1369         lsymbolic=true
1370         shift ;;
1371       -S | --more-symlinks | --more-symlink | --more-symlin | --more-symli | --more-syml | --more-sym | --more-sy | --more-s | --more- | --more | --mor | --mo )
1372         symbolic=true
1373         do_copyrights=
1374         shift ;;
1375       --help | --hel | --he | --h )
1376         func_usage
1377         func_exit $? ;;
1378       --version | --versio | --versi | --vers )
1379         func_version
1380         func_exit $? ;;
1381       -- )
1382         # Stop option processing
1383         shift
1384         break ;;
1385       -* )
1386         echo "gnulib-tool: unknown option $1" 1>&2
1387         echo "Try 'gnulib-tool --help' for more information." 1>&2
1388         func_exit 1 ;;
1389       * )
1390         break ;;
1391     esac
1392   done
1393
1394   if case "$mode" in import | add-import | remove-import) true;; *) false;; esac; then
1395     if test -n "$excl_cxx_tests" || test -n "$excl_longrunning_tests" \
1396        || test -n "$excl_privileged_tests" || test -n "$excl_unportable_tests" \
1397        || test "$single_configure" != false; then
1398       echo "gnulib-tool: invalid options for '$mode' mode" 1>&2
1399       echo "Try 'gnulib-tool --help' for more information." 1>&2
1400       func_exit 1
1401     fi
1402   fi
1403   if test "$mode" = update; then
1404     if test $# != 0; then
1405       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
1406       echo "Try 'gnulib-tool --help' for more information." 1>&2
1407       echo "If you really want to modify the gnulib configuration of your project," 1>&2
1408       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
1409       func_exit 1
1410     fi
1411     if test -n "$local_gnulib_path" || test -n "$supplied_libname" \
1412        || test -n "$sourcebase" || test -n "$m4base" || test -n "$pobase" \
1413        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
1414        || test -n "$inctests" || test -n "$incobsolete" \
1415        || test -n "$inc_cxx_tests" || test -n "$inc_longrunning_tests" \
1416        || test -n "$inc_privileged_tests" || test -n "$inc_unportable_tests" \
1417        || test -n "$inc_all_tests" \
1418        || test -n "$excl_cxx_tests" || test -n "$excl_longrunning_tests" \
1419        || test -n "$excl_privileged_tests" || test -n "$excl_unportable_tests" \
1420        || test -n "$avoidlist" || test -n "$lgpl" || test -n "$makefile_name" \
1421        || test -n "$macro_prefix" || test -n "$po_domain" \
1422        || test -n "$witness_c_macro" || test -n "$vc_files"; then
1423       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
1424       echo "Try 'gnulib-tool --help' for more information." 1>&2
1425       echo "If you really want to modify the gnulib configuration of your project," 1>&2
1426       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
1427       func_exit 1
1428     fi
1429   fi
1430   if test -n "$pobase" && test -z "$po_domain"; then
1431     echo "gnulib-tool: together with --po-base, you need to specify --po-domain" 1>&2
1432     echo "Try 'gnulib-tool --help' for more information." 1>&2
1433     func_exit 1
1434   fi
1435   if test -z "$pobase" && test -n "$po_domain"; then
1436     func_warning "--po-domain has no effect without a --po-base option"
1437   fi
1438   # Canonicalize the inctests variable.
1439   case "$mode" in
1440     import | add-import | remove-import | update)
1441       if test -z "$inctests"; then
1442         inctests=false
1443       fi
1444       ;;
1445     create-testdir | create-megatestdir | test | megatest)
1446       if test -z "$inctests"; then
1447         inctests=true
1448       fi
1449       ;;
1450   esac
1451   # Now the only possible values of "$inctests" are true and false
1452   # (or blank but then it is irrelevant).
1453   if test "$cond_dependencies" = true && test "$inctests" = true; then
1454     echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
1455     func_exit 1
1456   fi
1457
1458   # Determine the minimum supported autoconf version from the project's
1459   # configure.ac.
1460   DEFAULT_AUTOCONF_MINVERSION="2.59"
1461   autoconf_minversion=
1462   configure_ac=
1463   if case "$mode" in import | add-import | remove-import | update) true;; *) false;; esac \
1464      && test -n "$destdir"; then
1465     if test -f "$destdir"/configure.ac; then
1466       configure_ac="$destdir/configure.ac"
1467     else
1468       if test -f "$destdir"/configure.in; then
1469         configure_ac="$destdir/configure.in"
1470       fi
1471     fi
1472   else
1473     if test -f configure.ac; then
1474       configure_ac="configure.ac"
1475     else
1476       if test -f configure.in; then
1477         configure_ac="configure.in"
1478       fi
1479     fi
1480   fi
1481   if test -n "$configure_ac"; then
1482     # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
1483     # because when some m4 files are omitted from a version control repository,
1484     # "autoconf --trace=AC_PREREQ" fails with an error message like this:
1485     #   m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
1486     #   autom4te: m4 failed with exit status: 1
1487     prereqs=
1488     my_sed_traces='
1489       s,#.*$,,
1490       s,^dnl .*$,,
1491       s, dnl .*$,,
1492       /AC_PREREQ/ {
1493         s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,\1,p
1494       }'
1495     prereqs=`sed -n -e "$my_sed_traces" < "$configure_ac"`
1496     if test -n "$prereqs"; then
1497       autoconf_minversion=`
1498         for version in $prereqs; do echo $version; done |
1499         LC_ALL=C sort -nru | sed -e 1q
1500       `
1501     fi
1502   fi
1503   if test -z "$autoconf_minversion"; then
1504     autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
1505   fi
1506   case "$autoconf_minversion" in
1507     1.* | 2.[0-4]* | 2.5[0-8]*)
1508       func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
1509   esac
1510
1511   # Remove trailing slashes from the directory names. This is necessary for
1512   # m4base (to avoid an error in func_import) and optional for the others.
1513   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
1514   old_local_gnulib_path=$local_gnulib_path
1515   save_IFS=$IFS
1516   IFS=:
1517   local_gnulib_path=
1518   for dir in $old_local_gnulib_path
1519   do
1520     case "$dir" in
1521       */ ) dir=`echo "$dir" | sed -e "$sed_trimtrailingslashes"` ;;
1522     esac
1523     func_path_append local_gnulib_path "$dir"
1524   done
1525   IFS=$save_IFS
1526   case "$sourcebase" in
1527     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
1528   esac
1529   case "$m4base" in
1530     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
1531   esac
1532   case "$pobase" in
1533     */ ) pobase=`echo "$pobase" | sed -e "$sed_trimtrailingslashes"` ;;
1534   esac
1535   case "$docbase" in
1536     */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
1537   esac
1538   case "$testsbase" in
1539     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
1540   esac
1541   case "$auxdir" in
1542     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
1543   esac
1544 }
1545
1546 func_gnulib_dir
1547 func_tmpdir
1548 trap 'exit_status=$?
1549       if test "$signal" != 0; then
1550         echo "caught signal $signal" >&2
1551       fi
1552       rm -rf "$tmp"
1553       exit $exit_status' 0
1554 for signal in 1 2 3 13 15; do
1555   trap '{ signal='$signal'; func_exit 1; }' $signal
1556 done
1557 signal=0
1558
1559 # Note: The 'eval' silences stderr output in dash.
1560 if (declare -A x && { x[f/2]='foo'; x[f/3]='bar'; eval test '${x[f/2]}' = foo; }) 2>/dev/null; then
1561   # Zsh 4 and Bash 4 have associative arrays.
1562   have_associative=true
1563 else
1564   # For other shells, use 'eval' with computed shell variable names.
1565   have_associative=false
1566 fi
1567
1568 # func_lookup_local_file_cb dir file
1569 # return true and set func_lookup_local_file_result if the file 'dir/file'
1570 # exists
1571 func_lookup_local_file_cb ()
1572 {
1573   test -n "$func_lookup_local_file_result" && return 1 # already found?
1574   test -f "$1/$2" || return 1
1575   func_lookup_local_file_result=$1/$2
1576   :
1577 }
1578
1579 # func_lookup_local_file file
1580 # looks up a file in $local_gnulib_path.
1581 # Input:
1582 # - local_gnulib_path  from --local-dir
1583 # Output:
1584 # - func_lookup_local_file_result  name of the file, valid only when the
1585 #                   function succeeded.
1586 func_lookup_local_file ()
1587 {
1588   func_lookup_local_file_result=
1589   func_path_foreach "$local_gnulib_path" func_lookup_local_file_cb %dir% "$1"
1590 }
1591
1592 # func_lookup_file file
1593 # looks up a file in $local_gnulib_path or $gnulib_dir, or combines it through
1594 # 'patch'.
1595 # Input:
1596 # - local_gnulib_path  from --local-dir
1597 # Output:
1598 # - lookedup_file   name of the merged (combined) file
1599 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
1600 func_lookup_file ()
1601 {
1602   lkfile="$1"
1603   if func_lookup_local_file "$lkfile"; then
1604     lookedup_file=$func_lookup_local_file_result
1605     lookedup_tmp=
1606   else
1607     if test -f "$gnulib_dir/$lkfile"; then
1608       if func_lookup_local_file "$lkfile.diff"; then
1609         lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
1610         rm -f "$tmp/$lkbase"
1611         cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
1612         patch -s "$tmp/$lkbase" < "$func_lookup_local_file_result" >&2 \
1613           || func_fatal_error "patch file $func_lookup_local_file_result didn't apply cleanly"
1614         lookedup_file="$tmp/$lkbase"
1615         lookedup_tmp=true
1616       else
1617         lookedup_file="$gnulib_dir/$lkfile"
1618         lookedup_tmp=
1619       fi
1620     else
1621       func_fatal_error "file $gnulib_dir/$lkfile not found"
1622     fi
1623   fi
1624 }
1625
1626 # func_sanitize_modulelist
1627 # receives a list of possible module names on standard input, one per line.
1628 # It removes those which are just file names unrelated to modules, and outputs
1629 # the resulting list to standard output, one per line.
1630 func_sanitize_modulelist ()
1631 {
1632   sed -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
1633       -e '/^COPYING$/d' -e '/\/COPYING$/d' \
1634       -e '/^README$/d' -e '/\/README$/d' \
1635       -e '/^TEMPLATE$/d' \
1636       -e '/^TEMPLATE-EXTENDED$/d' \
1637       -e '/^TEMPLATE-TESTS$/d' \
1638       -e '/^\..*/d' \
1639       -e '/~$/d'
1640 }
1641
1642
1643 # func_modules_in_dir dir
1644 # outputs all module files in dir to standard output.
1645 func_modules_in_dir ()
1646 {
1647   (test -d "$1" && cd "$1" && find modules -type f -print)
1648 }
1649
1650 # func_all_modules
1651 # Input:
1652 # - local_gnulib_path  from --local-dir
1653 func_all_modules ()
1654 {
1655   # Filter out metainformation files like README, which are not modules.
1656   # Filter out unit test modules; they can be retrieved through
1657   # --extract-tests-module if desired.
1658   {
1659     (cd "$gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,')
1660     func_path_foreach "$local_gnulib_path" func_modules_in_dir %dir% | sed -e 's,^modules/,,' -e 's,\.diff$,,'
1661   } \
1662       | func_sanitize_modulelist \
1663       | sed -e '/-tests$/d' \
1664       | LC_ALL=C sort -u
1665 }
1666
1667 # func_exists_local_module dir module
1668 # returns true if module exists in dir
1669 func_exists_local_module ()
1670 {
1671     test -d "$1/modules" && test -f "$1/modules/$2";
1672 }
1673
1674 # func_exists_module module
1675 # tests whether a module, given by name, exists
1676 # Input:
1677 # - local_gnulib_path  from --local-dir
1678 func_exists_module ()
1679 {
1680   { test -f "$gnulib_dir/modules/$1" \
1681     || func_path_foreach "$local_gnulib_path" func_exists_local_module %dir% "$1" ; } \
1682   && test "ChangeLog" != "$1" \
1683   && test "COPYING" != "$1" \
1684   && test "README" != "$1" \
1685   && test "TEMPLATE" != "$1" \
1686   && test "TEMPLATE-EXTENDED" != "$1" \
1687   && test "TEMPLATE-TESTS" != "$1"
1688 }
1689
1690 # func_verify_module
1691 # verifies a module name
1692 # Input:
1693 # - local_gnulib_path  from --local-dir
1694 # - module          module name argument
1695 func_verify_module ()
1696 {
1697   if func_exists_module "$module"; then
1698     # OK, $module is a correct module name.
1699     # Verify that building the module description with 'patch' succeeds.
1700     func_lookup_file "modules/$module"
1701   else
1702     func_warning "module $module doesn't exist"
1703     module=
1704   fi
1705 }
1706
1707 # func_verify_nontests_module
1708 # verifies a module name, excluding tests modules
1709 # Input:
1710 # - local_gnulib_path  from --local-dir
1711 # - module          module name argument
1712 func_verify_nontests_module ()
1713 {
1714   case "$module" in
1715     *-tests ) module= ;;
1716     * ) func_verify_module ;;
1717   esac
1718 }
1719
1720 # func_verify_tests_module
1721 # verifies a module name, considering only tests modules
1722 # Input:
1723 # - local_gnulib_path  from --local-dir
1724 # - module          module name argument
1725 func_verify_tests_module ()
1726 {
1727   case "$module" in
1728     *-tests ) func_verify_module ;;
1729     * ) module= ;;
1730   esac
1731 }
1732
1733 # Suffix of a sed expression that extracts a particular field from a
1734 # module description.
1735 # A field starts with a line that contains a keyword, such as 'Description',
1736 # followed by a colon and optional whitespace. All following lines, up to
1737 # the next field (or end of file if there is none) form the contents of the
1738 # field.
1739 # An absent field is equivalent to a field with empty contents.
1740 # NOTE: Keep this in sync with sed_extract_cache_prog below!
1741 sed_extract_prog=':[     ]*$/ {
1742   :a
1743     n
1744     s/^Description:[     ]*$//
1745     s/^Comment:[         ]*$//
1746     s/^Status:[  ]*$//
1747     s/^Notice:[  ]*$//
1748     s/^Applicability:[   ]*$//
1749     s/^Files:[   ]*$//
1750     s/^Depends-on:[      ]*$//
1751     s/^configure\.ac-early:[     ]*$//
1752     s/^configure\.ac:[   ]*$//
1753     s/^Makefile\.am:[    ]*$//
1754     s/^Include:[         ]*$//
1755     s/^Link:[    ]*$//
1756     s/^License:[         ]*$//
1757     s/^Maintainer:[      ]*$//
1758     tb
1759     p
1760     ba
1761   :b
1762 }'
1763
1764 # Piece of a sed expression that converts a field header line to a shell
1765 # variable name,
1766 # NOTE: Keep this in sync with sed_extract_prog above!
1767 sed_extract_field_header='
1768   s/^Description:[       ]*$/description/
1769   s/^Comment:[   ]*$/comment/
1770   s/^Status:[    ]*$/status/
1771   s/^Notice:[    ]*$/notice/
1772   s/^Applicability:[     ]*$/applicability/
1773   s/^Files:[     ]*$/files/
1774   s/^Depends-on:[        ]*$/dependson/
1775   s/^configure\.ac-early:[       ]*$/configureac_early/
1776   s/^configure\.ac:[     ]*$/configureac/
1777   s/^Makefile\.am:[      ]*$/makefile/
1778   s/^Include:[   ]*$/include/
1779   s/^Link:[      ]*$/link/
1780   s/^License:[   ]*$/license/
1781   s/^Maintainer:[        ]*$/maintainer/'
1782
1783 if $modcache; then
1784
1785   if $have_associative; then
1786
1787     # Declare the associative arrays.
1788     declare -A modcache_cached
1789     sed_to_declare_statement='s|^.*/\([a-zA-Z0-9_]*\)/$|declare -A modcache_\1|p'
1790     declare_script=`echo "$sed_extract_field_header" | sed -n -e "$sed_to_declare_statement"`
1791     eval "$declare_script"
1792
1793   else
1794
1795     # func_cache_var module
1796     # computes the cache variable name corresponding to $module.
1797     # Note: This computation can map different module names to the same
1798     # cachevar (such as 'foo-bar', 'foo_bar', or 'foo/bar'); the caller has
1799     # to protect against this case.
1800     # Output:
1801     # - cachevar               a shell variable name
1802     if (f=foo; eval echo '${f//o/e}') < /dev/null 2>/dev/null | grep fee >/dev/null; then
1803       # Bash 2.0 and newer, ksh, and zsh support the syntax
1804       #   ${param//pattern/replacement}
1805       # as a shorthand for
1806       #   `echo "$param" | sed -e "s/pattern/replacement/g"`.
1807       # Note: The 'eval' is necessary for dash and NetBSD /bin/sh.
1808       eval 'func_cache_var ()
1809       {
1810         cachevar=c_${1//[!a-zA-Z0-9_]/_}
1811       }'
1812     else
1813       func_cache_var ()
1814       {
1815         case $1 in
1816           *[!a-zA-Z0-9_]*)
1817             cachevar=c_`echo "$1" | LC_ALL=C sed -e 's/[^a-zA-Z0-9_]/_/g'` ;;
1818           *)
1819             cachevar=c_$1 ;;
1820         esac
1821       }
1822     fi
1823
1824   fi
1825
1826   # func_init_sed_convert_to_cache_statements
1827   # Input:
1828   # - modcachevar_assignment
1829   # Output:
1830   # - sed_convert_to_cache_statements
1831   func_init_sed_convert_to_cache_statements ()
1832   {
1833     # 'sed' script that turns a module description into shell script
1834     # assignments, suitable to be eval'ed.  All active characters are escaped.
1835     # This script turns
1836     #   Description:
1837     #   Some module's description
1838     #
1839     #   Files:
1840     #   lib/file.h
1841     # into:
1842     #   modcache_description[$1]=\
1843     #   'Some module'"'"'s description
1844     #   '
1845     #   modcache_files[$1]=\
1846     #   'lib/file.h'
1847     # or:
1848     #   c_MODULE_description_set=set; c_MODULE_description=\
1849     #   'Some module'"'"'s description
1850     #   '
1851     #   c_MODULE_files_set=set; c_MODULE_files=\
1852     #   'lib/file.h'
1853     # The script consists of two parts:
1854     # 1) Ignore the lines before the first field header.
1855     # 2) A loop, treating non-field-header lines by escaping single quotes
1856     #    and adding a closing quote in the last line,
1857     sed_convert_to_cache_statements="
1858       :llla
1859         # Here we have not yet seen a field header.
1860
1861         # See if the current line contains a field header.
1862         t llla1
1863         :llla1
1864         ${sed_extract_field_header}
1865         t lllb
1866
1867         # No field header. Ignore the line.
1868
1869         # Read the next line. Upon EOF, just exit.
1870         n
1871       b llla
1872
1873       :lllb
1874         # The current line contains a field header.
1875
1876         # Turn it into the beginning of an assignment.
1877         s/^\\(.*\\)\$/${modcachevar_assignment}\\\\/
1878
1879         # Move it to the hold space. Don't print it yet,
1880         # because we want no assignment if the field is empty.
1881         h
1882
1883         # Read the next line.
1884         # Upon EOF, the field was empty. Print no assignment. Just exit.
1885         n
1886
1887         # See if the current line contains a field header.
1888         t lllb1
1889         :lllb1
1890         ${sed_extract_field_header}
1891         # If it is, the previous field was empty. Print no assignment.
1892         t lllb
1893
1894         # Not a field header.
1895
1896         # Print the previous line, held in the hold space.
1897         x
1898         p
1899         x
1900
1901         # Transform single quotes.
1902         s/'/'\"'\"'/g
1903
1904         # Prepend a single quote.
1905         s/^/'/
1906
1907         :lllc
1908
1909           # Move it to the hold space.
1910           h
1911
1912           # Read the next line.
1913           # Upon EOF, branch.
1914           \${
1915             b llle
1916           }
1917           n
1918
1919           # See if the current line contains a field header.
1920           t lllc1
1921           :lllc1
1922           ${sed_extract_field_header}
1923           t llld
1924
1925           # Print the previous line, held in the hold space.
1926           x
1927           p
1928           x
1929
1930           # Transform single quotes.
1931           s/'/'\"'\"'/g
1932
1933         b lllc
1934
1935         :llld
1936         # A field header.
1937         # Print the previous line, held in the hold space, with a single quote
1938         # to end the assignment.
1939         x
1940         s/\$/'/
1941         p
1942         x
1943
1944       b lllb
1945
1946       :llle
1947       # EOF seen.
1948       # Print the previous line, held in the hold space, with a single quote
1949       # to end the assignment.
1950       x
1951       s/\$/'/
1952       p
1953       # Exit.
1954       n
1955       "
1956     if ! $sed_comments; then
1957       # Remove comments.
1958       sed_convert_to_cache_statements=`echo "$sed_convert_to_cache_statements" \
1959                                        | sed -e 's/^ *//' -e 's/^#.*//'`
1960     fi
1961   }
1962
1963   if $have_associative; then
1964     # sed_convert_to_cache_statements does not depend on the module.
1965     modcachevar_assignment='modcache_\1[$1]='
1966     func_init_sed_convert_to_cache_statements
1967   fi
1968
1969   # func_cache_lookup_module module
1970   #
1971   # looks up a module, like 'func_lookup_file modules/$module', and stores all
1972   # of its relevant data in a cache in the memory of the processing shell.  If
1973   # already cached, it does not look it up again, thus saving file access time.
1974   # Parameters:
1975   # - module                             non-empty string
1976   # Output if $have_associative:
1977   # - modcache_cached[$module]           set to yes
1978   # - modcache_description[$module] ==
1979   # - modcache_status[$module]        \  set to the field's value, minus the
1980   # - ...                             /  final newline,
1981   # - modcache_maintainer[$module]  ==   or unset if the field's value is empty
1982   # Output if ! $have_associative:
1983   # - cachevar                           a shell variable name
1984   # - ${cachevar}_cached                 set to $module
1985   # - ${cachevar}_description       ==
1986   # - ${cachevar}_status              \  set to the field's value, minus the
1987   # - ...                             /  final newline,
1988   # - ${cachevar}_maintainer        ==   or unset if the field's value is empty
1989   # - ${cachevar}_description_set   ==
1990   # - ${cachevar}_status_set          \  set to non-empty if the field's value
1991   # - ...                             /  is non-empty,
1992   # - ${cachevar}_maintainer_set    ==   or unset if the field's value is empty
1993   func_cache_lookup_module ()
1994   {
1995     if $have_associative; then
1996       eval 'cached=${modcache_cached[$1]}'
1997     else
1998       func_cache_var "$1"
1999       eval "cached=\"\$${cachevar}_cached\""
2000     fi
2001     if test -z "$cached"; then
2002       # Not found in cache. Look it up on the file system.
2003       func_lookup_file "modules/$1"
2004       if $have_associative; then
2005         eval 'modcache_cached[$1]=yes'
2006       else
2007         eval "${cachevar}_cached=\"\$1\""
2008       fi
2009       if ! $have_associative; then
2010         # sed_convert_to_cache_statements depends on the module.
2011         modcachevar_assignment="${cachevar}"'_\1_set=set; '"${cachevar}"'_\1='
2012         func_init_sed_convert_to_cache_statements
2013       fi
2014       cache_statements=`LC_ALL=C sed -n -e "$sed_convert_to_cache_statements" < "$lookedup_file"`
2015       eval "$cache_statements"
2016     else
2017       if ! $have_associative; then
2018         if test "$1" != "$cached"; then
2019           func_fatal_error "cache variable collision between $1 and $cached"
2020         fi
2021       fi
2022     fi
2023   }
2024
2025 fi
2026
2027 # func_get_description module
2028 # Input:
2029 # - local_gnulib_path  from --local-dir
2030 # - modcache          true or false, from --cache-modules/--no-cache-modules
2031 func_get_description ()
2032 {
2033   if ! $modcache; then
2034     func_lookup_file "modules/$1"
2035     sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
2036   else
2037     func_cache_lookup_module "$1"
2038     # Output the field's value, including the final newline (if any).
2039     if $have_associative; then
2040       if eval 'test -n "${modcache_description[$1]+set}"'; then
2041         eval 'echo "${modcache_description[$1]}"'
2042       fi
2043     else
2044       eval "field_set=\"\$${cachevar}_description_set\""
2045       if test -n "$field_set"; then
2046         eval "field_value=\"\$${cachevar}_description\""
2047         echo "${field_value}"
2048       fi
2049     fi
2050   fi
2051 }
2052
2053 # func_get_comment module
2054 # Input:
2055 # - local_gnulib_path  from --local-dir
2056 # - modcache          true or false, from --cache-modules/--no-cache-modules
2057 func_get_comment ()
2058 {
2059   if ! $modcache; then
2060     func_lookup_file "modules/$1"
2061     sed -n -e "/^Comment$sed_extract_prog" < "$lookedup_file"
2062   else
2063     func_cache_lookup_module "$1"
2064     # Output the field's value, including the final newline (if any).
2065     if $have_associative; then
2066       if eval 'test -n "${modcache_comment[$1]+set}"'; then
2067         eval 'echo "${modcache_comment[$1]}"'
2068       fi
2069     else
2070       eval "field_set=\"\$${cachevar}_comment_set\""
2071       if test -n "$field_set"; then
2072         eval "field_value=\"\$${cachevar}_comment\""
2073         echo "${field_value}"
2074       fi
2075     fi
2076   fi
2077 }
2078
2079 # func_get_status module
2080 # Input:
2081 # - local_gnulib_path  from --local-dir
2082 # - modcache          true or false, from --cache-modules/--no-cache-modules
2083 func_get_status ()
2084 {
2085   if ! $modcache; then
2086     func_lookup_file "modules/$1"
2087     sed -n -e "/^Status$sed_extract_prog" < "$lookedup_file"
2088   else
2089     func_cache_lookup_module "$1"
2090     # Output the field's value, including the final newline (if any).
2091     if $have_associative; then
2092       if eval 'test -n "${modcache_status[$1]+set}"'; then
2093         eval 'echo "${modcache_status[$1]}"'
2094       fi
2095     else
2096       eval "field_set=\"\$${cachevar}_status_set\""
2097       if test -n "$field_set"; then
2098         eval "field_value=\"\$${cachevar}_status\""
2099         echo "${field_value}"
2100       fi
2101     fi
2102   fi
2103 }
2104
2105 # func_get_notice module
2106 # Input:
2107 # - local_gnulib_path  from --local-dir
2108 # - modcache          true or false, from --cache-modules/--no-cache-modules
2109 func_get_notice ()
2110 {
2111   if ! $modcache; then
2112     func_lookup_file "modules/$1"
2113     sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"
2114   else
2115     func_cache_lookup_module "$1"
2116     # Output the field's value, including the final newline (if any).
2117     if $have_associative; then
2118       if eval 'test -n "${modcache_notice[$1]+set}"'; then
2119         eval 'echo "${modcache_notice[$1]}"'
2120       fi
2121     else
2122       eval "field_set=\"\$${cachevar}_notice_set\""
2123       if test -n "$field_set"; then
2124         eval "field_value=\"\$${cachevar}_notice\""
2125         echo "${field_value}"
2126       fi
2127     fi
2128   fi
2129 }
2130
2131 # func_get_applicability module
2132 # Input:
2133 # - local_gnulib_path  from --local-dir
2134 # - modcache          true or false, from --cache-modules/--no-cache-modules
2135 # The expected result (on stdout) is either 'main', or 'tests', or 'all'.
2136 func_get_applicability ()
2137 {
2138   if ! $modcache; then
2139     func_lookup_file "modules/$1"
2140     my_applicability=`sed -n -e "/^Applicability$sed_extract_prog" < "$lookedup_file"`
2141   else
2142     func_cache_lookup_module "$1"
2143     # Get the field's value, without the final newline.
2144     if $have_associative; then
2145       eval 'my_applicability="${modcache_applicability[$1]}"'
2146     else
2147       eval "my_applicability=\"\$${cachevar}_applicability\""
2148     fi
2149   fi
2150   if test -n "$my_applicability"; then
2151     echo $my_applicability
2152   else
2153     # The default is 'main' or 'tests', depending on the module's name.
2154     case $1 in
2155       *-tests) echo "tests";;
2156       *)       echo "main";;
2157     esac
2158   fi
2159 }
2160
2161 # func_get_filelist module
2162 # Input:
2163 # - local_gnulib_path  from --local-dir
2164 # - modcache          true or false, from --cache-modules/--no-cache-modules
2165 func_get_filelist ()
2166 {
2167   if ! $modcache; then
2168     func_lookup_file "modules/$1"
2169     sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
2170   else
2171     func_cache_lookup_module "$1"
2172     # Output the field's value, including the final newline (if any).
2173     if $have_associative; then
2174       if eval 'test -n "${modcache_files[$1]+set}"'; then
2175         eval 'echo "${modcache_files[$1]}"'
2176       fi
2177     else
2178       eval "field_set=\"\$${cachevar}_files_set\""
2179       if test -n "$field_set"; then
2180         eval "field_value=\"\$${cachevar}_files\""
2181         echo "${field_value}"
2182       fi
2183     fi
2184   fi
2185   echo m4/00gnulib.m4
2186   echo m4/gnulib-common.m4
2187   case "$autoconf_minversion" in
2188     2.59)
2189       echo m4/onceonly.m4
2190       ;;
2191   esac
2192 }
2193
2194 # func_filter_filelist outputvar separator filelist prefix suffix removed_prefix removed_suffix [added_prefix [added_suffix]]
2195 # stores in outputvar the filtered and processed filelist. Filtering: Only the
2196 # elements starting with prefix and ending with suffix are considered.
2197 # Processing: removed_prefix and removed_suffix are removed from each element,
2198 # added_prefix and added_suffix are added to each element.
2199 # prefix, suffix should not contain shell-special characters.
2200 # removed_prefix, removed_suffix should not contain the characters "$`\{}[]^|.
2201 # added_prefix, added_suffix should not contain the characters \|&.
2202 func_filter_filelist ()
2203 {
2204   if test "$2" != "$nl" \
2205      || { $fast_func_append \
2206           && { test -z "$6" || $fast_func_remove_prefix; } \
2207           && { test -z "$7" || $fast_func_remove_suffix; }; \
2208         }; then
2209     ffflist=
2210     for fff in $3; do
2211       # Do not quote possibly-empty parameters in case patterns,
2212       # AIX and HP-UX ksh won't match them if they are empty.
2213       case "$fff" in
2214         $4*$5)
2215           if test -n "$6"; then
2216             func_remove_prefix fff "$6"
2217           fi
2218           if test -n "$7"; then
2219             func_remove_suffix fff "$7"
2220           fi
2221           fff="$8${fff}$9"
2222           if test -z "$ffflist"; then
2223             ffflist="${fff}"
2224           else
2225             func_append ffflist "$2${fff}"
2226           fi
2227           ;;
2228       esac
2229     done
2230   else
2231     sed_fff_filter="s|^$6\(.*\)$7\$|$8\\1$9|"
2232     ffflist=`for fff in $3; do
2233                case "$fff" in
2234                  $4*$5) echo "$fff" ;;
2235                esac
2236              done | sed -e "$sed_fff_filter"`
2237   fi
2238   eval "$1=\"\$ffflist\""
2239 }
2240
2241 # func_get_dependencies module
2242 # Input:
2243 # - local_gnulib_path  from --local-dir
2244 # - modcache          true or false, from --cache-modules/--no-cache-modules
2245 func_get_dependencies ()
2246 {
2247   # ${module}-tests implicitly depends on ${module}, if that module exists.
2248   case "$1" in
2249     *-tests)
2250       fgd1="$1"
2251       func_remove_suffix fgd1 '-tests'
2252       if func_exists_module "$fgd1"; then
2253         echo "$fgd1"
2254       fi
2255       ;;
2256   esac
2257   # Then the explicit dependencies listed in the module description.
2258   { if ! $modcache; then
2259       func_lookup_file "modules/$1"
2260       sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
2261     else
2262       func_cache_lookup_module "$1"
2263       # Output the field's value, including the final newline (if any).
2264       if $have_associative; then
2265         if eval 'test -n "${modcache_dependson[$1]+set}"'; then
2266           eval 'echo "${modcache_dependson[$1]}"'
2267         fi
2268       else
2269         eval "field_set=\"\$${cachevar}_dependson_set\""
2270         if test -n "$field_set"; then
2271           eval "field_value=\"\$${cachevar}_dependson\""
2272           echo "${field_value}"
2273         fi
2274       fi
2275     fi
2276   } \
2277   | sed -e '/^#/d'
2278 }
2279
2280 # func_get_autoconf_early_snippet module
2281 # Input:
2282 # - local_gnulib_path  from --local-dir
2283 # - modcache          true or false, from --cache-modules/--no-cache-modules
2284 func_get_autoconf_early_snippet ()
2285 {
2286   if ! $modcache; then
2287     func_lookup_file "modules/$1"
2288     sed -n -e "/^configure\.ac-early$sed_extract_prog" < "$lookedup_file"
2289   else
2290     func_cache_lookup_module "$1"
2291     # Output the field's value, including the final newline (if any).
2292     if $have_associative; then
2293       if eval 'test -n "${modcache_configureac_early[$1]+set}"'; then
2294         eval 'echo "${modcache_configureac_early[$1]}"'
2295       fi
2296     else
2297       eval "field_set=\"\$${cachevar}_configureac_early_set\""
2298       if test -n "$field_set"; then
2299         eval "field_value=\"\$${cachevar}_configureac_early\""
2300         echo "${field_value}"
2301       fi
2302     fi
2303   fi
2304 }
2305
2306 # func_get_autoconf_snippet module
2307 # Input:
2308 # - local_gnulib_path  from --local-dir
2309 # - modcache          true or false, from --cache-modules/--no-cache-modules
2310 func_get_autoconf_snippet ()
2311 {
2312   if ! $modcache; then
2313     func_lookup_file "modules/$1"
2314     sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
2315   else
2316     func_cache_lookup_module "$1"
2317     # Output the field's value, including the final newline (if any).
2318     if $have_associative; then
2319       if eval 'test -n "${modcache_configureac[$1]+set}"'; then
2320         eval 'echo "${modcache_configureac[$1]}"'
2321       fi
2322     else
2323       eval "field_set=\"\$${cachevar}_configureac_set\""
2324       if test -n "$field_set"; then
2325         eval "field_value=\"\$${cachevar}_configureac\""
2326         echo "${field_value}"
2327       fi
2328     fi
2329   fi
2330 }
2331
2332 # Concatenate lines with trailing slash.
2333 # $1 is an optional filter to restrict the
2334 # concatenation to groups starting with that expression
2335 combine_lines() {
2336   sed -e "/$1.*"'\\$/{
2337     :a
2338     N
2339     s/\\\n/ /
2340     s/\\$/\\/
2341     ta
2342   }'
2343 }
2344
2345 # func_get_automake_snippet_conditional module
2346 # returns the part of the Makefile.am snippet that can be put inside Automake
2347 # conditionals.
2348 # Input:
2349 # - local_gnulib_path  from --local-dir
2350 # - modcache          true or false, from --cache-modules/--no-cache-modules
2351 func_get_automake_snippet_conditional ()
2352 {
2353   if ! $modcache; then
2354     func_lookup_file "modules/$1"
2355     sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
2356   else
2357     func_cache_lookup_module "$1"
2358     # Output the field's value, including the final newline (if any).
2359     if $have_associative; then
2360       if eval 'test -n "${modcache_makefile[$1]+set}"'; then
2361         eval 'echo "${modcache_makefile[$1]}"'
2362       fi
2363     else
2364       eval "field_set=\"\$${cachevar}_makefile_set\""
2365       if test -n "$field_set"; then
2366         eval "field_value=\"\$${cachevar}_makefile\""
2367         echo "${field_value}"
2368       fi
2369     fi
2370   fi
2371 }
2372
2373 # func_get_automake_snippet_unconditional module
2374 # returns the part of the Makefile.am snippet that must stay outside of
2375 # Automake conditionals.
2376 # Input:
2377 # - local_gnulib_path  from --local-dir
2378 # - modcache          true or false, from --cache-modules/--no-cache-modules
2379 func_get_automake_snippet_unconditional ()
2380 {
2381   case "$1" in
2382     *-tests)
2383       # *-tests module live in tests/, not lib/.
2384       # Synthesize an EXTRA_DIST augmentation.
2385       all_files=`func_get_filelist $1`
2386       func_filter_filelist tests_files " " "$all_files" 'tests/' '' 'tests/' ''
2387       extra_files="$tests_files"
2388       if test -n "$extra_files"; then
2389         echo "EXTRA_DIST +=" $extra_files
2390         echo
2391       fi
2392       ;;
2393     *)
2394       # Synthesize an EXTRA_DIST augmentation.
2395       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
2396       already_mentioned_files=` \
2397         { if ! $modcache; then
2398             func_lookup_file "modules/$1"
2399             sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
2400           else
2401             func_cache_lookup_module "$1"
2402             if $have_associative; then
2403               if eval 'test -n "${modcache_makefile[$1]+set}"'; then
2404                 eval 'echo "${modcache_makefile[$1]}"'
2405               fi
2406             else
2407               eval 'field_set="$'"${cachevar}"'_makefile_set"'
2408               if test -n "$field_set"; then
2409                 eval 'field_value="$'"${cachevar}"'_makefile"'
2410                 echo "${field_value}"
2411               fi
2412             fi
2413           fi
2414         } \
2415         | combine_lines \
2416         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
2417       all_files=`func_get_filelist $1`
2418       func_filter_filelist lib_files "$nl" "$all_files" 'lib/' '' 'lib/' ''
2419       # Remove $already_mentioned_files from $lib_files.
2420       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
2421       extra_files=`for f in $already_mentioned_files; do echo $f; done \
2422                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
2423       if test -n "$extra_files"; then
2424         echo "EXTRA_DIST +=" $extra_files
2425         echo
2426       fi
2427       # Synthesize also an EXTRA_lib_SOURCES augmentation.
2428       # This is necessary so that automake can generate the right list of
2429       # dependency rules.
2430       # A possible approach would be to use autom4te --trace of the redefined
2431       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
2432       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
2433       # inside autoconf's built-in macros are not missed).
2434       # But it's simpler and more robust to do it here, based on the file list.
2435       # If some .c file exists and is not used with AC_LIBOBJ - for example,
2436       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
2437       # automake will generate a useless dependency; this is harmless.
2438       case "$1" in
2439         relocatable-prog-wrapper) ;;
2440         pt_chown) ;;
2441         *)
2442           func_filter_filelist extra_files "$nl" "$extra_files" '' '.c' '' ''
2443           if test -n "$extra_files"; then
2444             echo "EXTRA_lib_SOURCES +=" $extra_files
2445             echo
2446           fi
2447           ;;
2448       esac
2449       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
2450       func_filter_filelist buildaux_files "$nl" "$all_files" 'build-aux/' '' 'build-aux/' ''
2451       if test -n "$buildaux_files"; then
2452         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
2453         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
2454         echo
2455       fi
2456       # Synthesize an EXTRA_DIST augmentation also for the files from top/.
2457       func_filter_filelist top_files "$nl" "$all_files" 'top/' '' 'top/' ''
2458       if test -n "$top_files"; then
2459         sed_prepend_topdir='s,^,$(top_srcdir)/,'
2460         echo "EXTRA_DIST += "`echo "$top_files" | sed -e "$sed_prepend_topdir"`
2461         echo
2462       fi
2463       ;;
2464   esac
2465 }
2466
2467 # func_get_automake_snippet module
2468 # Input:
2469 # - local_gnulib_path  from --local-dir
2470 # - modcache          true or false, from --cache-modules/--no-cache-modules
2471 func_get_automake_snippet ()
2472 {
2473   func_get_automake_snippet_conditional "$1"
2474   func_get_automake_snippet_unconditional "$1"
2475 }
2476
2477 # func_get_include_directive module
2478 # Input:
2479 # - local_gnulib_path  from --local-dir
2480 # - modcache          true or false, from --cache-modules/--no-cache-modules
2481 func_get_include_directive ()
2482 {
2483   {
2484     if ! $modcache; then
2485       func_lookup_file "modules/$1"
2486       sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file"
2487     else
2488       func_cache_lookup_module "$1"
2489       # Output the field's value, including the final newline (if any).
2490       if $have_associative; then
2491         if eval 'test -n "${modcache_include[$1]+set}"'; then
2492           eval 'echo "${modcache_include[$1]}"'
2493         fi
2494       else
2495         eval "field_set=\"\$${cachevar}_include_set\""
2496         if test -n "$field_set"; then
2497           eval "field_value=\"\$${cachevar}_include\""
2498           echo "${field_value}"
2499         fi
2500       fi
2501     fi
2502   } | sed -e 's/^\(["<]\)/#include \1/'
2503 }
2504
2505 # func_get_link_directive module
2506 # Input:
2507 # - local_gnulib_path  from --local-dir
2508 # - modcache          true or false, from --cache-modules/--no-cache-modules
2509 func_get_link_directive ()
2510 {
2511   if ! $modcache; then
2512     func_lookup_file "modules/$1"
2513     sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
2514   else
2515     func_cache_lookup_module "$1"
2516     # Output the field's value, including the final newline (if any).
2517     if $have_associative; then
2518       if eval 'test -n "${modcache_link[$1]+set}"'; then
2519         eval 'echo "${modcache_link[$1]}"'
2520       fi
2521     else
2522       eval "field_set=\"\$${cachevar}_link_set\""
2523       if test -n "$field_set"; then
2524         eval "field_value=\"\$${cachevar}_link\""
2525         echo "${field_value}"
2526       fi
2527     fi
2528   fi
2529 }
2530
2531 # func_get_license_raw module
2532 # Input:
2533 # - local_gnulib_path  from --local-dir
2534 # - modcache          true or false, from --cache-modules/--no-cache-modules
2535 func_get_license_raw ()
2536 {
2537   if ! $modcache; then
2538     func_lookup_file "modules/$1"
2539     sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
2540   else
2541     func_cache_lookup_module "$1"
2542     # Output the field's value, including the final newline (if any).
2543     if $have_associative; then
2544       if eval 'test -n "${modcache_license[$1]+set}"'; then
2545         eval 'echo "${modcache_license[$1]}"'
2546       fi
2547     else
2548       eval "field_set=\"\$${cachevar}_license_set\""
2549       if test -n "$field_set"; then
2550         eval "field_value=\"\$${cachevar}_license\""
2551         echo "${field_value}"
2552       fi
2553     fi
2554   fi
2555 }
2556
2557 # func_get_license module
2558 # Input:
2559 # - local_gnulib_path  from --local-dir
2560 # - modcache          true or false, from --cache-modules/--no-cache-modules
2561 func_get_license ()
2562 {
2563   # Warn if the License field is missing.
2564   case "$1" in
2565     *-tests ) ;;
2566     * )
2567       license=`func_get_license_raw "$1"`
2568       if test -z "$license"; then
2569         func_warning "module $1 lacks a License"
2570       fi
2571       ;;
2572   esac
2573   {
2574     func_get_license_raw "$1"
2575     # The default is GPL.
2576     echo "GPL"
2577   } | sed -e 's,^ *$,,' | sed -e 1q
2578 }
2579
2580 # func_get_maintainer module
2581 # Input:
2582 # - local_gnulib_path  from --local-dir
2583 # - modcache          true or false, from --cache-modules/--no-cache-modules
2584 func_get_maintainer ()
2585 {
2586   if ! $modcache; then
2587     func_lookup_file "modules/$1"
2588     sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
2589   else
2590     func_cache_lookup_module "$1"
2591     # Output the field's value, including the final newline (if any).
2592     if $have_associative; then
2593       if eval 'test -n "${modcache_maintainer[$1]+set}"'; then
2594         eval 'echo "${modcache_maintainer[$1]}"'
2595       fi
2596     else
2597       eval "field_set=\"\$${cachevar}_maintainer_set\""
2598       if test -n "$field_set"; then
2599         eval "field_value=\"\$${cachevar}_maintainer\""
2600         echo "${field_value}"
2601       fi
2602     fi
2603   fi
2604 }
2605
2606 # func_get_tests_module module
2607 # Input:
2608 # - local_gnulib_path  from --local-dir
2609 func_get_tests_module ()
2610 {
2611   # The naming convention for tests modules is hardwired: ${module}-tests.
2612   if test -f "$gnulib_dir/modules/$1"-tests \
2613      || func_path_foreach "$local_gnulib_path" func_exists_local_module %dir% "$1-tests"; then
2614     echo "$1"-tests
2615   fi
2616 }
2617
2618 # func_acceptable module
2619 # tests whether a module is acceptable.
2620 # Input:
2621 # - avoidlist       list of modules to avoid
2622 func_acceptable ()
2623 {
2624   for avoid in $avoidlist; do
2625     if test "$avoid" = "$1"; then
2626       return 1
2627     fi
2628   done
2629   return 0
2630 }
2631
2632 # sed expression to keep the first 32 characters of each line.
2633 sed_first_32_chars='s/^\(................................\).*/\1/'
2634
2635 # func_module_shellfunc_name module
2636 # computes the shell function name that will contain the m4 macros for the module.
2637 # Input:
2638 # - macro_prefix    prefix to use
2639 # Output:
2640 # - shellfunc       shell function name
2641 func_module_shellfunc_name ()
2642 {
2643   case $1 in
2644     *[!a-zA-Z0-9_]*)
2645       shellfunc=func_${macro_prefix}_gnulib_m4code_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2646     *)
2647       shellfunc=func_${macro_prefix}_gnulib_m4code_$1 ;;
2648   esac
2649 }
2650
2651 # func_module_shellvar_name module
2652 # computes the shell variable name the will be set to true once the m4 macros
2653 # for the module have been executed.
2654 # Output:
2655 # - shellvar        shell variable name
2656 func_module_shellvar_name ()
2657 {
2658   case $1 in
2659     *[!a-zA-Z0-9_]*)
2660       shellvar=${macro_prefix}_gnulib_enabled_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2661     *)
2662       shellvar=${macro_prefix}_gnulib_enabled_$1 ;;
2663   esac
2664 }
2665
2666 # func_module_conditional_name module
2667 # computes the automake conditional name for the module.
2668 # Output:
2669 # - conditional     name of automake conditional
2670 func_module_conditional_name ()
2671 {
2672   case $1 in
2673     *[!a-zA-Z0-9_]*)
2674       conditional=${macro_prefix}_GNULIB_ENABLED_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2675     *)
2676       conditional=${macro_prefix}_GNULIB_ENABLED_$1 ;;
2677   esac
2678 }
2679
2680 # func_uncond_add_module B
2681 # notes the presence of B as an unconditional module.
2682 #
2683 # func_conddep_add_module A B cond
2684 # notes the presence of a conditional dependency from module A to module B,
2685 # subject to the condition that A is enabled and cond is true.
2686 #
2687 # func_cond_module_p B
2688 # tests whether module B is conditional.
2689 #
2690 # func_cond_module_condition A B
2691 # returns the condition when B should be enabled as a dependency of A, once the
2692 # m4 code for A has been executed.
2693 # Output: - condition
2694 #
2695 if $have_associative; then
2696   declare -A conddep_isuncond
2697   declare -A conddep_dependers
2698   declare -A conddep_condition
2699   func_uncond_add_module ()
2700   {
2701     eval 'conddep_isuncond[$1]=true'
2702     eval 'unset conddep_dependers[$1]'
2703   }
2704   func_conddep_add_module ()
2705   {
2706     eval 'isuncond="${conddep_isuncond[$2]}"'
2707     if test -z "$isuncond"; then
2708       # No unconditional dependency to B known at this point.
2709       eval 'conddep_dependers[$2]="${conddep_dependers[$2]} $1"'
2710       eval 'conddep_condition[$1---$2]="$3"'
2711     fi
2712   }
2713   func_cond_module_p ()
2714   {
2715     eval 'previous_dependers="${conddep_dependers[$1]}"'
2716     test -n "$previous_dependers"
2717   }
2718   func_cond_module_condition ()
2719   {
2720     eval 'condition="${conddep_condition[$1---$2]}"'
2721   }
2722 else
2723   func_uncond_add_module ()
2724   {
2725     case $1 in
2726       *[!a-zA-Z0-9_]*)
2727         suffix=`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2728       *)
2729         suffix=$1 ;;
2730     esac
2731     eval 'conddep_isuncond_'"$suffix"'=true'
2732     eval 'unset conddep_dependers_'"$suffix"
2733   }
2734   func_conddep_add_module ()
2735   {
2736     case $2 in
2737       *[!a-zA-Z0-9_]*)
2738         suffix=`echo "$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2739       *)
2740         suffix=$2 ;;
2741     esac
2742     eval 'isuncond="${conddep_isuncond_'"$suffix"'}"'
2743     if test -z "$isuncond"; then
2744       eval 'conddep_dependers_'"$suffix"'="${conddep_dependers_'"$suffix"'} $1"'
2745       suffix=`echo "$1---$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"`
2746       eval 'conddep_condition_'"$suffix"'="$3"'
2747     fi
2748   }
2749   func_cond_module_p ()
2750   {
2751     case $1 in
2752       *[!a-zA-Z0-9_]*)
2753         suffix=`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2754       *)
2755         suffix=$1 ;;
2756     esac
2757     eval 'previous_dependers="${conddep_dependers_'"$suffix"'}"'
2758     test -n "$previous_dependers"
2759   }
2760   func_cond_module_condition ()
2761   {
2762     suffix=`echo "$1---$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"`
2763     eval 'condition="${conddep_condition_'"$suffix"'}"'
2764   }
2765 fi
2766
2767 sed_dependencies_without_conditions='s/ *\[.*//'
2768
2769 # func_modules_transitive_closure
2770 # Input:
2771 # - local_gnulib_path  from --local-dir
2772 # - modcache        true or false, from --cache-modules/--no-cache-modules
2773 # - modules         list of specified modules
2774 # - inctests        true if tests should be included, false otherwise
2775 # - incobsolete     true if obsolete modules among dependencies should be
2776 #                   included, blank otherwise
2777 # - inc_cxx_tests   true if C++ interoperability tests should be included,
2778 #                   blank otherwise
2779 # - inc_longrunning_tests  true if long-runnings tests should be included,
2780 #                          blank otherwise
2781 # - inc_privileged_tests  true if tests that require root privileges should be
2782 #                         included, blank otherwise
2783 # - inc_unportable_tests  true if tests that fail on some platforms should be
2784 #                         included, blank otherwise
2785 # - inc_all_direct_tests   true if all kinds of problematic unit tests among
2786 #                          the unit tests of the specified modules should be
2787 #                          included, blank otherwise
2788 # - inc_all_indirect_tests   true if all kinds of problematic unit tests among
2789 #                            the unit tests of the dependencies should be
2790 #                            included, blank otherwise
2791 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
2792 #                    blank otherwise
2793 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
2794 #                           blank otherwise
2795 # - excl_privileged_tests  true if tests that require root privileges should be
2796 #                          excluded, blank otherwise
2797 # - excl_unportable_tests  true if tests that fail on some platforms should be
2798 #                          excluded, blank otherwise
2799 # - avoidlist       list of modules to avoid
2800 # - cond_dependencies  true if conditional dependencies shall be supported,
2801 #                      blank otherwise
2802 # - tmp             pathname of a temporary directory
2803 # Output:
2804 # - modules         list of modules, including dependencies
2805 # - conddep_dependers, conddep_condition  information about conditionally
2806 #                                         enabled modules
2807 func_modules_transitive_closure ()
2808 {
2809   sed_escape_dependency='s|\([/.]\)|\\\1|g'
2810   # In order to process every module only once (for speed), process an "input
2811   # list" of modules, producing an "output list" of modules. During each round,
2812   # more modules can be queued in the input list. Once a module on the input
2813   # list has been processed, it is added to the "handled list", so we can avoid
2814   # to process it again.
2815   handledmodules=
2816   inmodules="$modules"
2817   outmodules=
2818   fmtc_inc_all_tests="$inc_all_direct_tests"
2819   if test "$cond_dependencies" = true; then
2820     for module in $inmodules; do
2821       func_verify_module
2822       if test -n "$module"; then
2823         if func_acceptable $module; then
2824           func_uncond_add_module $module
2825         fi
2826       fi
2827     done
2828   fi
2829   while test -n "$inmodules"; do
2830     inmodules_this_round="$inmodules"
2831     inmodules=                    # Accumulator, queue for next round
2832     for module in $inmodules_this_round; do
2833       func_verify_module
2834       if test -n "$module"; then
2835         if func_acceptable $module; then
2836           func_append outmodules " $module"
2837           if test "$cond_dependencies" = true; then
2838             if func_get_automake_snippet_conditional $module | grep '^if ' > /dev/null; then
2839               # A module whose Makefile.am snippet contains a reference to an
2840               # automake conditional. If we were to use it conditionally, we
2841               # would get an error
2842               #   configure: error: conditional "..." was never defined.
2843               # because automake 1.11.1 does not handle nested conditionals
2844               # correctly. As a workaround, make the module unconditional.
2845               func_uncond_add_module $module
2846             fi
2847             if func_cond_module_p $module; then
2848               conditional=true
2849             else
2850               conditional=false
2851             fi
2852           fi
2853           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
2854           # Duplicate dependencies are harmless, but Jim wants a warning.
2855           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
2856           if test -n "$duplicated_deps"; then
2857             func_warning "module $module has duplicated dependencies: "`echo $duplicated_deps`
2858           fi
2859           if $inctests; then
2860             testsmodule=`func_get_tests_module $module`
2861             if test -n "$testsmodule"; then
2862               deps="$deps $testsmodule"
2863             fi
2864           fi
2865           for dep in $deps; do
2866             # Determine whether to include the dependency or tests module.
2867             inc=true
2868             for word in `func_get_status $dep`; do
2869               case "$word" in
2870                 obsolete)
2871                   test -n "$incobsolete" \
2872                     || inc=false
2873                   ;;
2874                 c++-test)
2875                   test -z "$excl_cxx_tests" \
2876                     || inc=false
2877                   test -n "$fmtc_inc_all_tests" || test -n "$inc_cxx_tests" \
2878                     || inc=false
2879                   ;;
2880                 longrunning-test)
2881                   test -z "$excl_longrunning_tests" \
2882                     || inc=false
2883                   test -n "$fmtc_inc_all_tests" || test -n "$inc_longrunning_tests" \
2884                     || inc=false
2885                   ;;
2886                 privileged-test)
2887                   test -z "$excl_privileged_tests" \
2888                     || inc=false
2889                   test -n "$fmtc_inc_all_tests" || test -n "$inc_privileged_tests" \
2890                     || inc=false
2891                   ;;
2892                 unportable-test)
2893                   test -z "$excl_unportable_tests" \
2894                     || inc=false
2895                   test -n "$fmtc_inc_all_tests" || test -n "$inc_unportable_tests" \
2896                     || inc=false
2897                   ;;
2898                 *-test)
2899                   test -n "$fmtc_inc_all_tests" \
2900                     || inc=false
2901                   ;;
2902               esac
2903             done
2904             if $inc && func_acceptable "$dep"; then
2905               func_append inmodules " $dep"
2906               if test "$cond_dependencies" = true; then
2907                 escaped_dep=`echo "$dep" | sed -e "$sed_escape_dependency"`
2908                 sed_extract_condition1='/^ *'"$escaped_dep"' *$/{
2909                   s/^.*$/true/p
2910                 }'
2911                 sed_extract_condition2='/^ *'"$escaped_dep"' *\[.*\] *$/{
2912                   s/^ *'"$escaped_dep"' *\[\(.*\)\] *$/\1/p
2913                 }'
2914                 condition=`func_get_dependencies $module | sed -n -e "$sed_extract_condition1" -e "$sed_extract_condition2"`
2915                 if test "$condition" = true; then
2916                   condition=
2917                 fi
2918                 if test -n "$condition"; then
2919                   func_conddep_add_module "$module" "$dep" "$condition"
2920                 else
2921                   if $conditional; then
2922                     func_conddep_add_module "$module" "$dep" true
2923                   else
2924                     func_uncond_add_module "$dep"
2925                   fi
2926                 fi
2927               fi
2928             fi
2929           done
2930         fi
2931       fi
2932     done
2933     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
2934     # Remove $handledmodules from $inmodules.
2935     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
2936     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
2937     fmtc_inc_all_tests="$inc_all_indirect_tests"
2938   done
2939   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
2940   rm -f "$tmp"/queued-modules
2941 }
2942
2943 # func_show_module_list
2944 # Input:
2945 # - specified_modules  list of specified modules (one per line, sorted)
2946 # - modules         complete list of modules (one per line, sorted)
2947 # - tmp             pathname of a temporary directory
2948 func_show_module_list ()
2949 {
2950   if case "$TERM" in
2951        xterm*) test -t 1;;
2952        *) false;;
2953      esac; then
2954     # Assume xterm compatible escape sequences.
2955     bold_on=`printf '\033[1m'`
2956     bold_off=`printf '\033[0m'`
2957   else
2958     bold_on=
2959     bold_off=
2960   fi
2961   echo "Module list with included dependencies (indented):"
2962   echo "$specified_modules" | sed -e '/^$/d' -e 's/$/| /' > "$tmp"/specified-modules
2963   echo "$modules" | sed -e '/^$/d' \
2964     | LC_ALL=C join -t '|' -a2 "$tmp"/specified-modules - \
2965     | sed -e 's/^\(.*\)|.*/|\1/' -e 's/^/    /' -e 's/^    |\(.*\)$/  '"${bold_on}"'\1'"${bold_off}"'/'
2966 }
2967
2968 # func_modules_transitive_closure_separately
2969 # Determine main module list and tests-related module list separately.
2970 # The main module list is the transitive closure of the specified modules,
2971 # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2972 # is specified, it will consist only of LGPLed source.
2973 # The tests-related module list is the transitive closure of the specified
2974 # modules, including tests modules, minus the main module list excluding
2975 # modules of applicability 'all'. Its lib/* sources (brought in through
2976 # dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
2977 # source, even if --lgpl is specified.
2978 # Input:
2979 # - local_gnulib_path  from --local-dir
2980 # - modcache        true or false, from --cache-modules/--no-cache-modules
2981 # - specified_modules  list of specified modules
2982 # - inctests        true if tests should be included, false otherwise
2983 # - incobsolete     true if obsolete modules among dependencies should be
2984 #                   included, blank otherwise
2985 # - inc_cxx_tests   true if C++ interoperability tests should be included,
2986 #                   blank otherwise
2987 # - inc_longrunning_tests  true if long-runnings tests should be included,
2988 #                          blank otherwise
2989 # - inc_privileged_tests  true if tests that require root privileges should be
2990 #                         included, blank otherwise
2991 # - inc_unportable_tests  true if tests that fail on some platforms should be
2992 #                         included, blank otherwise
2993 # - inc_all_direct_tests   true if all kinds of problematic unit tests among
2994 #                          the unit tests of the specified modules should be
2995 #                          included, blank otherwise
2996 # - inc_all_indirect_tests   true if all kinds of problematic unit tests among
2997 #                            the unit tests of the dependencies should be
2998 #                            included, blank otherwise
2999 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
3000 #                    blank otherwise
3001 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
3002 #                           blank otherwise
3003 # - excl_privileged_tests  true if tests that require root privileges should be
3004 #                          excluded, blank otherwise
3005 # - excl_unportable_tests  true if tests that fail on some platforms should be
3006 #                          excluded, blank otherwise
3007 # - avoidlist       list of modules to avoid
3008 # - cond_dependencies  true if conditional dependencies shall be supported,
3009 #                      blank otherwise
3010 # - tmp             pathname of a temporary directory
3011 # Output:
3012 # - main_modules    list of modules, including dependencies
3013 # - testsrelated_modules  list of tests-related modules, including dependencies
3014 # - conddep_dependers, conddep_condition  information about conditionally
3015 #                                         enabled modules
3016 func_modules_transitive_closure_separately ()
3017 {
3018   # Determine main module list.
3019   saved_inctests="$inctests"
3020   inctests=false
3021   modules="$specified_modules"
3022   func_modules_transitive_closure
3023   main_modules="$modules"
3024   inctests="$saved_inctests"
3025   if test $verbose -ge 1; then
3026     echo "Main module list:"
3027     echo "$main_modules" | sed -e 's/^/  /'
3028   fi
3029   # Determine tests-related module list.
3030   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
3031   testsrelated_modules=`for module in $main_modules; do
3032                           if test \`func_get_applicability $module\` = main; then
3033                             echo $module
3034                           fi
3035                         done \
3036                         | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
3037   if test $verbose -ge 1; then
3038     echo "Tests-related module list:"
3039     echo "$testsrelated_modules" | sed -e 's/^/  /'
3040   fi
3041 }
3042
3043 # func_determine_use_libtests
3044 # Determines whether a $testsbase/libtests.a is needed.
3045 # Input:
3046 # - local_gnulib_path  from --local-dir
3047 # - modcache        true or false, from --cache-modules/--no-cache-modules
3048 # - testsrelated_modules  list of tests-related modules, including dependencies
3049 # Output:
3050 # - use_libtests    true if a $testsbase/libtests.a is needed, false otherwise
3051 func_determine_use_libtests ()
3052 {
3053   use_libtests=false
3054   for module in $testsrelated_modules; do
3055     func_verify_nontests_module
3056     if test -n "$module"; then
3057       all_files=`func_get_filelist $module`
3058       # Test whether some file in $all_files lies in lib/.
3059       for f in $all_files; do
3060         case $f in
3061           lib/*)
3062             use_libtests=true
3063             break 2
3064             ;;
3065         esac
3066       done
3067     fi
3068   done
3069 }
3070
3071 # func_modules_add_dummy
3072 # Input:
3073 # - local_gnulib_path  from --local-dir
3074 # - modcache        true or false, from --cache-modules/--no-cache-modules
3075 # - modules         list of modules, including dependencies
3076 # Output:
3077 # - modules         list of modules, including 'dummy' if needed
3078 func_modules_add_dummy ()
3079 {
3080   # Determine whether any module provides a lib_SOURCES augmentation.
3081   have_lib_SOURCES=
3082   for module in $modules; do
3083     func_verify_nontests_module
3084     if test -n "$module"; then
3085       # Extract the value of "lib_SOURCES += ...".
3086       for file in `func_get_automake_snippet "$module" | combine_lines |
3087                    sed -n -e 's,^lib_SOURCES[    ]*+=\([^#]*\).*$,\1,p'`; do
3088         # Ignore .h files since they are not compiled.
3089         case "$file" in
3090           *.h) ;;
3091           *)
3092             have_lib_SOURCES=yes
3093             break 2
3094             ;;
3095         esac
3096       done
3097     fi
3098   done
3099   # Add the dummy module, to make sure the library will be non-empty.
3100   if test -z "$have_lib_SOURCES"; then
3101     if func_acceptable "dummy"; then
3102       func_append modules " dummy"
3103     fi
3104   fi
3105 }
3106
3107 # func_modules_add_dummy_separately
3108 # Input:
3109 # - local_gnulib_path  from --local-dir
3110 # - modcache        true or false, from --cache-modules/--no-cache-modules
3111 # - main_modules    list of modules, including dependencies
3112 # - testsrelated_modules  list of tests-related modules, including dependencies
3113 # - use_libtests    true if a $testsbase/libtests.a is needed, false otherwise
3114 # Output:
3115 # - main_modules    list of modules, including 'dummy' if needed
3116 # - testsrelated_modules  list of tests-related modules, including 'dummy' if
3117 #                         needed
3118 func_modules_add_dummy_separately ()
3119 {
3120   # Add the dummy module to the main module list if needed.
3121   modules="$main_modules"
3122   func_modules_add_dummy
3123   main_modules="$modules"
3124
3125   # Add the dummy module to the tests-related module list if needed.
3126   if $use_libtests; then
3127     modules="$testsrelated_modules"
3128     func_modules_add_dummy
3129     testsrelated_modules="$modules"
3130   fi
3131 }
3132
3133 # func_modules_notice
3134 # Input:
3135 # - local_gnulib_path  from --local-dir
3136 # - modcache        true or false, from --cache-modules/--no-cache-modules
3137 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
3138 # - modules         list of modules, including dependencies
3139 func_modules_notice ()
3140 {
3141   if test $verbose -ge -1; then
3142     for module in $modules; do
3143       func_verify_module
3144       if test -n "$module"; then
3145         msg=`func_get_notice $module`
3146         if test -n "$msg"; then
3147           echo "Notice from module $module:"
3148           echo "$msg" | sed -e 's/^/  /'
3149         fi
3150       fi
3151     done
3152   fi
3153 }
3154
3155 # func_modules_to_filelist
3156 # Input:
3157 # - local_gnulib_path  from --local-dir
3158 # - modcache        true or false, from --cache-modules/--no-cache-modules
3159 # - modules         list of modules, including dependencies
3160 # Output:
3161 # - files           list of files
3162 func_modules_to_filelist ()
3163 {
3164   files=
3165   for module in $modules; do
3166     func_verify_module
3167     if test -n "$module"; then
3168       fs=`func_get_filelist $module`
3169       func_append files " $fs"
3170     fi
3171   done
3172   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
3173 }
3174
3175 # func_modules_to_filelist_separately
3176 # Determine the final file lists.
3177 # They must be computed separately, because files in lib/* go into
3178 # $sourcebase/ if they are in the main file list but into $testsbase/
3179 # if they are in the tests-related file list. Furthermore lib/dummy.c
3180 # can be in both.
3181 # Input:
3182 # - local_gnulib_path  from --local-dir
3183 # - modcache        true or false, from --cache-modules/--no-cache-modules
3184 # - main_modules    list of modules, including dependencies
3185 # - testsrelated_modules  list of tests-related modules, including dependencies
3186 func_modules_to_filelist_separately ()
3187 {
3188   # Determine final main file list.
3189   modules="$main_modules"
3190   func_modules_to_filelist
3191   main_files="$files"
3192   # Determine final tests-related file list.
3193   modules="$testsrelated_modules"
3194   func_modules_to_filelist
3195   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
3196   # Merge both file lists.
3197   sed_remove_empty_lines='/^$/d'
3198   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
3199   if test $verbose -ge 0; then
3200     echo "File list:"
3201     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
3202     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
3203   fi
3204 }
3205
3206 # func_compute_include_guard_prefix
3207 # Determine include_guard_prefix.
3208 # Input:
3209 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3210 # Output:
3211 # - include_guard_prefix  replacement for ${gl_include_guard_prefix}
3212 # - sed_replace_include_guard_prefix
3213 #                   sed expression for resolving ${gl_include_guard_prefix}
3214 func_compute_include_guard_prefix ()
3215 {
3216   if test "$macro_prefix" = gl; then
3217     include_guard_prefix='GL'
3218   else
3219     include_guard_prefix='GL_'`echo "$macro_prefix" | LC_ALL=C tr '[a-z]' '[A-Z]'`
3220   fi
3221   sed_replace_include_guard_prefix='s/\${gl_include_guard_prefix}/'"${include_guard_prefix}"'/g'
3222 }
3223
3224 # func_execute_command command [args...]
3225 # Executes a command.
3226 # Uses also the variables
3227 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
3228 func_execute_command ()
3229 {
3230   if test $verbose -ge 0; then
3231     echo "executing $*"
3232     "$@"
3233   else
3234     # Commands like automake produce output to stderr even when they succeed.
3235     # Turn this output off if the command succeeds.
3236     "$@" > "$tmp"/cmdout 2>&1
3237     cmdret=$?
3238     if test $cmdret = 0; then
3239       rm -f "$tmp"/cmdout
3240     else
3241       echo "executing $*"
3242       cat "$tmp"/cmdout 1>&2
3243       rm -f "$tmp"/cmdout
3244       (exit $cmdret)
3245     fi
3246   fi
3247 }
3248
3249 # func_dest_tmpfilename file
3250 # determines the name of a temporary file (file is relative to destdir).
3251 # Input:
3252 # - destdir         target directory
3253 # - doit            : if actions shall be executed, false if only to be printed
3254 # - tmp             pathname of a temporary directory
3255 # Sets variable:
3256 #   - tmpfile       absolute filename of the temporary file
3257 func_dest_tmpfilename ()
3258 {
3259   if $doit; then
3260     # Put the new contents of $file in a file in the same directory (needed
3261     # to guarantee that an 'mv' to "$destdir/$file" works).
3262     tmpfile="$destdir/$1.tmp"
3263   else
3264     # Put the new contents of $file in a file in a temporary directory
3265     # (because the directory of "$file" might not exist).
3266     tmpfile="$tmp"/`basename "$1"`.tmp
3267   fi
3268 }
3269
3270 # func_is_local_file lookedup_file file
3271 # check whether file should be instantiated from local gnulib directory
3272 func_is_local_file ()
3273 {
3274   dname=$1
3275   func_remove_suffix dname "/$2"
3276   func_path_foreach "$local_gnulib_path" test %dir% = "$dname"
3277 }
3278
3279 # func_should_symlink
3280 # returns 0 when the file $f should be symlinked
3281 # Input:
3282 # - symbolic        true if files should be symlinked, copied otherwise
3283 # - lsymbolic       true if files from local_gnulib_path should be symlinked,
3284 #                   copied otherwise
3285 # - f               the original file name
3286 # - lookedup_file   name of the merged (combined) file
3287 func_should_symlink ()
3288 {
3289   test -n "$symbolic" \
3290     || { test -n "$lsymbolic" \
3291          && func_is_local_file "$lookedup_file" "$f"; }
3292 }
3293
3294 # func_add_file
3295 # copies a file from gnulib into the destination directory. The destination
3296 # is known to not exist.
3297 # Input:
3298 # - destdir         target directory
3299 # - local_gnulib_path  from --local-dir
3300 # - modcache        true or false, from --cache-modules/--no-cache-modules
3301 # - f               the original file name
3302 # - lookedup_file   name of the merged (combined) file
3303 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
3304 # - g               the rewritten file name
3305 # - tmpfile         absolute filename of the temporary file
3306 # - doit            : if actions shall be executed, false if only to be printed
3307 # - symbolic        true if files should be symlinked, copied otherwise
3308 # - lsymbolic       true if files from local_gnulib_path should be symlinked,
3309 #                   copied otherwise
3310 func_add_file ()
3311 {
3312   if $doit; then
3313     echo "Copying file $g"
3314     if func_should_symlink \
3315        && test -z "$lookedup_tmp" \
3316        && cmp -s "$lookedup_file" "$tmpfile"; then
3317       func_ln_if_changed "$lookedup_file" "$destdir/$g"
3318     else
3319       mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
3320     fi
3321   else
3322     echo "Copy file $g"
3323   fi
3324 }
3325
3326 # func_update_file
3327 # copies a file from gnulib into the destination directory. The destination
3328 # is known to exist.
3329 # Input:
3330 # - destdir         target directory
3331 # - local_gnulib_path  from --local-dir
3332 # - modcache        true or false, from --cache-modules/--no-cache-modules
3333 # - f               the original file name
3334 # - lookedup_file   name of the merged (combined) file
3335 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
3336 # - g               the rewritten file name
3337 # - tmpfile         absolute filename of the temporary file
3338 # - doit            : if actions shall be executed, false if only to be printed
3339 # - symbolic        true if files should be symlinked, copied otherwise
3340 # - lsymbolic       true if files from local_gnulib_path should be symlinked,
3341 #                   copied otherwise
3342 # - already_present  nonempty if the file should already exist, empty otherwise
3343 func_update_file ()
3344 {
3345   if cmp -s "$destdir/$g" "$tmpfile"; then
3346     : # The file has not changed.
3347   else
3348     # Replace the file.
3349     if $doit; then
3350       if test -n "$already_present"; then
3351         echo "Updating file $g (backup in ${g}~)"
3352       else
3353         echo "Replacing file $g (non-gnulib code backed up in ${g}~) !!"
3354       fi
3355       mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
3356       if func_should_symlink \
3357          && test -z "$lookedup_tmp" \
3358          && cmp -s "$lookedup_file" "$tmpfile"; then
3359         func_ln_if_changed "$lookedup_file" "$destdir/$g"
3360       else
3361         mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
3362       fi
3363     else
3364       if test -n "$already_present"; then
3365         echo "Update file $g (backup in ${g}~)"
3366       else
3367         echo "Replace file $g (non-gnulib code backed up in ${g}~) !!"
3368       fi
3369     fi
3370   fi
3371 }
3372
3373 # func_emit_lib_Makefile_am
3374 # emits the contents of library makefile to standard output.
3375 # Input:
3376 # - local_gnulib_path  from --local-dir
3377 # - modcache        true or false, from --cache-modules/--no-cache-modules
3378 # - modules         list of modules, including dependencies
3379 # - libname         library name
3380 # - pobase          directory relative to destdir where to place *.po files
3381 # - auxdir          directory relative to destdir where to place build aux files
3382 # - makefile_name   from --makefile-name
3383 # - libtool         true if libtool will be used, false or blank otherwise
3384 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3385 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3386 # - witness_c_macro  from --witness-c-macro
3387 # - actioncmd       (optional) command that will reproduce this invocation
3388 # - for_test        true if creating a package for testing, false otherwise
3389 # - sed_replace_include_guard_prefix
3390 #                   sed expression for resolving ${gl_include_guard_prefix}
3391 # - destfile        filename relative to destdir of makefile being generated
3392 # Input/Output:
3393 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
3394 #                   list of edits to be done to Makefile.am variables
3395 # Output:
3396 # - uses_subdirs    nonempty if object files in subdirs exist
3397 func_emit_lib_Makefile_am ()
3398 {
3399   # When creating an includable Makefile.am snippet, augment variables with
3400   # += instead of assigning them.
3401   if test -n "$makefile_name"; then
3402     assign='+='
3403   else
3404     assign='='
3405   fi
3406   if test "$libtool" = true; then
3407     libext=la
3408     perhapsLT=LT
3409     sed_eliminate_LDFLAGS="$sed_noop"
3410   else
3411     libext=a
3412     perhapsLT=
3413     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
3414   fi
3415   if $for_test; then
3416     # When creating a package for testing: Attempt to provoke failures,
3417     # especially link errors, already during "make" rather than during
3418     # "make check", because "make check" is not possible in a cross-compiling
3419     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
3420     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
3421   else
3422     sed_transform_check_PROGRAMS="$sed_noop"
3423   fi
3424   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3425   echo "## Process this file with automake to produce Makefile.in."
3426   func_emit_copyright_notice
3427   if test -n "$actioncmd"; then
3428     # The maximum line length (excluding the terminating newline) of any file
3429     # that is to be preprocessed by config.status is 3070.  config.status uses
3430     # awk, and the HP-UX 11.00 awk fails if a line has length >= 3071;
3431     # similarly, the IRIX 6.5 awk fails if a line has length >= 3072.
3432     len=`echo "$actioncmd" | wc -c`
3433     if test -n "$len" && test "$len" -le 3000; then
3434       echo "# Reproduce by: $actioncmd"
3435     fi
3436   fi
3437   echo
3438   uses_subdirs=
3439   {
3440     for module in $modules; do
3441       func_verify_nontests_module
3442       if test -n "$module"; then
3443         {
3444           func_get_automake_snippet_conditional "$module" |
3445             LC_ALL=C \
3446             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
3447                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
3448                 -e "$sed_eliminate_LDFLAGS" \
3449                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
3450                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
3451                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
3452                 -e "$sed_transform_check_PROGRAMS" \
3453                 -e "$sed_replace_include_guard_prefix"
3454           if test "$module" = 'alloca'; then
3455             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
3456             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
3457           fi
3458         } | combine_lines "${libname}_${libext}_SOURCES" > "$tmp"/amsnippet1
3459         {
3460           func_get_automake_snippet_unconditional "$module" |
3461             LC_ALL=C sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
3462         } > "$tmp"/amsnippet2
3463         # Skip the contents if it's entirely empty.
3464         if grep '[^      ]' "$tmp"/amsnippet1 "$tmp"/amsnippet2 > /dev/null ; then
3465           echo "## begin gnulib module $module"
3466           echo
3467           if test "$cond_dependencies" = true; then
3468             if func_cond_module_p "$module"; then
3469               func_module_conditional_name "$module"
3470               echo "if $conditional"
3471             fi
3472           fi
3473           cat "$tmp"/amsnippet1
3474           if test "$cond_dependencies" = true; then
3475             if func_cond_module_p "$module"; then
3476               echo "endif"
3477             fi
3478           fi
3479           cat "$tmp"/amsnippet2
3480           echo "## end   gnulib module $module"
3481           echo
3482         fi
3483         rm -f "$tmp"/amsnippet1 "$tmp"/amsnippet2
3484         # Test whether there are some source files in subdirectories.
3485         for f in `func_get_filelist "$module"`; do
3486           case $f in
3487             lib/*/*.c)
3488               uses_subdirs=yes
3489               break
3490               ;;
3491           esac
3492         done
3493       fi
3494     done
3495   } > "$tmp"/allsnippets
3496   if test -z "$makefile_name"; then
3497     # If there are source files in subdirectories, prevent collision of the
3498     # object files (example: hash.c and libxml/hash.c).
3499     subdir_options=
3500     if test -n "$uses_subdirs"; then
3501       subdir_options=' subdir-objects'
3502     fi
3503     echo "AUTOMAKE_OPTIONS = 1.9.6 gnits${subdir_options}"
3504   fi
3505   echo
3506   if test -z "$makefile_name"; then
3507     echo "SUBDIRS ="
3508     echo "noinst_HEADERS ="
3509     echo "noinst_LIBRARIES ="
3510     echo "noinst_LTLIBRARIES ="
3511     # Automake versions < 1.11.4 create an empty pkgdatadir at
3512     # installation time if you specify pkgdata_DATA to empty.
3513     # See automake bugs #10997 and #11030:
3514     #  * http://debbugs.gnu.org/10997
3515     #  * http://debbugs.gnu.org/11030
3516     # So we need this workaround.
3517     if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
3518       echo "pkgdata_DATA ="
3519     fi
3520     echo "EXTRA_DIST ="
3521     echo "BUILT_SOURCES ="
3522     echo "SUFFIXES ="
3523   fi
3524   echo "MOSTLYCLEANFILES $assign core *.stackdump"
3525   if test -z "$makefile_name"; then
3526     echo "MOSTLYCLEANDIRS ="
3527     echo "CLEANFILES ="
3528     echo "DISTCLEANFILES ="
3529     echo "MAINTAINERCLEANFILES ="
3530   fi
3531   # Execute edits that apply to the Makefile.am being generated.
3532   edit=0
3533   while test $edit != $makefile_am_edits; do
3534     edit=`expr $edit + 1`
3535     eval dir=\"\$makefile_am_edit${edit}_dir\"
3536     eval var=\"\$makefile_am_edit${edit}_var\"
3537     eval val=\"\$makefile_am_edit${edit}_val\"
3538     if test -n "$var"; then
3539       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
3540         echo "${var} += ${val}"
3541         eval "makefile_am_edit${edit}_var="
3542       fi
3543     fi
3544   done
3545   if test -n "$witness_c_macro"; then
3546     cppflags_part1=" -D$witness_c_macro=1"
3547   else
3548     cppflags_part1=
3549   fi
3550   if $for_test; then
3551     cppflags_part2=" -DGNULIB_STRICT_CHECKING=1"
3552   else
3553     cppflags_part2=
3554   fi
3555   if test -z "$makefile_name"; then
3556     echo
3557     echo "AM_CPPFLAGS =$cppflags_part1$cppflags_part2"
3558     echo "AM_CFLAGS ="
3559   else
3560     if test -n "$cppflags_part1$cppflags_part2"; then
3561       echo
3562       echo "AM_CPPFLAGS +=$cppflags_part1$cppflags_part2"
3563     fi
3564   fi
3565   echo
3566   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
3567      || { test -n "$makefile_name" \
3568           && test -f "$sourcebase/Makefile.am" \
3569           && LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$sourcebase/Makefile.am" > /dev/null; \
3570         }; then
3571     # One of the snippets or the user's Makefile.am already specifies an
3572     # installation location for the library. Don't confuse automake by saying
3573     # it should not be installed.
3574     :
3575   else
3576     # By default, the generated library should not be installed.
3577     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
3578   fi
3579   echo
3580   echo "${libname}_${libext}_SOURCES ="
3581   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
3582   # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
3583   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
3584   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
3585   echo "EXTRA_${libname}_${libext}_SOURCES ="
3586   if test "$libtool" = true; then
3587     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
3588     echo "${libname}_${libext}_LDFLAGS += -no-undefined"
3589     # Synthesize an ${libname}_${libext}_LDFLAGS augmentation by combining
3590     # the link dependencies of all modules.
3591     for module in $modules; do
3592       func_verify_nontests_module
3593       if test -n "$module"; then
3594         func_get_link_directive "$module"
3595       fi
3596     done \
3597       | LC_ALL=C sed -e '/^$/d' -e 's/ when linking with libtool.*//' \
3598       | LC_ALL=C sort -u \
3599       | LC_ALL=C sed -e 's/^/'"${libname}_${libext}"'_LDFLAGS += /'
3600   fi
3601   echo
3602   if test -n "$pobase"; then
3603     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
3604     echo
3605   fi
3606   cat "$tmp"/allsnippets \
3607     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
3608   echo
3609   echo "mostlyclean-local: mostlyclean-generic"
3610   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
3611   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
3612   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
3613   echo "          fi; \\"
3614   echo "        done; \\"
3615   echo "        :"
3616   rm -f "$tmp"/allsnippets
3617 }
3618
3619 # func_emit_po_Makevars
3620 # emits the contents of po/ makefile parameterization to standard output.
3621 # Input:
3622 # - local_gnulib_path  from --local-dir
3623 # - modcache        true or false, from --cache-modules/--no-cache-modules
3624 # - sourcebase      directory relative to destdir where to place source code
3625 # - pobase          directory relative to destdir where to place *.po files
3626 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3627 func_emit_po_Makevars ()
3628 {
3629   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3630   func_emit_copyright_notice
3631   echo
3632   echo "# Usually the message domain is the same as the package name."
3633   echo "# But here it has a '-gnulib' suffix."
3634   echo "DOMAIN = ${po_domain}-gnulib"
3635   echo
3636   echo "# These two variables depend on the location of this directory."
3637   echo "subdir = ${pobase}"
3638   echo "top_builddir = "`echo "$pobase" | sed -e 's,//*,/,g' -e 's,[^/][^/]*,..,g'`
3639   echo
3640   cat <<\EOF
3641 # These options get passed to xgettext.
3642 XGETTEXT_OPTIONS = \
3643   --keyword=_ --flag=_:1:pass-c-format \
3644   --keyword=N_ --flag=N_:1:pass-c-format \
3645   --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \
3646   --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \
3647   --flag=error:3:c-format --flag=error_at_line:5:c-format
3648
3649 # This is the copyright holder that gets inserted into the header of the
3650 # $(DOMAIN).pot file.  gnulib is copyrighted by the FSF.
3651 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
3652
3653 # This is the email address or URL to which the translators shall report
3654 # bugs in the untranslated strings:
3655 # - Strings which are not entire sentences, see the maintainer guidelines
3656 #   in the GNU gettext documentation, section 'Preparing Strings'.
3657 # - Strings which use unclear terms or require additional context to be
3658 #   understood.
3659 # - Strings which make invalid assumptions about notation of date, time or
3660 #   money.
3661 # - Pluralisation problems.
3662 # - Incorrect English spelling.
3663 # - Incorrect formatting.
3664 # It can be your email address, or a mailing list address where translators
3665 # can write to without being subscribed, or the URL of a web page through
3666 # which the translators can contact you.
3667 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
3668
3669 # This is the list of locale categories, beyond LC_MESSAGES, for which the
3670 # message catalogs shall be used.  It is usually empty.
3671 EXTRA_LOCALE_CATEGORIES =
3672
3673 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
3674 # context.  Possible values are "yes" and "no".  Set this to yes if the
3675 # package uses functions taking also a message context, like pgettext(), or
3676 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
3677 USE_MSGCTXT = no
3678 EOF
3679 }
3680
3681 # func_emit_po_POTFILES_in
3682 # emits the file list to be passed to xgettext to standard output.
3683 # Input:
3684 # - local_gnulib_path  from --local-dir
3685 # - modcache        true or false, from --cache-modules/--no-cache-modules
3686 # - sourcebase      directory relative to destdir where to place source code
3687 # - files           list of new files
3688 func_emit_po_POTFILES_in ()
3689 {
3690   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3691   func_emit_copyright_notice
3692   echo
3693   echo "# List of files which contain translatable strings."
3694   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
3695 }
3696
3697 # func_emit_tests_Makefile_am witness_macro
3698 # emits the contents of tests makefile to standard output.
3699 # Input:
3700 # - local_gnulib_path  from --local-dir
3701 # - modcache        true or false, from --cache-modules/--no-cache-modules
3702 # - modules         list of modules, including dependencies
3703 # - libname         library name
3704 # - auxdir          directory relative to destdir where to place build aux files
3705 # - makefile_name   from --makefile-name
3706 # - libtool         true if libtool will be used, false or blank otherwise
3707 # - sourcebase      relative directory containing lib source code
3708 # - m4base          relative directory containing autoconf macros
3709 # - testsbase       relative directory containing unit test code
3710 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3711 # - witness_c_macro  from --witness-c-macro
3712 # - for_test        true if creating a package for testing, false otherwise
3713 # - single_configure  true if a single configure file should be generated,
3714 #                     false for a separate configure file for the tests
3715 # - use_libtests    true if a libtests.a should be built, false otherwise
3716 # - sed_replace_include_guard_prefix
3717 #                   sed expression for resolving ${gl_include_guard_prefix}
3718 # - destfile        filename relative to destdir of makefile being generated
3719 # Input/Output:
3720 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
3721 #                   list of edits to be done to Makefile.am variables
3722 # Output:
3723 # - uses_subdirs    nonempty if object files in subdirs exist
3724 func_emit_tests_Makefile_am ()
3725 {
3726   witness_macro="$1"
3727   if test "$libtool" = true; then
3728     libext=la
3729     perhapsLT=LT
3730     sed_eliminate_LDFLAGS="$sed_noop"
3731   else
3732     libext=a
3733     perhapsLT=
3734     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
3735   fi
3736   if $for_test; then
3737     # When creating a package for testing: Attempt to provoke failures,
3738     # especially link errors, already during "make" rather than during
3739     # "make check", because "make check" is not possible in a cross-compiling
3740     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
3741     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
3742   else
3743     sed_transform_check_PROGRAMS="$sed_noop"
3744   fi
3745   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
3746   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3747   echo "## Process this file with automake to produce Makefile.in."
3748   func_emit_copyright_notice
3749   echo
3750   uses_subdirs=
3751   {
3752     for module in $modules; do
3753       if $for_test && ! $single_configure; then
3754         func_verify_tests_module
3755       else
3756         func_verify_module
3757       fi
3758       if test -n "$module"; then
3759         {
3760           func_get_automake_snippet "$module" |
3761             LC_ALL=C \
3762             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
3763                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
3764                 -e "$sed_eliminate_LDFLAGS" \
3765                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
3766                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
3767                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
3768                 -e "$sed_transform_check_PROGRAMS" \
3769                 -e "$sed_replace_include_guard_prefix"
3770           if $use_libtests && test "$module" = 'alloca'; then
3771             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
3772             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
3773           fi
3774         } > "$tmp"/amsnippet
3775         # Skip the contents if it's entirely empty.
3776         if grep '[^      ]' "$tmp"/amsnippet > /dev/null ; then
3777           # Mention long-running tests at the end.
3778           ofd=3
3779           for word in `func_get_status "$module"`; do
3780             if test "$word" = 'longrunning-test'; then
3781               ofd=4
3782               break
3783             fi
3784           done
3785           { echo "## begin gnulib module $module"
3786             echo
3787             cat "$tmp"/amsnippet
3788             echo "## end   gnulib module $module"
3789             echo
3790           } >&$ofd
3791         fi
3792         rm -f "$tmp"/amsnippet
3793         # Test whether there are some source files in subdirectories.
3794         for f in `func_get_filelist "$module"`; do
3795           case $f in
3796             lib/*/*.c | tests/*/*.c)
3797               uses_subdirs=yes
3798               break
3799               ;;
3800           esac
3801         done
3802       fi
3803     done
3804   } 3> "$tmp"/main_snippets 4> "$tmp"/longrunning_snippets
3805   # Generate dependencies here, since it eases the debugging of test failures.
3806   # If there are source files in subdirectories, prevent collision of the
3807   # object files (example: hash.c and libxml/hash.c).
3808   subdir_options=
3809   if test -n "$uses_subdirs"; then
3810     subdir_options=' subdir-objects'
3811   fi
3812   echo "AUTOMAKE_OPTIONS = 1.9.6 foreign${subdir_options}"
3813   echo
3814   if $for_test && ! $single_configure; then
3815     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
3816     echo
3817   fi
3818   # Nothing is being added to SUBDIRS; nevertheless the existence of this
3819   # variable is needed to avoid an error from automake:
3820   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
3821   echo "SUBDIRS = ."
3822   echo "TESTS ="
3823   echo "XFAIL_TESTS ="
3824   echo "TESTS_ENVIRONMENT ="
3825   echo "noinst_PROGRAMS ="
3826   if ! $for_test; then
3827     echo "check_PROGRAMS ="
3828   fi
3829   echo "noinst_HEADERS ="
3830   echo "noinst_LIBRARIES ="
3831   if $use_libtests; then
3832     if $for_test; then
3833       echo "noinst_LIBRARIES += libtests.a"
3834     else
3835       echo "check_LIBRARIES = libtests.a"
3836     fi
3837   fi
3838   # Automake versions < 1.11.4 create an empty pkgdatadir at
3839   # installation time if you specify pkgdata_DATA to empty.
3840   # See automake bugs #10997 and #11030:
3841   #  * http://debbugs.gnu.org/10997
3842   #  * http://debbugs.gnu.org/11030
3843   # So we need this workaround.
3844   if grep '^pkgdata_DATA *+=' "$tmp"/main_snippets "$tmp"/longrunning_snippets > /dev/null; then
3845     echo "pkgdata_DATA ="
3846   fi
3847   echo "EXTRA_DIST ="
3848   echo "BUILT_SOURCES ="
3849   echo "SUFFIXES ="
3850   echo "MOSTLYCLEANFILES = core *.stackdump"
3851   echo "MOSTLYCLEANDIRS ="
3852   echo "CLEANFILES ="
3853   echo "DISTCLEANFILES ="
3854   echo "MAINTAINERCLEANFILES ="
3855   # Execute edits that apply to the Makefile.am being generated.
3856   edit=0
3857   while test $edit != $makefile_am_edits; do
3858     edit=`expr $edit + 1`
3859     eval dir=\"\$makefile_am_edit${edit}_dir\"
3860     eval var=\"\$makefile_am_edit${edit}_var\"
3861     eval val=\"\$makefile_am_edit${edit}_val\"
3862     if test -n "$var"; then
3863       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
3864         echo "${var} += ${val}"
3865         eval "makefile_am_edit${edit}_var="
3866       fi
3867     fi
3868   done
3869   echo
3870   echo "AM_CPPFLAGS = \\"
3871   if $for_test; then
3872     echo "  -DGNULIB_STRICT_CHECKING=1 \\"
3873   fi
3874   if test -n "$witness_c_macro"; then
3875     echo "  -D$witness_c_macro=1 \\"
3876   fi
3877   if test -n "${witness_macro}"; then
3878     echo "  -D@${witness_macro}@=1 \\"
3879   fi
3880   echo "  -I. -I\$(srcdir) \\"
3881   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
3882   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
3883   echo
3884   local_ldadd_before=''
3885   local_ldadd_after=''
3886   if $use_libtests; then
3887     # All test programs need to be linked with libtests.a.
3888     # It needs to be passed to the linker before ${libname}.${libext}, since
3889     # the tests-related modules depend on the main modules.
3890     # It also needs to be passed to the linker after ${libname}.${libext}
3891     # because the latter might contain incomplete modules (such as the 'error'
3892     # module whose dependency to 'progname' is voluntarily omitted).
3893     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
3894     # not matter.
3895     local_ldadd_before=' libtests.a'
3896     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
3897   fi
3898   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
3899   echo
3900   if $use_libtests; then
3901     echo "libtests_a_SOURCES ="
3902     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
3903     # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
3904     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
3905     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
3906     echo "EXTRA_libtests_a_SOURCES ="
3907     # The circular dependency in LDADD requires this.
3908     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
3909     echo
3910   fi
3911   # Many test scripts use ${EXEEXT} or ${srcdir}.
3912   # EXEEXT is defined by AC_PROG_CC through autoconf.
3913   # srcdir is defined by autoconf and automake.
3914   echo "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='\$(srcdir)'"
3915   echo
3916   cat "$tmp"/main_snippets "$tmp"/longrunning_snippets \
3917     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
3918   echo "# Clean up after Solaris cc."
3919   echo "clean-local:"
3920   echo "        rm -rf SunWS_cache"
3921   echo
3922   echo "mostlyclean-local: mostlyclean-generic"
3923   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
3924   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
3925   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
3926   echo "          fi; \\"
3927   echo "        done; \\"
3928   echo "        :"
3929   rm -f "$tmp"/main_snippets "$tmp"/longrunning_snippets
3930 }
3931
3932 # func_emit_initmacro_start macro_prefix
3933 # emits the first few statements of the gl_INIT macro to standard output.
3934 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3935 func_emit_initmacro_start ()
3936 {
3937   macro_prefix_arg="$1"
3938   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
3939   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
3940   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
3941   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
3942   # flexibility.)
3943   # Furthermore it avoids an automake error like this when a Makefile.am
3944   # that uses pieces of gnulib also uses $(LIBOBJ):
3945   #   automatically discovered file `error.c' should not be explicitly mentioned
3946   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
3947   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
3948   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
3949   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
3950   #   automatically discovered file `error.c' should not be explicitly mentioned
3951   # We let automake know about the files to be distributed through the
3952   # EXTRA_lib_SOURCES variable.
3953   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
3954   # Create data variables for checking the presence of files that are mentioned
3955   # as AC_LIBSOURCES arguments. These are m4 variables, not shell variables,
3956   # because we want the check to happen when the configure file is created,
3957   # not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the list of
3958   # files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the subdirectory
3959   # in which to expect them.
3960   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_LIST], [])"
3961   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_DIR], [])"
3962   echo "  gl_COMMON"
3963 }
3964
3965 # func_emit_initmacro_end macro_prefix
3966 # emits the last few statements of the gl_INIT macro to standard output.
3967 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3968 func_emit_initmacro_end ()
3969 {
3970   macro_prefix_arg="$1"
3971   # Check the presence of files that are mentioned as AC_LIBSOURCES arguments.
3972   # The check is performed only when autoconf is run from the directory where
3973   # the configure.ac resides; if it is run from a different directory, the
3974   # check is skipped.
3975   echo "  m4_ifval(${macro_prefix_arg}_LIBSOURCES_LIST, ["
3976   echo "    m4_syscmd([test ! -d ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
3977   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
3978   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
3979   echo "          echo \"missing file ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file\" >&2"
3980   echo "          exit 1"
3981   echo "        fi"
3982   echo "      done])dnl"
3983   echo "      m4_if(m4_sysval, [0], [],"
3984   echo "        [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])"
3985   echo "  ])"
3986   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_DIR])"
3987   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_LIST])"
3988   echo "  m4_popdef([AC_LIBSOURCES])"
3989   echo "  m4_popdef([AC_REPLACE_FUNCS])"
3990   echo "  m4_popdef([AC_LIBOBJ])"
3991   echo "  AC_CONFIG_COMMANDS_PRE(["
3992   echo "    ${macro_prefix_arg}_libobjs="
3993   echo "    ${macro_prefix_arg}_ltlibobjs="
3994   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
3995   echo "      # Remove the extension."
3996   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
3997   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed -e \"\$sed_drop_objext\" | sort | uniq\`; do"
3998   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
3999   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
4000   echo "      done"
4001   echo "    fi"
4002   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
4003   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
4004   echo "  ])"
4005 }
4006
4007 # func_emit_initmacro_done macro_prefix sourcebase
4008 # emits a few statements after the gl_INIT macro to standard output.
4009 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
4010 # - sourcebase      directory relative to destdir where to place source code
4011 func_emit_initmacro_done ()
4012 {
4013   macro_prefix_arg="$1"
4014   sourcebase_arg="$2"
4015   echo
4016   echo "# Like AC_LIBOBJ, except that the module name goes"
4017   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
4018   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
4019   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
4020   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
4021   echo "])"
4022   echo
4023   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
4024   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
4025   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
4026   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
4027   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
4028   echo "])"
4029   echo
4030   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
4031   echo "# expected is derived from the gnulib-tool parameterization,"
4032   echo "# and alloca is special cased (for the alloca-opt module)."
4033   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
4034   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
4035   echo "  m4_foreach([_gl_NAME], [\$1], ["
4036   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
4037   echo "      m4_define([${macro_prefix_arg}_LIBSOURCES_DIR], [$sourcebase_arg])"
4038   echo "      m4_append([${macro_prefix_arg}_LIBSOURCES_LIST], _gl_NAME, [ ])"
4039   echo "    ])"
4040   echo "  ])"
4041   echo "])"
4042 }
4043
4044 # func_emit_autoconf_snippet indentation
4045 # emits the autoconf snippet of a module.
4046 # Input:
4047 # - indentation       spaces to prepend on each line
4048 # - local_gnulib_path  from --local-dir
4049 # - modcache          true or false, from --cache-modules/--no-cache-modules
4050 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
4051 # - sed_replace_include_guard_prefix
4052 #                     sed expression for resolving ${gl_include_guard_prefix}
4053 # - module            the module name
4054 # - toplevel          true or false. 'false' means a subordinate use of
4055 #                     gnulib-tool.
4056 # - disable_libtool   true or false. It tells whether to disable libtool
4057 #                     handling even if it has been specified through the
4058 #                     command line options.
4059 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
4060 #                     invocations.
4061 func_emit_autoconf_snippet ()
4062 {
4063   indentation="$1"
4064   if { case $module in
4065          gnumakefile | maintainer-makefile)
4066            # These modules are meant to be used only in the top-level directory.
4067            $toplevel ;;
4068          *)
4069            true ;;
4070        esac
4071      }; then
4072     func_get_autoconf_snippet "$module" \
4073       | sed -e '/^$/d;' -e "s/^/$indentation/" \
4074             -e "$sed_replace_build_aux" \
4075             -e "$sed_replace_include_guard_prefix" \
4076       | { if $disable_libtool; then
4077             sed -e 's/\$gl_cond_libtool/false/g' \
4078                 -e 's/gl_libdeps/gltests_libdeps/g' \
4079                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
4080           else
4081             cat
4082           fi
4083         } \
4084       | { if $disable_gettext; then
4085             sed -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
4086           else
4087             # Don't indent AM_GNU_GETTEXT_VERSION line, as that confuses
4088             # autopoint through at least GNU gettext version 0.18.2.
4089             sed -e 's/^ *AM_GNU_GETTEXT_VERSION/AM_GNU_GETTEXT_VERSION/'
4090           fi
4091         }
4092     if test "$module" = 'alloca' && test "$libtool" = true && ! $disable_libtool; then
4093       echo 'changequote(,)dnl'
4094       echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
4095       echo 'changequote([, ])dnl'
4096       echo 'AC_SUBST([LTALLOCA])'
4097     fi
4098   fi
4099 }
4100
4101 # func_emit_autoconf_snippets modules verifier toplevel disable_libtool disable_gettext
4102 # collects and emit the autoconf snippets of a set of modules.
4103 # Input:
4104 # - local_gnulib_path  from --local-dir
4105 # - modcache          true or false, from --cache-modules/--no-cache-modules
4106 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
4107 # - sed_replace_include_guard_prefix
4108 #                     sed expression for resolving ${gl_include_guard_prefix}
4109 # - modules           the list of modules.
4110 # - verifier          one of func_verify_module, func_verify_nontests_module,
4111 #                     func_verify_tests_module. It selects the subset of
4112 #                     $modules to consider.
4113 # - toplevel          true or false. 'false' means a subordinate use of
4114 #                     gnulib-tool.
4115 # - disable_libtool   true or false. It tells whether to disable libtool
4116 #                     handling even if it has been specified through the
4117 #                     command line options.
4118 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
4119 #                     invocations.
4120 func_emit_autoconf_snippets ()
4121 {
4122   verifier="$2"
4123   toplevel="$3"
4124   disable_libtool="$4"
4125   disable_gettext="$5"
4126   if test "$cond_dependencies" = true; then
4127     for m in $modules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/modules
4128     # Emit the autoconf code for the unconditional modules.
4129     for module in $1; do
4130       eval $verifier
4131       if test -n "$module"; then
4132         if func_cond_module_p "$module"; then
4133           :
4134         else
4135           func_emit_autoconf_snippet "  "
4136         fi
4137       fi
4138     done
4139     # Initialize the shell variables indicating that the modules are enabled.
4140     for module in $1; do
4141       eval $verifier
4142       if test -n "$module"; then
4143         if func_cond_module_p "$module"; then
4144           func_module_shellvar_name "$module"
4145           echo "  $shellvar=false"
4146         fi
4147       fi
4148     done
4149     # Emit the autoconf code for the conditional modules, each in a separate
4150     # function. This makes it possible to support cycles among conditional
4151     # modules.
4152     for module in $1; do
4153       eval $verifier
4154       if test -n "$module"; then
4155         if func_cond_module_p "$module"; then
4156           func_module_shellfunc_name "$module"
4157           func_module_shellvar_name "$module"
4158           echo "  $shellfunc ()"
4159           echo '  {'
4160           echo "    if ! \$$shellvar; then"
4161           func_emit_autoconf_snippet "      "
4162           echo "      $shellvar=true"
4163           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
4164           # Intersect $deps with the modules list $1.
4165           deps=`for m in $deps; do echo $m; done | LC_ALL=C sort -u | LC_ALL=C join - "$tmp"/modules`
4166           for dep in $deps; do
4167             if func_cond_module_p "$dep"; then
4168               func_module_shellfunc_name "$dep"
4169               func_cond_module_condition "$module" "$dep"
4170               if test "$condition" != true; then
4171                 echo "      if $condition; then"
4172                 echo "        $shellfunc"
4173                 echo '      fi'
4174               else
4175                 echo "      $shellfunc"
4176               fi
4177             else
4178               # The autoconf code for $dep has already been emitted above and
4179               # therefore is already executed when this function is run.
4180               :
4181             fi
4182           done
4183           echo '    fi'
4184           echo '  }'
4185         fi
4186       fi
4187     done
4188     # Emit the dependencies from the unconditional to the conditional modules.
4189     for module in $1; do
4190       eval $verifier
4191       if test -n "$module"; then
4192         if func_cond_module_p "$module"; then
4193           :
4194         else
4195           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
4196           # Intersect $deps with the modules list $1.
4197           deps=`for m in $deps; do echo $m; done | LC_ALL=C sort -u | LC_ALL=C join - "$tmp"/modules`
4198           for dep in $deps; do
4199             if func_cond_module_p "$dep"; then
4200               func_module_shellfunc_name "$dep"
4201               func_cond_module_condition "$module" "$dep"
4202               if test "$condition" != true; then
4203                 echo "  if $condition; then"
4204                 echo "    $shellfunc"
4205                 echo '  fi'
4206               else
4207                 echo "  $shellfunc"
4208               fi
4209             else
4210               # The autoconf code for $dep has already been emitted above and
4211               # therefore is already executed when this code is run.
4212               :
4213             fi
4214           done
4215         fi
4216       fi
4217     done
4218     # Define the Automake conditionals.
4219     echo "  m4_pattern_allow([^${macro_prefix}_GNULIB_ENABLED_])"
4220     for module in $1; do
4221       eval $verifier
4222       if test -n "$module"; then
4223         if func_cond_module_p "$module"; then
4224           func_module_conditional_name "$module"
4225           func_module_shellvar_name "$module"
4226           echo "  AM_CONDITIONAL([$conditional], [\$$shellvar])"
4227         fi
4228       fi
4229     done
4230   else
4231     # Ignore the conditions, and enable all modules unconditionally.
4232     for module in $1; do
4233       eval $verifier
4234       if test -n "$module"; then
4235         func_emit_autoconf_snippet "  "
4236       fi
4237     done
4238   fi
4239 }
4240
4241 # func_emit_pre_early_macros require indentation modules
4242 # The require parameter can be ':' (AC_REQUIRE) or 'false' (direct call).
4243 func_emit_pre_early_macros ()
4244 {
4245   echo
4246   echo "${2}# Pre-early section."
4247   if $1; then
4248     _pre_early_snippet="echo \"${2}AC_REQUIRE([\$_pre_early_macro])\""
4249   else
4250     _pre_early_snippet="echo \"${2}\$_pre_early_macro\""
4251   fi
4252
4253   # We need to call gl_USE_SYSTEM_EXTENSIONS before gl_PROG_AR_RANLIB.  Doing
4254   # AC_REQUIRE in configure-ac.early is not early enough.
4255   _pre_early_macro="gl_USE_SYSTEM_EXTENSIONS"
4256   case "${nl}${3}${nl}" in
4257     *${nl}extensions${nl}*) eval "$_pre_early_snippet" ;;
4258   esac
4259
4260   _pre_early_macro="gl_PROG_AR_RANLIB"
4261   eval "$_pre_early_snippet"
4262   echo
4263 }
4264
4265 # func_reconstruct_cached_dir
4266 # callback for func_reconstruct_cached_local_gnulib_path
4267 # Input:
4268 # - destdir         from --dir
4269 # Output:
4270 # - local_gnulib_path  restored '--local-dir' path from cache
4271 func_reconstruct_cached_dir ()
4272 {
4273   cached_dir=$1
4274   if test -n "$cached_dir"; then
4275     case "$destdir" in
4276       /*)
4277         func_path_append local_gnulib_path "$destdir/$cached_dir" ;;
4278       *)
4279         case "$cached_dir" in
4280           /*)
4281             func_path_append local_gnulib_path "$destdir/$cached_dir" ;;
4282           *)
4283             func_relconcat "$destdir" "$cached_dir"
4284             func_path_append local_gnulib_path "$relconcat" ;;
4285         esac ;;
4286     esac
4287   fi
4288 }
4289
4290 # func_reconstruct_cached_local_gnulib_path
4291 # reconstruct local_gnulib_path from cached_local_gnulib_path to be set
4292 # relatively to $destdir again.
4293 # Input:
4294 # - cached_local_gnulib_path  local_gnulib_path stored within gnulib-cache.m4
4295 # - destdir         from --dir
4296 # Output:
4297 # - local_gnulib_path  restored '--local-dir' path from cache
4298 func_reconstruct_cached_local_gnulib_path ()
4299 {
4300   func_path_foreach "$cached_local_gnulib_path" func_reconstruct_cached_dir %dir%
4301 }
4302
4303 # func_import modules
4304 # Uses also the variables
4305 # - mode            import or add-import or remove-import or update
4306 # - destdir         target directory
4307 # - local_gnulib_path  from --local-dir
4308 # - modcache        true or false, from --cache-modules/--no-cache-modules
4309 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
4310 # - libname         library name
4311 # - supplied_libname  true if --lib was given, blank otherwise
4312 # - sourcebase      directory relative to destdir where to place source code
4313 # - m4base          directory relative to destdir where to place *.m4 macros
4314 # - pobase          directory relative to destdir where to place *.po files
4315 # - docbase         directory relative to destdir where to place doc files
4316 # - testsbase       directory relative to destdir where to place unit test code
4317 # - auxdir          directory relative to destdir where to place build aux files
4318 # - inctests        true if --with-tests was given, false otherwise
4319 # - incobsolete     true if --with-obsolete was given, blank otherwise
4320 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
4321 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
4322 #                          otherwise
4323 # - inc_privileged_tests  true if --with-privileged-tests was given, blank
4324 #                         otherwise
4325 # - inc_unportable_tests  true if --with-unportable-tests was given, blank
4326 #                         otherwise
4327 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
4328 # - avoidlist       list of modules to avoid, from --avoid
4329 # - cond_dependencies  true if --conditional-dependencies was given, false if
4330 #                      --no-conditional-dependencies was given, blank otherwise
4331 # - lgpl            yes or a number if library's license shall be LGPL,
4332 #                   blank otherwise
4333 # - makefile_name   from --makefile-name
4334 # - libtool         true if --libtool was given, false if --no-libtool was
4335 #                   given, blank otherwise
4336 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
4337 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
4338 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
4339 # - witness_c_macro  from --witness-c-macro
4340 # - vc_files        true if --vc-files was given, false if --no-vc-files was
4341 #                   given, blank otherwise
4342 # - autoconf_minversion  minimum supported autoconf version
4343 # - doit            : if actions shall be executed, false if only to be printed
4344 # - symbolic        true if files should be symlinked, copied otherwise
4345 # - lsymbolic       true if files from local_gnulib_path should be symlinked,
4346 #                   copied otherwise
4347 # - do_copyrights   true if copyright notices in files should be replaced,
4348 #                   blank otherwise
4349 func_import ()
4350 {
4351   # Get the cached settings.
4352   # In 'import' mode, we read them only for the purpose of knowing the old
4353   # installed file list, and don't use them as defaults.
4354   cached_local_gnulib_path=
4355   cached_specified_modules=
4356   cached_incobsolete=
4357   cached_inc_cxx_tests=
4358   cached_inc_longrunning_tests=
4359   cached_inc_privileged_tests=
4360   cached_inc_unportable_tests=
4361   cached_inc_all_tests=
4362   cached_avoidlist=
4363   cached_sourcebase=
4364   cached_m4base=
4365   cached_pobase=
4366   cached_docbase=
4367   cached_testsbase=
4368   cached_inctests=
4369   cached_libname=
4370   cached_lgpl=
4371   cached_makefile_name=
4372   cached_cond_dependencies=
4373   cached_libtool=
4374   cached_macro_prefix=
4375   cached_po_domain=
4376   cached_witness_c_macro=
4377   cached_vc_files=
4378   cached_files=
4379   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
4380     cached_libtool=false
4381     my_sed_traces='
4382       s,#.*$,,
4383       s,^dnl .*$,,
4384       s, dnl .*$,,
4385       /gl_LOCAL_DIR(/ {
4386         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_path="\1",p
4387       }
4388       /gl_MODULES(/ {
4389         ta
4390         :a
4391           s/)/)/
4392           tb
4393           N
4394           ba
4395         :b
4396         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
4397       }
4398       /gl_WITH_OBSOLETE/ {
4399         s,^.*$,cached_incobsolete=true,p
4400       }
4401       /gl_WITH_CXX_TESTS/ {
4402         s,^.*$,cached_inc_cxx_tests=true,p
4403       }
4404       /gl_WITH_LONGRUNNING_TESTS/ {
4405         s,^.*$,cached_inc_longrunning_tests=true,p
4406       }
4407       /gl_WITH_PRIVILEGED_TESTS/ {
4408         s,^.*$,cached_inc_privileged_tests=true,p
4409       }
4410       /gl_WITH_UNPORTABLE_TESTS/ {
4411         s,^.*$,cached_inc_unportable_tests=true,p
4412       }
4413       /gl_WITH_ALL_TESTS/ {
4414         s,^.*$,cached_inc_all_tests=true,p
4415       }
4416       /gl_AVOID(/ {
4417         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
4418       }
4419       /gl_SOURCE_BASE(/ {
4420         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
4421       }
4422       /gl_M4_BASE(/ {
4423         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
4424       }
4425       /gl_PO_BASE(/ {
4426         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
4427       }
4428       /gl_DOC_BASE(/ {
4429         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
4430       }
4431       /gl_TESTS_BASE(/ {
4432         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
4433       }
4434       /gl_WITH_TESTS/ {
4435         s,^.*$,cached_inctests=true,p
4436       }
4437       /gl_LIB(/ {
4438         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
4439       }
4440       /gl_LGPL(/ {
4441         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
4442       }
4443       /gl_LGPL/ {
4444         s,^.*$,cached_lgpl=yes,p
4445       }
4446       /gl_MAKEFILE_NAME(/ {
4447         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
4448       }
4449       /gl_CONDITIONAL_DEPENDENCIES/ {
4450         s,^.*$,cached_cond_dependencies=true,p
4451       }
4452       /gl_LIBTOOL/ {
4453         s,^.*$,cached_libtool=true,p
4454       }
4455       /gl_MACRO_PREFIX(/ {
4456         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
4457       }
4458       /gl_PO_DOMAIN(/ {
4459         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
4460       }
4461       /gl_WITNESS_C_MACRO(/ {
4462         s,^.*gl_WITNESS_C_MACRO([[ ]*\([^]"$`\\)]*\).*$,cached_witness_c_macro="\1",p
4463       }
4464       /gl_VC_FILES(/ {
4465         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
4466       }'
4467     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
4468     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
4469       my_sed_traces='
4470         s,#.*$,,
4471         s,^dnl .*$,,
4472         s, dnl .*$,,
4473         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
4474           s,^.*$,cached_files=",p
4475           n
4476           ta
4477           :a
4478           s,^\]).*$,",
4479           tb
4480           s,["$`\\],,g
4481           p
4482           n
4483           ba
4484           :b
4485           p
4486         }'
4487       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
4488     fi
4489   fi
4490
4491   if test "$mode" = import; then
4492     # In 'import' mode, the new set of specified modules overrides the cached
4493     # set of modules. Ignore the cached settings.
4494     specified_modules="$1"
4495   else
4496     # Merge the cached settings with the specified ones.
4497     # The m4base must be the same as expected from the pathname.
4498     if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
4499       func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
4500     fi
4501     # The local_gnulib_path defaults to the cached one. Recall that the cached one
4502     # is relative to $destdir, whereas the one we use is relative to . or absolute.
4503     if test -z "$local_gnulib_path"; then
4504       func_reconstruct_cached_local_gnulib_path
4505     fi
4506     case $mode in
4507       add-import)
4508         # Append the cached and the specified module names. So that
4509         # "gnulib-tool --add-import foo" means to add the module foo.
4510         specified_modules="$cached_specified_modules $1"
4511         ;;
4512       remove-import)
4513         # Take the cached module names, minus the specified module names.
4514         specified_modules=
4515         if $have_associative; then
4516           # Use an associative array, for O(N) worst-case run time.
4517           declare -A to_remove
4518           for m in $1; do
4519             eval 'to_remove[$m]=yes'
4520           done
4521           for module in $cached_specified_modules; do
4522             if eval 'test -z "${to_remove[$module]}"'; then
4523               func_append specified_modules "$module "
4524             fi
4525           done
4526         else
4527           # This loop has O(N**2) worst-case run time.
4528           for module in $cached_specified_modules; do
4529             to_remove=
4530             for m in $1; do
4531               if test "$m" = "$module"; then
4532                 to_remove=yes
4533                 break
4534               fi
4535             done
4536             if test -z "$to_remove"; then
4537               func_append specified_modules "$module "
4538             fi
4539           done
4540         fi
4541         ;;
4542       update)
4543         # Take the cached module names. There are no specified module names.
4544         specified_modules="$cached_specified_modules"
4545         ;;
4546     esac
4547     # Included obsolete modules among the dependencies if specified either way.
4548     if test -z "$incobsolete"; then
4549       incobsolete="$cached_incobsolete"
4550     fi
4551     # Included special kinds of tests modules among the dependencies if specified
4552     # either way.
4553     if test -z "$inc_cxx_tests"; then
4554       inc_cxx_tests="$cached_inc_cxx_tests"
4555     fi
4556     if test -z "$inc_longrunning_tests"; then
4557       inc_longrunning_tests="$cached_inc_longrunning_tests"
4558     fi
4559     if test -z "$inc_privileged_tests"; then
4560       inc_privileged_tests="$cached_inc_privileged_tests"
4561     fi
4562     if test -z "$inc_unportable_tests"; then
4563       inc_unportable_tests="$cached_inc_unportable_tests"
4564     fi
4565     if test -z "$inc_all_tests"; then
4566       inc_all_tests="$cached_inc_all_tests"
4567     fi
4568     # Append the cached and the specified avoidlist. This is probably better
4569     # than dropping the cached one when --avoid is specified at least once.
4570     avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
4571     avoidlist=`echo $avoidlist`
4572
4573     # The sourcebase defaults to the cached one.
4574     if test -z "$sourcebase"; then
4575       sourcebase="$cached_sourcebase"
4576       if test -z "$sourcebase"; then
4577         func_fatal_error "missing --source-base option"
4578       fi
4579     fi
4580     # The pobase defaults to the cached one.
4581     if test -z "$pobase"; then
4582       pobase="$cached_pobase"
4583     fi
4584     # The docbase defaults to the cached one.
4585     if test -z "$docbase"; then
4586       docbase="$cached_docbase"
4587       if test -z "$docbase"; then
4588         func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --import' is before that date, you need to run 'gnulib-tool --import' once, with a --doc-base option."
4589       fi
4590     fi
4591     # The testsbase defaults to the cached one.
4592     if test -z "$testsbase"; then
4593       testsbase="$cached_testsbase"
4594       if test -z "$testsbase"; then
4595         func_fatal_error "missing --tests-base option"
4596       fi
4597     fi
4598     # Require the tests if specified either way.
4599     if ! $inctests; then
4600       inctests="$cached_inctests"
4601       if test -z "$inctests"; then
4602         inctests=false
4603       fi
4604     fi
4605     # The libname defaults to the cached one.
4606     if test -z "$supplied_libname"; then
4607       libname="$cached_libname"
4608       if test -z "$libname"; then
4609         func_fatal_error "missing --lib option"
4610       fi
4611     fi
4612     # Require LGPL if specified either way.
4613     if test -z "$lgpl"; then
4614       lgpl="$cached_lgpl"
4615     fi
4616     # The makefile_name defaults to the cached one.
4617     if test -z "$makefile_name"; then
4618       makefile_name="$cached_makefile_name"
4619     fi
4620     # Use conditional dependencies if specified either way.
4621     if test -z "$cond_dependencies"; then
4622       cond_dependencies="$cached_cond_dependencies"
4623     fi
4624     # Use libtool if specified either way, or if guessed.
4625     if test -z "$libtool"; then
4626       if test -n "$cached_m4base"; then
4627         libtool="$cached_libtool"
4628       else
4629         libtool="$guessed_libtool"
4630       fi
4631     fi
4632     # The macro_prefix defaults to the cached one.
4633     if test -z "$macro_prefix"; then
4634       macro_prefix="$cached_macro_prefix"
4635       if test -z "$macro_prefix"; then
4636         func_fatal_error "missing --macro-prefix option"
4637       fi
4638     fi
4639     # The po_domain defaults to the cached one.
4640     if test -z "$po_domain"; then
4641       po_domain="$cached_po_domain"
4642     fi
4643     # The witness_c_macro defaults to the cached one.
4644     if test -z "$witness_c_macro"; then
4645       witness_c_macro="$cached_witness_c_macro"
4646     fi
4647     # The vc_files defaults to the cached one.
4648     if test -z "$vc_files"; then
4649       vc_files="$cached_vc_files"
4650     fi
4651     # Ensure constraints.
4652     if test "$cond_dependencies" = true && $inctests; then
4653       echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
4654       func_exit 1
4655     fi
4656   fi
4657   # --without-*-tests options are not supported here.
4658   excl_cxx_tests=
4659   excl_longrunning_tests=
4660   excl_privileged_tests=
4661   excl_unportable_tests=
4662
4663   # Canonicalize the list of specified modules.
4664   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
4665
4666   # Include all kinds of tests modules if --with-all-tests was specified.
4667   inc_all_direct_tests="$inc_all_tests"
4668   inc_all_indirect_tests="$inc_all_tests"
4669
4670   # Determine final module list.
4671   modules="$specified_modules"
4672   func_modules_transitive_closure
4673   if test $verbose -ge 0; then
4674     func_show_module_list
4675   fi
4676   final_modules="$modules"
4677
4678   # Determine main module list and tests-related module list separately.
4679   func_modules_transitive_closure_separately
4680
4681   # Determine whether a $testsbase/libtests.a is needed.
4682   func_determine_use_libtests
4683
4684   # Add the dummy module to the main module list or to the tests-related module
4685   # list if needed.
4686   func_modules_add_dummy_separately
4687
4688   # If --lgpl, verify that the licenses of modules are compatible.
4689   if test -n "$lgpl"; then
4690     license_incompatibilities=
4691     for module in $main_modules; do
4692       license=`func_get_license $module`
4693       case $license in
4694         'GPLed build tool') ;;
4695         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
4696         *)
4697           case "$lgpl" in
4698             yes | 3)
4699               case $license in
4700                 LGPL | LGPLv2+ | LGPLv3+) ;;
4701                 *) func_append license_incompatibilities "$module $license$nl" ;;
4702               esac
4703               ;;
4704             2)
4705               case $license in
4706                 LGPLv2+) ;;
4707                 *) func_append license_incompatibilities "$module $license$nl" ;;
4708               esac
4709               ;;
4710             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
4711           esac
4712           ;;
4713       esac
4714     done
4715     if test -n "$license_incompatibilities"; then
4716       # Format the license incompatibilities as a table.
4717       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
4718 s,^\(.................................................[^ ]*\) *,                 \1 ,'
4719       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
4720       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
4721     fi
4722   fi
4723
4724   # Show banner notice of every module.
4725   modules="$main_modules"
4726   func_modules_notice
4727
4728   # Determine script to apply to imported library files.
4729   sed_transform_lib_file=
4730   for module in $main_modules; do
4731     if test $module = config-h; then
4732       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
4733       sed_transform_lib_file=$sed_transform_lib_file'
4734         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
4735       '
4736       break
4737     fi
4738   done
4739   sed_transform_main_lib_file="$sed_transform_lib_file"
4740   if test -n "$do_copyrights"; then
4741     if test -n "$lgpl"; then
4742       # Update license.
4743       case "$lgpl" in
4744         yes | 3)
4745           sed_transform_main_lib_file=$sed_transform_main_lib_file'
4746             s/GNU General/GNU Lesser General/g
4747             s/General Public License/Lesser General Public License/g
4748             s/Lesser Lesser General Public License/Lesser General Public License/g
4749           '
4750           ;;
4751         2)
4752           sed_transform_main_lib_file=$sed_transform_main_lib_file'
4753             s/GNU General/GNU Lesser General/g
4754             s/General Public License/Lesser General Public License/g
4755             s/Lesser Lesser General Public License/Lesser General Public License/g
4756
4757             s/version [23]\([ ,]\)/version 2.1\1/g
4758           '
4759           ;;
4760         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
4761       esac
4762     else
4763       # Update license.
4764       sed_transform_main_lib_file=$sed_transform_main_lib_file'
4765         s/GNU Lesser General/GNU General/g
4766         s/Lesser General Public License/General Public License/g
4767
4768         s/GNU Library General/GNU General/g
4769         s/Library General Public License/General Public License/g
4770
4771         s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4772       '
4773     fi
4774   fi
4775
4776   # Determine script to apply to auxiliary files that go into $auxdir/.
4777   sed_transform_build_aux_file=
4778   if test -n "$do_copyrights"; then
4779     # Update license.
4780     sed_transform_build_aux_file=$sed_transform_build_aux_file'
4781       s/GNU Lesser General/GNU General/g
4782       s/Lesser General Public License/General Public License/g
4783
4784       s/GNU Library General/GNU General/g
4785       s/Library General Public License/General Public License/g
4786
4787       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4788     '
4789   fi
4790
4791   # Determine script to apply to library files that go into $testsbase/.
4792   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
4793   if test -n "$do_copyrights"; then
4794     # Update license.
4795     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
4796       s/GNU Lesser General/GNU General/g
4797       s/Lesser General Public License/General Public License/g
4798
4799       s/GNU Library General/GNU General/g
4800       s/Library General Public License/General Public License/g
4801
4802       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4803     '
4804   fi
4805
4806   # Determine the final file lists.
4807   func_modules_to_filelist_separately
4808
4809   test -n "$files" \
4810     || func_fatal_error "refusing to do nothing"
4811
4812   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
4813   new_files="$files m4/gnulib-tool.m4"
4814   old_files="$cached_files"
4815   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
4816     func_append old_files " m4/gnulib-tool.m4"
4817   fi
4818
4819   rewritten='%REWRITTEN%'
4820   sed_rewrite_old_files="\
4821     s,^build-aux/,$rewritten$auxdir/,
4822     s,^doc/,$rewritten$cached_docbase/,
4823     s,^lib/,$rewritten$cached_sourcebase/,
4824     s,^m4/,$rewritten$cached_m4base/,
4825     s,^tests/,$rewritten$cached_testsbase/,
4826     s,^tests=lib/,$rewritten$cached_testsbase/,
4827     s,^top/,$rewritten,
4828     s,^$rewritten,,"
4829   sed_rewrite_new_files="\
4830     s,^build-aux/,$rewritten$auxdir/,
4831     s,^doc/,$rewritten$docbase/,
4832     s,^lib/,$rewritten$sourcebase/,
4833     s,^m4/,$rewritten$m4base/,
4834     s,^tests/,$rewritten$testsbase/,
4835     s,^tests=lib/,$rewritten$testsbase/,
4836     s,^top/,$rewritten,
4837     s,^$rewritten,,"
4838
4839   # Create directories.
4840   { echo "$sourcebase"
4841     echo "$m4base"
4842     if test -n "$pobase"; then
4843       echo "$pobase"
4844     fi
4845     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
4846     if test -n "$docfiles"; then
4847       echo "$docbase"
4848     fi
4849     if $inctests; then
4850       echo "$testsbase"
4851     fi
4852     echo "$auxdir"
4853     for f in $files; do echo $f; done \
4854       | sed -e "$sed_rewrite_new_files" \
4855       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
4856       | LC_ALL=C sort -u
4857   } > "$tmp"/dirs
4858   { # Rearrange file descriptors. Needed because "while ... done < ..."
4859     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4860     exec 5<&0 < "$tmp"/dirs
4861     while read d; do
4862       if test ! -d "$destdir/$d"; then
4863         if $doit; then
4864           echo "Creating directory $destdir/$d"
4865           mkdir -p "$destdir/$d" || func_fatal_error "failed"
4866         else
4867           echo "Create directory $destdir/$d"
4868         fi
4869       fi
4870     done
4871     exec 0<&5 5<&-
4872   }
4873
4874   # Copy files or make symbolic links. Remove obsolete files.
4875   added_files=''
4876   removed_files=''
4877   delimiter='   '
4878   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4879   # representing the files according to the last gnulib-tool invocation.
4880   for f in $old_files; do echo $f; done \
4881     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
4882     | LC_ALL=C sort \
4883     > "$tmp"/old-files
4884   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4885   # representing the files after this gnulib-tool invocation.
4886   for f in $new_files; do echo $f; done \
4887     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
4888     | LC_ALL=C sort \
4889     > "$tmp"/new-files
4890   # First the files that are in old-files, but not in new-files:
4891   sed_take_first_column='s,'"$delimiter"'.*,,'
4892   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
4893     # Remove the file. Do nothing if the user already removed it.
4894     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
4895       if $doit; then
4896         echo "Removing file $g (backup in ${g}~)"
4897         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
4898       else
4899         echo "Remove file $g (backup in ${g}~)"
4900       fi
4901       func_append removed_files "$g$nl"
4902     fi
4903   done
4904   # func_add_or_update handles a file that ought to be present afterwards.
4905   # Uses parameters
4906   # - f             the original file name
4907   # - g             the rewritten file name
4908   # - already_present  nonempty if the file should already exist, empty
4909   #                    otherwise
4910   func_add_or_update ()
4911   {
4912     of="$f"
4913     case "$f" in
4914       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
4915     esac
4916     is_binary_file=
4917     case "$f" in
4918       *.class | *.mo ) is_binary_file=true ;;
4919     esac
4920     func_dest_tmpfilename "$g"
4921     func_lookup_file "$f"
4922     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
4923     if test -n "$sed_transform_main_lib_file" \
4924        && test -z "$is_binary_file"; then
4925       case "$of" in
4926         lib/*)
4927           sed -e "$sed_transform_main_lib_file" \
4928             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4929           ;;
4930       esac
4931     fi
4932     if test -n "$sed_transform_build_aux_file" \
4933        && test -z "$is_binary_file"; then
4934       case "$of" in
4935         build-aux/*)
4936           sed -e "$sed_transform_build_aux_file" \
4937             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4938           ;;
4939       esac
4940     fi
4941     if test -n "$sed_transform_testsrelated_lib_file" \
4942        && test -z "$is_binary_file"; then
4943       case "$of" in
4944         tests=lib/*)
4945           sed -e "$sed_transform_testsrelated_lib_file" \
4946             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4947           ;;
4948       esac
4949     fi
4950     if test -f "$destdir/$g"; then
4951       # The file already exists.
4952       func_update_file
4953     else
4954       # Install the file.
4955       # Don't protest if the file should be there but isn't: it happens
4956       # frequently that developers don't put autogenerated files under version control.
4957       func_add_file
4958       func_append added_files "$g$nl"
4959     fi
4960     rm -f "$tmpfile"
4961   }
4962   # Then the files that are in new-files, but not in old-files:
4963   sed_take_last_column='s,^.*'"$delimiter"',,'
4964   already_present=
4965   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
4966     | sed -e "$sed_take_last_column" \
4967     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
4968   { # Rearrange file descriptors. Needed because "while ... done < ..."
4969     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4970     exec 5<&0 < "$tmp"/added-files
4971     while read g f; do
4972       func_add_or_update
4973     done
4974     exec 0<&5 5<&-
4975   }
4976   # Then the files that are in new-files and in old-files:
4977   already_present=true
4978   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
4979     | sed -e "$sed_take_last_column" \
4980     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
4981   { # Rearrange file descriptors. Needed because "while ... done < ..."
4982     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4983     exec 5<&0 < "$tmp"/kept-files
4984     while read g f; do
4985       func_add_or_update
4986     done
4987     exec 0<&5 5<&-
4988   }
4989
4990   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
4991   actioncmd="gnulib-tool --import"
4992
4993   # Local helper.
4994   func_append_local_dir ()
4995   {
4996     func_append "$1" " --local-dir=$2"
4997   }
4998   func_path_foreach "$local_gnulib_path" func_append_local_dir actioncmd %dir%
4999
5000   func_append actioncmd " --lib=$libname"
5001   func_append actioncmd " --source-base=$sourcebase"
5002   func_append actioncmd " --m4-base=$m4base"
5003   if test -n "$pobase"; then
5004     func_append actioncmd " --po-base=$pobase"
5005   fi
5006   func_append actioncmd " --doc-base=$docbase"
5007   func_append actioncmd " --tests-base=$testsbase"
5008   func_append actioncmd " --aux-dir=$auxdir"
5009   if $inctests; then
5010     func_append actioncmd " --with-tests"
5011   fi
5012   if test -n "$incobsolete"; then
5013     func_append actioncmd " --with-obsolete"
5014   fi
5015   if test -n "$inc_cxx_tests"; then
5016     func_append actioncmd " --with-c++-tests"
5017   fi
5018   if test -n "$inc_longrunning_tests"; then
5019     func_append actioncmd " --with-longrunning-tests"
5020   fi
5021   if test -n "$inc_privileged_tests"; then
5022     func_append actioncmd " --with-privileged-tests"
5023   fi
5024   if test -n "$inc_unportable_tests"; then
5025     func_append actioncmd " --with-unportable-tests"
5026   fi
5027   if test -n "$inc_all_tests"; then
5028     func_append actioncmd " --with-all-tests"
5029   fi
5030   for module in $avoidlist; do
5031     func_append actioncmd " --avoid=$module"
5032   done
5033   if test -n "$lgpl"; then
5034     if test "$lgpl" = yes; then
5035       func_append actioncmd " --lgpl"
5036     else
5037       func_append actioncmd " --lgpl=$lgpl"
5038     fi
5039   fi
5040   if test -n "$makefile_name"; then
5041     func_append actioncmd " --makefile-name=$makefile_name"
5042   fi
5043   if test "$cond_dependencies" = true; then
5044     func_append actioncmd " --conditional-dependencies"
5045   else
5046     func_append actioncmd " --no-conditional-dependencies"
5047   fi
5048   if test "$libtool" = true; then
5049     func_append actioncmd " --libtool"
5050   else
5051     func_append actioncmd " --no-libtool"
5052   fi
5053   func_append actioncmd " --macro-prefix=$macro_prefix"
5054   if test -n "$po_domain"; then
5055     func_append actioncmd " --po-domain=$po_domain"
5056   fi
5057   if test -n "$witness_c_macro"; then
5058     func_append actioncmd " --witness-c-macro=$witness_c_macro"
5059   fi
5060   if test -n "$vc_files"; then
5061     if test "$vc_files" = true; then
5062       func_append actioncmd " --vc-files"
5063     else
5064       func_append actioncmd " --no-vc-files"
5065     fi
5066   fi
5067   func_append actioncmd " `echo $specified_modules`"
5068
5069   # Determine include_guard_prefix.
5070   func_compute_include_guard_prefix
5071
5072   # Default the makefile name to Makefile.am.
5073   if test -n "$makefile_name"; then
5074     makefile_am=$makefile_name
5075   else
5076     makefile_am=Makefile.am
5077   fi
5078
5079   # Create normal Makefile.ams.
5080   for_test=false
5081
5082   # Setup list of Makefile.am edits that are to be performed afterwards.
5083   # Some of these edits apply to files that we will generate; others are
5084   # under the responsibility of the developer.
5085   makefile_am_edits=0
5086   # func_note_Makefile_am_edit dir var value
5087   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
5088   # ${value}.
5089   func_note_Makefile_am_edit ()
5090   {
5091     makefile_am_edits=`expr $makefile_am_edits + 1`
5092     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
5093     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
5094     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
5095   }
5096   if test "$makefile_am" = Makefile.am; then
5097     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
5098     sourcebase_base=`basename "$sourcebase"`
5099     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
5100   fi
5101   if test -n "$pobase"; then
5102     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
5103     pobase_base=`basename "$pobase"`
5104     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
5105   fi
5106   if $inctests; then
5107     if test "$makefile_am" = Makefile.am; then
5108       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
5109       testsbase_base=`basename "$testsbase"`
5110       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
5111     fi
5112   fi
5113   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
5114   {
5115     # Find the first parent directory of $m4base that contains or will contain
5116     # a Makefile.am.
5117     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
5118 s,//*$,/,'
5119     sed_butlast='s,[^/][^/]*//*$,,'
5120     dir1="${m4base}/"; dir2=""
5121     while test -n "$dir1" \
5122           && ! { test -f "${destdir}/${dir1}Makefile.am" \
5123                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
5124                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
5125                  || { $inctests \
5126                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
5127                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
5128       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
5129       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
5130     done
5131     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
5132   }
5133
5134   # Create library makefile.
5135   func_dest_tmpfilename $sourcebase/$makefile_am
5136   destfile="$sourcebase/$makefile_am"
5137   modules="$main_modules"
5138   func_emit_lib_Makefile_am > "$tmpfile"
5139   if test -f "$destdir"/$sourcebase/$makefile_am; then
5140     if cmp -s "$destdir"/$sourcebase/$makefile_am "$tmpfile"; then
5141       rm -f "$tmpfile"
5142     else
5143       if $doit; then
5144         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
5145         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
5146         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
5147       else
5148         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
5149         rm -f "$tmpfile"
5150       fi
5151     fi
5152   else
5153     if $doit; then
5154       echo "Creating $sourcebase/$makefile_am"
5155       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
5156     else
5157       echo "Create $sourcebase/$makefile_am"
5158       rm -f "$tmpfile"
5159     fi
5160     func_append added_files "$sourcebase/$makefile_am$nl"
5161   fi
5162
5163   # Create po/ directory.
5164   if test -n "$pobase"; then
5165     # Create po makefile and auxiliary files.
5166     for file in Makefile.in.in remove-potcdate.sin; do
5167       func_dest_tmpfilename $pobase/$file
5168       func_lookup_file build-aux/po/$file
5169       cat "$lookedup_file" > "$tmpfile"
5170       if test -f "$destdir"/$pobase/$file; then
5171         if cmp -s "$destdir"/$pobase/$file "$tmpfile"; then
5172           rm -f "$tmpfile"
5173         else
5174           if $doit; then
5175             echo "Updating $pobase/$file (backup in $pobase/$file~)"
5176             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
5177             mv -f "$tmpfile" "$destdir"/$pobase/$file
5178           else
5179             echo "Update $pobase/$file (backup in $pobase/$file~)"
5180             rm -f "$tmpfile"
5181           fi
5182         fi
5183       else
5184         if $doit; then
5185           echo "Creating $pobase/$file"
5186           mv -f "$tmpfile" "$destdir"/$pobase/$file
5187         else
5188           echo "Create $pobase/$file"
5189           rm -f "$tmpfile"
5190         fi
5191         func_append added_files "$pobase/$file$nl"
5192       fi
5193     done
5194     # Create po makefile parameterization, part 1.
5195     func_dest_tmpfilename $pobase/Makevars
5196     func_emit_po_Makevars > "$tmpfile"
5197     if test -f "$destdir"/$pobase/Makevars; then
5198       if cmp -s "$destdir"/$pobase/Makevars "$tmpfile"; then
5199         rm -f "$tmpfile"
5200       else
5201         if $doit; then
5202           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
5203           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
5204           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
5205         else
5206           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
5207           rm -f "$tmpfile"
5208         fi
5209       fi
5210     else
5211       if $doit; then
5212         echo "Creating $pobase/Makevars"
5213         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
5214       else
5215         echo "Create $pobase/Makevars"
5216         rm -f "$tmpfile"
5217       fi
5218       func_append added_files "$pobase/Makevars$nl"
5219     fi
5220     # Create po makefile parameterization, part 2.
5221     func_dest_tmpfilename $pobase/POTFILES.in
5222     func_emit_po_POTFILES_in > "$tmpfile"
5223     if test -f "$destdir"/$pobase/POTFILES.in; then
5224       if cmp -s "$destdir"/$pobase/POTFILES.in "$tmpfile"; then
5225         rm -f "$tmpfile"
5226       else
5227         if $doit; then
5228           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
5229           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
5230           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
5231         else
5232           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
5233           rm -f "$tmpfile"
5234         fi
5235       fi
5236     else
5237       if $doit; then
5238         echo "Creating $pobase/POTFILES.in"
5239         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
5240       else
5241         echo "Create $pobase/POTFILES.in"
5242         rm -f "$tmpfile"
5243       fi
5244       func_append added_files "$pobase/POTFILES.in$nl"
5245     fi
5246     # Fetch PO files.
5247     TP_URL="http://translationproject.org/latest/"
5248     TP_RSYNC_URI="translationproject.org::tp/latest/"
5249     if $doit; then
5250       echo "Fetching gnulib PO files from $TP_URL"
5251       (cd "$destdir"/$pobase \
5252        && { # Prefer rsync over wget if it is available, since it consumes
5253             # less network bandwidth, due to compression.
5254             if type rsync 2>/dev/null | grep / > /dev/null; then
5255               rsync --delete --exclude "*.s1" -Lrtz "${TP_RSYNC_URI}gnulib/" . && return
5256             fi
5257
5258             wget --no-verbose --mirror -nd -np  -A.po -P . "${TP_URL}gnulib/"
5259           }
5260       )
5261     else
5262       echo "Fetch gnulib PO files from $TP_URL"
5263     fi
5264     # Create po/LINGUAS.
5265     if $doit; then
5266       func_dest_tmpfilename $pobase/LINGUAS
5267       (cd "$destdir"/$pobase \
5268        && { echo '# Set of available languages.'
5269             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
5270           }
5271       ) > "$tmpfile"
5272       if test -f "$destdir"/$pobase/LINGUAS; then
5273         if cmp -s "$destdir"/$pobase/LINGUAS "$tmpfile"; then
5274           rm -f "$tmpfile"
5275         else
5276           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
5277           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
5278           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
5279         fi
5280       else
5281         echo "Creating $pobase/LINGUAS"
5282         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
5283         func_append added_files "$pobase/LINGUAS$nl"
5284       fi
5285     else
5286       if test -f "$destdir"/$pobase/LINGUAS; then
5287         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
5288       else
5289         echo "Create $pobase/LINGUAS"
5290       fi
5291     fi
5292   fi
5293
5294   # func_count_relative_local_gnulib_path
5295   # gl_LOCAL_DIR requires local_gnulib_path to be set relatively to destdir
5296   # Input:
5297   # - local_gnulib_path  from --local-dir
5298   # - destdir           from --dir
5299   # Output:
5300   # - relative_local_dir  path to be stored into gl_LOCAL_DIR
5301   func_count_relative_local_gnulib_path ()
5302   {
5303     save_IFS=$IFS
5304     IFS=$PATH_SEPARATOR
5305     relative_local_gnulib_path=
5306     for local_dir in $local_gnulib_path
5307     do
5308       # Store the local_dir relative to destdir.
5309       case "$local_dir" in
5310         "" | /*)
5311           relative_local_dir="$local_dir" ;;
5312         * )
5313           case "$destdir" in
5314             /*) relative_local_dir="$local_dir" ;;
5315             *)
5316               # destdir, local_dir are both relative.
5317               func_relativize "$destdir" "$local_dir"
5318               relative_local_dir="$reldir" ;;
5319           esac ;;
5320       esac
5321       func_path_append relative_local_gnulib_path "$relative_local_dir"
5322     done
5323     IFS=$save_IFS
5324   }
5325
5326   # Create m4/gnulib-cache.m4.
5327   func_dest_tmpfilename $m4base/gnulib-cache.m4
5328   (
5329     func_emit_copyright_notice
5330     echo "#"
5331     echo "# This file represents the specification of how gnulib-tool is used."
5332     echo "# It acts as a cache: It is written and read by gnulib-tool."
5333     echo "# In projects that use version control, this file is meant to be put under"
5334     echo "# version control, like the configure.ac and various Makefile.am files."
5335     echo
5336     echo
5337     echo "# Specification in the form of a command-line invocation:"
5338     echo "#   $actioncmd"
5339     echo
5340     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
5341     func_count_relative_local_gnulib_path
5342     echo "gl_LOCAL_DIR([$relative_local_gnulib_path])"
5343     echo "gl_MODULES(["
5344     echo "$specified_modules" | sed -e 's/^/  /g'
5345     echo "])"
5346     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
5347     test -z "$inc_cxx_tests" || echo "gl_WITH_CXX_TESTS"
5348     test -z "$inc_longrunning_tests" || echo "gl_WITH_LONGRUNNING_TESTS"
5349     test -z "$inc_privileged_tests" || echo "gl_WITH_PRIVILEGED_TESTS"
5350     test -z "$inc_unportable_tests" || echo "gl_WITH_UNPORTABLE_TESTS"
5351     test -z "$inc_all_tests" || echo "gl_WITH_ALL_TESTS"
5352     echo "gl_AVOID([$avoidlist])"
5353     echo "gl_SOURCE_BASE([$sourcebase])"
5354     echo "gl_M4_BASE([$m4base])"
5355     echo "gl_PO_BASE([$pobase])"
5356     echo "gl_DOC_BASE([$docbase])"
5357     echo "gl_TESTS_BASE([$testsbase])"
5358     if $inctests; then
5359       echo "gl_WITH_TESTS"
5360     fi
5361     echo "gl_LIB([$libname])"
5362     if test -n "$lgpl"; then
5363       if test "$lgpl" = yes; then
5364         echo "gl_LGPL"
5365       else
5366         echo "gl_LGPL([$lgpl])"
5367       fi
5368     fi
5369     echo "gl_MAKEFILE_NAME([$makefile_name])"
5370     if test "$cond_dependencies" = true; then
5371       echo "gl_CONDITIONAL_DEPENDENCIES"
5372     fi
5373     if test "$libtool" = true; then
5374       echo "gl_LIBTOOL"
5375     fi
5376     echo "gl_MACRO_PREFIX([$macro_prefix])"
5377     echo "gl_PO_DOMAIN([$po_domain])"
5378     echo "gl_WITNESS_C_MACRO([$witness_c_macro])"
5379     if test -n "$vc_files"; then
5380       echo "gl_VC_FILES([$vc_files])"
5381     fi
5382   ) > "$tmpfile"
5383   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
5384     if cmp -s "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile"; then
5385       rm -f "$tmpfile"
5386     else
5387       if $doit; then
5388         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
5389         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
5390         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
5391       else
5392         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
5393         if false; then
5394           cat "$tmpfile"
5395           echo
5396           echo "# gnulib-cache.m4 ends here"
5397         fi
5398         rm -f "$tmpfile"
5399       fi
5400     fi
5401   else
5402     if $doit; then
5403       echo "Creating $m4base/gnulib-cache.m4"
5404       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
5405     else
5406       echo "Create $m4base/gnulib-cache.m4"
5407       cat "$tmpfile"
5408       rm -f "$tmpfile"
5409     fi
5410   fi
5411
5412   # Create m4/gnulib-comp.m4.
5413   func_dest_tmpfilename $m4base/gnulib-comp.m4
5414   (
5415     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
5416     func_emit_copyright_notice
5417     echo "#"
5418     echo "# This file represents the compiled summary of the specification in"
5419     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
5420     echo "# to be invoked from configure.ac."
5421     echo "# In projects that use version control, this file can be treated like"
5422     echo "# other built files."
5423     echo
5424     echo
5425     echo "# This macro should be invoked from $configure_ac, in the section"
5426     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
5427     echo "# any checks for libraries, header files, types and library functions."
5428     echo "AC_DEFUN([${macro_prefix}_EARLY],"
5429     echo "["
5430     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5431     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5432     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5433     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5434
5435     func_emit_pre_early_macros : '  ' "$final_modules"
5436
5437     if test -n "$uses_subdirs"; then
5438       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
5439     fi
5440     for module in $final_modules; do
5441       func_verify_module
5442       if test -n "$module"; then
5443         echo "# Code from module $module:"
5444         func_get_autoconf_early_snippet "$module"
5445       fi
5446     done \
5447       | sed -e '/^$/d;' -e 's/^/  /'
5448     echo "])"
5449     echo
5450     echo "# This macro should be invoked from $configure_ac, in the section"
5451     echo "# \"Check for header files, types and library functions\"."
5452     echo "AC_DEFUN([${macro_prefix}_INIT],"
5453     echo "["
5454     if test "$libtool" = true; then
5455       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5456       echo "  gl_cond_libtool=true"
5457     else
5458       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5459       echo "  gl_cond_libtool=false"
5460       echo "  gl_libdeps="
5461       echo "  gl_ltlibdeps="
5462     fi
5463     if test "$auxdir" != "build-aux"; then
5464       sed_replace_build_aux='
5465         :a
5466         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5467           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5468           ba
5469         }'
5470     else
5471       sed_replace_build_aux="$sed_noop"
5472     fi
5473     echo "  gl_m4_base='$m4base'"
5474     func_emit_initmacro_start $macro_prefix
5475     echo "  gl_source_base='$sourcebase'"
5476     if test -n "$witness_c_macro"; then
5477       echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$witness_c_macro])"
5478     fi
5479     func_emit_autoconf_snippets "$main_modules" func_verify_module true false true
5480     if test -n "$witness_c_macro"; then
5481       echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5482     fi
5483     echo "  # End of code from modules"
5484     func_emit_initmacro_end $macro_prefix
5485     echo "  gltests_libdeps="
5486     echo "  gltests_ltlibdeps="
5487     func_emit_initmacro_start ${macro_prefix}tests
5488     echo "  gl_source_base='$testsbase'"
5489     # Define a tests witness macro that depends on the package.
5490     # PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
5491     # See <http://lists.gnu.org/archive/html/automake/2009-05/msg00145.html>.
5492     echo "changequote(,)dnl"
5493     echo "  ${macro_prefix}tests_WITNESS=IN_\`echo \"\${PACKAGE-\$PACKAGE_TARNAME}\" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e 's/[^A-Z0-9_]/_/g'\`_GNULIB_TESTS"
5494     echo "changequote([, ])dnl"
5495     echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
5496     echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
5497     echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
5498     func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true true true
5499     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5500     func_emit_initmacro_end ${macro_prefix}tests
5501     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5502     # created using libtool, because libtool already handles the dependencies.
5503     if test "$libtool" != true; then
5504       libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5505       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5506       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5507       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5508       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5509     fi
5510     if $use_libtests; then
5511       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
5512       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
5513     fi
5514     echo "])"
5515     func_emit_initmacro_done $macro_prefix $sourcebase
5516     func_emit_initmacro_done ${macro_prefix}tests $testsbase
5517     echo
5518     echo "# This macro records the list of files which have been installed by"
5519     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
5520     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
5521     echo "$files" | sed -e 's,^,  ,'
5522     echo "])"
5523   ) > "$tmpfile"
5524   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
5525     if cmp -s "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile"; then
5526       rm -f "$tmpfile"
5527     else
5528       if $doit; then
5529         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
5530         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
5531         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
5532       else
5533         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
5534         if false; then
5535           cat "$tmpfile"
5536           echo
5537           echo "# gnulib-comp.m4 ends here"
5538         fi
5539         rm -f "$tmpfile"
5540       fi
5541     fi
5542   else
5543     if $doit; then
5544       echo "Creating $m4base/gnulib-comp.m4"
5545       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
5546     else
5547       echo "Create $m4base/gnulib-comp.m4"
5548       cat "$tmpfile"
5549       rm -f "$tmpfile"
5550     fi
5551   fi
5552
5553   if $inctests; then
5554     # Create tests makefile.
5555     func_dest_tmpfilename $testsbase/$makefile_am
5556     destfile="$testsbase/$makefile_am"
5557     modules="$testsrelated_modules"
5558     func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
5559     if test -f "$destdir"/$testsbase/$makefile_am; then
5560       if cmp -s "$destdir"/$testsbase/$makefile_am "$tmpfile"; then
5561         rm -f "$tmpfile"
5562       else
5563         if $doit; then
5564           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
5565           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
5566           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
5567         else
5568           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
5569           rm -f "$tmpfile"
5570         fi
5571       fi
5572     else
5573       if $doit; then
5574         echo "Creating $testsbase/$makefile_am"
5575         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
5576       else
5577         echo "Create $testsbase/$makefile_am"
5578         rm -f "$tmpfile"
5579       fi
5580       func_append added_files "$testsbase/$makefile_am$nl"
5581     fi
5582   fi
5583
5584   if test "$vc_files" != false; then
5585     # Update the .cvsignore and .gitignore files.
5586     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
5587       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
5588       # Treat gnulib-comp.m4 like an added file, even if it already existed.
5589       echo "$m4base/|A|gnulib-comp.m4"
5590     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
5591     { # Rearrange file descriptors. Needed because "while ... done < ..."
5592       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5593       exec 5<&0 < "$tmp"/fileset-changes
5594       func_update_ignorelist ()
5595       {
5596         ignore="$1"
5597         if test "$ignore" = .gitignore; then
5598           # In a .gitignore file, "foo" applies to the current directory and all
5599           # subdirectories, whereas "/foo" applies to the current directory only.
5600           anchor='/'
5601           escaped_anchor='\/'
5602           doubly_escaped_anchor='\\/'
5603         else
5604           anchor=''
5605           escaped_anchor=''
5606           doubly_escaped_anchor=''
5607         fi
5608         if test -f "$destdir/$dir$ignore"; then
5609           if test -n "$dir_added" || test -n "$dir_removed"; then
5610             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
5611             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
5612                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
5613              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
5614                > "$tmp"/ignore-removed
5615             )
5616             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
5617               if $doit; then
5618                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
5619                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
5620                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
5621                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,$/d,' < "$tmp"/ignore-removed; fi
5622                 } > "$tmp"/sed-ignore-removed
5623                 { cat "$destdir/$dir$ignore"~
5624                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
5625                 } | sed -f "$tmp"/sed-ignore-removed \
5626                   > "$destdir/$dir$ignore"
5627               else
5628                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
5629               fi
5630             fi
5631           fi
5632         else
5633           if test -n "$dir_added"; then
5634             if $doit; then
5635               echo "Creating $destdir/$dir$ignore"
5636               {
5637                 if test "$ignore" = .cvsignore; then
5638                   echo ".deps"
5639                   # Automake generates Makefile rules that create .dirstamp files.
5640                   echo ".dirstamp"
5641                 fi
5642                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
5643               } > "$destdir/$dir$ignore"
5644             else
5645               echo "Create $destdir/$dir$ignore"
5646             fi
5647           fi
5648         fi
5649       }
5650       func_done_dir ()
5651       {
5652         dir="$1"
5653         dir_added="$2"
5654         dir_removed="$3"
5655         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
5656           func_update_ignorelist .cvsignore
5657         fi
5658         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
5659           func_update_ignorelist .gitignore
5660         fi
5661       }
5662       last_dir=
5663       last_dir_added=
5664       last_dir_removed=
5665       while read line; do
5666         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
5667         next_dir=`echo "$line" | sed -e 's,|.*,,'`
5668         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
5669         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
5670         if test "$next_dir" != "$last_dir"; then
5671           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
5672           last_dir="$next_dir"
5673           last_dir_added=
5674           last_dir_removed=
5675         fi
5676         case $op in
5677           A) func_append last_dir_added "$file$nl";;
5678           R) func_append last_dir_removed "$file$nl";;
5679         esac
5680       done
5681       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
5682       exec 0<&5 5<&-
5683     }
5684   fi
5685
5686   echo "Finished."
5687   echo
5688   echo "You may need to add #include directives for the following .h files."
5689   # Intersect $specified_modules and $main_modules
5690   # (since $specified_modules is not necessarily of subset of $main_modules
5691   # - some may have been skipped through --avoid, and since the elements of
5692   # $main_modules but not in $specified_modules can go away without explicit
5693   # notice - through changes in the module dependencies).
5694   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
5695   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
5696   # First the #include <...> directives without #ifs, sorted for convenience,
5697   # then the #include "..." directives without #ifs, sorted for convenience,
5698   # then the #include directives that are surrounded by #ifs. Not sorted.
5699   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
5700     include_directive=`func_get_include_directive "$module"`
5701     case "$nl$include_directive" in
5702       *"$nl#if"*)
5703         echo "$include_directive" 1>&5
5704         ;;
5705       *)
5706         echo "$include_directive" | grep -v 'include "' 1>&6
5707         echo "$include_directive" | grep 'include "' 1>&7
5708         ;;
5709     esac
5710   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
5711   (
5712    LC_ALL=C sort -u "$tmp"/include-angles
5713    LC_ALL=C sort -u "$tmp"/include-quotes
5714    cat "$tmp"/include-if
5715   ) | sed -e '/^$/d' -e 's/^/  /'
5716   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
5717
5718   for module in $main_modules; do
5719     func_get_link_directive "$module"
5720   done \
5721     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
5722   if test `wc -l < "$tmp"/link` != 0; then
5723     echo
5724     echo "You may need to use the following Makefile variables when linking."
5725     echo "Use them in <program>_LDADD when linking a program, or"
5726     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
5727     cat "$tmp"/link
5728   fi
5729   rm -f "$tmp"/link
5730
5731   echo
5732   echo "Don't forget to"
5733   if test "$makefile_am" = Makefile.am; then
5734     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
5735   else
5736     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
5737   fi
5738   if test -n "$pobase"; then
5739     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
5740   fi
5741   if $inctests; then
5742     if test "$makefile_am" = Makefile.am; then
5743       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
5744     else
5745       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
5746     fi
5747   fi
5748   edit=0
5749   while test $edit != $makefile_am_edits; do
5750     edit=`expr $edit + 1`
5751     eval dir=\"\$makefile_am_edit${edit}_dir\"
5752     eval var=\"\$makefile_am_edit${edit}_var\"
5753     eval val=\"\$makefile_am_edit${edit}_val\"
5754     if test -n "$var"; then
5755       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
5756     fi
5757   done
5758   if grep '^ *AC_PROG_CC_STDC' "$configure_ac" > /dev/null; then
5759     position_early_after=AC_PROG_CC_STDC
5760   else
5761     if grep '^ *AC_PROG_CC_C99' "$configure_ac" > /dev/null; then
5762       position_early_after=AC_PROG_CC_C99
5763     else
5764       position_early_after=AC_PROG_CC
5765     fi
5766   fi
5767   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after $position_early_after,"
5768   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
5769 }
5770
5771 # func_create_testdir testdir modules
5772 # Input:
5773 # - local_gnulib_path  from --local-dir
5774 # - modcache        true or false, from --cache-modules/--no-cache-modules
5775 # - auxdir          directory relative to destdir where to place build aux files
5776 # - inctests        true if tests should be included, false otherwise
5777 # - incobsolete     true if obsolete modules among dependencies should be
5778 #                   included, blank otherwise
5779 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
5780 #                    blank otherwise
5781 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
5782 #                           blank otherwise
5783 # - excl_privileged_tests  true if tests that require root privileges should be
5784 #                          excluded, blank otherwise
5785 # - excl_unportable_tests  true if tests that fail on some platforms should be
5786 #                          excluded, blank otherwise
5787 # - single_configure  true if a single configure file should be generated,
5788 #                     false for a separate configure file for the tests
5789 # - avoidlist       list of modules to avoid
5790 # - cond_dependencies  true if --conditional-dependencies was given, false if
5791 #                      --no-conditional-dependencies was given, blank otherwise
5792 # - libtool         true if --libtool was given, false if --no-libtool was
5793 #                   given, blank otherwise
5794 # - symbolic        true if files should be symlinked, copied otherwise
5795 # - lsymbolic       true if files from local_gnulib_path should be symlinked,
5796 #                   copied otherwise
5797 func_create_testdir ()
5798 {
5799   testdir="$1"
5800   modules="$2"
5801   if test -z "$modules"; then
5802     # All modules together.
5803     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
5804     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
5805     # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
5806     modules=`func_all_modules`
5807     modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist | lib-ignore) ;; *) echo $m;; esac; done`
5808   fi
5809   specified_modules="$modules"
5810
5811   # Canonicalize the list of specified modules.
5812   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
5813
5814   # Unlike in func_import, here we want to include all kinds of tests for the
5815   # directly specified modules, but not for dependencies.
5816   inc_all_direct_tests=true
5817   inc_all_indirect_tests="$inc_all_tests"
5818
5819   # Check that the license of every module is consistent with the license of
5820   # its dependencies.
5821   saved_inctests="$inctests"
5822   # When computing transitive closures, don't consider $module to depend on
5823   # $module-tests. Need this because tests are implicitly GPL and may depend
5824   # on GPL modules - therefore we don't want a warning in this case.
5825   inctests=false
5826   for requested_module in $specified_modules; do
5827     requested_license=`func_get_license "$requested_module"`
5828     if test "$requested_license" != GPL; then
5829       # Here we use func_modules_transitive_closure, not just
5830       # func_get_dependencies, so that we also detect weird situations like
5831       # an LGPL module which depends on a GPLed build tool module which depends
5832       # on a GPL module.
5833       modules="$requested_module"
5834       func_modules_transitive_closure
5835       for module in $modules; do
5836         license=`func_get_license "$module"`
5837         case "$license" in
5838           'GPLed build tool') ;;
5839           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
5840           *)
5841             case "$requested_license" in
5842               GPLv2+)
5843                 case "$license" in
5844                   GPLv2+ | LGPLv2+) ;;
5845                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5846                 esac
5847                 ;;
5848               LGPL)
5849                 case "$license" in
5850                   LGPL | LGPLv2+) ;;
5851                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5852                 esac
5853                 ;;
5854               LGPLv2+)
5855                 case "$license" in
5856                   LGPLv2+) ;;
5857                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5858                 esac
5859                 ;;
5860             esac
5861             ;;
5862         esac
5863       done
5864     fi
5865   done
5866   inctests="$saved_inctests"
5867
5868   # Subdirectory names.
5869   sourcebase=gllib
5870   m4base=glm4
5871   pobase=
5872   docbase=gldoc
5873   testsbase=gltests
5874   macro_prefix=gl
5875   po_domain=
5876   witness_c_macro=
5877   vc_files=
5878
5879   # Determine final module list.
5880   modules="$specified_modules"
5881   func_modules_transitive_closure
5882   if test $verbose -ge 0; then
5883     func_show_module_list
5884   fi
5885   final_modules="$modules"
5886
5887   if $single_configure; then
5888     # Determine main module list and tests-related module list separately.
5889     func_modules_transitive_closure_separately
5890   fi
5891
5892   if $single_configure; then
5893     # Determine whether a $testsbase/libtests.a is needed.
5894     func_determine_use_libtests
5895   fi
5896
5897   # Add the dummy module if needed.
5898   if $single_configure; then
5899     func_modules_add_dummy_separately
5900   else
5901     func_modules_add_dummy
5902   fi
5903
5904   # Show banner notice of every module.
5905   if $single_configure; then
5906     modules="$main_modules"
5907     func_modules_notice
5908   else
5909     func_modules_notice
5910   fi
5911
5912   # Determine final file list.
5913   if $single_configure; then
5914     func_modules_to_filelist_separately
5915   else
5916     func_modules_to_filelist
5917     if test $verbose -ge 0; then
5918       echo "File list:"
5919       echo "$files" | sed -e 's/^/  /'
5920     fi
5921   fi
5922   # Add files for which the copy in gnulib is newer than the one that
5923   # "automake --add-missing --copy" would provide.
5924   files="$files build-aux/config.guess"
5925   files="$files build-aux/config.sub"
5926   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
5927
5928   rewritten='%REWRITTEN%'
5929   sed_rewrite_files="\
5930     s,^build-aux/,$rewritten$auxdir/,
5931     s,^doc/,$rewritten$docbase/,
5932     s,^lib/,$rewritten$sourcebase/,
5933     s,^m4/,$rewritten$m4base/,
5934     s,^tests/,$rewritten$testsbase/,
5935     s,^tests=lib/,$rewritten$testsbase/,
5936     s,^top/,$rewritten,
5937     s,^$rewritten,,"
5938
5939   # Create directories.
5940   for f in $files; do echo $f; done \
5941     | sed -e "$sed_rewrite_files" \
5942     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
5943     | LC_ALL=C sort -u \
5944     > "$tmp"/dirs
5945   { # Rearrange file descriptors. Needed because "while ... done < ..."
5946     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5947     exec 5<&0 < "$tmp"/dirs
5948     while read d; do
5949       mkdir -p "$testdir/$d"
5950     done
5951     exec 0<&5 5<&-
5952   }
5953
5954   # Copy files or make symbolic links.
5955   delimiter='   '
5956   for f in $files; do echo $f; done \
5957     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
5958     | LC_ALL=C sort \
5959     > "$tmp"/files
5960   { # Rearrange file descriptors. Needed because "while ... done < ..."
5961     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5962     exec 5<&0 < "$tmp"/files
5963     while read g f; do
5964       case "$f" in
5965         tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
5966       esac
5967       func_lookup_file "$f"
5968       if test -n "$lookedup_tmp"; then
5969         cp -p "$lookedup_file" "$testdir/$g"
5970       else
5971         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
5972         if func_should_symlink; then
5973           func_ln "$lookedup_file" "$testdir/$g"
5974         else
5975           cp -p "$lookedup_file" "$testdir/$g"
5976         fi
5977       fi
5978     done
5979     exec 0<&5 5<&-
5980   }
5981
5982   # Determine include_guard_prefix.
5983   func_compute_include_guard_prefix
5984
5985   # Create Makefile.ams that are for testing.
5986   for_test=true
5987
5988   # No special edits are needed.
5989   makefile_am_edits=0
5990
5991   # Create $sourcebase/Makefile.am.
5992   mkdir -p "$testdir/$sourcebase"
5993   destfile="$sourcebase/Makefile.am"
5994   if $single_configure; then
5995     modules="$main_modules"
5996   fi
5997   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
5998   any_uses_subdirs="$uses_subdirs"
5999
6000   # Create $m4base/Makefile.am.
6001   mkdir -p "$testdir/$m4base"
6002   (echo "## Process this file with automake to produce Makefile.in."
6003    echo
6004    echo "EXTRA_DIST ="
6005    for f in $files; do
6006      case "$f" in
6007        m4/* )
6008          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
6009      esac
6010    done
6011   ) > "$testdir/$m4base/Makefile.am"
6012
6013   subdirs="$sourcebase $m4base"
6014   subdirs_with_configure_ac=""
6015
6016   if false && test -f "$testdir"/$m4base/gettext.m4; then
6017     # Avoid stupid error message from automake:
6018     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
6019     mkdir -p "$testdir/po"
6020     (echo "## Process this file with automake to produce Makefile.in."
6021     ) > "$testdir/po/Makefile.am"
6022     func_append subdirs " po"
6023   fi
6024
6025   if $inctests; then
6026     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
6027     if $single_configure; then
6028       # Create $testsbase/Makefile.am.
6029       destfile="$testsbase/Makefile.am"
6030       modules="$testsrelated_modules"
6031       func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$testdir/$testsbase/Makefile.am"
6032     else
6033       # Viewed from the $testsbase subdirectory, $auxdir is different.
6034       saved_auxdir="$auxdir"
6035       auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
6036       # Create $testsbase/Makefile.am.
6037       use_libtests=false
6038       destfile="$testsbase/Makefile.am"
6039       func_emit_tests_Makefile_am "" > "$testdir/$testsbase/Makefile.am"
6040       any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
6041       # Create $testsbase/configure.ac.
6042       (echo "# Process this file with autoconf to produce a configure script."
6043        echo "AC_INIT([dummy], [0])"
6044        echo "AC_CONFIG_AUX_DIR([$auxdir])"
6045        echo "AM_INIT_AUTOMAKE"
6046        echo
6047        echo "AC_CONFIG_HEADERS([config.h])"
6048        echo
6049        echo "AC_PROG_CC"
6050        echo "AC_PROG_INSTALL"
6051        echo "AC_PROG_MAKE_SET"
6052
6053        func_emit_pre_early_macros false '' "$modules"
6054
6055        if test -n "$uses_subdirs"; then
6056          echo "AM_PROG_CC_C_O"
6057          echo
6058        fi
6059        for module in $modules; do
6060          func_verify_module
6061          if test -n "$module"; then
6062            case $module in
6063              gnumakefile | maintainer-makefile)
6064                # These modules are meant to be used only in the top-level directory.
6065                ;;
6066              *)
6067                func_get_autoconf_early_snippet "$module"
6068                ;;
6069            esac
6070          fi
6071        done \
6072          | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
6073        if test "$libtool" = true; then
6074          echo "LT_INIT([win32-dll])"
6075          echo "LT_LANG([C++])"
6076          echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
6077          echo "gl_cond_libtool=true"
6078        else
6079          echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
6080          echo "gl_cond_libtool=false"
6081          echo "gl_libdeps="
6082          echo "gl_ltlibdeps="
6083        fi
6084        # Wrap the set of autoconf snippets into an autoconf macro that is then
6085        # invoked. This is needed because autoconf does not support AC_REQUIRE
6086        # at the top level:
6087        #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
6088        # but we want the AC_REQUIRE to have its normal meaning (provide one
6089        # expansion of the required macro before the current point, and only one
6090        # expansion total).
6091        echo "AC_DEFUN([gl_INIT], ["
6092        sed_replace_build_aux='
6093          :a
6094          /AC_CONFIG_FILES(.*:build-aux\/.*)/{
6095            s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
6096            ba
6097          }'
6098        echo "gl_m4_base='../$m4base'"
6099        func_emit_initmacro_start $macro_prefix
6100        # We don't have explicit ordering constraints between the various
6101        # autoconf snippets. It's cleanest to put those of the library before
6102        # those of the tests.
6103        echo "gl_source_base='../$sourcebase'"
6104        func_emit_autoconf_snippets "$modules" func_verify_nontests_module false false false
6105        echo "gl_source_base='.'"
6106        func_emit_autoconf_snippets "$modules" func_verify_tests_module false false false
6107        func_emit_initmacro_end $macro_prefix
6108        # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
6109        # created using libtool, because libtool already handles the dependencies.
6110        if test "$libtool" != true; then
6111          libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
6112          echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
6113          echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
6114          echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
6115          echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
6116        fi
6117        echo "])"
6118        func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
6119        echo
6120        echo "gl_INIT"
6121        echo
6122        # Usually $testsbase/config.h will be a superset of config.h. Verify this
6123        # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
6124        echo "AH_TOP([#include \"../config.h\"])"
6125        echo
6126        echo "AC_CONFIG_FILES([Makefile])"
6127        echo "AC_OUTPUT"
6128       ) > "$testdir/$testsbase/configure.ac"
6129       auxdir="$saved_auxdir"
6130       subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
6131     fi
6132     func_append subdirs " $testsbase"
6133   fi
6134
6135   # Create Makefile.am.
6136   (echo "## Process this file with automake to produce Makefile.in."
6137    echo
6138    echo "AUTOMAKE_OPTIONS = 1.9.6 foreign"
6139    echo
6140    echo "SUBDIRS = $subdirs"
6141    echo
6142    echo "ACLOCAL_AMFLAGS = -I $m4base"
6143   ) > "$testdir/Makefile.am"
6144
6145   # Create configure.ac.
6146   (echo "# Process this file with autoconf to produce a configure script."
6147    echo "AC_INIT([dummy], [0])"
6148    if test "$auxdir" != "."; then
6149      echo "AC_CONFIG_AUX_DIR([$auxdir])"
6150    fi
6151    echo "AM_INIT_AUTOMAKE"
6152    echo
6153    echo "AC_CONFIG_HEADERS([config.h])"
6154    echo
6155    echo "AC_PROG_CC"
6156    echo "AC_PROG_INSTALL"
6157    echo "AC_PROG_MAKE_SET"
6158    echo
6159    echo "# For autobuild."
6160    echo "AC_CANONICAL_BUILD"
6161    echo "AC_CANONICAL_HOST"
6162    echo
6163    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
6164    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
6165    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
6166    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
6167
6168    func_emit_pre_early_macros false '' "$final_modules"
6169
6170    if test -n "$any_uses_subdirs"; then
6171      echo "AM_PROG_CC_C_O"
6172      echo
6173    fi
6174    for module in $final_modules; do
6175      if $single_configure; then
6176        func_verify_module
6177      else
6178        func_verify_nontests_module
6179      fi
6180      if test -n "$module"; then
6181        func_get_autoconf_early_snippet "$module"
6182      fi
6183    done \
6184      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
6185    if test "$libtool" = true; then
6186      echo "LT_INIT([win32-dll])"
6187      echo "LT_LANG([C++])"
6188      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
6189      echo "gl_cond_libtool=true"
6190    else
6191      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
6192      echo "gl_cond_libtool=false"
6193      echo "gl_libdeps="
6194      echo "gl_ltlibdeps="
6195    fi
6196    # Wrap the set of autoconf snippets into an autoconf macro that is then
6197    # invoked. This is needed because autoconf does not support AC_REQUIRE
6198    # at the top level:
6199    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
6200    # but we want the AC_REQUIRE to have its normal meaning (provide one
6201    # expansion of the required macro before the current point, and only one
6202    # expansion total).
6203    echo "AC_DEFUN([gl_INIT], ["
6204    if test "$auxdir" != "build-aux"; then
6205      sed_replace_build_aux='
6206        :a
6207        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
6208          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
6209          ba
6210        }'
6211    else
6212      sed_replace_build_aux="$sed_noop"
6213    fi
6214    echo "gl_m4_base='$m4base'"
6215    func_emit_initmacro_start $macro_prefix
6216    echo "gl_source_base='$sourcebase'"
6217    if $single_configure; then
6218      func_emit_autoconf_snippets "$main_modules" func_verify_module true false false
6219    else
6220      func_emit_autoconf_snippets "$modules" func_verify_nontests_module true false false
6221    fi
6222    func_emit_initmacro_end $macro_prefix
6223    if $single_configure; then
6224      echo "  gltests_libdeps="
6225      echo "  gltests_ltlibdeps="
6226      func_emit_initmacro_start ${macro_prefix}tests
6227      echo "  gl_source_base='$testsbase'"
6228      # Define a tests witness macro.
6229      echo "  ${macro_prefix}tests_WITNESS=IN_GNULIB_TESTS"
6230      echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
6231      echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
6232      echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
6233      func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true false false
6234      echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
6235      func_emit_initmacro_end ${macro_prefix}tests
6236    fi
6237    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
6238    # created using libtool, because libtool already handles the dependencies.
6239    if test "$libtool" != true; then
6240      libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
6241      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
6242      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
6243      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
6244      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
6245    fi
6246    if $single_configure; then
6247      if $use_libtests; then
6248        echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
6249        echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
6250      fi
6251    fi
6252    echo "])"
6253    func_emit_initmacro_done $macro_prefix $sourcebase
6254    if $single_configure; then
6255      func_emit_initmacro_done ${macro_prefix}tests $testsbase
6256    fi
6257    echo
6258    echo "gl_INIT"
6259    echo
6260    if test -n "$subdirs_with_configure_ac"; then
6261      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
6262    fi
6263    makefiles="Makefile"
6264    for d in $subdirs; do
6265      # For subdirs that have a configure.ac by their own, it's the subdir's
6266      # configure.ac which creates the subdir's Makefile.am, not this one.
6267      case " $subdirs_with_configure_ac " in
6268        *" $d "*) ;;
6269        *) func_append makefiles " $d/Makefile" ;;
6270      esac
6271    done
6272    echo "AC_CONFIG_FILES([$makefiles])"
6273    echo "AC_OUTPUT"
6274   ) > "$testdir/configure.ac"
6275
6276   # Create autogenerated files.
6277   (cd "$testdir"
6278    # Do not use "${AUTORECONF} --force --install", because it may invoke
6279    # autopoint, which brings in older versions of some of our .m4 files.
6280    if test -f $m4base/gettext.m4; then
6281      func_execute_command ${AUTOPOINT} --force || func_exit 1
6282      for f in $m4base/*.m4~; do
6283        if test -f $f; then
6284          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
6285        fi
6286      done
6287    fi
6288    if test "$libtool" = true; then
6289      func_execute_command ${LIBTOOLIZE} --copy || func_exit 1
6290    fi
6291    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
6292    if ! test -d build-aux; then
6293      func_execute_command mkdir build-aux || func_exit 1
6294    fi
6295    func_execute_command ${AUTOCONF} || func_exit 1
6296    func_execute_command ${AUTOHEADER} || func_exit 1
6297    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6298   ) || func_exit 1
6299   if $inctests && ! $single_configure; then
6300     # Create autogenerated files.
6301     (cd "$testdir/$testsbase" || func_exit 1
6302      # Do not use "${AUTORECONF} --force --install", because it may invoke
6303      # autopoint, which brings in older versions of some of our .m4 files.
6304      if test -f ../$m4base/gettext.m4; then
6305        func_execute_command ${AUTOPOINT} --force || func_exit 1
6306        for f in ../$m4base/*.m4~; do
6307          if test -f $f; then
6308            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
6309          fi
6310        done
6311      fi
6312      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
6313      if ! test -d ../build-aux; then
6314        func_execute_command mkdir ../build-aux
6315      fi
6316      func_execute_command ${AUTOCONF} || func_exit 1
6317      func_execute_command ${AUTOHEADER} || func_exit 1
6318      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6319     ) || func_exit 1
6320   fi
6321   # Need to run configure and make once, to create built files that are to be
6322   # distributed (such as parse-datetime.c).
6323   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
6324   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
6325   cleaned_files=`combine_lines < "$testdir/$sourcebase/Makefile.am" \
6326                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
6327   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
6328   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
6329   # such $(FOO_H) because they don't refer to distributed files.
6330   built_sources=`combine_lines < "$testdir/$sourcebase/Makefile.am" \
6331                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
6332                  | sed -e "$sed_remove_make_variables"`
6333   distributed_built_sources=`for file in $built_sources; do
6334                                case "$cleaned_files" in
6335                                  *" "$file" "*) ;;
6336                                  *) echo $file ;;
6337                                esac;
6338                              done`
6339   tests_distributed_built_sources=
6340   if $inctests; then
6341     # Likewise for built files in the $testsbase directory.
6342     tests_cleaned_files=`combine_lines < "$testdir/$testsbase/Makefile.am" \
6343                          | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
6344     tests_cleaned_files=`for file in $tests_cleaned_files; do echo " $file "; done`
6345     tests_built_sources=`combine_lines < "$testdir/$testsbase/Makefile.am" \
6346                          | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
6347                          | sed -e "$sed_remove_make_variables"`
6348     tests_distributed_built_sources=`for file in $tests_built_sources; do
6349                                        case "$tests_cleaned_files" in
6350                                          *" "$file" "*) ;;
6351                                          *) echo $file ;;
6352                                        esac;
6353                                      done`
6354   fi
6355   if test -n "$distributed_built_sources" || test -n "$tests_distributed_built_sources"; then
6356     (cd "$testdir"
6357      ./configure || func_exit 1
6358        if test -n "$distributed_built_sources"; then
6359          cd "$sourcebase"
6360          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
6361          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6362                built_sources \
6363            || func_exit 1
6364          cd ..
6365        fi
6366        if test -n "$tests_distributed_built_sources"; then
6367          cd "$testsbase"
6368          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
6369          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6370                built_sources \
6371            || func_exit 1
6372          cd ..
6373        fi
6374      $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6375            distclean \
6376        || func_exit 1
6377     ) || func_exit 1
6378   fi
6379 }
6380
6381 # func_create_megatestdir megatestdir allmodules
6382 # Input:
6383 # - local_gnulib_path  from --local-dir
6384 # - modcache        true or false, from --cache-modules/--no-cache-modules
6385 # - auxdir          directory relative to destdir where to place build aux files
6386 func_create_megatestdir ()
6387 {
6388   megatestdir="$1"
6389   allmodules="$2"
6390   if test -z "$allmodules"; then
6391     allmodules=`func_all_modules`
6392   fi
6393
6394   megasubdirs=
6395   # First, all modules one by one.
6396   for onemodule in $allmodules; do
6397     func_create_testdir "$megatestdir/$onemodule" $onemodule
6398     func_append megasubdirs "$onemodule "
6399   done
6400   # Then, all modules all together.
6401   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
6402   allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
6403   func_create_testdir "$megatestdir/ALL" "$allmodules"
6404   func_append megasubdirs "ALL"
6405
6406   # Create autobuild.
6407   cvsdate=`vc_witness="$gnulib_dir/.git/refs/heads/master"; \
6408            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
6409              | sed -e 's,January,01,'   -e 's,Jan,01,' \
6410                    -e 's,February,02,'  -e 's,Feb,02,' \
6411                    -e 's,March,03,'     -e 's,Mar,03,' \
6412                    -e 's,April,04,'     -e 's,Apr,04,' \
6413                    -e 's,May,05,'                      \
6414                    -e 's,June,06,'      -e 's,Jun,06,' \
6415                    -e 's,July,07,'      -e 's,Jul,07,' \
6416                    -e 's,August,08,'    -e 's,Aug,08,' \
6417                    -e 's,September,09,' -e 's,Sep,09,' \
6418                    -e 's,October,10,'   -e 's,Oct,10,' \
6419                    -e 's,November,11,'  -e 's,Nov,11,' \
6420                    -e 's,December,12,'  -e 's,Dec,12,' \
6421                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
6422                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
6423   (echo '#!/bin/sh'
6424    echo "CVSDATE=$cvsdate"
6425    echo ": \${MAKE=make}"
6426    echo "test -d logs || mkdir logs"
6427    echo "for module in $megasubdirs; do"
6428    echo "  echo \"Working on module \$module...\""
6429    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
6430    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
6431    echo "   echo"
6432    echo "   set -x"
6433    echo "   : autobuild project... \$module"
6434    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
6435    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
6436    echo "   : autobuild hostname... \`hostname\`"
6437    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && \$MAKE && \$MAKE check && \$MAKE distclean"
6438    echo "   echo rc=\$?"
6439    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
6440    echo "done"
6441   ) > "$megatestdir/do-autobuild"
6442   chmod a+x "$megatestdir/do-autobuild"
6443
6444   # Create Makefile.am.
6445   (echo "## Process this file with automake to produce Makefile.in."
6446    echo
6447    echo "AUTOMAKE_OPTIONS = 1.9.6 foreign"
6448    echo
6449    echo "SUBDIRS = $megasubdirs"
6450    echo
6451    echo "EXTRA_DIST = do-autobuild"
6452   ) > "$megatestdir/Makefile.am"
6453
6454   # Create configure.ac.
6455   (echo "# Process this file with autoconf to produce a configure script."
6456    echo "AC_INIT([dummy], [0])"
6457    if test "$auxdir" != "."; then
6458      echo "AC_CONFIG_AUX_DIR([$auxdir])"
6459    fi
6460    echo "AM_INIT_AUTOMAKE"
6461    echo
6462    echo "AC_PROG_MAKE_SET"
6463    echo
6464    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
6465    echo "AC_CONFIG_FILES([Makefile])"
6466    echo "AC_OUTPUT"
6467   ) > "$megatestdir/configure.ac"
6468
6469   # Create autogenerated files.
6470   (cd "$megatestdir"
6471    # Do not use "${AUTORECONF} --install", because autoreconf operates
6472    # recursively, but the subdirectories are already finished, therefore
6473    # calling autoreconf here would only waste lots of CPU time.
6474    func_execute_command ${ACLOCAL} || func_exit 1
6475    func_execute_command mkdir build-aux
6476    func_execute_command ${AUTOCONF} || func_exit 1
6477    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6478   ) || func_exit 1
6479 }
6480
6481 case $mode in
6482   "" )
6483     func_fatal_error "no mode specified" ;;
6484
6485   list )
6486     func_all_modules
6487     ;;
6488
6489   find )
6490     # sed expression that converts a literal to a basic regular expression.
6491     # Needs to handle . [ \ * ^ $.
6492     sed_literal_to_basic_regex='s/\\/\\\\/g
6493 s/\[/\\[/g
6494 s/\^/\\^/g
6495 s/\([.*$]\)/[\1]/g'
6496     for filename
6497     do
6498       if test -f "$gnulib_dir/$filename" \
6499          || func_lookup_local_file "$filename"; then
6500         filename_anywhere_regex=`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`
6501         filename_line_regex='^'"$filename_anywhere_regex"'$'
6502         module_candidates=`
6503           {
6504             (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filename_line_regex" /dev/null | sed -e 's,^modules/,,')
6505             func_path_foreach "$local_gnulib_path" func_modules_in_dir %dir% | xargs -n 100 grep -l "$filename_anywhere_regex" /dev/null | sed -e 's,^modules/,,' -e 's,\.diff$,,'
6506           } \
6507             | func_sanitize_modulelist \
6508             | LC_ALL=C sort -u
6509           `
6510         for module in $module_candidates; do
6511           if func_get_filelist $module | grep "$filename_line_regex" > /dev/null; then
6512             echo $module
6513           fi
6514         done
6515       else
6516         func_warning "file $filename does not exist"
6517       fi
6518     done
6519     ;;
6520
6521   import | add-import | remove-import | update )
6522
6523     # Where to import.
6524     if test -z "$destdir"; then
6525       destdir=.
6526     fi
6527     test -d "$destdir" \
6528       || func_fatal_error "destination directory does not exist: $destdir"
6529
6530     # Prefer configure.ac to configure.in.
6531     if test -f "$destdir"/configure.ac; then
6532       configure_ac="$destdir/configure.ac"
6533     else
6534       if test -f "$destdir"/configure.in; then
6535         configure_ac="$destdir/configure.in"
6536       else
6537         func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
6538       fi
6539     fi
6540
6541     # Analyze configure.ac.
6542     guessed_auxdir="."
6543     guessed_libtool=false
6544     my_sed_traces='
6545       s,#.*$,,
6546       s,^dnl .*$,,
6547       s, dnl .*$,,
6548       /AC_CONFIG_AUX_DIR/ {
6549         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
6550       }
6551       /A[CM]_PROG_LIBTOOL/ {
6552         s,^.*$,guessed_libtool=true,p
6553       }'
6554     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
6555
6556     if test -z "$auxdir"; then
6557       auxdir="$guessed_auxdir"
6558     fi
6559
6560     # Determine where to apply func_import.
6561     if test "$mode" = import; then
6562       # Apply func_import to a particular gnulib directory.
6563       # The command line contains the complete specification; don't look at
6564       # the contents of gnulib-cache.m4.
6565       test -n "$supplied_libname" || supplied_libname=true
6566       test -n "$sourcebase" || sourcebase="lib"
6567       test -n "$m4base" || m4base="m4"
6568       test -n "$docbase" || docbase="doc"
6569       test -n "$testsbase" || testsbase="tests"
6570       test -n "$macro_prefix" || macro_prefix="gl"
6571       func_import "$*"
6572     else
6573       if test -n "$m4base"; then
6574         # Apply func_import to a particular gnulib directory.
6575         # Any number of additional modules can be given.
6576         if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
6577           # First use of gnulib in the given m4base.
6578           test -n "$supplied_libname" || supplied_libname=true
6579           test -n "$sourcebase" || sourcebase="lib"
6580           test -n "$docbase" || docbase="doc"
6581           test -n "$testsbase" || testsbase="tests"
6582           test -n "$macro_prefix" || macro_prefix="gl"
6583         fi
6584         func_import "$*"
6585       else
6586         # Apply func_import to all gnulib directories.
6587         # To get this list of directories, look at Makefile.am. (Not at
6588         # configure, because it may be omitted from version control. Also,
6589         # don't run "find $destdir -name gnulib-cache.m4", as it might be
6590         # too expensive.)
6591         m4dirs=
6592         m4dirs_count=0
6593         if test -f "$destdir"/Makefile.am; then
6594           aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[        ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
6595           m4dir_is_next=
6596           for arg in $aclocal_amflags; do
6597             if test -n "$m4dir_is_next"; then
6598               # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
6599               case "$arg" in
6600                 /*) ;;
6601                 *)
6602                   if test -f "$destdir/$arg"/gnulib-cache.m4; then
6603                     func_append m4dirs " $arg"
6604                     m4dirs_count=`expr $m4dirs_count + 1`
6605                   fi
6606                   ;;
6607               esac
6608               m4dir_is_next=
6609             else
6610               if test "X$arg" = "X-I"; then
6611                 m4dir_is_next=yes
6612               else
6613                 m4dir_is_next=
6614               fi
6615             fi
6616           done
6617         else
6618           # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
6619           if test -f "$destdir"/aclocal.m4; then
6620             sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
6621             sedexpr2='s,^[^/]*$,.,'
6622             sedexpr3='s,/[^/]*$,,'
6623             m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
6624             m4dirs=`for arg in $m4dirs; do if test -f "$destdir/$arg"/gnulib-cache.m4; then echo $arg; fi; done`
6625             m4dirs_count=`for arg in $m4dirs; do echo "$arg"; done | wc -l`
6626           fi
6627         fi
6628         if test $m4dirs_count = 0; then
6629           # First use of gnulib in a package.
6630           # Any number of additional modules can be given.
6631           test -n "$supplied_libname" || supplied_libname=true
6632           test -n "$sourcebase" || sourcebase="lib"
6633           m4base="m4"
6634           test -n "$docbase" || docbase="doc"
6635           test -n "$testsbase" || testsbase="tests"
6636           test -n "$macro_prefix" || macro_prefix="gl"
6637           func_import "$*"
6638         else
6639           if test $m4dirs_count = 1; then
6640             # There's only one use of gnulib here. Assume the user means it.
6641             # Any number of additional modules can be given.
6642             for m4base in $m4dirs; do
6643               func_import "$*"
6644             done
6645           else
6646             # Ambiguous - guess what the user meant.
6647             if test $# = 0; then
6648               # No further arguments. Guess the user wants to update all of them.
6649               for m4base in $m4dirs; do
6650                 # Perform func_import in a subshell, so that variable values
6651                 # such as
6652                 #   local_gnulib_path, incobsolete, inc_cxx_tests,
6653                 #   inc_longrunning_tests, inc_privileged_tests,
6654                 #   inc_unportable_tests, inc_all_tests, avoidlist, sourcebase,
6655                 #   m4base, pobase, docbase, testsbase, inctests, libname, lgpl,
6656                 #   makefile_name, libtool, macro_prefix, po_domain,
6657                 #   witness_c_macro, vc_files
6658                 # don't propagate from one directory to another.
6659                 (func_import) || func_exit 1
6660               done
6661             else
6662               # Really ambiguous.
6663               func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
6664             fi
6665           fi
6666         fi
6667       fi
6668     fi
6669     ;;
6670
6671   create-testdir )
6672     if test -z "$destdir"; then
6673       func_fatal_error "please specify --dir option"
6674     fi
6675     mkdir "$destdir"
6676     test -d "$destdir" \
6677       || func_fatal_error "could not create destination directory"
6678     test -n "$auxdir" || auxdir="build-aux"
6679     func_create_testdir "$destdir" "$*"
6680     ;;
6681
6682   create-megatestdir )
6683     if test -z "$destdir"; then
6684       func_fatal_error "please specify --dir option"
6685     fi
6686     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6687     test -n "$auxdir" || auxdir="build-aux"
6688     func_create_megatestdir "$destdir" "$*"
6689     ;;
6690
6691   test )
6692     test -n "$destdir" || destdir=testdir$$
6693     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6694     test -n "$auxdir" || auxdir="build-aux"
6695     func_create_testdir "$destdir" "$*"
6696     cd "$destdir"
6697       mkdir build
6698       cd build
6699         ../configure || func_exit 1
6700         $MAKE || func_exit 1
6701         $MAKE check || func_exit 1
6702         $MAKE distclean || func_exit 1
6703         remaining=`find . -type f -print`
6704         if test -n "$remaining"; then
6705           echo "Remaining files:" $remaining 1>&2
6706           echo "gnulib-tool: *** Stop." 1>&2
6707           func_exit 1
6708         fi
6709       cd ..
6710     cd ..
6711     rm -rf "$destdir"
6712     ;;
6713
6714   megatest )
6715     test -n "$destdir" || destdir=testdir$$
6716     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6717     test -n "$auxdir" || auxdir="build-aux"
6718     func_create_megatestdir "$destdir" "$*"
6719     cd "$destdir"
6720       mkdir build
6721       cd build
6722         ../configure
6723         $MAKE
6724         $MAKE check
6725         $MAKE distclean
6726         remaining=`find . -type f -print`
6727         if test -n "$remaining"; then
6728           echo "Remaining files:" $remaining 1>&2
6729           echo "gnulib-tool: *** Stop." 1>&2
6730           func_exit 1
6731         fi
6732       cd ..
6733     cd ..
6734     rm -rf "$destdir"
6735     ;;
6736
6737   extract-description )
6738     for module
6739     do
6740       func_verify_module
6741       if test -n "$module"; then
6742         func_get_description "$module"
6743       fi
6744     done
6745     ;;
6746
6747   extract-comment )
6748     for module
6749     do
6750       func_verify_module
6751       if test -n "$module"; then
6752         func_get_comment "$module"
6753       fi
6754     done
6755     ;;
6756
6757   extract-status )
6758     for module
6759     do
6760       func_verify_module
6761       if test -n "$module"; then
6762         func_get_status "$module"
6763       fi
6764     done
6765     ;;
6766
6767   extract-notice )
6768     for module
6769     do
6770       func_verify_module
6771       if test -n "$module"; then
6772         func_get_notice "$module"
6773       fi
6774     done
6775     ;;
6776
6777   extract-applicability )
6778     for module
6779     do
6780       func_verify_module
6781       if test -n "$module"; then
6782         func_get_applicability "$module"
6783       fi
6784     done
6785     ;;
6786
6787   extract-filelist )
6788     for module
6789     do
6790       func_verify_module
6791       if test -n "$module"; then
6792         func_get_filelist "$module"
6793       fi
6794     done
6795     ;;
6796
6797   extract-dependencies )
6798     if test -n "$avoidlist"; then
6799       func_fatal_error "cannot combine --avoid and --extract-dependencies"
6800     fi
6801     for module
6802     do
6803       func_verify_module
6804       if test -n "$module"; then
6805         func_get_dependencies "$module"
6806       fi
6807     done
6808     ;;
6809
6810   extract-autoconf-snippet )
6811     for module
6812     do
6813       func_verify_module
6814       if test -n "$module"; then
6815         func_get_autoconf_snippet "$module"
6816       fi
6817     done
6818     ;;
6819
6820   extract-automake-snippet )
6821     for module
6822     do
6823       func_verify_module
6824       if test -n "$module"; then
6825         func_get_automake_snippet "$module"
6826       fi
6827     done
6828     ;;
6829
6830   extract-include-directive )
6831     for module
6832     do
6833       func_verify_module
6834       if test -n "$module"; then
6835         func_get_include_directive "$module"
6836       fi
6837     done
6838     ;;
6839
6840   extract-link-directive )
6841     for module
6842     do
6843       func_verify_module
6844       if test -n "$module"; then
6845         func_get_link_directive "$module"
6846       fi
6847     done
6848     ;;
6849
6850   extract-license )
6851     for module
6852     do
6853       func_verify_module
6854       if test -n "$module"; then
6855         func_get_license "$module"
6856       fi
6857     done
6858     ;;
6859
6860   extract-maintainer )
6861     for module
6862     do
6863       func_verify_module
6864       if test -n "$module"; then
6865         func_get_maintainer "$module"
6866       fi
6867     done
6868     ;;
6869
6870   extract-tests-module )
6871     for module
6872     do
6873       func_verify_module
6874       if test -n "$module"; then
6875         func_get_tests_module "$module"
6876       fi
6877     done
6878     ;;
6879
6880   copy-file )
6881     # Verify the number of arguments.
6882     if test $# -lt 1 || test $# -gt 2; then
6883       func_fatal_error "invalid number of arguments for --$mode"
6884     fi
6885
6886     # The first argument is the file to be copied.
6887     f="$1"
6888     # Verify the file exists.
6889     func_lookup_file "$f"
6890
6891     # The second argument is the destination; either a directory ot a file.
6892     # It defaults to the current directory.
6893     dest="$2"
6894     test -n "$dest" || dest='.'
6895     test -n "$sourcebase" || sourcebase="lib"
6896     test -n "$m4base" || m4base="m4"
6897     test -n "$docbase" || docbase="doc"
6898     test -n "$testsbase" || testsbase="tests"
6899     test -n "$auxdir" || auxdir="build-aux"
6900     rewritten='%REWRITTEN%'
6901     sed_rewrite_files="\
6902       s,^build-aux/,$rewritten$auxdir/,
6903       s,^doc/,$rewritten$docbase/,
6904       s,^lib/,$rewritten$sourcebase/,
6905       s,^m4/,$rewritten$m4base/,
6906       s,^tests/,$rewritten$testsbase/,
6907       s,^top/,$rewritten,
6908       s,^$rewritten,,"
6909     if test -d "$dest"; then
6910       destdir="$dest"
6911       g=`echo "$f" | sed -e "$sed_rewrite_files"`
6912     else
6913       destdir=`dirname "$dest"`
6914       g=`basename "$dest"`
6915     fi
6916
6917     # Create the directory for destfile.
6918     d=`dirname "$destdir/$g"`
6919     if $doit; then
6920       if test -n "$d" && test ! -d "$d"; then
6921         mkdir -p "$d" || func_fatal_error "failed"
6922       fi
6923     fi
6924     # Copy the file.
6925     func_dest_tmpfilename "$g"
6926     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
6927     already_present=true
6928     if test -f "$destdir/$g"; then
6929       # The file already exists.
6930       func_update_file
6931     else
6932       # Install the file.
6933       # Don't protest if the file should be there but isn't: it happens
6934       # frequently that developers don't put autogenerated files under version
6935       # control.
6936       func_add_file
6937     fi
6938     rm -f "$tmpfile"
6939     ;;
6940
6941   * )
6942     func_fatal_error "unknown operation mode --$mode" ;;
6943 esac
6944
6945 rm -rf "$tmp"
6946 # Undo the effect of the previous 'trap' command. Some shellology:
6947 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
6948 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
6949 # exit); for the others we need to call 'exit' explicitly. The value of $? is
6950 # 128 + signal number and is set before the trap-registered command is run.
6951 trap '' 0
6952 trap 'func_exit $?' 1 2 3 13 15
6953
6954 exit 0
6955
6956 # Local Variables:
6957 # indent-tabs-mode: nil
6958 # whitespace-check-buffer-indent: nil
6959 # End: