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