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