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