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