f97597163badd6de7eaf795c1a50cf8a81a8ab02
[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-18 23:45:37 $'
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       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
1227       buildaux_files=`for f in $all_files; do \
1228                         case $f in \
1229                           build-aux/*) echo $f ;; \
1230                         esac; \
1231                       done | sed -e 's,^build-aux/,,'`
1232       if test -n "$buildaux_files"; then
1233         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
1234         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
1235         echo
1236       fi
1237       ;;
1238   esac
1239 }
1240
1241 # func_get_include_directive module
1242 # Input:
1243 # - local_gnulib_dir  from --local-dir
1244 func_get_include_directive ()
1245 {
1246   func_lookup_file "modules/$1"
1247   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1248   sed -e 's/^\(["<]\)/#include \1/'
1249 }
1250
1251 # func_get_link_directive module
1252 # Input:
1253 # - local_gnulib_dir  from --local-dir
1254 func_get_link_directive ()
1255 {
1256   func_lookup_file "modules/$1"
1257   sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
1258 }
1259
1260 # func_get_license module
1261 # Input:
1262 # - local_gnulib_dir  from --local-dir
1263 func_get_license ()
1264 {
1265   func_lookup_file "modules/$1"
1266   { sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1267     # The default is GPL.
1268     echo "GPL"
1269   } | sed -e 's,^ *$,,' | sed -e 1q
1270 }
1271
1272 # func_get_maintainer module
1273 # Input:
1274 # - local_gnulib_dir  from --local-dir
1275 func_get_maintainer ()
1276 {
1277   func_lookup_file "modules/$1"
1278   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1279 }
1280
1281 # func_get_tests_module module
1282 # Input:
1283 # - local_gnulib_dir  from --local-dir
1284 func_get_tests_module ()
1285 {
1286   # The naming convention for tests modules is hardwired: ${module}-tests.
1287   if test -f "$gnulib_dir/modules/$1"-tests \
1288      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1289           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1290     echo "$1"-tests
1291   fi
1292 }
1293
1294 # func_acceptable module
1295 # tests whether a module is acceptable.
1296 # Input:
1297 # - avoidlist       list of modules to avoid
1298 func_acceptable ()
1299 {
1300   for avoid in $avoidlist; do
1301     if test "$avoid" = "$1"; then
1302       return 1
1303     fi
1304   done
1305   return 0
1306 }
1307
1308 # func_modules_transitive_closure
1309 # Input:
1310 # - local_gnulib_dir  from --local-dir
1311 # - modules         list of specified modules
1312 # - inctests        true if tests should be included, blank otherwise
1313 # - avoidlist       list of modules to avoid
1314 # - tmp             pathname of a temporary directory
1315 # Output:
1316 # - modules         list of modules, including dependencies
1317 func_modules_transitive_closure ()
1318 {
1319   # In order to process every module only once (for speed), process an "input
1320   # list" of modules, producing an "output list" of modules. During each round,
1321   # more modules can be queued in the input list. Once a module on the input
1322   # list has been processed, it is added to the "handled list", so we can avoid
1323   # to process it again.
1324   handledmodules=
1325   inmodules="$modules"
1326   outmodules=
1327   while test -n "$inmodules"; do
1328     inmodules_this_round="$inmodules"
1329     inmodules=                    # Accumulator, queue for next round
1330     for module in $inmodules_this_round; do
1331       func_verify_module
1332       if test -n "$module"; then
1333         if func_acceptable $module; then
1334           func_append outmodules " $module"
1335           deps=`func_get_dependencies $module`
1336           # Duplicate dependencies are harmless, but Jim wants a warning.
1337           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1338           if test -n "$duplicated_deps"; then
1339             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1340           fi
1341           func_append inmodules " $deps"
1342           if test -n "$inctests"; then
1343             testsmodule=`func_get_tests_module $module`
1344             if test -n "$testsmodule"; then
1345               func_append inmodules " $testsmodule"
1346             fi
1347           fi
1348         fi
1349       fi
1350     done
1351     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1352     # Remove $handledmodules from $inmodules.
1353     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1354     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1355   done
1356   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1357   rm -f "$tmp"/queued-modules
1358 }
1359
1360 # func_modules_add_dummy
1361 # Input:
1362 # - local_gnulib_dir  from --local-dir
1363 # - modules         list of modules, including dependencies
1364 # Output:
1365 # - modules         list of modules, including 'dummy' if needed
1366 func_modules_add_dummy ()
1367 {
1368   have_lib_SOURCES=
1369   sed_remove_backslash_newline=':a
1370 /\\$/{
1371 s/\\$//
1372 N
1373 s/\n//
1374 ba
1375 }'
1376   for module in $modules; do
1377     func_verify_nontests_module
1378     if test -n "$module"; then
1379       # Extract the value of "lib_SOURCES += ...".
1380       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1381         # Ignore .h files since they are not compiled.
1382         case "$file" in
1383           *.h) ;;
1384           *) have_lib_SOURCES=yes ;;
1385         esac
1386       done
1387     fi
1388   done
1389   # Add the dummy module, to make sure the library will be non-empty.
1390   if test -z "$have_lib_SOURCES"; then
1391     if func_acceptable "dummy"; then
1392       func_append modules " dummy"
1393     fi
1394   fi
1395 }
1396
1397 # func_modules_to_filelist
1398 # Input:
1399 # - local_gnulib_dir  from --local-dir
1400 # - modules         list of modules, including dependencies
1401 # Output:
1402 # - files           list of files
1403 func_modules_to_filelist ()
1404 {
1405   files=
1406   for module in $modules; do
1407     func_verify_module
1408     if test -n "$module"; then
1409       fs=`func_get_filelist $module`
1410       func_append files " $fs"
1411     fi
1412   done
1413   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1414 }
1415
1416 # func_emit_lib_Makefile_am
1417 # emits the contents of library makefile to standard output.
1418 # Input:
1419 # - local_gnulib_dir  from --local-dir
1420 # - modules         list of modules, including dependencies
1421 # - libname         library name
1422 # - auxdir          directory relative to destdir where to place build aux files
1423 # - makefile_name   from --makefile-name
1424 # - libtool         true if libtool will be used, false or blank otherwise
1425 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1426 # - actioncmd       (optional) command that will reproduce this invocation
1427 # - for_test        true if creating a package for testing, false otherwise
1428 # Output:
1429 # - uses_subdirs    nonempty if object files in subdirs exist
1430 func_emit_lib_Makefile_am ()
1431 {
1432   # When creating an includable Makefile.am snippet, augment variables with
1433   # += instead of assigning them.
1434   if test -n "$makefile_name"; then
1435     assign='+='
1436   else
1437     assign='='
1438   fi
1439   if test "$libtool" = true; then
1440     libext=la
1441     perhapsLT=LT
1442     sed_eliminate_LDFLAGS=
1443   else
1444     libext=a
1445     perhapsLT=
1446     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1447   fi
1448   if $for_test; then
1449     # When creating a package for testing: Attempt to provoke failures,
1450     # especially link errors, already during "make" rather than during
1451     # "make check", because "make check" is not possible in a cross-compiling
1452     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1453     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1454   else
1455     sed_transform_check_PROGRAMS=
1456   fi
1457   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1458   echo "## Process this file with automake to produce Makefile.in."
1459   func_emit_copyright_notice
1460   if test -n "$actioncmd"; then
1461     echo "# Reproduce by: $actioncmd"
1462   fi
1463   echo
1464   uses_subdirs=
1465   {
1466     for module in $modules; do
1467       func_verify_nontests_module
1468       if test -n "$module"; then
1469         {
1470           func_get_automake_snippet "$module" |
1471             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1472                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1473                 -e "$sed_eliminate_LDFLAGS" \
1474                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1475                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1476                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1477                 -e "$sed_transform_check_PROGRAMS"
1478           if test "$module" = 'alloca'; then
1479             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1480             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1481           fi
1482         } > amsnippet.tmp
1483         # Skip the contents if its entirely empty.
1484         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1485           echo "## begin gnulib module $module"
1486           echo
1487           cat amsnippet.tmp
1488           echo "## end   gnulib module $module"
1489           echo
1490         fi
1491         rm -f amsnippet.tmp
1492         # Test whether there are some source files in subdirectories.
1493         for f in `func_get_filelist "$module"`; do
1494           case $f in
1495             lib/*/*.c) uses_subdirs=yes ;;
1496           esac
1497         done
1498       fi
1499     done
1500   } > allsnippets.tmp
1501   if test -z "$makefile_name"; then
1502     # If there are source files in subdirectories, prevent collision of the
1503     # object files (example: hash.c and libxml/hash.c).
1504     subdir_options=
1505     if test -n "$uses_subdirs"; then
1506       subdir_options=' subdir-objects'
1507     fi
1508     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1509   fi
1510   echo
1511   if test -z "$makefile_name"; then
1512     echo "noinst_HEADERS ="
1513     echo "noinst_LIBRARIES ="
1514     echo "noinst_LTLIBRARIES ="
1515     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1516     # if you specify pkgdata_DATA to empty. This is a workaround.
1517     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1518       echo "pkgdata_DATA ="
1519     fi
1520     echo "EXTRA_DIST ="
1521     echo "BUILT_SOURCES ="
1522     echo "SUFFIXES ="
1523   fi
1524   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1525   if test -z "$makefile_name"; then
1526     echo "MOSTLYCLEANDIRS ="
1527     echo "CLEANFILES ="
1528     echo "DISTCLEANFILES ="
1529     echo "MAINTAINERCLEANFILES ="
1530     echo
1531     echo "AM_CPPFLAGS ="
1532   fi
1533   echo
1534   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1535     # One of the snippets already specifies an installation location for the
1536     # library. Don't confuse automake by saying it should not be installed.
1537     :
1538   else
1539     # By default, the generated library should not be installed.
1540     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1541   fi
1542   echo
1543   echo "${libname}_${libext}_SOURCES ="
1544   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1545   # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1546   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1547   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1548   echo "EXTRA_${libname}_${libext}_SOURCES ="
1549   if test "$libtool" = true; then
1550     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1551   fi
1552   echo
1553   cat allsnippets.tmp \
1554     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1555   echo
1556   echo "mostlyclean-local: mostlyclean-generic"
1557   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1558   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1559   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1560   echo "          fi; \\"
1561   echo "        done; \\"
1562   echo "        :"
1563   rm -f allsnippets.tmp
1564 }
1565
1566 # func_emit_tests_Makefile_am
1567 # emits the contents of tests makefile to standard output.
1568 # Input:
1569 # - local_gnulib_dir  from --local-dir
1570 # - modules         list of modules, including dependencies
1571 # - libname         library name
1572 # - makefile_name   from --makefile-name
1573 # - libtool         true if libtool will be used, false or blank otherwise
1574 # - sourcebase      relative directory containing lib source code
1575 # - m4base          relative directory containing autoconf macros
1576 # - testsbase       relative directory containing unit test code
1577 # - for_test        true if creating a package for testing, false otherwise
1578 func_emit_tests_Makefile_am ()
1579 {
1580   if test "$libtool" = true; then
1581     libext=la
1582   else
1583     libext=a
1584   fi
1585   if test "$libtool" = true; then
1586     libext=la
1587     sed_eliminate_LDFLAGS=
1588   else
1589     libext=a
1590     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1591   fi
1592   if $for_test; then
1593     # When creating a package for testing: Attempt to provoke failures,
1594     # especially link errors, already during "make" rather than during
1595     # "make check", because "make check" is not possible in a cross-compiling
1596     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1597     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1598   else
1599     sed_transform_check_PROGRAMS=
1600   fi
1601   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1602   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1603   echo "## Process this file with automake to produce Makefile.in."
1604   func_emit_copyright_notice
1605   echo
1606   # Generate dependencies here, since it eases the debugging of test failures.
1607   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1608   echo
1609   echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1610   echo
1611   (
1612     for module in $modules; do
1613       func_verify_tests_module
1614       if test -n "$module"; then
1615         {
1616           func_get_automake_snippet "$module" |
1617             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1618                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1619                 -e "$sed_eliminate_LDFLAGS" \
1620                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1621                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1622                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1623                 -e "$sed_transform_check_PROGRAMS"
1624         } > amsnippet.tmp
1625         # Skip the contents if its entirely empty.
1626         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1627           echo "## begin gnulib module $module"
1628           echo
1629           cat amsnippet.tmp
1630           echo "## end   gnulib module $module"
1631           echo
1632         fi
1633         rm -f amsnippet.tmp
1634       fi
1635     done
1636   ) > allsnippets.tmp
1637   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1638   # variable is needed to avoid an error from automake:
1639   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1640   echo "SUBDIRS ="
1641   echo "TESTS ="
1642   echo "TESTS_ENVIRONMENT ="
1643   echo "noinst_PROGRAMS ="
1644   if ! $for_test; then
1645     echo "check_PROGRAMS ="
1646   fi
1647   echo "noinst_HEADERS ="
1648   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1649     echo "pkgdata_DATA ="
1650   fi
1651   echo "EXTRA_DIST ="
1652   echo "BUILT_SOURCES ="
1653   echo "SUFFIXES ="
1654   echo "MOSTLYCLEANFILES = core *.stackdump"
1655   echo "MOSTLYCLEANDIRS ="
1656   echo "CLEANFILES ="
1657   echo "DISTCLEANFILES ="
1658   echo "MAINTAINERCLEANFILES ="
1659   echo
1660   echo "AM_CPPFLAGS = \\"
1661   echo "  -I. -I\$(srcdir) \\"
1662   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1663   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1664   echo
1665   echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1666   echo
1667   cat allsnippets.tmp
1668   echo "# Clean up after Solaris cc."
1669   echo "clean-local:"
1670   echo "        rm -rf SunWS_cache"
1671   echo
1672   echo "mostlyclean-local: mostlyclean-generic"
1673   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1674   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1675   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1676   echo "          fi; \\"
1677   echo "        done; \\"
1678   echo "        :"
1679   rm -f allsnippets.tmp
1680 }
1681
1682 # func_emit_initmacro_start
1683 # emits the first few statements of the gl_INIT macro to standard output.
1684 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1685 func_emit_initmacro_start ()
1686 {
1687   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1688   # platform-dependent object files in ${macro_prefix}_LIBOBJS instead of
1689   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1690   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1691   # flexibility.)
1692   # Furthermore it avoids an automake error like this when a Makefile.am
1693   # that uses pieces of gnulib also uses $(LIBOBJ):
1694   #   automatically discovered file `error.c' should not be explicitly mentioned
1695   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix}_LIBOBJ]))"
1696   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix}_REPLACE_FUNCS]))"
1697   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1698   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1699   #   automatically discovered file `error.c' should not be explicitly mentioned
1700   # We let automake know about the files to be distributed through the
1701   # EXTRA_lib_SOURCES variable.
1702   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix}_LIBSOURCES]))"
1703 }
1704
1705 # func_emit_initmacro_end
1706 # emits the last few statements of the gl_INIT macro to standard output.
1707 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1708 func_emit_initmacro_end ()
1709 {
1710   echo "  m4_popdef([AC_LIBSOURCES])"
1711   echo "  m4_popdef([AC_REPLACE_FUNCS])"
1712   echo "  m4_popdef([AC_LIBOBJ])"
1713   echo "  AC_CONFIG_COMMANDS_PRE(["
1714   echo "    ${macro_prefix}_libobjs="
1715   echo "    ${macro_prefix}_ltlibobjs="
1716   echo "    if test -n \"\$${macro_prefix}_LIBOBJS\"; then"
1717   echo "      # Remove the extension."
1718   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
1719   echo "      for i in \`for i in \$${macro_prefix}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
1720   echo "        ${macro_prefix}_libobjs=\"\$${macro_prefix}_libobjs \$i.\$ac_objext\""
1721   echo "        ${macro_prefix}_ltlibobjs=\"\$${macro_prefix}_ltlibobjs \$i.lo\""
1722   echo "      done"
1723   echo "    fi"
1724   echo "    AC_SUBST([${macro_prefix}_LIBOBJS], [\$${macro_prefix}_libobjs])"
1725   echo "    AC_SUBST([${macro_prefix}_LTLIBOBJS], [\$${macro_prefix}_ltlibobjs])"
1726   echo "  ])"
1727 }
1728
1729 # func_emit_initmacro_done
1730 # emits a few statements after the gl_INIT macro to standard output.
1731 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1732 func_emit_initmacro_done ()
1733 {
1734   echo
1735   echo "# Like AC_LIBOBJ, except that the module name goes"
1736   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1737   echo "AC_DEFUN([${macro_prefix}_LIBOBJ],"
1738   echo "  [${macro_prefix}_LIBOBJS=\"\$${macro_prefix}_LIBOBJS \$1.\$ac_objext\"])"
1739   echo
1740   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
1741   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1742   echo "AC_DEFUN([${macro_prefix}_REPLACE_FUNCS],"
1743   echo "  [AC_CHECK_FUNCS([\$1], , [${macro_prefix}_LIBOBJ(\$ac_func)])])"
1744   echo
1745   echo "# Like AC_LIBSOURCES, except that it does nothing."
1746   echo "# We rely on EXTRA_lib..._SOURCES instead."
1747   echo "AC_DEFUN([${macro_prefix}_LIBSOURCES],"
1748   echo "  [])"
1749 }
1750
1751 # func_import modules
1752 # Uses also the variables
1753 # - destdir         target directory
1754 # - local_gnulib_dir  from --local-dir
1755 # - libname         library name
1756 # - sourcebase      directory relative to destdir where to place source code
1757 # - m4base          directory relative to destdir where to place *.m4 macros
1758 # - docbase         directory relative to destdir where to place doc files
1759 # - testsbase       directory relative to destdir where to place unit test code
1760 # - auxdir          directory relative to destdir where to place build aux files
1761 # - inctests        true if --with-tests was given, blank otherwise
1762 # - avoidlist       list of modules to avoid, from --avoid
1763 # - lgpl            true if library's license shall be LGPL, blank otherwise
1764 # - makefile_name   from --makefile-name
1765 # - libtool         true if --libtool was given, false if --no-libtool was
1766 #                   given, blank otherwise
1767 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1768 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1769 # - autoconf_minversion  minimum supported autoconf version
1770 # - doit            : if actions shall be executed, false if only to be printed
1771 # - symbolic        true if files should be symlinked, copied otherwise
1772 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
1773 #                   copied otherwise
1774 # - do_copyrights   true if copyright notices in files should be replaced,
1775 #                   blank otherwise
1776 func_import ()
1777 {
1778   # Get the cached settings.
1779   cached_local_gnulib_dir=
1780   cached_specified_modules=
1781   cached_avoidlist=
1782   cached_sourcebase=
1783   cached_m4base=
1784   cached_docbase=
1785   cached_testsbase=
1786   cached_inctests=
1787   cached_libname=
1788   cached_lgpl=
1789   cached_makefile_name=
1790   cached_libtool=
1791   cached_macro_prefix=
1792   cached_files=
1793   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1794     cached_libtool=false
1795     my_sed_traces='
1796       s,#.*$,,
1797       s,^dnl .*$,,
1798       s, dnl .*$,,
1799       /gl_LOCAL_DIR(/ {
1800         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1801       }
1802       /gl_MODULES(/ {
1803         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1804       }
1805       /gl_AVOID(/ {
1806         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1807       }
1808       /gl_SOURCE_BASE(/ {
1809         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1810       }
1811       /gl_M4_BASE(/ {
1812         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1813       }
1814       /gl_DOC_BASE(/ {
1815         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1816       }
1817       /gl_TESTS_BASE(/ {
1818         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1819       }
1820       /gl_WITH_TESTS/ {
1821         s,^.*$,cached_inctests=true,p
1822       }
1823       /gl_LIB(/ {
1824         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1825       }
1826       /gl_LGPL/ {
1827         s,^.*$,cached_lgpl=true,p
1828       }
1829       /gl_MAKEFILE_NAME(/ {
1830         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1831       }
1832       /gl_LIBTOOL/ {
1833         s,^.*$,cached_libtool=true,p
1834       }
1835       /gl_MACRO_PREFIX(/ {
1836         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1837       }'
1838     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1839     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1840       my_sed_traces='
1841         s,#.*$,,
1842         s,^dnl .*$,,
1843         s, dnl .*$,,
1844         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1845           s,^.*$,cached_files=",p
1846           n
1847           ta
1848           :a
1849           s,^\]).*$,",
1850           tb
1851           p
1852           n
1853           ba
1854           :b
1855           p
1856         }'
1857       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1858     fi
1859   fi
1860
1861   # Merge the cached settings with the specified ones.
1862   # The m4base must be the same as expected from the pathname.
1863   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1864     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1865   fi
1866   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1867   # is relative to $destdir, whereas the one we use is relative to . or absolute.
1868   if test -z "$local_gnulib_dir"; then
1869     if test -n "$cached_local_gnulib_dir"; then
1870       case "$destdir" in
1871         /*)
1872           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1873         *)
1874           case "$cached_local_gnulib_dir" in
1875             /*)
1876               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1877             *)
1878               func_relconcat "$destdir" "$cached_local_gnulib_dir"
1879               local_gnulib_dir="$relconcat" ;;
1880           esac ;;
1881       esac
1882     fi
1883   fi
1884   # Append the cached and the specified module names. So that
1885   # "gnulib-tool --import foo" means to add the module foo.
1886   specified_modules="$cached_specified_modules $1"
1887   # Append the cached and the specified avoidlist. This is probably better
1888   # than dropping the cached one when --avoid is specified at least once.
1889   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
1890   avoidlist=`echo $avoidlist`
1891
1892     # The sourcebase defaults to the cached one.
1893   if test -z "$sourcebase"; then
1894     sourcebase="$cached_sourcebase"
1895     if test -z "$sourcebase"; then
1896       func_fatal_error "missing --source-base option"
1897     fi
1898   fi
1899   # The docbase defaults to the cached one.
1900   if test -z "$docbase"; then
1901     docbase="$cached_docbase"
1902     if test -z "$docbase"; then
1903       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."
1904     fi
1905   fi
1906   # The testsbase defaults to the cached one.
1907   if test -z "$testsbase"; then
1908     testsbase="$cached_testsbase"
1909     if test -z "$testsbase"; then
1910       func_fatal_error "missing --tests-base option"
1911     fi
1912   fi
1913   # Require the tests if specified either way.
1914   if test -z "$inctests"; then
1915     inctests="$cached_inctests"
1916   fi
1917   # The libname defaults to the cached one.
1918   if test -z "$supplied_libname"; then
1919     libname="$cached_libname"
1920     if test -z "$libname"; then
1921       func_fatal_error "missing --lib option"
1922     fi
1923   fi
1924   # Require LGPL if specified either way.
1925   if test -z "$lgpl"; then
1926     lgpl="$cached_lgpl"
1927   fi
1928   # The makefile_name defaults to the cached one.
1929   if test -z "$makefile_name"; then
1930     makefile_name="$cached_makefile_name"
1931   fi
1932   # Use libtool if specified either way, or if guessed.
1933   if test -z "$libtool"; then
1934     if test -n "$cached_m4base"; then
1935       libtool="$cached_libtool"
1936     else
1937       libtool="$guessed_libtool"
1938     fi
1939   fi
1940   # The macro_prefix defaults to the cached one.
1941   if test -z "$macro_prefix"; then
1942     macro_prefix="$cached_macro_prefix"
1943     if test -z "$macro_prefix"; then
1944       func_fatal_error "missing --macro-prefix option"
1945     fi
1946   fi
1947
1948   # Canonicalize the list of specified modules.
1949   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1950
1951   # Determine final module list.
1952   modules="$specified_modules"
1953   func_modules_transitive_closure
1954   echo "Module list with included dependencies:"
1955   echo "$modules" | sed -e 's/^/  /'
1956
1957   # Add the dummy module if needed.
1958   func_modules_add_dummy
1959
1960   # If --lgpl, verify that the licenses of modules are compatible.
1961   if test -n "$lgpl"; then
1962     for module in $modules; do
1963       license=`func_get_license $module`
1964       case $license in
1965         LGPL | LGPLv2+ | 'GPLed build tool') ;;
1966         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1967         *) func_fatal_error "incompatible license on module $module: $license" ;;
1968       esac
1969     done
1970   fi
1971
1972   # Determine script to apply to imported library files.
1973   sed_transform_lib_file=
1974   for module in $modules; do
1975     if test $module = config-h; then
1976       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1977       sed_transform_lib_file=$sed_transform_lib_file'
1978         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
1979       '
1980       break
1981     fi
1982   done
1983   if test -n "$do_copyrights"; then
1984     if test -n "$lgpl"; then
1985       # Update license.
1986       sed_transform_lib_file=$sed_transform_lib_file'
1987         s/GNU General/GNU Lesser General/g
1988         s/version 2\([ ,]\)/version 2.1\1/g
1989       '
1990     fi
1991   fi
1992
1993   # Determine final file list.
1994   func_modules_to_filelist
1995   echo "File list:"
1996   echo "$files" | sed -e 's/^/  /'
1997
1998   test -n "$files" \
1999     || func_fatal_error "refusing to do nothing"
2000
2001   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2002   new_files="$files m4/gnulib-tool.m4"
2003   old_files="$cached_files"
2004   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2005     func_append old_files " m4/gnulib-tool.m4"
2006   fi
2007
2008   sed_rewrite_old_files="\
2009     s,^build-aux/,$auxdir/,
2010     s,^doc/,$cached_docbase/,
2011     s,^lib/,$cached_sourcebase/,
2012     s,^m4/,$cached_m4base/,
2013     s,^tests/,$cached_testsbase/,"
2014   sed_rewrite_new_files="\
2015     s,^build-aux/,$auxdir/,
2016     s,^doc/,$docbase/,
2017     s,^lib/,$sourcebase/,
2018     s,^m4/,$m4base/,
2019     s,^tests/,$testsbase/,"
2020
2021   # Create directories.
2022   { echo "$sourcebase"
2023     echo "$m4base"
2024     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2025     if test -n "$docfiles"; then
2026       echo "$docbase"
2027     fi
2028     if test -n "$inctests"; then
2029       echo "$testsbase"
2030     fi
2031     echo "$auxdir"
2032     for f in $files; do echo $f; done \
2033       | sed -e "$sed_rewrite_new_files" \
2034       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2035       | LC_ALL=C sort -u
2036   } > "$tmp"/dirs
2037   { # Rearrange file descriptors. Needed because "while ... done < ..."
2038     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2039     exec 5<&0 < "$tmp"/dirs
2040     while read d; do
2041       if test ! -d "$destdir/$d"; then
2042         if $doit; then
2043           echo "Creating directory $destdir/$d"
2044           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2045         else
2046           echo "Create directory $destdir/$d"
2047         fi
2048       fi
2049     done
2050     exec 0<&5 5<&-
2051   }
2052
2053   # func_dest_tmpfilename file
2054   # determines the name of a temporary file (file is relative to destdir).
2055   # Sets variable:
2056   #   - tmpfile       absolute filename of the temporary file
2057   func_dest_tmpfilename ()
2058   {
2059     if $doit; then
2060       # Put the new contents of $file in a file in the same directory (needed
2061       # to guarantee that an 'mv' to "$destdir/$file" works).
2062       tmpfile="$destdir/$1.tmp"
2063     else
2064       # Put the new contents of $file in a file in a temporary directory
2065       # (because the directory of "$file" might not exist).
2066       tmpfile="$tmp"/`basename "$1"`.tmp
2067     fi
2068   }
2069
2070   # Copy files or make symbolic links. Remove obsolete files.
2071   added_files=''
2072   removed_files=''
2073   delimiter='   '
2074   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2075   # representing the files according to the last gnulib-tool invocation.
2076   for f in $old_files; do echo $f; done \
2077     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2078     | LC_ALL=C sort \
2079     > "$tmp"/old-files
2080   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2081   # representing the files after this gnulib-tool invocation.
2082   for f in $new_files; do echo $f; done \
2083     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2084     | LC_ALL=C sort \
2085     > "$tmp"/new-files
2086   # First the files that are in old-files, but not in new-files:
2087   sed_take_first_column='s,'"$delimiter"'.*,,'
2088   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2089     # Remove the file. Do nothing if the user already removed it.
2090     if test -f "$destdir/$g"; then
2091       if $doit; then
2092         echo "Removing file $g (backup in ${g}~)"
2093         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2094       else
2095         echo "Remove file $g (backup in ${g}~)"
2096       fi
2097       func_append removed_files "$g$nl"
2098     fi
2099   done
2100   # func_add_or_update handles a file that ought to be present afterwards.
2101   # Uses parameters
2102   # - f             the original file name
2103   # - g             the rewritten file name
2104   # - already_present  nonempty if the file already exists, empty otherwise
2105   func_add_or_update ()
2106   {
2107     func_dest_tmpfilename "$g"
2108     func_lookup_file "$f"
2109     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2110     if test -n "$sed_transform_lib_file"; then
2111       case "$f" in
2112         lib/*)
2113           sed -e "$sed_transform_lib_file" \
2114             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2115           ;;
2116       esac
2117     fi
2118     if test -f "$destdir/$g"; then
2119       # The file already exists.
2120       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2121         : # The file has not changed.
2122       else
2123         # Replace the file.
2124         if $doit; then
2125           if test -n "$already_present"; then
2126             echo "Updating file $g (backup in ${g}~)"
2127           else
2128             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
2129           fi
2130           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2131           if { test -n "$symbolic" \
2132                || { test -n "$lsymbolic" \
2133                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2134              && test -z "$lookedup_tmp" \
2135              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2136             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2137           else
2138             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2139           fi
2140         else
2141           if test -n "$already_present"; then
2142             echo "Update file $g (backup in ${g}~)"
2143           else
2144             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
2145           fi
2146         fi
2147       fi
2148     else
2149       # Install the file.
2150       # Don't protest if the file should be there but isn't: it happens
2151       # frequently that developers don't put autogenerated files into CVS.
2152       if $doit; then
2153         echo "Copying file $g"
2154         if { test -n "$symbolic" \
2155              || { test -n "$lsymbolic" \
2156                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2157            && test -z "$lookedup_tmp" \
2158            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2159           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2160         else
2161           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2162         fi
2163       else
2164         echo "Copy file $g"
2165       fi
2166       func_append added_files "$g$nl"
2167     fi
2168     rm -f "$tmpfile"
2169   }
2170   # Then the files that are in new-files, but not in old-files:
2171   sed_take_last_column='s,^.*'"$delimiter"',,'
2172   already_present=
2173   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2174     | sed -e "$sed_take_last_column" \
2175     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2176   { # Rearrange file descriptors. Needed because "while ... done < ..."
2177     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2178     exec 5<&0 < "$tmp"/added-files
2179     while read g f; do
2180       func_add_or_update
2181     done
2182     exec 0<&5 5<&-
2183   }
2184   # Then the files that are in new-files and in old-files:
2185   already_present=true
2186   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2187     | sed -e "$sed_take_last_column" \
2188     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2189   { # Rearrange file descriptors. Needed because "while ... done < ..."
2190     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2191     exec 5<&0 < "$tmp"/kept-files
2192     while read g f; do
2193       func_add_or_update
2194     done
2195     exec 0<&5 5<&-
2196   }
2197
2198   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2199   actioncmd="gnulib-tool --import"
2200   func_append actioncmd " --dir=$destdir"
2201   if test -n "$local_gnulib_dir"; then
2202     func_append actioncmd " --local-dir=$local_gnulib_dir"
2203   fi
2204   func_append actioncmd " --lib=$libname"
2205   func_append actioncmd " --source-base=$sourcebase"
2206   func_append actioncmd " --m4-base=$m4base"
2207   func_append actioncmd " --doc-base=$docbase"
2208   func_append actioncmd " --aux-dir=$auxdir"
2209   if test -n "$inctests"; then
2210     func_append actioncmd " --with-tests"
2211   fi
2212   for module in $avoidlist; do
2213     func_append actioncmd " --avoid=$module"
2214   done
2215   if test -n "$lgpl"; then
2216     func_append actioncmd " --lgpl"
2217   fi
2218   if test -n "$makefile_name"; then
2219     func_append actioncmd " --makefile-name=$makefile_name"
2220   fi
2221   if test "$libtool" = true; then
2222     func_append actioncmd " --libtool"
2223   else
2224     func_append actioncmd " --no-libtool"
2225   fi
2226   func_append actioncmd " --macro-prefix=$macro_prefix"
2227   func_append actioncmd " `echo $specified_modules`"
2228
2229   # Default the makefile name to Makefile.am.
2230   if test -n "$makefile_name"; then
2231     makefile_am=$makefile_name
2232   else
2233     makefile_am=Makefile.am
2234   fi
2235
2236   # Create normal Makefile.ams.
2237   for_test=false
2238
2239   # Create library makefile.
2240   func_dest_tmpfilename $sourcebase/$makefile_am
2241   func_emit_lib_Makefile_am > "$tmpfile"
2242   if test -f "$destdir"/$sourcebase/$makefile_am; then
2243     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2244       rm -f "$tmpfile"
2245     else
2246       if $doit; then
2247         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2248         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2249         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2250       else
2251         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2252         rm -f "$tmpfile"
2253       fi
2254     fi
2255   else
2256     if $doit; then
2257       echo "Creating $sourcebase/$makefile_am"
2258       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2259     else
2260       echo "Create $sourcebase/$makefile_am"
2261       rm -f "$tmpfile"
2262     fi
2263     func_append added_files "$sourcebase/$makefile_am$nl"
2264   fi
2265
2266   # Create m4/gnulib-cache.m4.
2267   func_dest_tmpfilename $m4base/gnulib-cache.m4
2268   (
2269     func_emit_copyright_notice
2270     echo "#"
2271     echo "# This file represents the specification of how gnulib-tool is used."
2272     echo "# It acts as a cache: It is written and read by gnulib-tool."
2273     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2274     echo "# like the configure.ac and various Makefile.am files."
2275     echo
2276     echo
2277     echo "# Specification in the form of a command-line invocation:"
2278     echo "#   $actioncmd"
2279     echo
2280     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
2281     # Store the local_gnulib_dir relative to destdir.
2282     case "$local_gnulib_dir" in
2283       "" | /*)
2284         relative_local_gnulib_dir="$local_gnulib_dir" ;;
2285       * )
2286         case "$destdir" in
2287           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
2288           *)
2289             # destdir, local_gnulib_dir are both relative.
2290             func_relativize "$destdir" "$local_gnulib_dir"
2291             relative_local_gnulib_dir="$reldir" ;;
2292         esac ;;
2293     esac
2294     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
2295     echo "gl_MODULES(["`echo $specified_modules`"])"
2296     echo "gl_AVOID([$avoidlist])"
2297     echo "gl_SOURCE_BASE([$sourcebase])"
2298     echo "gl_M4_BASE([$m4base])"
2299     echo "gl_DOC_BASE([$docbase])"
2300     echo "gl_TESTS_BASE([$testsbase])"
2301     test -z "$inctests" || echo "gl_WITH_TESTS"
2302     echo "gl_LIB([$libname])"
2303     test -z "$lgpl" || echo "gl_LGPL"
2304     echo "gl_MAKEFILE_NAME([$makefile_name])"
2305     if test "$libtool" = true; then
2306       echo "gl_LIBTOOL"
2307     fi
2308     echo "gl_MACRO_PREFIX([$macro_prefix])"
2309   ) > "$tmpfile"
2310   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2311     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2312       rm -f "$tmpfile"
2313     else
2314       if $doit; then
2315         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2316         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2317         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2318       else
2319         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2320         if false; then
2321           cat "$tmpfile"
2322           echo
2323           echo "# gnulib-cache.m4 ends here"
2324         fi
2325         rm -f "$tmpfile"
2326       fi
2327     fi
2328   else
2329     if $doit; then
2330       echo "Creating $m4base/gnulib-cache.m4"
2331       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2332     else
2333       echo "Create $m4base/gnulib-cache.m4"
2334       cat "$tmpfile"
2335       rm -f "$tmpfile"
2336     fi
2337   fi
2338
2339   # Create m4/gnulib-comp.m4.
2340   func_dest_tmpfilename $m4base/gnulib-comp.m4
2341   (
2342     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2343     func_emit_copyright_notice
2344     echo "#"
2345     echo "# This file represents the compiled summary of the specification in"
2346     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2347     echo "# to be invoked from configure.ac."
2348     echo "# In projects using CVS, this file can be treated like other built files."
2349     echo
2350     echo
2351     echo "# This macro should be invoked from $configure_ac, in the section"
2352     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2353     echo "# any checks for libraries, header files, types and library functions."
2354     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2355     echo "["
2356     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2357     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2358     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2359     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2360     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2361     if test -n "$uses_subdirs"; then
2362       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2363     fi
2364     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2365       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2366     fi
2367     for module in $modules; do
2368       func_verify_module
2369       if test -n "$module"; then
2370         func_get_autoconf_early_snippet "$module"
2371       fi
2372     done \
2373       | sed -e '/^$/d;' -e 's/^/  /'
2374     echo "])"
2375     echo
2376     echo "# This macro should be invoked from $configure_ac, in the section"
2377     echo "# \"Check for header files, types and library functions\"."
2378     echo "AC_DEFUN([${macro_prefix}_INIT],"
2379     echo "["
2380     func_emit_initmacro_start
2381     if test "$libtool" = true; then
2382       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2383       echo "  gl_cond_libtool=true"
2384     else
2385       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2386       echo "  gl_cond_libtool=false"
2387       echo "  gl_libdeps="
2388       echo "  gl_ltlibdeps="
2389     fi
2390     echo "  gl_source_base='$sourcebase'"
2391     if test "$auxdir" != "build-aux"; then
2392       sed_replace_build_aux='
2393         :a
2394         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2395           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2396           ba
2397         }'
2398     else
2399       sed_replace_build_aux=
2400     fi
2401     for module in $modules; do
2402       func_verify_module
2403       if test -n "$module"; then
2404         func_get_autoconf_snippet "$module" \
2405           | sed -e '/^$/d;' -e 's/^/  /' \
2406                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
2407                 -e "$sed_replace_build_aux"
2408         if test "$module" = 'alloca' && test "$libtool" = true; then
2409           echo 'changequote(,)dnl'
2410           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
2411           echo 'changequote([, ])dnl'
2412           echo 'AC_SUBST([LTALLOCA])'
2413         fi
2414       fi
2415     done
2416     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2417     # created using libtool, because libtool already handles the dependencies.
2418     if test "$libtool" != true; then
2419       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
2420       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2421       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2422       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2423       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2424     fi
2425     func_emit_initmacro_end
2426     echo "])"
2427     func_emit_initmacro_done
2428     echo
2429     echo "# This macro records the list of files which have been installed by"
2430     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
2431     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
2432     echo "$files" | sed -e 's,^,  ,'
2433     echo "])"
2434   ) > "$tmpfile"
2435   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2436     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
2437       rm -f "$tmpfile"
2438     else
2439       if $doit; then
2440         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2441         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
2442         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2443       else
2444         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2445         if false; then
2446           cat "$tmpfile"
2447           echo
2448           echo "# gnulib-comp.m4 ends here"
2449         fi
2450         rm -f "$tmpfile"
2451       fi
2452     fi
2453   else
2454     if $doit; then
2455       echo "Creating $m4base/gnulib-comp.m4"
2456       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2457     else
2458       echo "Create $m4base/gnulib-comp.m4"
2459       cat "$tmpfile"
2460       rm -f "$tmpfile"
2461     fi
2462   fi
2463
2464   if test -n "$inctests"; then
2465     # Create tests makefile.
2466     func_dest_tmpfilename $testsbase/$makefile_am
2467     func_emit_tests_Makefile_am > "$tmpfile"
2468     if test -f "$destdir"/$testsbase/$makefile_am; then
2469       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
2470         rm -f "$tmpfile"
2471       else
2472         if $doit; then
2473           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2474           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
2475           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2476         else
2477           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2478           rm -f "$tmpfile"
2479         fi
2480       fi
2481     else
2482       if $doit; then
2483         echo "Creating $testsbase/$makefile_am"
2484         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2485       else
2486         echo "Create $testsbase/$makefile_am"
2487         rm -f "$tmpfile"
2488       fi
2489     func_append added_files "$testsbase/$makefile_am$nl"
2490     fi
2491   fi
2492
2493   # Update the .cvsignore and .gitignore files.
2494   { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
2495     echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
2496   } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
2497   { # Rearrange file descriptors. Needed because "while ... done < ..."
2498     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2499     exec 5<&0 < "$tmp"/fileset-changes
2500     func_update_ignorelist ()
2501     {
2502       ignore="$1"
2503       if test -f "$destdir/$dir$ignore"; then
2504         if test -n "$dir_added" || test -n "$dir_removed"; then
2505           LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
2506           echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
2507             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
2508           echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
2509             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
2510           if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
2511             if $doit; then
2512               echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
2513               mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
2514               sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
2515               cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
2516                 | sed -f "$tmp"/sed-ignore-removed \
2517                 > "$destdir/$dir$ignore"
2518             else
2519               echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
2520             fi
2521           fi
2522         fi
2523       else
2524         if test -n "$dir_added"; then
2525           if $doit; then
2526             echo "Creating $destdir/$dir$ignore"
2527             echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u > "$destdir/$dir$ignore"
2528           else
2529             echo "Create $destdir/$dir$ignore"
2530           fi
2531         fi
2532       fi
2533     }
2534     func_done_dir ()
2535     {
2536       dir="$1"
2537       dir_added="$2"
2538       dir_removed="$3"
2539       if test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
2540         func_update_ignorelist .cvsignore
2541       fi
2542       if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
2543         func_update_ignorelist .gitignore
2544       fi
2545     }
2546     last_dir=
2547     last_dir_added=
2548     last_dir_removed=
2549     while read line; do
2550       # Why not ''read next_dir op file'' ? Because the dir column can be empty.
2551       next_dir=`echo "$line" | sed -e 's,|.*,,'`
2552       op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
2553       file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
2554       if test "$next_dir" != "$last_dir"; then
2555         func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
2556         last_dir="$next_dir"
2557         last_dir_added=
2558         last_dir_removed=
2559       fi
2560       case $op in
2561         A) func_append last_dir_added "$file$nl";;
2562         R) func_append last_dir_removed "$file$nl";;
2563       esac
2564     done
2565     func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
2566     exec 0<&5 5<&-
2567   }
2568
2569   echo "Finished."
2570   echo
2571   echo "You may need to add #include directives for the following .h files."
2572   # Intersect $specified_modules and $modules
2573   # (since $specified_modules is not necessarily of subset of $modules - some
2574   # may have been skipped through --avoid, and since the elements of $modules
2575   # but not in $specified_modules can go away without explicit notice - through
2576   # changes in the module dependencies).
2577   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
2578   echo "$modules" > "$tmp"/modules2 # also a sorted list, one module per line
2579   # First the #include <...> directives without #ifs, sorted for convenience,
2580   # then the #include "..." directives without #ifs, sorted for convenience,
2581   # then the #include directives that are surrounded by #ifs. Not sorted.
2582   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
2583     include_directive=`func_get_include_directive "$module"`
2584     case "$nl$include_directive" in
2585       *"$nl#if"*)
2586         echo "$include_directive" 1>&5
2587         ;;
2588       *)
2589         echo "$include_directive" | grep -v 'include "' 1>&6
2590         echo "$include_directive" | grep 'include "' 1>&7
2591         ;;
2592     esac
2593   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2594   (
2595    LC_ALL=C sort -u "$tmp"/include-angles
2596    LC_ALL=C sort -u "$tmp"/include-quotes
2597    cat "$tmp"/include-if
2598   ) | sed -e '/^$/d' -e 's/^/  /'
2599   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2600
2601   for module in $modules; do
2602     func_get_link_directive "$module"
2603   done \
2604     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
2605   if test `wc -l < "$tmp"/link` != 0; then
2606     echo
2607     echo "You may need to use the following Makefile variables when linking."
2608     echo "Use them in <program>_LDADD when linking a program, or"
2609     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
2610     cat "$tmp"/link
2611   fi
2612   rm -f "$tmp"/link
2613
2614   echo
2615   echo "Don't forget to"
2616   if test "$makefile_am" = Makefile.am; then
2617     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2618   else
2619     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2620   fi
2621   if test -n "$inctests"; then
2622     if test "$makefile_am" = Makefile.am; then
2623       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2624     else
2625       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2626     fi
2627   fi
2628   if test "$makefile_am" = Makefile.am; then
2629     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2630     sourcebase_base=`basename "$sourcebase"`
2631     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2632   fi
2633   if test -n "$inctests"; then
2634     if test "$makefile_am" = Makefile.am; then
2635       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2636       testsbase_base=`basename "$testsbase"`
2637       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2638     fi
2639   fi
2640   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2641   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2642   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
2643 }
2644
2645 # func_create_testdir testdir modules
2646 # Input:
2647 # - local_gnulib_dir  from --local-dir
2648 # - auxdir          directory relative to destdir where to place build aux files
2649 func_create_testdir ()
2650 {
2651   testdir="$1"
2652   modules="$2"
2653   if test -z "$modules"; then
2654     # All modules together.
2655     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2656     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2657     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
2658     modules=`func_all_modules`
2659     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
2660   fi
2661   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2662
2663   # Check that the license of every module is consistent with the license of
2664   # its dependencies.
2665   saved_modules="$modules"
2666   saved_inctests="$inctests"
2667   # When computing transitive closures, don't consider $module to depend on
2668   # $module-tests. Need this becauses tests are implicitly GPL and may depend
2669   # on GPL modules - therefore we don't want a warning in this case.
2670   inctests=""
2671   for requested_module in $saved_modules; do
2672     requested_license=`func_get_license "$requested_module"`
2673     if test "$requested_license" != GPL; then
2674       # Here we use func_modules_transitive_closure, not just
2675       # func_get_dependencies, so that we also detect weird situations like
2676       # an LGPL module which depends on a GPLed build tool module which depends
2677       # on a GPL module.
2678       modules="$requested_module"
2679       func_modules_transitive_closure
2680       for module in $modules; do
2681         license=`func_get_license "$module"`
2682         case "$license" in
2683           'GPLed build tool') ;;
2684           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2685           *)
2686             case "$requested_license" in
2687               GPLv2+)
2688                 case "$license" in
2689                   GPLv2+ | LGPLv2+) ;;
2690                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2691                 esac
2692                 ;;
2693               LGPL)
2694                 case "$license" in
2695                   LGPL | LGPLv2+) ;;
2696                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2697                 esac
2698                 ;;
2699               LGPLv2+)
2700                 case "$license" in
2701                   LGPLv2+) ;;
2702                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2703                 esac
2704                 ;;
2705             esac
2706             ;;
2707         esac
2708       done
2709     fi
2710   done
2711   modules="$saved_modules"
2712   inctests="$saved_inctests"
2713
2714   # Subdirectory names.
2715   sourcebase=gllib
2716   m4base=glm4
2717   docbase=gldoc
2718   testsbase=gltests
2719   macro_prefix=gl
2720
2721   # Determine final module list.
2722   func_modules_transitive_closure
2723   echo "Module list with included dependencies:"
2724   echo "$modules" | sed -e 's/^/  /'
2725
2726   # Add the dummy module if needed.
2727   func_modules_add_dummy
2728
2729   # Determine final file list.
2730   func_modules_to_filelist
2731   echo "File list:"
2732   echo "$files" | sed -e 's/^/  /'
2733
2734   sed_rewrite_files="\
2735     s,^build-aux/,$auxdir/,
2736     s,^doc/,$docbase/,
2737     s,^lib/,$sourcebase/,
2738     s,^m4/,$m4base/,
2739     s,^tests/,$testsbase/,"
2740
2741   # Create directories.
2742   for f in $files; do echo $f; done \
2743     | sed -e "$sed_rewrite_files" \
2744     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2745     | LC_ALL=C sort -u \
2746     > "$tmp"/dirs
2747   { # Rearrange file descriptors. Needed because "while ... done < ..."
2748     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2749     exec 5<&0 < "$tmp"/dirs
2750     while read d; do
2751       mkdir -p "$testdir/$d"
2752     done
2753     exec 0<&5 5<&-
2754   }
2755
2756   # Copy files or make symbolic links.
2757   delimiter='   '
2758   for f in $files; do echo $f; done \
2759     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2760     | LC_ALL=C sort \
2761     > "$tmp"/files
2762   { # Rearrange file descriptors. Needed because "while ... done < ..."
2763     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2764     exec 5<&0 < "$tmp"/files
2765     while read g f; do
2766       func_lookup_file "$f"
2767       if test -n "$lookedup_tmp"; then
2768         cp -p "$lookedup_file" "$testdir/$g"
2769       else
2770         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2771         if { test -n "$symbolic" \
2772              || { test -n "$lsymbolic" \
2773                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
2774           func_ln "$lookedup_file" "$testdir/$g"
2775         else
2776           cp -p "$lookedup_file" "$testdir/$g"
2777         fi
2778       fi
2779     done
2780     exec 0<&5 5<&-
2781   }
2782
2783   # Create Makefile.ams that are for testing.
2784   for_test=true
2785
2786   # Create $sourcebase/Makefile.am.
2787   mkdir -p "$testdir/$sourcebase"
2788   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2789
2790   # Create $m4base/Makefile.am.
2791   mkdir -p "$testdir/$m4base"
2792   (echo "## Process this file with automake to produce Makefile.in."
2793    echo
2794    echo "EXTRA_DIST ="
2795    for f in $files; do
2796      case "$f" in
2797        m4/* )
2798          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2799      esac
2800    done
2801   ) > "$testdir/$m4base/Makefile.am"
2802
2803   subdirs="$sourcebase $m4base"
2804   subdirs_with_configure_ac=""
2805
2806   if false && test -f "$testdir"/$m4base/gettext.m4; then
2807     # Avoid stupid error message from automake:
2808     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2809     mkdir -p "$testdir/po"
2810     (echo "## Process this file with automake to produce Makefile.in."
2811     ) > "$testdir/po/Makefile.am"
2812     func_append subdirs " po"
2813   fi
2814
2815   if test -n "$inctests"; then
2816     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2817     # Create $testsbase/Makefile.am.
2818     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2819     # Create $testsbase/configure.ac.
2820     (echo "# Process this file with autoconf to produce a configure script."
2821      echo "AC_INIT([dummy], [0])"
2822      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2823      echo "AM_INIT_AUTOMAKE"
2824      echo
2825      echo "AM_CONFIG_HEADER([config.h])"
2826      echo
2827      echo "AC_PROG_CC"
2828      echo "AC_PROG_INSTALL"
2829      echo "AC_PROG_MAKE_SET"
2830      echo "AC_PROG_RANLIB"
2831      echo
2832      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2833        echo "AC_GNU_SOURCE"
2834        echo
2835      fi
2836      for module in $modules; do
2837        func_verify_module
2838        if test -n "$module"; then
2839          func_get_autoconf_early_snippet "$module"
2840        fi
2841      done \
2842        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
2843      if test "$libtool" = true; then
2844        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2845        echo "gl_cond_libtool=true"
2846      else
2847        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2848        echo "gl_cond_libtool=false"
2849        echo "gl_libdeps="
2850        echo "gl_ltlibdeps="
2851      fi
2852      # Wrap the set of autoconf snippets into an autoconf macro that is then
2853      # invoked. This is needed because autoconf does not support AC_REQUIRE
2854      # at the top level:
2855      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2856      # but we want the AC_REQUIRE to have its normal meaning (provide one
2857      # expansion of the required macro before the current point, and only one
2858      # expansion total).
2859      echo "AC_DEFUN([gl_INIT], ["
2860      func_emit_initmacro_start
2861      sed_replace_build_aux='
2862        :a
2863        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2864          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2865          ba
2866        }'
2867      # We don't have explicit ordering constraints between the various
2868      # autoconf snippets. It's cleanest to put those of the library before
2869      # those of the tests.
2870      echo "gl_source_base='../$sourcebase'"
2871      for module in $modules; do
2872        func_verify_nontests_module
2873        if test -n "$module"; then
2874          func_get_autoconf_snippet "$module" \
2875            | sed -e "$sed_replace_build_aux"
2876        fi
2877      done
2878      echo "gl_source_base='.'"
2879      for module in $modules; do
2880        func_verify_tests_module
2881        if test -n "$module"; then
2882          func_get_autoconf_snippet "$module" \
2883            | sed -e "$sed_replace_build_aux"
2884        fi
2885      done
2886      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2887      # created using libtool, because libtool already handles the dependencies.
2888      if test "$libtool" != true; then
2889        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
2890        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2891        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2892        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2893        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2894      fi
2895      func_emit_initmacro_end
2896      echo "])"
2897      func_emit_initmacro_done
2898      echo
2899      echo "gl_INIT"
2900      echo
2901      # Usually $testsbase/config.h will be a superset of config.h. Verify this
2902      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2903      echo "AH_TOP([#include \"../config.h\"])"
2904      echo
2905      echo "AC_OUTPUT([Makefile])"
2906     ) > "$testdir/$testsbase/configure.ac"
2907     func_append subdirs " $testsbase"
2908     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2909   fi
2910
2911   # Create Makefile.am.
2912   (echo "## Process this file with automake to produce Makefile.in."
2913    echo
2914    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2915    echo
2916    echo "SUBDIRS = $subdirs"
2917    echo
2918    echo "ACLOCAL_AMFLAGS = -I $m4base"
2919   ) > "$testdir/Makefile.am"
2920
2921   # Create configure.ac.
2922   (echo "# Process this file with autoconf to produce a configure script."
2923    echo "AC_INIT([dummy], [0])"
2924    if test "$auxdir" != "."; then
2925      echo "AC_CONFIG_AUX_DIR([$auxdir])"
2926    fi
2927    echo "AM_INIT_AUTOMAKE"
2928    echo
2929    echo "AM_CONFIG_HEADER([config.h])"
2930    echo
2931    echo "AC_PROG_CC"
2932    echo "AC_PROG_INSTALL"
2933    echo "AC_PROG_MAKE_SET"
2934    echo
2935    echo "# For autobuild."
2936    echo "AC_CANONICAL_BUILD"
2937    echo "AC_CANONICAL_HOST"
2938    echo
2939    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2940    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2941    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2942    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2943    echo
2944    echo "AC_PROG_RANLIB"
2945    echo
2946    if test -n "$uses_subdirs"; then
2947      echo "AM_PROG_CC_C_O"
2948      echo
2949    fi
2950    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2951      echo "AC_GNU_SOURCE"
2952      echo
2953    fi
2954    for module in $modules; do
2955      func_verify_nontests_module
2956      if test -n "$module"; then
2957        func_get_autoconf_early_snippet "$module"
2958      fi
2959    done \
2960      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
2961    if test "$libtool" = true; then
2962      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2963      echo "gl_cond_libtool=true"
2964    else
2965      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2966      echo "gl_cond_libtool=false"
2967      echo "gl_libdeps="
2968      echo "gl_ltlibdeps="
2969    fi
2970    echo "gl_source_base='$sourcebase'"
2971    # Wrap the set of autoconf snippets into an autoconf macro that is then
2972    # invoked. This is needed because autoconf does not support AC_REQUIRE
2973    # at the top level:
2974    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2975    # but we want the AC_REQUIRE to have its normal meaning (provide one
2976    # expansion of the required macro before the current point, and only one
2977    # expansion total).
2978    echo "AC_DEFUN([gl_INIT], ["
2979    func_emit_initmacro_start
2980    if test "$auxdir" != "build-aux"; then
2981      sed_replace_build_aux='
2982        :a
2983        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2984          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2985          ba
2986        }'
2987    else
2988      sed_replace_build_aux=
2989    fi
2990    for module in $modules; do
2991      func_verify_nontests_module
2992      if test -n "$module"; then
2993        func_get_autoconf_snippet "$module" \
2994          | sed -e "$sed_replace_build_aux"
2995      fi
2996    done
2997    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2998    # created using libtool, because libtool already handles the dependencies.
2999    if test "$libtool" != true; then
3000      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3001      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3002      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3003      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3004      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3005    fi
3006    func_emit_initmacro_end
3007    echo "])"
3008    func_emit_initmacro_done
3009    echo
3010    echo "gl_INIT"
3011    echo
3012    if test -n "$subdirs_with_configure_ac"; then
3013      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3014    fi
3015    makefiles="Makefile"
3016    for d in $subdirs; do
3017      # For subdirs that have a configure.ac by their own, it's the subdir's
3018      # configure.ac which creates the subdir's Makefile.am, not this one.
3019      case " $subdirs_with_configure_ac " in
3020        *" $d "*) ;;
3021        *) func_append makefiles " $d/Makefile" ;;
3022      esac
3023    done
3024    echo "AC_OUTPUT([$makefiles])"
3025   ) > "$testdir/configure.ac"
3026
3027   # Create autogenerated files.
3028   (cd "$testdir"
3029    # Do not use "${AUTORECONF} --force --install", because it may invoke
3030    # autopoint, which brings in older versions of some of our .m4 files.
3031    if test -f $m4base/gettext.m4; then
3032      echo "executing ${AUTOPOINT} --force"
3033      ${AUTOPOINT} --force || func_exit 1
3034      for f in $m4base/*.m4~; do
3035        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3036      done
3037    fi
3038    echo "executing ${ACLOCAL} -I $m4base"
3039    ${ACLOCAL} -I $m4base || func_exit 1
3040    if ! test -d build-aux; then
3041      echo "executing mkdir build-aux"
3042      mkdir build-aux || func_exit 1
3043    fi
3044    echo "executing ${AUTOCONF}"
3045    ${AUTOCONF} || func_exit 1
3046    echo "executing ${AUTOHEADER}"
3047    ${AUTOHEADER} || func_exit 1
3048    echo "executing ${AUTOMAKE} --add-missing --copy"
3049    ${AUTOMAKE} --add-missing --copy || func_exit 1
3050   ) || func_exit 1
3051   if test -n "$inctests"; then
3052     # Create autogenerated files.
3053     (cd "$testdir/$testsbase" || func_exit 1
3054      # Do not use "${AUTORECONF} --force --install", because it may invoke
3055      # autopoint, which brings in older versions of some of our .m4 files.
3056      if test -f ../$m4base/gettext.m4; then
3057        echo "executing ${AUTOPOINT} --force"
3058        ${AUTOPOINT} --force || func_exit 1
3059        for f in ../$m4base/*.m4~; do
3060          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3061        done
3062      fi
3063      echo "executing ${ACLOCAL} -I ../$m4base"
3064      ${ACLOCAL} -I ../$m4base || func_exit 1
3065      if ! test -d ../build-aux; then
3066        echo "executing mkdir ../build-aux"
3067        mkdir ../build-aux
3068      fi
3069      echo "executing ${AUTOCONF}"
3070      ${AUTOCONF} || func_exit 1
3071      echo "executing ${AUTOHEADER}"
3072      ${AUTOHEADER} || func_exit 1
3073      echo "executing ${AUTOMAKE} --add-missing --copy"
3074      ${AUTOMAKE} --add-missing --copy || func_exit 1
3075     ) || func_exit 1
3076   fi
3077   # Need to run configure and make once, to create built files that are to be
3078   # distributed (such as getdate.c).
3079   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3080   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3081                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3082   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3083   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3084   # such $(FOO_H) because they don't refer to distributed files.
3085   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3086   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3087                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3088                  | sed -e "$sed_remove_make_variables"`
3089   distributed_built_sources=`for file in $built_sources; do
3090                                case "$cleaned_files" in
3091                                  *" "$file" "*) ;;
3092                                  *) echo $file ;;
3093                                esac;
3094                              done`
3095   if test -n "$distributed_built_sources"; then
3096     (cd "$testdir"
3097      ./configure || func_exit 1
3098        cd "$sourcebase"
3099        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3100        make built_sources || func_exit 1
3101        cd ..
3102      make distclean || func_exit 1
3103     ) || func_exit 1
3104   fi
3105 }
3106
3107 # func_create_megatestdir megatestdir allmodules
3108 # Input:
3109 # - local_gnulib_dir  from --local-dir
3110 # - auxdir          directory relative to destdir where to place build aux files
3111 func_create_megatestdir ()
3112 {
3113   megatestdir="$1"
3114   allmodules="$2"
3115   if test -z "$allmodules"; then
3116     allmodules=`func_all_modules`
3117   fi
3118
3119   megasubdirs=
3120   # First, all modules one by one.
3121   for onemodule in $allmodules; do
3122     func_create_testdir "$megatestdir/$onemodule" $onemodule
3123     func_append megasubdirs "$onemodule "
3124   done
3125   # Then, all modules all together.
3126   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3127   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3128   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3129   func_create_testdir "$megatestdir/ALL" "$allmodules"
3130   func_append megasubdirs "ALL"
3131
3132   # Create autobuild.
3133   cvsdate=`sh "$gnulib_dir/build-aux/mdate-sh" "$gnulib_dir/CVS/Entries" \
3134              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3135                    -e 's,February,02,'  -e 's,Feb,02,' \
3136                    -e 's,March,03,'     -e 's,Mar,03,' \
3137                    -e 's,April,04,'     -e 's,Apr,04,' \
3138                    -e 's,May,05,'                      \
3139                    -e 's,June,06,'      -e 's,Jun,06,' \
3140                    -e 's,July,07,'      -e 's,Jul,07,' \
3141                    -e 's,August,08,'    -e 's,Aug,08,' \
3142                    -e 's,September,09,' -e 's,Sep,09,' \
3143                    -e 's,October,10,'   -e 's,Oct,10,' \
3144                    -e 's,November,11,'  -e 's,Nov,11,' \
3145                    -e 's,December,12,'  -e 's,Dec,12,' \
3146                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3147                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3148   (echo '#!/bin/sh'
3149    echo "CVSDATE=$cvsdate"
3150    echo "test -d logs || mkdir logs"
3151    echo "for module in $megasubdirs; do"
3152    echo "  echo \"Working on module \$module...\""
3153    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3154    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3155    echo "   echo"
3156    echo "   set -x"
3157    echo "   : autobuild project... \$module"
3158    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3159    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3160    echo "   : autobuild hostname... \`hostname\`"
3161    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3162    echo "   echo rc=\$?"
3163    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3164    echo "done"
3165   ) > "$megatestdir/do-autobuild"
3166   chmod a+x "$megatestdir/do-autobuild"
3167
3168   # Create Makefile.am.
3169   (echo "## Process this file with automake to produce Makefile.in."
3170    echo
3171    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3172    echo
3173    echo "SUBDIRS = $megasubdirs"
3174    echo
3175    echo "EXTRA_DIST = do-autobuild"
3176   ) > "$megatestdir/Makefile.am"
3177
3178   # Create configure.ac.
3179   (echo "# Process this file with autoconf to produce a configure script."
3180    echo "AC_INIT([dummy], [0])"
3181    if test "$auxdir" != "."; then
3182      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3183    fi
3184    echo "AM_INIT_AUTOMAKE"
3185    echo
3186    echo "AC_PROG_MAKE_SET"
3187    echo
3188    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
3189    echo "AC_OUTPUT([Makefile])"
3190   ) > "$megatestdir/configure.ac"
3191
3192   # Create autogenerated files.
3193   (cd "$megatestdir"
3194    # Do not use "${AUTORECONF} --install", because autoreconf operates
3195    # recursively, but the subdirectories are already finished, therefore
3196    # calling autoreconf here would only waste lots of CPU time.
3197    echo "executing ${ACLOCAL}"
3198    ${ACLOCAL} || func_exit 1
3199    echo "executing mkdir build-aux"
3200    mkdir build-aux
3201    echo "executing ${AUTOCONF}"
3202    ${AUTOCONF} || func_exit 1
3203    echo "executing ${AUTOMAKE} --add-missing --copy"
3204    ${AUTOMAKE} --add-missing --copy || func_exit 1
3205   ) || func_exit 1
3206 }
3207
3208 case $mode in
3209   "" )
3210     func_fatal_error "no mode specified" ;;
3211
3212   list )
3213     func_all_modules
3214     ;;
3215
3216   import | update )
3217
3218     # Where to import.
3219     if test -z "$destdir"; then
3220       destdir=.
3221     fi
3222     test -d "$destdir" \
3223       || func_fatal_error "destination directory does not exist: $destdir"
3224
3225     # Prefer configure.ac to configure.in.
3226     if test -f "$destdir"/configure.ac; then
3227       configure_ac="$destdir/configure.ac"
3228     else
3229       if test -f "$destdir"/configure.in; then
3230         configure_ac="$destdir/configure.in"
3231       else
3232         func_fatal_error "cannot find $destdir/configure.ac"
3233       fi
3234     fi
3235
3236     # Analyze configure.ac.
3237     guessed_auxdir="."
3238     guessed_libtool=false
3239     my_sed_traces='
3240       s,#.*$,,
3241       s,^dnl .*$,,
3242       s, dnl .*$,,
3243       /AC_CONFIG_AUX_DIR/ {
3244         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
3245       }
3246       /A[CM]_PROG_LIBTOOL/ {
3247         s,^.*$,guessed_libtool=true,p
3248       }'
3249     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
3250
3251     if test -z "$auxdir"; then
3252       auxdir="$guessed_auxdir"
3253     fi
3254
3255     # Determine where to apply func_import.
3256     if test -n "$m4base"; then
3257       # Apply func_import to a particular gnulib directory.
3258       # Any number of additional modules can be given.
3259       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
3260         # First use of gnulib in the given m4base.
3261         test -n "$supplied_libname" || supplied_libname=true
3262         test -n "$sourcebase" || sourcebase="lib"
3263         test -n "$docbase" || docbase="doc"
3264         test -n "$testsbase" || testsbase="tests"
3265         test -n "$macro_prefix" || macro_prefix="gl"
3266       fi
3267       func_import "$*"
3268     else
3269       # Apply func_import to all gnulib directories.
3270       # To get this list of directories, look at Makefile.am. (Not at
3271       # configure, because it may be omitted from CVS. Also, don't run
3272       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
3273       m4dirs=
3274       m4dirs_count=0
3275       if test -f "$destdir"/Makefile.am; then
3276         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
3277         m4dir_is_next=
3278         for arg in $aclocal_amflags; do
3279           if test -n "$m4dir_is_next"; then
3280             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
3281             case "$arg" in
3282               /*) ;;
3283               *)
3284                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
3285                   func_append m4dirs " $arg"
3286                   m4dirs_count=`expr $m4dirs_count + 1`
3287                 fi
3288                 ;;
3289             esac
3290             m4dir_is_next=
3291           else
3292             if test "X$arg" = "X-I"; then
3293               m4dir_is_next=yes
3294             else
3295               m4dir_is_next=
3296             fi
3297           fi
3298         done
3299       else
3300         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
3301         if test -f "$destdir"/aclocal.m4; then
3302           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
3303           sedexpr2='s,^[^/]*$,.,'
3304           sedexpr3='s,/[^/]*$,,'
3305           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
3306           m4dirs_count=`echo "$m4dirs" | wc -l`
3307         fi
3308       fi
3309       if test $m4dirs_count = 0; then
3310         # First use of gnulib in a package.
3311         # Any number of additional modules can be given.
3312         test -n "$supplied_libname" || supplied_libname=true
3313         test -n "$sourcebase" || sourcebase="lib"
3314         m4base="m4"
3315         test -n "$docbase" || docbase="doc"
3316         test -n "$testsbase" || testsbase="tests"
3317         test -n "$macro_prefix" || macro_prefix="gl"
3318         func_import "$*"
3319       else
3320         if test $m4dirs_count = 1; then
3321           # There's only one use of gnulib here. Assume the user means it.
3322           # Any number of additional modules can be given.
3323           for m4base in $m4dirs; do
3324             func_import "$*"
3325           done
3326         else
3327           # Ambiguous - guess what the user meant.
3328           if test $# = 0; then
3329             # No further arguments. Guess the user wants to update all of them.
3330             for m4base in $m4dirs; do
3331               # Perform func_import in a subshell, so that variable values
3332               # such as
3333               #   local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
3334               #   testsbase, inctests, libname, lgpl, makefile_name, libtool,
3335               #   macro_prefix
3336               # don't propagate from one directory to another.
3337               (func_import) || func_exit 1
3338             done
3339           else
3340             # Really ambiguous.
3341             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
3342           fi
3343         fi
3344       fi
3345     fi
3346     ;;
3347
3348   create-testdir )
3349     if test -z "$destdir"; then
3350       func_fatal_error "please specify --dir option"
3351     fi
3352     mkdir "$destdir"
3353     test -d "$destdir" \
3354       || func_fatal_error "could not create destination directory"
3355     test -n "$auxdir" || auxdir="build-aux"
3356     func_create_testdir "$destdir" "$*"
3357     ;;
3358
3359   create-megatestdir )
3360     if test -z "$destdir"; then
3361       func_fatal_error "please specify --dir option"
3362     fi
3363     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3364     test -n "$auxdir" || auxdir="build-aux"
3365     func_create_megatestdir "$destdir" "$*"
3366     ;;
3367
3368   test )
3369     test -n "$destdir" || destdir=testdir$$
3370     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3371     test -n "$auxdir" || auxdir="build-aux"
3372     func_create_testdir "$destdir" "$*"
3373     cd "$destdir"
3374       mkdir build
3375       cd build
3376         ../configure || func_exit 1
3377         make || func_exit 1
3378         make check || func_exit 1
3379         make distclean || func_exit 1
3380         remaining=`find . -type f -print`
3381         if test -n "$remaining"; then
3382           echo "Remaining files:" $remaining 1>&2
3383           echo "gnulib-tool: *** Stop." 1>&2
3384           func_exit 1
3385         fi
3386       cd ..
3387     cd ..
3388     rm -rf "$destdir"
3389     ;;
3390
3391   megatest )
3392     test -n "$destdir" || destdir=testdir$$
3393     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3394     test -n "$auxdir" || auxdir="build-aux"
3395     func_create_megatestdir "$destdir" "$*"
3396     cd "$destdir"
3397       mkdir build
3398       cd build
3399         ../configure
3400         make
3401         make check
3402         make distclean
3403         remaining=`find . -type f -print`
3404         if test -n "$remaining"; then
3405           echo "Remaining files:" $remaining 1>&2
3406           echo "gnulib-tool: *** Stop." 1>&2
3407           func_exit 1
3408         fi
3409       cd ..
3410     cd ..
3411     rm -rf "$destdir"
3412     ;;
3413
3414   extract-description )
3415     for module
3416     do
3417       func_verify_module
3418       if test -n "$module"; then
3419         func_get_description "$module"
3420       fi
3421     done
3422     ;;
3423
3424   extract-filelist )
3425     for module
3426     do
3427       func_verify_module
3428       if test -n "$module"; then
3429         func_get_filelist "$module"
3430       fi
3431     done
3432     ;;
3433
3434   extract-dependencies )
3435     for module
3436     do
3437       func_verify_module
3438       if test -n "$module"; then
3439         func_get_dependencies "$module"
3440       fi
3441     done
3442     ;;
3443
3444   extract-autoconf-snippet )
3445     for module
3446     do
3447       func_verify_module
3448       if test -n "$module"; then
3449         func_get_autoconf_snippet "$module"
3450       fi
3451     done
3452     ;;
3453
3454   extract-automake-snippet )
3455     for module
3456     do
3457       func_verify_module
3458       if test -n "$module"; then
3459         func_get_automake_snippet "$module"
3460       fi
3461     done
3462     ;;
3463
3464   extract-include-directive )
3465     for module
3466     do
3467       func_verify_module
3468       if test -n "$module"; then
3469         func_get_include_directive "$module"
3470       fi
3471     done
3472     ;;
3473
3474   extract-link-directive )
3475     for module
3476     do
3477       func_verify_module
3478       if test -n "$module"; then
3479         func_get_link_directive "$module"
3480       fi
3481     done
3482     ;;
3483
3484   extract-license )
3485     for module
3486     do
3487       func_verify_module
3488       if test -n "$module"; then
3489         func_get_license "$module"
3490       fi
3491     done
3492     ;;
3493
3494   extract-maintainer )
3495     for module
3496     do
3497       func_verify_module
3498       if test -n "$module"; then
3499         func_get_maintainer "$module"
3500       fi
3501     done
3502     ;;
3503
3504   extract-tests-module )
3505     for module
3506     do
3507       func_verify_module
3508       if test -n "$module"; then
3509         func_get_tests_module "$module"
3510       fi
3511     done
3512     ;;
3513
3514   * )
3515     func_fatal_error "unknown operation mode --$mode" ;;
3516 esac
3517
3518 rm -rf "$tmp"
3519 # Undo the effect of the previous 'trap' command. Some shellology:
3520 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
3521 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
3522 # exit); for the others we need to call 'exit' explicitly. The value of $? is
3523 # 128 + signal number and is set before the trap-registered command is run.
3524 trap '' 0
3525 trap 'func_exit $?' 1 2 3 13 15
3526
3527 exit 0
3528
3529 # Local Variables:
3530 # indent-tabs-mode: nil
3531 # whitespace-check-buffer-indent: nil
3532 # End: