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