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