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