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