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