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