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