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