Replace build-aux when it occurs in the autoconf snippet.
[gnulib.git] / 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
17 # Foundation, 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-01-11 12:24:28 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
28
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
30 AUTOCONFPATH=
31 #case $USER in
32 #  bruno )
33 #    AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34 #    AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
35 #    ;;
36 #esac
37
38 AUTORECONF="${AUTOCONFPATH}autoreconf"
39
40 # func_usage
41 # outputs to stdout the --help usage message.
42 func_usage ()
43 {
44   echo "\
45 Usage: gnulib-tool --list
46        gnulib-tool --import [module1 ... moduleN]
47        gnulib-tool --update
48        gnulib-tool --create-testdir --dir=directory module1 ... moduleN
49        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
50        gnulib-tool --test --dir=directory module1 ... moduleN
51        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
52        gnulib-tool --extract-description module
53        gnulib-tool --extract-filelist module
54        gnulib-tool --extract-dependencies module
55        gnulib-tool --extract-autoconf-snippet module
56        gnulib-tool --extract-automake-snippet module
57        gnulib-tool --extract-include-directive module
58        gnulib-tool --extract-license module
59        gnulib-tool --extract-maintainer module
60        gnulib-tool --extract-tests-module module
61
62 Operation modes:
63       --list                print the available module names
64       --import              import the given modules into the current package
65       --create-testdir      create a scratch package with the given modules
66       --create-megatestdir  create a mega scratch package with the given modules
67                             one by one and all together
68       --test                test the combination of the given modules
69                             (recommended to use CC=\"gcc -Wall\" here)
70       --megatest            test the given modules one by one and all together
71                             (recommended to use CC=\"gcc -Wall\" here)
72       --extract-description        extract the description
73       --extract-filelist           extract the list of files
74       --extract-dependencies       extract the dependencies
75       --extract-autoconf-snippet   extract the snippet for configure.ac
76       --extract-automake-snippet   extract the snippet for lib/Makefile.am
77       --extract-include-directive  extract the #include directive
78       --extract-license            report the license terms of the source files
79                                    under lib/
80       --extract-maintainer         report the maintainer(s) inside gnulib
81       --extract-tests-module       report the unit test module, if it exists
82
83 Options:
84       --dir=DIRECTORY       specify the target directory
85                             For --import, this specifies where your
86                             configure.ac can be found.  Defaults to current
87                             directory.
88       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
89       --source-base=DIRECTORY
90                             Directory relative --dir where source code is
91                             placed (default \"lib\"), for --import.
92       --m4-base=DIRECTORY   Directory relative --dir where *.m4 macros are
93                             placed (default \"m4\"), for --import.
94       --tests-base=DIRECTORY
95                             Directory relative --dir where unit tests are
96                             placed (default \"tests\"), for --import.
97       --aux-dir=DIRECTORY   Directory relative --dir where auxiliary build
98                             tools are placed (default \"build-aux\").
99       --with-tests          Include unit tests for the included modules.
100       --avoid=MODULE        Avoid including the given MODULE. Useful if you
101                             have code that provides equivalent functionality.
102                             This option can be repeated.
103       --lgpl                Abort if modules aren't available under the LGPL.
104                             Also modify license template from GPL to LGPL.
105       --libtool             Use libtool rules, for --import.
106       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
107                             'gl_INIT'. Default is 'gl'.
108       --no-changelog        don't update or create ChangeLog files
109       --dry-run             For --import, only print what would have been done.
110   -s, --symbolic, --symlink Make symbolic links instead of copying files.
111
112 Report bugs to <bug-gnulib@gnu.org>."
113 }
114
115 # func_version
116 # outputs to stdout the --version message.
117 func_version ()
118 {
119   echo "$progname (GNU $package) $version"
120   echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
121 This is free software; see the source for copying conditions.  There is NO
122 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
123   echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
124 }
125
126 # func_tmpdir
127 # creates a temporary directory.
128 # Sets variable
129 # - tmp             pathname of freshly created temporary directory
130 func_tmpdir ()
131 {
132   # Use the environment variable TMPDIR, falling back to /tmp. This allows
133   # users to specify a different temporary directory, for example, if their
134   # /tmp is filled up or too small.
135   : ${TMPDIR=/tmp}
136   {
137     # Use the mktemp program if available. If not available, hide the error
138     # message.
139     tmp=`(umask 077 && mktemp -d -q "$TMPDIR/glXXXXXX") 2>/dev/null` &&
140     test -n "$tmp" && test -d "$tmp"
141   } ||
142   {
143     # Use a simple mkdir command. It is guaranteed to fail if the directory
144     # already exists.  $RANDOM is bash specific and expands to empty in shells
145     # other than bash, ksh and zsh.  Its use does not increase security;
146     # rather, it minimizes the probability of failure in a very cluttered /tmp
147     # directory.
148     tmp=$TMPDIR/gl$$-$RANDOM
149     (umask 077 && mkdir "$tmp")
150   } ||
151   {
152     echo "$0: cannot create a temporary directory in $TMPDIR" >&2
153     { (exit 1); exit 1; }
154   }
155 }
156
157 # func_fatal_error message
158 # outputs to stderr a fatal error message, and terminates the program.
159 func_fatal_error ()
160 {
161   echo "gnulib-tool: *** $1" 1>&2
162   echo "gnulib-tool: *** Stop." 1>&2
163   exit 1
164 }
165
166 # func_readlink SYMLINK
167 # outputs the target of the given symlink.
168 if (type -p readlink) > /dev/null 2>&1; then
169   func_readlink ()
170   {
171     # Use the readlink program from GNU coreutils.
172     readlink "$1"
173   }
174 else
175   func_readlink ()
176   {
177     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
178     # would do the wrong thing if the link target contains " -> ".
179     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
180   }
181 fi
182
183 # func_ln_if_changed SRC DEST
184 # Like ln -s, but avoids munging timestamps if the link is correct.
185 func_ln_if_changed ()
186 {
187   if test $# -ne 2; then
188     echo "usage: func_ln_if_changed SRC DEST" >&2
189   fi
190   if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
191     :
192   else
193     rm -f "$2"
194     ln -s "$1" "$2"
195   fi
196 }
197
198 # Command-line option processing.
199 # Removes the OPTIONS from the arguments. Sets the variables:
200 # - mode            list or import or create-testdir or create-megatestdir
201 # - destdir         from --dir
202 # - libname, supplied_libname  from --lib
203 # - sourcebase      from --source-base
204 # - m4base          from --m4-base
205 # - testsbase       from --tests-base
206 # - auxdir          from --aux-dir
207 # - inctests        true if --with-tests was given, blank otherwise
208 # - avoidlist       list of modules to avoid, from --avoid
209 # - lgpl            true if --lgpl was given, blank otherwise
210 # - libtool         true if --libtool was given, blank otherwise
211 # - do_changelog    false if --no-changelog was given, : otherwise
212 # - doit            : if actions shall be executed, false if only to be printed
213 {
214   mode=
215   destdir=
216   libname=libgnu
217   supplied_libname=
218   sourcebase=
219   m4base=
220   testsbase=
221   auxdir=
222   inctests=
223   avoidlist=
224   lgpl=
225   libtool=
226   macro_prefix=
227   do_changelog=:
228   doit=:
229   symbolic=
230
231   supplied_opts="$@"
232
233   while test $# -gt 0; do
234     case "$1" in
235       --list | --lis )
236         mode=list
237         shift ;;
238       --import | --impor | --impo | --imp | --im | --i )
239         mode=import
240         shift ;;
241       --update | --updat | --upda | --upd | --up | --u )
242         mode=update
243         shift ;;
244       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
245         mode=create-testdir
246         shift ;;
247       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
248         mode=create-megatestdir
249         shift ;;
250       --test | --tes | --te | --t )
251         mode=test
252         shift ;;
253       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
254         mode=megatest
255         shift ;;
256       --extract-* )
257         mode=`echo "X$1" | sed -e 's/^X--//'`
258         shift ;;
259       --dir )
260         shift
261         if test $# = 0; then
262           func_fatal_error "missing argument for --dir"
263         fi
264         destdir=$1
265         shift ;;
266       --dir=* )
267         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
268         shift ;;
269       --lib )
270         shift
271         if test $# = 0; then
272           func_fatal_error "missing argument for --lib"
273         fi
274         libname=$1
275         supplied_libname=true
276         shift ;;
277       --lib=* )
278         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
279         supplied_libname=true
280         shift ;;
281       --source-base )
282         shift
283         if test $# = 0; then
284           func_fatal_error "missing argument for --source-base"
285         fi
286         sourcebase=$1
287         shift ;;
288       --source-base=* )
289         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
290         shift ;;
291       --m4-base )
292         shift
293         if test $# = 0; then
294           func_fatal_error "missing argument for --m4-base"
295         fi
296         m4base=$1
297         shift ;;
298       --m4-base=* )
299         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
300         shift ;;
301       --tests-base )
302         shift
303         if test $# = 0; then
304           func_fatal_error "missing argument for --tests-base"
305         fi
306         testsbase=$1
307         shift ;;
308       --tests-base=* )
309         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
310         shift ;;
311       --aux-dir )
312         shift
313         if test $# = 0; then
314           func_fatal_error "missing argument for --aux-dir"
315         fi
316         auxdir=$1
317         shift ;;
318       --aux-dir=* )
319         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
320         shift ;;
321       --with-tests )
322         inctests=true
323         shift ;;
324       --avoid )
325         shift
326         if test $# = 0; then
327           func_fatal_error "missing argument for --avoid"
328         fi
329         avoidlist="$avoidlist $1"
330         shift ;;
331       --avoid=* )
332         avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
333         shift ;;
334       --lgpl )
335         lgpl=true
336         shift ;;
337       --libtool )
338         libtool=true
339         shift ;;
340       --macro-prefix )
341         shift
342         if test $# = 0; then
343           func_fatal_error "missing argument for --macro-prefix"
344         fi
345         macro_prefix="$1"
346         shift ;;
347       --macro-prefix=* )
348         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
349         shift ;;
350       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
351         do_changelog=false
352         shift ;;
353       --dry-run )
354         doit=false
355         shift ;;
356       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
357         symbolic=true
358         shift ;;
359       --help | --hel | --he | --h )
360         func_usage
361         exit 0 ;;
362       --version | --versio | --versi | --vers | --ver | --ve | --v )
363         func_version
364         exit 0 ;;
365       -- )
366         # Stop option processing
367         shift
368         break ;;
369       -* )
370         echo "gnulib-tool: unknown option $1" 1>&2
371         echo "Try 'gnulib-tool --help' for more information." 1>&2
372         exit 1 ;;
373       * )
374         break ;;
375     esac
376   done
377
378   if test "$mode" = update; then
379     if test $# != 0; then
380       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
381       echo "Try 'gnulib-tool --help' for more information." 1>&2
382       echo "If you really want to modify the gnulib configuration of your project," 1>&2
383       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
384       exit 1
385     fi
386     if test -n "$libname" || test -n "$sourcebase" || test -n "$m4base" \
387        || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
388        || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
389       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
390       echo "Try 'gnulib-tool --help' for more information." 1>&2
391       echo "If you really want to modify the gnulib configuration of your project," 1>&2
392       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
393       exit 1
394     fi
395     do_changelog=false
396   fi
397
398   # Remove trailing slashes from the directory names. This is necessary for
399   # m4base (to avoid an error in func_import) and optional for the others.
400   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
401   case "$sourcebase" in
402     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
403   esac
404   case "$m4base" in
405     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
406   esac
407   case "$testsbase" in
408     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
409   esac
410   case "$auxdir" in
411     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
412   esac
413 }
414
415 case "$0" in
416   /*) self_abspathname="$0" ;;
417   */*) self_abspathname=`pwd`/"$0" ;;
418   *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
419        if test -x "$d/$0" && test ! -d "$d/$0"; then
420          self_abspathname="$d/$0"
421          break
422        fi
423      done
424      if test -z "$self_abspathname"; then
425        func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
426      fi
427      ;;
428 esac
429 while test -h "$self_abspathname"; do
430   # Resolve symbolic link.
431   linkval=`func_readlink "$self_abspathname"`
432   test -n "$linkval" || break
433   case "$linkval" in
434     /* ) self_abspathname="$linkval" ;;
435     * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
436   esac
437 done
438 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
439
440 # func_all_modules
441 func_all_modules ()
442 {
443   # Filter out metainformation files like README, which are not modules.
444   # Filter out unit test modules; they can be retrieved through
445   # --extract-tests-module if desired.
446   (cd "$gnulib_dir/modules" && ls -1) \
447       | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
448       | sed -e '/-tests$/d' \
449       | LC_ALL=C sort
450 }
451
452 # func_verify_module
453 # verifies a module name
454 func_verify_module ()
455 {
456   if test ! -f "$gnulib_dir/modules/$module" \
457      || test "CVS" = "$module" \
458      || test "ChangeLog" = "$module" \
459      || test "README" = "$module" \
460      || test "TEMPLATE" = "$module" \
461      || test "TEMPLATE-TESTS" = "$module"; then
462     echo "gnulib-tool: module $module doesn't exist" 1>&2
463     module=
464   fi
465 }
466
467 # func_verify_nontests_module
468 # verifies a module name, excluding tests modules
469 func_verify_nontests_module ()
470 {
471   case "$module" in
472     *-tests ) module= ;;
473     * ) func_verify_module ;;
474   esac
475 }
476
477 # func_verify_tests_module
478 # verifies a module name, considering only tests modules
479 func_verify_tests_module ()
480 {
481   case "$module" in
482     *-tests ) func_verify_module ;;
483     * ) module= ;;
484   esac
485 }
486
487 sed_extract_prog=':[    ]*$/ {
488   :a
489     n
490     s/^Description:[    ]*$//
491     s/^Files:[  ]*$//
492     s/^Depends-on:[     ]*$//
493     s/^configure\.ac:[  ]*$//
494     s/^Makefile\.am:[   ]*$//
495     s/^Include:[        ]*$//
496     s/^License:[        ]*$//
497     s/^Maintainer:[     ]*$//
498     tb
499     p
500     ba
501   :b
502 }'
503
504 # func_get_description module
505 func_get_description ()
506 {
507   sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
508 }
509
510 # func_get_filelist module
511 func_get_filelist ()
512 {
513   sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
514   #echo m4/onceonly.m4
515   echo m4/onceonly_2_57.m4
516 }
517
518 # func_get_dependencies module
519 func_get_dependencies ()
520 {
521   # ${module}-tests always implicitly depends on ${module}.
522   echo "$1" | sed -n -e 's/-tests//p'
523   # Then the explicit dependencies listed in the module description.
524   sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
525 }
526
527 # func_get_autoconf_snippet module
528 func_get_autoconf_snippet ()
529 {
530   sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
531 }
532
533 # func_get_automake_snippet module
534 func_get_automake_snippet ()
535 {
536   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
537 }
538
539 # func_get_include_directive module
540 func_get_include_directive ()
541 {
542   sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
543   sed -e 's/^\(["<]\)/#include \1/'
544 }
545
546 # func_get_license module
547 func_get_license ()
548 {
549   sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
550 }
551
552 # func_get_maintainer module
553 func_get_maintainer ()
554 {
555   sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
556 }
557
558 # func_get_tests_module module
559 func_get_tests_module ()
560 {
561   # The naming convention for tests modules is hardwired: ${module}-tests.
562   if test -f modules/"$1"-tests; then
563     echo "$1"-tests
564   fi
565 }
566
567 # func_acceptable module
568 # tests whether a module is acceptable.
569 # Input:
570 # - avoidlist       list of modules to avoid
571 func_acceptable ()
572 {
573   for avoid in $avoidlist; do
574     if test "$avoid" = "$1"; then
575       return 1
576     fi
577   done
578   return 0
579 }
580
581 # func_modules_transitive_closure
582 # Input:
583 # - modules         list of specified modules
584 # - inctests        true if tests should be included, blank otherwise
585 # - avoidlist       list of modules to avoid
586 # Output:
587 # - modules         list of modules, including dependencies
588 func_modules_transitive_closure ()
589 {
590   while true; do
591     xmodules=
592     for module in $modules; do
593       func_verify_module
594       if test -n "$module"; then
595         # Duplicate dependencies are harmless, but Jim wants a warning.
596         duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
597         if test -n "$duplicated_deps"; then
598           echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
599         fi
600         if func_acceptable $module; then
601           xmodules="$xmodules $module"
602           for depmodule in `func_get_dependencies $module`; do
603             if func_acceptable $depmodule; then
604               xmodules="$xmodules $depmodule"
605             fi
606           done
607           if test -n "$inctests"; then
608             testsmodule=`func_get_tests_module $module`
609             if test -n "$testsmodule"; then
610               if func_acceptable $testsmodule; then
611                 xmodules="$xmodules $testsmodule"
612                 for depmodule in `func_get_dependencies $testsmodule`; do
613                   if func_acceptable $depmodule; then
614                     xmodules="$xmodules $depmodule"
615                   fi
616                 done
617               fi
618             fi
619           fi
620         fi
621       fi
622     done
623     xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
624     if test "$xmodules" = "$modules"; then
625       break
626     fi
627     modules="$xmodules"
628   done
629 }
630
631 # func_modules_to_filelist
632 # Input:
633 # - modules         list of modules, including dependencies
634 # Output:
635 # - files           list of files
636 func_modules_to_filelist ()
637 {
638   files=
639   for module in $modules; do
640     func_verify_module
641     if test -n "$module"; then
642       files="$files "`func_get_filelist $module`
643     fi
644   done
645   files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
646 }
647
648 # func_emit_lib_Makefile_am
649 # emits the contents of lib/Makefile.am to standard output.
650 # Input:
651 # - modules         list of modules, including dependencies
652 # - libname         library name
653 # - libtool         true if libtool will be used, blank otherwise
654 # - actioncmd       (optional) command that will reproduce this invocation
655 func_emit_lib_Makefile_am ()
656 {
657   if test -n "$libtool"; then
658     libext=la
659     perhapsLT=LT
660   else
661     libext=a
662     perhapsLT=
663   fi
664   echo "## Process this file with automake to produce Makefile.in."
665   echo "# Copyright (C) 2004 Free Software Foundation, Inc."
666   echo "#"
667   echo "# This file is free software, distributed under the terms of the GNU"
668   echo "# General Public License.  As a special exception to the GNU General"
669   echo "# Public License, this file may be distributed as part of a program"
670   echo "# that contains a configuration script generated by Automake, under"
671   echo "# the same distribution terms as the rest of that program."
672   echo "#"
673   echo "# Generated by gnulib-tool."
674   if test -n "$actioncmd"; then
675     echo "# Reproduce by: $actioncmd"
676   fi
677   echo
678   # No need to generate dependencies since the sources are in gnulib, not here.
679   echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
680   echo
681   echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
682   echo
683   echo "${libname}_${libext}_SOURCES ="
684   echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
685   echo "EXTRA_DIST ="
686   echo "BUILT_SOURCES ="
687   echo "SUFFIXES ="
688   echo "MOSTLYCLEANFILES ="
689   echo "CLEANFILES ="
690   echo "DISTCLEANFILES ="
691   echo "MAINTAINERCLEANFILES ="
692   echo
693   for module in $modules; do
694     func_verify_nontests_module
695     if test -n "$module"; then
696       {
697         func_get_automake_snippet "$module" |
698           sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
699         if test "$module" = 'alloca'; then
700           echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
701         fi
702       } > amsnippet.tmp
703       # Skip the contents if its entirely empty.
704       if grep '[^       ]' amsnippet.tmp > /dev/null ; then
705         echo "## begin gnulib module $module"
706         echo
707         cat amsnippet.tmp
708         echo "## end   gnulib module $module"
709         echo
710       fi
711       rm -f amsnippet.tmp
712     fi
713   done
714   echo
715   echo "# Makefile.am ends here"
716 }
717
718 # func_emit_tests_Makefile_am
719 # emits the contents of tests/Makefile.am to standard output.
720 # Input:
721 # - modules         list of modules, including dependencies
722 # - libname         library name
723 # - libtool         true if libtool will be used, blank otherwise
724 # - sourcebase      relative directory containing lib source code
725 # - m4base          relative directory containing autoconf macros
726 # - testsbase       relative directory containing unit test code
727 func_emit_tests_Makefile_am ()
728 {
729   if test -n "$libtool"; then
730     libext=la
731   else
732     libext=a
733   fi
734   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
735   echo "## Process this file with automake to produce Makefile.in."
736   echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
737   echo "#"
738   echo "# This file is free software, distributed under the terms of the GNU"
739   echo "# General Public License.  As a special exception to the GNU General"
740   echo "# Public License, this file may be distributed as part of a program"
741   echo "# that contains a configuration script generated by Automake, under"
742   echo "# the same distribution terms as the rest of that program."
743   echo "#"
744   echo "# Generated by gnulib-tool."
745   echo
746   # Generate dependencies here, since it eases the debugging of test failures.
747   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
748   echo
749   echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
750   echo
751   # Nothing is being added to SUBDIRS; nevertheless the existence of this
752   # variable is needed to avoid an error from automake:
753   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
754   echo "SUBDIRS ="
755   echo "TESTS ="
756   echo "TESTS_ENVIRONMENT ="
757   echo "noinst_PROGRAMS ="
758   echo "EXTRA_DIST ="
759   echo "BUILT_SOURCES ="
760   echo "SUFFIXES ="
761   echo "MOSTLYCLEANFILES ="
762   echo "CLEANFILES ="
763   echo "DISTCLEANFILES ="
764   echo "MAINTAINERCLEANFILES ="
765   echo
766   echo "AM_CPPFLAGS = \\"
767   echo "  -I. -I\$(srcdir) \\"
768   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
769   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
770   echo
771   echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
772   echo
773   for module in $modules; do
774     func_verify_tests_module
775     if test -n "$module"; then
776       func_get_automake_snippet "$module" > amsnippet.tmp
777       # Skip the contents if its entirely empty.
778       if grep '[^       ]' amsnippet.tmp > /dev/null ; then
779         echo "## begin gnulib module $module"
780         echo
781         cat amsnippet.tmp
782         echo "## end   gnulib module $module"
783         echo
784       fi
785       rm -f amsnippet.tmp
786     fi
787   done
788   echo "# Clean up after Solaris cc."
789   echo "clean-local:"
790   echo "        rm -rf SunWS_cache"
791   echo
792   echo "# Makefile.am ends here"
793 }
794
795 # func_import modules
796 # Uses also the variables
797 # - destdir         target directory
798 # - libname         library name
799 # - sourcebase      directory relative to destdir where to place source code
800 # - m4base          directory relative to destdir where to place *.m4 macros
801 # - testsbase       directory relative to destdir where to place unit test code
802 # - auxdir          directory relative to destdir where to place build aux files
803 # - inctests        true if --with-tests was given, blank otherwise
804 # - avoidlist       list of modules to avoid, from --avoid
805 # - lgpl            true if library's license shall be LGPL, blank otherwise
806 # - libtool         true if libtool will be used, blank otherwise
807 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
808 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
809 # - doit            : if actions shall be executed, false if only to be printed
810 # - symbolic        true if files should be symlinked, copied otherwise
811 func_import ()
812 {
813   # Get the cached settings.
814   cached_specified_modules=
815   cached_avoidlist=
816   cached_sourcebase=
817   cached_m4base=
818   cached_testsbase=
819   cached_libname=
820   cached_lgpl=
821   cached_libtool=
822   cached_macro_prefix=
823   cached_files=
824   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
825     my_sed_traces='
826       s,#.*$,,
827       s,^dnl .*$,,
828       s, dnl .*$,,
829       /gl_MODULES(/ {
830         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
831       }
832       /gl_AVOID(/ {
833         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
834       }
835       /gl_SOURCE_BASE(/ {
836         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
837       }
838       /gl_M4_BASE(/ {
839         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
840       }
841       /gl_TESTS_BASE(/ {
842         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
843       }
844       /gl_LIB(/ {
845         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
846       }
847       /gl_LGPL/ {
848         s,^.*$,cached_lgpl=true,p
849       }
850       /gl_LIBTOOL/ {
851         s,^.*$,cached_libtool=true,p
852       }
853       /gl_MACRO_PREFIX(/ {
854         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
855       }'
856     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
857     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
858       my_sed_traces='
859         s,#.*$,,
860         s,^dnl .*$,,
861         s, dnl .*$,,
862         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
863           s,^.*$,cached_files=",p
864           n
865           ta
866           :a
867           s,^\]).*$,",
868           tb
869           p
870           n
871           ba
872           :b
873           p
874         }'
875       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
876     fi
877   fi
878
879   # Merge the cached settings with the specified ones.
880   # The m4base must be the same as expected from the pathname.
881   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
882     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
883   fi
884   # Append the cached and the specified module names. So that
885   # "gnulib-tool --import foo" means to add the module foo.
886   specified_modules="$cached_specified_modules $1"
887   # Append the cached and the specified avoidlist. This is probably better
888   # than dropping the cached one when --avoid is specified at least once.
889   avoidlist=`echo $cached_avoidlist $avoidlist`
890   # The sourcebase defaults to the cached one.
891   if test -z "$sourcebase"; then
892     sourcebase="$cached_sourcebase"
893     if test -z "$sourcebase"; then
894       func_fatal_error "missing --source-base option"
895     fi
896   fi
897   # The testsbase defaults to the cached one.
898   if test -z "$testsbase"; then
899     testsbase="$cached_testsbase"
900     if test -z "$testsbase"; then
901       func_fatal_error "missing --tests-base option"
902     fi
903   fi
904   # The libname defaults to the cached one.
905   if test -z "$supplied_libname"; then
906     libname="$cached_libname"
907     if test -z "$libname"; then
908       func_fatal_error "missing --lib option"
909     fi
910   fi
911   # Require LGPL if specified either way.
912   if test -z "$lgpl"; then
913     lgpl="$cached_lgpl"
914   fi
915   # Use libtool if specified either way, or if guessed.
916   if test -z "$libtool"; then
917     if test -n "$cached_m4base"; then
918       libtool="$cached_libtool"
919     else
920       libtool="$guessed_libtool"
921     fi
922   fi
923   # The macro_prefix defaults to the cached one.
924   if test -z "$macro_prefix"; then
925     macro_prefix="$cached_macro_prefix"
926     if test -z "$macro_prefix"; then
927       func_fatal_error "missing --macro-prefix option"
928     fi
929   fi
930
931   # Canonicalize the list of specified modules.
932   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
933
934   # Determine final module list.
935   modules="$specified_modules"
936   func_modules_transitive_closure
937   echo "Module list with included dependencies:"
938   echo "$modules" | sed -e 's/^/  /'
939
940   # If --lgpl, check the license of modules are compatible.
941   if test -n "$lgpl"; then
942     for module in $modules; do
943       license=`func_get_license $module`
944       case $license in
945         LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
946         *) func_fatal_error "incompatible license on module $module: $license" ;;
947       esac
948     done
949   fi
950
951   # Determine final file list.
952   func_modules_to_filelist
953   echo "File list:"
954   echo "$files" | sed -e 's/^/  /'
955
956   test -n "$files" \
957     || func_fatal_error "refusing to do nothing"
958
959   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
960   new_files="$files m4/gnulib-tool.m4"
961   old_files="$cached_files"
962   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
963     old_files="$old_files m4/gnulib-tool.m4"
964   fi
965
966   # Create directories.
967   if test ! -d "$destdir/$sourcebase"; then
968     if $doit; then
969       echo "Creating directory $destdir/$sourcebase"
970       mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
971     else
972       echo "Create directory $destdir/$sourcebase"
973     fi
974   fi
975   if test ! -d "$destdir/$m4base"; then
976     if $doit; then
977       echo "Creating directory $destdir/$m4base"
978       mkdir "$destdir/$m4base" || func_fatal_error "failed"
979     else
980       echo "Create directory $destdir/$m4base"
981     fi
982   fi
983   if test -n "$inctests"; then
984     if test ! -d "$destdir/$testsbase"; then
985       if $doit; then
986         echo "Creating directory $destdir/$testsbase"
987         mkdir "$destdir/$testsbase" || func_fatal_error "failed"
988       else
989         echo "Create directory $destdir/$testsbase"
990       fi
991     fi
992   fi
993   if test ! -d "$destdir/$auxdir"; then
994     if $doit; then
995       echo "Creating directory $destdir/$auxdir"
996       mkdir "$destdir/$auxdir" || func_fatal_error "failed"
997     else
998       echo "Create directory $destdir/$auxdir"
999     fi
1000   fi
1001
1002   # Copy files or make symbolic links. Remove obsolete files.
1003   func_tmpdir
1004   trap 'rm -rf "$tmp"' 0 1 2 3 15
1005   delimiter='   '
1006   for f in $old_files; do
1007     case "$f" in
1008       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1009       lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1010       m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1011       tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1012       *) g="$f" ;;
1013     esac
1014     echo "$g""$delimiter""$f"
1015   done | LC_ALL=C sort > "$tmp"/old-files
1016   for f in $new_files; do
1017     case "$f" in
1018       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1019       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1020       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1021       tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1022       *) g="$f" ;;
1023     esac
1024     echo "$g""$delimiter""$f"
1025   done | LC_ALL=C sort > "$tmp"/new-files
1026   # First the files that are in old-files, but not in new-files:
1027   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e 's,'"$delimiter"'.*,,'`; do
1028     # Remove the file. Do nothing if the user already removed it.
1029     if test -f "$destdir/$g"; then
1030       if $doit; then
1031         echo "Removing file $g (backup in ${g}~)"
1032         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1033       else
1034         echo "Remove file $g (backup in ${g}~)"
1035       fi
1036     fi
1037   done
1038   # func_add_or_update handles a file that ought to be present afterwards.
1039   # Uses parameters f, g, already_present.
1040   func_add_or_update ()
1041   {
1042     cp "$gnulib_dir/$f" "$destdir/$g.tmp" || func_fatal_error "failed"
1043     if test -n "$lgpl"; then
1044       # Update license.
1045       case "$f" in
1046         lib/*)
1047           sed -e 's/GNU General/GNU Lesser General/g' \
1048               -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1049             < "$gnulib_dir/$f" > "$destdir/$g.tmp" || func_fatal_error "failed"
1050           ;;
1051       esac
1052     fi
1053     if test -f "$destdir/$g"; then
1054       # The file already exists.
1055       if cmp "$destdir/$g" "$destdir/$g.tmp" > /dev/null; then
1056         : # The file has not changed.
1057       else
1058         # Replace the file.
1059         if $doit; then
1060           if test -n "$already_present"; then
1061             echo "Updating file $g (backup in ${g}~)"
1062           else
1063             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1064           fi
1065           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1066           if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1067             func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1068           else
1069             mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1070           fi
1071         else
1072           if test -n "$already_present"; then
1073             echo "Update file $g (backup in ${g}~)"
1074           else
1075             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1076           fi
1077         fi
1078       fi
1079     else
1080       # Install the file.
1081       # Don't protest if the file should be there but isn't: it happens
1082       # frequently that developers don't put autogenerated files into CVS.
1083       if $doit; then
1084         echo "Copying file $g"
1085         if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1086           func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1087         else
1088           mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1089         fi
1090       else
1091         echo "Copy file $g"
1092       fi
1093     fi
1094     rm -f "$destdir/$g.tmp"
1095   }
1096   # Then the files that are in new-files, but not in old-files:
1097   already_present=
1098   for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e 's,'^.*"$delimiter"',,'`; do
1099     case "$f" in
1100       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1101       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1102       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1103       tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1104       *) g="$f" ;;
1105     esac
1106     func_add_or_update
1107   done
1108   # Then the files that are in new-files and in old-files:
1109   already_present=true
1110   for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e 's,'^.*"$delimiter"',,'`; do
1111     case "$f" in
1112       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1113       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1114       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1115       tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1116       *) g="$f" ;;
1117     esac
1118     func_add_or_update
1119   done
1120   rm -rf "$tmp"
1121   trap - 0 1 2 3 15
1122
1123   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1124   actioncmd="gnulib-tool --import"
1125   actioncmd="$actioncmd --dir=$destdir"
1126   actioncmd="$actioncmd --lib=$libname"
1127   actioncmd="$actioncmd --source-base=$sourcebase"
1128   actioncmd="$actioncmd --m4-base=$m4base"
1129   actioncmd="$actioncmd --aux-dir=$auxdir"
1130   for module in $avoidlist; do
1131     actioncmd="$actioncmd --avoid=$module"
1132   done
1133   if test -n "$lgpl"; then
1134     actioncmd="$actioncmd --lgpl"
1135   fi
1136   if test -n "$libtool"; then
1137     actioncmd="$actioncmd --libtool"
1138   fi
1139   actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1140   actioncmd="$actioncmd `echo $specified_modules`"
1141
1142   # Create lib/Makefile.am.
1143   func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.tmp
1144   if test -f "$destdir"/$sourcebase/Makefile.am; then
1145     if cmp "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am.tmp > /dev/null; then
1146       rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1147     else
1148       if $doit; then
1149         echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1150         mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1151         mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1152       else
1153         echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1154         rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1155       fi
1156     fi
1157   else
1158     if $doit; then
1159       echo "Creating $sourcebase/Makefile.am"
1160       mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1161     else
1162       echo "Create $sourcebase/Makefile.am"
1163       rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1164     fi
1165   fi
1166
1167   # Create m4/gnulib-cache.m4.
1168   (
1169     echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1170     echo "# This file is free software, distributed under the terms of the GNU"
1171     echo "# General Public License.  As a special exception to the GNU General"
1172     echo "# Public License, this file may be distributed as part of a program"
1173     echo "# that contains a configuration script generated by Autoconf, under"
1174     echo "# the same distribution terms as the rest of that program."
1175     echo "#"
1176     echo "# Generated by gnulib-tool."
1177     echo "#"
1178     echo "# This file represents the specification of how gnulib-tool is used."
1179     echo "# It acts as a cache: It is written and read by gnulib-tool."
1180     echo "# In projects using CVS, this file is meant to be stored in CVS,"
1181     echo "# like the configure.ac and various Makefile.am files."
1182     echo
1183     echo
1184     echo "# Specification in the form of a command-line invocation:"
1185     echo "#   $actioncmd"
1186     echo
1187     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1188     echo "gl_MODULES(["`echo $specified_modules`"])"
1189     echo "gl_AVOID([$avoidlist])"
1190     echo "gl_SOURCE_BASE([$sourcebase])"
1191     echo "gl_M4_BASE([$m4base])"
1192     echo "gl_TESTS_BASE([$testsbase])"
1193     echo "gl_LIB([$libname])"
1194     test -z "$lgpl" || echo "gl_LGPL"
1195     test -z "$libtool" || echo "gl_LIBTOOL"
1196     echo "gl_MACRO_PREFIX([$macro_prefix])"
1197   ) > "$destdir"/$m4base/gnulib-cache.m4.tmp
1198   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1199     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4.tmp > /dev/null; then
1200       rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1201     else
1202       if $doit; then
1203         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1204         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1205         mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1206       else
1207         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1208         if false; then
1209           cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1210           echo
1211           echo "# gnulib-cache.m4 ends here"
1212         fi
1213         rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1214       fi
1215     fi
1216   else
1217     if $doit; then
1218       echo "Creating $m4base/gnulib-cache.m4"
1219       mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1220     else
1221       echo "Create $m4base/gnulib-cache.m4"
1222       cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1223       rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1224     fi
1225   fi
1226
1227   # Create m4/gnulib-comp.m4.
1228   (
1229     echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1230     echo "# This file is free software, distributed under the terms of the GNU"
1231     echo "# General Public License.  As a special exception to the GNU General"
1232     echo "# Public License, this file may be distributed as part of a program"
1233     echo "# that contains a configuration script generated by Autoconf, under"
1234     echo "# the same distribution terms as the rest of that program."
1235     echo "#"
1236     echo "# Generated by gnulib-tool."
1237     echo "#"
1238     echo "# This file represents the compiled summary of the specification in"
1239     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1240     echo "# to be invoked from configure.ac."
1241     echo "# In projects using CVS, this file can be treated like other built files."
1242     echo
1243     echo
1244     echo "# This macro should be invoked from $configure_ac, in the section"
1245     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1246     echo "# any checks for libraries, header files, types and library functions."
1247     echo "AC_DEFUN([${macro_prefix}_EARLY],"
1248     echo "["
1249     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
1250     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
1251       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
1252     fi
1253     if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
1254       echo "  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1255     fi
1256     echo "])"
1257     echo
1258     echo "# This macro should be invoked from $configure_ac, in the section"
1259     echo "# \"Check for header files, types and library functions\"."
1260     echo "AC_DEFUN([${macro_prefix}_INIT],"
1261     echo "["
1262     if test -z "$libtool"; then
1263       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1264     else
1265       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1266     fi
1267     sed_replace_build_aux='
1268       :a
1269       /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1270         s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1271         ba
1272       }'
1273     sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1274     for module in $modules; do
1275       func_verify_module
1276       if test -n "$module"; then
1277         func_get_autoconf_snippet "$module" \
1278           | sed -e '/^$/d;' -e 's/^/  /' \
1279                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1280                 -e "$sed_replace_build_aux"
1281         if test "$module" = 'alloca' && test -n "$libtool"; then
1282           echo 'changequote(,)dnl'
1283           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1284           echo 'changequote([, ])dnl'
1285           echo 'AC_SUBST([LTALLOCA])'
1286         fi
1287       fi
1288     done
1289     echo "])"
1290     echo
1291     echo "# This macro records the list of files which have been installed by"
1292     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1293     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1294     echo "$files" | sed -e 's,^,  ,'
1295     echo "])"
1296   ) > "$destdir"/$m4base/gnulib-comp.m4.tmp
1297   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1298     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4.tmp > /dev/null; then
1299       rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1300     else
1301       if $doit; then
1302         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1303         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1304         mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1305       else
1306         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1307         if false; then
1308           cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1309           echo
1310           echo "# gnulib-comp.m4 ends here"
1311         fi
1312         rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1313       fi
1314     fi
1315   else
1316     if $doit; then
1317       echo "Creating $m4base/gnulib-comp.m4"
1318       mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1319     else
1320       echo "Create $m4base/gnulib-comp.m4"
1321       cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1322       rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1323     fi
1324   fi
1325
1326   if test -n "$inctests"; then
1327     # Create tests/Makefile.am.
1328     func_emit_tests_Makefile_am > "$destdir"/$testsbase/Makefile.am.tmp
1329     if test -f "$destdir"/$testsbase/Makefile.am; then
1330       if cmp "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am.tmp > /dev/null; then
1331         rm -f "$destdir"/$testsbase/Makefile.am.tmp
1332       else
1333         if $doit; then
1334           echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1335           mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1336           mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1337         else
1338           echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1339           rm -f "$destdir"/$testsbase/Makefile.am.tmp
1340         fi
1341       fi
1342     else
1343       if $doit; then
1344         echo "Creating $testsbase/Makefile.am"
1345         mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1346       else
1347         echo "Create $testsbase/Makefile.am"
1348         rm -f "$destdir"/$testsbase/Makefile.am.tmp
1349       fi
1350     fi
1351   fi
1352
1353   echo "Finished."
1354   echo
1355   echo "You may need to add #include directives for the following .h files."
1356   for module in $modules; do
1357     func_get_include_directive "$module"
1358   done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/  /'
1359   echo
1360   echo "Don't forget to"
1361   echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1362   if test -n "$inctests"; then
1363     echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1364   fi
1365   sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1366   sourcebase_base=`basename "$sourcebase"`
1367   echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1368   if test -n "$inctests"; then
1369     testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1370     testsbase_base=`basename "$testsbase"`
1371     echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1372   fi
1373   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1374   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1375   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
1376 }
1377
1378 # func_create_testdir testdir modules
1379 # Input:
1380 # - auxdir          directory relative to destdir where to place build aux files
1381 func_create_testdir ()
1382 {
1383   testdir="$1"
1384   modules="$2"
1385   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1386
1387   # Determine final module list.
1388   func_modules_transitive_closure
1389   echo "Module list with included dependencies:"
1390   echo "$modules" | sed -e 's/^/  /'
1391
1392   # Determine final file list.
1393   func_modules_to_filelist
1394   echo "File list:"
1395   echo "$files" | sed -e 's/^/  /'
1396
1397   # Create directories.
1398   for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1399     if test "$d" = build-aux; then
1400       mkdir -p "$testdir/$auxdir"
1401     else
1402       mkdir -p "$testdir/$d"
1403     fi
1404   done
1405
1406   # Copy files or make symbolic links.
1407   for f in $files; do
1408     case "$f" in
1409       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1410       *) g="$f" ;;
1411     esac
1412     ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1413     if test -z "$symbolic"; then
1414       cp -p "$gnulib_dir/$f" "$testdir/$g"
1415     else
1416       ln -s "$gnulib_dir/$f" "$testdir/$g"
1417     fi
1418   done
1419
1420   # Create lib/Makefile.am.
1421   mkdir -p "$testdir/lib"
1422   func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1423
1424   # Create m4/Makefile.am.
1425   mkdir -p "$testdir/m4"
1426   (echo "## Process this file with automake to produce Makefile.in."
1427    echo
1428    echo "EXTRA_DIST ="
1429    for f in $files; do
1430      case "$f" in
1431        m4/* )
1432          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1433      esac
1434    done
1435   ) > "$testdir/m4/Makefile.am"
1436
1437   subdirs="lib m4"
1438   subdirs_with_configure_ac=""
1439
1440   if test -f "$testdir"/m4/gettext.m4; then
1441     # Avoid stupid error message from automake:
1442     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1443     mkdir -p "$testdir/po"
1444     (echo "## Process this file with automake to produce Makefile.in."
1445     ) > "$testdir/po/Makefile.am"
1446     subdirs="$subdirs po"
1447   fi
1448
1449   if test -n "$inctests"; then
1450     test -d "$testdir/tests" || mkdir "$testdir/tests"
1451     # Create tests/Makefile.am.
1452     sourcebase=lib
1453     m4base=m4
1454     testsbase=tests
1455     func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1456     # Create tests/configure.ac.
1457     (echo "# Process this file with autoconf to produce a configure script."
1458      echo "AC_INIT([dummy], [0])"
1459      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1460      echo "AM_INIT_AUTOMAKE"
1461      echo
1462      echo "AM_CONFIG_HEADER([config.h])"
1463      echo
1464      echo "AC_PROG_CC"
1465      echo "AC_PROG_INSTALL"
1466      echo "AC_PROG_MAKE_SET"
1467      echo "AC_PROG_RANLIB"
1468      echo
1469      if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1470        echo "AC_GNU_SOURCE"
1471        echo
1472      fi
1473      if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1474        echo "gl_USE_SYSTEM_EXTENSIONS"
1475        echo
1476      fi
1477      if test -z "$libtool"; then
1478        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1479      else
1480        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1481      fi
1482      sed_replace_build_aux='
1483        :a
1484        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1485          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1486          ba
1487        }'
1488      sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1489      # We don't have explicit ordering constraints between the various
1490      # autoconf snippets. It's cleanest to put those of the library before
1491      # those of the tests.
1492      for module in $modules; do
1493        func_verify_nontests_module
1494        if test -n "$module"; then
1495          func_get_autoconf_snippet "$module" \
1496            | sed -e "$sed_replace_build_aux"
1497        fi
1498      done
1499      for module in $modules; do
1500        func_verify_tests_module
1501        if test -n "$module"; then
1502          func_get_autoconf_snippet "$module" \
1503            | sed -e "$sed_replace_build_aux"
1504        fi
1505      done
1506      echo
1507      # Usually tests/config.h will be a superset of config.h. Verify this by
1508      # "merging" config.h into tests/config.h; look out for gcc warnings.
1509      echo "AH_TOP([#include \"../config.h\"])"
1510      echo
1511      echo "AC_OUTPUT([Makefile])"
1512     ) > "$testdir/tests/configure.ac"
1513     subdirs="$subdirs tests"
1514     subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1515   fi
1516
1517   # Create Makefile.am.
1518   (echo "## Process this file with automake to produce Makefile.in."
1519    echo
1520    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1521    echo
1522    echo "SUBDIRS = $subdirs"
1523    echo
1524    echo "ACLOCAL_AMFLAGS = -I m4"
1525   ) > "$testdir/Makefile.am"
1526
1527   # Create configure.ac.
1528   (echo "# Process this file with autoconf to produce a configure script."
1529    echo "AC_INIT([dummy], [0])"
1530    if test "$auxdir" != "."; then
1531      echo "AC_CONFIG_AUX_DIR([$auxdir])"
1532    fi
1533    echo "AM_INIT_AUTOMAKE"
1534    echo
1535    echo "AM_CONFIG_HEADER([config.h])"
1536    echo
1537    echo "AC_PROG_CC"
1538    echo "AC_PROG_INSTALL"
1539    echo "AC_PROG_MAKE_SET"
1540    echo "AC_PROG_RANLIB"
1541    echo
1542    if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1543      echo "AC_GNU_SOURCE"
1544      echo
1545    fi
1546    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1547      echo "gl_USE_SYSTEM_EXTENSIONS"
1548      echo
1549    fi
1550    if test -z "$libtool"; then
1551      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1552    else
1553      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1554    fi
1555    sed_replace_build_aux='
1556      :a
1557      /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1558        s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1559        ba
1560      }'
1561    sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1562    for module in $modules; do
1563      func_verify_nontests_module
1564      if test -n "$module"; then
1565        func_get_autoconf_snippet "$module" \
1566          | sed -e "$sed_replace_build_aux"
1567      fi
1568    done
1569    echo
1570    if test -n "$subdirs_with_configure_ac"; then
1571      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1572    fi
1573    makefiles="Makefile"
1574    for d in $subdirs; do
1575      # For subdirs that have a configure.ac by their own, it's the subdir's
1576      # configure.ac which creates the subdir's Makefile.am, not this one.
1577      case " $subdirs_with_configure_ac " in
1578        *" $d "*) ;;
1579        *) makefiles="$makefiles $d/Makefile" ;;
1580      esac
1581    done
1582    echo "AC_OUTPUT([$makefiles])"
1583   ) > "$testdir/configure.ac"
1584
1585   # Create autogenerated files.
1586   (cd "$testdir"
1587    echo "executing ${AUTORECONF} --force --install"
1588    ${AUTORECONF} --force --install
1589   )
1590   if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1591     (cd "$testdir"
1592      ./configure
1593        cd lib
1594        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1595        make built_sources
1596        cd ..
1597      make distclean
1598     )
1599   fi
1600 }
1601
1602 # func_create_megatestdir megatestdir allmodules
1603 # Input:
1604 # - auxdir          directory relative to destdir where to place build aux files
1605 func_create_megatestdir ()
1606 {
1607   megatestdir="$1"
1608   allmodules="$2"
1609   if test -z "$allmodules"; then
1610     allmodules=`func_all_modules`
1611   fi
1612
1613   megasubdirs=
1614   # First, all modules one by one.
1615   for onemodule in $allmodules; do
1616     func_create_testdir "$megatestdir/$onemodule" $onemodule
1617     megasubdirs="${megasubdirs}$onemodule "
1618   done
1619   # Then, all modules all together.
1620   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1621   allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1622   func_create_testdir "$megatestdir/ALL" "$allmodules"
1623   megasubdirs="${megasubdirs}ALL"
1624
1625   # Create Makefile.am.
1626   (echo "## Process this file with automake to produce Makefile.in."
1627    echo
1628    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1629    echo
1630    echo "SUBDIRS = $megasubdirs"
1631   ) > "$megatestdir/Makefile.am"
1632
1633   # Create configure.ac.
1634   (echo "# Process this file with autoconf to produce a configure script."
1635    echo "AC_INIT([dummy], [0])"
1636    if test "$auxdir" != "."; then
1637      echo "AC_CONFIG_AUX_DIR([$auxdir])"
1638    fi
1639    echo "AM_INIT_AUTOMAKE"
1640    echo
1641    echo "AC_PROG_MAKE_SET"
1642    echo
1643    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1644    echo "AC_OUTPUT([Makefile])"
1645   ) > "$megatestdir/configure.ac"
1646
1647   # Create autogenerated files.
1648   (cd "$megatestdir"
1649    echo "executing ${AUTORECONF} --install"
1650    ${AUTORECONF} --install
1651   )
1652 }
1653
1654 case $mode in
1655   "" )
1656     func_fatal_error "no mode specified" ;;
1657
1658   list )
1659     func_all_modules
1660     ;;
1661
1662   import | update )
1663     
1664     # Where to import.
1665     if test -z "$destdir"; then
1666       destdir=.
1667     fi
1668     test -d "$destdir" \
1669       || func_fatal_error "destination directory does not exist: $destdir"
1670
1671     # Prefer configure.ac to configure.in.
1672     if test -f "$destdir"/configure.ac; then
1673       configure_ac="$destdir/configure.ac"
1674     else
1675       if test -f "$destdir"/configure.in; then
1676         configure_ac="$destdir/configure.in"
1677       else
1678         func_fatal_error "cannot find $destdir/configure.ac"
1679       fi
1680     fi
1681
1682     test -f "$destdir"/Makefile.am \
1683       || func_fatal_error "cannot find $destdir/Makefile.am"
1684
1685     # Analyze configure.ac.
1686     guessed_auxdir="."
1687     guessed_libtool=
1688     my_sed_traces='
1689       s,#.*$,,
1690       s,^dnl .*$,,
1691       s, dnl .*$,,
1692       /AC_CONFIG_AUX_DIR/ {
1693         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1694       }
1695       /A[CM]_PROG_LIBTOOL/ {
1696         s,^.*$,guessed_libtool=true,p
1697       }'
1698     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1699
1700     if test -z "$auxdir"; then
1701       auxdir="$guessed_auxdir"
1702     fi
1703
1704     # Determine where to apply func_import.
1705     if test -n "$m4base"; then
1706       # Apply func_import to a particular gnulib directory.
1707       # Any number of additional modules can be given.
1708       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1709         # First use of gnulib in the given m4base.
1710         test -n "$supplied_libname" || supplied_libname=true
1711         test -n "$sourcebase" || sourcebase="lib"
1712         test -n "$testsbase" || testsbase="tests"
1713         test -n "$macro_prefix" || macro_prefix="gl"
1714       fi
1715       func_import "$*"
1716     else
1717       # Apply func_import to all gnulib directories.
1718       # To get this list of directories, look at Makefile.am. (Not at
1719       # configure, because it may be omitted from CVS. Also, don't run
1720       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1721       aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[  ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[       ]*=\(.*\)$/\1/'`
1722       m4dirs=
1723       m4dirs_count=0
1724       m4dir_is_next=
1725       for arg in $aclocal_amflags; do
1726         if test -n "$m4dir_is_next"; then
1727           # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1728           case "$arg" in
1729             /*) ;;
1730             *)
1731               if test -f "$destdir/$arg"/gnulib-cache.m4; then
1732                 m4dirs="$m4dirs $arg"
1733                 m4dirs_count=`expr $m4dirs_count + 1`
1734               fi
1735               ;;
1736           esac
1737         else
1738           if test "X$arg" = "X-I"; then
1739             m4dir_is_next=yes
1740           else
1741             m4dir_is_next=
1742           fi
1743         fi
1744       done
1745       if test $m4dirs_count = 0; then
1746         # First use of gnulib in a package.
1747         # Any number of additional modules can be given.
1748         test -n "$supplied_libname" || supplied_libname=true
1749         test -n "$sourcebase" || sourcebase="lib"
1750         m4base="m4"
1751         test -n "$testsbase" || testsbase="tests"
1752         test -n "$macro_prefix" || macro_prefix="gl"
1753         func_import "$*"
1754       else
1755         if test $m4dirs_count = 1; then
1756           # There's only one use of gnulib here. Assume the user means it.
1757           # Any number of additional modules can be given.
1758           for m4base in $m4dirs; do
1759             func_import "$*"
1760           done
1761         else
1762           # Ambiguous - guess what the user meant.
1763           if test $# = 0; then
1764             # No further arguments. Guess the user wants to update all of them.
1765             for m4base in $m4dirs; do
1766               func_import
1767             done
1768           else
1769             # Really ambiguous.
1770             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1771           fi
1772         fi
1773       fi
1774     fi
1775     ;;
1776
1777   create-testdir )
1778     if test -z "$destdir"; then
1779       func_fatal_error "please specify --dir option"
1780     fi
1781     mkdir "$destdir"
1782     test -d "$destdir" \
1783       || func_fatal_error "could not create destination directory"
1784     test -n "$auxdir" || auxdir="build-aux"
1785     func_create_testdir "$destdir" "$*"
1786     ;;
1787
1788   create-megatestdir )
1789     if test -z "$destdir"; then
1790       func_fatal_error "please specify --dir option"
1791     fi
1792     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1793     test -n "$auxdir" || auxdir="build-aux"
1794     func_create_megatestdir "$destdir" "$*"
1795     ;;
1796
1797   test )
1798     test -n "$destdir" || destdir=testdir$$
1799     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1800     test -n "$auxdir" || auxdir="build-aux"
1801     func_create_testdir "$destdir" "$*"
1802     cd "$destdir"
1803       mkdir build
1804       cd build
1805         ../configure
1806         make
1807         make check
1808         make distclean
1809         remaining=`find . -type f -print`
1810         if test -n "$remaining"; then
1811           echo "Remaining files:" $remaining 1>&2
1812           echo "gnulib-tool: *** Stop." 1>&2
1813           exit 1
1814         fi
1815       cd ..
1816     cd ..
1817     rm -rf "$destdir"
1818     ;;
1819
1820   megatest )
1821     test -n "$destdir" || destdir=testdir$$
1822     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1823     test -n "$auxdir" || auxdir="build-aux"
1824     func_create_megatestdir "$destdir" "$*"
1825     cd "$destdir"
1826       mkdir build
1827       cd build
1828         ../configure
1829         make
1830         make check
1831         make distclean
1832         remaining=`find . -type f -print`
1833         if test -n "$remaining"; then
1834           echo "Remaining files:" $remaining 1>&2
1835           echo "gnulib-tool: *** Stop." 1>&2
1836           exit 1
1837         fi
1838       cd ..
1839     cd ..
1840     rm -rf "$destdir"
1841     ;;
1842
1843   extract-description )
1844     for module
1845     do
1846       func_verify_module
1847       if test -n "$module"; then
1848         func_get_description "$module"
1849       fi
1850     done
1851     ;;
1852
1853   extract-filelist )
1854     for module
1855     do
1856       func_verify_module
1857       if test -n "$module"; then
1858         func_get_filelist "$module"
1859       fi
1860     done
1861     ;;
1862
1863   extract-dependencies )
1864     for module
1865     do
1866       func_verify_module
1867       if test -n "$module"; then
1868         func_get_dependencies "$module"
1869       fi
1870     done
1871     ;;
1872
1873   extract-autoconf-snippet )
1874     for module
1875     do
1876       func_verify_module
1877       if test -n "$module"; then
1878         func_get_autoconf_snippet "$module"
1879       fi
1880     done
1881     ;;
1882
1883   extract-automake-snippet )
1884     for module
1885     do
1886       func_verify_module
1887       if test -n "$module"; then
1888         func_get_automake_snippet "$module"
1889       fi
1890     done
1891     ;;
1892
1893   extract-include-directive )
1894     for module
1895     do
1896       func_verify_module
1897       if test -n "$module"; then
1898         func_get_include_directive "$module"
1899       fi
1900     done
1901     ;;
1902
1903   extract-license )
1904     for module
1905     do
1906       func_verify_module
1907       if test -n "$module"; then
1908         func_get_license "$module"
1909       fi
1910     done
1911     ;;
1912
1913   extract-maintainer )
1914     for module
1915     do
1916       func_verify_module
1917       if test -n "$module"; then
1918         func_get_maintainer "$module"
1919       fi
1920     done
1921     ;;
1922
1923   extract-tests-module )
1924     for module
1925     do
1926       func_verify_module
1927       if test -n "$module"; then
1928         func_get_tests_module "$module"
1929       fi
1930     done
1931     ;;
1932
1933   * )
1934     func_fatal_error "unknown operation mode --$mode" ;;
1935 esac
1936
1937 exit 0