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