libposix: Add _HEADERS primaries to posix modules.
[gnulib.git] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2011 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         pt_chown) ;;
2232         *)
2233           func_filter_filelist extra_files "$nl" "$extra_files" '' '.c' '' ''
2234           if test -n "$extra_files"; then
2235             echo "EXTRA_lib_SOURCES +=" $extra_files
2236             echo
2237           fi
2238           ;;
2239       esac
2240       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
2241       func_filter_filelist buildaux_files "$nl" "$all_files" 'build-aux/' '' 'build-aux/' ''
2242       if test -n "$buildaux_files"; then
2243         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
2244         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
2245         echo
2246       fi
2247       # Synthesize an EXTRA_DIST augmentation also for the files from top/.
2248       func_filter_filelist top_files "$nl" "$all_files" 'top/' '' 'top/' ''
2249       if test -n "$top_files"; then
2250         sed_prepend_topdir='s,^,$(top_srcdir)/,'
2251         echo "EXTRA_DIST += "`echo "$top_files" | sed -e "$sed_prepend_topdir"`
2252         echo
2253       fi
2254       ;;
2255   esac
2256 }
2257
2258 # func_get_include_directive module
2259 # Input:
2260 # - local_gnulib_dir  from --local-dir
2261 # - modcache          true or false, from --cache-modules/--no-cache-modules
2262 func_get_include_directive ()
2263 {
2264   {
2265     if ! $modcache; then
2266       func_lookup_file "modules/$1"
2267       sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file"
2268     else
2269       func_cache_lookup_module "$1"
2270       # Output the field's value, including the final newline (if any).
2271       if $have_associative; then
2272         if eval 'test -n "${modcache_include[$1]+set}"'; then
2273           eval 'echo "${modcache_include[$1]}"'
2274         fi
2275       else
2276         eval "field_set=\"\$${cachevar}_include_set\""
2277         if test -n "$field_set"; then
2278           eval "field_value=\"\$${cachevar}_include\""
2279           echo "${field_value}"
2280         fi
2281       fi
2282     fi
2283   } | sed -e 's/^\(["<]\)/#include \1/'
2284 }
2285
2286 # func_get_link_directive module
2287 # Input:
2288 # - local_gnulib_dir  from --local-dir
2289 # - modcache          true or false, from --cache-modules/--no-cache-modules
2290 func_get_link_directive ()
2291 {
2292   if ! $modcache; then
2293     func_lookup_file "modules/$1"
2294     sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
2295   else
2296     func_cache_lookup_module "$1"
2297     # Output the field's value, including the final newline (if any).
2298     if $have_associative; then
2299       if eval 'test -n "${modcache_link[$1]+set}"'; then
2300         eval 'echo "${modcache_link[$1]}"'
2301       fi
2302     else
2303       eval "field_set=\"\$${cachevar}_link_set\""
2304       if test -n "$field_set"; then
2305         eval "field_value=\"\$${cachevar}_link\""
2306         echo "${field_value}"
2307       fi
2308     fi
2309   fi
2310 }
2311
2312 # func_get_license module
2313 # Input:
2314 # - local_gnulib_dir  from --local-dir
2315 # - modcache          true or false, from --cache-modules/--no-cache-modules
2316 func_get_license ()
2317 {
2318   {
2319     if ! $modcache; then
2320       func_lookup_file "modules/$1"
2321       sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
2322     else
2323       func_cache_lookup_module "$1"
2324       # Output the field's value, including the final newline (if any).
2325       if $have_associative; then
2326         if eval 'test -n "${modcache_license[$1]+set}"'; then
2327           eval 'echo "${modcache_license[$1]}"'
2328         fi
2329       else
2330         eval "field_set=\"\$${cachevar}_license_set\""
2331         if test -n "$field_set"; then
2332           eval "field_value=\"\$${cachevar}_license\""
2333           echo "${field_value}"
2334         fi
2335       fi
2336     fi
2337     # The default is GPL.
2338     echo "GPL"
2339   } | sed -e 's,^ *$,,' | sed -e 1q
2340 }
2341
2342 # func_get_maintainer module
2343 # Input:
2344 # - local_gnulib_dir  from --local-dir
2345 # - modcache          true or false, from --cache-modules/--no-cache-modules
2346 func_get_maintainer ()
2347 {
2348   if ! $modcache; then
2349     func_lookup_file "modules/$1"
2350     sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
2351   else
2352     func_cache_lookup_module "$1"
2353     # Output the field's value, including the final newline (if any).
2354     if $have_associative; then
2355       if eval 'test -n "${modcache_maintainer[$1]+set}"'; then
2356         eval 'echo "${modcache_maintainer[$1]}"'
2357       fi
2358     else
2359       eval "field_set=\"\$${cachevar}_maintainer_set\""
2360       if test -n "$field_set"; then
2361         eval "field_value=\"\$${cachevar}_maintainer\""
2362         echo "${field_value}"
2363       fi
2364     fi
2365   fi
2366 }
2367
2368 # func_get_tests_module module
2369 # Input:
2370 # - local_gnulib_dir  from --local-dir
2371 func_get_tests_module ()
2372 {
2373   # The naming convention for tests modules is hardwired: ${module}-tests.
2374   if test -f "$gnulib_dir/modules/$1"-tests \
2375      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
2376           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
2377     echo "$1"-tests
2378   fi
2379 }
2380
2381 # func_acceptable module
2382 # tests whether a module is acceptable.
2383 # Input:
2384 # - avoidlist       list of modules to avoid
2385 func_acceptable ()
2386 {
2387   for avoid in $avoidlist; do
2388     if test "$avoid" = "$1"; then
2389       return 1
2390     fi
2391   done
2392   return 0
2393 }
2394
2395 # func_modules_transitive_closure
2396 # Input:
2397 # - local_gnulib_dir  from --local-dir
2398 # - modcache        true or false, from --cache-modules/--no-cache-modules
2399 # - modules         list of specified modules
2400 # - inctests        true if tests should be included, blank otherwise
2401 # - incobsolete     true if obsolete modules among dependencies should be
2402 #                   included, blank otherwise
2403 # - inc_cxx_tests   true if C++ interoperability tests should be included,
2404 #                   blank otherwise
2405 # - inc_longrunning_tests  true if long-runnings tests should be included,
2406 #                          blank otherwise
2407 # - inc_privileged_tests  true if tests that require root privileges should be
2408 #                         included, blank otherwise
2409 # - inc_unportable_tests  true if tests that fail on some platforms should be
2410 #                         included, blank otherwise
2411 # - inc_all_direct_tests   true if all kinds of problematic unit tests among
2412 #                          the unit tests of the specified modules should be
2413 #                          included, blank otherwise
2414 # - inc_all_indirect_tests   true if all kinds of problematic unit tests among
2415 #                            the unit tests of the dependencies should be
2416 #                            included, blank otherwise
2417 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
2418 #                    blank otherwise
2419 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
2420 #                           blank otherwise
2421 # - excl_privileged_tests  true if tests that require root privileges should be
2422 #                          excluded, blank otherwise
2423 # - excl_unportable_tests  true if tests that fail on some platforms should be
2424 #                          excluded, blank otherwise
2425 # - avoidlist       list of modules to avoid
2426 # - tmp             pathname of a temporary directory
2427 # Output:
2428 # - modules         list of modules, including dependencies
2429 func_modules_transitive_closure ()
2430 {
2431   # In order to process every module only once (for speed), process an "input
2432   # list" of modules, producing an "output list" of modules. During each round,
2433   # more modules can be queued in the input list. Once a module on the input
2434   # list has been processed, it is added to the "handled list", so we can avoid
2435   # to process it again.
2436   handledmodules=
2437   inmodules="$modules"
2438   outmodules=
2439   fmtc_inc_all_tests="$inc_all_direct_tests"
2440   while test -n "$inmodules"; do
2441     inmodules_this_round="$inmodules"
2442     inmodules=                    # Accumulator, queue for next round
2443     for module in $inmodules_this_round; do
2444       func_verify_module
2445       if test -n "$module"; then
2446         if func_acceptable $module; then
2447           func_append outmodules " $module"
2448           deps=`func_get_dependencies $module`
2449           # Duplicate dependencies are harmless, but Jim wants a warning.
2450           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
2451           if test -n "$duplicated_deps"; then
2452             func_warning "module $module has duplicated dependencies: "`echo $duplicated_deps`
2453           fi
2454           if test -n "$inctests"; then
2455             testsmodule=`func_get_tests_module $module`
2456             if test -n "$testsmodule"; then
2457               deps="$deps $testsmodule"
2458             fi
2459           fi
2460           for dep in $deps; do
2461             # Determine whether to include the dependency or tests module.
2462             inc=true
2463             for word in `func_get_status $dep`; do
2464               case "$word" in
2465                 obsolete)
2466                   test -n "$incobsolete" \
2467                     || inc=false
2468                   ;;
2469                 c++-test)
2470                   test -z "$excl_cxx_tests" \
2471                     || inc=false
2472                   test -n "$fmtc_inc_all_tests" || test -n "$inc_cxx_tests" \
2473                     || inc=false
2474                   ;;
2475                 longrunning-test)
2476                   test -z "$excl_longrunning_tests" \
2477                     || inc=false
2478                   test -n "$fmtc_inc_all_tests" || test -n "$inc_longrunning_tests" \
2479                     || inc=false
2480                   ;;
2481                 privileged-test)
2482                   test -z "$excl_privileged_tests" \
2483                     || inc=false
2484                   test -n "$fmtc_inc_all_tests" || test -n "$inc_privileged_tests" \
2485                     || inc=false
2486                   ;;
2487                 unportable-test)
2488                   test -z "$excl_unportable_tests" \
2489                     || inc=false
2490                   test -n "$fmtc_inc_all_tests" || test -n "$inc_unportable_tests" \
2491                     || inc=false
2492                   ;;
2493                 *-test)
2494                   test -n "$fmtc_inc_all_tests" \
2495                     || inc=false
2496                   ;;
2497               esac
2498             done
2499             if $inc; then
2500               func_append inmodules " $dep"
2501             fi
2502           done
2503         fi
2504       fi
2505     done
2506     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
2507     # Remove $handledmodules from $inmodules.
2508     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
2509     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
2510     fmtc_inc_all_tests="$inc_all_indirect_tests"
2511   done
2512   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
2513   rm -f "$tmp"/queued-modules
2514 }
2515
2516 # func_show_module_list
2517 # Input:
2518 # - specified_modules  list of specified modules (one per line, sorted)
2519 # - modules         complete list of modules (one per line, sorted)
2520 # - tmp             pathname of a temporary directory
2521 func_show_module_list ()
2522 {
2523   if case "$TERM" in
2524        xterm*) test -t 1;;
2525        *) false;;
2526      esac; then
2527     # Assume xterm compatible escape sequences.
2528     bold_on=`printf '\x1b[1m'`
2529     bold_off=`printf '\x1b[0m'`
2530   else
2531     bold_on=
2532     bold_off=
2533   fi
2534   echo "Module list with included dependencies (indented):"
2535   echo "$specified_modules" | sed -e '/^$/d' -e 's/$/| /' > "$tmp"/specified-modules
2536   echo "$modules" | sed -e '/^$/d' \
2537     | LC_ALL=C join -t '|' -a 2 "$tmp"/specified-modules - \
2538     | sed -e 's/^\(.*\)|.*/|\1/' -e 's/^/    /' -e 's/^    |\(.*\)$/  '"${bold_on}"'\1'"${bold_off}"'/'
2539 }
2540
2541 # func_modules_add_dummy
2542 # Input:
2543 # - local_gnulib_dir  from --local-dir
2544 # - modcache        true or false, from --cache-modules/--no-cache-modules
2545 # - modules         list of modules, including dependencies
2546 # Output:
2547 # - modules         list of modules, including 'dummy' if needed
2548 func_modules_add_dummy ()
2549 {
2550   # Determine whether any module provides a lib_SOURCES augmentation.
2551   have_lib_SOURCES=
2552   sed_remove_backslash_newline=':a
2553 /\\$/{
2554 s/\\$//
2555 N
2556 s/\n//
2557 ba
2558 }'
2559   for module in $modules; do
2560     func_verify_nontests_module
2561     if test -n "$module"; then
2562       # Extract the value of "lib_SOURCES += ...".
2563       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
2564         # Ignore .h files since they are not compiled.
2565         case "$file" in
2566           *.h) ;;
2567           *)
2568             have_lib_SOURCES=yes
2569             break 2
2570             ;;
2571         esac
2572       done
2573     fi
2574   done
2575   # Add the dummy module, to make sure the library will be non-empty.
2576   if test -z "$have_lib_SOURCES"; then
2577     if func_acceptable "dummy"; then
2578       func_append modules " dummy"
2579     fi
2580   fi
2581 }
2582
2583 # func_modules_notice
2584 # Input:
2585 # - local_gnulib_dir  from --local-dir
2586 # - modcache        true or false, from --cache-modules/--no-cache-modules
2587 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2588 # - modules         list of modules, including dependencies
2589 func_modules_notice ()
2590 {
2591   if test $verbose -ge -1; then
2592     for module in $modules; do
2593       func_verify_module
2594       if test -n "$module"; then
2595         msg=`func_get_notice $module`
2596         if test -n "$msg"; then
2597           echo "Notice from module $module:"
2598           echo "$msg" | sed -e 's/^/  /'
2599         fi
2600       fi
2601     done
2602   fi
2603 }
2604
2605 # func_modules_to_filelist
2606 # Input:
2607 # - local_gnulib_dir  from --local-dir
2608 # - modcache        true or false, from --cache-modules/--no-cache-modules
2609 # - modules         list of modules, including dependencies
2610 # Output:
2611 # - files           list of files
2612 func_modules_to_filelist ()
2613 {
2614   files=
2615   for module in $modules; do
2616     func_verify_module
2617     if test -n "$module"; then
2618       fs=`func_get_filelist $module`
2619       func_append files " $fs"
2620     fi
2621   done
2622   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
2623 }
2624
2625 # func_execute_command command [args...]
2626 # Executes a command.
2627 # Uses also the variables
2628 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2629 func_execute_command ()
2630 {
2631   if test $verbose -ge 0; then
2632     echo "executing $*"
2633     "$@"
2634   else
2635     # Commands like automake produce output to stderr even when they succeed.
2636     # Turn this output off if the command succeeds.
2637     "$@" > "$tmp"/cmdout 2>&1
2638     cmdret=$?
2639     if test $cmdret = 0; then
2640       rm -f "$tmp"/cmdout
2641     else
2642       echo "executing $*"
2643       cat "$tmp"/cmdout 1>&2
2644       rm -f "$tmp"/cmdout
2645       (exit $cmdret)
2646     fi
2647   fi
2648 }
2649
2650 # func_dest_tmpfilename file
2651 # determines the name of a temporary file (file is relative to destdir).
2652 # Input:
2653 # - destdir         target directory
2654 # - doit            : if actions shall be executed, false if only to be printed
2655 # - tmp             pathname of a temporary directory
2656 # Sets variable:
2657 #   - tmpfile       absolute filename of the temporary file
2658 func_dest_tmpfilename ()
2659 {
2660   if $doit; then
2661     # Put the new contents of $file in a file in the same directory (needed
2662     # to guarantee that an 'mv' to "$destdir/$file" works).
2663     tmpfile="$destdir/$1.tmp"
2664   else
2665     # Put the new contents of $file in a file in a temporary directory
2666     # (because the directory of "$file" might not exist).
2667     tmpfile="$tmp"/`basename "$1"`.tmp
2668   fi
2669 }
2670
2671 # func_add_file
2672 # copies a file from gnulib into the destination directory. The destination
2673 # is known to not exist.
2674 # Input:
2675 # - destdir         target directory
2676 # - local_gnulib_dir  from --local-dir
2677 # - modcache        true or false, from --cache-modules/--no-cache-modules
2678 # - f               the original file name
2679 # - lookedup_file   name of the merged (combined) file
2680 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
2681 # - g               the rewritten file name
2682 # - tmpfile         absolute filename of the temporary file
2683 # - doit            : if actions shall be executed, false if only to be printed
2684 # - symbolic        true if files should be symlinked, copied otherwise
2685 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
2686 #                   copied otherwise
2687 func_add_file ()
2688 {
2689   if $doit; then
2690     echo "Copying file $g"
2691     if { test -n "$symbolic" \
2692          || { test -n "$lsymbolic" \
2693               && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2694        && test -z "$lookedup_tmp" \
2695        && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2696       func_ln_if_changed "$lookedup_file" "$destdir/$g"
2697     else
2698       mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2699     fi
2700   else
2701     echo "Copy file $g"
2702   fi
2703 }
2704
2705 # func_update_file
2706 # copies a file from gnulib into the destination directory. The destination
2707 # is known to exist.
2708 # Input:
2709 # - destdir         target directory
2710 # - local_gnulib_dir  from --local-dir
2711 # - modcache        true or false, from --cache-modules/--no-cache-modules
2712 # - f               the original file name
2713 # - lookedup_file   name of the merged (combined) file
2714 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
2715 # - g               the rewritten file name
2716 # - tmpfile         absolute filename of the temporary file
2717 # - doit            : if actions shall be executed, false if only to be printed
2718 # - symbolic        true if files should be symlinked, copied otherwise
2719 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
2720 #                   copied otherwise
2721 # - already_present  nonempty if the file should already exist, empty otherwise
2722 func_update_file ()
2723 {
2724   if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2725     : # The file has not changed.
2726   else
2727     # Replace the file.
2728     if $doit; then
2729       if test -n "$already_present"; then
2730         echo "Updating file $g (backup in ${g}~)"
2731       else
2732         echo "Replacing file $g (non-gnulib code backed up in ${g}~) !!"
2733       fi
2734       mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2735       if { test -n "$symbolic" \
2736            || { test -n "$lsymbolic" \
2737                 && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2738          && test -z "$lookedup_tmp" \
2739          && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2740         func_ln_if_changed "$lookedup_file" "$destdir/$g"
2741       else
2742         mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2743       fi
2744     else
2745       if test -n "$already_present"; then
2746         echo "Update file $g (backup in ${g}~)"
2747       else
2748         echo "Replace file $g (non-gnulib code backed up in ${g}~) !!"
2749       fi
2750     fi
2751   fi
2752 }
2753
2754 # func_emit_lib_Makefile_am
2755 # emits the contents of library makefile to standard output.
2756 # Input:
2757 # - local_gnulib_dir  from --local-dir
2758 # - modcache        true or false, from --cache-modules/--no-cache-modules
2759 # - modules         list of modules, including dependencies
2760 # - libname         library name
2761 # - pobase          directory relative to destdir where to place *.po files
2762 # - auxdir          directory relative to destdir where to place build aux files
2763 # - makefile_name   from --makefile-name
2764 # - libtool         true if libtool will be used, false or blank otherwise
2765 # - macro_prefix    prefix of gl_LIBOBJS macros to use
2766 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
2767 # - actioncmd       (optional) command that will reproduce this invocation
2768 # - for_test        true if creating a package for testing, false otherwise
2769 # - destfile        filename relative to destdir of makefile being generated
2770 # Input/Output:
2771 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
2772 #                   list of edits to be done to Makefile.am variables
2773 # Output:
2774 # - uses_subdirs    nonempty if object files in subdirs exist
2775 func_emit_lib_Makefile_am ()
2776 {
2777   # When creating an includable Makefile.am snippet, augment variables with
2778   # += instead of assigning them.
2779   if test -n "$makefile_name"; then
2780     assign='+='
2781   else
2782     assign='='
2783   fi
2784   if test "$libtool" = true; then
2785     libext=la
2786     perhapsLT=LT
2787     sed_eliminate_LDFLAGS="$sed_noop"
2788   else
2789     libext=a
2790     perhapsLT=
2791     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
2792   fi
2793   if $for_test; then
2794     # When creating a package for testing: Attempt to provoke failures,
2795     # especially link errors, already during "make" rather than during
2796     # "make check", because "make check" is not possible in a cross-compiling
2797     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
2798     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
2799   else
2800     sed_transform_check_PROGRAMS="$sed_noop"
2801   fi
2802   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
2803   echo "## Process this file with automake to produce Makefile.in."
2804   func_emit_copyright_notice
2805   if test -n "$actioncmd"; then
2806     # The maximum line length (excluding the terminating newline) of any file
2807     # that is to be preprocessed by config.status is 3070.  config.status uses
2808     # awk, and the HP-UX 11.00 awk fails if a line has length >= 3071;
2809     # similarly, the IRIX 6.5 awk fails if a line has length >= 3072.
2810     len=`echo "$actioncmd" | wc -c`
2811     if test -n "$len" && test "$len" -le 3000; then
2812       echo "# Reproduce by: $actioncmd"
2813     fi
2814   fi
2815   echo
2816   uses_subdirs=
2817   {
2818     if test false = "$libtool"; then
2819       sed_transform_libgnu_a="s, libgnu\\.a, $libname.a,g"
2820     else
2821       sed_transform_libgnu_a="s, libgnu\\.a, $libname.la,g"
2822     fi
2823     for module in $modules; do
2824       func_verify_nontests_module
2825       if test -n "$module"; then
2826         {
2827           func_get_automake_snippet "$module" |
2828             LC_ALL=C \
2829             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
2830                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
2831                 -e "$sed_eliminate_LDFLAGS" \
2832                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
2833                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
2834                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
2835                 -e "$sed_transform_libgnu_a" \
2836                 -e "$sed_transform_check_PROGRAMS"
2837           if test "$module" = 'alloca'; then
2838             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
2839             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
2840           fi
2841         } > "$tmp"/amsnippet
2842         # Skip the contents if it's entirely empty.
2843         if grep '[^      ]' "$tmp"/amsnippet > /dev/null ; then
2844           echo "## begin gnulib module $module"
2845           echo
2846           cat "$tmp"/amsnippet
2847           echo "## end   gnulib module $module"
2848           echo
2849         fi
2850         rm -f "$tmp"/amsnippet
2851         # Test whether there are some source files in subdirectories.
2852         for f in `func_get_filelist "$module"`; do
2853           case $f in
2854             lib/*/*.c)
2855               uses_subdirs=yes
2856               break
2857               ;;
2858           esac
2859         done
2860       fi
2861     done
2862   } > "$tmp"/allsnippets
2863   if test -z "$makefile_name"; then
2864     # If there are source files in subdirectories, prevent collision of the
2865     # object files (example: hash.c and libxml/hash.c).
2866     subdir_options=
2867     if test -n "$uses_subdirs"; then
2868       subdir_options=' subdir-objects'
2869     fi
2870     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
2871   fi
2872   echo
2873   if test -z "$makefile_name"; then
2874     echo "SUBDIRS ="
2875     echo "nodist_pkginclude_HEADERS ="
2876     echo "nobase_nodist_pkginclude_HEADERS ="
2877     echo "noinst_HEADERS ="
2878     echo "noinst_LIBRARIES ="
2879     echo "noinst_LTLIBRARIES ="
2880     # Automake versions < 1.9b create an empty pkgdatadir at installation time
2881     # if you specify pkgdata_DATA to empty. This is a workaround.
2882     if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
2883       echo "pkgdata_DATA ="
2884     fi
2885     echo "EXTRA_DIST ="
2886     echo "EXTRA_HEADERS ="
2887     echo "BUILT_SOURCES ="
2888     echo "SUFFIXES ="
2889   fi
2890   echo "MOSTLYCLEANFILES $assign core *.stackdump"
2891   if test -z "$makefile_name"; then
2892     echo "MOSTLYCLEANDIRS ="
2893     echo "CLEANFILES ="
2894     echo "DISTCLEANFILES ="
2895     echo "MAINTAINERCLEANFILES ="
2896   fi
2897   # Execute edits that apply to the Makefile.am being generated.
2898   edit=0
2899   while test $edit != $makefile_am_edits; do
2900     edit=`expr $edit + 1`
2901     eval dir=\"\$makefile_am_edit${edit}_dir\"
2902     eval var=\"\$makefile_am_edit${edit}_var\"
2903     eval val=\"\$makefile_am_edit${edit}_val\"
2904     if test -n "$var"; then
2905       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
2906         echo "${var} += ${val}"
2907         eval "makefile_am_edit${edit}_var="
2908       fi
2909     fi
2910   done
2911   if test -z "$makefile_name"; then
2912     echo
2913     if $for_test; then
2914       echo "AM_CPPFLAGS = -DGNULIB_STRICT_CHECKING=1"
2915     else
2916       echo "AM_CPPFLAGS ="
2917     fi
2918     echo "AM_CFLAGS ="
2919   fi
2920   echo
2921   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
2922      || { test -n "$makefile_name" \
2923           && test -f "$sourcebase/Makefile.am" \
2924           && LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$sourcebase/Makefile.am" > /dev/null; \
2925         }; then
2926     # Install associated header files, per module Makefile.am snippets.
2927     sed_transform_HEADERS_primaries="$sed_noop"
2928     # One of the snippets or the user's Makefile.am already specifies an
2929     # installation location for the library. Don't confuse automake by saying
2930     # it should not be installed.
2931     :
2932   else
2933     # Don't install header files when generated library is not installed.
2934     sed_transform_HEADERS_primaries="\
2935         /^\(nobase_\)\{0,1\}nodist_pkginclude_HEADERS *=.*$/d
2936         /^EXTRA_HEADERS *=.*$/d
2937     "
2938     # By default, the generated library should not be installed.
2939     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
2940   fi
2941   echo
2942   echo "${libname}_${libext}_SOURCES ="
2943   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
2944   # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
2945   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
2946   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
2947   echo "EXTRA_${libname}_${libext}_SOURCES ="
2948   if test "$libtool" = true; then
2949     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
2950     echo "${libname}_${libext}_LDFLAGS += -no-undefined"
2951     # Synthesize an ${libname}_${libext}_LDFLAGS augmentation by combining
2952     # the link dependencies of all modules.
2953     for module in $modules; do
2954       func_verify_nontests_module
2955       if test -n "$module"; then
2956         func_get_link_directive "$module"
2957       fi
2958     done \
2959       | LC_ALL=C sed -e '/^$/d' -e 's/ when linking with libtool.*//' \
2960       | LC_ALL=C sort -u \
2961       | LC_ALL=C sed -e 's/^/'"${libname}_${libext}"'_LDFLAGS += /'
2962   fi
2963   echo
2964   if test -n "$pobase"; then
2965     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
2966     echo
2967   fi
2968   cat "$tmp"/allsnippets \
2969     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g' \
2970           -e "$sed_transform_HEADERS_primaries"
2971   echo
2972   echo "mostlyclean-local: mostlyclean-generic"
2973   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
2974   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
2975   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
2976   echo "          fi; \\"
2977   echo "        done; \\"
2978   echo "        :"
2979   rm -f "$tmp"/allsnippets
2980 }
2981
2982 # func_emit_po_Makevars
2983 # emits the contents of po/ makefile parameterization to standard output.
2984 # Input:
2985 # - local_gnulib_dir  from --local-dir
2986 # - modcache        true or false, from --cache-modules/--no-cache-modules
2987 # - sourcebase      directory relative to destdir where to place source code
2988 # - pobase          directory relative to destdir where to place *.po files
2989 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
2990 func_emit_po_Makevars ()
2991 {
2992   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
2993   func_emit_copyright_notice
2994   echo
2995   echo "# Usually the message domain is the same as the package name."
2996   echo "# But here it has a '-gnulib' suffix."
2997   echo "DOMAIN = ${po_domain}-gnulib"
2998   echo
2999   echo "# These two variables depend on the location of this directory."
3000   echo "subdir = ${pobase}"
3001   echo "top_builddir = "`echo "$pobase" | sed -e 's,//*,/,g' -e 's,[^/][^/]*,..,g'`
3002   echo
3003   cat <<\EOF
3004 # These options get passed to xgettext.
3005 XGETTEXT_OPTIONS = \
3006   --keyword=_ --flag=_:1:pass-c-format \
3007   --keyword=N_ --flag=N_:1:pass-c-format \
3008   --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \
3009   --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \
3010   --flag=error:3:c-format --flag=error_at_line:5:c-format
3011
3012 # This is the copyright holder that gets inserted into the header of the
3013 # $(DOMAIN).pot file.  gnulib is copyrighted by the FSF.
3014 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
3015
3016 # This is the email address or URL to which the translators shall report
3017 # bugs in the untranslated strings:
3018 # - Strings which are not entire sentences, see the maintainer guidelines
3019 #   in the GNU gettext documentation, section 'Preparing Strings'.
3020 # - Strings which use unclear terms or require additional context to be
3021 #   understood.
3022 # - Strings which make invalid assumptions about notation of date, time or
3023 #   money.
3024 # - Pluralisation problems.
3025 # - Incorrect English spelling.
3026 # - Incorrect formatting.
3027 # It can be your email address, or a mailing list address where translators
3028 # can write to without being subscribed, or the URL of a web page through
3029 # which the translators can contact you.
3030 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
3031
3032 # This is the list of locale categories, beyond LC_MESSAGES, for which the
3033 # message catalogs shall be used.  It is usually empty.
3034 EXTRA_LOCALE_CATEGORIES =
3035
3036 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
3037 # context.  Possible values are "yes" and "no".  Set this to yes if the
3038 # package uses functions taking also a message context, like pgettext(), or
3039 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
3040 USE_MSGCTXT = no
3041 EOF
3042 }
3043
3044 # func_emit_po_POTFILES_in
3045 # emits the file list to be passed to xgettext to standard output.
3046 # Input:
3047 # - local_gnulib_dir  from --local-dir
3048 # - modcache        true or false, from --cache-modules/--no-cache-modules
3049 # - sourcebase      directory relative to destdir where to place source code
3050 # - files           list of new files
3051 func_emit_po_POTFILES_in ()
3052 {
3053   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3054   func_emit_copyright_notice
3055   echo
3056   echo "# List of files which contain translatable strings."
3057   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
3058 }
3059
3060 # func_emit_tests_Makefile_am witness_macro
3061 # emits the contents of tests makefile to standard output.
3062 # Input:
3063 # - local_gnulib_dir  from --local-dir
3064 # - modcache        true or false, from --cache-modules/--no-cache-modules
3065 # - modules         list of modules, including dependencies
3066 # - libname         library name
3067 # - auxdir          directory relative to destdir where to place build aux files
3068 # - makefile_name   from --makefile-name
3069 # - libtool         true if libtool will be used, false or blank otherwise
3070 # - sourcebase      relative directory containing lib source code
3071 # - m4base          relative directory containing autoconf macros
3072 # - testsbase       relative directory containing unit test code
3073 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3074 # - for_test        true if creating a package for testing, false otherwise
3075 # - use_libtests    true if a libtests.a should be built, false otherwise
3076 # - destfile        filename relative to destdir of makefile being generated
3077 # Input/Output:
3078 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
3079 #                   list of edits to be done to Makefile.am variables
3080 # Output:
3081 # - uses_subdirs    nonempty if object files in subdirs exist
3082 func_emit_tests_Makefile_am ()
3083 {
3084   witness_macro="$1"
3085   if test "$libtool" = true; then
3086     libext=la
3087     sed_eliminate_LDFLAGS="$sed_noop"
3088   else
3089     libext=a
3090     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
3091   fi
3092   if $for_test; then
3093     # When creating a package for testing: Attempt to provoke failures,
3094     # especially link errors, already during "make" rather than during
3095     # "make check", because "make check" is not possible in a cross-compiling
3096     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
3097     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
3098   else
3099     sed_transform_check_PROGRAMS="$sed_noop"
3100   fi
3101   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
3102   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3103   echo "## Process this file with automake to produce Makefile.in."
3104   func_emit_copyright_notice
3105   echo
3106   uses_subdirs=
3107   {
3108     for module in $modules; do
3109       if $for_test; then
3110         func_verify_tests_module
3111       else
3112         func_verify_module
3113       fi
3114       if test -n "$module"; then
3115         {
3116           func_get_automake_snippet "$module" |
3117             LC_ALL=C \
3118             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
3119                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
3120                 -e "$sed_eliminate_LDFLAGS" \
3121                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
3122                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
3123                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
3124                 -e "$sed_transform_check_PROGRAMS"
3125           if $use_libtests && test "$module" = 'alloca'; then
3126             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
3127             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
3128           fi
3129         } > "$tmp"/amsnippet
3130         # Skip the contents if it's entirely empty.
3131         if grep '[^      ]' "$tmp"/amsnippet > /dev/null ; then
3132           # Mention long-running tests at the end.
3133           ofd=3
3134           for word in `func_get_status "$module"`; do
3135             if test "$word" = 'longrunning-test'; then
3136               ofd=4
3137               break
3138             fi
3139           done
3140           { echo "## begin gnulib module $module"
3141             echo
3142             cat "$tmp"/amsnippet
3143             echo "## end   gnulib module $module"
3144             echo
3145           } >&$ofd
3146         fi
3147         rm -f "$tmp"/amsnippet
3148         # Test whether there are some source files in subdirectories.
3149         for f in `func_get_filelist "$module"`; do
3150           case $f in
3151             lib/*/*.c | tests/*/*.c)
3152               uses_subdirs=yes
3153               break
3154               ;;
3155           esac
3156         done
3157       fi
3158     done
3159   } 3> "$tmp"/main_snippets 4> "$tmp"/longrunning_snippets
3160   # Generate dependencies here, since it eases the debugging of test failures.
3161   # If there are source files in subdirectories, prevent collision of the
3162   # object files (example: hash.c and libxml/hash.c).
3163   subdir_options=
3164   if test -n "$uses_subdirs"; then
3165     subdir_options=' subdir-objects'
3166   fi
3167   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
3168   echo
3169   if $for_test; then
3170     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
3171     echo
3172   fi
3173   # Nothing is being added to SUBDIRS; nevertheless the existence of this
3174   # variable is needed to avoid an error from automake:
3175   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
3176   echo "SUBDIRS = ."
3177   echo "TESTS ="
3178   echo "XFAIL_TESTS ="
3179   echo "TESTS_ENVIRONMENT ="
3180   echo "noinst_PROGRAMS ="
3181   if ! $for_test; then
3182     echo "check_PROGRAMS ="
3183   fi
3184   echo "nodist_pkginclude_HEADERS ="
3185   echo "nobase_nodist_pkginclude_HEADERS ="
3186   echo "noinst_HEADERS ="
3187   echo "noinst_LIBRARIES ="
3188   if $use_libtests; then
3189     if $for_test; then
3190       echo "noinst_LIBRARIES += libtests.a"
3191     else
3192       echo "check_LIBRARIES = libtests.a"
3193     fi
3194   fi
3195   # Automake versions < 1.9b create an empty pkgdatadir at installation time
3196   # if you specify pkgdata_DATA to empty. This is a workaround.
3197   if grep '^pkgdata_DATA *+=' "$tmp"/main_snippets "$tmp"/longrunning_snippets > /dev/null; then
3198     echo "pkgdata_DATA ="
3199   fi
3200   echo "EXTRA_DIST ="
3201   echo "EXTRA_HEADERS ="
3202   echo "BUILT_SOURCES ="
3203   echo "SUFFIXES ="
3204   echo "MOSTLYCLEANFILES = core *.stackdump"
3205   echo "MOSTLYCLEANDIRS ="
3206   echo "CLEANFILES ="
3207   echo "DISTCLEANFILES ="
3208   echo "MAINTAINERCLEANFILES ="
3209   # Execute edits that apply to the Makefile.am being generated.
3210   edit=0
3211   while test $edit != $makefile_am_edits; do
3212     edit=`expr $edit + 1`
3213     eval dir=\"\$makefile_am_edit${edit}_dir\"
3214     eval var=\"\$makefile_am_edit${edit}_var\"
3215     eval val=\"\$makefile_am_edit${edit}_val\"
3216     if test -n "$var"; then
3217       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
3218         echo "${var} += ${val}"
3219         eval "makefile_am_edit${edit}_var="
3220       fi
3221     fi
3222   done
3223   echo
3224   echo "AM_CPPFLAGS = \\"
3225   if $for_test; then
3226     echo "  -DGNULIB_STRICT_CHECKING=1 \\"
3227   fi
3228   if test -n "${witness_macro}"; then
3229     echo "  -D@${witness_macro}@=1 \\"
3230   fi
3231   echo "  -I. -I\$(srcdir) \\"
3232   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
3233   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
3234   echo
3235   local_ldadd_before=''
3236   local_ldadd_after=''
3237   if $use_libtests; then
3238     # All test programs need to be linked with libtests.a.
3239     # It needs to be passed to the linker before ${libname}.${libext}, since
3240     # the tests-related modules depend on the main modules.
3241     # It also needs to be passed to the linker after ${libname}.${libext}
3242     # because the latter might contain incomplete modules (such as the 'error'
3243     # module whose dependency to 'progname' is voluntarily omitted).
3244     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
3245     # not matter.
3246     local_ldadd_before=' libtests.a'
3247     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
3248   fi
3249   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
3250   echo
3251   if $use_libtests; then
3252     echo "libtests_a_SOURCES ="
3253     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
3254     # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
3255     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
3256     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
3257     echo "EXTRA_libtests_a_SOURCES ="
3258     # The circular dependency in LDADD requires this.
3259     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
3260     echo
3261   fi
3262   # Many test scripts use ${EXEEXT} or ${srcdir}.
3263   # EXEEXT is defined by AC_PROG_CC through autoconf.
3264   # srcdir is defined by autoconf and automake.
3265   echo "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='\$(srcdir)'"
3266   echo
3267   cat "$tmp"/main_snippets "$tmp"/longrunning_snippets \
3268     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
3269   echo "# Clean up after Solaris cc."
3270   echo "clean-local:"
3271   echo "        rm -rf SunWS_cache"
3272   echo
3273   echo "mostlyclean-local: mostlyclean-generic"
3274   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
3275   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
3276   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
3277   echo "          fi; \\"
3278   echo "        done; \\"
3279   echo "        :"
3280   rm -f "$tmp"/main_snippets "$tmp"/longrunning_snippets
3281 }
3282
3283 # func_emit_initmacro_start macro_prefix
3284 # emits the first 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_start ()
3287 {
3288   macro_prefix_arg="$1"
3289   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
3290   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
3291   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
3292   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
3293   # flexibility.)
3294   # Furthermore it avoids an automake error like this when a Makefile.am
3295   # that uses pieces of gnulib also uses $(LIBOBJ):
3296   #   automatically discovered file `error.c' should not be explicitly mentioned
3297   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
3298   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
3299   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
3300   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
3301   #   automatically discovered file `error.c' should not be explicitly mentioned
3302   # We let automake know about the files to be distributed through the
3303   # EXTRA_lib_SOURCES variable.
3304   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
3305   # Create data variables for checking the presence of files that are mentioned
3306   # as AC_LIBSOURCES arguments. These are m4 variables, not shell variables,
3307   # because we want the check to happen when the configure file is created,
3308   # not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the list of
3309   # files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the subdirectory
3310   # in which to expect them.
3311   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_LIST], [])"
3312   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_DIR], [])"
3313   echo "  gl_COMMON"
3314 }
3315
3316 # func_emit_initmacro_end macro_prefix
3317 # emits the last few statements of the gl_INIT macro to standard output.
3318 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3319 func_emit_initmacro_end ()
3320 {
3321   macro_prefix_arg="$1"
3322   # Check the presence of files that are mentioned as AC_LIBSOURCES arguments.
3323   # The check is performed only when autoconf is run from the directory where
3324   # the configure.ac resides; if it is run from a different directory, the
3325   # check is skipped.
3326   echo "  m4_ifval(${macro_prefix_arg}_LIBSOURCES_LIST, ["
3327   echo "    m4_syscmd([test ! -d ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
3328   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
3329   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
3330   echo "          echo \"missing file ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file\" >&2"
3331   echo "          exit 1"
3332   echo "        fi"
3333   echo "      done])dnl"
3334   echo "      m4_if(m4_sysval, [0], [],"
3335   echo "        [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])"
3336   echo "  ])"
3337   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_DIR])"
3338   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_LIST])"
3339   echo "  m4_popdef([AC_LIBSOURCES])"
3340   echo "  m4_popdef([AC_REPLACE_FUNCS])"
3341   echo "  m4_popdef([AC_LIBOBJ])"
3342   echo "  AC_CONFIG_COMMANDS_PRE(["
3343   echo "    ${macro_prefix_arg}_libobjs="
3344   echo "    ${macro_prefix_arg}_ltlibobjs="
3345   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
3346   echo "      # Remove the extension."
3347   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
3348   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed -e \"\$sed_drop_objext\" | sort | uniq\`; do"
3349   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
3350   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
3351   echo "      done"
3352   echo "    fi"
3353   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
3354   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
3355   echo "  ])"
3356 }
3357
3358 # func_emit_initmacro_done macro_prefix sourcebase
3359 # emits a few statements after the gl_INIT macro to standard output.
3360 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3361 # - sourcebase      directory relative to destdir where to place source code
3362 func_emit_initmacro_done ()
3363 {
3364   macro_prefix_arg="$1"
3365   sourcebase_arg="$2"
3366   echo
3367   echo "# Like AC_LIBOBJ, except that the module name goes"
3368   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3369   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
3370   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
3371   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
3372   echo "])"
3373   echo
3374   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
3375   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3376   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
3377   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
3378   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
3379   echo "])"
3380   echo
3381   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
3382   echo "# expected is derived from the gnulib-tool parameterization,"
3383   echo "# and alloca is special cased (for the alloca-opt module)."
3384   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
3385   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
3386   echo "  m4_foreach([_gl_NAME], [\$1], ["
3387   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
3388   echo "      m4_define([${macro_prefix_arg}_LIBSOURCES_DIR], [$sourcebase_arg])"
3389   echo "      m4_append([${macro_prefix_arg}_LIBSOURCES_LIST], _gl_NAME, [ ])"
3390   echo "    ])"
3391   echo "  ])"
3392   echo "])"
3393 }
3394
3395 # func_import modules
3396 # Uses also the variables
3397 # - mode            import or add-import or remove-import or update
3398 # - destdir         target directory
3399 # - local_gnulib_dir  from --local-dir
3400 # - modcache        true or false, from --cache-modules/--no-cache-modules
3401 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
3402 # - libname         library name
3403 # - supplied_libname  true if --lib was given, blank otherwise
3404 # - sourcebase      directory relative to destdir where to place source code
3405 # - m4base          directory relative to destdir where to place *.m4 macros
3406 # - pobase          directory relative to destdir where to place *.po files
3407 # - docbase         directory relative to destdir where to place doc files
3408 # - testsbase       directory relative to destdir where to place unit test code
3409 # - auxdir          directory relative to destdir where to place build aux files
3410 # - inctests        true if --with-tests was given, blank otherwise
3411 # - incobsolete     true if --with-obsolete was given, blank otherwise
3412 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
3413 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
3414 #                          otherwise
3415 # - inc_privileged_tests  true if --with-privileged-tests was given, blank
3416 #                         otherwise
3417 # - inc_unportable_tests  true if --with-unportable-tests was given, blank
3418 #                         otherwise
3419 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
3420 # - avoidlist       list of modules to avoid, from --avoid
3421 # - lgpl            yes or a number if library's license shall be LGPL,
3422 #                   blank otherwise
3423 # - makefile_name   from --makefile-name
3424 # - libtool         true if --libtool was given, false if --no-libtool was
3425 #                   given, blank otherwise
3426 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
3427 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3428 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3429 # - vc_files        true if --vc-files was given, false if --no-vc-files was
3430 #                   given, blank otherwise
3431 # - autoconf_minversion  minimum supported autoconf version
3432 # - doit            : if actions shall be executed, false if only to be printed
3433 # - symbolic        true if files should be symlinked, copied otherwise
3434 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
3435 #                   copied otherwise
3436 # - do_copyrights   true if copyright notices in files should be replaced,
3437 #                   blank otherwise
3438 func_import ()
3439 {
3440   # Get the cached settings.
3441   # In 'import' mode, we read them only for the purpose of knowing the old
3442   # installed file list, and don't use them as defaults.
3443   cached_local_gnulib_dir=
3444   cached_specified_modules=
3445   cached_incobsolete=
3446   cached_inc_cxx_tests=
3447   cached_inc_longrunning_tests=
3448   cached_inc_privileged_tests=
3449   cached_inc_unportable_tests=
3450   cached_inc_all_tests=
3451   cached_avoidlist=
3452   cached_sourcebase=
3453   cached_m4base=
3454   cached_pobase=
3455   cached_docbase=
3456   cached_testsbase=
3457   cached_inctests=
3458   cached_libname=
3459   cached_lgpl=
3460   cached_makefile_name=
3461   cached_libtool=
3462   cached_macro_prefix=
3463   cached_po_domain=
3464   cached_vc_files=
3465   cached_files=
3466   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
3467     cached_libtool=false
3468     my_sed_traces='
3469       s,#.*$,,
3470       s,^dnl .*$,,
3471       s, dnl .*$,,
3472       /gl_LOCAL_DIR(/ {
3473         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_dir="\1",p
3474       }
3475       /gl_MODULES(/ {
3476         ta
3477         :a
3478           s/)/)/
3479           tb
3480           N
3481           ba
3482         :b
3483         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
3484       }
3485       /gl_WITH_OBSOLETE/ {
3486         s,^.*$,cached_incobsolete=true,p
3487       }
3488       /gl_WITH_CXX_TESTS/ {
3489         s,^.*$,cached_inc_cxx_tests=true,p
3490       }
3491       /gl_WITH_LONGRUNNING_TESTS/ {
3492         s,^.*$,cached_inc_longrunning_tests=true,p
3493       }
3494       /gl_WITH_PRIVILEGED_TESTS/ {
3495         s,^.*$,cached_inc_privileged_tests=true,p
3496       }
3497       /gl_WITH_UNPORTABLE_TESTS/ {
3498         s,^.*$,cached_inc_unportable_tests=true,p
3499       }
3500       /gl_WITH_ALL_TESTS/ {
3501         s,^.*$,cached_inc_all_tests=true,p
3502       }
3503       /gl_AVOID(/ {
3504         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
3505       }
3506       /gl_SOURCE_BASE(/ {
3507         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
3508       }
3509       /gl_M4_BASE(/ {
3510         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
3511       }
3512       /gl_PO_BASE(/ {
3513         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
3514       }
3515       /gl_DOC_BASE(/ {
3516         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
3517       }
3518       /gl_TESTS_BASE(/ {
3519         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
3520       }
3521       /gl_WITH_TESTS/ {
3522         s,^.*$,cached_inctests=true,p
3523       }
3524       /gl_LIB(/ {
3525         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
3526       }
3527       /gl_LGPL(/ {
3528         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
3529       }
3530       /gl_LGPL/ {
3531         s,^.*$,cached_lgpl=yes,p
3532       }
3533       /gl_MAKEFILE_NAME(/ {
3534         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
3535       }
3536       /gl_LIBTOOL/ {
3537         s,^.*$,cached_libtool=true,p
3538       }
3539       /gl_MACRO_PREFIX(/ {
3540         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
3541       }
3542       /gl_PO_DOMAIN(/ {
3543         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
3544       }
3545       /gl_VC_FILES(/ {
3546         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
3547       }'
3548     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
3549     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3550       my_sed_traces='
3551         s,#.*$,,
3552         s,^dnl .*$,,
3553         s, dnl .*$,,
3554         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
3555           s,^.*$,cached_files=",p
3556           n
3557           ta
3558           :a
3559           s,^\]).*$,",
3560           tb
3561           s,["$`\\],,g
3562           p
3563           n
3564           ba
3565           :b
3566           p
3567         }'
3568       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
3569     fi
3570   fi
3571
3572   if test "$mode" = import; then
3573     # In 'import' mode, the new set of specified modules overrides the cached
3574     # set of modules. Ignore the cached settings.
3575     specified_modules="$1"
3576   else
3577     # Merge the cached settings with the specified ones.
3578     # The m4base must be the same as expected from the pathname.
3579     if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
3580       func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
3581     fi
3582     # The local_gnulib_dir defaults to the cached one. Recall that the cached one
3583     # is relative to $destdir, whereas the one we use is relative to . or absolute.
3584     if test -z "$local_gnulib_dir"; then
3585       if test -n "$cached_local_gnulib_dir"; then
3586         case "$destdir" in
3587           /*)
3588             local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
3589           *)
3590             case "$cached_local_gnulib_dir" in
3591               /*)
3592                 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
3593               *)
3594                 func_relconcat "$destdir" "$cached_local_gnulib_dir"
3595                 local_gnulib_dir="$relconcat" ;;
3596             esac ;;
3597         esac
3598       fi
3599     fi
3600     case $mode in
3601       add-import)
3602         # Append the cached and the specified module names. So that
3603         # "gnulib-tool --add-import foo" means to add the module foo.
3604         specified_modules="$cached_specified_modules $1"
3605         ;;
3606       remove-import)
3607         # Take the cached module names, minus the specified module names.
3608         specified_modules=
3609         if $have_associative; then
3610           # Use an associative array, for O(N) worst-case run time.
3611           declare -A to_remove
3612           for m in $1; do
3613             eval 'to_remove[$m]=yes'
3614           done
3615           for module in $cached_specified_modules; do
3616             if eval 'test -z "${to_remove[$module]}"'; then
3617               func_append specified_modules "$module "
3618             fi
3619           done
3620         else
3621           # This loop has O(N²) worst-case run time.
3622           for module in $cached_specified_modules; do
3623             to_remove=
3624             for m in $1; do
3625               if test "$m" = "$module"; then
3626                 to_remove=yes
3627                 break
3628               fi
3629             done
3630             if test -z "$to_remove"; then
3631               func_append specified_modules "$module "
3632             fi
3633           done
3634         fi
3635         ;;
3636       update)
3637         # Take the cached module names. There are no specified module names.
3638         specified_modules="$cached_specified_modules"
3639         ;;
3640     esac
3641     # Included obsolete modules among the dependencies if specified either way.
3642     if test -z "$incobsolete"; then
3643       incobsolete="$cached_incobsolete"
3644     fi
3645     # Included special kinds of tests modules among the dependencies if specified
3646     # either way.
3647     if test -z "$inc_cxx_tests"; then
3648       inc_cxx_tests="$cached_inc_cxx_tests"
3649     fi
3650     if test -z "$inc_longrunning_tests"; then
3651       inc_longrunning_tests="$cached_inc_longrunning_tests"
3652     fi
3653     if test -z "$inc_privileged_tests"; then
3654       inc_privileged_tests="$cached_inc_privileged_tests"
3655     fi
3656     if test -z "$inc_unportable_tests"; then
3657       inc_unportable_tests="$cached_inc_unportable_tests"
3658     fi
3659     if test -z "$inc_all_tests"; then
3660       inc_all_tests="$cached_inc_all_tests"
3661     fi
3662     # Append the cached and the specified avoidlist. This is probably better
3663     # than dropping the cached one when --avoid is specified at least once.
3664     avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
3665     avoidlist=`echo $avoidlist`
3666
3667     # The sourcebase defaults to the cached one.
3668     if test -z "$sourcebase"; then
3669       sourcebase="$cached_sourcebase"
3670       if test -z "$sourcebase"; then
3671         func_fatal_error "missing --source-base option"
3672       fi
3673     fi
3674     # The pobase defaults to the cached one.
3675     if test -z "$pobase"; then
3676       pobase="$cached_pobase"
3677     fi
3678     # The docbase defaults to the cached one.
3679     if test -z "$docbase"; then
3680       docbase="$cached_docbase"
3681       if test -z "$docbase"; then
3682         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."
3683       fi
3684     fi
3685     # The testsbase defaults to the cached one.
3686     if test -z "$testsbase"; then
3687       testsbase="$cached_testsbase"
3688       if test -z "$testsbase"; then
3689         func_fatal_error "missing --tests-base option"
3690       fi
3691     fi
3692     # Require the tests if specified either way.
3693     if test -z "$inctests"; then
3694       inctests="$cached_inctests"
3695     fi
3696     # The libname defaults to the cached one.
3697     if test -z "$supplied_libname"; then
3698       libname="$cached_libname"
3699       if test -z "$libname"; then
3700         func_fatal_error "missing --lib option"
3701       fi
3702     fi
3703     # Require LGPL if specified either way.
3704     if test -z "$lgpl"; then
3705       lgpl="$cached_lgpl"
3706     fi
3707     # The makefile_name defaults to the cached one.
3708     if test -z "$makefile_name"; then
3709       makefile_name="$cached_makefile_name"
3710     fi
3711     # Use libtool if specified either way, or if guessed.
3712     if test -z "$libtool"; then
3713       if test -n "$cached_m4base"; then
3714         libtool="$cached_libtool"
3715       else
3716         libtool="$guessed_libtool"
3717       fi
3718     fi
3719     # The macro_prefix defaults to the cached one.
3720     if test -z "$macro_prefix"; then
3721       macro_prefix="$cached_macro_prefix"
3722       if test -z "$macro_prefix"; then
3723         func_fatal_error "missing --macro-prefix option"
3724       fi
3725     fi
3726     # The po_domain defaults to the cached one.
3727     if test -z "$po_domain"; then
3728       po_domain="$cached_po_domain"
3729     fi
3730     # The vc_files defaults to the cached one.
3731     if test -z "$vc_files"; then
3732       vc_files="$cached_vc_files"
3733     fi
3734   fi
3735   # --without-*-tests options are not supported here.
3736   excl_cxx_tests=
3737   excl_longrunning_tests=
3738   excl_privileged_tests=
3739   excl_unportable_tests=
3740
3741   # Canonicalize the list of specified modules.
3742   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
3743
3744   # Include all kinds of tests modules if --with-all-tests was specified.
3745   inc_all_direct_tests="$inc_all_tests"
3746   inc_all_indirect_tests="$inc_all_tests"
3747
3748   # Determine final module list.
3749   modules="$specified_modules"
3750   func_modules_transitive_closure
3751   if test $verbose -ge 0; then
3752     func_show_module_list
3753   fi
3754   final_modules="$modules"
3755
3756   # Determine main module list and tests-related module list separately.
3757   # The main module list is the transitive closure of the specified modules,
3758   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
3759   # is specified, it will consist only of LGPLed source.
3760   # The tests-related module list is the transitive closure of the specified
3761   # modules, including tests modules, minus the main module list excluding
3762   # modules of applicability 'all'. Its lib/* sources (brought in through
3763   # dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
3764   # source, even if --lgpl is specified.
3765   # Determine main module list.
3766   saved_inctests="$inctests"
3767   inctests=""
3768   modules="$specified_modules"
3769   func_modules_transitive_closure
3770   main_modules="$modules"
3771   inctests="$saved_inctests"
3772   if test $verbose -ge 1; then
3773     echo "Main module list:"
3774     echo "$main_modules" | sed -e 's/^/  /'
3775   fi
3776   # Determine tests-related module list.
3777   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
3778   testsrelated_modules=`for module in $main_modules; do
3779                           if test \`func_get_applicability $module\` = main; then
3780                             echo $module
3781                           fi
3782                         done \
3783                         | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
3784   if test $verbose -ge 1; then
3785     echo "Tests-related module list:"
3786     echo "$testsrelated_modules" | sed -e 's/^/  /'
3787   fi
3788
3789   # Add the dummy module to the main module list if needed.
3790   modules="$main_modules"
3791   func_modules_add_dummy
3792   main_modules="$modules"
3793
3794   # Determine whether a $testsbase/libtests.a is needed.
3795   use_libtests=false
3796   for module in $testsrelated_modules; do
3797     func_verify_nontests_module
3798     if test -n "$module"; then
3799       all_files=`func_get_filelist $module`
3800       # Test whether some file in $all_files lies in lib/.
3801       for f in $all_files; do
3802         case $f in
3803           lib/*)
3804             use_libtests=true
3805             break 2
3806             ;;
3807         esac
3808       done
3809     fi
3810   done
3811
3812   # Add the dummy module to the tests-related module list if needed.
3813   if $use_libtests; then
3814     modules="$testsrelated_modules"
3815     func_modules_add_dummy
3816     testsrelated_modules="$modules"
3817   fi
3818
3819   # If --lgpl, verify that the licenses of modules are compatible.
3820   if test -n "$lgpl"; then
3821     license_incompatibilities=
3822     for module in $main_modules; do
3823       license=`func_get_license $module`
3824       case $license in
3825         'GPLed build tool') ;;
3826         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3827         *)
3828           case "$lgpl" in
3829             yes | 3)
3830               case $license in
3831                 LGPL | LGPLv2+ | LGPLv3+) ;;
3832                 *) func_append license_incompatibilities "$module $license$nl" ;;
3833               esac
3834               ;;
3835             2)
3836               case $license in
3837                 LGPLv2+) ;;
3838                 *) func_append license_incompatibilities "$module $license$nl" ;;
3839               esac
3840               ;;
3841             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
3842           esac
3843           ;;
3844       esac
3845     done
3846     if test -n "$license_incompatibilities"; then
3847       # Format the license incompatibilities as a table.
3848       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
3849 s,^\(.................................................[^ ]*\) *,                 \1 ,'
3850       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
3851       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
3852     fi
3853   fi
3854
3855   # Show banner notice of every module.
3856   modules="$main_modules"
3857   func_modules_notice
3858
3859   # Determine script to apply to imported library files.
3860   sed_transform_lib_file=
3861   for module in $main_modules; do
3862     if test $module = config-h; then
3863       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
3864       sed_transform_lib_file=$sed_transform_lib_file'
3865         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
3866       '
3867       break
3868     fi
3869   done
3870   test -n "${macro_prefix}" && sed_transform_lib_file=$sed_transform_lib_file"
3871     s/_GL_\(.*\)_H/_${macro_prefix}_GL_\1_H/g
3872   "
3873   sed_transform_main_lib_file="$sed_transform_lib_file"
3874   if test -n "$do_copyrights"; then
3875     if test -n "$lgpl"; then
3876       # Update license.
3877       case "$lgpl" in
3878         yes | 3)
3879           sed_transform_main_lib_file=$sed_transform_main_lib_file'
3880             s/GNU General/GNU Lesser General/g
3881           '
3882           ;;
3883         2)
3884           sed_transform_main_lib_file=$sed_transform_main_lib_file'
3885             s/GNU General/GNU Lesser General/g
3886             s/version [23]\([ ,]\)/version 2.1\1/g
3887           '
3888           ;;
3889         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
3890       esac
3891     else
3892       # Update license.
3893       sed_transform_main_lib_file=$sed_transform_main_lib_file'
3894         s/GNU Lesser General/GNU General/g
3895         s/GNU Library General/GNU General/g
3896         s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3897       '
3898     fi
3899   fi
3900
3901   # Determine script to apply to auxiliary files that go into $auxdir/.
3902   sed_transform_build_aux_file=
3903   if test -n "$do_copyrights"; then
3904     # Update license.
3905     sed_transform_build_aux_file=$sed_transform_build_aux_file'
3906       s/GNU Lesser General/GNU General/g
3907       s/GNU Library General/GNU General/g
3908       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3909     '
3910   fi
3911   test -n "${macro_prefix}" \
3912     && sed_transform_build_aux_file=$sed_transform_build_aux_file"
3913          s/_GL_\(.*\)_H/_${macro_prefix}_GL_\1_H/g
3914        "
3915
3916   # Determine script to apply to library files that go into $testsbase/.
3917   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
3918   if test -n "$do_copyrights"; then
3919     # Update license.
3920     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
3921       s/GNU Lesser General/GNU General/g
3922       s/GNU Library General/GNU General/g
3923       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3924     '
3925   fi
3926
3927   # Determine the final file lists.
3928   # They must be computed separately, because files in lib/* go into
3929   # $sourcebase/ if they are in the main file list but into $testsbase/
3930   # if they are in the tests-related file list. Furthermore lib/dummy.c
3931   # can be in both.
3932   # Determine final main file list.
3933   modules="$main_modules"
3934   func_modules_to_filelist
3935   main_files="$files"
3936   # Determine final tests-related file list.
3937   modules="$testsrelated_modules"
3938   func_modules_to_filelist
3939   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
3940   # Merge both file lists.
3941   sed_remove_empty_lines='/^$/d'
3942   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
3943   if test $verbose -ge 0; then
3944     echo "File list:"
3945     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
3946     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
3947   fi
3948
3949   test -n "$files" \
3950     || func_fatal_error "refusing to do nothing"
3951
3952   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
3953   new_files="$files m4/gnulib-tool.m4"
3954   old_files="$cached_files"
3955   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
3956     func_append old_files " m4/gnulib-tool.m4"
3957   fi
3958
3959   rewritten='%REWRITTEN%'
3960   sed_rewrite_old_files="\
3961     s,^build-aux/,$rewritten$auxdir/,
3962     s,^doc/,$rewritten$cached_docbase/,
3963     s,^lib/,$rewritten$cached_sourcebase/,
3964     s,^m4/,$rewritten$cached_m4base/,
3965     s,^tests/,$rewritten$cached_testsbase/,
3966     s,^tests=lib/,$rewritten$cached_testsbase/,
3967     s,^top/,$rewritten,
3968     s,^$rewritten,,"
3969   sed_rewrite_new_files="\
3970     s,^build-aux/,$rewritten$auxdir/,
3971     s,^doc/,$rewritten$docbase/,
3972     s,^lib/,$rewritten$sourcebase/,
3973     s,^m4/,$rewritten$m4base/,
3974     s,^tests/,$rewritten$testsbase/,
3975     s,^tests=lib/,$rewritten$testsbase/,
3976     s,^top/,$rewritten,
3977     s,^$rewritten,,"
3978
3979   # Create directories.
3980   { echo "$sourcebase"
3981     echo "$m4base"
3982     if test -n "$pobase"; then
3983       echo "$pobase"
3984     fi
3985     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
3986     if test -n "$docfiles"; then
3987       echo "$docbase"
3988     fi
3989     if test -n "$inctests"; then
3990       echo "$testsbase"
3991     fi
3992     echo "$auxdir"
3993     for f in $files; do echo $f; done \
3994       | sed -e "$sed_rewrite_new_files" \
3995       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3996       | LC_ALL=C sort -u
3997   } > "$tmp"/dirs
3998   { # Rearrange file descriptors. Needed because "while ... done < ..."
3999     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4000     exec 5<&0 < "$tmp"/dirs
4001     while read d; do
4002       if test ! -d "$destdir/$d"; then
4003         if $doit; then
4004           echo "Creating directory $destdir/$d"
4005           mkdir -p "$destdir/$d" || func_fatal_error "failed"
4006         else
4007           echo "Create directory $destdir/$d"
4008         fi
4009       fi
4010     done
4011     exec 0<&5 5<&-
4012   }
4013
4014   # Copy files or make symbolic links. Remove obsolete files.
4015   added_files=''
4016   removed_files=''
4017   delimiter='   '
4018   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4019   # representing the files according to the last gnulib-tool invocation.
4020   for f in $old_files; do echo $f; done \
4021     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
4022     | LC_ALL=C sort \
4023     > "$tmp"/old-files
4024   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4025   # representing the files after this gnulib-tool invocation.
4026   for f in $new_files; do echo $f; done \
4027     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
4028     | LC_ALL=C sort \
4029     > "$tmp"/new-files
4030   # First the files that are in old-files, but not in new-files:
4031   sed_take_first_column='s,'"$delimiter"'.*,,'
4032   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
4033     # Remove the file. Do nothing if the user already removed it.
4034     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
4035       if $doit; then
4036         echo "Removing file $g (backup in ${g}~)"
4037         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
4038       else
4039         echo "Remove file $g (backup in ${g}~)"
4040       fi
4041       func_append removed_files "$g$nl"
4042     fi
4043   done
4044   # func_add_or_update handles a file that ought to be present afterwards.
4045   # Uses parameters
4046   # - f             the original file name
4047   # - g             the rewritten file name
4048   # - already_present  nonempty if the file should already exist, empty
4049   #                    otherwise
4050   func_add_or_update ()
4051   {
4052     of="$f"
4053     case "$f" in
4054       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
4055     esac
4056     func_dest_tmpfilename "$g"
4057     func_lookup_file "$f"
4058     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
4059     if test -n "$sed_transform_main_lib_file"; then
4060       case "$of" in
4061         lib/*)
4062           sed -e "$sed_transform_main_lib_file" \
4063             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4064           ;;
4065       esac
4066     fi
4067     if test -n "$sed_transform_build_aux_file"; then
4068       case "$of" in
4069         build-aux/*)
4070           sed -e "$sed_transform_build_aux_file" \
4071             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4072           ;;
4073       esac
4074     fi
4075     if test -n "$sed_transform_testsrelated_lib_file"; then
4076       case "$of" in
4077         tests=lib/*)
4078           sed -e "$sed_transform_testsrelated_lib_file" \
4079             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4080           ;;
4081       esac
4082     fi
4083     if test -f "$destdir/$g"; then
4084       # The file already exists.
4085       func_update_file
4086     else
4087       # Install the file.
4088       # Don't protest if the file should be there but isn't: it happens
4089       # frequently that developers don't put autogenerated files under version control.
4090       func_add_file
4091       func_append added_files "$g$nl"
4092     fi
4093     rm -f "$tmpfile"
4094   }
4095   # Then the files that are in new-files, but not in old-files:
4096   sed_take_last_column='s,^.*'"$delimiter"',,'
4097   already_present=
4098   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
4099     | sed -e "$sed_take_last_column" \
4100     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
4101   { # Rearrange file descriptors. Needed because "while ... done < ..."
4102     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4103     exec 5<&0 < "$tmp"/added-files
4104     while read g f; do
4105       func_add_or_update
4106     done
4107     exec 0<&5 5<&-
4108   }
4109   # Then the files that are in new-files and in old-files:
4110   already_present=true
4111   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
4112     | sed -e "$sed_take_last_column" \
4113     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
4114   { # Rearrange file descriptors. Needed because "while ... done < ..."
4115     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4116     exec 5<&0 < "$tmp"/kept-files
4117     while read g f; do
4118       func_add_or_update
4119     done
4120     exec 0<&5 5<&-
4121   }
4122
4123   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
4124   actioncmd="gnulib-tool --import"
4125   func_append actioncmd " --dir=$destdir"
4126   if test -n "$local_gnulib_dir"; then
4127     func_append actioncmd " --local-dir=$local_gnulib_dir"
4128   fi
4129   func_append actioncmd " --lib=$libname"
4130   func_append actioncmd " --source-base=$sourcebase"
4131   func_append actioncmd " --m4-base=$m4base"
4132   if test -n "$pobase"; then
4133     func_append actioncmd " --po-base=$pobase"
4134   fi
4135   func_append actioncmd " --doc-base=$docbase"
4136   func_append actioncmd " --tests-base=$testsbase"
4137   func_append actioncmd " --aux-dir=$auxdir"
4138   if test -n "$inctests"; then
4139     func_append actioncmd " --with-tests"
4140   fi
4141   if test -n "$incobsolete"; then
4142     func_append actioncmd " --with-obsolete"
4143   fi
4144   if test -n "$inc_cxx_tests"; then
4145     func_append actioncmd " --with-c++-tests"
4146   fi
4147   if test -n "$inc_longrunning_tests"; then
4148     func_append actioncmd " --with-longrunning-tests"
4149   fi
4150   if test -n "$inc_privileged_tests"; then
4151     func_append actioncmd " --with-privileged-tests"
4152   fi
4153   if test -n "$inc_unportable_tests"; then
4154     func_append actioncmd " --with-unportable-tests"
4155   fi
4156   if test -n "$inc_all_tests"; then
4157     func_append actioncmd " --with-all-tests"
4158   fi
4159   for module in $avoidlist; do
4160     func_append actioncmd " --avoid=$module"
4161   done
4162   if test -n "$lgpl"; then
4163     if test "$lgpl" = yes; then
4164       func_append actioncmd " --lgpl"
4165     else
4166       func_append actioncmd " --lgpl=$lgpl"
4167     fi
4168   fi
4169   if test -n "$makefile_name"; then
4170     func_append actioncmd " --makefile-name=$makefile_name"
4171   fi
4172   if test "$libtool" = true; then
4173     func_append actioncmd " --libtool"
4174   else
4175     func_append actioncmd " --no-libtool"
4176   fi
4177   func_append actioncmd " --macro-prefix=$macro_prefix"
4178   if test -n "$po_domain"; then
4179     func_append actioncmd " --po-domain=$po_domain"
4180   fi
4181   if test -n "$vc_files"; then
4182     if test "$vc_files" = true; then
4183       func_append actioncmd " --vc-files"
4184     else
4185       func_append actioncmd " --no-vc-files"
4186     fi
4187   fi
4188   func_append actioncmd " `echo $specified_modules`"
4189
4190   # Default the makefile name to Makefile.am.
4191   if test -n "$makefile_name"; then
4192     makefile_am=$makefile_name
4193   else
4194     makefile_am=Makefile.am
4195   fi
4196
4197   # Create normal Makefile.ams.
4198   for_test=false
4199
4200   # Setup list of Makefile.am edits that are to be performed afterwards.
4201   # Some of these edits apply to files that we will generate; others are
4202   # under the responsibility of the developer.
4203   makefile_am_edits=0
4204   # func_note_Makefile_am_edit dir var value
4205   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
4206   # ${value}.
4207   func_note_Makefile_am_edit ()
4208   {
4209     makefile_am_edits=`expr $makefile_am_edits + 1`
4210     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
4211     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
4212     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
4213   }
4214   if test "$makefile_am" = Makefile.am; then
4215     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
4216     sourcebase_base=`basename "$sourcebase"`
4217     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
4218   fi
4219   if test -n "$pobase"; then
4220     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
4221     pobase_base=`basename "$pobase"`
4222     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
4223   fi
4224   if test -n "$inctests"; then
4225     if test "$makefile_am" = Makefile.am; then
4226       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
4227       testsbase_base=`basename "$testsbase"`
4228       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
4229     fi
4230   fi
4231   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
4232   {
4233     # Find the first parent directory of $m4base that contains or will contain
4234     # a Makefile.am.
4235     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
4236 s,//*$,/,'
4237     sed_butlast='s,[^/][^/]*//*$,,'
4238     dir1="${m4base}/"; dir2=""
4239     while test -n "$dir1" \
4240           && ! { test -f "${destdir}/${dir1}Makefile.am" \
4241                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4242                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4243                  || { test -n "$inctests" \
4244                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
4245                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
4246       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
4247       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
4248     done
4249     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
4250   }
4251
4252   # Create library makefile.
4253   func_dest_tmpfilename $sourcebase/$makefile_am
4254   destfile="$sourcebase/$makefile_am"
4255   modules="$main_modules"
4256   func_emit_lib_Makefile_am > "$tmpfile"
4257   if test -f "$destdir"/$sourcebase/$makefile_am; then
4258     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
4259       rm -f "$tmpfile"
4260     else
4261       if $doit; then
4262         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4263         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
4264         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4265       else
4266         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4267         rm -f "$tmpfile"
4268       fi
4269     fi
4270   else
4271     if $doit; then
4272       echo "Creating $sourcebase/$makefile_am"
4273       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4274     else
4275       echo "Create $sourcebase/$makefile_am"
4276       rm -f "$tmpfile"
4277     fi
4278     func_append added_files "$sourcebase/$makefile_am$nl"
4279   fi
4280
4281   # Create po/ directory.
4282   if test -n "$pobase"; then
4283     # Create po makefile and auxiliary files.
4284     for file in Makefile.in.in remove-potcdate.sin; do
4285       func_dest_tmpfilename $pobase/$file
4286       func_lookup_file build-aux/po/$file
4287       cat "$lookedup_file" > "$tmpfile"
4288       if test -f "$destdir"/$pobase/$file; then
4289         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
4290           rm -f "$tmpfile"
4291         else
4292           if $doit; then
4293             echo "Updating $pobase/$file (backup in $pobase/$file~)"
4294             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
4295             mv -f "$tmpfile" "$destdir"/$pobase/$file
4296           else
4297             echo "Update $pobase/$file (backup in $pobase/$file~)"
4298             rm -f "$tmpfile"
4299           fi
4300         fi
4301       else
4302         if $doit; then
4303           echo "Creating $pobase/$file"
4304           mv -f "$tmpfile" "$destdir"/$pobase/$file
4305         else
4306           echo "Create $pobase/$file"
4307           rm -f "$tmpfile"
4308         fi
4309         func_append added_files "$pobase/$file$nl"
4310       fi
4311     done
4312     # Create po makefile parameterization, part 1.
4313     func_dest_tmpfilename $pobase/Makevars
4314     func_emit_po_Makevars > "$tmpfile"
4315     if test -f "$destdir"/$pobase/Makevars; then
4316       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
4317         rm -f "$tmpfile"
4318       else
4319         if $doit; then
4320           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
4321           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
4322           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4323         else
4324           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
4325           rm -f "$tmpfile"
4326         fi
4327       fi
4328     else
4329       if $doit; then
4330         echo "Creating $pobase/Makevars"
4331         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4332       else
4333         echo "Create $pobase/Makevars"
4334         rm -f "$tmpfile"
4335       fi
4336       func_append added_files "$pobase/Makevars$nl"
4337     fi
4338     # Create po makefile parameterization, part 2.
4339     func_dest_tmpfilename $pobase/POTFILES.in
4340     func_emit_po_POTFILES_in > "$tmpfile"
4341     if test -f "$destdir"/$pobase/POTFILES.in; then
4342       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
4343         rm -f "$tmpfile"
4344       else
4345         if $doit; then
4346           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
4347           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
4348           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
4349         else
4350           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
4351           rm -f "$tmpfile"
4352         fi
4353       fi
4354     else
4355       if $doit; then
4356         echo "Creating $pobase/POTFILES.in"
4357         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
4358       else
4359         echo "Create $pobase/POTFILES.in"
4360         rm -f "$tmpfile"
4361       fi
4362       func_append added_files "$pobase/POTFILES.in$nl"
4363     fi
4364     # Fetch PO files.
4365     TP_URL="http://translationproject.org/latest/"
4366     TP_RSYNC_URI="translationproject.org::tp/latest/"
4367     if $doit; then
4368       echo "Fetching gnulib PO files from $TP_URL"
4369       (cd "$destdir"/$pobase \
4370        && { # Prefer rsync over wget if it is available, since it consumes
4371             # less network bandwidth, due to compression.
4372             if type rsync 2>/dev/null | grep / > /dev/null; then
4373               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
4374             else
4375               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
4376             fi
4377           }
4378       )
4379     else
4380       echo "Fetch gnulib PO files from $TP_URL"
4381     fi
4382     # Create po/LINGUAS.
4383     if $doit; then
4384       func_dest_tmpfilename $pobase/LINGUAS
4385       (cd "$destdir"/$pobase \
4386        && { echo '# Set of available languages.'
4387             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
4388           }
4389       ) > "$tmpfile"
4390       if test -f "$destdir"/$pobase/LINGUAS; then
4391         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
4392           rm -f "$tmpfile"
4393         else
4394           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
4395           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
4396           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
4397         fi
4398       else
4399         echo "Creating $pobase/LINGUAS"
4400         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
4401         func_append added_files "$pobase/LINGUAS$nl"
4402       fi
4403     else
4404       if test -f "$destdir"/$pobase/LINGUAS; then
4405         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
4406       else
4407         echo "Create $pobase/LINGUAS"
4408       fi
4409     fi
4410   fi
4411
4412   # Create m4/gnulib-cache.m4.
4413   func_dest_tmpfilename $m4base/gnulib-cache.m4
4414   (
4415     func_emit_copyright_notice
4416     echo "#"
4417     echo "# This file represents the specification of how gnulib-tool is used."
4418     echo "# It acts as a cache: It is written and read by gnulib-tool."
4419     echo "# In projects that use version control, this file is meant to be put under"
4420     echo "# version control, like the configure.ac and various Makefile.am files."
4421     echo
4422     echo
4423     echo "# Specification in the form of a command-line invocation:"
4424     echo "#   $actioncmd"
4425     echo
4426     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
4427     # Store the local_gnulib_dir relative to destdir.
4428     case "$local_gnulib_dir" in
4429       "" | /*)
4430         relative_local_gnulib_dir="$local_gnulib_dir" ;;
4431       * )
4432         case "$destdir" in
4433           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
4434           *)
4435             # destdir, local_gnulib_dir are both relative.
4436             func_relativize "$destdir" "$local_gnulib_dir"
4437             relative_local_gnulib_dir="$reldir" ;;
4438         esac ;;
4439     esac
4440     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
4441     echo "gl_MODULES(["
4442     echo "$specified_modules" | sed -e 's/^/  /g'
4443     echo "])"
4444     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
4445     test -z "$inc_cxx_tests" || echo "gl_WITH_CXX_TESTS"
4446     test -z "$inc_longrunning_tests" || echo "gl_WITH_LONGRUNNING_TESTS"
4447     test -z "$inc_privileged_tests" || echo "gl_WITH_PRIVILEGED_TESTS"
4448     test -z "$inc_unportable_tests" || echo "gl_WITH_UNPORTABLE_TESTS"
4449     test -z "$inc_all_tests" || echo "gl_WITH_ALL_TESTS"
4450     echo "gl_AVOID([$avoidlist])"
4451     echo "gl_SOURCE_BASE([$sourcebase])"
4452     echo "gl_M4_BASE([$m4base])"
4453     echo "gl_PO_BASE([$pobase])"
4454     echo "gl_DOC_BASE([$docbase])"
4455     echo "gl_TESTS_BASE([$testsbase])"
4456     test -z "$inctests" || echo "gl_WITH_TESTS"
4457     echo "gl_LIB([$libname])"
4458     if test -n "$lgpl"; then
4459       if test "$lgpl" = yes; then
4460         echo "gl_LGPL"
4461       else
4462         echo "gl_LGPL([$lgpl])"
4463       fi
4464     fi
4465     echo "gl_MAKEFILE_NAME([$makefile_name])"
4466     if test "$libtool" = true; then
4467       echo "gl_LIBTOOL"
4468     fi
4469     echo "gl_MACRO_PREFIX([$macro_prefix])"
4470     echo "gl_PO_DOMAIN([$po_domain])"
4471     if test -n "$vc_files"; then
4472       echo "gl_VC_FILES([$vc_files])"
4473     fi
4474   ) > "$tmpfile"
4475   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
4476     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
4477       rm -f "$tmpfile"
4478     else
4479       if $doit; then
4480         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
4481         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
4482         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
4483       else
4484         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
4485         if false; then
4486           cat "$tmpfile"
4487           echo
4488           echo "# gnulib-cache.m4 ends here"
4489         fi
4490         rm -f "$tmpfile"
4491       fi
4492     fi
4493   else
4494     if $doit; then
4495       echo "Creating $m4base/gnulib-cache.m4"
4496       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
4497     else
4498       echo "Create $m4base/gnulib-cache.m4"
4499       cat "$tmpfile"
4500       rm -f "$tmpfile"
4501     fi
4502   fi
4503
4504   # Create m4/gnulib-comp.m4.
4505   func_dest_tmpfilename $m4base/gnulib-comp.m4
4506   (
4507     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
4508     func_emit_copyright_notice
4509     echo "#"
4510     echo "# This file represents the compiled summary of the specification in"
4511     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
4512     echo "# to be invoked from configure.ac."
4513     echo "# In projects that use version control, this file can be treated like"
4514     echo "# other built files."
4515     echo
4516     echo
4517     echo "# This macro should be invoked from $configure_ac, in the section"
4518     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
4519     echo "# any checks for libraries, header files, types and library functions."
4520     echo "AC_DEFUN([${macro_prefix}_EARLY],"
4521     echo "["
4522     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
4523     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
4524     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
4525     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
4526     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
4527     if test -n "$uses_subdirs"; then
4528       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
4529     fi
4530     for module in $final_modules; do
4531       func_verify_module
4532       if test -n "$module"; then
4533         echo "# Code from module $module:"
4534         func_get_autoconf_early_snippet "$module"
4535       fi
4536     done \
4537       | sed -e '/^$/d;' -e 's/^/  /'
4538     echo "])"
4539     echo
4540     echo "# This macro should be invoked from $configure_ac, in the section"
4541     echo "# \"Check for header files, types and library functions\"."
4542     echo "AC_DEFUN([${macro_prefix}_INIT],"
4543     echo "["
4544     if test "$libtool" = true; then
4545       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
4546       echo "  gl_cond_libtool=true"
4547     else
4548       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
4549       echo "  gl_cond_libtool=false"
4550       echo "  gl_libdeps="
4551       echo "  gl_ltlibdeps="
4552     fi
4553     if test "$auxdir" != "build-aux"; then
4554       sed_replace_build_aux='
4555         :a
4556         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
4557           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
4558           ba
4559         }'
4560     else
4561       sed_replace_build_aux="$sed_noop"
4562     fi
4563     echo "  gl_m4_base='$m4base'"
4564     func_emit_initmacro_start $macro_prefix
4565     echo "  gl_source_base='$sourcebase'"
4566     for module in $main_modules; do
4567       func_verify_module
4568       if test -n "$module"; then
4569         echo "  # Code from module $module:"
4570         func_get_autoconf_snippet "$module" \
4571           | sed -e '/^$/d;' -e 's/^/  /' \
4572                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
4573                 -e "$sed_replace_build_aux"
4574         if test "$module" = 'alloca' && test "$libtool" = true; then
4575           echo 'changequote(,)dnl'
4576           echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
4577           echo 'changequote([, ])dnl'
4578           echo 'AC_SUBST([LTALLOCA])'
4579         fi
4580       fi
4581     done
4582     echo "  # End of code from modules"
4583     func_emit_initmacro_end $macro_prefix
4584     echo "  gltests_libdeps="
4585     echo "  gltests_ltlibdeps="
4586     func_emit_initmacro_start ${macro_prefix}tests
4587     echo "  gl_source_base='$testsbase'"
4588     # Define a tests witness macro that depends on the package.
4589     # PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
4590     # See <http://lists.gnu.org/archive/html/automake/2009-05/msg00145.html>.
4591     echo "changequote(,)dnl"
4592     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"
4593     echo "changequote([, ])dnl"
4594     echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
4595     echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
4596     echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
4597     for module in $testsrelated_modules; do
4598       func_verify_module
4599       if test -n "$module"; then
4600         func_get_autoconf_snippet "$module" \
4601           | sed -e '/^$/d;' -e 's/^/  /' \
4602                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
4603                 -e "$sed_replace_build_aux" \
4604                 -e 's/\$gl_cond_libtool/false/g' \
4605                 -e 's/gl_libdeps/gltests_libdeps/g' \
4606                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
4607       fi
4608     done
4609     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
4610     func_emit_initmacro_end ${macro_prefix}tests
4611     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
4612     # created using libtool, because libtool already handles the dependencies.
4613     if test "$libtool" != true; then
4614       libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
4615       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
4616       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
4617       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
4618       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
4619     fi
4620     if $use_libtests; then
4621       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
4622       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
4623     fi
4624     echo "])"
4625     func_emit_initmacro_done $macro_prefix $sourcebase
4626     func_emit_initmacro_done ${macro_prefix}tests $testsbase
4627     echo
4628     echo "# This macro records the list of files which have been installed by"
4629     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
4630     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
4631     echo "$files" | sed -e 's,^,  ,'
4632     echo "])"
4633   ) > "$tmpfile"
4634   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
4635     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
4636       rm -f "$tmpfile"
4637     else
4638       if $doit; then
4639         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
4640         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
4641         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
4642       else
4643         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
4644         if false; then
4645           cat "$tmpfile"
4646           echo
4647           echo "# gnulib-comp.m4 ends here"
4648         fi
4649         rm -f "$tmpfile"
4650       fi
4651     fi
4652   else
4653     if $doit; then
4654       echo "Creating $m4base/gnulib-comp.m4"
4655       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
4656     else
4657       echo "Create $m4base/gnulib-comp.m4"
4658       cat "$tmpfile"
4659       rm -f "$tmpfile"
4660     fi
4661   fi
4662
4663   if test -n "$inctests"; then
4664     # Create tests makefile.
4665     func_dest_tmpfilename $testsbase/$makefile_am
4666     destfile="$testsbase/$makefile_am"
4667     modules="$testsrelated_modules"
4668     func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
4669     if test -f "$destdir"/$testsbase/$makefile_am; then
4670       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
4671         rm -f "$tmpfile"
4672       else
4673         if $doit; then
4674           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
4675           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
4676           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
4677         else
4678           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
4679           rm -f "$tmpfile"
4680         fi
4681       fi
4682     else
4683       if $doit; then
4684         echo "Creating $testsbase/$makefile_am"
4685         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
4686       else
4687         echo "Create $testsbase/$makefile_am"
4688         rm -f "$tmpfile"
4689       fi
4690     func_append added_files "$testsbase/$makefile_am$nl"
4691     fi
4692   fi
4693
4694   if test "$vc_files" != false; then
4695     # Update the .cvsignore and .gitignore files.
4696     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
4697       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
4698       # Treat gnulib-comp.m4 like an added file, even if it already existed.
4699       echo "$m4base/|A|gnulib-comp.m4"
4700     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
4701     { # Rearrange file descriptors. Needed because "while ... done < ..."
4702       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4703       exec 5<&0 < "$tmp"/fileset-changes
4704       func_update_ignorelist ()
4705       {
4706         ignore="$1"
4707         if test "$ignore" = .gitignore; then
4708           # In a .gitignore file, "foo" applies to the current directory and all
4709           # subdirectories, whereas "/foo" applies to the current directory only.
4710           anchor='/'
4711           escaped_anchor='\/'
4712           doubly_escaped_anchor='\\/'
4713         else
4714           anchor=''
4715           escaped_anchor=''
4716           doubly_escaped_anchor=''
4717         fi
4718         if test -f "$destdir/$dir$ignore"; then
4719           if test -n "$dir_added" || test -n "$dir_removed"; then
4720             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
4721             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
4722                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
4723              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
4724                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-removed
4725             )
4726             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
4727               if $doit; then
4728                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
4729                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
4730                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
4731                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,$/d,' < "$tmp"/ignore-removed; fi
4732                 } > "$tmp"/sed-ignore-removed
4733                 { cat "$destdir/$dir$ignore"~
4734                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
4735                 } | sed -f "$tmp"/sed-ignore-removed \
4736                   > "$destdir/$dir$ignore"
4737               else
4738                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
4739               fi
4740             fi
4741           fi
4742         else
4743           if test -n "$dir_added"; then
4744             if $doit; then
4745               echo "Creating $destdir/$dir$ignore"
4746               {
4747                 if test "$ignore" = .cvsignore; then
4748                   echo ".deps"
4749                   # Automake generates Makefile rules that create .dirstamp files.
4750                   echo ".dirstamp"
4751                 fi
4752                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
4753               } > "$destdir/$dir$ignore"
4754             else
4755               echo "Create $destdir/$dir$ignore"
4756             fi
4757           fi
4758         fi
4759       }
4760       func_done_dir ()
4761       {
4762         dir="$1"
4763         dir_added="$2"
4764         dir_removed="$3"
4765         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
4766           func_update_ignorelist .cvsignore
4767         fi
4768         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
4769           func_update_ignorelist .gitignore
4770         fi
4771       }
4772       last_dir=
4773       last_dir_added=
4774       last_dir_removed=
4775       while read line; do
4776         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
4777         next_dir=`echo "$line" | sed -e 's,|.*,,'`
4778         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
4779         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
4780         if test "$next_dir" != "$last_dir"; then
4781           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
4782           last_dir="$next_dir"
4783           last_dir_added=
4784           last_dir_removed=
4785         fi
4786         case $op in
4787           A) func_append last_dir_added "$file$nl";;
4788           R) func_append last_dir_removed "$file$nl";;
4789         esac
4790       done
4791       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
4792       exec 0<&5 5<&-
4793     }
4794   fi
4795
4796   echo "Finished."
4797   echo
4798   echo "You may need to add #include directives for the following .h files."
4799   # Intersect $specified_modules and $main_modules
4800   # (since $specified_modules is not necessarily of subset of $main_modules
4801   # - some may have been skipped through --avoid, and since the elements of
4802   # $main_modules but not in $specified_modules can go away without explicit
4803   # notice - through changes in the module dependencies).
4804   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
4805   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
4806   # First the #include <...> directives without #ifs, sorted for convenience,
4807   # then the #include "..." directives without #ifs, sorted for convenience,
4808   # then the #include directives that are surrounded by #ifs. Not sorted.
4809   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
4810     include_directive=`func_get_include_directive "$module"`
4811     case "$nl$include_directive" in
4812       *"$nl#if"*)
4813         echo "$include_directive" 1>&5
4814         ;;
4815       *)
4816         echo "$include_directive" | grep -v 'include "' 1>&6
4817         echo "$include_directive" | grep 'include "' 1>&7
4818         ;;
4819     esac
4820   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
4821   (
4822    LC_ALL=C sort -u "$tmp"/include-angles
4823    LC_ALL=C sort -u "$tmp"/include-quotes
4824    cat "$tmp"/include-if
4825   ) | sed -e '/^$/d' -e 's/^/  /'
4826   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
4827
4828   for module in $main_modules; do
4829     func_get_link_directive "$module"
4830   done \
4831     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
4832   if test `wc -l < "$tmp"/link` != 0; then
4833     echo
4834     echo "You may need to use the following Makefile variables when linking."
4835     echo "Use them in <program>_LDADD when linking a program, or"
4836     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
4837     cat "$tmp"/link
4838   fi
4839   rm -f "$tmp"/link
4840
4841   echo
4842   echo "Don't forget to"
4843   if test "$makefile_am" = Makefile.am; then
4844     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
4845   else
4846     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
4847   fi
4848   if test -n "$pobase"; then
4849     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
4850   fi
4851   if test -n "$inctests"; then
4852     if test "$makefile_am" = Makefile.am; then
4853       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
4854     else
4855       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
4856     fi
4857   fi
4858   edit=0
4859   while test $edit != $makefile_am_edits; do
4860     edit=`expr $edit + 1`
4861     eval dir=\"\$makefile_am_edit${edit}_dir\"
4862     eval var=\"\$makefile_am_edit${edit}_var\"
4863     eval val=\"\$makefile_am_edit${edit}_val\"
4864     if test -n "$var"; then
4865       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
4866     fi
4867   done
4868   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
4869   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
4870 }
4871
4872 # func_create_testdir testdir modules
4873 # Input:
4874 # - local_gnulib_dir  from --local-dir
4875 # - modcache        true or false, from --cache-modules/--no-cache-modules
4876 # - auxdir          directory relative to destdir where to place build aux files
4877 # - inctests        true if tests should be included, blank otherwise
4878 # - incobsolete     true if obsolete modules among dependencies should be
4879 #                   included, blank otherwise
4880 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
4881 #                    blank otherwise
4882 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
4883 #                           blank otherwise
4884 # - excl_privileged_tests  true if tests that require root privileges should be
4885 #                          excluded, blank otherwise
4886 # - excl_unportable_tests  true if tests that fail on some platforms should be
4887 #                          excluded, blank otherwise
4888 # - avoidlist       list of modules to avoid
4889 # - libtool         true if --libtool was given, false if --no-libtool was
4890 #                   given, blank otherwise
4891 # - symbolic        true if files should be symlinked, copied otherwise
4892 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
4893 #                   copied otherwise
4894 func_create_testdir ()
4895 {
4896   testdir="$1"
4897   modules="$2"
4898   if test -z "$modules"; then
4899     # All modules together.
4900     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
4901     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
4902     # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
4903     modules=`func_all_modules`
4904     modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist | lib-ignore) ;; *) echo $m;; esac; done`
4905   fi
4906   specified_modules="$modules"
4907
4908   # Canonicalize the list of specified modules.
4909   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
4910
4911   # Unlike in func_import, here we want to include all kinds of tests for the
4912   # directly specified modules, but not for dependencies.
4913   inc_all_direct_tests=true
4914   inc_all_indirect_tests="$inc_all_tests"
4915
4916   # Check that the license of every module is consistent with the license of
4917   # its dependencies.
4918   saved_inctests="$inctests"
4919   # When computing transitive closures, don't consider $module to depend on
4920   # $module-tests. Need this becauses tests are implicitly GPL and may depend
4921   # on GPL modules - therefore we don't want a warning in this case.
4922   inctests=""
4923   for requested_module in $specified_modules; do
4924     requested_license=`func_get_license "$requested_module"`
4925     if test "$requested_license" != GPL; then
4926       # Here we use func_modules_transitive_closure, not just
4927       # func_get_dependencies, so that we also detect weird situations like
4928       # an LGPL module which depends on a GPLed build tool module which depends
4929       # on a GPL module.
4930       modules="$requested_module"
4931       func_modules_transitive_closure
4932       for module in $modules; do
4933         license=`func_get_license "$module"`
4934         case "$license" in
4935           'GPLed build tool') ;;
4936           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
4937           *)
4938             case "$requested_license" in
4939               GPLv2+)
4940                 case "$license" in
4941                   GPLv2+ | LGPLv2+) ;;
4942                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4943                 esac
4944                 ;;
4945               LGPL)
4946                 case "$license" in
4947                   LGPL | LGPLv2+) ;;
4948                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4949                 esac
4950                 ;;
4951               LGPLv2+)
4952                 case "$license" in
4953                   LGPLv2+) ;;
4954                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4955                 esac
4956                 ;;
4957             esac
4958             ;;
4959         esac
4960       done
4961     fi
4962   done
4963   inctests="$saved_inctests"
4964
4965   # Subdirectory names.
4966   sourcebase=gllib
4967   m4base=glm4
4968   pobase=
4969   docbase=gldoc
4970   testsbase=gltests
4971   macro_prefix=gl
4972   po_domain=
4973   vc_files=
4974
4975   # Determine final module list.
4976   modules="$specified_modules"
4977   func_modules_transitive_closure
4978   if test $verbose -ge 0; then
4979     func_show_module_list
4980   fi
4981
4982   # Add the dummy module if needed.
4983   func_modules_add_dummy
4984
4985   # Show banner notice of every module.
4986   func_modules_notice
4987
4988   # Determine final file list.
4989   func_modules_to_filelist
4990   if test $verbose -ge 0; then
4991     echo "File list:"
4992     echo "$files" | sed -e 's/^/  /'
4993   fi
4994   # Add files for which the copy in gnulib is newer than the one that
4995   # "automake --add-missing --copy" would provide.
4996   files="$files build-aux/config.guess"
4997   files="$files build-aux/config.sub"
4998   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
4999
5000   rewritten='%REWRITTEN%'
5001   sed_rewrite_files="\
5002     s,^build-aux/,$rewritten$auxdir/,
5003     s,^doc/,$rewritten$docbase/,
5004     s,^lib/,$rewritten$sourcebase/,
5005     s,^m4/,$rewritten$m4base/,
5006     s,^tests/,$rewritten$testsbase/,
5007     s,^top/,$rewritten,
5008     s,^$rewritten,,"
5009
5010   # Create directories.
5011   for f in $files; do echo $f; done \
5012     | sed -e "$sed_rewrite_files" \
5013     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
5014     | LC_ALL=C sort -u \
5015     > "$tmp"/dirs
5016   { # Rearrange file descriptors. Needed because "while ... done < ..."
5017     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5018     exec 5<&0 < "$tmp"/dirs
5019     while read d; do
5020       mkdir -p "$testdir/$d"
5021     done
5022     exec 0<&5 5<&-
5023   }
5024
5025   # Copy files or make symbolic links.
5026   delimiter='   '
5027   for f in $files; do echo $f; done \
5028     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
5029     | LC_ALL=C sort \
5030     > "$tmp"/files
5031   { # Rearrange file descriptors. Needed because "while ... done < ..."
5032     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5033     exec 5<&0 < "$tmp"/files
5034     while read g f; do
5035       func_lookup_file "$f"
5036       if test -n "$lookedup_tmp"; then
5037         cp -p "$lookedup_file" "$testdir/$g"
5038       else
5039         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
5040         if { test -n "$symbolic" \
5041              || { test -n "$lsymbolic" \
5042                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
5043           func_ln "$lookedup_file" "$testdir/$g"
5044         else
5045           cp -p "$lookedup_file" "$testdir/$g"
5046         fi
5047       fi
5048     done
5049     exec 0<&5 5<&-
5050   }
5051
5052   # Create Makefile.ams that are for testing.
5053   for_test=true
5054
5055   # No special edits are needed.
5056   makefile_am_edits=0
5057
5058   # Create $sourcebase/Makefile.am.
5059   mkdir -p "$testdir/$sourcebase"
5060   destfile="$sourcebase/Makefile.am"
5061   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
5062   any_uses_subdirs="$uses_subdirs"
5063
5064   # Create $m4base/Makefile.am.
5065   mkdir -p "$testdir/$m4base"
5066   (echo "## Process this file with automake to produce Makefile.in."
5067    echo
5068    echo "EXTRA_DIST ="
5069    for f in $files; do
5070      case "$f" in
5071        m4/* )
5072          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
5073      esac
5074    done
5075   ) > "$testdir/$m4base/Makefile.am"
5076
5077   subdirs="$sourcebase $m4base"
5078   subdirs_with_configure_ac=""
5079
5080   if false && test -f "$testdir"/$m4base/gettext.m4; then
5081     # Avoid stupid error message from automake:
5082     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
5083     mkdir -p "$testdir/po"
5084     (echo "## Process this file with automake to produce Makefile.in."
5085     ) > "$testdir/po/Makefile.am"
5086     func_append subdirs " po"
5087   fi
5088
5089   if test -n "$inctests"; then
5090     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
5091     # Viewed from the $testsbase subdirectory, $auxdir is different.
5092     saved_auxdir="$auxdir"
5093     auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
5094     # Create $testsbase/Makefile.am.
5095     use_libtests=false
5096     destfile="$testsbase/Makefile.am"
5097     func_emit_tests_Makefile_am "" > "$testdir/$testsbase/Makefile.am"
5098     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
5099     # Create $testsbase/configure.ac.
5100     (echo "# Process this file with autoconf to produce a configure script."
5101      echo "AC_INIT([dummy], [0])"
5102      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5103      echo "AM_INIT_AUTOMAKE"
5104      echo
5105      echo "AC_CONFIG_HEADERS([config.h])"
5106      echo
5107      echo "AC_PROG_CC"
5108      echo "AC_PROG_INSTALL"
5109      echo "AC_PROG_MAKE_SET"
5110      echo "AC_PROG_RANLIB"
5111      echo
5112      if test -n "$uses_subdirs"; then
5113        echo "AM_PROG_CC_C_O"
5114        echo
5115      fi
5116      for module in $modules; do
5117        func_verify_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_early_snippet "$module"
5125              ;;
5126          esac
5127        fi
5128      done \
5129        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5130      if test "$libtool" = true; then
5131        echo "LT_INIT([win32-dll])"
5132        echo "LT_LANG([C++])"
5133        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5134        echo "gl_cond_libtool=true"
5135      else
5136        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5137        echo "gl_cond_libtool=false"
5138        echo "gl_libdeps="
5139        echo "gl_ltlibdeps="
5140      fi
5141      # Wrap the set of autoconf snippets into an autoconf macro that is then
5142      # invoked. This is needed because autoconf does not support AC_REQUIRE
5143      # at the top level:
5144      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5145      # but we want the AC_REQUIRE to have its normal meaning (provide one
5146      # expansion of the required macro before the current point, and only one
5147      # expansion total).
5148      echo "AC_DEFUN([gl_INIT], ["
5149      sed_replace_build_aux='
5150        :a
5151        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5152          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5153          ba
5154        }'
5155      echo "gl_m4_base='../$m4base'"
5156      func_emit_initmacro_start $macro_prefix
5157      # We don't have explicit ordering constraints between the various
5158      # autoconf snippets. It's cleanest to put those of the library before
5159      # those of the tests.
5160      echo "gl_source_base='../$sourcebase'"
5161      for module in $modules; do
5162        func_verify_nontests_module
5163        if test -n "$module"; then
5164          case $module in
5165            gnumakefile | maintainer-makefile)
5166              # These modules are meant to be used only in the top-level directory.
5167              ;;
5168            *)
5169              func_get_autoconf_snippet "$module" \
5170                | sed -e "$sed_replace_build_aux"
5171              if test "$module" = 'alloca' && test "$libtool" = true; then
5172                echo 'changequote(,)dnl'
5173                echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
5174                echo 'changequote([, ])dnl'
5175                echo 'AC_SUBST([LTALLOCA])'
5176              fi
5177              ;;
5178          esac
5179        fi
5180      done
5181      echo "gl_source_base='.'"
5182      for module in $modules; do
5183        func_verify_tests_module
5184        if test -n "$module"; then
5185          func_get_autoconf_snippet "$module" \
5186            | sed -e "$sed_replace_build_aux"
5187        fi
5188      done
5189      func_emit_initmacro_end $macro_prefix
5190      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5191      # created using libtool, because libtool already handles the dependencies.
5192      if test "$libtool" != true; then
5193        libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5194        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5195        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5196        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5197        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5198      fi
5199      echo "])"
5200      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
5201      echo
5202      echo "gl_INIT"
5203      echo
5204      # Usually $testsbase/config.h will be a superset of config.h. Verify this
5205      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
5206      echo "AH_TOP([#include \"../config.h\"])"
5207      echo
5208      echo "AC_CONFIG_FILES([Makefile])"
5209      echo "AC_OUTPUT"
5210     ) > "$testdir/$testsbase/configure.ac"
5211     auxdir="$saved_auxdir"
5212     func_append subdirs " $testsbase"
5213     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
5214   fi
5215
5216   # Create Makefile.am.
5217   (echo "## Process this file with automake to produce Makefile.in."
5218    echo
5219    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
5220    echo
5221    echo "SUBDIRS = $subdirs"
5222    echo
5223    echo "ACLOCAL_AMFLAGS = -I $m4base"
5224   ) > "$testdir/Makefile.am"
5225
5226   # Create configure.ac.
5227   (echo "# Process this file with autoconf to produce a configure script."
5228    echo "AC_INIT([dummy], [0])"
5229    if test "$auxdir" != "."; then
5230      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5231    fi
5232    echo "AM_INIT_AUTOMAKE"
5233    echo
5234    echo "AC_CONFIG_HEADERS([config.h])"
5235    echo
5236    echo "AC_PROG_CC"
5237    echo "AC_PROG_INSTALL"
5238    echo "AC_PROG_MAKE_SET"
5239    echo
5240    echo "# For autobuild."
5241    echo "AC_CANONICAL_BUILD"
5242    echo "AC_CANONICAL_HOST"
5243    echo
5244    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5245    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5246    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5247    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5248    echo
5249    echo "AC_PROG_RANLIB"
5250    echo
5251    if test -n "$any_uses_subdirs"; then
5252      echo "AM_PROG_CC_C_O"
5253      echo
5254    fi
5255    for module in $modules; do
5256      func_verify_nontests_module
5257      if test -n "$module"; then
5258        func_get_autoconf_early_snippet "$module"
5259      fi
5260    done \
5261      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5262    if test "$libtool" = true; then
5263      echo "LT_INIT([win32-dll])"
5264      echo "LT_LANG([C++])"
5265      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5266      echo "gl_cond_libtool=true"
5267    else
5268      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5269      echo "gl_cond_libtool=false"
5270      echo "gl_libdeps="
5271      echo "gl_ltlibdeps="
5272    fi
5273    # Wrap the set of autoconf snippets into an autoconf macro that is then
5274    # invoked. This is needed because autoconf does not support AC_REQUIRE
5275    # at the top level:
5276    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5277    # but we want the AC_REQUIRE to have its normal meaning (provide one
5278    # expansion of the required macro before the current point, and only one
5279    # expansion total).
5280    echo "AC_DEFUN([gl_INIT], ["
5281    if test "$auxdir" != "build-aux"; then
5282      sed_replace_build_aux='
5283        :a
5284        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5285          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5286          ba
5287        }'
5288    else
5289      sed_replace_build_aux="$sed_noop"
5290    fi
5291    echo "gl_m4_base='$m4base'"
5292    func_emit_initmacro_start $macro_prefix
5293    echo "gl_source_base='$sourcebase'"
5294    for module in $modules; do
5295      func_verify_nontests_module
5296      if test -n "$module"; then
5297        func_get_autoconf_snippet "$module" \
5298          | sed -e "$sed_replace_build_aux"
5299        if test "$module" = 'alloca' && test "$libtool" = true; then
5300          echo 'changequote(,)dnl'
5301          echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
5302          echo 'changequote([, ])dnl'
5303          echo 'AC_SUBST([LTALLOCA])'
5304        fi
5305      fi
5306    done
5307    func_emit_initmacro_end $macro_prefix
5308    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5309    # created using libtool, because libtool already handles the dependencies.
5310    if test "$libtool" != true; then
5311      libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5312      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5313      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5314      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5315      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5316    fi
5317    echo "])"
5318    func_emit_initmacro_done $macro_prefix $sourcebase
5319    echo
5320    echo "gl_INIT"
5321    echo
5322    if test -n "$subdirs_with_configure_ac"; then
5323      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
5324    fi
5325    makefiles="Makefile"
5326    for d in $subdirs; do
5327      # For subdirs that have a configure.ac by their own, it's the subdir's
5328      # configure.ac which creates the subdir's Makefile.am, not this one.
5329      case " $subdirs_with_configure_ac " in
5330        *" $d "*) ;;
5331        *) func_append makefiles " $d/Makefile" ;;
5332      esac
5333    done
5334    echo "AC_CONFIG_FILES([$makefiles])"
5335    echo "AC_OUTPUT"
5336   ) > "$testdir/configure.ac"
5337
5338   # Create autogenerated files.
5339   (cd "$testdir"
5340    # Do not use "${AUTORECONF} --force --install", because it may invoke
5341    # autopoint, which brings in older versions of some of our .m4 files.
5342    if test -f $m4base/gettext.m4; then
5343      func_execute_command ${AUTOPOINT} --force || func_exit 1
5344      for f in $m4base/*.m4~; do
5345        if test -f $f; then
5346          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
5347        fi
5348      done
5349    fi
5350    if test "$libtool" = true; then
5351      func_execute_command ${LIBTOOLIZE} --copy || func_exit 1
5352    fi
5353    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
5354    if ! test -d build-aux; then
5355      func_execute_command mkdir build-aux || func_exit 1
5356    fi
5357    func_execute_command ${AUTOCONF} || func_exit 1
5358    func_execute_command ${AUTOHEADER} || func_exit 1
5359    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5360   ) || func_exit 1
5361   if test -n "$inctests"; then
5362     # Create autogenerated files.
5363     (cd "$testdir/$testsbase" || func_exit 1
5364      # Do not use "${AUTORECONF} --force --install", because it may invoke
5365      # autopoint, which brings in older versions of some of our .m4 files.
5366      if test -f ../$m4base/gettext.m4; then
5367        func_execute_command ${AUTOPOINT} --force || func_exit 1
5368        for f in ../$m4base/*.m4~; do
5369          if test -f $f; then
5370            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
5371          fi
5372        done
5373      fi
5374      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
5375      if ! test -d ../build-aux; then
5376        func_execute_command mkdir ../build-aux
5377      fi
5378      func_execute_command ${AUTOCONF} || func_exit 1
5379      func_execute_command ${AUTOHEADER} || func_exit 1
5380      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5381     ) || func_exit 1
5382   fi
5383   # Need to run configure and make once, to create built files that are to be
5384   # distributed (such as parse-datetime.c).
5385   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
5386   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
5387   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
5388                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
5389   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
5390   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
5391   # such $(FOO_H) because they don't refer to distributed files.
5392   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
5393                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
5394                  | sed -e "$sed_remove_make_variables"`
5395   distributed_built_sources=`for file in $built_sources; do
5396                                case "$cleaned_files" in
5397                                  *" "$file" "*) ;;
5398                                  *) echo $file ;;
5399                                esac;
5400                              done`
5401   tests_distributed_built_sources=
5402   if test -n "$inctests"; then
5403     # Likewise for built files in the $testsbase directory.
5404     tests_cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
5405                          | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
5406     tests_cleaned_files=`for file in $tests_cleaned_files; do echo " $file "; done`
5407     tests_built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
5408                          | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
5409                          | sed -e "$sed_remove_make_variables"`
5410     tests_distributed_built_sources=`for file in $tests_built_sources; do
5411                                        case "$tests_cleaned_files" in
5412                                          *" "$file" "*) ;;
5413                                          *) echo $file ;;
5414                                        esac;
5415                                      done`
5416   fi
5417   if test -n "$distributed_built_sources" || test -n "$tests_distributed_built_sources"; then
5418     (cd "$testdir"
5419      ./configure || func_exit 1
5420        if test -n "$distributed_built_sources"; then
5421          cd "$sourcebase"
5422          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
5423          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
5424                built_sources \
5425            || func_exit 1
5426          cd ..
5427        fi
5428        if test -n "$tests_distributed_built_sources"; then
5429          cd "$testsbase"
5430          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
5431          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
5432                built_sources \
5433            || func_exit 1
5434          cd ..
5435        fi
5436      $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
5437            distclean \
5438        || func_exit 1
5439     ) || func_exit 1
5440   fi
5441 }
5442
5443 # func_create_megatestdir megatestdir allmodules
5444 # Input:
5445 # - local_gnulib_dir  from --local-dir
5446 # - modcache        true or false, from --cache-modules/--no-cache-modules
5447 # - auxdir          directory relative to destdir where to place build aux files
5448 func_create_megatestdir ()
5449 {
5450   megatestdir="$1"
5451   allmodules="$2"
5452   if test -z "$allmodules"; then
5453     allmodules=`func_all_modules`
5454   fi
5455
5456   megasubdirs=
5457   # First, all modules one by one.
5458   for onemodule in $allmodules; do
5459     func_create_testdir "$megatestdir/$onemodule" $onemodule
5460     func_append megasubdirs "$onemodule "
5461   done
5462   # Then, all modules all together.
5463   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
5464   allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
5465   func_create_testdir "$megatestdir/ALL" "$allmodules"
5466   func_append megasubdirs "ALL"
5467
5468   # Create autobuild.
5469   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
5470              vc_witness="$gnulib_dir/CVS/Entries"; \
5471            else \
5472              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
5473            fi; \
5474            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
5475              | sed -e 's,January,01,'   -e 's,Jan,01,' \
5476                    -e 's,February,02,'  -e 's,Feb,02,' \
5477                    -e 's,March,03,'     -e 's,Mar,03,' \
5478                    -e 's,April,04,'     -e 's,Apr,04,' \
5479                    -e 's,May,05,'                      \
5480                    -e 's,June,06,'      -e 's,Jun,06,' \
5481                    -e 's,July,07,'      -e 's,Jul,07,' \
5482                    -e 's,August,08,'    -e 's,Aug,08,' \
5483                    -e 's,September,09,' -e 's,Sep,09,' \
5484                    -e 's,October,10,'   -e 's,Oct,10,' \
5485                    -e 's,November,11,'  -e 's,Nov,11,' \
5486                    -e 's,December,12,'  -e 's,Dec,12,' \
5487                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
5488                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
5489   (echo '#!/bin/sh'
5490    echo "CVSDATE=$cvsdate"
5491    echo ": \${MAKE=make}"
5492    echo "test -d logs || mkdir logs"
5493    echo "for module in $megasubdirs; do"
5494    echo "  echo \"Working on module \$module...\""
5495    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
5496    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
5497    echo "   echo"
5498    echo "   set -x"
5499    echo "   : autobuild project... \$module"
5500    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
5501    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
5502    echo "   : autobuild hostname... \`hostname\`"
5503    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && \$MAKE && \$MAKE check && \$MAKE distclean"
5504    echo "   echo rc=\$?"
5505    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
5506    echo "done"
5507   ) > "$megatestdir/do-autobuild"
5508   chmod a+x "$megatestdir/do-autobuild"
5509
5510   # Create Makefile.am.
5511   (echo "## Process this file with automake to produce Makefile.in."
5512    echo
5513    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
5514    echo
5515    echo "SUBDIRS = $megasubdirs"
5516    echo
5517    echo "EXTRA_DIST = do-autobuild"
5518   ) > "$megatestdir/Makefile.am"
5519
5520   # Create configure.ac.
5521   (echo "# Process this file with autoconf to produce a configure script."
5522    echo "AC_INIT([dummy], [0])"
5523    if test "$auxdir" != "."; then
5524      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5525    fi
5526    echo "AM_INIT_AUTOMAKE"
5527    echo
5528    echo "AC_PROG_MAKE_SET"
5529    echo
5530    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
5531    echo "AC_CONFIG_FILES([Makefile])"
5532    echo "AC_OUTPUT"
5533   ) > "$megatestdir/configure.ac"
5534
5535   # Create autogenerated files.
5536   (cd "$megatestdir"
5537    # Do not use "${AUTORECONF} --install", because autoreconf operates
5538    # recursively, but the subdirectories are already finished, therefore
5539    # calling autoreconf here would only waste lots of CPU time.
5540    func_execute_command ${ACLOCAL} || func_exit 1
5541    func_execute_command mkdir build-aux
5542    func_execute_command ${AUTOCONF} || func_exit 1
5543    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5544   ) || func_exit 1
5545 }
5546
5547 case $mode in
5548   "" )
5549     func_fatal_error "no mode specified" ;;
5550
5551   list )
5552     func_all_modules
5553     ;;
5554
5555   find )
5556     # sed expression that converts a literal to a basic regular expression.
5557     # Needs to handle . [ \ * ^ $.
5558     sed_literal_to_basic_regex='s/\\/\\\\/g
5559 s/\[/\\[/g
5560 s/\^/\\^/g
5561 s/\([.*$]\)/[\1]/g'
5562     for filename
5563     do
5564       if test -f "$gnulib_dir/$filename" \
5565          || { test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$filename"; }; then
5566         filename_anywhere_regex=`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`
5567         filename_line_regex='^'"$filename_anywhere_regex"'$'
5568         module_candidates=`
5569           {
5570             (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filename_line_regex" /dev/null | sed -e 's,^modules/,,')
5571             if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
5572               (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$,,')
5573             fi
5574           } \
5575             | func_sanitize_modulelist \
5576             | LC_ALL=C sort -u
5577           `
5578         for module in $module_candidates; do
5579           if func_get_filelist $module | grep "$filename_line_regex" > /dev/null; then
5580             echo $module
5581           fi
5582         done
5583       else
5584         func_warning "file $filename does not exist"
5585       fi
5586     done
5587     ;;
5588
5589   import | add-import | remove-import | update )
5590
5591     # Where to import.
5592     if test -z "$destdir"; then
5593       destdir=.
5594     fi
5595     test -d "$destdir" \
5596       || func_fatal_error "destination directory does not exist: $destdir"
5597
5598     # Prefer configure.ac to configure.in.
5599     if test -f "$destdir"/configure.ac; then
5600       configure_ac="$destdir/configure.ac"
5601     else
5602       if test -f "$destdir"/configure.in; then
5603         configure_ac="$destdir/configure.in"
5604       else
5605         func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
5606       fi
5607     fi
5608
5609     # Analyze configure.ac.
5610     guessed_auxdir="."
5611     guessed_libtool=false
5612     my_sed_traces='
5613       s,#.*$,,
5614       s,^dnl .*$,,
5615       s, dnl .*$,,
5616       /AC_CONFIG_AUX_DIR/ {
5617         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
5618       }
5619       /A[CM]_PROG_LIBTOOL/ {
5620         s,^.*$,guessed_libtool=true,p
5621       }'
5622     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
5623
5624     if test -z "$auxdir"; then
5625       auxdir="$guessed_auxdir"
5626     fi
5627
5628     # Determine where to apply func_import.
5629     if test "$mode" = import; then
5630       # Apply func_import to a particular gnulib directory.
5631       # The command line contains the complete specification; don't look at
5632       # the contents of gnulib-cache.m4.
5633       test -n "$supplied_libname" || supplied_libname=true
5634       test -n "$sourcebase" || sourcebase="lib"
5635       test -n "$m4base" || m4base="m4"
5636       test -n "$docbase" || docbase="doc"
5637       test -n "$testsbase" || testsbase="tests"
5638       test -n "$macro_prefix" || macro_prefix="gl"
5639       func_import "$*"
5640     else
5641       if test -n "$m4base"; then
5642         # Apply func_import to a particular gnulib directory.
5643         # Any number of additional modules can be given.
5644         if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
5645           # First use of gnulib in the given m4base.
5646           test -n "$supplied_libname" || supplied_libname=true
5647           test -n "$sourcebase" || sourcebase="lib"
5648           test -n "$docbase" || docbase="doc"
5649           test -n "$testsbase" || testsbase="tests"
5650           test -n "$macro_prefix" || macro_prefix="gl"
5651         fi
5652         func_import "$*"
5653       else
5654         # Apply func_import to all gnulib directories.
5655         # To get this list of directories, look at Makefile.am. (Not at
5656         # configure, because it may be omitted from version control. Also,
5657         # don't run "find $destdir -name gnulib-cache.m4", as it might be
5658         # too expensive.)
5659         m4dirs=
5660         m4dirs_count=0
5661         if test -f "$destdir"/Makefile.am; then
5662           aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[        ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
5663           m4dir_is_next=
5664           for arg in $aclocal_amflags; do
5665             if test -n "$m4dir_is_next"; then
5666               # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
5667               case "$arg" in
5668                 /*) ;;
5669                 *)
5670                   if test -f "$destdir/$arg"/gnulib-cache.m4; then
5671                     func_append m4dirs " $arg"
5672                     m4dirs_count=`expr $m4dirs_count + 1`
5673                   fi
5674                   ;;
5675               esac
5676               m4dir_is_next=
5677             else
5678               if test "X$arg" = "X-I"; then
5679                 m4dir_is_next=yes
5680               else
5681                 m4dir_is_next=
5682               fi
5683             fi
5684           done
5685         else
5686           # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
5687           if test -f "$destdir"/aclocal.m4; then
5688             sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
5689             sedexpr2='s,^[^/]*$,.,'
5690             sedexpr3='s,/[^/]*$,,'
5691             m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
5692             m4dirs=`for arg in $m4dirs; do if test -f "$destdir/$arg"/gnulib-cache.m4; then echo $arg; fi; done`
5693             m4dirs_count=`for arg in $m4dirs; do echo "$arg"; done | wc -l`
5694           fi
5695         fi
5696         if test $m4dirs_count = 0; then
5697           # First use of gnulib in a package.
5698           # Any number of additional modules can be given.
5699           test -n "$supplied_libname" || supplied_libname=true
5700           test -n "$sourcebase" || sourcebase="lib"
5701           m4base="m4"
5702           test -n "$docbase" || docbase="doc"
5703           test -n "$testsbase" || testsbase="tests"
5704           test -n "$macro_prefix" || macro_prefix="gl"
5705           func_import "$*"
5706         else
5707           if test $m4dirs_count = 1; then
5708             # There's only one use of gnulib here. Assume the user means it.
5709             # Any number of additional modules can be given.
5710             for m4base in $m4dirs; do
5711               func_import "$*"
5712             done
5713           else
5714             # Ambiguous - guess what the user meant.
5715             if test $# = 0; then
5716               # No further arguments. Guess the user wants to update all of them.
5717               for m4base in $m4dirs; do
5718                 # Perform func_import in a subshell, so that variable values
5719                 # such as
5720                 #   local_gnulib_dir, incobsolete, inc_cxx_tests,
5721                 #   inc_longrunning_tests, inc_privileged_tests,
5722                 #   inc_unportable_tests, inc_all_tests, avoidlist, sourcebase,
5723                 #   m4base, pobase, docbase, testsbase, inctests, libname, lgpl,
5724                 #   makefile_name, libtool, macro_prefix, po_domain, vc_files
5725                 # don't propagate from one directory to another.
5726                 (func_import) || func_exit 1
5727               done
5728             else
5729               # Really ambiguous.
5730               func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
5731             fi
5732           fi
5733         fi
5734       fi
5735     fi
5736     ;;
5737
5738   create-testdir )
5739     if test -z "$destdir"; then
5740       func_fatal_error "please specify --dir option"
5741     fi
5742     mkdir "$destdir"
5743     test -d "$destdir" \
5744       || func_fatal_error "could not create destination directory"
5745     test -n "$auxdir" || auxdir="build-aux"
5746     func_create_testdir "$destdir" "$*"
5747     ;;
5748
5749   create-megatestdir )
5750     if test -z "$destdir"; then
5751       func_fatal_error "please specify --dir option"
5752     fi
5753     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5754     test -n "$auxdir" || auxdir="build-aux"
5755     func_create_megatestdir "$destdir" "$*"
5756     ;;
5757
5758   test )
5759     test -n "$destdir" || destdir=testdir$$
5760     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5761     test -n "$auxdir" || auxdir="build-aux"
5762     func_create_testdir "$destdir" "$*"
5763     cd "$destdir"
5764       mkdir build
5765       cd build
5766         ../configure || func_exit 1
5767         $MAKE || func_exit 1
5768         $MAKE check || func_exit 1
5769         $MAKE distclean || func_exit 1
5770         remaining=`find . -type f -print`
5771         if test -n "$remaining"; then
5772           echo "Remaining files:" $remaining 1>&2
5773           echo "gnulib-tool: *** Stop." 1>&2
5774           func_exit 1
5775         fi
5776       cd ..
5777     cd ..
5778     rm -rf "$destdir"
5779     ;;
5780
5781   megatest )
5782     test -n "$destdir" || destdir=testdir$$
5783     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5784     test -n "$auxdir" || auxdir="build-aux"
5785     func_create_megatestdir "$destdir" "$*"
5786     cd "$destdir"
5787       mkdir build
5788       cd build
5789         ../configure
5790         $MAKE
5791         $MAKE check
5792         $MAKE distclean
5793         remaining=`find . -type f -print`
5794         if test -n "$remaining"; then
5795           echo "Remaining files:" $remaining 1>&2
5796           echo "gnulib-tool: *** Stop." 1>&2
5797           func_exit 1
5798         fi
5799       cd ..
5800     cd ..
5801     rm -rf "$destdir"
5802     ;;
5803
5804   extract-description )
5805     for module
5806     do
5807       func_verify_module
5808       if test -n "$module"; then
5809         func_get_description "$module"
5810       fi
5811     done
5812     ;;
5813
5814   extract-comment )
5815     for module
5816     do
5817       func_verify_module
5818       if test -n "$module"; then
5819         func_get_comment "$module"
5820       fi
5821     done
5822     ;;
5823
5824   extract-status )
5825     for module
5826     do
5827       func_verify_module
5828       if test -n "$module"; then
5829         func_get_status "$module"
5830       fi
5831     done
5832     ;;
5833
5834   extract-notice )
5835     for module
5836     do
5837       func_verify_module
5838       if test -n "$module"; then
5839         func_get_notice "$module"
5840       fi
5841     done
5842     ;;
5843
5844   extract-applicability )
5845     for module
5846     do
5847       func_verify_module
5848       if test -n "$module"; then
5849         func_get_applicability "$module"
5850       fi
5851     done
5852     ;;
5853
5854   extract-filelist )
5855     for module
5856     do
5857       func_verify_module
5858       if test -n "$module"; then
5859         func_get_filelist "$module"
5860       fi
5861     done
5862     ;;
5863
5864   extract-dependencies )
5865     for module
5866     do
5867       func_verify_module
5868       if test -n "$module"; then
5869         func_get_dependencies "$module"
5870       fi
5871     done
5872     ;;
5873
5874   extract-autoconf-snippet )
5875     for module
5876     do
5877       func_verify_module
5878       if test -n "$module"; then
5879         func_get_autoconf_snippet "$module"
5880       fi
5881     done
5882     ;;
5883
5884   extract-automake-snippet )
5885     for module
5886     do
5887       func_verify_module
5888       if test -n "$module"; then
5889         func_get_automake_snippet "$module"
5890       fi
5891     done
5892     ;;
5893
5894   extract-include-directive )
5895     for module
5896     do
5897       func_verify_module
5898       if test -n "$module"; then
5899         func_get_include_directive "$module"
5900       fi
5901     done
5902     ;;
5903
5904   extract-link-directive )
5905     for module
5906     do
5907       func_verify_module
5908       if test -n "$module"; then
5909         func_get_link_directive "$module"
5910       fi
5911     done
5912     ;;
5913
5914   extract-license )
5915     for module
5916     do
5917       func_verify_module
5918       if test -n "$module"; then
5919         func_get_license "$module"
5920       fi
5921     done
5922     ;;
5923
5924   extract-maintainer )
5925     for module
5926     do
5927       func_verify_module
5928       if test -n "$module"; then
5929         func_get_maintainer "$module"
5930       fi
5931     done
5932     ;;
5933
5934   extract-tests-module )
5935     for module
5936     do
5937       func_verify_module
5938       if test -n "$module"; then
5939         func_get_tests_module "$module"
5940       fi
5941     done
5942     ;;
5943
5944   copy-file )
5945     # Verify the number of arguments.
5946     if test $# -lt 1 || test $# -gt 2; then
5947       func_fatal_error "invalid number of arguments for --$mode"
5948     fi
5949
5950     # The first argument is the file to be copied.
5951     f="$1"
5952     # Verify the file exists.
5953     func_lookup_file "$f"
5954
5955     # The second argument is the destination; either a directory ot a file.
5956     # It defaults to the current directory.
5957     dest="$2"
5958     test -n "$dest" || dest='.'
5959     test -n "$sourcebase" || sourcebase="lib"
5960     test -n "$m4base" || m4base="m4"
5961     test -n "$docbase" || docbase="doc"
5962     test -n "$testsbase" || testsbase="tests"
5963     test -n "$auxdir" || auxdir="build-aux"
5964     rewritten='%REWRITTEN%'
5965     sed_rewrite_files="\
5966       s,^build-aux/,$rewritten$auxdir/,
5967       s,^doc/,$rewritten$docbase/,
5968       s,^lib/,$rewritten$sourcebase/,
5969       s,^m4/,$rewritten$m4base/,
5970       s,^tests/,$rewritten$testsbase/,
5971       s,^top/,$rewritten,
5972       s,^$rewritten,,"
5973     if test -d "$dest"; then
5974       destdir="$dest"
5975       g=`echo "$f" | sed -e "$sed_rewrite_files"`
5976     else
5977       destdir=`dirname "$dest"`
5978       g=`basename "$dest"`
5979     fi
5980
5981     # Create the directory for destfile.
5982     d=`dirname "$destdir/$g"`
5983     if $doit; then
5984       if test -n "$d" && test ! -d "$d"; then
5985         mkdir -p "$d" || func_fatal_error "failed"
5986       fi
5987     fi
5988     # Copy the file.
5989     func_dest_tmpfilename "$g"
5990     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
5991     already_present=true
5992     if test -f "$destdir/$g"; then
5993       # The file already exists.
5994       func_update_file
5995     else
5996       # Install the file.
5997       # Don't protest if the file should be there but isn't: it happens
5998       # frequently that developers don't put autogenerated files under version
5999       # control.
6000       func_add_file
6001     fi
6002     rm -f "$tmpfile"
6003     ;;
6004
6005   * )
6006     func_fatal_error "unknown operation mode --$mode" ;;
6007 esac
6008
6009 rm -rf "$tmp"
6010 # Undo the effect of the previous 'trap' command. Some shellology:
6011 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
6012 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
6013 # exit); for the others we need to call 'exit' explicitly. The value of $? is
6014 # 128 + signal number and is set before the trap-registered command is run.
6015 trap '' 0
6016 trap 'func_exit $?' 1 2 3 13 15
6017
6018 exit 0
6019
6020 # Local Variables:
6021 # indent-tabs-mode: nil
6022 # whitespace-check-buffer-indent: nil
6023 # End: