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