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