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