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