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