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