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