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