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