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