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