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