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