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