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