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