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