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