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