435897ee2dc30b30b4f250c5cacd4310240cb2f5
[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-08-29 20:03:02 $'
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       --no-changelog        don't update or create ChangeLog files
106       --dry-run             For --import, only print what would have been done.
107   -s, --symbolic, --symlink Make symbolic links instead of copying files.
108
109 Report bugs to <bug-gnulib@gnu.org>."
110 }
111
112 # func_version
113 # outputs to stdout the --version message.
114 func_version ()
115 {
116   echo "$progname (GNU $package) $version"
117   echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
118 This is free software; see the source for copying conditions.  There is NO
119 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
120   echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
121 }
122
123 # func_fatal_error message
124 # outputs to stderr a fatal error message, and terminates the program.
125 func_fatal_error ()
126 {
127   echo "gnulib-tool: *** $1" 1>&2
128   echo "gnulib-tool: *** Stop." 1>&2
129   exit 1
130 }
131
132 # func_cp_if_changed SRC DEST
133 # Like cp, but avoids munging timestamps if the file hasn't changed.
134 # Uses also the variables
135 # - dry_run         true if actions shall only be printed, blank otherwise
136 func_cp_if_changed ()
137 {
138   if test $# -ne 2; then
139     echo "usage: func_cp_if_changed SRC DEST" >&2
140   fi
141   test -n "$dry_run" && dry=echo
142   if cmp "$1" "$2" >/dev/null 2>&1; then
143     :
144   else
145     $dry cp -p "$1" "$2"
146   fi
147 }
148
149 # func_mv_if_changed SRC DEST
150 # Like mv, but avoids munging timestamps if the file hasn't changed.
151 # Removes SRC if it is not renamed.
152 # Uses also the variables
153 # - dry_run         true if actions shall only be printed, blank otherwise
154 func_mv_if_changed ()
155 {
156   if test $# -ne 2; then
157     echo "usage: func_mv_if_changed SRC DEST" >&2
158   fi
159   test -n "$dry_run" && dry=echo
160   if cmp "$1" "$2" >/dev/null 2>&1; then
161     $dry rm "$1"
162   else
163     $dry mv "$1" "$2"
164   fi
165 }
166
167 # func_ln_if_changed SRC DEST
168 # Like ln -s, but avoids munging timestamps if the link is correct.
169 # Uses also the variables
170 # - dry_run         true if actions shall only be printed, blank otherwise
171 func_ln_if_changed ()
172 {
173   if test $# -ne 2; then
174     echo "usage: func_ln_if_changed SRC DEST" >&2
175   fi
176   test -n "$dry_run" && dry=echo
177   if test -L "$2" -a "$1" = "`readlink "$2"`"; then
178     :
179   else
180     $dry rm -f "$2"
181     $dry ln -s "$1" "$2"
182   fi
183 }
184
185 # Command-line option processing.
186 # Removes the OPTIONS from the arguments. Sets the variables:
187 # - mode            list or import or create-testdir or create-megatestdir
188 # - destdir         from --dir
189 # - libname, supplied_libname  from --lib
190 # - sourcebase      from --source-base
191 # - m4base          from --m4-base
192 # - testsbase       from --tests-base
193 # - auxdir          from --aux-dir
194 # - inctests        true if --with-tests was given, blank otherwise
195 # - avoidlist       list of modules to avoid, from --avoid
196 # - lgpl            true if --lgpl was given, blank otherwise
197 # - libtool         true if --libtool was given, blank otherwise
198 # - do_changelog    false if --no-changelog was given, : otherwise
199 # - dry_run         true if --dry-run was given, blank otherwise
200 {
201   mode=
202   destdir=
203   libname=libgnu
204   supplied_libname=
205   sourcebase=
206   m4base=
207   testsbase=
208   auxdir=
209   inctests=
210   avoidlist=
211   lgpl=
212   libtool=
213   do_changelog=:
214   dry_run=
215   symbolic=
216
217   supplied_opts="$@"
218
219   while test $# -gt 0; do
220     case "$1" in
221       --list | --lis )
222         mode=list
223         shift ;;
224       --import | --impor | --impo | --imp | --im | --i )
225         mode=import
226         shift ;;
227       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
228         mode=create-testdir
229         shift ;;
230       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
231         mode=create-megatestdir
232         shift ;;
233       --test | --tes | --te | --t )
234         mode=test
235         shift ;;
236       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
237         mode=megatest
238         shift ;;
239       --extract-* )
240         mode=`echo "X$1" | sed -e 's/^X--//'`
241         shift ;;
242       --dir )
243         shift
244         if test $# = 0; then
245           func_fatal_error "missing argument for --dir"
246         fi
247         destdir=$1
248         shift ;;
249       --dir=* )
250         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
251         shift ;;
252       --lib )
253         shift
254         if test $# = 0; then
255           func_fatal_error "missing argument for --lib"
256         fi
257         libname=$1
258         supplied_libname=true
259         shift ;;
260       --lib=* )
261         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
262         supplied_libname=true
263         shift ;;
264       --source-base )
265         shift
266         if test $# = 0; then
267           func_fatal_error "missing argument for --source-base"
268         fi
269         sourcebase=$1
270         shift ;;
271       --source-base=* )
272         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
273         shift ;;
274       --m4-base )
275         shift
276         if test $# = 0; then
277           func_fatal_error "missing argument for --m4-base"
278         fi
279         m4base=$1
280         shift ;;
281       --m4-base=* )
282         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
283         shift ;;
284       --tests-base )
285         shift
286         if test $# = 0; then
287           func_fatal_error "missing argument for --tests-base"
288         fi
289         testsbase=$1
290         shift ;;
291       --tests-base=* )
292         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
293         shift ;;
294       --aux-dir )
295         shift
296         if test $# = 0; then
297           func_fatal_error "missing argument for --aux-dir"
298         fi
299         auxdir=$1
300         shift ;;
301       --aux-dir=* )
302         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
303         shift ;;
304       --with-tests )
305         inctests=true
306         shift ;;
307       --avoid )
308         shift
309         if test $# = 0; then
310           func_fatal_error "missing argument for --avoid"
311         fi
312         avoidlist="$avoidlist $1"
313         shift ;;
314       --avoid=* )
315         avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
316         shift ;;
317       --lgpl )
318         lgpl=true
319         shift ;;
320       --libtool )
321         libtool=true
322         shift ;;
323       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
324         do_changelog=false
325         shift ;;
326       --dry-run )
327         dry_run=true
328         shift ;;
329       -s | --symbolic | --symlink )
330         symbolic=true
331         shift ;;
332       --help | --hel | --he | --h )
333         func_usage
334         exit 0 ;;
335       --version | --versio | --versi | --vers | --ver | --ve | --v )
336         func_version
337         exit 0 ;;
338       -- )
339         # Stop option prcessing
340         shift
341         break ;;
342       -* )
343         echo "gnulib-tool: unknown option $1" 1>&2
344         echo "Try 'gnulib-tool --help' for more information." 1>&2
345         exit 1 ;;
346       * )
347         break ;;
348     esac
349   done
350 }
351
352 case "$0" in
353   /*) self_abspathname="$0" ;;
354   */*) self_abspathname=`pwd`/"$0" ;;
355   *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
356        if test -x "$d/$0" && test ! -d "$d/$0"; then
357          self_abspathname="$d/$0"
358          break
359        fi
360      done
361      if test -z "$self_abspathname"; then
362        func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
363      fi
364      ;;
365 esac
366 while test -h "$self_abspathname"; do
367   # Resolve symbolic link.
368   sedexpr1='s, -> ,#%%#,'
369   sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
370   linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
371   test -n "$linkval" || break
372   case "$linkval" in
373     /* ) self_abspathname="$linkval" ;;
374     * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
375   esac
376 done
377 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
378
379 # func_all_modules
380 func_all_modules ()
381 {
382   # Filter out metainformation files like README, which are not modules.
383   # Filter out unit test modules; they can be retrieved through
384   # --extract-tests-module if desired.
385   (cd "$gnulib_dir/modules" && ls -1) \
386       | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
387       | sed -e '/-tests$/d' \
388       | sort
389 }
390
391 # func_verify_module
392 # verifies a module name
393 func_verify_module ()
394 {
395   if test ! -f "$gnulib_dir/modules/$module" \
396      || test "CVS" = "$module" \
397      || test "ChangeLog" = "$module" \
398      || test "README" = "$module" \
399      || test "TEMPLATE" = "$module" \
400      || test "TEMPLATE-TESTS" = "$module"; then
401     echo "gnulib-tool: module $module doesn't exist" 1>&2
402     module=
403   fi
404 }
405
406 # func_verify_nontests_module
407 # verifies a module name, excluding tests modules
408 func_verify_nontests_module ()
409 {
410   case "$module" in
411     *-tests ) module= ;;
412     * ) func_verify_module ;;
413   esac
414 }
415
416 # func_verify_tests_module
417 # verifies a module name, considering only tests modules
418 func_verify_tests_module ()
419 {
420   case "$module" in
421     *-tests ) func_verify_module ;;
422     * ) module= ;;
423   esac
424 }
425
426 sed_extract_prog=':[    ]*$/ {
427   :a
428     n
429     s/^Description:[    ]*$//
430     s/^Files:[  ]*$//
431     s/^Depends-on:[     ]*$//
432     s/^configure\.ac:[  ]*$//
433     s/^Makefile\.am:[   ]*$//
434     s/^Include:[        ]*$//
435     s/^License:[        ]*$//
436     s/^Maintainer:[     ]*$//
437     tb
438     p
439     ba
440   :b
441 }'
442
443 # func_get_description module
444 func_get_description ()
445 {
446   sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
447 }
448
449 # func_get_filelist module
450 func_get_filelist ()
451 {
452   sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
453   #echo m4/onceonly.m4
454   echo m4/onceonly_2_57.m4
455 }
456
457 # func_get_dependencies module
458 func_get_dependencies ()
459 {
460   # ${module}-tests always implicitly depends on ${module}.
461   echo "$1" | sed -n -e 's/-tests//p'
462   # Then the explicit dependencies listed in the module description.
463   sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
464 }
465
466 # func_get_autoconf_snippet module
467 func_get_autoconf_snippet ()
468 {
469   sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
470 }
471
472 # func_get_automake_snippet module
473 func_get_automake_snippet ()
474 {
475   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
476 }
477
478 # func_get_include_directive module
479 func_get_include_directive ()
480 {
481   sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
482   sed -e 's/^\(["<]\)/#include \1/'
483 }
484
485 # func_get_license module
486 func_get_license ()
487 {
488   sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
489 }
490
491 # func_get_maintainer module
492 func_get_maintainer ()
493 {
494   sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
495 }
496
497 # func_get_tests_module module
498 func_get_tests_module ()
499 {
500   # The naming convention for tests modules is hardwired: ${module}-tests.
501   if test -f modules/"$1"-tests; then
502     echo "$1"-tests
503   fi
504 }
505
506 # func_acceptable module
507 # tests whether a module is acceptable.
508 # Input:
509 # - avoidlist       list of modules to avoid
510 func_acceptable ()
511 {
512   for avoid in $avoidlist; do
513     if test "$avoid" = "$1"; then
514       return 1
515     fi
516   done
517   return 0
518 }
519
520 # func_modules_transitive_closure
521 # Input:
522 # - modules         list of specified modules
523 # - inctests        true if tests should be included, blank otherwise
524 # - avoidlist       list of modules to avoid
525 # Output:
526 # - modules         list of modules, including dependencies
527 func_modules_transitive_closure ()
528 {
529   while true; do
530     xmodules=
531     for module in $modules; do
532       func_verify_module
533       if test -n "$module"; then
534         # Duplicate dependencies are harmless, but Jim wants a warning.
535         duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
536         if test -n "$duplicated_deps"; then
537           echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
538         fi
539         if func_acceptable $module; then
540           xmodules="$xmodules $module"
541           for depmodule in `func_get_dependencies $module`; do
542             if func_acceptable $depmodule; then
543               xmodules="$xmodules $depmodule"
544             fi
545           done
546           if test -n "$inctests"; then
547             testsmodule=`func_get_tests_module $module`
548             if test -n "$testsmodule"; then
549               if func_acceptable $testsmodule; then
550                 xmodules="$xmodules $testsmodule"
551                 for depmodule in `func_get_dependencies $testsmodule`; do
552                   if func_acceptable $depmodule; then
553                     xmodules="$xmodules $depmodule"
554                   fi
555                 done
556               fi
557             fi
558           fi
559         fi
560       fi
561     done
562     xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
563     if test "$xmodules" = "$modules"; then
564       break
565     fi
566     modules="$xmodules"
567   done
568 }
569
570 # func_modules_to_filelist
571 # Input:
572 # - modules         list of modules, including dependencies
573 # Output:
574 # - files           list of files
575 func_modules_to_filelist ()
576 {
577   files=
578   for module in $modules; do
579     func_verify_module
580     if test -n "$module"; then
581       files="$files "`func_get_filelist $module`
582     fi
583   done
584   files=`for f in $files; do echo $f; done | sort | uniq`
585 }
586
587 # func_emit_lib_Makefile_am
588 # emits the contents of lib/Makefile.am to standard output.
589 # Input:
590 # - modules         list of modules, including dependencies
591 # - libname         library name
592 # - libtool         true if libtool will be used, blank otherwise
593 # - cmd             (optional) command that led to this invocation
594 # - actioncmd       (optional) command that will reproduce this invocation
595 func_emit_lib_Makefile_am ()
596 {
597   if test -n "$libtool"; then
598     libext=la
599     perhapsLT=LT
600   else
601     libext=a
602     perhapsLT=
603   fi
604   echo "## Process this file with automake to produce Makefile.in."
605   echo "# Copyright (C) 2004 Free Software Foundation, Inc."
606   echo "#"
607   echo "# This file is free software, distributed under the terms of the GNU"
608   echo "# General Public License.  As a special exception to the GNU General"
609   echo "# Public License, this file may be distributed as part of a program"
610   echo "# that contains a configuration script generated by Automake, under"
611   echo "# the same distribution terms as the rest of that program."
612   echo "#"
613   echo "# Generated by gnulib-tool."
614   if test -n "$cmd"; then
615     echo "# Invoked as: $cmd"
616   fi
617   if test -n "$actioncmd"; then
618     echo "# Reproduce by: $actioncmd"
619   fi
620   echo
621   # No need to generate dependencies since the sources are in gnulib, not here.
622   echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
623   echo
624   echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
625   echo
626   echo "${libname}_${libext}_SOURCES ="
627   echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
628   echo "EXTRA_DIST ="
629   echo "BUILT_SOURCES ="
630   echo "SUFFIXES ="
631   echo "MOSTLYCLEANFILES ="
632   echo "CLEANFILES ="
633   echo "DISTCLEANFILES ="
634   echo "MAINTAINERCLEANFILES ="
635   echo
636   for module in $modules; do
637     func_verify_nontests_module
638     if test -n "$module"; then
639       {
640         func_get_automake_snippet "$module" |
641           sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
642         if test "$module" = 'alloca'; then
643           echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
644         fi
645       } > amsnippet.tmp
646       # Skip the contents if its entirely empty.
647       if grep '[^       ]' amsnippet.tmp > /dev/null ; then
648         echo "## begin gnulib module $module"
649         echo
650         cat amsnippet.tmp
651         echo "## end   gnulib module $module"
652         echo
653       fi
654       rm -f amsnippet.tmp
655     fi
656   done
657   echo
658   echo "# Makefile.am ends here"
659 }
660
661 # func_emit_tests_Makefile_am
662 # emits the contents of tests/Makefile.am to standard output.
663 # Input:
664 # - modules         list of modules, including dependencies
665 # - libname         library name
666 # - libtool         true if libtool will be used, blank otherwise
667 # - sourcebase      relative directory containing lib source code
668 func_emit_tests_Makefile_am ()
669 {
670   if test -n "$libtool"; then
671     libext=la
672   else
673     libext=a
674   fi
675   echo "## Process this file with automake to produce Makefile.in."
676   echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
677   echo "#"
678   echo "# This file is free software, distributed under the terms of the GNU"
679   echo "# General Public License.  As a special exception to the GNU General"
680   echo "# Public License, this file may be distributed as part of a program"
681   echo "# that contains a configuration script generated by Automake, under"
682   echo "# the same distribution terms as the rest of that program."
683   echo "#"
684   echo "# Generated by gnulib-tool."
685   echo
686   # Generate dependencies here, since it eases the debugging of test failures.
687   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
688   echo
689   echo "ACLOCAL_AMFLAGS = -I ../m4"
690   echo
691   echo "TESTS ="
692   echo "noinst_PROGRAMS ="
693   echo "EXTRA_DIST ="
694   echo "BUILT_SOURCES ="
695   echo "SUFFIXES ="
696   echo "MOSTLYCLEANFILES ="
697   echo "CLEANFILES ="
698   echo "DISTCLEANFILES ="
699   echo "MAINTAINERCLEANFILES ="
700   echo
701   echo "AM_CPPFLAGS = \\"
702   echo "  -I. -I\$(srcdir) \\"
703   echo "  -I.. -I\$(srcdir)/.. \\"
704   echo "  -I../${sourcebase-lib} -I\$(srcdir)/../${sourcebase-lib}"
705   echo
706   echo "LDADD = ../${sourcebase-lib}/${libname}.${libext}"
707   echo
708   for module in $modules; do
709     func_verify_tests_module
710     if test -n "$module"; then
711       func_get_automake_snippet "$module" > amsnippet.tmp
712       # Skip the contents if its entirely empty.
713       if grep '[^       ]' amsnippet.tmp > /dev/null ; then
714         echo "## begin gnulib module $module"
715         echo
716         cat amsnippet.tmp
717         echo "## end   gnulib module $module"
718         echo
719       fi
720       rm -f amsnippet.tmp
721     fi
722   done
723   echo "# Clean up after Solaris cc."
724   echo "clean-local:"
725   echo "        rm -rf SunWS_cache"
726   echo
727   echo "# Makefile.am ends here"
728 }
729
730 # func_import modules
731 # Uses also the variables
732 # - destdir         target directory
733 # - libname         library name
734 # - sourcebase      directory relative to destdir where to place source code
735 # - m4base          directory relative to destdir where to place *.m4 macros
736 # - auxdir          directory relative to destdir where to place build aux files
737 # - avoidlist       list of modules to avoid, from --avoid
738 # - lgpl            true if library's license shall be LGPL, blank otherwise
739 # - libtool         true if libtool will be used, blank otherwise
740 # - dry_run         true if actions shall only be printed, blank otherwise
741 # - symbolic        true if files should be symlinked, copied otherwise
742 # - supplied_opts   all options passed to gnulib-tool
743 func_import ()
744 {
745   modules="$1"
746   modules=`for m in $modules; do echo $m; done | sort | uniq`
747
748   # Determine final module list.
749   func_modules_transitive_closure
750   echo "Module list with included dependencies:"
751   echo "$modules" | sed -e 's/^/  /'
752
753   # If --lgpl, check the license of modules are compatible.
754   if test -n "$lgpl"; then
755     for module in $modules; do
756       license=`func_get_license $module`
757       case $license in
758         LGPL | 'public domain' | 'unlimited') ;;
759         *)
760           func_fatal_error \
761             "incompatible license on module \`$module\`: $license" ;;
762       esac
763     done
764   fi
765
766   # Determine final file list.
767   func_modules_to_filelist
768   echo "File list:"
769   echo "$files" | sed -e 's/^/  /'
770
771   test -n "$files" \
772     || func_fatal_error "refusing to do nothing"
773
774   # Copy files or make symbolic links.
775   for f in $files; do
776     source=
777     case "$f" in
778       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
779       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"`; source=true ;;
780       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
781       *) g="$f" ;;
782     esac
783     if test -z "$symbolic"; then
784       func_cp_if_changed "$gnulib_dir/$f" "$destdir/$g"
785     else
786       func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
787     fi
788     # Update license.
789     if test -z "$dry_run" && test -n "$lgpl" && test -n "$source"; then
790       perl -pi -e 's/GNU General/GNU Lesser General/g;' \
791                -e 's/version 2([ ,])/version 2.1\1/g' \
792                "$destdir/$g"
793     fi
794   done
795
796   # Commands printed in a comment in generated files.
797   cmd="gnulib-tool $supplied_opts"
798   opt_libtool=
799   if test -n "$libtool"; then
800     opt_libtool="--libtool"
801   fi
802   opt_lgpl=
803   if test -n "$lgpl"; then
804     opt_lgpl="--lgpl"
805   fi
806   actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base --aux-dir=$auxdir $opt_libtool $opt_lgpl `echo $modules`"
807
808   # Create lib/Makefile.am.
809   echo "Creating $destdir/$sourcebase/Makefile.am..."
810   if test -z "$dry_run"; then
811     func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.new
812   else
813     func_emit_lib_Makefile_am
814   fi
815   func_mv_if_changed "$destdir"/$sourcebase/Makefile.am.new \
816                      "$destdir"/$sourcebase/Makefile.am
817
818   # Create gnulib.m4.
819   echo "Creating $destdir/$m4base/gnulib.m4..."
820   (
821     if test -z "$dry_run"; then
822       exec > "$destdir"/$m4base/gnulib.m4.new
823     else
824       echo "# $destdir/$m4base/gnulib.m4"
825     fi
826     echo "# Copyright (C) 2004 Free Software Foundation, Inc."
827     echo "# This file is free software, distributed under the terms of the GNU"
828     echo "# General Public License.  As a special exception to the GNU General"
829     echo "# Public License, this file may be distributed as part of a program"
830     echo "# that contains a configuration script generated by Autoconf, under"
831     echo "# the same distribution terms as the rest of that program."
832     echo "#"
833     echo "# Generated by gnulib-tool."
834     echo "#"
835     echo "# Invoked as: $cmd"
836     echo "# Reproduce by: $actioncmd"
837     echo
838     echo "# This macro should be invoked from $configure_ac, in the section"
839     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
840     echo "# any checks for libraries, header files, types and library functions."
841     echo "AC_DEFUN([gl_EARLY],"
842     echo "["
843     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
844       echo "  AC_GNU_SOURCE"
845     fi
846     if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
847       echo "  gl_USE_SYSTEM_EXTENSIONS"
848     fi
849     echo "])"
850     echo
851     echo "# This macro should be invoked from $configure_ac, in the section"
852     echo "# \"Check for header files, types and library functions\"."
853     echo "AC_DEFUN([gl_INIT],"
854     echo "["
855     for module in $modules; do
856       func_verify_module
857       if test -n "$module"; then
858         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./'
859         if test "$module" = 'alloca' && test -n "$libtool"; then
860           echo 'changequote(,)dnl'
861           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
862           echo 'changequote([, ])dnl'
863           echo 'AC_SUBST([LTALLOCA])'
864         fi
865       fi
866     done
867     echo "])"
868     echo
869     echo "dnl Usage: gl_MODULES([module1 module2 ...])"
870     echo "AC_DEFUN([gl_MODULES], [])"
871     echo
872     echo "dnl Usage: gl_AVOID([module1 module2 ...])"
873     echo "AC_DEFUN([gl_AVOID], [])"
874     echo
875     echo "dnl Usage: gl_SOURCE_BASE([DIR])"
876     echo "AC_DEFUN([gl_SOURCE_BASE], [])"
877     echo
878     echo "dnl Usage: gl_M4_BASE([DIR])"
879     echo "AC_DEFUN([gl_M4_BASE], [])"
880     echo
881     echo "dnl Usage: gl_LIB([LIBNAME])"
882     echo "AC_DEFUN([gl_LIB], [])"
883     echo
884     echo "dnl Usage: gl_LGPL"
885     echo "AC_DEFUN([gl_LGPL], [])"
886     echo
887     echo "# gnulib.m4 ends here"
888   )
889   func_mv_if_changed "$destdir"/$m4base/gnulib.m4.new "$destdir"/$m4base/gnulib.m4
890   echo "Finished."
891   echo
892   echo "You may need to add #include directives for the following .h files."
893   for module in $modules; do
894     func_get_include_directive "$module"
895   done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/  /'
896   echo
897   echo "Don't forget to"
898   echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
899   sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
900   sourcebase_base=`basename "$sourcebase"`
901   echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
902   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
903   echo "  - invoke gl_EARLY in $configure_ac, right after AC_PROG_CC,"
904   echo "  - invoke gl_INIT in $configure_ac."
905 }
906
907 # func_create_testdir testdir modules
908 # Input:
909 # - auxdir          directory relative to destdir where to place build aux files
910 func_create_testdir ()
911 {
912   testdir="$1"
913   modules="$2"
914   modules=`for m in $modules; do echo $m; done | sort | uniq`
915
916   # Determine final module list.
917   func_modules_transitive_closure
918   echo "Module list with included dependencies:"
919   echo "$modules" | sed -e 's/^/  /'
920
921   # Determine final file list.
922   func_modules_to_filelist
923   echo "File list:"
924   echo "$files" | sed -e 's/^/  /'
925
926   # Create directories.
927   for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
928     if test "$d" = build-aux; then
929       mkdir -p "$testdir/$auxdir"
930     else
931       mkdir -p "$testdir/$d"
932     fi
933   done
934
935   # Copy files or make symbolic links.
936   for f in $files; do
937     case "$f" in
938       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
939       *) g="$f" ;;
940     esac
941     ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
942     if test -z "$symbolic"; then
943       cp -p "$gnulib_dir/$f" "$testdir/$g"
944     else
945       ln -s "$gnulib_dir/$f" "$testdir/$g"
946     fi
947   done
948
949   # Create lib/Makefile.am.
950   mkdir -p "$testdir/lib"
951   func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
952
953   # Create m4/Makefile.am.
954   mkdir -p "$testdir/m4"
955   (echo "## Process this file with automake to produce Makefile.in."
956    echo
957    echo "EXTRA_DIST ="
958    for f in $files; do
959      case "$f" in
960        m4/* )
961          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
962      esac
963    done
964   ) > "$testdir/m4/Makefile.am"
965
966   subdirs="lib m4"
967   subdirs_with_configure_ac=""
968
969   if test -f "$testdir"/m4/gettext.m4; then
970     # Avoid stupid error message from automake:
971     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
972     mkdir -p "$testdir/po"
973     (echo "## Process this file with automake to produce Makefile.in."
974     ) > "$testdir/po/Makefile.am"
975     subdirs="$subdirs po"
976   fi
977
978   if test -n "$inctests"; then
979     test -d "$testdir/tests" || mkdir "$testdir/tests"
980     # Create tests/Makefile.am.
981     sourcebase=lib
982     func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
983     # Create tests/configure.ac.
984     (echo "# Process this file with autoconf to produce a configure script."
985      echo "AC_INIT([dummy], [0])"
986      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
987      echo "AM_INIT_AUTOMAKE"
988      echo
989      echo "AM_CONFIG_HEADER([config.h])"
990      echo
991      echo "AC_PROG_CC"
992      echo "AC_PROG_INSTALL"
993      echo "AC_PROG_MAKE_SET"
994      echo "AC_PROG_RANLIB"
995      echo
996      if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
997        echo "AC_GNU_SOURCE"
998        echo
999      fi
1000      if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1001        echo "gl_USE_SYSTEM_EXTENSIONS"
1002        echo
1003      fi
1004      # We don't have explicit ordering constraints between the various
1005      # autoconf snippets. It's cleanest to put those of the library before
1006      # those of the tests.
1007      for module in $modules; do
1008        func_verify_nontests_module
1009        if test -n "$module"; then
1010          func_get_autoconf_snippet "$module"
1011        fi
1012      done
1013      for module in $modules; do
1014        func_verify_tests_module
1015        if test -n "$module"; then
1016          func_get_autoconf_snippet "$module"
1017        fi
1018      done
1019      echo
1020      # Usually tests/config.h will be a superset of config.h. Verify this by
1021      # "merging" config.h into tests/config.h; look out for gcc warnings.
1022      echo "AH_TOP([#include \"../config.h\"])"
1023      echo
1024      echo "AC_OUTPUT([Makefile])"
1025     ) > "$testdir/tests/configure.ac"
1026     subdirs="$subdirs tests"
1027     subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1028   fi
1029
1030   # Create Makefile.am.
1031   (echo "## Process this file with automake to produce Makefile.in."
1032    echo
1033    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1034    echo
1035    echo "SUBDIRS = $subdirs"
1036    echo
1037    echo "ACLOCAL_AMFLAGS = -I m4"
1038   ) > "$testdir/Makefile.am"
1039
1040   # Create configure.ac.
1041   (echo "# Process this file with autoconf to produce a configure script."
1042    echo "AC_INIT([dummy], [0])"
1043    if test "$auxdir" != "."; then
1044      echo "AC_CONFIG_AUX_DIR([$auxdir])"
1045    fi
1046    echo "AM_INIT_AUTOMAKE"
1047    echo
1048    echo "AM_CONFIG_HEADER([config.h])"
1049    echo
1050    echo "AC_PROG_CC"
1051    echo "AC_PROG_INSTALL"
1052    echo "AC_PROG_MAKE_SET"
1053    echo "AC_PROG_RANLIB"
1054    echo
1055    if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1056      echo "AC_GNU_SOURCE"
1057      echo
1058    fi
1059    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1060      echo "gl_USE_SYSTEM_EXTENSIONS"
1061      echo
1062    fi
1063    for module in $modules; do
1064      func_verify_nontests_module
1065      if test -n "$module"; then
1066        func_get_autoconf_snippet "$module"
1067      fi
1068    done
1069    echo
1070    if test -n "$subdirs_with_configure_ac"; then
1071      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1072    fi
1073    makefiles="Makefile"
1074    for d in $subdirs; do
1075      # For subdirs that have a configure.ac by their own, it's the subdir's
1076      # configure.ac which creates the subdir's Makefile.am, not this one.
1077      case " $subdirs_with_configure_ac " in
1078        *" $d "*) ;;
1079        *) makefiles="$makefiles $d/Makefile" ;;
1080      esac
1081    done
1082    echo "AC_OUTPUT([$makefiles])"
1083   ) > "$testdir/configure.ac"
1084
1085   # Create autogenerated files.
1086   (cd "$testdir"
1087    echo "executing ${AUTORECONF} --force --install"
1088    ${AUTORECONF} --force --install
1089   )
1090   if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1091     (cd "$testdir"
1092      ./configure
1093        cd lib
1094        built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
1095        if test -n "$built_sources"; then
1096          make $built_sources
1097        fi
1098        cd ..
1099      make distclean
1100     )
1101   fi
1102 }
1103
1104 # func_create_megatestdir megatestdir allmodules
1105 # Input:
1106 # - auxdir          directory relative to destdir where to place build aux files
1107 func_create_megatestdir ()
1108 {
1109   megatestdir="$1"
1110   allmodules="$2"
1111   if test -z "$allmodules"; then
1112     allmodules=`func_all_modules`
1113   fi
1114
1115   megasubdirs=
1116   # First, all modules one by one.
1117   for onemodule in $allmodules; do
1118     func_create_testdir "$megatestdir/$onemodule" $onemodule
1119     megasubdirs="${megasubdirs}$onemodule "
1120   done
1121   # Then, all modules all together.
1122   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1123   allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1124   func_create_testdir "$megatestdir/ALL" "$allmodules"
1125   megasubdirs="${megasubdirs}ALL"
1126
1127   # Create Makefile.am.
1128   (echo "## Process this file with automake to produce Makefile.in."
1129    echo
1130    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1131    echo
1132    echo "SUBDIRS = $megasubdirs"
1133   ) > "$megatestdir/Makefile.am"
1134
1135   # Create configure.ac.
1136   (echo "# Process this file with autoconf to produce a configure script."
1137    echo "AC_INIT([dummy], [0])"
1138    if test "$auxdir" != "."; then
1139      echo "AC_CONFIG_AUX_DIR([$auxdir])"
1140    fi
1141    echo "AM_INIT_AUTOMAKE"
1142    echo
1143    echo "AC_PROG_MAKE_SET"
1144    echo
1145    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1146    echo "AC_OUTPUT([Makefile])"
1147   ) > "$megatestdir/configure.ac"
1148
1149   # Create autogenerated files.
1150   (cd "$megatestdir"
1151    echo "executing ${AUTORECONF} --install"
1152    ${AUTORECONF} --install
1153   )
1154 }
1155
1156 case $mode in
1157   "" )
1158     func_fatal_error "no mode specified" ;;
1159
1160   list )
1161     func_all_modules
1162     ;;
1163
1164   import )
1165     # Where to import.
1166     if test -z "$destdir"; then
1167       destdir=.
1168     fi
1169     test -d "$destdir" \
1170       || func_fatal_error "destination directory does not exist: $destdir"
1171
1172     # Prefer configure.ac to configure.in
1173     test -f "$destdir"/configure.in && configure_ac="$destdir/configure.in"
1174     test -f "$destdir"/configure.ac && configure_ac="$destdir/configure.ac"
1175     test -f "$configure_ac" \
1176       || func_fatal_error "cannot find $destdir/configure.ac"
1177
1178     # Get settings.
1179     my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
1180       /gl_MODULES[^_]/  {
1181         s,^.*gl_MODULES([[   ]*\([^])]*\).*$,ac_modules="\1",; p;
1182       };
1183       /gl_AVOID[^_]/  {
1184         s,^.*gl_AVOID([[   ]*\([^])]*\).*$,ac_avoidlist="\1",; p;
1185       };
1186       /gl_SOURCE_BASE/   {
1187         s,^.*gl_SOURCE_BASE([[         ]*\([^])]*\).*$,ac_sourcebase="\1",; p;
1188       };
1189       /gl_M4_BASE/   {
1190         s,^.*gl_M4_BASE([[         ]*\([^])]*\).*$,ac_m4base="\1",; p;
1191       };
1192       /gl_LIB/   {
1193         s,^.*gl_LIB([[         ]*\([^])]*\).*$,ac_libname="\1",; p;
1194       };
1195       /AC_CONFIG_AUX_DIR/  {
1196         s,^.*AC_CONFIG_AUX_DIR([[         ]*\([^])]*\).*$,ac_auxdir="\1",; p;
1197       }
1198       /A[CM]_PROG_LIBTOOL/ { s,^.*$,seen_libtool=:,; p; };
1199       /LT_INIT/            { s,^.*$,seen_libtool=:,; p; };
1200       /gl_LGPL/            { s,^.*$,lgpl=true,; p; };
1201       d;'
1202     eval `cat $configure_ac | sed "$my_sed_traces"`
1203
1204     # Override libname?
1205     if test -z "$supplied_libname" && test -n "$ac_libname"; then
1206       libname="$ac_libname"
1207     fi
1208
1209     # Set up source base.
1210     test -z "$sourcebase" && sourcebase="$ac_sourcebase"
1211     test -z "$sourcebase" && sourcebase="lib"
1212     test -d "$destdir/$sourcebase" \
1213       || { test -z "$dry_run" && mkdir "$destdir/$sourcebase"; } \
1214       || func_fatal_error "source base $destdir/$sourcebase doesn't exist"
1215
1216     # Set up m4 base.
1217     test -z "$m4base" && m4base="$ac_m4base"
1218     test -z "$m4base" && m4base="m4"
1219     test -d "$destdir/$m4base" \
1220       || { test -z "$dry_run" && mkdir "$destdir/$m4base"; } \
1221       || func_fatal_error "m4 base $destdir/$m4base doesn't exist"
1222
1223     # Set up auxiliary directory.
1224     test -z "$auxdir" && auxdir="$ac_auxdir"
1225     test -z "$auxdir" && auxdir="build-aux"
1226     test -d "$destdir/$auxdir" \
1227       || { test -z "$dry_run" && mkdir "$destdir/$auxdir"; } \
1228       || func_fatal_error "aux directory $destdir/$auxdir doesn't exist"
1229
1230     # Using libtool?
1231     if test -n "$seen_libtool"; then
1232       libtool=true
1233     fi
1234
1235     # What modules to extract.
1236     if test $# = 0; then
1237       modules="$ac_modules"
1238     else
1239       modules="$*"
1240     fi
1241
1242     # Which modules to avoid?
1243     avoidlist=`echo $avoidlist $ac_avoidlist`
1244
1245     func_import "$modules"
1246     ;;
1247
1248   create-testdir )
1249     if test -z "$destdir"; then
1250       func_fatal_error "please specify --dir option"
1251     fi
1252     mkdir "$destdir"
1253     test -d "$destdir" \
1254       || func_fatal_error "could not create destination directory"
1255     test -n "$auxdir" || auxdir="build-aux"
1256     func_create_testdir "$destdir" "$*"
1257     ;;
1258
1259   create-megatestdir )
1260     if test -z "$destdir"; then
1261       func_fatal_error "please specify --dir option"
1262     fi
1263     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1264     test -n "$auxdir" || auxdir="build-aux"
1265     func_create_megatestdir "$destdir" "$*"
1266     ;;
1267
1268   test )
1269     test -n "$destdir" || destdir=testdir$$
1270     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1271     test -n "$auxdir" || auxdir="build-aux"
1272     func_create_testdir "$destdir" "$*"
1273     cd "$destdir"
1274       mkdir build
1275       cd build
1276         ../configure
1277         make
1278         make check
1279         make distclean
1280         remaining=`find . -type f -print`
1281         if test -n "$remaining"; then
1282           echo "Remaining files:" $remaining 1>&2
1283           echo "gnulib-tool: *** Stop." 1>&2
1284           exit 1
1285         fi
1286       cd ..
1287     cd ..
1288     rm -rf "$destdir"
1289     ;;
1290
1291   megatest )
1292     test -n "$destdir" || destdir=testdir$$
1293     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1294     test -n "$auxdir" || auxdir="build-aux"
1295     func_create_megatestdir "$destdir" "$*"
1296     cd "$destdir"
1297       mkdir build
1298       cd build
1299         ../configure
1300         make
1301         make check
1302         make distclean
1303         remaining=`find . -type f -print`
1304         if test -n "$remaining"; then
1305           echo "Remaining files:" $remaining 1>&2
1306           echo "gnulib-tool: *** Stop." 1>&2
1307           exit 1
1308         fi
1309       cd ..
1310     cd ..
1311     rm -rf "$destdir"
1312     ;;
1313
1314   extract-description )
1315     for module
1316     do
1317       func_verify_module
1318       if test -n "$module"; then
1319         func_get_description "$module"
1320       fi
1321     done
1322     ;;
1323
1324   extract-filelist )
1325     for module
1326     do
1327       func_verify_module
1328       if test -n "$module"; then
1329         func_get_filelist "$module"
1330       fi
1331     done
1332     ;;
1333
1334   extract-dependencies )
1335     for module
1336     do
1337       func_verify_module
1338       if test -n "$module"; then
1339         func_get_dependencies "$module"
1340       fi
1341     done
1342     ;;
1343
1344   extract-autoconf-snippet )
1345     for module
1346     do
1347       func_verify_module
1348       if test -n "$module"; then
1349         func_get_autoconf_snippet "$module"
1350       fi
1351     done
1352     ;;
1353
1354   extract-automake-snippet )
1355     for module
1356     do
1357       func_verify_module
1358       if test -n "$module"; then
1359         func_get_automake_snippet "$module"
1360       fi
1361     done
1362     ;;
1363
1364   extract-include-directive )
1365     for module
1366     do
1367       func_verify_module
1368       if test -n "$module"; then
1369         func_get_include_directive "$module"
1370       fi
1371     done
1372     ;;
1373
1374   extract-license )
1375     for module
1376     do
1377       func_verify_module
1378       if test -n "$module"; then
1379         func_get_license "$module"
1380       fi
1381     done
1382     ;;
1383
1384   extract-maintainer )
1385     for module
1386     do
1387       func_verify_module
1388       if test -n "$module"; then
1389         func_get_maintainer "$module"
1390       fi
1391     done
1392     ;;
1393
1394   extract-tests-module )
1395     for module
1396     do
1397       func_verify_module
1398       if test -n "$module"; then
1399         func_get_tests_module "$module"
1400       fi
1401     done
1402     ;;
1403
1404   * )
1405     func_fatal_error "unknown operation mode --$mode" ;;
1406 esac
1407
1408 exit 0