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