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