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