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