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