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