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