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