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