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