Clarify which options are available for --create-testdir.
[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
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   if test "$libtool" = true; then
2789     libext=la
2790     sed_eliminate_LDFLAGS="$sed_noop"
2791   else
2792     libext=a
2793     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
2794   fi
2795   if $for_test; then
2796     # When creating a package for testing: Attempt to provoke failures,
2797     # especially link errors, already during "make" rather than during
2798     # "make check", because "make check" is not possible in a cross-compiling
2799     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
2800     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
2801   else
2802     sed_transform_check_PROGRAMS="$sed_noop"
2803   fi
2804   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
2805   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
2806   echo "## Process this file with automake to produce Makefile.in."
2807   func_emit_copyright_notice
2808   echo
2809   uses_subdirs=
2810   {
2811     for module in $modules; do
2812       if $for_test; then
2813         func_verify_tests_module
2814       else
2815         func_verify_module
2816       fi
2817       if test -n "$module"; then
2818         {
2819           func_get_automake_snippet "$module" |
2820             LC_ALL=C \
2821             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
2822                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
2823                 -e "$sed_eliminate_LDFLAGS" \
2824                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
2825                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
2826                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
2827                 -e "$sed_transform_check_PROGRAMS"
2828           if $use_libtests && test "$module" = 'alloca'; then
2829             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
2830             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
2831           fi
2832         } > "$tmp"/amsnippet
2833         # Skip the contents if it's entirely empty.
2834         if grep '[^      ]' "$tmp"/amsnippet > /dev/null ; then
2835           echo "## begin gnulib module $module"
2836           echo
2837           cat "$tmp"/amsnippet
2838           echo "## end   gnulib module $module"
2839           echo
2840         fi
2841         rm -f "$tmp"/amsnippet
2842         # Test whether there are some source files in subdirectories.
2843         for f in `func_get_filelist "$module"`; do
2844           case $f in
2845             lib/*/*.c | tests/*/*.c)
2846               uses_subdirs=yes
2847               break
2848               ;;
2849           esac
2850         done
2851       fi
2852     done
2853   } > "$tmp"/allsnippets
2854   # Generate dependencies here, since it eases the debugging of test failures.
2855   # If there are source files in subdirectories, prevent collision of the
2856   # object files (example: hash.c and libxml/hash.c).
2857   subdir_options=
2858   if test -n "$uses_subdirs"; then
2859     subdir_options=' subdir-objects'
2860   fi
2861   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
2862   echo
2863   if $for_test; then
2864     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
2865     echo
2866   fi
2867   # Nothing is being added to SUBDIRS; nevertheless the existence of this
2868   # variable is needed to avoid an error from automake:
2869   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
2870   echo "SUBDIRS ="
2871   echo "TESTS ="
2872   echo "XFAIL_TESTS ="
2873   echo "TESTS_ENVIRONMENT ="
2874   echo "noinst_PROGRAMS ="
2875   if ! $for_test; then
2876     echo "check_PROGRAMS ="
2877   fi
2878   echo "noinst_HEADERS ="
2879   echo "noinst_LIBRARIES ="
2880   if $use_libtests; then
2881     if $for_test; then
2882       echo "noinst_LIBRARIES += libtests.a"
2883     else
2884       echo "check_LIBRARIES = libtests.a"
2885     fi
2886   fi
2887   # Automake versions < 1.9b create an empty pkgdatadir at installation time
2888   # if you specify pkgdata_DATA to empty. This is a workaround.
2889   if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
2890     echo "pkgdata_DATA ="
2891   fi
2892   echo "EXTRA_DIST ="
2893   echo "BUILT_SOURCES ="
2894   echo "SUFFIXES ="
2895   echo "MOSTLYCLEANFILES = core *.stackdump"
2896   echo "MOSTLYCLEANDIRS ="
2897   echo "CLEANFILES ="
2898   echo "DISTCLEANFILES ="
2899   echo "MAINTAINERCLEANFILES ="
2900   # Execute edits that apply to the Makefile.am being generated.
2901   edit=0
2902   while test $edit != $makefile_am_edits; do
2903     edit=`expr $edit + 1`
2904     eval dir=\"\$makefile_am_edit${edit}_dir\"
2905     eval var=\"\$makefile_am_edit${edit}_var\"
2906     eval val=\"\$makefile_am_edit${edit}_val\"
2907     if test -n "$var"; then
2908       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
2909         echo "${var} += ${val}"
2910         eval "makefile_am_edit${edit}_var="
2911       fi
2912     fi
2913   done
2914   echo
2915   echo "AM_CPPFLAGS = \\"
2916   echo "  -I. -I\$(srcdir) \\"
2917   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
2918   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
2919   echo
2920   local_ldadd_before=''
2921   local_ldadd_after=''
2922   if $use_libtests; then
2923     # All test programs need to be linked with libtests.a.
2924     # It needs to be passed to the linker before ${libname}.${libext}, since
2925     # the tests-related modules depend on the main modules.
2926     # It also needs to be passed to the linker after ${libname}.${libext}
2927     # because the latter might contain incomplete modules (such as the 'error'
2928     # module whose dependency to 'progname' is voluntarily omitted).
2929     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
2930     # not matter.
2931     local_ldadd_before=' libtests.a'
2932     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
2933   fi
2934   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
2935   echo
2936   if $use_libtests; then
2937     echo "libtests_a_SOURCES ="
2938     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
2939     # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
2940     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
2941     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
2942     echo "EXTRA_libtests_a_SOURCES ="
2943     # The circular dependency in LDADD requires this.
2944     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
2945     echo
2946   fi
2947   # Many test scripts use ${EXEEXT} or ${srcdir}.
2948   # EXEEXT is defined by AC_PROG_CC through autoconf.
2949   # srcdir is defined by autoconf and automake.
2950   echo "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='\$(srcdir)'"
2951   echo
2952   cat "$tmp"/allsnippets \
2953     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
2954   echo "# Clean up after Solaris cc."
2955   echo "clean-local:"
2956   echo "        rm -rf SunWS_cache"
2957   echo
2958   echo "mostlyclean-local: mostlyclean-generic"
2959   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
2960   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
2961   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
2962   echo "          fi; \\"
2963   echo "        done; \\"
2964   echo "        :"
2965   rm -f "$tmp"/allsnippets
2966 }
2967
2968 # func_emit_initmacro_start macro_prefix
2969 # emits the first few statements of the gl_INIT macro to standard output.
2970 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2971 func_emit_initmacro_start ()
2972 {
2973   macro_prefix_arg="$1"
2974   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
2975   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
2976   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
2977   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
2978   # flexibility.)
2979   # Furthermore it avoids an automake error like this when a Makefile.am
2980   # that uses pieces of gnulib also uses $(LIBOBJ):
2981   #   automatically discovered file `error.c' should not be explicitly mentioned
2982   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
2983   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
2984   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
2985   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
2986   #   automatically discovered file `error.c' should not be explicitly mentioned
2987   # We let automake know about the files to be distributed through the
2988   # EXTRA_lib_SOURCES variable.
2989   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
2990   # Create data variables for checking the presence of files that are mentioned
2991   # as AC_LIBSOURCES arguments. These are m4 variables, not shell variables,
2992   # because we want the check to happen when the configure file is created,
2993   # not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the list of
2994   # files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the subdirectory
2995   # in which to expect them.
2996   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_LIST], [])"
2997   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_DIR], [])"
2998   echo "  gl_COMMON"
2999 }
3000
3001 # func_emit_initmacro_end macro_prefix
3002 # emits the last few statements of the gl_INIT macro to standard output.
3003 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3004 func_emit_initmacro_end ()
3005 {
3006   macro_prefix_arg="$1"
3007   # Check the presence of files that are mentioned as AC_LIBSOURCES arguments.
3008   # The check is performed only when autoconf is run from the directory where
3009   # the configure.ac resides; if it is run from a different directory, the
3010   # check is skipped.
3011   echo "  m4_ifval(${macro_prefix_arg}_LIBSOURCES_LIST, ["
3012   echo "    m4_syscmd([test ! -d ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
3013   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
3014   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
3015   echo "          echo \"missing file ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file\" >&2"
3016   echo "          exit 1"
3017   echo "        fi"
3018   echo "      done])dnl"
3019   echo "      m4_if(m4_sysval, [0], [],"
3020   echo "        [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])"
3021   echo "  ])"
3022   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_DIR])"
3023   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_LIST])"
3024   echo "  m4_popdef([AC_LIBSOURCES])"
3025   echo "  m4_popdef([AC_REPLACE_FUNCS])"
3026   echo "  m4_popdef([AC_LIBOBJ])"
3027   echo "  AC_CONFIG_COMMANDS_PRE(["
3028   echo "    ${macro_prefix_arg}_libobjs="
3029   echo "    ${macro_prefix_arg}_ltlibobjs="
3030   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
3031   echo "      # Remove the extension."
3032   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
3033   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed -e \"\$sed_drop_objext\" | sort | uniq\`; do"
3034   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
3035   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
3036   echo "      done"
3037   echo "    fi"
3038   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
3039   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
3040   echo "  ])"
3041 }
3042
3043 # func_emit_initmacro_done macro_prefix sourcebase
3044 # emits a few statements after the gl_INIT macro to standard output.
3045 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3046 # - sourcebase      directory relative to destdir where to place source code
3047 func_emit_initmacro_done ()
3048 {
3049   macro_prefix_arg="$1"
3050   sourcebase_arg="$2"
3051   echo
3052   echo "# Like AC_LIBOBJ, except that the module name goes"
3053   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3054   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
3055   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
3056   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
3057   echo "])"
3058   echo
3059   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
3060   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3061   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
3062   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
3063   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
3064   echo "])"
3065   echo
3066   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
3067   echo "# expected is derived from the gnulib-tool parameterization,"
3068   echo "# and alloca is special cased (for the alloca-opt module)."
3069   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
3070   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
3071   echo "  m4_foreach([_gl_NAME], [\$1], ["
3072   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
3073   echo "      m4_define([${macro_prefix_arg}_LIBSOURCES_DIR], [$sourcebase_arg])"
3074   echo "      m4_append([${macro_prefix_arg}_LIBSOURCES_LIST], _gl_NAME, [ ])"
3075   echo "    ])"
3076   echo "  ])"
3077   echo "])"
3078 }
3079
3080 # func_import modules
3081 # Uses also the variables
3082 # - destdir         target directory
3083 # - local_gnulib_dir  from --local-dir
3084 # - modcache        true or false, from --cache-modules/--no-cache-modules
3085 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
3086 # - libname         library name
3087 # - sourcebase      directory relative to destdir where to place source code
3088 # - m4base          directory relative to destdir where to place *.m4 macros
3089 # - pobase          directory relative to destdir where to place *.po files
3090 # - docbase         directory relative to destdir where to place doc files
3091 # - testsbase       directory relative to destdir where to place unit test code
3092 # - auxdir          directory relative to destdir where to place build aux files
3093 # - inctests        true if --with-tests was given, blank otherwise
3094 # - incobsolete     true if --with-obsolete was given, blank otherwise
3095 # - avoidlist       list of modules to avoid, from --avoid
3096 # - lgpl            yes or a number if library's license shall be LGPL,
3097 #                   blank otherwise
3098 # - makefile_name   from --makefile-name
3099 # - libtool         true if --libtool was given, false if --no-libtool was
3100 #                   given, blank otherwise
3101 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
3102 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3103 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3104 # - vc_files        true if --vc-files was given, false if --no-vc-files was
3105 #                   given, blank otherwise
3106 # - autoconf_minversion  minimum supported autoconf version
3107 # - doit            : if actions shall be executed, false if only to be printed
3108 # - symbolic        true if files should be symlinked, copied otherwise
3109 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
3110 #                   copied otherwise
3111 # - do_copyrights   true if copyright notices in files should be replaced,
3112 #                   blank otherwise
3113 func_import ()
3114 {
3115   # Get the cached settings.
3116   cached_local_gnulib_dir=
3117   cached_specified_modules=
3118   cached_incobsolete=
3119   cached_avoidlist=
3120   cached_sourcebase=
3121   cached_m4base=
3122   cached_pobase=
3123   cached_docbase=
3124   cached_testsbase=
3125   cached_inctests=
3126   cached_libname=
3127   cached_lgpl=
3128   cached_makefile_name=
3129   cached_libtool=
3130   cached_macro_prefix=
3131   cached_po_domain=
3132   cached_vc_files=
3133   cached_files=
3134   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
3135     cached_libtool=false
3136     my_sed_traces='
3137       s,#.*$,,
3138       s,^dnl .*$,,
3139       s, dnl .*$,,
3140       /gl_LOCAL_DIR(/ {
3141         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_dir="\1",p
3142       }
3143       /gl_MODULES(/ {
3144         ta
3145         :a
3146           s/)/)/
3147           tb
3148           N
3149           ba
3150         :b
3151         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
3152       }
3153       /gl_WITH_OBSOLETE/ {
3154         s,^.*$,cached_incobsolete=true,p
3155       }
3156       /gl_AVOID(/ {
3157         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
3158       }
3159       /gl_SOURCE_BASE(/ {
3160         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
3161       }
3162       /gl_M4_BASE(/ {
3163         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
3164       }
3165       /gl_PO_BASE(/ {
3166         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
3167       }
3168       /gl_DOC_BASE(/ {
3169         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
3170       }
3171       /gl_TESTS_BASE(/ {
3172         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
3173       }
3174       /gl_WITH_TESTS/ {
3175         s,^.*$,cached_inctests=true,p
3176       }
3177       /gl_LIB(/ {
3178         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
3179       }
3180       /gl_LGPL(/ {
3181         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
3182       }
3183       /gl_LGPL/ {
3184         s,^.*$,cached_lgpl=yes,p
3185       }
3186       /gl_MAKEFILE_NAME(/ {
3187         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
3188       }
3189       /gl_LIBTOOL/ {
3190         s,^.*$,cached_libtool=true,p
3191       }
3192       /gl_MACRO_PREFIX(/ {
3193         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
3194       }
3195       /gl_PO_DOMAIN(/ {
3196         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
3197       }
3198       /gl_VC_FILES(/ {
3199         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
3200       }'
3201     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
3202     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3203       my_sed_traces='
3204         s,#.*$,,
3205         s,^dnl .*$,,
3206         s, dnl .*$,,
3207         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
3208           s,^.*$,cached_files=",p
3209           n
3210           ta
3211           :a
3212           s,^\]).*$,",
3213           tb
3214           s,["$`\\],,g
3215           p
3216           n
3217           ba
3218           :b
3219           p
3220         }'
3221       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
3222     fi
3223   fi
3224
3225   # Merge the cached settings with the specified ones.
3226   # The m4base must be the same as expected from the pathname.
3227   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
3228     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
3229   fi
3230   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
3231   # is relative to $destdir, whereas the one we use is relative to . or absolute.
3232   if test -z "$local_gnulib_dir"; then
3233     if test -n "$cached_local_gnulib_dir"; then
3234       case "$destdir" in
3235         /*)
3236           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
3237         *)
3238           case "$cached_local_gnulib_dir" in
3239             /*)
3240               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
3241             *)
3242               func_relconcat "$destdir" "$cached_local_gnulib_dir"
3243               local_gnulib_dir="$relconcat" ;;
3244           esac ;;
3245       esac
3246     fi
3247   fi
3248   # Append the cached and the specified module names. So that
3249   # "gnulib-tool --import foo" means to add the module foo.
3250   specified_modules="$cached_specified_modules $1"
3251   # Included obsolete modules among the dependencies if specified either way.
3252   if test -z "$incobsolete"; then
3253     incobsolete="$cached_incobsolete"
3254   fi
3255   # Append the cached and the specified avoidlist. This is probably better
3256   # than dropping the cached one when --avoid is specified at least once.
3257   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
3258   avoidlist=`echo $avoidlist`
3259
3260   # The sourcebase defaults to the cached one.
3261   if test -z "$sourcebase"; then
3262     sourcebase="$cached_sourcebase"
3263     if test -z "$sourcebase"; then
3264       func_fatal_error "missing --source-base option"
3265     fi
3266   fi
3267   # The pobase defaults to the cached one.
3268   if test -z "$pobase"; then
3269     pobase="$cached_pobase"
3270   fi
3271   # The docbase defaults to the cached one.
3272   if test -z "$docbase"; then
3273     docbase="$cached_docbase"
3274     if test -z "$docbase"; then
3275       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."
3276     fi
3277   fi
3278   # The testsbase defaults to the cached one.
3279   if test -z "$testsbase"; then
3280     testsbase="$cached_testsbase"
3281     if test -z "$testsbase"; then
3282       func_fatal_error "missing --tests-base option"
3283     fi
3284   fi
3285   # Require the tests if specified either way.
3286   if test -z "$inctests"; then
3287     inctests="$cached_inctests"
3288   fi
3289   # The libname defaults to the cached one.
3290   if test -z "$supplied_libname"; then
3291     libname="$cached_libname"
3292     if test -z "$libname"; then
3293       func_fatal_error "missing --lib option"
3294     fi
3295   fi
3296   # Require LGPL if specified either way.
3297   if test -z "$lgpl"; then
3298     lgpl="$cached_lgpl"
3299   fi
3300   # The makefile_name defaults to the cached one.
3301   if test -z "$makefile_name"; then
3302     makefile_name="$cached_makefile_name"
3303   fi
3304   # Use libtool if specified either way, or if guessed.
3305   if test -z "$libtool"; then
3306     if test -n "$cached_m4base"; then
3307       libtool="$cached_libtool"
3308     else
3309       libtool="$guessed_libtool"
3310     fi
3311   fi
3312   # The macro_prefix defaults to the cached one.
3313   if test -z "$macro_prefix"; then
3314     macro_prefix="$cached_macro_prefix"
3315     if test -z "$macro_prefix"; then
3316       func_fatal_error "missing --macro-prefix option"
3317     fi
3318   fi
3319   # The po_domain defaults to the cached one.
3320   if test -z "$po_domain"; then
3321     po_domain="$cached_po_domain"
3322   fi
3323   # The vc_files defaults to the cached one.
3324   if test -z "$vc_files"; then
3325     vc_files="$cached_vc_files"
3326   fi
3327
3328   # Canonicalize the list of specified modules.
3329   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
3330
3331   # Determine final module list.
3332   modules="$specified_modules"
3333   func_modules_transitive_closure
3334   if test $verbose -ge 0; then
3335     echo "Module list with included dependencies:"
3336     echo "$modules" | sed -e 's/^/  /'
3337   fi
3338   final_modules="$modules"
3339
3340   # Determine main module list and tests-related module list separately.
3341   # The main module list is the transitive closure of the specified modules,
3342   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
3343   # is specified, it will consist only of LGPLed source.
3344   # The tests-related module list is the transitive closure of the specified
3345   # modules, including tests modules, minus the main module list excluding
3346   # modules of applicability 'all'. Its lib/* sources (brought in through
3347   # dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
3348   # source, even if --lgpl is specified.
3349   # Determine main module list.
3350   saved_inctests="$inctests"
3351   inctests=""
3352   modules="$specified_modules"
3353   func_modules_transitive_closure
3354   main_modules="$modules"
3355   inctests="$saved_inctests"
3356   if test $verbose -ge 1; then
3357     echo "Main module list:"
3358     echo "$main_modules" | sed -e 's/^/  /'
3359   fi
3360   # Determine tests-related module list.
3361   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
3362   testsrelated_modules=`for module in $main_modules; do
3363                           if test \`func_get_applicability $module\` = main; then
3364                             echo $module
3365                           fi
3366                         done \
3367                         | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
3368   if test $verbose -ge 1; then
3369     echo "Tests-related module list:"
3370     echo "$testsrelated_modules" | sed -e 's/^/  /'
3371   fi
3372
3373   # Add the dummy module to the main module list if needed.
3374   modules="$main_modules"
3375   func_modules_add_dummy
3376   main_modules="$modules"
3377
3378   # Determine whether a $testsbase/libtests.a is needed.
3379   use_libtests=false
3380   for module in $testsrelated_modules; do
3381     func_verify_nontests_module
3382     if test -n "$module"; then
3383       all_files=`func_get_filelist $module`
3384       # Test whether some file in $all_files lies in lib/.
3385       for f in $all_files; do
3386         case $f in
3387           lib/*)
3388             use_libtests=true
3389             break 2
3390             ;;
3391         esac
3392       done
3393     fi
3394   done
3395
3396   # Add the dummy module to the tests-related module list if needed.
3397   if $use_libtests; then
3398     modules="$testsrelated_modules"
3399     func_modules_add_dummy
3400     testsrelated_modules="$modules"
3401   fi
3402
3403   # If --lgpl, verify that the licenses of modules are compatible.
3404   if test -n "$lgpl"; then
3405     license_incompatibilities=
3406     for module in $main_modules; do
3407       license=`func_get_license $module`
3408       case $license in
3409         'GPLed build tool') ;;
3410         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3411         *)
3412           case "$lgpl" in
3413             yes | 3)
3414               case $license in
3415                 LGPL | LGPLv2+ | LGPLv3+) ;;
3416                 *) func_append license_incompatibilities "$module $license$nl" ;;
3417               esac
3418               ;;
3419             2)
3420               case $license in
3421                 LGPLv2+) ;;
3422                 *) func_append license_incompatibilities "$module $license$nl" ;;
3423               esac
3424               ;;
3425             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
3426           esac
3427           ;;
3428       esac
3429     done
3430     if test -n "$license_incompatibilities"; then
3431       # Format the license incompatibilities as a table.
3432       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
3433 s,^\(.................................................[^ ]*\) *,                 \1 ,'
3434       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
3435       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
3436     fi
3437   fi
3438
3439   # Show banner notice of every module.
3440   modules="$main_modules"
3441   func_modules_notice
3442
3443   # Determine script to apply to imported library files.
3444   sed_transform_lib_file=
3445   for module in $main_modules; do
3446     if test $module = config-h; then
3447       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
3448       sed_transform_lib_file=$sed_transform_lib_file'
3449         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
3450       '
3451       break
3452     fi
3453   done
3454   sed_transform_main_lib_file="$sed_transform_lib_file"
3455   if test -n "$do_copyrights"; then
3456     if test -n "$lgpl"; then
3457       # Update license.
3458       case "$lgpl" in
3459         yes | 3)
3460           sed_transform_main_lib_file=$sed_transform_main_lib_file'
3461             s/GNU General/GNU Lesser General/g
3462           '
3463           ;;
3464         2)
3465           sed_transform_main_lib_file=$sed_transform_main_lib_file'
3466             s/GNU General/GNU Lesser General/g
3467             s/version [23]\([ ,]\)/version 2.1\1/g
3468           '
3469           ;;
3470         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
3471       esac
3472     else
3473       # Update license.
3474       sed_transform_main_lib_file=$sed_transform_main_lib_file'
3475         s/GNU Lesser General/GNU General/g
3476         s/GNU Library General/GNU General/g
3477         s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3478       '
3479     fi
3480   fi
3481
3482   # Determine script to apply to auxiliary files that go into $auxdir/.
3483   sed_transform_build_aux_file=
3484   if test -n "$do_copyrights"; then
3485     # Update license.
3486     sed_transform_build_aux_file=$sed_transform_build_aux_file'
3487       s/GNU Lesser General/GNU General/g
3488       s/GNU Library General/GNU General/g
3489       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3490     '
3491   fi
3492
3493   # Determine script to apply to library files that go into $testsbase/.
3494   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
3495   if test -n "$do_copyrights"; then
3496     # Update license.
3497     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
3498       s/GNU Lesser General/GNU General/g
3499       s/GNU Library General/GNU General/g
3500       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3501     '
3502   fi
3503
3504   # Determine the final file lists.
3505   # They must be computed separately, because files in lib/* go into
3506   # $sourcebase/ if they are in the main file list but into $testsbase/
3507   # if they are in the tests-related file list. Furthermore lib/dummy.c
3508   # can be in both.
3509   # Determine final main file list.
3510   modules="$main_modules"
3511   func_modules_to_filelist
3512   main_files="$files"
3513   # Determine final tests-related file list.
3514   modules="$testsrelated_modules"
3515   func_modules_to_filelist
3516   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
3517   # Merge both file lists.
3518   sed_remove_empty_lines='/^$/d'
3519   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
3520   if test $verbose -ge 0; then
3521     echo "File list:"
3522     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
3523     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
3524   fi
3525
3526   test -n "$files" \
3527     || func_fatal_error "refusing to do nothing"
3528
3529   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
3530   new_files="$files m4/gnulib-tool.m4"
3531   old_files="$cached_files"
3532   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
3533     func_append old_files " m4/gnulib-tool.m4"
3534   fi
3535
3536   rewritten='%REWRITTEN%'
3537   sed_rewrite_old_files="\
3538     s,^build-aux/,$rewritten$auxdir/,
3539     s,^doc/,$rewritten$cached_docbase/,
3540     s,^lib/,$rewritten$cached_sourcebase/,
3541     s,^m4/,$rewritten$cached_m4base/,
3542     s,^tests/,$rewritten$cached_testsbase/,
3543     s,^tests=lib/,$rewritten$cached_testsbase/,
3544     s,^top/,$rewritten,
3545     s,^$rewritten,,"
3546   sed_rewrite_new_files="\
3547     s,^build-aux/,$rewritten$auxdir/,
3548     s,^doc/,$rewritten$docbase/,
3549     s,^lib/,$rewritten$sourcebase/,
3550     s,^m4/,$rewritten$m4base/,
3551     s,^tests/,$rewritten$testsbase/,
3552     s,^tests=lib/,$rewritten$testsbase/,
3553     s,^top/,$rewritten,
3554     s,^$rewritten,,"
3555
3556   # Create directories.
3557   { echo "$sourcebase"
3558     echo "$m4base"
3559     if test -n "$pobase"; then
3560       echo "$pobase"
3561     fi
3562     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
3563     if test -n "$docfiles"; then
3564       echo "$docbase"
3565     fi
3566     if test -n "$inctests"; then
3567       echo "$testsbase"
3568     fi
3569     echo "$auxdir"
3570     for f in $files; do echo $f; done \
3571       | sed -e "$sed_rewrite_new_files" \
3572       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3573       | LC_ALL=C sort -u
3574   } > "$tmp"/dirs
3575   { # Rearrange file descriptors. Needed because "while ... done < ..."
3576     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3577     exec 5<&0 < "$tmp"/dirs
3578     while read d; do
3579       if test ! -d "$destdir/$d"; then
3580         if $doit; then
3581           echo "Creating directory $destdir/$d"
3582           mkdir -p "$destdir/$d" || func_fatal_error "failed"
3583         else
3584           echo "Create directory $destdir/$d"
3585         fi
3586       fi
3587     done
3588     exec 0<&5 5<&-
3589   }
3590
3591   # Copy files or make symbolic links. Remove obsolete files.
3592   added_files=''
3593   removed_files=''
3594   delimiter='   '
3595   # Construct a table with 2 columns: rewritten-file-name original-file-name,
3596   # representing the files according to the last gnulib-tool invocation.
3597   for f in $old_files; do echo $f; done \
3598     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
3599     | LC_ALL=C sort \
3600     > "$tmp"/old-files
3601   # Construct a table with 2 columns: rewritten-file-name original-file-name,
3602   # representing the files after this gnulib-tool invocation.
3603   for f in $new_files; do echo $f; done \
3604     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
3605     | LC_ALL=C sort \
3606     > "$tmp"/new-files
3607   # First the files that are in old-files, but not in new-files:
3608   sed_take_first_column='s,'"$delimiter"'.*,,'
3609   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
3610     # Remove the file. Do nothing if the user already removed it.
3611     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
3612       if $doit; then
3613         echo "Removing file $g (backup in ${g}~)"
3614         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
3615       else
3616         echo "Remove file $g (backup in ${g}~)"
3617       fi
3618       func_append removed_files "$g$nl"
3619     fi
3620   done
3621   # func_add_or_update handles a file that ought to be present afterwards.
3622   # Uses parameters
3623   # - f             the original file name
3624   # - g             the rewritten file name
3625   # - already_present  nonempty if the file should already exist, empty
3626   #                    otherwise
3627   func_add_or_update ()
3628   {
3629     of="$f"
3630     case "$f" in
3631       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
3632     esac
3633     func_dest_tmpfilename "$g"
3634     func_lookup_file "$f"
3635     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
3636     if test -n "$sed_transform_main_lib_file"; then
3637       case "$of" in
3638         lib/*)
3639           sed -e "$sed_transform_main_lib_file" \
3640             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
3641           ;;
3642       esac
3643     fi
3644     if test -n "$sed_transform_build_aux_file"; then
3645       case "$of" in
3646         build-aux/*)
3647           sed -e "$sed_transform_build_aux_file" \
3648             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
3649           ;;
3650       esac
3651     fi
3652     if test -n "$sed_transform_testsrelated_lib_file"; then
3653       case "$of" in
3654         tests=lib/*)
3655           sed -e "$sed_transform_testsrelated_lib_file" \
3656             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
3657           ;;
3658       esac
3659     fi
3660     if test -f "$destdir/$g"; then
3661       # The file already exists.
3662       func_update_file
3663     else
3664       # Install the file.
3665       # Don't protest if the file should be there but isn't: it happens
3666       # frequently that developers don't put autogenerated files into CVS.
3667       func_add_file
3668       func_append added_files "$g$nl"
3669     fi
3670     rm -f "$tmpfile"
3671   }
3672   # Then the files that are in new-files, but not in old-files:
3673   sed_take_last_column='s,^.*'"$delimiter"',,'
3674   already_present=
3675   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
3676     | sed -e "$sed_take_last_column" \
3677     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
3678   { # Rearrange file descriptors. Needed because "while ... done < ..."
3679     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3680     exec 5<&0 < "$tmp"/added-files
3681     while read g f; do
3682       func_add_or_update
3683     done
3684     exec 0<&5 5<&-
3685   }
3686   # Then the files that are in new-files and in old-files:
3687   already_present=true
3688   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
3689     | sed -e "$sed_take_last_column" \
3690     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
3691   { # Rearrange file descriptors. Needed because "while ... done < ..."
3692     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3693     exec 5<&0 < "$tmp"/kept-files
3694     while read g f; do
3695       func_add_or_update
3696     done
3697     exec 0<&5 5<&-
3698   }
3699
3700   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
3701   actioncmd="gnulib-tool --import"
3702   func_append actioncmd " --dir=$destdir"
3703   if test -n "$local_gnulib_dir"; then
3704     func_append actioncmd " --local-dir=$local_gnulib_dir"
3705   fi
3706   func_append actioncmd " --lib=$libname"
3707   func_append actioncmd " --source-base=$sourcebase"
3708   func_append actioncmd " --m4-base=$m4base"
3709   if test -n "$pobase"; then
3710     func_append actioncmd " --po-base=$pobase"
3711   fi
3712   func_append actioncmd " --doc-base=$docbase"
3713   func_append actioncmd " --tests-base=$testsbase"
3714   func_append actioncmd " --aux-dir=$auxdir"
3715   if test -n "$inctests"; then
3716     func_append actioncmd " --with-tests"
3717   fi
3718   if test -n "$incobsolete"; then
3719     func_append actioncmd " --with-obsolete"
3720   fi
3721   for module in $avoidlist; do
3722     func_append actioncmd " --avoid=$module"
3723   done
3724   if test -n "$lgpl"; then
3725     if test "$lgpl" = yes; then
3726       func_append actioncmd " --lgpl"
3727     else
3728       func_append actioncmd " --lgpl=$lgpl"
3729     fi
3730   fi
3731   if test -n "$makefile_name"; then
3732     func_append actioncmd " --makefile-name=$makefile_name"
3733   fi
3734   if test "$libtool" = true; then
3735     func_append actioncmd " --libtool"
3736   else
3737     func_append actioncmd " --no-libtool"
3738   fi
3739   func_append actioncmd " --macro-prefix=$macro_prefix"
3740   if test -n "$po_domain"; then
3741     func_append actioncmd " --po-domain=$po_domain"
3742   fi
3743   if test -n "$vc_files"; then
3744     if test "$vc_files" = true; then
3745       func_append actioncmd " --vc-files"
3746     else
3747       func_append actioncmd " --no-vc-files"
3748     fi
3749   fi
3750   func_append actioncmd " `echo $specified_modules`"
3751
3752   # Default the makefile name to Makefile.am.
3753   if test -n "$makefile_name"; then
3754     makefile_am=$makefile_name
3755   else
3756     makefile_am=Makefile.am
3757   fi
3758
3759   # Create normal Makefile.ams.
3760   for_test=false
3761
3762   # Setup list of Makefile.am edits that are to be performed afterwards.
3763   # Some of these edits apply to files that we will generate; others are
3764   # under the responsibility of the developer.
3765   makefile_am_edits=0
3766   # func_note_Makefile_am_edit dir var value
3767   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
3768   # ${value}.
3769   func_note_Makefile_am_edit ()
3770   {
3771     makefile_am_edits=`expr $makefile_am_edits + 1`
3772     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
3773     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
3774     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
3775   }
3776   if test "$makefile_am" = Makefile.am; then
3777     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
3778     sourcebase_base=`basename "$sourcebase"`
3779     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
3780   fi
3781   if test -n "$pobase"; then
3782     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
3783     pobase_base=`basename "$pobase"`
3784     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
3785   fi
3786   if test -n "$inctests"; then
3787     if test "$makefile_am" = Makefile.am; then
3788       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
3789       testsbase_base=`basename "$testsbase"`
3790       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
3791     fi
3792   fi
3793   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
3794   {
3795     # Find the first parent directory of $m4base that contains or will contain
3796     # a Makefile.am.
3797     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
3798 s,//*$,/,'
3799     sed_butlast='s,[^/][^/]*//*$,,'
3800     dir1="${m4base}/"; dir2=""
3801     while test -n "$dir1" \
3802           && ! { test -f "${destdir}/${dir1}Makefile.am" \
3803                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
3804                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
3805                  || { test -n "$inctests" \
3806                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
3807                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
3808       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
3809       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
3810     done
3811     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
3812   }
3813
3814   # Create library makefile.
3815   func_dest_tmpfilename $sourcebase/$makefile_am
3816   destfile="$sourcebase/$makefile_am"
3817   modules="$main_modules"
3818   func_emit_lib_Makefile_am > "$tmpfile"
3819   if test -f "$destdir"/$sourcebase/$makefile_am; then
3820     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
3821       rm -f "$tmpfile"
3822     else
3823       if $doit; then
3824         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
3825         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
3826         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
3827       else
3828         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
3829         rm -f "$tmpfile"
3830       fi
3831     fi
3832   else
3833     if $doit; then
3834       echo "Creating $sourcebase/$makefile_am"
3835       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
3836     else
3837       echo "Create $sourcebase/$makefile_am"
3838       rm -f "$tmpfile"
3839     fi
3840     func_append added_files "$sourcebase/$makefile_am$nl"
3841   fi
3842
3843   # Create po/ directory.
3844   if test -n "$pobase"; then
3845     # Create po makefile and auxiliary files.
3846     for file in Makefile.in.in remove-potcdate.sin; do
3847       func_dest_tmpfilename $pobase/$file
3848       func_lookup_file build-aux/po/$file
3849       cat "$lookedup_file" > "$tmpfile"
3850       if test -f "$destdir"/$pobase/$file; then
3851         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
3852           rm -f "$tmpfile"
3853         else
3854           if $doit; then
3855             echo "Updating $pobase/$file (backup in $pobase/$file~)"
3856             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
3857             mv -f "$tmpfile" "$destdir"/$pobase/$file
3858           else
3859             echo "Update $pobase/$file (backup in $pobase/$file~)"
3860             rm -f "$tmpfile"
3861           fi
3862         fi
3863       else
3864         if $doit; then
3865           echo "Creating $pobase/$file"
3866           mv -f "$tmpfile" "$destdir"/$pobase/$file
3867         else
3868           echo "Create $pobase/$file"
3869           rm -f "$tmpfile"
3870         fi
3871         func_append added_files "$pobase/$file$nl"
3872       fi
3873     done
3874     # Create po makefile parameterization, part 1.
3875     func_dest_tmpfilename $pobase/Makevars
3876     func_emit_po_Makevars > "$tmpfile"
3877     if test -f "$destdir"/$pobase/Makevars; then
3878       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
3879         rm -f "$tmpfile"
3880       else
3881         if $doit; then
3882           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
3883           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
3884           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
3885         else
3886           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
3887           rm -f "$tmpfile"
3888         fi
3889       fi
3890     else
3891       if $doit; then
3892         echo "Creating $pobase/Makevars"
3893         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
3894       else
3895         echo "Create $pobase/Makevars"
3896         rm -f "$tmpfile"
3897       fi
3898       func_append added_files "$pobase/Makevars$nl"
3899     fi
3900     # Create po makefile parameterization, part 2.
3901     func_dest_tmpfilename $pobase/POTFILES.in
3902     func_emit_po_POTFILES_in > "$tmpfile"
3903     if test -f "$destdir"/$pobase/POTFILES.in; then
3904       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
3905         rm -f "$tmpfile"
3906       else
3907         if $doit; then
3908           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
3909           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
3910           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
3911         else
3912           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
3913           rm -f "$tmpfile"
3914         fi
3915       fi
3916     else
3917       if $doit; then
3918         echo "Creating $pobase/POTFILES.in"
3919         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
3920       else
3921         echo "Create $pobase/POTFILES.in"
3922         rm -f "$tmpfile"
3923       fi
3924       func_append added_files "$pobase/POTFILES.in$nl"
3925     fi
3926     # Fetch PO files.
3927     TP_URL="http://translationproject.org/latest/"
3928     TP_RSYNC_URI="translationproject.org::tp/latest/"
3929     if $doit; then
3930       echo "Fetching gnulib PO files from $TP_URL"
3931       (cd "$destdir"/$pobase \
3932        && { # Prefer rsync over wget if it is available, since it consumes
3933             # less network bandwidth, due to compression.
3934             if type rsync 2>/dev/null | grep / > /dev/null; then
3935               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
3936             else
3937               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
3938             fi
3939           }
3940       )
3941     else
3942       echo "Fetch gnulib PO files from $TP_URL"
3943     fi
3944     # Create po/LINGUAS.
3945     if $doit; then
3946       func_dest_tmpfilename $pobase/LINGUAS
3947       (cd "$destdir"/$pobase \
3948        && { echo '# Set of available languages.'
3949             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
3950           }
3951       ) > "$tmpfile"
3952       if test -f "$destdir"/$pobase/LINGUAS; then
3953         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
3954           rm -f "$tmpfile"
3955         else
3956           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
3957           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
3958           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
3959         fi
3960       else
3961         echo "Creating $pobase/LINGUAS"
3962         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
3963         func_append added_files "$pobase/LINGUAS$nl"
3964       fi
3965     else
3966       if test -f "$destdir"/$pobase/LINGUAS; then
3967         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
3968       else
3969         echo "Create $pobase/LINGUAS"
3970       fi
3971     fi
3972   fi
3973
3974   # Create m4/gnulib-cache.m4.
3975   func_dest_tmpfilename $m4base/gnulib-cache.m4
3976   (
3977     func_emit_copyright_notice
3978     echo "#"
3979     echo "# This file represents the specification of how gnulib-tool is used."
3980     echo "# It acts as a cache: It is written and read by gnulib-tool."
3981     echo "# In projects using CVS, this file is meant to be stored in CVS,"
3982     echo "# like the configure.ac and various Makefile.am files."
3983     echo
3984     echo
3985     echo "# Specification in the form of a command-line invocation:"
3986     echo "#   $actioncmd"
3987     echo
3988     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
3989     # Store the local_gnulib_dir relative to destdir.
3990     case "$local_gnulib_dir" in
3991       "" | /*)
3992         relative_local_gnulib_dir="$local_gnulib_dir" ;;
3993       * )
3994         case "$destdir" in
3995           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
3996           *)
3997             # destdir, local_gnulib_dir are both relative.
3998             func_relativize "$destdir" "$local_gnulib_dir"
3999             relative_local_gnulib_dir="$reldir" ;;
4000         esac ;;
4001     esac
4002     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
4003     echo "gl_MODULES(["
4004     echo "$specified_modules" | sed -e 's/^/  /g'
4005     echo "])"
4006     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
4007     echo "gl_AVOID([$avoidlist])"
4008     echo "gl_SOURCE_BASE([$sourcebase])"
4009     echo "gl_M4_BASE([$m4base])"
4010     echo "gl_PO_BASE([$pobase])"
4011     echo "gl_DOC_BASE([$docbase])"
4012     echo "gl_TESTS_BASE([$testsbase])"
4013     test -z "$inctests" || echo "gl_WITH_TESTS"
4014     echo "gl_LIB([$libname])"
4015     if test -n "$lgpl"; then
4016       if test "$lgpl" = yes; then
4017         echo "gl_LGPL"
4018       else
4019         echo "gl_LGPL([$lgpl])"
4020       fi
4021     fi
4022     echo "gl_MAKEFILE_NAME([$makefile_name])"
4023     if test "$libtool" = true; then
4024       echo "gl_LIBTOOL"
4025     fi
4026     echo "gl_MACRO_PREFIX([$macro_prefix])"
4027     echo "gl_PO_DOMAIN([$po_domain])"
4028     if test -n "$vc_files"; then
4029       echo "gl_VC_FILES([$vc_files])"
4030     fi
4031   ) > "$tmpfile"
4032   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
4033     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
4034       rm -f "$tmpfile"
4035     else
4036       if $doit; then
4037         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
4038         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
4039         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
4040       else
4041         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
4042         if false; then
4043           cat "$tmpfile"
4044           echo
4045           echo "# gnulib-cache.m4 ends here"
4046         fi
4047         rm -f "$tmpfile"
4048       fi
4049     fi
4050   else
4051     if $doit; then
4052       echo "Creating $m4base/gnulib-cache.m4"
4053       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
4054     else
4055       echo "Create $m4base/gnulib-cache.m4"
4056       cat "$tmpfile"
4057       rm -f "$tmpfile"
4058     fi
4059   fi
4060
4061   # Create m4/gnulib-comp.m4.
4062   func_dest_tmpfilename $m4base/gnulib-comp.m4
4063   (
4064     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
4065     func_emit_copyright_notice
4066     echo "#"
4067     echo "# This file represents the compiled summary of the specification in"
4068     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
4069     echo "# to be invoked from configure.ac."
4070     echo "# In projects using CVS, this file can be treated like other built files."
4071     echo
4072     echo
4073     echo "# This macro should be invoked from $configure_ac, in the section"
4074     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
4075     echo "# any checks for libraries, header files, types and library functions."
4076     echo "AC_DEFUN([${macro_prefix}_EARLY],"
4077     echo "["
4078     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
4079     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
4080     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
4081     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
4082     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
4083     if test -n "$uses_subdirs"; then
4084       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
4085     fi
4086     for module in $final_modules; do
4087       func_verify_module
4088       if test -n "$module"; then
4089         echo "# Code from module $module:"
4090         func_get_autoconf_early_snippet "$module"
4091       fi
4092     done \
4093       | sed -e '/^$/d;' -e 's/^/  /'
4094     echo "])"
4095     echo
4096     echo "# This macro should be invoked from $configure_ac, in the section"
4097     echo "# \"Check for header files, types and library functions\"."
4098     echo "AC_DEFUN([${macro_prefix}_INIT],"
4099     echo "["
4100     if test "$libtool" = true; then
4101       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
4102       echo "  gl_cond_libtool=true"
4103     else
4104       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
4105       echo "  gl_cond_libtool=false"
4106       echo "  gl_libdeps="
4107       echo "  gl_ltlibdeps="
4108     fi
4109     if test "$auxdir" != "build-aux"; then
4110       sed_replace_build_aux='
4111         :a
4112         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
4113           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
4114           ba
4115         }'
4116     else
4117       sed_replace_build_aux="$sed_noop"
4118     fi
4119     func_emit_initmacro_start $macro_prefix
4120     echo "  gl_source_base='$sourcebase'"
4121     for module in $main_modules; do
4122       func_verify_module
4123       if test -n "$module"; then
4124         echo "  # Code from module $module:"
4125         func_get_autoconf_snippet "$module" \
4126           | sed -e '/^$/d;' -e 's/^/  /' \
4127                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
4128                 -e "$sed_replace_build_aux"
4129         if test "$module" = 'alloca' && test "$libtool" = true; then
4130           echo 'changequote(,)dnl'
4131           echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
4132           echo 'changequote([, ])dnl'
4133           echo 'AC_SUBST([LTALLOCA])'
4134         fi
4135       fi
4136     done
4137     echo "  # End of code from modules"
4138     func_emit_initmacro_end $macro_prefix
4139     echo "  gltests_libdeps="
4140     echo "  gltests_ltlibdeps="
4141     func_emit_initmacro_start ${macro_prefix}tests
4142     echo "  gl_source_base='$testsbase'"
4143     for module in $testsrelated_modules; do
4144       func_verify_module
4145       if test -n "$module"; then
4146         func_get_autoconf_snippet "$module" \
4147           | sed -e '/^$/d;' -e 's/^/  /' \
4148                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
4149                 -e "$sed_replace_build_aux" \
4150                 -e 's/\$gl_cond_libtool/false/g' \
4151                 -e 's/gl_libdeps/gltests_libdeps/g' \
4152                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
4153       fi
4154     done
4155     func_emit_initmacro_end ${macro_prefix}tests
4156     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
4157     # created using libtool, because libtool already handles the dependencies.
4158     if test "$libtool" != true; then
4159       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
4160       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
4161       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
4162       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
4163       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
4164     fi
4165     if $use_libtests; then
4166       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
4167       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
4168     fi
4169     echo "])"
4170     func_emit_initmacro_done $macro_prefix $sourcebase
4171     func_emit_initmacro_done ${macro_prefix}tests $testsbase
4172     echo
4173     echo "# This macro records the list of files which have been installed by"
4174     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
4175     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
4176     echo "$files" | sed -e 's,^,  ,'
4177     echo "])"
4178   ) > "$tmpfile"
4179   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
4180     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
4181       rm -f "$tmpfile"
4182     else
4183       if $doit; then
4184         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
4185         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
4186         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
4187       else
4188         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
4189         if false; then
4190           cat "$tmpfile"
4191           echo
4192           echo "# gnulib-comp.m4 ends here"
4193         fi
4194         rm -f "$tmpfile"
4195       fi
4196     fi
4197   else
4198     if $doit; then
4199       echo "Creating $m4base/gnulib-comp.m4"
4200       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
4201     else
4202       echo "Create $m4base/gnulib-comp.m4"
4203       cat "$tmpfile"
4204       rm -f "$tmpfile"
4205     fi
4206   fi
4207
4208   if test -n "$inctests"; then
4209     # Create tests makefile.
4210     func_dest_tmpfilename $testsbase/$makefile_am
4211     destfile="$testsbase/$makefile_am"
4212     modules="$testsrelated_modules"
4213     func_emit_tests_Makefile_am > "$tmpfile"
4214     if test -f "$destdir"/$testsbase/$makefile_am; then
4215       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
4216         rm -f "$tmpfile"
4217       else
4218         if $doit; then
4219           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
4220           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
4221           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
4222         else
4223           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
4224           rm -f "$tmpfile"
4225         fi
4226       fi
4227     else
4228       if $doit; then
4229         echo "Creating $testsbase/$makefile_am"
4230         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
4231       else
4232         echo "Create $testsbase/$makefile_am"
4233         rm -f "$tmpfile"
4234       fi
4235     func_append added_files "$testsbase/$makefile_am$nl"
4236     fi
4237   fi
4238
4239   if test "$vc_files" != false; then
4240     # Update the .cvsignore and .gitignore files.
4241     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
4242       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
4243       # Treat gnulib-comp.m4 like an added file, even if it already existed.
4244       echo "$m4base/|A|gnulib-comp.m4"
4245     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
4246     { # Rearrange file descriptors. Needed because "while ... done < ..."
4247       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4248       exec 5<&0 < "$tmp"/fileset-changes
4249       func_update_ignorelist ()
4250       {
4251         ignore="$1"
4252         if test "$ignore" = .gitignore; then
4253           # In a .gitignore file, "foo" applies to the current directory and all
4254           # subdirectories, whereas "/foo" applies to the current directory only.
4255           anchor='/'
4256           escaped_anchor='\/'
4257           doubly_escaped_anchor='\\/'
4258         else
4259           anchor=''
4260           escaped_anchor=''
4261           doubly_escaped_anchor=''
4262         fi
4263         if test -f "$destdir/$dir$ignore"; then
4264           if test -n "$dir_added" || test -n "$dir_removed"; then
4265             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
4266             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
4267                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
4268              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
4269                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-removed
4270             )
4271             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
4272               if $doit; then
4273                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
4274                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
4275                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
4276                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,$/d,' < "$tmp"/ignore-removed; fi
4277                 } > "$tmp"/sed-ignore-removed
4278                 { cat "$destdir/$dir$ignore"~
4279                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
4280                 } | sed -f "$tmp"/sed-ignore-removed \
4281                   > "$destdir/$dir$ignore"
4282               else
4283                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
4284               fi
4285             fi
4286           fi
4287         else
4288           if test -n "$dir_added"; then
4289             if $doit; then
4290               echo "Creating $destdir/$dir$ignore"
4291               {
4292                 if test "$ignore" = .cvsignore; then
4293                   echo ".deps"
4294                   # Automake generates Makefile rules that create .dirstamp files.
4295                   echo ".dirstamp"
4296                 fi
4297                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
4298               } > "$destdir/$dir$ignore"
4299             else
4300               echo "Create $destdir/$dir$ignore"
4301             fi
4302           fi
4303         fi
4304       }
4305       func_done_dir ()
4306       {
4307         dir="$1"
4308         dir_added="$2"
4309         dir_removed="$3"
4310         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
4311           func_update_ignorelist .cvsignore
4312         fi
4313         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
4314           func_update_ignorelist .gitignore
4315         fi
4316       }
4317       last_dir=
4318       last_dir_added=
4319       last_dir_removed=
4320       while read line; do
4321         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
4322         next_dir=`echo "$line" | sed -e 's,|.*,,'`
4323         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
4324         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
4325         if test "$next_dir" != "$last_dir"; then
4326           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
4327           last_dir="$next_dir"
4328           last_dir_added=
4329           last_dir_removed=
4330         fi
4331         case $op in
4332           A) func_append last_dir_added "$file$nl";;
4333           R) func_append last_dir_removed "$file$nl";;
4334         esac
4335       done
4336       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
4337       exec 0<&5 5<&-
4338     }
4339   fi
4340
4341   echo "Finished."
4342   echo
4343   echo "You may need to add #include directives for the following .h files."
4344   # Intersect $specified_modules and $main_modules
4345   # (since $specified_modules is not necessarily of subset of $main_modules
4346   # - some may have been skipped through --avoid, and since the elements of
4347   # $main_modules but not in $specified_modules can go away without explicit
4348   # notice - through changes in the module dependencies).
4349   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
4350   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
4351   # First the #include <...> directives without #ifs, sorted for convenience,
4352   # then the #include "..." directives without #ifs, sorted for convenience,
4353   # then the #include directives that are surrounded by #ifs. Not sorted.
4354   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
4355     include_directive=`func_get_include_directive "$module"`
4356     case "$nl$include_directive" in
4357       *"$nl#if"*)
4358         echo "$include_directive" 1>&5
4359         ;;
4360       *)
4361         echo "$include_directive" | grep -v 'include "' 1>&6
4362         echo "$include_directive" | grep 'include "' 1>&7
4363         ;;
4364     esac
4365   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
4366   (
4367    LC_ALL=C sort -u "$tmp"/include-angles
4368    LC_ALL=C sort -u "$tmp"/include-quotes
4369    cat "$tmp"/include-if
4370   ) | sed -e '/^$/d' -e 's/^/  /'
4371   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
4372
4373   for module in $main_modules; do
4374     func_get_link_directive "$module"
4375   done \
4376     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
4377   if test `wc -l < "$tmp"/link` != 0; then
4378     echo
4379     echo "You may need to use the following Makefile variables when linking."
4380     echo "Use them in <program>_LDADD when linking a program, or"
4381     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
4382     cat "$tmp"/link
4383   fi
4384   rm -f "$tmp"/link
4385
4386   echo
4387   echo "Don't forget to"
4388   if test "$makefile_am" = Makefile.am; then
4389     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
4390   else
4391     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
4392   fi
4393   if test -n "$pobase"; then
4394     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
4395   fi
4396   if test -n "$inctests"; then
4397     if test "$makefile_am" = Makefile.am; then
4398       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
4399     else
4400       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
4401     fi
4402   fi
4403   edit=0
4404   while test $edit != $makefile_am_edits; do
4405     edit=`expr $edit + 1`
4406     eval dir=\"\$makefile_am_edit${edit}_dir\"
4407     eval var=\"\$makefile_am_edit${edit}_var\"
4408     eval val=\"\$makefile_am_edit${edit}_val\"
4409     if test -n "$var"; then
4410       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
4411     fi
4412   done
4413   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
4414   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
4415 }
4416
4417 # func_create_testdir testdir modules
4418 # Input:
4419 # - local_gnulib_dir  from --local-dir
4420 # - modcache        true or false, from --cache-modules/--no-cache-modules
4421 # - auxdir          directory relative to destdir where to place build aux files
4422 # - inctests        true if tests should be included, blank otherwise
4423 # - incobsolete     true if obsolete modules among dependencies should be
4424 #                   included, blank otherwise
4425 # - avoidlist       list of modules to avoid
4426 # - libtool         true if --libtool was given, false if --no-libtool was
4427 #                   given, blank otherwise
4428 # - symbolic        true if files should be symlinked, copied otherwise
4429 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
4430 #                   copied otherwise
4431 func_create_testdir ()
4432 {
4433   testdir="$1"
4434   modules="$2"
4435   if test -z "$modules"; then
4436     # All modules together.
4437     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
4438     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
4439     # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
4440     modules=`func_all_modules`
4441     modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist | lib-ignore) ;; *) echo $m;; esac; done`
4442   fi
4443   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
4444
4445   # Check that the license of every module is consistent with the license of
4446   # its dependencies.
4447   saved_modules="$modules"
4448   saved_inctests="$inctests"
4449   # When computing transitive closures, don't consider $module to depend on
4450   # $module-tests. Need this becauses tests are implicitly GPL and may depend
4451   # on GPL modules - therefore we don't want a warning in this case.
4452   inctests=""
4453   for requested_module in $saved_modules; do
4454     requested_license=`func_get_license "$requested_module"`
4455     if test "$requested_license" != GPL; then
4456       # Here we use func_modules_transitive_closure, not just
4457       # func_get_dependencies, so that we also detect weird situations like
4458       # an LGPL module which depends on a GPLed build tool module which depends
4459       # on a GPL module.
4460       modules="$requested_module"
4461       func_modules_transitive_closure
4462       for module in $modules; do
4463         license=`func_get_license "$module"`
4464         case "$license" in
4465           'GPLed build tool') ;;
4466           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
4467           *)
4468             case "$requested_license" in
4469               GPLv2+)
4470                 case "$license" in
4471                   GPLv2+ | LGPLv2+) ;;
4472                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4473                 esac
4474                 ;;
4475               LGPL)
4476                 case "$license" in
4477                   LGPL | LGPLv2+) ;;
4478                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4479                 esac
4480                 ;;
4481               LGPLv2+)
4482                 case "$license" in
4483                   LGPLv2+) ;;
4484                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4485                 esac
4486                 ;;
4487             esac
4488             ;;
4489         esac
4490       done
4491     fi
4492   done
4493   modules="$saved_modules"
4494   inctests="$saved_inctests"
4495
4496   # Subdirectory names.
4497   sourcebase=gllib
4498   m4base=glm4
4499   pobase=
4500   docbase=gldoc
4501   testsbase=gltests
4502   macro_prefix=gl
4503   po_domain=
4504   vc_files=
4505
4506   # Determine final module list.
4507   func_modules_transitive_closure
4508   if test $verbose -ge 0; then
4509     echo "Module list with included dependencies:"
4510     echo "$modules" | sed -e 's/^/  /'
4511   fi
4512
4513   # Add the dummy module if needed.
4514   func_modules_add_dummy
4515
4516   # Show banner notice of every module.
4517   func_modules_notice
4518
4519   # Determine final file list.
4520   func_modules_to_filelist
4521   if test $verbose -ge 0; then
4522     echo "File list:"
4523     echo "$files" | sed -e 's/^/  /'
4524   fi
4525
4526   rewritten='%REWRITTEN%'
4527   sed_rewrite_files="\
4528     s,^build-aux/,$rewritten$auxdir/,
4529     s,^doc/,$rewritten$docbase/,
4530     s,^lib/,$rewritten$sourcebase/,
4531     s,^m4/,$rewritten$m4base/,
4532     s,^tests/,$rewritten$testsbase/,
4533     s,^top/,$rewritten,
4534     s,^$rewritten,,"
4535
4536   # Create directories.
4537   for f in $files; do echo $f; done \
4538     | sed -e "$sed_rewrite_files" \
4539     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
4540     | LC_ALL=C sort -u \
4541     > "$tmp"/dirs
4542   { # Rearrange file descriptors. Needed because "while ... done < ..."
4543     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4544     exec 5<&0 < "$tmp"/dirs
4545     while read d; do
4546       mkdir -p "$testdir/$d"
4547     done
4548     exec 0<&5 5<&-
4549   }
4550
4551   # Copy files or make symbolic links.
4552   delimiter='   '
4553   for f in $files; do echo $f; done \
4554     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
4555     | LC_ALL=C sort \
4556     > "$tmp"/files
4557   { # Rearrange file descriptors. Needed because "while ... done < ..."
4558     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4559     exec 5<&0 < "$tmp"/files
4560     while read g f; do
4561       func_lookup_file "$f"
4562       if test -n "$lookedup_tmp"; then
4563         cp -p "$lookedup_file" "$testdir/$g"
4564       else
4565         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
4566         if { test -n "$symbolic" \
4567              || { test -n "$lsymbolic" \
4568                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
4569           func_ln "$lookedup_file" "$testdir/$g"
4570         else
4571           cp -p "$lookedup_file" "$testdir/$g"
4572         fi
4573       fi
4574     done
4575     exec 0<&5 5<&-
4576   }
4577
4578   # Create Makefile.ams that are for testing.
4579   for_test=true
4580
4581   # No special edits are needed.
4582   makefile_am_edits=0
4583
4584   # Create $sourcebase/Makefile.am.
4585   mkdir -p "$testdir/$sourcebase"
4586   destfile="$sourcebase/Makefile.am"
4587   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
4588   any_uses_subdirs="$uses_subdirs"
4589
4590   # Create $m4base/Makefile.am.
4591   mkdir -p "$testdir/$m4base"
4592   (echo "## Process this file with automake to produce Makefile.in."
4593    echo
4594    echo "EXTRA_DIST ="
4595    for f in $files; do
4596      case "$f" in
4597        m4/* )
4598          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
4599      esac
4600    done
4601   ) > "$testdir/$m4base/Makefile.am"
4602
4603   subdirs="$sourcebase $m4base"
4604   subdirs_with_configure_ac=""
4605
4606   if false && test -f "$testdir"/$m4base/gettext.m4; then
4607     # Avoid stupid error message from automake:
4608     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
4609     mkdir -p "$testdir/po"
4610     (echo "## Process this file with automake to produce Makefile.in."
4611     ) > "$testdir/po/Makefile.am"
4612     func_append subdirs " po"
4613   fi
4614
4615   if test -n "$inctests"; then
4616     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
4617     # Viewed from the $testsbase subdirectory, $auxdir is different.
4618     saved_auxdir="$auxdir"
4619     auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
4620     # Create $testsbase/Makefile.am.
4621     use_libtests=false
4622     destfile="$testsbase/Makefile.am"
4623     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
4624     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
4625     # Create $testsbase/configure.ac.
4626     (echo "# Process this file with autoconf to produce a configure script."
4627      echo "AC_INIT([dummy], [0])"
4628      echo "AC_CONFIG_AUX_DIR([$auxdir])"
4629      echo "AM_INIT_AUTOMAKE"
4630      echo
4631      echo "AC_CONFIG_HEADERS([config.h])"
4632      echo
4633      echo "AC_PROG_CC"
4634      echo "AC_PROG_INSTALL"
4635      echo "AC_PROG_MAKE_SET"
4636      echo "AC_PROG_RANLIB"
4637      echo
4638      if test -n "$uses_subdirs"; then
4639        echo "AM_PROG_CC_C_O"
4640        echo
4641      fi
4642      for module in $modules; do
4643        func_verify_module
4644        if test -n "$module"; then
4645          case $module in
4646            gnumakefile | maintainer-makefile)
4647              # These modules are meant to be used only in the top-level directory.
4648              ;;
4649            *)
4650              func_get_autoconf_early_snippet "$module"
4651              ;;
4652          esac
4653        fi
4654      done \
4655        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
4656      if test "$libtool" = true; then
4657        echo "LT_INIT([win32-dll])"
4658        echo "LT_LANG([C++])"
4659        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
4660        echo "gl_cond_libtool=true"
4661      else
4662        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
4663        echo "gl_cond_libtool=false"
4664        echo "gl_libdeps="
4665        echo "gl_ltlibdeps="
4666      fi
4667      # Wrap the set of autoconf snippets into an autoconf macro that is then
4668      # invoked. This is needed because autoconf does not support AC_REQUIRE
4669      # at the top level:
4670      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
4671      # but we want the AC_REQUIRE to have its normal meaning (provide one
4672      # expansion of the required macro before the current point, and only one
4673      # expansion total).
4674      echo "AC_DEFUN([gl_INIT], ["
4675      sed_replace_build_aux='
4676        :a
4677        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
4678          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
4679          ba
4680        }'
4681      func_emit_initmacro_start $macro_prefix
4682      # We don't have explicit ordering constraints between the various
4683      # autoconf snippets. It's cleanest to put those of the library before
4684      # those of the tests.
4685      echo "gl_source_base='../$sourcebase'"
4686      for module in $modules; do
4687        func_verify_nontests_module
4688        if test -n "$module"; then
4689          case $module in
4690            gnumakefile | maintainer-makefile)
4691              # These modules are meant to be used only in the top-level directory.
4692              ;;
4693            *)
4694              func_get_autoconf_snippet "$module" \
4695                | sed -e "$sed_replace_build_aux"
4696              ;;
4697          esac
4698        fi
4699      done
4700      echo "gl_source_base='.'"
4701      for module in $modules; do
4702        func_verify_tests_module
4703        if test -n "$module"; then
4704          func_get_autoconf_snippet "$module" \
4705            | sed -e "$sed_replace_build_aux"
4706        fi
4707      done
4708      func_emit_initmacro_end $macro_prefix
4709      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
4710      # created using libtool, because libtool already handles the dependencies.
4711      if test "$libtool" != true; then
4712        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
4713        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
4714        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
4715        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
4716        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
4717      fi
4718      echo "])"
4719      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
4720      echo
4721      echo "gl_INIT"
4722      echo
4723      # Usually $testsbase/config.h will be a superset of config.h. Verify this
4724      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
4725      echo "AH_TOP([#include \"../config.h\"])"
4726      echo
4727      echo "AC_CONFIG_FILES([Makefile])"
4728      echo "AC_OUTPUT"
4729     ) > "$testdir/$testsbase/configure.ac"
4730     auxdir="$saved_auxdir"
4731     func_append subdirs " $testsbase"
4732     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
4733   fi
4734
4735   # Create Makefile.am.
4736   (echo "## Process this file with automake to produce Makefile.in."
4737    echo
4738    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
4739    echo
4740    echo "SUBDIRS = $subdirs"
4741    echo
4742    echo "ACLOCAL_AMFLAGS = -I $m4base"
4743   ) > "$testdir/Makefile.am"
4744
4745   # Create configure.ac.
4746   (echo "# Process this file with autoconf to produce a configure script."
4747    echo "AC_INIT([dummy], [0])"
4748    if test "$auxdir" != "."; then
4749      echo "AC_CONFIG_AUX_DIR([$auxdir])"
4750    fi
4751    echo "AM_INIT_AUTOMAKE"
4752    echo
4753    echo "AC_CONFIG_HEADERS([config.h])"
4754    echo
4755    echo "AC_PROG_CC"
4756    echo "AC_PROG_INSTALL"
4757    echo "AC_PROG_MAKE_SET"
4758    echo
4759    echo "# For autobuild."
4760    echo "AC_CANONICAL_BUILD"
4761    echo "AC_CANONICAL_HOST"
4762    echo
4763    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
4764    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
4765    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
4766    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
4767    echo
4768    echo "AC_PROG_RANLIB"
4769    echo
4770    if test -n "$any_uses_subdirs"; then
4771      echo "AM_PROG_CC_C_O"
4772      echo
4773    fi
4774    for module in $modules; do
4775      func_verify_nontests_module
4776      if test -n "$module"; then
4777        func_get_autoconf_early_snippet "$module"
4778      fi
4779    done \
4780      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
4781    if test "$libtool" = true; then
4782      echo "LT_INIT([win32-dll])"
4783      echo "LT_LANG([C++])"
4784      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
4785      echo "gl_cond_libtool=true"
4786    else
4787      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
4788      echo "gl_cond_libtool=false"
4789      echo "gl_libdeps="
4790      echo "gl_ltlibdeps="
4791    fi
4792    # Wrap the set of autoconf snippets into an autoconf macro that is then
4793    # invoked. This is needed because autoconf does not support AC_REQUIRE
4794    # at the top level:
4795    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
4796    # but we want the AC_REQUIRE to have its normal meaning (provide one
4797    # expansion of the required macro before the current point, and only one
4798    # expansion total).
4799    echo "AC_DEFUN([gl_INIT], ["
4800    if test "$auxdir" != "build-aux"; then
4801      sed_replace_build_aux='
4802        :a
4803        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
4804          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
4805          ba
4806        }'
4807    else
4808      sed_replace_build_aux="$sed_noop"
4809    fi
4810    func_emit_initmacro_start $macro_prefix
4811    echo "gl_source_base='$sourcebase'"
4812    for module in $modules; do
4813      func_verify_nontests_module
4814      if test -n "$module"; then
4815        func_get_autoconf_snippet "$module" \
4816          | sed -e "$sed_replace_build_aux"
4817      fi
4818    done
4819    func_emit_initmacro_end $macro_prefix
4820    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
4821    # created using libtool, because libtool already handles the dependencies.
4822    if test "$libtool" != true; then
4823      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
4824      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
4825      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
4826      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
4827      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
4828    fi
4829    echo "])"
4830    func_emit_initmacro_done $macro_prefix $sourcebase
4831    echo
4832    echo "gl_INIT"
4833    echo
4834    if test -n "$subdirs_with_configure_ac"; then
4835      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
4836    fi
4837    makefiles="Makefile"
4838    for d in $subdirs; do
4839      # For subdirs that have a configure.ac by their own, it's the subdir's
4840      # configure.ac which creates the subdir's Makefile.am, not this one.
4841      case " $subdirs_with_configure_ac " in
4842        *" $d "*) ;;
4843        *) func_append makefiles " $d/Makefile" ;;
4844      esac
4845    done
4846    echo "AC_CONFIG_FILES([$makefiles])"
4847    echo "AC_OUTPUT"
4848   ) > "$testdir/configure.ac"
4849
4850   # Create autogenerated files.
4851   (cd "$testdir"
4852    # Do not use "${AUTORECONF} --force --install", because it may invoke
4853    # autopoint, which brings in older versions of some of our .m4 files.
4854    if test -f $m4base/gettext.m4; then
4855      func_execute_command ${AUTOPOINT} --force || func_exit 1
4856      for f in $m4base/*.m4~; do
4857        if test -f $f; then
4858          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
4859        fi
4860      done
4861    fi
4862    if test "$libtool" = true; then
4863      func_execute_command ${LIBTOOLIZE} --copy || func_exit 1
4864    fi
4865    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
4866    if ! test -d build-aux; then
4867      func_execute_command mkdir build-aux || func_exit 1
4868    fi
4869    func_execute_command ${AUTOCONF} || func_exit 1
4870    func_execute_command ${AUTOHEADER} || func_exit 1
4871    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
4872   ) || func_exit 1
4873   if test -n "$inctests"; then
4874     # Create autogenerated files.
4875     (cd "$testdir/$testsbase" || func_exit 1
4876      # Do not use "${AUTORECONF} --force --install", because it may invoke
4877      # autopoint, which brings in older versions of some of our .m4 files.
4878      if test -f ../$m4base/gettext.m4; then
4879        func_execute_command ${AUTOPOINT} --force || func_exit 1
4880        for f in ../$m4base/*.m4~; do
4881          if test -f $f; then
4882            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
4883          fi
4884        done
4885      fi
4886      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
4887      if ! test -d ../build-aux; then
4888        func_execute_command mkdir ../build-aux
4889      fi
4890      func_execute_command ${AUTOCONF} || func_exit 1
4891      func_execute_command ${AUTOHEADER} || func_exit 1
4892      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
4893     ) || func_exit 1
4894   fi
4895   # Need to run configure and make once, to create built files that are to be
4896   # distributed (such as getdate.c).
4897   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
4898   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
4899                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
4900   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
4901   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
4902   # such $(FOO_H) because they don't refer to distributed files.
4903   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
4904   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
4905                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
4906                  | sed -e "$sed_remove_make_variables"`
4907   distributed_built_sources=`for file in $built_sources; do
4908                                case "$cleaned_files" in
4909                                  *" "$file" "*) ;;
4910                                  *) echo $file ;;
4911                                esac;
4912                              done`
4913   if test -n "$distributed_built_sources"; then
4914     (cd "$testdir"
4915      ./configure || func_exit 1
4916        cd "$sourcebase"
4917        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
4918        $MAKE built_sources || func_exit 1
4919        cd ..
4920      $MAKE distclean || func_exit 1
4921     ) || func_exit 1
4922   fi
4923 }
4924
4925 # func_create_megatestdir megatestdir allmodules
4926 # Input:
4927 # - local_gnulib_dir  from --local-dir
4928 # - modcache        true or false, from --cache-modules/--no-cache-modules
4929 # - auxdir          directory relative to destdir where to place build aux files
4930 func_create_megatestdir ()
4931 {
4932   megatestdir="$1"
4933   allmodules="$2"
4934   if test -z "$allmodules"; then
4935     allmodules=`func_all_modules`
4936   fi
4937
4938   megasubdirs=
4939   # First, all modules one by one.
4940   for onemodule in $allmodules; do
4941     func_create_testdir "$megatestdir/$onemodule" $onemodule
4942     func_append megasubdirs "$onemodule "
4943   done
4944   # Then, all modules all together.
4945   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
4946   allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
4947   func_create_testdir "$megatestdir/ALL" "$allmodules"
4948   func_append megasubdirs "ALL"
4949
4950   # Create autobuild.
4951   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
4952              vc_witness="$gnulib_dir/CVS/Entries"; \
4953            else \
4954              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
4955            fi; \
4956            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
4957              | sed -e 's,January,01,'   -e 's,Jan,01,' \
4958                    -e 's,February,02,'  -e 's,Feb,02,' \
4959                    -e 's,March,03,'     -e 's,Mar,03,' \
4960                    -e 's,April,04,'     -e 's,Apr,04,' \
4961                    -e 's,May,05,'                      \
4962                    -e 's,June,06,'      -e 's,Jun,06,' \
4963                    -e 's,July,07,'      -e 's,Jul,07,' \
4964                    -e 's,August,08,'    -e 's,Aug,08,' \
4965                    -e 's,September,09,' -e 's,Sep,09,' \
4966                    -e 's,October,10,'   -e 's,Oct,10,' \
4967                    -e 's,November,11,'  -e 's,Nov,11,' \
4968                    -e 's,December,12,'  -e 's,Dec,12,' \
4969                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
4970                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
4971   (echo '#!/bin/sh'
4972    echo "CVSDATE=$cvsdate"
4973    echo ": \${MAKE=make}"
4974    echo "test -d logs || mkdir logs"
4975    echo "for module in $megasubdirs; do"
4976    echo "  echo \"Working on module \$module...\""
4977    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
4978    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
4979    echo "   echo"
4980    echo "   set -x"
4981    echo "   : autobuild project... \$module"
4982    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
4983    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
4984    echo "   : autobuild hostname... \`hostname\`"
4985    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && \$MAKE && \$MAKE check && \$MAKE distclean"
4986    echo "   echo rc=\$?"
4987    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
4988    echo "done"
4989   ) > "$megatestdir/do-autobuild"
4990   chmod a+x "$megatestdir/do-autobuild"
4991
4992   # Create Makefile.am.
4993   (echo "## Process this file with automake to produce Makefile.in."
4994    echo
4995    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
4996    echo
4997    echo "SUBDIRS = $megasubdirs"
4998    echo
4999    echo "EXTRA_DIST = do-autobuild"
5000   ) > "$megatestdir/Makefile.am"
5001
5002   # Create configure.ac.
5003   (echo "# Process this file with autoconf to produce a configure script."
5004    echo "AC_INIT([dummy], [0])"
5005    if test "$auxdir" != "."; then
5006      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5007    fi
5008    echo "AM_INIT_AUTOMAKE"
5009    echo
5010    echo "AC_PROG_MAKE_SET"
5011    echo
5012    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
5013    echo "AC_CONFIG_FILES([Makefile])"
5014    echo "AC_OUTPUT"
5015   ) > "$megatestdir/configure.ac"
5016
5017   # Create autogenerated files.
5018   (cd "$megatestdir"
5019    # Do not use "${AUTORECONF} --install", because autoreconf operates
5020    # recursively, but the subdirectories are already finished, therefore
5021    # calling autoreconf here would only waste lots of CPU time.
5022    func_execute_command ${ACLOCAL} || func_exit 1
5023    func_execute_command mkdir build-aux
5024    func_execute_command ${AUTOCONF} || func_exit 1
5025    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5026   ) || func_exit 1
5027 }
5028
5029 case $mode in
5030   "" )
5031     func_fatal_error "no mode specified" ;;
5032
5033   list )
5034     func_all_modules
5035     ;;
5036
5037   find )
5038     # sed expression that converts a literal to a basic regular expression.
5039     # Needs to handle . [ \ * ^ $.
5040     sed_literal_to_basic_regex='s/\\/\\\\/g
5041 s/\[/\\[/g
5042 s/\^/\\^/g
5043 s/\([.*$]\)/[\1]/g'
5044     for filename
5045     do
5046       if test -f "$gnulib_dir/$filename" \
5047          || { test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$filename"; }; then
5048         filename_anywhere_regex=`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`
5049         filename_line_regex='^'"$filename_anywhere_regex"'$'
5050         module_candidates=`
5051           {
5052             (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filename_line_regex" /dev/null | sed -e 's,^modules/,,')
5053             if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
5054               (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$,,')
5055             fi
5056           } \
5057             | func_sanitize_modulelist \
5058             | LC_ALL=C sort -u
5059           `
5060         for module in $module_candidates; do
5061           if func_get_filelist $module | grep "$filename_line_regex" > /dev/null; then
5062             echo $module
5063           fi
5064         done
5065       else
5066         func_warning "file $filename does not exist"
5067       fi
5068     done
5069     ;;
5070
5071   import | update )
5072
5073     # Where to import.
5074     if test -z "$destdir"; then
5075       destdir=.
5076     fi
5077     test -d "$destdir" \
5078       || func_fatal_error "destination directory does not exist: $destdir"
5079
5080     # Prefer configure.ac to configure.in.
5081     if test -f "$destdir"/configure.ac; then
5082       configure_ac="$destdir/configure.ac"
5083     else
5084       if test -f "$destdir"/configure.in; then
5085         configure_ac="$destdir/configure.in"
5086       else
5087         func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
5088       fi
5089     fi
5090
5091     # Analyze configure.ac.
5092     guessed_auxdir="."
5093     guessed_libtool=false
5094     my_sed_traces='
5095       s,#.*$,,
5096       s,^dnl .*$,,
5097       s, dnl .*$,,
5098       /AC_CONFIG_AUX_DIR/ {
5099         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
5100       }
5101       /A[CM]_PROG_LIBTOOL/ {
5102         s,^.*$,guessed_libtool=true,p
5103       }'
5104     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
5105
5106     if test -z "$auxdir"; then
5107       auxdir="$guessed_auxdir"
5108     fi
5109
5110     # Determine where to apply func_import.
5111     if test -n "$m4base"; then
5112       # Apply func_import to a particular gnulib directory.
5113       # Any number of additional modules can be given.
5114       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
5115         # First use of gnulib in the given m4base.
5116         test -n "$supplied_libname" || supplied_libname=true
5117         test -n "$sourcebase" || sourcebase="lib"
5118         test -n "$docbase" || docbase="doc"
5119         test -n "$testsbase" || testsbase="tests"
5120         test -n "$macro_prefix" || macro_prefix="gl"
5121       fi
5122       func_import "$*"
5123     else
5124       # Apply func_import to all gnulib directories.
5125       # To get this list of directories, look at Makefile.am. (Not at
5126       # configure, because it may be omitted from CVS. Also, don't run
5127       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
5128       m4dirs=
5129       m4dirs_count=0
5130       if test -f "$destdir"/Makefile.am; then
5131         aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[  ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
5132         m4dir_is_next=
5133         for arg in $aclocal_amflags; do
5134           if test -n "$m4dir_is_next"; then
5135             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
5136             case "$arg" in
5137               /*) ;;
5138               *)
5139                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
5140                   func_append m4dirs " $arg"
5141                   m4dirs_count=`expr $m4dirs_count + 1`
5142                 fi
5143                 ;;
5144             esac
5145             m4dir_is_next=
5146           else
5147             if test "X$arg" = "X-I"; then
5148               m4dir_is_next=yes
5149             else
5150               m4dir_is_next=
5151             fi
5152           fi
5153         done
5154       else
5155         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
5156         if test -f "$destdir"/aclocal.m4; then
5157           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
5158           sedexpr2='s,^[^/]*$,.,'
5159           sedexpr3='s,/[^/]*$,,'
5160           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
5161           m4dirs_count=`printf %s "$m4dirs" | wc -l`
5162         fi
5163       fi
5164       if test $m4dirs_count = 0; then
5165         # First use of gnulib in a package.
5166         # Any number of additional modules can be given.
5167         test -n "$supplied_libname" || supplied_libname=true
5168         test -n "$sourcebase" || sourcebase="lib"
5169         m4base="m4"
5170         test -n "$docbase" || docbase="doc"
5171         test -n "$testsbase" || testsbase="tests"
5172         test -n "$macro_prefix" || macro_prefix="gl"
5173         func_import "$*"
5174       else
5175         if test $m4dirs_count = 1; then
5176           # There's only one use of gnulib here. Assume the user means it.
5177           # Any number of additional modules can be given.
5178           for m4base in $m4dirs; do
5179             func_import "$*"
5180           done
5181         else
5182           # Ambiguous - guess what the user meant.
5183           if test $# = 0; then
5184             # No further arguments. Guess the user wants to update all of them.
5185             for m4base in $m4dirs; do
5186               # Perform func_import in a subshell, so that variable values
5187               # such as
5188               #   local_gnulib_dir, incobsolete, avoidlist, sourcebase, m4base,
5189               #   pobase, docbase, testsbase, inctests, libname, lgpl,
5190               #   makefile_name, libtool, macro_prefix, po_domain, vc_files
5191               # don't propagate from one directory to another.
5192               (func_import) || func_exit 1
5193             done
5194           else
5195             # Really ambiguous.
5196             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
5197           fi
5198         fi
5199       fi
5200     fi
5201     ;;
5202
5203   create-testdir )
5204     if test -z "$destdir"; then
5205       func_fatal_error "please specify --dir option"
5206     fi
5207     mkdir "$destdir"
5208     test -d "$destdir" \
5209       || func_fatal_error "could not create destination directory"
5210     test -n "$auxdir" || auxdir="build-aux"
5211     func_create_testdir "$destdir" "$*"
5212     ;;
5213
5214   create-megatestdir )
5215     if test -z "$destdir"; then
5216       func_fatal_error "please specify --dir option"
5217     fi
5218     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5219     test -n "$auxdir" || auxdir="build-aux"
5220     func_create_megatestdir "$destdir" "$*"
5221     ;;
5222
5223   test )
5224     test -n "$destdir" || destdir=testdir$$
5225     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5226     test -n "$auxdir" || auxdir="build-aux"
5227     func_create_testdir "$destdir" "$*"
5228     cd "$destdir"
5229       mkdir build
5230       cd build
5231         ../configure || func_exit 1
5232         $MAKE || func_exit 1
5233         $MAKE check || func_exit 1
5234         $MAKE distclean || func_exit 1
5235         remaining=`find . -type f -print`
5236         if test -n "$remaining"; then
5237           echo "Remaining files:" $remaining 1>&2
5238           echo "gnulib-tool: *** Stop." 1>&2
5239           func_exit 1
5240         fi
5241       cd ..
5242     cd ..
5243     rm -rf "$destdir"
5244     ;;
5245
5246   megatest )
5247     test -n "$destdir" || destdir=testdir$$
5248     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5249     test -n "$auxdir" || auxdir="build-aux"
5250     func_create_megatestdir "$destdir" "$*"
5251     cd "$destdir"
5252       mkdir build
5253       cd build
5254         ../configure
5255         $MAKE
5256         $MAKE check
5257         $MAKE distclean
5258         remaining=`find . -type f -print`
5259         if test -n "$remaining"; then
5260           echo "Remaining files:" $remaining 1>&2
5261           echo "gnulib-tool: *** Stop." 1>&2
5262           func_exit 1
5263         fi
5264       cd ..
5265     cd ..
5266     rm -rf "$destdir"
5267     ;;
5268
5269   extract-description )
5270     for module
5271     do
5272       func_verify_module
5273       if test -n "$module"; then
5274         func_get_description "$module"
5275       fi
5276     done
5277     ;;
5278
5279   extract-status )
5280     for module
5281     do
5282       func_verify_module
5283       if test -n "$module"; then
5284         func_get_status "$module"
5285       fi
5286     done
5287     ;;
5288
5289   extract-notice )
5290     for module
5291     do
5292       func_verify_module
5293       if test -n "$module"; then
5294         func_get_notice "$module"
5295       fi
5296     done
5297     ;;
5298
5299   extract-applicability )
5300     for module
5301     do
5302       func_verify_module
5303       if test -n "$module"; then
5304         func_get_applicability "$module"
5305       fi
5306     done
5307     ;;
5308
5309   extract-filelist )
5310     for module
5311     do
5312       func_verify_module
5313       if test -n "$module"; then
5314         func_get_filelist "$module"
5315       fi
5316     done
5317     ;;
5318
5319   extract-dependencies )
5320     for module
5321     do
5322       func_verify_module
5323       if test -n "$module"; then
5324         func_get_dependencies "$module"
5325       fi
5326     done
5327     ;;
5328
5329   extract-autoconf-snippet )
5330     for module
5331     do
5332       func_verify_module
5333       if test -n "$module"; then
5334         func_get_autoconf_snippet "$module"
5335       fi
5336     done
5337     ;;
5338
5339   extract-automake-snippet )
5340     for module
5341     do
5342       func_verify_module
5343       if test -n "$module"; then
5344         func_get_automake_snippet "$module"
5345       fi
5346     done
5347     ;;
5348
5349   extract-include-directive )
5350     for module
5351     do
5352       func_verify_module
5353       if test -n "$module"; then
5354         func_get_include_directive "$module"
5355       fi
5356     done
5357     ;;
5358
5359   extract-link-directive )
5360     for module
5361     do
5362       func_verify_module
5363       if test -n "$module"; then
5364         func_get_link_directive "$module"
5365       fi
5366     done
5367     ;;
5368
5369   extract-license )
5370     for module
5371     do
5372       func_verify_module
5373       if test -n "$module"; then
5374         func_get_license "$module"
5375       fi
5376     done
5377     ;;
5378
5379   extract-maintainer )
5380     for module
5381     do
5382       func_verify_module
5383       if test -n "$module"; then
5384         func_get_maintainer "$module"
5385       fi
5386     done
5387     ;;
5388
5389   extract-tests-module )
5390     for module
5391     do
5392       func_verify_module
5393       if test -n "$module"; then
5394         func_get_tests_module "$module"
5395       fi
5396     done
5397     ;;
5398
5399   copy-file )
5400     # Verify the number of arguments.
5401     if test $# -lt 1 || test $# -gt 2; then
5402       func_fatal_error "invalid number of arguments for --$mode"
5403     fi
5404
5405     # The first argument is the file to be copied.
5406     f="$1"
5407     # Verify the file exists.
5408     func_lookup_file "$f"
5409
5410     # The second argument is the destination; either a directory ot a file.
5411     # It defaults to the current directory.
5412     dest="$2"
5413     test -n "$dest" || dest='.'
5414     test -n "$sourcebase" || sourcebase="lib"
5415     test -n "$m4base" || m4base="m4"
5416     test -n "$docbase" || docbase="doc"
5417     test -n "$testsbase" || testsbase="tests"
5418     test -n "$auxdir" || auxdir="build-aux"
5419     rewritten='%REWRITTEN%'
5420     sed_rewrite_files="\
5421       s,^build-aux/,$rewritten$auxdir/,
5422       s,^doc/,$rewritten$docbase/,
5423       s,^lib/,$rewritten$sourcebase/,
5424       s,^m4/,$rewritten$m4base/,
5425       s,^tests/,$rewritten$testsbase/,
5426       s,^top/,$rewritten,
5427       s,^$rewritten,,"
5428     if test -d "$dest"; then
5429       destdir="$dest"
5430       g=`echo "$f" | sed -e "$sed_rewrite_files"`
5431     else
5432       destdir=`dirname "$dest"`
5433       g=`basename "$dest"`
5434     fi
5435
5436     # Create the directory for destfile.
5437     d=`dirname "$destdir/$g"`
5438     if $doit; then
5439       if test -n "$d" && test ! -d "$d"; then
5440         mkdir -p "$d" || func_fatal_error "failed"
5441       fi
5442     fi
5443     # Copy the file.
5444     func_dest_tmpfilename "$g"
5445     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
5446     already_present=true
5447     if test -f "$destdir/$g"; then
5448       # The file already exists.
5449       func_update_file
5450     else
5451       # Install the file.
5452       # Don't protest if the file should be there but isn't: it happens
5453       # frequently that developers don't put autogenerated files into CVS.
5454       func_add_file
5455     fi
5456     rm -f "$tmpfile"
5457     ;;
5458
5459   * )
5460     func_fatal_error "unknown operation mode --$mode" ;;
5461 esac
5462
5463 rm -rf "$tmp"
5464 # Undo the effect of the previous 'trap' command. Some shellology:
5465 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
5466 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
5467 # exit); for the others we need to call 'exit' explicitly. The value of $? is
5468 # 128 + signal number and is set before the trap-registered command is run.
5469 trap '' 0
5470 trap 'func_exit $?' 1 2 3 13 15
5471
5472 exit 0
5473
5474 # Local Variables:
5475 # indent-tabs-mode: nil
5476 # whitespace-check-buffer-indent: nil
5477 # End: