(func_all_modules): Exclude all .* files (e.g., Emacs .#* auto-save files).
[gnulib.git] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2007 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: 2007-01-11 13:28:50 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
28 nl='
29 '
30
31 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
32 AUTOCONFPATH=
33 #case $USER in
34 #  bruno )
35 #    AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
36 #    AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
37 #    ;;
38 #esac
39
40 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
41 AUTOMAKEPATH=
42
43 # You can set GETTEXTPATH to empty if autopoint 0.15 is already in your PATH.
44 GETTEXTPATH=
45
46 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
47 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
48 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
49   AUTOCONF="${AUTOCONFPATH}autoconf"
50 fi
51 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
52   AUTOHEADER="${AUTOCONFPATH}autoheader"
53 fi
54 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
55   ACLOCAL="${AUTOMAKEPATH}aclocal"
56 fi
57 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
58   AUTOMAKE="${AUTOMAKEPATH}automake"
59 fi
60 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
61   AUTORECONF="${AUTOCONFPATH}autoreconf"
62 fi
63
64 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
65 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
66   AUTOPOINT="${GETTEXTPATH}autopoint"
67 fi
68
69 # When using GNU sed, turn off as many GNU extensions as possible,
70 # to minimize the risk of accidentally using non-portable features.
71 # However, do this only for gnulib-tool itself, not for the code that
72 # gnulib-tool generates, since we don't want "sed --posix" to leak
73 # into makefiles.
74 if (alias) > /dev/null 2>&1 && echo | sed --posix d >/dev/null 2>&1; then
75   alias sed='sed --posix'
76 fi
77
78 # func_usage
79 # outputs to stdout the --help usage message.
80 func_usage ()
81 {
82   echo "\
83 Usage: gnulib-tool --list
84        gnulib-tool --import [module1 ... moduleN]
85        gnulib-tool --update
86        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
87        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
88        gnulib-tool --test --dir=directory module1 ... moduleN
89        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
90        gnulib-tool --extract-description module
91        gnulib-tool --extract-filelist module
92        gnulib-tool --extract-dependencies module
93        gnulib-tool --extract-autoconf-snippet module
94        gnulib-tool --extract-automake-snippet module
95        gnulib-tool --extract-include-directive module
96        gnulib-tool --extract-license module
97        gnulib-tool --extract-maintainer module
98        gnulib-tool --extract-tests-module module
99
100 Operation modes:
101       --list                print the available module names
102       --import              import the given modules into the current package;
103                             if no modules are specified, update the current
104                             package from the current gnulib
105       --update              update the current package, restore files omitted
106                             from CVS
107       --create-testdir      create a scratch package with the given modules
108       --create-megatestdir  create a mega scratch package with the given modules
109                             one by one and all together
110       --test                test the combination of the given modules
111                             (recommended to use CC=\"gcc -Wall\" here)
112       --megatest            test the given modules one by one and all together
113                             (recommended to use CC=\"gcc -Wall\" here)
114       --extract-description        extract the description
115       --extract-filelist           extract the list of files
116       --extract-dependencies       extract the dependencies
117       --extract-autoconf-snippet   extract the snippet for configure.ac
118       --extract-automake-snippet   extract the snippet for library makefile
119       --extract-include-directive  extract the #include directive
120       --extract-license            report the license terms of the source files
121                                    under lib/
122       --extract-maintainer         report the maintainer(s) inside gnulib
123       --extract-tests-module       report the unit test module, if it exists
124
125 General options:
126       --dir=DIRECTORY       Specify the target directory.
127                             For --import, this specifies where your
128                             configure.ac can be found.  Defaults to current
129                             directory.
130       --local-dir=DIRECTORY  Specify a local override directory where to look
131                             up files before looking in gnulib's directory.
132
133 Options for --import:
134       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
135       --source-base=DIRECTORY
136                             Directory relative to --dir where source code is
137                             placed (default \"lib\").
138       --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
139                             placed (default \"m4\").
140       --doc-base=DIRECTORY  Directory relative to --dir where doc files are
141                             placed (default \"doc\").
142       --tests-base=DIRECTORY
143                             Directory relative to --dir where unit tests are
144                             placed (default \"tests\").
145       --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
146                             tools are placed (default \"build-aux\").
147       --with-tests          Include unit tests for the included modules.
148       --avoid=MODULE        Avoid including the given MODULE. Useful if you
149                             have code that provides equivalent functionality.
150                             This option can be repeated.
151       --lgpl                Abort if modules aren't available under the LGPL.
152                             Also modify license template from GPL to LGPL.
153       --makefile-name=NAME  Name of makefile in automake syntax in the
154                             source-base and tests-base directories
155                             (default \"Makefile.am\").
156       --libtool             Use libtool rules.
157       --no-libtool          Don't use libtool rules.
158       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
159                             'gl_INIT'. Default is 'gl'.
160       --no-changelog        don't update or create ChangeLog files
161
162 Options for --import and --update:
163       --dry-run             For --import, only print what would have been done.
164   -s, --symbolic, --symlink Make symbolic links instead of copying files.
165       --local-symlink       Make symbolic links instead of copying files, only
166                             for files from the local override directory.
167
168 Report bugs to <bug-gnulib@gnu.org>."
169 }
170
171 # func_version
172 # outputs to stdout the --version message.
173 func_version ()
174 {
175   year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
176   echo "\
177 $progname (GNU $package) $version
178 Copyright (C) $year Free Software Foundation, Inc.
179 This is free software; see the source for copying conditions.  There is NO
180 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
181 Written by" "Bruno Haible" "and" "Simon Josefsson"
182 }
183
184 # func_emit_copyright_notice
185 # outputs to stdout a header for a generated file.
186 func_emit_copyright_notice ()
187 {
188   echo "# Copyright (C) 2004-2007 Free Software Foundation, Inc."
189   echo "#"
190   echo "# This file is free software, distributed under the terms of the GNU"
191   echo "# General Public License.  As a special exception to the GNU General"
192   echo "# Public License, this file may be distributed as part of a program"
193   echo "# that contains a configuration script generated by Autoconf, under"
194   echo "# the same distribution terms as the rest of that program."
195   echo "#"
196   echo "# Generated by gnulib-tool."
197 }
198
199 # func_exit STATUS
200 # exit with status
201 func_exit ()
202 {
203   (exit $1); exit $1
204 }
205
206 # func_tmpdir
207 # creates a temporary directory.
208 # Sets variable
209 # - tmp             pathname of freshly created temporary directory
210 func_tmpdir ()
211 {
212   # Use the environment variable TMPDIR, falling back to /tmp. This allows
213   # users to specify a different temporary directory, for example, if their
214   # /tmp is filled up or too small.
215   : ${TMPDIR=/tmp}
216   {
217     # Use the mktemp program if available. If not available, hide the error
218     # message.
219     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
220     test -n "$tmp" && test -d "$tmp"
221   } ||
222   {
223     # Use a simple mkdir command. It is guaranteed to fail if the directory
224     # already exists.  $RANDOM is bash specific and expands to empty in shells
225     # other than bash, ksh and zsh.  Its use does not increase security;
226     # rather, it minimizes the probability of failure in a very cluttered /tmp
227     # directory.
228     tmp=$TMPDIR/gl$$-$RANDOM
229     (umask 077 && mkdir "$tmp")
230   } ||
231   {
232     echo "$0: cannot create a temporary directory in $TMPDIR" >&2
233     func_exit 1
234   }
235 }
236
237 # func_append var value
238 # appends the given value to the shell variable var.
239 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
240   # Use bash's += operator. It reduces complexity of appending repeatedly to
241   # a single variable from O(n^2) to O(n).
242   func_append ()
243   {
244     eval "$1+=\"\$2\""
245   }
246 else
247   func_append ()
248   {
249     eval "$1=\"\$$1\$2\""
250   }
251 fi
252
253 # func_fatal_error message
254 # outputs to stderr a fatal error message, and terminates the program.
255 func_fatal_error ()
256 {
257   echo "gnulib-tool: *** $1" 1>&2
258   echo "gnulib-tool: *** Stop." 1>&2
259   func_exit 1
260 }
261
262 # func_readlink SYMLINK
263 # outputs the target of the given symlink.
264 if (type -p readlink) > /dev/null 2>&1; then
265   func_readlink ()
266   {
267     # Use the readlink program from GNU coreutils.
268     readlink "$1"
269   }
270 else
271   func_readlink ()
272   {
273     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
274     # would do the wrong thing if the link target contains " -> ".
275     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
276   }
277 fi
278
279 # func_relativize DIR1 DIR2
280 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
281 # Input:
282 # - DIR1            relative pathname, relative to the current directory
283 # - DIR2            relative pathname, relative to the current directory
284 # Output:
285 # - reldir          relative pathname of DIR2, relative to DIR1
286 func_relativize ()
287 {
288   dir0=`pwd`
289   dir1="$1"
290   dir2="$2"
291   sed_first='s,^\([^/]*\)/.*$,\1,'
292   sed_rest='s,^[^/]*/*,,'
293   sed_last='s,^.*/\([^/]*\)$,\1,'
294   sed_butlast='s,/*[^/]*$,,'
295   while test -n "$dir1"; do
296     first=`echo "$dir1" | sed -e "$sed_first"`
297     if test "$first" != "."; then
298       if test "$first" = ".."; then
299         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
300         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
301       else
302         first2=`echo "$dir2" | sed -e "$sed_first"`
303         if test "$first2" = "$first"; then
304           dir2=`echo "$dir2" | sed -e "$sed_rest"`
305         else
306           dir2="../$dir2"
307         fi
308         dir0="$dir0"/"$first"
309       fi
310     fi
311     dir1=`echo "$dir1" | sed -e "$sed_rest"`
312   done
313   reldir="$dir2"
314 }
315
316 # func_relconcat DIR1 DIR2
317 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
318 # Input:
319 # - DIR1            relative pathname, relative to the current directory
320 # - DIR2            relative pathname, relative to DIR1
321 # Output:
322 # - relconcat       DIR1/DIR2, relative to the current directory
323 func_relconcat ()
324 {
325   dir1="$1"
326   dir2="$2"
327   sed_first='s,^\([^/]*\)/.*$,\1,'
328   sed_rest='s,^[^/]*/*,,'
329   sed_last='s,^.*/\([^/]*\)$,\1,'
330   sed_butlast='s,/*[^/]*$,,'
331   while true; do
332     first=`echo "$dir2" | sed -e "$sed_first"`
333     if test "$first" = "."; then
334       dir2=`echo "$dir2" | sed -e "$sed_rest"`
335       if test -z "$dir2"; then
336         relconcat="$dir1"
337         break
338       fi
339     else
340       last=`echo "$dir1" | sed -e "$sed_last"`
341       while test "$last" = "."; do
342         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
343         last=`echo "$dir1" | sed -e "$sed_last"`
344       done
345       if test -z "$dir1"; then
346         relconcat="$dir2"
347         break
348       fi
349       if test "$first" = ".."; then
350         if test "$last" = ".."; then
351           relconcat="$dir1/$dir2"
352           break
353         fi
354         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
355         dir2=`echo "$dir2" | sed -e "$sed_rest"`
356         if test -z "$dir1"; then
357           relconcat="$dir2"
358           break
359         fi
360         if test -z "$dir2"; then
361           relconcat="$dir1"
362           break
363         fi
364       else
365         relconcat="$dir1/$dir2"
366         break
367       fi
368     fi
369   done
370 }
371
372 # func_ln SRC DEST
373 # Like ln -s, except that SRC is given relative to the current directory (or
374 # absolute), not given relative to the directory of DEST.
375 func_ln ()
376 {
377   case "$1" in
378     /*)
379       ln -s "$1" "$2" ;;
380     *) # SRC is relative.
381       case "$2" in
382         /*)
383           ln -s "`pwd`/$1" "$2" ;;
384         *) # DEST is relative too.
385           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
386           test -n "$ln_destdir" || ln_destdir="."
387           func_relativize "$ln_destdir" "$1"
388           ln -s "$reldir" "$2"
389           ;;
390       esac
391       ;;
392   esac
393 }
394
395 # func_ln_if_changed SRC DEST
396 # Like func_ln, but avoids munging timestamps if the link is correct.
397 func_ln_if_changed ()
398 {
399   if test $# -ne 2; then
400     echo "usage: func_ln_if_changed SRC DEST" >&2
401   fi
402   ln_target=`func_readlink "$2"`
403   if test -L "$2" && test "$1" = "$ln_target"; then
404     :
405   else
406     rm -f "$2"
407     func_ln "$1" "$2"
408   fi
409 }
410
411 # Command-line option processing.
412 # Removes the OPTIONS from the arguments. Sets the variables:
413 # - mode            list or import or create-testdir or create-megatestdir
414 # - destdir         from --dir
415 # - local_gnulib_dir  from --local-dir
416 # - libname, supplied_libname  from --lib
417 # - sourcebase      from --source-base
418 # - m4base          from --m4-base
419 # - docbase         from --doc-base
420 # - testsbase       from --tests-base
421 # - auxdir          from --aux-dir
422 # - inctests        true if --with-tests was given, blank otherwise
423 # - avoidlist       list of modules to avoid, from --avoid
424 # - lgpl            true if --lgpl was given, blank otherwise
425 # - makefile_name   from --makefile-name
426 # - libtool         true if --libtool was given, false if --no-libtool was
427 #                   given, blank otherwise
428 # - macro_prefix    from --macro-prefix
429 # - autoconf_minversion  minimum supported autoconf version
430 # - do_changelog    false if --no-changelog was given, : otherwise
431 # - doit            : if actions shall be executed, false if only to be printed
432 # - symbolic        true if --symlink was given, blank otherwise
433 # - lsymbolic       true if --local-symlink was given, blank otherwise
434 {
435   mode=
436   destdir=
437   local_gnulib_dir=
438   libname=libgnu
439   supplied_libname=
440   sourcebase=
441   m4base=
442   docbase=
443   testsbase=
444   auxdir=
445   inctests=
446   avoidlist=
447   lgpl=
448   makefile_name=
449   libtool=
450   macro_prefix=
451   do_changelog=:
452   doit=:
453   symbolic=
454   lsymbolic=
455
456   supplied_opts="$@"
457
458   while test $# -gt 0; do
459     case "$1" in
460       --list | --lis )
461         mode=list
462         shift ;;
463       --import | --impor | --impo | --imp | --im | --i )
464         mode=import
465         shift ;;
466       --update | --updat | --upda | --upd | --up | --u )
467         mode=update
468         shift ;;
469       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
470         mode=create-testdir
471         shift ;;
472       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
473         mode=create-megatestdir
474         shift ;;
475       --test | --tes | --te | --t )
476         mode=test
477         shift ;;
478       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
479         mode=megatest
480         shift ;;
481       --extract-* )
482         mode=`echo "X$1" | sed -e 's/^X--//'`
483         shift ;;
484       --dir )
485         shift
486         if test $# = 0; then
487           func_fatal_error "missing argument for --dir"
488         fi
489         destdir=$1
490         shift ;;
491       --dir=* )
492         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
493         shift ;;
494       --local-dir )
495         shift
496         if test $# = 0; then
497           func_fatal_error "missing argument for --local-dir"
498         fi
499         local_gnulib_dir=$1
500         shift ;;
501       --local-dir=* )
502         local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
503         shift ;;
504       --lib )
505         shift
506         if test $# = 0; then
507           func_fatal_error "missing argument for --lib"
508         fi
509         libname=$1
510         supplied_libname=true
511         shift ;;
512       --lib=* )
513         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
514         supplied_libname=true
515         shift ;;
516       --source-base )
517         shift
518         if test $# = 0; then
519           func_fatal_error "missing argument for --source-base"
520         fi
521         sourcebase=$1
522         shift ;;
523       --source-base=* )
524         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
525         shift ;;
526       --m4-base )
527         shift
528         if test $# = 0; then
529           func_fatal_error "missing argument for --m4-base"
530         fi
531         m4base=$1
532         shift ;;
533       --m4-base=* )
534         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
535         shift ;;
536       --doc-base )
537         shift
538         if test $# = 0; then
539           func_fatal_error "missing argument for --doc-base"
540         fi
541         docbase=$1
542         shift ;;
543       --doc-base=* )
544         docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
545         shift ;;
546       --tests-base )
547         shift
548         if test $# = 0; then
549           func_fatal_error "missing argument for --tests-base"
550         fi
551         testsbase=$1
552         shift ;;
553       --tests-base=* )
554         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
555         shift ;;
556       --aux-dir )
557         shift
558         if test $# = 0; then
559           func_fatal_error "missing argument for --aux-dir"
560         fi
561         auxdir=$1
562         shift ;;
563       --aux-dir=* )
564         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
565         shift ;;
566       --with-tests )
567         inctests=true
568         shift ;;
569       --avoid )
570         shift
571         if test $# = 0; then
572           func_fatal_error "missing argument for --avoid"
573         fi
574         func_append avoidlist " $1"
575         shift ;;
576       --avoid=* )
577         arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
578         func_append avoidlist " $arg"
579         shift ;;
580       --lgpl )
581         lgpl=true
582         shift ;;
583       --makefile-name )
584         shift
585         if test $# = 0; then
586           func_fatal_error "missing argument for --makefile-name"
587         fi
588         makefile_name="$1"
589         shift ;;
590       --makefile-name=* )
591         makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
592         shift ;;
593       --libtool )
594         libtool=true
595         shift ;;
596       --no-libtool )
597         libtool=false
598         shift ;;
599       --macro-prefix )
600         shift
601         if test $# = 0; then
602           func_fatal_error "missing argument for --macro-prefix"
603         fi
604         macro_prefix="$1"
605         shift ;;
606       --macro-prefix=* )
607         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
608         shift ;;
609       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
610         do_changelog=false
611         shift ;;
612       --dry-run )
613         doit=false
614         shift ;;
615       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
616         symbolic=true
617         shift ;;
618       --local-symlink | --local-symlin | --local-symli | --local-syml | --local-sym | --local-sy | --local-s )
619         lsymbolic=true
620         shift ;;
621       --help | --hel | --he | --h )
622         func_usage
623         func_exit $? ;;
624       --version | --versio | --versi | --vers | --ver | --ve | --v )
625         func_version
626         func_exit $? ;;
627       -- )
628         # Stop option processing
629         shift
630         break ;;
631       -* )
632         echo "gnulib-tool: unknown option $1" 1>&2
633         echo "Try 'gnulib-tool --help' for more information." 1>&2
634         func_exit 1 ;;
635       * )
636         break ;;
637     esac
638   done
639
640   if test "$mode" = update; then
641     if test $# != 0; then
642       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
643       echo "Try 'gnulib-tool --help' for more information." 1>&2
644       echo "If you really want to modify the gnulib configuration of your project," 1>&2
645       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
646       func_exit 1
647     fi
648     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
649        || test -n "$sourcebase" || test -n "$m4base" \
650        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
651        || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
652        || test -n "$makefile_name" || test -n "$macro_prefix"; then
653       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
654       echo "Try 'gnulib-tool --help' for more information." 1>&2
655       echo "If you really want to modify the gnulib configuration of your project," 1>&2
656       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
657       func_exit 1
658     fi
659     do_changelog=false
660   fi
661
662   # Determine the minimum supported autoconf version from the project's
663   # configure.ac.
664   DEFAULT_AUTOCONF_MINVERSION="2.59"
665   autoconf_minversion=
666   configure_ac=
667   if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
668     if test -f "$destdir"/configure.ac; then
669       configure_ac="$destdir/configure.ac"
670     else
671       if test -f "$destdir"/configure.in; then
672         configure_ac="$destdir/configure.in"
673       fi
674     fi
675   else
676     if test -f configure.ac; then
677       configure_ac="configure.ac"
678     else
679       if test -f configure.in; then
680         configure_ac="configure.in"
681       fi
682     fi
683   fi
684   if test -n "$configure_ac"; then
685     # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
686     # because when some m4 files are omitted from a CVS repository,
687     # "autoconf --trace=AC_PREREQ" fails with an error message like this:
688     #   m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
689     #   autom4te: m4 failed with exit status: 1
690     prereqs=
691     my_sed_traces='
692       s,#.*$,,
693       s,^dnl .*$,,
694       s, dnl .*$,,
695       /AC_PREREQ/ {
696         s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,\1,p
697       }'
698     prereqs=`sed -n -e "$my_sed_traces" < "$configure_ac"`
699     if test -n "$prereqs"; then
700       autoconf_minversion=`
701         for version in $prereqs; do echo $version; done |
702         LC_ALL=C sort -nru | sed 1q
703       `
704     fi
705   fi
706   if test -z "$autoconf_minversion"; then
707     autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
708   fi
709   case "$autoconf_minversion" in
710     1.* | 2.[0-4]* | 2.5[0-8]*)
711       func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
712   esac
713
714   # Remove trailing slashes from the directory names. This is necessary for
715   # m4base (to avoid an error in func_import) and optional for the others.
716   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
717   case "$local_gnulib_dir" in
718     */ ) local_gnulib_dir=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
719   esac
720   case "$sourcebase" in
721     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
722   esac
723   case "$m4base" in
724     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
725   esac
726   case "$docbase" in
727     */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
728   esac
729   case "$testsbase" in
730     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
731   esac
732   case "$auxdir" in
733     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
734   esac
735 }
736
737 case "$0" in
738   /*) self_abspathname="$0" ;;
739   */*) self_abspathname=`pwd`/"$0" ;;
740   *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
741        if test -x "$d/$0" && test ! -d "$d/$0"; then
742          self_abspathname="$d/$0"
743          break
744        fi
745      done
746      if test -z "$self_abspathname"; then
747        func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
748      fi
749      ;;
750 esac
751 while test -h "$self_abspathname"; do
752   # Resolve symbolic link.
753   linkval=`func_readlink "$self_abspathname"`
754   test -n "$linkval" || break
755   case "$linkval" in
756     /* ) self_abspathname="$linkval" ;;
757     * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
758   esac
759 done
760 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
761
762 func_tmpdir
763 trap 'exit_status=$?
764       if test "$signal" != 0; then
765         echo "caught signal $signal" >&2
766       fi
767       rm -rf "$tmp"
768       exit $exit_status' 0
769 for signal in 1 2 3 13 15; do
770   trap '{ signal='$signal'; func_exit 1; }' $signal
771 done
772 signal=0
773
774 # func_lookup_file file
775 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
776 # 'patch'.
777 # Input:
778 # - local_gnulib_dir  from --local-dir
779 # Output:
780 # - lookedup_file   name of the merged (combined) file
781 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
782 func_lookup_file ()
783 {
784   lkfile="$1"
785   if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
786     lookedup_file="$local_gnulib_dir/$lkfile"
787     lookedup_tmp=
788   else
789     if test -f "$gnulib_dir/$lkfile"; then
790       if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
791         lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
792         rm -f "$tmp/$lkbase"
793         cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
794         patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
795           || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
796         lookedup_file="$tmp/$lkbase"
797         lookedup_tmp=true
798       else
799         lookedup_file="$gnulib_dir/$lkfile"
800         lookedup_tmp=
801       fi
802     else
803       func_fatal_error "file $gnulib_dir/$lkfile not found"
804     fi
805   fi
806 }
807
808 # func_all_modules
809 # Input:
810 # - local_gnulib_dir  from --local-dir
811 func_all_modules ()
812 {
813   # Filter out metainformation files like README, which are not modules.
814   # Filter out unit test modules; they can be retrieved through
815   # --extract-tests-module if desired.
816   {
817     (cd "$gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,')
818     if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
819       (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,')
820     fi
821   } \
822       | sed -e '/^CVS\//d' -e '/\/CVS\//d' \
823             -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
824             -e '/^COPYING$/d' -e '/\/COPYING$/d' \
825             -e '/^README$/d' -e '/\/README$/d' \
826             -e '/^TEMPLATE$/d' \
827             -e '/^TEMPLATE-TESTS$/d' \
828             -e '/^\..*/d' \
829             -e '/~$/d' \
830       | sed -e '/-tests$/d' \
831       | LC_ALL=C sort -u
832 }
833
834 # func_verify_module
835 # verifies a module name
836 # Input:
837 # - local_gnulib_dir  from --local-dir
838 # - module          module name argument
839 func_verify_module ()
840 {
841   if { test -f "$gnulib_dir/modules/$module" \
842        || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
843             && test -f "$local_gnulib_dir/modules/$module"; }; } \
844      && test "CVS" != "$module" \
845      && test "ChangeLog" != "$module" \
846      && test "COPYING" != "$module" \
847      && test "README" != "$module" \
848      && test "TEMPLATE" != "$module" \
849      && test "TEMPLATE-TESTS" != "$module"; then
850     # OK, $module is a correct module name.
851     # Verify that building the module description with 'patch' succeeds.
852     func_lookup_file "modules/$module"
853   else
854     echo "gnulib-tool: module $module doesn't exist" 1>&2
855     module=
856   fi
857 }
858
859 # func_verify_nontests_module
860 # verifies a module name, excluding tests modules
861 # Input:
862 # - local_gnulib_dir  from --local-dir
863 # - module          module name argument
864 func_verify_nontests_module ()
865 {
866   case "$module" in
867     *-tests ) module= ;;
868     * ) func_verify_module ;;
869   esac
870 }
871
872 # func_verify_tests_module
873 # verifies a module name, considering only tests modules
874 # Input:
875 # - local_gnulib_dir  from --local-dir
876 # - module          module name argument
877 func_verify_tests_module ()
878 {
879   case "$module" in
880     *-tests ) func_verify_module ;;
881     * ) module= ;;
882   esac
883 }
884
885 sed_extract_prog=':[     ]*$/ {
886   :a
887     n
888     s/^Description:[     ]*$//
889     s/^Files:[   ]*$//
890     s/^Depends-on:[      ]*$//
891     s/^configure\.ac:[   ]*$//
892     s/^Makefile\.am:[    ]*$//
893     s/^Include:[         ]*$//
894     s/^License:[         ]*$//
895     s/^Maintainer:[      ]*$//
896     tb
897     p
898     ba
899   :b
900 }'
901
902 # func_get_description module
903 # Input:
904 # - local_gnulib_dir  from --local-dir
905 func_get_description ()
906 {
907   func_lookup_file "modules/$1"
908   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
909 }
910
911 # func_get_filelist module
912 # Input:
913 # - local_gnulib_dir  from --local-dir
914 func_get_filelist ()
915 {
916   func_lookup_file "modules/$1"
917   sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
918   echo m4/gnulib-common.m4
919   case "$autoconf_minversion" in
920     2.59)
921       #echo m4/onceonly.m4
922       echo m4/onceonly_2_57.m4
923       ;;
924   esac
925 }
926
927 # func_get_dependencies module
928 # Input:
929 # - local_gnulib_dir  from --local-dir
930 func_get_dependencies ()
931 {
932   # ${module}-tests always implicitly depends on ${module}.
933   echo "$1" | sed -n -e 's/-tests//p'
934   # Then the explicit dependencies listed in the module description.
935   func_lookup_file "modules/$1"
936   sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
937 }
938
939 # func_get_autoconf_snippet module
940 # Input:
941 # - local_gnulib_dir  from --local-dir
942 func_get_autoconf_snippet ()
943 {
944   func_lookup_file "modules/$1"
945   sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
946 }
947
948 # func_get_automake_snippet module
949 # Input:
950 # - local_gnulib_dir  from --local-dir
951 func_get_automake_snippet ()
952 {
953   func_lookup_file "modules/$1"
954   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
955   case "$1" in
956     *-tests)
957       # *-tests module live in tests/, not lib/.
958       ;;
959     *)
960       # Synthesize an EXTRA_DIST augmentation.
961       sed_combine_lines='/\\$/{
962         :a
963         N
964         s/\\\n/ /
965         s/\\$/\\/
966         ta
967       }'
968       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
969       already_mentioned_files=` \
970         sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
971         | sed -e "$sed_combine_lines" \
972         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
973       all_files=`func_get_filelist $1`
974       lib_files=`for f in $all_files; do \
975                    case $f in \
976                      lib/*) echo $f ;; \
977                    esac; \
978                  done | sed -e 's,^lib/,,'`
979       # Remove $already_mentioned_files from $lib_files.
980       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
981       extra_files=`for f in $already_mentioned_files; do echo $f; done \
982                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
983       if test -n "$extra_files"; then
984         echo "EXTRA_DIST +=" $extra_files
985         echo
986       fi
987       # Synthesize also an EXTRA_lib_SOURCES augmentation.
988       # This is necessary so that automake can generate the right list of
989       # dependency rules.
990       # A possible approach would be to use autom4te --trace of the redefined
991       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
992       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
993       # inside autoconf's built-in macros are not missed).
994       # But it's simpler and more robust to do it here, based on the file list.
995       # If some .c file exists and is not used with AC_LIBOBJ - for example,
996       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
997       # automake will generate a useless dependency; this is harmless.
998       sed_extract_c_files='/\.c$/p'
999       extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
1000       if test -n "$extra_files"; then
1001         echo "EXTRA_lib_SOURCES +=" $extra_files
1002         echo
1003       fi
1004       ;;
1005   esac
1006 }
1007
1008 # func_get_include_directive module
1009 # Input:
1010 # - local_gnulib_dir  from --local-dir
1011 func_get_include_directive ()
1012 {
1013   func_lookup_file "modules/$1"
1014   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1015   sed -e 's/^\(["<]\)/#include \1/'
1016 }
1017
1018 # func_get_license module
1019 # Input:
1020 # - local_gnulib_dir  from --local-dir
1021 func_get_license ()
1022 {
1023   func_lookup_file "modules/$1"
1024   sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1025 }
1026
1027 # func_get_maintainer module
1028 # Input:
1029 # - local_gnulib_dir  from --local-dir
1030 func_get_maintainer ()
1031 {
1032   func_lookup_file "modules/$1"
1033   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1034 }
1035
1036 # func_get_tests_module module
1037 # Input:
1038 # - local_gnulib_dir  from --local-dir
1039 func_get_tests_module ()
1040 {
1041   # The naming convention for tests modules is hardwired: ${module}-tests.
1042   if test -f "$gnulib_dir/modules/$1"-tests \
1043      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1044           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1045     echo "$1"-tests
1046   fi
1047 }
1048
1049 # func_acceptable module
1050 # tests whether a module is acceptable.
1051 # Input:
1052 # - avoidlist       list of modules to avoid
1053 func_acceptable ()
1054 {
1055   for avoid in $avoidlist; do
1056     if test "$avoid" = "$1"; then
1057       return 1
1058     fi
1059   done
1060   return 0
1061 }
1062
1063 # func_modules_transitive_closure
1064 # Input:
1065 # - local_gnulib_dir  from --local-dir
1066 # - modules         list of specified modules
1067 # - inctests        true if tests should be included, blank otherwise
1068 # - avoidlist       list of modules to avoid
1069 # - tmp             pathname of a temporary directory
1070 # Output:
1071 # - modules         list of modules, including dependencies
1072 func_modules_transitive_closure ()
1073 {
1074   # In order to process every module only once (for speed), process an "input
1075   # list" of modules, producing an "output list" of modules. During each round,
1076   # more modules can be queued in the input list. Once a module on the input
1077   # list has been processed, it is added to the "handled list", so we can avoid
1078   # to process it again.
1079   handledmodules=
1080   inmodules="$modules"
1081   outmodules=
1082   while test -n "$inmodules"; do
1083     inmodules_this_round="$inmodules"
1084     inmodules=                    # Accumulator, queue for next round
1085     for module in $inmodules_this_round; do
1086       func_verify_module
1087       if test -n "$module"; then
1088         if func_acceptable $module; then
1089           func_append outmodules " $module"
1090           deps=`func_get_dependencies $module`
1091           # Duplicate dependencies are harmless, but Jim wants a warning.
1092           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1093           if test -n "$duplicated_deps"; then
1094             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1095           fi
1096           func_append inmodules " $deps"
1097           if test -n "$inctests"; then
1098             testsmodule=`func_get_tests_module $module`
1099             if test -n "$testsmodule"; then
1100               func_append inmodules " $testsmodule"
1101             fi
1102           fi
1103         fi
1104       fi
1105     done
1106     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1107     # Remove $handledmodules from $inmodules.
1108     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1109     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1110   done
1111   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1112   rm -f "$tmp"/queued-modules
1113 }
1114
1115 # func_modules_add_dummy
1116 # Input:
1117 # - local_gnulib_dir  from --local-dir
1118 # - modules         list of modules, including dependencies
1119 # Output:
1120 # - modules         list of modules, including 'dummy' if needed
1121 func_modules_add_dummy ()
1122 {
1123   have_lib_SOURCES=
1124   sed_remove_backslash_newline=':a
1125 /\\$/{
1126 s/\\$//
1127 N
1128 s/\n//
1129 ba
1130 }'
1131   for module in $modules; do
1132     func_verify_nontests_module
1133     if test -n "$module"; then
1134       # Extract the value of "lib_SOURCES += ...".
1135       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1136         # Ignore .h files since they are not compiled.
1137         case "$file" in
1138           *.h) ;;
1139           *) have_lib_SOURCES=yes ;;
1140         esac
1141       done
1142     fi
1143   done
1144   # Add the dummy module, to make sure the library will be non-empty.
1145   if test -z "$have_lib_SOURCES"; then
1146     func_append modules " dummy"
1147   fi
1148 }
1149
1150 # func_modules_to_filelist
1151 # Input:
1152 # - local_gnulib_dir  from --local-dir
1153 # - modules         list of modules, including dependencies
1154 # Output:
1155 # - files           list of files
1156 func_modules_to_filelist ()
1157 {
1158   files=
1159   for module in $modules; do
1160     func_verify_module
1161     if test -n "$module"; then
1162       fs=`func_get_filelist $module`
1163       func_append files " $fs"
1164     fi
1165   done
1166   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1167 }
1168
1169 # func_emit_lib_Makefile_am
1170 # emits the contents of library makefile to standard output.
1171 # Input:
1172 # - local_gnulib_dir  from --local-dir
1173 # - modules         list of modules, including dependencies
1174 # - libname         library name
1175 # - auxdir          directory relative to destdir where to place build aux files
1176 # - makefile_name   from --makefile-name
1177 # - libtool         true if libtool will be used, false or blank otherwise
1178 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1179 # - actioncmd       (optional) command that will reproduce this invocation
1180 # Output:
1181 # - uses_subdirs    nonempty if object files in subdirs exist
1182 func_emit_lib_Makefile_am ()
1183 {
1184   # When creating an includable Makefile.am snippet, augment variables with
1185   # += instead of assigning them.
1186   if test -n "$makefile_name"; then
1187     assign='+='
1188   else
1189     assign='='
1190   fi
1191   if test "$libtool" = true; then
1192     libext=la
1193     perhapsLT=LT
1194     sed_eliminate_LDFLAGS=
1195   else
1196     libext=a
1197     perhapsLT=
1198     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1199   fi
1200   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1201   echo "## Process this file with automake to produce Makefile.in."
1202   func_emit_copyright_notice
1203   if test -n "$actioncmd"; then
1204     echo "# Reproduce by: $actioncmd"
1205   fi
1206   echo
1207   uses_subdirs=
1208   {
1209     for module in $modules; do
1210       func_verify_nontests_module
1211       if test -n "$module"; then
1212         {
1213           func_get_automake_snippet "$module" |
1214             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1215                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1216             sed -e "$sed_eliminate_LDFLAGS" |
1217             sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1218             sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1219                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1220           if test "$module" = 'alloca'; then
1221             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1222             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1223           fi
1224         } > amsnippet.tmp
1225         # Skip the contents if its entirely empty.
1226         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1227           echo "## begin gnulib module $module"
1228           echo
1229           cat amsnippet.tmp
1230           echo "## end   gnulib module $module"
1231           echo
1232         fi
1233         rm -f amsnippet.tmp
1234         # Test whether there are some source files in subdirectories.
1235         for f in `func_get_filelist "$module"`; do
1236           case $f in
1237             lib/*/*.c) uses_subdirs=yes ;;
1238           esac
1239         done
1240       fi
1241     done
1242   } > allsnippets.tmp
1243   if test -z "$makefile_name"; then
1244     # If there are source files in subdirectories, prevent collision of the
1245     # object files (example: hash.c and libxml/hash.c).
1246     subdir_options=
1247     if test -n "$uses_subdirs"; then
1248       subdir_options=' subdir-objects'
1249     fi
1250     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1251   fi
1252   echo
1253   if test -z "$makefile_name"; then
1254     echo "noinst_HEADERS ="
1255     echo "noinst_LIBRARIES ="
1256     echo "noinst_LTLIBRARIES ="
1257     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1258     # if you specify pkgdata_DATA to empty. This is a workaround.
1259     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1260       echo "pkgdata_DATA ="
1261     fi
1262     echo "EXTRA_DIST ="
1263     echo "BUILT_SOURCES ="
1264     echo "SUFFIXES ="
1265   fi
1266   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1267   if test -z "$makefile_name"; then
1268     echo "MOSTLYCLEANDIRS ="
1269     echo "CLEANFILES ="
1270     echo "DISTCLEANFILES ="
1271     echo "MAINTAINERCLEANFILES ="
1272     echo
1273     echo "AM_CPPFLAGS ="
1274   fi
1275   echo
1276   if grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1277     # One of the snippets already specifies an installation location for the
1278     # library. Don't confuse automake by saying it should not be installed.
1279     :
1280   else
1281     # By default, the generated library should not be installed.
1282     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1283   fi
1284   echo
1285   echo "${libname}_${libext}_SOURCES ="
1286   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1287   # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1288   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1289   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1290   echo "EXTRA_${libname}_${libext}_SOURCES ="
1291   if test "$libtool" = true; then
1292     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1293   fi
1294   echo
1295   cat allsnippets.tmp \
1296     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1297   echo
1298   echo "mostlyclean-local: mostlyclean-generic"
1299   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1300   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1301   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1302   echo "          fi; \\"
1303   echo "        done"
1304   rm -f allsnippets.tmp
1305 }
1306
1307 # func_emit_tests_Makefile_am
1308 # emits the contents of tests makefile to standard output.
1309 # Input:
1310 # - local_gnulib_dir  from --local-dir
1311 # - modules         list of modules, including dependencies
1312 # - libname         library name
1313 # - makefile_name   from --makefile-name
1314 # - libtool         true if libtool will be used, false or blank otherwise
1315 # - sourcebase      relative directory containing lib source code
1316 # - m4base          relative directory containing autoconf macros
1317 # - testsbase       relative directory containing unit test code
1318 func_emit_tests_Makefile_am ()
1319 {
1320   if test "$libtool" = true; then
1321     libext=la
1322   else
1323     libext=a
1324   fi
1325   if test "$libtool" = true; then
1326     libext=la
1327     sed_eliminate_LDFLAGS=
1328   else
1329     libext=a
1330     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1331   fi
1332   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1333   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1334   echo "## Process this file with automake to produce Makefile.in."
1335   func_emit_copyright_notice
1336   echo
1337   # Generate dependencies here, since it eases the debugging of test failures.
1338   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1339   echo
1340   echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1341   echo
1342   (
1343     for module in $modules; do
1344       func_verify_tests_module
1345       if test -n "$module"; then
1346         {
1347           func_get_automake_snippet "$module" |
1348             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1349                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1350             sed -e "$sed_eliminate_LDFLAGS" |
1351             sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1352             sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1353                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1354         } > amsnippet.tmp
1355         # Skip the contents if its entirely empty.
1356         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1357           echo "## begin gnulib module $module"
1358           echo
1359           cat amsnippet.tmp
1360           echo "## end   gnulib module $module"
1361           echo
1362         fi
1363         rm -f amsnippet.tmp
1364       fi
1365     done
1366   ) > allsnippets.tmp
1367   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1368   # variable is needed to avoid an error from automake:
1369   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1370   echo "SUBDIRS ="
1371   echo "TESTS ="
1372   echo "TESTS_ENVIRONMENT ="
1373   echo "noinst_PROGRAMS ="
1374   echo "check_PROGRAMS ="
1375   echo "noinst_HEADERS ="
1376   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1377     echo "pkgdata_DATA ="
1378   fi
1379   echo "EXTRA_DIST ="
1380   echo "BUILT_SOURCES ="
1381   echo "SUFFIXES ="
1382   echo "MOSTLYCLEANFILES = core *.stackdump"
1383   echo "MOSTLYCLEANDIRS ="
1384   echo "CLEANFILES ="
1385   echo "DISTCLEANFILES ="
1386   echo "MAINTAINERCLEANFILES ="
1387   echo
1388   echo "AM_CPPFLAGS = \\"
1389   echo "  -I. -I\$(srcdir) \\"
1390   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1391   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1392   echo
1393   echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1394   echo
1395   cat allsnippets.tmp
1396   echo "# Clean up after Solaris cc."
1397   echo "clean-local:"
1398   echo "        rm -rf SunWS_cache"
1399   echo
1400   echo "mostlyclean-local: mostlyclean-generic"
1401   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1402   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1403   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1404   echo "          fi; \\"
1405   echo "        done"
1406   rm -f allsnippets.tmp
1407 }
1408
1409 # func_emit_initmacro_start
1410 # emits the first few statements of the gl_INIT macro to standard output.
1411 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1412 func_emit_initmacro_start ()
1413 {
1414   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1415   # platform-dependent object files in ${macro_prefix}_LIBOBJS instead of
1416   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1417   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1418   # flexibility.)
1419   # Furthermore it avoids an automake error like this when a Makefile.am
1420   # that uses pieces of gnulib also uses $(LIBOBJ):
1421   #   automatically discovered file `error.c' should not be explicitly mentioned
1422   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix}_LIBOBJ]))"
1423   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix}_REPLACE_FUNCS]))"
1424   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1425   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1426   #   automatically discovered file `error.c' should not be explicitly mentioned
1427   # We let automake know about the files to be distributed through the
1428   # EXTRA_lib_SOURCES variable.
1429   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix}_LIBSOURCES]))"
1430 }
1431
1432 # func_emit_initmacro_end
1433 # emits the last few statements of the gl_INIT macro to standard output.
1434 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1435 func_emit_initmacro_end ()
1436 {
1437   echo "  m4_popdef([AC_LIBSOURCES])"
1438   echo "  m4_popdef([AC_REPLACE_FUNCS])"
1439   echo "  m4_popdef([AC_LIBOBJ])"
1440   echo "  AC_CONFIG_COMMANDS_PRE(["
1441   echo "    ${macro_prefix}_libobjs="
1442   echo "    ${macro_prefix}_ltlibobjs="
1443   echo "    if test -n \"\$${macro_prefix}_LIBOBJS\"; then"
1444   echo "      # Remove the extension."
1445   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
1446   echo "      for i in \`for i in \$${macro_prefix}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
1447   echo "        ${macro_prefix}_libobjs=\"\$${macro_prefix}_libobjs \$i.\$ac_objext\""
1448   echo "        ${macro_prefix}_ltlibobjs=\"\$${macro_prefix}_ltlibobjs \$i.lo\""
1449   echo "      done"
1450   echo "    fi"
1451   echo "    AC_SUBST([${macro_prefix}_LIBOBJS], [\$${macro_prefix}_libobjs])"
1452   echo "    AC_SUBST([${macro_prefix}_LTLIBOBJS], [\$${macro_prefix}_ltlibobjs])"
1453   echo "  ])"
1454 }
1455
1456 # func_emit_initmacro_done
1457 # emits a few statements after the gl_INIT macro to standard output.
1458 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1459 func_emit_initmacro_done ()
1460 {
1461   echo
1462   echo "# Like AC_LIBOBJ, except that the module name goes"
1463   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1464   echo "AC_DEFUN([${macro_prefix}_LIBOBJ],"
1465   echo "  [${macro_prefix}_LIBOBJS=\"\$${macro_prefix}_LIBOBJS \$1.\$ac_objext\"])"
1466   echo
1467   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
1468   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1469   echo "AC_DEFUN([${macro_prefix}_REPLACE_FUNCS],"
1470   echo "  [AC_CHECK_FUNCS([\$1], , [${macro_prefix}_LIBOBJ(\$ac_func)])])"
1471   echo
1472   echo "# Like AC_LIBSOURCES, except that it does nothing."
1473   echo "# We rely on EXTRA_lib..._SOURCES instead."
1474   echo "AC_DEFUN([${macro_prefix}_LIBSOURCES],"
1475   echo "  [])"
1476 }
1477
1478 # func_import modules
1479 # Uses also the variables
1480 # - destdir         target directory
1481 # - local_gnulib_dir  from --local-dir
1482 # - libname         library name
1483 # - sourcebase      directory relative to destdir where to place source code
1484 # - m4base          directory relative to destdir where to place *.m4 macros
1485 # - docbase         directory relative to destdir where to place doc files
1486 # - testsbase       directory relative to destdir where to place unit test code
1487 # - auxdir          directory relative to destdir where to place build aux files
1488 # - inctests        true if --with-tests was given, blank otherwise
1489 # - avoidlist       list of modules to avoid, from --avoid
1490 # - lgpl            true if library's license shall be LGPL, blank otherwise
1491 # - makefile_name   from --makefile-name
1492 # - libtool         true if --libtool was given, false if --no-libtool was
1493 #                   given, blank otherwise
1494 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1495 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1496 # - autoconf_minversion  minimum supported autoconf version
1497 # - doit            : if actions shall be executed, false if only to be printed
1498 # - symbolic        true if files should be symlinked, copied otherwise
1499 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
1500 #                   copied otherwise
1501 func_import ()
1502 {
1503   # Get the cached settings.
1504   cached_local_gnulib_dir=
1505   cached_specified_modules=
1506   cached_avoidlist=
1507   cached_sourcebase=
1508   cached_m4base=
1509   cached_docbase=
1510   cached_testsbase=
1511   cached_libname=
1512   cached_lgpl=
1513   cached_makefile_name=
1514   cached_libtool=
1515   cached_macro_prefix=
1516   cached_files=
1517   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1518     cached_libtool=false
1519     my_sed_traces='
1520       s,#.*$,,
1521       s,^dnl .*$,,
1522       s, dnl .*$,,
1523       /gl_LOCAL_DIR(/ {
1524         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1525       }
1526       /gl_MODULES(/ {
1527         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1528       }
1529       /gl_AVOID(/ {
1530         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1531       }
1532       /gl_SOURCE_BASE(/ {
1533         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1534       }
1535       /gl_M4_BASE(/ {
1536         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1537       }
1538       /gl_DOC_BASE(/ {
1539         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1540       }
1541       /gl_TESTS_BASE(/ {
1542         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1543       }
1544       /gl_LIB(/ {
1545         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1546       }
1547       /gl_LGPL/ {
1548         s,^.*$,cached_lgpl=true,p
1549       }
1550       /gl_MAKEFILE_NAME(/ {
1551         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1552       }
1553       /gl_LIBTOOL/ {
1554         s,^.*$,cached_libtool=true,p
1555       }
1556       /gl_MACRO_PREFIX(/ {
1557         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1558       }'
1559     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1560     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1561       my_sed_traces='
1562         s,#.*$,,
1563         s,^dnl .*$,,
1564         s, dnl .*$,,
1565         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1566           s,^.*$,cached_files=",p
1567           n
1568           ta
1569           :a
1570           s,^\]).*$,",
1571           tb
1572           p
1573           n
1574           ba
1575           :b
1576           p
1577         }'
1578       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1579     fi
1580   fi
1581
1582   # Merge the cached settings with the specified ones.
1583   # The m4base must be the same as expected from the pathname.
1584   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1585     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1586   fi
1587   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1588   # is relative to $destdir, whereas the one we use is relative to . or absolute.
1589   if test -z "$local_gnulib_dir"; then
1590     if test -n "$cached_local_gnulib_dir"; then
1591       case "$destdir" in
1592         /*)
1593           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1594         *)
1595           case "$cached_local_gnulib_dir" in
1596             /*)
1597               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1598             *)
1599               func_relconcat "$destdir" "$cached_local_gnulib_dir"
1600               local_gnulib_dir="$relconcat" ;;
1601           esac ;;
1602       esac
1603     fi
1604   fi
1605   # Append the cached and the specified module names. So that
1606   # "gnulib-tool --import foo" means to add the module foo.
1607   specified_modules="$cached_specified_modules $1"
1608   # Append the cached and the specified avoidlist. This is probably better
1609   # than dropping the cached one when --avoid is specified at least once.
1610   avoidlist=`echo $cached_avoidlist $avoidlist`
1611   # The sourcebase defaults to the cached one.
1612   if test -z "$sourcebase"; then
1613     sourcebase="$cached_sourcebase"
1614     if test -z "$sourcebase"; then
1615       func_fatal_error "missing --source-base option"
1616     fi
1617   fi
1618   # The docbase defaults to the cached one.
1619   if test -z "$docbase"; then
1620     docbase="$cached_docbase"
1621     if test -z "$docbase"; then
1622       func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --import' is before that date, you need to run 'gnulib-tool --import' once, with a --doc-base option."
1623     fi
1624   fi
1625   # The testsbase defaults to the cached one.
1626   if test -z "$testsbase"; then
1627     testsbase="$cached_testsbase"
1628     if test -z "$testsbase"; then
1629       func_fatal_error "missing --tests-base option"
1630     fi
1631   fi
1632   # The libname defaults to the cached one.
1633   if test -z "$supplied_libname"; then
1634     libname="$cached_libname"
1635     if test -z "$libname"; then
1636       func_fatal_error "missing --lib option"
1637     fi
1638   fi
1639   # Require LGPL if specified either way.
1640   if test -z "$lgpl"; then
1641     lgpl="$cached_lgpl"
1642   fi
1643   # The makefile_name defaults to the cached one.
1644   if test -z "$makefile_name"; then
1645     makefile_name="$cached_makefile_name"
1646   fi
1647   # Use libtool if specified either way, or if guessed.
1648   if test -z "$libtool"; then
1649     if test -n "$cached_m4base"; then
1650       libtool="$cached_libtool"
1651     else
1652       libtool="$guessed_libtool"
1653     fi
1654   fi
1655   # The macro_prefix defaults to the cached one.
1656   if test -z "$macro_prefix"; then
1657     macro_prefix="$cached_macro_prefix"
1658     if test -z "$macro_prefix"; then
1659       func_fatal_error "missing --macro-prefix option"
1660     fi
1661   fi
1662
1663   # Canonicalize the list of specified modules.
1664   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1665
1666   # Determine final module list.
1667   modules="$specified_modules"
1668   func_modules_transitive_closure
1669   echo "Module list with included dependencies:"
1670   echo "$modules" | sed -e 's/^/  /'
1671
1672   # Add the dummy module if needed.
1673   func_modules_add_dummy
1674
1675   # If --lgpl, verify that the licenses of modules are compatible.
1676   if test -n "$lgpl"; then
1677     for module in $modules; do
1678       license=`func_get_license $module`
1679       case $license in
1680         LGPL | 'GPLed build tool') ;;
1681         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1682         *) func_fatal_error "incompatible license on module $module: $license" ;;
1683       esac
1684     done
1685   fi
1686
1687   # Determine script to apply to imported library files.
1688   sed_transform_lib_file=
1689   for module in $modules; do
1690     if test $module = config-h; then
1691       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1692       sed_transform_lib_file=$sed_transform_lib_file'
1693         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
1694       '
1695       break
1696     fi
1697   done
1698   if test -n "$lgpl"; then
1699     # Update license.
1700     sed_transform_lib_file=$sed_transform_lib_file'
1701       s/GNU General/GNU Lesser General/g
1702       s/version 2\([ ,]\)/version 2.1\1/g
1703     '
1704   fi
1705
1706   # Determine final file list.
1707   func_modules_to_filelist
1708   echo "File list:"
1709   echo "$files" | sed -e 's/^/  /'
1710
1711   test -n "$files" \
1712     || func_fatal_error "refusing to do nothing"
1713
1714   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1715   new_files="$files m4/gnulib-tool.m4"
1716   old_files="$cached_files"
1717   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1718     func_append old_files " m4/gnulib-tool.m4"
1719   fi
1720
1721   sed_rewrite_old_files="\
1722     s,^build-aux/,$auxdir/,
1723     s,^doc/,$cached_docbase/,
1724     s,^lib/,$cached_sourcebase/,
1725     s,^m4/,$cached_m4base/,
1726     s,^tests/,$cached_testsbase/,"
1727   sed_rewrite_new_files="\
1728     s,^build-aux/,$auxdir/,
1729     s,^doc/,$docbase/,
1730     s,^lib/,$sourcebase/,
1731     s,^m4/,$m4base/,
1732     s,^tests/,$testsbase/,"
1733
1734   # Create directories.
1735   { echo "$sourcebase"
1736     echo "$m4base"
1737     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1738     if test -n "$docfiles"; then
1739       echo "$docbase"
1740     fi
1741     if test -n "$inctests"; then
1742       echo "$testsbase"
1743     fi
1744     echo "$auxdir"
1745     for f in $files; do echo $f; done \
1746       | sed -e "$sed_rewrite_new_files" \
1747       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
1748       | LC_ALL=C sort -u
1749   } > "$tmp"/dirs
1750   { # Rearrange file descriptors. Needed because "while ... done < ..."
1751     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1752     exec 5<&0 < "$tmp"/dirs
1753     while read d; do
1754       if test ! -d "$destdir/$d"; then
1755         if $doit; then
1756           echo "Creating directory $destdir/$d"
1757           mkdir -p "$destdir/$d" || func_fatal_error "failed"
1758         else
1759           echo "Create directory $destdir/$d"
1760         fi
1761       fi
1762     done
1763     exec 0<&5 5<&-
1764   }
1765
1766   # func_dest_tmpfilename file
1767   # determines the name of a temporary file (file is relative to destdir).
1768   # Sets variable:
1769   #   - tmpfile       absolute filename of the temporary file
1770   func_dest_tmpfilename ()
1771   {
1772     if $doit; then
1773       # Put the new contents of $file in a file in the same directory (needed
1774       # to guarantee that an 'mv' to "$destdir/$file" works).
1775       tmpfile="$destdir/$1.tmp"
1776     else
1777       # Put the new contents of $file in a file in a temporary directory
1778       # (because the directory of "$file" might not exist).
1779       tmpfile="$tmp"/`basename "$1"`.tmp
1780     fi
1781   }
1782
1783   # Copy files or make symbolic links. Remove obsolete files.
1784   delimiter='   '
1785   # Construct a table with 2 columns: rewritten-file-name original-file-name,
1786   # representing the files according to the last gnulib-tool invocation.
1787   for f in $old_files; do echo $f; done \
1788     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
1789     | LC_ALL=C sort \
1790     > "$tmp"/old-files
1791   # Construct a table with 2 columns: rewritten-file-name original-file-name,
1792   # representing the files after this gnulib-tool invocation.
1793   for f in $new_files; do echo $f; done \
1794     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
1795     | LC_ALL=C sort \
1796     > "$tmp"/new-files
1797   # First the files that are in old-files, but not in new-files:
1798   sed_take_first_column='s,'"$delimiter"'.*,,'
1799   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1800     # Remove the file. Do nothing if the user already removed it.
1801     if test -f "$destdir/$g"; then
1802       if $doit; then
1803         echo "Removing file $g (backup in ${g}~)"
1804         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1805       else
1806         echo "Remove file $g (backup in ${g}~)"
1807       fi
1808     fi
1809   done
1810   # func_add_or_update handles a file that ought to be present afterwards.
1811   # Uses parameters
1812   # - f             the original file name
1813   # - g             the rewritten file name
1814   # - already_present  nonempty if the file already exists, empty otherwise
1815   func_add_or_update ()
1816   {
1817     func_dest_tmpfilename "$g"
1818     func_lookup_file "$f"
1819     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1820     if test -n "$sed_transform_lib_file"; then
1821       case "$f" in
1822         lib/*)
1823           sed -e "$sed_transform_lib_file" \
1824             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1825           ;;
1826       esac
1827     fi
1828     if test -f "$destdir/$g"; then
1829       # The file already exists.
1830       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1831         : # The file has not changed.
1832       else
1833         # Replace the file.
1834         if $doit; then
1835           if test -n "$already_present"; then
1836             echo "Updating file $g (backup in ${g}~)"
1837           else
1838             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1839           fi
1840           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1841           if { test -n "$symbolic" \
1842                || { test -n "$lsymbolic" \
1843                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
1844              && test -z "$lookedup_tmp" \
1845              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1846             func_ln_if_changed "$lookedup_file" "$destdir/$g"
1847           else
1848             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1849           fi
1850         else
1851           if test -n "$already_present"; then
1852             echo "Update file $g (backup in ${g}~)"
1853           else
1854             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1855           fi
1856         fi
1857       fi
1858     else
1859       # Install the file.
1860       # Don't protest if the file should be there but isn't: it happens
1861       # frequently that developers don't put autogenerated files into CVS.
1862       if $doit; then
1863         echo "Copying file $g"
1864         if { test -n "$symbolic" \
1865              || { test -n "$lsymbolic" \
1866                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
1867            && test -z "$lookedup_tmp" \
1868            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1869           func_ln_if_changed "$lookedup_file" "$destdir/$g"
1870         else
1871           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1872         fi
1873       else
1874         echo "Copy file $g"
1875       fi
1876     fi
1877     rm -f "$tmpfile"
1878   }
1879   # Then the files that are in new-files, but not in old-files:
1880   sed_take_last_column='s,^.*'"$delimiter"',,'
1881   already_present=
1882   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
1883     | sed -e "$sed_take_last_column" \
1884     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
1885   { # Rearrange file descriptors. Needed because "while ... done < ..."
1886     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1887     exec 5<&0 < "$tmp"/added-files
1888     while read g f; do
1889       func_add_or_update
1890     done
1891     exec 0<&5 5<&-
1892   }
1893   # Then the files that are in new-files and in old-files:
1894   already_present=true
1895   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
1896     | sed -e "$sed_take_last_column" \
1897     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
1898   { # Rearrange file descriptors. Needed because "while ... done < ..."
1899     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1900     exec 5<&0 < "$tmp"/kept-files
1901     while read g f; do
1902       func_add_or_update
1903     done
1904     exec 0<&5 5<&-
1905   }
1906
1907   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1908   actioncmd="gnulib-tool --import"
1909   func_append actioncmd " --dir=$destdir"
1910   if test -n "$local_gnulib_dir"; then
1911     func_append actioncmd " --local-dir=$local_gnulib_dir"
1912   fi
1913   func_append actioncmd " --lib=$libname"
1914   func_append actioncmd " --source-base=$sourcebase"
1915   func_append actioncmd " --m4-base=$m4base"
1916   func_append actioncmd " --doc-base=$docbase"
1917   func_append actioncmd " --aux-dir=$auxdir"
1918   for module in $avoidlist; do
1919     func_append actioncmd " --avoid=$module"
1920   done
1921   if test -n "$lgpl"; then
1922     func_append actioncmd " --lgpl"
1923   fi
1924   if test -n "$makefile_name"; then
1925     func_append actioncmd " --makefile-name=$makefile_name"
1926   fi
1927   if test "$libtool" = true; then
1928     func_append actioncmd " --libtool"
1929   else
1930     func_append actioncmd " --no-libtool"
1931   fi
1932   func_append actioncmd " --macro-prefix=$macro_prefix"
1933   func_append actioncmd " `echo $specified_modules`"
1934
1935   # Default the makefile name to Makefile.am.
1936   if test -n "$makefile_name"; then
1937     makefile_am=$makefile_name
1938   else
1939     makefile_am=Makefile.am
1940   fi
1941
1942   # Create library makefile.
1943   func_dest_tmpfilename $sourcebase/$makefile_am
1944   func_emit_lib_Makefile_am > "$tmpfile"
1945   if test -f "$destdir"/$sourcebase/$makefile_am; then
1946     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
1947       rm -f "$tmpfile"
1948     else
1949       if $doit; then
1950         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1951         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
1952         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1953       else
1954         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1955         rm -f "$tmpfile"
1956       fi
1957     fi
1958   else
1959     if $doit; then
1960       echo "Creating $sourcebase/$makefile_am"
1961       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1962     else
1963       echo "Create $sourcebase/$makefile_am"
1964       rm -f "$tmpfile"
1965     fi
1966   fi
1967
1968   # Create m4/gnulib-cache.m4.
1969   func_dest_tmpfilename $m4base/gnulib-cache.m4
1970   (
1971     func_emit_copyright_notice
1972     echo "#"
1973     echo "# This file represents the specification of how gnulib-tool is used."
1974     echo "# It acts as a cache: It is written and read by gnulib-tool."
1975     echo "# In projects using CVS, this file is meant to be stored in CVS,"
1976     echo "# like the configure.ac and various Makefile.am files."
1977     echo
1978     echo
1979     echo "# Specification in the form of a command-line invocation:"
1980     echo "#   $actioncmd"
1981     echo
1982     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1983     # Store the local_gnulib_dir relative to destdir.
1984     case "$local_gnulib_dir" in
1985       "" | /*)
1986         relative_local_gnulib_dir="$local_gnulib_dir" ;;
1987       * )
1988         case "$destdir" in
1989           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
1990           *)
1991             # destdir, local_gnulib_dir are both relative.
1992             func_relativize "$destdir" "$local_gnulib_dir"
1993             relative_local_gnulib_dir="$reldir" ;;
1994         esac ;;
1995     esac
1996     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
1997     echo "gl_MODULES(["`echo $specified_modules`"])"
1998     echo "gl_AVOID([$avoidlist])"
1999     echo "gl_SOURCE_BASE([$sourcebase])"
2000     echo "gl_M4_BASE([$m4base])"
2001     echo "gl_DOC_BASE([$docbase])"
2002     echo "gl_TESTS_BASE([$testsbase])"
2003     echo "gl_LIB([$libname])"
2004     test -z "$lgpl" || echo "gl_LGPL"
2005     echo "gl_MAKEFILE_NAME([$makefile_name])"
2006     if test "$libtool" = true; then
2007       echo "gl_LIBTOOL"
2008     fi
2009     echo "gl_MACRO_PREFIX([$macro_prefix])"
2010   ) > "$tmpfile"
2011   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2012     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2013       rm -f "$tmpfile"
2014     else
2015       if $doit; then
2016         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2017         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2018         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2019       else
2020         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2021         if false; then
2022           cat "$tmpfile"
2023           echo
2024           echo "# gnulib-cache.m4 ends here"
2025         fi
2026         rm -f "$tmpfile"
2027       fi
2028     fi
2029   else
2030     if $doit; then
2031       echo "Creating $m4base/gnulib-cache.m4"
2032       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2033     else
2034       echo "Create $m4base/gnulib-cache.m4"
2035       cat "$tmpfile"
2036       rm -f "$tmpfile"
2037     fi
2038   fi
2039
2040   # Create m4/gnulib-comp.m4.
2041   func_dest_tmpfilename $m4base/gnulib-comp.m4
2042   (
2043     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2044     func_emit_copyright_notice
2045     echo "#"
2046     echo "# This file represents the compiled summary of the specification in"
2047     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2048     echo "# to be invoked from configure.ac."
2049     echo "# In projects using CVS, this file can be treated like other built files."
2050     echo
2051     echo
2052     echo "# This macro should be invoked from $configure_ac, in the section"
2053     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2054     echo "# any checks for libraries, header files, types and library functions."
2055     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2056     echo "["
2057     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2058     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2059     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2060     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2061     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2062     if test -n "$uses_subdirs"; then
2063       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2064     fi
2065     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2066       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2067     fi
2068     if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2069       echo "  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
2070     fi
2071     if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2072       echo "  AC_REQUIRE([gl_LOCK_EARLY])"
2073     fi
2074     echo "])"
2075     echo
2076     echo "# This macro should be invoked from $configure_ac, in the section"
2077     echo "# \"Check for header files, types and library functions\"."
2078     echo "AC_DEFUN([${macro_prefix}_INIT],"
2079     echo "["
2080     func_emit_initmacro_start
2081     if test "$libtool" = true; then
2082       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2083       echo "  gl_cond_libtool=true"
2084     else
2085       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2086       echo "  gl_cond_libtool=false"
2087       echo "  gl_libdeps="
2088       echo "  gl_ltlibdeps="
2089     fi
2090     echo "  gl_source_base='$sourcebase'"
2091     if test "$auxdir" != "build-aux"; then
2092       sed_replace_build_aux='
2093         :a
2094         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2095           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2096           ba
2097         }'
2098       sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2099     else
2100       sed_replace_build_aux=
2101     fi
2102     for module in $modules; do
2103       func_verify_module
2104       if test -n "$module"; then
2105         func_get_autoconf_snippet "$module" \
2106           | sed -e '/^$/d;' -e 's/^/  /' \
2107                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
2108                 -e "$sed_replace_build_aux"
2109         if test "$module" = 'alloca' && test "$libtool" = true; then
2110           echo 'changequote(,)dnl'
2111           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
2112           echo 'changequote([, ])dnl'
2113           echo 'AC_SUBST([LTALLOCA])'
2114         fi
2115       fi
2116     done
2117     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2118     # created using libtool, because libtool already handles the dependencies.
2119     if test "$libtool" != true; then
2120       libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2121       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2122       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2123       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2124       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2125     fi
2126     func_emit_initmacro_end
2127     echo "])"
2128     func_emit_initmacro_done
2129     echo
2130     echo "# This macro records the list of files which have been installed by"
2131     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
2132     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
2133     echo "$files" | sed -e 's,^,  ,'
2134     echo "])"
2135   ) > "$tmpfile"
2136   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2137     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
2138       rm -f "$tmpfile"
2139     else
2140       if $doit; then
2141         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2142         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
2143         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2144       else
2145         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2146         if false; then
2147           cat "$tmpfile"
2148           echo
2149           echo "# gnulib-comp.m4 ends here"
2150         fi
2151         rm -f "$tmpfile"
2152       fi
2153     fi
2154   else
2155     if $doit; then
2156       echo "Creating $m4base/gnulib-comp.m4"
2157       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2158     else
2159       echo "Create $m4base/gnulib-comp.m4"
2160       cat "$tmpfile"
2161       rm -f "$tmpfile"
2162     fi
2163   fi
2164
2165   if test -n "$inctests"; then
2166     # Create tests makefile.
2167     func_dest_tmpfilename $testsbase/$makefile_am
2168     func_emit_tests_Makefile_am > "$tmpfile"
2169     if test -f "$destdir"/$testsbase/$makefile_am; then
2170       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
2171         rm -f "$tmpfile"
2172       else
2173         if $doit; then
2174           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2175           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
2176           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2177         else
2178           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2179           rm -f "$tmpfile"
2180         fi
2181       fi
2182     else
2183       if $doit; then
2184         echo "Creating $testsbase/$makefile_am"
2185         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2186       else
2187         echo "Create $testsbase/$makefile_am"
2188         rm -f "$tmpfile"
2189       fi
2190     fi
2191   fi
2192
2193   echo "Finished."
2194   echo
2195   echo "You may need to add #include directives for the following .h files."
2196   # Intersect $specified_modules and $modules
2197   # (since $specified_modules is not necessarily of subset of $modules - some
2198   # may have been skipped through --avoid, and since the elements of $modules
2199   # but not in $specified_modules can go away without explicit notice - through
2200   # changes in the module dependencies).
2201   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
2202   echo "$modules" > "$tmp"/modules2 # also a sorted list, one module per line
2203   # First the #include <...> directives without #ifs, sorted for convenience,
2204   # then the #include "..." directives without #ifs, sorted for convenience,
2205   # then the #include directives that are surrounded by #ifs. Not sorted.
2206   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
2207     include_directive=`func_get_include_directive "$module"`
2208     case "$nl$include_directive" in
2209       *"$nl#if"*)
2210         echo "$include_directive" 1>&5
2211         ;;
2212       *)
2213         echo "$include_directive" | grep -v 'include "' 1>&6
2214         echo "$include_directive" | grep 'include "' 1>&7
2215         ;;
2216     esac
2217   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2218   (
2219    LC_ALL=C sort -u "$tmp"/include-angles
2220    LC_ALL=C sort -u "$tmp"/include-quotes
2221    cat "$tmp"/include-if
2222   ) | sed -e '/^$/d' -e 's/^/  /'
2223   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2224
2225   echo
2226   echo "Don't forget to"
2227   if test "$makefile_am" = Makefile.am; then
2228     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2229   else
2230     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2231   fi
2232   if test -n "$inctests"; then
2233     if test "$makefile_am" = Makefile.am; then
2234       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2235     else
2236       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2237     fi
2238   fi
2239   if test "$makefile_am" = Makefile.am; then
2240     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2241     sourcebase_base=`basename "$sourcebase"`
2242     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2243   fi
2244   if test -n "$inctests"; then
2245     if test "$makefile_am" = Makefile.am; then
2246       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2247       testsbase_base=`basename "$testsbase"`
2248       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2249     fi
2250   fi
2251   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2252   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2253   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
2254 }
2255
2256 # func_create_testdir testdir modules
2257 # Input:
2258 # - local_gnulib_dir  from --local-dir
2259 # - auxdir          directory relative to destdir where to place build aux files
2260 func_create_testdir ()
2261 {
2262   testdir="$1"
2263   modules="$2"
2264   if test -z "$modules"; then
2265     # All modules together.
2266     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2267     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2268     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
2269     modules=`func_all_modules`
2270     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
2271   fi
2272   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2273
2274   # Check that the license of every module is consistent with the license of
2275   # its dependencies.
2276   saved_modules="$modules"
2277   for requested_module in $saved_modules; do
2278     requested_license=`func_get_license "$requested_module"`
2279     if test "$requested_license" != GPL; then
2280       # Here we use func_modules_transitive_closure, not just
2281       # func_get_dependencies, so that we also detect weird situations like
2282       # an LGPL module which depends on a GPLed build tool module which depends
2283       # on a GPL module.
2284       modules="$requested_module"
2285       func_modules_transitive_closure
2286       for module in $modules; do
2287         license=`func_get_license "$module"`
2288         case $license in
2289           LGPL | 'GPLed build tool') ;;
2290           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2291           *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2292         esac
2293       done
2294     fi
2295   done
2296   modules="$saved_modules"
2297
2298   # Subdirectory names.
2299   sourcebase=gllib
2300   m4base=glm4
2301   docbase=gldoc
2302   testsbase=gltests
2303   macro_prefix=gl
2304
2305   # Determine final module list.
2306   func_modules_transitive_closure
2307   echo "Module list with included dependencies:"
2308   echo "$modules" | sed -e 's/^/  /'
2309
2310   # Add the dummy module if needed.
2311   func_modules_add_dummy
2312
2313   # Determine final file list.
2314   func_modules_to_filelist
2315   echo "File list:"
2316   echo "$files" | sed -e 's/^/  /'
2317
2318   sed_rewrite_files="\
2319     s,^build-aux/,$auxdir/,
2320     s,^doc/,$docbase/,
2321     s,^lib/,$sourcebase/,
2322     s,^m4/,$m4base/,
2323     s,^tests/,$testsbase/,"
2324
2325   # Create directories.
2326   for f in $files; do echo $f; done \
2327     | sed -e "$sed_rewrite_files" \
2328     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2329     | LC_ALL=C sort -u \
2330     > "$tmp"/dirs
2331   { # Rearrange file descriptors. Needed because "while ... done < ..."
2332     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2333     exec 5<&0 < "$tmp"/dirs
2334     while read d; do
2335       mkdir -p "$testdir/$d"
2336     done
2337     exec 0<&5 5<&-
2338   }
2339
2340   # Copy files or make symbolic links.
2341   delimiter='   '
2342   for f in $files; do echo $f; done \
2343     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2344     | LC_ALL=C sort \
2345     > "$tmp"/files
2346   { # Rearrange file descriptors. Needed because "while ... done < ..."
2347     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2348     exec 5<&0 < "$tmp"/files
2349     while read g f; do
2350       func_lookup_file "$f"
2351       if test -n "$lookedup_tmp"; then
2352         cp -p "$lookedup_file" "$testdir/$g"
2353       else
2354         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2355         if { test -n "$symbolic" \
2356              || { test -n "$lsymbolic" \
2357                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
2358           func_ln "$lookedup_file" "$testdir/$g"
2359         else
2360           cp -p "$lookedup_file" "$testdir/$g"
2361         fi
2362       fi
2363     done
2364     exec 0<&5 5<&-
2365   }
2366
2367   # Create $sourcebase/Makefile.am.
2368   mkdir -p "$testdir/$sourcebase"
2369   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2370
2371   # Create $m4base/Makefile.am.
2372   mkdir -p "$testdir/$m4base"
2373   (echo "## Process this file with automake to produce Makefile.in."
2374    echo
2375    echo "EXTRA_DIST ="
2376    for f in $files; do
2377      case "$f" in
2378        m4/* )
2379          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2380      esac
2381    done
2382   ) > "$testdir/$m4base/Makefile.am"
2383
2384   subdirs="$sourcebase $m4base"
2385   subdirs_with_configure_ac=""
2386
2387   if false && test -f "$testdir"/$m4base/gettext.m4; then
2388     # Avoid stupid error message from automake:
2389     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2390     mkdir -p "$testdir/po"
2391     (echo "## Process this file with automake to produce Makefile.in."
2392     ) > "$testdir/po/Makefile.am"
2393     func_append subdirs " po"
2394   fi
2395
2396   if test -n "$inctests"; then
2397     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2398     # Create $testsbase/Makefile.am.
2399     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2400     # Create $testsbase/configure.ac.
2401     (echo "# Process this file with autoconf to produce a configure script."
2402      echo "AC_INIT([dummy], [0])"
2403      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2404      echo "AM_INIT_AUTOMAKE"
2405      echo
2406      echo "AM_CONFIG_HEADER([config.h])"
2407      echo
2408      echo "AC_PROG_CC"
2409      echo "AC_PROG_INSTALL"
2410      echo "AC_PROG_MAKE_SET"
2411      echo "AC_PROG_RANLIB"
2412      echo
2413      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2414        echo "AC_GNU_SOURCE"
2415        echo
2416      fi
2417      if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2418        echo "gl_USE_SYSTEM_EXTENSIONS"
2419        echo
2420      fi
2421      if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2422        echo "gl_LOCK_EARLY"
2423        echo
2424      fi
2425      if test "$libtool" = true; then
2426        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2427        echo "gl_cond_libtool=true"
2428      else
2429        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2430        echo "gl_cond_libtool=false"
2431        echo "gl_libdeps="
2432        echo "gl_ltlibdeps="
2433      fi
2434      # Wrap the set of autoconf snippets into an autoconf macro that is then
2435      # invoked. This is needed because autoconf does not support AC_REQUIRE
2436      # at the top level:
2437      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2438      # but we want the AC_REQUIRE to have its normal meaning (provide one
2439      # expansion of the required macro before the current point, and only one
2440      # expansion total).
2441      echo "AC_DEFUN([gl_INIT], ["
2442      func_emit_initmacro_start
2443      sed_replace_build_aux='
2444        :a
2445        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2446          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2447          ba
2448        }'
2449      sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2450      # We don't have explicit ordering constraints between the various
2451      # autoconf snippets. It's cleanest to put those of the library before
2452      # those of the tests.
2453      echo "gl_source_base='../$sourcebase'"
2454      for module in $modules; do
2455        func_verify_nontests_module
2456        if test -n "$module"; then
2457          func_get_autoconf_snippet "$module" \
2458            | sed -e "$sed_replace_build_aux"
2459        fi
2460      done
2461      echo "gl_source_base='.'"
2462      for module in $modules; do
2463        func_verify_tests_module
2464        if test -n "$module"; then
2465          func_get_autoconf_snippet "$module" \
2466            | sed -e "$sed_replace_build_aux"
2467        fi
2468      done
2469      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2470      # created using libtool, because libtool already handles the dependencies.
2471      if test "$libtool" != true; then
2472        libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2473        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2474        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2475        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2476        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2477      fi
2478      func_emit_initmacro_end
2479      echo "])"
2480      func_emit_initmacro_done
2481      echo
2482      echo "gl_INIT"
2483      echo
2484      # Usually $testsbase/config.h will be a superset of config.h. Verify this
2485      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2486      echo "AH_TOP([#include \"../config.h\"])"
2487      echo
2488      echo "AC_OUTPUT([Makefile])"
2489     ) > "$testdir/$testsbase/configure.ac"
2490     func_append subdirs " $testsbase"
2491     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2492   fi
2493
2494   # Create Makefile.am.
2495   (echo "## Process this file with automake to produce Makefile.in."
2496    echo
2497    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2498    echo
2499    echo "SUBDIRS = $subdirs"
2500    echo
2501    echo "ACLOCAL_AMFLAGS = -I $m4base"
2502   ) > "$testdir/Makefile.am"
2503
2504   # Create configure.ac.
2505   (echo "# Process this file with autoconf to produce a configure script."
2506    echo "AC_INIT([dummy], [0])"
2507    if test "$auxdir" != "."; then
2508      echo "AC_CONFIG_AUX_DIR([$auxdir])"
2509    fi
2510    echo "AM_INIT_AUTOMAKE"
2511    echo
2512    echo "AM_CONFIG_HEADER([config.h])"
2513    echo
2514    echo "AC_PROG_CC"
2515    echo "AC_PROG_INSTALL"
2516    echo "AC_PROG_MAKE_SET"
2517    echo
2518    echo "# For autobuild."
2519    echo "AC_CANONICAL_BUILD"
2520    echo "AC_CANONICAL_HOST"
2521    echo
2522    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2523    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2524    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2525    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2526    echo
2527    echo "AC_PROG_RANLIB"
2528    echo
2529    if test -n "$uses_subdirs"; then
2530      echo "AM_PROG_CC_C_O"
2531      echo
2532    fi
2533    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2534      echo "AC_GNU_SOURCE"
2535      echo
2536    fi
2537    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2538      echo "gl_USE_SYSTEM_EXTENSIONS"
2539      echo
2540    fi
2541    if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2542      echo "gl_LOCK_EARLY"
2543      echo
2544    fi
2545    if test "$libtool" = true; then
2546      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2547      echo "gl_cond_libtool=true"
2548    else
2549      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2550      echo "gl_cond_libtool=false"
2551      echo "gl_libdeps="
2552      echo "gl_ltlibdeps="
2553    fi
2554    echo "gl_source_base='$sourcebase'"
2555    # Wrap the set of autoconf snippets into an autoconf macro that is then
2556    # invoked. This is needed because autoconf does not support AC_REQUIRE
2557    # at the top level:
2558    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2559    # but we want the AC_REQUIRE to have its normal meaning (provide one
2560    # expansion of the required macro before the current point, and only one
2561    # expansion total).
2562    echo "AC_DEFUN([gl_INIT], ["
2563    func_emit_initmacro_start
2564    if test "$auxdir" != "build-aux"; then
2565      sed_replace_build_aux='
2566        :a
2567        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2568          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2569          ba
2570        }'
2571      sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2572    else
2573      sed_replace_build_aux=
2574    fi
2575    for module in $modules; do
2576      func_verify_nontests_module
2577      if test -n "$module"; then
2578        func_get_autoconf_snippet "$module" \
2579          | sed -e "$sed_replace_build_aux"
2580      fi
2581    done
2582    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2583    # created using libtool, because libtool already handles the dependencies.
2584    if test "$libtool" != true; then
2585      libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2586      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2587      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2588      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2589      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2590    fi
2591    func_emit_initmacro_end
2592    echo "])"
2593    func_emit_initmacro_done
2594    echo
2595    echo "gl_INIT"
2596    echo
2597    if test -n "$subdirs_with_configure_ac"; then
2598      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
2599    fi
2600    makefiles="Makefile"
2601    for d in $subdirs; do
2602      # For subdirs that have a configure.ac by their own, it's the subdir's
2603      # configure.ac which creates the subdir's Makefile.am, not this one.
2604      case " $subdirs_with_configure_ac " in
2605        *" $d "*) ;;
2606        *) func_append makefiles " $d/Makefile" ;;
2607      esac
2608    done
2609    echo "AC_OUTPUT([$makefiles])"
2610   ) > "$testdir/configure.ac"
2611
2612   # Create autogenerated files.
2613   (cd "$testdir"
2614    # Do not use "${AUTORECONF} --force --install", because it may invoke
2615    # autopoint, which brings in older versions of some of our .m4 files.
2616    if test -f $m4base/gettext.m4; then
2617      echo "executing ${AUTOPOINT} --force"
2618      ${AUTOPOINT} --force || func_exit 1
2619      for f in $m4base/*.m4~; do
2620        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
2621      done
2622    fi
2623    echo "executing ${ACLOCAL} -I $m4base"
2624    ${ACLOCAL} -I $m4base || func_exit 1
2625    if ! test -d build-aux; then
2626      echo "executing mkdir build-aux"
2627      mkdir build-aux || func_exit 1
2628    fi
2629    echo "executing ${AUTOCONF}"
2630    ${AUTOCONF} || func_exit 1
2631    echo "executing ${AUTOHEADER}"
2632    ${AUTOHEADER} || func_exit 1
2633    echo "executing ${AUTOMAKE} --add-missing --copy"
2634    ${AUTOMAKE} --add-missing --copy || func_exit 1
2635   ) || func_exit 1
2636   if test -n "$inctests"; then
2637     # Create autogenerated files.
2638     (cd "$testdir/$testsbase" || func_exit 1
2639      # Do not use "${AUTORECONF} --force --install", because it may invoke
2640      # autopoint, which brings in older versions of some of our .m4 files.
2641      if test -f ../$m4base/gettext.m4; then
2642        echo "executing ${AUTOPOINT} --force"
2643        ${AUTOPOINT} --force || func_exit 1
2644        for f in ../$m4base/*.m4~; do
2645          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
2646        done
2647      fi
2648      echo "executing ${ACLOCAL} -I ../$m4base"
2649      ${ACLOCAL} -I ../$m4base || func_exit 1
2650      if ! test -d ../build-aux; then
2651        echo "executing mkdir ../build-aux"
2652        mkdir ../build-aux
2653      fi
2654      echo "executing ${AUTOCONF}"
2655      ${AUTOCONF} || func_exit 1
2656      echo "executing ${AUTOHEADER}"
2657      ${AUTOHEADER} || func_exit 1
2658      echo "executing ${AUTOMAKE} --add-missing --copy"
2659      ${AUTOMAKE} --add-missing --copy || func_exit 1
2660     ) || func_exit 1
2661   fi
2662   if grep '^BUILT_SOURCES *+=' "$testdir/$sourcebase/Makefile.am" > /dev/null; then
2663     (cd "$testdir"
2664      ./configure || func_exit 1
2665        cd "$sourcebase"
2666        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
2667        make built_sources || func_exit 1
2668        cd ..
2669      make distclean || func_exit 1
2670     ) || func_exit 1
2671   fi
2672 }
2673
2674 # func_create_megatestdir megatestdir allmodules
2675 # Input:
2676 # - local_gnulib_dir  from --local-dir
2677 # - auxdir          directory relative to destdir where to place build aux files
2678 func_create_megatestdir ()
2679 {
2680   megatestdir="$1"
2681   allmodules="$2"
2682   if test -z "$allmodules"; then
2683     allmodules=`func_all_modules`
2684   fi
2685
2686   megasubdirs=
2687   # First, all modules one by one.
2688   for onemodule in $allmodules; do
2689     func_create_testdir "$megatestdir/$onemodule" $onemodule
2690     func_append megasubdirs "$onemodule "
2691   done
2692   # Then, all modules all together.
2693   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2694   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2695   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
2696   func_create_testdir "$megatestdir/ALL" "$allmodules"
2697   func_append megasubdirs "ALL"
2698
2699   # Create Makefile.am.
2700   (echo "## Process this file with automake to produce Makefile.in."
2701    echo
2702    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2703    echo
2704    echo "SUBDIRS = $megasubdirs"
2705   ) > "$megatestdir/Makefile.am"
2706
2707   # Create configure.ac.
2708   (echo "# Process this file with autoconf to produce a configure script."
2709    echo "AC_INIT([dummy], [0])"
2710    if test "$auxdir" != "."; then
2711      echo "AC_CONFIG_AUX_DIR([$auxdir])"
2712    fi
2713    echo "AM_INIT_AUTOMAKE"
2714    echo
2715    echo "AC_PROG_MAKE_SET"
2716    echo
2717    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
2718    echo "AC_OUTPUT([Makefile])"
2719   ) > "$megatestdir/configure.ac"
2720
2721   # Create autogenerated files.
2722   (cd "$megatestdir"
2723    # Do not use "${AUTORECONF} --install", because autoreconf operates
2724    # recursively, but the subdirectories are already finished, therefore
2725    # calling autoreconf here would only waste lots of CPU time.
2726    echo "executing ${ACLOCAL}"
2727    ${ACLOCAL} || func_exit 1
2728    echo "executing mkdir build-aux"
2729    mkdir build-aux
2730    echo "executing ${AUTOCONF}"
2731    ${AUTOCONF} || func_exit 1
2732    echo "executing ${AUTOMAKE} --add-missing --copy"
2733    ${AUTOMAKE} --add-missing --copy || func_exit 1
2734   ) || func_exit 1
2735 }
2736
2737 case $mode in
2738   "" )
2739     func_fatal_error "no mode specified" ;;
2740
2741   list )
2742     func_all_modules
2743     ;;
2744
2745   import | update )
2746
2747     # Where to import.
2748     if test -z "$destdir"; then
2749       destdir=.
2750     fi
2751     test -d "$destdir" \
2752       || func_fatal_error "destination directory does not exist: $destdir"
2753
2754     # Prefer configure.ac to configure.in.
2755     if test -f "$destdir"/configure.ac; then
2756       configure_ac="$destdir/configure.ac"
2757     else
2758       if test -f "$destdir"/configure.in; then
2759         configure_ac="$destdir/configure.in"
2760       else
2761         func_fatal_error "cannot find $destdir/configure.ac"
2762       fi
2763     fi
2764
2765     # Analyze configure.ac.
2766     guessed_auxdir="."
2767     guessed_libtool=false
2768     my_sed_traces='
2769       s,#.*$,,
2770       s,^dnl .*$,,
2771       s, dnl .*$,,
2772       /AC_CONFIG_AUX_DIR/ {
2773         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
2774       }
2775       /A[CM]_PROG_LIBTOOL/ {
2776         s,^.*$,guessed_libtool=true,p
2777       }'
2778     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2779
2780     if test -z "$auxdir"; then
2781       auxdir="$guessed_auxdir"
2782     fi
2783
2784     # Determine where to apply func_import.
2785     if test -n "$m4base"; then
2786       # Apply func_import to a particular gnulib directory.
2787       # Any number of additional modules can be given.
2788       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2789         # First use of gnulib in the given m4base.
2790         test -n "$supplied_libname" || supplied_libname=true
2791         test -n "$sourcebase" || sourcebase="lib"
2792         test -n "$docbase" || docbase="doc"
2793         test -n "$testsbase" || testsbase="tests"
2794         test -n "$macro_prefix" || macro_prefix="gl"
2795       fi
2796       func_import "$*"
2797     else
2798       # Apply func_import to all gnulib directories.
2799       # To get this list of directories, look at Makefile.am. (Not at
2800       # configure, because it may be omitted from CVS. Also, don't run
2801       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2802       m4dirs=
2803       m4dirs_count=0
2804       if test -f "$destdir"/Makefile.am; then
2805         aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[         ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[       ]*=\(.*\)$/\1/'`
2806         m4dir_is_next=
2807         for arg in $aclocal_amflags; do
2808           if test -n "$m4dir_is_next"; then
2809             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2810             case "$arg" in
2811               /*) ;;
2812               *)
2813                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2814                   func_append m4dirs " $arg"
2815                   m4dirs_count=`expr $m4dirs_count + 1`
2816                 fi
2817                 ;;
2818             esac
2819           else
2820             if test "X$arg" = "X-I"; then
2821               m4dir_is_next=yes
2822             else
2823               m4dir_is_next=
2824             fi
2825           fi
2826         done
2827       else
2828         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2829         if test -f "$destdir"/aclocal.m4; then
2830           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2831           sedexpr2='s,^[^/]*$,.,'
2832           sedexpr3='s,/[^/]*$,,'
2833           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
2834           m4dirs_count=`echo "$m4dirs" | wc -l`
2835         fi
2836       fi
2837       if test $m4dirs_count = 0; then
2838         # First use of gnulib in a package.
2839         # Any number of additional modules can be given.
2840         test -n "$supplied_libname" || supplied_libname=true
2841         test -n "$sourcebase" || sourcebase="lib"
2842         m4base="m4"
2843         test -n "$docbase" || docbase="doc"
2844         test -n "$testsbase" || testsbase="tests"
2845         test -n "$macro_prefix" || macro_prefix="gl"
2846         func_import "$*"
2847       else
2848         if test $m4dirs_count = 1; then
2849           # There's only one use of gnulib here. Assume the user means it.
2850           # Any number of additional modules can be given.
2851           for m4base in $m4dirs; do
2852             func_import "$*"
2853           done
2854         else
2855           # Ambiguous - guess what the user meant.
2856           if test $# = 0; then
2857             # No further arguments. Guess the user wants to update all of them.
2858             for m4base in $m4dirs; do
2859               # Perform func_import in a subshell, so that variable values
2860               # such as
2861               #   local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
2862               #   testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
2863               # don't propagate from one directory to another.
2864               (func_import) || func_exit 1
2865             done
2866           else
2867             # Really ambiguous.
2868             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2869           fi
2870         fi
2871       fi
2872     fi
2873     ;;
2874
2875   create-testdir )
2876     if test -z "$destdir"; then
2877       func_fatal_error "please specify --dir option"
2878     fi
2879     mkdir "$destdir"
2880     test -d "$destdir" \
2881       || func_fatal_error "could not create destination directory"
2882     test -n "$auxdir" || auxdir="build-aux"
2883     func_create_testdir "$destdir" "$*"
2884     ;;
2885
2886   create-megatestdir )
2887     if test -z "$destdir"; then
2888       func_fatal_error "please specify --dir option"
2889     fi
2890     mkdir "$destdir" || func_fatal_error "could not create destination directory"
2891     test -n "$auxdir" || auxdir="build-aux"
2892     func_create_megatestdir "$destdir" "$*"
2893     ;;
2894
2895   test )
2896     test -n "$destdir" || destdir=testdir$$
2897     mkdir "$destdir" || func_fatal_error "could not create destination directory"
2898     test -n "$auxdir" || auxdir="build-aux"
2899     func_create_testdir "$destdir" "$*"
2900     cd "$destdir"
2901       mkdir build
2902       cd build
2903         ../configure || func_exit 1
2904         make || func_exit 1
2905         make check || func_exit 1
2906         make distclean || func_exit 1
2907         remaining=`find . -type f -print`
2908         if test -n "$remaining"; then
2909           echo "Remaining files:" $remaining 1>&2
2910           echo "gnulib-tool: *** Stop." 1>&2
2911           func_exit 1
2912         fi
2913       cd ..
2914     cd ..
2915     rm -rf "$destdir"
2916     ;;
2917
2918   megatest )
2919     test -n "$destdir" || destdir=testdir$$
2920     mkdir "$destdir" || func_fatal_error "could not create destination directory"
2921     test -n "$auxdir" || auxdir="build-aux"
2922     func_create_megatestdir "$destdir" "$*"
2923     cd "$destdir"
2924       mkdir build
2925       cd build
2926         ../configure
2927         make
2928         make check
2929         make distclean
2930         remaining=`find . -type f -print`
2931         if test -n "$remaining"; then
2932           echo "Remaining files:" $remaining 1>&2
2933           echo "gnulib-tool: *** Stop." 1>&2
2934           func_exit 1
2935         fi
2936       cd ..
2937     cd ..
2938     rm -rf "$destdir"
2939     ;;
2940
2941   extract-description )
2942     for module
2943     do
2944       func_verify_module
2945       if test -n "$module"; then
2946         func_get_description "$module"
2947       fi
2948     done
2949     ;;
2950
2951   extract-filelist )
2952     for module
2953     do
2954       func_verify_module
2955       if test -n "$module"; then
2956         func_get_filelist "$module"
2957       fi
2958     done
2959     ;;
2960
2961   extract-dependencies )
2962     for module
2963     do
2964       func_verify_module
2965       if test -n "$module"; then
2966         func_get_dependencies "$module"
2967       fi
2968     done
2969     ;;
2970
2971   extract-autoconf-snippet )
2972     for module
2973     do
2974       func_verify_module
2975       if test -n "$module"; then
2976         func_get_autoconf_snippet "$module"
2977       fi
2978     done
2979     ;;
2980
2981   extract-automake-snippet )
2982     for module
2983     do
2984       func_verify_module
2985       if test -n "$module"; then
2986         func_get_automake_snippet "$module"
2987       fi
2988     done
2989     ;;
2990
2991   extract-include-directive )
2992     for module
2993     do
2994       func_verify_module
2995       if test -n "$module"; then
2996         func_get_include_directive "$module"
2997       fi
2998     done
2999     ;;
3000
3001   extract-license )
3002     for module
3003     do
3004       func_verify_module
3005       if test -n "$module"; then
3006         func_get_license "$module"
3007       fi
3008     done
3009     ;;
3010
3011   extract-maintainer )
3012     for module
3013     do
3014       func_verify_module
3015       if test -n "$module"; then
3016         func_get_maintainer "$module"
3017       fi
3018     done
3019     ;;
3020
3021   extract-tests-module )
3022     for module
3023     do
3024       func_verify_module
3025       if test -n "$module"; then
3026         func_get_tests_module "$module"
3027       fi
3028     done
3029     ;;
3030
3031   * )
3032     func_fatal_error "unknown operation mode --$mode" ;;
3033 esac
3034
3035 rm -rf "$tmp"
3036 # Undo the effect of the previous 'trap' command. Some shellology:
3037 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
3038 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
3039 # exit); for the others we need to call 'exit' explicitly. The value of $? is
3040 # 128 + signal number and is set before the trap-registered command is run.
3041 trap '' 0
3042 trap 'func_exit $?' 1 2 3 13 15
3043
3044 exit 0
3045
3046 # Local Variables:
3047 # indent-tabs-mode: nil
3048 # whitespace-check-buffer-indent: nil
3049 # End: