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