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