c11ef354d8ede16283f5426a39d246e5ae795426
[pspp] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2009 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 3 of the License, or
8 # (at your option) 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, see <http://www.gnu.org/licenses/>.
17 #
18
19 # This program is meant for authors or maintainers which want to import
20 # modules from gnulib into their packages.
21
22 progname=$0
23 package=gnulib
24 nl='
25 '
26 IFS=" ""        $nl"
27
28 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
29 AUTOCONFPATH=
30 #case $USER in
31 #  bruno )
32 #    AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
33 #    AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
34 #    ;;
35 #esac
36
37 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
38 AUTOMAKEPATH=
39
40 # You can set GETTEXTPATH to empty if autopoint 0.15 is already in your PATH.
41 GETTEXTPATH=
42
43 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
44 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
45 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
46   AUTOCONF="${AUTOCONFPATH}autoconf"
47 fi
48 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
49   AUTOHEADER="${AUTOCONFPATH}autoheader"
50 fi
51 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
52   ACLOCAL="${AUTOMAKEPATH}aclocal"
53 fi
54 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
55   AUTOMAKE="${AUTOMAKEPATH}automake"
56 fi
57 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
58   AUTORECONF="${AUTOCONFPATH}autoreconf"
59 fi
60
61 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
62 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
63   AUTOPOINT="${GETTEXTPATH}autopoint"
64 fi
65
66 # When using GNU sed, turn off as many GNU extensions as possible,
67 # to minimize the risk of accidentally using non-portable features.
68 # However, do this only for gnulib-tool itself, not for the code that
69 # gnulib-tool generates, since we don't want "sed --posix" to leak
70 # into makefiles.
71 if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then
72   # Define sed as an alias.
73   # It is not always possible to use aliases. Aliases are guaranteed to work
74   # if the executing shell is bash and either it is invoked as /bin/sh or
75   # is a version >= 2.0, supporting shopt. This is the common case.
76   # Two other approaches (use of a variable $sed or of a function func_sed
77   # instead of an alias) require massive, fragile code changes.
78   # An other approach (use of function sed) requires `which sed` - but 'which'
79   # is hard to emulate, due to missing "test -x" on some platforms.
80   if test -n "$BASH_VERSION"; then
81     shopt -s expand_aliases >/dev/null 2>&1
82   fi
83   alias sed='sed --posix'
84 fi
85
86 # sed_noop is a sed expression that does nothing.
87 # An empty expression does not work with the native 'sed' on AIX 6.1.
88 sed_noop='s,x,x,'
89
90 # func_usage
91 # outputs to stdout the --help usage message.
92 func_usage ()
93 {
94   echo "\
95 Usage: gnulib-tool --list
96        gnulib-tool --import [module1 ... moduleN]
97        gnulib-tool --update
98        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
99        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
100        gnulib-tool --test --dir=directory module1 ... moduleN
101        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
102        gnulib-tool --extract-description module
103        gnulib-tool --extract-status module
104        gnulib-tool --extract-notice module
105        gnulib-tool --extract-filelist module
106        gnulib-tool --extract-dependencies module
107        gnulib-tool --extract-autoconf-snippet module
108        gnulib-tool --extract-automake-snippet module
109        gnulib-tool --extract-include-directive module
110        gnulib-tool --extract-link-directive module
111        gnulib-tool --extract-license module
112        gnulib-tool --extract-maintainer module
113        gnulib-tool --extract-tests-module module
114
115 Operation modes:
116       --list                print the available module names
117       --import              import the given modules into the current package;
118                             if no modules are specified, update the current
119                             package from the current gnulib
120       --update              update the current package, restore files omitted
121                             from CVS
122       --create-testdir      create a scratch package with the given modules
123       --create-megatestdir  create a mega scratch package with the given modules
124                             one by one and all together
125       --test                test the combination of the given modules
126                             (recommended to use CC=\"gcc -Wall\" here)
127       --megatest            test the given modules one by one and all together
128                             (recommended to use CC=\"gcc -Wall\" here)
129       --extract-description        extract the description
130       --extract-status             extract the status (obsolete or not)
131       --extract-notice             extract the notice or banner
132       --extract-filelist           extract the list of files
133       --extract-dependencies       extract the dependencies
134       --extract-autoconf-snippet   extract the snippet for configure.ac
135       --extract-automake-snippet   extract the snippet for library makefile
136       --extract-include-directive  extract the #include directive
137       --extract-link-directive     extract the linker directive
138       --extract-license            report the license terms of the source files
139                                    under lib/
140       --extract-maintainer         report the maintainer(s) inside gnulib
141       --extract-tests-module       report the unit test module, if it exists
142
143 General options:
144       --dir=DIRECTORY       Specify the target directory.
145                             For --import, this specifies where your
146                             configure.ac can be found.  Defaults to current
147                             directory.
148       --local-dir=DIRECTORY  Specify a local override directory where to look
149                             up files before looking in gnulib's directory.
150       --verbose             Increase verbosity. May be repeated.
151       --quiet               Decrease verbosity. May be repeated.
152
153 Options for --import:
154       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
155       --source-base=DIRECTORY
156                             Directory relative to --dir where source code is
157                             placed (default \"lib\").
158       --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
159                             placed (default \"m4\").
160       --po-base=DIRECTORY   Directory relative to --dir where *.po files are
161                             placed (default \"po\").
162       --doc-base=DIRECTORY  Directory relative to --dir where doc files are
163                             placed (default \"doc\").
164       --tests-base=DIRECTORY
165                             Directory relative to --dir where unit tests are
166                             placed (default \"tests\").
167       --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
168                             tools are placed (default \"build-aux\").
169       --with-tests          Include unit tests for the included modules.
170       --with-obsolete       Include obsolete modules when they occur among the
171                             dependencies. By default, dependencies to obsolete
172                             modules are ignored.
173       --avoid=MODULE        Avoid including the given MODULE. Useful if you
174                             have code that provides equivalent functionality.
175                             This option can be repeated.
176       --lgpl[=2|=3]         Abort if modules aren't available under the LGPL.
177                             Also modify license template from GPL to LGPL.
178                             The version number of the LGPL can be specified;
179                             the default is currently LGPLv3.
180       --makefile-name=NAME  Name of makefile in automake syntax in the
181                             source-base and tests-base directories
182                             (default \"Makefile.am\").
183       --libtool             Use libtool rules.
184       --no-libtool          Don't use libtool rules.
185       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
186                             'gl_INIT'. Default is 'gl'.
187       --po-domain=NAME      Specify the prefix of the i18n domain. Usually use
188                             the package name. A suffix '-gnulib' is appended.
189       --vc-files            Update version control related files.
190       --no-vc-files         Don't update version control related files
191                             (.gitignore and/or .cvsignore).
192       --no-changelog        Don't update or create ChangeLog files.
193
194 Options for --import and --update:
195       --dry-run             For --import, only print what would have been done.
196   -s, --symbolic, --symlink Make symbolic links instead of copying files.
197       --local-symlink       Make symbolic links instead of copying files, only
198                             for files from the local override directory.
199   -S, --more-symlinks       Make symbolic links instead of copying files, and
200                             don't replace copyright notices.
201
202 Report bugs to <bug-gnulib@gnu.org>."
203 }
204
205 # func_version
206 # outputs to stdout the --version message.
207 func_version ()
208 {
209   func_gnulib_dir
210   if test -d "$gnulib_dir"/.git \
211      && (git --version) >/dev/null 2>/dev/null \
212      && (date --version) >/dev/null 2>/dev/null; then
213     # gnulib checked out from git.
214     sed_extract_first_date='/^Date/{
215 s/^Date:[        ]*//p
216 q
217 }'
218     date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
219     # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
220     sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
221     date=`echo "$date" | sed -e "$sed_year_before_time"`
222     # Use GNU date to compute the time in GMT.
223     date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
224     version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
225   else
226     if test -d "$gnulib_dir"/CVS \
227        && (cvs --version) >/dev/null 2>/dev/null; then
228       # gnulib checked out from CVS.
229       sed_extract_first_date='/^date: /{
230 s/^date: \([0-9][0-9][0-9][0-9]\).\([0-9][0-9]\).\([0-9][0-9]\) \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1-\2-\3 \4/p
231 q
232 }'
233       date=`cd "$gnulib_dir" && cvs log -N ChangeLog 2>/dev/null | sed -n -e "$sed_extract_first_date"`
234     else
235       # gnulib copy without versioning information.
236       date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
237     fi
238     version=
239   fi
240   year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
241   echo "\
242 gnulib-tool (GNU $package $date)$version
243 Copyright (C) $year Free Software Foundation, Inc.
244 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
245 This is free software: you are free to change and redistribute it.
246 There is NO WARRANTY, to the extent permitted by law.
247
248 Written by" "Bruno Haible" "and" "Simon Josefsson"
249 }
250
251 # func_emit_copyright_notice
252 # outputs to stdout a header for a generated file.
253 func_emit_copyright_notice ()
254 {
255   sed -n '/Copyright/ {
256             p
257             q
258           }' < "$self_abspathname"
259   echo "#"
260   echo "# This file is free software, distributed under the terms of the GNU"
261   echo "# General Public License.  As a special exception to the GNU General"
262   echo "# Public License, this file may be distributed as part of a program"
263   echo "# that contains a configuration script generated by Autoconf, under"
264   echo "# the same distribution terms as the rest of that program."
265   echo "#"
266   echo "# Generated by gnulib-tool."
267 }
268
269 # func_exit STATUS
270 # exits with a given status.
271 # This function needs to be used, rather than 'exit', when a 'trap' handler is
272 # in effect that refers to $?.
273 func_exit ()
274 {
275   (exit $1); exit $1
276 }
277
278 # func_gnulib_dir
279 # locates the directory where the gnulib repository lives
280 # Input:
281 # - progname                 name of this program
282 # Sets variables
283 # - self_abspathname         absolute pathname of gnulib-tool
284 # - gnulib_dir               absolute pathname of gnulib repository
285 func_gnulib_dir ()
286 {
287   case "$progname" in
288     /*) self_abspathname="$progname" ;;
289     */*) self_abspathname=`pwd`/"$progname" ;;
290     *)
291       # Look in $PATH.
292       # Iterate through the elements of $PATH.
293       # We use IFS=: instead of
294       #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
295       # because the latter does not work when some PATH element contains spaces.
296       # We use a canonicalized $pathx instead of $PATH, because empty PATH
297       # elements are by definition equivalent to '.', however field splitting
298       # according to IFS=: loses empty fields in many shells:
299       #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
300       #     beginning, at the end, and in the middle),
301       #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
302       #     at the beginning and at the end,
303       #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
304       #     Solaris lose empty fields at the end.
305       # The 'case' statement is an optimization, to avoid evaluating the
306       # explicit canonicalization command when $PATH contains no empty fields.
307       self_abspathname=
308       if test "${PATH_SEPARATOR+set}" != set; then
309         func_tmpdir
310         { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
311         chmod +x "$tmp"/conf.sh
312         if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
313           PATH_SEPARATOR=';'
314         else
315           PATH_SEPARATOR=:
316         fi
317         rm -rf "$tmp"
318       fi
319       if test "$PATH_SEPARATOR" = ";"; then
320         # On Windows, programs are searched in "." before $PATH.
321         pathx=".;$PATH"
322       else
323         # On Unix, we have to convert empty PATH elements to ".".
324         pathx="$PATH"
325         case :$PATH: in
326           *::*)
327             pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
328             ;;
329         esac
330       fi
331       save_IFS="$IFS"
332       IFS="$PATH_SEPARATOR"
333       for d in $pathx; do
334         IFS="$save_IFS"
335         test -z "$d" && d=.
336         if test -x "$d/$progname" && test ! -d "$d/$progname"; then
337           self_abspathname="$d/$progname"
338           break
339         fi
340       done
341       IFS="$save_IFS"
342       if test -z "$self_abspathname"; then
343         func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
344       fi
345       ;;
346   esac
347   while test -h "$self_abspathname"; do
348     # Resolve symbolic link.
349     linkval=`func_readlink "$self_abspathname"`
350     test -n "$linkval" || break
351     case "$linkval" in
352       /* ) self_abspathname="$linkval" ;;
353       * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
354     esac
355   done
356   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
357 }
358
359 # func_tmpdir
360 # creates a temporary directory.
361 # Input:
362 # - progname                 name of this program
363 # Sets variable
364 # - tmp             pathname of freshly created temporary directory
365 func_tmpdir ()
366 {
367   # Use the environment variable TMPDIR, falling back to /tmp. This allows
368   # users to specify a different temporary directory, for example, if their
369   # /tmp is filled up or too small.
370   : ${TMPDIR=/tmp}
371   {
372     # Use the mktemp program if available. If not available, hide the error
373     # message.
374     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
375     test -n "$tmp" && test -d "$tmp"
376   } ||
377   {
378     # Use a simple mkdir command. It is guaranteed to fail if the directory
379     # already exists.  $RANDOM is bash specific and expands to empty in shells
380     # other than bash, ksh and zsh.  Its use does not increase security;
381     # rather, it minimizes the probability of failure in a very cluttered /tmp
382     # directory.
383     tmp=$TMPDIR/gl$$-$RANDOM
384     (umask 077 && mkdir "$tmp")
385   } ||
386   {
387     echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
388     func_exit 1
389   }
390 }
391
392 # func_append var value
393 # appends the given value to the shell variable var.
394 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
395   # Use bash's += operator. It reduces complexity of appending repeatedly to
396   # a single variable from O(n^2) to O(n).
397   func_append ()
398   {
399     eval "$1+=\"\$2\""
400   }
401   fast_func_append=true
402 else
403   func_append ()
404   {
405     eval "$1=\"\$$1\$2\""
406   }
407   fast_func_append=false
408 fi
409
410 # func_remove_prefix var prefix
411 # removes the given prefix from the value of the shell variable var.
412 # var should be the name of a shell variable.
413 # Its value should not contain a newline and not start or end with whitespace.
414 # prefix should not contain the characters "$`\{}[]^|.
415 if ( foo=bar; eval 'test "${foo#b}" = ar' ) >/dev/null 2>&1; then
416   func_remove_prefix ()
417   {
418     eval "$1=\${$1#\$2}"
419   }
420   fast_func_remove_prefix=true
421 else
422   func_remove_prefix ()
423   {
424     eval "value=\"\$$1\""
425     prefix="$2"
426     case "$prefix" in
427       *.*)
428         sed_escape_dots='s/\([.]\)/\\\1/g'
429         prefix=`echo "$prefix" | sed -e "$sed_escape_dots"`
430         ;;
431     esac
432     value=`echo "$value" | sed -e "s|^${prefix}||"`
433     eval "$1=\"\$value\""
434   }
435   fast_func_remove_prefix=false
436 fi
437
438 # func_remove_suffix var suffix
439 # removes the given suffix from the value of the shell variable var.
440 # var should be the name of a shell variable.
441 # Its value should not contain a newline and not start or end with whitespace.
442 # suffix should not contain the characters "$`\{}[]^|.
443 if ( foo=bar; eval 'test "${foo%r}" = ba' ) >/dev/null 2>&1; then
444   func_remove_suffix ()
445   {
446     eval "$1=\${$1%\$2}"
447   }
448   fast_func_remove_suffix=true
449 else
450   func_remove_suffix ()
451   {
452     eval "value=\"\$$1\""
453     suffix="$2"
454     case "$suffix" in
455       *.*)
456         sed_escape_dots='s/\([.]\)/\\\1/g'
457         suffix=`echo "$suffix" | sed -e "$sed_escape_dots"`
458         ;;
459     esac
460     value=`echo "$value" | sed -e "s|${suffix}\$||"`
461     eval "$1=\"\$value\""
462   }
463   fast_func_remove_suffix=false
464 fi
465
466 # func_fatal_error message
467 # outputs to stderr a fatal error message, and terminates the program.
468 # Input:
469 # - progname                 name of this program
470 func_fatal_error ()
471 {
472   echo "$progname: *** $1" 1>&2
473   echo "$progname: *** Stop." 1>&2
474   func_exit 1
475 }
476
477 # func_readlink SYMLINK
478 # outputs the target of the given symlink.
479 if (type -p readlink) > /dev/null 2>&1; then
480   func_readlink ()
481   {
482     # Use the readlink program from GNU coreutils.
483     readlink "$1"
484   }
485 else
486   func_readlink ()
487   {
488     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
489     # would do the wrong thing if the link target contains " -> ".
490     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
491   }
492 fi
493
494 # func_relativize DIR1 DIR2
495 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
496 # Input:
497 # - DIR1            relative pathname, relative to the current directory
498 # - DIR2            relative pathname, relative to the current directory
499 # Output:
500 # - reldir          relative pathname of DIR2, relative to DIR1
501 func_relativize ()
502 {
503   dir0=`pwd`
504   dir1="$1"
505   dir2="$2"
506   sed_first='s,^\([^/]*\)/.*$,\1,'
507   sed_rest='s,^[^/]*/*,,'
508   sed_last='s,^.*/\([^/]*\)$,\1,'
509   sed_butlast='s,/*[^/]*$,,'
510   while test -n "$dir1"; do
511     first=`echo "$dir1" | sed -e "$sed_first"`
512     if test "$first" != "."; then
513       if test "$first" = ".."; then
514         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
515         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
516       else
517         first2=`echo "$dir2" | sed -e "$sed_first"`
518         if test "$first2" = "$first"; then
519           dir2=`echo "$dir2" | sed -e "$sed_rest"`
520         else
521           dir2="../$dir2"
522         fi
523         dir0="$dir0"/"$first"
524       fi
525     fi
526     dir1=`echo "$dir1" | sed -e "$sed_rest"`
527   done
528   reldir="$dir2"
529 }
530
531 # func_relconcat DIR1 DIR2
532 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
533 # Input:
534 # - DIR1            relative pathname, relative to the current directory
535 # - DIR2            relative pathname, relative to DIR1
536 # Output:
537 # - relconcat       DIR1/DIR2, relative to the current directory
538 func_relconcat ()
539 {
540   dir1="$1"
541   dir2="$2"
542   sed_first='s,^\([^/]*\)/.*$,\1,'
543   sed_rest='s,^[^/]*/*,,'
544   sed_last='s,^.*/\([^/]*\)$,\1,'
545   sed_butlast='s,/*[^/]*$,,'
546   while true; do
547     first=`echo "$dir2" | sed -e "$sed_first"`
548     if test "$first" = "."; then
549       dir2=`echo "$dir2" | sed -e "$sed_rest"`
550       if test -z "$dir2"; then
551         relconcat="$dir1"
552         break
553       fi
554     else
555       last=`echo "$dir1" | sed -e "$sed_last"`
556       while test "$last" = "."; do
557         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
558         last=`echo "$dir1" | sed -e "$sed_last"`
559       done
560       if test -z "$dir1"; then
561         relconcat="$dir2"
562         break
563       fi
564       if test "$first" = ".."; then
565         if test "$last" = ".."; then
566           relconcat="$dir1/$dir2"
567           break
568         fi
569         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
570         dir2=`echo "$dir2" | sed -e "$sed_rest"`
571         if test -z "$dir1"; then
572           relconcat="$dir2"
573           break
574         fi
575         if test -z "$dir2"; then
576           relconcat="$dir1"
577           break
578         fi
579       else
580         relconcat="$dir1/$dir2"
581         break
582       fi
583     fi
584   done
585 }
586
587 # func_ln SRC DEST
588 # Like ln -s, except that SRC is given relative to the current directory (or
589 # absolute), not given relative to the directory of DEST.
590 func_ln ()
591 {
592   case "$1" in
593     /*)
594       ln -s "$1" "$2" ;;
595     *) # SRC is relative.
596       case "$2" in
597         /*)
598           ln -s "`pwd`/$1" "$2" ;;
599         *) # DEST is relative too.
600           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
601           test -n "$ln_destdir" || ln_destdir="."
602           func_relativize "$ln_destdir" "$1"
603           ln -s "$reldir" "$2"
604           ;;
605       esac
606       ;;
607   esac
608 }
609
610 # func_ln_if_changed SRC DEST
611 # Like func_ln, but avoids munging timestamps if the link is correct.
612 func_ln_if_changed ()
613 {
614   if test $# -ne 2; then
615     echo "usage: func_ln_if_changed SRC DEST" >&2
616   fi
617   ln_target=`func_readlink "$2"`
618   if test -h "$2" && test "$1" = "$ln_target"; then
619     :
620   else
621     rm -f "$2"
622     func_ln "$1" "$2"
623   fi
624 }
625
626 # func_reset_sigpipe
627 # Resets SIGPIPE to its default behaviour. SIGPIPE is signalled when a process
628 # writes into a pipe with no readers, i.e. a pipe where all readers have
629 # already closed their file descriptor that read from it or exited entirely.
630 # The default behaviour is to terminate the current process without an error
631 # message.
632 # When "trap '' SIGPIPE" is in effect, the behaviour (at least with bash) is to
633 # terminate the current process with an error message.
634 # This function should be called at the beginning of a command that only
635 # produces output to stdout (i.e. no side effects!), when the command that
636 # will read from this pipe might prematurely exit or close its standard input
637 # descriptor.
638 if test -n "$BASH_VERSION"; then
639   # The problem has only been reported with bash. Probably it occurs only with
640   # bash-3.2. For the reasons, see
641   # <http://lists.gnu.org/archive/html/bug-bash/2008-12/msg00050.html>.
642   # Note that Solaris sh does not understand "trap - SIGPIPE".
643   func_reset_sigpipe ()
644   {
645     trap - SIGPIPE
646   }
647 else
648   func_reset_sigpipe ()
649   {
650     :
651   }
652 fi
653
654 # Ensure an 'echo' command that does not interpret backslashes.
655 # Test cases:
656 #   echo '\n' | wc -l                 prints 1 when OK, 2 when KO
657 #   echo '\t' | grep t > /dev/null    has return code 0 when OK, 1 when KO
658 # This problem is a weird heritage from SVR4. BSD got it right (except that
659 # BSD echo interprets '-n' as an option, which is also not desirable).
660 # Nowadays the problem occurs in 4 situations:
661 # - in bash, when the shell option xpg_echo is set (bash >= 2.04)
662 #            or when it was built with --enable-usg-echo-default (bash >= 2.0)
663 #            or when it was built with DEFAULT_ECHO_TO_USG (bash < 2.0),
664 # - in zsh, when sh-emulation is not set,
665 # - in ksh (e.g. AIX /bin/sh and Solaris /usr/xpg4/bin/sh are ksh instances,
666 #           and HP-UX /bin/sh and IRIX /bin/sh behave similarly),
667 # - in Solaris /bin/sh and OSF/1 /bin/sh.
668 # We try the following workarounds:
669 # - for all: respawn using $CONFIG_SHELL if that is set and works.
670 # - for bash >= 2.04: unset the shell option xpg_echo.
671 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
672 # - for bash < 2.0: define echo to a function that uses cat of a here document.
673 # - for zsh: turn sh-emulation on.
674 # - for ksh: alias echo to 'print -r'.
675 # - for ksh: alias echo to a function that uses cat of a here document.
676 # - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
677 #   the ksh workaround.
678 # - otherwise: respawn using /bin/sh and rely on the workarounds.
679 # When respawning, we pass --no-reexec as first argument, so as to avoid
680 # turning this script into a fork bomb in unlucky situations.
681 have_echo=
682 if echo '\t' | grep t > /dev/null; then
683   have_echo=yes # Lucky!
684 fi
685 # Try the workarounds.
686 # Respawn using $CONFIG_SHELL if that is set and works.
687 if test -z "$have_echo" \
688    && test "X$1" != "X--no-reexec" \
689    && test -n "$CONFIG_SHELL" \
690    && test -f "$CONFIG_SHELL" \
691    && $CONFIG_SHELL -c 'echo '\t' | grep t > /dev/null'; then
692   exec $CONFIG_SHELL "$0" --no-reexec "$@"
693   exit 127
694 fi
695 # For bash >= 2.04: unset the shell option xpg_echo.
696 if test -z "$have_echo" \
697    && test -n "$BASH_VERSION" \
698    && (shopt -o xpg_echo; echo '\t' | grep t > /dev/null) 2>/dev/null; then
699   shopt -o xpg_echo
700   have_echo=yes
701 fi
702 # For bash >= 2.0: define echo to a function that uses the printf built-in.
703 # For bash < 2.0: define echo to a function that uses cat of a here document.
704 # (There is no win in using 'printf' over 'cat' if it is not a shell built-in.)
705 if test -z "$have_echo" \
706    && test -n "$BASH_VERSION"; then \
707   if type printf 2>/dev/null | grep / > /dev/null; then
708     # 'printf' is not a shell built-in.
709 echo ()
710 {
711 cat <<EOF
712 $*
713 EOF
714 }
715   else
716     # 'printf' is a shell built-in.
717 echo ()
718 {
719   printf '%s\n' "$*"
720 }
721   fi
722   if echo '\t' | grep t > /dev/null; then
723     have_echo=yes
724   fi
725 fi
726 # For zsh: turn sh-emulation on.
727 if test -z "$have_echo" \
728    && test -n "$ZSH_VERSION" \
729    && (emulate sh) >/dev/null 2>&1; then
730   emulate sh
731 fi
732 # For ksh: alias echo to 'print -r'.
733 if test -z "$have_echo" \
734    && (type print) >/dev/null 2>&1; then
735   # A 'print' command exists.
736   if type print 2>/dev/null | grep / > /dev/null; then
737     :
738   else
739     # 'print' is a shell built-in.
740     if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
741       # 'print' is the ksh shell built-in.
742       alias echo='print -r'
743     fi
744   fi
745 fi
746 if test -z "$have_echo" \
747    && echo '\t' | grep t > /dev/null; then
748   have_echo=yes
749 fi
750 # For ksh: alias echo to a function that uses cat of a here document.
751 # The ksh manual page says:
752 #   "Aliasing is performed when scripts are read, not while they are executed.
753 #    Therefore, for an alias to take effect, the alias definition command has
754 #    to be executed before the command which references the alias is read."
755 # Because of this, we have to play strange tricks with have_echo, to ensure
756 # that the top-level statement containing the test starts after the 'alias'
757 # command.
758 if test -z "$have_echo"; then
759 bsd_echo ()
760 {
761 cat <<EOF
762 $*
763 EOF
764 }
765 alias echo=bsd_echo 2>/dev/null
766 fi
767 if test -z "$have_echo" \
768    && echo '\t' | grep t > /dev/null; then
769   have_echo=yes
770 fi
771 if test -z "$have_echo"; then
772   unalias echo 2>/dev/null
773 fi
774 # For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
775 if test -z "$have_echo" \
776    && test "X$1" != "X--no-reexec" \
777    && test -f /bin/ksh; then
778   exec /bin/ksh "$0" --no-reexec "$@"
779   exit 127
780 fi
781 # Otherwise: respawn using /bin/sh.
782 if test -z "$have_echo" \
783    && test "X$1" != "X--no-reexec" \
784    && test -f /bin/sh; then
785   exec /bin/sh "$0" --no-reexec "$@"
786   exit 127
787 fi
788 if test -z "$have_echo"; then
789   func_fatal_error "Shell does not support 'echo' correctly. Please install GNU bash and set the environment variable CONFIG_SHELL to point to it."
790 fi
791 if echo '\t' | grep t > /dev/null; then
792   : # Works fine now.
793 else
794   func_fatal_error "Shell does not support 'echo' correctly. Workaround does not work. Please report this as a bug to bug-gnulib@gnu.org."
795 fi
796 if test "X$1" = "X--no-reexec"; then
797   shift
798 fi
799
800 # Command-line option processing.
801 # Removes the OPTIONS from the arguments. Sets the variables:
802 # - mode            list or import or create-testdir or create-megatestdir
803 # - destdir         from --dir
804 # - local_gnulib_dir  from --local-dir
805 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
806 # - libname, supplied_libname  from --lib
807 # - sourcebase      from --source-base
808 # - m4base          from --m4-base
809 # - pobase          from --po-base
810 # - docbase         from --doc-base
811 # - testsbase       from --tests-base
812 # - auxdir          from --aux-dir
813 # - inctests        true if --with-tests was given, blank otherwise
814 # - incobsolete     true if --with-obsolete was given, blank otherwise
815 # - avoidlist       list of modules to avoid, from --avoid
816 # - lgpl            yes or a number if --lgpl was given, blank otherwise
817 # - makefile_name   from --makefile-name
818 # - libtool         true if --libtool was given, false if --no-libtool was
819 #                   given, blank otherwise
820 # - macro_prefix    from --macro-prefix
821 # - po_domain       from --po-domain
822 # - vc_files        true if --vc-files was given, false if --no-vc-files was
823 #                   given, blank otherwise
824 # - autoconf_minversion  minimum supported autoconf version
825 # - do_changelog    false if --no-changelog was given, : otherwise
826 # - doit            : if actions shall be executed, false if only to be printed
827 # - symbolic        true if --symlink or --more-symlinks was given, blank
828 #                   otherwise
829 # - lsymbolic       true if --local-symlink was given, blank otherwise
830 # - do_copyrights   blank if --more-symlinks was given, true otherwise
831 {
832   mode=
833   destdir=
834   local_gnulib_dir=
835   verbose=0
836   libname=libgnu
837   supplied_libname=
838   sourcebase=
839   m4base=
840   pobase=
841   docbase=
842   testsbase=
843   auxdir=
844   inctests=
845   incobsolete=
846   avoidlist=
847   lgpl=
848   makefile_name=
849   libtool=
850   macro_prefix=
851   po_domain=
852   vc_files=
853   do_changelog=:
854   doit=:
855   symbolic=
856   lsymbolic=
857   do_copyrights=true
858
859   supplied_opts="$@"
860
861   while test $# -gt 0; do
862     case "$1" in
863       --list | --lis )
864         mode=list
865         shift ;;
866       --import | --impor | --impo | --imp | --im | --i )
867         mode=import
868         shift ;;
869       --update | --updat | --upda | --upd | --up | --u )
870         mode=update
871         shift ;;
872       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
873         mode=create-testdir
874         shift ;;
875       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
876         mode=create-megatestdir
877         shift ;;
878       --test | --tes | --te | --t )
879         mode=test
880         shift ;;
881       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
882         mode=megatest
883         shift ;;
884       --extract-* )
885         mode=`echo "X$1" | sed -e 's/^X--//'`
886         shift ;;
887       --dir )
888         shift
889         if test $# = 0; then
890           func_fatal_error "missing argument for --dir"
891         fi
892         destdir=$1
893         shift ;;
894       --dir=* )
895         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
896         shift ;;
897       --local-dir )
898         shift
899         if test $# = 0; then
900           func_fatal_error "missing argument for --local-dir"
901         fi
902         local_gnulib_dir=$1
903         shift ;;
904       --local-dir=* )
905         local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
906         shift ;;
907       --verbose | --verbos | --verbo | --verb )
908         verbose=`expr $verbose + 1`
909         shift ;;
910       --quiet | --quie | --qui | --qu | --q )
911         verbose=`expr $verbose - 1`
912         shift ;;
913       --lib )
914         shift
915         if test $# = 0; then
916           func_fatal_error "missing argument for --lib"
917         fi
918         libname=$1
919         supplied_libname=true
920         shift ;;
921       --lib=* )
922         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
923         supplied_libname=true
924         shift ;;
925       --source-base )
926         shift
927         if test $# = 0; then
928           func_fatal_error "missing argument for --source-base"
929         fi
930         sourcebase=$1
931         shift ;;
932       --source-base=* )
933         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
934         shift ;;
935       --m4-base )
936         shift
937         if test $# = 0; then
938           func_fatal_error "missing argument for --m4-base"
939         fi
940         m4base=$1
941         shift ;;
942       --m4-base=* )
943         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
944         shift ;;
945       --po-base )
946         shift
947         if test $# = 0; then
948           func_fatal_error "missing argument for --po-base"
949         fi
950         pobase=$1
951         shift ;;
952       --po-base=* )
953         pobase=`echo "X$1" | sed -e 's/^X--po-base=//'`
954         shift ;;
955       --doc-base )
956         shift
957         if test $# = 0; then
958           func_fatal_error "missing argument for --doc-base"
959         fi
960         docbase=$1
961         shift ;;
962       --doc-base=* )
963         docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
964         shift ;;
965       --tests-base )
966         shift
967         if test $# = 0; then
968           func_fatal_error "missing argument for --tests-base"
969         fi
970         testsbase=$1
971         shift ;;
972       --tests-base=* )
973         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
974         shift ;;
975       --aux-dir )
976         shift
977         if test $# = 0; then
978           func_fatal_error "missing argument for --aux-dir"
979         fi
980         auxdir=$1
981         shift ;;
982       --aux-dir=* )
983         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
984         shift ;;
985       --with-tests )
986         inctests=true
987         shift ;;
988       --with-obsolete )
989         incobsolete=true
990         shift ;;
991       --avoid )
992         shift
993         if test $# = 0; then
994           func_fatal_error "missing argument for --avoid"
995         fi
996         func_append avoidlist " $1"
997         shift ;;
998       --avoid=* )
999         arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
1000         func_append avoidlist " $arg"
1001         shift ;;
1002       --lgpl )
1003         lgpl=yes
1004         shift ;;
1005       --lgpl=* )
1006         arg=`echo "X$1" | sed -e 's/^X--lgpl=//'`
1007         case "$arg" in
1008           2 | 3) ;;
1009           *) func_fatal_error "invalid LGPL version number for --lgpl" ;;
1010         esac
1011         lgpl=$arg
1012         shift ;;
1013       --makefile-name )
1014         shift
1015         if test $# = 0; then
1016           func_fatal_error "missing argument for --makefile-name"
1017         fi
1018         makefile_name="$1"
1019         shift ;;
1020       --makefile-name=* )
1021         makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
1022         shift ;;
1023       --libtool )
1024         libtool=true
1025         shift ;;
1026       --no-libtool )
1027         libtool=false
1028         shift ;;
1029       --macro-prefix )
1030         shift
1031         if test $# = 0; then
1032           func_fatal_error "missing argument for --macro-prefix"
1033         fi
1034         macro_prefix="$1"
1035         shift ;;
1036       --macro-prefix=* )
1037         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
1038         shift ;;
1039       --po-domain )
1040         shift
1041         if test $# = 0; then
1042           func_fatal_error "missing argument for --po-domain"
1043         fi
1044         po_domain="$1"
1045         shift ;;
1046       --po-domain=* )
1047         po_domain=`echo "X$1" | sed -e 's/^X--po-domain=//'`
1048         shift ;;
1049       --vc-files )
1050         vc_files=true
1051         shift ;;
1052       --no-vc-files )
1053         vc_files=false
1054         shift ;;
1055       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
1056         do_changelog=false
1057         shift ;;
1058       --dry-run )
1059         doit=false
1060         shift ;;
1061       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
1062         symbolic=true
1063         shift ;;
1064       --local-symlink | --local-symlin | --local-symli | --local-syml | --local-sym | --local-sy | --local-s )
1065         lsymbolic=true
1066         shift ;;
1067       -S | --more-symlinks | --more-symlink | --more-symlin | --more-symli | --more-syml | --more-sym | --more-sy | --more-s | --more- | --more | --mor | --mo )
1068         symbolic=true
1069         do_copyrights=
1070         shift ;;
1071       --help | --hel | --he | --h )
1072         func_usage
1073         func_exit $? ;;
1074       --version | --versio | --versi | --vers )
1075         func_version
1076         func_exit $? ;;
1077       -- )
1078         # Stop option processing
1079         shift
1080         break ;;
1081       -* )
1082         echo "gnulib-tool: unknown option $1" 1>&2
1083         echo "Try 'gnulib-tool --help' for more information." 1>&2
1084         func_exit 1 ;;
1085       * )
1086         break ;;
1087     esac
1088   done
1089
1090   if test "$mode" = update; then
1091     if test $# != 0; then
1092       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
1093       echo "Try 'gnulib-tool --help' for more information." 1>&2
1094       echo "If you really want to modify the gnulib configuration of your project," 1>&2
1095       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
1096       func_exit 1
1097     fi
1098     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
1099        || test -n "$sourcebase" || test -n "$m4base" || test -n "$pobase" \
1100        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
1101        || test -n "$inctests" || test -n "$incobsolete" \
1102        || test -n "$avoidlist" || test -n "$lgpl" || test -n "$makefile_name" \
1103        || test -n "$macro_prefix" || test -n "$po_domain" \
1104        || test -n "$vc_files"; then
1105       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
1106       echo "Try 'gnulib-tool --help' for more information." 1>&2
1107       echo "If you really want to modify the gnulib configuration of your project," 1>&2
1108       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
1109       func_exit 1
1110     fi
1111     do_changelog=false
1112   fi
1113   if test -n "$pobase" && test -z "$po_domain"; then
1114     echo "gnulib-tool: together with --po-base, you need to specify --po-domain" 1>&2
1115     echo "Try 'gnulib-tool --help' for more information." 1>&2
1116     func_exit 1
1117   fi
1118   if test -z "$pobase" && test -n "$po_domain"; then
1119     echo "gnulib-tool: warning: --po-domain has no effect without a --po-base option" 1>&2
1120   fi
1121
1122   # Determine the minimum supported autoconf version from the project's
1123   # configure.ac.
1124   DEFAULT_AUTOCONF_MINVERSION="2.59"
1125   autoconf_minversion=
1126   configure_ac=
1127   if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
1128     if test -f "$destdir"/configure.ac; then
1129       configure_ac="$destdir/configure.ac"
1130     else
1131       if test -f "$destdir"/configure.in; then
1132         configure_ac="$destdir/configure.in"
1133       fi
1134     fi
1135   else
1136     if test -f configure.ac; then
1137       configure_ac="configure.ac"
1138     else
1139       if test -f configure.in; then
1140         configure_ac="configure.in"
1141       fi
1142     fi
1143   fi
1144   if test -n "$configure_ac"; then
1145     # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
1146     # because when some m4 files are omitted from a CVS repository,
1147     # "autoconf --trace=AC_PREREQ" fails with an error message like this:
1148     #   m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
1149     #   autom4te: m4 failed with exit status: 1
1150     prereqs=
1151     my_sed_traces='
1152       s,#.*$,,
1153       s,^dnl .*$,,
1154       s, dnl .*$,,
1155       /AC_PREREQ/ {
1156         s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,\1,p
1157       }'
1158     prereqs=`sed -n -e "$my_sed_traces" < "$configure_ac"`
1159     if test -n "$prereqs"; then
1160       autoconf_minversion=`
1161         for version in $prereqs; do echo $version; done |
1162         LC_ALL=C sort -nru | sed 1q
1163       `
1164     fi
1165   fi
1166   if test -z "$autoconf_minversion"; then
1167     autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
1168   fi
1169   case "$autoconf_minversion" in
1170     1.* | 2.[0-4]* | 2.5[0-8]*)
1171       func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
1172   esac
1173
1174   # Remove trailing slashes from the directory names. This is necessary for
1175   # m4base (to avoid an error in func_import) and optional for the others.
1176   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
1177   case "$local_gnulib_dir" in
1178     */ ) local_gnulib_dir=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
1179   esac
1180   case "$sourcebase" in
1181     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
1182   esac
1183   case "$m4base" in
1184     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
1185   esac
1186   case "$pobase" in
1187     */ ) pobase=`echo "$pobase" | sed -e "$sed_trimtrailingslashes"` ;;
1188   esac
1189   case "$docbase" in
1190     */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
1191   esac
1192   case "$testsbase" in
1193     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
1194   esac
1195   case "$auxdir" in
1196     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
1197   esac
1198 }
1199
1200 func_gnulib_dir
1201 func_tmpdir
1202 trap 'exit_status=$?
1203       if test "$signal" != 0; then
1204         echo "caught signal $signal" >&2
1205       fi
1206       rm -rf "$tmp"
1207       exit $exit_status' 0
1208 for signal in 1 2 3 13 15; do
1209   trap '{ signal='$signal'; func_exit 1; }' $signal
1210 done
1211 signal=0
1212
1213 # func_lookup_file file
1214 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
1215 # 'patch'.
1216 # Input:
1217 # - local_gnulib_dir  from --local-dir
1218 # Output:
1219 # - lookedup_file   name of the merged (combined) file
1220 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
1221 func_lookup_file ()
1222 {
1223   lkfile="$1"
1224   if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
1225     lookedup_file="$local_gnulib_dir/$lkfile"
1226     lookedup_tmp=
1227   else
1228     if test -f "$gnulib_dir/$lkfile"; then
1229       if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
1230         lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
1231         rm -f "$tmp/$lkbase"
1232         cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
1233         patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
1234           || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
1235         lookedup_file="$tmp/$lkbase"
1236         lookedup_tmp=true
1237       else
1238         lookedup_file="$gnulib_dir/$lkfile"
1239         lookedup_tmp=
1240       fi
1241     else
1242       func_fatal_error "file $gnulib_dir/$lkfile not found"
1243     fi
1244   fi
1245 }
1246
1247 # func_all_modules
1248 # Input:
1249 # - local_gnulib_dir  from --local-dir
1250 func_all_modules ()
1251 {
1252   # Filter out metainformation files like README, which are not modules.
1253   # Filter out unit test modules; they can be retrieved through
1254   # --extract-tests-module if desired.
1255   {
1256     (cd "$gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,')
1257     if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
1258       (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,')
1259     fi
1260   } \
1261       | sed -e '/^CVS\//d' -e '/\/CVS\//d' \
1262             -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
1263             -e '/^COPYING$/d' -e '/\/COPYING$/d' \
1264             -e '/^README$/d' -e '/\/README$/d' \
1265             -e '/^TEMPLATE$/d' \
1266             -e '/^TEMPLATE-EXTENDED$/d' \
1267             -e '/^TEMPLATE-TESTS$/d' \
1268             -e '/^\..*/d' \
1269             -e '/~$/d' \
1270       | sed -e '/-tests$/d' \
1271       | LC_ALL=C sort -u
1272 }
1273
1274 # func_verify_module
1275 # verifies a module name
1276 # Input:
1277 # - local_gnulib_dir  from --local-dir
1278 # - module          module name argument
1279 func_verify_module ()
1280 {
1281   if { test -f "$gnulib_dir/modules/$module" \
1282        || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1283             && test -f "$local_gnulib_dir/modules/$module"; }; } \
1284      && test "CVS" != "$module" \
1285      && test "ChangeLog" != "$module" \
1286      && test "COPYING" != "$module" \
1287      && test "README" != "$module" \
1288      && test "TEMPLATE" != "$module" \
1289      && test "TEMPLATE-EXTENDED" != "$module" \
1290      && test "TEMPLATE-TESTS" != "$module"; then
1291     # OK, $module is a correct module name.
1292     # Verify that building the module description with 'patch' succeeds.
1293     func_lookup_file "modules/$module"
1294   else
1295     echo "gnulib-tool: module $module doesn't exist" 1>&2
1296     module=
1297   fi
1298 }
1299
1300 # func_verify_nontests_module
1301 # verifies a module name, excluding tests modules
1302 # Input:
1303 # - local_gnulib_dir  from --local-dir
1304 # - module          module name argument
1305 func_verify_nontests_module ()
1306 {
1307   case "$module" in
1308     *-tests ) module= ;;
1309     * ) func_verify_module ;;
1310   esac
1311 }
1312
1313 # func_verify_tests_module
1314 # verifies a module name, considering only tests modules
1315 # Input:
1316 # - local_gnulib_dir  from --local-dir
1317 # - module          module name argument
1318 func_verify_tests_module ()
1319 {
1320   case "$module" in
1321     *-tests ) func_verify_module ;;
1322     * ) module= ;;
1323   esac
1324 }
1325
1326 sed_extract_prog=':[     ]*$/ {
1327   :a
1328     n
1329     s/^Description:[     ]*$//
1330     s/^Status:[  ]*$//
1331     s/^Notice:[  ]*$//
1332     s/^Files:[   ]*$//
1333     s/^Depends-on:[      ]*$//
1334     s/^configure\.ac-early:[     ]*$//
1335     s/^configure\.ac:[   ]*$//
1336     s/^Makefile\.am:[    ]*$//
1337     s/^Include:[         ]*$//
1338     s/^Link:[    ]*$//
1339     s/^License:[         ]*$//
1340     s/^Maintainer:[      ]*$//
1341     tb
1342     p
1343     ba
1344   :b
1345 }'
1346
1347 # func_get_description module
1348 # Input:
1349 # - local_gnulib_dir  from --local-dir
1350 func_get_description ()
1351 {
1352   func_lookup_file "modules/$1"
1353   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
1354 }
1355
1356 # func_get_status module
1357 # Input:
1358 # - local_gnulib_dir  from --local-dir
1359 func_get_status ()
1360 {
1361   func_lookup_file "modules/$1"
1362   sed -n -e "/^Status$sed_extract_prog" < "$lookedup_file"
1363 }
1364
1365 # func_get_notice module
1366 # Input:
1367 # - local_gnulib_dir  from --local-dir
1368 func_get_notice ()
1369 {
1370   func_lookup_file "modules/$1"
1371   sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"
1372 }
1373
1374 # func_get_filelist module
1375 # Input:
1376 # - local_gnulib_dir  from --local-dir
1377 func_get_filelist ()
1378 {
1379   func_lookup_file "modules/$1"
1380   sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
1381   echo m4/gnulib-common.m4
1382   case "$autoconf_minversion" in
1383     2.59)
1384       echo m4/onceonly.m4
1385       ;;
1386   esac
1387 }
1388
1389 # func_filter_filelist outputvar separator filelist prefix suffix removed_prefix removed_suffix [added_prefix [added_suffix]]
1390 # stores in outputvar the filtered and processed filelist. Filtering: Only the
1391 # elements starting with prefix and ending with suffix are considered.
1392 # Processing: removed_prefix and removed_suffix are removed from each element,
1393 # added_prefix and added_suffix are added to each element.
1394 # removed_prefix, removed_suffix should not contain the characters "$`\{}[]^|.
1395 # added_prefix, added_suffix should not contain the characters \|.
1396 func_filter_filelist ()
1397 {
1398   if test "$2" != "$nl" \
1399      || { $fast_func_append \
1400           && { test -z "$6" || $fast_func_remove_prefix; } \
1401           && { test -z "$7" || $fast_func_remove_suffix; }; \
1402         }; then
1403     ffflist=
1404     for fff in $3; do
1405       case "$fff" in
1406         "$4"*"$5")
1407           if test -n "$6"; then
1408             func_remove_prefix fff "$6"
1409           fi
1410           if test -n "$7"; then
1411             func_remove_suffix fff "$7"
1412           fi
1413           fff="$8${fff}$9"
1414           if test -z "$ffflist"; then
1415             ffflist="${fff}"
1416           else
1417             func_append ffflist "$2${fff}"
1418           fi
1419           ;;
1420       esac
1421     done
1422   else
1423     sed_fff_filter="s|^$6\(.*\)$7\$|$8\\1$9|"
1424     ffflist=`for fff in $3; do
1425                case "$fff" in
1426                  "$4"*"$5") echo "$fff" ;;
1427                esac
1428              done | sed -e "$sed_fff_filter"`
1429   fi
1430   eval "$1=\"\$ffflist\""
1431 }
1432
1433 # func_get_dependencies module
1434 # Input:
1435 # - local_gnulib_dir  from --local-dir
1436 func_get_dependencies ()
1437 {
1438   # ${module}-tests always implicitly depends on ${module}.
1439   case "$1" in
1440     *-tests)
1441       fgd1="$1"
1442       func_remove_suffix fgd1 '-tests'
1443       echo "$fgd1"
1444       ;;
1445   esac
1446   # Then the explicit dependencies listed in the module description.
1447   func_lookup_file "modules/$1"
1448   sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
1449 }
1450
1451 # func_get_autoconf_early_snippet module
1452 # Input:
1453 # - local_gnulib_dir  from --local-dir
1454 func_get_autoconf_early_snippet ()
1455 {
1456   func_lookup_file "modules/$1"
1457   sed -n -e "/^configure\.ac-early$sed_extract_prog" < "$lookedup_file"
1458 }
1459
1460 # func_get_autoconf_snippet module
1461 # Input:
1462 # - local_gnulib_dir  from --local-dir
1463 func_get_autoconf_snippet ()
1464 {
1465   func_lookup_file "modules/$1"
1466   sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
1467 }
1468
1469 # func_get_automake_snippet module
1470 # Input:
1471 # - local_gnulib_dir  from --local-dir
1472 func_get_automake_snippet ()
1473 {
1474   func_lookup_file "modules/$1"
1475   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
1476   case "$1" in
1477     *-tests)
1478       # *-tests module live in tests/, not lib/.
1479       # Synthesize an EXTRA_DIST augmentation.
1480       all_files=`func_get_filelist $1`
1481       func_filter_filelist tests_files " " "$all_files" 'tests/' '' 'tests/' ''
1482       extra_files="$tests_files"
1483       if test -n "$extra_files"; then
1484         echo "EXTRA_DIST +=" $extra_files
1485         echo
1486       fi
1487       ;;
1488     *)
1489       # Synthesize an EXTRA_DIST augmentation.
1490       sed_combine_lines='/\\$/{
1491         :a
1492         N
1493         s/\\\n/ /
1494         s/\\$/\\/
1495         ta
1496       }'
1497       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
1498       already_mentioned_files=` \
1499         sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
1500         | sed -e "$sed_combine_lines" \
1501         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
1502       all_files=`func_get_filelist $1`
1503       func_filter_filelist lib_files "$nl" "$all_files" 'lib/' '' 'lib/' ''
1504       # Remove $already_mentioned_files from $lib_files.
1505       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
1506       extra_files=`func_reset_sigpipe; \
1507                    for f in $already_mentioned_files; do echo $f; done \
1508                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
1509       if test -n "$extra_files"; then
1510         echo "EXTRA_DIST +=" $extra_files
1511         echo
1512       fi
1513       # Synthesize also an EXTRA_lib_SOURCES augmentation.
1514       # This is necessary so that automake can generate the right list of
1515       # dependency rules.
1516       # A possible approach would be to use autom4te --trace of the redefined
1517       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
1518       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
1519       # inside autoconf's built-in macros are not missed).
1520       # But it's simpler and more robust to do it here, based on the file list.
1521       # If some .c file exists and is not used with AC_LIBOBJ - for example,
1522       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
1523       # automake will generate a useless dependency; this is harmless.
1524       case "$1" in
1525         relocatable-prog-wrapper) ;;
1526         *)
1527           func_filter_filelist extra_files "$nl" "$extra_files" '' '.c' '' ''
1528           if test -n "$extra_files"; then
1529             echo "EXTRA_lib_SOURCES +=" $extra_files
1530             echo
1531           fi
1532           ;;
1533       esac
1534       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
1535       func_filter_filelist buildaux_files "$nl" "$all_files" 'build-aux/' '' 'build-aux/' ''
1536       if test -n "$buildaux_files"; then
1537         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
1538         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
1539         echo
1540       fi
1541       # Synthesize an EXTRA_DIST augmentation also for the files from top/.
1542       func_filter_filelist top_files "$nl" "$all_files" 'top/' '' 'top/' ''
1543       if test -n "$top_files"; then
1544         sed_prepend_topdir='s,^,$(top_srcdir)/,'
1545         echo "EXTRA_DIST += "`echo "$top_files" | sed -e "$sed_prepend_topdir"`
1546         echo
1547       fi
1548       ;;
1549   esac
1550 }
1551
1552 # func_get_include_directive module
1553 # Input:
1554 # - local_gnulib_dir  from --local-dir
1555 func_get_include_directive ()
1556 {
1557   func_lookup_file "modules/$1"
1558   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1559   sed -e 's/^\(["<]\)/#include \1/'
1560 }
1561
1562 # func_get_link_directive module
1563 # Input:
1564 # - local_gnulib_dir  from --local-dir
1565 func_get_link_directive ()
1566 {
1567   func_lookup_file "modules/$1"
1568   sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
1569 }
1570
1571 # func_get_license module
1572 # Input:
1573 # - local_gnulib_dir  from --local-dir
1574 func_get_license ()
1575 {
1576   func_lookup_file "modules/$1"
1577   { sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1578     # The default is GPL.
1579     echo "GPL"
1580   } | sed -e 's,^ *$,,' | sed -e 1q
1581 }
1582
1583 # func_get_maintainer module
1584 # Input:
1585 # - local_gnulib_dir  from --local-dir
1586 func_get_maintainer ()
1587 {
1588   func_lookup_file "modules/$1"
1589   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1590 }
1591
1592 # func_get_tests_module module
1593 # Input:
1594 # - local_gnulib_dir  from --local-dir
1595 func_get_tests_module ()
1596 {
1597   # The naming convention for tests modules is hardwired: ${module}-tests.
1598   if test -f "$gnulib_dir/modules/$1"-tests \
1599      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1600           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1601     echo "$1"-tests
1602   fi
1603 }
1604
1605 # func_acceptable module
1606 # tests whether a module is acceptable.
1607 # Input:
1608 # - avoidlist       list of modules to avoid
1609 func_acceptable ()
1610 {
1611   for avoid in $avoidlist; do
1612     if test "$avoid" = "$1"; then
1613       return 1
1614     fi
1615   done
1616   return 0
1617 }
1618
1619 # func_modules_transitive_closure
1620 # Input:
1621 # - local_gnulib_dir  from --local-dir
1622 # - modules         list of specified modules
1623 # - inctests        true if tests should be included, blank otherwise
1624 # - incobsolete     true if obsolete modules among dependencies should be
1625 #                   included, blank otherwise
1626 # - avoidlist       list of modules to avoid
1627 # - tmp             pathname of a temporary directory
1628 # Output:
1629 # - modules         list of modules, including dependencies
1630 func_modules_transitive_closure ()
1631 {
1632   # In order to process every module only once (for speed), process an "input
1633   # list" of modules, producing an "output list" of modules. During each round,
1634   # more modules can be queued in the input list. Once a module on the input
1635   # list has been processed, it is added to the "handled list", so we can avoid
1636   # to process it again.
1637   handledmodules=
1638   inmodules="$modules"
1639   outmodules=
1640   while test -n "$inmodules"; do
1641     inmodules_this_round="$inmodules"
1642     inmodules=                    # Accumulator, queue for next round
1643     for module in $inmodules_this_round; do
1644       func_verify_module
1645       if test -n "$module"; then
1646         if func_acceptable $module; then
1647           func_append outmodules " $module"
1648           deps=`func_get_dependencies $module`
1649           # Duplicate dependencies are harmless, but Jim wants a warning.
1650           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1651           if test -n "$duplicated_deps"; then
1652             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1653           fi
1654           for dep in $deps; do
1655             if test -n "$incobsolete" \
1656                || { status=`func_get_status $dep`; test "$status" != obsolete; }; then
1657               func_append inmodules " $dep"
1658             fi
1659           done
1660           if test -n "$inctests"; then
1661             testsmodule=`func_get_tests_module $module`
1662             if test -n "$testsmodule"; then
1663               func_append inmodules " $testsmodule"
1664             fi
1665           fi
1666         fi
1667       fi
1668     done
1669     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1670     # Remove $handledmodules from $inmodules.
1671     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1672     inmodules=`func_reset_sigpipe; echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1673   done
1674   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1675   rm -f "$tmp"/queued-modules
1676 }
1677
1678 # func_modules_add_dummy
1679 # Input:
1680 # - local_gnulib_dir  from --local-dir
1681 # - modules         list of modules, including dependencies
1682 # Output:
1683 # - modules         list of modules, including 'dummy' if needed
1684 func_modules_add_dummy ()
1685 {
1686   # Determine whether any module provides a lib_SOURCES augmentation.
1687   have_lib_SOURCES=
1688   sed_remove_backslash_newline=':a
1689 /\\$/{
1690 s/\\$//
1691 N
1692 s/\n//
1693 ba
1694 }'
1695   for module in $modules; do
1696     func_verify_nontests_module
1697     if test -n "$module"; then
1698       # Extract the value of "lib_SOURCES += ...".
1699       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1700         # Ignore .h files since they are not compiled.
1701         case "$file" in
1702           *.h) ;;
1703           *)
1704             have_lib_SOURCES=yes
1705             break 2
1706             ;;
1707         esac
1708       done
1709     fi
1710   done
1711   # Add the dummy module, to make sure the library will be non-empty.
1712   if test -z "$have_lib_SOURCES"; then
1713     if func_acceptable "dummy"; then
1714       func_append modules " dummy"
1715     fi
1716   fi
1717 }
1718
1719 # func_modules_notice
1720 # Input:
1721 # - local_gnulib_dir  from --local-dir
1722 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1723 # - modules         list of modules, including dependencies
1724 func_modules_notice ()
1725 {
1726   if test $verbose -ge -1; then
1727     for module in $modules; do
1728       func_verify_module
1729       if test -n "$module"; then
1730         msg=`func_get_notice $module`
1731         if test -n "$msg"; then
1732           echo "Notice from module $module:"
1733           echo "$msg" | sed -e 's/^/  /'
1734         fi
1735       fi
1736     done
1737   fi
1738 }
1739
1740 # func_modules_to_filelist
1741 # Input:
1742 # - local_gnulib_dir  from --local-dir
1743 # - modules         list of modules, including dependencies
1744 # Output:
1745 # - files           list of files
1746 func_modules_to_filelist ()
1747 {
1748   files=
1749   for module in $modules; do
1750     func_verify_module
1751     if test -n "$module"; then
1752       fs=`func_get_filelist $module`
1753       func_append files " $fs"
1754     fi
1755   done
1756   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1757 }
1758
1759 # func_execute_command command [args...]
1760 # Executes a command.
1761 # Uses also the variables
1762 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1763 func_execute_command ()
1764 {
1765   if test $verbose -ge 0; then
1766     echo "executing $*"
1767     "$@"
1768   else
1769     # Commands like automake produce output to stderr even when they succeed.
1770     # Turn this output off if the command succeeds.
1771     "$@" > "$tmp"/cmdout 2>&1
1772     cmdret=$?
1773     if test $cmdret = 0; then
1774       rm -f "$tmp"/cmdout
1775     else
1776       echo "executing $*"
1777       cat "$tmp"/cmdout 1>&2
1778       rm -f "$tmp"/cmdout
1779       (exit $cmdret)
1780     fi
1781   fi
1782 }
1783
1784 # func_emit_lib_Makefile_am
1785 # emits the contents of library makefile to standard output.
1786 # Input:
1787 # - local_gnulib_dir  from --local-dir
1788 # - modules         list of modules, including dependencies
1789 # - libname         library name
1790 # - pobase          directory relative to destdir where to place *.po files
1791 # - auxdir          directory relative to destdir where to place build aux files
1792 # - makefile_name   from --makefile-name
1793 # - libtool         true if libtool will be used, false or blank otherwise
1794 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1795 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
1796 # - actioncmd       (optional) command that will reproduce this invocation
1797 # - for_test        true if creating a package for testing, false otherwise
1798 # - destfile        filename relative to destdir of makefile being generated
1799 # Input/Output:
1800 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
1801 #                   list of edits to be done to Makefile.am variables
1802 # Output:
1803 # - uses_subdirs    nonempty if object files in subdirs exist
1804 func_emit_lib_Makefile_am ()
1805 {
1806   # When creating an includable Makefile.am snippet, augment variables with
1807   # += instead of assigning them.
1808   if test -n "$makefile_name"; then
1809     assign='+='
1810   else
1811     assign='='
1812   fi
1813   if test "$libtool" = true; then
1814     libext=la
1815     perhapsLT=LT
1816     sed_eliminate_LDFLAGS="$sed_noop"
1817   else
1818     libext=a
1819     perhapsLT=
1820     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1821   fi
1822   if $for_test; then
1823     # When creating a package for testing: Attempt to provoke failures,
1824     # especially link errors, already during "make" rather than during
1825     # "make check", because "make check" is not possible in a cross-compiling
1826     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1827     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1828   else
1829     sed_transform_check_PROGRAMS="$sed_noop"
1830   fi
1831   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1832   echo "## Process this file with automake to produce Makefile.in."
1833   func_emit_copyright_notice
1834   if test -n "$actioncmd"; then
1835     echo "# Reproduce by: $actioncmd"
1836   fi
1837   echo
1838   uses_subdirs=
1839   {
1840     for module in $modules; do
1841       func_verify_nontests_module
1842       if test -n "$module"; then
1843         {
1844           func_get_automake_snippet "$module" |
1845             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1846                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1847                 -e "$sed_eliminate_LDFLAGS" \
1848                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1849                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1850                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1851                 -e "$sed_transform_check_PROGRAMS"
1852           if test "$module" = 'alloca'; then
1853             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1854             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1855           fi
1856         } > amsnippet.tmp
1857         # Skip the contents if it's entirely empty.
1858         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1859           echo "## begin gnulib module $module"
1860           echo
1861           cat amsnippet.tmp
1862           echo "## end   gnulib module $module"
1863           echo
1864         fi
1865         rm -f amsnippet.tmp
1866         # Test whether there are some source files in subdirectories.
1867         for f in `func_get_filelist "$module"`; do
1868           case $f in
1869             lib/*/*.c)
1870               uses_subdirs=yes
1871               break
1872               ;;
1873           esac
1874         done
1875       fi
1876     done
1877   } > allsnippets.tmp
1878   if test -z "$makefile_name"; then
1879     # If there are source files in subdirectories, prevent collision of the
1880     # object files (example: hash.c and libxml/hash.c).
1881     subdir_options=
1882     if test -n "$uses_subdirs"; then
1883       subdir_options=' subdir-objects'
1884     fi
1885     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1886   fi
1887   echo
1888   if test -z "$makefile_name"; then
1889     echo "SUBDIRS ="
1890     echo "noinst_HEADERS ="
1891     echo "noinst_LIBRARIES ="
1892     echo "noinst_LTLIBRARIES ="
1893     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1894     # if you specify pkgdata_DATA to empty. This is a workaround.
1895     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1896       echo "pkgdata_DATA ="
1897     fi
1898     echo "EXTRA_DIST ="
1899     echo "BUILT_SOURCES ="
1900     echo "SUFFIXES ="
1901   fi
1902   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1903   if test -z "$makefile_name"; then
1904     echo "MOSTLYCLEANDIRS ="
1905     echo "CLEANFILES ="
1906     echo "DISTCLEANFILES ="
1907     echo "MAINTAINERCLEANFILES ="
1908   fi
1909   # Execute edits that apply to the Makefile.am being generated.
1910   edit=0
1911   while test $edit != $makefile_am_edits; do
1912     edit=`expr $edit + 1`
1913     eval dir=\"\$makefile_am_edit${edit}_dir\"
1914     eval var=\"\$makefile_am_edit${edit}_var\"
1915     eval val=\"\$makefile_am_edit${edit}_val\"
1916     if test -n "$var"; then
1917       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
1918         echo "${var} += ${val}"
1919         eval "makefile_am_edit${edit}_var="
1920       fi
1921     fi
1922   done
1923   if test -z "$makefile_name"; then
1924     echo
1925     echo "AM_CPPFLAGS ="
1926   fi
1927   echo
1928   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1929     # One of the snippets already specifies an installation location for the
1930     # library. Don't confuse automake by saying it should not be installed.
1931     :
1932   else
1933     # By default, the generated library should not be installed.
1934     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1935   fi
1936   echo
1937   echo "${libname}_${libext}_SOURCES ="
1938   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1939   # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
1940   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1941   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1942   echo "EXTRA_${libname}_${libext}_SOURCES ="
1943   if test "$libtool" = true; then
1944     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1945   fi
1946   echo
1947   if test -n "$pobase"; then
1948     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
1949     echo
1950   fi
1951   cat allsnippets.tmp \
1952     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1953   echo
1954   echo "mostlyclean-local: mostlyclean-generic"
1955   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1956   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1957   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1958   echo "          fi; \\"
1959   echo "        done; \\"
1960   echo "        :"
1961   rm -f allsnippets.tmp
1962 }
1963
1964 # func_emit_po_Makevars
1965 # emits the contents of po/ makefile parameterization to standard output.
1966 # Input:
1967 # - local_gnulib_dir  from --local-dir
1968 # - sourcebase      directory relative to destdir where to place source code
1969 # - pobase          directory relative to destdir where to place *.po files
1970 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
1971 func_emit_po_Makevars ()
1972 {
1973   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1974   func_emit_copyright_notice
1975   echo
1976   echo "# Usually the message domain is the same as the package name."
1977   echo "# But here it has a '-gnulib' suffix."
1978   echo "DOMAIN = ${po_domain}-gnulib"
1979   echo
1980   echo "# These two variables depend on the location of this directory."
1981   echo "subdir = ${pobase}"
1982   echo "top_builddir = "`echo "$pobase" | sed -e 's,//*,/,g' -e 's,[^/][^/]*,..,g'`
1983   echo
1984   cat <<\EOF
1985 # These options get passed to xgettext.
1986 XGETTEXT_OPTIONS = \
1987   --keyword=_ --flag=_:1:pass-c-format \
1988   --keyword=N_ --flag=N_:1:pass-c-format \
1989   --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \
1990   --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \
1991   --flag=error:3:c-format --flag=error_at_line:5:c-format
1992
1993 # This is the copyright holder that gets inserted into the header of the
1994 # $(DOMAIN).pot file.  gnulib is copyrighted by the FSF.
1995 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
1996
1997 # This is the email address or URL to which the translators shall report
1998 # bugs in the untranslated strings:
1999 # - Strings which are not entire sentences, see the maintainer guidelines
2000 #   in the GNU gettext documentation, section 'Preparing Strings'.
2001 # - Strings which use unclear terms or require additional context to be
2002 #   understood.
2003 # - Strings which make invalid assumptions about notation of date, time or
2004 #   money.
2005 # - Pluralisation problems.
2006 # - Incorrect English spelling.
2007 # - Incorrect formatting.
2008 # It can be your email address, or a mailing list address where translators
2009 # can write to without being subscribed, or the URL of a web page through
2010 # which the translators can contact you.
2011 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
2012
2013 # This is the list of locale categories, beyond LC_MESSAGES, for which the
2014 # message catalogs shall be used.  It is usually empty.
2015 EXTRA_LOCALE_CATEGORIES =
2016
2017 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
2018 # context.  Possible values are "yes" and "no".  Set this to yes if the
2019 # package uses functions taking also a message context, like pgettext(), or
2020 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
2021 USE_MSGCTXT = no
2022 EOF
2023 }
2024
2025 # func_emit_po_POTFILES_in
2026 # emits the file list to be passed to xgettext to standard output.
2027 # Input:
2028 # - local_gnulib_dir  from --local-dir
2029 # - sourcebase      directory relative to destdir where to place source code
2030 # - files           list of new files
2031 func_emit_po_POTFILES_in ()
2032 {
2033   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
2034   func_emit_copyright_notice
2035   echo
2036   echo "# List of files which contain translatable strings."
2037   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
2038 }
2039
2040 # func_emit_tests_Makefile_am
2041 # emits the contents of tests makefile to standard output.
2042 # Input:
2043 # - local_gnulib_dir  from --local-dir
2044 # - modules         list of modules, including dependencies
2045 # - libname         library name
2046 # - auxdir          directory relative to destdir where to place build aux files
2047 # - makefile_name   from --makefile-name
2048 # - libtool         true if libtool will be used, false or blank otherwise
2049 # - sourcebase      relative directory containing lib source code
2050 # - m4base          relative directory containing autoconf macros
2051 # - testsbase       relative directory containing unit test code
2052 # - macro_prefix    prefix of gl_LIBOBJS macros to use
2053 # - for_test        true if creating a package for testing, false otherwise
2054 # - use_libtests    true if a libtests.a should be built, false otherwise
2055 # - destfile        filename relative to destdir of makefile being generated
2056 # Input/Output:
2057 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
2058 #                   list of edits to be done to Makefile.am variables
2059 # Output:
2060 # - uses_subdirs    nonempty if object files in subdirs exist
2061 func_emit_tests_Makefile_am ()
2062 {
2063   if test "$libtool" = true; then
2064     libext=la
2065     sed_eliminate_LDFLAGS="$sed_noop"
2066   else
2067     libext=a
2068     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
2069   fi
2070   if $for_test; then
2071     # When creating a package for testing: Attempt to provoke failures,
2072     # especially link errors, already during "make" rather than during
2073     # "make check", because "make check" is not possible in a cross-compiling
2074     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
2075     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
2076   else
2077     sed_transform_check_PROGRAMS="$sed_noop"
2078   fi
2079   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
2080   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
2081   echo "## Process this file with automake to produce Makefile.in."
2082   func_emit_copyright_notice
2083   echo
2084   uses_subdirs=
2085   (
2086     for module in $modules; do
2087       if $for_test; then
2088         func_verify_tests_module
2089       else
2090         func_verify_module
2091       fi
2092       if test -n "$module"; then
2093         {
2094           func_get_automake_snippet "$module" |
2095             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
2096                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
2097                 -e "$sed_eliminate_LDFLAGS" \
2098                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
2099                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
2100                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
2101                 -e "$sed_transform_check_PROGRAMS"
2102           if $use_libtests && test "$module" = 'alloca'; then
2103             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
2104             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
2105           fi
2106         } > amsnippet.tmp
2107         # Skip the contents if it's entirely empty.
2108         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
2109           echo "## begin gnulib module $module"
2110           echo
2111           cat amsnippet.tmp
2112           echo "## end   gnulib module $module"
2113           echo
2114         fi
2115         rm -f amsnippet.tmp
2116         # Test whether there are some source files in subdirectories.
2117         for f in `func_get_filelist "$module"`; do
2118           case $f in
2119             lib/*/*.c | tests/*/*.c)
2120               uses_subdirs=yes
2121               break
2122               ;;
2123           esac
2124         done
2125       fi
2126     done
2127   ) > allsnippets.tmp
2128   # Generate dependencies here, since it eases the debugging of test failures.
2129   # If there are source files in subdirectories, prevent collision of the
2130   # object files (example: hash.c and libxml/hash.c).
2131   subdir_options=
2132   if test -n "$uses_subdirs"; then
2133     subdir_options=' subdir-objects'
2134   fi
2135   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
2136   echo
2137   if $for_test; then
2138     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
2139     echo
2140   fi
2141   # Nothing is being added to SUBDIRS; nevertheless the existence of this
2142   # variable is needed to avoid an error from automake:
2143   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
2144   echo "SUBDIRS ="
2145   echo "TESTS ="
2146   echo "TESTS_ENVIRONMENT ="
2147   echo "noinst_PROGRAMS ="
2148   if ! $for_test; then
2149     echo "check_PROGRAMS ="
2150   fi
2151   echo "noinst_HEADERS ="
2152   echo "noinst_LIBRARIES ="
2153   if $use_libtests; then
2154     if $for_test; then
2155       echo "noinst_LIBRARIES += libtests.a"
2156     else
2157       echo "check_LIBRARIES = libtests.a"
2158     fi
2159   fi
2160   # Automake versions < 1.9b create an empty pkgdatadir at installation time
2161   # if you specify pkgdata_DATA to empty. This is a workaround.
2162   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
2163     echo "pkgdata_DATA ="
2164   fi
2165   echo "EXTRA_DIST ="
2166   echo "BUILT_SOURCES ="
2167   echo "SUFFIXES ="
2168   echo "MOSTLYCLEANFILES = core *.stackdump"
2169   echo "MOSTLYCLEANDIRS ="
2170   echo "CLEANFILES ="
2171   echo "DISTCLEANFILES ="
2172   echo "MAINTAINERCLEANFILES ="
2173   # Execute edits that apply to the Makefile.am being generated.
2174   edit=0
2175   while test $edit != $makefile_am_edits; do
2176     edit=`expr $edit + 1`
2177     eval dir=\"\$makefile_am_edit${edit}_dir\"
2178     eval var=\"\$makefile_am_edit${edit}_var\"
2179     eval val=\"\$makefile_am_edit${edit}_val\"
2180     if test -n "$var"; then
2181       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
2182         echo "${var} += ${val}"
2183         eval "makefile_am_edit${edit}_var="
2184       fi
2185     fi
2186   done
2187   echo
2188   echo "AM_CPPFLAGS = \\"
2189   echo "  -I. -I\$(srcdir) \\"
2190   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
2191   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
2192   echo
2193   local_ldadd_before=''
2194   local_ldadd_after=''
2195   if $use_libtests; then
2196     # All test programs need to be linked with libtests.a.
2197     # It needs to be passed to the linker before ${libname}.${libext}, since
2198     # the tests-related modules depend on the main modules.
2199     # It also needs to be passed to the linker after ${libname}.${libext}
2200     # because the latter might contain incomplete modules (such as the 'error'
2201     # module whose dependency to 'progname' is voluntarily omitted).
2202     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
2203     # not matter.
2204     local_ldadd_before=' libtests.a'
2205     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
2206   fi
2207   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
2208   echo
2209   if $use_libtests; then
2210     echo "libtests_a_SOURCES ="
2211     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
2212     # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
2213     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
2214     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
2215     echo "EXTRA_libtests_a_SOURCES ="
2216     # The circular dependency in LDADD requires this.
2217     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
2218     echo
2219   fi
2220   cat allsnippets.tmp \
2221     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
2222   echo "# Clean up after Solaris cc."
2223   echo "clean-local:"
2224   echo "        rm -rf SunWS_cache"
2225   echo
2226   echo "mostlyclean-local: mostlyclean-generic"
2227   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
2228   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
2229   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
2230   echo "          fi; \\"
2231   echo "        done; \\"
2232   echo "        :"
2233   rm -f allsnippets.tmp
2234 }
2235
2236 # func_emit_initmacro_start macro_prefix
2237 # emits the first few statements of the gl_INIT macro to standard output.
2238 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2239 func_emit_initmacro_start ()
2240 {
2241   macro_prefix_arg="$1"
2242   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
2243   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
2244   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
2245   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
2246   # flexibility.)
2247   # Furthermore it avoids an automake error like this when a Makefile.am
2248   # that uses pieces of gnulib also uses $(LIBOBJ):
2249   #   automatically discovered file `error.c' should not be explicitly mentioned
2250   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
2251   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
2252   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
2253   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
2254   #   automatically discovered file `error.c' should not be explicitly mentioned
2255   # We let automake know about the files to be distributed through the
2256   # EXTRA_lib_SOURCES variable.
2257   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
2258   # Create data variables for checking the presence of files that are mentioned
2259   # as AC_LIBSOURCES arguments. These are m4 variables, not shell variables,
2260   # because we want the check to happen when the configure file is created,
2261   # not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the list of
2262   # files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the subdirectory
2263   # in which to expect them.
2264   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_LIST], [])"
2265   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_DIR], [])"
2266   echo "  gl_COMMON"
2267 }
2268
2269 # func_emit_initmacro_end macro_prefix
2270 # emits the last few statements of the gl_INIT macro to standard output.
2271 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2272 func_emit_initmacro_end ()
2273 {
2274   macro_prefix_arg="$1"
2275   # Check the presence of files that are mentioned as AC_LIBSOURCES arguments.
2276   # The check is performed only when autoconf is run from the directory where
2277   # the configure.ac resides; if it is run from a different directory, the
2278   # check is skipped.
2279   echo "  m4_ifval(${macro_prefix_arg}_LIBSOURCES_LIST, ["
2280   echo "    m4_syscmd([test ! -d ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
2281   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
2282   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
2283   echo "          echo \"missing file ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file\" >&2"
2284   echo "          exit 1"
2285   echo "        fi"
2286   echo "      done])dnl"
2287   echo "      m4_if(m4_sysval, [0], [],"
2288   echo "        [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])"
2289   echo "  ])"
2290   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_DIR])"
2291   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_LIST])"
2292   echo "  m4_popdef([AC_LIBSOURCES])"
2293   echo "  m4_popdef([AC_REPLACE_FUNCS])"
2294   echo "  m4_popdef([AC_LIBOBJ])"
2295   echo "  AC_CONFIG_COMMANDS_PRE(["
2296   echo "    ${macro_prefix_arg}_libobjs="
2297   echo "    ${macro_prefix_arg}_ltlibobjs="
2298   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
2299   echo "      # Remove the extension."
2300   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
2301   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
2302   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
2303   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
2304   echo "      done"
2305   echo "    fi"
2306   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
2307   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
2308   echo "  ])"
2309 }
2310
2311 # func_emit_initmacro_done macro_prefix sourcebase
2312 # emits a few statements after the gl_INIT macro to standard output.
2313 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2314 # - sourcebase      directory relative to destdir where to place source code
2315 func_emit_initmacro_done ()
2316 {
2317   macro_prefix_arg="$1"
2318   sourcebase_arg="$2"
2319   echo
2320   echo "# Like AC_LIBOBJ, except that the module name goes"
2321   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2322   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
2323   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
2324   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
2325   echo "])"
2326   echo
2327   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
2328   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2329   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
2330   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
2331   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
2332   echo "])"
2333   echo
2334   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
2335   echo "# expected is derived from the gnulib-tool parameterization,"
2336   echo "# and alloca is special cased (for the alloca-opt module)."
2337   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
2338   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
2339   echo "  m4_foreach([_gl_NAME], [\$1], ["
2340   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
2341   echo "      m4_define([${macro_prefix_arg}_LIBSOURCES_DIR], [$sourcebase_arg])"
2342   echo "      m4_append([${macro_prefix_arg}_LIBSOURCES_LIST], _gl_NAME, [ ])"
2343   echo "    ])"
2344   echo "  ])"
2345   echo "])"
2346 }
2347
2348 # func_import modules
2349 # Uses also the variables
2350 # - destdir         target directory
2351 # - local_gnulib_dir  from --local-dir
2352 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2353 # - libname         library name
2354 # - sourcebase      directory relative to destdir where to place source code
2355 # - m4base          directory relative to destdir where to place *.m4 macros
2356 # - pobase          directory relative to destdir where to place *.po files
2357 # - docbase         directory relative to destdir where to place doc files
2358 # - testsbase       directory relative to destdir where to place unit test code
2359 # - auxdir          directory relative to destdir where to place build aux files
2360 # - inctests        true if --with-tests was given, blank otherwise
2361 # - incobsolete     true if --with-obsolete was given, blank otherwise
2362 # - avoidlist       list of modules to avoid, from --avoid
2363 # - lgpl            yes or a number if library's license shall be LGPL,
2364 #                   blank otherwise
2365 # - makefile_name   from --makefile-name
2366 # - libtool         true if --libtool was given, false if --no-libtool was
2367 #                   given, blank otherwise
2368 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
2369 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2370 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
2371 # - vc_files        true if --vc-files was given, false if --no-vc-files was
2372 #                   given, blank otherwise
2373 # - autoconf_minversion  minimum supported autoconf version
2374 # - doit            : if actions shall be executed, false if only to be printed
2375 # - symbolic        true if files should be symlinked, copied otherwise
2376 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
2377 #                   copied otherwise
2378 # - do_copyrights   true if copyright notices in files should be replaced,
2379 #                   blank otherwise
2380 func_import ()
2381 {
2382   # Get the cached settings.
2383   cached_local_gnulib_dir=
2384   cached_specified_modules=
2385   cached_incobsolete=
2386   cached_avoidlist=
2387   cached_sourcebase=
2388   cached_m4base=
2389   cached_pobase=
2390   cached_docbase=
2391   cached_testsbase=
2392   cached_inctests=
2393   cached_libname=
2394   cached_lgpl=
2395   cached_makefile_name=
2396   cached_libtool=
2397   cached_macro_prefix=
2398   cached_po_domain=
2399   cached_vc_files=
2400   cached_files=
2401   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2402     cached_libtool=false
2403     my_sed_traces='
2404       s,#.*$,,
2405       s,^dnl .*$,,
2406       s, dnl .*$,,
2407       /gl_LOCAL_DIR(/ {
2408         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_dir="\1",p
2409       }
2410       /gl_MODULES(/ {
2411         ta
2412         :a
2413           s/)/)/
2414           tb
2415           N
2416           ba
2417         :b
2418         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
2419       }
2420       /gl_WITH_OBSOLETE/ {
2421         s,^.*$,cached_incobsolete=true,p
2422       }
2423       /gl_AVOID(/ {
2424         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
2425       }
2426       /gl_SOURCE_BASE(/ {
2427         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
2428       }
2429       /gl_M4_BASE(/ {
2430         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
2431       }
2432       /gl_PO_BASE(/ {
2433         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
2434       }
2435       /gl_DOC_BASE(/ {
2436         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
2437       }
2438       /gl_TESTS_BASE(/ {
2439         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
2440       }
2441       /gl_WITH_TESTS/ {
2442         s,^.*$,cached_inctests=true,p
2443       }
2444       /gl_LIB(/ {
2445         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
2446       }
2447       /gl_LGPL(/ {
2448         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
2449       }
2450       /gl_LGPL/ {
2451         s,^.*$,cached_lgpl=yes,p
2452       }
2453       /gl_MAKEFILE_NAME(/ {
2454         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
2455       }
2456       /gl_LIBTOOL/ {
2457         s,^.*$,cached_libtool=true,p
2458       }
2459       /gl_MACRO_PREFIX(/ {
2460         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
2461       }
2462       /gl_PO_DOMAIN(/ {
2463         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
2464       }
2465       /gl_VC_FILES(/ {
2466         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
2467       }'
2468     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
2469     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2470       my_sed_traces='
2471         s,#.*$,,
2472         s,^dnl .*$,,
2473         s, dnl .*$,,
2474         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
2475           s,^.*$,cached_files=",p
2476           n
2477           ta
2478           :a
2479           s,^\]).*$,",
2480           tb
2481           s,["$`\\],,g
2482           p
2483           n
2484           ba
2485           :b
2486           p
2487         }'
2488       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
2489     fi
2490   fi
2491
2492   # Merge the cached settings with the specified ones.
2493   # The m4base must be the same as expected from the pathname.
2494   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
2495     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
2496   fi
2497   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
2498   # is relative to $destdir, whereas the one we use is relative to . or absolute.
2499   if test -z "$local_gnulib_dir"; then
2500     if test -n "$cached_local_gnulib_dir"; then
2501       case "$destdir" in
2502         /*)
2503           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2504         *)
2505           case "$cached_local_gnulib_dir" in
2506             /*)
2507               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2508             *)
2509               func_relconcat "$destdir" "$cached_local_gnulib_dir"
2510               local_gnulib_dir="$relconcat" ;;
2511           esac ;;
2512       esac
2513     fi
2514   fi
2515   # Append the cached and the specified module names. So that
2516   # "gnulib-tool --import foo" means to add the module foo.
2517   specified_modules="$cached_specified_modules $1"
2518   # Included obsolete modules among the dependencies if specified either way.
2519   if test -z "$incobsolete"; then
2520     incobsolete="$cached_incobsolete"
2521   fi
2522   # Append the cached and the specified avoidlist. This is probably better
2523   # than dropping the cached one when --avoid is specified at least once.
2524   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
2525   avoidlist=`echo $avoidlist`
2526
2527   # The sourcebase defaults to the cached one.
2528   if test -z "$sourcebase"; then
2529     sourcebase="$cached_sourcebase"
2530     if test -z "$sourcebase"; then
2531       func_fatal_error "missing --source-base option"
2532     fi
2533   fi
2534   # The pobase defaults to the cached one.
2535   if test -z "$pobase"; then
2536     pobase="$cached_pobase"
2537   fi
2538   # The docbase defaults to the cached one.
2539   if test -z "$docbase"; then
2540     docbase="$cached_docbase"
2541     if test -z "$docbase"; then
2542       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."
2543     fi
2544   fi
2545   # The testsbase defaults to the cached one.
2546   if test -z "$testsbase"; then
2547     testsbase="$cached_testsbase"
2548     if test -z "$testsbase"; then
2549       func_fatal_error "missing --tests-base option"
2550     fi
2551   fi
2552   # Require the tests if specified either way.
2553   if test -z "$inctests"; then
2554     inctests="$cached_inctests"
2555   fi
2556   # The libname defaults to the cached one.
2557   if test -z "$supplied_libname"; then
2558     libname="$cached_libname"
2559     if test -z "$libname"; then
2560       func_fatal_error "missing --lib option"
2561     fi
2562   fi
2563   # Require LGPL if specified either way.
2564   if test -z "$lgpl"; then
2565     lgpl="$cached_lgpl"
2566   fi
2567   # The makefile_name defaults to the cached one.
2568   if test -z "$makefile_name"; then
2569     makefile_name="$cached_makefile_name"
2570   fi
2571   # Use libtool if specified either way, or if guessed.
2572   if test -z "$libtool"; then
2573     if test -n "$cached_m4base"; then
2574       libtool="$cached_libtool"
2575     else
2576       libtool="$guessed_libtool"
2577     fi
2578   fi
2579   # The macro_prefix defaults to the cached one.
2580   if test -z "$macro_prefix"; then
2581     macro_prefix="$cached_macro_prefix"
2582     if test -z "$macro_prefix"; then
2583       func_fatal_error "missing --macro-prefix option"
2584     fi
2585   fi
2586   # The po_domain defaults to the cached one.
2587   if test -z "$po_domain"; then
2588     po_domain="$cached_po_domain"
2589   fi
2590   # The vc_files defaults to the cached one.
2591   if test -z "$vc_files"; then
2592     vc_files="$cached_vc_files"
2593   fi
2594
2595   # Canonicalize the list of specified modules.
2596   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
2597
2598   # Determine final module list.
2599   modules="$specified_modules"
2600   func_modules_transitive_closure
2601   if test $verbose -ge 0; then
2602     echo "Module list with included dependencies:"
2603     echo "$modules" | sed -e 's/^/  /'
2604   fi
2605   final_modules="$modules"
2606
2607   # Determine main module list and tests-related module list separately.
2608   # The main module list is the transitive closure of the specified modules,
2609   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2610   # is specified, it will consist only of LGPLed source.
2611   # The tests-related module list is the transitive closure of the specified
2612   # modules, including tests modules, minus the main module list. Its lib/*
2613   # sources (brought in through dependencies of *-tests modules) go into
2614   # $testsbase/. It may contain GPLed source, even if --lgpl is specified.
2615   # Determine main module list.
2616   saved_inctests="$inctests"
2617   inctests=""
2618   modules="$specified_modules"
2619   func_modules_transitive_closure
2620   main_modules="$modules"
2621   inctests="$saved_inctests"
2622   if test $verbose -ge 1; then
2623     echo "Main module list:"
2624     echo "$main_modules" | sed -e 's/^/  /'
2625   fi
2626   # Determine tests-related module list.
2627   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
2628   testsrelated_modules=`func_reset_sigpipe; echo "$main_modules" | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
2629   if test $verbose -ge 1; then
2630     echo "Tests-related module list:"
2631     echo "$testsrelated_modules" | sed -e 's/^/  /'
2632   fi
2633
2634   # Add the dummy module to the main module list if needed.
2635   modules="$main_modules"
2636   func_modules_add_dummy
2637   main_modules="$modules"
2638
2639   # Determine whether a $testsbase/libtests.a is needed.
2640   use_libtests=false
2641   for module in $testsrelated_modules; do
2642     func_verify_nontests_module
2643     if test -n "$module"; then
2644       all_files=`func_get_filelist $module`
2645       # Test whether some file in $all_files lies in lib/.
2646       for f in $all_files; do
2647         case $f in
2648           lib/*)
2649             use_libtests=true
2650             break 2
2651             ;;
2652         esac
2653       done
2654     fi
2655   done
2656
2657   # Add the dummy module to the tests-related module list if needed.
2658   if $use_libtests; then
2659     modules="$testsrelated_modules"
2660     func_modules_add_dummy
2661     testsrelated_modules="$modules"
2662   fi
2663
2664   # If --lgpl, verify that the licenses of modules are compatible.
2665   if test -n "$lgpl"; then
2666     license_incompatibilities=
2667     for module in $main_modules; do
2668       license=`func_get_license $module`
2669       case $license in
2670         'GPLed build tool') ;;
2671         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2672         *)
2673           case "$lgpl" in
2674             yes | 3)
2675               case $license in
2676                 LGPL | LGPLv2+) ;;
2677                 *) func_append license_incompatibilities "$module $license$nl" ;;
2678               esac
2679               ;;
2680             2)
2681               case $license in
2682                 LGPLv2+) ;;
2683                 *) func_append license_incompatibilities "$module $license$nl" ;;
2684               esac
2685               ;;
2686             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2687           esac
2688           ;;
2689       esac
2690     done
2691     if test -n "$license_incompatibilities"; then
2692       # Format the license incompatibilities as a table.
2693       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
2694 s,^\(.................................................[^ ]*\) *,                 \1 ,'
2695       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
2696       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
2697     fi
2698   fi
2699
2700   # Show banner notice of every module.
2701   modules="$main_modules"
2702   func_modules_notice
2703
2704   # Determine script to apply to imported library files.
2705   sed_transform_lib_file=
2706   for module in $main_modules; do
2707     if test $module = config-h; then
2708       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
2709       sed_transform_lib_file=$sed_transform_lib_file'
2710         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
2711       '
2712       break
2713     fi
2714   done
2715   sed_transform_main_lib_file="$sed_transform_lib_file"
2716   if test -n "$do_copyrights"; then
2717     if test -n "$lgpl"; then
2718       # Update license.
2719       case "$lgpl" in
2720         yes | 3)
2721           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2722             s/GNU General/GNU Lesser General/g
2723           '
2724           ;;
2725         2)
2726           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2727             s/GNU General/GNU Lesser General/g
2728             s/version [23]\([ ,]\)/version 2.1\1/g
2729           '
2730           ;;
2731         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2732       esac
2733     else
2734       # Update license.
2735       sed_transform_main_lib_file=$sed_transform_main_lib_file'
2736         s/GNU Lesser General/GNU General/g
2737         s/GNU Library General/GNU General/g
2738         s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2739       '
2740     fi
2741   fi
2742
2743   # Determine script to apply to library files that go into $testsbase/.
2744   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
2745   if test -n "$do_copyrights"; then
2746     # Update license.
2747     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
2748       s/GNU Lesser General/GNU General/g
2749       s/GNU Library General/GNU General/g
2750       s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2751     '
2752   fi
2753
2754   # Determine the final file lists.
2755   # They must be computed separately, because files in lib/* go into
2756   # $sourcebase/ if they are in the main file list but into $testsbase/
2757   # if they are in the tests-related file list. Furthermore lib/dummy.c
2758   # can be in both.
2759   # Determine final main file list.
2760   modules="$main_modules"
2761   func_modules_to_filelist
2762   main_files="$files"
2763   # Determine final tests-related file list.
2764   modules="$testsrelated_modules"
2765   func_modules_to_filelist
2766   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
2767   # Merge both file lists.
2768   sed_remove_empty_lines='/^$/d'
2769   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
2770   if test $verbose -ge 0; then
2771     echo "File list:"
2772     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
2773     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
2774   fi
2775
2776   test -n "$files" \
2777     || func_fatal_error "refusing to do nothing"
2778
2779   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2780   new_files="$files m4/gnulib-tool.m4"
2781   old_files="$cached_files"
2782   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2783     func_append old_files " m4/gnulib-tool.m4"
2784   fi
2785
2786   sed_rewrite_old_files="\
2787     s,^build-aux/,$auxdir/,
2788     s,^doc/,$cached_docbase/,
2789     s,^lib/,$cached_sourcebase/,
2790     s,^m4/,$cached_m4base/,
2791     s,^tests/,$cached_testsbase/,
2792     s,^tests=lib/,$cached_testsbase/,
2793     s,^top/,,"
2794   sed_rewrite_new_files="\
2795     s,^build-aux/,$auxdir/,
2796     s,^doc/,$docbase/,
2797     s,^lib/,$sourcebase/,
2798     s,^m4/,$m4base/,
2799     s,^tests/,$testsbase/,
2800     s,^tests=lib/,$testsbase/,
2801     s,^top/,,"
2802
2803   # Create directories.
2804   { echo "$sourcebase"
2805     echo "$m4base"
2806     if test -n "$pobase"; then
2807       echo "$pobase"
2808     fi
2809     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2810     if test -n "$docfiles"; then
2811       echo "$docbase"
2812     fi
2813     if test -n "$inctests"; then
2814       echo "$testsbase"
2815     fi
2816     echo "$auxdir"
2817     for f in $files; do echo $f; done \
2818       | sed -e "$sed_rewrite_new_files" \
2819       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2820       | LC_ALL=C sort -u
2821   } > "$tmp"/dirs
2822   { # Rearrange file descriptors. Needed because "while ... done < ..."
2823     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2824     exec 5<&0 < "$tmp"/dirs
2825     while read d; do
2826       if test ! -d "$destdir/$d"; then
2827         if $doit; then
2828           echo "Creating directory $destdir/$d"
2829           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2830         else
2831           echo "Create directory $destdir/$d"
2832         fi
2833       fi
2834     done
2835     exec 0<&5 5<&-
2836   }
2837
2838   # func_dest_tmpfilename file
2839   # determines the name of a temporary file (file is relative to destdir).
2840   # Sets variable:
2841   #   - tmpfile       absolute filename of the temporary file
2842   func_dest_tmpfilename ()
2843   {
2844     if $doit; then
2845       # Put the new contents of $file in a file in the same directory (needed
2846       # to guarantee that an 'mv' to "$destdir/$file" works).
2847       tmpfile="$destdir/$1.tmp"
2848     else
2849       # Put the new contents of $file in a file in a temporary directory
2850       # (because the directory of "$file" might not exist).
2851       tmpfile="$tmp"/`basename "$1"`.tmp
2852     fi
2853   }
2854
2855   # Copy files or make symbolic links. Remove obsolete files.
2856   added_files=''
2857   removed_files=''
2858   delimiter='   '
2859   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2860   # representing the files according to the last gnulib-tool invocation.
2861   for f in $old_files; do echo $f; done \
2862     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2863     | LC_ALL=C sort \
2864     > "$tmp"/old-files
2865   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2866   # representing the files after this gnulib-tool invocation.
2867   for f in $new_files; do echo $f; done \
2868     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2869     | LC_ALL=C sort \
2870     > "$tmp"/new-files
2871   # First the files that are in old-files, but not in new-files:
2872   sed_take_first_column='s,'"$delimiter"'.*,,'
2873   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2874     # Remove the file. Do nothing if the user already removed it.
2875     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
2876       if $doit; then
2877         echo "Removing file $g (backup in ${g}~)"
2878         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2879       else
2880         echo "Remove file $g (backup in ${g}~)"
2881       fi
2882       func_append removed_files "$g$nl"
2883     fi
2884   done
2885   # func_add_or_update handles a file that ought to be present afterwards.
2886   # Uses parameters
2887   # - f             the original file name
2888   # - g             the rewritten file name
2889   # - already_present  nonempty if the file already exists, empty otherwise
2890   func_add_or_update ()
2891   {
2892     of="$f"
2893     case "$f" in
2894       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
2895     esac
2896     func_dest_tmpfilename "$g"
2897     func_lookup_file "$f"
2898     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2899     if test -n "$sed_transform_main_lib_file"; then
2900       case "$of" in
2901         lib/*)
2902           sed -e "$sed_transform_main_lib_file" \
2903             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2904           ;;
2905       esac
2906     fi
2907     if test -n "$sed_transform_testsrelated_lib_file"; then
2908       case "$of" in
2909         tests=lib/*)
2910           sed -e "$sed_transform_testsrelated_lib_file" \
2911             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2912           ;;
2913       esac
2914     fi
2915     if test -f "$destdir/$g"; then
2916       # The file already exists.
2917       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2918         : # The file has not changed.
2919       else
2920         # Replace the file.
2921         if $doit; then
2922           if test -n "$already_present"; then
2923             echo "Updating file $g (backup in ${g}~)"
2924           else
2925             echo "Replacing file $g (non-gnulib code backed up in ${g}~) !!"
2926           fi
2927           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2928           if { test -n "$symbolic" \
2929                || { test -n "$lsymbolic" \
2930                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2931              && test -z "$lookedup_tmp" \
2932              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2933             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2934           else
2935             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2936           fi
2937         else
2938           if test -n "$already_present"; then
2939             echo "Update file $g (backup in ${g}~)"
2940           else
2941             echo "Replace file $g (non-gnulib code backed up in ${g}~) !!"
2942           fi
2943         fi
2944       fi
2945     else
2946       # Install the file.
2947       # Don't protest if the file should be there but isn't: it happens
2948       # frequently that developers don't put autogenerated files into CVS.
2949       if $doit; then
2950         echo "Copying file $g"
2951         if { test -n "$symbolic" \
2952              || { test -n "$lsymbolic" \
2953                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2954            && test -z "$lookedup_tmp" \
2955            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2956           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2957         else
2958           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2959         fi
2960       else
2961         echo "Copy file $g"
2962       fi
2963       func_append added_files "$g$nl"
2964     fi
2965     rm -f "$tmpfile"
2966   }
2967   # Then the files that are in new-files, but not in old-files:
2968   sed_take_last_column='s,^.*'"$delimiter"',,'
2969   already_present=
2970   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2971     | sed -e "$sed_take_last_column" \
2972     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2973   { # Rearrange file descriptors. Needed because "while ... done < ..."
2974     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2975     exec 5<&0 < "$tmp"/added-files
2976     while read g f; do
2977       func_add_or_update
2978     done
2979     exec 0<&5 5<&-
2980   }
2981   # Then the files that are in new-files and in old-files:
2982   already_present=true
2983   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2984     | sed -e "$sed_take_last_column" \
2985     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2986   { # Rearrange file descriptors. Needed because "while ... done < ..."
2987     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2988     exec 5<&0 < "$tmp"/kept-files
2989     while read g f; do
2990       func_add_or_update
2991     done
2992     exec 0<&5 5<&-
2993   }
2994
2995   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2996   actioncmd="gnulib-tool --import"
2997   func_append actioncmd " --dir=$destdir"
2998   if test -n "$local_gnulib_dir"; then
2999     func_append actioncmd " --local-dir=$local_gnulib_dir"
3000   fi
3001   func_append actioncmd " --lib=$libname"
3002   func_append actioncmd " --source-base=$sourcebase"
3003   func_append actioncmd " --m4-base=$m4base"
3004   if test -n "$pobase"; then
3005     func_append actioncmd " --po-base=$pobase"
3006   fi
3007   func_append actioncmd " --doc-base=$docbase"
3008   func_append actioncmd " --tests-base=$testsbase"
3009   func_append actioncmd " --aux-dir=$auxdir"
3010   if test -n "$inctests"; then
3011     func_append actioncmd " --with-tests"
3012   fi
3013   if test -n "$incobsolete"; then
3014     func_append actioncmd " --with-obsolete"
3015   fi
3016   for module in $avoidlist; do
3017     func_append actioncmd " --avoid=$module"
3018   done
3019   if test -n "$lgpl"; then
3020     if test "$lgpl" = yes; then
3021       func_append actioncmd " --lgpl"
3022     else
3023       func_append actioncmd " --lgpl=$lgpl"
3024     fi
3025   fi
3026   if test -n "$makefile_name"; then
3027     func_append actioncmd " --makefile-name=$makefile_name"
3028   fi
3029   if test "$libtool" = true; then
3030     func_append actioncmd " --libtool"
3031   else
3032     func_append actioncmd " --no-libtool"
3033   fi
3034   func_append actioncmd " --macro-prefix=$macro_prefix"
3035   if test -n "$po_domain"; then
3036     func_append actioncmd " --po-domain=$po_domain"
3037   fi
3038   if test -n "$vc_files"; then
3039     if test "$vc_files" = true; then
3040       func_append actioncmd " --vc-files"
3041     else
3042       func_append actioncmd " --no-vc-files"
3043     fi
3044   fi
3045   func_append actioncmd " `echo $specified_modules`"
3046
3047   # Default the makefile name to Makefile.am.
3048   if test -n "$makefile_name"; then
3049     makefile_am=$makefile_name
3050   else
3051     makefile_am=Makefile.am
3052   fi
3053
3054   # Create normal Makefile.ams.
3055   for_test=false
3056
3057   # Setup list of Makefile.am edits that are to be performed afterwards.
3058   # Some of these edits apply to files that we will generate; others are
3059   # under the responsibility of the developer.
3060   makefile_am_edits=0
3061   # func_note_Makefile_am_edit dir var value
3062   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
3063   # ${value}.
3064   func_note_Makefile_am_edit ()
3065   {
3066     makefile_am_edits=`expr $makefile_am_edits + 1`
3067     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
3068     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
3069     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
3070   }
3071   if test "$makefile_am" = Makefile.am; then
3072     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
3073     sourcebase_base=`basename "$sourcebase"`
3074     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
3075   fi
3076   if test -n "$pobase"; then
3077     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
3078     pobase_base=`basename "$pobase"`
3079     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
3080   fi
3081   if test -n "$inctests"; then
3082     if test "$makefile_am" = Makefile.am; then
3083       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
3084       testsbase_base=`basename "$testsbase"`
3085       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
3086     fi
3087   fi
3088   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
3089   {
3090     # Find the first parent directory of $m4base that contains or will contain
3091     # a Makefile.am.
3092     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
3093 s,//*$,/,'
3094     sed_butlast='s,[^/][^/]*//*$,,'
3095     dir1="${m4base}/"; dir2=""
3096     while test -n "$dir1" \
3097           && ! { test -f "${destdir}/${dir1}Makefile.am" \
3098                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
3099                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
3100                  || { test -n "$inctests" \
3101                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
3102                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
3103       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
3104       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
3105     done
3106     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
3107   }
3108
3109   # Create library makefile.
3110   func_dest_tmpfilename $sourcebase/$makefile_am
3111   destfile="$sourcebase/$makefile_am"
3112   modules="$main_modules"
3113   func_emit_lib_Makefile_am > "$tmpfile"
3114   if test -f "$destdir"/$sourcebase/$makefile_am; then
3115     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
3116       rm -f "$tmpfile"
3117     else
3118       if $doit; then
3119         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
3120         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
3121         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
3122       else
3123         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
3124         rm -f "$tmpfile"
3125       fi
3126     fi
3127   else
3128     if $doit; then
3129       echo "Creating $sourcebase/$makefile_am"
3130       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
3131     else
3132       echo "Create $sourcebase/$makefile_am"
3133       rm -f "$tmpfile"
3134     fi
3135     func_append added_files "$sourcebase/$makefile_am$nl"
3136   fi
3137
3138   # Create po/ directory.
3139   if test -n "$pobase"; then
3140     # Create po makefile and auxiliary files.
3141     for file in Makefile.in.in remove-potcdate.sin; do
3142       func_dest_tmpfilename $pobase/$file
3143       func_lookup_file build-aux/po/$file
3144       cat "$lookedup_file" > "$tmpfile"
3145       if test -f "$destdir"/$pobase/$file; then
3146         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
3147           rm -f "$tmpfile"
3148         else
3149           if $doit; then
3150             echo "Updating $pobase/$file (backup in $pobase/$file~)"
3151             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
3152             mv -f "$tmpfile" "$destdir"/$pobase/$file
3153           else
3154             echo "Update $pobase/$file (backup in $pobase/$file~)"
3155             rm -f "$tmpfile"
3156           fi
3157         fi
3158       else
3159         if $doit; then
3160           echo "Creating $pobase/$file"
3161           mv -f "$tmpfile" "$destdir"/$pobase/$file
3162         else
3163           echo "Create $pobase/$file"
3164           rm -f "$tmpfile"
3165         fi
3166         func_append added_files "$pobase/$file$nl"
3167       fi
3168     done
3169     # Create po makefile parameterization, part 1.
3170     func_dest_tmpfilename $pobase/Makevars
3171     func_emit_po_Makevars > "$tmpfile"
3172     if test -f "$destdir"/$pobase/Makevars; then
3173       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
3174         rm -f "$tmpfile"
3175       else
3176         if $doit; then
3177           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
3178           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
3179           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
3180         else
3181           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
3182           rm -f "$tmpfile"
3183         fi
3184       fi
3185     else
3186       if $doit; then
3187         echo "Creating $pobase/Makevars"
3188         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
3189       else
3190         echo "Create $pobase/Makevars"
3191         rm -f "$tmpfile"
3192       fi
3193       func_append added_files "$pobase/Makevars$nl"
3194     fi
3195     # Create po makefile parameterization, part 2.
3196     func_dest_tmpfilename $pobase/POTFILES.in
3197     func_emit_po_POTFILES_in > "$tmpfile"
3198     if test -f "$destdir"/$pobase/POTFILES.in; then
3199       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
3200         rm -f "$tmpfile"
3201       else
3202         if $doit; then
3203           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
3204           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
3205           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
3206         else
3207           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
3208           rm -f "$tmpfile"
3209         fi
3210       fi
3211     else
3212       if $doit; then
3213         echo "Creating $pobase/POTFILES.in"
3214         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
3215       else
3216         echo "Create $pobase/POTFILES.in"
3217         rm -f "$tmpfile"
3218       fi
3219       func_append added_files "$pobase/POTFILES.in$nl"
3220     fi
3221     # Fetch PO files.
3222     TP_URL="http://translationproject.org/latest/"
3223     TP_RSYNC_URI="translationproject.org::tp/latest/"
3224     if $doit; then
3225       echo "Fetching gnulib PO files from $TP_URL"
3226       (cd "$destdir"/$pobase \
3227        && { # Prefer rsync over wget if it is available, since it consumes
3228             # less network bandwidth, due to compression.
3229             if type rsync 2>/dev/null | grep / > /dev/null; then
3230               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
3231             else
3232               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
3233             fi
3234           }
3235       )
3236     else
3237       echo "Fetch gnulib PO files from $TP_URL"
3238     fi
3239     # Create po/LINGUAS.
3240     if $doit; then
3241       func_dest_tmpfilename $pobase/LINGUAS
3242       (cd "$destdir"/$pobase \
3243        && { echo '# Set of available languages.'
3244             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
3245           }
3246       ) > "$tmpfile"
3247       if test -f "$destdir"/$pobase/LINGUAS; then
3248         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
3249           rm -f "$tmpfile"
3250         else
3251           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
3252           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
3253           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
3254         fi
3255       else
3256         echo "Creating $pobase/LINGUAS"
3257         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
3258         func_append added_files "$pobase/LINGUAS$nl"
3259       fi
3260     else
3261       if test -f "$destdir"/$pobase/LINGUAS; then
3262         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
3263       else
3264         echo "Create $pobase/LINGUAS"
3265       fi
3266     fi
3267   fi
3268
3269   # Create m4/gnulib-cache.m4.
3270   func_dest_tmpfilename $m4base/gnulib-cache.m4
3271   (
3272     func_emit_copyright_notice
3273     echo "#"
3274     echo "# This file represents the specification of how gnulib-tool is used."
3275     echo "# It acts as a cache: It is written and read by gnulib-tool."
3276     echo "# In projects using CVS, this file is meant to be stored in CVS,"
3277     echo "# like the configure.ac and various Makefile.am files."
3278     echo
3279     echo
3280     echo "# Specification in the form of a command-line invocation:"
3281     echo "#   $actioncmd"
3282     echo
3283     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
3284     # Store the local_gnulib_dir relative to destdir.
3285     case "$local_gnulib_dir" in
3286       "" | /*)
3287         relative_local_gnulib_dir="$local_gnulib_dir" ;;
3288       * )
3289         case "$destdir" in
3290           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
3291           *)
3292             # destdir, local_gnulib_dir are both relative.
3293             func_relativize "$destdir" "$local_gnulib_dir"
3294             relative_local_gnulib_dir="$reldir" ;;
3295         esac ;;
3296     esac
3297     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
3298     echo "gl_MODULES(["
3299     echo "$specified_modules" | sed 's/^/  /g'
3300     echo "])"
3301     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
3302     echo "gl_AVOID([$avoidlist])"
3303     echo "gl_SOURCE_BASE([$sourcebase])"
3304     echo "gl_M4_BASE([$m4base])"
3305     echo "gl_PO_BASE([$pobase])"
3306     echo "gl_DOC_BASE([$docbase])"
3307     echo "gl_TESTS_BASE([$testsbase])"
3308     test -z "$inctests" || echo "gl_WITH_TESTS"
3309     echo "gl_LIB([$libname])"
3310     if test -n "$lgpl"; then
3311       if test "$lgpl" = yes; then
3312         echo "gl_LGPL"
3313       else
3314         echo "gl_LGPL([$lgpl])"
3315       fi
3316     fi
3317     echo "gl_MAKEFILE_NAME([$makefile_name])"
3318     if test "$libtool" = true; then
3319       echo "gl_LIBTOOL"
3320     fi
3321     echo "gl_MACRO_PREFIX([$macro_prefix])"
3322     echo "gl_PO_DOMAIN([$po_domain])"
3323     if test -n "$vc_files"; then
3324       echo "gl_VC_FILES([$vc_files])"
3325     fi
3326   ) > "$tmpfile"
3327   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
3328     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
3329       rm -f "$tmpfile"
3330     else
3331       if $doit; then
3332         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
3333         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
3334         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
3335       else
3336         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
3337         if false; then
3338           cat "$tmpfile"
3339           echo
3340           echo "# gnulib-cache.m4 ends here"
3341         fi
3342         rm -f "$tmpfile"
3343       fi
3344     fi
3345   else
3346     if $doit; then
3347       echo "Creating $m4base/gnulib-cache.m4"
3348       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
3349     else
3350       echo "Create $m4base/gnulib-cache.m4"
3351       cat "$tmpfile"
3352       rm -f "$tmpfile"
3353     fi
3354   fi
3355
3356   # Create m4/gnulib-comp.m4.
3357   func_dest_tmpfilename $m4base/gnulib-comp.m4
3358   (
3359     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
3360     func_emit_copyright_notice
3361     echo "#"
3362     echo "# This file represents the compiled summary of the specification in"
3363     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
3364     echo "# to be invoked from configure.ac."
3365     echo "# In projects using CVS, this file can be treated like other built files."
3366     echo
3367     echo
3368     echo "# This macro should be invoked from $configure_ac, in the section"
3369     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
3370     echo "# any checks for libraries, header files, types and library functions."
3371     echo "AC_DEFUN([${macro_prefix}_EARLY],"
3372     echo "["
3373     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3374     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3375     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3376     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3377     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
3378     if test -n "$uses_subdirs"; then
3379       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
3380     fi
3381     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
3382       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
3383     fi
3384     for module in $final_modules; do
3385       func_verify_module
3386       if test -n "$module"; then
3387         func_get_autoconf_early_snippet "$module"
3388       fi
3389     done \
3390       | sed -e '/^$/d;' -e 's/^/  /'
3391     echo "])"
3392     echo
3393     echo "# This macro should be invoked from $configure_ac, in the section"
3394     echo "# \"Check for header files, types and library functions\"."
3395     echo "AC_DEFUN([${macro_prefix}_INIT],"
3396     echo "["
3397     if test "$libtool" = true; then
3398       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3399       echo "  gl_cond_libtool=true"
3400     else
3401       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3402       echo "  gl_cond_libtool=false"
3403       echo "  gl_libdeps="
3404       echo "  gl_ltlibdeps="
3405     fi
3406     if test "$auxdir" != "build-aux"; then
3407       sed_replace_build_aux='
3408         :a
3409         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3410           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3411           ba
3412         }'
3413     else
3414       sed_replace_build_aux="$sed_noop"
3415     fi
3416     func_emit_initmacro_start $macro_prefix
3417     echo "  gl_source_base='$sourcebase'"
3418     for module in $main_modules; do
3419       func_verify_module
3420       if test -n "$module"; then
3421         func_get_autoconf_snippet "$module" \
3422           | sed -e '/^$/d;' -e 's/^/  /' \
3423                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3424                 -e "$sed_replace_build_aux"
3425         if test "$module" = 'alloca' && test "$libtool" = true; then
3426           echo 'changequote(,)dnl'
3427           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3428           echo 'changequote([, ])dnl'
3429           echo 'AC_SUBST([LTALLOCA])'
3430         fi
3431       fi
3432     done
3433     func_emit_initmacro_end $macro_prefix
3434     echo "  gltests_libdeps="
3435     echo "  gltests_ltlibdeps="
3436     func_emit_initmacro_start ${macro_prefix}tests
3437     echo "  gl_source_base='$testsbase'"
3438     for module in $testsrelated_modules; do
3439       func_verify_module
3440       if test -n "$module"; then
3441         func_get_autoconf_snippet "$module" \
3442           | sed -e '/^$/d;' -e 's/^/  /' \
3443                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3444                 -e "$sed_replace_build_aux" \
3445                 -e 's/\$gl_cond_libtool/false/g' \
3446                 -e 's/gl_libdeps/gltests_libdeps/g' \
3447                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3448       fi
3449     done
3450     func_emit_initmacro_end ${macro_prefix}tests
3451     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3452     # created using libtool, because libtool already handles the dependencies.
3453     if test "$libtool" != true; then
3454       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3455       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3456       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3457       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3458       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3459     fi
3460     if $use_libtests; then
3461       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
3462       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
3463     fi
3464     echo "])"
3465     func_emit_initmacro_done $macro_prefix $sourcebase
3466     func_emit_initmacro_done ${macro_prefix}tests $testsbase
3467     echo
3468     echo "# This macro records the list of files which have been installed by"
3469     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
3470     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
3471     echo "$files" | sed -e 's,^,  ,'
3472     echo "])"
3473   ) > "$tmpfile"
3474   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3475     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
3476       rm -f "$tmpfile"
3477     else
3478       if $doit; then
3479         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3480         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
3481         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3482       else
3483         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3484         if false; then
3485           cat "$tmpfile"
3486           echo
3487           echo "# gnulib-comp.m4 ends here"
3488         fi
3489         rm -f "$tmpfile"
3490       fi
3491     fi
3492   else
3493     if $doit; then
3494       echo "Creating $m4base/gnulib-comp.m4"
3495       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3496     else
3497       echo "Create $m4base/gnulib-comp.m4"
3498       cat "$tmpfile"
3499       rm -f "$tmpfile"
3500     fi
3501   fi
3502
3503   if test -n "$inctests"; then
3504     # Create tests makefile.
3505     func_dest_tmpfilename $testsbase/$makefile_am
3506     destfile="$testsbase/$makefile_am"
3507     modules="$testsrelated_modules"
3508     func_emit_tests_Makefile_am > "$tmpfile"
3509     if test -f "$destdir"/$testsbase/$makefile_am; then
3510       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
3511         rm -f "$tmpfile"
3512       else
3513         if $doit; then
3514           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3515           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
3516           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3517         else
3518           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3519           rm -f "$tmpfile"
3520         fi
3521       fi
3522     else
3523       if $doit; then
3524         echo "Creating $testsbase/$makefile_am"
3525         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3526       else
3527         echo "Create $testsbase/$makefile_am"
3528         rm -f "$tmpfile"
3529       fi
3530     func_append added_files "$testsbase/$makefile_am$nl"
3531     fi
3532   fi
3533
3534   if test "$vc_files" != false; then
3535     # Update the .cvsignore and .gitignore files.
3536     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
3537       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
3538       # Treat gnulib-comp.m4 like an added file, even if it already existed.
3539       echo "$m4base/|A|gnulib-comp.m4"
3540     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
3541     { # Rearrange file descriptors. Needed because "while ... done < ..."
3542       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3543       exec 5<&0 < "$tmp"/fileset-changes
3544       func_update_ignorelist ()
3545       {
3546         ignore="$1"
3547         if test "$ignore" = .gitignore; then
3548           # In a .gitignore file, "foo" applies to the current directory and all
3549           # subdirectories, whereas "/foo" applies to the current directory only.
3550           anchor='/'
3551           escaped_anchor='\/'
3552           doubly_escaped_anchor='\\/'
3553         else
3554           anchor=''
3555           escaped_anchor=''
3556           doubly_escaped_anchor=''
3557         fi
3558         if test -f "$destdir/$dir$ignore"; then
3559           if test -n "$dir_added" || test -n "$dir_removed"; then
3560             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
3561             (func_reset_sigpipe
3562              echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
3563                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
3564              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
3565                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-removed
3566             )
3567             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
3568               if $doit; then
3569                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3570                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
3571                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
3572                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,\$/d,' < "$tmp"/ignore-removed; fi
3573                 } > "$tmp"/sed-ignore-removed
3574                 { cat "$destdir/$dir$ignore"~
3575                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
3576                 } | sed -f "$tmp"/sed-ignore-removed \
3577                   > "$destdir/$dir$ignore"
3578               else
3579                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3580               fi
3581             fi
3582           fi
3583         else
3584           if test -n "$dir_added"; then
3585             if $doit; then
3586               echo "Creating $destdir/$dir$ignore"
3587               {
3588                 if test "$ignore" = .cvsignore; then
3589                   echo ".deps"
3590                   # Automake generates Makefile rules that create .dirstamp files.
3591                   echo ".dirstamp"
3592                 fi
3593                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
3594               } > "$destdir/$dir$ignore"
3595             else
3596               echo "Create $destdir/$dir$ignore"
3597             fi
3598           fi
3599         fi
3600       }
3601       func_done_dir ()
3602       {
3603         dir="$1"
3604         dir_added="$2"
3605         dir_removed="$3"
3606         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
3607           func_update_ignorelist .cvsignore
3608         fi
3609         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
3610           func_update_ignorelist .gitignore
3611         fi
3612       }
3613       last_dir=
3614       last_dir_added=
3615       last_dir_removed=
3616       while read line; do
3617         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
3618         next_dir=`echo "$line" | sed -e 's,|.*,,'`
3619         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
3620         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
3621         if test "$next_dir" != "$last_dir"; then
3622           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3623           last_dir="$next_dir"
3624           last_dir_added=
3625           last_dir_removed=
3626         fi
3627         case $op in
3628           A) func_append last_dir_added "$file$nl";;
3629           R) func_append last_dir_removed "$file$nl";;
3630         esac
3631       done
3632       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3633       exec 0<&5 5<&-
3634     }
3635   fi
3636
3637   echo "Finished."
3638   echo
3639   echo "You may need to add #include directives for the following .h files."
3640   # Intersect $specified_modules and $main_modules
3641   # (since $specified_modules is not necessarily of subset of $main_modules
3642   # - some may have been skipped through --avoid, and since the elements of
3643   # $main_modules but not in $specified_modules can go away without explicit
3644   # notice - through changes in the module dependencies).
3645   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
3646   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
3647   # First the #include <...> directives without #ifs, sorted for convenience,
3648   # then the #include "..." directives without #ifs, sorted for convenience,
3649   # then the #include directives that are surrounded by #ifs. Not sorted.
3650   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
3651     include_directive=`func_get_include_directive "$module"`
3652     case "$nl$include_directive" in
3653       *"$nl#if"*)
3654         echo "$include_directive" 1>&5
3655         ;;
3656       *)
3657         echo "$include_directive" | grep -v 'include "' 1>&6
3658         echo "$include_directive" | grep 'include "' 1>&7
3659         ;;
3660     esac
3661   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
3662   (
3663    LC_ALL=C sort -u "$tmp"/include-angles
3664    LC_ALL=C sort -u "$tmp"/include-quotes
3665    cat "$tmp"/include-if
3666   ) | sed -e '/^$/d' -e 's/^/  /'
3667   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
3668
3669   for module in $main_modules; do
3670     func_get_link_directive "$module"
3671   done \
3672     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
3673   if test `wc -l < "$tmp"/link` != 0; then
3674     echo
3675     echo "You may need to use the following Makefile variables when linking."
3676     echo "Use them in <program>_LDADD when linking a program, or"
3677     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
3678     cat "$tmp"/link
3679   fi
3680   rm -f "$tmp"/link
3681
3682   echo
3683   echo "Don't forget to"
3684   if test "$makefile_am" = Makefile.am; then
3685     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3686   else
3687     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
3688   fi
3689   if test -n "$pobase"; then
3690     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
3691   fi
3692   if test -n "$inctests"; then
3693     if test "$makefile_am" = Makefile.am; then
3694       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3695     else
3696       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
3697     fi
3698   fi
3699   edit=0
3700   while test $edit != $makefile_am_edits; do
3701     edit=`expr $edit + 1`
3702     eval dir=\"\$makefile_am_edit${edit}_dir\"
3703     eval var=\"\$makefile_am_edit${edit}_var\"
3704     eval val=\"\$makefile_am_edit${edit}_val\"
3705     if test -n "$var"; then
3706       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
3707     fi
3708   done
3709   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
3710   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
3711 }
3712
3713 # func_create_testdir testdir modules
3714 # Input:
3715 # - local_gnulib_dir  from --local-dir
3716 # - auxdir          directory relative to destdir where to place build aux files
3717 func_create_testdir ()
3718 {
3719   testdir="$1"
3720   modules="$2"
3721   if test -z "$modules"; then
3722     # All modules together.
3723     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3724     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3725     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
3726     modules=`func_all_modules`
3727     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
3728   fi
3729   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
3730
3731   # Check that the license of every module is consistent with the license of
3732   # its dependencies.
3733   saved_modules="$modules"
3734   saved_inctests="$inctests"
3735   # When computing transitive closures, don't consider $module to depend on
3736   # $module-tests. Need this becauses tests are implicitly GPL and may depend
3737   # on GPL modules - therefore we don't want a warning in this case.
3738   inctests=""
3739   for requested_module in $saved_modules; do
3740     requested_license=`func_get_license "$requested_module"`
3741     if test "$requested_license" != GPL; then
3742       # Here we use func_modules_transitive_closure, not just
3743       # func_get_dependencies, so that we also detect weird situations like
3744       # an LGPL module which depends on a GPLed build tool module which depends
3745       # on a GPL module.
3746       modules="$requested_module"
3747       func_modules_transitive_closure
3748       for module in $modules; do
3749         license=`func_get_license "$module"`
3750         case "$license" in
3751           'GPLed build tool') ;;
3752           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3753           *)
3754             case "$requested_license" in
3755               GPLv2+)
3756                 case "$license" in
3757                   GPLv2+ | LGPLv2+) ;;
3758                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3759                 esac
3760                 ;;
3761               LGPL)
3762                 case "$license" in
3763                   LGPL | LGPLv2+) ;;
3764                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3765                 esac
3766                 ;;
3767               LGPLv2+)
3768                 case "$license" in
3769                   LGPLv2+) ;;
3770                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3771                 esac
3772                 ;;
3773             esac
3774             ;;
3775         esac
3776       done
3777     fi
3778   done
3779   modules="$saved_modules"
3780   inctests="$saved_inctests"
3781
3782   # Subdirectory names.
3783   sourcebase=gllib
3784   m4base=glm4
3785   pobase=
3786   docbase=gldoc
3787   testsbase=gltests
3788   macro_prefix=gl
3789   po_domain=
3790   vc_files=
3791
3792   # Determine final module list.
3793   func_modules_transitive_closure
3794   if test $verbose -ge 0; then
3795     echo "Module list with included dependencies:"
3796     echo "$modules" | sed -e 's/^/  /'
3797   fi
3798
3799   # Add the dummy module if needed.
3800   func_modules_add_dummy
3801
3802   # Show banner notice of every module.
3803   func_modules_notice
3804
3805   # Determine final file list.
3806   func_modules_to_filelist
3807   if test $verbose -ge 0; then
3808     echo "File list:"
3809     echo "$files" | sed -e 's/^/  /'
3810   fi
3811
3812   sed_rewrite_files="\
3813     s,^build-aux/,$auxdir/,
3814     s,^doc/,$docbase/,
3815     s,^lib/,$sourcebase/,
3816     s,^m4/,$m4base/,
3817     s,^tests/,$testsbase/,
3818     s,^top/,,"
3819
3820   # Create directories.
3821   for f in $files; do echo $f; done \
3822     | sed -e "$sed_rewrite_files" \
3823     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3824     | LC_ALL=C sort -u \
3825     > "$tmp"/dirs
3826   { # Rearrange file descriptors. Needed because "while ... done < ..."
3827     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3828     exec 5<&0 < "$tmp"/dirs
3829     while read d; do
3830       mkdir -p "$testdir/$d"
3831     done
3832     exec 0<&5 5<&-
3833   }
3834
3835   # Copy files or make symbolic links.
3836   delimiter='   '
3837   for f in $files; do echo $f; done \
3838     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
3839     | LC_ALL=C sort \
3840     > "$tmp"/files
3841   { # Rearrange file descriptors. Needed because "while ... done < ..."
3842     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3843     exec 5<&0 < "$tmp"/files
3844     while read g f; do
3845       func_lookup_file "$f"
3846       if test -n "$lookedup_tmp"; then
3847         cp -p "$lookedup_file" "$testdir/$g"
3848       else
3849         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
3850         if { test -n "$symbolic" \
3851              || { test -n "$lsymbolic" \
3852                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
3853           func_ln "$lookedup_file" "$testdir/$g"
3854         else
3855           cp -p "$lookedup_file" "$testdir/$g"
3856         fi
3857       fi
3858     done
3859     exec 0<&5 5<&-
3860   }
3861
3862   # Create Makefile.ams that are for testing.
3863   for_test=true
3864
3865   # No special edits are needed.
3866   makefile_am_edits=0
3867
3868   # Create $sourcebase/Makefile.am.
3869   mkdir -p "$testdir/$sourcebase"
3870   destfile="$sourcebase/Makefile.am"
3871   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
3872   any_uses_subdirs="$uses_subdirs"
3873
3874   # Create $m4base/Makefile.am.
3875   mkdir -p "$testdir/$m4base"
3876   (echo "## Process this file with automake to produce Makefile.in."
3877    echo
3878    echo "EXTRA_DIST ="
3879    for f in $files; do
3880      case "$f" in
3881        m4/* )
3882          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
3883      esac
3884    done
3885   ) > "$testdir/$m4base/Makefile.am"
3886
3887   subdirs="$sourcebase $m4base"
3888   subdirs_with_configure_ac=""
3889
3890   if false && test -f "$testdir"/$m4base/gettext.m4; then
3891     # Avoid stupid error message from automake:
3892     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
3893     mkdir -p "$testdir/po"
3894     (echo "## Process this file with automake to produce Makefile.in."
3895     ) > "$testdir/po/Makefile.am"
3896     func_append subdirs " po"
3897   fi
3898
3899   if test -n "$inctests"; then
3900     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
3901     # Viewed from the $testsbase subdirectory, $auxdir is different.
3902     saved_auxdir="$auxdir"
3903     auxdir=`echo "$testsbase/"|sed 's%[^/][^/]*//*%../%g'`"$auxdir"
3904     # Create $testsbase/Makefile.am.
3905     use_libtests=false
3906     destfile="$testsbase/Makefile.am"
3907     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
3908     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
3909     # Create $testsbase/configure.ac.
3910     (echo "# Process this file with autoconf to produce a configure script."
3911      echo "AC_INIT([dummy], [0])"
3912      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3913      echo "AM_INIT_AUTOMAKE"
3914      echo
3915      echo "AM_CONFIG_HEADER([config.h])"
3916      echo
3917      echo "AC_PROG_CC"
3918      echo "AC_PROG_INSTALL"
3919      echo "AC_PROG_MAKE_SET"
3920      echo "AC_PROG_RANLIB"
3921      echo
3922      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3923        echo "AC_GNU_SOURCE"
3924        echo
3925      fi
3926      for module in $modules; do
3927        func_verify_module
3928        if test -n "$module"; then
3929          case $module in
3930            gnumakefile | maintainer-makefile)
3931              # These modules are meant to be used only in the top-level directory.
3932              ;;
3933            *)
3934              func_get_autoconf_early_snippet "$module"
3935              ;;
3936          esac
3937        fi
3938      done \
3939        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3940      if test "$libtool" = true; then
3941        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3942        echo "gl_cond_libtool=true"
3943      else
3944        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3945        echo "gl_cond_libtool=false"
3946        echo "gl_libdeps="
3947        echo "gl_ltlibdeps="
3948      fi
3949      # Wrap the set of autoconf snippets into an autoconf macro that is then
3950      # invoked. This is needed because autoconf does not support AC_REQUIRE
3951      # at the top level:
3952      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3953      # but we want the AC_REQUIRE to have its normal meaning (provide one
3954      # expansion of the required macro before the current point, and only one
3955      # expansion total).
3956      echo "AC_DEFUN([gl_INIT], ["
3957      sed_replace_build_aux='
3958        :a
3959        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3960          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3961          ba
3962        }'
3963      func_emit_initmacro_start $macro_prefix
3964      # We don't have explicit ordering constraints between the various
3965      # autoconf snippets. It's cleanest to put those of the library before
3966      # those of the tests.
3967      echo "gl_source_base='../$sourcebase'"
3968      for module in $modules; do
3969        func_verify_nontests_module
3970        if test -n "$module"; then
3971          case $module in
3972            gnumakefile | maintainer-makefile)
3973              # These modules are meant to be used only in the top-level directory.
3974              ;;
3975            *)
3976              func_get_autoconf_snippet "$module" \
3977                | sed -e "$sed_replace_build_aux"
3978              ;;
3979          esac
3980        fi
3981      done
3982      echo "gl_source_base='.'"
3983      for module in $modules; do
3984        func_verify_tests_module
3985        if test -n "$module"; then
3986          func_get_autoconf_snippet "$module" \
3987            | sed -e "$sed_replace_build_aux"
3988        fi
3989      done
3990      func_emit_initmacro_end $macro_prefix
3991      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3992      # created using libtool, because libtool already handles the dependencies.
3993      if test "$libtool" != true; then
3994        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3995        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3996        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3997        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3998        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3999      fi
4000      echo "])"
4001      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
4002      echo
4003      echo "gl_INIT"
4004      echo
4005      # Usually $testsbase/config.h will be a superset of config.h. Verify this
4006      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
4007      echo "AH_TOP([#include \"../config.h\"])"
4008      echo
4009      echo "AC_OUTPUT([Makefile])"
4010     ) > "$testdir/$testsbase/configure.ac"
4011     auxdir="$saved_auxdir"
4012     func_append subdirs " $testsbase"
4013     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
4014   fi
4015
4016   # Create Makefile.am.
4017   (echo "## Process this file with automake to produce Makefile.in."
4018    echo
4019    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
4020    echo
4021    echo "SUBDIRS = $subdirs"
4022    echo
4023    echo "ACLOCAL_AMFLAGS = -I $m4base"
4024   ) > "$testdir/Makefile.am"
4025
4026   # Create configure.ac.
4027   (echo "# Process this file with autoconf to produce a configure script."
4028    echo "AC_INIT([dummy], [0])"
4029    if test "$auxdir" != "."; then
4030      echo "AC_CONFIG_AUX_DIR([$auxdir])"
4031    fi
4032    echo "AM_INIT_AUTOMAKE"
4033    echo
4034    echo "AM_CONFIG_HEADER([config.h])"
4035    echo
4036    echo "AC_PROG_CC"
4037    echo "AC_PROG_INSTALL"
4038    echo "AC_PROG_MAKE_SET"
4039    echo
4040    echo "# For autobuild."
4041    echo "AC_CANONICAL_BUILD"
4042    echo "AC_CANONICAL_HOST"
4043    echo
4044    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
4045    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
4046    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
4047    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
4048    echo
4049    echo "AC_PROG_RANLIB"
4050    echo
4051    if test -n "$any_uses_subdirs"; then
4052      echo "AM_PROG_CC_C_O"
4053      echo
4054    fi
4055    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
4056      echo "AC_GNU_SOURCE"
4057      echo
4058    fi
4059    for module in $modules; do
4060      func_verify_nontests_module
4061      if test -n "$module"; then
4062        func_get_autoconf_early_snippet "$module"
4063      fi
4064    done \
4065      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
4066    if test "$libtool" = true; then
4067      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
4068      echo "gl_cond_libtool=true"
4069    else
4070      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
4071      echo "gl_cond_libtool=false"
4072      echo "gl_libdeps="
4073      echo "gl_ltlibdeps="
4074    fi
4075    # Wrap the set of autoconf snippets into an autoconf macro that is then
4076    # invoked. This is needed because autoconf does not support AC_REQUIRE
4077    # at the top level:
4078    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
4079    # but we want the AC_REQUIRE to have its normal meaning (provide one
4080    # expansion of the required macro before the current point, and only one
4081    # expansion total).
4082    echo "AC_DEFUN([gl_INIT], ["
4083    if test "$auxdir" != "build-aux"; then
4084      sed_replace_build_aux='
4085        :a
4086        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
4087          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
4088          ba
4089        }'
4090    else
4091      sed_replace_build_aux="$sed_noop"
4092    fi
4093    func_emit_initmacro_start $macro_prefix
4094    echo "gl_source_base='$sourcebase'"
4095    for module in $modules; do
4096      func_verify_nontests_module
4097      if test -n "$module"; then
4098        func_get_autoconf_snippet "$module" \
4099          | sed -e "$sed_replace_build_aux"
4100      fi
4101    done
4102    func_emit_initmacro_end $macro_prefix
4103    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
4104    # created using libtool, because libtool already handles the dependencies.
4105    if test "$libtool" != true; then
4106      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
4107      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
4108      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
4109      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
4110      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
4111    fi
4112    echo "])"
4113    func_emit_initmacro_done $macro_prefix $sourcebase
4114    echo
4115    echo "gl_INIT"
4116    echo
4117    if test -n "$subdirs_with_configure_ac"; then
4118      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
4119    fi
4120    makefiles="Makefile"
4121    for d in $subdirs; do
4122      # For subdirs that have a configure.ac by their own, it's the subdir's
4123      # configure.ac which creates the subdir's Makefile.am, not this one.
4124      case " $subdirs_with_configure_ac " in
4125        *" $d "*) ;;
4126        *) func_append makefiles " $d/Makefile" ;;
4127      esac
4128    done
4129    echo "AC_OUTPUT([$makefiles])"
4130   ) > "$testdir/configure.ac"
4131
4132   # Create autogenerated files.
4133   (cd "$testdir"
4134    # Do not use "${AUTORECONF} --force --install", because it may invoke
4135    # autopoint, which brings in older versions of some of our .m4 files.
4136    if test -f $m4base/gettext.m4; then
4137      func_execute_command ${AUTOPOINT} --force || func_exit 1
4138      for f in $m4base/*.m4~; do
4139        if test -f $f; then
4140          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
4141        fi
4142      done
4143    fi
4144    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
4145    if ! test -d build-aux; then
4146      func_execute_command mkdir build-aux || func_exit 1
4147    fi
4148    func_execute_command ${AUTOCONF} || func_exit 1
4149    func_execute_command ${AUTOHEADER} || func_exit 1
4150    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
4151   ) || func_exit 1
4152   if test -n "$inctests"; then
4153     # Create autogenerated files.
4154     (cd "$testdir/$testsbase" || func_exit 1
4155      # Do not use "${AUTORECONF} --force --install", because it may invoke
4156      # autopoint, which brings in older versions of some of our .m4 files.
4157      if test -f ../$m4base/gettext.m4; then
4158        func_execute_command ${AUTOPOINT} --force || func_exit 1
4159        for f in ../$m4base/*.m4~; do
4160          if test -f $f; then
4161            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
4162          fi
4163        done
4164      fi
4165      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
4166      if ! test -d ../build-aux; then
4167        func_execute_command mkdir ../build-aux
4168      fi
4169      func_execute_command ${AUTOCONF} || func_exit 1
4170      func_execute_command ${AUTOHEADER} || func_exit 1
4171      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
4172     ) || func_exit 1
4173   fi
4174   # Need to run configure and make once, to create built files that are to be
4175   # distributed (such as getdate.c).
4176   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
4177   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
4178                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
4179   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
4180   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
4181   # such $(FOO_H) because they don't refer to distributed files.
4182   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
4183   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
4184                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
4185                  | sed -e "$sed_remove_make_variables"`
4186   distributed_built_sources=`for file in $built_sources; do
4187                                case "$cleaned_files" in
4188                                  *" "$file" "*) ;;
4189                                  *) echo $file ;;
4190                                esac;
4191                              done`
4192   if test -n "$distributed_built_sources"; then
4193     (cd "$testdir"
4194      ./configure || func_exit 1
4195        cd "$sourcebase"
4196        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
4197        make built_sources || func_exit 1
4198        cd ..
4199      make distclean || func_exit 1
4200     ) || func_exit 1
4201   fi
4202 }
4203
4204 # func_create_megatestdir megatestdir allmodules
4205 # Input:
4206 # - local_gnulib_dir  from --local-dir
4207 # - auxdir          directory relative to destdir where to place build aux files
4208 func_create_megatestdir ()
4209 {
4210   megatestdir="$1"
4211   allmodules="$2"
4212   if test -z "$allmodules"; then
4213     allmodules=`func_all_modules`
4214   fi
4215
4216   megasubdirs=
4217   # First, all modules one by one.
4218   for onemodule in $allmodules; do
4219     func_create_testdir "$megatestdir/$onemodule" $onemodule
4220     func_append megasubdirs "$onemodule "
4221   done
4222   # Then, all modules all together.
4223   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
4224   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
4225   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
4226   func_create_testdir "$megatestdir/ALL" "$allmodules"
4227   func_append megasubdirs "ALL"
4228
4229   # Create autobuild.
4230   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
4231              vc_witness="$gnulib_dir/CVS/Entries"; \
4232            else \
4233              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
4234            fi; \
4235            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
4236              | sed -e 's,January,01,'   -e 's,Jan,01,' \
4237                    -e 's,February,02,'  -e 's,Feb,02,' \
4238                    -e 's,March,03,'     -e 's,Mar,03,' \
4239                    -e 's,April,04,'     -e 's,Apr,04,' \
4240                    -e 's,May,05,'                      \
4241                    -e 's,June,06,'      -e 's,Jun,06,' \
4242                    -e 's,July,07,'      -e 's,Jul,07,' \
4243                    -e 's,August,08,'    -e 's,Aug,08,' \
4244                    -e 's,September,09,' -e 's,Sep,09,' \
4245                    -e 's,October,10,'   -e 's,Oct,10,' \
4246                    -e 's,November,11,'  -e 's,Nov,11,' \
4247                    -e 's,December,12,'  -e 's,Dec,12,' \
4248                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
4249                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
4250   (echo '#!/bin/sh'
4251    echo "CVSDATE=$cvsdate"
4252    echo "test -d logs || mkdir logs"
4253    echo "for module in $megasubdirs; do"
4254    echo "  echo \"Working on module \$module...\""
4255    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
4256    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
4257    echo "   echo"
4258    echo "   set -x"
4259    echo "   : autobuild project... \$module"
4260    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
4261    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
4262    echo "   : autobuild hostname... \`hostname\`"
4263    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
4264    echo "   echo rc=\$?"
4265    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
4266    echo "done"
4267   ) > "$megatestdir/do-autobuild"
4268   chmod a+x "$megatestdir/do-autobuild"
4269
4270   # Create Makefile.am.
4271   (echo "## Process this file with automake to produce Makefile.in."
4272    echo
4273    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
4274    echo
4275    echo "SUBDIRS = $megasubdirs"
4276    echo
4277    echo "EXTRA_DIST = do-autobuild"
4278   ) > "$megatestdir/Makefile.am"
4279
4280   # Create configure.ac.
4281   (echo "# Process this file with autoconf to produce a configure script."
4282    echo "AC_INIT([dummy], [0])"
4283    if test "$auxdir" != "."; then
4284      echo "AC_CONFIG_AUX_DIR([$auxdir])"
4285    fi
4286    echo "AM_INIT_AUTOMAKE"
4287    echo
4288    echo "AC_PROG_MAKE_SET"
4289    echo
4290    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
4291    echo "AC_OUTPUT([Makefile])"
4292   ) > "$megatestdir/configure.ac"
4293
4294   # Create autogenerated files.
4295   (cd "$megatestdir"
4296    # Do not use "${AUTORECONF} --install", because autoreconf operates
4297    # recursively, but the subdirectories are already finished, therefore
4298    # calling autoreconf here would only waste lots of CPU time.
4299    func_execute_command ${ACLOCAL} || func_exit 1
4300    func_execute_command mkdir build-aux
4301    func_execute_command ${AUTOCONF} || func_exit 1
4302    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
4303   ) || func_exit 1
4304 }
4305
4306 case $mode in
4307   "" )
4308     func_fatal_error "no mode specified" ;;
4309
4310   list )
4311     func_all_modules
4312     ;;
4313
4314   import | update )
4315
4316     # Where to import.
4317     if test -z "$destdir"; then
4318       destdir=.
4319     fi
4320     test -d "$destdir" \
4321       || func_fatal_error "destination directory does not exist: $destdir"
4322
4323     # Prefer configure.ac to configure.in.
4324     if test -f "$destdir"/configure.ac; then
4325       configure_ac="$destdir/configure.ac"
4326     else
4327       if test -f "$destdir"/configure.in; then
4328         configure_ac="$destdir/configure.in"
4329       else
4330         func_fatal_error "cannot find $destdir/configure.ac"
4331       fi
4332     fi
4333
4334     # Analyze configure.ac.
4335     guessed_auxdir="."
4336     guessed_libtool=false
4337     my_sed_traces='
4338       s,#.*$,,
4339       s,^dnl .*$,,
4340       s, dnl .*$,,
4341       /AC_CONFIG_AUX_DIR/ {
4342         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
4343       }
4344       /A[CM]_PROG_LIBTOOL/ {
4345         s,^.*$,guessed_libtool=true,p
4346       }'
4347     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
4348
4349     if test -z "$auxdir"; then
4350       auxdir="$guessed_auxdir"
4351     fi
4352
4353     # Determine where to apply func_import.
4354     if test -n "$m4base"; then
4355       # Apply func_import to a particular gnulib directory.
4356       # Any number of additional modules can be given.
4357       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
4358         # First use of gnulib in the given m4base.
4359         test -n "$supplied_libname" || supplied_libname=true
4360         test -n "$sourcebase" || sourcebase="lib"
4361         test -n "$docbase" || docbase="doc"
4362         test -n "$testsbase" || testsbase="tests"
4363         test -n "$macro_prefix" || macro_prefix="gl"
4364       fi
4365       func_import "$*"
4366     else
4367       # Apply func_import to all gnulib directories.
4368       # To get this list of directories, look at Makefile.am. (Not at
4369       # configure, because it may be omitted from CVS. Also, don't run
4370       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
4371       m4dirs=
4372       m4dirs_count=0
4373       if test -f "$destdir"/Makefile.am; then
4374         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
4375         m4dir_is_next=
4376         for arg in $aclocal_amflags; do
4377           if test -n "$m4dir_is_next"; then
4378             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
4379             case "$arg" in
4380               /*) ;;
4381               *)
4382                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
4383                   func_append m4dirs " $arg"
4384                   m4dirs_count=`expr $m4dirs_count + 1`
4385                 fi
4386                 ;;
4387             esac
4388             m4dir_is_next=
4389           else
4390             if test "X$arg" = "X-I"; then
4391               m4dir_is_next=yes
4392             else
4393               m4dir_is_next=
4394             fi
4395           fi
4396         done
4397       else
4398         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
4399         if test -f "$destdir"/aclocal.m4; then
4400           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
4401           sedexpr2='s,^[^/]*$,.,'
4402           sedexpr3='s,/[^/]*$,,'
4403           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
4404           m4dirs_count=`echo "$m4dirs" | wc -l`
4405         fi
4406       fi
4407       if test $m4dirs_count = 0; then
4408         # First use of gnulib in a package.
4409         # Any number of additional modules can be given.
4410         test -n "$supplied_libname" || supplied_libname=true
4411         test -n "$sourcebase" || sourcebase="lib"
4412         m4base="m4"
4413         test -n "$docbase" || docbase="doc"
4414         test -n "$testsbase" || testsbase="tests"
4415         test -n "$macro_prefix" || macro_prefix="gl"
4416         func_import "$*"
4417       else
4418         if test $m4dirs_count = 1; then
4419           # There's only one use of gnulib here. Assume the user means it.
4420           # Any number of additional modules can be given.
4421           for m4base in $m4dirs; do
4422             func_import "$*"
4423           done
4424         else
4425           # Ambiguous - guess what the user meant.
4426           if test $# = 0; then
4427             # No further arguments. Guess the user wants to update all of them.
4428             for m4base in $m4dirs; do
4429               # Perform func_import in a subshell, so that variable values
4430               # such as
4431               #   local_gnulib_dir, incobsolete, avoidlist, sourcebase, m4base,
4432               #   pobase, docbase, testsbase, inctests, libname, lgpl,
4433               #   makefile_name, libtool, macro_prefix, po_domain, vc_files
4434               # don't propagate from one directory to another.
4435               (func_import) || func_exit 1
4436             done
4437           else
4438             # Really ambiguous.
4439             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
4440           fi
4441         fi
4442       fi
4443     fi
4444     ;;
4445
4446   create-testdir )
4447     if test -z "$destdir"; then
4448       func_fatal_error "please specify --dir option"
4449     fi
4450     mkdir "$destdir"
4451     test -d "$destdir" \
4452       || func_fatal_error "could not create destination directory"
4453     test -n "$auxdir" || auxdir="build-aux"
4454     func_create_testdir "$destdir" "$*"
4455     ;;
4456
4457   create-megatestdir )
4458     if test -z "$destdir"; then
4459       func_fatal_error "please specify --dir option"
4460     fi
4461     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4462     test -n "$auxdir" || auxdir="build-aux"
4463     func_create_megatestdir "$destdir" "$*"
4464     ;;
4465
4466   test )
4467     test -n "$destdir" || destdir=testdir$$
4468     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4469     test -n "$auxdir" || auxdir="build-aux"
4470     func_create_testdir "$destdir" "$*"
4471     cd "$destdir"
4472       mkdir build
4473       cd build
4474         ../configure || func_exit 1
4475         make || func_exit 1
4476         make check || func_exit 1
4477         make distclean || func_exit 1
4478         remaining=`find . -type f -print`
4479         if test -n "$remaining"; then
4480           echo "Remaining files:" $remaining 1>&2
4481           echo "gnulib-tool: *** Stop." 1>&2
4482           func_exit 1
4483         fi
4484       cd ..
4485     cd ..
4486     rm -rf "$destdir"
4487     ;;
4488
4489   megatest )
4490     test -n "$destdir" || destdir=testdir$$
4491     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4492     test -n "$auxdir" || auxdir="build-aux"
4493     func_create_megatestdir "$destdir" "$*"
4494     cd "$destdir"
4495       mkdir build
4496       cd build
4497         ../configure
4498         make
4499         make check
4500         make distclean
4501         remaining=`find . -type f -print`
4502         if test -n "$remaining"; then
4503           echo "Remaining files:" $remaining 1>&2
4504           echo "gnulib-tool: *** Stop." 1>&2
4505           func_exit 1
4506         fi
4507       cd ..
4508     cd ..
4509     rm -rf "$destdir"
4510     ;;
4511
4512   extract-description )
4513     for module
4514     do
4515       func_verify_module
4516       if test -n "$module"; then
4517         func_get_description "$module"
4518       fi
4519     done
4520     ;;
4521
4522   extract-status )
4523     for module
4524     do
4525       func_verify_module
4526       if test -n "$module"; then
4527         func_get_status "$module"
4528       fi
4529     done
4530     ;;
4531
4532   extract-notice )
4533     for module
4534     do
4535       func_verify_module
4536       if test -n "$module"; then
4537         func_get_notice "$module"
4538       fi
4539     done
4540     ;;
4541
4542   extract-filelist )
4543     for module
4544     do
4545       func_verify_module
4546       if test -n "$module"; then
4547         func_get_filelist "$module"
4548       fi
4549     done
4550     ;;
4551
4552   extract-dependencies )
4553     for module
4554     do
4555       func_verify_module
4556       if test -n "$module"; then
4557         func_get_dependencies "$module"
4558       fi
4559     done
4560     ;;
4561
4562   extract-autoconf-snippet )
4563     for module
4564     do
4565       func_verify_module
4566       if test -n "$module"; then
4567         func_get_autoconf_snippet "$module"
4568       fi
4569     done
4570     ;;
4571
4572   extract-automake-snippet )
4573     for module
4574     do
4575       func_verify_module
4576       if test -n "$module"; then
4577         func_get_automake_snippet "$module"
4578       fi
4579     done
4580     ;;
4581
4582   extract-include-directive )
4583     for module
4584     do
4585       func_verify_module
4586       if test -n "$module"; then
4587         func_get_include_directive "$module"
4588       fi
4589     done
4590     ;;
4591
4592   extract-link-directive )
4593     for module
4594     do
4595       func_verify_module
4596       if test -n "$module"; then
4597         func_get_link_directive "$module"
4598       fi
4599     done
4600     ;;
4601
4602   extract-license )
4603     for module
4604     do
4605       func_verify_module
4606       if test -n "$module"; then
4607         func_get_license "$module"
4608       fi
4609     done
4610     ;;
4611
4612   extract-maintainer )
4613     for module
4614     do
4615       func_verify_module
4616       if test -n "$module"; then
4617         func_get_maintainer "$module"
4618       fi
4619     done
4620     ;;
4621
4622   extract-tests-module )
4623     for module
4624     do
4625       func_verify_module
4626       if test -n "$module"; then
4627         func_get_tests_module "$module"
4628       fi
4629     done
4630     ;;
4631
4632   * )
4633     func_fatal_error "unknown operation mode --$mode" ;;
4634 esac
4635
4636 rm -rf "$tmp"
4637 # Undo the effect of the previous 'trap' command. Some shellology:
4638 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
4639 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
4640 # exit); for the others we need to call 'exit' explicitly. The value of $? is
4641 # 128 + signal number and is set before the trap-registered command is run.
4642 trap '' 0
4643 trap 'func_exit $?' 1 2 3 13 15
4644
4645 exit 0
4646
4647 # Local Variables:
4648 # indent-tabs-mode: nil
4649 # whitespace-check-buffer-indent: nil
4650 # End: