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