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