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