Move out the body of the conversion function to a compilation unit of its own.
[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-08 19:20:07 $'
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/modules" && ls -1)
818     if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
819       (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
820     fi
821   } \
822       | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^COPYING$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
823       | sed -e '/-tests$/d' \
824       | LC_ALL=C sort -u
825 }
826
827 # func_verify_module
828 # verifies a module name
829 # Input:
830 # - local_gnulib_dir  from --local-dir
831 # - module          module name argument
832 func_verify_module ()
833 {
834   if { test -f "$gnulib_dir/modules/$module" \
835        || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
836             && test -f "$local_gnulib_dir/modules/$module"; }; } \
837      && test "CVS" != "$module" \
838      && test "ChangeLog" != "$module" \
839      && test "COPYING" != "$module" \
840      && test "README" != "$module" \
841      && test "TEMPLATE" != "$module" \
842      && test "TEMPLATE-TESTS" != "$module"; then
843     # OK, $module is a correct module name.
844     # Verify that building the module description with 'patch' succeeds.
845     func_lookup_file "modules/$module"
846   else
847     echo "gnulib-tool: module $module doesn't exist" 1>&2
848     module=
849   fi
850 }
851
852 # func_verify_nontests_module
853 # verifies a module name, excluding tests modules
854 # Input:
855 # - local_gnulib_dir  from --local-dir
856 # - module          module name argument
857 func_verify_nontests_module ()
858 {
859   case "$module" in
860     *-tests ) module= ;;
861     * ) func_verify_module ;;
862   esac
863 }
864
865 # func_verify_tests_module
866 # verifies a module name, considering only tests modules
867 # Input:
868 # - local_gnulib_dir  from --local-dir
869 # - module          module name argument
870 func_verify_tests_module ()
871 {
872   case "$module" in
873     *-tests ) func_verify_module ;;
874     * ) module= ;;
875   esac
876 }
877
878 sed_extract_prog=':[     ]*$/ {
879   :a
880     n
881     s/^Description:[     ]*$//
882     s/^Files:[   ]*$//
883     s/^Depends-on:[      ]*$//
884     s/^configure\.ac:[   ]*$//
885     s/^Makefile\.am:[    ]*$//
886     s/^Include:[         ]*$//
887     s/^License:[         ]*$//
888     s/^Maintainer:[      ]*$//
889     tb
890     p
891     ba
892   :b
893 }'
894
895 # func_get_description module
896 # Input:
897 # - local_gnulib_dir  from --local-dir
898 func_get_description ()
899 {
900   func_lookup_file "modules/$1"
901   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
902 }
903
904 # func_get_filelist module
905 # Input:
906 # - local_gnulib_dir  from --local-dir
907 func_get_filelist ()
908 {
909   func_lookup_file "modules/$1"
910   sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
911   echo m4/gnulib-common.m4
912   case "$autoconf_minversion" in
913     2.59)
914       #echo m4/onceonly.m4
915       echo m4/onceonly_2_57.m4
916       ;;
917   esac
918 }
919
920 # func_get_dependencies module
921 # Input:
922 # - local_gnulib_dir  from --local-dir
923 func_get_dependencies ()
924 {
925   # ${module}-tests always implicitly depends on ${module}.
926   echo "$1" | sed -n -e 's/-tests//p'
927   # Then the explicit dependencies listed in the module description.
928   func_lookup_file "modules/$1"
929   sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
930 }
931
932 # func_get_autoconf_snippet module
933 # Input:
934 # - local_gnulib_dir  from --local-dir
935 func_get_autoconf_snippet ()
936 {
937   func_lookup_file "modules/$1"
938   sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
939 }
940
941 # func_get_automake_snippet module
942 # Input:
943 # - local_gnulib_dir  from --local-dir
944 func_get_automake_snippet ()
945 {
946   func_lookup_file "modules/$1"
947   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
948   case "$1" in
949     *-tests)
950       # *-tests module live in tests/, not lib/.
951       ;;
952     *)
953       # Synthesize an EXTRA_DIST augmentation.
954       sed_combine_lines='/\\$/{
955         :a
956         N
957         s/\\\n/ /
958         s/\\$/\\/
959         ta
960       }'
961       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
962       already_mentioned_files=` \
963         sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
964         | sed -e "$sed_combine_lines" \
965         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
966       all_files=`func_get_filelist $1`
967       lib_files=`for f in $all_files; do \
968                    case $f in \
969                      lib/*) echo $f ;; \
970                    esac; \
971                  done | sed -e 's,^lib/,,'`
972       # Remove $already_mentioned_files from $lib_files.
973       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
974       extra_files=`for f in $already_mentioned_files; do echo $f; done \
975                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
976       if test -n "$extra_files"; then
977         echo "EXTRA_DIST +=" $extra_files
978         echo
979       fi
980       # Synthesize also an EXTRA_lib_SOURCES augmentation.
981       # This is necessary so that automake can generate the right list of
982       # dependency rules.
983       # A possible approach would be to use autom4te --trace of the redefined
984       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
985       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
986       # inside autoconf's built-in macros are not missed).
987       # But it's simpler and more robust to do it here, based on the file list.
988       # If some .c file exists and is not used with AC_LIBOBJ - for example,
989       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
990       # automake will generate a useless dependency; this is harmless.
991       sed_extract_c_files='/\.c$/p'
992       extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
993       if test -n "$extra_files"; then
994         echo "EXTRA_lib_SOURCES +=" $extra_files
995         echo
996       fi
997       ;;
998   esac
999 }
1000
1001 # func_get_include_directive module
1002 # Input:
1003 # - local_gnulib_dir  from --local-dir
1004 func_get_include_directive ()
1005 {
1006   func_lookup_file "modules/$1"
1007   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1008   sed -e 's/^\(["<]\)/#include \1/'
1009 }
1010
1011 # func_get_license module
1012 # Input:
1013 # - local_gnulib_dir  from --local-dir
1014 func_get_license ()
1015 {
1016   func_lookup_file "modules/$1"
1017   sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1018 }
1019
1020 # func_get_maintainer module
1021 # Input:
1022 # - local_gnulib_dir  from --local-dir
1023 func_get_maintainer ()
1024 {
1025   func_lookup_file "modules/$1"
1026   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1027 }
1028
1029 # func_get_tests_module module
1030 # Input:
1031 # - local_gnulib_dir  from --local-dir
1032 func_get_tests_module ()
1033 {
1034   # The naming convention for tests modules is hardwired: ${module}-tests.
1035   if test -f "$gnulib_dir/modules/$1"-tests \
1036      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1037           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1038     echo "$1"-tests
1039   fi
1040 }
1041
1042 # func_acceptable module
1043 # tests whether a module is acceptable.
1044 # Input:
1045 # - avoidlist       list of modules to avoid
1046 func_acceptable ()
1047 {
1048   for avoid in $avoidlist; do
1049     if test "$avoid" = "$1"; then
1050       return 1
1051     fi
1052   done
1053   return 0
1054 }
1055
1056 # func_modules_transitive_closure
1057 # Input:
1058 # - local_gnulib_dir  from --local-dir
1059 # - modules         list of specified modules
1060 # - inctests        true if tests should be included, blank otherwise
1061 # - avoidlist       list of modules to avoid
1062 # - tmp             pathname of a temporary directory
1063 # Output:
1064 # - modules         list of modules, including dependencies
1065 func_modules_transitive_closure ()
1066 {
1067   # In order to process every module only once (for speed), process an "input
1068   # list" of modules, producing an "output list" of modules. During each round,
1069   # more modules can be queued in the input list. Once a module on the input
1070   # list has been processed, it is added to the "handled list", so we can avoid
1071   # to process it again.
1072   handledmodules=
1073   inmodules="$modules"
1074   outmodules=
1075   while test -n "$inmodules"; do
1076     inmodules_this_round="$inmodules"
1077     inmodules=                    # Accumulator, queue for next round
1078     for module in $inmodules_this_round; do
1079       func_verify_module
1080       if test -n "$module"; then
1081         if func_acceptable $module; then
1082           func_append outmodules " $module"
1083           deps=`func_get_dependencies $module`
1084           # Duplicate dependencies are harmless, but Jim wants a warning.
1085           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1086           if test -n "$duplicated_deps"; then
1087             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1088           fi
1089           func_append inmodules " $deps"
1090           if test -n "$inctests"; then
1091             testsmodule=`func_get_tests_module $module`
1092             if test -n "$testsmodule"; then
1093               func_append inmodules " $testsmodule"
1094             fi
1095           fi
1096         fi
1097       fi
1098     done
1099     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1100     # Remove $handledmodules from $inmodules.
1101     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1102     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1103   done
1104   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1105   rm -f "$tmp"/queued-modules
1106 }
1107
1108 # func_modules_add_dummy
1109 # Input:
1110 # - local_gnulib_dir  from --local-dir
1111 # - modules         list of modules, including dependencies
1112 # Output:
1113 # - modules         list of modules, including 'dummy' if needed
1114 func_modules_add_dummy ()
1115 {
1116   have_lib_SOURCES=
1117   sed_remove_backslash_newline=':a
1118 /\\$/{
1119 s/\\$//
1120 N
1121 s/\n//
1122 ba
1123 }'
1124   for module in $modules; do
1125     func_verify_nontests_module
1126     if test -n "$module"; then
1127       # Extract the value of "lib_SOURCES += ...".
1128       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1129         # Ignore .h files since they are not compiled.
1130         case "$file" in
1131           *.h) ;;
1132           *) have_lib_SOURCES=yes ;;
1133         esac
1134       done
1135     fi
1136   done
1137   # Add the dummy module, to make sure the library will be non-empty.
1138   if test -z "$have_lib_SOURCES"; then
1139     func_append modules " dummy"
1140   fi
1141 }
1142
1143 # func_modules_to_filelist
1144 # Input:
1145 # - local_gnulib_dir  from --local-dir
1146 # - modules         list of modules, including dependencies
1147 # Output:
1148 # - files           list of files
1149 func_modules_to_filelist ()
1150 {
1151   files=
1152   for module in $modules; do
1153     func_verify_module
1154     if test -n "$module"; then
1155       fs=`func_get_filelist $module`
1156       func_append files " $fs"
1157     fi
1158   done
1159   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1160 }
1161
1162 # func_emit_lib_Makefile_am
1163 # emits the contents of library makefile to standard output.
1164 # Input:
1165 # - local_gnulib_dir  from --local-dir
1166 # - modules         list of modules, including dependencies
1167 # - libname         library name
1168 # - auxdir          directory relative to destdir where to place build aux files
1169 # - makefile_name   from --makefile-name
1170 # - libtool         true if libtool will be used, false or blank otherwise
1171 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1172 # - actioncmd       (optional) command that will reproduce this invocation
1173 # Output:
1174 # - uses_subdirs    nonempty if object files in subdirs exist
1175 func_emit_lib_Makefile_am ()
1176 {
1177   # When creating an includable Makefile.am snippet, augment variables with
1178   # += instead of assigning them.
1179   if test -n "$makefile_name"; then
1180     assign='+='
1181   else
1182     assign='='
1183   fi
1184   if test "$libtool" = true; then
1185     libext=la
1186     perhapsLT=LT
1187     sed_eliminate_LDFLAGS=
1188   else
1189     libext=a
1190     perhapsLT=
1191     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1192   fi
1193   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1194   echo "## Process this file with automake to produce Makefile.in."
1195   func_emit_copyright_notice
1196   if test -n "$actioncmd"; then
1197     echo "# Reproduce by: $actioncmd"
1198   fi
1199   echo
1200   uses_subdirs=
1201   {
1202     for module in $modules; do
1203       func_verify_nontests_module
1204       if test -n "$module"; then
1205         {
1206           func_get_automake_snippet "$module" |
1207             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1208                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1209             sed -e "$sed_eliminate_LDFLAGS" |
1210             sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1211             sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1212                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1213           if test "$module" = 'alloca'; then
1214             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1215             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1216           fi
1217         } > amsnippet.tmp
1218         # Skip the contents if its entirely empty.
1219         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1220           echo "## begin gnulib module $module"
1221           echo
1222           cat amsnippet.tmp
1223           echo "## end   gnulib module $module"
1224           echo
1225         fi
1226         rm -f amsnippet.tmp
1227         # Test whether there are some source files in subdirectories.
1228         for f in `func_get_filelist "$module"`; do
1229           case $f in
1230             lib/*/*.c) uses_subdirs=yes ;;
1231           esac
1232         done
1233       fi
1234     done
1235   } > allsnippets.tmp
1236   if test -z "$makefile_name"; then
1237     # If there are source files in subdirectories, prevent collision of the
1238     # object files (example: hash.c and libxml/hash.c).
1239     subdir_options=
1240     if test -n "$uses_subdirs"; then
1241       subdir_options=' subdir-objects'
1242     fi
1243     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1244   fi
1245   echo
1246   if test -z "$makefile_name"; then
1247     echo "noinst_HEADERS ="
1248     echo "noinst_LIBRARIES ="
1249     echo "noinst_LTLIBRARIES ="
1250     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1251     # if you specify pkgdata_DATA to empty. This is a workaround.
1252     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1253       echo "pkgdata_DATA ="
1254     fi
1255     echo "EXTRA_DIST ="
1256     echo "BUILT_SOURCES ="
1257     echo "SUFFIXES ="
1258   fi
1259   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1260   if test -z "$makefile_name"; then
1261     echo "MOSTLYCLEANDIRS ="
1262     echo "CLEANFILES ="
1263     echo "DISTCLEANFILES ="
1264     echo "MAINTAINERCLEANFILES ="
1265     echo
1266     echo "AM_CPPFLAGS ="
1267   fi
1268   echo
1269   if grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1270     # One of the snippets already specifies an installation location for the
1271     # library. Don't confuse automake by saying it should not be installed.
1272     :
1273   else
1274     # By default, the generated library should not be installed.
1275     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1276   fi
1277   echo
1278   echo "${libname}_${libext}_SOURCES ="
1279   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1280   # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1281   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1282   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1283   echo "EXTRA_${libname}_${libext}_SOURCES ="
1284   if test "$libtool" = true; then
1285     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1286   fi
1287   echo
1288   cat allsnippets.tmp \
1289     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1290   echo
1291   echo "mostlyclean-local: mostlyclean-generic"
1292   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1293   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1294   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1295   echo "          fi; \\"
1296   echo "        done"
1297   rm -f allsnippets.tmp
1298 }
1299
1300 # func_emit_tests_Makefile_am
1301 # emits the contents of tests makefile to standard output.
1302 # Input:
1303 # - local_gnulib_dir  from --local-dir
1304 # - modules         list of modules, including dependencies
1305 # - libname         library name
1306 # - makefile_name   from --makefile-name
1307 # - libtool         true if libtool will be used, false or blank otherwise
1308 # - sourcebase      relative directory containing lib source code
1309 # - m4base          relative directory containing autoconf macros
1310 # - testsbase       relative directory containing unit test code
1311 func_emit_tests_Makefile_am ()
1312 {
1313   if test "$libtool" = true; then
1314     libext=la
1315   else
1316     libext=a
1317   fi
1318   if test "$libtool" = true; then
1319     libext=la
1320     sed_eliminate_LDFLAGS=
1321   else
1322     libext=a
1323     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1324   fi
1325   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1326   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1327   echo "## Process this file with automake to produce Makefile.in."
1328   func_emit_copyright_notice
1329   echo
1330   # Generate dependencies here, since it eases the debugging of test failures.
1331   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1332   echo
1333   echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1334   echo
1335   (
1336     for module in $modules; do
1337       func_verify_tests_module
1338       if test -n "$module"; then
1339         {
1340           func_get_automake_snippet "$module" |
1341             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1342                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1343             sed -e "$sed_eliminate_LDFLAGS" |
1344             sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1345             sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1346                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1347         } > amsnippet.tmp
1348         # Skip the contents if its entirely empty.
1349         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1350           echo "## begin gnulib module $module"
1351           echo
1352           cat amsnippet.tmp
1353           echo "## end   gnulib module $module"
1354           echo
1355         fi
1356         rm -f amsnippet.tmp
1357       fi
1358     done
1359   ) > allsnippets.tmp
1360   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1361   # variable is needed to avoid an error from automake:
1362   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1363   echo "SUBDIRS ="
1364   echo "TESTS ="
1365   echo "TESTS_ENVIRONMENT ="
1366   echo "noinst_PROGRAMS ="
1367   echo "check_PROGRAMS ="
1368   echo "noinst_HEADERS ="
1369   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1370     echo "pkgdata_DATA ="
1371   fi
1372   echo "EXTRA_DIST ="
1373   echo "BUILT_SOURCES ="
1374   echo "SUFFIXES ="
1375   echo "MOSTLYCLEANFILES = core *.stackdump"
1376   echo "MOSTLYCLEANDIRS ="
1377   echo "CLEANFILES ="
1378   echo "DISTCLEANFILES ="
1379   echo "MAINTAINERCLEANFILES ="
1380   echo
1381   echo "AM_CPPFLAGS = \\"
1382   echo "  -I. -I\$(srcdir) \\"
1383   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1384   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1385   echo
1386   echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1387   echo
1388   cat allsnippets.tmp
1389   echo "# Clean up after Solaris cc."
1390   echo "clean-local:"
1391   echo "        rm -rf SunWS_cache"
1392   echo
1393   echo "mostlyclean-local: mostlyclean-generic"
1394   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1395   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1396   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1397   echo "          fi; \\"
1398   echo "        done"
1399   rm -f allsnippets.tmp
1400 }
1401
1402 # func_emit_initmacro_start
1403 # emits the first few statements of the gl_INIT macro to standard output.
1404 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1405 func_emit_initmacro_start ()
1406 {
1407   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1408   # platform-dependent object files in ${macro_prefix}_LIBOBJS instead of
1409   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1410   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1411   # flexibility.)
1412   # Furthermore it avoids an automake error like this when a Makefile.am
1413   # that uses pieces of gnulib also uses $(LIBOBJ):
1414   #   automatically discovered file `error.c' should not be explicitly mentioned
1415   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix}_LIBOBJ]))"
1416   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix}_REPLACE_FUNCS]))"
1417   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1418   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1419   #   automatically discovered file `error.c' should not be explicitly mentioned
1420   # We let automake know about the files to be distributed through the
1421   # EXTRA_lib_SOURCES variable.
1422   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix}_LIBSOURCES]))"
1423 }
1424
1425 # func_emit_initmacro_end
1426 # emits the last few statements of the gl_INIT macro to standard output.
1427 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1428 func_emit_initmacro_end ()
1429 {
1430   echo "  m4_popdef([AC_LIBSOURCES])"
1431   echo "  m4_popdef([AC_REPLACE_FUNCS])"
1432   echo "  m4_popdef([AC_LIBOBJ])"
1433   echo "  AC_CONFIG_COMMANDS_PRE(["
1434   echo "    ${macro_prefix}_libobjs="
1435   echo "    ${macro_prefix}_ltlibobjs="
1436   echo "    if test -n \"\$${macro_prefix}_LIBOBJS\"; then"
1437   echo "      # Remove the extension."
1438   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
1439   echo "      for i in \`for i in \$${macro_prefix}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
1440   echo "        ${macro_prefix}_libobjs=\"\$${macro_prefix}_libobjs \$i.\$ac_objext\""
1441   echo "        ${macro_prefix}_ltlibobjs=\"\$${macro_prefix}_ltlibobjs \$i.lo\""
1442   echo "      done"
1443   echo "    fi"
1444   echo "    AC_SUBST([${macro_prefix}_LIBOBJS], [\$${macro_prefix}_libobjs])"
1445   echo "    AC_SUBST([${macro_prefix}_LTLIBOBJS], [\$${macro_prefix}_ltlibobjs])"
1446   echo "  ])"
1447 }
1448
1449 # func_emit_initmacro_done
1450 # emits a few statements after the gl_INIT macro to standard output.
1451 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1452 func_emit_initmacro_done ()
1453 {
1454   echo
1455   echo "# Like AC_LIBOBJ, except that the module name goes"
1456   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1457   echo "AC_DEFUN([${macro_prefix}_LIBOBJ],"
1458   echo "  [${macro_prefix}_LIBOBJS=\"\$${macro_prefix}_LIBOBJS \$1.\$ac_objext\"])"
1459   echo
1460   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
1461   echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1462   echo "AC_DEFUN([${macro_prefix}_REPLACE_FUNCS],"
1463   echo "  [AC_CHECK_FUNCS([\$1], , [${macro_prefix}_LIBOBJ(\$ac_func)])])"
1464   echo
1465   echo "# Like AC_LIBSOURCES, except that it does nothing."
1466   echo "# We rely on EXTRA_lib..._SOURCES instead."
1467   echo "AC_DEFUN([${macro_prefix}_LIBSOURCES],"
1468   echo "  [])"
1469 }
1470
1471 # func_import modules
1472 # Uses also the variables
1473 # - destdir         target directory
1474 # - local_gnulib_dir  from --local-dir
1475 # - libname         library name
1476 # - sourcebase      directory relative to destdir where to place source code
1477 # - m4base          directory relative to destdir where to place *.m4 macros
1478 # - docbase         directory relative to destdir where to place doc files
1479 # - testsbase       directory relative to destdir where to place unit test code
1480 # - auxdir          directory relative to destdir where to place build aux files
1481 # - inctests        true if --with-tests was given, blank otherwise
1482 # - avoidlist       list of modules to avoid, from --avoid
1483 # - lgpl            true if library's license shall be LGPL, blank otherwise
1484 # - makefile_name   from --makefile-name
1485 # - libtool         true if --libtool was given, false if --no-libtool was
1486 #                   given, blank otherwise
1487 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1488 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1489 # - autoconf_minversion  minimum supported autoconf version
1490 # - doit            : if actions shall be executed, false if only to be printed
1491 # - symbolic        true if files should be symlinked, copied otherwise
1492 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
1493 #                   copied otherwise
1494 func_import ()
1495 {
1496   # Get the cached settings.
1497   cached_local_gnulib_dir=
1498   cached_specified_modules=
1499   cached_avoidlist=
1500   cached_sourcebase=
1501   cached_m4base=
1502   cached_docbase=
1503   cached_testsbase=
1504   cached_libname=
1505   cached_lgpl=
1506   cached_makefile_name=
1507   cached_libtool=
1508   cached_macro_prefix=
1509   cached_files=
1510   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1511     cached_libtool=false
1512     my_sed_traces='
1513       s,#.*$,,
1514       s,^dnl .*$,,
1515       s, dnl .*$,,
1516       /gl_LOCAL_DIR(/ {
1517         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1518       }
1519       /gl_MODULES(/ {
1520         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1521       }
1522       /gl_AVOID(/ {
1523         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1524       }
1525       /gl_SOURCE_BASE(/ {
1526         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1527       }
1528       /gl_M4_BASE(/ {
1529         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1530       }
1531       /gl_DOC_BASE(/ {
1532         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1533       }
1534       /gl_TESTS_BASE(/ {
1535         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1536       }
1537       /gl_LIB(/ {
1538         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1539       }
1540       /gl_LGPL/ {
1541         s,^.*$,cached_lgpl=true,p
1542       }
1543       /gl_MAKEFILE_NAME(/ {
1544         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1545       }
1546       /gl_LIBTOOL/ {
1547         s,^.*$,cached_libtool=true,p
1548       }
1549       /gl_MACRO_PREFIX(/ {
1550         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1551       }'
1552     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1553     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1554       my_sed_traces='
1555         s,#.*$,,
1556         s,^dnl .*$,,
1557         s, dnl .*$,,
1558         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1559           s,^.*$,cached_files=",p
1560           n
1561           ta
1562           :a
1563           s,^\]).*$,",
1564           tb
1565           p
1566           n
1567           ba
1568           :b
1569           p
1570         }'
1571       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1572     fi
1573   fi
1574
1575   # Merge the cached settings with the specified ones.
1576   # The m4base must be the same as expected from the pathname.
1577   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1578     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1579   fi
1580   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1581   # is relative to $destdir, whereas the one we use is relative to . or absolute.
1582   if test -z "$local_gnulib_dir"; then
1583     if test -n "$cached_local_gnulib_dir"; then
1584       case "$destdir" in
1585         /*)
1586           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1587         *)
1588           case "$cached_local_gnulib_dir" in
1589             /*)
1590               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1591             *)
1592               func_relconcat "$destdir" "$cached_local_gnulib_dir"
1593               local_gnulib_dir="$relconcat" ;;
1594           esac ;;
1595       esac
1596     fi
1597   fi
1598   # Append the cached and the specified module names. So that
1599   # "gnulib-tool --import foo" means to add the module foo.
1600   specified_modules="$cached_specified_modules $1"
1601   # Append the cached and the specified avoidlist. This is probably better
1602   # than dropping the cached one when --avoid is specified at least once.
1603   avoidlist=`echo $cached_avoidlist $avoidlist`
1604   # The sourcebase defaults to the cached one.
1605   if test -z "$sourcebase"; then
1606     sourcebase="$cached_sourcebase"
1607     if test -z "$sourcebase"; then
1608       func_fatal_error "missing --source-base option"
1609     fi
1610   fi
1611   # The docbase defaults to the cached one.
1612   if test -z "$docbase"; then
1613     docbase="$cached_docbase"
1614     if test -z "$docbase"; then
1615       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."
1616     fi
1617   fi
1618   # The testsbase defaults to the cached one.
1619   if test -z "$testsbase"; then
1620     testsbase="$cached_testsbase"
1621     if test -z "$testsbase"; then
1622       func_fatal_error "missing --tests-base option"
1623     fi
1624   fi
1625   # The libname defaults to the cached one.
1626   if test -z "$supplied_libname"; then
1627     libname="$cached_libname"
1628     if test -z "$libname"; then
1629       func_fatal_error "missing --lib option"
1630     fi
1631   fi
1632   # Require LGPL if specified either way.
1633   if test -z "$lgpl"; then
1634     lgpl="$cached_lgpl"
1635   fi
1636   # The makefile_name defaults to the cached one.
1637   if test -z "$makefile_name"; then
1638     makefile_name="$cached_makefile_name"
1639   fi
1640   # Use libtool if specified either way, or if guessed.
1641   if test -z "$libtool"; then
1642     if test -n "$cached_m4base"; then
1643       libtool="$cached_libtool"
1644     else
1645       libtool="$guessed_libtool"
1646     fi
1647   fi
1648   # The macro_prefix defaults to the cached one.
1649   if test -z "$macro_prefix"; then
1650     macro_prefix="$cached_macro_prefix"
1651     if test -z "$macro_prefix"; then
1652       func_fatal_error "missing --macro-prefix option"
1653     fi
1654   fi
1655
1656   # Canonicalize the list of specified modules.
1657   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1658
1659   # Determine final module list.
1660   modules="$specified_modules"
1661   func_modules_transitive_closure
1662   echo "Module list with included dependencies:"
1663   echo "$modules" | sed -e 's/^/  /'
1664
1665   # Add the dummy module if needed.
1666   func_modules_add_dummy
1667
1668   # If --lgpl, verify that the licenses of modules are compatible.
1669   if test -n "$lgpl"; then
1670     for module in $modules; do
1671       license=`func_get_license $module`
1672       case $license in
1673         LGPL | 'GPLed build tool') ;;
1674         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1675         *) func_fatal_error "incompatible license on module $module: $license" ;;
1676       esac
1677     done
1678   fi
1679
1680   # Determine script to apply to imported library files.
1681   sed_transform_lib_file=
1682   for module in $modules; do
1683     if test $module = config-h; then
1684       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1685       sed_transform_lib_file=$sed_transform_lib_file'
1686         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
1687       '
1688       break
1689     fi
1690   done
1691   if test -n "$lgpl"; then
1692     # Update license.
1693     sed_transform_lib_file=$sed_transform_lib_file'
1694       s/GNU General/GNU Lesser General/g
1695       s/version 2\([ ,]\)/version 2.1\1/g
1696     '
1697   fi
1698
1699   # Determine final file list.
1700   func_modules_to_filelist
1701   echo "File list:"
1702   echo "$files" | sed -e 's/^/  /'
1703
1704   test -n "$files" \
1705     || func_fatal_error "refusing to do nothing"
1706
1707   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1708   new_files="$files m4/gnulib-tool.m4"
1709   old_files="$cached_files"
1710   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1711     func_append old_files " m4/gnulib-tool.m4"
1712   fi
1713
1714   sed_rewrite_old_files="\
1715     s,^build-aux/,$auxdir/,
1716     s,^doc/,$cached_docbase/,
1717     s,^lib/,$cached_sourcebase/,
1718     s,^m4/,$cached_m4base/,
1719     s,^tests/,$cached_testsbase/,"
1720   sed_rewrite_new_files="\
1721     s,^build-aux/,$auxdir/,
1722     s,^doc/,$docbase/,
1723     s,^lib/,$sourcebase/,
1724     s,^m4/,$m4base/,
1725     s,^tests/,$testsbase/,"
1726
1727   # Create directories.
1728   { echo "$sourcebase"
1729     echo "$m4base"
1730     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1731     if test -n "$docfiles"; then
1732       echo "$docbase"
1733     fi
1734     if test -n "$inctests"; then
1735       echo "$testsbase"
1736     fi
1737     echo "$auxdir"
1738     for f in $files; do echo $f; done \
1739       | sed -e "$sed_rewrite_new_files" \
1740       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
1741       | LC_ALL=C sort -u
1742   } > "$tmp"/dirs
1743   { # Rearrange file descriptors. Needed because "while ... done < ..."
1744     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1745     exec 5<&0 < "$tmp"/dirs
1746     while read d; do
1747       if test ! -d "$destdir/$d"; then
1748         if $doit; then
1749           echo "Creating directory $destdir/$d"
1750           mkdir -p "$destdir/$d" || func_fatal_error "failed"
1751         else
1752           echo "Create directory $destdir/$d"
1753         fi
1754       fi
1755     done
1756     exec 0<&5 5<&-
1757   }
1758
1759   # func_dest_tmpfilename file
1760   # determines the name of a temporary file (file is relative to destdir).
1761   # Sets variable:
1762   #   - tmpfile       absolute filename of the temporary file
1763   func_dest_tmpfilename ()
1764   {
1765     if $doit; then
1766       # Put the new contents of $file in a file in the same directory (needed
1767       # to guarantee that an 'mv' to "$destdir/$file" works).
1768       tmpfile="$destdir/$1.tmp"
1769     else
1770       # Put the new contents of $file in a file in a temporary directory
1771       # (because the directory of "$file" might not exist).
1772       tmpfile="$tmp"/`basename "$1"`.tmp
1773     fi
1774   }
1775
1776   # Copy files or make symbolic links. Remove obsolete files.
1777   delimiter='   '
1778   # Construct a table with 2 columns: rewritten-file-name original-file-name,
1779   # representing the files according to the last gnulib-tool invocation.
1780   for f in $old_files; do echo $f; done \
1781     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
1782     | LC_ALL=C sort \
1783     > "$tmp"/old-files
1784   # Construct a table with 2 columns: rewritten-file-name original-file-name,
1785   # representing the files after this gnulib-tool invocation.
1786   for f in $new_files; do echo $f; done \
1787     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
1788     | LC_ALL=C sort \
1789     > "$tmp"/new-files
1790   # First the files that are in old-files, but not in new-files:
1791   sed_take_first_column='s,'"$delimiter"'.*,,'
1792   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1793     # Remove the file. Do nothing if the user already removed it.
1794     if test -f "$destdir/$g"; then
1795       if $doit; then
1796         echo "Removing file $g (backup in ${g}~)"
1797         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1798       else
1799         echo "Remove file $g (backup in ${g}~)"
1800       fi
1801     fi
1802   done
1803   # func_add_or_update handles a file that ought to be present afterwards.
1804   # Uses parameters
1805   # - f             the original file name
1806   # - g             the rewritten file name
1807   # - already_present  nonempty if the file already exists, empty otherwise
1808   func_add_or_update ()
1809   {
1810     func_dest_tmpfilename "$g"
1811     func_lookup_file "$f"
1812     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1813     if test -n "$sed_transform_lib_file"; then
1814       case "$f" in
1815         lib/*)
1816           sed -e "$sed_transform_lib_file" \
1817             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1818           ;;
1819       esac
1820     fi
1821     if test -f "$destdir/$g"; then
1822       # The file already exists.
1823       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1824         : # The file has not changed.
1825       else
1826         # Replace the file.
1827         if $doit; then
1828           if test -n "$already_present"; then
1829             echo "Updating file $g (backup in ${g}~)"
1830           else
1831             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1832           fi
1833           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1834           if { test -n "$symbolic" \
1835                || { test -n "$lsymbolic" \
1836                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
1837              && test -z "$lookedup_tmp" \
1838              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1839             func_ln_if_changed "$lookedup_file" "$destdir/$g"
1840           else
1841             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1842           fi
1843         else
1844           if test -n "$already_present"; then
1845             echo "Update file $g (backup in ${g}~)"
1846           else
1847             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1848           fi
1849         fi
1850       fi
1851     else
1852       # Install the file.
1853       # Don't protest if the file should be there but isn't: it happens
1854       # frequently that developers don't put autogenerated files into CVS.
1855       if $doit; then
1856         echo "Copying file $g"
1857         if { test -n "$symbolic" \
1858              || { test -n "$lsymbolic" \
1859                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
1860            && test -z "$lookedup_tmp" \
1861            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1862           func_ln_if_changed "$lookedup_file" "$destdir/$g"
1863         else
1864           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1865         fi
1866       else
1867         echo "Copy file $g"
1868       fi
1869     fi
1870     rm -f "$tmpfile"
1871   }
1872   # Then the files that are in new-files, but not in old-files:
1873   sed_take_last_column='s,^.*'"$delimiter"',,'
1874   already_present=
1875   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
1876     | sed -e "$sed_take_last_column" \
1877     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
1878   { # Rearrange file descriptors. Needed because "while ... done < ..."
1879     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1880     exec 5<&0 < "$tmp"/added-files
1881     while read g f; do
1882       func_add_or_update
1883     done
1884     exec 0<&5 5<&-
1885   }
1886   # Then the files that are in new-files and in old-files:
1887   already_present=true
1888   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
1889     | sed -e "$sed_take_last_column" \
1890     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
1891   { # Rearrange file descriptors. Needed because "while ... done < ..."
1892     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1893     exec 5<&0 < "$tmp"/kept-files
1894     while read g f; do
1895       func_add_or_update
1896     done
1897     exec 0<&5 5<&-
1898   }
1899
1900   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1901   actioncmd="gnulib-tool --import"
1902   func_append actioncmd " --dir=$destdir"
1903   if test -n "$local_gnulib_dir"; then
1904     func_append actioncmd " --local-dir=$local_gnulib_dir"
1905   fi
1906   func_append actioncmd " --lib=$libname"
1907   func_append actioncmd " --source-base=$sourcebase"
1908   func_append actioncmd " --m4-base=$m4base"
1909   func_append actioncmd " --doc-base=$docbase"
1910   func_append actioncmd " --aux-dir=$auxdir"
1911   for module in $avoidlist; do
1912     func_append actioncmd " --avoid=$module"
1913   done
1914   if test -n "$lgpl"; then
1915     func_append actioncmd " --lgpl"
1916   fi
1917   if test -n "$makefile_name"; then
1918     func_append actioncmd " --makefile-name=$makefile_name"
1919   fi
1920   if test "$libtool" = true; then
1921     func_append actioncmd " --libtool"
1922   else
1923     func_append actioncmd " --no-libtool"
1924   fi
1925   func_append actioncmd " --macro-prefix=$macro_prefix"
1926   func_append actioncmd " `echo $specified_modules`"
1927
1928   # Default the makefile name to Makefile.am.
1929   if test -n "$makefile_name"; then
1930     makefile_am=$makefile_name
1931   else
1932     makefile_am=Makefile.am
1933   fi
1934
1935   # Create library makefile.
1936   func_dest_tmpfilename $sourcebase/$makefile_am
1937   func_emit_lib_Makefile_am > "$tmpfile"
1938   if test -f "$destdir"/$sourcebase/$makefile_am; then
1939     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
1940       rm -f "$tmpfile"
1941     else
1942       if $doit; then
1943         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1944         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
1945         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1946       else
1947         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1948         rm -f "$tmpfile"
1949       fi
1950     fi
1951   else
1952     if $doit; then
1953       echo "Creating $sourcebase/$makefile_am"
1954       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1955     else
1956       echo "Create $sourcebase/$makefile_am"
1957       rm -f "$tmpfile"
1958     fi
1959   fi
1960
1961   # Create m4/gnulib-cache.m4.
1962   func_dest_tmpfilename $m4base/gnulib-cache.m4
1963   (
1964     func_emit_copyright_notice
1965     echo "#"
1966     echo "# This file represents the specification of how gnulib-tool is used."
1967     echo "# It acts as a cache: It is written and read by gnulib-tool."
1968     echo "# In projects using CVS, this file is meant to be stored in CVS,"
1969     echo "# like the configure.ac and various Makefile.am files."
1970     echo
1971     echo
1972     echo "# Specification in the form of a command-line invocation:"
1973     echo "#   $actioncmd"
1974     echo
1975     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1976     # Store the local_gnulib_dir relative to destdir.
1977     case "$local_gnulib_dir" in
1978       "" | /*)
1979         relative_local_gnulib_dir="$local_gnulib_dir" ;;
1980       * )
1981         case "$destdir" in
1982           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
1983           *)
1984             # destdir, local_gnulib_dir are both relative.
1985             func_relativize "$destdir" "$local_gnulib_dir"
1986             relative_local_gnulib_dir="$reldir" ;;
1987         esac ;;
1988     esac
1989     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
1990     echo "gl_MODULES(["`echo $specified_modules`"])"
1991     echo "gl_AVOID([$avoidlist])"
1992     echo "gl_SOURCE_BASE([$sourcebase])"
1993     echo "gl_M4_BASE([$m4base])"
1994     echo "gl_DOC_BASE([$docbase])"
1995     echo "gl_TESTS_BASE([$testsbase])"
1996     echo "gl_LIB([$libname])"
1997     test -z "$lgpl" || echo "gl_LGPL"
1998     echo "gl_MAKEFILE_NAME([$makefile_name])"
1999     if test "$libtool" = true; then
2000       echo "gl_LIBTOOL"
2001     fi
2002     echo "gl_MACRO_PREFIX([$macro_prefix])"
2003   ) > "$tmpfile"
2004   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2005     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2006       rm -f "$tmpfile"
2007     else
2008       if $doit; then
2009         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2010         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2011         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2012       else
2013         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2014         if false; then
2015           cat "$tmpfile"
2016           echo
2017           echo "# gnulib-cache.m4 ends here"
2018         fi
2019         rm -f "$tmpfile"
2020       fi
2021     fi
2022   else
2023     if $doit; then
2024       echo "Creating $m4base/gnulib-cache.m4"
2025       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2026     else
2027       echo "Create $m4base/gnulib-cache.m4"
2028       cat "$tmpfile"
2029       rm -f "$tmpfile"
2030     fi
2031   fi
2032
2033   # Create m4/gnulib-comp.m4.
2034   func_dest_tmpfilename $m4base/gnulib-comp.m4
2035   (
2036     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2037     func_emit_copyright_notice
2038     echo "#"
2039     echo "# This file represents the compiled summary of the specification in"
2040     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2041     echo "# to be invoked from configure.ac."
2042     echo "# In projects using CVS, this file can be treated like other built files."
2043     echo
2044     echo
2045     echo "# This macro should be invoked from $configure_ac, in the section"
2046     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2047     echo "# any checks for libraries, header files, types and library functions."
2048     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2049     echo "["
2050     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2051     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2052     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2053     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2054     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2055     if test -n "$uses_subdirs"; then
2056       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2057     fi
2058     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2059       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2060     fi
2061     if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2062       echo "  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
2063     fi
2064     if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2065       echo "  AC_REQUIRE([gl_LOCK_EARLY])"
2066     fi
2067     echo "])"
2068     echo
2069     echo "# This macro should be invoked from $configure_ac, in the section"
2070     echo "# \"Check for header files, types and library functions\"."
2071     echo "AC_DEFUN([${macro_prefix}_INIT],"
2072     echo "["
2073     func_emit_initmacro_start
2074     if test "$libtool" = true; then
2075       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2076       echo "  gl_cond_libtool=true"
2077     else
2078       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2079       echo "  gl_cond_libtool=false"
2080       echo "  gl_libdeps="
2081       echo "  gl_ltlibdeps="
2082     fi
2083     echo "  gl_source_base='$sourcebase'"
2084     if test "$auxdir" != "build-aux"; then
2085       sed_replace_build_aux='
2086         :a
2087         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2088           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2089           ba
2090         }'
2091       sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2092     else
2093       sed_replace_build_aux=
2094     fi
2095     for module in $modules; do
2096       func_verify_module
2097       if test -n "$module"; then
2098         func_get_autoconf_snippet "$module" \
2099           | sed -e '/^$/d;' -e 's/^/  /' \
2100                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
2101                 -e "$sed_replace_build_aux"
2102         if test "$module" = 'alloca' && test "$libtool" = true; then
2103           echo 'changequote(,)dnl'
2104           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
2105           echo 'changequote([, ])dnl'
2106           echo 'AC_SUBST([LTALLOCA])'
2107         fi
2108       fi
2109     done
2110     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2111     # created using libtool, because libtool already handles the dependencies.
2112     if test "$libtool" != true; then
2113       libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2114       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2115       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2116       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2117       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2118     fi
2119     func_emit_initmacro_end
2120     echo "])"
2121     func_emit_initmacro_done
2122     echo
2123     echo "# This macro records the list of files which have been installed by"
2124     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
2125     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
2126     echo "$files" | sed -e 's,^,  ,'
2127     echo "])"
2128   ) > "$tmpfile"
2129   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2130     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
2131       rm -f "$tmpfile"
2132     else
2133       if $doit; then
2134         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2135         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
2136         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2137       else
2138         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2139         if false; then
2140           cat "$tmpfile"
2141           echo
2142           echo "# gnulib-comp.m4 ends here"
2143         fi
2144         rm -f "$tmpfile"
2145       fi
2146     fi
2147   else
2148     if $doit; then
2149       echo "Creating $m4base/gnulib-comp.m4"
2150       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2151     else
2152       echo "Create $m4base/gnulib-comp.m4"
2153       cat "$tmpfile"
2154       rm -f "$tmpfile"
2155     fi
2156   fi
2157
2158   if test -n "$inctests"; then
2159     # Create tests makefile.
2160     func_dest_tmpfilename $testsbase/$makefile_am
2161     func_emit_tests_Makefile_am > "$tmpfile"
2162     if test -f "$destdir"/$testsbase/$makefile_am; then
2163       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
2164         rm -f "$tmpfile"
2165       else
2166         if $doit; then
2167           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2168           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
2169           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2170         else
2171           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2172           rm -f "$tmpfile"
2173         fi
2174       fi
2175     else
2176       if $doit; then
2177         echo "Creating $testsbase/$makefile_am"
2178         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2179       else
2180         echo "Create $testsbase/$makefile_am"
2181         rm -f "$tmpfile"
2182       fi
2183     fi
2184   fi
2185
2186   echo "Finished."
2187   echo
2188   echo "You may need to add #include directives for the following .h files."
2189   # Intersect $specified_modules and $modules
2190   # (since $specified_modules is not necessarily of subset of $modules - some
2191   # may have been skipped through --avoid, and since the elements of $modules
2192   # but not in $specified_modules can go away without explicit notice - through
2193   # changes in the module dependencies).
2194   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
2195   echo "$modules" > "$tmp"/modules2 # also a sorted list, one module per line
2196   # First the #include <...> directives without #ifs, sorted for convenience,
2197   # then the #include "..." directives without #ifs, sorted for convenience,
2198   # then the #include directives that are surrounded by #ifs. Not sorted.
2199   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
2200     include_directive=`func_get_include_directive "$module"`
2201     case "$nl$include_directive" in
2202       *"$nl#if"*)
2203         echo "$include_directive" 1>&5
2204         ;;
2205       *)
2206         echo "$include_directive" | grep -v 'include "' 1>&6
2207         echo "$include_directive" | grep 'include "' 1>&7
2208         ;;
2209     esac
2210   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2211   (
2212    LC_ALL=C sort -u "$tmp"/include-angles
2213    LC_ALL=C sort -u "$tmp"/include-quotes
2214    cat "$tmp"/include-if
2215   ) | sed -e '/^$/d' -e 's/^/  /'
2216   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2217
2218   echo
2219   echo "Don't forget to"
2220   if test "$makefile_am" = Makefile.am; then
2221     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2222   else
2223     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2224   fi
2225   if test -n "$inctests"; then
2226     if test "$makefile_am" = Makefile.am; then
2227       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2228     else
2229       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2230     fi
2231   fi
2232   if test "$makefile_am" = Makefile.am; then
2233     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2234     sourcebase_base=`basename "$sourcebase"`
2235     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2236   fi
2237   if test -n "$inctests"; then
2238     if test "$makefile_am" = Makefile.am; then
2239       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2240       testsbase_base=`basename "$testsbase"`
2241       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2242     fi
2243   fi
2244   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2245   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2246   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
2247 }
2248
2249 # func_create_testdir testdir modules
2250 # Input:
2251 # - local_gnulib_dir  from --local-dir
2252 # - auxdir          directory relative to destdir where to place build aux files
2253 func_create_testdir ()
2254 {
2255   testdir="$1"
2256   modules="$2"
2257   if test -z "$modules"; then
2258     # All modules together.
2259     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2260     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2261     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
2262     modules=`func_all_modules`
2263     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
2264   fi
2265   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2266
2267   # Check that the license of every module is consistent with the license of
2268   # its dependencies.
2269   saved_modules="$modules"
2270   for requested_module in $saved_modules; do
2271     requested_license=`func_get_license "$requested_module"`
2272     if test "$requested_license" != GPL; then
2273       # Here we use func_modules_transitive_closure, not just
2274       # func_get_dependencies, so that we also detect weird situations like
2275       # an LGPL module which depends on a GPLed build tool module which depends
2276       # on a GPL module.
2277       modules="$requested_module"
2278       func_modules_transitive_closure
2279       for module in $modules; do
2280         license=`func_get_license "$module"`
2281         case $license in
2282           LGPL | 'GPLed build tool') ;;
2283           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2284           *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2285         esac
2286       done
2287     fi
2288   done
2289   modules="$saved_modules"
2290
2291   # Subdirectory names.
2292   sourcebase=gllib
2293   m4base=glm4
2294   docbase=gldoc
2295   testsbase=gltests
2296   macro_prefix=gl
2297
2298   # Determine final module list.
2299   func_modules_transitive_closure
2300   echo "Module list with included dependencies:"
2301   echo "$modules" | sed -e 's/^/  /'
2302
2303   # Add the dummy module if needed.
2304   func_modules_add_dummy
2305
2306   # Determine final file list.
2307   func_modules_to_filelist
2308   echo "File list:"
2309   echo "$files" | sed -e 's/^/  /'
2310
2311   sed_rewrite_files="\
2312     s,^build-aux/,$auxdir/,
2313     s,^doc/,$docbase/,
2314     s,^lib/,$sourcebase/,
2315     s,^m4/,$m4base/,
2316     s,^tests/,$testsbase/,"
2317
2318   # Create directories.
2319   for f in $files; do echo $f; done \
2320     | sed -e "$sed_rewrite_files" \
2321     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2322     | LC_ALL=C sort -u \
2323     > "$tmp"/dirs
2324   { # Rearrange file descriptors. Needed because "while ... done < ..."
2325     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2326     exec 5<&0 < "$tmp"/dirs
2327     while read d; do
2328       mkdir -p "$testdir/$d"
2329     done
2330     exec 0<&5 5<&-
2331   }
2332
2333   # Copy files or make symbolic links.
2334   delimiter='   '
2335   for f in $files; do echo $f; done \
2336     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2337     | LC_ALL=C sort \
2338     > "$tmp"/files
2339   { # Rearrange file descriptors. Needed because "while ... done < ..."
2340     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2341     exec 5<&0 < "$tmp"/files
2342     while read g f; do
2343       func_lookup_file "$f"
2344       if test -n "$lookedup_tmp"; then
2345         cp -p "$lookedup_file" "$testdir/$g"
2346       else
2347         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2348         if { test -n "$symbolic" \
2349              || { test -n "$lsymbolic" \
2350                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
2351           func_ln "$lookedup_file" "$testdir/$g"
2352         else
2353           cp -p "$lookedup_file" "$testdir/$g"
2354         fi
2355       fi
2356     done
2357     exec 0<&5 5<&-
2358   }
2359
2360   # Create $sourcebase/Makefile.am.
2361   mkdir -p "$testdir/$sourcebase"
2362   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2363
2364   # Create $m4base/Makefile.am.
2365   mkdir -p "$testdir/$m4base"
2366   (echo "## Process this file with automake to produce Makefile.in."
2367    echo
2368    echo "EXTRA_DIST ="
2369    for f in $files; do
2370      case "$f" in
2371        m4/* )
2372          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2373      esac
2374    done
2375   ) > "$testdir/$m4base/Makefile.am"
2376
2377   subdirs="$sourcebase $m4base"
2378   subdirs_with_configure_ac=""
2379
2380   if false && test -f "$testdir"/$m4base/gettext.m4; then
2381     # Avoid stupid error message from automake:
2382     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2383     mkdir -p "$testdir/po"
2384     (echo "## Process this file with automake to produce Makefile.in."
2385     ) > "$testdir/po/Makefile.am"
2386     func_append subdirs " po"
2387   fi
2388
2389   if test -n "$inctests"; then
2390     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2391     # Create $testsbase/Makefile.am.
2392     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2393     # Create $testsbase/configure.ac.
2394     (echo "# Process this file with autoconf to produce a configure script."
2395      echo "AC_INIT([dummy], [0])"
2396      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2397      echo "AM_INIT_AUTOMAKE"
2398      echo
2399      echo "AM_CONFIG_HEADER([config.h])"
2400      echo
2401      echo "AC_PROG_CC"
2402      echo "AC_PROG_INSTALL"
2403      echo "AC_PROG_MAKE_SET"
2404      echo "AC_PROG_RANLIB"
2405      echo
2406      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2407        echo "AC_GNU_SOURCE"
2408        echo
2409      fi
2410      if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2411        echo "gl_USE_SYSTEM_EXTENSIONS"
2412        echo
2413      fi
2414      if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2415        echo "gl_LOCK_EARLY"
2416        echo
2417      fi
2418      if test "$libtool" = true; then
2419        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2420        echo "gl_cond_libtool=true"
2421      else
2422        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2423        echo "gl_cond_libtool=false"
2424        echo "gl_libdeps="
2425        echo "gl_ltlibdeps="
2426      fi
2427      # Wrap the set of autoconf snippets into an autoconf macro that is then
2428      # invoked. This is needed because autoconf does not support AC_REQUIRE
2429      # at the top level:
2430      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2431      # but we want the AC_REQUIRE to have its normal meaning (provide one
2432      # expansion of the required macro before the current point, and only one
2433      # expansion total).
2434      echo "AC_DEFUN([gl_INIT], ["
2435      func_emit_initmacro_start
2436      sed_replace_build_aux='
2437        :a
2438        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2439          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2440          ba
2441        }'
2442      sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2443      # We don't have explicit ordering constraints between the various
2444      # autoconf snippets. It's cleanest to put those of the library before
2445      # those of the tests.
2446      echo "gl_source_base='../$sourcebase'"
2447      for module in $modules; do
2448        func_verify_nontests_module
2449        if test -n "$module"; then
2450          func_get_autoconf_snippet "$module" \
2451            | sed -e "$sed_replace_build_aux"
2452        fi
2453      done
2454      echo "gl_source_base='.'"
2455      for module in $modules; do
2456        func_verify_tests_module
2457        if test -n "$module"; then
2458          func_get_autoconf_snippet "$module" \
2459            | sed -e "$sed_replace_build_aux"
2460        fi
2461      done
2462      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2463      # created using libtool, because libtool already handles the dependencies.
2464      if test "$libtool" != true; then
2465        libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2466        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2467        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2468        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2469        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2470      fi
2471      func_emit_initmacro_end
2472      echo "])"
2473      func_emit_initmacro_done
2474      echo
2475      echo "gl_INIT"
2476      echo
2477      # Usually $testsbase/config.h will be a superset of config.h. Verify this
2478      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2479      echo "AH_TOP([#include \"../config.h\"])"
2480      echo
2481      echo "AC_OUTPUT([Makefile])"
2482     ) > "$testdir/$testsbase/configure.ac"
2483     func_append subdirs " $testsbase"
2484     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2485   fi
2486
2487   # Create Makefile.am.
2488   (echo "## Process this file with automake to produce Makefile.in."
2489    echo
2490    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2491    echo
2492    echo "SUBDIRS = $subdirs"
2493    echo
2494    echo "ACLOCAL_AMFLAGS = -I $m4base"
2495   ) > "$testdir/Makefile.am"
2496
2497   # Create configure.ac.
2498   (echo "# Process this file with autoconf to produce a configure script."
2499    echo "AC_INIT([dummy], [0])"
2500    if test "$auxdir" != "."; then
2501      echo "AC_CONFIG_AUX_DIR([$auxdir])"
2502    fi
2503    echo "AM_INIT_AUTOMAKE"
2504    echo
2505    echo "AM_CONFIG_HEADER([config.h])"
2506    echo
2507    echo "AC_PROG_CC"
2508    echo "AC_PROG_INSTALL"
2509    echo "AC_PROG_MAKE_SET"
2510    echo
2511    echo "# For autobuild."
2512    echo "AC_CANONICAL_BUILD"
2513    echo "AC_CANONICAL_HOST"
2514    echo
2515    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2516    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2517    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2518    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2519    echo
2520    echo "AC_PROG_RANLIB"
2521    echo
2522    if test -n "$uses_subdirs"; then
2523      echo "AM_PROG_CC_C_O"
2524      echo
2525    fi
2526    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2527      echo "AC_GNU_SOURCE"
2528      echo
2529    fi
2530    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2531      echo "gl_USE_SYSTEM_EXTENSIONS"
2532      echo
2533    fi
2534    if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2535      echo "gl_LOCK_EARLY"
2536      echo
2537    fi
2538    if test "$libtool" = true; then
2539      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2540      echo "gl_cond_libtool=true"
2541    else
2542      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2543      echo "gl_cond_libtool=false"
2544      echo "gl_libdeps="
2545      echo "gl_ltlibdeps="
2546    fi
2547    echo "gl_source_base='$sourcebase'"
2548    # Wrap the set of autoconf snippets into an autoconf macro that is then
2549    # invoked. This is needed because autoconf does not support AC_REQUIRE
2550    # at the top level:
2551    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2552    # but we want the AC_REQUIRE to have its normal meaning (provide one
2553    # expansion of the required macro before the current point, and only one
2554    # expansion total).
2555    echo "AC_DEFUN([gl_INIT], ["
2556    func_emit_initmacro_start
2557    if test "$auxdir" != "build-aux"; then
2558      sed_replace_build_aux='
2559        :a
2560        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2561          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2562          ba
2563        }'
2564      sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2565    else
2566      sed_replace_build_aux=
2567    fi
2568    for module in $modules; do
2569      func_verify_nontests_module
2570      if test -n "$module"; then
2571        func_get_autoconf_snippet "$module" \
2572          | sed -e "$sed_replace_build_aux"
2573      fi
2574    done
2575    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2576    # created using libtool, because libtool already handles the dependencies.
2577    if test "$libtool" != true; then
2578      libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2579      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2580      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2581      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2582      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2583    fi
2584    func_emit_initmacro_end
2585    echo "])"
2586    func_emit_initmacro_done
2587    echo
2588    echo "gl_INIT"
2589    echo
2590    if test -n "$subdirs_with_configure_ac"; then
2591      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
2592    fi
2593    makefiles="Makefile"
2594    for d in $subdirs; do
2595      # For subdirs that have a configure.ac by their own, it's the subdir's
2596      # configure.ac which creates the subdir's Makefile.am, not this one.
2597      case " $subdirs_with_configure_ac " in
2598        *" $d "*) ;;
2599        *) func_append makefiles " $d/Makefile" ;;
2600      esac
2601    done
2602    echo "AC_OUTPUT([$makefiles])"
2603   ) > "$testdir/configure.ac"
2604
2605   # Create autogenerated files.
2606   (cd "$testdir"
2607    # Do not use "${AUTORECONF} --force --install", because it may invoke
2608    # autopoint, which brings in older versions of some of our .m4 files.
2609    if test -f $m4base/gettext.m4; then
2610      echo "executing ${AUTOPOINT} --force"
2611      ${AUTOPOINT} --force || func_exit 1
2612      for f in $m4base/*.m4~; do
2613        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
2614      done
2615    fi
2616    echo "executing ${ACLOCAL} -I $m4base"
2617    ${ACLOCAL} -I $m4base || func_exit 1
2618    if ! test -d build-aux; then
2619      echo "executing mkdir build-aux"
2620      mkdir build-aux || func_exit 1
2621    fi
2622    echo "executing ${AUTOCONF}"
2623    ${AUTOCONF} || func_exit 1
2624    echo "executing ${AUTOHEADER}"
2625    ${AUTOHEADER} || func_exit 1
2626    echo "executing ${AUTOMAKE} --add-missing --copy"
2627    ${AUTOMAKE} --add-missing --copy || func_exit 1
2628   ) || func_exit 1
2629   if test -n "$inctests"; then
2630     # Create autogenerated files.
2631     (cd "$testdir/$testsbase" || func_exit 1
2632      # Do not use "${AUTORECONF} --force --install", because it may invoke
2633      # autopoint, which brings in older versions of some of our .m4 files.
2634      if test -f ../$m4base/gettext.m4; then
2635        echo "executing ${AUTOPOINT} --force"
2636        ${AUTOPOINT} --force || func_exit 1
2637        for f in ../$m4base/*.m4~; do
2638          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
2639        done
2640      fi
2641      echo "executing ${ACLOCAL} -I ../$m4base"
2642      ${ACLOCAL} -I ../$m4base || func_exit 1
2643      if ! test -d ../build-aux; then
2644        echo "executing mkdir ../build-aux"
2645        mkdir ../build-aux
2646      fi
2647      echo "executing ${AUTOCONF}"
2648      ${AUTOCONF} || func_exit 1
2649      echo "executing ${AUTOHEADER}"
2650      ${AUTOHEADER} || func_exit 1
2651      echo "executing ${AUTOMAKE} --add-missing --copy"
2652      ${AUTOMAKE} --add-missing --copy || func_exit 1
2653     ) || func_exit 1
2654   fi
2655   if grep '^BUILT_SOURCES *+=' "$testdir/$sourcebase/Makefile.am" > /dev/null; then
2656     (cd "$testdir"
2657      ./configure || func_exit 1
2658        cd "$sourcebase"
2659        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
2660        make built_sources || func_exit 1
2661        cd ..
2662      make distclean || func_exit 1
2663     ) || func_exit 1
2664   fi
2665 }
2666
2667 # func_create_megatestdir megatestdir allmodules
2668 # Input:
2669 # - local_gnulib_dir  from --local-dir
2670 # - auxdir          directory relative to destdir where to place build aux files
2671 func_create_megatestdir ()
2672 {
2673   megatestdir="$1"
2674   allmodules="$2"
2675   if test -z "$allmodules"; then
2676     allmodules=`func_all_modules`
2677   fi
2678
2679   megasubdirs=
2680   # First, all modules one by one.
2681   for onemodule in $allmodules; do
2682     func_create_testdir "$megatestdir/$onemodule" $onemodule
2683     func_append megasubdirs "$onemodule "
2684   done
2685   # Then, all modules all together.
2686   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2687   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2688   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
2689   func_create_testdir "$megatestdir/ALL" "$allmodules"
2690   func_append megasubdirs "ALL"
2691
2692   # Create Makefile.am.
2693   (echo "## Process this file with automake to produce Makefile.in."
2694    echo
2695    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2696    echo
2697    echo "SUBDIRS = $megasubdirs"
2698   ) > "$megatestdir/Makefile.am"
2699
2700   # Create configure.ac.
2701   (echo "# Process this file with autoconf to produce a configure script."
2702    echo "AC_INIT([dummy], [0])"
2703    if test "$auxdir" != "."; then
2704      echo "AC_CONFIG_AUX_DIR([$auxdir])"
2705    fi
2706    echo "AM_INIT_AUTOMAKE"
2707    echo
2708    echo "AC_PROG_MAKE_SET"
2709    echo
2710    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
2711    echo "AC_OUTPUT([Makefile])"
2712   ) > "$megatestdir/configure.ac"
2713
2714   # Create autogenerated files.
2715   (cd "$megatestdir"
2716    # Do not use "${AUTORECONF} --install", because autoreconf operates
2717    # recursively, but the subdirectories are already finished, therefore
2718    # calling autoreconf here would only waste lots of CPU time.
2719    echo "executing ${ACLOCAL}"
2720    ${ACLOCAL} || func_exit 1
2721    echo "executing mkdir build-aux"
2722    mkdir build-aux
2723    echo "executing ${AUTOCONF}"
2724    ${AUTOCONF} || func_exit 1
2725    echo "executing ${AUTOMAKE} --add-missing --copy"
2726    ${AUTOMAKE} --add-missing --copy || func_exit 1
2727   ) || func_exit 1
2728 }
2729
2730 case $mode in
2731   "" )
2732     func_fatal_error "no mode specified" ;;
2733
2734   list )
2735     func_all_modules
2736     ;;
2737
2738   import | update )
2739
2740     # Where to import.
2741     if test -z "$destdir"; then
2742       destdir=.
2743     fi
2744     test -d "$destdir" \
2745       || func_fatal_error "destination directory does not exist: $destdir"
2746
2747     # Prefer configure.ac to configure.in.
2748     if test -f "$destdir"/configure.ac; then
2749       configure_ac="$destdir/configure.ac"
2750     else
2751       if test -f "$destdir"/configure.in; then
2752         configure_ac="$destdir/configure.in"
2753       else
2754         func_fatal_error "cannot find $destdir/configure.ac"
2755       fi
2756     fi
2757
2758     # Analyze configure.ac.
2759     guessed_auxdir="."
2760     guessed_libtool=false
2761     my_sed_traces='
2762       s,#.*$,,
2763       s,^dnl .*$,,
2764       s, dnl .*$,,
2765       /AC_CONFIG_AUX_DIR/ {
2766         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
2767       }
2768       /A[CM]_PROG_LIBTOOL/ {
2769         s,^.*$,guessed_libtool=true,p
2770       }'
2771     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2772
2773     if test -z "$auxdir"; then
2774       auxdir="$guessed_auxdir"
2775     fi
2776
2777     # Determine where to apply func_import.
2778     if test -n "$m4base"; then
2779       # Apply func_import to a particular gnulib directory.
2780       # Any number of additional modules can be given.
2781       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2782         # First use of gnulib in the given m4base.
2783         test -n "$supplied_libname" || supplied_libname=true
2784         test -n "$sourcebase" || sourcebase="lib"
2785         test -n "$docbase" || docbase="doc"
2786         test -n "$testsbase" || testsbase="tests"
2787         test -n "$macro_prefix" || macro_prefix="gl"
2788       fi
2789       func_import "$*"
2790     else
2791       # Apply func_import to all gnulib directories.
2792       # To get this list of directories, look at Makefile.am. (Not at
2793       # configure, because it may be omitted from CVS. Also, don't run
2794       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2795       m4dirs=
2796       m4dirs_count=0
2797       if test -f "$destdir"/Makefile.am; then
2798         aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[         ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[       ]*=\(.*\)$/\1/'`
2799         m4dir_is_next=
2800         for arg in $aclocal_amflags; do
2801           if test -n "$m4dir_is_next"; then
2802             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2803             case "$arg" in
2804               /*) ;;
2805               *)
2806                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2807                   func_append m4dirs " $arg"
2808                   m4dirs_count=`expr $m4dirs_count + 1`
2809                 fi
2810                 ;;
2811             esac
2812           else
2813             if test "X$arg" = "X-I"; then
2814               m4dir_is_next=yes
2815             else
2816               m4dir_is_next=
2817             fi
2818           fi
2819         done
2820       else
2821         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2822         if test -f "$destdir"/aclocal.m4; then
2823           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2824           sedexpr2='s,^[^/]*$,.,'
2825           sedexpr3='s,/[^/]*$,,'
2826           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
2827           m4dirs_count=`echo "$m4dirs" | wc -l`
2828         fi
2829       fi
2830       if test $m4dirs_count = 0; then
2831         # First use of gnulib in a package.
2832         # Any number of additional modules can be given.
2833         test -n "$supplied_libname" || supplied_libname=true
2834         test -n "$sourcebase" || sourcebase="lib"
2835         m4base="m4"
2836         test -n "$docbase" || docbase="doc"
2837         test -n "$testsbase" || testsbase="tests"
2838         test -n "$macro_prefix" || macro_prefix="gl"
2839         func_import "$*"
2840       else
2841         if test $m4dirs_count = 1; then
2842           # There's only one use of gnulib here. Assume the user means it.
2843           # Any number of additional modules can be given.
2844           for m4base in $m4dirs; do
2845             func_import "$*"
2846           done
2847         else
2848           # Ambiguous - guess what the user meant.
2849           if test $# = 0; then
2850             # No further arguments. Guess the user wants to update all of them.
2851             for m4base in $m4dirs; do
2852               # Perform func_import in a subshell, so that variable values
2853               # such as
2854               #   local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
2855               #   testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
2856               # don't propagate from one directory to another.
2857               (func_import) || func_exit 1
2858             done
2859           else
2860             # Really ambiguous.
2861             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2862           fi
2863         fi
2864       fi
2865     fi
2866     ;;
2867
2868   create-testdir )
2869     if test -z "$destdir"; then
2870       func_fatal_error "please specify --dir option"
2871     fi
2872     mkdir "$destdir"
2873     test -d "$destdir" \
2874       || func_fatal_error "could not create destination directory"
2875     test -n "$auxdir" || auxdir="build-aux"
2876     func_create_testdir "$destdir" "$*"
2877     ;;
2878
2879   create-megatestdir )
2880     if test -z "$destdir"; then
2881       func_fatal_error "please specify --dir option"
2882     fi
2883     mkdir "$destdir" || func_fatal_error "could not create destination directory"
2884     test -n "$auxdir" || auxdir="build-aux"
2885     func_create_megatestdir "$destdir" "$*"
2886     ;;
2887
2888   test )
2889     test -n "$destdir" || destdir=testdir$$
2890     mkdir "$destdir" || func_fatal_error "could not create destination directory"
2891     test -n "$auxdir" || auxdir="build-aux"
2892     func_create_testdir "$destdir" "$*"
2893     cd "$destdir"
2894       mkdir build
2895       cd build
2896         ../configure || func_exit 1
2897         make || func_exit 1
2898         make check || func_exit 1
2899         make distclean || func_exit 1
2900         remaining=`find . -type f -print`
2901         if test -n "$remaining"; then
2902           echo "Remaining files:" $remaining 1>&2
2903           echo "gnulib-tool: *** Stop." 1>&2
2904           func_exit 1
2905         fi
2906       cd ..
2907     cd ..
2908     rm -rf "$destdir"
2909     ;;
2910
2911   megatest )
2912     test -n "$destdir" || destdir=testdir$$
2913     mkdir "$destdir" || func_fatal_error "could not create destination directory"
2914     test -n "$auxdir" || auxdir="build-aux"
2915     func_create_megatestdir "$destdir" "$*"
2916     cd "$destdir"
2917       mkdir build
2918       cd build
2919         ../configure
2920         make
2921         make check
2922         make distclean
2923         remaining=`find . -type f -print`
2924         if test -n "$remaining"; then
2925           echo "Remaining files:" $remaining 1>&2
2926           echo "gnulib-tool: *** Stop." 1>&2
2927           func_exit 1
2928         fi
2929       cd ..
2930     cd ..
2931     rm -rf "$destdir"
2932     ;;
2933
2934   extract-description )
2935     for module
2936     do
2937       func_verify_module
2938       if test -n "$module"; then
2939         func_get_description "$module"
2940       fi
2941     done
2942     ;;
2943
2944   extract-filelist )
2945     for module
2946     do
2947       func_verify_module
2948       if test -n "$module"; then
2949         func_get_filelist "$module"
2950       fi
2951     done
2952     ;;
2953
2954   extract-dependencies )
2955     for module
2956     do
2957       func_verify_module
2958       if test -n "$module"; then
2959         func_get_dependencies "$module"
2960       fi
2961     done
2962     ;;
2963
2964   extract-autoconf-snippet )
2965     for module
2966     do
2967       func_verify_module
2968       if test -n "$module"; then
2969         func_get_autoconf_snippet "$module"
2970       fi
2971     done
2972     ;;
2973
2974   extract-automake-snippet )
2975     for module
2976     do
2977       func_verify_module
2978       if test -n "$module"; then
2979         func_get_automake_snippet "$module"
2980       fi
2981     done
2982     ;;
2983
2984   extract-include-directive )
2985     for module
2986     do
2987       func_verify_module
2988       if test -n "$module"; then
2989         func_get_include_directive "$module"
2990       fi
2991     done
2992     ;;
2993
2994   extract-license )
2995     for module
2996     do
2997       func_verify_module
2998       if test -n "$module"; then
2999         func_get_license "$module"
3000       fi
3001     done
3002     ;;
3003
3004   extract-maintainer )
3005     for module
3006     do
3007       func_verify_module
3008       if test -n "$module"; then
3009         func_get_maintainer "$module"
3010       fi
3011     done
3012     ;;
3013
3014   extract-tests-module )
3015     for module
3016     do
3017       func_verify_module
3018       if test -n "$module"; then
3019         func_get_tests_module "$module"
3020       fi
3021     done
3022     ;;
3023
3024   * )
3025     func_fatal_error "unknown operation mode --$mode" ;;
3026 esac
3027
3028 rm -rf "$tmp"
3029 # Undo the effect of the previous 'trap' command. Some shellology:
3030 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
3031 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
3032 # exit); for the others we need to call 'exit' explicitly. The value of $? is
3033 # 128 + signal number and is set before the trap-registered command is run.
3034 trap '' 0
3035 trap 'func_exit $?' 1 2 3 13 15
3036
3037 exit 0
3038
3039 # Local Variables:
3040 # indent-tabs-mode: nil
3041 # whitespace-check-buffer-indent: nil
3042 # End: