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