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