Make --update option actually work.
[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-05-02 14:31:00 $'
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 "$supplied_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   (
1457    # First the #include <...> directives without #ifs, sorted for convenience.
1458    for module in $modules; do
1459      if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1460        :
1461      else
1462        func_get_include_directive "$module" | grep -v 'include "'
1463      fi
1464    done | LC_ALL=C sort -u
1465    # Then the #include "..." directives without #ifs, sorted for convenience.
1466    for module in $modules; do
1467      if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1468        :
1469      else
1470        func_get_include_directive "$module" | grep 'include "'
1471      fi
1472    done | LC_ALL=C sort -u
1473    # Then the #include directives that are surrounded by #ifs. Not sorted.
1474    for module in $modules; do
1475      if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1476        func_get_include_directive "$module"
1477      fi
1478    done
1479   ) | sed -e '/^$/d;' -e 's/^/  /'
1480   echo
1481   echo "Don't forget to"
1482   echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1483   if test -n "$inctests"; then
1484     echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1485   fi
1486   sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1487   sourcebase_base=`basename "$sourcebase"`
1488   echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1489   if test -n "$inctests"; then
1490     testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1491     testsbase_base=`basename "$testsbase"`
1492     echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1493   fi
1494   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1495   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1496   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
1497 }
1498
1499 # func_create_testdir testdir modules
1500 # Input:
1501 # - auxdir          directory relative to destdir where to place build aux files
1502 func_create_testdir ()
1503 {
1504   testdir="$1"
1505   modules="$2"
1506   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1507
1508   # Determine final module list.
1509   func_modules_transitive_closure
1510   echo "Module list with included dependencies:"
1511   echo "$modules" | sed -e 's/^/  /'
1512
1513   # Add the dummy module if needed.
1514   func_modules_add_dummy
1515
1516   # Determine final file list.
1517   func_modules_to_filelist
1518   echo "File list:"
1519   echo "$files" | sed -e 's/^/  /'
1520
1521   # Create directories.
1522   for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1523     if test "$d" = build-aux; then
1524       mkdir -p "$testdir/$auxdir"
1525     else
1526       mkdir -p "$testdir/$d"
1527     fi
1528   done
1529
1530   # Copy files or make symbolic links.
1531   for f in $files; do
1532     case "$f" in
1533       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1534       *) g="$f" ;;
1535     esac
1536     ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1537     if test -z "$symbolic"; then
1538       cp -p "$gnulib_dir/$f" "$testdir/$g"
1539     else
1540       ln -s "$gnulib_dir/$f" "$testdir/$g"
1541     fi
1542   done
1543
1544   # Create lib/Makefile.am.
1545   mkdir -p "$testdir/lib"
1546   func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1547
1548   # Create m4/Makefile.am.
1549   mkdir -p "$testdir/m4"
1550   (echo "## Process this file with automake to produce Makefile.in."
1551    echo
1552    echo "EXTRA_DIST ="
1553    for f in $files; do
1554      case "$f" in
1555        m4/* )
1556          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1557      esac
1558    done
1559   ) > "$testdir/m4/Makefile.am"
1560
1561   subdirs="lib m4"
1562   subdirs_with_configure_ac=""
1563
1564   if test -f "$testdir"/m4/gettext.m4; then
1565     # Avoid stupid error message from automake:
1566     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1567     mkdir -p "$testdir/po"
1568     (echo "## Process this file with automake to produce Makefile.in."
1569     ) > "$testdir/po/Makefile.am"
1570     subdirs="$subdirs po"
1571   fi
1572
1573   if test -n "$inctests"; then
1574     test -d "$testdir/tests" || mkdir "$testdir/tests"
1575     # Create tests/Makefile.am.
1576     sourcebase=lib
1577     m4base=m4
1578     testsbase=tests
1579     func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1580     # Create tests/configure.ac.
1581     (echo "# Process this file with autoconf to produce a configure script."
1582      echo "AC_INIT([dummy], [0])"
1583      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1584      echo "AM_INIT_AUTOMAKE"
1585      echo
1586      echo "AM_CONFIG_HEADER([config.h])"
1587      echo
1588      echo "AC_PROG_CC"
1589      echo "AC_PROG_INSTALL"
1590      echo "AC_PROG_MAKE_SET"
1591      echo "AC_PROG_RANLIB"
1592      echo
1593      if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1594        echo "AC_GNU_SOURCE"
1595        echo
1596      fi
1597      if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1598        echo "gl_USE_SYSTEM_EXTENSIONS"
1599        echo
1600      fi
1601      if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1602        echo "gl_LOCK"
1603        echo
1604      fi
1605      if test -z "$libtool"; then
1606        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1607      else
1608        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1609      fi
1610      if test "$auxdir" != "build-aux"; then
1611        sed_replace_build_aux='
1612          :a
1613          /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1614            s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1615            ba
1616          }'
1617        sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1618      else
1619        sed_replace_build_aux=
1620      fi
1621      # We don't have explicit ordering constraints between the various
1622      # autoconf snippets. It's cleanest to put those of the library before
1623      # those of the tests.
1624      for module in $modules; do
1625        func_verify_nontests_module
1626        if test -n "$module"; then
1627          func_get_autoconf_snippet "$module" \
1628            | sed -e "$sed_replace_build_aux"
1629        fi
1630      done
1631      for module in $modules; do
1632        func_verify_tests_module
1633        if test -n "$module"; then
1634          func_get_autoconf_snippet "$module" \
1635            | sed -e "$sed_replace_build_aux"
1636        fi
1637      done
1638      echo
1639      # Usually tests/config.h will be a superset of config.h. Verify this by
1640      # "merging" config.h into tests/config.h; look out for gcc warnings.
1641      echo "AH_TOP([#include \"../config.h\"])"
1642      echo
1643      echo "AC_OUTPUT([Makefile])"
1644     ) > "$testdir/tests/configure.ac"
1645     subdirs="$subdirs tests"
1646     subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1647   fi
1648
1649   # Create Makefile.am.
1650   (echo "## Process this file with automake to produce Makefile.in."
1651    echo
1652    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1653    echo
1654    echo "SUBDIRS = $subdirs"
1655    echo
1656    echo "ACLOCAL_AMFLAGS = -I m4"
1657   ) > "$testdir/Makefile.am"
1658
1659   # Create configure.ac.
1660   (echo "# Process this file with autoconf to produce a configure script."
1661    echo "AC_INIT([dummy], [0])"
1662    if test "$auxdir" != "."; then
1663      echo "AC_CONFIG_AUX_DIR([$auxdir])"
1664    fi
1665    echo "AM_INIT_AUTOMAKE"
1666    echo
1667    echo "AM_CONFIG_HEADER([config.h])"
1668    echo
1669    echo "AC_PROG_CC"
1670    echo "AC_PROG_INSTALL"
1671    echo "AC_PROG_MAKE_SET"
1672    echo "AC_PROG_RANLIB"
1673    echo
1674    if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1675      echo "AC_GNU_SOURCE"
1676      echo
1677    fi
1678    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1679      echo "gl_USE_SYSTEM_EXTENSIONS"
1680      echo
1681    fi
1682    if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1683      echo "gl_LOCK"
1684      echo
1685    fi
1686    if test -z "$libtool"; then
1687      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1688    else
1689      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1690    fi
1691    if test "$auxdir" != "build-aux"; then
1692      sed_replace_build_aux='
1693        :a
1694        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1695          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1696          ba
1697        }'
1698      sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1699    else
1700      sed_replace_build_aux=
1701    fi
1702    for module in $modules; do
1703      func_verify_nontests_module
1704      if test -n "$module"; then
1705        func_get_autoconf_snippet "$module" \
1706          | sed -e "$sed_replace_build_aux"
1707      fi
1708    done
1709    echo
1710    if test -n "$subdirs_with_configure_ac"; then
1711      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1712    fi
1713    makefiles="Makefile"
1714    for d in $subdirs; do
1715      # For subdirs that have a configure.ac by their own, it's the subdir's
1716      # configure.ac which creates the subdir's Makefile.am, not this one.
1717      case " $subdirs_with_configure_ac " in
1718        *" $d "*) ;;
1719        *) makefiles="$makefiles $d/Makefile" ;;
1720      esac
1721    done
1722    echo "AC_OUTPUT([$makefiles])"
1723   ) > "$testdir/configure.ac"
1724
1725   # Create autogenerated files.
1726   (cd "$testdir"
1727    echo "executing ${AUTORECONF} --force --install"
1728    ${AUTORECONF} --force --install
1729   )
1730   if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1731     (cd "$testdir"
1732      ./configure
1733        cd lib
1734        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1735        make built_sources
1736        cd ..
1737      make distclean
1738     )
1739   fi
1740 }
1741
1742 # func_create_megatestdir megatestdir allmodules
1743 # Input:
1744 # - auxdir          directory relative to destdir where to place build aux files
1745 func_create_megatestdir ()
1746 {
1747   megatestdir="$1"
1748   allmodules="$2"
1749   if test -z "$allmodules"; then
1750     allmodules=`func_all_modules`
1751   fi
1752
1753   megasubdirs=
1754   # First, all modules one by one.
1755   for onemodule in $allmodules; do
1756     func_create_testdir "$megatestdir/$onemodule" $onemodule
1757     megasubdirs="${megasubdirs}$onemodule "
1758   done
1759   # Then, all modules all together.
1760   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1761   allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1762   func_create_testdir "$megatestdir/ALL" "$allmodules"
1763   megasubdirs="${megasubdirs}ALL"
1764
1765   # Create Makefile.am.
1766   (echo "## Process this file with automake to produce Makefile.in."
1767    echo
1768    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1769    echo
1770    echo "SUBDIRS = $megasubdirs"
1771   ) > "$megatestdir/Makefile.am"
1772
1773   # Create configure.ac.
1774   (echo "# Process this file with autoconf to produce a configure script."
1775    echo "AC_INIT([dummy], [0])"
1776    if test "$auxdir" != "."; then
1777      echo "AC_CONFIG_AUX_DIR([$auxdir])"
1778    fi
1779    echo "AM_INIT_AUTOMAKE"
1780    echo
1781    echo "AC_PROG_MAKE_SET"
1782    echo
1783    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1784    echo "AC_OUTPUT([Makefile])"
1785   ) > "$megatestdir/configure.ac"
1786
1787   # Create autogenerated files.
1788   (cd "$megatestdir"
1789    # Do not use "${AUTORECONF} --install", because autoreconf operates
1790    # recursively, but the subdirectories are already finished, therefore
1791    # calling autoreconf here would only waste lots of CPU time.
1792    echo "executing ${ACLOCAL}"
1793    ${ACLOCAL}
1794    echo "executing mkdir build-aux"
1795    mkdir build-aux
1796    echo "executing ${AUTOCONF}"
1797    ${AUTOCONF}
1798    echo "executing ${AUTOMAKE} --add-missing --copy"
1799    ${AUTOMAKE} --add-missing --copy
1800   )
1801 }
1802
1803 case $mode in
1804   "" )
1805     func_fatal_error "no mode specified" ;;
1806
1807   list )
1808     func_all_modules
1809     ;;
1810
1811   import | update )
1812     
1813     # Where to import.
1814     if test -z "$destdir"; then
1815       destdir=.
1816     fi
1817     test -d "$destdir" \
1818       || func_fatal_error "destination directory does not exist: $destdir"
1819
1820     # Prefer configure.ac to configure.in.
1821     if test -f "$destdir"/configure.ac; then
1822       configure_ac="$destdir/configure.ac"
1823     else
1824       if test -f "$destdir"/configure.in; then
1825         configure_ac="$destdir/configure.in"
1826       else
1827         func_fatal_error "cannot find $destdir/configure.ac"
1828       fi
1829     fi
1830
1831     test -f "$destdir"/Makefile.am \
1832       || func_fatal_error "cannot find $destdir/Makefile.am"
1833
1834     # Analyze configure.ac.
1835     guessed_auxdir="."
1836     guessed_libtool=
1837     my_sed_traces='
1838       s,#.*$,,
1839       s,^dnl .*$,,
1840       s, dnl .*$,,
1841       /AC_CONFIG_AUX_DIR/ {
1842         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1843       }
1844       /A[CM]_PROG_LIBTOOL/ {
1845         s,^.*$,guessed_libtool=true,p
1846       }'
1847     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1848
1849     if test -z "$auxdir"; then
1850       auxdir="$guessed_auxdir"
1851     fi
1852
1853     # Determine where to apply func_import.
1854     if test -n "$m4base"; then
1855       # Apply func_import to a particular gnulib directory.
1856       # Any number of additional modules can be given.
1857       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1858         # First use of gnulib in the given m4base.
1859         test -n "$supplied_libname" || supplied_libname=true
1860         test -n "$sourcebase" || sourcebase="lib"
1861         test -n "$testsbase" || testsbase="tests"
1862         test -n "$macro_prefix" || macro_prefix="gl"
1863       fi
1864       func_import "$*"
1865     else
1866       # Apply func_import to all gnulib directories.
1867       # To get this list of directories, look at Makefile.am. (Not at
1868       # configure, because it may be omitted from CVS. Also, don't run
1869       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1870       aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[  ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[       ]*=\(.*\)$/\1/'`
1871       m4dirs=
1872       m4dirs_count=0
1873       m4dir_is_next=
1874       for arg in $aclocal_amflags; do
1875         if test -n "$m4dir_is_next"; then
1876           # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1877           case "$arg" in
1878             /*) ;;
1879             *)
1880               if test -f "$destdir/$arg"/gnulib-cache.m4; then
1881                 m4dirs="$m4dirs $arg"
1882                 m4dirs_count=`expr $m4dirs_count + 1`
1883               fi
1884               ;;
1885           esac
1886         else
1887           if test "X$arg" = "X-I"; then
1888             m4dir_is_next=yes
1889           else
1890             m4dir_is_next=
1891           fi
1892         fi
1893       done
1894       if test $m4dirs_count = 0; then
1895         # First use of gnulib in a package.
1896         # Any number of additional modules can be given.
1897         test -n "$supplied_libname" || supplied_libname=true
1898         test -n "$sourcebase" || sourcebase="lib"
1899         m4base="m4"
1900         test -n "$testsbase" || testsbase="tests"
1901         test -n "$macro_prefix" || macro_prefix="gl"
1902         func_import "$*"
1903       else
1904         if test $m4dirs_count = 1; then
1905           # There's only one use of gnulib here. Assume the user means it.
1906           # Any number of additional modules can be given.
1907           for m4base in $m4dirs; do
1908             func_import "$*"
1909           done
1910         else
1911           # Ambiguous - guess what the user meant.
1912           if test $# = 0; then
1913             # No further arguments. Guess the user wants to update all of them.
1914             for m4base in $m4dirs; do
1915               func_import
1916             done
1917           else
1918             # Really ambiguous.
1919             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1920           fi
1921         fi
1922       fi
1923     fi
1924     ;;
1925
1926   create-testdir )
1927     if test -z "$destdir"; then
1928       func_fatal_error "please specify --dir option"
1929     fi
1930     mkdir "$destdir"
1931     test -d "$destdir" \
1932       || func_fatal_error "could not create destination directory"
1933     test -n "$auxdir" || auxdir="build-aux"
1934     func_create_testdir "$destdir" "$*"
1935     ;;
1936
1937   create-megatestdir )
1938     if test -z "$destdir"; then
1939       func_fatal_error "please specify --dir option"
1940     fi
1941     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1942     test -n "$auxdir" || auxdir="build-aux"
1943     func_create_megatestdir "$destdir" "$*"
1944     ;;
1945
1946   test )
1947     test -n "$destdir" || destdir=testdir$$
1948     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1949     test -n "$auxdir" || auxdir="build-aux"
1950     func_create_testdir "$destdir" "$*"
1951     cd "$destdir"
1952       mkdir build
1953       cd build
1954         ../configure
1955         make
1956         make check
1957         make distclean
1958         remaining=`find . -type f -print`
1959         if test -n "$remaining"; then
1960           echo "Remaining files:" $remaining 1>&2
1961           echo "gnulib-tool: *** Stop." 1>&2
1962           exit 1
1963         fi
1964       cd ..
1965     cd ..
1966     rm -rf "$destdir"
1967     ;;
1968
1969   megatest )
1970     test -n "$destdir" || destdir=testdir$$
1971     mkdir "$destdir" || func_fatal_error "could not create destination directory"
1972     test -n "$auxdir" || auxdir="build-aux"
1973     func_create_megatestdir "$destdir" "$*"
1974     cd "$destdir"
1975       mkdir build
1976       cd build
1977         ../configure
1978         make
1979         make check
1980         make distclean
1981         remaining=`find . -type f -print`
1982         if test -n "$remaining"; then
1983           echo "Remaining files:" $remaining 1>&2
1984           echo "gnulib-tool: *** Stop." 1>&2
1985           exit 1
1986         fi
1987       cd ..
1988     cd ..
1989     rm -rf "$destdir"
1990     ;;
1991
1992   extract-description )
1993     for module
1994     do
1995       func_verify_module
1996       if test -n "$module"; then
1997         func_get_description "$module"
1998       fi
1999     done
2000     ;;
2001
2002   extract-filelist )
2003     for module
2004     do
2005       func_verify_module
2006       if test -n "$module"; then
2007         func_get_filelist "$module"
2008       fi
2009     done
2010     ;;
2011
2012   extract-dependencies )
2013     for module
2014     do
2015       func_verify_module
2016       if test -n "$module"; then
2017         func_get_dependencies "$module"
2018       fi
2019     done
2020     ;;
2021
2022   extract-autoconf-snippet )
2023     for module
2024     do
2025       func_verify_module
2026       if test -n "$module"; then
2027         func_get_autoconf_snippet "$module"
2028       fi
2029     done
2030     ;;
2031
2032   extract-automake-snippet )
2033     for module
2034     do
2035       func_verify_module
2036       if test -n "$module"; then
2037         func_get_automake_snippet "$module"
2038       fi
2039     done
2040     ;;
2041
2042   extract-include-directive )
2043     for module
2044     do
2045       func_verify_module
2046       if test -n "$module"; then
2047         func_get_include_directive "$module"
2048       fi
2049     done
2050     ;;
2051
2052   extract-license )
2053     for module
2054     do
2055       func_verify_module
2056       if test -n "$module"; then
2057         func_get_license "$module"
2058       fi
2059     done
2060     ;;
2061
2062   extract-maintainer )
2063     for module
2064     do
2065       func_verify_module
2066       if test -n "$module"; then
2067         func_get_maintainer "$module"
2068       fi
2069     done
2070     ;;
2071
2072   extract-tests-module )
2073     for module
2074     do
2075       func_verify_module
2076       if test -n "$module"; then
2077         func_get_tests_module "$module"
2078       fi
2079     done
2080     ;;
2081
2082   * )
2083     func_fatal_error "unknown operation mode --$mode" ;;
2084 esac
2085
2086 exit 0