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