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