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