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