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