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