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