gnulib-tool: Remove old file names from .cvsignore, .gitignore.
[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     sed_eliminate_LDFLAGS="$sed_noop"
3580   else
3581     libext=a
3582     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
3583   fi
3584   if $for_test; then
3585     # When creating a package for testing: Attempt to provoke failures,
3586     # especially link errors, already during "make" rather than during
3587     # "make check", because "make check" is not possible in a cross-compiling
3588     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
3589     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
3590   else
3591     sed_transform_check_PROGRAMS="$sed_noop"
3592   fi
3593   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
3594   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3595   echo "## Process this file with automake to produce Makefile.in."
3596   func_emit_copyright_notice
3597   echo
3598   uses_subdirs=
3599   {
3600     for module in $modules; do
3601       if $for_test && ! $single_configure; then
3602         func_verify_tests_module
3603       else
3604         func_verify_module
3605       fi
3606       if test -n "$module"; then
3607         {
3608           func_get_automake_snippet "$module" |
3609             LC_ALL=C \
3610             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
3611                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
3612                 -e "$sed_eliminate_LDFLAGS" \
3613                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
3614                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
3615                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
3616                 -e "$sed_transform_check_PROGRAMS" \
3617                 -e "$sed_replace_include_guard_prefix"
3618           if $use_libtests && test "$module" = 'alloca'; then
3619             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
3620             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
3621           fi
3622         } > "$tmp"/amsnippet
3623         # Skip the contents if it's entirely empty.
3624         if grep '[^      ]' "$tmp"/amsnippet > /dev/null ; then
3625           # Mention long-running tests at the end.
3626           ofd=3
3627           for word in `func_get_status "$module"`; do
3628             if test "$word" = 'longrunning-test'; then
3629               ofd=4
3630               break
3631             fi
3632           done
3633           { echo "## begin gnulib module $module"
3634             echo
3635             cat "$tmp"/amsnippet
3636             echo "## end   gnulib module $module"
3637             echo
3638           } >&$ofd
3639         fi
3640         rm -f "$tmp"/amsnippet
3641         # Test whether there are some source files in subdirectories.
3642         for f in `func_get_filelist "$module"`; do
3643           case $f in
3644             lib/*/*.c | tests/*/*.c)
3645               uses_subdirs=yes
3646               break
3647               ;;
3648           esac
3649         done
3650       fi
3651     done
3652   } 3> "$tmp"/main_snippets 4> "$tmp"/longrunning_snippets
3653   # Generate dependencies here, since it eases the debugging of test failures.
3654   # If there are source files in subdirectories, prevent collision of the
3655   # object files (example: hash.c and libxml/hash.c).
3656   subdir_options=
3657   if test -n "$uses_subdirs"; then
3658     subdir_options=' subdir-objects'
3659   fi
3660   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
3661   echo
3662   if $for_test && ! $single_configure; then
3663     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
3664     echo
3665   fi
3666   # Nothing is being added to SUBDIRS; nevertheless the existence of this
3667   # variable is needed to avoid an error from automake:
3668   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
3669   echo "SUBDIRS = ."
3670   echo "TESTS ="
3671   echo "XFAIL_TESTS ="
3672   echo "TESTS_ENVIRONMENT ="
3673   echo "noinst_PROGRAMS ="
3674   if ! $for_test; then
3675     echo "check_PROGRAMS ="
3676   fi
3677   echo "noinst_HEADERS ="
3678   echo "noinst_LIBRARIES ="
3679   if $use_libtests; then
3680     if $for_test; then
3681       echo "noinst_LIBRARIES += libtests.a"
3682     else
3683       echo "check_LIBRARIES = libtests.a"
3684     fi
3685   fi
3686   # Automake versions < 1.11.4 create an empty pkgdatadir at
3687   # installation time if you specify pkgdata_DATA to empty.
3688   # See automake bugs #10997 and #11030:
3689   #  * http://debbugs.gnu.org/10997
3690   #  * http://debbugs.gnu.org/11030
3691   # So we need this workaround.
3692   if grep '^pkgdata_DATA *+=' "$tmp"/main_snippets "$tmp"/longrunning_snippets > /dev/null; then
3693     echo "pkgdata_DATA ="
3694   fi
3695   echo "EXTRA_DIST ="
3696   echo "BUILT_SOURCES ="
3697   echo "SUFFIXES ="
3698   echo "MOSTLYCLEANFILES = core *.stackdump"
3699   echo "MOSTLYCLEANDIRS ="
3700   echo "CLEANFILES ="
3701   echo "DISTCLEANFILES ="
3702   echo "MAINTAINERCLEANFILES ="
3703   # Execute edits that apply to the Makefile.am being generated.
3704   edit=0
3705   while test $edit != $makefile_am_edits; do
3706     edit=`expr $edit + 1`
3707     eval dir=\"\$makefile_am_edit${edit}_dir\"
3708     eval var=\"\$makefile_am_edit${edit}_var\"
3709     eval val=\"\$makefile_am_edit${edit}_val\"
3710     if test -n "$var"; then
3711       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
3712         echo "${var} += ${val}"
3713         eval "makefile_am_edit${edit}_var="
3714       fi
3715     fi
3716   done
3717   echo
3718   echo "AM_CPPFLAGS = \\"
3719   if $for_test; then
3720     echo "  -DGNULIB_STRICT_CHECKING=1 \\"
3721   fi
3722   if test -n "$witness_c_macro"; then
3723     echo "  -D$witness_c_macro=1 \\"
3724   fi
3725   if test -n "${witness_macro}"; then
3726     echo "  -D@${witness_macro}@=1 \\"
3727   fi
3728   echo "  -I. -I\$(srcdir) \\"
3729   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
3730   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
3731   echo
3732   local_ldadd_before=''
3733   local_ldadd_after=''
3734   if $use_libtests; then
3735     # All test programs need to be linked with libtests.a.
3736     # It needs to be passed to the linker before ${libname}.${libext}, since
3737     # the tests-related modules depend on the main modules.
3738     # It also needs to be passed to the linker after ${libname}.${libext}
3739     # because the latter might contain incomplete modules (such as the 'error'
3740     # module whose dependency to 'progname' is voluntarily omitted).
3741     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
3742     # not matter.
3743     local_ldadd_before=' libtests.a'
3744     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
3745   fi
3746   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
3747   echo
3748   if $use_libtests; then
3749     echo "libtests_a_SOURCES ="
3750     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
3751     # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
3752     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
3753     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
3754     echo "EXTRA_libtests_a_SOURCES ="
3755     # The circular dependency in LDADD requires this.
3756     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
3757     echo
3758   fi
3759   # Many test scripts use ${EXEEXT} or ${srcdir}.
3760   # EXEEXT is defined by AC_PROG_CC through autoconf.
3761   # srcdir is defined by autoconf and automake.
3762   echo "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='\$(srcdir)'"
3763   echo
3764   cat "$tmp"/main_snippets "$tmp"/longrunning_snippets \
3765     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
3766   echo "# Clean up after Solaris cc."
3767   echo "clean-local:"
3768   echo "        rm -rf SunWS_cache"
3769   echo
3770   echo "mostlyclean-local: mostlyclean-generic"
3771   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
3772   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
3773   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
3774   echo "          fi; \\"
3775   echo "        done; \\"
3776   echo "        :"
3777   rm -f "$tmp"/main_snippets "$tmp"/longrunning_snippets
3778 }
3779
3780 # func_emit_initmacro_start macro_prefix
3781 # emits the first few statements of the gl_INIT macro to standard output.
3782 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3783 func_emit_initmacro_start ()
3784 {
3785   macro_prefix_arg="$1"
3786   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
3787   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
3788   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
3789   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
3790   # flexibility.)
3791   # Furthermore it avoids an automake error like this when a Makefile.am
3792   # that uses pieces of gnulib also uses $(LIBOBJ):
3793   #   automatically discovered file `error.c' should not be explicitly mentioned
3794   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
3795   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
3796   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
3797   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
3798   #   automatically discovered file `error.c' should not be explicitly mentioned
3799   # We let automake know about the files to be distributed through the
3800   # EXTRA_lib_SOURCES variable.
3801   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
3802   # Create data variables for checking the presence of files that are mentioned
3803   # as AC_LIBSOURCES arguments. These are m4 variables, not shell variables,
3804   # because we want the check to happen when the configure file is created,
3805   # not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the list of
3806   # files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the subdirectory
3807   # in which to expect them.
3808   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_LIST], [])"
3809   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_DIR], [])"
3810   echo "  gl_COMMON"
3811 }
3812
3813 # func_emit_initmacro_end macro_prefix
3814 # emits the last few statements of the gl_INIT macro to standard output.
3815 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3816 func_emit_initmacro_end ()
3817 {
3818   macro_prefix_arg="$1"
3819   # Check the presence of files that are mentioned as AC_LIBSOURCES arguments.
3820   # The check is performed only when autoconf is run from the directory where
3821   # the configure.ac resides; if it is run from a different directory, the
3822   # check is skipped.
3823   echo "  m4_ifval(${macro_prefix_arg}_LIBSOURCES_LIST, ["
3824   echo "    m4_syscmd([test ! -d ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
3825   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
3826   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
3827   echo "          echo \"missing file ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file\" >&2"
3828   echo "          exit 1"
3829   echo "        fi"
3830   echo "      done])dnl"
3831   echo "      m4_if(m4_sysval, [0], [],"
3832   echo "        [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])"
3833   echo "  ])"
3834   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_DIR])"
3835   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_LIST])"
3836   echo "  m4_popdef([AC_LIBSOURCES])"
3837   echo "  m4_popdef([AC_REPLACE_FUNCS])"
3838   echo "  m4_popdef([AC_LIBOBJ])"
3839   echo "  AC_CONFIG_COMMANDS_PRE(["
3840   echo "    ${macro_prefix_arg}_libobjs="
3841   echo "    ${macro_prefix_arg}_ltlibobjs="
3842   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
3843   echo "      # Remove the extension."
3844   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
3845   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed -e \"\$sed_drop_objext\" | sort | uniq\`; do"
3846   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
3847   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
3848   echo "      done"
3849   echo "    fi"
3850   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
3851   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
3852   echo "  ])"
3853 }
3854
3855 # func_emit_initmacro_done macro_prefix sourcebase
3856 # emits a few statements after the gl_INIT macro to standard output.
3857 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3858 # - sourcebase      directory relative to destdir where to place source code
3859 func_emit_initmacro_done ()
3860 {
3861   macro_prefix_arg="$1"
3862   sourcebase_arg="$2"
3863   echo
3864   echo "# Like AC_LIBOBJ, except that the module name goes"
3865   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3866   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
3867   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
3868   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
3869   echo "])"
3870   echo
3871   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
3872   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3873   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
3874   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
3875   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
3876   echo "])"
3877   echo
3878   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
3879   echo "# expected is derived from the gnulib-tool parameterization,"
3880   echo "# and alloca is special cased (for the alloca-opt module)."
3881   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
3882   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
3883   echo "  m4_foreach([_gl_NAME], [\$1], ["
3884   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
3885   echo "      m4_define([${macro_prefix_arg}_LIBSOURCES_DIR], [$sourcebase_arg])"
3886   echo "      m4_append([${macro_prefix_arg}_LIBSOURCES_LIST], _gl_NAME, [ ])"
3887   echo "    ])"
3888   echo "  ])"
3889   echo "])"
3890 }
3891
3892 # func_emit_autoconf_snippet indentation
3893 # emits the autoconf snippet of a module.
3894 # Input:
3895 # - indentation       spaces to prepend on each line
3896 # - local_gnulib_dir  from --local-dir
3897 # - modcache          true or false, from --cache-modules/--no-cache-modules
3898 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
3899 # - sed_replace_include_guard_prefix
3900 #                     sed expression for resolving ${gl_include_guard_prefix}
3901 # - module            the module name
3902 # - toplevel          true or false. 'false' means a subordinate use of
3903 #                     gnulib-tool.
3904 # - disable_libtool   true or false. It tells whether to disable libtool
3905 #                     handling even if it has been specified through the
3906 #                     command line options.
3907 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
3908 #                     invocations.
3909 func_emit_autoconf_snippet ()
3910 {
3911   indentation="$1"
3912   if { case $module in
3913          gnumakefile | maintainer-makefile)
3914            # These modules are meant to be used only in the top-level directory.
3915            $toplevel ;;
3916          *)
3917            true ;;
3918        esac
3919      }; then
3920     func_get_autoconf_snippet "$module" \
3921       | sed -e '/^$/d;' -e "s/^/$indentation/" \
3922             -e "$sed_replace_build_aux" \
3923             -e "$sed_replace_include_guard_prefix" \
3924       | { if $disable_libtool; then
3925             sed -e 's/\$gl_cond_libtool/false/g' \
3926                 -e 's/gl_libdeps/gltests_libdeps/g' \
3927                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3928           else
3929             cat
3930           fi
3931         } \
3932       | { if $disable_gettext; then
3933             sed -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
3934           else
3935             cat
3936           fi
3937         }
3938     if test "$module" = 'alloca' && test "$libtool" = true && ! $disable_libtool; then
3939       echo 'changequote(,)dnl'
3940       echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3941       echo 'changequote([, ])dnl'
3942       echo 'AC_SUBST([LTALLOCA])'
3943     fi
3944   fi
3945 }
3946
3947 # func_emit_autoconf_snippets modules verifier toplevel disable_libtool disable_gettext
3948 # collects and emit the autoconf snippets of a set of modules.
3949 # Input:
3950 # - local_gnulib_dir  from --local-dir
3951 # - modcache          true or false, from --cache-modules/--no-cache-modules
3952 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
3953 # - sed_replace_include_guard_prefix
3954 #                     sed expression for resolving ${gl_include_guard_prefix}
3955 # - modules           the list of modules.
3956 # - verifier          one of func_verify_module, func_verify_nontests_module,
3957 #                     func_verify_tests_module. It selects the subset of
3958 #                     $modules to consider.
3959 # - toplevel          true or false. 'false' means a subordinate use of
3960 #                     gnulib-tool.
3961 # - disable_libtool   true or false. It tells whether to disable libtool
3962 #                     handling even if it has been specified through the
3963 #                     command line options.
3964 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
3965 #                     invocations.
3966 func_emit_autoconf_snippets ()
3967 {
3968   verifier="$2"
3969   toplevel="$3"
3970   disable_libtool="$4"
3971   disable_gettext="$5"
3972   if test "$cond_dependencies" = true; then
3973     for m in $modules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/modules
3974     # Emit the autoconf code for the unconditional modules.
3975     for module in $1; do
3976       eval $verifier
3977       if test -n "$module"; then
3978         if func_cond_module_p "$module"; then
3979           :
3980         else
3981           func_emit_autoconf_snippet "  "
3982         fi
3983       fi
3984     done
3985     # Initialize the shell variables indicating that the modules are enabled.
3986     for module in $1; do
3987       eval $verifier
3988       if test -n "$module"; then
3989         if func_cond_module_p "$module"; then
3990           func_module_shellvar_name "$module"
3991           echo "  $shellvar=false"
3992         fi
3993       fi
3994     done
3995     # Emit the autoconf code for the conditional modules, each in a separate
3996     # function. This makes it possible to support cycles among conditional
3997     # modules.
3998     for module in $1; do
3999       eval $verifier
4000       if test -n "$module"; then
4001         if func_cond_module_p "$module"; then
4002           func_module_shellfunc_name "$module"
4003           func_module_shellvar_name "$module"
4004           echo "  $shellfunc ()"
4005           echo '  {'
4006           echo "    if ! \$$shellvar; then"
4007           func_emit_autoconf_snippet "      "
4008           echo "      $shellvar=true"
4009           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
4010           # Intersect $deps with the modules list $1.
4011           deps=`for m in $deps; do echo $m; done | LC_ALL=C sort -u | LC_ALL=C join - "$tmp"/modules`
4012           for dep in $deps; do
4013             if func_cond_module_p "$dep"; then
4014               func_module_shellfunc_name "$dep"
4015               func_cond_module_condition "$module" "$dep"
4016               if test "$condition" != true; then
4017                 echo "      if $condition; then"
4018                 echo "        $shellfunc"
4019                 echo '      fi'
4020               else
4021                 echo "      $shellfunc"
4022               fi
4023             else
4024               # The autoconf code for $dep has already been emitted above and
4025               # therefore is already executed when this function is run.
4026               :
4027             fi
4028           done
4029           echo '    fi'
4030           echo '  }'
4031         fi
4032       fi
4033     done
4034     # Emit the dependencies from the unconditional to the conditional modules.
4035     for module in $1; do
4036       eval $verifier
4037       if test -n "$module"; then
4038         if func_cond_module_p "$module"; then
4039           :
4040         else
4041           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
4042           # Intersect $deps with the modules list $1.
4043           deps=`for m in $deps; do echo $m; done | LC_ALL=C sort -u | LC_ALL=C join - "$tmp"/modules`
4044           for dep in $deps; do
4045             if func_cond_module_p "$dep"; then
4046               func_module_shellfunc_name "$dep"
4047               func_cond_module_condition "$module" "$dep"
4048               if test "$condition" != true; then
4049                 echo "  if $condition; then"
4050                 echo "    $shellfunc"
4051                 echo '  fi'
4052               else
4053                 echo "  $shellfunc"
4054               fi
4055             else
4056               # The autoconf code for $dep has already been emitted above and
4057               # therefore is already executed when this code is run.
4058               :
4059             fi
4060           done
4061         fi
4062       fi
4063     done
4064     # Define the Automake conditionals.
4065     echo "  m4_pattern_allow([^${macro_prefix}_GNULIB_ENABLED_])"
4066     for module in $1; do
4067       eval $verifier
4068       if test -n "$module"; then
4069         if func_cond_module_p "$module"; then
4070           func_module_conditional_name "$module"
4071           func_module_shellvar_name "$module"
4072           echo "  AM_CONDITIONAL([$conditional], [\$$shellvar])"
4073         fi
4074       fi
4075     done
4076   else
4077     # Ignore the conditions, and enable all modules unconditionally.
4078     for module in $1; do
4079       eval $verifier
4080       if test -n "$module"; then
4081         func_emit_autoconf_snippet "  "
4082       fi
4083     done
4084   fi
4085 }
4086
4087 # func_import modules
4088 # Uses also the variables
4089 # - mode            import or add-import or remove-import or update
4090 # - destdir         target directory
4091 # - local_gnulib_dir  from --local-dir
4092 # - modcache        true or false, from --cache-modules/--no-cache-modules
4093 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
4094 # - libname         library name
4095 # - supplied_libname  true if --lib was given, blank otherwise
4096 # - sourcebase      directory relative to destdir where to place source code
4097 # - m4base          directory relative to destdir where to place *.m4 macros
4098 # - pobase          directory relative to destdir where to place *.po files
4099 # - docbase         directory relative to destdir where to place doc files
4100 # - testsbase       directory relative to destdir where to place unit test code
4101 # - auxdir          directory relative to destdir where to place build aux files
4102 # - inctests        true if --with-tests was given, false otherwise
4103 # - incobsolete     true if --with-obsolete was given, blank otherwise
4104 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
4105 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
4106 #                          otherwise
4107 # - inc_privileged_tests  true if --with-privileged-tests was given, blank
4108 #                         otherwise
4109 # - inc_unportable_tests  true if --with-unportable-tests was given, blank
4110 #                         otherwise
4111 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
4112 # - avoidlist       list of modules to avoid, from --avoid
4113 # - cond_dependencies  true if --conditional-dependencies was given, false if
4114 #                      --no-conditional-dependencies was given, blank otherwise
4115 # - lgpl            yes or a number if library's license shall be LGPL,
4116 #                   blank otherwise
4117 # - makefile_name   from --makefile-name
4118 # - libtool         true if --libtool was given, false if --no-libtool was
4119 #                   given, blank otherwise
4120 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
4121 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
4122 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
4123 # - witness_c_macro  from --witness-c-macro
4124 # - vc_files        true if --vc-files was given, false if --no-vc-files was
4125 #                   given, blank otherwise
4126 # - autoconf_minversion  minimum supported autoconf version
4127 # - doit            : if actions shall be executed, false if only to be printed
4128 # - symbolic        true if files should be symlinked, copied otherwise
4129 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
4130 #                   copied otherwise
4131 # - do_copyrights   true if copyright notices in files should be replaced,
4132 #                   blank otherwise
4133 func_import ()
4134 {
4135   # Get the cached settings.
4136   # In 'import' mode, we read them only for the purpose of knowing the old
4137   # installed file list, and don't use them as defaults.
4138   cached_local_gnulib_dir=
4139   cached_specified_modules=
4140   cached_incobsolete=
4141   cached_inc_cxx_tests=
4142   cached_inc_longrunning_tests=
4143   cached_inc_privileged_tests=
4144   cached_inc_unportable_tests=
4145   cached_inc_all_tests=
4146   cached_avoidlist=
4147   cached_sourcebase=
4148   cached_m4base=
4149   cached_pobase=
4150   cached_docbase=
4151   cached_testsbase=
4152   cached_inctests=
4153   cached_libname=
4154   cached_lgpl=
4155   cached_makefile_name=
4156   cached_cond_dependencies=
4157   cached_libtool=
4158   cached_macro_prefix=
4159   cached_po_domain=
4160   cached_witness_c_macro=
4161   cached_vc_files=
4162   cached_files=
4163   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
4164     cached_libtool=false
4165     my_sed_traces='
4166       s,#.*$,,
4167       s,^dnl .*$,,
4168       s, dnl .*$,,
4169       /gl_LOCAL_DIR(/ {
4170         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_dir="\1",p
4171       }
4172       /gl_MODULES(/ {
4173         ta
4174         :a
4175           s/)/)/
4176           tb
4177           N
4178           ba
4179         :b
4180         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
4181       }
4182       /gl_WITH_OBSOLETE/ {
4183         s,^.*$,cached_incobsolete=true,p
4184       }
4185       /gl_WITH_CXX_TESTS/ {
4186         s,^.*$,cached_inc_cxx_tests=true,p
4187       }
4188       /gl_WITH_LONGRUNNING_TESTS/ {
4189         s,^.*$,cached_inc_longrunning_tests=true,p
4190       }
4191       /gl_WITH_PRIVILEGED_TESTS/ {
4192         s,^.*$,cached_inc_privileged_tests=true,p
4193       }
4194       /gl_WITH_UNPORTABLE_TESTS/ {
4195         s,^.*$,cached_inc_unportable_tests=true,p
4196       }
4197       /gl_WITH_ALL_TESTS/ {
4198         s,^.*$,cached_inc_all_tests=true,p
4199       }
4200       /gl_AVOID(/ {
4201         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
4202       }
4203       /gl_SOURCE_BASE(/ {
4204         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
4205       }
4206       /gl_M4_BASE(/ {
4207         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
4208       }
4209       /gl_PO_BASE(/ {
4210         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
4211       }
4212       /gl_DOC_BASE(/ {
4213         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
4214       }
4215       /gl_TESTS_BASE(/ {
4216         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
4217       }
4218       /gl_WITH_TESTS/ {
4219         s,^.*$,cached_inctests=true,p
4220       }
4221       /gl_LIB(/ {
4222         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
4223       }
4224       /gl_LGPL(/ {
4225         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
4226       }
4227       /gl_LGPL/ {
4228         s,^.*$,cached_lgpl=yes,p
4229       }
4230       /gl_MAKEFILE_NAME(/ {
4231         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
4232       }
4233       /gl_CONDITIONAL_DEPENDENCIES/ {
4234         s,^.*$,cached_cond_dependencies=true,p
4235       }
4236       /gl_LIBTOOL/ {
4237         s,^.*$,cached_libtool=true,p
4238       }
4239       /gl_MACRO_PREFIX(/ {
4240         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
4241       }
4242       /gl_PO_DOMAIN(/ {
4243         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
4244       }
4245       /gl_WITNESS_C_MACRO(/ {
4246         s,^.*gl_WITNESS_C_MACRO([[ ]*\([^]"$`\\)]*\).*$,cached_witness_c_macro="\1",p
4247       }
4248       /gl_VC_FILES(/ {
4249         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
4250       }'
4251     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
4252     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
4253       my_sed_traces='
4254         s,#.*$,,
4255         s,^dnl .*$,,
4256         s, dnl .*$,,
4257         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
4258           s,^.*$,cached_files=",p
4259           n
4260           ta
4261           :a
4262           s,^\]).*$,",
4263           tb
4264           s,["$`\\],,g
4265           p
4266           n
4267           ba
4268           :b
4269           p
4270         }'
4271       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
4272     fi
4273   fi
4274
4275   if test "$mode" = import; then
4276     # In 'import' mode, the new set of specified modules overrides the cached
4277     # set of modules. Ignore the cached settings.
4278     specified_modules="$1"
4279   else
4280     # Merge the cached settings with the specified ones.
4281     # The m4base must be the same as expected from the pathname.
4282     if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
4283       func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
4284     fi
4285     # The local_gnulib_dir defaults to the cached one. Recall that the cached one
4286     # is relative to $destdir, whereas the one we use is relative to . or absolute.
4287     if test -z "$local_gnulib_dir"; then
4288       if test -n "$cached_local_gnulib_dir"; then
4289         case "$destdir" in
4290           /*)
4291             local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
4292           *)
4293             case "$cached_local_gnulib_dir" in
4294               /*)
4295                 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
4296               *)
4297                 func_relconcat "$destdir" "$cached_local_gnulib_dir"
4298                 local_gnulib_dir="$relconcat" ;;
4299             esac ;;
4300         esac
4301       fi
4302     fi
4303     case $mode in
4304       add-import)
4305         # Append the cached and the specified module names. So that
4306         # "gnulib-tool --add-import foo" means to add the module foo.
4307         specified_modules="$cached_specified_modules $1"
4308         ;;
4309       remove-import)
4310         # Take the cached module names, minus the specified module names.
4311         specified_modules=
4312         if $have_associative; then
4313           # Use an associative array, for O(N) worst-case run time.
4314           declare -A to_remove
4315           for m in $1; do
4316             eval 'to_remove[$m]=yes'
4317           done
4318           for module in $cached_specified_modules; do
4319             if eval 'test -z "${to_remove[$module]}"'; then
4320               func_append specified_modules "$module "
4321             fi
4322           done
4323         else
4324           # This loop has O(N²) worst-case run time.
4325           for module in $cached_specified_modules; do
4326             to_remove=
4327             for m in $1; do
4328               if test "$m" = "$module"; then
4329                 to_remove=yes
4330                 break
4331               fi
4332             done
4333             if test -z "$to_remove"; then
4334               func_append specified_modules "$module "
4335             fi
4336           done
4337         fi
4338         ;;
4339       update)
4340         # Take the cached module names. There are no specified module names.
4341         specified_modules="$cached_specified_modules"
4342         ;;
4343     esac
4344     # Included obsolete modules among the dependencies if specified either way.
4345     if test -z "$incobsolete"; then
4346       incobsolete="$cached_incobsolete"
4347     fi
4348     # Included special kinds of tests modules among the dependencies if specified
4349     # either way.
4350     if test -z "$inc_cxx_tests"; then
4351       inc_cxx_tests="$cached_inc_cxx_tests"
4352     fi
4353     if test -z "$inc_longrunning_tests"; then
4354       inc_longrunning_tests="$cached_inc_longrunning_tests"
4355     fi
4356     if test -z "$inc_privileged_tests"; then
4357       inc_privileged_tests="$cached_inc_privileged_tests"
4358     fi
4359     if test -z "$inc_unportable_tests"; then
4360       inc_unportable_tests="$cached_inc_unportable_tests"
4361     fi
4362     if test -z "$inc_all_tests"; then
4363       inc_all_tests="$cached_inc_all_tests"
4364     fi
4365     # Append the cached and the specified avoidlist. This is probably better
4366     # than dropping the cached one when --avoid is specified at least once.
4367     avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
4368     avoidlist=`echo $avoidlist`
4369
4370     # The sourcebase defaults to the cached one.
4371     if test -z "$sourcebase"; then
4372       sourcebase="$cached_sourcebase"
4373       if test -z "$sourcebase"; then
4374         func_fatal_error "missing --source-base option"
4375       fi
4376     fi
4377     # The pobase defaults to the cached one.
4378     if test -z "$pobase"; then
4379       pobase="$cached_pobase"
4380     fi
4381     # The docbase defaults to the cached one.
4382     if test -z "$docbase"; then
4383       docbase="$cached_docbase"
4384       if test -z "$docbase"; then
4385         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."
4386       fi
4387     fi
4388     # The testsbase defaults to the cached one.
4389     if test -z "$testsbase"; then
4390       testsbase="$cached_testsbase"
4391       if test -z "$testsbase"; then
4392         func_fatal_error "missing --tests-base option"
4393       fi
4394     fi
4395     # Require the tests if specified either way.
4396     if ! $inctests; then
4397       inctests="$cached_inctests"
4398       if test -z "$inctests"; then
4399         inctests=false
4400       fi
4401     fi
4402     # The libname defaults to the cached one.
4403     if test -z "$supplied_libname"; then
4404       libname="$cached_libname"
4405       if test -z "$libname"; then
4406         func_fatal_error "missing --lib option"
4407       fi
4408     fi
4409     # Require LGPL if specified either way.
4410     if test -z "$lgpl"; then
4411       lgpl="$cached_lgpl"
4412     fi
4413     # The makefile_name defaults to the cached one.
4414     if test -z "$makefile_name"; then
4415       makefile_name="$cached_makefile_name"
4416     fi
4417     # Use conditional dependencies if specified either way.
4418     if test -z "$cond_dependencies"; then
4419       cond_dependencies="$cached_cond_dependencies"
4420     fi
4421     # Use libtool if specified either way, or if guessed.
4422     if test -z "$libtool"; then
4423       if test -n "$cached_m4base"; then
4424         libtool="$cached_libtool"
4425       else
4426         libtool="$guessed_libtool"
4427       fi
4428     fi
4429     # The macro_prefix defaults to the cached one.
4430     if test -z "$macro_prefix"; then
4431       macro_prefix="$cached_macro_prefix"
4432       if test -z "$macro_prefix"; then
4433         func_fatal_error "missing --macro-prefix option"
4434       fi
4435     fi
4436     # The po_domain defaults to the cached one.
4437     if test -z "$po_domain"; then
4438       po_domain="$cached_po_domain"
4439     fi
4440     # The witness_c_macro defaults to the cached one.
4441     if test -z "$witness_c_macro"; then
4442       witness_c_macro="$cached_witness_c_macro"
4443     fi
4444     # The vc_files defaults to the cached one.
4445     if test -z "$vc_files"; then
4446       vc_files="$cached_vc_files"
4447     fi
4448     # Ensure constraints.
4449     if test "$cond_dependencies" = true && $inctests; then
4450       echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
4451       func_exit 1
4452     fi
4453   fi
4454   # --without-*-tests options are not supported here.
4455   excl_cxx_tests=
4456   excl_longrunning_tests=
4457   excl_privileged_tests=
4458   excl_unportable_tests=
4459
4460   # Canonicalize the list of specified modules.
4461   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
4462
4463   # Include all kinds of tests modules if --with-all-tests was specified.
4464   inc_all_direct_tests="$inc_all_tests"
4465   inc_all_indirect_tests="$inc_all_tests"
4466
4467   # Determine final module list.
4468   modules="$specified_modules"
4469   func_modules_transitive_closure
4470   if test $verbose -ge 0; then
4471     func_show_module_list
4472   fi
4473   final_modules="$modules"
4474
4475   # Determine main module list and tests-related module list separately.
4476   func_modules_transitive_closure_separately
4477
4478   # Determine whether a $testsbase/libtests.a is needed.
4479   func_determine_use_libtests
4480
4481   # Add the dummy module to the main module list or to the tests-related module
4482   # list if needed.
4483   func_modules_add_dummy_separately
4484
4485   # If --lgpl, verify that the licenses of modules are compatible.
4486   if test -n "$lgpl"; then
4487     license_incompatibilities=
4488     for module in $main_modules; do
4489       license=`func_get_license $module`
4490       case $license in
4491         'GPLed build tool') ;;
4492         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
4493         *)
4494           case "$lgpl" in
4495             yes | 3)
4496               case $license in
4497                 LGPL | LGPLv2+ | LGPLv3+) ;;
4498                 *) func_append license_incompatibilities "$module $license$nl" ;;
4499               esac
4500               ;;
4501             2)
4502               case $license in
4503                 LGPLv2+) ;;
4504                 *) func_append license_incompatibilities "$module $license$nl" ;;
4505               esac
4506               ;;
4507             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
4508           esac
4509           ;;
4510       esac
4511     done
4512     if test -n "$license_incompatibilities"; then
4513       # Format the license incompatibilities as a table.
4514       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
4515 s,^\(.................................................[^ ]*\) *,                 \1 ,'
4516       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
4517       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
4518     fi
4519   fi
4520
4521   # Show banner notice of every module.
4522   modules="$main_modules"
4523   func_modules_notice
4524
4525   # Determine script to apply to imported library files.
4526   sed_transform_lib_file=
4527   for module in $main_modules; do
4528     if test $module = config-h; then
4529       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
4530       sed_transform_lib_file=$sed_transform_lib_file'
4531         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
4532       '
4533       break
4534     fi
4535   done
4536   sed_transform_main_lib_file="$sed_transform_lib_file"
4537   if test -n "$do_copyrights"; then
4538     if test -n "$lgpl"; then
4539       # Update license.
4540       case "$lgpl" in
4541         yes | 3)
4542           sed_transform_main_lib_file=$sed_transform_main_lib_file'
4543             s/GNU General/GNU Lesser General/g
4544             s/General Public License/Lesser General Public License/g
4545             s/Lesser Lesser General Public License/Lesser General Public License/g
4546           '
4547           ;;
4548         2)
4549           sed_transform_main_lib_file=$sed_transform_main_lib_file'
4550             s/GNU General/GNU Lesser General/g
4551             s/General Public License/Lesser General Public License/g
4552             s/Lesser Lesser General Public License/Lesser General Public License/g
4553
4554             s/version [23]\([ ,]\)/version 2.1\1/g
4555           '
4556           ;;
4557         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
4558       esac
4559     else
4560       # Update license.
4561       sed_transform_main_lib_file=$sed_transform_main_lib_file'
4562         s/GNU Lesser General/GNU General/g
4563         s/Lesser General Public License/General Public License/g
4564
4565         s/GNU Library General/GNU General/g
4566         s/Library General Public License/General Public License/g
4567
4568         s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4569       '
4570     fi
4571   fi
4572
4573   # Determine script to apply to auxiliary files that go into $auxdir/.
4574   sed_transform_build_aux_file=
4575   if test -n "$do_copyrights"; then
4576     # Update license.
4577     sed_transform_build_aux_file=$sed_transform_build_aux_file'
4578       s/GNU Lesser General/GNU General/g
4579       s/Lesser General Public License/General Public License/g
4580
4581       s/GNU Library General/GNU General/g
4582       s/Library General Public License/General Public License/g
4583
4584       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4585     '
4586   fi
4587
4588   # Determine script to apply to library files that go into $testsbase/.
4589   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
4590   if test -n "$do_copyrights"; then
4591     # Update license.
4592     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
4593       s/GNU Lesser General/GNU General/g
4594       s/Lesser General Public License/General Public License/g
4595
4596       s/GNU Library General/GNU General/g
4597       s/Library General Public License/General Public License/g
4598
4599       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4600     '
4601   fi
4602
4603   # Determine the final file lists.
4604   func_modules_to_filelist_separately
4605
4606   test -n "$files" \
4607     || func_fatal_error "refusing to do nothing"
4608
4609   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
4610   new_files="$files m4/gnulib-tool.m4"
4611   old_files="$cached_files"
4612   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
4613     func_append old_files " m4/gnulib-tool.m4"
4614   fi
4615
4616   rewritten='%REWRITTEN%'
4617   sed_rewrite_old_files="\
4618     s,^build-aux/,$rewritten$auxdir/,
4619     s,^doc/,$rewritten$cached_docbase/,
4620     s,^lib/,$rewritten$cached_sourcebase/,
4621     s,^m4/,$rewritten$cached_m4base/,
4622     s,^tests/,$rewritten$cached_testsbase/,
4623     s,^tests=lib/,$rewritten$cached_testsbase/,
4624     s,^top/,$rewritten,
4625     s,^$rewritten,,"
4626   sed_rewrite_new_files="\
4627     s,^build-aux/,$rewritten$auxdir/,
4628     s,^doc/,$rewritten$docbase/,
4629     s,^lib/,$rewritten$sourcebase/,
4630     s,^m4/,$rewritten$m4base/,
4631     s,^tests/,$rewritten$testsbase/,
4632     s,^tests=lib/,$rewritten$testsbase/,
4633     s,^top/,$rewritten,
4634     s,^$rewritten,,"
4635
4636   # Create directories.
4637   { echo "$sourcebase"
4638     echo "$m4base"
4639     if test -n "$pobase"; then
4640       echo "$pobase"
4641     fi
4642     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
4643     if test -n "$docfiles"; then
4644       echo "$docbase"
4645     fi
4646     if $inctests; then
4647       echo "$testsbase"
4648     fi
4649     echo "$auxdir"
4650     for f in $files; do echo $f; done \
4651       | sed -e "$sed_rewrite_new_files" \
4652       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
4653       | LC_ALL=C sort -u
4654   } > "$tmp"/dirs
4655   { # Rearrange file descriptors. Needed because "while ... done < ..."
4656     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4657     exec 5<&0 < "$tmp"/dirs
4658     while read d; do
4659       if test ! -d "$destdir/$d"; then
4660         if $doit; then
4661           echo "Creating directory $destdir/$d"
4662           mkdir -p "$destdir/$d" || func_fatal_error "failed"
4663         else
4664           echo "Create directory $destdir/$d"
4665         fi
4666       fi
4667     done
4668     exec 0<&5 5<&-
4669   }
4670
4671   # Copy files or make symbolic links. Remove obsolete files.
4672   added_files=''
4673   removed_files=''
4674   delimiter='   '
4675   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4676   # representing the files according to the last gnulib-tool invocation.
4677   for f in $old_files; do echo $f; done \
4678     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
4679     | LC_ALL=C sort \
4680     > "$tmp"/old-files
4681   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4682   # representing the files after this gnulib-tool invocation.
4683   for f in $new_files; do echo $f; done \
4684     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
4685     | LC_ALL=C sort \
4686     > "$tmp"/new-files
4687   # First the files that are in old-files, but not in new-files:
4688   sed_take_first_column='s,'"$delimiter"'.*,,'
4689   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
4690     # Remove the file. Do nothing if the user already removed it.
4691     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
4692       if $doit; then
4693         echo "Removing file $g (backup in ${g}~)"
4694         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
4695       else
4696         echo "Remove file $g (backup in ${g}~)"
4697       fi
4698       func_append removed_files "$g$nl"
4699     fi
4700   done
4701   # func_add_or_update handles a file that ought to be present afterwards.
4702   # Uses parameters
4703   # - f             the original file name
4704   # - g             the rewritten file name
4705   # - already_present  nonempty if the file should already exist, empty
4706   #                    otherwise
4707   func_add_or_update ()
4708   {
4709     of="$f"
4710     case "$f" in
4711       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
4712     esac
4713     func_dest_tmpfilename "$g"
4714     func_lookup_file "$f"
4715     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
4716     if test -n "$sed_transform_main_lib_file"; then
4717       case "$of" in
4718         lib/*)
4719           sed -e "$sed_transform_main_lib_file" \
4720             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4721           ;;
4722       esac
4723     fi
4724     if test -n "$sed_transform_build_aux_file"; then
4725       case "$of" in
4726         build-aux/*)
4727           sed -e "$sed_transform_build_aux_file" \
4728             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4729           ;;
4730       esac
4731     fi
4732     if test -n "$sed_transform_testsrelated_lib_file"; then
4733       case "$of" in
4734         tests=lib/*)
4735           sed -e "$sed_transform_testsrelated_lib_file" \
4736             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4737           ;;
4738       esac
4739     fi
4740     if test -f "$destdir/$g"; then
4741       # The file already exists.
4742       func_update_file
4743     else
4744       # Install the file.
4745       # Don't protest if the file should be there but isn't: it happens
4746       # frequently that developers don't put autogenerated files under version control.
4747       func_add_file
4748       func_append added_files "$g$nl"
4749     fi
4750     rm -f "$tmpfile"
4751   }
4752   # Then the files that are in new-files, but not in old-files:
4753   sed_take_last_column='s,^.*'"$delimiter"',,'
4754   already_present=
4755   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
4756     | sed -e "$sed_take_last_column" \
4757     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
4758   { # Rearrange file descriptors. Needed because "while ... done < ..."
4759     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4760     exec 5<&0 < "$tmp"/added-files
4761     while read g f; do
4762       func_add_or_update
4763     done
4764     exec 0<&5 5<&-
4765   }
4766   # Then the files that are in new-files and in old-files:
4767   already_present=true
4768   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
4769     | sed -e "$sed_take_last_column" \
4770     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
4771   { # Rearrange file descriptors. Needed because "while ... done < ..."
4772     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4773     exec 5<&0 < "$tmp"/kept-files
4774     while read g f; do
4775       func_add_or_update
4776     done
4777     exec 0<&5 5<&-
4778   }
4779
4780   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
4781   actioncmd="gnulib-tool --import"
4782   func_append actioncmd " --dir=$destdir"
4783   if test -n "$local_gnulib_dir"; then
4784     func_append actioncmd " --local-dir=$local_gnulib_dir"
4785   fi
4786   func_append actioncmd " --lib=$libname"
4787   func_append actioncmd " --source-base=$sourcebase"
4788   func_append actioncmd " --m4-base=$m4base"
4789   if test -n "$pobase"; then
4790     func_append actioncmd " --po-base=$pobase"
4791   fi
4792   func_append actioncmd " --doc-base=$docbase"
4793   func_append actioncmd " --tests-base=$testsbase"
4794   func_append actioncmd " --aux-dir=$auxdir"
4795   if $inctests; then
4796     func_append actioncmd " --with-tests"
4797   fi
4798   if test -n "$incobsolete"; then
4799     func_append actioncmd " --with-obsolete"
4800   fi
4801   if test -n "$inc_cxx_tests"; then
4802     func_append actioncmd " --with-c++-tests"
4803   fi
4804   if test -n "$inc_longrunning_tests"; then
4805     func_append actioncmd " --with-longrunning-tests"
4806   fi
4807   if test -n "$inc_privileged_tests"; then
4808     func_append actioncmd " --with-privileged-tests"
4809   fi
4810   if test -n "$inc_unportable_tests"; then
4811     func_append actioncmd " --with-unportable-tests"
4812   fi
4813   if test -n "$inc_all_tests"; then
4814     func_append actioncmd " --with-all-tests"
4815   fi
4816   for module in $avoidlist; do
4817     func_append actioncmd " --avoid=$module"
4818   done
4819   if test -n "$lgpl"; then
4820     if test "$lgpl" = yes; then
4821       func_append actioncmd " --lgpl"
4822     else
4823       func_append actioncmd " --lgpl=$lgpl"
4824     fi
4825   fi
4826   if test -n "$makefile_name"; then
4827     func_append actioncmd " --makefile-name=$makefile_name"
4828   fi
4829   if test "$cond_dependencies" = true; then
4830     func_append actioncmd " --conditional-dependencies"
4831   else
4832     func_append actioncmd " --no-conditional-dependencies"
4833   fi
4834   if test "$libtool" = true; then
4835     func_append actioncmd " --libtool"
4836   else
4837     func_append actioncmd " --no-libtool"
4838   fi
4839   func_append actioncmd " --macro-prefix=$macro_prefix"
4840   if test -n "$po_domain"; then
4841     func_append actioncmd " --po-domain=$po_domain"
4842   fi
4843   if test -n "$witness_c_macro"; then
4844     func_append actioncmd " --witness-c-macro=$witness_c_macro"
4845   fi
4846   if test -n "$vc_files"; then
4847     if test "$vc_files" = true; then
4848       func_append actioncmd " --vc-files"
4849     else
4850       func_append actioncmd " --no-vc-files"
4851     fi
4852   fi
4853   func_append actioncmd " `echo $specified_modules`"
4854
4855   # Determine include_guard_prefix.
4856   func_compute_include_guard_prefix
4857
4858   # Default the makefile name to Makefile.am.
4859   if test -n "$makefile_name"; then
4860     makefile_am=$makefile_name
4861   else
4862     makefile_am=Makefile.am
4863   fi
4864
4865   # Create normal Makefile.ams.
4866   for_test=false
4867
4868   # Setup list of Makefile.am edits that are to be performed afterwards.
4869   # Some of these edits apply to files that we will generate; others are
4870   # under the responsibility of the developer.
4871   makefile_am_edits=0
4872   # func_note_Makefile_am_edit dir var value
4873   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
4874   # ${value}.
4875   func_note_Makefile_am_edit ()
4876   {
4877     makefile_am_edits=`expr $makefile_am_edits + 1`
4878     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
4879     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
4880     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
4881   }
4882   if test "$makefile_am" = Makefile.am; then
4883     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
4884     sourcebase_base=`basename "$sourcebase"`
4885     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
4886   fi
4887   if test -n "$pobase"; then
4888     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
4889     pobase_base=`basename "$pobase"`
4890     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
4891   fi
4892   if $inctests; then
4893     if test "$makefile_am" = Makefile.am; then
4894       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
4895       testsbase_base=`basename "$testsbase"`
4896       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
4897     fi
4898   fi
4899   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
4900   {
4901     # Find the first parent directory of $m4base that contains or will contain
4902     # a Makefile.am.
4903     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
4904 s,//*$,/,'
4905     sed_butlast='s,[^/][^/]*//*$,,'
4906     dir1="${m4base}/"; dir2=""
4907     while test -n "$dir1" \
4908           && ! { test -f "${destdir}/${dir1}Makefile.am" \
4909                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4910                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4911                  || { $inctests \
4912                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
4913                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
4914       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
4915       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
4916     done
4917     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
4918   }
4919
4920   # Create library makefile.
4921   func_dest_tmpfilename $sourcebase/$makefile_am
4922   destfile="$sourcebase/$makefile_am"
4923   modules="$main_modules"
4924   func_emit_lib_Makefile_am > "$tmpfile"
4925   if test -f "$destdir"/$sourcebase/$makefile_am; then
4926     if cmp -s "$destdir"/$sourcebase/$makefile_am "$tmpfile"; then
4927       rm -f "$tmpfile"
4928     else
4929       if $doit; then
4930         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4931         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
4932         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4933       else
4934         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4935         rm -f "$tmpfile"
4936       fi
4937     fi
4938   else
4939     if $doit; then
4940       echo "Creating $sourcebase/$makefile_am"
4941       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4942     else
4943       echo "Create $sourcebase/$makefile_am"
4944       rm -f "$tmpfile"
4945     fi
4946     func_append added_files "$sourcebase/$makefile_am$nl"
4947   fi
4948
4949   # Create po/ directory.
4950   if test -n "$pobase"; then
4951     # Create po makefile and auxiliary files.
4952     for file in Makefile.in.in remove-potcdate.sin; do
4953       func_dest_tmpfilename $pobase/$file
4954       func_lookup_file build-aux/po/$file
4955       cat "$lookedup_file" > "$tmpfile"
4956       if test -f "$destdir"/$pobase/$file; then
4957         if cmp -s "$destdir"/$pobase/$file "$tmpfile"; then
4958           rm -f "$tmpfile"
4959         else
4960           if $doit; then
4961             echo "Updating $pobase/$file (backup in $pobase/$file~)"
4962             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
4963             mv -f "$tmpfile" "$destdir"/$pobase/$file
4964           else
4965             echo "Update $pobase/$file (backup in $pobase/$file~)"
4966             rm -f "$tmpfile"
4967           fi
4968         fi
4969       else
4970         if $doit; then
4971           echo "Creating $pobase/$file"
4972           mv -f "$tmpfile" "$destdir"/$pobase/$file
4973         else
4974           echo "Create $pobase/$file"
4975           rm -f "$tmpfile"
4976         fi
4977         func_append added_files "$pobase/$file$nl"
4978       fi
4979     done
4980     # Create po makefile parameterization, part 1.
4981     func_dest_tmpfilename $pobase/Makevars
4982     func_emit_po_Makevars > "$tmpfile"
4983     if test -f "$destdir"/$pobase/Makevars; then
4984       if cmp -s "$destdir"/$pobase/Makevars "$tmpfile"; then
4985         rm -f "$tmpfile"
4986       else
4987         if $doit; then
4988           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
4989           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
4990           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4991         else
4992           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
4993           rm -f "$tmpfile"
4994         fi
4995       fi
4996     else
4997       if $doit; then
4998         echo "Creating $pobase/Makevars"
4999         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
5000       else
5001         echo "Create $pobase/Makevars"
5002         rm -f "$tmpfile"
5003       fi
5004       func_append added_files "$pobase/Makevars$nl"
5005     fi
5006     # Create po makefile parameterization, part 2.
5007     func_dest_tmpfilename $pobase/POTFILES.in
5008     func_emit_po_POTFILES_in > "$tmpfile"
5009     if test -f "$destdir"/$pobase/POTFILES.in; then
5010       if cmp -s "$destdir"/$pobase/POTFILES.in "$tmpfile"; then
5011         rm -f "$tmpfile"
5012       else
5013         if $doit; then
5014           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
5015           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
5016           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
5017         else
5018           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
5019           rm -f "$tmpfile"
5020         fi
5021       fi
5022     else
5023       if $doit; then
5024         echo "Creating $pobase/POTFILES.in"
5025         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
5026       else
5027         echo "Create $pobase/POTFILES.in"
5028         rm -f "$tmpfile"
5029       fi
5030       func_append added_files "$pobase/POTFILES.in$nl"
5031     fi
5032     # Fetch PO files.
5033     TP_URL="http://translationproject.org/latest/"
5034     TP_RSYNC_URI="translationproject.org::tp/latest/"
5035     if $doit; then
5036       echo "Fetching gnulib PO files from $TP_URL"
5037       (cd "$destdir"/$pobase \
5038        && { # Prefer rsync over wget if it is available, since it consumes
5039             # less network bandwidth, due to compression.
5040             if type rsync 2>/dev/null | grep / > /dev/null; then
5041               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
5042             else
5043               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
5044             fi
5045           }
5046       )
5047     else
5048       echo "Fetch gnulib PO files from $TP_URL"
5049     fi
5050     # Create po/LINGUAS.
5051     if $doit; then
5052       func_dest_tmpfilename $pobase/LINGUAS
5053       (cd "$destdir"/$pobase \
5054        && { echo '# Set of available languages.'
5055             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
5056           }
5057       ) > "$tmpfile"
5058       if test -f "$destdir"/$pobase/LINGUAS; then
5059         if cmp -s "$destdir"/$pobase/LINGUAS "$tmpfile"; then
5060           rm -f "$tmpfile"
5061         else
5062           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
5063           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
5064           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
5065         fi
5066       else
5067         echo "Creating $pobase/LINGUAS"
5068         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
5069         func_append added_files "$pobase/LINGUAS$nl"
5070       fi
5071     else
5072       if test -f "$destdir"/$pobase/LINGUAS; then
5073         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
5074       else
5075         echo "Create $pobase/LINGUAS"
5076       fi
5077     fi
5078   fi
5079
5080   # Create m4/gnulib-cache.m4.
5081   func_dest_tmpfilename $m4base/gnulib-cache.m4
5082   (
5083     func_emit_copyright_notice
5084     echo "#"
5085     echo "# This file represents the specification of how gnulib-tool is used."
5086     echo "# It acts as a cache: It is written and read by gnulib-tool."
5087     echo "# In projects that use version control, this file is meant to be put under"
5088     echo "# version control, like the configure.ac and various Makefile.am files."
5089     echo
5090     echo
5091     echo "# Specification in the form of a command-line invocation:"
5092     echo "#   $actioncmd"
5093     echo
5094     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
5095     # Store the local_gnulib_dir relative to destdir.
5096     case "$local_gnulib_dir" in
5097       "" | /*)
5098         relative_local_gnulib_dir="$local_gnulib_dir" ;;
5099       * )
5100         case "$destdir" in
5101           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
5102           *)
5103             # destdir, local_gnulib_dir are both relative.
5104             func_relativize "$destdir" "$local_gnulib_dir"
5105             relative_local_gnulib_dir="$reldir" ;;
5106         esac ;;
5107     esac
5108     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
5109     echo "gl_MODULES(["
5110     echo "$specified_modules" | sed -e 's/^/  /g'
5111     echo "])"
5112     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
5113     test -z "$inc_cxx_tests" || echo "gl_WITH_CXX_TESTS"
5114     test -z "$inc_longrunning_tests" || echo "gl_WITH_LONGRUNNING_TESTS"
5115     test -z "$inc_privileged_tests" || echo "gl_WITH_PRIVILEGED_TESTS"
5116     test -z "$inc_unportable_tests" || echo "gl_WITH_UNPORTABLE_TESTS"
5117     test -z "$inc_all_tests" || echo "gl_WITH_ALL_TESTS"
5118     echo "gl_AVOID([$avoidlist])"
5119     echo "gl_SOURCE_BASE([$sourcebase])"
5120     echo "gl_M4_BASE([$m4base])"
5121     echo "gl_PO_BASE([$pobase])"
5122     echo "gl_DOC_BASE([$docbase])"
5123     echo "gl_TESTS_BASE([$testsbase])"
5124     if $inctests; then
5125       echo "gl_WITH_TESTS"
5126     fi
5127     echo "gl_LIB([$libname])"
5128     if test -n "$lgpl"; then
5129       if test "$lgpl" = yes; then
5130         echo "gl_LGPL"
5131       else
5132         echo "gl_LGPL([$lgpl])"
5133       fi
5134     fi
5135     echo "gl_MAKEFILE_NAME([$makefile_name])"
5136     if test "$cond_dependencies" = true; then
5137       echo "gl_CONDITIONAL_DEPENDENCIES"
5138     fi
5139     if test "$libtool" = true; then
5140       echo "gl_LIBTOOL"
5141     fi
5142     echo "gl_MACRO_PREFIX([$macro_prefix])"
5143     echo "gl_PO_DOMAIN([$po_domain])"
5144     echo "gl_WITNESS_C_MACRO([$witness_c_macro])"
5145     if test -n "$vc_files"; then
5146       echo "gl_VC_FILES([$vc_files])"
5147     fi
5148   ) > "$tmpfile"
5149   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
5150     if cmp -s "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile"; then
5151       rm -f "$tmpfile"
5152     else
5153       if $doit; then
5154         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
5155         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
5156         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
5157       else
5158         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
5159         if false; then
5160           cat "$tmpfile"
5161           echo
5162           echo "# gnulib-cache.m4 ends here"
5163         fi
5164         rm -f "$tmpfile"
5165       fi
5166     fi
5167   else
5168     if $doit; then
5169       echo "Creating $m4base/gnulib-cache.m4"
5170       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
5171     else
5172       echo "Create $m4base/gnulib-cache.m4"
5173       cat "$tmpfile"
5174       rm -f "$tmpfile"
5175     fi
5176   fi
5177
5178   # Create m4/gnulib-comp.m4.
5179   func_dest_tmpfilename $m4base/gnulib-comp.m4
5180   (
5181     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
5182     func_emit_copyright_notice
5183     echo "#"
5184     echo "# This file represents the compiled summary of the specification in"
5185     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
5186     echo "# to be invoked from configure.ac."
5187     echo "# In projects that use version control, this file can be treated like"
5188     echo "# other built files."
5189     echo
5190     echo
5191     echo "# This macro should be invoked from $configure_ac, in the section"
5192     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
5193     echo "# any checks for libraries, header files, types and library functions."
5194     echo "AC_DEFUN([${macro_prefix}_EARLY],"
5195     echo "["
5196     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5197     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5198     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5199     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5200     echo "  AC_REQUIRE([gl_PROG_AR_RANLIB])"
5201     if test -n "$uses_subdirs"; then
5202       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
5203     fi
5204     for module in $final_modules; do
5205       func_verify_module
5206       if test -n "$module"; then
5207         echo "# Code from module $module:"
5208         func_get_autoconf_early_snippet "$module"
5209       fi
5210     done \
5211       | sed -e '/^$/d;' -e 's/^/  /'
5212     echo "])"
5213     echo
5214     echo "# This macro should be invoked from $configure_ac, in the section"
5215     echo "# \"Check for header files, types and library functions\"."
5216     echo "AC_DEFUN([${macro_prefix}_INIT],"
5217     echo "["
5218     if test "$libtool" = true; then
5219       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5220       echo "  gl_cond_libtool=true"
5221     else
5222       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5223       echo "  gl_cond_libtool=false"
5224       echo "  gl_libdeps="
5225       echo "  gl_ltlibdeps="
5226     fi
5227     if test "$auxdir" != "build-aux"; then
5228       sed_replace_build_aux='
5229         :a
5230         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5231           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5232           ba
5233         }'
5234     else
5235       sed_replace_build_aux="$sed_noop"
5236     fi
5237     echo "  gl_m4_base='$m4base'"
5238     func_emit_initmacro_start $macro_prefix
5239     echo "  gl_source_base='$sourcebase'"
5240     if test -n "$witness_c_macro"; then
5241       echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$witness_c_macro])"
5242     fi
5243     func_emit_autoconf_snippets "$main_modules" func_verify_module true false true
5244     if test -n "$witness_c_macro"; then
5245       echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5246     fi
5247     echo "  # End of code from modules"
5248     func_emit_initmacro_end $macro_prefix
5249     echo "  gltests_libdeps="
5250     echo "  gltests_ltlibdeps="
5251     func_emit_initmacro_start ${macro_prefix}tests
5252     echo "  gl_source_base='$testsbase'"
5253     # Define a tests witness macro that depends on the package.
5254     # PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
5255     # See <http://lists.gnu.org/archive/html/automake/2009-05/msg00145.html>.
5256     echo "changequote(,)dnl"
5257     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"
5258     echo "changequote([, ])dnl"
5259     echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
5260     echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
5261     echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
5262     func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true true true
5263     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5264     func_emit_initmacro_end ${macro_prefix}tests
5265     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5266     # created using libtool, because libtool already handles the dependencies.
5267     if test "$libtool" != true; then
5268       libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5269       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5270       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5271       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5272       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5273     fi
5274     if $use_libtests; then
5275       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
5276       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
5277     fi
5278     echo "])"
5279     func_emit_initmacro_done $macro_prefix $sourcebase
5280     func_emit_initmacro_done ${macro_prefix}tests $testsbase
5281     echo
5282     echo "# This macro records the list of files which have been installed by"
5283     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
5284     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
5285     echo "$files" | sed -e 's,^,  ,'
5286     echo "])"
5287   ) > "$tmpfile"
5288   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
5289     if cmp -s "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile"; then
5290       rm -f "$tmpfile"
5291     else
5292       if $doit; then
5293         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
5294         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
5295         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
5296       else
5297         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
5298         if false; then
5299           cat "$tmpfile"
5300           echo
5301           echo "# gnulib-comp.m4 ends here"
5302         fi
5303         rm -f "$tmpfile"
5304       fi
5305     fi
5306   else
5307     if $doit; then
5308       echo "Creating $m4base/gnulib-comp.m4"
5309       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
5310     else
5311       echo "Create $m4base/gnulib-comp.m4"
5312       cat "$tmpfile"
5313       rm -f "$tmpfile"
5314     fi
5315   fi
5316
5317   if $inctests; then
5318     # Create tests makefile.
5319     func_dest_tmpfilename $testsbase/$makefile_am
5320     destfile="$testsbase/$makefile_am"
5321     modules="$testsrelated_modules"
5322     func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
5323     if test -f "$destdir"/$testsbase/$makefile_am; then
5324       if cmp -s "$destdir"/$testsbase/$makefile_am "$tmpfile"; then
5325         rm -f "$tmpfile"
5326       else
5327         if $doit; then
5328           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
5329           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
5330           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
5331         else
5332           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
5333           rm -f "$tmpfile"
5334         fi
5335       fi
5336     else
5337       if $doit; then
5338         echo "Creating $testsbase/$makefile_am"
5339         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
5340       else
5341         echo "Create $testsbase/$makefile_am"
5342         rm -f "$tmpfile"
5343       fi
5344     func_append added_files "$testsbase/$makefile_am$nl"
5345     fi
5346   fi
5347
5348   if test "$vc_files" != false; then
5349     # Update the .cvsignore and .gitignore files.
5350     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
5351       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
5352       # Treat gnulib-comp.m4 like an added file, even if it already existed.
5353       echo "$m4base/|A|gnulib-comp.m4"
5354     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
5355     { # Rearrange file descriptors. Needed because "while ... done < ..."
5356       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5357       exec 5<&0 < "$tmp"/fileset-changes
5358       func_update_ignorelist ()
5359       {
5360         ignore="$1"
5361         if test "$ignore" = .gitignore; then
5362           # In a .gitignore file, "foo" applies to the current directory and all
5363           # subdirectories, whereas "/foo" applies to the current directory only.
5364           anchor='/'
5365           escaped_anchor='\/'
5366           doubly_escaped_anchor='\\/'
5367         else
5368           anchor=''
5369           escaped_anchor=''
5370           doubly_escaped_anchor=''
5371         fi
5372         if test -f "$destdir/$dir$ignore"; then
5373           if test -n "$dir_added" || test -n "$dir_removed"; then
5374             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
5375             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
5376                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
5377              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
5378                > "$tmp"/ignore-removed
5379             )
5380             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
5381               if $doit; then
5382                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
5383                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
5384                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
5385                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,$/d,' < "$tmp"/ignore-removed; fi
5386                 } > "$tmp"/sed-ignore-removed
5387                 { cat "$destdir/$dir$ignore"~
5388                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
5389                 } | sed -f "$tmp"/sed-ignore-removed \
5390                   > "$destdir/$dir$ignore"
5391               else
5392                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
5393               fi
5394             fi
5395           fi
5396         else
5397           if test -n "$dir_added"; then
5398             if $doit; then
5399               echo "Creating $destdir/$dir$ignore"
5400               {
5401                 if test "$ignore" = .cvsignore; then
5402                   echo ".deps"
5403                   # Automake generates Makefile rules that create .dirstamp files.
5404                   echo ".dirstamp"
5405                 fi
5406                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
5407               } > "$destdir/$dir$ignore"
5408             else
5409               echo "Create $destdir/$dir$ignore"
5410             fi
5411           fi
5412         fi
5413       }
5414       func_done_dir ()
5415       {
5416         dir="$1"
5417         dir_added="$2"
5418         dir_removed="$3"
5419         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
5420           func_update_ignorelist .cvsignore
5421         fi
5422         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
5423           func_update_ignorelist .gitignore
5424         fi
5425       }
5426       last_dir=
5427       last_dir_added=
5428       last_dir_removed=
5429       while read line; do
5430         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
5431         next_dir=`echo "$line" | sed -e 's,|.*,,'`
5432         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
5433         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
5434         if test "$next_dir" != "$last_dir"; then
5435           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
5436           last_dir="$next_dir"
5437           last_dir_added=
5438           last_dir_removed=
5439         fi
5440         case $op in
5441           A) func_append last_dir_added "$file$nl";;
5442           R) func_append last_dir_removed "$file$nl";;
5443         esac
5444       done
5445       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
5446       exec 0<&5 5<&-
5447     }
5448   fi
5449
5450   echo "Finished."
5451   echo
5452   echo "You may need to add #include directives for the following .h files."
5453   # Intersect $specified_modules and $main_modules
5454   # (since $specified_modules is not necessarily of subset of $main_modules
5455   # - some may have been skipped through --avoid, and since the elements of
5456   # $main_modules but not in $specified_modules can go away without explicit
5457   # notice - through changes in the module dependencies).
5458   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
5459   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
5460   # First the #include <...> directives without #ifs, sorted for convenience,
5461   # then the #include "..." directives without #ifs, sorted for convenience,
5462   # then the #include directives that are surrounded by #ifs. Not sorted.
5463   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
5464     include_directive=`func_get_include_directive "$module"`
5465     case "$nl$include_directive" in
5466       *"$nl#if"*)
5467         echo "$include_directive" 1>&5
5468         ;;
5469       *)
5470         echo "$include_directive" | grep -v 'include "' 1>&6
5471         echo "$include_directive" | grep 'include "' 1>&7
5472         ;;
5473     esac
5474   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
5475   (
5476    LC_ALL=C sort -u "$tmp"/include-angles
5477    LC_ALL=C sort -u "$tmp"/include-quotes
5478    cat "$tmp"/include-if
5479   ) | sed -e '/^$/d' -e 's/^/  /'
5480   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
5481
5482   for module in $main_modules; do
5483     func_get_link_directive "$module"
5484   done \
5485     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
5486   if test `wc -l < "$tmp"/link` != 0; then
5487     echo
5488     echo "You may need to use the following Makefile variables when linking."
5489     echo "Use them in <program>_LDADD when linking a program, or"
5490     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
5491     cat "$tmp"/link
5492   fi
5493   rm -f "$tmp"/link
5494
5495   echo
5496   echo "Don't forget to"
5497   if test "$makefile_am" = Makefile.am; then
5498     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
5499   else
5500     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
5501   fi
5502   if test -n "$pobase"; then
5503     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
5504   fi
5505   if $inctests; then
5506     if test "$makefile_am" = Makefile.am; then
5507       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
5508     else
5509       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
5510     fi
5511   fi
5512   edit=0
5513   while test $edit != $makefile_am_edits; do
5514     edit=`expr $edit + 1`
5515     eval dir=\"\$makefile_am_edit${edit}_dir\"
5516     eval var=\"\$makefile_am_edit${edit}_var\"
5517     eval val=\"\$makefile_am_edit${edit}_val\"
5518     if test -n "$var"; then
5519       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
5520     fi
5521   done
5522   if grep '^ *AC_PROG_CC_STDC' "$configure_ac" > /dev/null; then
5523     position_early_after=AC_PROG_CC_STDC
5524   else
5525     if grep '^ *AC_PROG_CC_C99' "$configure_ac" > /dev/null; then
5526       position_early_after=AC_PROG_CC_C99
5527     else
5528       position_early_after=AC_PROG_CC
5529     fi
5530   fi
5531   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after $position_early_after,"
5532   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
5533 }
5534
5535 # func_create_testdir testdir modules
5536 # Input:
5537 # - local_gnulib_dir  from --local-dir
5538 # - modcache        true or false, from --cache-modules/--no-cache-modules
5539 # - auxdir          directory relative to destdir where to place build aux files
5540 # - inctests        true if tests should be included, false otherwise
5541 # - incobsolete     true if obsolete modules among dependencies should be
5542 #                   included, blank otherwise
5543 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
5544 #                    blank otherwise
5545 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
5546 #                           blank otherwise
5547 # - excl_privileged_tests  true if tests that require root privileges should be
5548 #                          excluded, blank otherwise
5549 # - excl_unportable_tests  true if tests that fail on some platforms should be
5550 #                          excluded, blank otherwise
5551 # - single_configure  true if a single configure file should be generated,
5552 #                     false for a separate configure file for the tests
5553 # - avoidlist       list of modules to avoid
5554 # - cond_dependencies  true if --conditional-dependencies was given, false if
5555 #                      --no-conditional-dependencies was given, blank otherwise
5556 # - libtool         true if --libtool was given, false if --no-libtool was
5557 #                   given, blank otherwise
5558 # - symbolic        true if files should be symlinked, copied otherwise
5559 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
5560 #                   copied otherwise
5561 func_create_testdir ()
5562 {
5563   testdir="$1"
5564   modules="$2"
5565   if test -z "$modules"; then
5566     # All modules together.
5567     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
5568     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
5569     # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
5570     modules=`func_all_modules`
5571     modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist | lib-ignore) ;; *) echo $m;; esac; done`
5572   fi
5573   specified_modules="$modules"
5574
5575   # Canonicalize the list of specified modules.
5576   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
5577
5578   # Unlike in func_import, here we want to include all kinds of tests for the
5579   # directly specified modules, but not for dependencies.
5580   inc_all_direct_tests=true
5581   inc_all_indirect_tests="$inc_all_tests"
5582
5583   # Check that the license of every module is consistent with the license of
5584   # its dependencies.
5585   saved_inctests="$inctests"
5586   # When computing transitive closures, don't consider $module to depend on
5587   # $module-tests. Need this because tests are implicitly GPL and may depend
5588   # on GPL modules - therefore we don't want a warning in this case.
5589   inctests=false
5590   for requested_module in $specified_modules; do
5591     requested_license=`func_get_license "$requested_module"`
5592     if test "$requested_license" != GPL; then
5593       # Here we use func_modules_transitive_closure, not just
5594       # func_get_dependencies, so that we also detect weird situations like
5595       # an LGPL module which depends on a GPLed build tool module which depends
5596       # on a GPL module.
5597       modules="$requested_module"
5598       func_modules_transitive_closure
5599       for module in $modules; do
5600         license=`func_get_license "$module"`
5601         case "$license" in
5602           'GPLed build tool') ;;
5603           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
5604           *)
5605             case "$requested_license" in
5606               GPLv2+)
5607                 case "$license" in
5608                   GPLv2+ | LGPLv2+) ;;
5609                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5610                 esac
5611                 ;;
5612               LGPL)
5613                 case "$license" in
5614                   LGPL | LGPLv2+) ;;
5615                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5616                 esac
5617                 ;;
5618               LGPLv2+)
5619                 case "$license" in
5620                   LGPLv2+) ;;
5621                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5622                 esac
5623                 ;;
5624             esac
5625             ;;
5626         esac
5627       done
5628     fi
5629   done
5630   inctests="$saved_inctests"
5631
5632   # Subdirectory names.
5633   sourcebase=gllib
5634   m4base=glm4
5635   pobase=
5636   docbase=gldoc
5637   testsbase=gltests
5638   macro_prefix=gl
5639   po_domain=
5640   witness_c_macro=
5641   vc_files=
5642
5643   # Determine final module list.
5644   modules="$specified_modules"
5645   func_modules_transitive_closure
5646   if test $verbose -ge 0; then
5647     func_show_module_list
5648   fi
5649   final_modules="$modules"
5650
5651   if $single_configure; then
5652     # Determine main module list and tests-related module list separately.
5653     func_modules_transitive_closure_separately
5654   fi
5655
5656   if $single_configure; then
5657     # Determine whether a $testsbase/libtests.a is needed.
5658     func_determine_use_libtests
5659   fi
5660
5661   # Add the dummy module if needed.
5662   if $single_configure; then
5663     func_modules_add_dummy_separately
5664   else
5665     func_modules_add_dummy
5666   fi
5667
5668   # Show banner notice of every module.
5669   if $single_configure; then
5670     modules="$main_modules"
5671     func_modules_notice
5672   else
5673     func_modules_notice
5674   fi
5675
5676   # Determine final file list.
5677   if $single_configure; then
5678     func_modules_to_filelist_separately
5679   else
5680     func_modules_to_filelist
5681     if test $verbose -ge 0; then
5682       echo "File list:"
5683       echo "$files" | sed -e 's/^/  /'
5684     fi
5685   fi
5686   # Add files for which the copy in gnulib is newer than the one that
5687   # "automake --add-missing --copy" would provide.
5688   files="$files build-aux/config.guess"
5689   files="$files build-aux/config.sub"
5690   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
5691
5692   rewritten='%REWRITTEN%'
5693   sed_rewrite_files="\
5694     s,^build-aux/,$rewritten$auxdir/,
5695     s,^doc/,$rewritten$docbase/,
5696     s,^lib/,$rewritten$sourcebase/,
5697     s,^m4/,$rewritten$m4base/,
5698     s,^tests/,$rewritten$testsbase/,
5699     s,^tests=lib/,$rewritten$testsbase/,
5700     s,^top/,$rewritten,
5701     s,^$rewritten,,"
5702
5703   # Create directories.
5704   for f in $files; do echo $f; done \
5705     | sed -e "$sed_rewrite_files" \
5706     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
5707     | LC_ALL=C sort -u \
5708     > "$tmp"/dirs
5709   { # Rearrange file descriptors. Needed because "while ... done < ..."
5710     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5711     exec 5<&0 < "$tmp"/dirs
5712     while read d; do
5713       mkdir -p "$testdir/$d"
5714     done
5715     exec 0<&5 5<&-
5716   }
5717
5718   # Copy files or make symbolic links.
5719   delimiter='   '
5720   for f in $files; do echo $f; done \
5721     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
5722     | LC_ALL=C sort \
5723     > "$tmp"/files
5724   { # Rearrange file descriptors. Needed because "while ... done < ..."
5725     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5726     exec 5<&0 < "$tmp"/files
5727     while read g f; do
5728       case "$f" in
5729         tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
5730       esac
5731       func_lookup_file "$f"
5732       if test -n "$lookedup_tmp"; then
5733         cp -p "$lookedup_file" "$testdir/$g"
5734       else
5735         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
5736         if { test -n "$symbolic" \
5737              || { test -n "$lsymbolic" \
5738                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
5739           func_ln "$lookedup_file" "$testdir/$g"
5740         else
5741           cp -p "$lookedup_file" "$testdir/$g"
5742         fi
5743       fi
5744     done
5745     exec 0<&5 5<&-
5746   }
5747
5748   # Determine include_guard_prefix.
5749   func_compute_include_guard_prefix
5750
5751   # Create Makefile.ams that are for testing.
5752   for_test=true
5753
5754   # No special edits are needed.
5755   makefile_am_edits=0
5756
5757   # Create $sourcebase/Makefile.am.
5758   mkdir -p "$testdir/$sourcebase"
5759   destfile="$sourcebase/Makefile.am"
5760   if $single_configure; then
5761     modules="$main_modules"
5762   fi
5763   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
5764   any_uses_subdirs="$uses_subdirs"
5765
5766   # Create $m4base/Makefile.am.
5767   mkdir -p "$testdir/$m4base"
5768   (echo "## Process this file with automake to produce Makefile.in."
5769    echo
5770    echo "EXTRA_DIST ="
5771    for f in $files; do
5772      case "$f" in
5773        m4/* )
5774          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
5775      esac
5776    done
5777   ) > "$testdir/$m4base/Makefile.am"
5778
5779   subdirs="$sourcebase $m4base"
5780   subdirs_with_configure_ac=""
5781
5782   if false && test -f "$testdir"/$m4base/gettext.m4; then
5783     # Avoid stupid error message from automake:
5784     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
5785     mkdir -p "$testdir/po"
5786     (echo "## Process this file with automake to produce Makefile.in."
5787     ) > "$testdir/po/Makefile.am"
5788     func_append subdirs " po"
5789   fi
5790
5791   if $inctests; then
5792     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
5793     if $single_configure; then
5794       # Create $testsbase/Makefile.am.
5795       destfile="$testsbase/Makefile.am"
5796       modules="$testsrelated_modules"
5797       func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$testdir/$testsbase/Makefile.am"
5798     else
5799       # Viewed from the $testsbase subdirectory, $auxdir is different.
5800       saved_auxdir="$auxdir"
5801       auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
5802       # Create $testsbase/Makefile.am.
5803       use_libtests=false
5804       destfile="$testsbase/Makefile.am"
5805       func_emit_tests_Makefile_am "" > "$testdir/$testsbase/Makefile.am"
5806       any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
5807       # Create $testsbase/configure.ac.
5808       (echo "# Process this file with autoconf to produce a configure script."
5809        echo "AC_INIT([dummy], [0])"
5810        echo "AC_CONFIG_AUX_DIR([$auxdir])"
5811        echo "AM_INIT_AUTOMAKE"
5812        echo
5813        echo "AC_CONFIG_HEADERS([config.h])"
5814        echo
5815        echo "AC_PROG_CC"
5816        echo "AC_PROG_INSTALL"
5817        echo "AC_PROG_MAKE_SET"
5818        echo "gl_PROG_AR_RANLIB"
5819        echo
5820        if test -n "$uses_subdirs"; then
5821          echo "AM_PROG_CC_C_O"
5822          echo
5823        fi
5824        for module in $modules; do
5825          func_verify_module
5826          if test -n "$module"; then
5827            case $module in
5828              gnumakefile | maintainer-makefile)
5829                # These modules are meant to be used only in the top-level directory.
5830                ;;
5831              *)
5832                func_get_autoconf_early_snippet "$module"
5833                ;;
5834            esac
5835          fi
5836        done \
5837          | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5838        if test "$libtool" = true; then
5839          echo "LT_INIT([win32-dll])"
5840          echo "LT_LANG([C++])"
5841          echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5842          echo "gl_cond_libtool=true"
5843        else
5844          echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5845          echo "gl_cond_libtool=false"
5846          echo "gl_libdeps="
5847          echo "gl_ltlibdeps="
5848        fi
5849        # Wrap the set of autoconf snippets into an autoconf macro that is then
5850        # invoked. This is needed because autoconf does not support AC_REQUIRE
5851        # at the top level:
5852        #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5853        # but we want the AC_REQUIRE to have its normal meaning (provide one
5854        # expansion of the required macro before the current point, and only one
5855        # expansion total).
5856        echo "AC_DEFUN([gl_INIT], ["
5857        sed_replace_build_aux='
5858          :a
5859          /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5860            s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5861            ba
5862          }'
5863        echo "gl_m4_base='../$m4base'"
5864        func_emit_initmacro_start $macro_prefix
5865        # We don't have explicit ordering constraints between the various
5866        # autoconf snippets. It's cleanest to put those of the library before
5867        # those of the tests.
5868        echo "gl_source_base='../$sourcebase'"
5869        func_emit_autoconf_snippets "$modules" func_verify_nontests_module false false false
5870        echo "gl_source_base='.'"
5871        func_emit_autoconf_snippets "$modules" func_verify_tests_module false false false
5872        func_emit_initmacro_end $macro_prefix
5873        # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5874        # created using libtool, because libtool already handles the dependencies.
5875        if test "$libtool" != true; then
5876          libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5877          echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5878          echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5879          echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5880          echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5881        fi
5882        echo "])"
5883        func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
5884        echo
5885        echo "gl_INIT"
5886        echo
5887        # Usually $testsbase/config.h will be a superset of config.h. Verify this
5888        # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
5889        echo "AH_TOP([#include \"../config.h\"])"
5890        echo
5891        echo "AC_CONFIG_FILES([Makefile])"
5892        echo "AC_OUTPUT"
5893       ) > "$testdir/$testsbase/configure.ac"
5894       auxdir="$saved_auxdir"
5895       subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
5896     fi
5897     func_append subdirs " $testsbase"
5898   fi
5899
5900   # Create Makefile.am.
5901   (echo "## Process this file with automake to produce Makefile.in."
5902    echo
5903    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
5904    echo
5905    echo "SUBDIRS = $subdirs"
5906    echo
5907    echo "ACLOCAL_AMFLAGS = -I $m4base"
5908   ) > "$testdir/Makefile.am"
5909
5910   # Create configure.ac.
5911   (echo "# Process this file with autoconf to produce a configure script."
5912    echo "AC_INIT([dummy], [0])"
5913    if test "$auxdir" != "."; then
5914      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5915    fi
5916    echo "AM_INIT_AUTOMAKE"
5917    echo
5918    echo "AC_CONFIG_HEADERS([config.h])"
5919    echo
5920    echo "AC_PROG_CC"
5921    echo "AC_PROG_INSTALL"
5922    echo "AC_PROG_MAKE_SET"
5923    echo
5924    echo "# For autobuild."
5925    echo "AC_CANONICAL_BUILD"
5926    echo "AC_CANONICAL_HOST"
5927    echo
5928    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5929    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5930    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5931    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5932    echo
5933    echo "gl_PROG_AR_RANLIB"
5934    echo
5935    if test -n "$any_uses_subdirs"; then
5936      echo "AM_PROG_CC_C_O"
5937      echo
5938    fi
5939    for module in $final_modules; do
5940      if $single_configure; then
5941        func_verify_module
5942      else
5943        func_verify_nontests_module
5944      fi
5945      if test -n "$module"; then
5946        func_get_autoconf_early_snippet "$module"
5947      fi
5948    done \
5949      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5950    if test "$libtool" = true; then
5951      echo "LT_INIT([win32-dll])"
5952      echo "LT_LANG([C++])"
5953      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5954      echo "gl_cond_libtool=true"
5955    else
5956      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5957      echo "gl_cond_libtool=false"
5958      echo "gl_libdeps="
5959      echo "gl_ltlibdeps="
5960    fi
5961    # Wrap the set of autoconf snippets into an autoconf macro that is then
5962    # invoked. This is needed because autoconf does not support AC_REQUIRE
5963    # at the top level:
5964    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5965    # but we want the AC_REQUIRE to have its normal meaning (provide one
5966    # expansion of the required macro before the current point, and only one
5967    # expansion total).
5968    echo "AC_DEFUN([gl_INIT], ["
5969    if test "$auxdir" != "build-aux"; then
5970      sed_replace_build_aux='
5971        :a
5972        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5973          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5974          ba
5975        }'
5976    else
5977      sed_replace_build_aux="$sed_noop"
5978    fi
5979    echo "gl_m4_base='$m4base'"
5980    func_emit_initmacro_start $macro_prefix
5981    echo "gl_source_base='$sourcebase'"
5982    if $single_configure; then
5983      func_emit_autoconf_snippets "$main_modules" func_verify_module true false false
5984    else
5985      func_emit_autoconf_snippets "$modules" func_verify_nontests_module true false false
5986    fi
5987    func_emit_initmacro_end $macro_prefix
5988    if $single_configure; then
5989      echo "  gltests_libdeps="
5990      echo "  gltests_ltlibdeps="
5991      func_emit_initmacro_start ${macro_prefix}tests
5992      echo "  gl_source_base='$testsbase'"
5993      # Define a tests witness macro.
5994      echo "  ${macro_prefix}tests_WITNESS=IN_GNULIB_TESTS"
5995      echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
5996      echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
5997      echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
5998      func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true false false
5999      echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
6000      func_emit_initmacro_end ${macro_prefix}tests
6001    fi
6002    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
6003    # created using libtool, because libtool already handles the dependencies.
6004    if test "$libtool" != true; then
6005      libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
6006      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
6007      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
6008      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
6009      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
6010    fi
6011    if $single_configure; then
6012      if $use_libtests; then
6013        echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
6014        echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
6015      fi
6016    fi
6017    echo "])"
6018    func_emit_initmacro_done $macro_prefix $sourcebase
6019    if $single_configure; then
6020      func_emit_initmacro_done ${macro_prefix}tests $testsbase
6021    fi
6022    echo
6023    echo "gl_INIT"
6024    echo
6025    if test -n "$subdirs_with_configure_ac"; then
6026      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
6027    fi
6028    makefiles="Makefile"
6029    for d in $subdirs; do
6030      # For subdirs that have a configure.ac by their own, it's the subdir's
6031      # configure.ac which creates the subdir's Makefile.am, not this one.
6032      case " $subdirs_with_configure_ac " in
6033        *" $d "*) ;;
6034        *) func_append makefiles " $d/Makefile" ;;
6035      esac
6036    done
6037    echo "AC_CONFIG_FILES([$makefiles])"
6038    echo "AC_OUTPUT"
6039   ) > "$testdir/configure.ac"
6040
6041   # Create autogenerated files.
6042   (cd "$testdir"
6043    # Do not use "${AUTORECONF} --force --install", because it may invoke
6044    # autopoint, which brings in older versions of some of our .m4 files.
6045    if test -f $m4base/gettext.m4; then
6046      func_execute_command ${AUTOPOINT} --force || func_exit 1
6047      for f in $m4base/*.m4~; do
6048        if test -f $f; then
6049          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
6050        fi
6051      done
6052    fi
6053    if test "$libtool" = true; then
6054      func_execute_command ${LIBTOOLIZE} --copy || func_exit 1
6055    fi
6056    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
6057    if ! test -d build-aux; then
6058      func_execute_command mkdir build-aux || func_exit 1
6059    fi
6060    func_execute_command ${AUTOCONF} || func_exit 1
6061    func_execute_command ${AUTOHEADER} || func_exit 1
6062    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6063   ) || func_exit 1
6064   if $inctests && ! $single_configure; then
6065     # Create autogenerated files.
6066     (cd "$testdir/$testsbase" || func_exit 1
6067      # Do not use "${AUTORECONF} --force --install", because it may invoke
6068      # autopoint, which brings in older versions of some of our .m4 files.
6069      if test -f ../$m4base/gettext.m4; then
6070        func_execute_command ${AUTOPOINT} --force || func_exit 1
6071        for f in ../$m4base/*.m4~; do
6072          if test -f $f; then
6073            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
6074          fi
6075        done
6076      fi
6077      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
6078      if ! test -d ../build-aux; then
6079        func_execute_command mkdir ../build-aux
6080      fi
6081      func_execute_command ${AUTOCONF} || func_exit 1
6082      func_execute_command ${AUTOHEADER} || func_exit 1
6083      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6084     ) || func_exit 1
6085   fi
6086   # Need to run configure and make once, to create built files that are to be
6087   # distributed (such as parse-datetime.c).
6088   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
6089   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
6090   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
6091                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
6092   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
6093   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
6094   # such $(FOO_H) because they don't refer to distributed files.
6095   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
6096                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
6097                  | sed -e "$sed_remove_make_variables"`
6098   distributed_built_sources=`for file in $built_sources; do
6099                                case "$cleaned_files" in
6100                                  *" "$file" "*) ;;
6101                                  *) echo $file ;;
6102                                esac;
6103                              done`
6104   tests_distributed_built_sources=
6105   if $inctests; then
6106     # Likewise for built files in the $testsbase directory.
6107     tests_cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
6108                          | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
6109     tests_cleaned_files=`for file in $tests_cleaned_files; do echo " $file "; done`
6110     tests_built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
6111                          | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
6112                          | sed -e "$sed_remove_make_variables"`
6113     tests_distributed_built_sources=`for file in $tests_built_sources; do
6114                                        case "$tests_cleaned_files" in
6115                                          *" "$file" "*) ;;
6116                                          *) echo $file ;;
6117                                        esac;
6118                                      done`
6119   fi
6120   if test -n "$distributed_built_sources" || test -n "$tests_distributed_built_sources"; then
6121     (cd "$testdir"
6122      ./configure || func_exit 1
6123        if test -n "$distributed_built_sources"; then
6124          cd "$sourcebase"
6125          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
6126          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6127                built_sources \
6128            || func_exit 1
6129          cd ..
6130        fi
6131        if test -n "$tests_distributed_built_sources"; then
6132          cd "$testsbase"
6133          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
6134          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6135                built_sources \
6136            || func_exit 1
6137          cd ..
6138        fi
6139      $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6140            distclean \
6141        || func_exit 1
6142     ) || func_exit 1
6143   fi
6144 }
6145
6146 # func_create_megatestdir megatestdir allmodules
6147 # Input:
6148 # - local_gnulib_dir  from --local-dir
6149 # - modcache        true or false, from --cache-modules/--no-cache-modules
6150 # - auxdir          directory relative to destdir where to place build aux files
6151 func_create_megatestdir ()
6152 {
6153   megatestdir="$1"
6154   allmodules="$2"
6155   if test -z "$allmodules"; then
6156     allmodules=`func_all_modules`
6157   fi
6158
6159   megasubdirs=
6160   # First, all modules one by one.
6161   for onemodule in $allmodules; do
6162     func_create_testdir "$megatestdir/$onemodule" $onemodule
6163     func_append megasubdirs "$onemodule "
6164   done
6165   # Then, all modules all together.
6166   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
6167   allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
6168   func_create_testdir "$megatestdir/ALL" "$allmodules"
6169   func_append megasubdirs "ALL"
6170
6171   # Create autobuild.
6172   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
6173              vc_witness="$gnulib_dir/CVS/Entries"; \
6174            else \
6175              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
6176            fi; \
6177            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
6178              | sed -e 's,January,01,'   -e 's,Jan,01,' \
6179                    -e 's,February,02,'  -e 's,Feb,02,' \
6180                    -e 's,March,03,'     -e 's,Mar,03,' \
6181                    -e 's,April,04,'     -e 's,Apr,04,' \
6182                    -e 's,May,05,'                      \
6183                    -e 's,June,06,'      -e 's,Jun,06,' \
6184                    -e 's,July,07,'      -e 's,Jul,07,' \
6185                    -e 's,August,08,'    -e 's,Aug,08,' \
6186                    -e 's,September,09,' -e 's,Sep,09,' \
6187                    -e 's,October,10,'   -e 's,Oct,10,' \
6188                    -e 's,November,11,'  -e 's,Nov,11,' \
6189                    -e 's,December,12,'  -e 's,Dec,12,' \
6190                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
6191                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
6192   (echo '#!/bin/sh'
6193    echo "CVSDATE=$cvsdate"
6194    echo ": \${MAKE=make}"
6195    echo "test -d logs || mkdir logs"
6196    echo "for module in $megasubdirs; do"
6197    echo "  echo \"Working on module \$module...\""
6198    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
6199    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
6200    echo "   echo"
6201    echo "   set -x"
6202    echo "   : autobuild project... \$module"
6203    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
6204    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
6205    echo "   : autobuild hostname... \`hostname\`"
6206    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && \$MAKE && \$MAKE check && \$MAKE distclean"
6207    echo "   echo rc=\$?"
6208    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
6209    echo "done"
6210   ) > "$megatestdir/do-autobuild"
6211   chmod a+x "$megatestdir/do-autobuild"
6212
6213   # Create Makefile.am.
6214   (echo "## Process this file with automake to produce Makefile.in."
6215    echo
6216    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
6217    echo
6218    echo "SUBDIRS = $megasubdirs"
6219    echo
6220    echo "EXTRA_DIST = do-autobuild"
6221   ) > "$megatestdir/Makefile.am"
6222
6223   # Create configure.ac.
6224   (echo "# Process this file with autoconf to produce a configure script."
6225    echo "AC_INIT([dummy], [0])"
6226    if test "$auxdir" != "."; then
6227      echo "AC_CONFIG_AUX_DIR([$auxdir])"
6228    fi
6229    echo "AM_INIT_AUTOMAKE"
6230    echo
6231    echo "AC_PROG_MAKE_SET"
6232    echo
6233    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
6234    echo "AC_CONFIG_FILES([Makefile])"
6235    echo "AC_OUTPUT"
6236   ) > "$megatestdir/configure.ac"
6237
6238   # Create autogenerated files.
6239   (cd "$megatestdir"
6240    # Do not use "${AUTORECONF} --install", because autoreconf operates
6241    # recursively, but the subdirectories are already finished, therefore
6242    # calling autoreconf here would only waste lots of CPU time.
6243    func_execute_command ${ACLOCAL} || func_exit 1
6244    func_execute_command mkdir build-aux
6245    func_execute_command ${AUTOCONF} || func_exit 1
6246    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6247   ) || func_exit 1
6248 }
6249
6250 case $mode in
6251   "" )
6252     func_fatal_error "no mode specified" ;;
6253
6254   list )
6255     func_all_modules
6256     ;;
6257
6258   find )
6259     # sed expression that converts a literal to a basic regular expression.
6260     # Needs to handle . [ \ * ^ $.
6261     sed_literal_to_basic_regex='s/\\/\\\\/g
6262 s/\[/\\[/g
6263 s/\^/\\^/g
6264 s/\([.*$]\)/[\1]/g'
6265     for filename
6266     do
6267       if test -f "$gnulib_dir/$filename" \
6268          || { test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$filename"; }; then
6269         filename_anywhere_regex=`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`
6270         filename_line_regex='^'"$filename_anywhere_regex"'$'
6271         module_candidates=`
6272           {
6273             (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filename_line_regex" /dev/null | sed -e 's,^modules/,,')
6274             if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
6275               (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$,,')
6276             fi
6277           } \
6278             | func_sanitize_modulelist \
6279             | LC_ALL=C sort -u
6280           `
6281         for module in $module_candidates; do
6282           if func_get_filelist $module | grep "$filename_line_regex" > /dev/null; then
6283             echo $module
6284           fi
6285         done
6286       else
6287         func_warning "file $filename does not exist"
6288       fi
6289     done
6290     ;;
6291
6292   import | add-import | remove-import | update )
6293
6294     # Where to import.
6295     if test -z "$destdir"; then
6296       destdir=.
6297     fi
6298     test -d "$destdir" \
6299       || func_fatal_error "destination directory does not exist: $destdir"
6300
6301     # Prefer configure.ac to configure.in.
6302     if test -f "$destdir"/configure.ac; then
6303       configure_ac="$destdir/configure.ac"
6304     else
6305       if test -f "$destdir"/configure.in; then
6306         configure_ac="$destdir/configure.in"
6307       else
6308         func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
6309       fi
6310     fi
6311
6312     # Analyze configure.ac.
6313     guessed_auxdir="."
6314     guessed_libtool=false
6315     my_sed_traces='
6316       s,#.*$,,
6317       s,^dnl .*$,,
6318       s, dnl .*$,,
6319       /AC_CONFIG_AUX_DIR/ {
6320         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
6321       }
6322       /A[CM]_PROG_LIBTOOL/ {
6323         s,^.*$,guessed_libtool=true,p
6324       }'
6325     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
6326
6327     if test -z "$auxdir"; then
6328       auxdir="$guessed_auxdir"
6329     fi
6330
6331     # Determine where to apply func_import.
6332     if test "$mode" = import; then
6333       # Apply func_import to a particular gnulib directory.
6334       # The command line contains the complete specification; don't look at
6335       # the contents of gnulib-cache.m4.
6336       test -n "$supplied_libname" || supplied_libname=true
6337       test -n "$sourcebase" || sourcebase="lib"
6338       test -n "$m4base" || m4base="m4"
6339       test -n "$docbase" || docbase="doc"
6340       test -n "$testsbase" || testsbase="tests"
6341       test -n "$macro_prefix" || macro_prefix="gl"
6342       func_import "$*"
6343     else
6344       if test -n "$m4base"; then
6345         # Apply func_import to a particular gnulib directory.
6346         # Any number of additional modules can be given.
6347         if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
6348           # First use of gnulib in the given m4base.
6349           test -n "$supplied_libname" || supplied_libname=true
6350           test -n "$sourcebase" || sourcebase="lib"
6351           test -n "$docbase" || docbase="doc"
6352           test -n "$testsbase" || testsbase="tests"
6353           test -n "$macro_prefix" || macro_prefix="gl"
6354         fi
6355         func_import "$*"
6356       else
6357         # Apply func_import to all gnulib directories.
6358         # To get this list of directories, look at Makefile.am. (Not at
6359         # configure, because it may be omitted from version control. Also,
6360         # don't run "find $destdir -name gnulib-cache.m4", as it might be
6361         # too expensive.)
6362         m4dirs=
6363         m4dirs_count=0
6364         if test -f "$destdir"/Makefile.am; then
6365           aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[        ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
6366           m4dir_is_next=
6367           for arg in $aclocal_amflags; do
6368             if test -n "$m4dir_is_next"; then
6369               # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
6370               case "$arg" in
6371                 /*) ;;
6372                 *)
6373                   if test -f "$destdir/$arg"/gnulib-cache.m4; then
6374                     func_append m4dirs " $arg"
6375                     m4dirs_count=`expr $m4dirs_count + 1`
6376                   fi
6377                   ;;
6378               esac
6379               m4dir_is_next=
6380             else
6381               if test "X$arg" = "X-I"; then
6382                 m4dir_is_next=yes
6383               else
6384                 m4dir_is_next=
6385               fi
6386             fi
6387           done
6388         else
6389           # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
6390           if test -f "$destdir"/aclocal.m4; then
6391             sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
6392             sedexpr2='s,^[^/]*$,.,'
6393             sedexpr3='s,/[^/]*$,,'
6394             m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
6395             m4dirs=`for arg in $m4dirs; do if test -f "$destdir/$arg"/gnulib-cache.m4; then echo $arg; fi; done`
6396             m4dirs_count=`for arg in $m4dirs; do echo "$arg"; done | wc -l`
6397           fi
6398         fi
6399         if test $m4dirs_count = 0; then
6400           # First use of gnulib in a package.
6401           # Any number of additional modules can be given.
6402           test -n "$supplied_libname" || supplied_libname=true
6403           test -n "$sourcebase" || sourcebase="lib"
6404           m4base="m4"
6405           test -n "$docbase" || docbase="doc"
6406           test -n "$testsbase" || testsbase="tests"
6407           test -n "$macro_prefix" || macro_prefix="gl"
6408           func_import "$*"
6409         else
6410           if test $m4dirs_count = 1; then
6411             # There's only one use of gnulib here. Assume the user means it.
6412             # Any number of additional modules can be given.
6413             for m4base in $m4dirs; do
6414               func_import "$*"
6415             done
6416           else
6417             # Ambiguous - guess what the user meant.
6418             if test $# = 0; then
6419               # No further arguments. Guess the user wants to update all of them.
6420               for m4base in $m4dirs; do
6421                 # Perform func_import in a subshell, so that variable values
6422                 # such as
6423                 #   local_gnulib_dir, incobsolete, inc_cxx_tests,
6424                 #   inc_longrunning_tests, inc_privileged_tests,
6425                 #   inc_unportable_tests, inc_all_tests, avoidlist, sourcebase,
6426                 #   m4base, pobase, docbase, testsbase, inctests, libname, lgpl,
6427                 #   makefile_name, libtool, macro_prefix, po_domain,
6428                 #   witness_c_macro, vc_files
6429                 # don't propagate from one directory to another.
6430                 (func_import) || func_exit 1
6431               done
6432             else
6433               # Really ambiguous.
6434               func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
6435             fi
6436           fi
6437         fi
6438       fi
6439     fi
6440     ;;
6441
6442   create-testdir )
6443     if test -z "$destdir"; then
6444       func_fatal_error "please specify --dir option"
6445     fi
6446     mkdir "$destdir"
6447     test -d "$destdir" \
6448       || func_fatal_error "could not create destination directory"
6449     test -n "$auxdir" || auxdir="build-aux"
6450     func_create_testdir "$destdir" "$*"
6451     ;;
6452
6453   create-megatestdir )
6454     if test -z "$destdir"; then
6455       func_fatal_error "please specify --dir option"
6456     fi
6457     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6458     test -n "$auxdir" || auxdir="build-aux"
6459     func_create_megatestdir "$destdir" "$*"
6460     ;;
6461
6462   test )
6463     test -n "$destdir" || destdir=testdir$$
6464     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6465     test -n "$auxdir" || auxdir="build-aux"
6466     func_create_testdir "$destdir" "$*"
6467     cd "$destdir"
6468       mkdir build
6469       cd build
6470         ../configure || func_exit 1
6471         $MAKE || func_exit 1
6472         $MAKE check || func_exit 1
6473         $MAKE distclean || func_exit 1
6474         remaining=`find . -type f -print`
6475         if test -n "$remaining"; then
6476           echo "Remaining files:" $remaining 1>&2
6477           echo "gnulib-tool: *** Stop." 1>&2
6478           func_exit 1
6479         fi
6480       cd ..
6481     cd ..
6482     rm -rf "$destdir"
6483     ;;
6484
6485   megatest )
6486     test -n "$destdir" || destdir=testdir$$
6487     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6488     test -n "$auxdir" || auxdir="build-aux"
6489     func_create_megatestdir "$destdir" "$*"
6490     cd "$destdir"
6491       mkdir build
6492       cd build
6493         ../configure
6494         $MAKE
6495         $MAKE check
6496         $MAKE distclean
6497         remaining=`find . -type f -print`
6498         if test -n "$remaining"; then
6499           echo "Remaining files:" $remaining 1>&2
6500           echo "gnulib-tool: *** Stop." 1>&2
6501           func_exit 1
6502         fi
6503       cd ..
6504     cd ..
6505     rm -rf "$destdir"
6506     ;;
6507
6508   extract-description )
6509     for module
6510     do
6511       func_verify_module
6512       if test -n "$module"; then
6513         func_get_description "$module"
6514       fi
6515     done
6516     ;;
6517
6518   extract-comment )
6519     for module
6520     do
6521       func_verify_module
6522       if test -n "$module"; then
6523         func_get_comment "$module"
6524       fi
6525     done
6526     ;;
6527
6528   extract-status )
6529     for module
6530     do
6531       func_verify_module
6532       if test -n "$module"; then
6533         func_get_status "$module"
6534       fi
6535     done
6536     ;;
6537
6538   extract-notice )
6539     for module
6540     do
6541       func_verify_module
6542       if test -n "$module"; then
6543         func_get_notice "$module"
6544       fi
6545     done
6546     ;;
6547
6548   extract-applicability )
6549     for module
6550     do
6551       func_verify_module
6552       if test -n "$module"; then
6553         func_get_applicability "$module"
6554       fi
6555     done
6556     ;;
6557
6558   extract-filelist )
6559     for module
6560     do
6561       func_verify_module
6562       if test -n "$module"; then
6563         func_get_filelist "$module"
6564       fi
6565     done
6566     ;;
6567
6568   extract-dependencies )
6569     if test -n "$avoidlist"; then
6570       func_fatal_error "cannot combine --avoid and --extract-dependencies"
6571     fi
6572     for module
6573     do
6574       func_verify_module
6575       if test -n "$module"; then
6576         func_get_dependencies "$module"
6577       fi
6578     done
6579     ;;
6580
6581   extract-autoconf-snippet )
6582     for module
6583     do
6584       func_verify_module
6585       if test -n "$module"; then
6586         func_get_autoconf_snippet "$module"
6587       fi
6588     done
6589     ;;
6590
6591   extract-automake-snippet )
6592     for module
6593     do
6594       func_verify_module
6595       if test -n "$module"; then
6596         func_get_automake_snippet "$module"
6597       fi
6598     done
6599     ;;
6600
6601   extract-include-directive )
6602     for module
6603     do
6604       func_verify_module
6605       if test -n "$module"; then
6606         func_get_include_directive "$module"
6607       fi
6608     done
6609     ;;
6610
6611   extract-link-directive )
6612     for module
6613     do
6614       func_verify_module
6615       if test -n "$module"; then
6616         func_get_link_directive "$module"
6617       fi
6618     done
6619     ;;
6620
6621   extract-license )
6622     for module
6623     do
6624       func_verify_module
6625       if test -n "$module"; then
6626         func_get_license "$module"
6627       fi
6628     done
6629     ;;
6630
6631   extract-maintainer )
6632     for module
6633     do
6634       func_verify_module
6635       if test -n "$module"; then
6636         func_get_maintainer "$module"
6637       fi
6638     done
6639     ;;
6640
6641   extract-tests-module )
6642     for module
6643     do
6644       func_verify_module
6645       if test -n "$module"; then
6646         func_get_tests_module "$module"
6647       fi
6648     done
6649     ;;
6650
6651   copy-file )
6652     # Verify the number of arguments.
6653     if test $# -lt 1 || test $# -gt 2; then
6654       func_fatal_error "invalid number of arguments for --$mode"
6655     fi
6656
6657     # The first argument is the file to be copied.
6658     f="$1"
6659     # Verify the file exists.
6660     func_lookup_file "$f"
6661
6662     # The second argument is the destination; either a directory ot a file.
6663     # It defaults to the current directory.
6664     dest="$2"
6665     test -n "$dest" || dest='.'
6666     test -n "$sourcebase" || sourcebase="lib"
6667     test -n "$m4base" || m4base="m4"
6668     test -n "$docbase" || docbase="doc"
6669     test -n "$testsbase" || testsbase="tests"
6670     test -n "$auxdir" || auxdir="build-aux"
6671     rewritten='%REWRITTEN%'
6672     sed_rewrite_files="\
6673       s,^build-aux/,$rewritten$auxdir/,
6674       s,^doc/,$rewritten$docbase/,
6675       s,^lib/,$rewritten$sourcebase/,
6676       s,^m4/,$rewritten$m4base/,
6677       s,^tests/,$rewritten$testsbase/,
6678       s,^top/,$rewritten,
6679       s,^$rewritten,,"
6680     if test -d "$dest"; then
6681       destdir="$dest"
6682       g=`echo "$f" | sed -e "$sed_rewrite_files"`
6683     else
6684       destdir=`dirname "$dest"`
6685       g=`basename "$dest"`
6686     fi
6687
6688     # Create the directory for destfile.
6689     d=`dirname "$destdir/$g"`
6690     if $doit; then
6691       if test -n "$d" && test ! -d "$d"; then
6692         mkdir -p "$d" || func_fatal_error "failed"
6693       fi
6694     fi
6695     # Copy the file.
6696     func_dest_tmpfilename "$g"
6697     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
6698     already_present=true
6699     if test -f "$destdir/$g"; then
6700       # The file already exists.
6701       func_update_file
6702     else
6703       # Install the file.
6704       # Don't protest if the file should be there but isn't: it happens
6705       # frequently that developers don't put autogenerated files under version
6706       # control.
6707       func_add_file
6708     fi
6709     rm -f "$tmpfile"
6710     ;;
6711
6712   * )
6713     func_fatal_error "unknown operation mode --$mode" ;;
6714 esac
6715
6716 rm -rf "$tmp"
6717 # Undo the effect of the previous 'trap' command. Some shellology:
6718 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
6719 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
6720 # exit); for the others we need to call 'exit' explicitly. The value of $? is
6721 # 128 + signal number and is set before the trap-registered command is run.
6722 trap '' 0
6723 trap 'func_exit $?' 1 2 3 13 15
6724
6725 exit 0
6726
6727 # Local Variables:
6728 # indent-tabs-mode: nil
6729 # whitespace-check-buffer-indent: nil
6730 # End: