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