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