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