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