Merge branch 'master' of ssh://karl@git.sv.gnu.org/srv/git/gnulib
[pspp] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2007 Free Software Foundation, Inc.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 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 # - auxdir          directory relative to destdir where to place build aux files
1797 # - makefile_name   from --makefile-name
1798 # - libtool         true if libtool will be used, false or blank otherwise
1799 # - sourcebase      relative directory containing lib source code
1800 # - m4base          relative directory containing autoconf macros
1801 # - testsbase       relative directory containing unit test code
1802 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1803 # - for_test        true if creating a package for testing, false otherwise
1804 # - use_libtests    true if a libtests.a should be built, false otherwise
1805 # Output:
1806 # - uses_subdirs    nonempty if object files in subdirs exist
1807 func_emit_tests_Makefile_am ()
1808 {
1809   if test "$libtool" = true; then
1810     libext=la
1811     sed_eliminate_LDFLAGS=
1812   else
1813     libext=a
1814     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1815   fi
1816   if $for_test; then
1817     # When creating a package for testing: Attempt to provoke failures,
1818     # especially link errors, already during "make" rather than during
1819     # "make check", because "make check" is not possible in a cross-compiling
1820     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1821     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1822   else
1823     sed_transform_check_PROGRAMS=
1824   fi
1825   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1826   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1827   echo "## Process this file with automake to produce Makefile.in."
1828   func_emit_copyright_notice
1829   echo
1830   uses_subdirs=
1831   (
1832     for module in $modules; do
1833       if $for_test; then
1834         func_verify_tests_module
1835       else
1836         func_verify_module
1837       fi
1838       if test -n "$module"; then
1839         {
1840           func_get_automake_snippet "$module" |
1841             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1842                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1843                 -e "$sed_eliminate_LDFLAGS" \
1844                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
1845                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1846                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1847                 -e "$sed_transform_check_PROGRAMS"
1848           if $use_libtests && test "$module" = 'alloca'; then
1849             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
1850             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1851           fi
1852         } > amsnippet.tmp
1853         # Skip the contents if its entirely empty.
1854         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1855           echo "## begin gnulib module $module"
1856           echo
1857           cat amsnippet.tmp
1858           echo "## end   gnulib module $module"
1859           echo
1860         fi
1861         rm -f amsnippet.tmp
1862         # Test whether there are some source files in subdirectories.
1863         for f in `func_get_filelist "$module"`; do
1864           case $f in
1865             lib/*/*.c | tests/*/*.c) uses_subdirs=yes ;;
1866           esac
1867         done
1868       fi
1869     done
1870   ) > allsnippets.tmp
1871   # Generate dependencies here, since it eases the debugging of test failures.
1872   # If there are source files in subdirectories, prevent collision of the
1873   # object files (example: hash.c and libxml/hash.c).
1874   subdir_options=
1875   if test -n "$uses_subdirs"; then
1876     subdir_options=' subdir-objects'
1877   fi
1878   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
1879   echo
1880   if $for_test; then
1881     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1882     echo
1883   fi
1884   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1885   # variable is needed to avoid an error from automake:
1886   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1887   echo "SUBDIRS ="
1888   echo "TESTS ="
1889   echo "TESTS_ENVIRONMENT ="
1890   echo "noinst_PROGRAMS ="
1891   if ! $for_test; then
1892     echo "check_PROGRAMS ="
1893   fi
1894   echo "noinst_HEADERS ="
1895   echo "noinst_LIBRARIES ="
1896   if $use_libtests; then
1897     if $for_test; then
1898       echo "noinst_LIBRARIES += libtests.a"
1899     else
1900       echo "check_LIBRARIES = libtests.a"
1901     fi
1902   fi
1903   # Automake versions < 1.9b create an empty pkgdatadir at installation time
1904   # if you specify pkgdata_DATA to empty. This is a workaround.
1905   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1906     echo "pkgdata_DATA ="
1907   fi
1908   echo "EXTRA_DIST ="
1909   echo "BUILT_SOURCES ="
1910   echo "SUFFIXES ="
1911   echo "MOSTLYCLEANFILES = core *.stackdump"
1912   echo "MOSTLYCLEANDIRS ="
1913   echo "CLEANFILES ="
1914   echo "DISTCLEANFILES ="
1915   echo "MAINTAINERCLEANFILES ="
1916   echo
1917   echo "AM_CPPFLAGS = \\"
1918   echo "  -I. -I\$(srcdir) \\"
1919   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1920   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1921   echo
1922   local_ldadd=''
1923   if $use_libtests; then
1924     local_ldadd=' libtests.a $(LIBTESTS_LIBDEPS)'
1925   fi
1926   # local_ldadd must be listed first, since it often depends on non-test
1927   # modules; it must also be listed last, since it can include modules
1928   # such as progname that satisfy dependencies of non-test modules.
1929   echo "LDADD =${local_ldadd} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd}"
1930   echo
1931   if $use_libtests; then
1932     echo "libtests_a_SOURCES ="
1933     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1934     # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1935     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
1936     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
1937     echo "EXTRA_libtests_a_SOURCES ="
1938     # The circular dependency in LDADD requires this.
1939     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
1940     echo
1941   fi
1942   cat allsnippets.tmp \
1943     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1944   echo "# Clean up after Solaris cc."
1945   echo "clean-local:"
1946   echo "        rm -rf SunWS_cache"
1947   echo
1948   echo "mostlyclean-local: mostlyclean-generic"
1949   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1950   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1951   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1952   echo "          fi; \\"
1953   echo "        done; \\"
1954   echo "        :"
1955   rm -f allsnippets.tmp
1956 }
1957
1958 # func_emit_initmacro_start macro_prefix
1959 # emits the first few statements of the gl_INIT macro to standard output.
1960 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1961 func_emit_initmacro_start ()
1962 {
1963   macro_prefix_arg="$1"
1964   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1965   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
1966   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1967   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1968   # flexibility.)
1969   # Furthermore it avoids an automake error like this when a Makefile.am
1970   # that uses pieces of gnulib also uses $(LIBOBJ):
1971   #   automatically discovered file `error.c' should not be explicitly mentioned
1972   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
1973   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
1974   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1975   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1976   #   automatically discovered file `error.c' should not be explicitly mentioned
1977   # We let automake know about the files to be distributed through the
1978   # EXTRA_lib_SOURCES variable.
1979   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
1980 }
1981
1982 # func_emit_initmacro_end macro_prefix
1983 # emits the last few statements of the gl_INIT macro to standard output.
1984 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1985 func_emit_initmacro_end ()
1986 {
1987   macro_prefix_arg="$1"
1988   echo "  m4_popdef([AC_LIBSOURCES])"
1989   echo "  m4_popdef([AC_REPLACE_FUNCS])"
1990   echo "  m4_popdef([AC_LIBOBJ])"
1991   echo "  AC_CONFIG_COMMANDS_PRE(["
1992   echo "    ${macro_prefix_arg}_libobjs="
1993   echo "    ${macro_prefix_arg}_ltlibobjs="
1994   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
1995   echo "      # Remove the extension."
1996   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
1997   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
1998   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
1999   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
2000   echo "      done"
2001   echo "    fi"
2002   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
2003   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
2004   echo "  ])"
2005 }
2006
2007 # func_emit_initmacro_done macro_prefix sourcebase
2008 # emits a few statements after the gl_INIT macro to standard output.
2009 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2010 # - sourcebase      directory relative to destdir where to place source code
2011 func_emit_initmacro_done ()
2012 {
2013   macro_prefix_arg="$1"
2014   sourcebase_arg="$2"
2015   echo
2016   echo "# Like AC_LIBOBJ, except that the module name goes"
2017   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2018   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
2019   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
2020   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
2021   echo "])"
2022   echo
2023   echo "# m4_foreach_w is provided by autoconf-2.59c and later."
2024   echo "# This definition is to accommodate developers using versions"
2025   echo "# of autoconf older than that."
2026   echo "m4_ifndef([m4_foreach_w],"
2027   echo "  [m4_define([m4_foreach_w],"
2028   echo "    [m4_foreach([\$1], m4_split(m4_normalize([\$2]), [ ]), [\$3])])])"
2029   echo
2030   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
2031   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2032   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
2033   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
2034   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
2035   echo "])"
2036   echo
2037   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
2038   echo "# expected is derived from the gnulib-tool parametrization,"
2039   echo "# and alloca is special cased (for the alloca-opt module)."
2040   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
2041   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
2042   echo "  m4_foreach([_gl_NAME], [\$1], ["
2043   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
2044   echo "      m4_syscmd([test -r $sourcebase_arg/]_gl_NAME[ || test ! -d $sourcebase_arg])dnl"
2045   echo "      m4_if(m4_sysval, [0], [],"
2046   echo "        [AC_FATAL([missing $sourcebase_arg/]_gl_NAME)])"
2047   echo "    ])"
2048   echo "  ])"
2049   echo "])"
2050 }
2051
2052 # func_import modules
2053 # Uses also the variables
2054 # - destdir         target directory
2055 # - local_gnulib_dir  from --local-dir
2056 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2057 # - libname         library name
2058 # - sourcebase      directory relative to destdir where to place source code
2059 # - m4base          directory relative to destdir where to place *.m4 macros
2060 # - pobase          directory relative to destdir where to place *.po files
2061 # - docbase         directory relative to destdir where to place doc files
2062 # - testsbase       directory relative to destdir where to place unit test code
2063 # - auxdir          directory relative to destdir where to place build aux files
2064 # - inctests        true if --with-tests was given, blank otherwise
2065 # - avoidlist       list of modules to avoid, from --avoid
2066 # - lgpl            yes or a number if library's license shall be LGPL,
2067 #                   blank otherwise
2068 # - makefile_name   from --makefile-name
2069 # - libtool         true if --libtool was given, false if --no-libtool was
2070 #                   given, blank otherwise
2071 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
2072 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2073 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
2074 # - autoconf_minversion  minimum supported autoconf version
2075 # - doit            : if actions shall be executed, false if only to be printed
2076 # - symbolic        true if files should be symlinked, copied otherwise
2077 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
2078 #                   copied otherwise
2079 # - do_copyrights   true if copyright notices in files should be replaced,
2080 #                   blank otherwise
2081 func_import ()
2082 {
2083   # Get the cached settings.
2084   cached_local_gnulib_dir=
2085   cached_specified_modules=
2086   cached_avoidlist=
2087   cached_sourcebase=
2088   cached_m4base=
2089   cached_pobase=
2090   cached_docbase=
2091   cached_testsbase=
2092   cached_inctests=
2093   cached_libname=
2094   cached_lgpl=
2095   cached_makefile_name=
2096   cached_libtool=
2097   cached_macro_prefix=
2098   cached_po_domain=
2099   cached_files=
2100   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2101     cached_libtool=false
2102     my_sed_traces='
2103       s,#.*$,,
2104       s,^dnl .*$,,
2105       s, dnl .*$,,
2106       /gl_LOCAL_DIR(/ {
2107         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
2108       }
2109       /gl_MODULES(/ {
2110         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
2111       }
2112       /gl_AVOID(/ {
2113         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
2114       }
2115       /gl_SOURCE_BASE(/ {
2116         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
2117       }
2118       /gl_M4_BASE(/ {
2119         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
2120       }
2121       /gl_PO_BASE(/ {
2122         s,^.*gl_PO_BASE([[ ]*\([^])]*\).*$,cached_pobase="\1",p
2123       }
2124       /gl_DOC_BASE(/ {
2125         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
2126       }
2127       /gl_TESTS_BASE(/ {
2128         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
2129       }
2130       /gl_WITH_TESTS/ {
2131         s,^.*$,cached_inctests=true,p
2132       }
2133       /gl_LIB(/ {
2134         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
2135       }
2136       /gl_LGPL(/ {
2137         s,^.*gl_LGPL([[ ]*\([^])]*\).*$,cached_lgpl="\1",p
2138       }
2139       /gl_LGPL/ {
2140         s,^.*$,cached_lgpl=yes,p
2141       }
2142       /gl_MAKEFILE_NAME(/ {
2143         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
2144       }
2145       /gl_LIBTOOL/ {
2146         s,^.*$,cached_libtool=true,p
2147       }
2148       /gl_MACRO_PREFIX(/ {
2149         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
2150       }
2151       /gl_PO_DOMAIN(/ {
2152         s,^.*gl_PO_DOMAIN([[ ]*\([^])]*\).*$,cached_po_domain="\1",p
2153       }'
2154     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
2155     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2156       my_sed_traces='
2157         s,#.*$,,
2158         s,^dnl .*$,,
2159         s, dnl .*$,,
2160         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
2161           s,^.*$,cached_files=",p
2162           n
2163           ta
2164           :a
2165           s,^\]).*$,",
2166           tb
2167           p
2168           n
2169           ba
2170           :b
2171           p
2172         }'
2173       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
2174     fi
2175   fi
2176
2177   # Merge the cached settings with the specified ones.
2178   # The m4base must be the same as expected from the pathname.
2179   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
2180     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
2181   fi
2182   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
2183   # is relative to $destdir, whereas the one we use is relative to . or absolute.
2184   if test -z "$local_gnulib_dir"; then
2185     if test -n "$cached_local_gnulib_dir"; then
2186       case "$destdir" in
2187         /*)
2188           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2189         *)
2190           case "$cached_local_gnulib_dir" in
2191             /*)
2192               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2193             *)
2194               func_relconcat "$destdir" "$cached_local_gnulib_dir"
2195               local_gnulib_dir="$relconcat" ;;
2196           esac ;;
2197       esac
2198     fi
2199   fi
2200   # Append the cached and the specified module names. So that
2201   # "gnulib-tool --import foo" means to add the module foo.
2202   specified_modules="$cached_specified_modules $1"
2203   # Append the cached and the specified avoidlist. This is probably better
2204   # than dropping the cached one when --avoid is specified at least once.
2205   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
2206   avoidlist=`echo $avoidlist`
2207
2208   # The sourcebase defaults to the cached one.
2209   if test -z "$sourcebase"; then
2210     sourcebase="$cached_sourcebase"
2211     if test -z "$sourcebase"; then
2212       func_fatal_error "missing --source-base option"
2213     fi
2214   fi
2215   # The pobase defaults to the cached one.
2216   if test -z "$pobase"; then
2217     pobase="$cached_pobase"
2218   fi
2219   # The docbase defaults to the cached one.
2220   if test -z "$docbase"; then
2221     docbase="$cached_docbase"
2222     if test -z "$docbase"; then
2223       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."
2224     fi
2225   fi
2226   # The testsbase defaults to the cached one.
2227   if test -z "$testsbase"; then
2228     testsbase="$cached_testsbase"
2229     if test -z "$testsbase"; then
2230       func_fatal_error "missing --tests-base option"
2231     fi
2232   fi
2233   # Require the tests if specified either way.
2234   if test -z "$inctests"; then
2235     inctests="$cached_inctests"
2236   fi
2237   # The libname defaults to the cached one.
2238   if test -z "$supplied_libname"; then
2239     libname="$cached_libname"
2240     if test -z "$libname"; then
2241       func_fatal_error "missing --lib option"
2242     fi
2243   fi
2244   # Require LGPL if specified either way.
2245   if test -z "$lgpl"; then
2246     lgpl="$cached_lgpl"
2247   fi
2248   # The makefile_name defaults to the cached one.
2249   if test -z "$makefile_name"; then
2250     makefile_name="$cached_makefile_name"
2251   fi
2252   # Use libtool if specified either way, or if guessed.
2253   if test -z "$libtool"; then
2254     if test -n "$cached_m4base"; then
2255       libtool="$cached_libtool"
2256     else
2257       libtool="$guessed_libtool"
2258     fi
2259   fi
2260   # The macro_prefix defaults to the cached one.
2261   if test -z "$macro_prefix"; then
2262     macro_prefix="$cached_macro_prefix"
2263     if test -z "$macro_prefix"; then
2264       func_fatal_error "missing --macro-prefix option"
2265     fi
2266   fi
2267   # The po_domain defaults to the cached one.
2268   if test -z "$po_domain"; then
2269     po_domain="$cached_po_domain"
2270   fi
2271
2272   # Canonicalize the list of specified modules.
2273   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
2274
2275   # Determine final module list.
2276   modules="$specified_modules"
2277   func_modules_transitive_closure
2278   if test $verbose -ge 0; then
2279     echo "Module list with included dependencies:"
2280     echo "$modules" | sed -e 's/^/  /'
2281   fi
2282   final_modules="$modules"
2283
2284   # Determine main module list and tests-related module list separately.
2285   # The main module list is the transitive closure of the specified modules,
2286   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2287   # is specified, it will consist only of LGPLed source.
2288   # The tests-related module list is the transitive closure of the specified
2289   # modules, including tests modules, minus the main module list. Its lib/*
2290   # sources (brought in through dependencies of *-tests modules) go into
2291   # $testsbase/. It may contain GPLed source, even if --lgpl is specified.
2292   # Determine main module list.
2293   saved_inctests="$inctests"
2294   inctests=""
2295   modules="$specified_modules"
2296   func_modules_transitive_closure
2297   main_modules="$modules"
2298   inctests="$saved_inctests"
2299   if test $verbose -ge 1; then
2300     echo "Main module list:"
2301     echo "$main_modules" | sed -e 's/^/  /'
2302   fi
2303   # Determine tests-related module list.
2304   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
2305   testsrelated_modules=`echo "$main_modules" | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
2306   if test $verbose -ge 1; then
2307     echo "Tests-related module list:"
2308     echo "$testsrelated_modules" | sed -e 's/^/  /'
2309   fi
2310
2311   # Add the dummy module to the main module list if needed.
2312   modules="$main_modules"
2313   func_modules_add_dummy
2314   main_modules="$modules"
2315
2316   # Determine whether a $testsbase/libtests.a is needed.
2317   use_libtests=false
2318   for module in $testsrelated_modules; do
2319     func_verify_nontests_module
2320     if test -n "$module"; then
2321       all_files=`func_get_filelist $module`
2322       lib_files=`for f in $all_files; do \
2323                    case $f in \
2324                      lib/*) echo $f ;; \
2325                    esac; \
2326                  done | sed -e 's,^lib/,,'`
2327       if test -n "$lib_files"; then
2328         use_libtests=true
2329         break
2330       fi
2331     fi
2332   done
2333
2334   # Add the dummy module to the tests-related module list if needed.
2335   if $use_libtests; then
2336     modules="$testsrelated_modules"
2337     func_modules_add_dummy
2338     testsrelated_modules="$modules"
2339   fi
2340
2341   # If --lgpl, verify that the licenses of modules are compatible.
2342   if test -n "$lgpl"; then
2343     for module in $main_modules; do
2344       license=`func_get_license $module`
2345       case $license in
2346         'GPLed build tool') ;;
2347         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2348         *)
2349           case "$lgpl" in
2350             yes | 3)
2351               case $license in
2352                 LGPL | LGPLv2+) ;;
2353                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2354               esac
2355               ;;
2356             2)
2357               case $license in
2358                 LGPLv2+) ;;
2359                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2360               esac
2361               ;;
2362             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2363           esac
2364           ;;
2365       esac
2366     done
2367   fi
2368
2369   # Show banner notice of every module.
2370   modules="$main_modules"
2371   func_modules_notice
2372
2373   # Determine script to apply to imported library files.
2374   sed_transform_lib_file=
2375   for module in $main_modules; do
2376     if test $module = config-h; then
2377       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
2378       sed_transform_lib_file=$sed_transform_lib_file'
2379         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
2380       '
2381       break
2382     fi
2383   done
2384   sed_transform_main_lib_file="$sed_transform_lib_file"
2385   if test -n "$do_copyrights"; then
2386     if test -n "$lgpl"; then
2387       # Update license.
2388       case "$lgpl" in
2389         yes | 3)
2390           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2391             s/GNU General/GNU Lesser General/g
2392           '
2393           ;;
2394         2)
2395           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2396             s/GNU General/GNU Lesser General/g
2397             s/version [23]\([ ,]\)/version 2.1\1/g
2398           '
2399           ;;
2400         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2401       esac
2402     else
2403       # Update license.
2404       sed_transform_main_lib_file=$sed_transform_main_lib_file'
2405         s/GNU Lesser General/GNU General/g
2406         s/GNU Library General/GNU General/g
2407         s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2408       '
2409     fi
2410   fi
2411
2412   # Determine script to apply to library files that go into $testsbase/.
2413   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
2414   if test -n "$do_copyrights"; then
2415     # Update license.
2416     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
2417       s/GNU Lesser General/GNU General/g
2418       s/GNU Library General/GNU General/g
2419       s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2420     '
2421   fi
2422
2423   # Determine the final file lists.
2424   # They must be computed separately, because files in lib/* go into
2425   # $sourcebase/ if they are in the main file list but into $testsbase/
2426   # if they are in the tests-related file list. Furthermore lib/dummy.c
2427   # can be in both.
2428   # Determine final main file list.
2429   modules="$main_modules"
2430   func_modules_to_filelist
2431   main_files="$files"
2432   # Determine final tests-related file list.
2433   modules="$testsrelated_modules"
2434   func_modules_to_filelist
2435   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
2436   # Merge both file lists.
2437   sed_remove_empty_lines='/^$/d'
2438   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
2439   if test $verbose -ge 0; then
2440     echo "File list:"
2441     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
2442     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
2443   fi
2444
2445   test -n "$files" \
2446     || func_fatal_error "refusing to do nothing"
2447
2448   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2449   new_files="$files m4/gnulib-tool.m4"
2450   old_files="$cached_files"
2451   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2452     func_append old_files " m4/gnulib-tool.m4"
2453   fi
2454
2455   sed_rewrite_old_files="\
2456     s,^build-aux/,$auxdir/,
2457     s,^doc/,$cached_docbase/,
2458     s,^lib/,$cached_sourcebase/,
2459     s,^m4/,$cached_m4base/,
2460     s,^tests/,$cached_testsbase/,
2461     s,^tests=lib/,$cached_testsbase/,"
2462   sed_rewrite_new_files="\
2463     s,^build-aux/,$auxdir/,
2464     s,^doc/,$docbase/,
2465     s,^lib/,$sourcebase/,
2466     s,^m4/,$m4base/,
2467     s,^tests/,$testsbase/,
2468     s,^tests=lib/,$testsbase/,"
2469
2470   # Create directories.
2471   { echo "$sourcebase"
2472     echo "$m4base"
2473     if test -n "$pobase"; then
2474       echo "$pobase"
2475     fi
2476     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2477     if test -n "$docfiles"; then
2478       echo "$docbase"
2479     fi
2480     if test -n "$inctests"; then
2481       echo "$testsbase"
2482     fi
2483     echo "$auxdir"
2484     for f in $files; do echo $f; done \
2485       | sed -e "$sed_rewrite_new_files" \
2486       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2487       | LC_ALL=C sort -u
2488   } > "$tmp"/dirs
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"/dirs
2492     while read d; do
2493       if test ! -d "$destdir/$d"; then
2494         if $doit; then
2495           echo "Creating directory $destdir/$d"
2496           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2497         else
2498           echo "Create directory $destdir/$d"
2499         fi
2500       fi
2501     done
2502     exec 0<&5 5<&-
2503   }
2504
2505   # func_dest_tmpfilename file
2506   # determines the name of a temporary file (file is relative to destdir).
2507   # Sets variable:
2508   #   - tmpfile       absolute filename of the temporary file
2509   func_dest_tmpfilename ()
2510   {
2511     if $doit; then
2512       # Put the new contents of $file in a file in the same directory (needed
2513       # to guarantee that an 'mv' to "$destdir/$file" works).
2514       tmpfile="$destdir/$1.tmp"
2515     else
2516       # Put the new contents of $file in a file in a temporary directory
2517       # (because the directory of "$file" might not exist).
2518       tmpfile="$tmp"/`basename "$1"`.tmp
2519     fi
2520   }
2521
2522   # Copy files or make symbolic links. Remove obsolete files.
2523   added_files=''
2524   removed_files=''
2525   delimiter='   '
2526   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2527   # representing the files according to the last gnulib-tool invocation.
2528   for f in $old_files; do echo $f; done \
2529     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2530     | LC_ALL=C sort \
2531     > "$tmp"/old-files
2532   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2533   # representing the files after this gnulib-tool invocation.
2534   for f in $new_files; do echo $f; done \
2535     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2536     | LC_ALL=C sort \
2537     > "$tmp"/new-files
2538   # First the files that are in old-files, but not in new-files:
2539   sed_take_first_column='s,'"$delimiter"'.*,,'
2540   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2541     # Remove the file. Do nothing if the user already removed it.
2542     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
2543       if $doit; then
2544         echo "Removing file $g (backup in ${g}~)"
2545         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2546       else
2547         echo "Remove file $g (backup in ${g}~)"
2548       fi
2549       func_append removed_files "$g$nl"
2550     fi
2551   done
2552   # func_add_or_update handles a file that ought to be present afterwards.
2553   # Uses parameters
2554   # - f             the original file name
2555   # - g             the rewritten file name
2556   # - already_present  nonempty if the file already exists, empty otherwise
2557   func_add_or_update ()
2558   {
2559     of="$f"
2560     case "$f" in
2561       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
2562     esac
2563     func_dest_tmpfilename "$g"
2564     func_lookup_file "$f"
2565     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2566     if test -n "$sed_transform_main_lib_file"; then
2567       case "$of" in
2568         lib/*)
2569           sed -e "$sed_transform_main_lib_file" \
2570             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2571           ;;
2572       esac
2573     fi
2574     if test -n "$sed_transform_testsrelated_lib_file"; then
2575       case "$of" in
2576         tests=lib/*)
2577           sed -e "$sed_transform_testsrelated_lib_file" \
2578             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2579           ;;
2580       esac
2581     fi
2582     if test -f "$destdir/$g"; then
2583       # The file already exists.
2584       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2585         : # The file has not changed.
2586       else
2587         # Replace the file.
2588         if $doit; then
2589           if test -n "$already_present"; then
2590             echo "Updating file $g (backup in ${g}~)"
2591           else
2592             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
2593           fi
2594           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2595           if { test -n "$symbolic" \
2596                || { test -n "$lsymbolic" \
2597                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2598              && test -z "$lookedup_tmp" \
2599              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2600             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2601           else
2602             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2603           fi
2604         else
2605           if test -n "$already_present"; then
2606             echo "Update file $g (backup in ${g}~)"
2607           else
2608             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
2609           fi
2610         fi
2611       fi
2612     else
2613       # Install the file.
2614       # Don't protest if the file should be there but isn't: it happens
2615       # frequently that developers don't put autogenerated files into CVS.
2616       if $doit; then
2617         echo "Copying file $g"
2618         if { test -n "$symbolic" \
2619              || { test -n "$lsymbolic" \
2620                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2621            && test -z "$lookedup_tmp" \
2622            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2623           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2624         else
2625           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2626         fi
2627       else
2628         echo "Copy file $g"
2629       fi
2630       func_append added_files "$g$nl"
2631     fi
2632     rm -f "$tmpfile"
2633   }
2634   # Then the files that are in new-files, but not in old-files:
2635   sed_take_last_column='s,^.*'"$delimiter"',,'
2636   already_present=
2637   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2638     | sed -e "$sed_take_last_column" \
2639     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2640   { # Rearrange file descriptors. Needed because "while ... done < ..."
2641     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2642     exec 5<&0 < "$tmp"/added-files
2643     while read g f; do
2644       func_add_or_update
2645     done
2646     exec 0<&5 5<&-
2647   }
2648   # Then the files that are in new-files and in old-files:
2649   already_present=true
2650   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2651     | sed -e "$sed_take_last_column" \
2652     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2653   { # Rearrange file descriptors. Needed because "while ... done < ..."
2654     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2655     exec 5<&0 < "$tmp"/kept-files
2656     while read g f; do
2657       func_add_or_update
2658     done
2659     exec 0<&5 5<&-
2660   }
2661
2662   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2663   actioncmd="gnulib-tool --import"
2664   func_append actioncmd " --dir=$destdir"
2665   if test -n "$local_gnulib_dir"; then
2666     func_append actioncmd " --local-dir=$local_gnulib_dir"
2667   fi
2668   func_append actioncmd " --lib=$libname"
2669   func_append actioncmd " --source-base=$sourcebase"
2670   func_append actioncmd " --m4-base=$m4base"
2671   if test -n "$pobase"; then
2672     func_append actioncmd " --po-base=$pobase"
2673   fi
2674   func_append actioncmd " --doc-base=$docbase"
2675   func_append actioncmd " --aux-dir=$auxdir"
2676   if test -n "$inctests"; then
2677     func_append actioncmd " --with-tests"
2678   fi
2679   for module in $avoidlist; do
2680     func_append actioncmd " --avoid=$module"
2681   done
2682   if test -n "$lgpl"; then
2683     if test "$lgpl" = yes; then
2684       func_append actioncmd " --lgpl"
2685     else
2686       func_append actioncmd " --lgpl=$lgpl"
2687     fi
2688   fi
2689   if test -n "$makefile_name"; then
2690     func_append actioncmd " --makefile-name=$makefile_name"
2691   fi
2692   if test "$libtool" = true; then
2693     func_append actioncmd " --libtool"
2694   else
2695     func_append actioncmd " --no-libtool"
2696   fi
2697   func_append actioncmd " --macro-prefix=$macro_prefix"
2698   if test -n "$po_domain"; then
2699     func_append actioncmd " --po-domain=$po_domain"
2700   fi
2701   func_append actioncmd " `echo $specified_modules`"
2702
2703   # Default the makefile name to Makefile.am.
2704   if test -n "$makefile_name"; then
2705     makefile_am=$makefile_name
2706   else
2707     makefile_am=Makefile.am
2708   fi
2709
2710   # Create normal Makefile.ams.
2711   for_test=false
2712
2713   # Create library makefile.
2714   func_dest_tmpfilename $sourcebase/$makefile_am
2715   modules="$main_modules"
2716   func_emit_lib_Makefile_am > "$tmpfile"
2717   if test -f "$destdir"/$sourcebase/$makefile_am; then
2718     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2719       rm -f "$tmpfile"
2720     else
2721       if $doit; then
2722         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2723         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2724         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2725       else
2726         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2727         rm -f "$tmpfile"
2728       fi
2729     fi
2730   else
2731     if $doit; then
2732       echo "Creating $sourcebase/$makefile_am"
2733       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2734     else
2735       echo "Create $sourcebase/$makefile_am"
2736       rm -f "$tmpfile"
2737     fi
2738     func_append added_files "$sourcebase/$makefile_am$nl"
2739   fi
2740
2741   # Create po/ directory.
2742   if test -n "$pobase"; then
2743     # Create po makefile and auxiliary files.
2744     for file in Makefile.in.in remove-potcdate.sin; do
2745       func_dest_tmpfilename $pobase/$file
2746       func_lookup_file build-aux/po/$file
2747       cat "$lookedup_file" > "$tmpfile"
2748       if test -f "$destdir"/$pobase/$file; then
2749         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
2750           rm -f "$tmpfile"
2751         else
2752           if $doit; then
2753             echo "Updating $pobase/$file (backup in $pobase/$file~)"
2754             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
2755             mv -f "$tmpfile" "$destdir"/$pobase/$file
2756           else
2757             echo "Update $pobase/$file (backup in $pobase/$file~)"
2758             rm -f "$tmpfile"
2759           fi
2760         fi
2761       else
2762         if $doit; then
2763           echo "Creating $pobase/$file"
2764           mv -f "$tmpfile" "$destdir"/$pobase/$file
2765         else
2766           echo "Create $pobase/$file"
2767           rm -f "$tmpfile"
2768         fi
2769         func_append added_files "$pobase/$file$nl"
2770       fi
2771     done
2772     # Create po makefile parametrization, part 1.
2773     func_dest_tmpfilename $pobase/Makevars
2774     func_emit_po_Makevars > "$tmpfile"
2775     if test -f "$destdir"/$pobase/Makevars; then
2776       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
2777         rm -f "$tmpfile"
2778       else
2779         if $doit; then
2780           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
2781           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
2782           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2783         else
2784           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
2785           rm -f "$tmpfile"
2786         fi
2787       fi
2788     else
2789       if $doit; then
2790         echo "Creating $pobase/Makevars"
2791         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2792       else
2793         echo "Create $pobase/Makevars"
2794         rm -f "$tmpfile"
2795       fi
2796       func_append added_files "$pobase/Makevars$nl"
2797     fi
2798     # Create po makefile parametrization, part 2.
2799     func_dest_tmpfilename $pobase/POTFILES.in
2800     func_emit_po_POTFILES_in > "$tmpfile"
2801     if test -f "$destdir"/$pobase/POTFILES.in; then
2802       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
2803         rm -f "$tmpfile"
2804       else
2805         if $doit; then
2806           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2807           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
2808           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2809         else
2810           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2811           rm -f "$tmpfile"
2812         fi
2813       fi
2814     else
2815       if $doit; then
2816         echo "Creating $pobase/POTFILES.in"
2817         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2818       else
2819         echo "Create $pobase/POTFILES.in"
2820         rm -f "$tmpfile"
2821       fi
2822       func_append added_files "$pobase/POTFILES.in$nl"
2823     fi
2824     # Fetch PO files.
2825     TP_URL="http://translationproject.org/latest/"
2826     TP_RSYNC_URI="translationproject.org::tp/latest/"
2827     if $doit; then
2828       echo "Fetching gnulib PO files from $TP_URL"
2829       (cd "$destdir"/$pobase \
2830        && { # Prefer rsync over wget if it is available, since it consumes
2831             # less network bandwidth, due to compression.
2832             if type rsync 2>/dev/null | grep / > /dev/null; then
2833               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
2834             else
2835               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
2836             fi
2837           }
2838       )
2839     else
2840       echo "Fetch gnulib PO files from $TP_URL"
2841     fi
2842     # Create po/LINGUAS.
2843     if $doit; then
2844       func_dest_tmpfilename $pobase/LINGUAS
2845       (cd "$destdir"/$pobase \
2846        && { echo '# Set of available languages.'
2847             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
2848           }
2849       ) > "$tmpfile"
2850       if test -f "$destdir"/$pobase/LINGUAS; then
2851         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
2852           rm -f "$tmpfile"
2853         else
2854           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2855           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
2856           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2857         fi
2858       else
2859         echo "Creating $pobase/LINGUAS"
2860         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2861         func_append added_files "$pobase/LINGUAS$nl"
2862       fi
2863     else
2864       if test -f "$destdir"/$pobase/LINGUAS; then
2865         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2866       else
2867         echo "Create $pobase/LINGUAS"
2868       fi
2869     fi
2870   fi
2871
2872   # Create m4/gnulib-cache.m4.
2873   func_dest_tmpfilename $m4base/gnulib-cache.m4
2874   (
2875     func_emit_copyright_notice
2876     echo "#"
2877     echo "# This file represents the specification of how gnulib-tool is used."
2878     echo "# It acts as a cache: It is written and read by gnulib-tool."
2879     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2880     echo "# like the configure.ac and various Makefile.am files."
2881     echo
2882     echo
2883     echo "# Specification in the form of a command-line invocation:"
2884     echo "#   $actioncmd"
2885     echo
2886     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
2887     # Store the local_gnulib_dir relative to destdir.
2888     case "$local_gnulib_dir" in
2889       "" | /*)
2890         relative_local_gnulib_dir="$local_gnulib_dir" ;;
2891       * )
2892         case "$destdir" in
2893           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
2894           *)
2895             # destdir, local_gnulib_dir are both relative.
2896             func_relativize "$destdir" "$local_gnulib_dir"
2897             relative_local_gnulib_dir="$reldir" ;;
2898         esac ;;
2899     esac
2900     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
2901     echo "gl_MODULES(["`echo $specified_modules`"])"
2902     echo "gl_AVOID([$avoidlist])"
2903     echo "gl_SOURCE_BASE([$sourcebase])"
2904     echo "gl_M4_BASE([$m4base])"
2905     echo "gl_PO_BASE([$pobase])"
2906     echo "gl_DOC_BASE([$docbase])"
2907     echo "gl_TESTS_BASE([$testsbase])"
2908     test -z "$inctests" || echo "gl_WITH_TESTS"
2909     echo "gl_LIB([$libname])"
2910     if test -n "$lgpl"; then
2911       if test "$lgpl" = yes; then
2912         echo "gl_LGPL"
2913       else
2914         echo "gl_LGPL([$lgpl])"
2915       fi
2916     fi
2917     echo "gl_MAKEFILE_NAME([$makefile_name])"
2918     if test "$libtool" = true; then
2919       echo "gl_LIBTOOL"
2920     fi
2921     echo "gl_MACRO_PREFIX([$macro_prefix])"
2922     echo "gl_PO_DOMAIN([$po_domain])"
2923   ) > "$tmpfile"
2924   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2925     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2926       rm -f "$tmpfile"
2927     else
2928       if $doit; then
2929         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2930         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2931         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2932       else
2933         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2934         if false; then
2935           cat "$tmpfile"
2936           echo
2937           echo "# gnulib-cache.m4 ends here"
2938         fi
2939         rm -f "$tmpfile"
2940       fi
2941     fi
2942   else
2943     if $doit; then
2944       echo "Creating $m4base/gnulib-cache.m4"
2945       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2946     else
2947       echo "Create $m4base/gnulib-cache.m4"
2948       cat "$tmpfile"
2949       rm -f "$tmpfile"
2950     fi
2951   fi
2952
2953   # Create m4/gnulib-comp.m4.
2954   func_dest_tmpfilename $m4base/gnulib-comp.m4
2955   (
2956     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2957     func_emit_copyright_notice
2958     echo "#"
2959     echo "# This file represents the compiled summary of the specification in"
2960     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2961     echo "# to be invoked from configure.ac."
2962     echo "# In projects using CVS, this file can be treated like other built files."
2963     echo
2964     echo
2965     echo "# This macro should be invoked from $configure_ac, in the section"
2966     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2967     echo "# any checks for libraries, header files, types and library functions."
2968     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2969     echo "["
2970     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2971     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2972     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2973     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2974     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2975     if test -n "$uses_subdirs"; then
2976       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2977     fi
2978     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2979       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2980     fi
2981     for module in $final_modules; do
2982       func_verify_module
2983       if test -n "$module"; then
2984         func_get_autoconf_early_snippet "$module"
2985       fi
2986     done \
2987       | sed -e '/^$/d;' -e 's/^/  /'
2988     echo "])"
2989     echo
2990     echo "# This macro should be invoked from $configure_ac, in the section"
2991     echo "# \"Check for header files, types and library functions\"."
2992     echo "AC_DEFUN([${macro_prefix}_INIT],"
2993     echo "["
2994     if test "$libtool" = true; then
2995       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2996       echo "  gl_cond_libtool=true"
2997     else
2998       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2999       echo "  gl_cond_libtool=false"
3000       echo "  gl_libdeps="
3001       echo "  gl_ltlibdeps="
3002     fi
3003     if test "$auxdir" != "build-aux"; then
3004       sed_replace_build_aux='
3005         :a
3006         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3007           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3008           ba
3009         }'
3010     else
3011       sed_replace_build_aux=
3012     fi
3013     func_emit_initmacro_start $macro_prefix
3014     echo "  gl_source_base='$sourcebase'"
3015     for module in $main_modules; do
3016       func_verify_module
3017       if test -n "$module"; then
3018         func_get_autoconf_snippet "$module" \
3019           | sed -e '/^$/d;' -e 's/^/  /' \
3020                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3021                 -e "$sed_replace_build_aux"
3022         if test "$module" = 'alloca' && test "$libtool" = true; then
3023           echo 'changequote(,)dnl'
3024           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3025           echo 'changequote([, ])dnl'
3026           echo 'AC_SUBST([LTALLOCA])'
3027         fi
3028       fi
3029     done
3030     func_emit_initmacro_end $macro_prefix
3031     echo "  gltests_libdeps="
3032     echo "  gltests_ltlibdeps="
3033     func_emit_initmacro_start ${macro_prefix}tests
3034     echo "  gl_source_base='$testsbase'"
3035     for module in $testsrelated_modules; do
3036       func_verify_module
3037       if test -n "$module"; then
3038         func_get_autoconf_snippet "$module" \
3039           | sed -e '/^$/d;' -e 's/^/  /' \
3040                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3041                 -e "$sed_replace_build_aux" \
3042                 -e 's/\$gl_cond_libtool/false/g' \
3043                 -e 's/gl_libdeps/gltests_libdeps/g' \
3044                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3045       fi
3046     done
3047     func_emit_initmacro_end ${macro_prefix}tests
3048     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3049     # created using libtool, because libtool already handles the dependencies.
3050     if test "$libtool" != true; then
3051       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3052       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3053       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3054       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3055       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3056     fi
3057     if $use_libtests; then
3058       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
3059       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
3060     fi
3061     echo "])"
3062     func_emit_initmacro_done $macro_prefix $sourcebase
3063     func_emit_initmacro_done ${macro_prefix}tests $testsbase
3064     echo
3065     echo "# This macro records the list of files which have been installed by"
3066     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
3067     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
3068     echo "$files" | sed -e 's,^,  ,'
3069     echo "])"
3070   ) > "$tmpfile"
3071   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3072     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
3073       rm -f "$tmpfile"
3074     else
3075       if $doit; then
3076         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3077         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
3078         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3079       else
3080         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3081         if false; then
3082           cat "$tmpfile"
3083           echo
3084           echo "# gnulib-comp.m4 ends here"
3085         fi
3086         rm -f "$tmpfile"
3087       fi
3088     fi
3089   else
3090     if $doit; then
3091       echo "Creating $m4base/gnulib-comp.m4"
3092       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3093     else
3094       echo "Create $m4base/gnulib-comp.m4"
3095       cat "$tmpfile"
3096       rm -f "$tmpfile"
3097     fi
3098   fi
3099
3100   if test -n "$inctests"; then
3101     # Create tests makefile.
3102     func_dest_tmpfilename $testsbase/$makefile_am
3103     modules="$testsrelated_modules"
3104     func_emit_tests_Makefile_am > "$tmpfile"
3105     if test -f "$destdir"/$testsbase/$makefile_am; then
3106       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
3107         rm -f "$tmpfile"
3108       else
3109         if $doit; then
3110           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3111           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
3112           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3113         else
3114           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3115           rm -f "$tmpfile"
3116         fi
3117       fi
3118     else
3119       if $doit; then
3120         echo "Creating $testsbase/$makefile_am"
3121         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3122       else
3123         echo "Create $testsbase/$makefile_am"
3124         rm -f "$tmpfile"
3125       fi
3126     func_append added_files "$testsbase/$makefile_am$nl"
3127     fi
3128   fi
3129
3130   # Update the .cvsignore and .gitignore files.
3131   { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
3132     echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
3133   } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
3134   { # Rearrange file descriptors. Needed because "while ... done < ..."
3135     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3136     exec 5<&0 < "$tmp"/fileset-changes
3137     func_update_ignorelist ()
3138     {
3139       ignore="$1"
3140       if test -f "$destdir/$dir$ignore"; then
3141         if test -n "$dir_added" || test -n "$dir_removed"; then
3142           LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
3143           echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
3144             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
3145           echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
3146             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
3147           if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
3148             if $doit; then
3149               echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3150               mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
3151               sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
3152               cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
3153                 | sed -f "$tmp"/sed-ignore-removed \
3154                 > "$destdir/$dir$ignore"
3155             else
3156               echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3157             fi
3158           fi
3159         fi
3160       else
3161         if test -n "$dir_added"; then
3162           if $doit; then
3163             echo "Creating $destdir/$dir$ignore"
3164             {
3165               if test "$ignore" = .cvsignore; then
3166                 echo ".deps"
3167                 # Automake generates Makefile rules that create .dirstamp files.
3168                 echo ".dirstamp"
3169               fi
3170               echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u
3171             } > "$destdir/$dir$ignore"
3172           else
3173             echo "Create $destdir/$dir$ignore"
3174           fi
3175         fi
3176       fi
3177     }
3178     func_done_dir ()
3179     {
3180       dir="$1"
3181       dir_added="$2"
3182       dir_removed="$3"
3183       if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
3184         func_update_ignorelist .cvsignore
3185       fi
3186       if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
3187         func_update_ignorelist .gitignore
3188       fi
3189     }
3190     last_dir=
3191     last_dir_added=
3192     last_dir_removed=
3193     while read line; do
3194       # Why not ''read next_dir op file'' ? Because the dir column can be empty.
3195       next_dir=`echo "$line" | sed -e 's,|.*,,'`
3196       op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
3197       file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
3198       if test "$next_dir" != "$last_dir"; then
3199         func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3200         last_dir="$next_dir"
3201         last_dir_added=
3202         last_dir_removed=
3203       fi
3204       case $op in
3205         A) func_append last_dir_added "$file$nl";;
3206         R) func_append last_dir_removed "$file$nl";;
3207       esac
3208     done
3209     func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3210     exec 0<&5 5<&-
3211   }
3212
3213   echo "Finished."
3214   echo
3215   echo "You may need to add #include directives for the following .h files."
3216   # Intersect $specified_modules and $main_modules
3217   # (since $specified_modules is not necessarily of subset of $main_modules
3218   # - some may have been skipped through --avoid, and since the elements of
3219   # $main_modules but not in $specified_modules can go away without explicit
3220   # notice - through changes in the module dependencies).
3221   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
3222   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
3223   # First the #include <...> directives without #ifs, sorted for convenience,
3224   # then the #include "..." directives without #ifs, sorted for convenience,
3225   # then the #include directives that are surrounded by #ifs. Not sorted.
3226   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
3227     include_directive=`func_get_include_directive "$module"`
3228     case "$nl$include_directive" in
3229       *"$nl#if"*)
3230         echo "$include_directive" 1>&5
3231         ;;
3232       *)
3233         echo "$include_directive" | grep -v 'include "' 1>&6
3234         echo "$include_directive" | grep 'include "' 1>&7
3235         ;;
3236     esac
3237   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
3238   (
3239    LC_ALL=C sort -u "$tmp"/include-angles
3240    LC_ALL=C sort -u "$tmp"/include-quotes
3241    cat "$tmp"/include-if
3242   ) | sed -e '/^$/d' -e 's/^/  /'
3243   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
3244
3245   for module in $main_modules; do
3246     func_get_link_directive "$module"
3247   done \
3248     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
3249   if test `wc -l < "$tmp"/link` != 0; then
3250     echo
3251     echo "You may need to use the following Makefile variables when linking."
3252     echo "Use them in <program>_LDADD when linking a program, or"
3253     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
3254     cat "$tmp"/link
3255   fi
3256   rm -f "$tmp"/link
3257
3258   echo
3259   echo "Don't forget to"
3260   if test "$makefile_am" = Makefile.am; then
3261     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3262   else
3263     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
3264   fi
3265   if test -n "$pobase"; then
3266     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
3267   fi
3268   if test -n "$inctests"; then
3269     if test "$makefile_am" = Makefile.am; then
3270       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3271     else
3272       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
3273     fi
3274   fi
3275   if test "$makefile_am" = Makefile.am; then
3276     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
3277     sourcebase_base=`basename "$sourcebase"`
3278     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
3279   fi
3280   if test -n "$pobase"; then
3281     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
3282     pobase_base=`basename "$pobase"`
3283     echo "  - mention \"${pobase_base}\" in SUBDIRS in ${pobase_dir}Makefile.am,"
3284   fi
3285   if test -n "$inctests"; then
3286     if test "$makefile_am" = Makefile.am; then
3287       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
3288       testsbase_base=`basename "$testsbase"`
3289       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
3290     fi
3291   fi
3292   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
3293   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
3294   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
3295 }
3296
3297 # func_create_testdir testdir modules
3298 # Input:
3299 # - local_gnulib_dir  from --local-dir
3300 # - auxdir          directory relative to destdir where to place build aux files
3301 func_create_testdir ()
3302 {
3303   testdir="$1"
3304   modules="$2"
3305   if test -z "$modules"; then
3306     # All modules together.
3307     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3308     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3309     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
3310     modules=`func_all_modules`
3311     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
3312   fi
3313   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
3314
3315   # Check that the license of every module is consistent with the license of
3316   # its dependencies.
3317   saved_modules="$modules"
3318   saved_inctests="$inctests"
3319   # When computing transitive closures, don't consider $module to depend on
3320   # $module-tests. Need this becauses tests are implicitly GPL and may depend
3321   # on GPL modules - therefore we don't want a warning in this case.
3322   inctests=""
3323   for requested_module in $saved_modules; do
3324     requested_license=`func_get_license "$requested_module"`
3325     if test "$requested_license" != GPL; then
3326       # Here we use func_modules_transitive_closure, not just
3327       # func_get_dependencies, so that we also detect weird situations like
3328       # an LGPL module which depends on a GPLed build tool module which depends
3329       # on a GPL module.
3330       modules="$requested_module"
3331       func_modules_transitive_closure
3332       for module in $modules; do
3333         license=`func_get_license "$module"`
3334         case "$license" in
3335           'GPLed build tool') ;;
3336           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3337           *)
3338             case "$requested_license" in
3339               GPLv2+)
3340                 case "$license" in
3341                   GPLv2+ | LGPLv2+) ;;
3342                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3343                 esac
3344                 ;;
3345               LGPL)
3346                 case "$license" in
3347                   LGPL | LGPLv2+) ;;
3348                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3349                 esac
3350                 ;;
3351               LGPLv2+)
3352                 case "$license" in
3353                   LGPLv2+) ;;
3354                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3355                 esac
3356                 ;;
3357             esac
3358             ;;
3359         esac
3360       done
3361     fi
3362   done
3363   modules="$saved_modules"
3364   inctests="$saved_inctests"
3365
3366   # Subdirectory names.
3367   sourcebase=gllib
3368   m4base=glm4
3369   pobase=
3370   docbase=gldoc
3371   testsbase=gltests
3372   macro_prefix=gl
3373   po_domain=
3374
3375   # Determine final module list.
3376   func_modules_transitive_closure
3377   if test $verbose -ge 0; then
3378     echo "Module list with included dependencies:"
3379     echo "$modules" | sed -e 's/^/  /'
3380   fi
3381
3382   # Add the dummy module if needed.
3383   func_modules_add_dummy
3384
3385   # Show banner notice of every module.
3386   func_modules_notice
3387
3388   # Determine final file list.
3389   func_modules_to_filelist
3390   if test $verbose -ge 0; then
3391     echo "File list:"
3392     echo "$files" | sed -e 's/^/  /'
3393   fi
3394
3395   sed_rewrite_files="\
3396     s,^build-aux/,$auxdir/,
3397     s,^doc/,$docbase/,
3398     s,^lib/,$sourcebase/,
3399     s,^m4/,$m4base/,
3400     s,^tests/,$testsbase/,"
3401
3402   # Create directories.
3403   for f in $files; do echo $f; done \
3404     | sed -e "$sed_rewrite_files" \
3405     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3406     | LC_ALL=C sort -u \
3407     > "$tmp"/dirs
3408   { # Rearrange file descriptors. Needed because "while ... done < ..."
3409     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3410     exec 5<&0 < "$tmp"/dirs
3411     while read d; do
3412       mkdir -p "$testdir/$d"
3413     done
3414     exec 0<&5 5<&-
3415   }
3416
3417   # Copy files or make symbolic links.
3418   delimiter='   '
3419   for f in $files; do echo $f; done \
3420     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
3421     | LC_ALL=C sort \
3422     > "$tmp"/files
3423   { # Rearrange file descriptors. Needed because "while ... done < ..."
3424     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3425     exec 5<&0 < "$tmp"/files
3426     while read g f; do
3427       func_lookup_file "$f"
3428       if test -n "$lookedup_tmp"; then
3429         cp -p "$lookedup_file" "$testdir/$g"
3430       else
3431         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
3432         if { test -n "$symbolic" \
3433              || { test -n "$lsymbolic" \
3434                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
3435           func_ln "$lookedup_file" "$testdir/$g"
3436         else
3437           cp -p "$lookedup_file" "$testdir/$g"
3438         fi
3439       fi
3440     done
3441     exec 0<&5 5<&-
3442   }
3443
3444   # Create Makefile.ams that are for testing.
3445   for_test=true
3446
3447   # Create $sourcebase/Makefile.am.
3448   mkdir -p "$testdir/$sourcebase"
3449   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
3450   any_uses_subdirs="$uses_subdirs"
3451
3452   # Create $m4base/Makefile.am.
3453   mkdir -p "$testdir/$m4base"
3454   (echo "## Process this file with automake to produce Makefile.in."
3455    echo
3456    echo "EXTRA_DIST ="
3457    for f in $files; do
3458      case "$f" in
3459        m4/* )
3460          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
3461      esac
3462    done
3463   ) > "$testdir/$m4base/Makefile.am"
3464
3465   subdirs="$sourcebase $m4base"
3466   subdirs_with_configure_ac=""
3467
3468   if false && test -f "$testdir"/$m4base/gettext.m4; then
3469     # Avoid stupid error message from automake:
3470     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
3471     mkdir -p "$testdir/po"
3472     (echo "## Process this file with automake to produce Makefile.in."
3473     ) > "$testdir/po/Makefile.am"
3474     func_append subdirs " po"
3475   fi
3476
3477   if test -n "$inctests"; then
3478     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
3479     # Create $testsbase/Makefile.am.
3480     use_libtests=false
3481     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
3482     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
3483     # Create $testsbase/configure.ac.
3484     (echo "# Process this file with autoconf to produce a configure script."
3485      echo "AC_INIT([dummy], [0])"
3486      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
3487      echo "AM_INIT_AUTOMAKE"
3488      echo
3489      echo "AM_CONFIG_HEADER([config.h])"
3490      echo
3491      echo "AC_PROG_CC"
3492      echo "AC_PROG_INSTALL"
3493      echo "AC_PROG_MAKE_SET"
3494      echo "AC_PROG_RANLIB"
3495      echo
3496      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3497        echo "AC_GNU_SOURCE"
3498        echo
3499      fi
3500      for module in $modules; do
3501        func_verify_module
3502        if test -n "$module"; then
3503          func_get_autoconf_early_snippet "$module"
3504        fi
3505      done \
3506        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3507      if test "$libtool" = true; then
3508        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3509        echo "gl_cond_libtool=true"
3510      else
3511        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3512        echo "gl_cond_libtool=false"
3513        echo "gl_libdeps="
3514        echo "gl_ltlibdeps="
3515      fi
3516      # Wrap the set of autoconf snippets into an autoconf macro that is then
3517      # invoked. This is needed because autoconf does not support AC_REQUIRE
3518      # at the top level:
3519      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3520      # but we want the AC_REQUIRE to have its normal meaning (provide one
3521      # expansion of the required macro before the current point, and only one
3522      # expansion total).
3523      echo "AC_DEFUN([gl_INIT], ["
3524      sed_replace_build_aux='
3525        :a
3526        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3527          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
3528          ba
3529        }'
3530      func_emit_initmacro_start $macro_prefix
3531      # We don't have explicit ordering constraints between the various
3532      # autoconf snippets. It's cleanest to put those of the library before
3533      # those of the tests.
3534      echo "gl_source_base='../$sourcebase'"
3535      for module in $modules; do
3536        func_verify_nontests_module
3537        if test -n "$module"; then
3538          func_get_autoconf_snippet "$module" \
3539            | sed -e "$sed_replace_build_aux"
3540        fi
3541      done
3542      echo "gl_source_base='.'"
3543      for module in $modules; do
3544        func_verify_tests_module
3545        if test -n "$module"; then
3546          func_get_autoconf_snippet "$module" \
3547            | sed -e "$sed_replace_build_aux"
3548        fi
3549      done
3550      func_emit_initmacro_end $macro_prefix
3551      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3552      # created using libtool, because libtool already handles the dependencies.
3553      if test "$libtool" != true; then
3554        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3555        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3556        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3557        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3558        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3559      fi
3560      echo "])"
3561      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
3562      echo
3563      echo "gl_INIT"
3564      echo
3565      # Usually $testsbase/config.h will be a superset of config.h. Verify this
3566      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
3567      echo "AH_TOP([#include \"../config.h\"])"
3568      echo
3569      echo "AC_OUTPUT([Makefile])"
3570     ) > "$testdir/$testsbase/configure.ac"
3571     func_append subdirs " $testsbase"
3572     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
3573   fi
3574
3575   # Create Makefile.am.
3576   (echo "## Process this file with automake to produce Makefile.in."
3577    echo
3578    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3579    echo
3580    echo "SUBDIRS = $subdirs"
3581    echo
3582    echo "ACLOCAL_AMFLAGS = -I $m4base"
3583   ) > "$testdir/Makefile.am"
3584
3585   # Create configure.ac.
3586   (echo "# Process this file with autoconf to produce a configure script."
3587    echo "AC_INIT([dummy], [0])"
3588    if test "$auxdir" != "."; then
3589      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3590    fi
3591    echo "AM_INIT_AUTOMAKE"
3592    echo
3593    echo "AM_CONFIG_HEADER([config.h])"
3594    echo
3595    echo "AC_PROG_CC"
3596    echo "AC_PROG_INSTALL"
3597    echo "AC_PROG_MAKE_SET"
3598    echo
3599    echo "# For autobuild."
3600    echo "AC_CANONICAL_BUILD"
3601    echo "AC_CANONICAL_HOST"
3602    echo
3603    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3604    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3605    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3606    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3607    echo
3608    echo "AC_PROG_RANLIB"
3609    echo
3610    if test -n "$any_uses_subdirs"; then
3611      echo "AM_PROG_CC_C_O"
3612      echo
3613    fi
3614    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3615      echo "AC_GNU_SOURCE"
3616      echo
3617    fi
3618    for module in $modules; do
3619      func_verify_nontests_module
3620      if test -n "$module"; then
3621        func_get_autoconf_early_snippet "$module"
3622      fi
3623    done \
3624      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3625    if test "$libtool" = true; then
3626      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3627      echo "gl_cond_libtool=true"
3628    else
3629      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3630      echo "gl_cond_libtool=false"
3631      echo "gl_libdeps="
3632      echo "gl_ltlibdeps="
3633    fi
3634    # Wrap the set of autoconf snippets into an autoconf macro that is then
3635    # invoked. This is needed because autoconf does not support AC_REQUIRE
3636    # at the top level:
3637    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3638    # but we want the AC_REQUIRE to have its normal meaning (provide one
3639    # expansion of the required macro before the current point, and only one
3640    # expansion total).
3641    echo "AC_DEFUN([gl_INIT], ["
3642    if test "$auxdir" != "build-aux"; then
3643      sed_replace_build_aux='
3644        :a
3645        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3646          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3647          ba
3648        }'
3649    else
3650      sed_replace_build_aux=
3651    fi
3652    func_emit_initmacro_start $macro_prefix
3653    echo "gl_source_base='$sourcebase'"
3654    for module in $modules; do
3655      func_verify_nontests_module
3656      if test -n "$module"; then
3657        func_get_autoconf_snippet "$module" \
3658          | sed -e "$sed_replace_build_aux"
3659      fi
3660    done
3661    func_emit_initmacro_end $macro_prefix
3662    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3663    # created using libtool, because libtool already handles the dependencies.
3664    if test "$libtool" != true; then
3665      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3666      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3667      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3668      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3669      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3670    fi
3671    echo "])"
3672    func_emit_initmacro_done $macro_prefix $sourcebase
3673    echo
3674    echo "gl_INIT"
3675    echo
3676    if test -n "$subdirs_with_configure_ac"; then
3677      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3678    fi
3679    makefiles="Makefile"
3680    for d in $subdirs; do
3681      # For subdirs that have a configure.ac by their own, it's the subdir's
3682      # configure.ac which creates the subdir's Makefile.am, not this one.
3683      case " $subdirs_with_configure_ac " in
3684        *" $d "*) ;;
3685        *) func_append makefiles " $d/Makefile" ;;
3686      esac
3687    done
3688    echo "AC_OUTPUT([$makefiles])"
3689   ) > "$testdir/configure.ac"
3690
3691   # Create autogenerated files.
3692   (cd "$testdir"
3693    # Do not use "${AUTORECONF} --force --install", because it may invoke
3694    # autopoint, which brings in older versions of some of our .m4 files.
3695    if test -f $m4base/gettext.m4; then
3696      func_execute_command ${AUTOPOINT} --force || func_exit 1
3697      for f in $m4base/*.m4~; do
3698        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3699      done
3700    fi
3701    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
3702    if ! test -d build-aux; then
3703      func_execute_command mkdir build-aux || func_exit 1
3704    fi
3705    func_execute_command ${AUTOCONF} || func_exit 1
3706    func_execute_command ${AUTOHEADER} || func_exit 1
3707    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3708   ) || func_exit 1
3709   if test -n "$inctests"; then
3710     # Create autogenerated files.
3711     (cd "$testdir/$testsbase" || func_exit 1
3712      # Do not use "${AUTORECONF} --force --install", because it may invoke
3713      # autopoint, which brings in older versions of some of our .m4 files.
3714      if test -f ../$m4base/gettext.m4; then
3715        func_execute_command ${AUTOPOINT} --force || func_exit 1
3716        for f in ../$m4base/*.m4~; do
3717          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3718        done
3719      fi
3720      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
3721      if ! test -d ../build-aux; then
3722        func_execute_command mkdir ../build-aux
3723      fi
3724      func_execute_command ${AUTOCONF} || func_exit 1
3725      func_execute_command ${AUTOHEADER} || func_exit 1
3726      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3727     ) || func_exit 1
3728   fi
3729   # Need to run configure and make once, to create built files that are to be
3730   # distributed (such as getdate.c).
3731   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3732   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3733                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3734   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3735   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3736   # such $(FOO_H) because they don't refer to distributed files.
3737   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3738   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3739                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3740                  | sed -e "$sed_remove_make_variables"`
3741   distributed_built_sources=`for file in $built_sources; do
3742                                case "$cleaned_files" in
3743                                  *" "$file" "*) ;;
3744                                  *) echo $file ;;
3745                                esac;
3746                              done`
3747   if test -n "$distributed_built_sources"; then
3748     (cd "$testdir"
3749      ./configure || func_exit 1
3750        cd "$sourcebase"
3751        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3752        make built_sources || func_exit 1
3753        cd ..
3754      make distclean || func_exit 1
3755     ) || func_exit 1
3756   fi
3757 }
3758
3759 # func_create_megatestdir megatestdir allmodules
3760 # Input:
3761 # - local_gnulib_dir  from --local-dir
3762 # - auxdir          directory relative to destdir where to place build aux files
3763 func_create_megatestdir ()
3764 {
3765   megatestdir="$1"
3766   allmodules="$2"
3767   if test -z "$allmodules"; then
3768     allmodules=`func_all_modules`
3769   fi
3770
3771   megasubdirs=
3772   # First, all modules one by one.
3773   for onemodule in $allmodules; do
3774     func_create_testdir "$megatestdir/$onemodule" $onemodule
3775     func_append megasubdirs "$onemodule "
3776   done
3777   # Then, all modules all together.
3778   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3779   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3780   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3781   func_create_testdir "$megatestdir/ALL" "$allmodules"
3782   func_append megasubdirs "ALL"
3783
3784   # Create autobuild.
3785   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
3786              vc_witness="$gnulib_dir/CVS/Entries"; \
3787            else \
3788              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
3789            fi; \
3790            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
3791              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3792                    -e 's,February,02,'  -e 's,Feb,02,' \
3793                    -e 's,March,03,'     -e 's,Mar,03,' \
3794                    -e 's,April,04,'     -e 's,Apr,04,' \
3795                    -e 's,May,05,'                      \
3796                    -e 's,June,06,'      -e 's,Jun,06,' \
3797                    -e 's,July,07,'      -e 's,Jul,07,' \
3798                    -e 's,August,08,'    -e 's,Aug,08,' \
3799                    -e 's,September,09,' -e 's,Sep,09,' \
3800                    -e 's,October,10,'   -e 's,Oct,10,' \
3801                    -e 's,November,11,'  -e 's,Nov,11,' \
3802                    -e 's,December,12,'  -e 's,Dec,12,' \
3803                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3804                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3805   (echo '#!/bin/sh'
3806    echo "CVSDATE=$cvsdate"
3807    echo "test -d logs || mkdir logs"
3808    echo "for module in $megasubdirs; do"
3809    echo "  echo \"Working on module \$module...\""
3810    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3811    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3812    echo "   echo"
3813    echo "   set -x"
3814    echo "   : autobuild project... \$module"
3815    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3816    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3817    echo "   : autobuild hostname... \`hostname\`"
3818    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3819    echo "   echo rc=\$?"
3820    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3821    echo "done"
3822   ) > "$megatestdir/do-autobuild"
3823   chmod a+x "$megatestdir/do-autobuild"
3824
3825   # Create Makefile.am.
3826   (echo "## Process this file with automake to produce Makefile.in."
3827    echo
3828    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3829    echo
3830    echo "SUBDIRS = $megasubdirs"
3831    echo
3832    echo "EXTRA_DIST = do-autobuild"
3833   ) > "$megatestdir/Makefile.am"
3834
3835   # Create configure.ac.
3836   (echo "# Process this file with autoconf to produce a configure script."
3837    echo "AC_INIT([dummy], [0])"
3838    if test "$auxdir" != "."; then
3839      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3840    fi
3841    echo "AM_INIT_AUTOMAKE"
3842    echo
3843    echo "AC_PROG_MAKE_SET"
3844    echo
3845    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
3846    echo "AC_OUTPUT([Makefile])"
3847   ) > "$megatestdir/configure.ac"
3848
3849   # Create autogenerated files.
3850   (cd "$megatestdir"
3851    # Do not use "${AUTORECONF} --install", because autoreconf operates
3852    # recursively, but the subdirectories are already finished, therefore
3853    # calling autoreconf here would only waste lots of CPU time.
3854    func_execute_command ${ACLOCAL} || func_exit 1
3855    func_execute_command mkdir build-aux
3856    func_execute_command ${AUTOCONF} || func_exit 1
3857    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3858   ) || func_exit 1
3859 }
3860
3861 case $mode in
3862   "" )
3863     func_fatal_error "no mode specified" ;;
3864
3865   list )
3866     func_all_modules
3867     ;;
3868
3869   import | update )
3870
3871     # Where to import.
3872     if test -z "$destdir"; then
3873       destdir=.
3874     fi
3875     test -d "$destdir" \
3876       || func_fatal_error "destination directory does not exist: $destdir"
3877
3878     # Prefer configure.ac to configure.in.
3879     if test -f "$destdir"/configure.ac; then
3880       configure_ac="$destdir/configure.ac"
3881     else
3882       if test -f "$destdir"/configure.in; then
3883         configure_ac="$destdir/configure.in"
3884       else
3885         func_fatal_error "cannot find $destdir/configure.ac"
3886       fi
3887     fi
3888
3889     # Analyze configure.ac.
3890     guessed_auxdir="."
3891     guessed_libtool=false
3892     my_sed_traces='
3893       s,#.*$,,
3894       s,^dnl .*$,,
3895       s, dnl .*$,,
3896       /AC_CONFIG_AUX_DIR/ {
3897         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
3898       }
3899       /A[CM]_PROG_LIBTOOL/ {
3900         s,^.*$,guessed_libtool=true,p
3901       }'
3902     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
3903
3904     if test -z "$auxdir"; then
3905       auxdir="$guessed_auxdir"
3906     fi
3907
3908     # Determine where to apply func_import.
3909     if test -n "$m4base"; then
3910       # Apply func_import to a particular gnulib directory.
3911       # Any number of additional modules can be given.
3912       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
3913         # First use of gnulib in the given m4base.
3914         test -n "$supplied_libname" || supplied_libname=true
3915         test -n "$sourcebase" || sourcebase="lib"
3916         test -n "$docbase" || docbase="doc"
3917         test -n "$testsbase" || testsbase="tests"
3918         test -n "$macro_prefix" || macro_prefix="gl"
3919       fi
3920       func_import "$*"
3921     else
3922       # Apply func_import to all gnulib directories.
3923       # To get this list of directories, look at Makefile.am. (Not at
3924       # configure, because it may be omitted from CVS. Also, don't run
3925       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
3926       m4dirs=
3927       m4dirs_count=0
3928       if test -f "$destdir"/Makefile.am; then
3929         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
3930         m4dir_is_next=
3931         for arg in $aclocal_amflags; do
3932           if test -n "$m4dir_is_next"; then
3933             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
3934             case "$arg" in
3935               /*) ;;
3936               *)
3937                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
3938                   func_append m4dirs " $arg"
3939                   m4dirs_count=`expr $m4dirs_count + 1`
3940                 fi
3941                 ;;
3942             esac
3943             m4dir_is_next=
3944           else
3945             if test "X$arg" = "X-I"; then
3946               m4dir_is_next=yes
3947             else
3948               m4dir_is_next=
3949             fi
3950           fi
3951         done
3952       else
3953         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
3954         if test -f "$destdir"/aclocal.m4; then
3955           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
3956           sedexpr2='s,^[^/]*$,.,'
3957           sedexpr3='s,/[^/]*$,,'
3958           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
3959           m4dirs_count=`echo "$m4dirs" | wc -l`
3960         fi
3961       fi
3962       if test $m4dirs_count = 0; then
3963         # First use of gnulib in a package.
3964         # Any number of additional modules can be given.
3965         test -n "$supplied_libname" || supplied_libname=true
3966         test -n "$sourcebase" || sourcebase="lib"
3967         m4base="m4"
3968         test -n "$docbase" || docbase="doc"
3969         test -n "$testsbase" || testsbase="tests"
3970         test -n "$macro_prefix" || macro_prefix="gl"
3971         func_import "$*"
3972       else
3973         if test $m4dirs_count = 1; then
3974           # There's only one use of gnulib here. Assume the user means it.
3975           # Any number of additional modules can be given.
3976           for m4base in $m4dirs; do
3977             func_import "$*"
3978           done
3979         else
3980           # Ambiguous - guess what the user meant.
3981           if test $# = 0; then
3982             # No further arguments. Guess the user wants to update all of them.
3983             for m4base in $m4dirs; do
3984               # Perform func_import in a subshell, so that variable values
3985               # such as
3986               #   local_gnulib_dir, avoidlist, sourcebase, m4base, pobase,
3987               #   docbase, testsbase, inctests, libname, lgpl, makefile_name,
3988               #   libtool, macro_prefix, po_domain
3989               # don't propagate from one directory to another.
3990               (func_import) || func_exit 1
3991             done
3992           else
3993             # Really ambiguous.
3994             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
3995           fi
3996         fi
3997       fi
3998     fi
3999     ;;
4000
4001   create-testdir )
4002     if test -z "$destdir"; then
4003       func_fatal_error "please specify --dir option"
4004     fi
4005     mkdir "$destdir"
4006     test -d "$destdir" \
4007       || func_fatal_error "could not create destination directory"
4008     test -n "$auxdir" || auxdir="build-aux"
4009     func_create_testdir "$destdir" "$*"
4010     ;;
4011
4012   create-megatestdir )
4013     if test -z "$destdir"; then
4014       func_fatal_error "please specify --dir option"
4015     fi
4016     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4017     test -n "$auxdir" || auxdir="build-aux"
4018     func_create_megatestdir "$destdir" "$*"
4019     ;;
4020
4021   test )
4022     test -n "$destdir" || destdir=testdir$$
4023     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4024     test -n "$auxdir" || auxdir="build-aux"
4025     func_create_testdir "$destdir" "$*"
4026     cd "$destdir"
4027       mkdir build
4028       cd build
4029         ../configure || func_exit 1
4030         make || func_exit 1
4031         make check || func_exit 1
4032         make distclean || func_exit 1
4033         remaining=`find . -type f -print`
4034         if test -n "$remaining"; then
4035           echo "Remaining files:" $remaining 1>&2
4036           echo "gnulib-tool: *** Stop." 1>&2
4037           func_exit 1
4038         fi
4039       cd ..
4040     cd ..
4041     rm -rf "$destdir"
4042     ;;
4043
4044   megatest )
4045     test -n "$destdir" || destdir=testdir$$
4046     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4047     test -n "$auxdir" || auxdir="build-aux"
4048     func_create_megatestdir "$destdir" "$*"
4049     cd "$destdir"
4050       mkdir build
4051       cd build
4052         ../configure
4053         make
4054         make check
4055         make distclean
4056         remaining=`find . -type f -print`
4057         if test -n "$remaining"; then
4058           echo "Remaining files:" $remaining 1>&2
4059           echo "gnulib-tool: *** Stop." 1>&2
4060           func_exit 1
4061         fi
4062       cd ..
4063     cd ..
4064     rm -rf "$destdir"
4065     ;;
4066
4067   extract-description )
4068     for module
4069     do
4070       func_verify_module
4071       if test -n "$module"; then
4072         func_get_description "$module"
4073       fi
4074     done
4075     ;;
4076
4077   extract-notice )
4078     for module
4079     do
4080       func_verify_module
4081       if test -n "$module"; then
4082         func_get_notice "$module"
4083       fi
4084     done
4085     ;;
4086
4087   extract-filelist )
4088     for module
4089     do
4090       func_verify_module
4091       if test -n "$module"; then
4092         func_get_filelist "$module"
4093       fi
4094     done
4095     ;;
4096
4097   extract-dependencies )
4098     for module
4099     do
4100       func_verify_module
4101       if test -n "$module"; then
4102         func_get_dependencies "$module"
4103       fi
4104     done
4105     ;;
4106
4107   extract-autoconf-snippet )
4108     for module
4109     do
4110       func_verify_module
4111       if test -n "$module"; then
4112         func_get_autoconf_snippet "$module"
4113       fi
4114     done
4115     ;;
4116
4117   extract-automake-snippet )
4118     for module
4119     do
4120       func_verify_module
4121       if test -n "$module"; then
4122         func_get_automake_snippet "$module"
4123       fi
4124     done
4125     ;;
4126
4127   extract-include-directive )
4128     for module
4129     do
4130       func_verify_module
4131       if test -n "$module"; then
4132         func_get_include_directive "$module"
4133       fi
4134     done
4135     ;;
4136
4137   extract-link-directive )
4138     for module
4139     do
4140       func_verify_module
4141       if test -n "$module"; then
4142         func_get_link_directive "$module"
4143       fi
4144     done
4145     ;;
4146
4147   extract-license )
4148     for module
4149     do
4150       func_verify_module
4151       if test -n "$module"; then
4152         func_get_license "$module"
4153       fi
4154     done
4155     ;;
4156
4157   extract-maintainer )
4158     for module
4159     do
4160       func_verify_module
4161       if test -n "$module"; then
4162         func_get_maintainer "$module"
4163       fi
4164     done
4165     ;;
4166
4167   extract-tests-module )
4168     for module
4169     do
4170       func_verify_module
4171       if test -n "$module"; then
4172         func_get_tests_module "$module"
4173       fi
4174     done
4175     ;;
4176
4177   * )
4178     func_fatal_error "unknown operation mode --$mode" ;;
4179 esac
4180
4181 rm -rf "$tmp"
4182 # Undo the effect of the previous 'trap' command. Some shellology:
4183 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
4184 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
4185 # exit); for the others we need to call 'exit' explicitly. The value of $? is
4186 # 128 + signal number and is set before the trap-registered command is run.
4187 trap '' 0
4188 trap 'func_exit $?' 1 2 3 13 15
4189
4190 exit 0
4191
4192 # Local Variables:
4193 # indent-tabs-mode: nil
4194 # whitespace-check-buffer-indent: nil
4195 # End: