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