gnulib-tool: Allow comments in the 'Depends-on' section.
[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   | sed -e '/^#/d'
2119 }
2120
2121 # func_get_autoconf_early_snippet module
2122 # Input:
2123 # - local_gnulib_dir  from --local-dir
2124 # - modcache          true or false, from --cache-modules/--no-cache-modules
2125 func_get_autoconf_early_snippet ()
2126 {
2127   if ! $modcache; then
2128     func_lookup_file "modules/$1"
2129     sed -n -e "/^configure\.ac-early$sed_extract_prog" < "$lookedup_file"
2130   else
2131     func_cache_lookup_module "$1"
2132     # Output the field's value, including the final newline (if any).
2133     if $have_associative; then
2134       if eval 'test -n "${modcache_configureac_early[$1]+set}"'; then
2135         eval 'echo "${modcache_configureac_early[$1]}"'
2136       fi
2137     else
2138       eval "field_set=\"\$${cachevar}_configureac_early_set\""
2139       if test -n "$field_set"; then
2140         eval "field_value=\"\$${cachevar}_configureac_early\""
2141         echo "${field_value}"
2142       fi
2143     fi
2144   fi
2145 }
2146
2147 # func_get_autoconf_snippet module
2148 # Input:
2149 # - local_gnulib_dir  from --local-dir
2150 # - modcache          true or false, from --cache-modules/--no-cache-modules
2151 func_get_autoconf_snippet ()
2152 {
2153   if ! $modcache; then
2154     func_lookup_file "modules/$1"
2155     sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
2156   else
2157     func_cache_lookup_module "$1"
2158     # Output the field's value, including the final newline (if any).
2159     if $have_associative; then
2160       if eval 'test -n "${modcache_configureac[$1]+set}"'; then
2161         eval 'echo "${modcache_configureac[$1]}"'
2162       fi
2163     else
2164       eval "field_set=\"\$${cachevar}_configureac_set\""
2165       if test -n "$field_set"; then
2166         eval "field_value=\"\$${cachevar}_configureac\""
2167         echo "${field_value}"
2168       fi
2169     fi
2170   fi
2171 }
2172
2173 # func_get_automake_snippet_conditional module
2174 # returns the part of the Makefile.am snippet that can be put inside Automake
2175 # conditionals.
2176 # Input:
2177 # - local_gnulib_dir  from --local-dir
2178 # - modcache          true or false, from --cache-modules/--no-cache-modules
2179 func_get_automake_snippet_conditional ()
2180 {
2181   if ! $modcache; then
2182     func_lookup_file "modules/$1"
2183     sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
2184   else
2185     func_cache_lookup_module "$1"
2186     # Output the field's value, including the final newline (if any).
2187     if $have_associative; then
2188       if eval 'test -n "${modcache_makefile[$1]+set}"'; then
2189         eval 'echo "${modcache_makefile[$1]}"'
2190       fi
2191     else
2192       eval "field_set=\"\$${cachevar}_makefile_set\""
2193       if test -n "$field_set"; then
2194         eval "field_value=\"\$${cachevar}_makefile\""
2195         echo "${field_value}"
2196       fi
2197     fi
2198   fi
2199 }
2200
2201 # func_get_automake_snippet_unconditional module
2202 # returns the part of the Makefile.am snippet that must stay outside of
2203 # Automake conditionals.
2204 # Input:
2205 # - local_gnulib_dir  from --local-dir
2206 # - modcache          true or false, from --cache-modules/--no-cache-modules
2207 func_get_automake_snippet_unconditional ()
2208 {
2209   case "$1" in
2210     *-tests)
2211       # *-tests module live in tests/, not lib/.
2212       # Synthesize an EXTRA_DIST augmentation.
2213       all_files=`func_get_filelist $1`
2214       func_filter_filelist tests_files " " "$all_files" 'tests/' '' 'tests/' ''
2215       extra_files="$tests_files"
2216       if test -n "$extra_files"; then
2217         echo "EXTRA_DIST +=" $extra_files
2218         echo
2219       fi
2220       ;;
2221     *)
2222       # Synthesize an EXTRA_DIST augmentation.
2223       sed_combine_lines='/\\$/{
2224         :a
2225         N
2226         s/\\\n/ /
2227         s/\\$/\\/
2228         ta
2229       }'
2230       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
2231       already_mentioned_files=` \
2232         { if ! $modcache; then
2233             func_lookup_file "modules/$1"
2234             sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
2235           else
2236             func_cache_lookup_module "$1"
2237             if $have_associative; then
2238               if eval 'test -n "${modcache_makefile[$1]+set}"'; then
2239                 eval 'echo "${modcache_makefile[$1]}"'
2240               fi
2241             else
2242               eval 'field_set="$'"${cachevar}"'_makefile_set"'
2243               if test -n "$field_set"; then
2244                 eval 'field_value="$'"${cachevar}"'_makefile"'
2245                 echo "${field_value}"
2246               fi
2247             fi
2248           fi
2249         } \
2250         | sed -e "$sed_combine_lines" \
2251         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
2252       all_files=`func_get_filelist $1`
2253       func_filter_filelist lib_files "$nl" "$all_files" 'lib/' '' 'lib/' ''
2254       # Remove $already_mentioned_files from $lib_files.
2255       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
2256       extra_files=`for f in $already_mentioned_files; do echo $f; done \
2257                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
2258       if test -n "$extra_files"; then
2259         echo "EXTRA_DIST +=" $extra_files
2260         echo
2261       fi
2262       # Synthesize also an EXTRA_lib_SOURCES augmentation.
2263       # This is necessary so that automake can generate the right list of
2264       # dependency rules.
2265       # A possible approach would be to use autom4te --trace of the redefined
2266       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
2267       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
2268       # inside autoconf's built-in macros are not missed).
2269       # But it's simpler and more robust to do it here, based on the file list.
2270       # If some .c file exists and is not used with AC_LIBOBJ - for example,
2271       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
2272       # automake will generate a useless dependency; this is harmless.
2273       case "$1" in
2274         relocatable-prog-wrapper) ;;
2275         pt_chown) ;;
2276         *)
2277           func_filter_filelist extra_files "$nl" "$extra_files" '' '.c' '' ''
2278           if test -n "$extra_files"; then
2279             echo "EXTRA_lib_SOURCES +=" $extra_files
2280             echo
2281           fi
2282           ;;
2283       esac
2284       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
2285       func_filter_filelist buildaux_files "$nl" "$all_files" 'build-aux/' '' 'build-aux/' ''
2286       if test -n "$buildaux_files"; then
2287         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
2288         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
2289         echo
2290       fi
2291       # Synthesize an EXTRA_DIST augmentation also for the files from top/.
2292       func_filter_filelist top_files "$nl" "$all_files" 'top/' '' 'top/' ''
2293       if test -n "$top_files"; then
2294         sed_prepend_topdir='s,^,$(top_srcdir)/,'
2295         echo "EXTRA_DIST += "`echo "$top_files" | sed -e "$sed_prepend_topdir"`
2296         echo
2297       fi
2298       ;;
2299   esac
2300 }
2301
2302 # func_get_automake_snippet module
2303 # Input:
2304 # - local_gnulib_dir  from --local-dir
2305 # - modcache          true or false, from --cache-modules/--no-cache-modules
2306 func_get_automake_snippet ()
2307 {
2308   func_get_automake_snippet_conditional "$1"
2309   func_get_automake_snippet_unconditional "$1"
2310 }
2311
2312 # func_get_include_directive module
2313 # Input:
2314 # - local_gnulib_dir  from --local-dir
2315 # - modcache          true or false, from --cache-modules/--no-cache-modules
2316 func_get_include_directive ()
2317 {
2318   {
2319     if ! $modcache; then
2320       func_lookup_file "modules/$1"
2321       sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file"
2322     else
2323       func_cache_lookup_module "$1"
2324       # Output the field's value, including the final newline (if any).
2325       if $have_associative; then
2326         if eval 'test -n "${modcache_include[$1]+set}"'; then
2327           eval 'echo "${modcache_include[$1]}"'
2328         fi
2329       else
2330         eval "field_set=\"\$${cachevar}_include_set\""
2331         if test -n "$field_set"; then
2332           eval "field_value=\"\$${cachevar}_include\""
2333           echo "${field_value}"
2334         fi
2335       fi
2336     fi
2337   } | sed -e 's/^\(["<]\)/#include \1/'
2338 }
2339
2340 # func_get_link_directive module
2341 # Input:
2342 # - local_gnulib_dir  from --local-dir
2343 # - modcache          true or false, from --cache-modules/--no-cache-modules
2344 func_get_link_directive ()
2345 {
2346   if ! $modcache; then
2347     func_lookup_file "modules/$1"
2348     sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
2349   else
2350     func_cache_lookup_module "$1"
2351     # Output the field's value, including the final newline (if any).
2352     if $have_associative; then
2353       if eval 'test -n "${modcache_link[$1]+set}"'; then
2354         eval 'echo "${modcache_link[$1]}"'
2355       fi
2356     else
2357       eval "field_set=\"\$${cachevar}_link_set\""
2358       if test -n "$field_set"; then
2359         eval "field_value=\"\$${cachevar}_link\""
2360         echo "${field_value}"
2361       fi
2362     fi
2363   fi
2364 }
2365
2366 # func_get_license module
2367 # Input:
2368 # - local_gnulib_dir  from --local-dir
2369 # - modcache          true or false, from --cache-modules/--no-cache-modules
2370 func_get_license ()
2371 {
2372   {
2373     if ! $modcache; then
2374       func_lookup_file "modules/$1"
2375       sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
2376     else
2377       func_cache_lookup_module "$1"
2378       # Output the field's value, including the final newline (if any).
2379       if $have_associative; then
2380         if eval 'test -n "${modcache_license[$1]+set}"'; then
2381           eval 'echo "${modcache_license[$1]}"'
2382         fi
2383       else
2384         eval "field_set=\"\$${cachevar}_license_set\""
2385         if test -n "$field_set"; then
2386           eval "field_value=\"\$${cachevar}_license\""
2387           echo "${field_value}"
2388         fi
2389       fi
2390     fi
2391     # The default is GPL.
2392     echo "GPL"
2393   } | sed -e 's,^ *$,,' | sed -e 1q
2394 }
2395
2396 # func_get_maintainer module
2397 # Input:
2398 # - local_gnulib_dir  from --local-dir
2399 # - modcache          true or false, from --cache-modules/--no-cache-modules
2400 func_get_maintainer ()
2401 {
2402   if ! $modcache; then
2403     func_lookup_file "modules/$1"
2404     sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
2405   else
2406     func_cache_lookup_module "$1"
2407     # Output the field's value, including the final newline (if any).
2408     if $have_associative; then
2409       if eval 'test -n "${modcache_maintainer[$1]+set}"'; then
2410         eval 'echo "${modcache_maintainer[$1]}"'
2411       fi
2412     else
2413       eval "field_set=\"\$${cachevar}_maintainer_set\""
2414       if test -n "$field_set"; then
2415         eval "field_value=\"\$${cachevar}_maintainer\""
2416         echo "${field_value}"
2417       fi
2418     fi
2419   fi
2420 }
2421
2422 # func_get_tests_module module
2423 # Input:
2424 # - local_gnulib_dir  from --local-dir
2425 func_get_tests_module ()
2426 {
2427   # The naming convention for tests modules is hardwired: ${module}-tests.
2428   if test -f "$gnulib_dir/modules/$1"-tests \
2429      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
2430           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
2431     echo "$1"-tests
2432   fi
2433 }
2434
2435 # func_acceptable module
2436 # tests whether a module is acceptable.
2437 # Input:
2438 # - avoidlist       list of modules to avoid
2439 func_acceptable ()
2440 {
2441   for avoid in $avoidlist; do
2442     if test "$avoid" = "$1"; then
2443       return 1
2444     fi
2445   done
2446   return 0
2447 }
2448
2449 # sed expression to keep the first 32 characters of each line.
2450 sed_first_32_chars='s/^\(................................\).*/\1/'
2451
2452 # func_module_shellfunc_name module
2453 # computes the shell function name that will contain the m4 macros for the module.
2454 # Input:
2455 # - macro_prefix    prefix to use
2456 # Output:
2457 # - shellfunc       shell function name
2458 func_module_shellfunc_name ()
2459 {
2460   case $1 in
2461     *[!a-zA-Z0-9_]*)
2462       shellfunc=func_${macro_prefix}_gnulib_m4code_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2463     *)
2464       shellfunc=func_${macro_prefix}_gnulib_m4code_$1 ;;
2465   esac
2466 }
2467
2468 # func_module_shellvar_name module
2469 # computes the shell variable name the will be set to true once the m4 macros
2470 # for the module have been executed.
2471 # Output:
2472 # - shellvar        shell variable name
2473 func_module_shellvar_name ()
2474 {
2475   case $1 in
2476     *[!a-zA-Z0-9_]*)
2477       shellvar=${macro_prefix}_gnulib_enabled_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2478     *)
2479       shellvar=${macro_prefix}_gnulib_enabled_$1 ;;
2480   esac
2481 }
2482
2483 # func_module_conditional_name module
2484 # computes the automake conditional name for the module.
2485 # Output:
2486 # - conditional     name of automake conditional
2487 func_module_conditional_name ()
2488 {
2489   case $1 in
2490     *[!a-zA-Z0-9_]*)
2491       conditional=${macro_prefix}_GNULIB_ENABLED_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2492     *)
2493       conditional=${macro_prefix}_GNULIB_ENABLED_$1 ;;
2494   esac
2495 }
2496
2497 # func_uncond_add_module B
2498 # notes the presence of B as an unconditional module.
2499 #
2500 # func_conddep_add_module A B cond
2501 # notes the presence of a conditional dependency from module A to module B,
2502 # subject to the condition that A is enabled and cond is true.
2503 #
2504 # func_cond_module_p B
2505 # tests whether module B is conditional.
2506 #
2507 # func_cond_module_condition A B
2508 # returns the condition when B should be enabled as a dependency of A, once the
2509 # m4 code for A has been executed.
2510 # Output: - condition
2511 #
2512 if $have_associative; then
2513   declare -A conddep_isuncond
2514   declare -A conddep_dependers
2515   declare -A conddep_condition
2516   func_uncond_add_module ()
2517   {
2518     eval 'conddep_isuncond[$1]=true'
2519     eval 'unset conddep_dependers[$1]'
2520   }
2521   func_conddep_add_module ()
2522   {
2523     eval 'isuncond="${conddep_isuncond[$2]}"'
2524     if test -z "$isuncond"; then
2525       # No unconditional dependency to B known at this point.
2526       eval 'conddep_dependers[$2]="${conddep_dependers[$2]} $1"'
2527       eval 'conddep_condition[$1---$2]="$3"'
2528     fi
2529   }
2530   func_cond_module_p ()
2531   {
2532     eval 'previous_dependers="${conddep_dependers[$1]}"'
2533     test -n "$previous_dependers"
2534   }
2535   func_cond_module_condition ()
2536   {
2537     eval 'condition="${conddep_condition[$1---$2]}"'
2538   }
2539 else
2540   func_uncond_add_module ()
2541   {
2542     case $1 in
2543       *[!a-zA-Z0-9_]*)
2544         suffix=`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2545       *)
2546         suffix=$1 ;;
2547     esac
2548     eval 'conddep_isuncond_'"$suffix"'=true'
2549     eval 'unset conddep_dependers_'"$suffix"
2550   }
2551   func_conddep_add_module ()
2552   {
2553     case $2 in
2554       *[!a-zA-Z0-9_]*)
2555         suffix=`echo "$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2556       *)
2557         suffix=$2 ;;
2558     esac
2559     eval 'isuncond="${conddep_isuncond_'"$suffix"'}"'
2560     if test -z "$isuncond"; then
2561       eval 'conddep_dependers_'"$suffix"'="${conddep_dependers_'"$suffix"'} $1"'
2562       suffix=`echo "$1---$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"`
2563       eval 'conddep_condition_'"$suffix"'="$3"'
2564     fi
2565   }
2566   func_cond_module_p ()
2567   {
2568     case $1 in
2569       *[!a-zA-Z0-9_]*)
2570         suffix=`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
2571       *)
2572         suffix=$1 ;;
2573     esac
2574     eval 'previous_dependers="${conddep_dependers_'"$suffix"'}"'
2575     test -n "$previous_dependers"
2576   }
2577   func_cond_module_condition ()
2578   {
2579     suffix=`echo "$1---$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"`
2580     eval 'condition="${conddep_condition_'"$suffix"'}"'
2581   }
2582 fi
2583
2584 sed_dependencies_without_conditions='s/ *\[.*//'
2585
2586 # func_modules_transitive_closure
2587 # Input:
2588 # - local_gnulib_dir  from --local-dir
2589 # - modcache        true or false, from --cache-modules/--no-cache-modules
2590 # - modules         list of specified modules
2591 # - inctests        true if tests should be included, blank otherwise
2592 # - incobsolete     true if obsolete modules among dependencies should be
2593 #                   included, blank otherwise
2594 # - inc_cxx_tests   true if C++ interoperability tests should be included,
2595 #                   blank otherwise
2596 # - inc_longrunning_tests  true if long-runnings tests should be included,
2597 #                          blank otherwise
2598 # - inc_privileged_tests  true if tests that require root privileges should be
2599 #                         included, blank otherwise
2600 # - inc_unportable_tests  true if tests that fail on some platforms should be
2601 #                         included, blank otherwise
2602 # - inc_all_direct_tests   true if all kinds of problematic unit tests among
2603 #                          the unit tests of the specified modules should be
2604 #                          included, blank otherwise
2605 # - inc_all_indirect_tests   true if all kinds of problematic unit tests among
2606 #                            the unit tests of the dependencies should be
2607 #                            included, blank otherwise
2608 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
2609 #                    blank otherwise
2610 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
2611 #                           blank otherwise
2612 # - excl_privileged_tests  true if tests that require root privileges should be
2613 #                          excluded, blank otherwise
2614 # - excl_unportable_tests  true if tests that fail on some platforms should be
2615 #                          excluded, blank otherwise
2616 # - avoidlist       list of modules to avoid
2617 # - cond_dependencies  true if conditional dependencies shall be supported,
2618 #                      blank otherwise
2619 # - tmp             pathname of a temporary directory
2620 # Output:
2621 # - modules         list of modules, including dependencies
2622 # - conddep_dependers, conddep_condition  information about conditionally
2623 #                                         enabled modules
2624 func_modules_transitive_closure ()
2625 {
2626   sed_escape_dependency='s|\([/.]\)|\\\1|g'
2627   # In order to process every module only once (for speed), process an "input
2628   # list" of modules, producing an "output list" of modules. During each round,
2629   # more modules can be queued in the input list. Once a module on the input
2630   # list has been processed, it is added to the "handled list", so we can avoid
2631   # to process it again.
2632   handledmodules=
2633   inmodules="$modules"
2634   outmodules=
2635   fmtc_inc_all_tests="$inc_all_direct_tests"
2636   if test "$cond_dependencies" = true; then
2637     for module in $inmodules; do
2638       func_verify_module
2639       if test -n "$module"; then
2640         if func_acceptable $module; then
2641           func_uncond_add_module $module
2642         fi
2643       fi
2644     done
2645   fi
2646   while test -n "$inmodules"; do
2647     inmodules_this_round="$inmodules"
2648     inmodules=                    # Accumulator, queue for next round
2649     for module in $inmodules_this_round; do
2650       func_verify_module
2651       if test -n "$module"; then
2652         if func_acceptable $module; then
2653           func_append outmodules " $module"
2654           if test "$cond_dependencies" = true; then
2655             if func_get_automake_snippet_conditional $module | grep '^if ' > /dev/null; then
2656               # A module whose Makefile.am snippet contains a reference to an
2657               # automake conditional. If we were to use it conditionally, we
2658               # would get an error
2659               #   configure: error: conditional "..." was never defined.
2660               # because automake 1.11.1 does not handle nested conditionals
2661               # correctly. As a workaround, make the module unconditional.
2662               func_uncond_add_module $module
2663             fi
2664             if func_cond_module_p $module; then
2665               conditional=true
2666             else
2667               conditional=false
2668             fi
2669           fi
2670           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
2671           # Duplicate dependencies are harmless, but Jim wants a warning.
2672           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
2673           if test -n "$duplicated_deps"; then
2674             func_warning "module $module has duplicated dependencies: "`echo $duplicated_deps`
2675           fi
2676           if test -n "$inctests"; then
2677             testsmodule=`func_get_tests_module $module`
2678             if test -n "$testsmodule"; then
2679               deps="$deps $testsmodule"
2680             fi
2681           fi
2682           for dep in $deps; do
2683             # Determine whether to include the dependency or tests module.
2684             inc=true
2685             for word in `func_get_status $dep`; do
2686               case "$word" in
2687                 obsolete)
2688                   test -n "$incobsolete" \
2689                     || inc=false
2690                   ;;
2691                 c++-test)
2692                   test -z "$excl_cxx_tests" \
2693                     || inc=false
2694                   test -n "$fmtc_inc_all_tests" || test -n "$inc_cxx_tests" \
2695                     || inc=false
2696                   ;;
2697                 longrunning-test)
2698                   test -z "$excl_longrunning_tests" \
2699                     || inc=false
2700                   test -n "$fmtc_inc_all_tests" || test -n "$inc_longrunning_tests" \
2701                     || inc=false
2702                   ;;
2703                 privileged-test)
2704                   test -z "$excl_privileged_tests" \
2705                     || inc=false
2706                   test -n "$fmtc_inc_all_tests" || test -n "$inc_privileged_tests" \
2707                     || inc=false
2708                   ;;
2709                 unportable-test)
2710                   test -z "$excl_unportable_tests" \
2711                     || inc=false
2712                   test -n "$fmtc_inc_all_tests" || test -n "$inc_unportable_tests" \
2713                     || inc=false
2714                   ;;
2715                 *-test)
2716                   test -n "$fmtc_inc_all_tests" \
2717                     || inc=false
2718                   ;;
2719               esac
2720             done
2721             if $inc; then
2722               func_append inmodules " $dep"
2723               if test "$cond_dependencies" = true; then
2724                 escaped_dep=`echo "$dep" | sed -e "$sed_escape_dependency"`
2725                 sed_extract_condition1='/^ *'"$escaped_dep"' *$/{
2726                   s/^.*$/true/p
2727                 }'
2728                 sed_extract_condition2='/^ *'"$escaped_dep"' *\[.*\] *$/{
2729                   s/^ *'"$escaped_dep"' *\[\(.*\)\] *$/\1/p
2730                 }'
2731                 condition=`func_get_dependencies $module | sed -n -e "$sed_extract_condition1" -e "$sed_extract_condition2"`
2732                 if test "$condition" = true; then
2733                   condition=
2734                 fi
2735                 if test -n "$condition"; then
2736                   func_conddep_add_module "$module" "$dep" "$condition"
2737                 else
2738                   if $conditional; then
2739                     func_conddep_add_module "$module" "$dep" true
2740                   else
2741                     func_uncond_add_module "$dep"
2742                   fi
2743                 fi
2744               fi
2745             fi
2746           done
2747         fi
2748       fi
2749     done
2750     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
2751     # Remove $handledmodules from $inmodules.
2752     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
2753     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
2754     fmtc_inc_all_tests="$inc_all_indirect_tests"
2755   done
2756   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
2757   rm -f "$tmp"/queued-modules
2758 }
2759
2760 # func_show_module_list
2761 # Input:
2762 # - specified_modules  list of specified modules (one per line, sorted)
2763 # - modules         complete list of modules (one per line, sorted)
2764 # - tmp             pathname of a temporary directory
2765 func_show_module_list ()
2766 {
2767   if case "$TERM" in
2768        xterm*) test -t 1;;
2769        *) false;;
2770      esac; then
2771     # Assume xterm compatible escape sequences.
2772     bold_on=`printf '\x1b[1m'`
2773     bold_off=`printf '\x1b[0m'`
2774   else
2775     bold_on=
2776     bold_off=
2777   fi
2778   echo "Module list with included dependencies (indented):"
2779   echo "$specified_modules" | sed -e '/^$/d' -e 's/$/| /' > "$tmp"/specified-modules
2780   echo "$modules" | sed -e '/^$/d' \
2781     | LC_ALL=C join -t '|' -a2 "$tmp"/specified-modules - \
2782     | sed -e 's/^\(.*\)|.*/|\1/' -e 's/^/    /' -e 's/^    |\(.*\)$/  '"${bold_on}"'\1'"${bold_off}"'/'
2783 }
2784
2785 # func_modules_transitive_closure_separately
2786 # Determine main module list and tests-related module list separately.
2787 # The main module list is the transitive closure of the specified modules,
2788 # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2789 # is specified, it will consist only of LGPLed source.
2790 # The tests-related module list is the transitive closure of the specified
2791 # modules, including tests modules, minus the main module list excluding
2792 # modules of applicability 'all'. Its lib/* sources (brought in through
2793 # dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
2794 # source, even if --lgpl is specified.
2795 # Input:
2796 # - local_gnulib_dir  from --local-dir
2797 # - modcache        true or false, from --cache-modules/--no-cache-modules
2798 # - specified_modules  list of specified modules
2799 # - inctests        true if tests should be included, blank otherwise
2800 # - incobsolete     true if obsolete modules among dependencies should be
2801 #                   included, blank otherwise
2802 # - inc_cxx_tests   true if C++ interoperability tests should be included,
2803 #                   blank otherwise
2804 # - inc_longrunning_tests  true if long-runnings tests should be included,
2805 #                          blank otherwise
2806 # - inc_privileged_tests  true if tests that require root privileges should be
2807 #                         included, blank otherwise
2808 # - inc_unportable_tests  true if tests that fail on some platforms should be
2809 #                         included, blank otherwise
2810 # - inc_all_direct_tests   true if all kinds of problematic unit tests among
2811 #                          the unit tests of the specified modules should be
2812 #                          included, blank otherwise
2813 # - inc_all_indirect_tests   true if all kinds of problematic unit tests among
2814 #                            the unit tests of the dependencies should be
2815 #                            included, blank otherwise
2816 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
2817 #                    blank otherwise
2818 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
2819 #                           blank otherwise
2820 # - excl_privileged_tests  true if tests that require root privileges should be
2821 #                          excluded, blank otherwise
2822 # - excl_unportable_tests  true if tests that fail on some platforms should be
2823 #                          excluded, blank otherwise
2824 # - avoidlist       list of modules to avoid
2825 # - cond_dependencies  true if conditional dependencies shall be supported,
2826 #                      blank otherwise
2827 # - tmp             pathname of a temporary directory
2828 # Output:
2829 # - main_modules    list of modules, including dependencies
2830 # - testsrelated_modules  list of tests-related modules, including dependencies
2831 # - conddep_dependers, conddep_condition  information about conditionally
2832 #                                         enabled modules
2833 func_modules_transitive_closure_separately ()
2834 {
2835   # Determine main module list.
2836   saved_inctests="$inctests"
2837   inctests=""
2838   modules="$specified_modules"
2839   func_modules_transitive_closure
2840   main_modules="$modules"
2841   inctests="$saved_inctests"
2842   if test $verbose -ge 1; then
2843     echo "Main module list:"
2844     echo "$main_modules" | sed -e 's/^/  /'
2845   fi
2846   # Determine tests-related module list.
2847   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
2848   testsrelated_modules=`for module in $main_modules; do
2849                           if test \`func_get_applicability $module\` = main; then
2850                             echo $module
2851                           fi
2852                         done \
2853                         | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
2854   if test $verbose -ge 1; then
2855     echo "Tests-related module list:"
2856     echo "$testsrelated_modules" | sed -e 's/^/  /'
2857   fi
2858 }
2859
2860 # func_determine_use_libtests
2861 # Determines whether a $testsbase/libtests.a is needed.
2862 # Input:
2863 # - local_gnulib_dir  from --local-dir
2864 # - modcache        true or false, from --cache-modules/--no-cache-modules
2865 # - testsrelated_modules  list of tests-related modules, including dependencies
2866 # Output:
2867 # - use_libtests    true if a $testsbase/libtests.a is needed, false otherwise
2868 func_determine_use_libtests ()
2869 {
2870   use_libtests=false
2871   for module in $testsrelated_modules; do
2872     func_verify_nontests_module
2873     if test -n "$module"; then
2874       all_files=`func_get_filelist $module`
2875       # Test whether some file in $all_files lies in lib/.
2876       for f in $all_files; do
2877         case $f in
2878           lib/*)
2879             use_libtests=true
2880             break 2
2881             ;;
2882         esac
2883       done
2884     fi
2885   done
2886 }
2887
2888 # func_modules_add_dummy
2889 # Input:
2890 # - local_gnulib_dir  from --local-dir
2891 # - modcache        true or false, from --cache-modules/--no-cache-modules
2892 # - modules         list of modules, including dependencies
2893 # Output:
2894 # - modules         list of modules, including 'dummy' if needed
2895 func_modules_add_dummy ()
2896 {
2897   # Determine whether any module provides a lib_SOURCES augmentation.
2898   have_lib_SOURCES=
2899   sed_remove_backslash_newline=':a
2900 /\\$/{
2901 s/\\$//
2902 N
2903 s/\n//
2904 ba
2905 }'
2906   for module in $modules; do
2907     func_verify_nontests_module
2908     if test -n "$module"; then
2909       # Extract the value of "lib_SOURCES += ...".
2910       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
2911         # Ignore .h files since they are not compiled.
2912         case "$file" in
2913           *.h) ;;
2914           *)
2915             have_lib_SOURCES=yes
2916             break 2
2917             ;;
2918         esac
2919       done
2920     fi
2921   done
2922   # Add the dummy module, to make sure the library will be non-empty.
2923   if test -z "$have_lib_SOURCES"; then
2924     if func_acceptable "dummy"; then
2925       func_append modules " dummy"
2926     fi
2927   fi
2928 }
2929
2930 # func_modules_add_dummy_separately
2931 # Input:
2932 # - local_gnulib_dir  from --local-dir
2933 # - modcache        true or false, from --cache-modules/--no-cache-modules
2934 # - main_modules    list of modules, including dependencies
2935 # - testsrelated_modules  list of tests-related modules, including dependencies
2936 # - use_libtests    true if a $testsbase/libtests.a is needed, false otherwise
2937 # Output:
2938 # - main_modules    list of modules, including 'dummy' if needed
2939 # - testsrelated_modules  list of tests-related modules, including 'dummy' if
2940 #                         needed
2941 func_modules_add_dummy_separately ()
2942 {
2943   # Add the dummy module to the main module list if needed.
2944   modules="$main_modules"
2945   func_modules_add_dummy
2946   main_modules="$modules"
2947
2948   # Add the dummy module to the tests-related module list if needed.
2949   if $use_libtests; then
2950     modules="$testsrelated_modules"
2951     func_modules_add_dummy
2952     testsrelated_modules="$modules"
2953   fi
2954 }
2955
2956 # func_modules_notice
2957 # Input:
2958 # - local_gnulib_dir  from --local-dir
2959 # - modcache        true or false, from --cache-modules/--no-cache-modules
2960 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2961 # - modules         list of modules, including dependencies
2962 func_modules_notice ()
2963 {
2964   if test $verbose -ge -1; then
2965     for module in $modules; do
2966       func_verify_module
2967       if test -n "$module"; then
2968         msg=`func_get_notice $module`
2969         if test -n "$msg"; then
2970           echo "Notice from module $module:"
2971           echo "$msg" | sed -e 's/^/  /'
2972         fi
2973       fi
2974     done
2975   fi
2976 }
2977
2978 # func_modules_to_filelist
2979 # Input:
2980 # - local_gnulib_dir  from --local-dir
2981 # - modcache        true or false, from --cache-modules/--no-cache-modules
2982 # - modules         list of modules, including dependencies
2983 # Output:
2984 # - files           list of files
2985 func_modules_to_filelist ()
2986 {
2987   files=
2988   for module in $modules; do
2989     func_verify_module
2990     if test -n "$module"; then
2991       fs=`func_get_filelist $module`
2992       func_append files " $fs"
2993     fi
2994   done
2995   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
2996 }
2997
2998 # func_modules_to_filelist_separately
2999 # Determine the final file lists.
3000 # They must be computed separately, because files in lib/* go into
3001 # $sourcebase/ if they are in the main file list but into $testsbase/
3002 # if they are in the tests-related file list. Furthermore lib/dummy.c
3003 # can be in both.
3004 # Input:
3005 # - local_gnulib_dir  from --local-dir
3006 # - modcache        true or false, from --cache-modules/--no-cache-modules
3007 # - main_modules    list of modules, including dependencies
3008 # - testsrelated_modules  list of tests-related modules, including dependencies
3009 func_modules_to_filelist_separately ()
3010 {
3011   # Determine final main file list.
3012   modules="$main_modules"
3013   func_modules_to_filelist
3014   main_files="$files"
3015   # Determine final tests-related file list.
3016   modules="$testsrelated_modules"
3017   func_modules_to_filelist
3018   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
3019   # Merge both file lists.
3020   sed_remove_empty_lines='/^$/d'
3021   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
3022   if test $verbose -ge 0; then
3023     echo "File list:"
3024     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
3025     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
3026   fi
3027 }
3028
3029 # func_compute_include_guard_prefix
3030 # Determine include_guard_prefix.
3031 # Input:
3032 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3033 # Output:
3034 # - include_guard_prefix  replacement for ${gl_include_guard_prefix}
3035 # - sed_replace_include_guard_prefix
3036 #                   sed expression for resolving ${gl_include_guard_prefix}
3037 func_compute_include_guard_prefix ()
3038 {
3039   if test "$macro_prefix" = gl; then
3040     include_guard_prefix='GL'
3041   else
3042     include_guard_prefix='GL_'`echo "$macro_prefix" | LC_ALL=C tr '[a-z]' '[A-Z]'`
3043   fi
3044   sed_replace_include_guard_prefix='s/\${gl_include_guard_prefix}/'"${include_guard_prefix}"'/g'
3045 }
3046
3047 # func_execute_command command [args...]
3048 # Executes a command.
3049 # Uses also the variables
3050 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
3051 func_execute_command ()
3052 {
3053   if test $verbose -ge 0; then
3054     echo "executing $*"
3055     "$@"
3056   else
3057     # Commands like automake produce output to stderr even when they succeed.
3058     # Turn this output off if the command succeeds.
3059     "$@" > "$tmp"/cmdout 2>&1
3060     cmdret=$?
3061     if test $cmdret = 0; then
3062       rm -f "$tmp"/cmdout
3063     else
3064       echo "executing $*"
3065       cat "$tmp"/cmdout 1>&2
3066       rm -f "$tmp"/cmdout
3067       (exit $cmdret)
3068     fi
3069   fi
3070 }
3071
3072 # func_dest_tmpfilename file
3073 # determines the name of a temporary file (file is relative to destdir).
3074 # Input:
3075 # - destdir         target directory
3076 # - doit            : if actions shall be executed, false if only to be printed
3077 # - tmp             pathname of a temporary directory
3078 # Sets variable:
3079 #   - tmpfile       absolute filename of the temporary file
3080 func_dest_tmpfilename ()
3081 {
3082   if $doit; then
3083     # Put the new contents of $file in a file in the same directory (needed
3084     # to guarantee that an 'mv' to "$destdir/$file" works).
3085     tmpfile="$destdir/$1.tmp"
3086   else
3087     # Put the new contents of $file in a file in a temporary directory
3088     # (because the directory of "$file" might not exist).
3089     tmpfile="$tmp"/`basename "$1"`.tmp
3090   fi
3091 }
3092
3093 # func_add_file
3094 # copies a file from gnulib into the destination directory. The destination
3095 # is known to not exist.
3096 # Input:
3097 # - destdir         target directory
3098 # - local_gnulib_dir  from --local-dir
3099 # - modcache        true or false, from --cache-modules/--no-cache-modules
3100 # - f               the original file name
3101 # - lookedup_file   name of the merged (combined) file
3102 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
3103 # - g               the rewritten file name
3104 # - tmpfile         absolute filename of the temporary file
3105 # - doit            : if actions shall be executed, false if only to be printed
3106 # - symbolic        true if files should be symlinked, copied otherwise
3107 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
3108 #                   copied otherwise
3109 func_add_file ()
3110 {
3111   if $doit; then
3112     echo "Copying file $g"
3113     if { test -n "$symbolic" \
3114          || { test -n "$lsymbolic" \
3115               && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
3116        && test -z "$lookedup_tmp" \
3117        && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
3118       func_ln_if_changed "$lookedup_file" "$destdir/$g"
3119     else
3120       mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
3121     fi
3122   else
3123     echo "Copy file $g"
3124   fi
3125 }
3126
3127 # func_update_file
3128 # copies a file from gnulib into the destination directory. The destination
3129 # is known to exist.
3130 # Input:
3131 # - destdir         target directory
3132 # - local_gnulib_dir  from --local-dir
3133 # - modcache        true or false, from --cache-modules/--no-cache-modules
3134 # - f               the original file name
3135 # - lookedup_file   name of the merged (combined) file
3136 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
3137 # - g               the rewritten file name
3138 # - tmpfile         absolute filename of the temporary file
3139 # - doit            : if actions shall be executed, false if only to be printed
3140 # - symbolic        true if files should be symlinked, copied otherwise
3141 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
3142 #                   copied otherwise
3143 # - already_present  nonempty if the file should already exist, empty otherwise
3144 func_update_file ()
3145 {
3146   if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
3147     : # The file has not changed.
3148   else
3149     # Replace the file.
3150     if $doit; then
3151       if test -n "$already_present"; then
3152         echo "Updating file $g (backup in ${g}~)"
3153       else
3154         echo "Replacing file $g (non-gnulib code backed up in ${g}~) !!"
3155       fi
3156       mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
3157       if { test -n "$symbolic" \
3158            || { test -n "$lsymbolic" \
3159                 && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
3160          && test -z "$lookedup_tmp" \
3161          && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
3162         func_ln_if_changed "$lookedup_file" "$destdir/$g"
3163       else
3164         mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
3165       fi
3166     else
3167       if test -n "$already_present"; then
3168         echo "Update file $g (backup in ${g}~)"
3169       else
3170         echo "Replace file $g (non-gnulib code backed up in ${g}~) !!"
3171       fi
3172     fi
3173   fi
3174 }
3175
3176 # func_emit_lib_Makefile_am
3177 # emits the contents of library makefile to standard output.
3178 # Input:
3179 # - local_gnulib_dir  from --local-dir
3180 # - modcache        true or false, from --cache-modules/--no-cache-modules
3181 # - modules         list of modules, including dependencies
3182 # - libname         library name
3183 # - pobase          directory relative to destdir where to place *.po files
3184 # - auxdir          directory relative to destdir where to place build aux files
3185 # - makefile_name   from --makefile-name
3186 # - libtool         true if libtool will be used, false or blank otherwise
3187 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3188 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3189 # - witness_c_macro  from --witness-c-macro
3190 # - actioncmd       (optional) command that will reproduce this invocation
3191 # - for_test        true if creating a package for testing, false otherwise
3192 # - sed_replace_include_guard_prefix
3193 #                   sed expression for resolving ${gl_include_guard_prefix}
3194 # - destfile        filename relative to destdir of makefile being generated
3195 # Input/Output:
3196 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
3197 #                   list of edits to be done to Makefile.am variables
3198 # Output:
3199 # - uses_subdirs    nonempty if object files in subdirs exist
3200 func_emit_lib_Makefile_am ()
3201 {
3202   # When creating an includable Makefile.am snippet, augment variables with
3203   # += instead of assigning them.
3204   if test -n "$makefile_name"; then
3205     assign='+='
3206   else
3207     assign='='
3208   fi
3209   if test "$libtool" = true; then
3210     libext=la
3211     perhapsLT=LT
3212     sed_eliminate_LDFLAGS="$sed_noop"
3213   else
3214     libext=a
3215     perhapsLT=
3216     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
3217   fi
3218   if $for_test; then
3219     # When creating a package for testing: Attempt to provoke failures,
3220     # especially link errors, already during "make" rather than during
3221     # "make check", because "make check" is not possible in a cross-compiling
3222     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
3223     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
3224   else
3225     sed_transform_check_PROGRAMS="$sed_noop"
3226   fi
3227   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3228   echo "## Process this file with automake to produce Makefile.in."
3229   func_emit_copyright_notice
3230   if test -n "$actioncmd"; then
3231     # The maximum line length (excluding the terminating newline) of any file
3232     # that is to be preprocessed by config.status is 3070.  config.status uses
3233     # awk, and the HP-UX 11.00 awk fails if a line has length >= 3071;
3234     # similarly, the IRIX 6.5 awk fails if a line has length >= 3072.
3235     len=`echo "$actioncmd" | wc -c`
3236     if test -n "$len" && test "$len" -le 3000; then
3237       echo "# Reproduce by: $actioncmd"
3238     fi
3239   fi
3240   echo
3241   uses_subdirs=
3242   {
3243     for module in $modules; do
3244       func_verify_nontests_module
3245       if test -n "$module"; then
3246         {
3247           func_get_automake_snippet_conditional "$module" |
3248             LC_ALL=C \
3249             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
3250                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
3251                 -e "$sed_eliminate_LDFLAGS" \
3252                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
3253                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
3254                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
3255                 -e "$sed_transform_check_PROGRAMS" \
3256                 -e "$sed_replace_include_guard_prefix"
3257           if test "$module" = 'alloca'; then
3258             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
3259             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
3260           fi
3261         } > "$tmp"/amsnippet1
3262         {
3263           func_get_automake_snippet_unconditional "$module" |
3264             LC_ALL=C sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
3265         } > "$tmp"/amsnippet2
3266         # Skip the contents if it's entirely empty.
3267         if grep '[^      ]' "$tmp"/amsnippet1 "$tmp"/amsnippet2 > /dev/null ; then
3268           echo "## begin gnulib module $module"
3269           echo
3270           if test "$cond_dependencies" = true; then
3271             if func_cond_module_p "$module"; then
3272               func_module_conditional_name "$module"
3273               echo "if $conditional"
3274             fi
3275           fi
3276           cat "$tmp"/amsnippet1
3277           if test "$cond_dependencies" = true; then
3278             if func_cond_module_p "$module"; then
3279               echo "endif"
3280             fi
3281           fi
3282           cat "$tmp"/amsnippet2
3283           echo "## end   gnulib module $module"
3284           echo
3285         fi
3286         rm -f "$tmp"/amsnippet1 "$tmp"/amsnippet2
3287         # Test whether there are some source files in subdirectories.
3288         for f in `func_get_filelist "$module"`; do
3289           case $f in
3290             lib/*/*.c)
3291               uses_subdirs=yes
3292               break
3293               ;;
3294           esac
3295         done
3296       fi
3297     done
3298   } > "$tmp"/allsnippets
3299   if test -z "$makefile_name"; then
3300     # If there are source files in subdirectories, prevent collision of the
3301     # object files (example: hash.c and libxml/hash.c).
3302     subdir_options=
3303     if test -n "$uses_subdirs"; then
3304       subdir_options=' subdir-objects'
3305     fi
3306     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
3307   fi
3308   echo
3309   if test -z "$makefile_name"; then
3310     echo "SUBDIRS ="
3311     echo "noinst_HEADERS ="
3312     echo "noinst_LIBRARIES ="
3313     echo "noinst_LTLIBRARIES ="
3314     # Automake versions < 1.9b create an empty pkgdatadir at installation time
3315     # if you specify pkgdata_DATA to empty. This is a workaround.
3316     if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
3317       echo "pkgdata_DATA ="
3318     fi
3319     echo "EXTRA_DIST ="
3320     echo "BUILT_SOURCES ="
3321     echo "SUFFIXES ="
3322   fi
3323   echo "MOSTLYCLEANFILES $assign core *.stackdump"
3324   if test -z "$makefile_name"; then
3325     echo "MOSTLYCLEANDIRS ="
3326     echo "CLEANFILES ="
3327     echo "DISTCLEANFILES ="
3328     echo "MAINTAINERCLEANFILES ="
3329   fi
3330   # Execute edits that apply to the Makefile.am being generated.
3331   edit=0
3332   while test $edit != $makefile_am_edits; do
3333     edit=`expr $edit + 1`
3334     eval dir=\"\$makefile_am_edit${edit}_dir\"
3335     eval var=\"\$makefile_am_edit${edit}_var\"
3336     eval val=\"\$makefile_am_edit${edit}_val\"
3337     if test -n "$var"; then
3338       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
3339         echo "${var} += ${val}"
3340         eval "makefile_am_edit${edit}_var="
3341       fi
3342     fi
3343   done
3344   if test -z "$makefile_name"; then
3345     echo
3346     if $for_test; then
3347       cppflags_part1=" -DGNULIB_STRICT_CHECKING=1"
3348     else
3349       cppflags_part1=
3350     fi
3351     if test -n "$witness_c_macro"; then
3352       cppflags_part2=" -D$witness_c_macro=1"
3353     else
3354       cppflags_part2=
3355     fi
3356     echo "AM_CPPFLAGS =$cppflags_part1$cppflags_part2"
3357     echo "AM_CFLAGS ="
3358   fi
3359   echo
3360   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
3361      || { test -n "$makefile_name" \
3362           && test -f "$sourcebase/Makefile.am" \
3363           && LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$sourcebase/Makefile.am" > /dev/null; \
3364         }; then
3365     # One of the snippets or the user's Makefile.am already specifies an
3366     # installation location for the library. Don't confuse automake by saying
3367     # it should not be installed.
3368     :
3369   else
3370     # By default, the generated library should not be installed.
3371     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
3372   fi
3373   echo
3374   echo "${libname}_${libext}_SOURCES ="
3375   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
3376   # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
3377   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
3378   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
3379   echo "EXTRA_${libname}_${libext}_SOURCES ="
3380   if test "$libtool" = true; then
3381     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
3382     echo "${libname}_${libext}_LDFLAGS += -no-undefined"
3383     # Synthesize an ${libname}_${libext}_LDFLAGS augmentation by combining
3384     # the link dependencies of all modules.
3385     for module in $modules; do
3386       func_verify_nontests_module
3387       if test -n "$module"; then
3388         func_get_link_directive "$module"
3389       fi
3390     done \
3391       | LC_ALL=C sed -e '/^$/d' -e 's/ when linking with libtool.*//' \
3392       | LC_ALL=C sort -u \
3393       | LC_ALL=C sed -e 's/^/'"${libname}_${libext}"'_LDFLAGS += /'
3394   fi
3395   echo
3396   if test -n "$pobase"; then
3397     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
3398     echo
3399   fi
3400   cat "$tmp"/allsnippets \
3401     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
3402   echo
3403   echo "mostlyclean-local: mostlyclean-generic"
3404   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
3405   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
3406   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
3407   echo "          fi; \\"
3408   echo "        done; \\"
3409   echo "        :"
3410   rm -f "$tmp"/allsnippets
3411 }
3412
3413 # func_emit_po_Makevars
3414 # emits the contents of po/ makefile parameterization to standard output.
3415 # Input:
3416 # - local_gnulib_dir  from --local-dir
3417 # - modcache        true or false, from --cache-modules/--no-cache-modules
3418 # - sourcebase      directory relative to destdir where to place source code
3419 # - pobase          directory relative to destdir where to place *.po files
3420 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3421 func_emit_po_Makevars ()
3422 {
3423   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3424   func_emit_copyright_notice
3425   echo
3426   echo "# Usually the message domain is the same as the package name."
3427   echo "# But here it has a '-gnulib' suffix."
3428   echo "DOMAIN = ${po_domain}-gnulib"
3429   echo
3430   echo "# These two variables depend on the location of this directory."
3431   echo "subdir = ${pobase}"
3432   echo "top_builddir = "`echo "$pobase" | sed -e 's,//*,/,g' -e 's,[^/][^/]*,..,g'`
3433   echo
3434   cat <<\EOF
3435 # These options get passed to xgettext.
3436 XGETTEXT_OPTIONS = \
3437   --keyword=_ --flag=_:1:pass-c-format \
3438   --keyword=N_ --flag=N_:1:pass-c-format \
3439   --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \
3440   --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \
3441   --flag=error:3:c-format --flag=error_at_line:5:c-format
3442
3443 # This is the copyright holder that gets inserted into the header of the
3444 # $(DOMAIN).pot file.  gnulib is copyrighted by the FSF.
3445 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
3446
3447 # This is the email address or URL to which the translators shall report
3448 # bugs in the untranslated strings:
3449 # - Strings which are not entire sentences, see the maintainer guidelines
3450 #   in the GNU gettext documentation, section 'Preparing Strings'.
3451 # - Strings which use unclear terms or require additional context to be
3452 #   understood.
3453 # - Strings which make invalid assumptions about notation of date, time or
3454 #   money.
3455 # - Pluralisation problems.
3456 # - Incorrect English spelling.
3457 # - Incorrect formatting.
3458 # It can be your email address, or a mailing list address where translators
3459 # can write to without being subscribed, or the URL of a web page through
3460 # which the translators can contact you.
3461 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
3462
3463 # This is the list of locale categories, beyond LC_MESSAGES, for which the
3464 # message catalogs shall be used.  It is usually empty.
3465 EXTRA_LOCALE_CATEGORIES =
3466
3467 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
3468 # context.  Possible values are "yes" and "no".  Set this to yes if the
3469 # package uses functions taking also a message context, like pgettext(), or
3470 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
3471 USE_MSGCTXT = no
3472 EOF
3473 }
3474
3475 # func_emit_po_POTFILES_in
3476 # emits the file list to be passed to xgettext to standard output.
3477 # Input:
3478 # - local_gnulib_dir  from --local-dir
3479 # - modcache        true or false, from --cache-modules/--no-cache-modules
3480 # - sourcebase      directory relative to destdir where to place source code
3481 # - files           list of new files
3482 func_emit_po_POTFILES_in ()
3483 {
3484   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3485   func_emit_copyright_notice
3486   echo
3487   echo "# List of files which contain translatable strings."
3488   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
3489 }
3490
3491 # func_emit_tests_Makefile_am witness_macro
3492 # emits the contents of tests makefile to standard output.
3493 # Input:
3494 # - local_gnulib_dir  from --local-dir
3495 # - modcache        true or false, from --cache-modules/--no-cache-modules
3496 # - modules         list of modules, including dependencies
3497 # - libname         library name
3498 # - auxdir          directory relative to destdir where to place build aux files
3499 # - makefile_name   from --makefile-name
3500 # - libtool         true if libtool will be used, false or blank otherwise
3501 # - sourcebase      relative directory containing lib source code
3502 # - m4base          relative directory containing autoconf macros
3503 # - testsbase       relative directory containing unit test code
3504 # - macro_prefix    prefix of gl_LIBOBJS macros to use
3505 # - witness_c_macro  from --witness-c-macro
3506 # - for_test        true if creating a package for testing, false otherwise
3507 # - single_configure  true if a single configure file should be generated,
3508 #                     false for a separate configure file for the tests
3509 # - use_libtests    true if a libtests.a should be built, false otherwise
3510 # - sed_replace_include_guard_prefix
3511 #                   sed expression for resolving ${gl_include_guard_prefix}
3512 # - destfile        filename relative to destdir of makefile being generated
3513 # Input/Output:
3514 # - makefile_am_edits and makefile_am_edit${edit}_{dir,var,val}
3515 #                   list of edits to be done to Makefile.am variables
3516 # Output:
3517 # - uses_subdirs    nonempty if object files in subdirs exist
3518 func_emit_tests_Makefile_am ()
3519 {
3520   witness_macro="$1"
3521   if test "$libtool" = true; then
3522     libext=la
3523     sed_eliminate_LDFLAGS="$sed_noop"
3524   else
3525     libext=a
3526     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
3527   fi
3528   if $for_test; then
3529     # When creating a package for testing: Attempt to provoke failures,
3530     # especially link errors, already during "make" rather than during
3531     # "make check", because "make check" is not possible in a cross-compiling
3532     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
3533     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
3534   else
3535     sed_transform_check_PROGRAMS="$sed_noop"
3536   fi
3537   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
3538   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
3539   echo "## Process this file with automake to produce Makefile.in."
3540   func_emit_copyright_notice
3541   echo
3542   uses_subdirs=
3543   {
3544     for module in $modules; do
3545       if $for_test && ! $single_configure; then
3546         func_verify_tests_module
3547       else
3548         func_verify_module
3549       fi
3550       if test -n "$module"; then
3551         {
3552           func_get_automake_snippet "$module" |
3553             LC_ALL=C \
3554             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
3555                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
3556                 -e "$sed_eliminate_LDFLAGS" \
3557                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
3558                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
3559                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
3560                 -e "$sed_transform_check_PROGRAMS" \
3561                 -e "$sed_replace_include_guard_prefix"
3562           if $use_libtests && test "$module" = 'alloca'; then
3563             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
3564             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
3565           fi
3566         } > "$tmp"/amsnippet
3567         # Skip the contents if it's entirely empty.
3568         if grep '[^      ]' "$tmp"/amsnippet > /dev/null ; then
3569           # Mention long-running tests at the end.
3570           ofd=3
3571           for word in `func_get_status "$module"`; do
3572             if test "$word" = 'longrunning-test'; then
3573               ofd=4
3574               break
3575             fi
3576           done
3577           { echo "## begin gnulib module $module"
3578             echo
3579             cat "$tmp"/amsnippet
3580             echo "## end   gnulib module $module"
3581             echo
3582           } >&$ofd
3583         fi
3584         rm -f "$tmp"/amsnippet
3585         # Test whether there are some source files in subdirectories.
3586         for f in `func_get_filelist "$module"`; do
3587           case $f in
3588             lib/*/*.c | tests/*/*.c)
3589               uses_subdirs=yes
3590               break
3591               ;;
3592           esac
3593         done
3594       fi
3595     done
3596   } 3> "$tmp"/main_snippets 4> "$tmp"/longrunning_snippets
3597   # Generate dependencies here, since it eases the debugging of test failures.
3598   # If there are source files in subdirectories, prevent collision of the
3599   # object files (example: hash.c and libxml/hash.c).
3600   subdir_options=
3601   if test -n "$uses_subdirs"; then
3602     subdir_options=' subdir-objects'
3603   fi
3604   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
3605   echo
3606   if $for_test && ! $single_configure; then
3607     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
3608     echo
3609   fi
3610   # Nothing is being added to SUBDIRS; nevertheless the existence of this
3611   # variable is needed to avoid an error from automake:
3612   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
3613   echo "SUBDIRS = ."
3614   echo "TESTS ="
3615   echo "XFAIL_TESTS ="
3616   echo "TESTS_ENVIRONMENT ="
3617   echo "noinst_PROGRAMS ="
3618   if ! $for_test; then
3619     echo "check_PROGRAMS ="
3620   fi
3621   echo "noinst_HEADERS ="
3622   echo "noinst_LIBRARIES ="
3623   if $use_libtests; then
3624     if $for_test; then
3625       echo "noinst_LIBRARIES += libtests.a"
3626     else
3627       echo "check_LIBRARIES = libtests.a"
3628     fi
3629   fi
3630   # Automake versions < 1.9b create an empty pkgdatadir at installation time
3631   # if you specify pkgdata_DATA to empty. This is a workaround.
3632   if grep '^pkgdata_DATA *+=' "$tmp"/main_snippets "$tmp"/longrunning_snippets > /dev/null; then
3633     echo "pkgdata_DATA ="
3634   fi
3635   echo "EXTRA_DIST ="
3636   echo "BUILT_SOURCES ="
3637   echo "SUFFIXES ="
3638   echo "MOSTLYCLEANFILES = core *.stackdump"
3639   echo "MOSTLYCLEANDIRS ="
3640   echo "CLEANFILES ="
3641   echo "DISTCLEANFILES ="
3642   echo "MAINTAINERCLEANFILES ="
3643   # Execute edits that apply to the Makefile.am being generated.
3644   edit=0
3645   while test $edit != $makefile_am_edits; do
3646     edit=`expr $edit + 1`
3647     eval dir=\"\$makefile_am_edit${edit}_dir\"
3648     eval var=\"\$makefile_am_edit${edit}_var\"
3649     eval val=\"\$makefile_am_edit${edit}_val\"
3650     if test -n "$var"; then
3651       if test "${dir}Makefile.am" = "$destfile" || test "./${dir}Makefile.am" = "$destfile"; then
3652         echo "${var} += ${val}"
3653         eval "makefile_am_edit${edit}_var="
3654       fi
3655     fi
3656   done
3657   echo
3658   echo "AM_CPPFLAGS = \\"
3659   if $for_test; then
3660     echo "  -DGNULIB_STRICT_CHECKING=1 \\"
3661   fi
3662   if test -n "$witness_c_macro"; then
3663     echo "  -D$witness_c_macro=1 \\"
3664   fi
3665   if test -n "${witness_macro}"; then
3666     echo "  -D@${witness_macro}@=1 \\"
3667   fi
3668   echo "  -I. -I\$(srcdir) \\"
3669   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
3670   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
3671   echo
3672   local_ldadd_before=''
3673   local_ldadd_after=''
3674   if $use_libtests; then
3675     # All test programs need to be linked with libtests.a.
3676     # It needs to be passed to the linker before ${libname}.${libext}, since
3677     # the tests-related modules depend on the main modules.
3678     # It also needs to be passed to the linker after ${libname}.${libext}
3679     # because the latter might contain incomplete modules (such as the 'error'
3680     # module whose dependency to 'progname' is voluntarily omitted).
3681     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
3682     # not matter.
3683     local_ldadd_before=' libtests.a'
3684     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
3685   fi
3686   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
3687   echo
3688   if $use_libtests; then
3689     echo "libtests_a_SOURCES ="
3690     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
3691     # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
3692     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
3693     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
3694     echo "EXTRA_libtests_a_SOURCES ="
3695     # The circular dependency in LDADD requires this.
3696     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
3697     echo
3698   fi
3699   # Many test scripts use ${EXEEXT} or ${srcdir}.
3700   # EXEEXT is defined by AC_PROG_CC through autoconf.
3701   # srcdir is defined by autoconf and automake.
3702   echo "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='\$(srcdir)'"
3703   echo
3704   cat "$tmp"/main_snippets "$tmp"/longrunning_snippets \
3705     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
3706   echo "# Clean up after Solaris cc."
3707   echo "clean-local:"
3708   echo "        rm -rf SunWS_cache"
3709   echo
3710   echo "mostlyclean-local: mostlyclean-generic"
3711   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
3712   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
3713   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
3714   echo "          fi; \\"
3715   echo "        done; \\"
3716   echo "        :"
3717   rm -f "$tmp"/main_snippets "$tmp"/longrunning_snippets
3718 }
3719
3720 # func_emit_initmacro_start macro_prefix
3721 # emits the first few statements of the gl_INIT macro to standard output.
3722 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3723 func_emit_initmacro_start ()
3724 {
3725   macro_prefix_arg="$1"
3726   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
3727   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
3728   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
3729   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
3730   # flexibility.)
3731   # Furthermore it avoids an automake error like this when a Makefile.am
3732   # that uses pieces of gnulib also uses $(LIBOBJ):
3733   #   automatically discovered file `error.c' should not be explicitly mentioned
3734   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
3735   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
3736   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
3737   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
3738   #   automatically discovered file `error.c' should not be explicitly mentioned
3739   # We let automake know about the files to be distributed through the
3740   # EXTRA_lib_SOURCES variable.
3741   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
3742   # Create data variables for checking the presence of files that are mentioned
3743   # as AC_LIBSOURCES arguments. These are m4 variables, not shell variables,
3744   # because we want the check to happen when the configure file is created,
3745   # not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the list of
3746   # files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the subdirectory
3747   # in which to expect them.
3748   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_LIST], [])"
3749   echo "  m4_pushdef([${macro_prefix_arg}_LIBSOURCES_DIR], [])"
3750   echo "  gl_COMMON"
3751 }
3752
3753 # func_emit_initmacro_end macro_prefix
3754 # emits the last few statements of the gl_INIT macro to standard output.
3755 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3756 func_emit_initmacro_end ()
3757 {
3758   macro_prefix_arg="$1"
3759   # Check the presence of files that are mentioned as AC_LIBSOURCES arguments.
3760   # The check is performed only when autoconf is run from the directory where
3761   # the configure.ac resides; if it is run from a different directory, the
3762   # check is skipped.
3763   echo "  m4_ifval(${macro_prefix_arg}_LIBSOURCES_LIST, ["
3764   echo "    m4_syscmd([test ! -d ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
3765   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
3766   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
3767   echo "          echo \"missing file ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file\" >&2"
3768   echo "          exit 1"
3769   echo "        fi"
3770   echo "      done])dnl"
3771   echo "      m4_if(m4_sysval, [0], [],"
3772   echo "        [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])"
3773   echo "  ])"
3774   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_DIR])"
3775   echo "  m4_popdef([${macro_prefix_arg}_LIBSOURCES_LIST])"
3776   echo "  m4_popdef([AC_LIBSOURCES])"
3777   echo "  m4_popdef([AC_REPLACE_FUNCS])"
3778   echo "  m4_popdef([AC_LIBOBJ])"
3779   echo "  AC_CONFIG_COMMANDS_PRE(["
3780   echo "    ${macro_prefix_arg}_libobjs="
3781   echo "    ${macro_prefix_arg}_ltlibobjs="
3782   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
3783   echo "      # Remove the extension."
3784   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
3785   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed -e \"\$sed_drop_objext\" | sort | uniq\`; do"
3786   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
3787   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
3788   echo "      done"
3789   echo "    fi"
3790   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
3791   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
3792   echo "  ])"
3793 }
3794
3795 # func_emit_initmacro_done macro_prefix sourcebase
3796 # emits a few statements after the gl_INIT macro to standard output.
3797 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3798 # - sourcebase      directory relative to destdir where to place source code
3799 func_emit_initmacro_done ()
3800 {
3801   macro_prefix_arg="$1"
3802   sourcebase_arg="$2"
3803   echo
3804   echo "# Like AC_LIBOBJ, except that the module name goes"
3805   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3806   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
3807   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
3808   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
3809   echo "])"
3810   echo
3811   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
3812   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
3813   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
3814   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
3815   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
3816   echo "])"
3817   echo
3818   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
3819   echo "# expected is derived from the gnulib-tool parameterization,"
3820   echo "# and alloca is special cased (for the alloca-opt module)."
3821   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
3822   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
3823   echo "  m4_foreach([_gl_NAME], [\$1], ["
3824   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
3825   echo "      m4_define([${macro_prefix_arg}_LIBSOURCES_DIR], [$sourcebase_arg])"
3826   echo "      m4_append([${macro_prefix_arg}_LIBSOURCES_LIST], _gl_NAME, [ ])"
3827   echo "    ])"
3828   echo "  ])"
3829   echo "])"
3830 }
3831
3832 # func_emit_autoconf_snippet indentation
3833 # emits the autoconf snippet of a module.
3834 # Input:
3835 # - local_gnulib_dir  from --local-dir
3836 # - modcache          true or false, from --cache-modules/--no-cache-modules
3837 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
3838 # - module            the module name
3839 # - toplevel          true or false. 'false' means a subordinate use of
3840 #                     gnulib-tool.
3841 # - disable_libtool   true or false. It tells whether to disable libtool
3842 #                     handling even if it has been specified through the
3843 #                     command line options.
3844 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
3845 #                     invocations.
3846 # - indentation       spaces to prepend on each line
3847 func_emit_autoconf_snippet ()
3848 {
3849   if { case $module in
3850          gnumakefile | maintainer-makefile)
3851            # These modules are meant to be used only in the top-level directory.
3852            $toplevel ;;
3853          *)
3854            true ;;
3855        esac
3856      }; then
3857     func_get_autoconf_snippet "$module" \
3858       | sed -e '/^$/d;' -e "s/^/$indentation/" \
3859             -e "$sed_replace_build_aux" \
3860       | { if $disable_libtool; then
3861             sed -e 's/\$gl_cond_libtool/false/g' \
3862                 -e 's/gl_libdeps/gltests_libdeps/g' \
3863                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3864           else
3865             cat
3866           fi
3867         } \
3868       | { if $disable_gettext; then
3869             sed -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
3870           else
3871             cat
3872           fi
3873         }
3874     if test "$module" = 'alloca' && test "$libtool" = true && ! $disable_libtool; then
3875       echo 'changequote(,)dnl'
3876       echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3877       echo 'changequote([, ])dnl'
3878       echo 'AC_SUBST([LTALLOCA])'
3879     fi
3880   fi
3881 }
3882
3883 # func_emit_autoconf_snippets modules verifier toplevel disable_libtool disable_gettext
3884 # collects and emit the autoconf snippets of a set of modules.
3885 # Input:
3886 # - local_gnulib_dir  from --local-dir
3887 # - modcache          true or false, from --cache-modules/--no-cache-modules
3888 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
3889 # - modules           the list of modules.
3890 # - verifier          one of func_verify_module, func_verify_nontests_module,
3891 #                     func_verify_tests_module. It selects the subset of
3892 #                     $modules to consider.
3893 # - toplevel          true or false. 'false' means a subordinate use of
3894 #                     gnulib-tool.
3895 # - disable_libtool   true or false. It tells whether to disable libtool
3896 #                     handling even if it has been specified through the
3897 #                     command line options.
3898 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
3899 #                     invocations.
3900 func_emit_autoconf_snippets ()
3901 {
3902   verifier="$2"
3903   toplevel="$3"
3904   disable_libtool="$4"
3905   disable_gettext="$5"
3906   if test "$cond_dependencies" = true; then
3907     # Emit the autoconf code for the unconditional modules.
3908     for module in $1; do
3909       eval $verifier
3910       if test -n "$module"; then
3911         if func_cond_module_p "$module"; then
3912           :
3913         else
3914           func_emit_autoconf_snippet "  "
3915         fi
3916       fi
3917     done
3918     # Initialize the shell variables indicating that the modules are enabled.
3919     for module in $1; do
3920       eval $verifier
3921       if test -n "$module"; then
3922         if func_cond_module_p "$module"; then
3923           func_module_shellvar_name "$module"
3924           echo "  $shellvar=false"
3925         fi
3926       fi
3927     done
3928     # Emit the autoconf code for the conditional modules, each in a separate
3929     # function. This makes it possible to support cycles among conditional
3930     # modules.
3931     for module in $1; do
3932       eval $verifier
3933       if test -n "$module"; then
3934         if func_cond_module_p "$module"; then
3935           func_module_shellfunc_name "$module"
3936           func_module_shellvar_name "$module"
3937           echo "  $shellfunc ()"
3938           echo '  {'
3939           echo "    if ! \$$shellvar; then"
3940           func_emit_autoconf_snippet "      "
3941           echo "      $shellvar=true"
3942           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
3943           for dep in $deps; do
3944             if func_cond_module_p "$dep"; then
3945               func_module_shellfunc_name "$dep"
3946               func_cond_module_condition "$module" "$dep"
3947               if test "$condition" != true; then
3948                 echo '      if $condition; then'
3949                 echo "        $shellfunc"
3950                 echo '      fi'
3951               else
3952                 echo "      $shellfunc"
3953               fi
3954             else
3955               # The autoconf code for $dep has already been emitted above and
3956               # therefore is already executed when this function is run.
3957               :
3958             fi
3959           done
3960           echo '    fi'
3961           echo '  }'
3962         fi
3963       fi
3964     done
3965     # Emit the dependencies from the unconditional to the conditional modules.
3966     for module in $1; do
3967       eval $verifier
3968       if test -n "$module"; then
3969         if func_cond_module_p "$module"; then
3970           :
3971         else
3972           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
3973           for dep in $deps; do
3974             if func_cond_module_p "$dep"; then
3975               func_module_shellfunc_name "$dep"
3976               func_cond_module_condition "$module" "$dep"
3977               if test "$condition" != true; then
3978                 echo "  if $condition; then"
3979                 echo "    $shellfunc"
3980                 echo '  fi'
3981               else
3982                 echo "  $shellfunc"
3983               fi
3984             else
3985               # The autoconf code for $dep has already been emitted above and
3986               # therefore is already executed when this code is run.
3987               :
3988             fi
3989           done
3990         fi
3991       fi
3992     done
3993     # Define the Automake conditionals.
3994     echo "  m4_pattern_allow([^${macro_prefix}_GNULIB_ENABLED_])"
3995     for module in $1; do
3996       eval $verifier
3997       if test -n "$module"; then
3998         if func_cond_module_p "$module"; then
3999           func_module_conditional_name "$module"
4000           func_module_shellvar_name "$module"
4001           echo "  AM_CONDITIONAL([$conditional], [\$$shellvar])"
4002         fi
4003       fi
4004     done
4005   else
4006     # Ignore the conditions, and enable all modules unconditionally.
4007     for module in $1; do
4008       eval $verifier
4009       if test -n "$module"; then
4010         func_emit_autoconf_snippet "  "
4011       fi
4012     done
4013   fi
4014 }
4015
4016 # func_import modules
4017 # Uses also the variables
4018 # - mode            import or add-import or remove-import or update
4019 # - destdir         target directory
4020 # - local_gnulib_dir  from --local-dir
4021 # - modcache        true or false, from --cache-modules/--no-cache-modules
4022 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
4023 # - libname         library name
4024 # - supplied_libname  true if --lib was given, blank otherwise
4025 # - sourcebase      directory relative to destdir where to place source code
4026 # - m4base          directory relative to destdir where to place *.m4 macros
4027 # - pobase          directory relative to destdir where to place *.po files
4028 # - docbase         directory relative to destdir where to place doc files
4029 # - testsbase       directory relative to destdir where to place unit test code
4030 # - auxdir          directory relative to destdir where to place build aux files
4031 # - inctests        true if --with-tests was given, blank otherwise
4032 # - incobsolete     true if --with-obsolete was given, blank otherwise
4033 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
4034 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
4035 #                          otherwise
4036 # - inc_privileged_tests  true if --with-privileged-tests was given, blank
4037 #                         otherwise
4038 # - inc_unportable_tests  true if --with-unportable-tests was given, blank
4039 #                         otherwise
4040 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
4041 # - avoidlist       list of modules to avoid, from --avoid
4042 # - cond_dependencies  true if --conditional-dependencies was given, false if
4043 #                      --no-conditional-dependencies was given, blank otherwise
4044 # - lgpl            yes or a number if library's license shall be LGPL,
4045 #                   blank otherwise
4046 # - makefile_name   from --makefile-name
4047 # - libtool         true if --libtool was given, false if --no-libtool was
4048 #                   given, blank otherwise
4049 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
4050 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
4051 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
4052 # - witness_c_macro  from --witness-c-macro
4053 # - vc_files        true if --vc-files was given, false if --no-vc-files was
4054 #                   given, blank otherwise
4055 # - autoconf_minversion  minimum supported autoconf version
4056 # - doit            : if actions shall be executed, false if only to be printed
4057 # - symbolic        true if files should be symlinked, copied otherwise
4058 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
4059 #                   copied otherwise
4060 # - do_copyrights   true if copyright notices in files should be replaced,
4061 #                   blank otherwise
4062 func_import ()
4063 {
4064   # Get the cached settings.
4065   # In 'import' mode, we read them only for the purpose of knowing the old
4066   # installed file list, and don't use them as defaults.
4067   cached_local_gnulib_dir=
4068   cached_specified_modules=
4069   cached_incobsolete=
4070   cached_inc_cxx_tests=
4071   cached_inc_longrunning_tests=
4072   cached_inc_privileged_tests=
4073   cached_inc_unportable_tests=
4074   cached_inc_all_tests=
4075   cached_avoidlist=
4076   cached_sourcebase=
4077   cached_m4base=
4078   cached_pobase=
4079   cached_docbase=
4080   cached_testsbase=
4081   cached_inctests=
4082   cached_libname=
4083   cached_lgpl=
4084   cached_makefile_name=
4085   cached_cond_dependencies=
4086   cached_libtool=
4087   cached_macro_prefix=
4088   cached_po_domain=
4089   cached_witness_c_macro=
4090   cached_vc_files=
4091   cached_files=
4092   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
4093     cached_libtool=false
4094     my_sed_traces='
4095       s,#.*$,,
4096       s,^dnl .*$,,
4097       s, dnl .*$,,
4098       /gl_LOCAL_DIR(/ {
4099         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_dir="\1",p
4100       }
4101       /gl_MODULES(/ {
4102         ta
4103         :a
4104           s/)/)/
4105           tb
4106           N
4107           ba
4108         :b
4109         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
4110       }
4111       /gl_WITH_OBSOLETE/ {
4112         s,^.*$,cached_incobsolete=true,p
4113       }
4114       /gl_WITH_CXX_TESTS/ {
4115         s,^.*$,cached_inc_cxx_tests=true,p
4116       }
4117       /gl_WITH_LONGRUNNING_TESTS/ {
4118         s,^.*$,cached_inc_longrunning_tests=true,p
4119       }
4120       /gl_WITH_PRIVILEGED_TESTS/ {
4121         s,^.*$,cached_inc_privileged_tests=true,p
4122       }
4123       /gl_WITH_UNPORTABLE_TESTS/ {
4124         s,^.*$,cached_inc_unportable_tests=true,p
4125       }
4126       /gl_WITH_ALL_TESTS/ {
4127         s,^.*$,cached_inc_all_tests=true,p
4128       }
4129       /gl_AVOID(/ {
4130         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
4131       }
4132       /gl_SOURCE_BASE(/ {
4133         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
4134       }
4135       /gl_M4_BASE(/ {
4136         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
4137       }
4138       /gl_PO_BASE(/ {
4139         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
4140       }
4141       /gl_DOC_BASE(/ {
4142         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
4143       }
4144       /gl_TESTS_BASE(/ {
4145         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
4146       }
4147       /gl_WITH_TESTS/ {
4148         s,^.*$,cached_inctests=true,p
4149       }
4150       /gl_LIB(/ {
4151         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
4152       }
4153       /gl_LGPL(/ {
4154         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
4155       }
4156       /gl_LGPL/ {
4157         s,^.*$,cached_lgpl=yes,p
4158       }
4159       /gl_MAKEFILE_NAME(/ {
4160         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
4161       }
4162       /gl_CONDITIONAL_DEPENDENCIES/ {
4163         s,^.*$,cached_cond_dependencies=true,p
4164       }
4165       /gl_LIBTOOL/ {
4166         s,^.*$,cached_libtool=true,p
4167       }
4168       /gl_MACRO_PREFIX(/ {
4169         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
4170       }
4171       /gl_PO_DOMAIN(/ {
4172         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
4173       }
4174       /gl_WITNESS_C_MACRO(/ {
4175         s,^.*gl_WITNESS_C_MACRO([[ ]*\([^]"$`\\)]*\).*$,cached_witness_c_macro="\1",p
4176       }
4177       /gl_VC_FILES(/ {
4178         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
4179       }'
4180     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
4181     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
4182       my_sed_traces='
4183         s,#.*$,,
4184         s,^dnl .*$,,
4185         s, dnl .*$,,
4186         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
4187           s,^.*$,cached_files=",p
4188           n
4189           ta
4190           :a
4191           s,^\]).*$,",
4192           tb
4193           s,["$`\\],,g
4194           p
4195           n
4196           ba
4197           :b
4198           p
4199         }'
4200       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
4201     fi
4202   fi
4203
4204   if test "$mode" = import; then
4205     # In 'import' mode, the new set of specified modules overrides the cached
4206     # set of modules. Ignore the cached settings.
4207     specified_modules="$1"
4208   else
4209     # Merge the cached settings with the specified ones.
4210     # The m4base must be the same as expected from the pathname.
4211     if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
4212       func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
4213     fi
4214     # The local_gnulib_dir defaults to the cached one. Recall that the cached one
4215     # is relative to $destdir, whereas the one we use is relative to . or absolute.
4216     if test -z "$local_gnulib_dir"; then
4217       if test -n "$cached_local_gnulib_dir"; then
4218         case "$destdir" in
4219           /*)
4220             local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
4221           *)
4222             case "$cached_local_gnulib_dir" in
4223               /*)
4224                 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
4225               *)
4226                 func_relconcat "$destdir" "$cached_local_gnulib_dir"
4227                 local_gnulib_dir="$relconcat" ;;
4228             esac ;;
4229         esac
4230       fi
4231     fi
4232     case $mode in
4233       add-import)
4234         # Append the cached and the specified module names. So that
4235         # "gnulib-tool --add-import foo" means to add the module foo.
4236         specified_modules="$cached_specified_modules $1"
4237         ;;
4238       remove-import)
4239         # Take the cached module names, minus the specified module names.
4240         specified_modules=
4241         if $have_associative; then
4242           # Use an associative array, for O(N) worst-case run time.
4243           declare -A to_remove
4244           for m in $1; do
4245             eval 'to_remove[$m]=yes'
4246           done
4247           for module in $cached_specified_modules; do
4248             if eval 'test -z "${to_remove[$module]}"'; then
4249               func_append specified_modules "$module "
4250             fi
4251           done
4252         else
4253           # This loop has O(N²) worst-case run time.
4254           for module in $cached_specified_modules; do
4255             to_remove=
4256             for m in $1; do
4257               if test "$m" = "$module"; then
4258                 to_remove=yes
4259                 break
4260               fi
4261             done
4262             if test -z "$to_remove"; then
4263               func_append specified_modules "$module "
4264             fi
4265           done
4266         fi
4267         ;;
4268       update)
4269         # Take the cached module names. There are no specified module names.
4270         specified_modules="$cached_specified_modules"
4271         ;;
4272     esac
4273     # Included obsolete modules among the dependencies if specified either way.
4274     if test -z "$incobsolete"; then
4275       incobsolete="$cached_incobsolete"
4276     fi
4277     # Included special kinds of tests modules among the dependencies if specified
4278     # either way.
4279     if test -z "$inc_cxx_tests"; then
4280       inc_cxx_tests="$cached_inc_cxx_tests"
4281     fi
4282     if test -z "$inc_longrunning_tests"; then
4283       inc_longrunning_tests="$cached_inc_longrunning_tests"
4284     fi
4285     if test -z "$inc_privileged_tests"; then
4286       inc_privileged_tests="$cached_inc_privileged_tests"
4287     fi
4288     if test -z "$inc_unportable_tests"; then
4289       inc_unportable_tests="$cached_inc_unportable_tests"
4290     fi
4291     if test -z "$inc_all_tests"; then
4292       inc_all_tests="$cached_inc_all_tests"
4293     fi
4294     # Append the cached and the specified avoidlist. This is probably better
4295     # than dropping the cached one when --avoid is specified at least once.
4296     avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
4297     avoidlist=`echo $avoidlist`
4298
4299     # The sourcebase defaults to the cached one.
4300     if test -z "$sourcebase"; then
4301       sourcebase="$cached_sourcebase"
4302       if test -z "$sourcebase"; then
4303         func_fatal_error "missing --source-base option"
4304       fi
4305     fi
4306     # The pobase defaults to the cached one.
4307     if test -z "$pobase"; then
4308       pobase="$cached_pobase"
4309     fi
4310     # The docbase defaults to the cached one.
4311     if test -z "$docbase"; then
4312       docbase="$cached_docbase"
4313       if test -z "$docbase"; then
4314         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."
4315       fi
4316     fi
4317     # The testsbase defaults to the cached one.
4318     if test -z "$testsbase"; then
4319       testsbase="$cached_testsbase"
4320       if test -z "$testsbase"; then
4321         func_fatal_error "missing --tests-base option"
4322       fi
4323     fi
4324     # Require the tests if specified either way.
4325     if test -z "$inctests"; then
4326       inctests="$cached_inctests"
4327     fi
4328     # The libname defaults to the cached one.
4329     if test -z "$supplied_libname"; then
4330       libname="$cached_libname"
4331       if test -z "$libname"; then
4332         func_fatal_error "missing --lib option"
4333       fi
4334     fi
4335     # Require LGPL if specified either way.
4336     if test -z "$lgpl"; then
4337       lgpl="$cached_lgpl"
4338     fi
4339     # The makefile_name defaults to the cached one.
4340     if test -z "$makefile_name"; then
4341       makefile_name="$cached_makefile_name"
4342     fi
4343     # Use conditional dependencies if specified either way.
4344     if test -z "$cond_dependencies"; then
4345       cond_dependencies="$cached_cond_dependencies"
4346     fi
4347     # Use libtool if specified either way, or if guessed.
4348     if test -z "$libtool"; then
4349       if test -n "$cached_m4base"; then
4350         libtool="$cached_libtool"
4351       else
4352         libtool="$guessed_libtool"
4353       fi
4354     fi
4355     # The macro_prefix defaults to the cached one.
4356     if test -z "$macro_prefix"; then
4357       macro_prefix="$cached_macro_prefix"
4358       if test -z "$macro_prefix"; then
4359         func_fatal_error "missing --macro-prefix option"
4360       fi
4361     fi
4362     # The po_domain defaults to the cached one.
4363     if test -z "$po_domain"; then
4364       po_domain="$cached_po_domain"
4365     fi
4366     # The witness_c_macro defaults to the cached one.
4367     if test -z "$witness_c_macro"; then
4368       witness_c_macro="$cached_witness_c_macro"
4369     fi
4370     # The vc_files defaults to the cached one.
4371     if test -z "$vc_files"; then
4372       vc_files="$cached_vc_files"
4373     fi
4374     # Ensure constraints.
4375     if test "$cond_dependencies" = true && test -n "$inctests"; then
4376       echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
4377       func_exit 1
4378     fi
4379   fi
4380   # --without-*-tests options are not supported here.
4381   excl_cxx_tests=
4382   excl_longrunning_tests=
4383   excl_privileged_tests=
4384   excl_unportable_tests=
4385
4386   # Canonicalize the list of specified modules.
4387   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
4388
4389   # Include all kinds of tests modules if --with-all-tests was specified.
4390   inc_all_direct_tests="$inc_all_tests"
4391   inc_all_indirect_tests="$inc_all_tests"
4392
4393   # Determine final module list.
4394   modules="$specified_modules"
4395   func_modules_transitive_closure
4396   if test $verbose -ge 0; then
4397     func_show_module_list
4398   fi
4399   final_modules="$modules"
4400
4401   # Determine main module list and tests-related module list separately.
4402   func_modules_transitive_closure_separately
4403
4404   # Determine whether a $testsbase/libtests.a is needed.
4405   func_determine_use_libtests
4406
4407   # Add the dummy module to the main module list or to the tests-related module
4408   # list if needed.
4409   func_modules_add_dummy_separately
4410
4411   # If --lgpl, verify that the licenses of modules are compatible.
4412   if test -n "$lgpl"; then
4413     license_incompatibilities=
4414     for module in $main_modules; do
4415       license=`func_get_license $module`
4416       case $license in
4417         'GPLed build tool') ;;
4418         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
4419         *)
4420           case "$lgpl" in
4421             yes | 3)
4422               case $license in
4423                 LGPL | LGPLv2+ | LGPLv3+) ;;
4424                 *) func_append license_incompatibilities "$module $license$nl" ;;
4425               esac
4426               ;;
4427             2)
4428               case $license in
4429                 LGPLv2+) ;;
4430                 *) func_append license_incompatibilities "$module $license$nl" ;;
4431               esac
4432               ;;
4433             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
4434           esac
4435           ;;
4436       esac
4437     done
4438     if test -n "$license_incompatibilities"; then
4439       # Format the license incompatibilities as a table.
4440       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
4441 s,^\(.................................................[^ ]*\) *,                 \1 ,'
4442       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
4443       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
4444     fi
4445   fi
4446
4447   # Show banner notice of every module.
4448   modules="$main_modules"
4449   func_modules_notice
4450
4451   # Determine script to apply to imported library files.
4452   sed_transform_lib_file=
4453   for module in $main_modules; do
4454     if test $module = config-h; then
4455       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
4456       sed_transform_lib_file=$sed_transform_lib_file'
4457         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
4458       '
4459       break
4460     fi
4461   done
4462   sed_transform_main_lib_file="$sed_transform_lib_file"
4463   if test -n "$do_copyrights"; then
4464     if test -n "$lgpl"; then
4465       # Update license.
4466       case "$lgpl" in
4467         yes | 3)
4468           sed_transform_main_lib_file=$sed_transform_main_lib_file'
4469             s/GNU General/GNU Lesser General/g
4470             s/General Public License/Lesser General Public License/g
4471             s/Lesser Lesser General Public License/Lesser General Public License/g
4472           '
4473           ;;
4474         2)
4475           sed_transform_main_lib_file=$sed_transform_main_lib_file'
4476             s/GNU General/GNU Lesser General/g
4477             s/General Public License/Lesser General Public License/g
4478             s/Lesser Lesser General Public License/Lesser General Public License/g
4479
4480             s/version [23]\([ ,]\)/version 2.1\1/g
4481           '
4482           ;;
4483         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
4484       esac
4485     else
4486       # Update license.
4487       sed_transform_main_lib_file=$sed_transform_main_lib_file'
4488         s/GNU Lesser General/GNU General/g
4489         s/Lesser General Public License/General Public License/g
4490
4491         s/GNU Library General/GNU General/g
4492         s/Library General Public License/General Public License/g
4493
4494         s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4495       '
4496     fi
4497   fi
4498
4499   # Determine script to apply to auxiliary files that go into $auxdir/.
4500   sed_transform_build_aux_file=
4501   if test -n "$do_copyrights"; then
4502     # Update license.
4503     sed_transform_build_aux_file=$sed_transform_build_aux_file'
4504       s/GNU Lesser General/GNU General/g
4505       s/Lesser General Public License/General Public License/g
4506
4507       s/GNU Library General/GNU General/g
4508       s/Library General Public License/General Public License/g
4509
4510       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4511     '
4512   fi
4513
4514   # Determine script to apply to library files that go into $testsbase/.
4515   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
4516   if test -n "$do_copyrights"; then
4517     # Update license.
4518     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
4519       s/GNU Lesser General/GNU General/g
4520       s/Lesser General Public License/General Public License/g
4521
4522       s/GNU Library General/GNU General/g
4523       s/Library General Public License/General Public License/g
4524
4525       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
4526     '
4527   fi
4528
4529   # Determine the final file lists.
4530   func_modules_to_filelist_separately
4531
4532   test -n "$files" \
4533     || func_fatal_error "refusing to do nothing"
4534
4535   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
4536   new_files="$files m4/gnulib-tool.m4"
4537   old_files="$cached_files"
4538   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
4539     func_append old_files " m4/gnulib-tool.m4"
4540   fi
4541
4542   rewritten='%REWRITTEN%'
4543   sed_rewrite_old_files="\
4544     s,^build-aux/,$rewritten$auxdir/,
4545     s,^doc/,$rewritten$cached_docbase/,
4546     s,^lib/,$rewritten$cached_sourcebase/,
4547     s,^m4/,$rewritten$cached_m4base/,
4548     s,^tests/,$rewritten$cached_testsbase/,
4549     s,^tests=lib/,$rewritten$cached_testsbase/,
4550     s,^top/,$rewritten,
4551     s,^$rewritten,,"
4552   sed_rewrite_new_files="\
4553     s,^build-aux/,$rewritten$auxdir/,
4554     s,^doc/,$rewritten$docbase/,
4555     s,^lib/,$rewritten$sourcebase/,
4556     s,^m4/,$rewritten$m4base/,
4557     s,^tests/,$rewritten$testsbase/,
4558     s,^tests=lib/,$rewritten$testsbase/,
4559     s,^top/,$rewritten,
4560     s,^$rewritten,,"
4561
4562   # Create directories.
4563   { echo "$sourcebase"
4564     echo "$m4base"
4565     if test -n "$pobase"; then
4566       echo "$pobase"
4567     fi
4568     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
4569     if test -n "$docfiles"; then
4570       echo "$docbase"
4571     fi
4572     if test -n "$inctests"; then
4573       echo "$testsbase"
4574     fi
4575     echo "$auxdir"
4576     for f in $files; do echo $f; done \
4577       | sed -e "$sed_rewrite_new_files" \
4578       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
4579       | LC_ALL=C sort -u
4580   } > "$tmp"/dirs
4581   { # Rearrange file descriptors. Needed because "while ... done < ..."
4582     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4583     exec 5<&0 < "$tmp"/dirs
4584     while read d; do
4585       if test ! -d "$destdir/$d"; then
4586         if $doit; then
4587           echo "Creating directory $destdir/$d"
4588           mkdir -p "$destdir/$d" || func_fatal_error "failed"
4589         else
4590           echo "Create directory $destdir/$d"
4591         fi
4592       fi
4593     done
4594     exec 0<&5 5<&-
4595   }
4596
4597   # Copy files or make symbolic links. Remove obsolete files.
4598   added_files=''
4599   removed_files=''
4600   delimiter='   '
4601   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4602   # representing the files according to the last gnulib-tool invocation.
4603   for f in $old_files; do echo $f; done \
4604     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
4605     | LC_ALL=C sort \
4606     > "$tmp"/old-files
4607   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4608   # representing the files after this gnulib-tool invocation.
4609   for f in $new_files; do echo $f; done \
4610     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
4611     | LC_ALL=C sort \
4612     > "$tmp"/new-files
4613   # First the files that are in old-files, but not in new-files:
4614   sed_take_first_column='s,'"$delimiter"'.*,,'
4615   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
4616     # Remove the file. Do nothing if the user already removed it.
4617     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
4618       if $doit; then
4619         echo "Removing file $g (backup in ${g}~)"
4620         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
4621       else
4622         echo "Remove file $g (backup in ${g}~)"
4623       fi
4624       func_append removed_files "$g$nl"
4625     fi
4626   done
4627   # func_add_or_update handles a file that ought to be present afterwards.
4628   # Uses parameters
4629   # - f             the original file name
4630   # - g             the rewritten file name
4631   # - already_present  nonempty if the file should already exist, empty
4632   #                    otherwise
4633   func_add_or_update ()
4634   {
4635     of="$f"
4636     case "$f" in
4637       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
4638     esac
4639     func_dest_tmpfilename "$g"
4640     func_lookup_file "$f"
4641     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
4642     if test -n "$sed_transform_main_lib_file"; then
4643       case "$of" in
4644         lib/*)
4645           sed -e "$sed_transform_main_lib_file" \
4646             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4647           ;;
4648       esac
4649     fi
4650     if test -n "$sed_transform_build_aux_file"; then
4651       case "$of" in
4652         build-aux/*)
4653           sed -e "$sed_transform_build_aux_file" \
4654             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4655           ;;
4656       esac
4657     fi
4658     if test -n "$sed_transform_testsrelated_lib_file"; then
4659       case "$of" in
4660         tests=lib/*)
4661           sed -e "$sed_transform_testsrelated_lib_file" \
4662             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4663           ;;
4664       esac
4665     fi
4666     if test -f "$destdir/$g"; then
4667       # The file already exists.
4668       func_update_file
4669     else
4670       # Install the file.
4671       # Don't protest if the file should be there but isn't: it happens
4672       # frequently that developers don't put autogenerated files under version control.
4673       func_add_file
4674       func_append added_files "$g$nl"
4675     fi
4676     rm -f "$tmpfile"
4677   }
4678   # Then the files that are in new-files, but not in old-files:
4679   sed_take_last_column='s,^.*'"$delimiter"',,'
4680   already_present=
4681   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
4682     | sed -e "$sed_take_last_column" \
4683     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
4684   { # Rearrange file descriptors. Needed because "while ... done < ..."
4685     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4686     exec 5<&0 < "$tmp"/added-files
4687     while read g f; do
4688       func_add_or_update
4689     done
4690     exec 0<&5 5<&-
4691   }
4692   # Then the files that are in new-files and in old-files:
4693   already_present=true
4694   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
4695     | sed -e "$sed_take_last_column" \
4696     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
4697   { # Rearrange file descriptors. Needed because "while ... done < ..."
4698     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4699     exec 5<&0 < "$tmp"/kept-files
4700     while read g f; do
4701       func_add_or_update
4702     done
4703     exec 0<&5 5<&-
4704   }
4705
4706   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
4707   actioncmd="gnulib-tool --import"
4708   func_append actioncmd " --dir=$destdir"
4709   if test -n "$local_gnulib_dir"; then
4710     func_append actioncmd " --local-dir=$local_gnulib_dir"
4711   fi
4712   func_append actioncmd " --lib=$libname"
4713   func_append actioncmd " --source-base=$sourcebase"
4714   func_append actioncmd " --m4-base=$m4base"
4715   if test -n "$pobase"; then
4716     func_append actioncmd " --po-base=$pobase"
4717   fi
4718   func_append actioncmd " --doc-base=$docbase"
4719   func_append actioncmd " --tests-base=$testsbase"
4720   func_append actioncmd " --aux-dir=$auxdir"
4721   if test -n "$inctests"; then
4722     func_append actioncmd " --with-tests"
4723   fi
4724   if test -n "$incobsolete"; then
4725     func_append actioncmd " --with-obsolete"
4726   fi
4727   if test -n "$inc_cxx_tests"; then
4728     func_append actioncmd " --with-c++-tests"
4729   fi
4730   if test -n "$inc_longrunning_tests"; then
4731     func_append actioncmd " --with-longrunning-tests"
4732   fi
4733   if test -n "$inc_privileged_tests"; then
4734     func_append actioncmd " --with-privileged-tests"
4735   fi
4736   if test -n "$inc_unportable_tests"; then
4737     func_append actioncmd " --with-unportable-tests"
4738   fi
4739   if test -n "$inc_all_tests"; then
4740     func_append actioncmd " --with-all-tests"
4741   fi
4742   for module in $avoidlist; do
4743     func_append actioncmd " --avoid=$module"
4744   done
4745   if test -n "$lgpl"; then
4746     if test "$lgpl" = yes; then
4747       func_append actioncmd " --lgpl"
4748     else
4749       func_append actioncmd " --lgpl=$lgpl"
4750     fi
4751   fi
4752   if test -n "$makefile_name"; then
4753     func_append actioncmd " --makefile-name=$makefile_name"
4754   fi
4755   if test "$cond_dependencies" = true; then
4756     func_append actioncmd " --conditional-dependencies"
4757   else
4758     func_append actioncmd " --no-conditional-dependencies"
4759   fi
4760   if test "$libtool" = true; then
4761     func_append actioncmd " --libtool"
4762   else
4763     func_append actioncmd " --no-libtool"
4764   fi
4765   func_append actioncmd " --macro-prefix=$macro_prefix"
4766   if test -n "$po_domain"; then
4767     func_append actioncmd " --po-domain=$po_domain"
4768   fi
4769   if test -n "$witness_c_macro"; then
4770     func_append actioncmd " --witness-c-macro=$witness_c_macro"
4771   fi
4772   if test -n "$vc_files"; then
4773     if test "$vc_files" = true; then
4774       func_append actioncmd " --vc-files"
4775     else
4776       func_append actioncmd " --no-vc-files"
4777     fi
4778   fi
4779   func_append actioncmd " `echo $specified_modules`"
4780
4781   # Determine include_guard_prefix.
4782   func_compute_include_guard_prefix
4783
4784   # Default the makefile name to Makefile.am.
4785   if test -n "$makefile_name"; then
4786     makefile_am=$makefile_name
4787   else
4788     makefile_am=Makefile.am
4789   fi
4790
4791   # Create normal Makefile.ams.
4792   for_test=false
4793
4794   # Setup list of Makefile.am edits that are to be performed afterwards.
4795   # Some of these edits apply to files that we will generate; others are
4796   # under the responsibility of the developer.
4797   makefile_am_edits=0
4798   # func_note_Makefile_am_edit dir var value
4799   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
4800   # ${value}.
4801   func_note_Makefile_am_edit ()
4802   {
4803     makefile_am_edits=`expr $makefile_am_edits + 1`
4804     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
4805     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
4806     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
4807   }
4808   if test "$makefile_am" = Makefile.am; then
4809     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
4810     sourcebase_base=`basename "$sourcebase"`
4811     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
4812   fi
4813   if test -n "$pobase"; then
4814     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
4815     pobase_base=`basename "$pobase"`
4816     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
4817   fi
4818   if test -n "$inctests"; then
4819     if test "$makefile_am" = Makefile.am; then
4820       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
4821       testsbase_base=`basename "$testsbase"`
4822       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
4823     fi
4824   fi
4825   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
4826   {
4827     # Find the first parent directory of $m4base that contains or will contain
4828     # a Makefile.am.
4829     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
4830 s,//*$,/,'
4831     sed_butlast='s,[^/][^/]*//*$,,'
4832     dir1="${m4base}/"; dir2=""
4833     while test -n "$dir1" \
4834           && ! { test -f "${destdir}/${dir1}Makefile.am" \
4835                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4836                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4837                  || { test -n "$inctests" \
4838                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
4839                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
4840       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
4841       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
4842     done
4843     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
4844   }
4845
4846   # Create library makefile.
4847   func_dest_tmpfilename $sourcebase/$makefile_am
4848   destfile="$sourcebase/$makefile_am"
4849   modules="$main_modules"
4850   func_emit_lib_Makefile_am > "$tmpfile"
4851   if test -f "$destdir"/$sourcebase/$makefile_am; then
4852     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
4853       rm -f "$tmpfile"
4854     else
4855       if $doit; then
4856         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4857         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
4858         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4859       else
4860         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4861         rm -f "$tmpfile"
4862       fi
4863     fi
4864   else
4865     if $doit; then
4866       echo "Creating $sourcebase/$makefile_am"
4867       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4868     else
4869       echo "Create $sourcebase/$makefile_am"
4870       rm -f "$tmpfile"
4871     fi
4872     func_append added_files "$sourcebase/$makefile_am$nl"
4873   fi
4874
4875   # Create po/ directory.
4876   if test -n "$pobase"; then
4877     # Create po makefile and auxiliary files.
4878     for file in Makefile.in.in remove-potcdate.sin; do
4879       func_dest_tmpfilename $pobase/$file
4880       func_lookup_file build-aux/po/$file
4881       cat "$lookedup_file" > "$tmpfile"
4882       if test -f "$destdir"/$pobase/$file; then
4883         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
4884           rm -f "$tmpfile"
4885         else
4886           if $doit; then
4887             echo "Updating $pobase/$file (backup in $pobase/$file~)"
4888             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
4889             mv -f "$tmpfile" "$destdir"/$pobase/$file
4890           else
4891             echo "Update $pobase/$file (backup in $pobase/$file~)"
4892             rm -f "$tmpfile"
4893           fi
4894         fi
4895       else
4896         if $doit; then
4897           echo "Creating $pobase/$file"
4898           mv -f "$tmpfile" "$destdir"/$pobase/$file
4899         else
4900           echo "Create $pobase/$file"
4901           rm -f "$tmpfile"
4902         fi
4903         func_append added_files "$pobase/$file$nl"
4904       fi
4905     done
4906     # Create po makefile parameterization, part 1.
4907     func_dest_tmpfilename $pobase/Makevars
4908     func_emit_po_Makevars > "$tmpfile"
4909     if test -f "$destdir"/$pobase/Makevars; then
4910       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
4911         rm -f "$tmpfile"
4912       else
4913         if $doit; then
4914           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
4915           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
4916           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4917         else
4918           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
4919           rm -f "$tmpfile"
4920         fi
4921       fi
4922     else
4923       if $doit; then
4924         echo "Creating $pobase/Makevars"
4925         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4926       else
4927         echo "Create $pobase/Makevars"
4928         rm -f "$tmpfile"
4929       fi
4930       func_append added_files "$pobase/Makevars$nl"
4931     fi
4932     # Create po makefile parameterization, part 2.
4933     func_dest_tmpfilename $pobase/POTFILES.in
4934     func_emit_po_POTFILES_in > "$tmpfile"
4935     if test -f "$destdir"/$pobase/POTFILES.in; then
4936       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
4937         rm -f "$tmpfile"
4938       else
4939         if $doit; then
4940           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
4941           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
4942           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
4943         else
4944           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
4945           rm -f "$tmpfile"
4946         fi
4947       fi
4948     else
4949       if $doit; then
4950         echo "Creating $pobase/POTFILES.in"
4951         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
4952       else
4953         echo "Create $pobase/POTFILES.in"
4954         rm -f "$tmpfile"
4955       fi
4956       func_append added_files "$pobase/POTFILES.in$nl"
4957     fi
4958     # Fetch PO files.
4959     TP_URL="http://translationproject.org/latest/"
4960     TP_RSYNC_URI="translationproject.org::tp/latest/"
4961     if $doit; then
4962       echo "Fetching gnulib PO files from $TP_URL"
4963       (cd "$destdir"/$pobase \
4964        && { # Prefer rsync over wget if it is available, since it consumes
4965             # less network bandwidth, due to compression.
4966             if type rsync 2>/dev/null | grep / > /dev/null; then
4967               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
4968             else
4969               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
4970             fi
4971           }
4972       )
4973     else
4974       echo "Fetch gnulib PO files from $TP_URL"
4975     fi
4976     # Create po/LINGUAS.
4977     if $doit; then
4978       func_dest_tmpfilename $pobase/LINGUAS
4979       (cd "$destdir"/$pobase \
4980        && { echo '# Set of available languages.'
4981             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
4982           }
4983       ) > "$tmpfile"
4984       if test -f "$destdir"/$pobase/LINGUAS; then
4985         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
4986           rm -f "$tmpfile"
4987         else
4988           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
4989           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
4990           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
4991         fi
4992       else
4993         echo "Creating $pobase/LINGUAS"
4994         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
4995         func_append added_files "$pobase/LINGUAS$nl"
4996       fi
4997     else
4998       if test -f "$destdir"/$pobase/LINGUAS; then
4999         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
5000       else
5001         echo "Create $pobase/LINGUAS"
5002       fi
5003     fi
5004   fi
5005
5006   # Create m4/gnulib-cache.m4.
5007   func_dest_tmpfilename $m4base/gnulib-cache.m4
5008   (
5009     func_emit_copyright_notice
5010     echo "#"
5011     echo "# This file represents the specification of how gnulib-tool is used."
5012     echo "# It acts as a cache: It is written and read by gnulib-tool."
5013     echo "# In projects that use version control, this file is meant to be put under"
5014     echo "# version control, like the configure.ac and various Makefile.am files."
5015     echo
5016     echo
5017     echo "# Specification in the form of a command-line invocation:"
5018     echo "#   $actioncmd"
5019     echo
5020     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
5021     # Store the local_gnulib_dir relative to destdir.
5022     case "$local_gnulib_dir" in
5023       "" | /*)
5024         relative_local_gnulib_dir="$local_gnulib_dir" ;;
5025       * )
5026         case "$destdir" in
5027           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
5028           *)
5029             # destdir, local_gnulib_dir are both relative.
5030             func_relativize "$destdir" "$local_gnulib_dir"
5031             relative_local_gnulib_dir="$reldir" ;;
5032         esac ;;
5033     esac
5034     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
5035     echo "gl_MODULES(["
5036     echo "$specified_modules" | sed -e 's/^/  /g'
5037     echo "])"
5038     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
5039     test -z "$inc_cxx_tests" || echo "gl_WITH_CXX_TESTS"
5040     test -z "$inc_longrunning_tests" || echo "gl_WITH_LONGRUNNING_TESTS"
5041     test -z "$inc_privileged_tests" || echo "gl_WITH_PRIVILEGED_TESTS"
5042     test -z "$inc_unportable_tests" || echo "gl_WITH_UNPORTABLE_TESTS"
5043     test -z "$inc_all_tests" || echo "gl_WITH_ALL_TESTS"
5044     echo "gl_AVOID([$avoidlist])"
5045     echo "gl_SOURCE_BASE([$sourcebase])"
5046     echo "gl_M4_BASE([$m4base])"
5047     echo "gl_PO_BASE([$pobase])"
5048     echo "gl_DOC_BASE([$docbase])"
5049     echo "gl_TESTS_BASE([$testsbase])"
5050     test -z "$inctests" || echo "gl_WITH_TESTS"
5051     echo "gl_LIB([$libname])"
5052     if test -n "$lgpl"; then
5053       if test "$lgpl" = yes; then
5054         echo "gl_LGPL"
5055       else
5056         echo "gl_LGPL([$lgpl])"
5057       fi
5058     fi
5059     echo "gl_MAKEFILE_NAME([$makefile_name])"
5060     if test "$cond_dependencies" = true; then
5061       echo "gl_CONDITIONAL_DEPENDENCIES"
5062     fi
5063     if test "$libtool" = true; then
5064       echo "gl_LIBTOOL"
5065     fi
5066     echo "gl_MACRO_PREFIX([$macro_prefix])"
5067     echo "gl_PO_DOMAIN([$po_domain])"
5068     echo "gl_WITNESS_C_DOMAIN([$witness_c_macro])"
5069     if test -n "$vc_files"; then
5070       echo "gl_VC_FILES([$vc_files])"
5071     fi
5072   ) > "$tmpfile"
5073   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
5074     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
5075       rm -f "$tmpfile"
5076     else
5077       if $doit; then
5078         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
5079         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
5080         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
5081       else
5082         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
5083         if false; then
5084           cat "$tmpfile"
5085           echo
5086           echo "# gnulib-cache.m4 ends here"
5087         fi
5088         rm -f "$tmpfile"
5089       fi
5090     fi
5091   else
5092     if $doit; then
5093       echo "Creating $m4base/gnulib-cache.m4"
5094       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
5095     else
5096       echo "Create $m4base/gnulib-cache.m4"
5097       cat "$tmpfile"
5098       rm -f "$tmpfile"
5099     fi
5100   fi
5101
5102   # Create m4/gnulib-comp.m4.
5103   func_dest_tmpfilename $m4base/gnulib-comp.m4
5104   (
5105     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
5106     func_emit_copyright_notice
5107     echo "#"
5108     echo "# This file represents the compiled summary of the specification in"
5109     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
5110     echo "# to be invoked from configure.ac."
5111     echo "# In projects that use version control, this file can be treated like"
5112     echo "# other built files."
5113     echo
5114     echo
5115     echo "# This macro should be invoked from $configure_ac, in the section"
5116     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
5117     echo "# any checks for libraries, header files, types and library functions."
5118     echo "AC_DEFUN([${macro_prefix}_EARLY],"
5119     echo "["
5120     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5121     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5122     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5123     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5124     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
5125     if test -n "$uses_subdirs"; then
5126       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
5127     fi
5128     for module in $final_modules; do
5129       func_verify_module
5130       if test -n "$module"; then
5131         echo "# Code from module $module:"
5132         func_get_autoconf_early_snippet "$module"
5133       fi
5134     done \
5135       | sed -e '/^$/d;' -e 's/^/  /'
5136     echo "])"
5137     echo
5138     echo "# This macro should be invoked from $configure_ac, in the section"
5139     echo "# \"Check for header files, types and library functions\"."
5140     echo "AC_DEFUN([${macro_prefix}_INIT],"
5141     echo "["
5142     if test "$libtool" = true; then
5143       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5144       echo "  gl_cond_libtool=true"
5145     else
5146       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5147       echo "  gl_cond_libtool=false"
5148       echo "  gl_libdeps="
5149       echo "  gl_ltlibdeps="
5150     fi
5151     if test "$auxdir" != "build-aux"; then
5152       sed_replace_build_aux='
5153         :a
5154         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5155           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5156           ba
5157         }'
5158     else
5159       sed_replace_build_aux="$sed_noop"
5160     fi
5161     echo "  gl_m4_base='$m4base'"
5162     func_emit_initmacro_start $macro_prefix
5163     echo "  gl_source_base='$sourcebase'"
5164     if test -n "$witness_c_macro"; then
5165       echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$witness_c_macro])"
5166     fi
5167     func_emit_autoconf_snippets "$main_modules" func_verify_module true false true
5168     if test -n "$witness_c_macro"; then
5169       echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5170     fi
5171     echo "  # End of code from modules"
5172     func_emit_initmacro_end $macro_prefix
5173     echo "  gltests_libdeps="
5174     echo "  gltests_ltlibdeps="
5175     func_emit_initmacro_start ${macro_prefix}tests
5176     echo "  gl_source_base='$testsbase'"
5177     # Define a tests witness macro that depends on the package.
5178     # PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
5179     # See <http://lists.gnu.org/archive/html/automake/2009-05/msg00145.html>.
5180     echo "changequote(,)dnl"
5181     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"
5182     echo "changequote([, ])dnl"
5183     echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
5184     echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
5185     echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
5186     func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true true true
5187     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5188     func_emit_initmacro_end ${macro_prefix}tests
5189     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5190     # created using libtool, because libtool already handles the dependencies.
5191     if test "$libtool" != true; then
5192       libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5193       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5194       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5195       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5196       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5197     fi
5198     if $use_libtests; then
5199       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
5200       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
5201     fi
5202     echo "])"
5203     func_emit_initmacro_done $macro_prefix $sourcebase
5204     func_emit_initmacro_done ${macro_prefix}tests $testsbase
5205     echo
5206     echo "# This macro records the list of files which have been installed by"
5207     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
5208     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
5209     echo "$files" | sed -e 's,^,  ,'
5210     echo "])"
5211   ) > "$tmpfile"
5212   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
5213     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
5214       rm -f "$tmpfile"
5215     else
5216       if $doit; then
5217         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
5218         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
5219         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
5220       else
5221         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
5222         if false; then
5223           cat "$tmpfile"
5224           echo
5225           echo "# gnulib-comp.m4 ends here"
5226         fi
5227         rm -f "$tmpfile"
5228       fi
5229     fi
5230   else
5231     if $doit; then
5232       echo "Creating $m4base/gnulib-comp.m4"
5233       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
5234     else
5235       echo "Create $m4base/gnulib-comp.m4"
5236       cat "$tmpfile"
5237       rm -f "$tmpfile"
5238     fi
5239   fi
5240
5241   if test -n "$inctests"; then
5242     # Create tests makefile.
5243     func_dest_tmpfilename $testsbase/$makefile_am
5244     destfile="$testsbase/$makefile_am"
5245     modules="$testsrelated_modules"
5246     func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
5247     if test -f "$destdir"/$testsbase/$makefile_am; then
5248       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
5249         rm -f "$tmpfile"
5250       else
5251         if $doit; then
5252           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
5253           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
5254           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
5255         else
5256           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
5257           rm -f "$tmpfile"
5258         fi
5259       fi
5260     else
5261       if $doit; then
5262         echo "Creating $testsbase/$makefile_am"
5263         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
5264       else
5265         echo "Create $testsbase/$makefile_am"
5266         rm -f "$tmpfile"
5267       fi
5268     func_append added_files "$testsbase/$makefile_am$nl"
5269     fi
5270   fi
5271
5272   if test "$vc_files" != false; then
5273     # Update the .cvsignore and .gitignore files.
5274     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
5275       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
5276       # Treat gnulib-comp.m4 like an added file, even if it already existed.
5277       echo "$m4base/|A|gnulib-comp.m4"
5278     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
5279     { # Rearrange file descriptors. Needed because "while ... done < ..."
5280       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5281       exec 5<&0 < "$tmp"/fileset-changes
5282       func_update_ignorelist ()
5283       {
5284         ignore="$1"
5285         if test "$ignore" = .gitignore; then
5286           # In a .gitignore file, "foo" applies to the current directory and all
5287           # subdirectories, whereas "/foo" applies to the current directory only.
5288           anchor='/'
5289           escaped_anchor='\/'
5290           doubly_escaped_anchor='\\/'
5291         else
5292           anchor=''
5293           escaped_anchor=''
5294           doubly_escaped_anchor=''
5295         fi
5296         if test -f "$destdir/$dir$ignore"; then
5297           if test -n "$dir_added" || test -n "$dir_removed"; then
5298             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
5299             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
5300                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
5301              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
5302                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-removed
5303             )
5304             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
5305               if $doit; then
5306                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
5307                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
5308                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
5309                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,$/d,' < "$tmp"/ignore-removed; fi
5310                 } > "$tmp"/sed-ignore-removed
5311                 { cat "$destdir/$dir$ignore"~
5312                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
5313                 } | sed -f "$tmp"/sed-ignore-removed \
5314                   > "$destdir/$dir$ignore"
5315               else
5316                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
5317               fi
5318             fi
5319           fi
5320         else
5321           if test -n "$dir_added"; then
5322             if $doit; then
5323               echo "Creating $destdir/$dir$ignore"
5324               {
5325                 if test "$ignore" = .cvsignore; then
5326                   echo ".deps"
5327                   # Automake generates Makefile rules that create .dirstamp files.
5328                   echo ".dirstamp"
5329                 fi
5330                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
5331               } > "$destdir/$dir$ignore"
5332             else
5333               echo "Create $destdir/$dir$ignore"
5334             fi
5335           fi
5336         fi
5337       }
5338       func_done_dir ()
5339       {
5340         dir="$1"
5341         dir_added="$2"
5342         dir_removed="$3"
5343         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
5344           func_update_ignorelist .cvsignore
5345         fi
5346         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
5347           func_update_ignorelist .gitignore
5348         fi
5349       }
5350       last_dir=
5351       last_dir_added=
5352       last_dir_removed=
5353       while read line; do
5354         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
5355         next_dir=`echo "$line" | sed -e 's,|.*,,'`
5356         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
5357         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
5358         if test "$next_dir" != "$last_dir"; then
5359           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
5360           last_dir="$next_dir"
5361           last_dir_added=
5362           last_dir_removed=
5363         fi
5364         case $op in
5365           A) func_append last_dir_added "$file$nl";;
5366           R) func_append last_dir_removed "$file$nl";;
5367         esac
5368       done
5369       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
5370       exec 0<&5 5<&-
5371     }
5372   fi
5373
5374   echo "Finished."
5375   echo
5376   echo "You may need to add #include directives for the following .h files."
5377   # Intersect $specified_modules and $main_modules
5378   # (since $specified_modules is not necessarily of subset of $main_modules
5379   # - some may have been skipped through --avoid, and since the elements of
5380   # $main_modules but not in $specified_modules can go away without explicit
5381   # notice - through changes in the module dependencies).
5382   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
5383   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
5384   # First the #include <...> directives without #ifs, sorted for convenience,
5385   # then the #include "..." directives without #ifs, sorted for convenience,
5386   # then the #include directives that are surrounded by #ifs. Not sorted.
5387   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
5388     include_directive=`func_get_include_directive "$module"`
5389     case "$nl$include_directive" in
5390       *"$nl#if"*)
5391         echo "$include_directive" 1>&5
5392         ;;
5393       *)
5394         echo "$include_directive" | grep -v 'include "' 1>&6
5395         echo "$include_directive" | grep 'include "' 1>&7
5396         ;;
5397     esac
5398   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
5399   (
5400    LC_ALL=C sort -u "$tmp"/include-angles
5401    LC_ALL=C sort -u "$tmp"/include-quotes
5402    cat "$tmp"/include-if
5403   ) | sed -e '/^$/d' -e 's/^/  /'
5404   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
5405
5406   for module in $main_modules; do
5407     func_get_link_directive "$module"
5408   done \
5409     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
5410   if test `wc -l < "$tmp"/link` != 0; then
5411     echo
5412     echo "You may need to use the following Makefile variables when linking."
5413     echo "Use them in <program>_LDADD when linking a program, or"
5414     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
5415     cat "$tmp"/link
5416   fi
5417   rm -f "$tmp"/link
5418
5419   echo
5420   echo "Don't forget to"
5421   if test "$makefile_am" = Makefile.am; then
5422     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
5423   else
5424     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
5425   fi
5426   if test -n "$pobase"; then
5427     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
5428   fi
5429   if test -n "$inctests"; then
5430     if test "$makefile_am" = Makefile.am; then
5431       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
5432     else
5433       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
5434     fi
5435   fi
5436   edit=0
5437   while test $edit != $makefile_am_edits; do
5438     edit=`expr $edit + 1`
5439     eval dir=\"\$makefile_am_edit${edit}_dir\"
5440     eval var=\"\$makefile_am_edit${edit}_var\"
5441     eval val=\"\$makefile_am_edit${edit}_val\"
5442     if test -n "$var"; then
5443       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
5444     fi
5445   done
5446   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
5447   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
5448 }
5449
5450 # func_create_testdir testdir modules
5451 # Input:
5452 # - local_gnulib_dir  from --local-dir
5453 # - modcache        true or false, from --cache-modules/--no-cache-modules
5454 # - auxdir          directory relative to destdir where to place build aux files
5455 # - inctests        true if tests should be included, blank otherwise
5456 # - incobsolete     true if obsolete modules among dependencies should be
5457 #                   included, blank otherwise
5458 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
5459 #                    blank otherwise
5460 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
5461 #                           blank otherwise
5462 # - excl_privileged_tests  true if tests that require root privileges should be
5463 #                          excluded, blank otherwise
5464 # - excl_unportable_tests  true if tests that fail on some platforms should be
5465 #                          excluded, blank otherwise
5466 # - single_configure  true if a single configure file should be generated,
5467 #                     false for a separate configure file for the tests
5468 # - avoidlist       list of modules to avoid
5469 # - cond_dependencies  true if --conditional-dependencies was given, false if
5470 #                      --no-conditional-dependencies was given, blank otherwise
5471 # - libtool         true if --libtool was given, false if --no-libtool was
5472 #                   given, blank otherwise
5473 # - symbolic        true if files should be symlinked, copied otherwise
5474 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
5475 #                   copied otherwise
5476 func_create_testdir ()
5477 {
5478   testdir="$1"
5479   modules="$2"
5480   if test -z "$modules"; then
5481     # All modules together.
5482     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
5483     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
5484     # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
5485     modules=`func_all_modules`
5486     modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist | lib-ignore) ;; *) echo $m;; esac; done`
5487   fi
5488   specified_modules="$modules"
5489
5490   # Canonicalize the list of specified modules.
5491   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
5492
5493   # Unlike in func_import, here we want to include all kinds of tests for the
5494   # directly specified modules, but not for dependencies.
5495   inc_all_direct_tests=true
5496   inc_all_indirect_tests="$inc_all_tests"
5497
5498   # Check that the license of every module is consistent with the license of
5499   # its dependencies.
5500   saved_inctests="$inctests"
5501   # When computing transitive closures, don't consider $module to depend on
5502   # $module-tests. Need this becauses tests are implicitly GPL and may depend
5503   # on GPL modules - therefore we don't want a warning in this case.
5504   inctests=""
5505   for requested_module in $specified_modules; do
5506     requested_license=`func_get_license "$requested_module"`
5507     if test "$requested_license" != GPL; then
5508       # Here we use func_modules_transitive_closure, not just
5509       # func_get_dependencies, so that we also detect weird situations like
5510       # an LGPL module which depends on a GPLed build tool module which depends
5511       # on a GPL module.
5512       modules="$requested_module"
5513       func_modules_transitive_closure
5514       for module in $modules; do
5515         license=`func_get_license "$module"`
5516         case "$license" in
5517           'GPLed build tool') ;;
5518           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
5519           *)
5520             case "$requested_license" in
5521               GPLv2+)
5522                 case "$license" in
5523                   GPLv2+ | LGPLv2+) ;;
5524                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5525                 esac
5526                 ;;
5527               LGPL)
5528                 case "$license" in
5529                   LGPL | LGPLv2+) ;;
5530                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5531                 esac
5532                 ;;
5533               LGPLv2+)
5534                 case "$license" in
5535                   LGPLv2+) ;;
5536                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
5537                 esac
5538                 ;;
5539             esac
5540             ;;
5541         esac
5542       done
5543     fi
5544   done
5545   inctests="$saved_inctests"
5546
5547   # Subdirectory names.
5548   sourcebase=gllib
5549   m4base=glm4
5550   pobase=
5551   docbase=gldoc
5552   testsbase=gltests
5553   macro_prefix=gl
5554   po_domain=
5555   witness_c_macro=
5556   vc_files=
5557
5558   # Determine final module list.
5559   modules="$specified_modules"
5560   func_modules_transitive_closure
5561   if test $verbose -ge 0; then
5562     func_show_module_list
5563   fi
5564   final_modules="$modules"
5565
5566   if $single_configure; then
5567     # Determine main module list and tests-related module list separately.
5568     func_modules_transitive_closure_separately
5569   fi
5570
5571   if $single_configure; then
5572     # Determine whether a $testsbase/libtests.a is needed.
5573     func_determine_use_libtests
5574   fi
5575
5576   # Add the dummy module if needed.
5577   if $single_configure; then
5578     func_modules_add_dummy_separately
5579   else
5580     func_modules_add_dummy
5581   fi
5582
5583   # Show banner notice of every module.
5584   if $single_configure; then
5585     modules="$main_modules"
5586     func_modules_notice
5587   else
5588     func_modules_notice
5589   fi
5590
5591   # Determine final file list.
5592   if $single_configure; then
5593     func_modules_to_filelist_separately
5594   else
5595     func_modules_to_filelist
5596     if test $verbose -ge 0; then
5597       echo "File list:"
5598       echo "$files" | sed -e 's/^/  /'
5599     fi
5600   fi
5601   # Add files for which the copy in gnulib is newer than the one that
5602   # "automake --add-missing --copy" would provide.
5603   files="$files build-aux/config.guess"
5604   files="$files build-aux/config.sub"
5605   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
5606
5607   rewritten='%REWRITTEN%'
5608   sed_rewrite_files="\
5609     s,^build-aux/,$rewritten$auxdir/,
5610     s,^doc/,$rewritten$docbase/,
5611     s,^lib/,$rewritten$sourcebase/,
5612     s,^m4/,$rewritten$m4base/,
5613     s,^tests/,$rewritten$testsbase/,
5614     s,^tests=lib/,$rewritten$testsbase/,
5615     s,^top/,$rewritten,
5616     s,^$rewritten,,"
5617
5618   # Create directories.
5619   for f in $files; do echo $f; done \
5620     | sed -e "$sed_rewrite_files" \
5621     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
5622     | LC_ALL=C sort -u \
5623     > "$tmp"/dirs
5624   { # Rearrange file descriptors. Needed because "while ... done < ..."
5625     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5626     exec 5<&0 < "$tmp"/dirs
5627     while read d; do
5628       mkdir -p "$testdir/$d"
5629     done
5630     exec 0<&5 5<&-
5631   }
5632
5633   # Copy files or make symbolic links.
5634   delimiter='   '
5635   for f in $files; do echo $f; done \
5636     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
5637     | LC_ALL=C sort \
5638     > "$tmp"/files
5639   { # Rearrange file descriptors. Needed because "while ... done < ..."
5640     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5641     exec 5<&0 < "$tmp"/files
5642     while read g f; do
5643       case "$f" in
5644         tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
5645       esac
5646       func_lookup_file "$f"
5647       if test -n "$lookedup_tmp"; then
5648         cp -p "$lookedup_file" "$testdir/$g"
5649       else
5650         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
5651         if { test -n "$symbolic" \
5652              || { test -n "$lsymbolic" \
5653                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
5654           func_ln "$lookedup_file" "$testdir/$g"
5655         else
5656           cp -p "$lookedup_file" "$testdir/$g"
5657         fi
5658       fi
5659     done
5660     exec 0<&5 5<&-
5661   }
5662
5663   # Determine include_guard_prefix.
5664   func_compute_include_guard_prefix
5665
5666   # Create Makefile.ams that are for testing.
5667   for_test=true
5668
5669   # No special edits are needed.
5670   makefile_am_edits=0
5671
5672   # Create $sourcebase/Makefile.am.
5673   mkdir -p "$testdir/$sourcebase"
5674   destfile="$sourcebase/Makefile.am"
5675   if $single_configure; then
5676     modules="$main_modules"
5677   fi
5678   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
5679   any_uses_subdirs="$uses_subdirs"
5680
5681   # Create $m4base/Makefile.am.
5682   mkdir -p "$testdir/$m4base"
5683   (echo "## Process this file with automake to produce Makefile.in."
5684    echo
5685    echo "EXTRA_DIST ="
5686    for f in $files; do
5687      case "$f" in
5688        m4/* )
5689          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
5690      esac
5691    done
5692   ) > "$testdir/$m4base/Makefile.am"
5693
5694   subdirs="$sourcebase $m4base"
5695   subdirs_with_configure_ac=""
5696
5697   if false && test -f "$testdir"/$m4base/gettext.m4; then
5698     # Avoid stupid error message from automake:
5699     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
5700     mkdir -p "$testdir/po"
5701     (echo "## Process this file with automake to produce Makefile.in."
5702     ) > "$testdir/po/Makefile.am"
5703     func_append subdirs " po"
5704   fi
5705
5706   if test -n "$inctests"; then
5707     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
5708     if $single_configure; then
5709       # Create $testsbase/Makefile.am.
5710       destfile="$testsbase/Makefile.am"
5711       modules="$testsrelated_modules"
5712       func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$testdir/$testsbase/Makefile.am"
5713     else
5714       # Viewed from the $testsbase subdirectory, $auxdir is different.
5715       saved_auxdir="$auxdir"
5716       auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
5717       # Create $testsbase/Makefile.am.
5718       use_libtests=false
5719       destfile="$testsbase/Makefile.am"
5720       func_emit_tests_Makefile_am "" > "$testdir/$testsbase/Makefile.am"
5721       any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
5722       # Create $testsbase/configure.ac.
5723       (echo "# Process this file with autoconf to produce a configure script."
5724        echo "AC_INIT([dummy], [0])"
5725        echo "AC_CONFIG_AUX_DIR([$auxdir])"
5726        echo "AM_INIT_AUTOMAKE"
5727        echo
5728        echo "AC_CONFIG_HEADERS([config.h])"
5729        echo
5730        echo "AC_PROG_CC"
5731        echo "AC_PROG_INSTALL"
5732        echo "AC_PROG_MAKE_SET"
5733        echo "AC_PROG_RANLIB"
5734        echo
5735        if test -n "$uses_subdirs"; then
5736          echo "AM_PROG_CC_C_O"
5737          echo
5738        fi
5739        for module in $modules; do
5740          func_verify_module
5741          if test -n "$module"; then
5742            case $module in
5743              gnumakefile | maintainer-makefile)
5744                # These modules are meant to be used only in the top-level directory.
5745                ;;
5746              *)
5747                func_get_autoconf_early_snippet "$module"
5748                ;;
5749            esac
5750          fi
5751        done \
5752          | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5753        if test "$libtool" = true; then
5754          echo "LT_INIT([win32-dll])"
5755          echo "LT_LANG([C++])"
5756          echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5757          echo "gl_cond_libtool=true"
5758        else
5759          echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5760          echo "gl_cond_libtool=false"
5761          echo "gl_libdeps="
5762          echo "gl_ltlibdeps="
5763        fi
5764        # Wrap the set of autoconf snippets into an autoconf macro that is then
5765        # invoked. This is needed because autoconf does not support AC_REQUIRE
5766        # at the top level:
5767        #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5768        # but we want the AC_REQUIRE to have its normal meaning (provide one
5769        # expansion of the required macro before the current point, and only one
5770        # expansion total).
5771        echo "AC_DEFUN([gl_INIT], ["
5772        sed_replace_build_aux='
5773          :a
5774          /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5775            s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5776            ba
5777          }'
5778        echo "gl_m4_base='../$m4base'"
5779        func_emit_initmacro_start $macro_prefix
5780        # We don't have explicit ordering constraints between the various
5781        # autoconf snippets. It's cleanest to put those of the library before
5782        # those of the tests.
5783        echo "gl_source_base='../$sourcebase'"
5784        func_emit_autoconf_snippets "$modules" func_verify_nontests_module false false false
5785        echo "gl_source_base='.'"
5786        func_emit_autoconf_snippets "$modules" func_verify_tests_module false false false
5787        func_emit_initmacro_end $macro_prefix
5788        # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5789        # created using libtool, because libtool already handles the dependencies.
5790        if test "$libtool" != true; then
5791          libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5792          echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5793          echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5794          echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5795          echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5796        fi
5797        echo "])"
5798        func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
5799        echo
5800        echo "gl_INIT"
5801        echo
5802        # Usually $testsbase/config.h will be a superset of config.h. Verify this
5803        # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
5804        echo "AH_TOP([#include \"../config.h\"])"
5805        echo
5806        echo "AC_CONFIG_FILES([Makefile])"
5807        echo "AC_OUTPUT"
5808       ) > "$testdir/$testsbase/configure.ac"
5809       auxdir="$saved_auxdir"
5810       subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
5811     fi
5812     func_append subdirs " $testsbase"
5813   fi
5814
5815   # Create Makefile.am.
5816   (echo "## Process this file with automake to produce Makefile.in."
5817    echo
5818    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
5819    echo
5820    echo "SUBDIRS = $subdirs"
5821    echo
5822    echo "ACLOCAL_AMFLAGS = -I $m4base"
5823   ) > "$testdir/Makefile.am"
5824
5825   # Create configure.ac.
5826   (echo "# Process this file with autoconf to produce a configure script."
5827    echo "AC_INIT([dummy], [0])"
5828    if test "$auxdir" != "."; then
5829      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5830    fi
5831    echo "AM_INIT_AUTOMAKE"
5832    echo
5833    echo "AC_CONFIG_HEADERS([config.h])"
5834    echo
5835    echo "AC_PROG_CC"
5836    echo "AC_PROG_INSTALL"
5837    echo "AC_PROG_MAKE_SET"
5838    echo
5839    echo "# For autobuild."
5840    echo "AC_CANONICAL_BUILD"
5841    echo "AC_CANONICAL_HOST"
5842    echo
5843    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5844    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5845    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5846    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5847    echo
5848    echo "AC_PROG_RANLIB"
5849    echo
5850    if test -n "$any_uses_subdirs"; then
5851      echo "AM_PROG_CC_C_O"
5852      echo
5853    fi
5854    for module in $final_modules; do
5855      if $single_configure; then
5856        func_verify_module
5857      else
5858        func_verify_nontests_module
5859      fi
5860      if test -n "$module"; then
5861        func_get_autoconf_early_snippet "$module"
5862      fi
5863    done \
5864      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5865    if test "$libtool" = true; then
5866      echo "LT_INIT([win32-dll])"
5867      echo "LT_LANG([C++])"
5868      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5869      echo "gl_cond_libtool=true"
5870    else
5871      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5872      echo "gl_cond_libtool=false"
5873      echo "gl_libdeps="
5874      echo "gl_ltlibdeps="
5875    fi
5876    # Wrap the set of autoconf snippets into an autoconf macro that is then
5877    # invoked. This is needed because autoconf does not support AC_REQUIRE
5878    # at the top level:
5879    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5880    # but we want the AC_REQUIRE to have its normal meaning (provide one
5881    # expansion of the required macro before the current point, and only one
5882    # expansion total).
5883    echo "AC_DEFUN([gl_INIT], ["
5884    if test "$auxdir" != "build-aux"; then
5885      sed_replace_build_aux='
5886        :a
5887        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5888          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5889          ba
5890        }'
5891    else
5892      sed_replace_build_aux="$sed_noop"
5893    fi
5894    echo "gl_m4_base='$m4base'"
5895    func_emit_initmacro_start $macro_prefix
5896    echo "gl_source_base='$sourcebase'"
5897    if $single_configure; then
5898      func_emit_autoconf_snippets "$main_modules" func_verify_module true false false
5899    else
5900      func_emit_autoconf_snippets "$modules" func_verify_nontests_module true false false
5901    fi
5902    func_emit_initmacro_end $macro_prefix
5903    if $single_configure; then
5904      echo "  gltests_libdeps="
5905      echo "  gltests_ltlibdeps="
5906      func_emit_initmacro_start ${macro_prefix}tests
5907      echo "  gl_source_base='$testsbase'"
5908      # Define a tests witness macro.
5909      echo "  ${macro_prefix}tests_WITNESS=IN_GNULIB_TESTS"
5910      echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
5911      echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
5912      echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
5913      func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true false false
5914      echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
5915      func_emit_initmacro_end ${macro_prefix}tests
5916    fi
5917    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5918    # created using libtool, because libtool already handles the dependencies.
5919    if test "$libtool" != true; then
5920      libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5921      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5922      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5923      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5924      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5925    fi
5926    if $single_configure; then
5927      if $use_libtests; then
5928        echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
5929        echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
5930      fi
5931    fi
5932    echo "])"
5933    func_emit_initmacro_done $macro_prefix $sourcebase
5934    if $single_configure; then
5935      func_emit_initmacro_done ${macro_prefix}tests $testsbase
5936    fi
5937    echo
5938    echo "gl_INIT"
5939    echo
5940    if test -n "$subdirs_with_configure_ac"; then
5941      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
5942    fi
5943    makefiles="Makefile"
5944    for d in $subdirs; do
5945      # For subdirs that have a configure.ac by their own, it's the subdir's
5946      # configure.ac which creates the subdir's Makefile.am, not this one.
5947      case " $subdirs_with_configure_ac " in
5948        *" $d "*) ;;
5949        *) func_append makefiles " $d/Makefile" ;;
5950      esac
5951    done
5952    echo "AC_CONFIG_FILES([$makefiles])"
5953    echo "AC_OUTPUT"
5954   ) > "$testdir/configure.ac"
5955
5956   # Create autogenerated files.
5957   (cd "$testdir"
5958    # Do not use "${AUTORECONF} --force --install", because it may invoke
5959    # autopoint, which brings in older versions of some of our .m4 files.
5960    if test -f $m4base/gettext.m4; then
5961      func_execute_command ${AUTOPOINT} --force || func_exit 1
5962      for f in $m4base/*.m4~; do
5963        if test -f $f; then
5964          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
5965        fi
5966      done
5967    fi
5968    if test "$libtool" = true; then
5969      func_execute_command ${LIBTOOLIZE} --copy || func_exit 1
5970    fi
5971    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
5972    if ! test -d build-aux; then
5973      func_execute_command mkdir build-aux || func_exit 1
5974    fi
5975    func_execute_command ${AUTOCONF} || func_exit 1
5976    func_execute_command ${AUTOHEADER} || func_exit 1
5977    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5978   ) || func_exit 1
5979   if test -n "$inctests" && ! $single_configure; then
5980     # Create autogenerated files.
5981     (cd "$testdir/$testsbase" || func_exit 1
5982      # Do not use "${AUTORECONF} --force --install", because it may invoke
5983      # autopoint, which brings in older versions of some of our .m4 files.
5984      if test -f ../$m4base/gettext.m4; then
5985        func_execute_command ${AUTOPOINT} --force || func_exit 1
5986        for f in ../$m4base/*.m4~; do
5987          if test -f $f; then
5988            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
5989          fi
5990        done
5991      fi
5992      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
5993      if ! test -d ../build-aux; then
5994        func_execute_command mkdir ../build-aux
5995      fi
5996      func_execute_command ${AUTOCONF} || func_exit 1
5997      func_execute_command ${AUTOHEADER} || func_exit 1
5998      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5999     ) || func_exit 1
6000   fi
6001   # Need to run configure and make once, to create built files that are to be
6002   # distributed (such as parse-datetime.c).
6003   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
6004   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
6005   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
6006                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
6007   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
6008   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
6009   # such $(FOO_H) because they don't refer to distributed files.
6010   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
6011                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
6012                  | sed -e "$sed_remove_make_variables"`
6013   distributed_built_sources=`for file in $built_sources; do
6014                                case "$cleaned_files" in
6015                                  *" "$file" "*) ;;
6016                                  *) echo $file ;;
6017                                esac;
6018                              done`
6019   tests_distributed_built_sources=
6020   if test -n "$inctests"; then
6021     # Likewise for built files in the $testsbase directory.
6022     tests_cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
6023                          | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
6024     tests_cleaned_files=`for file in $tests_cleaned_files; do echo " $file "; done`
6025     tests_built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
6026                          | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
6027                          | sed -e "$sed_remove_make_variables"`
6028     tests_distributed_built_sources=`for file in $tests_built_sources; do
6029                                        case "$tests_cleaned_files" in
6030                                          *" "$file" "*) ;;
6031                                          *) echo $file ;;
6032                                        esac;
6033                                      done`
6034   fi
6035   if test -n "$distributed_built_sources" || test -n "$tests_distributed_built_sources"; then
6036     (cd "$testdir"
6037      ./configure || func_exit 1
6038        if test -n "$distributed_built_sources"; then
6039          cd "$sourcebase"
6040          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
6041          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6042                built_sources \
6043            || func_exit 1
6044          cd ..
6045        fi
6046        if test -n "$tests_distributed_built_sources"; then
6047          cd "$testsbase"
6048          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
6049          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6050                built_sources \
6051            || func_exit 1
6052          cd ..
6053        fi
6054      $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
6055            distclean \
6056        || func_exit 1
6057     ) || func_exit 1
6058   fi
6059 }
6060
6061 # func_create_megatestdir megatestdir allmodules
6062 # Input:
6063 # - local_gnulib_dir  from --local-dir
6064 # - modcache        true or false, from --cache-modules/--no-cache-modules
6065 # - auxdir          directory relative to destdir where to place build aux files
6066 func_create_megatestdir ()
6067 {
6068   megatestdir="$1"
6069   allmodules="$2"
6070   if test -z "$allmodules"; then
6071     allmodules=`func_all_modules`
6072   fi
6073
6074   megasubdirs=
6075   # First, all modules one by one.
6076   for onemodule in $allmodules; do
6077     func_create_testdir "$megatestdir/$onemodule" $onemodule
6078     func_append megasubdirs "$onemodule "
6079   done
6080   # Then, all modules all together.
6081   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
6082   allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
6083   func_create_testdir "$megatestdir/ALL" "$allmodules"
6084   func_append megasubdirs "ALL"
6085
6086   # Create autobuild.
6087   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
6088              vc_witness="$gnulib_dir/CVS/Entries"; \
6089            else \
6090              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
6091            fi; \
6092            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
6093              | sed -e 's,January,01,'   -e 's,Jan,01,' \
6094                    -e 's,February,02,'  -e 's,Feb,02,' \
6095                    -e 's,March,03,'     -e 's,Mar,03,' \
6096                    -e 's,April,04,'     -e 's,Apr,04,' \
6097                    -e 's,May,05,'                      \
6098                    -e 's,June,06,'      -e 's,Jun,06,' \
6099                    -e 's,July,07,'      -e 's,Jul,07,' \
6100                    -e 's,August,08,'    -e 's,Aug,08,' \
6101                    -e 's,September,09,' -e 's,Sep,09,' \
6102                    -e 's,October,10,'   -e 's,Oct,10,' \
6103                    -e 's,November,11,'  -e 's,Nov,11,' \
6104                    -e 's,December,12,'  -e 's,Dec,12,' \
6105                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
6106                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
6107   (echo '#!/bin/sh'
6108    echo "CVSDATE=$cvsdate"
6109    echo ": \${MAKE=make}"
6110    echo "test -d logs || mkdir logs"
6111    echo "for module in $megasubdirs; do"
6112    echo "  echo \"Working on module \$module...\""
6113    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
6114    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
6115    echo "   echo"
6116    echo "   set -x"
6117    echo "   : autobuild project... \$module"
6118    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
6119    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
6120    echo "   : autobuild hostname... \`hostname\`"
6121    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && \$MAKE && \$MAKE check && \$MAKE distclean"
6122    echo "   echo rc=\$?"
6123    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
6124    echo "done"
6125   ) > "$megatestdir/do-autobuild"
6126   chmod a+x "$megatestdir/do-autobuild"
6127
6128   # Create Makefile.am.
6129   (echo "## Process this file with automake to produce Makefile.in."
6130    echo
6131    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
6132    echo
6133    echo "SUBDIRS = $megasubdirs"
6134    echo
6135    echo "EXTRA_DIST = do-autobuild"
6136   ) > "$megatestdir/Makefile.am"
6137
6138   # Create configure.ac.
6139   (echo "# Process this file with autoconf to produce a configure script."
6140    echo "AC_INIT([dummy], [0])"
6141    if test "$auxdir" != "."; then
6142      echo "AC_CONFIG_AUX_DIR([$auxdir])"
6143    fi
6144    echo "AM_INIT_AUTOMAKE"
6145    echo
6146    echo "AC_PROG_MAKE_SET"
6147    echo
6148    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
6149    echo "AC_CONFIG_FILES([Makefile])"
6150    echo "AC_OUTPUT"
6151   ) > "$megatestdir/configure.ac"
6152
6153   # Create autogenerated files.
6154   (cd "$megatestdir"
6155    # Do not use "${AUTORECONF} --install", because autoreconf operates
6156    # recursively, but the subdirectories are already finished, therefore
6157    # calling autoreconf here would only waste lots of CPU time.
6158    func_execute_command ${ACLOCAL} || func_exit 1
6159    func_execute_command mkdir build-aux
6160    func_execute_command ${AUTOCONF} || func_exit 1
6161    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
6162   ) || func_exit 1
6163 }
6164
6165 case $mode in
6166   "" )
6167     func_fatal_error "no mode specified" ;;
6168
6169   list )
6170     func_all_modules
6171     ;;
6172
6173   find )
6174     # sed expression that converts a literal to a basic regular expression.
6175     # Needs to handle . [ \ * ^ $.
6176     sed_literal_to_basic_regex='s/\\/\\\\/g
6177 s/\[/\\[/g
6178 s/\^/\\^/g
6179 s/\([.*$]\)/[\1]/g'
6180     for filename
6181     do
6182       if test -f "$gnulib_dir/$filename" \
6183          || { test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$filename"; }; then
6184         filename_anywhere_regex=`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`
6185         filename_line_regex='^'"$filename_anywhere_regex"'$'
6186         module_candidates=`
6187           {
6188             (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filename_line_regex" /dev/null | sed -e 's,^modules/,,')
6189             if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
6190               (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$,,')
6191             fi
6192           } \
6193             | func_sanitize_modulelist \
6194             | LC_ALL=C sort -u
6195           `
6196         for module in $module_candidates; do
6197           if func_get_filelist $module | grep "$filename_line_regex" > /dev/null; then
6198             echo $module
6199           fi
6200         done
6201       else
6202         func_warning "file $filename does not exist"
6203       fi
6204     done
6205     ;;
6206
6207   import | add-import | remove-import | update )
6208
6209     # Where to import.
6210     if test -z "$destdir"; then
6211       destdir=.
6212     fi
6213     test -d "$destdir" \
6214       || func_fatal_error "destination directory does not exist: $destdir"
6215
6216     # Prefer configure.ac to configure.in.
6217     if test -f "$destdir"/configure.ac; then
6218       configure_ac="$destdir/configure.ac"
6219     else
6220       if test -f "$destdir"/configure.in; then
6221         configure_ac="$destdir/configure.in"
6222       else
6223         func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
6224       fi
6225     fi
6226
6227     # Analyze configure.ac.
6228     guessed_auxdir="."
6229     guessed_libtool=false
6230     my_sed_traces='
6231       s,#.*$,,
6232       s,^dnl .*$,,
6233       s, dnl .*$,,
6234       /AC_CONFIG_AUX_DIR/ {
6235         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
6236       }
6237       /A[CM]_PROG_LIBTOOL/ {
6238         s,^.*$,guessed_libtool=true,p
6239       }'
6240     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
6241
6242     if test -z "$auxdir"; then
6243       auxdir="$guessed_auxdir"
6244     fi
6245
6246     # Determine where to apply func_import.
6247     if test "$mode" = import; then
6248       # Apply func_import to a particular gnulib directory.
6249       # The command line contains the complete specification; don't look at
6250       # the contents of gnulib-cache.m4.
6251       test -n "$supplied_libname" || supplied_libname=true
6252       test -n "$sourcebase" || sourcebase="lib"
6253       test -n "$m4base" || m4base="m4"
6254       test -n "$docbase" || docbase="doc"
6255       test -n "$testsbase" || testsbase="tests"
6256       test -n "$macro_prefix" || macro_prefix="gl"
6257       func_import "$*"
6258     else
6259       if test -n "$m4base"; then
6260         # Apply func_import to a particular gnulib directory.
6261         # Any number of additional modules can be given.
6262         if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
6263           # First use of gnulib in the given m4base.
6264           test -n "$supplied_libname" || supplied_libname=true
6265           test -n "$sourcebase" || sourcebase="lib"
6266           test -n "$docbase" || docbase="doc"
6267           test -n "$testsbase" || testsbase="tests"
6268           test -n "$macro_prefix" || macro_prefix="gl"
6269         fi
6270         func_import "$*"
6271       else
6272         # Apply func_import to all gnulib directories.
6273         # To get this list of directories, look at Makefile.am. (Not at
6274         # configure, because it may be omitted from version control. Also,
6275         # don't run "find $destdir -name gnulib-cache.m4", as it might be
6276         # too expensive.)
6277         m4dirs=
6278         m4dirs_count=0
6279         if test -f "$destdir"/Makefile.am; then
6280           aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[        ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
6281           m4dir_is_next=
6282           for arg in $aclocal_amflags; do
6283             if test -n "$m4dir_is_next"; then
6284               # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
6285               case "$arg" in
6286                 /*) ;;
6287                 *)
6288                   if test -f "$destdir/$arg"/gnulib-cache.m4; then
6289                     func_append m4dirs " $arg"
6290                     m4dirs_count=`expr $m4dirs_count + 1`
6291                   fi
6292                   ;;
6293               esac
6294               m4dir_is_next=
6295             else
6296               if test "X$arg" = "X-I"; then
6297                 m4dir_is_next=yes
6298               else
6299                 m4dir_is_next=
6300               fi
6301             fi
6302           done
6303         else
6304           # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
6305           if test -f "$destdir"/aclocal.m4; then
6306             sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
6307             sedexpr2='s,^[^/]*$,.,'
6308             sedexpr3='s,/[^/]*$,,'
6309             m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
6310             m4dirs=`for arg in $m4dirs; do if test -f "$destdir/$arg"/gnulib-cache.m4; then echo $arg; fi; done`
6311             m4dirs_count=`for arg in $m4dirs; do echo "$arg"; done | wc -l`
6312           fi
6313         fi
6314         if test $m4dirs_count = 0; then
6315           # First use of gnulib in a package.
6316           # Any number of additional modules can be given.
6317           test -n "$supplied_libname" || supplied_libname=true
6318           test -n "$sourcebase" || sourcebase="lib"
6319           m4base="m4"
6320           test -n "$docbase" || docbase="doc"
6321           test -n "$testsbase" || testsbase="tests"
6322           test -n "$macro_prefix" || macro_prefix="gl"
6323           func_import "$*"
6324         else
6325           if test $m4dirs_count = 1; then
6326             # There's only one use of gnulib here. Assume the user means it.
6327             # Any number of additional modules can be given.
6328             for m4base in $m4dirs; do
6329               func_import "$*"
6330             done
6331           else
6332             # Ambiguous - guess what the user meant.
6333             if test $# = 0; then
6334               # No further arguments. Guess the user wants to update all of them.
6335               for m4base in $m4dirs; do
6336                 # Perform func_import in a subshell, so that variable values
6337                 # such as
6338                 #   local_gnulib_dir, incobsolete, inc_cxx_tests,
6339                 #   inc_longrunning_tests, inc_privileged_tests,
6340                 #   inc_unportable_tests, inc_all_tests, avoidlist, sourcebase,
6341                 #   m4base, pobase, docbase, testsbase, inctests, libname, lgpl,
6342                 #   makefile_name, libtool, macro_prefix, po_domain,
6343                 #   witness_c_macro, vc_files
6344                 # don't propagate from one directory to another.
6345                 (func_import) || func_exit 1
6346               done
6347             else
6348               # Really ambiguous.
6349               func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
6350             fi
6351           fi
6352         fi
6353       fi
6354     fi
6355     ;;
6356
6357   create-testdir )
6358     if test -z "$destdir"; then
6359       func_fatal_error "please specify --dir option"
6360     fi
6361     mkdir "$destdir"
6362     test -d "$destdir" \
6363       || func_fatal_error "could not create destination directory"
6364     test -n "$auxdir" || auxdir="build-aux"
6365     func_create_testdir "$destdir" "$*"
6366     ;;
6367
6368   create-megatestdir )
6369     if test -z "$destdir"; then
6370       func_fatal_error "please specify --dir option"
6371     fi
6372     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6373     test -n "$auxdir" || auxdir="build-aux"
6374     func_create_megatestdir "$destdir" "$*"
6375     ;;
6376
6377   test )
6378     test -n "$destdir" || destdir=testdir$$
6379     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6380     test -n "$auxdir" || auxdir="build-aux"
6381     func_create_testdir "$destdir" "$*"
6382     cd "$destdir"
6383       mkdir build
6384       cd build
6385         ../configure || func_exit 1
6386         $MAKE || func_exit 1
6387         $MAKE check || func_exit 1
6388         $MAKE distclean || func_exit 1
6389         remaining=`find . -type f -print`
6390         if test -n "$remaining"; then
6391           echo "Remaining files:" $remaining 1>&2
6392           echo "gnulib-tool: *** Stop." 1>&2
6393           func_exit 1
6394         fi
6395       cd ..
6396     cd ..
6397     rm -rf "$destdir"
6398     ;;
6399
6400   megatest )
6401     test -n "$destdir" || destdir=testdir$$
6402     mkdir "$destdir" || func_fatal_error "could not create destination directory"
6403     test -n "$auxdir" || auxdir="build-aux"
6404     func_create_megatestdir "$destdir" "$*"
6405     cd "$destdir"
6406       mkdir build
6407       cd build
6408         ../configure
6409         $MAKE
6410         $MAKE check
6411         $MAKE distclean
6412         remaining=`find . -type f -print`
6413         if test -n "$remaining"; then
6414           echo "Remaining files:" $remaining 1>&2
6415           echo "gnulib-tool: *** Stop." 1>&2
6416           func_exit 1
6417         fi
6418       cd ..
6419     cd ..
6420     rm -rf "$destdir"
6421     ;;
6422
6423   extract-description )
6424     for module
6425     do
6426       func_verify_module
6427       if test -n "$module"; then
6428         func_get_description "$module"
6429       fi
6430     done
6431     ;;
6432
6433   extract-comment )
6434     for module
6435     do
6436       func_verify_module
6437       if test -n "$module"; then
6438         func_get_comment "$module"
6439       fi
6440     done
6441     ;;
6442
6443   extract-status )
6444     for module
6445     do
6446       func_verify_module
6447       if test -n "$module"; then
6448         func_get_status "$module"
6449       fi
6450     done
6451     ;;
6452
6453   extract-notice )
6454     for module
6455     do
6456       func_verify_module
6457       if test -n "$module"; then
6458         func_get_notice "$module"
6459       fi
6460     done
6461     ;;
6462
6463   extract-applicability )
6464     for module
6465     do
6466       func_verify_module
6467       if test -n "$module"; then
6468         func_get_applicability "$module"
6469       fi
6470     done
6471     ;;
6472
6473   extract-filelist )
6474     for module
6475     do
6476       func_verify_module
6477       if test -n "$module"; then
6478         func_get_filelist "$module"
6479       fi
6480     done
6481     ;;
6482
6483   extract-dependencies )
6484     for module
6485     do
6486       func_verify_module
6487       if test -n "$module"; then
6488         func_get_dependencies "$module"
6489       fi
6490     done
6491     ;;
6492
6493   extract-autoconf-snippet )
6494     for module
6495     do
6496       func_verify_module
6497       if test -n "$module"; then
6498         func_get_autoconf_snippet "$module"
6499       fi
6500     done
6501     ;;
6502
6503   extract-automake-snippet )
6504     for module
6505     do
6506       func_verify_module
6507       if test -n "$module"; then
6508         func_get_automake_snippet "$module"
6509       fi
6510     done
6511     ;;
6512
6513   extract-include-directive )
6514     for module
6515     do
6516       func_verify_module
6517       if test -n "$module"; then
6518         func_get_include_directive "$module"
6519       fi
6520     done
6521     ;;
6522
6523   extract-link-directive )
6524     for module
6525     do
6526       func_verify_module
6527       if test -n "$module"; then
6528         func_get_link_directive "$module"
6529       fi
6530     done
6531     ;;
6532
6533   extract-license )
6534     for module
6535     do
6536       func_verify_module
6537       if test -n "$module"; then
6538         func_get_license "$module"
6539       fi
6540     done
6541     ;;
6542
6543   extract-maintainer )
6544     for module
6545     do
6546       func_verify_module
6547       if test -n "$module"; then
6548         func_get_maintainer "$module"
6549       fi
6550     done
6551     ;;
6552
6553   extract-tests-module )
6554     for module
6555     do
6556       func_verify_module
6557       if test -n "$module"; then
6558         func_get_tests_module "$module"
6559       fi
6560     done
6561     ;;
6562
6563   copy-file )
6564     # Verify the number of arguments.
6565     if test $# -lt 1 || test $# -gt 2; then
6566       func_fatal_error "invalid number of arguments for --$mode"
6567     fi
6568
6569     # The first argument is the file to be copied.
6570     f="$1"
6571     # Verify the file exists.
6572     func_lookup_file "$f"
6573
6574     # The second argument is the destination; either a directory ot a file.
6575     # It defaults to the current directory.
6576     dest="$2"
6577     test -n "$dest" || dest='.'
6578     test -n "$sourcebase" || sourcebase="lib"
6579     test -n "$m4base" || m4base="m4"
6580     test -n "$docbase" || docbase="doc"
6581     test -n "$testsbase" || testsbase="tests"
6582     test -n "$auxdir" || auxdir="build-aux"
6583     rewritten='%REWRITTEN%'
6584     sed_rewrite_files="\
6585       s,^build-aux/,$rewritten$auxdir/,
6586       s,^doc/,$rewritten$docbase/,
6587       s,^lib/,$rewritten$sourcebase/,
6588       s,^m4/,$rewritten$m4base/,
6589       s,^tests/,$rewritten$testsbase/,
6590       s,^top/,$rewritten,
6591       s,^$rewritten,,"
6592     if test -d "$dest"; then
6593       destdir="$dest"
6594       g=`echo "$f" | sed -e "$sed_rewrite_files"`
6595     else
6596       destdir=`dirname "$dest"`
6597       g=`basename "$dest"`
6598     fi
6599
6600     # Create the directory for destfile.
6601     d=`dirname "$destdir/$g"`
6602     if $doit; then
6603       if test -n "$d" && test ! -d "$d"; then
6604         mkdir -p "$d" || func_fatal_error "failed"
6605       fi
6606     fi
6607     # Copy the file.
6608     func_dest_tmpfilename "$g"
6609     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
6610     already_present=true
6611     if test -f "$destdir/$g"; then
6612       # The file already exists.
6613       func_update_file
6614     else
6615       # Install the file.
6616       # Don't protest if the file should be there but isn't: it happens
6617       # frequently that developers don't put autogenerated files under version
6618       # control.
6619       func_add_file
6620     fi
6621     rm -f "$tmpfile"
6622     ;;
6623
6624   * )
6625     func_fatal_error "unknown operation mode --$mode" ;;
6626 esac
6627
6628 rm -rf "$tmp"
6629 # Undo the effect of the previous 'trap' command. Some shellology:
6630 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
6631 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
6632 # exit); for the others we need to call 'exit' explicitly. The value of $? is
6633 # 128 + signal number and is set before the trap-registered command is run.
6634 trap '' 0
6635 trap 'func_exit $?' 1 2 3 13 15
6636
6637 exit 0
6638
6639 # Local Variables:
6640 # indent-tabs-mode: nil
6641 # whitespace-check-buffer-indent: nil
6642 # End: