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