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