add lgpl-3.0.texi; have all Texinfo licenses consistently omit any sectioning and...
[pspp] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2007 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 2, or (at your option)
8 # 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, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19
20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages.
22
23 progname=$0
24 package=gnulib
25 cvsdatestamp='$Date: 2007-07-14 01:42:14 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
28 nl='
29 '
30 IFS=" ""        $nl"
31
32 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
33 AUTOCONFPATH=
34 #case $USER in
35 #  bruno )
36 #    AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
37 #    AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
38 #    ;;
39 #esac
40
41 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
42 AUTOMAKEPATH=
43
44 # You can set GETTEXTPATH to empty if autopoint 0.15 is already in your PATH.
45 GETTEXTPATH=
46
47 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
48 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
49 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
50   AUTOCONF="${AUTOCONFPATH}autoconf"
51 fi
52 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
53   AUTOHEADER="${AUTOCONFPATH}autoheader"
54 fi
55 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
56   ACLOCAL="${AUTOMAKEPATH}aclocal"
57 fi
58 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
59   AUTOMAKE="${AUTOMAKEPATH}automake"
60 fi
61 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
62   AUTORECONF="${AUTOCONFPATH}autoreconf"
63 fi
64
65 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
66 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
67   AUTOPOINT="${GETTEXTPATH}autopoint"
68 fi
69
70 # When using GNU sed, turn off as many GNU extensions as possible,
71 # to minimize the risk of accidentally using non-portable features.
72 # However, do this only for gnulib-tool itself, not for the code that
73 # gnulib-tool generates, since we don't want "sed --posix" to leak
74 # into makefiles.
75 if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then
76   alias sed='sed --posix'
77 fi
78
79 # func_usage
80 # outputs to stdout the --help usage message.
81 func_usage ()
82 {
83   echo "\
84 Usage: gnulib-tool --list
85        gnulib-tool --import [module1 ... moduleN]
86        gnulib-tool --update
87        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
88        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
89        gnulib-tool --test --dir=directory module1 ... moduleN
90        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
91        gnulib-tool --extract-description module
92        gnulib-tool --extract-filelist module
93        gnulib-tool --extract-dependencies module
94        gnulib-tool --extract-autoconf-snippet module
95        gnulib-tool --extract-automake-snippet module
96        gnulib-tool --extract-include-directive module
97        gnulib-tool --extract-link-directive module
98        gnulib-tool --extract-license module
99        gnulib-tool --extract-maintainer module
100        gnulib-tool --extract-tests-module module
101
102 Operation modes:
103       --list                print the available module names
104       --import              import the given modules into the current package;
105                             if no modules are specified, update the current
106                             package from the current gnulib
107       --update              update the current package, restore files omitted
108                             from CVS
109       --create-testdir      create a scratch package with the given modules
110       --create-megatestdir  create a mega scratch package with the given modules
111                             one by one and all together
112       --test                test the combination of the given modules
113                             (recommended to use CC=\"gcc -Wall\" here)
114       --megatest            test the given modules one by one and all together
115                             (recommended to use CC=\"gcc -Wall\" here)
116       --extract-description        extract the description
117       --extract-filelist           extract the list of files
118       --extract-dependencies       extract the dependencies
119       --extract-autoconf-snippet   extract the snippet for configure.ac
120       --extract-automake-snippet   extract the snippet for library makefile
121       --extract-include-directive  extract the #include directive
122       --extract-link-directive     extract the linker directive
123       --extract-license            report the license terms of the source files
124                                    under lib/
125       --extract-maintainer         report the maintainer(s) inside gnulib
126       --extract-tests-module       report the unit test module, if it exists
127
128 General options:
129       --dir=DIRECTORY       Specify the target directory.
130                             For --import, this specifies where your
131                             configure.ac can be found.  Defaults to current
132                             directory.
133       --local-dir=DIRECTORY  Specify a local override directory where to look
134                             up files before looking in gnulib's directory.
135
136 Options for --import:
137       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
138       --source-base=DIRECTORY
139                             Directory relative to --dir where source code is
140                             placed (default \"lib\").
141       --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
142                             placed (default \"m4\").
143       --doc-base=DIRECTORY  Directory relative to --dir where doc files are
144                             placed (default \"doc\").
145       --tests-base=DIRECTORY
146                             Directory relative to --dir where unit tests are
147                             placed (default \"tests\").
148       --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
149                             tools are placed (default \"build-aux\").
150       --with-tests          Include unit tests for the included modules.
151       --avoid=MODULE        Avoid including the given MODULE. Useful if you
152                             have code that provides equivalent functionality.
153                             This option can be repeated.
154       --lgpl                Abort if modules aren't available under the LGPL.
155                             Also modify license template from GPL to LGPL.
156       --makefile-name=NAME  Name of makefile in automake syntax in the
157                             source-base and tests-base directories
158                             (default \"Makefile.am\").
159       --libtool             Use libtool rules.
160       --no-libtool          Don't use libtool rules.
161       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
162                             'gl_INIT'. Default is 'gl'.
163       --no-changelog        don't update or create ChangeLog files
164
165 Options for --import and --update:
166       --dry-run             For --import, only print what would have been done.
167   -s, --symbolic, --symlink Make symbolic links instead of copying files.
168       --local-symlink       Make symbolic links instead of copying files, only
169                             for files from the local override directory.
170   -S, --more-symlinks       Make symbolic links instead of copying files, and
171                             don't replace copyright notices.
172
173 Report bugs to <bug-gnulib@gnu.org>."
174 }
175
176 # func_version
177 # outputs to stdout the --version message.
178 func_version ()
179 {
180   year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
181   echo "\
182 $progname (GNU $package) $version
183 Copyright (C) $year Free Software Foundation, Inc.
184 This is free software; see the source for copying conditions.  There is NO
185 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
186 Written by" "Bruno Haible" "and" "Simon Josefsson"
187 }
188
189 # func_emit_copyright_notice
190 # outputs to stdout a header for a generated file.
191 func_emit_copyright_notice ()
192 {
193   echo "# Copyright (C) 2004-2007 Free Software Foundation, Inc."
194   echo "#"
195   echo "# This file is free software, distributed under the terms of the GNU"
196   echo "# General Public License.  As a special exception to the GNU General"
197   echo "# Public License, this file may be distributed as part of a program"
198   echo "# that contains a configuration script generated by Autoconf, under"
199   echo "# the same distribution terms as the rest of that program."
200   echo "#"
201   echo "# Generated by gnulib-tool."
202 }
203
204 # func_exit STATUS
205 # exit with status
206 func_exit ()
207 {
208   (exit $1); exit $1
209 }
210
211 # func_tmpdir
212 # creates a temporary directory.
213 # Sets variable
214 # - tmp             pathname of freshly created temporary directory
215 func_tmpdir ()
216 {
217   # Use the environment variable TMPDIR, falling back to /tmp. This allows
218   # users to specify a different temporary directory, for example, if their
219   # /tmp is filled up or too small.
220   : ${TMPDIR=/tmp}
221   {
222     # Use the mktemp program if available. If not available, hide the error
223     # message.
224     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
225     test -n "$tmp" && test -d "$tmp"
226   } ||
227   {
228     # Use a simple mkdir command. It is guaranteed to fail if the directory
229     # already exists.  $RANDOM is bash specific and expands to empty in shells
230     # other than bash, ksh and zsh.  Its use does not increase security;
231     # rather, it minimizes the probability of failure in a very cluttered /tmp
232     # directory.
233     tmp=$TMPDIR/gl$$-$RANDOM
234     (umask 077 && mkdir "$tmp")
235   } ||
236   {
237     echo "$0: cannot create a temporary directory in $TMPDIR" >&2
238     func_exit 1
239   }
240 }
241
242 # func_append var value
243 # appends the given value to the shell variable var.
244 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
245   # Use bash's += operator. It reduces complexity of appending repeatedly to
246   # a single variable from O(n^2) to O(n).
247   func_append ()
248   {
249     eval "$1+=\"\$2\""
250   }
251 else
252   func_append ()
253   {
254     eval "$1=\"\$$1\$2\""
255   }
256 fi
257
258 # func_fatal_error message
259 # outputs to stderr a fatal error message, and terminates the program.
260 func_fatal_error ()
261 {
262   echo "gnulib-tool: *** $1" 1>&2
263   echo "gnulib-tool: *** Stop." 1>&2
264   func_exit 1
265 }
266
267 # func_readlink SYMLINK
268 # outputs the target of the given symlink.
269 if (type -p readlink) > /dev/null 2>&1; then
270   func_readlink ()
271   {
272     # Use the readlink program from GNU coreutils.
273     readlink "$1"
274   }
275 else
276   func_readlink ()
277   {
278     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
279     # would do the wrong thing if the link target contains " -> ".
280     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
281   }
282 fi
283
284 # func_relativize DIR1 DIR2
285 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
286 # Input:
287 # - DIR1            relative pathname, relative to the current directory
288 # - DIR2            relative pathname, relative to the current directory
289 # Output:
290 # - reldir          relative pathname of DIR2, relative to DIR1
291 func_relativize ()
292 {
293   dir0=`pwd`
294   dir1="$1"
295   dir2="$2"
296   sed_first='s,^\([^/]*\)/.*$,\1,'
297   sed_rest='s,^[^/]*/*,,'
298   sed_last='s,^.*/\([^/]*\)$,\1,'
299   sed_butlast='s,/*[^/]*$,,'
300   while test -n "$dir1"; do
301     first=`echo "$dir1" | sed -e "$sed_first"`
302     if test "$first" != "."; then
303       if test "$first" = ".."; then
304         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
305         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
306       else
307         first2=`echo "$dir2" | sed -e "$sed_first"`
308         if test "$first2" = "$first"; then
309           dir2=`echo "$dir2" | sed -e "$sed_rest"`
310         else
311           dir2="../$dir2"
312         fi
313         dir0="$dir0"/"$first"
314       fi
315     fi
316     dir1=`echo "$dir1" | sed -e "$sed_rest"`
317   done
318   reldir="$dir2"
319 }
320
321 # func_relconcat DIR1 DIR2
322 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
323 # Input:
324 # - DIR1            relative pathname, relative to the current directory
325 # - DIR2            relative pathname, relative to DIR1
326 # Output:
327 # - relconcat       DIR1/DIR2, relative to the current directory
328 func_relconcat ()
329 {
330   dir1="$1"
331   dir2="$2"
332   sed_first='s,^\([^/]*\)/.*$,\1,'
333   sed_rest='s,^[^/]*/*,,'
334   sed_last='s,^.*/\([^/]*\)$,\1,'
335   sed_butlast='s,/*[^/]*$,,'
336   while true; do
337     first=`echo "$dir2" | sed -e "$sed_first"`
338     if test "$first" = "."; then
339       dir2=`echo "$dir2" | sed -e "$sed_rest"`
340       if test -z "$dir2"; then
341         relconcat="$dir1"
342         break
343       fi
344     else
345       last=`echo "$dir1" | sed -e "$sed_last"`
346       while test "$last" = "."; do
347         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
348         last=`echo "$dir1" | sed -e "$sed_last"`
349       done
350       if test -z "$dir1"; then
351         relconcat="$dir2"
352         break
353       fi
354       if test "$first" = ".."; then
355         if test "$last" = ".."; then
356           relconcat="$dir1/$dir2"
357           break
358         fi
359         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
360         dir2=`echo "$dir2" | sed -e "$sed_rest"`
361         if test -z "$dir1"; then
362           relconcat="$dir2"
363           break
364         fi
365         if test -z "$dir2"; then
366           relconcat="$dir1"
367           break
368         fi
369       else
370         relconcat="$dir1/$dir2"
371         break
372       fi
373     fi
374   done
375 }
376
377 # func_ln SRC DEST
378 # Like ln -s, except that SRC is given relative to the current directory (or
379 # absolute), not given relative to the directory of DEST.
380 func_ln ()
381 {
382   case "$1" in
383     /*)
384       ln -s "$1" "$2" ;;
385     *) # SRC is relative.
386       case "$2" in
387         /*)
388           ln -s "`pwd`/$1" "$2" ;;
389         *) # DEST is relative too.
390           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
391           test -n "$ln_destdir" || ln_destdir="."
392           func_relativize "$ln_destdir" "$1"
393           ln -s "$reldir" "$2"
394           ;;
395       esac
396       ;;
397   esac
398 }
399
400 # func_ln_if_changed SRC DEST
401 # Like func_ln, but avoids munging timestamps if the link is correct.
402 func_ln_if_changed ()
403 {
404   if test $# -ne 2; then
405     echo "usage: func_ln_if_changed SRC DEST" >&2
406   fi
407   ln_target=`func_readlink "$2"`
408   if test -L "$2" && test "$1" = "$ln_target"; then
409     :
410   else
411     rm -f "$2"
412     func_ln "$1" "$2"
413   fi
414 }
415
416 # Ensure an 'echo' command that does not interpret backslashes.
417 # Test cases:
418 #   echo '\n' | wc -l                 prints 1 when OK, 2 when KO
419 #   echo '\t' | grep t > /dev/null    has return code 0 when OK, 1 when KO
420 # This problem is a weird heritage from SVR4. BSD got it right (except that
421 # BSD echo interprets '-n' as an option, which is also not desirable).
422 # Nowadays the problem occurs in 4 situations:
423 # - in bash, when the shell option xpg_echo is set (bash >= 2.04)
424 #            or when it was built with --enable-usg-echo-default (bash >= 2.0)
425 #            or when it was built with DEFAULT_ECHO_TO_USG (bash < 2.0),
426 # - in zsh, when sh-emulation is not set,
427 # - in ksh (e.g. AIX /bin/sh and Solaris /usr/xpg4/bin/sh are ksh instances,
428 #           and HP-UX /bin/sh and IRIX /bin/sh behave similarly),
429 # - in Solaris /bin/sh and OSF/1 /bin/sh.
430 # We try the following workarounds:
431 # - for all: respawn using $CONFIG_SHELL if that is set and works.
432 # - for bash >= 2.04: unset the shell option xpg_echo.
433 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
434 # - for bash < 2.0: define echo to a function that uses cat of a here document.
435 # - for zsh: turn sh-emulation on.
436 # - for ksh: alias echo to 'print -r'.
437 # - for ksh: alias echo to a function that uses cat of a here document.
438 # - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
439 #   the ksh workaround.
440 # - otherwise: respawn using /bin/sh and rely on the workarounds.
441 # When respawning, we pass --no-reexec as first argument, so as to avoid
442 # turning this script into a fork bomb in unlucky situations.
443 have_echo=
444 if echo '\t' | grep t > /dev/null; then
445   have_echo=yes # Lucky!
446 fi
447 # Try the workarounds.
448 # Respawn using $CONFIG_SHELL if that is set and works.
449 if test -z "$have_echo" \
450    && test "X$1" != "X--no-reexec" \
451    && test -n "$CONFIG_SHELL" \
452    && test -f "$CONFIG_SHELL" \
453    && $CONFIG_SHELL -c 'echo '\t' | grep t > /dev/null'; then
454   exec $CONFIG_SHELL "$0" --no-reexec "$@"
455   exit 127
456 fi
457 # For bash >= 2.04: unset the shell option xpg_echo.
458 if test -z "$have_echo" \
459    && test -n "$BASH_VERSION" \
460    && (shopt -o xpg_echo; echo '\t' | grep t > /dev/null) 2>/dev/null; then
461   shopt -o xpg_echo
462   have_echo=yes
463 fi
464 # For bash >= 2.0: define echo to a function that uses the printf built-in.
465 # For bash < 2.0: define echo to a function that uses cat of a here document.
466 # (There is no win in using 'printf' over 'cat' if it is not a shell built-in.)
467 if test -z "$have_echo" \
468    && test -n "$BASH_VERSION"; then \
469   if type printf 2>/dev/null | grep / > /dev/null; then
470     # 'printf' is not a shell built-in.
471 echo ()
472 {
473 cat <<EOF
474 $*
475 EOF
476 }
477   else
478     # 'printf' is a shell built-in.
479 echo ()
480 {
481   printf '%s\n' "$*"
482 }
483   fi
484   if echo '\t' | grep t > /dev/null; then
485     have_echo=yes
486   fi
487 fi
488 # For zsh: turn sh-emulation on.
489 if test -z "$have_echo" \
490    && test -n "$ZSH_VERSION" \
491    && (emulate sh) >/dev/null 2>&1; then
492   emulate sh
493 fi
494 # For ksh: alias echo to 'print -r'.
495 if test -z "$have_echo" \
496    && (type print) >/dev/null 2>&1; then
497   # A 'print' command exists.
498   if type print 2>/dev/null | grep / > /dev/null; then
499     :
500   else
501     # 'print' is a shell built-in.
502     if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
503       # 'print' is the ksh shell built-in.
504       alias echo='print -r'
505     fi
506   fi
507 fi
508 if test -z "$have_echo" \
509    && echo '\t' | grep t > /dev/null; then
510   have_echo=yes
511 fi
512 # For ksh: alias echo to a function that uses cat of a here document.
513 # The ksh manual page says:
514 #   "Aliasing is performed when scripts are read, not while they are executed.
515 #    Therefore, for an alias to take effect, the alias definition command has
516 #    to be executed before the command which references the alias is read."
517 # Because of this, we have to play strange tricks with have_echo, to ensure
518 # that the top-level statement containing the test starts after the 'alias'
519 # command.
520 if test -z "$have_echo"; then
521 bsd_echo ()
522 {
523 cat <<EOF
524 $*
525 EOF
526 }
527 alias echo=bsd_echo 2>/dev/null
528 fi
529 if test -z "$have_echo" \
530    && echo '\t' | grep t > /dev/null; then
531   have_echo=yes
532 fi
533 if test -z "$have_echo"; then
534   unalias echo 2>/dev/null
535 fi
536 # For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
537 if test -z "$have_echo" \
538    && test "X$1" != "X--no-reexec" \
539    && test -f /bin/ksh; then
540   exec /bin/ksh "$0" --no-reexec "$@"
541   exit 127
542 fi
543 # Otherwise: respawn using /bin/sh.
544 if test -z "$have_echo" \
545    && test "X$1" != "X--no-reexec" \
546    && test -f /bin/sh; then
547   exec /bin/sh "$0" --no-reexec "$@"
548   exit 127
549 fi
550 if test -z "$have_echo"; then
551   func_fatal_error "Shell does not support 'echo' correctly. Please install GNU bash and set the environment variable CONFIG_SHELL to point to it."
552 fi
553 if echo '\t' | grep t > /dev/null; then
554   : # Works fine now.
555 else
556   func_fatal_error "Shell does not support 'echo' correctly. Workaround does not work. Please report this as a bug to bug-gnulib@gnu.org."
557 fi
558 if test "X$1" = "X--no-reexec"; then
559   shift
560 fi
561
562 # Command-line option processing.
563 # Removes the OPTIONS from the arguments. Sets the variables:
564 # - mode            list or import or create-testdir or create-megatestdir
565 # - destdir         from --dir
566 # - local_gnulib_dir  from --local-dir
567 # - libname, supplied_libname  from --lib
568 # - sourcebase      from --source-base
569 # - m4base          from --m4-base
570 # - docbase         from --doc-base
571 # - testsbase       from --tests-base
572 # - auxdir          from --aux-dir
573 # - inctests        true if --with-tests was given, blank otherwise
574 # - avoidlist       list of modules to avoid, from --avoid
575 # - lgpl            true if --lgpl was given, blank otherwise
576 # - makefile_name   from --makefile-name
577 # - libtool         true if --libtool was given, false if --no-libtool was
578 #                   given, blank otherwise
579 # - macro_prefix    from --macro-prefix
580 # - autoconf_minversion  minimum supported autoconf version
581 # - do_changelog    false if --no-changelog was given, : otherwise
582 # - doit            : if actions shall be executed, false if only to be printed
583 # - symbolic        true if --symlink or --more-symlinks was given, blank
584 #                   otherwise
585 # - lsymbolic       true if --local-symlink was given, blank otherwise
586 # - do_copyrights   blank if --more-symlinks was given, true otherwise
587 {
588   mode=
589   destdir=
590   local_gnulib_dir=
591   libname=libgnu
592   supplied_libname=
593   sourcebase=
594   m4base=
595   docbase=
596   testsbase=
597   auxdir=
598   inctests=
599   avoidlist=
600   lgpl=
601   makefile_name=
602   libtool=
603   macro_prefix=
604   do_changelog=:
605   doit=:
606   symbolic=
607   lsymbolic=
608   do_copyrights=true
609
610   supplied_opts="$@"
611
612   while test $# -gt 0; do
613     case "$1" in
614       --list | --lis )
615         mode=list
616         shift ;;
617       --import | --impor | --impo | --imp | --im | --i )
618         mode=import
619         shift ;;
620       --update | --updat | --upda | --upd | --up | --u )
621         mode=update
622         shift ;;
623       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
624         mode=create-testdir
625         shift ;;
626       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
627         mode=create-megatestdir
628         shift ;;
629       --test | --tes | --te | --t )
630         mode=test
631         shift ;;
632       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
633         mode=megatest
634         shift ;;
635       --extract-* )
636         mode=`echo "X$1" | sed -e 's/^X--//'`
637         shift ;;
638       --dir )
639         shift
640         if test $# = 0; then
641           func_fatal_error "missing argument for --dir"
642         fi
643         destdir=$1
644         shift ;;
645       --dir=* )
646         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
647         shift ;;
648       --local-dir )
649         shift
650         if test $# = 0; then
651           func_fatal_error "missing argument for --local-dir"
652         fi
653         local_gnulib_dir=$1
654         shift ;;
655       --local-dir=* )
656         local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
657         shift ;;
658       --lib )
659         shift
660         if test $# = 0; then
661           func_fatal_error "missing argument for --lib"
662         fi
663         libname=$1
664         supplied_libname=true
665         shift ;;
666       --lib=* )
667         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
668         supplied_libname=true
669         shift ;;
670       --source-base )
671         shift
672         if test $# = 0; then
673           func_fatal_error "missing argument for --source-base"
674         fi
675         sourcebase=$1
676         shift ;;
677       --source-base=* )
678         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
679         shift ;;
680       --m4-base )
681         shift
682         if test $# = 0; then
683           func_fatal_error "missing argument for --m4-base"
684         fi
685         m4base=$1
686         shift ;;
687       --m4-base=* )
688         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
689         shift ;;
690       --doc-base )
691         shift
692         if test $# = 0; then
693           func_fatal_error "missing argument for --doc-base"
694         fi
695         docbase=$1
696         shift ;;
697       --doc-base=* )
698         docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
699         shift ;;
700       --tests-base )
701         shift
702         if test $# = 0; then
703           func_fatal_error "missing argument for --tests-base"
704         fi
705         testsbase=$1
706         shift ;;
707       --tests-base=* )
708         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
709         shift ;;
710       --aux-dir )
711         shift
712         if test $# = 0; then
713           func_fatal_error "missing argument for --aux-dir"
714         fi
715         auxdir=$1
716         shift ;;
717       --aux-dir=* )
718         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
719         shift ;;
720       --with-tests )
721         inctests=true
722         shift ;;
723       --avoid )
724         shift
725         if test $# = 0; then
726           func_fatal_error "missing argument for --avoid"
727         fi
728         func_append avoidlist " $1"
729         shift ;;
730       --avoid=* )
731         arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
732         func_append avoidlist " $arg"
733         shift ;;
734       --lgpl )
735         lgpl=true
736         shift ;;
737       --makefile-name )
738         shift
739         if test $# = 0; then
740           func_fatal_error "missing argument for --makefile-name"
741         fi
742         makefile_name="$1"
743         shift ;;
744       --makefile-name=* )
745         makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
746         shift ;;
747       --libtool )
748         libtool=true
749         shift ;;
750       --no-libtool )
751         libtool=false
752         shift ;;
753       --macro-prefix )
754         shift
755         if test $# = 0; then
756           func_fatal_error "missing argument for --macro-prefix"
757         fi
758         macro_prefix="$1"
759         shift ;;
760       --macro-prefix=* )
761         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
762         shift ;;
763       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
764         do_changelog=false
765         shift ;;
766       --dry-run )
767         doit=false
768         shift ;;
769       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
770         symbolic=true
771         shift ;;
772       --local-symlink | --local-symlin | --local-symli | --local-syml | --local-sym | --local-sy | --local-s )
773         lsymbolic=true
774         shift ;;
775       -S | --more-symlinks | --more-symlink | --more-symlin | --more-symli | --more-syml | --more-sym | --more-sy | --more-s | --more- | --more | --mor | --mo )
776         symbolic=true
777         do_copyrights=
778         shift ;;
779       --help | --hel | --he | --h )
780         func_usage
781         func_exit $? ;;
782       --version | --versio | --versi | --vers | --ver | --ve | --v )
783         func_version
784         func_exit $? ;;
785       -- )
786         # Stop option processing
787         shift
788         break ;;
789       -* )
790         echo "gnulib-tool: unknown option $1" 1>&2
791         echo "Try 'gnulib-tool --help' for more information." 1>&2
792         func_exit 1 ;;
793       * )
794         break ;;
795     esac
796   done
797
798   if test "$mode" = update; then
799     if test $# != 0; then
800       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
801       echo "Try 'gnulib-tool --help' for more information." 1>&2
802       echo "If you really want to modify the gnulib configuration of your project," 1>&2
803       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
804       func_exit 1
805     fi
806     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
807        || test -n "$sourcebase" || test -n "$m4base" \
808        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
809        || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
810        || test -n "$makefile_name" || test -n "$macro_prefix"; then
811       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
812       echo "Try 'gnulib-tool --help' for more information." 1>&2
813       echo "If you really want to modify the gnulib configuration of your project," 1>&2
814       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
815       func_exit 1
816     fi
817     do_changelog=false
818   fi
819
820   # Determine the minimum supported autoconf version from the project's
821   # configure.ac.
822   DEFAULT_AUTOCONF_MINVERSION="2.59"
823   autoconf_minversion=
824   configure_ac=
825   if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
826     if test -f "$destdir"/configure.ac; then
827       configure_ac="$destdir/configure.ac"
828     else
829       if test -f "$destdir"/configure.in; then
830         configure_ac="$destdir/configure.in"
831       fi
832     fi
833   else
834     if test -f configure.ac; then
835       configure_ac="configure.ac"
836     else
837       if test -f configure.in; then
838         configure_ac="configure.in"
839       fi
840     fi
841   fi
842   if test -n "$configure_ac"; then
843     # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
844     # because when some m4 files are omitted from a CVS repository,
845     # "autoconf --trace=AC_PREREQ" fails with an error message like this:
846     #   m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
847     #   autom4te: m4 failed with exit status: 1
848     prereqs=
849     my_sed_traces='
850       s,#.*$,,
851       s,^dnl .*$,,
852       s, dnl .*$,,
853       /AC_PREREQ/ {
854         s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,\1,p
855       }'
856     prereqs=`sed -n -e "$my_sed_traces" < "$configure_ac"`
857     if test -n "$prereqs"; then
858       autoconf_minversion=`
859         for version in $prereqs; do echo $version; done |
860         LC_ALL=C sort -nru | sed 1q
861       `
862     fi
863   fi
864   if test -z "$autoconf_minversion"; then
865     autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
866   fi
867   case "$autoconf_minversion" in
868     1.* | 2.[0-4]* | 2.5[0-8]*)
869       func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
870   esac
871
872   # Remove trailing slashes from the directory names. This is necessary for
873   # m4base (to avoid an error in func_import) and optional for the others.
874   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
875   case "$local_gnulib_dir" in
876     */ ) local_gnulib_dir=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
877   esac
878   case "$sourcebase" in
879     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
880   esac
881   case "$m4base" in
882     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
883   esac
884   case "$docbase" in
885     */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
886   esac
887   case "$testsbase" in
888     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
889   esac
890   case "$auxdir" in
891     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
892   esac
893 }
894
895 case "$0" in
896   /*) self_abspathname="$0" ;;
897   */*) self_abspathname=`pwd`/"$0" ;;
898   *)
899     # Look in $PATH.
900     # Iterate through the elements of $PATH.
901     # We use IFS=: instead of
902     #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
903     # because the latter does not work when some PATH element contains spaces.
904     # We use a canonicalized $pathx instead of $PATH, because empty PATH
905     # elements are by definition equivalent to '.', however field splitting
906     # according to IFS=: loses empty fields in many shells:
907     #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
908     #     beginning, at the end, and in the middle),
909     #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
910     #     at the beginning and at the end,
911     #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
912     #     Solaris lose empty fields at the end.
913     # The 'case' statement is an optimization, to avoid evaluating the
914     # explicit canonicalization command when $PATH contains no empty fields.
915     self_abspathname=
916     if test "${PATH_SEPARATOR+set}" != set; then
917       func_tmpdir
918       { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
919       chmod +x "$tmp"/conf.sh
920       if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
921         PATH_SEPARATOR=';'
922       else
923         PATH_SEPARATOR=:
924       fi
925       rm -rf "$tmp"
926     fi
927     if test "$PATH_SEPARATOR" = ";"; then
928       # On Windows, programs are searched in "." before $PATH.
929       pathx=".;$PATH"
930     else
931       # On Unix, we have to convert empty PATH elements to ".".
932       pathx="$PATH"
933       case :$PATH: in
934         *::*)
935           pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
936           ;;
937       esac
938     fi
939     save_IFS="$IFS"
940     IFS="$PATH_SEPARATOR"
941     for d in $pathx; do
942       IFS="$save_IFS"
943       test -z "$d" && d=.
944       if test -x "$d/$0" && test ! -d "$d/$0"; then
945         self_abspathname="$d/$0"
946         break
947       fi
948     done
949     IFS="$save_IFS"
950     if test -z "$self_abspathname"; then
951       func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
952     fi
953     ;;
954 esac
955 while test -h "$self_abspathname"; do
956   # Resolve symbolic link.
957   linkval=`func_readlink "$self_abspathname"`
958   test -n "$linkval" || break
959   case "$linkval" in
960     /* ) self_abspathname="$linkval" ;;
961     * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
962   esac
963 done
964 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
965
966 func_tmpdir
967 trap 'exit_status=$?
968       if test "$signal" != 0; then
969         echo "caught signal $signal" >&2
970       fi
971       rm -rf "$tmp"
972       exit $exit_status' 0
973 for signal in 1 2 3 13 15; do
974   trap '{ signal='$signal'; func_exit 1; }' $signal
975 done
976 signal=0
977
978 # func_lookup_file file
979 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
980 # 'patch'.
981 # Input:
982 # - local_gnulib_dir  from --local-dir
983 # Output:
984 # - lookedup_file   name of the merged (combined) file
985 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
986 func_lookup_file ()
987 {
988   lkfile="$1"
989   if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
990     lookedup_file="$local_gnulib_dir/$lkfile"
991     lookedup_tmp=
992   else
993     if test -f "$gnulib_dir/$lkfile"; then
994       if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
995         lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
996         rm -f "$tmp/$lkbase"
997         cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
998         patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
999           || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
1000         lookedup_file="$tmp/$lkbase"
1001         lookedup_tmp=true
1002       else
1003         lookedup_file="$gnulib_dir/$lkfile"
1004         lookedup_tmp=
1005       fi
1006     else
1007       func_fatal_error "file $gnulib_dir/$lkfile not found"
1008     fi
1009   fi
1010 }
1011
1012 # func_all_modules
1013 # Input:
1014 # - local_gnulib_dir  from --local-dir
1015 func_all_modules ()
1016 {
1017   # Filter out metainformation files like README, which are not modules.
1018   # Filter out unit test modules; they can be retrieved through
1019   # --extract-tests-module if desired.
1020   {
1021     (cd "$gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,')
1022     if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
1023       (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,')
1024     fi
1025   } \
1026       | sed -e '/^CVS\//d' -e '/\/CVS\//d' \
1027             -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
1028             -e '/^COPYING$/d' -e '/\/COPYING$/d' \
1029             -e '/^README$/d' -e '/\/README$/d' \
1030             -e '/^TEMPLATE$/d' \
1031             -e '/^TEMPLATE-EXTENDED$/d' \
1032             -e '/^TEMPLATE-TESTS$/d' \
1033             -e '/^\..*/d' \
1034             -e '/~$/d' \
1035       | sed -e '/-tests$/d' \
1036       | LC_ALL=C sort -u
1037 }
1038
1039 # func_verify_module
1040 # verifies a module name
1041 # Input:
1042 # - local_gnulib_dir  from --local-dir
1043 # - module          module name argument
1044 func_verify_module ()
1045 {
1046   if { test -f "$gnulib_dir/modules/$module" \
1047        || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1048             && test -f "$local_gnulib_dir/modules/$module"; }; } \
1049      && test "CVS" != "$module" \
1050      && test "ChangeLog" != "$module" \
1051      && test "COPYING" != "$module" \
1052      && test "README" != "$module" \
1053      && test "TEMPLATE" != "$module" \
1054      && test "TEMPLATE-EXTENDED" != "$module" \
1055      && test "TEMPLATE-TESTS" != "$module"; then
1056     # OK, $module is a correct module name.
1057     # Verify that building the module description with 'patch' succeeds.
1058     func_lookup_file "modules/$module"
1059   else
1060     echo "gnulib-tool: module $module doesn't exist" 1>&2
1061     module=
1062   fi
1063 }
1064
1065 # func_verify_nontests_module
1066 # verifies a module name, excluding tests modules
1067 # Input:
1068 # - local_gnulib_dir  from --local-dir
1069 # - module          module name argument
1070 func_verify_nontests_module ()
1071 {
1072   case "$module" in
1073     *-tests ) module= ;;
1074     * ) func_verify_module ;;
1075   esac
1076 }
1077
1078 # func_verify_tests_module
1079 # verifies a module name, considering only tests modules
1080 # Input:
1081 # - local_gnulib_dir  from --local-dir
1082 # - module          module name argument
1083 func_verify_tests_module ()
1084 {
1085   case "$module" in
1086     *-tests ) func_verify_module ;;
1087     * ) module= ;;
1088   esac
1089 }
1090
1091 sed_extract_prog=':[     ]*$/ {
1092   :a
1093     n
1094     s/^Description:[     ]*$//
1095     s/^Files:[   ]*$//
1096     s/^Depends-on:[      ]*$//
1097     s/^configure\.ac-early:[     ]*$//
1098     s/^configure\.ac:[   ]*$//
1099     s/^Makefile\.am:[    ]*$//
1100     s/^Include:[         ]*$//
1101     s/^Link:[    ]*$//
1102     s/^License:[         ]*$//
1103     s/^Maintainer:[      ]*$//
1104     tb
1105     p
1106     ba
1107   :b
1108 }'
1109
1110 # func_get_description module
1111 # Input:
1112 # - local_gnulib_dir  from --local-dir
1113 func_get_description ()
1114 {
1115   func_lookup_file "modules/$1"
1116   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
1117 }
1118
1119 # func_get_filelist module
1120 # Input:
1121 # - local_gnulib_dir  from --local-dir
1122 func_get_filelist ()
1123 {
1124   func_lookup_file "modules/$1"
1125   sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
1126   echo m4/gnulib-common.m4
1127   case "$autoconf_minversion" in
1128     2.59)
1129       #echo m4/onceonly.m4
1130       echo m4/onceonly_2_57.m4
1131       ;;
1132   esac
1133 }
1134
1135 # func_get_dependencies module
1136 # Input:
1137 # - local_gnulib_dir  from --local-dir
1138 func_get_dependencies ()
1139 {
1140   # ${module}-tests always implicitly depends on ${module}.
1141   echo "$1" | sed -n -e 's/-tests//p'
1142   # Then the explicit dependencies listed in the module description.
1143   func_lookup_file "modules/$1"
1144   sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
1145 }
1146
1147 # func_get_autoconf_early_snippet module
1148 # Input:
1149 # - local_gnulib_dir  from --local-dir
1150 func_get_autoconf_early_snippet ()
1151 {
1152   func_lookup_file "modules/$1"
1153   sed -n -e "/^configure\.ac-early$sed_extract_prog" < "$lookedup_file"
1154 }
1155
1156 # func_get_autoconf_snippet module
1157 # Input:
1158 # - local_gnulib_dir  from --local-dir
1159 func_get_autoconf_snippet ()
1160 {
1161   func_lookup_file "modules/$1"
1162   sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
1163 }
1164
1165 # func_get_automake_snippet module
1166 # Input:
1167 # - local_gnulib_dir  from --local-dir
1168 func_get_automake_snippet ()
1169 {
1170   func_lookup_file "modules/$1"
1171   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
1172   case "$1" in
1173     *-tests)
1174       # *-tests module live in tests/, not lib/.
1175       ;;
1176     *)
1177       # Synthesize an EXTRA_DIST augmentation.
1178       sed_combine_lines='/\\$/{
1179         :a
1180         N
1181         s/\\\n/ /
1182         s/\\$/\\/
1183         ta
1184       }'
1185       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
1186       already_mentioned_files=` \
1187         sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
1188         | sed -e "$sed_combine_lines" \
1189         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
1190       all_files=`func_get_filelist $1`
1191       lib_files=`for f in $all_files; do \
1192                    case $f in \
1193                      lib/*) echo $f ;; \
1194                    esac; \
1195                  done | sed -e 's,^lib/,,'`
1196       # Remove $already_mentioned_files from $lib_files.
1197       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
1198       extra_files=`for f in $already_mentioned_files; do echo $f; done \
1199                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
1200       if test -n "$extra_files"; then
1201         echo "EXTRA_DIST +=" $extra_files
1202         echo
1203       fi
1204       # Synthesize also an EXTRA_lib_SOURCES augmentation.
1205       # This is necessary so that automake can generate the right list of
1206       # dependency rules.
1207       # A possible approach would be to use autom4te --trace of the redefined
1208       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
1209       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
1210       # inside autoconf's built-in macros are not missed).
1211       # But it's simpler and more robust to do it here, based on the file list.
1212       # If some .c file exists and is not used with AC_LIBOBJ - for example,
1213       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
1214       # automake will generate a useless dependency; this is harmless.
1215       case "$1" in
1216         relocatable-prog-wrapper) ;;
1217         *)
1218           sed_extract_c_files='/\.c$/p'
1219           extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
1220           if test -n "$extra_files"; then
1221             echo "EXTRA_lib_SOURCES +=" $extra_files
1222             echo
1223           fi
1224           ;;
1225       esac
1226       ;;
1227   esac
1228 }
1229
1230 # func_get_include_directive module
1231 # Input:
1232 # - local_gnulib_dir  from --local-dir
1233 func_get_include_directive ()
1234 {
1235   func_lookup_file "modules/$1"
1236   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1237   sed -e 's/^\(["<]\)/#include \1/'
1238 }
1239
1240 # func_get_link_directive module
1241 # Input:
1242 # - local_gnulib_dir  from --local-dir
1243 func_get_link_directive ()
1244 {
1245   func_lookup_file "modules/$1"
1246   sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
1247 }
1248
1249 # func_get_license module
1250 # Input:
1251 # - local_gnulib_dir  from --local-dir
1252 func_get_license ()
1253 {
1254   func_lookup_file "modules/$1"
1255   { sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1256     # The default is GPL.
1257     echo "GPL"
1258   } | sed -e 's,^ *$,,' | sed -e 1q
1259 }
1260
1261 # func_get_maintainer module
1262 # Input:
1263 # - local_gnulib_dir  from --local-dir
1264 func_get_maintainer ()
1265 {
1266   func_lookup_file "modules/$1"
1267   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1268 }
1269
1270 # func_get_tests_module module
1271 # Input:
1272 # - local_gnulib_dir  from --local-dir
1273 func_get_tests_module ()
1274 {
1275   # The naming convention for tests modules is hardwired: ${module}-tests.
1276   if test -f "$gnulib_dir/modules/$1"-tests \
1277      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1278           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1279     echo "$1"-tests
1280   fi
1281 }
1282
1283 # func_acceptable module
1284 # tests whether a module is acceptable.
1285 # Input:
1286 # - avoidlist       list of modules to avoid
1287 func_acceptable ()
1288 {
1289   for avoid in $avoidlist; do
1290     if test "$avoid" = "$1"; then
1291       return 1
1292     fi
1293   done
1294   return 0
1295 }
1296
1297 # func_modules_transitive_closure
1298 # Input:
1299 # - local_gnulib_dir  from --local-dir
1300 # - modules         list of specified modules
1301 # - inctests        true if tests should be included, blank otherwise
1302 # - avoidlist       list of modules to avoid
1303 # - tmp             pathname of a temporary directory
1304 # Output:
1305 # - modules         list of modules, including dependencies
1306 func_modules_transitive_closure ()
1307 {
1308   # In order to process every module only once (for speed), process an "input
1309   # list" of modules, producing an "output list" of modules. During each round,
1310   # more modules can be queued in the input list. Once a module on the input
1311   # list has been processed, it is added to the "handled list", so we can avoid
1312   # to process it again.
1313   handledmodules=
1314   inmodules="$modules"
1315   outmodules=
1316   while test -n "$inmodules"; do
1317     inmodules_this_round="$inmodules"
1318     inmodules=                    # Accumulator, queue for next round
1319     for module in $inmodules_this_round; do
1320       func_verify_module
1321       if test -n "$module"; then
1322         if func_acceptable $module; then
1323           func_append outmodules " $module"
1324           deps=`func_get_dependencies $module`
1325           # Duplicate dependencies are harmless, but Jim wants a warning.
1326           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1327           if test -n "$duplicated_deps"; then
1328             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1329           fi
1330           func_append inmodules " $deps"
1331           if test -n "$inctests"; then
1332             testsmodule=`func_get_tests_module $module`
1333             if test -n "$testsmodule"; then
1334               func_append inmodules " $testsmodule"
1335             fi
1336           fi
1337         fi
1338       fi
1339     done
1340     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1341     # Remove $handledmodules from $inmodules.
1342     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1343     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1344   done
1345   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1346   rm -f "$tmp"/queued-modules
1347 }
1348
1349 # func_modules_add_dummy
1350 # Input:
1351 # - local_gnulib_dir  from --local-dir
1352 # - modules         list of modules, including dependencies
1353 # Output:
1354 # - modules         list of modules, including 'dummy' if needed
1355 func_modules_add_dummy ()
1356 {
1357   have_lib_SOURCES=
1358   sed_remove_backslash_newline=':a
1359 /\\$/{
1360 s/\\$//
1361 N
1362 s/\n//
1363 ba
1364 }'
1365   for module in $modules; do
1366     func_verify_nontests_module
1367     if test -n "$module"; then
1368       # Extract the value of "lib_SOURCES += ...".
1369       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1370         # Ignore .h files since they are not compiled.
1371         case "$file" in
1372           *.h) ;;
1373           *) have_lib_SOURCES=yes ;;
1374         esac
1375       done
1376     fi
1377   done
1378   # Add the dummy module, to make sure the library will be non-empty.
1379   if test -z "$have_lib_SOURCES"; then
1380     if func_acceptable "dummy"; then
1381       func_append modules " dummy"
1382     fi
1383   fi
1384 }
1385
1386 # func_modules_to_filelist
1387 # Input:
1388 # - local_gnulib_dir  from --local-dir
1389 # - modules         list of modules, including dependencies
1390 # Output:
1391 # - files           list of files
1392 func_modules_to_filelist ()
1393 {
1394   files=
1395   for module in $modules; do
1396     func_verify_module
1397     if test -n "$module"; then
1398       fs=`func_get_filelist $module`
1399       func_append files " $fs"
1400     fi
1401   done
1402   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1403 }
1404
1405 # func_emit_lib_Makefile_am
1406 # emits the contents of library makefile to standard output.
1407 # Input:
1408 # - local_gnulib_dir  from --local-dir
1409 # - modules         list of modules, including dependencies
1410 # - libname         library name
1411 # - auxdir          directory relative to destdir where to place build aux files
1412 # - makefile_name   from --makefile-name
1413 # - libtool         true if libtool will be used, false or blank otherwise
1414 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1415 # - actioncmd       (optional) command that will reproduce this invocation
1416 # - for_test        true if creating a package for testing, false otherwise
1417 # Output:
1418 # - uses_subdirs    nonempty if object files in subdirs exist
1419 func_emit_lib_Makefile_am ()
1420 {
1421   # When creating an includable Makefile.am snippet, augment variables with
1422   # += instead of assigning them.
1423   if test -n "$makefile_name"; then
1424     assign='+='
1425   else
1426     assign='='
1427   fi
1428   if test "$libtool" = true; then
1429     libext=la
1430     perhapsLT=LT
1431     sed_eliminate_LDFLAGS=
1432   else
1433     libext=a
1434     perhapsLT=
1435     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1436   fi
1437   if $for_test; then
1438     # When creating a package for testing: Attempt to provoke failures,
1439     # especially link errors, already during "make" rather than during
1440     # "make check", because "make check" is not possible in a cross-compiling
1441     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1442     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1443   else
1444     sed_transform_check_PROGRAMS=
1445   fi
1446   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1447   echo "## Process this file with automake to produce Makefile.in."
1448   func_emit_copyright_notice
1449   if test -n "$actioncmd"; then
1450     echo "# Reproduce by: $actioncmd"
1451   fi
1452   echo
1453   uses_subdirs=
1454   {
1455     for module in $modules; do
1456       func_verify_nontests_module
1457       if test -n "$module"; then
1458         {
1459           func_get_automake_snippet "$module" |
1460             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1461                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1462                 -e "$sed_eliminate_LDFLAGS" \
1463                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1464                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1465                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1466                 -e "$sed_transform_check_PROGRAMS"
1467           if test "$module" = 'alloca'; then
1468             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1469             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1470           fi
1471         } > amsnippet.tmp
1472         # Skip the contents if its entirely empty.
1473         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1474           echo "## begin gnulib module $module"
1475           echo
1476           cat amsnippet.tmp
1477           echo "## end   gnulib module $module"
1478           echo
1479         fi
1480         rm -f amsnippet.tmp
1481         # Test whether there are some source files in subdirectories.
1482         for f in `func_get_filelist "$module"`; do
1483           case $f in
1484             lib/*/*.c) uses_subdirs=yes ;;
1485           esac
1486         done
1487       fi
1488     done
1489   } > allsnippets.tmp
1490   if test -z "$makefile_name"; then
1491     # If there are source files in subdirectories, prevent collision of the
1492     # object files (example: hash.c and libxml/hash.c).
1493     subdir_options=
1494     if test -n "$uses_subdirs"; then
1495       subdir_options=' subdir-objects'
1496     fi
1497     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1498   fi
1499   echo
1500   if test -z "$makefile_name"; then
1501     echo "noinst_HEADERS ="
1502     echo "noinst_LIBRARIES ="
1503     echo "noinst_LTLIBRARIES ="
1504     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1505     # if you specify pkgdata_DATA to empty. This is a workaround.
1506     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1507       echo "pkgdata_DATA ="
1508     fi
1509     echo "EXTRA_DIST ="
1510     echo "BUILT_SOURCES ="
1511     echo "SUFFIXES ="
1512   fi
1513   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1514   if test -z "$makefile_name"; then
1515     echo "MOSTLYCLEANDIRS ="
1516     echo "CLEANFILES ="
1517     echo "DISTCLEANFILES ="
1518     echo "MAINTAINERCLEANFILES ="
1519     echo
1520     echo "AM_CPPFLAGS ="
1521   fi
1522   echo
1523   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1524     # One of the snippets already specifies an installation location for the
1525     # library. Don't confuse automake by saying it should not be installed.
1526     :
1527   else
1528     # By default, the generated library should not be installed.
1529     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1530   fi
1531   echo
1532   echo "${libname}_${libext}_SOURCES ="
1533   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1534   # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1535   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1536   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1537   echo "EXTRA_${libname}_${libext}_SOURCES ="
1538   if test "$libtool" = true; then
1539     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1540   fi
1541   echo
1542   cat allsnippets.tmp \
1543     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1544   echo
1545   echo "mostlyclean-local: mostlyclean-generic"
1546   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1547   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1548   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1549   echo "          fi; \\"
1550   echo "        done; \\"
1551   echo "        :"
1552   rm -f allsnippets.tmp
1553 }
1554
1555 # func_emit_tests_Makefile_am
1556 # emits the contents of tests makefile to standard output.
1557 # Input:
1558 # - local_gnulib_dir  from --local-dir
1559 # - modules         list of modules, including dependencies
1560 # - libname         library name
1561 # - makefile_name   from --makefile-name
1562 # - libtool         true if libtool will be used, false or blank otherwise
1563 # - sourcebase      relative directory containing lib source code
1564 # - m4base          relative directory containing autoconf macros
1565 # - testsbase       relative directory containing unit test code
1566 # - for_test        true if creating a package for testing, false otherwise
1567 func_emit_tests_Makefile_am ()
1568 {
1569   if test "$libtool" = true; then
1570     libext=la
1571   else
1572     libext=a
1573   fi
1574   if test "$libtool" = true; then
1575     libext=la
1576     sed_eliminate_LDFLAGS=
1577   else
1578     libext=a
1579     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1580   fi
1581   if $for_test; then
1582     # When creating a package for testing: Attempt to provoke failures,
1583     # especially link errors, already during "make" rather than during
1584     # "make check", because "make check" is not possible in a cross-compiling
1585     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1586     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1587   else
1588     sed_transform_check_PROGRAMS=
1589   fi
1590   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1591   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1592   echo "## Process this file with automake to produce Makefile.in."
1593   func_emit_copyright_notice
1594   echo
1595   # Generate dependencies here, since it eases the debugging of test failures.
1596   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1597   echo
1598   echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1599   echo
1600   (
1601     for module in $modules; do
1602       func_verify_tests_module
1603       if test -n "$module"; then
1604         {
1605           func_get_automake_snippet "$module" |
1606             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1607                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1608                 -e "$sed_eliminate_LDFLAGS" \
1609                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1610                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1611                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1612                 -e "$sed_transform_check_PROGRAMS"
1613         } > amsnippet.tmp
1614         # Skip the contents if its entirely empty.
1615         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1616           echo "## begin gnulib module $module"
1617           echo
1618           cat amsnippet.tmp
1619           echo "## end   gnulib module $module"
1620           echo
1621         fi
1622         rm -f amsnippet.tmp
1623       fi
1624     done
1625   ) > allsnippets.tmp
1626   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1627   # variable is needed to avoid an error from automake:
1628   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1629   echo "SUBDIRS ="
1630   echo "TESTS ="
1631   echo "TESTS_ENVIRONMENT ="
1632   echo "noinst_PROGRAMS ="
1633   if ! $for_test; then
1634     echo "check_PROGRAMS ="
1635   fi
1636   echo "noinst_HEADERS ="
1637   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1638     echo "pkgdata_DATA ="
1639   fi
1640   echo "EXTRA_DIST ="
1641   echo "BUILT_SOURCES ="
1642   echo "SUFFIXES ="
1643   echo "MOSTLYCLEANFILES = core *.stackdump"
1644   echo "MOSTLYCLEANDIRS ="
1645   echo "CLEANFILES ="
1646   echo "DISTCLEANFILES ="
1647   echo "MAINTAINERCLEANFILES ="
1648   echo
1649   echo "AM_CPPFLAGS = \\"
1650   echo "  -I. -I\$(srcdir) \\"
1651   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1652   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1653   echo
1654   echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1655   echo
1656   cat allsnippets.tmp
1657   echo "# Clean up after Solaris cc."
1658   echo "clean-local:"
1659   echo "        rm -rf SunWS_cache"
1660   echo
1661   echo "mostlyclean-local: mostlyclean-generic"
1662   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1663   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1664   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1665   echo "          fi; \\"
1666   echo "        done; \\"
1667   echo "        :"
1668   rm -f allsnippets.tmp
1669 }
1670
1671 # func_emit_initmacro_start
1672 # emits the first few statements of the gl_INIT macro to standard output.
1673 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1674 func_emit_initmacro_start ()
1675 {
1676   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1677   # platform-dependent object files in ${macro_prefix}_LIBOBJS instead of
1678   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1679   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1680   # flexibility.)
1681   # Furthermore it avoids an automake error like this when a Makefile.am
1682   # that uses pieces of gnulib also uses $(LIBOBJ):
1683   #   automatically discovered file `error.c' should not be explicitly mentioned
1684   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix}_LIBOBJ]))"
1685   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix}_REPLACE_FUNCS]))"
1686   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1687   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1688   #   automatically discovered file `error.c' should not be explicitly mentioned
1689   # We let automake know about the files to be distributed through the
1690   # EXTRA_lib_SOURCES variable.
1691   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix}_LIBSOURCES]))"
1692 }
1693
1694 # func_emit_initmacro_end
1695 # emits the last few statements of the gl_INIT macro to standard output.
1696 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1697 func_emit_initmacro_end ()
1698 {
1699   echo "  m4_popdef([AC_LIBSOURCES])"
1700   echo "  m4_popdef([AC_REPLACE_FUNCS])"
1701   echo "  m4_popdef([AC_LIBOBJ])"
1702   echo "  AC_CONFIG_COMMANDS_PRE(["
1703   echo "    ${macro_prefix}_libobjs="
1704   echo "    ${macro_prefix}_ltlibobjs="
1705   echo "    if test -n \"\$${macro_prefix}_LIBOBJS\"; then"
1706   echo "      # Remove the extension."
1707   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
1708   echo "      for i in \`for i in \$${macro_prefix}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
1709   echo "        ${macro_prefix}_libobjs=\"\$${macro_prefix}_libobjs \$i.\$ac_objext\""
1710   echo "        ${macro_prefix}_ltlibobjs=\"\$${macro_prefix}_ltlibobjs \$i.lo\""
1711   echo "      done"
1712   echo "    fi"
1713   echo "    AC_SUBST([${macro_prefix}_LIBOBJS], [\$${macro_prefix}_libobjs])"
1714   echo "    AC_SUBST([${macro_prefix}_LTLIBOBJS], [\$${macro_prefix}_ltlibobjs])"
1715   echo "  ])"
1716 }
1717
1718 # func_emit_initmacro_done
1719 # emits a few statements after the gl_INIT macro to standard output.
1720 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1721 func_emit_initmacro_done ()
1722 {
1723   echo
1724   echo "# Like AC_LIBOBJ, except that the module name goes"
1725   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1726   echo "AC_DEFUN([${macro_prefix}_LIBOBJ],"
1727   echo "  [${macro_prefix}_LIBOBJS=\"\$${macro_prefix}_LIBOBJS \$1.\$ac_objext\"])"
1728   echo
1729   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
1730   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1731   echo "AC_DEFUN([${macro_prefix}_REPLACE_FUNCS],"
1732   echo "  [AC_CHECK_FUNCS([\$1], , [${macro_prefix}_LIBOBJ(\$ac_func)])])"
1733   echo
1734   echo "# Like AC_LIBSOURCES, except that it does nothing."
1735   echo "# We rely on EXTRA_lib..._SOURCES instead."
1736   echo "AC_DEFUN([${macro_prefix}_LIBSOURCES],"
1737   echo "  [])"
1738 }
1739
1740 # func_import modules
1741 # Uses also the variables
1742 # - destdir         target directory
1743 # - local_gnulib_dir  from --local-dir
1744 # - libname         library name
1745 # - sourcebase      directory relative to destdir where to place source code
1746 # - m4base          directory relative to destdir where to place *.m4 macros
1747 # - docbase         directory relative to destdir where to place doc files
1748 # - testsbase       directory relative to destdir where to place unit test code
1749 # - auxdir          directory relative to destdir where to place build aux files
1750 # - inctests        true if --with-tests was given, blank otherwise
1751 # - avoidlist       list of modules to avoid, from --avoid
1752 # - lgpl            true if library's license shall be LGPL, blank otherwise
1753 # - makefile_name   from --makefile-name
1754 # - libtool         true if --libtool was given, false if --no-libtool was
1755 #                   given, blank otherwise
1756 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1757 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1758 # - autoconf_minversion  minimum supported autoconf version
1759 # - doit            : if actions shall be executed, false if only to be printed
1760 # - symbolic        true if files should be symlinked, copied otherwise
1761 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
1762 #                   copied otherwise
1763 # - do_copyrights   true if copyright notices in files should be replaced,
1764 #                   blank otherwise
1765 func_import ()
1766 {
1767   # Get the cached settings.
1768   cached_local_gnulib_dir=
1769   cached_specified_modules=
1770   cached_avoidlist=
1771   cached_sourcebase=
1772   cached_m4base=
1773   cached_docbase=
1774   cached_testsbase=
1775   cached_inctests=
1776   cached_libname=
1777   cached_lgpl=
1778   cached_makefile_name=
1779   cached_libtool=
1780   cached_macro_prefix=
1781   cached_files=
1782   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1783     cached_libtool=false
1784     my_sed_traces='
1785       s,#.*$,,
1786       s,^dnl .*$,,
1787       s, dnl .*$,,
1788       /gl_LOCAL_DIR(/ {
1789         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1790       }
1791       /gl_MODULES(/ {
1792         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1793       }
1794       /gl_AVOID(/ {
1795         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1796       }
1797       /gl_SOURCE_BASE(/ {
1798         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1799       }
1800       /gl_M4_BASE(/ {
1801         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1802       }
1803       /gl_DOC_BASE(/ {
1804         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1805       }
1806       /gl_TESTS_BASE(/ {
1807         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1808       }
1809       /gl_WITH_TESTS/ {
1810         s,^.*$,cached_inctests=true,p
1811       }
1812       /gl_LIB(/ {
1813         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1814       }
1815       /gl_LGPL/ {
1816         s,^.*$,cached_lgpl=true,p
1817       }
1818       /gl_MAKEFILE_NAME(/ {
1819         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1820       }
1821       /gl_LIBTOOL/ {
1822         s,^.*$,cached_libtool=true,p
1823       }
1824       /gl_MACRO_PREFIX(/ {
1825         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1826       }'
1827     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1828     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1829       my_sed_traces='
1830         s,#.*$,,
1831         s,^dnl .*$,,
1832         s, dnl .*$,,
1833         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1834           s,^.*$,cached_files=",p
1835           n
1836           ta
1837           :a
1838           s,^\]).*$,",
1839           tb
1840           p
1841           n
1842           ba
1843           :b
1844           p
1845         }'
1846       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1847     fi
1848   fi
1849
1850   # Merge the cached settings with the specified ones.
1851   # The m4base must be the same as expected from the pathname.
1852   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1853     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1854   fi
1855   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1856   # is relative to $destdir, whereas the one we use is relative to . or absolute.
1857   if test -z "$local_gnulib_dir"; then
1858     if test -n "$cached_local_gnulib_dir"; then
1859       case "$destdir" in
1860         /*)
1861           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1862         *)
1863           case "$cached_local_gnulib_dir" in
1864             /*)
1865               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1866             *)
1867               func_relconcat "$destdir" "$cached_local_gnulib_dir"
1868               local_gnulib_dir="$relconcat" ;;
1869           esac ;;
1870       esac
1871     fi
1872   fi
1873   # Append the cached and the specified module names. So that
1874   # "gnulib-tool --import foo" means to add the module foo.
1875   specified_modules="$cached_specified_modules $1"
1876   # Append the cached and the specified avoidlist. This is probably better
1877   # than dropping the cached one when --avoid is specified at least once.
1878   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
1879   avoidlist=`echo $avoidlist`
1880
1881     # The sourcebase defaults to the cached one.
1882   if test -z "$sourcebase"; then
1883     sourcebase="$cached_sourcebase"
1884     if test -z "$sourcebase"; then
1885       func_fatal_error "missing --source-base option"
1886     fi
1887   fi
1888   # The docbase defaults to the cached one.
1889   if test -z "$docbase"; then
1890     docbase="$cached_docbase"
1891     if test -z "$docbase"; then
1892       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."
1893     fi
1894   fi
1895   # The testsbase defaults to the cached one.
1896   if test -z "$testsbase"; then
1897     testsbase="$cached_testsbase"
1898     if test -z "$testsbase"; then
1899       func_fatal_error "missing --tests-base option"
1900     fi
1901   fi
1902   # Require the tests if specified either way.
1903   if test -z "$inctests"; then
1904     inctests="$cached_inctests"
1905   fi
1906   # The libname defaults to the cached one.
1907   if test -z "$supplied_libname"; then
1908     libname="$cached_libname"
1909     if test -z "$libname"; then
1910       func_fatal_error "missing --lib option"
1911     fi
1912   fi
1913   # Require LGPL if specified either way.
1914   if test -z "$lgpl"; then
1915     lgpl="$cached_lgpl"
1916   fi
1917   # The makefile_name defaults to the cached one.
1918   if test -z "$makefile_name"; then
1919     makefile_name="$cached_makefile_name"
1920   fi
1921   # Use libtool if specified either way, or if guessed.
1922   if test -z "$libtool"; then
1923     if test -n "$cached_m4base"; then
1924       libtool="$cached_libtool"
1925     else
1926       libtool="$guessed_libtool"
1927     fi
1928   fi
1929   # The macro_prefix defaults to the cached one.
1930   if test -z "$macro_prefix"; then
1931     macro_prefix="$cached_macro_prefix"
1932     if test -z "$macro_prefix"; then
1933       func_fatal_error "missing --macro-prefix option"
1934     fi
1935   fi
1936
1937   # Canonicalize the list of specified modules.
1938   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1939
1940   # Determine final module list.
1941   modules="$specified_modules"
1942   func_modules_transitive_closure
1943   echo "Module list with included dependencies:"
1944   echo "$modules" | sed -e 's/^/  /'
1945
1946   # Add the dummy module if needed.
1947   func_modules_add_dummy
1948
1949   # If --lgpl, verify that the licenses of modules are compatible.
1950   if test -n "$lgpl"; then
1951     for module in $modules; do
1952       license=`func_get_license $module`
1953       case $license in
1954         LGPL | LGPLv2+ | 'GPLed build tool') ;;
1955         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1956         *) func_fatal_error "incompatible license on module $module: $license" ;;
1957       esac
1958     done
1959   fi
1960
1961   # Determine script to apply to imported library files.
1962   sed_transform_lib_file=
1963   for module in $modules; do
1964     if test $module = config-h; then
1965       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1966       sed_transform_lib_file=$sed_transform_lib_file'
1967         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
1968       '
1969       break
1970     fi
1971   done
1972   if test -n "$do_copyrights"; then
1973     if test -n "$lgpl"; then
1974       # Update license.
1975       sed_transform_lib_file=$sed_transform_lib_file'
1976         s/GNU General/GNU Lesser General/g
1977         s/version 2\([ ,]\)/version 2.1\1/g
1978       '
1979     fi
1980   fi
1981
1982   # Determine final file list.
1983   func_modules_to_filelist
1984   echo "File list:"
1985   echo "$files" | sed -e 's/^/  /'
1986
1987   test -n "$files" \
1988     || func_fatal_error "refusing to do nothing"
1989
1990   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1991   new_files="$files m4/gnulib-tool.m4"
1992   old_files="$cached_files"
1993   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1994     func_append old_files " m4/gnulib-tool.m4"
1995   fi
1996
1997   sed_rewrite_old_files="\
1998     s,^build-aux/,$auxdir/,
1999     s,^doc/,$cached_docbase/,
2000     s,^lib/,$cached_sourcebase/,
2001     s,^m4/,$cached_m4base/,
2002     s,^tests/,$cached_testsbase/,"
2003   sed_rewrite_new_files="\
2004     s,^build-aux/,$auxdir/,
2005     s,^doc/,$docbase/,
2006     s,^lib/,$sourcebase/,
2007     s,^m4/,$m4base/,
2008     s,^tests/,$testsbase/,"
2009
2010   # Create directories.
2011   { echo "$sourcebase"
2012     echo "$m4base"
2013     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2014     if test -n "$docfiles"; then
2015       echo "$docbase"
2016     fi
2017     if test -n "$inctests"; then
2018       echo "$testsbase"
2019     fi
2020     echo "$auxdir"
2021     for f in $files; do echo $f; done \
2022       | sed -e "$sed_rewrite_new_files" \
2023       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2024       | LC_ALL=C sort -u
2025   } > "$tmp"/dirs
2026   { # Rearrange file descriptors. Needed because "while ... done < ..."
2027     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2028     exec 5<&0 < "$tmp"/dirs
2029     while read d; do
2030       if test ! -d "$destdir/$d"; then
2031         if $doit; then
2032           echo "Creating directory $destdir/$d"
2033           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2034         else
2035           echo "Create directory $destdir/$d"
2036         fi
2037       fi
2038     done
2039     exec 0<&5 5<&-
2040   }
2041
2042   # func_dest_tmpfilename file
2043   # determines the name of a temporary file (file is relative to destdir).
2044   # Sets variable:
2045   #   - tmpfile       absolute filename of the temporary file
2046   func_dest_tmpfilename ()
2047   {
2048     if $doit; then
2049       # Put the new contents of $file in a file in the same directory (needed
2050       # to guarantee that an 'mv' to "$destdir/$file" works).
2051       tmpfile="$destdir/$1.tmp"
2052     else
2053       # Put the new contents of $file in a file in a temporary directory
2054       # (because the directory of "$file" might not exist).
2055       tmpfile="$tmp"/`basename "$1"`.tmp
2056     fi
2057   }
2058
2059   # Copy files or make symbolic links. Remove obsolete files.
2060   added_files=''
2061   removed_files=''
2062   delimiter='   '
2063   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2064   # representing the files according to the last gnulib-tool invocation.
2065   for f in $old_files; do echo $f; done \
2066     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2067     | LC_ALL=C sort \
2068     > "$tmp"/old-files
2069   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2070   # representing the files after this gnulib-tool invocation.
2071   for f in $new_files; do echo $f; done \
2072     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2073     | LC_ALL=C sort \
2074     > "$tmp"/new-files
2075   # First the files that are in old-files, but not in new-files:
2076   sed_take_first_column='s,'"$delimiter"'.*,,'
2077   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2078     # Remove the file. Do nothing if the user already removed it.
2079     if test -f "$destdir/$g"; then
2080       if $doit; then
2081         echo "Removing file $g (backup in ${g}~)"
2082         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2083       else
2084         echo "Remove file $g (backup in ${g}~)"
2085       fi
2086       func_append removed_files "$g$nl"
2087     fi
2088   done
2089   # func_add_or_update handles a file that ought to be present afterwards.
2090   # Uses parameters
2091   # - f             the original file name
2092   # - g             the rewritten file name
2093   # - already_present  nonempty if the file already exists, empty otherwise
2094   func_add_or_update ()
2095   {
2096     func_dest_tmpfilename "$g"
2097     func_lookup_file "$f"
2098     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2099     if test -n "$sed_transform_lib_file"; then
2100       case "$f" in
2101         lib/*)
2102           sed -e "$sed_transform_lib_file" \
2103             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2104           ;;
2105       esac
2106     fi
2107     if test -f "$destdir/$g"; then
2108       # The file already exists.
2109       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2110         : # The file has not changed.
2111       else
2112         # Replace the file.
2113         if $doit; then
2114           if test -n "$already_present"; then
2115             echo "Updating file $g (backup in ${g}~)"
2116           else
2117             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
2118           fi
2119           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2120           if { test -n "$symbolic" \
2121                || { test -n "$lsymbolic" \
2122                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2123              && test -z "$lookedup_tmp" \
2124              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2125             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2126           else
2127             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2128           fi
2129         else
2130           if test -n "$already_present"; then
2131             echo "Update file $g (backup in ${g}~)"
2132           else
2133             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
2134           fi
2135         fi
2136       fi
2137     else
2138       # Install the file.
2139       # Don't protest if the file should be there but isn't: it happens
2140       # frequently that developers don't put autogenerated files into CVS.
2141       if $doit; then
2142         echo "Copying file $g"
2143         if { test -n "$symbolic" \
2144              || { test -n "$lsymbolic" \
2145                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2146            && test -z "$lookedup_tmp" \
2147            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2148           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2149         else
2150           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2151         fi
2152       else
2153         echo "Copy file $g"
2154       fi
2155       func_append added_files "$g$nl"
2156     fi
2157     rm -f "$tmpfile"
2158   }
2159   # Then the files that are in new-files, but not in old-files:
2160   sed_take_last_column='s,^.*'"$delimiter"',,'
2161   already_present=
2162   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2163     | sed -e "$sed_take_last_column" \
2164     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2165   { # Rearrange file descriptors. Needed because "while ... done < ..."
2166     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2167     exec 5<&0 < "$tmp"/added-files
2168     while read g f; do
2169       func_add_or_update
2170     done
2171     exec 0<&5 5<&-
2172   }
2173   # Then the files that are in new-files and in old-files:
2174   already_present=true
2175   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2176     | sed -e "$sed_take_last_column" \
2177     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2178   { # Rearrange file descriptors. Needed because "while ... done < ..."
2179     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2180     exec 5<&0 < "$tmp"/kept-files
2181     while read g f; do
2182       func_add_or_update
2183     done
2184     exec 0<&5 5<&-
2185   }
2186
2187   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2188   actioncmd="gnulib-tool --import"
2189   func_append actioncmd " --dir=$destdir"
2190   if test -n "$local_gnulib_dir"; then
2191     func_append actioncmd " --local-dir=$local_gnulib_dir"
2192   fi
2193   func_append actioncmd " --lib=$libname"
2194   func_append actioncmd " --source-base=$sourcebase"
2195   func_append actioncmd " --m4-base=$m4base"
2196   func_append actioncmd " --doc-base=$docbase"
2197   func_append actioncmd " --aux-dir=$auxdir"
2198   if test -n "$inctests"; then
2199     func_append actioncmd " --with-tests"
2200   fi
2201   for module in $avoidlist; do
2202     func_append actioncmd " --avoid=$module"
2203   done
2204   if test -n "$lgpl"; then
2205     func_append actioncmd " --lgpl"
2206   fi
2207   if test -n "$makefile_name"; then
2208     func_append actioncmd " --makefile-name=$makefile_name"
2209   fi
2210   if test "$libtool" = true; then
2211     func_append actioncmd " --libtool"
2212   else
2213     func_append actioncmd " --no-libtool"
2214   fi
2215   func_append actioncmd " --macro-prefix=$macro_prefix"
2216   func_append actioncmd " `echo $specified_modules`"
2217
2218   # Default the makefile name to Makefile.am.
2219   if test -n "$makefile_name"; then
2220     makefile_am=$makefile_name
2221   else
2222     makefile_am=Makefile.am
2223   fi
2224
2225   # Create normal Makefile.ams.
2226   for_test=false
2227
2228   # Create library makefile.
2229   func_dest_tmpfilename $sourcebase/$makefile_am
2230   func_emit_lib_Makefile_am > "$tmpfile"
2231   if test -f "$destdir"/$sourcebase/$makefile_am; then
2232     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2233       rm -f "$tmpfile"
2234     else
2235       if $doit; then
2236         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2237         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2238         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2239       else
2240         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2241         rm -f "$tmpfile"
2242       fi
2243     fi
2244   else
2245     if $doit; then
2246       echo "Creating $sourcebase/$makefile_am"
2247       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2248     else
2249       echo "Create $sourcebase/$makefile_am"
2250       rm -f "$tmpfile"
2251     fi
2252     func_append added_files "$sourcebase/$makefile_am$nl"
2253   fi
2254
2255   # Create m4/gnulib-cache.m4.
2256   func_dest_tmpfilename $m4base/gnulib-cache.m4
2257   (
2258     func_emit_copyright_notice
2259     echo "#"
2260     echo "# This file represents the specification of how gnulib-tool is used."
2261     echo "# It acts as a cache: It is written and read by gnulib-tool."
2262     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2263     echo "# like the configure.ac and various Makefile.am files."
2264     echo
2265     echo
2266     echo "# Specification in the form of a command-line invocation:"
2267     echo "#   $actioncmd"
2268     echo
2269     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
2270     # Store the local_gnulib_dir relative to destdir.
2271     case "$local_gnulib_dir" in
2272       "" | /*)
2273         relative_local_gnulib_dir="$local_gnulib_dir" ;;
2274       * )
2275         case "$destdir" in
2276           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
2277           *)
2278             # destdir, local_gnulib_dir are both relative.
2279             func_relativize "$destdir" "$local_gnulib_dir"
2280             relative_local_gnulib_dir="$reldir" ;;
2281         esac ;;
2282     esac
2283     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
2284     echo "gl_MODULES(["`echo $specified_modules`"])"
2285     echo "gl_AVOID([$avoidlist])"
2286     echo "gl_SOURCE_BASE([$sourcebase])"
2287     echo "gl_M4_BASE([$m4base])"
2288     echo "gl_DOC_BASE([$docbase])"
2289     echo "gl_TESTS_BASE([$testsbase])"
2290     test -z "$inctests" || echo "gl_WITH_TESTS"
2291     echo "gl_LIB([$libname])"
2292     test -z "$lgpl" || echo "gl_LGPL"
2293     echo "gl_MAKEFILE_NAME([$makefile_name])"
2294     if test "$libtool" = true; then
2295       echo "gl_LIBTOOL"
2296     fi
2297     echo "gl_MACRO_PREFIX([$macro_prefix])"
2298   ) > "$tmpfile"
2299   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2300     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2301       rm -f "$tmpfile"
2302     else
2303       if $doit; then
2304         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2305         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2306         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2307       else
2308         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2309         if false; then
2310           cat "$tmpfile"
2311           echo
2312           echo "# gnulib-cache.m4 ends here"
2313         fi
2314         rm -f "$tmpfile"
2315       fi
2316     fi
2317   else
2318     if $doit; then
2319       echo "Creating $m4base/gnulib-cache.m4"
2320       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2321     else
2322       echo "Create $m4base/gnulib-cache.m4"
2323       cat "$tmpfile"
2324       rm -f "$tmpfile"
2325     fi
2326   fi
2327
2328   # Create m4/gnulib-comp.m4.
2329   func_dest_tmpfilename $m4base/gnulib-comp.m4
2330   (
2331     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2332     func_emit_copyright_notice
2333     echo "#"
2334     echo "# This file represents the compiled summary of the specification in"
2335     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2336     echo "# to be invoked from configure.ac."
2337     echo "# In projects using CVS, this file can be treated like other built files."
2338     echo
2339     echo
2340     echo "# This macro should be invoked from $configure_ac, in the section"
2341     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2342     echo "# any checks for libraries, header files, types and library functions."
2343     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2344     echo "["
2345     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2346     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2347     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2348     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2349     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2350     if test -n "$uses_subdirs"; then
2351       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2352     fi
2353     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2354       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2355     fi
2356     for module in $modules; do
2357       func_verify_module
2358       if test -n "$module"; then
2359         func_get_autoconf_early_snippet "$module"
2360       fi
2361     done \
2362       | sed -e '/^$/d;' -e 's/^/  /'
2363     echo "])"
2364     echo
2365     echo "# This macro should be invoked from $configure_ac, in the section"
2366     echo "# \"Check for header files, types and library functions\"."
2367     echo "AC_DEFUN([${macro_prefix}_INIT],"
2368     echo "["
2369     func_emit_initmacro_start
2370     if test "$libtool" = true; then
2371       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2372       echo "  gl_cond_libtool=true"
2373     else
2374       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2375       echo "  gl_cond_libtool=false"
2376       echo "  gl_libdeps="
2377       echo "  gl_ltlibdeps="
2378     fi
2379     echo "  gl_source_base='$sourcebase'"
2380     if test "$auxdir" != "build-aux"; then
2381       sed_replace_build_aux='
2382         :a
2383         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2384           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2385           ba
2386         }'
2387     else
2388       sed_replace_build_aux=
2389     fi
2390     for module in $modules; do
2391       func_verify_module
2392       if test -n "$module"; then
2393         func_get_autoconf_snippet "$module" \
2394           | sed -e '/^$/d;' -e 's/^/  /' \
2395                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
2396                 -e "$sed_replace_build_aux"
2397         if test "$module" = 'alloca' && test "$libtool" = true; then
2398           echo 'changequote(,)dnl'
2399           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
2400           echo 'changequote([, ])dnl'
2401           echo 'AC_SUBST([LTALLOCA])'
2402         fi
2403       fi
2404     done
2405     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2406     # created using libtool, because libtool already handles the dependencies.
2407     if test "$libtool" != true; then
2408       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
2409       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2410       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2411       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2412       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2413     fi
2414     func_emit_initmacro_end
2415     echo "])"
2416     func_emit_initmacro_done
2417     echo
2418     echo "# This macro records the list of files which have been installed by"
2419     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
2420     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
2421     echo "$files" | sed -e 's,^,  ,'
2422     echo "])"
2423   ) > "$tmpfile"
2424   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2425     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
2426       rm -f "$tmpfile"
2427     else
2428       if $doit; then
2429         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2430         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
2431         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2432       else
2433         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2434         if false; then
2435           cat "$tmpfile"
2436           echo
2437           echo "# gnulib-comp.m4 ends here"
2438         fi
2439         rm -f "$tmpfile"
2440       fi
2441     fi
2442   else
2443     if $doit; then
2444       echo "Creating $m4base/gnulib-comp.m4"
2445       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2446     else
2447       echo "Create $m4base/gnulib-comp.m4"
2448       cat "$tmpfile"
2449       rm -f "$tmpfile"
2450     fi
2451   fi
2452
2453   if test -n "$inctests"; then
2454     # Create tests makefile.
2455     func_dest_tmpfilename $testsbase/$makefile_am
2456     func_emit_tests_Makefile_am > "$tmpfile"
2457     if test -f "$destdir"/$testsbase/$makefile_am; then
2458       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
2459         rm -f "$tmpfile"
2460       else
2461         if $doit; then
2462           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2463           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
2464           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2465         else
2466           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2467           rm -f "$tmpfile"
2468         fi
2469       fi
2470     else
2471       if $doit; then
2472         echo "Creating $testsbase/$makefile_am"
2473         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2474       else
2475         echo "Create $testsbase/$makefile_am"
2476         rm -f "$tmpfile"
2477       fi
2478     func_append added_files "$testsbase/$makefile_am$nl"
2479     fi
2480   fi
2481
2482   # Update the .cvsignore and .gitignore files.
2483   { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
2484     echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
2485   } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
2486   { # Rearrange file descriptors. Needed because "while ... done < ..."
2487     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2488     exec 5<&0 < "$tmp"/fileset-changes
2489     func_update_ignorelist ()
2490     {
2491       ignore="$1"
2492       if test -f "$destdir/$dir$ignore"; then
2493         if test -n "$dir_added" || test -n "$dir_removed"; then
2494           LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
2495           echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
2496             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
2497           echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
2498             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
2499           if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
2500             if $doit; then
2501               echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
2502               mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
2503               sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
2504               cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
2505                 | sed -f "$tmp"/sed-ignore-removed \
2506                 > "$destdir/$dir$ignore"
2507             else
2508               echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
2509             fi
2510           fi
2511         fi
2512       else
2513         if test -n "$dir_added"; then
2514           if $doit; then
2515             echo "Creating $destdir/$dir$ignore"
2516             echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u > "$destdir/$dir$ignore"
2517           else
2518             echo "Create $destdir/$dir$ignore"
2519           fi
2520         fi
2521       fi
2522     }
2523     func_done_dir ()
2524     {
2525       dir="$1"
2526       dir_added="$2"
2527       dir_removed="$3"
2528       if test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
2529         func_update_ignorelist .cvsignore
2530       fi
2531       if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
2532         func_update_ignorelist .gitignore
2533       fi
2534     }
2535     last_dir=
2536     last_dir_added=
2537     last_dir_removed=
2538     while read line; do
2539       # Why not ''read next_dir op file'' ? Because the dir column can be empty.
2540       next_dir=`echo "$line" | sed -e 's,|.*,,'`
2541       op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
2542       file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
2543       if test "$next_dir" != "$last_dir"; then
2544         func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
2545         last_dir="$next_dir"
2546         last_dir_added=
2547         last_dir_removed=
2548       fi
2549       case $op in
2550         A) func_append last_dir_added "$file$nl";;
2551         R) func_append last_dir_removed "$file$nl";;
2552       esac
2553     done
2554     func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
2555     exec 0<&5 5<&-
2556   }
2557
2558   echo "Finished."
2559   echo
2560   echo "You may need to add #include directives for the following .h files."
2561   # Intersect $specified_modules and $modules
2562   # (since $specified_modules is not necessarily of subset of $modules - some
2563   # may have been skipped through --avoid, and since the elements of $modules
2564   # but not in $specified_modules can go away without explicit notice - through
2565   # changes in the module dependencies).
2566   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
2567   echo "$modules" > "$tmp"/modules2 # also a sorted list, one module per line
2568   # First the #include <...> directives without #ifs, sorted for convenience,
2569   # then the #include "..." directives without #ifs, sorted for convenience,
2570   # then the #include directives that are surrounded by #ifs. Not sorted.
2571   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
2572     include_directive=`func_get_include_directive "$module"`
2573     case "$nl$include_directive" in
2574       *"$nl#if"*)
2575         echo "$include_directive" 1>&5
2576         ;;
2577       *)
2578         echo "$include_directive" | grep -v 'include "' 1>&6
2579         echo "$include_directive" | grep 'include "' 1>&7
2580         ;;
2581     esac
2582   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2583   (
2584    LC_ALL=C sort -u "$tmp"/include-angles
2585    LC_ALL=C sort -u "$tmp"/include-quotes
2586    cat "$tmp"/include-if
2587   ) | sed -e '/^$/d' -e 's/^/  /'
2588   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2589
2590   for module in $modules; do
2591     func_get_link_directive "$module"
2592   done \
2593     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
2594   if test `wc -l < "$tmp"/link` != 0; then
2595     echo
2596     echo "You may need to use the following Makefile variables when linking."
2597     echo "Use them in <program>_LDADD when linking a program, or"
2598     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
2599     cat "$tmp"/link
2600   fi
2601   rm -f "$tmp"/link
2602
2603   echo
2604   echo "Don't forget to"
2605   if test "$makefile_am" = Makefile.am; then
2606     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2607   else
2608     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2609   fi
2610   if test -n "$inctests"; then
2611     if test "$makefile_am" = Makefile.am; then
2612       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2613     else
2614       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2615     fi
2616   fi
2617   if test "$makefile_am" = Makefile.am; then
2618     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2619     sourcebase_base=`basename "$sourcebase"`
2620     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2621   fi
2622   if test -n "$inctests"; then
2623     if test "$makefile_am" = Makefile.am; then
2624       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2625       testsbase_base=`basename "$testsbase"`
2626       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2627     fi
2628   fi
2629   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2630   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2631   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
2632 }
2633
2634 # func_create_testdir testdir modules
2635 # Input:
2636 # - local_gnulib_dir  from --local-dir
2637 # - auxdir          directory relative to destdir where to place build aux files
2638 func_create_testdir ()
2639 {
2640   testdir="$1"
2641   modules="$2"
2642   if test -z "$modules"; then
2643     # All modules together.
2644     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2645     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2646     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
2647     modules=`func_all_modules`
2648     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
2649   fi
2650   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2651
2652   # Check that the license of every module is consistent with the license of
2653   # its dependencies.
2654   saved_modules="$modules"
2655   saved_inctests="$inctests"
2656   # When computing transitive closures, don't consider $module to depend on
2657   # $module-tests. Need this becauses tests are implicitly GPL and may depend
2658   # on GPL modules - therefore we don't want a warning in this case.
2659   inctests=""
2660   for requested_module in $saved_modules; do
2661     requested_license=`func_get_license "$requested_module"`
2662     if test "$requested_license" != GPL; then
2663       # Here we use func_modules_transitive_closure, not just
2664       # func_get_dependencies, so that we also detect weird situations like
2665       # an LGPL module which depends on a GPLed build tool module which depends
2666       # on a GPL module.
2667       modules="$requested_module"
2668       func_modules_transitive_closure
2669       for module in $modules; do
2670         license=`func_get_license "$module"`
2671         case "$license" in
2672           'GPLed build tool') ;;
2673           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2674           *)
2675             case "$requested_license" in
2676               GPLv2+)
2677                 case "$license" in
2678                   GPLv2+ | LGPLv2+) ;;
2679                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2680                 esac
2681                 ;;
2682               LGPL)
2683                 case "$license" in
2684                   LGPL | LGPLv2+) ;;
2685                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2686                 esac
2687                 ;;
2688               LGPLv2+)
2689                 case "$license" in
2690                   LGPLv2+) ;;
2691                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2692                 esac
2693                 ;;
2694             esac
2695             ;;
2696         esac
2697       done
2698     fi
2699   done
2700   modules="$saved_modules"
2701   inctests="$saved_inctests"
2702
2703   # Subdirectory names.
2704   sourcebase=gllib
2705   m4base=glm4
2706   docbase=gldoc
2707   testsbase=gltests
2708   macro_prefix=gl
2709
2710   # Determine final module list.
2711   func_modules_transitive_closure
2712   echo "Module list with included dependencies:"
2713   echo "$modules" | sed -e 's/^/  /'
2714
2715   # Add the dummy module if needed.
2716   func_modules_add_dummy
2717
2718   # Determine final file list.
2719   func_modules_to_filelist
2720   echo "File list:"
2721   echo "$files" | sed -e 's/^/  /'
2722
2723   sed_rewrite_files="\
2724     s,^build-aux/,$auxdir/,
2725     s,^doc/,$docbase/,
2726     s,^lib/,$sourcebase/,
2727     s,^m4/,$m4base/,
2728     s,^tests/,$testsbase/,"
2729
2730   # Create directories.
2731   for f in $files; do echo $f; done \
2732     | sed -e "$sed_rewrite_files" \
2733     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2734     | LC_ALL=C sort -u \
2735     > "$tmp"/dirs
2736   { # Rearrange file descriptors. Needed because "while ... done < ..."
2737     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2738     exec 5<&0 < "$tmp"/dirs
2739     while read d; do
2740       mkdir -p "$testdir/$d"
2741     done
2742     exec 0<&5 5<&-
2743   }
2744
2745   # Copy files or make symbolic links.
2746   delimiter='   '
2747   for f in $files; do echo $f; done \
2748     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2749     | LC_ALL=C sort \
2750     > "$tmp"/files
2751   { # Rearrange file descriptors. Needed because "while ... done < ..."
2752     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2753     exec 5<&0 < "$tmp"/files
2754     while read g f; do
2755       func_lookup_file "$f"
2756       if test -n "$lookedup_tmp"; then
2757         cp -p "$lookedup_file" "$testdir/$g"
2758       else
2759         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2760         if { test -n "$symbolic" \
2761              || { test -n "$lsymbolic" \
2762                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
2763           func_ln "$lookedup_file" "$testdir/$g"
2764         else
2765           cp -p "$lookedup_file" "$testdir/$g"
2766         fi
2767       fi
2768     done
2769     exec 0<&5 5<&-
2770   }
2771
2772   # Create Makefile.ams that are for testing.
2773   for_test=true
2774
2775   # Create $sourcebase/Makefile.am.
2776   mkdir -p "$testdir/$sourcebase"
2777   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2778
2779   # Create $m4base/Makefile.am.
2780   mkdir -p "$testdir/$m4base"
2781   (echo "## Process this file with automake to produce Makefile.in."
2782    echo
2783    echo "EXTRA_DIST ="
2784    for f in $files; do
2785      case "$f" in
2786        m4/* )
2787          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2788      esac
2789    done
2790   ) > "$testdir/$m4base/Makefile.am"
2791
2792   subdirs="$sourcebase $m4base"
2793   subdirs_with_configure_ac=""
2794
2795   if false && test -f "$testdir"/$m4base/gettext.m4; then
2796     # Avoid stupid error message from automake:
2797     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2798     mkdir -p "$testdir/po"
2799     (echo "## Process this file with automake to produce Makefile.in."
2800     ) > "$testdir/po/Makefile.am"
2801     func_append subdirs " po"
2802   fi
2803
2804   if test -n "$inctests"; then
2805     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2806     # Create $testsbase/Makefile.am.
2807     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2808     # Create $testsbase/configure.ac.
2809     (echo "# Process this file with autoconf to produce a configure script."
2810      echo "AC_INIT([dummy], [0])"
2811      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2812      echo "AM_INIT_AUTOMAKE"
2813      echo
2814      echo "AM_CONFIG_HEADER([config.h])"
2815      echo
2816      echo "AC_PROG_CC"
2817      echo "AC_PROG_INSTALL"
2818      echo "AC_PROG_MAKE_SET"
2819      echo "AC_PROG_RANLIB"
2820      echo
2821      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2822        echo "AC_GNU_SOURCE"
2823        echo
2824      fi
2825      for module in $modules; do
2826        func_verify_module
2827        if test -n "$module"; then
2828          func_get_autoconf_early_snippet "$module"
2829        fi
2830      done \
2831        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
2832      if test "$libtool" = true; then
2833        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2834        echo "gl_cond_libtool=true"
2835      else
2836        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2837        echo "gl_cond_libtool=false"
2838        echo "gl_libdeps="
2839        echo "gl_ltlibdeps="
2840      fi
2841      # Wrap the set of autoconf snippets into an autoconf macro that is then
2842      # invoked. This is needed because autoconf does not support AC_REQUIRE
2843      # at the top level:
2844      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2845      # but we want the AC_REQUIRE to have its normal meaning (provide one
2846      # expansion of the required macro before the current point, and only one
2847      # expansion total).
2848      echo "AC_DEFUN([gl_INIT], ["
2849      func_emit_initmacro_start
2850      sed_replace_build_aux='
2851        :a
2852        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2853          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2854          ba
2855        }'
2856      # We don't have explicit ordering constraints between the various
2857      # autoconf snippets. It's cleanest to put those of the library before
2858      # those of the tests.
2859      echo "gl_source_base='../$sourcebase'"
2860      for module in $modules; do
2861        func_verify_nontests_module
2862        if test -n "$module"; then
2863          func_get_autoconf_snippet "$module" \
2864            | sed -e "$sed_replace_build_aux"
2865        fi
2866      done
2867      echo "gl_source_base='.'"
2868      for module in $modules; do
2869        func_verify_tests_module
2870        if test -n "$module"; then
2871          func_get_autoconf_snippet "$module" \
2872            | sed -e "$sed_replace_build_aux"
2873        fi
2874      done
2875      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2876      # created using libtool, because libtool already handles the dependencies.
2877      if test "$libtool" != true; then
2878        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
2879        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2880        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2881        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2882        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2883      fi
2884      func_emit_initmacro_end
2885      echo "])"
2886      func_emit_initmacro_done
2887      echo
2888      echo "gl_INIT"
2889      echo
2890      # Usually $testsbase/config.h will be a superset of config.h. Verify this
2891      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2892      echo "AH_TOP([#include \"../config.h\"])"
2893      echo
2894      echo "AC_OUTPUT([Makefile])"
2895     ) > "$testdir/$testsbase/configure.ac"
2896     func_append subdirs " $testsbase"
2897     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2898   fi
2899
2900   # Create Makefile.am.
2901   (echo "## Process this file with automake to produce Makefile.in."
2902    echo
2903    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2904    echo
2905    echo "SUBDIRS = $subdirs"
2906    echo
2907    echo "ACLOCAL_AMFLAGS = -I $m4base"
2908   ) > "$testdir/Makefile.am"
2909
2910   # Create configure.ac.
2911   (echo "# Process this file with autoconf to produce a configure script."
2912    echo "AC_INIT([dummy], [0])"
2913    if test "$auxdir" != "."; then
2914      echo "AC_CONFIG_AUX_DIR([$auxdir])"
2915    fi
2916    echo "AM_INIT_AUTOMAKE"
2917    echo
2918    echo "AM_CONFIG_HEADER([config.h])"
2919    echo
2920    echo "AC_PROG_CC"
2921    echo "AC_PROG_INSTALL"
2922    echo "AC_PROG_MAKE_SET"
2923    echo
2924    echo "# For autobuild."
2925    echo "AC_CANONICAL_BUILD"
2926    echo "AC_CANONICAL_HOST"
2927    echo
2928    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2929    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2930    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2931    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2932    echo
2933    echo "AC_PROG_RANLIB"
2934    echo
2935    if test -n "$uses_subdirs"; then
2936      echo "AM_PROG_CC_C_O"
2937      echo
2938    fi
2939    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2940      echo "AC_GNU_SOURCE"
2941      echo
2942    fi
2943    for module in $modules; do
2944      func_verify_nontests_module
2945      if test -n "$module"; then
2946        func_get_autoconf_early_snippet "$module"
2947      fi
2948    done \
2949      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
2950    if test "$libtool" = true; then
2951      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2952      echo "gl_cond_libtool=true"
2953    else
2954      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2955      echo "gl_cond_libtool=false"
2956      echo "gl_libdeps="
2957      echo "gl_ltlibdeps="
2958    fi
2959    echo "gl_source_base='$sourcebase'"
2960    # Wrap the set of autoconf snippets into an autoconf macro that is then
2961    # invoked. This is needed because autoconf does not support AC_REQUIRE
2962    # at the top level:
2963    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2964    # but we want the AC_REQUIRE to have its normal meaning (provide one
2965    # expansion of the required macro before the current point, and only one
2966    # expansion total).
2967    echo "AC_DEFUN([gl_INIT], ["
2968    func_emit_initmacro_start
2969    if test "$auxdir" != "build-aux"; then
2970      sed_replace_build_aux='
2971        :a
2972        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2973          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2974          ba
2975        }'
2976    else
2977      sed_replace_build_aux=
2978    fi
2979    for module in $modules; do
2980      func_verify_nontests_module
2981      if test -n "$module"; then
2982        func_get_autoconf_snippet "$module" \
2983          | sed -e "$sed_replace_build_aux"
2984      fi
2985    done
2986    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2987    # created using libtool, because libtool already handles the dependencies.
2988    if test "$libtool" != true; then
2989      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
2990      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2991      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2992      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2993      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2994    fi
2995    func_emit_initmacro_end
2996    echo "])"
2997    func_emit_initmacro_done
2998    echo
2999    echo "gl_INIT"
3000    echo
3001    if test -n "$subdirs_with_configure_ac"; then
3002      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3003    fi
3004    makefiles="Makefile"
3005    for d in $subdirs; do
3006      # For subdirs that have a configure.ac by their own, it's the subdir's
3007      # configure.ac which creates the subdir's Makefile.am, not this one.
3008      case " $subdirs_with_configure_ac " in
3009        *" $d "*) ;;
3010        *) func_append makefiles " $d/Makefile" ;;
3011      esac
3012    done
3013    echo "AC_OUTPUT([$makefiles])"
3014   ) > "$testdir/configure.ac"
3015
3016   # Create autogenerated files.
3017   (cd "$testdir"
3018    # Do not use "${AUTORECONF} --force --install", because it may invoke
3019    # autopoint, which brings in older versions of some of our .m4 files.
3020    if test -f $m4base/gettext.m4; then
3021      echo "executing ${AUTOPOINT} --force"
3022      ${AUTOPOINT} --force || func_exit 1
3023      for f in $m4base/*.m4~; do
3024        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3025      done
3026    fi
3027    echo "executing ${ACLOCAL} -I $m4base"
3028    ${ACLOCAL} -I $m4base || func_exit 1
3029    if ! test -d build-aux; then
3030      echo "executing mkdir build-aux"
3031      mkdir build-aux || func_exit 1
3032    fi
3033    echo "executing ${AUTOCONF}"
3034    ${AUTOCONF} || func_exit 1
3035    echo "executing ${AUTOHEADER}"
3036    ${AUTOHEADER} || func_exit 1
3037    echo "executing ${AUTOMAKE} --add-missing --copy"
3038    ${AUTOMAKE} --add-missing --copy || func_exit 1
3039   ) || func_exit 1
3040   if test -n "$inctests"; then
3041     # Create autogenerated files.
3042     (cd "$testdir/$testsbase" || func_exit 1
3043      # Do not use "${AUTORECONF} --force --install", because it may invoke
3044      # autopoint, which brings in older versions of some of our .m4 files.
3045      if test -f ../$m4base/gettext.m4; then
3046        echo "executing ${AUTOPOINT} --force"
3047        ${AUTOPOINT} --force || func_exit 1
3048        for f in ../$m4base/*.m4~; do
3049          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3050        done
3051      fi
3052      echo "executing ${ACLOCAL} -I ../$m4base"
3053      ${ACLOCAL} -I ../$m4base || func_exit 1
3054      if ! test -d ../build-aux; then
3055        echo "executing mkdir ../build-aux"
3056        mkdir ../build-aux
3057      fi
3058      echo "executing ${AUTOCONF}"
3059      ${AUTOCONF} || func_exit 1
3060      echo "executing ${AUTOHEADER}"
3061      ${AUTOHEADER} || func_exit 1
3062      echo "executing ${AUTOMAKE} --add-missing --copy"
3063      ${AUTOMAKE} --add-missing --copy || func_exit 1
3064     ) || func_exit 1
3065   fi
3066   # Need to run configure and make once, to create built files that are to be
3067   # distributed (such as getdate.c).
3068   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3069   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3070                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3071   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3072   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3073   # such $(FOO_H) because they don't refer to distributed files.
3074   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3075   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3076                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3077                  | sed -e "$sed_remove_make_variables"`
3078   distributed_built_sources=`for file in $built_sources; do
3079                                case "$cleaned_files" in
3080                                  *" "$file" "*) ;;
3081                                  *) echo $file ;;
3082                                esac;
3083                              done`
3084   if test -n "$distributed_built_sources"; then
3085     (cd "$testdir"
3086      ./configure || func_exit 1
3087        cd "$sourcebase"
3088        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3089        make built_sources || func_exit 1
3090        cd ..
3091      make distclean || func_exit 1
3092     ) || func_exit 1
3093   fi
3094 }
3095
3096 # func_create_megatestdir megatestdir allmodules
3097 # Input:
3098 # - local_gnulib_dir  from --local-dir
3099 # - auxdir          directory relative to destdir where to place build aux files
3100 func_create_megatestdir ()
3101 {
3102   megatestdir="$1"
3103   allmodules="$2"
3104   if test -z "$allmodules"; then
3105     allmodules=`func_all_modules`
3106   fi
3107
3108   megasubdirs=
3109   # First, all modules one by one.
3110   for onemodule in $allmodules; do
3111     func_create_testdir "$megatestdir/$onemodule" $onemodule
3112     func_append megasubdirs "$onemodule "
3113   done
3114   # Then, all modules all together.
3115   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3116   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3117   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3118   func_create_testdir "$megatestdir/ALL" "$allmodules"
3119   func_append megasubdirs "ALL"
3120
3121   # Create autobuild.
3122   cvsdate=`sh "$gnulib_dir/build-aux/mdate-sh" "$gnulib_dir/CVS/Entries" \
3123              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3124                    -e 's,February,02,'  -e 's,Feb,02,' \
3125                    -e 's,March,03,'     -e 's,Mar,03,' \
3126                    -e 's,April,04,'     -e 's,Apr,04,' \
3127                    -e 's,May,05,'                      \
3128                    -e 's,June,06,'      -e 's,Jun,06,' \
3129                    -e 's,July,07,'      -e 's,Jul,07,' \
3130                    -e 's,August,08,'    -e 's,Aug,08,' \
3131                    -e 's,September,09,' -e 's,Sep,09,' \
3132                    -e 's,October,10,'   -e 's,Oct,10,' \
3133                    -e 's,November,11,'  -e 's,Nov,11,' \
3134                    -e 's,December,12,'  -e 's,Dec,12,' \
3135                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3136                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3137   (echo '#!/bin/sh'
3138    echo "CVSDATE=$cvsdate"
3139    echo "test -d logs || mkdir logs"
3140    echo "for module in $megasubdirs; do"
3141    echo "  echo \"Working on module \$module...\""
3142    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3143    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3144    echo "   echo"
3145    echo "   set -x"
3146    echo "   : autobuild project... \$module"
3147    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3148    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3149    echo "   : autobuild hostname... \`hostname\`"
3150    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3151    echo "   echo rc=\$?"
3152    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3153    echo "done"
3154   ) > "$megatestdir/do-autobuild"
3155   chmod a+x "$megatestdir/do-autobuild"
3156
3157   # Create Makefile.am.
3158   (echo "## Process this file with automake to produce Makefile.in."
3159    echo
3160    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3161    echo
3162    echo "SUBDIRS = $megasubdirs"
3163    echo
3164    echo "EXTRA_DIST = do-autobuild"
3165   ) > "$megatestdir/Makefile.am"
3166
3167   # Create configure.ac.
3168   (echo "# Process this file with autoconf to produce a configure script."
3169    echo "AC_INIT([dummy], [0])"
3170    if test "$auxdir" != "."; then
3171      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3172    fi
3173    echo "AM_INIT_AUTOMAKE"
3174    echo
3175    echo "AC_PROG_MAKE_SET"
3176    echo
3177    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
3178    echo "AC_OUTPUT([Makefile])"
3179   ) > "$megatestdir/configure.ac"
3180
3181   # Create autogenerated files.
3182   (cd "$megatestdir"
3183    # Do not use "${AUTORECONF} --install", because autoreconf operates
3184    # recursively, but the subdirectories are already finished, therefore
3185    # calling autoreconf here would only waste lots of CPU time.
3186    echo "executing ${ACLOCAL}"
3187    ${ACLOCAL} || func_exit 1
3188    echo "executing mkdir build-aux"
3189    mkdir build-aux
3190    echo "executing ${AUTOCONF}"
3191    ${AUTOCONF} || func_exit 1
3192    echo "executing ${AUTOMAKE} --add-missing --copy"
3193    ${AUTOMAKE} --add-missing --copy || func_exit 1
3194   ) || func_exit 1
3195 }
3196
3197 case $mode in
3198   "" )
3199     func_fatal_error "no mode specified" ;;
3200
3201   list )
3202     func_all_modules
3203     ;;
3204
3205   import | update )
3206
3207     # Where to import.
3208     if test -z "$destdir"; then
3209       destdir=.
3210     fi
3211     test -d "$destdir" \
3212       || func_fatal_error "destination directory does not exist: $destdir"
3213
3214     # Prefer configure.ac to configure.in.
3215     if test -f "$destdir"/configure.ac; then
3216       configure_ac="$destdir/configure.ac"
3217     else
3218       if test -f "$destdir"/configure.in; then
3219         configure_ac="$destdir/configure.in"
3220       else
3221         func_fatal_error "cannot find $destdir/configure.ac"
3222       fi
3223     fi
3224
3225     # Analyze configure.ac.
3226     guessed_auxdir="."
3227     guessed_libtool=false
3228     my_sed_traces='
3229       s,#.*$,,
3230       s,^dnl .*$,,
3231       s, dnl .*$,,
3232       /AC_CONFIG_AUX_DIR/ {
3233         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
3234       }
3235       /A[CM]_PROG_LIBTOOL/ {
3236         s,^.*$,guessed_libtool=true,p
3237       }'
3238     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
3239
3240     if test -z "$auxdir"; then
3241       auxdir="$guessed_auxdir"
3242     fi
3243
3244     # Determine where to apply func_import.
3245     if test -n "$m4base"; then
3246       # Apply func_import to a particular gnulib directory.
3247       # Any number of additional modules can be given.
3248       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
3249         # First use of gnulib in the given m4base.
3250         test -n "$supplied_libname" || supplied_libname=true
3251         test -n "$sourcebase" || sourcebase="lib"
3252         test -n "$docbase" || docbase="doc"
3253         test -n "$testsbase" || testsbase="tests"
3254         test -n "$macro_prefix" || macro_prefix="gl"
3255       fi
3256       func_import "$*"
3257     else
3258       # Apply func_import to all gnulib directories.
3259       # To get this list of directories, look at Makefile.am. (Not at
3260       # configure, because it may be omitted from CVS. Also, don't run
3261       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
3262       m4dirs=
3263       m4dirs_count=0
3264       if test -f "$destdir"/Makefile.am; then
3265         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
3266         m4dir_is_next=
3267         for arg in $aclocal_amflags; do
3268           if test -n "$m4dir_is_next"; then
3269             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
3270             case "$arg" in
3271               /*) ;;
3272               *)
3273                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
3274                   func_append m4dirs " $arg"
3275                   m4dirs_count=`expr $m4dirs_count + 1`
3276                 fi
3277                 ;;
3278             esac
3279             m4dir_is_next=
3280           else
3281             if test "X$arg" = "X-I"; then
3282               m4dir_is_next=yes
3283             else
3284               m4dir_is_next=
3285             fi
3286           fi
3287         done
3288       else
3289         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
3290         if test -f "$destdir"/aclocal.m4; then
3291           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
3292           sedexpr2='s,^[^/]*$,.,'
3293           sedexpr3='s,/[^/]*$,,'
3294           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
3295           m4dirs_count=`echo "$m4dirs" | wc -l`
3296         fi
3297       fi
3298       if test $m4dirs_count = 0; then
3299         # First use of gnulib in a package.
3300         # Any number of additional modules can be given.
3301         test -n "$supplied_libname" || supplied_libname=true
3302         test -n "$sourcebase" || sourcebase="lib"
3303         m4base="m4"
3304         test -n "$docbase" || docbase="doc"
3305         test -n "$testsbase" || testsbase="tests"
3306         test -n "$macro_prefix" || macro_prefix="gl"
3307         func_import "$*"
3308       else
3309         if test $m4dirs_count = 1; then
3310           # There's only one use of gnulib here. Assume the user means it.
3311           # Any number of additional modules can be given.
3312           for m4base in $m4dirs; do
3313             func_import "$*"
3314           done
3315         else
3316           # Ambiguous - guess what the user meant.
3317           if test $# = 0; then
3318             # No further arguments. Guess the user wants to update all of them.
3319             for m4base in $m4dirs; do
3320               # Perform func_import in a subshell, so that variable values
3321               # such as
3322               #   local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
3323               #   testsbase, inctests, libname, lgpl, makefile_name, libtool,
3324               #   macro_prefix
3325               # don't propagate from one directory to another.
3326               (func_import) || func_exit 1
3327             done
3328           else
3329             # Really ambiguous.
3330             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
3331           fi
3332         fi
3333       fi
3334     fi
3335     ;;
3336
3337   create-testdir )
3338     if test -z "$destdir"; then
3339       func_fatal_error "please specify --dir option"
3340     fi
3341     mkdir "$destdir"
3342     test -d "$destdir" \
3343       || func_fatal_error "could not create destination directory"
3344     test -n "$auxdir" || auxdir="build-aux"
3345     func_create_testdir "$destdir" "$*"
3346     ;;
3347
3348   create-megatestdir )
3349     if test -z "$destdir"; then
3350       func_fatal_error "please specify --dir option"
3351     fi
3352     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3353     test -n "$auxdir" || auxdir="build-aux"
3354     func_create_megatestdir "$destdir" "$*"
3355     ;;
3356
3357   test )
3358     test -n "$destdir" || destdir=testdir$$
3359     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3360     test -n "$auxdir" || auxdir="build-aux"
3361     func_create_testdir "$destdir" "$*"
3362     cd "$destdir"
3363       mkdir build
3364       cd build
3365         ../configure || func_exit 1
3366         make || func_exit 1
3367         make check || func_exit 1
3368         make distclean || func_exit 1
3369         remaining=`find . -type f -print`
3370         if test -n "$remaining"; then
3371           echo "Remaining files:" $remaining 1>&2
3372           echo "gnulib-tool: *** Stop." 1>&2
3373           func_exit 1
3374         fi
3375       cd ..
3376     cd ..
3377     rm -rf "$destdir"
3378     ;;
3379
3380   megatest )
3381     test -n "$destdir" || destdir=testdir$$
3382     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3383     test -n "$auxdir" || auxdir="build-aux"
3384     func_create_megatestdir "$destdir" "$*"
3385     cd "$destdir"
3386       mkdir build
3387       cd build
3388         ../configure
3389         make
3390         make check
3391         make distclean
3392         remaining=`find . -type f -print`
3393         if test -n "$remaining"; then
3394           echo "Remaining files:" $remaining 1>&2
3395           echo "gnulib-tool: *** Stop." 1>&2
3396           func_exit 1
3397         fi
3398       cd ..
3399     cd ..
3400     rm -rf "$destdir"
3401     ;;
3402
3403   extract-description )
3404     for module
3405     do
3406       func_verify_module
3407       if test -n "$module"; then
3408         func_get_description "$module"
3409       fi
3410     done
3411     ;;
3412
3413   extract-filelist )
3414     for module
3415     do
3416       func_verify_module
3417       if test -n "$module"; then
3418         func_get_filelist "$module"
3419       fi
3420     done
3421     ;;
3422
3423   extract-dependencies )
3424     for module
3425     do
3426       func_verify_module
3427       if test -n "$module"; then
3428         func_get_dependencies "$module"
3429       fi
3430     done
3431     ;;
3432
3433   extract-autoconf-snippet )
3434     for module
3435     do
3436       func_verify_module
3437       if test -n "$module"; then
3438         func_get_autoconf_snippet "$module"
3439       fi
3440     done
3441     ;;
3442
3443   extract-automake-snippet )
3444     for module
3445     do
3446       func_verify_module
3447       if test -n "$module"; then
3448         func_get_automake_snippet "$module"
3449       fi
3450     done
3451     ;;
3452
3453   extract-include-directive )
3454     for module
3455     do
3456       func_verify_module
3457       if test -n "$module"; then
3458         func_get_include_directive "$module"
3459       fi
3460     done
3461     ;;
3462
3463   extract-link-directive )
3464     for module
3465     do
3466       func_verify_module
3467       if test -n "$module"; then
3468         func_get_link_directive "$module"
3469       fi
3470     done
3471     ;;
3472
3473   extract-license )
3474     for module
3475     do
3476       func_verify_module
3477       if test -n "$module"; then
3478         func_get_license "$module"
3479       fi
3480     done
3481     ;;
3482
3483   extract-maintainer )
3484     for module
3485     do
3486       func_verify_module
3487       if test -n "$module"; then
3488         func_get_maintainer "$module"
3489       fi
3490     done
3491     ;;
3492
3493   extract-tests-module )
3494     for module
3495     do
3496       func_verify_module
3497       if test -n "$module"; then
3498         func_get_tests_module "$module"
3499       fi
3500     done
3501     ;;
3502
3503   * )
3504     func_fatal_error "unknown operation mode --$mode" ;;
3505 esac
3506
3507 rm -rf "$tmp"
3508 # Undo the effect of the previous 'trap' command. Some shellology:
3509 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
3510 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
3511 # exit); for the others we need to call 'exit' explicitly. The value of $? is
3512 # 128 + signal number and is set before the trap-registered command is run.
3513 trap '' 0
3514 trap 'func_exit $?' 1 2 3 13 15
3515
3516 exit 0
3517
3518 # Local Variables:
3519 # indent-tabs-mode: nil
3520 # whitespace-check-buffer-indent: nil
3521 # End: