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