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