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