gnulib-tool: Reduce code duplication.
[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_snippets modules verifier toplevel disable_libtool disable_gettext
3364 # collects and emit the autoconf snippets of a set of modules.
3365 # - modules is the list of modules.
3366 # - verifier is one of func_verify_module, func_verify_nontests_module,
3367 #   func_verify_tests_module. It selects the subset of $modules to consider.
3368 # - toplevel is true or false. 'false' means a subordinate use of gnulib-tool.
3369 # - disable_libtool is true or false. It tells whether to disable libtool
3370 #   handling even if it has been specified through the command line options.
3371 # - disable_gettext is true or false. It tells whether to disable AM_GNU_GETTEXT
3372 #   invocations.
3373 # Input:
3374 # - local_gnulib_dir  from --local-dir
3375 # - modcache          true or false, from --cache-modules/--no-cache-modules
3376 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
3377 func_emit_autoconf_snippets ()
3378 {
3379   verifier="$2"
3380   toplevel="$3"
3381   disable_libtool="$4"
3382   disable_gettext="$5"
3383   for module in $1; do
3384     eval $verifier # one of func_verify_module, func_verify_nontests_module, func_verify_tests_module.
3385     if test -n "$module"; then
3386       if { case $module in
3387              gnumakefile | maintainer-makefile)
3388                # These modules are meant to be used only in the top-level directory.
3389                $toplevel ;;
3390              *)
3391                true ;;
3392            esac
3393          }; then
3394         func_get_autoconf_snippet "$module" \
3395           | sed -e '/^$/d;' -e 's/^/  /' \
3396                 -e "$sed_replace_build_aux" \
3397           | { if $disable_libtool; then
3398                 sed -e 's/\$gl_cond_libtool/false/g' \
3399                     -e 's/gl_libdeps/gltests_libdeps/g' \
3400                     -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3401               else
3402                 cat
3403               fi
3404             } \
3405           | { if $disable_gettext; then
3406                 sed -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
3407               else
3408                 cat
3409               fi
3410             }
3411         if test "$module" = 'alloca' && test "$libtool" = true && ! $disable_libtool; then
3412           echo 'changequote(,)dnl'
3413           echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3414           echo 'changequote([, ])dnl'
3415           echo 'AC_SUBST([LTALLOCA])'
3416         fi
3417       fi
3418     fi
3419   done
3420 }
3421
3422 # func_import modules
3423 # Uses also the variables
3424 # - mode            import or add-import or remove-import or update
3425 # - destdir         target directory
3426 # - local_gnulib_dir  from --local-dir
3427 # - modcache        true or false, from --cache-modules/--no-cache-modules
3428 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
3429 # - libname         library name
3430 # - supplied_libname  true if --lib was given, blank otherwise
3431 # - sourcebase      directory relative to destdir where to place source code
3432 # - m4base          directory relative to destdir where to place *.m4 macros
3433 # - pobase          directory relative to destdir where to place *.po files
3434 # - docbase         directory relative to destdir where to place doc files
3435 # - testsbase       directory relative to destdir where to place unit test code
3436 # - auxdir          directory relative to destdir where to place build aux files
3437 # - inctests        true if --with-tests was given, blank otherwise
3438 # - incobsolete     true if --with-obsolete was given, blank otherwise
3439 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
3440 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
3441 #                          otherwise
3442 # - inc_privileged_tests  true if --with-privileged-tests was given, blank
3443 #                         otherwise
3444 # - inc_unportable_tests  true if --with-unportable-tests was given, blank
3445 #                         otherwise
3446 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
3447 # - avoidlist       list of modules to avoid, from --avoid
3448 # - lgpl            yes or a number if library's license shall be LGPL,
3449 #                   blank otherwise
3450 # - makefile_name   from --makefile-name
3451 # - libtool         true if --libtool was given, false if --no-libtool was
3452 #                   given, blank otherwise
3453 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
3454 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
3455 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
3456 # - vc_files        true if --vc-files was given, false if --no-vc-files was
3457 #                   given, blank otherwise
3458 # - autoconf_minversion  minimum supported autoconf version
3459 # - doit            : if actions shall be executed, false if only to be printed
3460 # - symbolic        true if files should be symlinked, copied otherwise
3461 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
3462 #                   copied otherwise
3463 # - do_copyrights   true if copyright notices in files should be replaced,
3464 #                   blank otherwise
3465 func_import ()
3466 {
3467   # Get the cached settings.
3468   # In 'import' mode, we read them only for the purpose of knowing the old
3469   # installed file list, and don't use them as defaults.
3470   cached_local_gnulib_dir=
3471   cached_specified_modules=
3472   cached_incobsolete=
3473   cached_inc_cxx_tests=
3474   cached_inc_longrunning_tests=
3475   cached_inc_privileged_tests=
3476   cached_inc_unportable_tests=
3477   cached_inc_all_tests=
3478   cached_avoidlist=
3479   cached_sourcebase=
3480   cached_m4base=
3481   cached_pobase=
3482   cached_docbase=
3483   cached_testsbase=
3484   cached_inctests=
3485   cached_libname=
3486   cached_lgpl=
3487   cached_makefile_name=
3488   cached_libtool=
3489   cached_macro_prefix=
3490   cached_po_domain=
3491   cached_vc_files=
3492   cached_files=
3493   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
3494     cached_libtool=false
3495     my_sed_traces='
3496       s,#.*$,,
3497       s,^dnl .*$,,
3498       s, dnl .*$,,
3499       /gl_LOCAL_DIR(/ {
3500         s,^.*gl_LOCAL_DIR([[ ]*\([^]"$`\\)]*\).*$,cached_local_gnulib_dir="\1",p
3501       }
3502       /gl_MODULES(/ {
3503         ta
3504         :a
3505           s/)/)/
3506           tb
3507           N
3508           ba
3509         :b
3510         s,^.*gl_MODULES([[ ]*\([^]"$`\\)]*\).*$,cached_specified_modules="\1",p
3511       }
3512       /gl_WITH_OBSOLETE/ {
3513         s,^.*$,cached_incobsolete=true,p
3514       }
3515       /gl_WITH_CXX_TESTS/ {
3516         s,^.*$,cached_inc_cxx_tests=true,p
3517       }
3518       /gl_WITH_LONGRUNNING_TESTS/ {
3519         s,^.*$,cached_inc_longrunning_tests=true,p
3520       }
3521       /gl_WITH_PRIVILEGED_TESTS/ {
3522         s,^.*$,cached_inc_privileged_tests=true,p
3523       }
3524       /gl_WITH_UNPORTABLE_TESTS/ {
3525         s,^.*$,cached_inc_unportable_tests=true,p
3526       }
3527       /gl_WITH_ALL_TESTS/ {
3528         s,^.*$,cached_inc_all_tests=true,p
3529       }
3530       /gl_AVOID(/ {
3531         s,^.*gl_AVOID([[ ]*\([^]"$`\\)]*\).*$,cached_avoidlist="\1",p
3532       }
3533       /gl_SOURCE_BASE(/ {
3534         s,^.*gl_SOURCE_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_sourcebase="\1",p
3535       }
3536       /gl_M4_BASE(/ {
3537         s,^.*gl_M4_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_m4base="\1",p
3538       }
3539       /gl_PO_BASE(/ {
3540         s,^.*gl_PO_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_pobase="\1",p
3541       }
3542       /gl_DOC_BASE(/ {
3543         s,^.*gl_DOC_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_docbase="\1",p
3544       }
3545       /gl_TESTS_BASE(/ {
3546         s,^.*gl_TESTS_BASE([[ ]*\([^]"$`\\)]*\).*$,cached_testsbase="\1",p
3547       }
3548       /gl_WITH_TESTS/ {
3549         s,^.*$,cached_inctests=true,p
3550       }
3551       /gl_LIB(/ {
3552         s,^.*gl_LIB([[ ]*\([^]"$`\\)]*\).*$,cached_libname="\1",p
3553       }
3554       /gl_LGPL(/ {
3555         s,^.*gl_LGPL([[ ]*\([^]"$`\\)]*\).*$,cached_lgpl="\1",p
3556       }
3557       /gl_LGPL/ {
3558         s,^.*$,cached_lgpl=yes,p
3559       }
3560       /gl_MAKEFILE_NAME(/ {
3561         s,^.*gl_MAKEFILE_NAME([[ ]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
3562       }
3563       /gl_LIBTOOL/ {
3564         s,^.*$,cached_libtool=true,p
3565       }
3566       /gl_MACRO_PREFIX(/ {
3567         s,^.*gl_MACRO_PREFIX([[ ]*\([^]"$`\\)]*\).*$,cached_macro_prefix="\1",p
3568       }
3569       /gl_PO_DOMAIN(/ {
3570         s,^.*gl_PO_DOMAIN([[ ]*\([^]"$`\\)]*\).*$,cached_po_domain="\1",p
3571       }
3572       /gl_VC_FILES(/ {
3573         s,^.*gl_VC_FILES([[ ]*\([^]"$`\\)]*\).*$,cached_vc_files="\1",p
3574       }'
3575     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
3576     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3577       my_sed_traces='
3578         s,#.*$,,
3579         s,^dnl .*$,,
3580         s, dnl .*$,,
3581         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
3582           s,^.*$,cached_files=",p
3583           n
3584           ta
3585           :a
3586           s,^\]).*$,",
3587           tb
3588           s,["$`\\],,g
3589           p
3590           n
3591           ba
3592           :b
3593           p
3594         }'
3595       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
3596     fi
3597   fi
3598
3599   if test "$mode" = import; then
3600     # In 'import' mode, the new set of specified modules overrides the cached
3601     # set of modules. Ignore the cached settings.
3602     specified_modules="$1"
3603   else
3604     # Merge the cached settings with the specified ones.
3605     # The m4base must be the same as expected from the pathname.
3606     if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
3607       func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
3608     fi
3609     # The local_gnulib_dir defaults to the cached one. Recall that the cached one
3610     # is relative to $destdir, whereas the one we use is relative to . or absolute.
3611     if test -z "$local_gnulib_dir"; then
3612       if test -n "$cached_local_gnulib_dir"; then
3613         case "$destdir" in
3614           /*)
3615             local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
3616           *)
3617             case "$cached_local_gnulib_dir" in
3618               /*)
3619                 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
3620               *)
3621                 func_relconcat "$destdir" "$cached_local_gnulib_dir"
3622                 local_gnulib_dir="$relconcat" ;;
3623             esac ;;
3624         esac
3625       fi
3626     fi
3627     case $mode in
3628       add-import)
3629         # Append the cached and the specified module names. So that
3630         # "gnulib-tool --add-import foo" means to add the module foo.
3631         specified_modules="$cached_specified_modules $1"
3632         ;;
3633       remove-import)
3634         # Take the cached module names, minus the specified module names.
3635         specified_modules=
3636         if $have_associative; then
3637           # Use an associative array, for O(N) worst-case run time.
3638           declare -A to_remove
3639           for m in $1; do
3640             eval 'to_remove[$m]=yes'
3641           done
3642           for module in $cached_specified_modules; do
3643             if eval 'test -z "${to_remove[$module]}"'; then
3644               func_append specified_modules "$module "
3645             fi
3646           done
3647         else
3648           # This loop has O(N²) worst-case run time.
3649           for module in $cached_specified_modules; do
3650             to_remove=
3651             for m in $1; do
3652               if test "$m" = "$module"; then
3653                 to_remove=yes
3654                 break
3655               fi
3656             done
3657             if test -z "$to_remove"; then
3658               func_append specified_modules "$module "
3659             fi
3660           done
3661         fi
3662         ;;
3663       update)
3664         # Take the cached module names. There are no specified module names.
3665         specified_modules="$cached_specified_modules"
3666         ;;
3667     esac
3668     # Included obsolete modules among the dependencies if specified either way.
3669     if test -z "$incobsolete"; then
3670       incobsolete="$cached_incobsolete"
3671     fi
3672     # Included special kinds of tests modules among the dependencies if specified
3673     # either way.
3674     if test -z "$inc_cxx_tests"; then
3675       inc_cxx_tests="$cached_inc_cxx_tests"
3676     fi
3677     if test -z "$inc_longrunning_tests"; then
3678       inc_longrunning_tests="$cached_inc_longrunning_tests"
3679     fi
3680     if test -z "$inc_privileged_tests"; then
3681       inc_privileged_tests="$cached_inc_privileged_tests"
3682     fi
3683     if test -z "$inc_unportable_tests"; then
3684       inc_unportable_tests="$cached_inc_unportable_tests"
3685     fi
3686     if test -z "$inc_all_tests"; then
3687       inc_all_tests="$cached_inc_all_tests"
3688     fi
3689     # Append the cached and the specified avoidlist. This is probably better
3690     # than dropping the cached one when --avoid is specified at least once.
3691     avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
3692     avoidlist=`echo $avoidlist`
3693
3694     # The sourcebase defaults to the cached one.
3695     if test -z "$sourcebase"; then
3696       sourcebase="$cached_sourcebase"
3697       if test -z "$sourcebase"; then
3698         func_fatal_error "missing --source-base option"
3699       fi
3700     fi
3701     # The pobase defaults to the cached one.
3702     if test -z "$pobase"; then
3703       pobase="$cached_pobase"
3704     fi
3705     # The docbase defaults to the cached one.
3706     if test -z "$docbase"; then
3707       docbase="$cached_docbase"
3708       if test -z "$docbase"; then
3709         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."
3710       fi
3711     fi
3712     # The testsbase defaults to the cached one.
3713     if test -z "$testsbase"; then
3714       testsbase="$cached_testsbase"
3715       if test -z "$testsbase"; then
3716         func_fatal_error "missing --tests-base option"
3717       fi
3718     fi
3719     # Require the tests if specified either way.
3720     if test -z "$inctests"; then
3721       inctests="$cached_inctests"
3722     fi
3723     # The libname defaults to the cached one.
3724     if test -z "$supplied_libname"; then
3725       libname="$cached_libname"
3726       if test -z "$libname"; then
3727         func_fatal_error "missing --lib option"
3728       fi
3729     fi
3730     # Require LGPL if specified either way.
3731     if test -z "$lgpl"; then
3732       lgpl="$cached_lgpl"
3733     fi
3734     # The makefile_name defaults to the cached one.
3735     if test -z "$makefile_name"; then
3736       makefile_name="$cached_makefile_name"
3737     fi
3738     # Use libtool if specified either way, or if guessed.
3739     if test -z "$libtool"; then
3740       if test -n "$cached_m4base"; then
3741         libtool="$cached_libtool"
3742       else
3743         libtool="$guessed_libtool"
3744       fi
3745     fi
3746     # The macro_prefix defaults to the cached one.
3747     if test -z "$macro_prefix"; then
3748       macro_prefix="$cached_macro_prefix"
3749       if test -z "$macro_prefix"; then
3750         func_fatal_error "missing --macro-prefix option"
3751       fi
3752     fi
3753     # The po_domain defaults to the cached one.
3754     if test -z "$po_domain"; then
3755       po_domain="$cached_po_domain"
3756     fi
3757     # The vc_files defaults to the cached one.
3758     if test -z "$vc_files"; then
3759       vc_files="$cached_vc_files"
3760     fi
3761   fi
3762   # --without-*-tests options are not supported here.
3763   excl_cxx_tests=
3764   excl_longrunning_tests=
3765   excl_privileged_tests=
3766   excl_unportable_tests=
3767
3768   # Canonicalize the list of specified modules.
3769   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
3770
3771   # Include all kinds of tests modules if --with-all-tests was specified.
3772   inc_all_direct_tests="$inc_all_tests"
3773   inc_all_indirect_tests="$inc_all_tests"
3774
3775   # Determine final module list.
3776   modules="$specified_modules"
3777   func_modules_transitive_closure
3778   if test $verbose -ge 0; then
3779     func_show_module_list
3780   fi
3781   final_modules="$modules"
3782
3783   # Determine main module list and tests-related module list separately.
3784   # The main module list is the transitive closure of the specified modules,
3785   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
3786   # is specified, it will consist only of LGPLed source.
3787   # The tests-related module list is the transitive closure of the specified
3788   # modules, including tests modules, minus the main module list excluding
3789   # modules of applicability 'all'. Its lib/* sources (brought in through
3790   # dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
3791   # source, even if --lgpl is specified.
3792   # Determine main module list.
3793   saved_inctests="$inctests"
3794   inctests=""
3795   modules="$specified_modules"
3796   func_modules_transitive_closure
3797   main_modules="$modules"
3798   inctests="$saved_inctests"
3799   if test $verbose -ge 1; then
3800     echo "Main module list:"
3801     echo "$main_modules" | sed -e 's/^/  /'
3802   fi
3803   # Determine tests-related module list.
3804   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
3805   testsrelated_modules=`for module in $main_modules; do
3806                           if test \`func_get_applicability $module\` = main; then
3807                             echo $module
3808                           fi
3809                         done \
3810                         | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
3811   if test $verbose -ge 1; then
3812     echo "Tests-related module list:"
3813     echo "$testsrelated_modules" | sed -e 's/^/  /'
3814   fi
3815
3816   # Add the dummy module to the main module list if needed.
3817   modules="$main_modules"
3818   func_modules_add_dummy
3819   main_modules="$modules"
3820
3821   # Determine whether a $testsbase/libtests.a is needed.
3822   use_libtests=false
3823   for module in $testsrelated_modules; do
3824     func_verify_nontests_module
3825     if test -n "$module"; then
3826       all_files=`func_get_filelist $module`
3827       # Test whether some file in $all_files lies in lib/.
3828       for f in $all_files; do
3829         case $f in
3830           lib/*)
3831             use_libtests=true
3832             break 2
3833             ;;
3834         esac
3835       done
3836     fi
3837   done
3838
3839   # Add the dummy module to the tests-related module list if needed.
3840   if $use_libtests; then
3841     modules="$testsrelated_modules"
3842     func_modules_add_dummy
3843     testsrelated_modules="$modules"
3844   fi
3845
3846   # If --lgpl, verify that the licenses of modules are compatible.
3847   if test -n "$lgpl"; then
3848     license_incompatibilities=
3849     for module in $main_modules; do
3850       license=`func_get_license $module`
3851       case $license in
3852         'GPLed build tool') ;;
3853         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3854         *)
3855           case "$lgpl" in
3856             yes | 3)
3857               case $license in
3858                 LGPL | LGPLv2+ | LGPLv3+) ;;
3859                 *) func_append license_incompatibilities "$module $license$nl" ;;
3860               esac
3861               ;;
3862             2)
3863               case $license in
3864                 LGPLv2+) ;;
3865                 *) func_append license_incompatibilities "$module $license$nl" ;;
3866               esac
3867               ;;
3868             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
3869           esac
3870           ;;
3871       esac
3872     done
3873     if test -n "$license_incompatibilities"; then
3874       # Format the license incompatibilities as a table.
3875       sed_expand_column1_width50_indent17='s,^\([^ ]*\) ,\1                                                   ,
3876 s,^\(.................................................[^ ]*\) *,                 \1 ,'
3877       license_incompatibilities=`echo "$license_incompatibilities" | sed -e "$sed_expand_column1_width50_indent17"`
3878       func_fatal_error "incompatible license on modules:$nl$license_incompatibilities"
3879     fi
3880   fi
3881
3882   # Show banner notice of every module.
3883   modules="$main_modules"
3884   func_modules_notice
3885
3886   # Determine script to apply to imported library files.
3887   sed_transform_lib_file=
3888   for module in $main_modules; do
3889     if test $module = config-h; then
3890       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
3891       sed_transform_lib_file=$sed_transform_lib_file'
3892         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
3893       '
3894       break
3895     fi
3896   done
3897   sed_transform_main_lib_file="$sed_transform_lib_file"
3898   if test -n "$do_copyrights"; then
3899     if test -n "$lgpl"; then
3900       # Update license.
3901       case "$lgpl" in
3902         yes | 3)
3903           sed_transform_main_lib_file=$sed_transform_main_lib_file'
3904             s/GNU General/GNU Lesser General/g
3905             s/General Public License/Lesser General Public License/g
3906             s/Lesser Lesser General Public License/Lesser General Public License/g
3907           '
3908           ;;
3909         2)
3910           sed_transform_main_lib_file=$sed_transform_main_lib_file'
3911             s/GNU General/GNU Lesser General/g
3912             s/General Public License/Lesser General Public License/g
3913             s/Lesser Lesser General Public License/Lesser General Public License/g
3914
3915             s/version [23]\([ ,]\)/version 2.1\1/g
3916           '
3917           ;;
3918         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
3919       esac
3920     else
3921       # Update license.
3922       sed_transform_main_lib_file=$sed_transform_main_lib_file'
3923         s/GNU Lesser General/GNU General/g
3924         s/Lesser General Public License/General Public License/g
3925
3926         s/GNU Library General/GNU General/g
3927         s/Library General Public License/General Public License/g
3928
3929         s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3930       '
3931     fi
3932   fi
3933
3934   # Determine script to apply to auxiliary files that go into $auxdir/.
3935   sed_transform_build_aux_file=
3936   if test -n "$do_copyrights"; then
3937     # Update license.
3938     sed_transform_build_aux_file=$sed_transform_build_aux_file'
3939       s/GNU Lesser General/GNU General/g
3940       s/Lesser General Public License/General Public License/g
3941
3942       s/GNU Library General/GNU General/g
3943       s/Library General Public License/General Public License/g
3944
3945       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3946     '
3947   fi
3948
3949   # Determine script to apply to library files that go into $testsbase/.
3950   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
3951   if test -n "$do_copyrights"; then
3952     # Update license.
3953     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
3954       s/GNU Lesser General/GNU General/g
3955       s/Lesser General Public License/General Public License/g
3956
3957       s/GNU Library General/GNU General/g
3958       s/Library General Public License/General Public License/g
3959
3960       s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
3961     '
3962   fi
3963
3964   # Determine the final file lists.
3965   # They must be computed separately, because files in lib/* go into
3966   # $sourcebase/ if they are in the main file list but into $testsbase/
3967   # if they are in the tests-related file list. Furthermore lib/dummy.c
3968   # can be in both.
3969   # Determine final main file list.
3970   modules="$main_modules"
3971   func_modules_to_filelist
3972   main_files="$files"
3973   # Determine final tests-related file list.
3974   modules="$testsrelated_modules"
3975   func_modules_to_filelist
3976   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
3977   # Merge both file lists.
3978   sed_remove_empty_lines='/^$/d'
3979   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
3980   if test $verbose -ge 0; then
3981     echo "File list:"
3982     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
3983     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
3984   fi
3985
3986   test -n "$files" \
3987     || func_fatal_error "refusing to do nothing"
3988
3989   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
3990   new_files="$files m4/gnulib-tool.m4"
3991   old_files="$cached_files"
3992   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
3993     func_append old_files " m4/gnulib-tool.m4"
3994   fi
3995
3996   rewritten='%REWRITTEN%'
3997   sed_rewrite_old_files="\
3998     s,^build-aux/,$rewritten$auxdir/,
3999     s,^doc/,$rewritten$cached_docbase/,
4000     s,^lib/,$rewritten$cached_sourcebase/,
4001     s,^m4/,$rewritten$cached_m4base/,
4002     s,^tests/,$rewritten$cached_testsbase/,
4003     s,^tests=lib/,$rewritten$cached_testsbase/,
4004     s,^top/,$rewritten,
4005     s,^$rewritten,,"
4006   sed_rewrite_new_files="\
4007     s,^build-aux/,$rewritten$auxdir/,
4008     s,^doc/,$rewritten$docbase/,
4009     s,^lib/,$rewritten$sourcebase/,
4010     s,^m4/,$rewritten$m4base/,
4011     s,^tests/,$rewritten$testsbase/,
4012     s,^tests=lib/,$rewritten$testsbase/,
4013     s,^top/,$rewritten,
4014     s,^$rewritten,,"
4015
4016   # Create directories.
4017   { echo "$sourcebase"
4018     echo "$m4base"
4019     if test -n "$pobase"; then
4020       echo "$pobase"
4021     fi
4022     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
4023     if test -n "$docfiles"; then
4024       echo "$docbase"
4025     fi
4026     if test -n "$inctests"; then
4027       echo "$testsbase"
4028     fi
4029     echo "$auxdir"
4030     for f in $files; do echo $f; done \
4031       | sed -e "$sed_rewrite_new_files" \
4032       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
4033       | LC_ALL=C sort -u
4034   } > "$tmp"/dirs
4035   { # Rearrange file descriptors. Needed because "while ... done < ..."
4036     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4037     exec 5<&0 < "$tmp"/dirs
4038     while read d; do
4039       if test ! -d "$destdir/$d"; then
4040         if $doit; then
4041           echo "Creating directory $destdir/$d"
4042           mkdir -p "$destdir/$d" || func_fatal_error "failed"
4043         else
4044           echo "Create directory $destdir/$d"
4045         fi
4046       fi
4047     done
4048     exec 0<&5 5<&-
4049   }
4050
4051   # Copy files or make symbolic links. Remove obsolete files.
4052   added_files=''
4053   removed_files=''
4054   delimiter='   '
4055   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4056   # representing the files according to the last gnulib-tool invocation.
4057   for f in $old_files; do echo $f; done \
4058     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
4059     | LC_ALL=C sort \
4060     > "$tmp"/old-files
4061   # Construct a table with 2 columns: rewritten-file-name original-file-name,
4062   # representing the files after this gnulib-tool invocation.
4063   for f in $new_files; do echo $f; done \
4064     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
4065     | LC_ALL=C sort \
4066     > "$tmp"/new-files
4067   # First the files that are in old-files, but not in new-files:
4068   sed_take_first_column='s,'"$delimiter"'.*,,'
4069   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
4070     # Remove the file. Do nothing if the user already removed it.
4071     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
4072       if $doit; then
4073         echo "Removing file $g (backup in ${g}~)"
4074         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
4075       else
4076         echo "Remove file $g (backup in ${g}~)"
4077       fi
4078       func_append removed_files "$g$nl"
4079     fi
4080   done
4081   # func_add_or_update handles a file that ought to be present afterwards.
4082   # Uses parameters
4083   # - f             the original file name
4084   # - g             the rewritten file name
4085   # - already_present  nonempty if the file should already exist, empty
4086   #                    otherwise
4087   func_add_or_update ()
4088   {
4089     of="$f"
4090     case "$f" in
4091       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
4092     esac
4093     func_dest_tmpfilename "$g"
4094     func_lookup_file "$f"
4095     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
4096     if test -n "$sed_transform_main_lib_file"; then
4097       case "$of" in
4098         lib/*)
4099           sed -e "$sed_transform_main_lib_file" \
4100             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4101           ;;
4102       esac
4103     fi
4104     if test -n "$sed_transform_build_aux_file"; then
4105       case "$of" in
4106         build-aux/*)
4107           sed -e "$sed_transform_build_aux_file" \
4108             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4109           ;;
4110       esac
4111     fi
4112     if test -n "$sed_transform_testsrelated_lib_file"; then
4113       case "$of" in
4114         tests=lib/*)
4115           sed -e "$sed_transform_testsrelated_lib_file" \
4116             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
4117           ;;
4118       esac
4119     fi
4120     if test -f "$destdir/$g"; then
4121       # The file already exists.
4122       func_update_file
4123     else
4124       # Install the file.
4125       # Don't protest if the file should be there but isn't: it happens
4126       # frequently that developers don't put autogenerated files under version control.
4127       func_add_file
4128       func_append added_files "$g$nl"
4129     fi
4130     rm -f "$tmpfile"
4131   }
4132   # Then the files that are in new-files, but not in old-files:
4133   sed_take_last_column='s,^.*'"$delimiter"',,'
4134   already_present=
4135   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
4136     | sed -e "$sed_take_last_column" \
4137     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
4138   { # Rearrange file descriptors. Needed because "while ... done < ..."
4139     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4140     exec 5<&0 < "$tmp"/added-files
4141     while read g f; do
4142       func_add_or_update
4143     done
4144     exec 0<&5 5<&-
4145   }
4146   # Then the files that are in new-files and in old-files:
4147   already_present=true
4148   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
4149     | sed -e "$sed_take_last_column" \
4150     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
4151   { # Rearrange file descriptors. Needed because "while ... done < ..."
4152     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4153     exec 5<&0 < "$tmp"/kept-files
4154     while read g f; do
4155       func_add_or_update
4156     done
4157     exec 0<&5 5<&-
4158   }
4159
4160   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
4161   actioncmd="gnulib-tool --import"
4162   func_append actioncmd " --dir=$destdir"
4163   if test -n "$local_gnulib_dir"; then
4164     func_append actioncmd " --local-dir=$local_gnulib_dir"
4165   fi
4166   func_append actioncmd " --lib=$libname"
4167   func_append actioncmd " --source-base=$sourcebase"
4168   func_append actioncmd " --m4-base=$m4base"
4169   if test -n "$pobase"; then
4170     func_append actioncmd " --po-base=$pobase"
4171   fi
4172   func_append actioncmd " --doc-base=$docbase"
4173   func_append actioncmd " --tests-base=$testsbase"
4174   func_append actioncmd " --aux-dir=$auxdir"
4175   if test -n "$inctests"; then
4176     func_append actioncmd " --with-tests"
4177   fi
4178   if test -n "$incobsolete"; then
4179     func_append actioncmd " --with-obsolete"
4180   fi
4181   if test -n "$inc_cxx_tests"; then
4182     func_append actioncmd " --with-c++-tests"
4183   fi
4184   if test -n "$inc_longrunning_tests"; then
4185     func_append actioncmd " --with-longrunning-tests"
4186   fi
4187   if test -n "$inc_privileged_tests"; then
4188     func_append actioncmd " --with-privileged-tests"
4189   fi
4190   if test -n "$inc_unportable_tests"; then
4191     func_append actioncmd " --with-unportable-tests"
4192   fi
4193   if test -n "$inc_all_tests"; then
4194     func_append actioncmd " --with-all-tests"
4195   fi
4196   for module in $avoidlist; do
4197     func_append actioncmd " --avoid=$module"
4198   done
4199   if test -n "$lgpl"; then
4200     if test "$lgpl" = yes; then
4201       func_append actioncmd " --lgpl"
4202     else
4203       func_append actioncmd " --lgpl=$lgpl"
4204     fi
4205   fi
4206   if test -n "$makefile_name"; then
4207     func_append actioncmd " --makefile-name=$makefile_name"
4208   fi
4209   if test "$libtool" = true; then
4210     func_append actioncmd " --libtool"
4211   else
4212     func_append actioncmd " --no-libtool"
4213   fi
4214   func_append actioncmd " --macro-prefix=$macro_prefix"
4215   if test -n "$po_domain"; then
4216     func_append actioncmd " --po-domain=$po_domain"
4217   fi
4218   if test -n "$vc_files"; then
4219     if test "$vc_files" = true; then
4220       func_append actioncmd " --vc-files"
4221     else
4222       func_append actioncmd " --no-vc-files"
4223     fi
4224   fi
4225   func_append actioncmd " `echo $specified_modules`"
4226
4227   # Default the makefile name to Makefile.am.
4228   if test -n "$makefile_name"; then
4229     makefile_am=$makefile_name
4230   else
4231     makefile_am=Makefile.am
4232   fi
4233
4234   # Create normal Makefile.ams.
4235   for_test=false
4236
4237   # Setup list of Makefile.am edits that are to be performed afterwards.
4238   # Some of these edits apply to files that we will generate; others are
4239   # under the responsibility of the developer.
4240   makefile_am_edits=0
4241   # func_note_Makefile_am_edit dir var value
4242   # remembers that ${dir}Makefile.am needs to be edited to that ${var} mentions
4243   # ${value}.
4244   func_note_Makefile_am_edit ()
4245   {
4246     makefile_am_edits=`expr $makefile_am_edits + 1`
4247     eval makefile_am_edit${makefile_am_edits}_dir=\"\$1\"
4248     eval makefile_am_edit${makefile_am_edits}_var=\"\$2\"
4249     eval makefile_am_edit${makefile_am_edits}_val=\"\$3\"
4250   }
4251   if test "$makefile_am" = Makefile.am; then
4252     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
4253     sourcebase_base=`basename "$sourcebase"`
4254     func_note_Makefile_am_edit "$sourcebase_dir" SUBDIRS "$sourcebase_base"
4255   fi
4256   if test -n "$pobase"; then
4257     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
4258     pobase_base=`basename "$pobase"`
4259     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
4260   fi
4261   if test -n "$inctests"; then
4262     if test "$makefile_am" = Makefile.am; then
4263       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
4264       testsbase_base=`basename "$testsbase"`
4265       func_note_Makefile_am_edit "$testsbase_dir" SUBDIRS "$testsbase_base"
4266     fi
4267   fi
4268   func_note_Makefile_am_edit "" ACLOCAL_AMFLAGS "-I ${m4base}"
4269   {
4270     # Find the first parent directory of $m4base that contains or will contain
4271     # a Makefile.am.
4272     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
4273 s,//*$,/,'
4274     sed_butlast='s,[^/][^/]*//*$,,'
4275     dir1="${m4base}/"; dir2=""
4276     while test -n "$dir1" \
4277           && ! { test -f "${destdir}/${dir1}Makefile.am" \
4278                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4279                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
4280                  || { test -n "$inctests" \
4281                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
4282                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
4283       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
4284       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
4285     done
4286     func_note_Makefile_am_edit "$dir1" EXTRA_DIST "${dir2}gnulib-cache.m4"
4287   }
4288
4289   # Create library makefile.
4290   func_dest_tmpfilename $sourcebase/$makefile_am
4291   destfile="$sourcebase/$makefile_am"
4292   modules="$main_modules"
4293   func_emit_lib_Makefile_am > "$tmpfile"
4294   if test -f "$destdir"/$sourcebase/$makefile_am; then
4295     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
4296       rm -f "$tmpfile"
4297     else
4298       if $doit; then
4299         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4300         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
4301         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4302       else
4303         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
4304         rm -f "$tmpfile"
4305       fi
4306     fi
4307   else
4308     if $doit; then
4309       echo "Creating $sourcebase/$makefile_am"
4310       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
4311     else
4312       echo "Create $sourcebase/$makefile_am"
4313       rm -f "$tmpfile"
4314     fi
4315     func_append added_files "$sourcebase/$makefile_am$nl"
4316   fi
4317
4318   # Create po/ directory.
4319   if test -n "$pobase"; then
4320     # Create po makefile and auxiliary files.
4321     for file in Makefile.in.in remove-potcdate.sin; do
4322       func_dest_tmpfilename $pobase/$file
4323       func_lookup_file build-aux/po/$file
4324       cat "$lookedup_file" > "$tmpfile"
4325       if test -f "$destdir"/$pobase/$file; then
4326         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
4327           rm -f "$tmpfile"
4328         else
4329           if $doit; then
4330             echo "Updating $pobase/$file (backup in $pobase/$file~)"
4331             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
4332             mv -f "$tmpfile" "$destdir"/$pobase/$file
4333           else
4334             echo "Update $pobase/$file (backup in $pobase/$file~)"
4335             rm -f "$tmpfile"
4336           fi
4337         fi
4338       else
4339         if $doit; then
4340           echo "Creating $pobase/$file"
4341           mv -f "$tmpfile" "$destdir"/$pobase/$file
4342         else
4343           echo "Create $pobase/$file"
4344           rm -f "$tmpfile"
4345         fi
4346         func_append added_files "$pobase/$file$nl"
4347       fi
4348     done
4349     # Create po makefile parameterization, part 1.
4350     func_dest_tmpfilename $pobase/Makevars
4351     func_emit_po_Makevars > "$tmpfile"
4352     if test -f "$destdir"/$pobase/Makevars; then
4353       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
4354         rm -f "$tmpfile"
4355       else
4356         if $doit; then
4357           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
4358           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
4359           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4360         else
4361           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
4362           rm -f "$tmpfile"
4363         fi
4364       fi
4365     else
4366       if $doit; then
4367         echo "Creating $pobase/Makevars"
4368         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
4369       else
4370         echo "Create $pobase/Makevars"
4371         rm -f "$tmpfile"
4372       fi
4373       func_append added_files "$pobase/Makevars$nl"
4374     fi
4375     # Create po makefile parameterization, part 2.
4376     func_dest_tmpfilename $pobase/POTFILES.in
4377     func_emit_po_POTFILES_in > "$tmpfile"
4378     if test -f "$destdir"/$pobase/POTFILES.in; then
4379       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
4380         rm -f "$tmpfile"
4381       else
4382         if $doit; then
4383           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
4384           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
4385           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
4386         else
4387           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
4388           rm -f "$tmpfile"
4389         fi
4390       fi
4391     else
4392       if $doit; then
4393         echo "Creating $pobase/POTFILES.in"
4394         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
4395       else
4396         echo "Create $pobase/POTFILES.in"
4397         rm -f "$tmpfile"
4398       fi
4399       func_append added_files "$pobase/POTFILES.in$nl"
4400     fi
4401     # Fetch PO files.
4402     TP_URL="http://translationproject.org/latest/"
4403     TP_RSYNC_URI="translationproject.org::tp/latest/"
4404     if $doit; then
4405       echo "Fetching gnulib PO files from $TP_URL"
4406       (cd "$destdir"/$pobase \
4407        && { # Prefer rsync over wget if it is available, since it consumes
4408             # less network bandwidth, due to compression.
4409             if type rsync 2>/dev/null | grep / > /dev/null; then
4410               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
4411             else
4412               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
4413             fi
4414           }
4415       )
4416     else
4417       echo "Fetch gnulib PO files from $TP_URL"
4418     fi
4419     # Create po/LINGUAS.
4420     if $doit; then
4421       func_dest_tmpfilename $pobase/LINGUAS
4422       (cd "$destdir"/$pobase \
4423        && { echo '# Set of available languages.'
4424             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
4425           }
4426       ) > "$tmpfile"
4427       if test -f "$destdir"/$pobase/LINGUAS; then
4428         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
4429           rm -f "$tmpfile"
4430         else
4431           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
4432           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
4433           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
4434         fi
4435       else
4436         echo "Creating $pobase/LINGUAS"
4437         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
4438         func_append added_files "$pobase/LINGUAS$nl"
4439       fi
4440     else
4441       if test -f "$destdir"/$pobase/LINGUAS; then
4442         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
4443       else
4444         echo "Create $pobase/LINGUAS"
4445       fi
4446     fi
4447   fi
4448
4449   # Create m4/gnulib-cache.m4.
4450   func_dest_tmpfilename $m4base/gnulib-cache.m4
4451   (
4452     func_emit_copyright_notice
4453     echo "#"
4454     echo "# This file represents the specification of how gnulib-tool is used."
4455     echo "# It acts as a cache: It is written and read by gnulib-tool."
4456     echo "# In projects that use version control, this file is meant to be put under"
4457     echo "# version control, like the configure.ac and various Makefile.am files."
4458     echo
4459     echo
4460     echo "# Specification in the form of a command-line invocation:"
4461     echo "#   $actioncmd"
4462     echo
4463     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
4464     # Store the local_gnulib_dir relative to destdir.
4465     case "$local_gnulib_dir" in
4466       "" | /*)
4467         relative_local_gnulib_dir="$local_gnulib_dir" ;;
4468       * )
4469         case "$destdir" in
4470           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
4471           *)
4472             # destdir, local_gnulib_dir are both relative.
4473             func_relativize "$destdir" "$local_gnulib_dir"
4474             relative_local_gnulib_dir="$reldir" ;;
4475         esac ;;
4476     esac
4477     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
4478     echo "gl_MODULES(["
4479     echo "$specified_modules" | sed -e 's/^/  /g'
4480     echo "])"
4481     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
4482     test -z "$inc_cxx_tests" || echo "gl_WITH_CXX_TESTS"
4483     test -z "$inc_longrunning_tests" || echo "gl_WITH_LONGRUNNING_TESTS"
4484     test -z "$inc_privileged_tests" || echo "gl_WITH_PRIVILEGED_TESTS"
4485     test -z "$inc_unportable_tests" || echo "gl_WITH_UNPORTABLE_TESTS"
4486     test -z "$inc_all_tests" || echo "gl_WITH_ALL_TESTS"
4487     echo "gl_AVOID([$avoidlist])"
4488     echo "gl_SOURCE_BASE([$sourcebase])"
4489     echo "gl_M4_BASE([$m4base])"
4490     echo "gl_PO_BASE([$pobase])"
4491     echo "gl_DOC_BASE([$docbase])"
4492     echo "gl_TESTS_BASE([$testsbase])"
4493     test -z "$inctests" || echo "gl_WITH_TESTS"
4494     echo "gl_LIB([$libname])"
4495     if test -n "$lgpl"; then
4496       if test "$lgpl" = yes; then
4497         echo "gl_LGPL"
4498       else
4499         echo "gl_LGPL([$lgpl])"
4500       fi
4501     fi
4502     echo "gl_MAKEFILE_NAME([$makefile_name])"
4503     if test "$libtool" = true; then
4504       echo "gl_LIBTOOL"
4505     fi
4506     echo "gl_MACRO_PREFIX([$macro_prefix])"
4507     echo "gl_PO_DOMAIN([$po_domain])"
4508     if test -n "$vc_files"; then
4509       echo "gl_VC_FILES([$vc_files])"
4510     fi
4511   ) > "$tmpfile"
4512   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
4513     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
4514       rm -f "$tmpfile"
4515     else
4516       if $doit; then
4517         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
4518         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
4519         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
4520       else
4521         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
4522         if false; then
4523           cat "$tmpfile"
4524           echo
4525           echo "# gnulib-cache.m4 ends here"
4526         fi
4527         rm -f "$tmpfile"
4528       fi
4529     fi
4530   else
4531     if $doit; then
4532       echo "Creating $m4base/gnulib-cache.m4"
4533       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
4534     else
4535       echo "Create $m4base/gnulib-cache.m4"
4536       cat "$tmpfile"
4537       rm -f "$tmpfile"
4538     fi
4539   fi
4540
4541   # Create m4/gnulib-comp.m4.
4542   func_dest_tmpfilename $m4base/gnulib-comp.m4
4543   (
4544     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
4545     func_emit_copyright_notice
4546     echo "#"
4547     echo "# This file represents the compiled summary of the specification in"
4548     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
4549     echo "# to be invoked from configure.ac."
4550     echo "# In projects that use version control, this file can be treated like"
4551     echo "# other built files."
4552     echo
4553     echo
4554     echo "# This macro should be invoked from $configure_ac, in the section"
4555     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
4556     echo "# any checks for libraries, header files, types and library functions."
4557     echo "AC_DEFUN([${macro_prefix}_EARLY],"
4558     echo "["
4559     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
4560     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
4561     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
4562     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
4563     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
4564     if test -n "$uses_subdirs"; then
4565       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
4566     fi
4567     for module in $final_modules; do
4568       func_verify_module
4569       if test -n "$module"; then
4570         echo "# Code from module $module:"
4571         func_get_autoconf_early_snippet "$module"
4572       fi
4573     done \
4574       | sed -e '/^$/d;' -e 's/^/  /'
4575     echo "])"
4576     echo
4577     echo "# This macro should be invoked from $configure_ac, in the section"
4578     echo "# \"Check for header files, types and library functions\"."
4579     echo "AC_DEFUN([${macro_prefix}_INIT],"
4580     echo "["
4581     if test "$libtool" = true; then
4582       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
4583       echo "  gl_cond_libtool=true"
4584     else
4585       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
4586       echo "  gl_cond_libtool=false"
4587       echo "  gl_libdeps="
4588       echo "  gl_ltlibdeps="
4589     fi
4590     if test "$auxdir" != "build-aux"; then
4591       sed_replace_build_aux='
4592         :a
4593         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
4594           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
4595           ba
4596         }'
4597     else
4598       sed_replace_build_aux="$sed_noop"
4599     fi
4600     echo "  gl_m4_base='$m4base'"
4601     func_emit_initmacro_start $macro_prefix
4602     echo "  gl_source_base='$sourcebase'"
4603     func_emit_autoconf_snippets "$main_modules" func_verify_module true false true
4604     echo "  # End of code from modules"
4605     func_emit_initmacro_end $macro_prefix
4606     echo "  gltests_libdeps="
4607     echo "  gltests_ltlibdeps="
4608     func_emit_initmacro_start ${macro_prefix}tests
4609     echo "  gl_source_base='$testsbase'"
4610     # Define a tests witness macro that depends on the package.
4611     # PACKAGE is defined by AM_INIT_AUTOMAKE, PACKAGE_TARNAME is defined by AC_INIT.
4612     # See <http://lists.gnu.org/archive/html/automake/2009-05/msg00145.html>.
4613     echo "changequote(,)dnl"
4614     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"
4615     echo "changequote([, ])dnl"
4616     echo "  AC_SUBST([${macro_prefix}tests_WITNESS])"
4617     echo "  gl_module_indicator_condition=\$${macro_prefix}tests_WITNESS"
4618     echo "  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [\$gl_module_indicator_condition])"
4619     func_emit_autoconf_snippets "$testsrelated_modules" func_verify_module true true true
4620     echo "  m4_popdef([gl_MODULE_INDICATOR_CONDITION])"
4621     func_emit_initmacro_end ${macro_prefix}tests
4622     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
4623     # created using libtool, because libtool already handles the dependencies.
4624     if test "$libtool" != true; then
4625       libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
4626       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
4627       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
4628       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
4629       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
4630     fi
4631     if $use_libtests; then
4632       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
4633       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
4634     fi
4635     echo "])"
4636     func_emit_initmacro_done $macro_prefix $sourcebase
4637     func_emit_initmacro_done ${macro_prefix}tests $testsbase
4638     echo
4639     echo "# This macro records the list of files which have been installed by"
4640     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
4641     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
4642     echo "$files" | sed -e 's,^,  ,'
4643     echo "])"
4644   ) > "$tmpfile"
4645   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
4646     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
4647       rm -f "$tmpfile"
4648     else
4649       if $doit; then
4650         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
4651         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
4652         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
4653       else
4654         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
4655         if false; then
4656           cat "$tmpfile"
4657           echo
4658           echo "# gnulib-comp.m4 ends here"
4659         fi
4660         rm -f "$tmpfile"
4661       fi
4662     fi
4663   else
4664     if $doit; then
4665       echo "Creating $m4base/gnulib-comp.m4"
4666       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
4667     else
4668       echo "Create $m4base/gnulib-comp.m4"
4669       cat "$tmpfile"
4670       rm -f "$tmpfile"
4671     fi
4672   fi
4673
4674   if test -n "$inctests"; then
4675     # Create tests makefile.
4676     func_dest_tmpfilename $testsbase/$makefile_am
4677     destfile="$testsbase/$makefile_am"
4678     modules="$testsrelated_modules"
4679     func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
4680     if test -f "$destdir"/$testsbase/$makefile_am; then
4681       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
4682         rm -f "$tmpfile"
4683       else
4684         if $doit; then
4685           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
4686           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
4687           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
4688         else
4689           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
4690           rm -f "$tmpfile"
4691         fi
4692       fi
4693     else
4694       if $doit; then
4695         echo "Creating $testsbase/$makefile_am"
4696         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
4697       else
4698         echo "Create $testsbase/$makefile_am"
4699         rm -f "$tmpfile"
4700       fi
4701     func_append added_files "$testsbase/$makefile_am$nl"
4702     fi
4703   fi
4704
4705   if test "$vc_files" != false; then
4706     # Update the .cvsignore and .gitignore files.
4707     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
4708       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
4709       # Treat gnulib-comp.m4 like an added file, even if it already existed.
4710       echo "$m4base/|A|gnulib-comp.m4"
4711     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
4712     { # Rearrange file descriptors. Needed because "while ... done < ..."
4713       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
4714       exec 5<&0 < "$tmp"/fileset-changes
4715       func_update_ignorelist ()
4716       {
4717         ignore="$1"
4718         if test "$ignore" = .gitignore; then
4719           # In a .gitignore file, "foo" applies to the current directory and all
4720           # subdirectories, whereas "/foo" applies to the current directory only.
4721           anchor='/'
4722           escaped_anchor='\/'
4723           doubly_escaped_anchor='\\/'
4724         else
4725           anchor=''
4726           escaped_anchor=''
4727           doubly_escaped_anchor=''
4728         fi
4729         if test -f "$destdir/$dir$ignore"; then
4730           if test -n "$dir_added" || test -n "$dir_removed"; then
4731             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
4732             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
4733                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
4734              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
4735                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-removed
4736             )
4737             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
4738               if $doit; then
4739                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
4740                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
4741                 { sed -e 's,/,\\/,g' -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
4742                   if test -n "$anchor"; then sed -e 's,/,\\/,g' -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,$/d,' < "$tmp"/ignore-removed; fi
4743                 } > "$tmp"/sed-ignore-removed
4744                 { cat "$destdir/$dir$ignore"~
4745                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
4746                 } | sed -f "$tmp"/sed-ignore-removed \
4747                   > "$destdir/$dir$ignore"
4748               else
4749                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
4750               fi
4751             fi
4752           fi
4753         else
4754           if test -n "$dir_added"; then
4755             if $doit; then
4756               echo "Creating $destdir/$dir$ignore"
4757               {
4758                 if test "$ignore" = .cvsignore; then
4759                   echo ".deps"
4760                   # Automake generates Makefile rules that create .dirstamp files.
4761                   echo ".dirstamp"
4762                 fi
4763                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
4764               } > "$destdir/$dir$ignore"
4765             else
4766               echo "Create $destdir/$dir$ignore"
4767             fi
4768           fi
4769         fi
4770       }
4771       func_done_dir ()
4772       {
4773         dir="$1"
4774         dir_added="$2"
4775         dir_removed="$3"
4776         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
4777           func_update_ignorelist .cvsignore
4778         fi
4779         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
4780           func_update_ignorelist .gitignore
4781         fi
4782       }
4783       last_dir=
4784       last_dir_added=
4785       last_dir_removed=
4786       while read line; do
4787         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
4788         next_dir=`echo "$line" | sed -e 's,|.*,,'`
4789         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
4790         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
4791         if test "$next_dir" != "$last_dir"; then
4792           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
4793           last_dir="$next_dir"
4794           last_dir_added=
4795           last_dir_removed=
4796         fi
4797         case $op in
4798           A) func_append last_dir_added "$file$nl";;
4799           R) func_append last_dir_removed "$file$nl";;
4800         esac
4801       done
4802       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
4803       exec 0<&5 5<&-
4804     }
4805   fi
4806
4807   echo "Finished."
4808   echo
4809   echo "You may need to add #include directives for the following .h files."
4810   # Intersect $specified_modules and $main_modules
4811   # (since $specified_modules is not necessarily of subset of $main_modules
4812   # - some may have been skipped through --avoid, and since the elements of
4813   # $main_modules but not in $specified_modules can go away without explicit
4814   # notice - through changes in the module dependencies).
4815   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
4816   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
4817   # First the #include <...> directives without #ifs, sorted for convenience,
4818   # then the #include "..." directives without #ifs, sorted for convenience,
4819   # then the #include directives that are surrounded by #ifs. Not sorted.
4820   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
4821     include_directive=`func_get_include_directive "$module"`
4822     case "$nl$include_directive" in
4823       *"$nl#if"*)
4824         echo "$include_directive" 1>&5
4825         ;;
4826       *)
4827         echo "$include_directive" | grep -v 'include "' 1>&6
4828         echo "$include_directive" | grep 'include "' 1>&7
4829         ;;
4830     esac
4831   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
4832   (
4833    LC_ALL=C sort -u "$tmp"/include-angles
4834    LC_ALL=C sort -u "$tmp"/include-quotes
4835    cat "$tmp"/include-if
4836   ) | sed -e '/^$/d' -e 's/^/  /'
4837   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
4838
4839   for module in $main_modules; do
4840     func_get_link_directive "$module"
4841   done \
4842     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
4843   if test `wc -l < "$tmp"/link` != 0; then
4844     echo
4845     echo "You may need to use the following Makefile variables when linking."
4846     echo "Use them in <program>_LDADD when linking a program, or"
4847     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
4848     cat "$tmp"/link
4849   fi
4850   rm -f "$tmp"/link
4851
4852   echo
4853   echo "Don't forget to"
4854   if test "$makefile_am" = Makefile.am; then
4855     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
4856   else
4857     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
4858   fi
4859   if test -n "$pobase"; then
4860     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
4861   fi
4862   if test -n "$inctests"; then
4863     if test "$makefile_am" = Makefile.am; then
4864       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
4865     else
4866       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
4867     fi
4868   fi
4869   edit=0
4870   while test $edit != $makefile_am_edits; do
4871     edit=`expr $edit + 1`
4872     eval dir=\"\$makefile_am_edit${edit}_dir\"
4873     eval var=\"\$makefile_am_edit${edit}_var\"
4874     eval val=\"\$makefile_am_edit${edit}_val\"
4875     if test -n "$var"; then
4876       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
4877     fi
4878   done
4879   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
4880   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
4881 }
4882
4883 # func_create_testdir testdir modules
4884 # Input:
4885 # - local_gnulib_dir  from --local-dir
4886 # - modcache        true or false, from --cache-modules/--no-cache-modules
4887 # - auxdir          directory relative to destdir where to place build aux files
4888 # - inctests        true if tests should be included, blank otherwise
4889 # - incobsolete     true if obsolete modules among dependencies should be
4890 #                   included, blank otherwise
4891 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
4892 #                    blank otherwise
4893 # - excl_longrunning_tests  true if long-runnings tests should be excluded,
4894 #                           blank otherwise
4895 # - excl_privileged_tests  true if tests that require root privileges should be
4896 #                          excluded, blank otherwise
4897 # - excl_unportable_tests  true if tests that fail on some platforms should be
4898 #                          excluded, blank otherwise
4899 # - avoidlist       list of modules to avoid
4900 # - libtool         true if --libtool was given, false if --no-libtool was
4901 #                   given, blank otherwise
4902 # - symbolic        true if files should be symlinked, copied otherwise
4903 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
4904 #                   copied otherwise
4905 func_create_testdir ()
4906 {
4907   testdir="$1"
4908   modules="$2"
4909   if test -z "$modules"; then
4910     # All modules together.
4911     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
4912     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
4913     # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
4914     modules=`func_all_modules`
4915     modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist | lib-ignore) ;; *) echo $m;; esac; done`
4916   fi
4917   specified_modules="$modules"
4918
4919   # Canonicalize the list of specified modules.
4920   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
4921
4922   # Unlike in func_import, here we want to include all kinds of tests for the
4923   # directly specified modules, but not for dependencies.
4924   inc_all_direct_tests=true
4925   inc_all_indirect_tests="$inc_all_tests"
4926
4927   # Check that the license of every module is consistent with the license of
4928   # its dependencies.
4929   saved_inctests="$inctests"
4930   # When computing transitive closures, don't consider $module to depend on
4931   # $module-tests. Need this becauses tests are implicitly GPL and may depend
4932   # on GPL modules - therefore we don't want a warning in this case.
4933   inctests=""
4934   for requested_module in $specified_modules; do
4935     requested_license=`func_get_license "$requested_module"`
4936     if test "$requested_license" != GPL; then
4937       # Here we use func_modules_transitive_closure, not just
4938       # func_get_dependencies, so that we also detect weird situations like
4939       # an LGPL module which depends on a GPLed build tool module which depends
4940       # on a GPL module.
4941       modules="$requested_module"
4942       func_modules_transitive_closure
4943       for module in $modules; do
4944         license=`func_get_license "$module"`
4945         case "$license" in
4946           'GPLed build tool') ;;
4947           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
4948           *)
4949             case "$requested_license" in
4950               GPLv2+)
4951                 case "$license" in
4952                   GPLv2+ | LGPLv2+) ;;
4953                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4954                 esac
4955                 ;;
4956               LGPL)
4957                 case "$license" in
4958                   LGPL | LGPLv2+) ;;
4959                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4960                 esac
4961                 ;;
4962               LGPLv2+)
4963                 case "$license" in
4964                   LGPLv2+) ;;
4965                   *) func_warning "module $requested_module depends on a module with an incompatible license: $module" ;;
4966                 esac
4967                 ;;
4968             esac
4969             ;;
4970         esac
4971       done
4972     fi
4973   done
4974   inctests="$saved_inctests"
4975
4976   # Subdirectory names.
4977   sourcebase=gllib
4978   m4base=glm4
4979   pobase=
4980   docbase=gldoc
4981   testsbase=gltests
4982   macro_prefix=gl
4983   po_domain=
4984   vc_files=
4985
4986   # Determine final module list.
4987   modules="$specified_modules"
4988   func_modules_transitive_closure
4989   if test $verbose -ge 0; then
4990     func_show_module_list
4991   fi
4992
4993   # Add the dummy module if needed.
4994   func_modules_add_dummy
4995
4996   # Show banner notice of every module.
4997   func_modules_notice
4998
4999   # Determine final file list.
5000   func_modules_to_filelist
5001   if test $verbose -ge 0; then
5002     echo "File list:"
5003     echo "$files" | sed -e 's/^/  /'
5004   fi
5005   # Add files for which the copy in gnulib is newer than the one that
5006   # "automake --add-missing --copy" would provide.
5007   files="$files build-aux/config.guess"
5008   files="$files build-aux/config.sub"
5009   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
5010
5011   rewritten='%REWRITTEN%'
5012   sed_rewrite_files="\
5013     s,^build-aux/,$rewritten$auxdir/,
5014     s,^doc/,$rewritten$docbase/,
5015     s,^lib/,$rewritten$sourcebase/,
5016     s,^m4/,$rewritten$m4base/,
5017     s,^tests/,$rewritten$testsbase/,
5018     s,^top/,$rewritten,
5019     s,^$rewritten,,"
5020
5021   # Create directories.
5022   for f in $files; do echo $f; done \
5023     | sed -e "$sed_rewrite_files" \
5024     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
5025     | LC_ALL=C sort -u \
5026     > "$tmp"/dirs
5027   { # Rearrange file descriptors. Needed because "while ... done < ..."
5028     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5029     exec 5<&0 < "$tmp"/dirs
5030     while read d; do
5031       mkdir -p "$testdir/$d"
5032     done
5033     exec 0<&5 5<&-
5034   }
5035
5036   # Copy files or make symbolic links.
5037   delimiter='   '
5038   for f in $files; do echo $f; done \
5039     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
5040     | LC_ALL=C sort \
5041     > "$tmp"/files
5042   { # Rearrange file descriptors. Needed because "while ... done < ..."
5043     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
5044     exec 5<&0 < "$tmp"/files
5045     while read g f; do
5046       func_lookup_file "$f"
5047       if test -n "$lookedup_tmp"; then
5048         cp -p "$lookedup_file" "$testdir/$g"
5049       else
5050         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
5051         if { test -n "$symbolic" \
5052              || { test -n "$lsymbolic" \
5053                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
5054           func_ln "$lookedup_file" "$testdir/$g"
5055         else
5056           cp -p "$lookedup_file" "$testdir/$g"
5057         fi
5058       fi
5059     done
5060     exec 0<&5 5<&-
5061   }
5062
5063   # Create Makefile.ams that are for testing.
5064   for_test=true
5065
5066   # No special edits are needed.
5067   makefile_am_edits=0
5068
5069   # Create $sourcebase/Makefile.am.
5070   mkdir -p "$testdir/$sourcebase"
5071   destfile="$sourcebase/Makefile.am"
5072   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
5073   any_uses_subdirs="$uses_subdirs"
5074
5075   # Create $m4base/Makefile.am.
5076   mkdir -p "$testdir/$m4base"
5077   (echo "## Process this file with automake to produce Makefile.in."
5078    echo
5079    echo "EXTRA_DIST ="
5080    for f in $files; do
5081      case "$f" in
5082        m4/* )
5083          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
5084      esac
5085    done
5086   ) > "$testdir/$m4base/Makefile.am"
5087
5088   subdirs="$sourcebase $m4base"
5089   subdirs_with_configure_ac=""
5090
5091   if false && test -f "$testdir"/$m4base/gettext.m4; then
5092     # Avoid stupid error message from automake:
5093     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
5094     mkdir -p "$testdir/po"
5095     (echo "## Process this file with automake to produce Makefile.in."
5096     ) > "$testdir/po/Makefile.am"
5097     func_append subdirs " po"
5098   fi
5099
5100   if test -n "$inctests"; then
5101     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
5102     # Viewed from the $testsbase subdirectory, $auxdir is different.
5103     saved_auxdir="$auxdir"
5104     auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
5105     # Create $testsbase/Makefile.am.
5106     use_libtests=false
5107     destfile="$testsbase/Makefile.am"
5108     func_emit_tests_Makefile_am "" > "$testdir/$testsbase/Makefile.am"
5109     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
5110     # Create $testsbase/configure.ac.
5111     (echo "# Process this file with autoconf to produce a configure script."
5112      echo "AC_INIT([dummy], [0])"
5113      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5114      echo "AM_INIT_AUTOMAKE"
5115      echo
5116      echo "AC_CONFIG_HEADERS([config.h])"
5117      echo
5118      echo "AC_PROG_CC"
5119      echo "AC_PROG_INSTALL"
5120      echo "AC_PROG_MAKE_SET"
5121      echo "AC_PROG_RANLIB"
5122      echo
5123      if test -n "$uses_subdirs"; then
5124        echo "AM_PROG_CC_C_O"
5125        echo
5126      fi
5127      for module in $modules; do
5128        func_verify_module
5129        if test -n "$module"; then
5130          case $module in
5131            gnumakefile | maintainer-makefile)
5132              # These modules are meant to be used only in the top-level directory.
5133              ;;
5134            *)
5135              func_get_autoconf_early_snippet "$module"
5136              ;;
5137          esac
5138        fi
5139      done \
5140        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5141      if test "$libtool" = true; then
5142        echo "LT_INIT([win32-dll])"
5143        echo "LT_LANG([C++])"
5144        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5145        echo "gl_cond_libtool=true"
5146      else
5147        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5148        echo "gl_cond_libtool=false"
5149        echo "gl_libdeps="
5150        echo "gl_ltlibdeps="
5151      fi
5152      # Wrap the set of autoconf snippets into an autoconf macro that is then
5153      # invoked. This is needed because autoconf does not support AC_REQUIRE
5154      # at the top level:
5155      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5156      # but we want the AC_REQUIRE to have its normal meaning (provide one
5157      # expansion of the required macro before the current point, and only one
5158      # expansion total).
5159      echo "AC_DEFUN([gl_INIT], ["
5160      sed_replace_build_aux='
5161        :a
5162        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5163          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5164          ba
5165        }'
5166      echo "gl_m4_base='../$m4base'"
5167      func_emit_initmacro_start $macro_prefix
5168      # We don't have explicit ordering constraints between the various
5169      # autoconf snippets. It's cleanest to put those of the library before
5170      # those of the tests.
5171      echo "gl_source_base='../$sourcebase'"
5172      func_emit_autoconf_snippets "$modules" func_verify_nontests_module false false false
5173      echo "gl_source_base='.'"
5174      func_emit_autoconf_snippets "$modules" func_verify_tests_module false false false
5175      func_emit_initmacro_end $macro_prefix
5176      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5177      # created using libtool, because libtool already handles the dependencies.
5178      if test "$libtool" != true; then
5179        libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5180        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5181        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5182        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5183        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5184      fi
5185      echo "])"
5186      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
5187      echo
5188      echo "gl_INIT"
5189      echo
5190      # Usually $testsbase/config.h will be a superset of config.h. Verify this
5191      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
5192      echo "AH_TOP([#include \"../config.h\"])"
5193      echo
5194      echo "AC_CONFIG_FILES([Makefile])"
5195      echo "AC_OUTPUT"
5196     ) > "$testdir/$testsbase/configure.ac"
5197     auxdir="$saved_auxdir"
5198     func_append subdirs " $testsbase"
5199     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
5200   fi
5201
5202   # Create Makefile.am.
5203   (echo "## Process this file with automake to produce Makefile.in."
5204    echo
5205    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
5206    echo
5207    echo "SUBDIRS = $subdirs"
5208    echo
5209    echo "ACLOCAL_AMFLAGS = -I $m4base"
5210   ) > "$testdir/Makefile.am"
5211
5212   # Create configure.ac.
5213   (echo "# Process this file with autoconf to produce a configure script."
5214    echo "AC_INIT([dummy], [0])"
5215    if test "$auxdir" != "."; then
5216      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5217    fi
5218    echo "AM_INIT_AUTOMAKE"
5219    echo
5220    echo "AC_CONFIG_HEADERS([config.h])"
5221    echo
5222    echo "AC_PROG_CC"
5223    echo "AC_PROG_INSTALL"
5224    echo "AC_PROG_MAKE_SET"
5225    echo
5226    echo "# For autobuild."
5227    echo "AC_CANONICAL_BUILD"
5228    echo "AC_CANONICAL_HOST"
5229    echo
5230    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
5231    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
5232    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
5233    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
5234    echo
5235    echo "AC_PROG_RANLIB"
5236    echo
5237    if test -n "$any_uses_subdirs"; then
5238      echo "AM_PROG_CC_C_O"
5239      echo
5240    fi
5241    for module in $modules; do
5242      func_verify_nontests_module
5243      if test -n "$module"; then
5244        func_get_autoconf_early_snippet "$module"
5245      fi
5246    done \
5247      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
5248    if test "$libtool" = true; then
5249      echo "LT_INIT([win32-dll])"
5250      echo "LT_LANG([C++])"
5251      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
5252      echo "gl_cond_libtool=true"
5253    else
5254      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
5255      echo "gl_cond_libtool=false"
5256      echo "gl_libdeps="
5257      echo "gl_ltlibdeps="
5258    fi
5259    # Wrap the set of autoconf snippets into an autoconf macro that is then
5260    # invoked. This is needed because autoconf does not support AC_REQUIRE
5261    # at the top level:
5262    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
5263    # but we want the AC_REQUIRE to have its normal meaning (provide one
5264    # expansion of the required macro before the current point, and only one
5265    # expansion total).
5266    echo "AC_DEFUN([gl_INIT], ["
5267    if test "$auxdir" != "build-aux"; then
5268      sed_replace_build_aux='
5269        :a
5270        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
5271          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
5272          ba
5273        }'
5274    else
5275      sed_replace_build_aux="$sed_noop"
5276    fi
5277    echo "gl_m4_base='$m4base'"
5278    func_emit_initmacro_start $macro_prefix
5279    echo "gl_source_base='$sourcebase'"
5280    func_emit_autoconf_snippets "$modules" func_verify_nontests_module true false false
5281    func_emit_initmacro_end $macro_prefix
5282    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
5283    # created using libtool, because libtool already handles the dependencies.
5284    if test "$libtool" != true; then
5285      libname_upper=`echo "$libname" | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
5286      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
5287      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
5288      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
5289      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
5290    fi
5291    echo "])"
5292    func_emit_initmacro_done $macro_prefix $sourcebase
5293    echo
5294    echo "gl_INIT"
5295    echo
5296    if test -n "$subdirs_with_configure_ac"; then
5297      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
5298    fi
5299    makefiles="Makefile"
5300    for d in $subdirs; do
5301      # For subdirs that have a configure.ac by their own, it's the subdir's
5302      # configure.ac which creates the subdir's Makefile.am, not this one.
5303      case " $subdirs_with_configure_ac " in
5304        *" $d "*) ;;
5305        *) func_append makefiles " $d/Makefile" ;;
5306      esac
5307    done
5308    echo "AC_CONFIG_FILES([$makefiles])"
5309    echo "AC_OUTPUT"
5310   ) > "$testdir/configure.ac"
5311
5312   # Create autogenerated files.
5313   (cd "$testdir"
5314    # Do not use "${AUTORECONF} --force --install", because it may invoke
5315    # autopoint, which brings in older versions of some of our .m4 files.
5316    if test -f $m4base/gettext.m4; then
5317      func_execute_command ${AUTOPOINT} --force || func_exit 1
5318      for f in $m4base/*.m4~; do
5319        if test -f $f; then
5320          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
5321        fi
5322      done
5323    fi
5324    if test "$libtool" = true; then
5325      func_execute_command ${LIBTOOLIZE} --copy || func_exit 1
5326    fi
5327    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
5328    if ! test -d build-aux; then
5329      func_execute_command mkdir build-aux || func_exit 1
5330    fi
5331    func_execute_command ${AUTOCONF} || func_exit 1
5332    func_execute_command ${AUTOHEADER} || func_exit 1
5333    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5334   ) || func_exit 1
5335   if test -n "$inctests"; then
5336     # Create autogenerated files.
5337     (cd "$testdir/$testsbase" || func_exit 1
5338      # Do not use "${AUTORECONF} --force --install", because it may invoke
5339      # autopoint, which brings in older versions of some of our .m4 files.
5340      if test -f ../$m4base/gettext.m4; then
5341        func_execute_command ${AUTOPOINT} --force || func_exit 1
5342        for f in ../$m4base/*.m4~; do
5343          if test -f $f; then
5344            mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
5345          fi
5346        done
5347      fi
5348      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
5349      if ! test -d ../build-aux; then
5350        func_execute_command mkdir ../build-aux
5351      fi
5352      func_execute_command ${AUTOCONF} || func_exit 1
5353      func_execute_command ${AUTOHEADER} || func_exit 1
5354      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5355     ) || func_exit 1
5356   fi
5357   # Need to run configure and make once, to create built files that are to be
5358   # distributed (such as parse-datetime.c).
5359   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
5360   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
5361   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
5362                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
5363   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
5364   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
5365   # such $(FOO_H) because they don't refer to distributed files.
5366   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
5367                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
5368                  | sed -e "$sed_remove_make_variables"`
5369   distributed_built_sources=`for file in $built_sources; do
5370                                case "$cleaned_files" in
5371                                  *" "$file" "*) ;;
5372                                  *) echo $file ;;
5373                                esac;
5374                              done`
5375   tests_distributed_built_sources=
5376   if test -n "$inctests"; then
5377     # Likewise for built files in the $testsbase directory.
5378     tests_cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
5379                          | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
5380     tests_cleaned_files=`for file in $tests_cleaned_files; do echo " $file "; done`
5381     tests_built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
5382                          | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
5383                          | sed -e "$sed_remove_make_variables"`
5384     tests_distributed_built_sources=`for file in $tests_built_sources; do
5385                                        case "$tests_cleaned_files" in
5386                                          *" "$file" "*) ;;
5387                                          *) echo $file ;;
5388                                        esac;
5389                                      done`
5390   fi
5391   if test -n "$distributed_built_sources" || test -n "$tests_distributed_built_sources"; then
5392     (cd "$testdir"
5393      ./configure || func_exit 1
5394        if test -n "$distributed_built_sources"; then
5395          cd "$sourcebase"
5396          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
5397          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
5398                built_sources \
5399            || func_exit 1
5400          cd ..
5401        fi
5402        if test -n "$tests_distributed_built_sources"; then
5403          cd "$testsbase"
5404          echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
5405          $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
5406                built_sources \
5407            || func_exit 1
5408          cd ..
5409        fi
5410      $MAKE AUTOCONF="${AUTOCONF}" AUTOHEADER="${AUTOHEADER}" ACLOCAL="${ACLOCAL}" AUTOMAKE="${AUTOMAKE}" AUTORECONF="${AUTORECONF}" AUTOPOINT="${AUTOPOINT}" LIBTOOLIZE="${LIBTOOLIZE}" \
5411            distclean \
5412        || func_exit 1
5413     ) || func_exit 1
5414   fi
5415 }
5416
5417 # func_create_megatestdir megatestdir allmodules
5418 # Input:
5419 # - local_gnulib_dir  from --local-dir
5420 # - modcache        true or false, from --cache-modules/--no-cache-modules
5421 # - auxdir          directory relative to destdir where to place build aux files
5422 func_create_megatestdir ()
5423 {
5424   megatestdir="$1"
5425   allmodules="$2"
5426   if test -z "$allmodules"; then
5427     allmodules=`func_all_modules`
5428   fi
5429
5430   megasubdirs=
5431   # First, all modules one by one.
5432   for onemodule in $allmodules; do
5433     func_create_testdir "$megatestdir/$onemodule" $onemodule
5434     func_append megasubdirs "$onemodule "
5435   done
5436   # Then, all modules all together.
5437   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
5438   allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
5439   func_create_testdir "$megatestdir/ALL" "$allmodules"
5440   func_append megasubdirs "ALL"
5441
5442   # Create autobuild.
5443   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
5444              vc_witness="$gnulib_dir/CVS/Entries"; \
5445            else \
5446              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
5447            fi; \
5448            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
5449              | sed -e 's,January,01,'   -e 's,Jan,01,' \
5450                    -e 's,February,02,'  -e 's,Feb,02,' \
5451                    -e 's,March,03,'     -e 's,Mar,03,' \
5452                    -e 's,April,04,'     -e 's,Apr,04,' \
5453                    -e 's,May,05,'                      \
5454                    -e 's,June,06,'      -e 's,Jun,06,' \
5455                    -e 's,July,07,'      -e 's,Jul,07,' \
5456                    -e 's,August,08,'    -e 's,Aug,08,' \
5457                    -e 's,September,09,' -e 's,Sep,09,' \
5458                    -e 's,October,10,'   -e 's,Oct,10,' \
5459                    -e 's,November,11,'  -e 's,Nov,11,' \
5460                    -e 's,December,12,'  -e 's,Dec,12,' \
5461                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
5462                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
5463   (echo '#!/bin/sh'
5464    echo "CVSDATE=$cvsdate"
5465    echo ": \${MAKE=make}"
5466    echo "test -d logs || mkdir logs"
5467    echo "for module in $megasubdirs; do"
5468    echo "  echo \"Working on module \$module...\""
5469    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
5470    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
5471    echo "   echo"
5472    echo "   set -x"
5473    echo "   : autobuild project... \$module"
5474    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
5475    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
5476    echo "   : autobuild hostname... \`hostname\`"
5477    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && \$MAKE && \$MAKE check && \$MAKE distclean"
5478    echo "   echo rc=\$?"
5479    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
5480    echo "done"
5481   ) > "$megatestdir/do-autobuild"
5482   chmod a+x "$megatestdir/do-autobuild"
5483
5484   # Create Makefile.am.
5485   (echo "## Process this file with automake to produce Makefile.in."
5486    echo
5487    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
5488    echo
5489    echo "SUBDIRS = $megasubdirs"
5490    echo
5491    echo "EXTRA_DIST = do-autobuild"
5492   ) > "$megatestdir/Makefile.am"
5493
5494   # Create configure.ac.
5495   (echo "# Process this file with autoconf to produce a configure script."
5496    echo "AC_INIT([dummy], [0])"
5497    if test "$auxdir" != "."; then
5498      echo "AC_CONFIG_AUX_DIR([$auxdir])"
5499    fi
5500    echo "AM_INIT_AUTOMAKE"
5501    echo
5502    echo "AC_PROG_MAKE_SET"
5503    echo
5504    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
5505    echo "AC_CONFIG_FILES([Makefile])"
5506    echo "AC_OUTPUT"
5507   ) > "$megatestdir/configure.ac"
5508
5509   # Create autogenerated files.
5510   (cd "$megatestdir"
5511    # Do not use "${AUTORECONF} --install", because autoreconf operates
5512    # recursively, but the subdirectories are already finished, therefore
5513    # calling autoreconf here would only waste lots of CPU time.
5514    func_execute_command ${ACLOCAL} || func_exit 1
5515    func_execute_command mkdir build-aux
5516    func_execute_command ${AUTOCONF} || func_exit 1
5517    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
5518   ) || func_exit 1
5519 }
5520
5521 case $mode in
5522   "" )
5523     func_fatal_error "no mode specified" ;;
5524
5525   list )
5526     func_all_modules
5527     ;;
5528
5529   find )
5530     # sed expression that converts a literal to a basic regular expression.
5531     # Needs to handle . [ \ * ^ $.
5532     sed_literal_to_basic_regex='s/\\/\\\\/g
5533 s/\[/\\[/g
5534 s/\^/\\^/g
5535 s/\([.*$]\)/[\1]/g'
5536     for filename
5537     do
5538       if test -f "$gnulib_dir/$filename" \
5539          || { test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$filename"; }; then
5540         filename_anywhere_regex=`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`
5541         filename_line_regex='^'"$filename_anywhere_regex"'$'
5542         module_candidates=`
5543           {
5544             (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filename_line_regex" /dev/null | sed -e 's,^modules/,,')
5545             if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
5546               (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$,,')
5547             fi
5548           } \
5549             | func_sanitize_modulelist \
5550             | LC_ALL=C sort -u
5551           `
5552         for module in $module_candidates; do
5553           if func_get_filelist $module | grep "$filename_line_regex" > /dev/null; then
5554             echo $module
5555           fi
5556         done
5557       else
5558         func_warning "file $filename does not exist"
5559       fi
5560     done
5561     ;;
5562
5563   import | add-import | remove-import | update )
5564
5565     # Where to import.
5566     if test -z "$destdir"; then
5567       destdir=.
5568     fi
5569     test -d "$destdir" \
5570       || func_fatal_error "destination directory does not exist: $destdir"
5571
5572     # Prefer configure.ac to configure.in.
5573     if test -f "$destdir"/configure.ac; then
5574       configure_ac="$destdir/configure.ac"
5575     else
5576       if test -f "$destdir"/configure.in; then
5577         configure_ac="$destdir/configure.in"
5578       else
5579         func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
5580       fi
5581     fi
5582
5583     # Analyze configure.ac.
5584     guessed_auxdir="."
5585     guessed_libtool=false
5586     my_sed_traces='
5587       s,#.*$,,
5588       s,^dnl .*$,,
5589       s, dnl .*$,,
5590       /AC_CONFIG_AUX_DIR/ {
5591         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^]"$`\\)]*\).*$,guessed_auxdir="\1",p
5592       }
5593       /A[CM]_PROG_LIBTOOL/ {
5594         s,^.*$,guessed_libtool=true,p
5595       }'
5596     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
5597
5598     if test -z "$auxdir"; then
5599       auxdir="$guessed_auxdir"
5600     fi
5601
5602     # Determine where to apply func_import.
5603     if test "$mode" = import; then
5604       # Apply func_import to a particular gnulib directory.
5605       # The command line contains the complete specification; don't look at
5606       # the contents of gnulib-cache.m4.
5607       test -n "$supplied_libname" || supplied_libname=true
5608       test -n "$sourcebase" || sourcebase="lib"
5609       test -n "$m4base" || m4base="m4"
5610       test -n "$docbase" || docbase="doc"
5611       test -n "$testsbase" || testsbase="tests"
5612       test -n "$macro_prefix" || macro_prefix="gl"
5613       func_import "$*"
5614     else
5615       if test -n "$m4base"; then
5616         # Apply func_import to a particular gnulib directory.
5617         # Any number of additional modules can be given.
5618         if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
5619           # First use of gnulib in the given m4base.
5620           test -n "$supplied_libname" || supplied_libname=true
5621           test -n "$sourcebase" || sourcebase="lib"
5622           test -n "$docbase" || docbase="doc"
5623           test -n "$testsbase" || testsbase="tests"
5624           test -n "$macro_prefix" || macro_prefix="gl"
5625         fi
5626         func_import "$*"
5627       else
5628         # Apply func_import to all gnulib directories.
5629         # To get this list of directories, look at Makefile.am. (Not at
5630         # configure, because it may be omitted from version control. Also,
5631         # don't run "find $destdir -name gnulib-cache.m4", as it might be
5632         # too expensive.)
5633         m4dirs=
5634         m4dirs_count=0
5635         if test -f "$destdir"/Makefile.am; then
5636           aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[        ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
5637           m4dir_is_next=
5638           for arg in $aclocal_amflags; do
5639             if test -n "$m4dir_is_next"; then
5640               # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
5641               case "$arg" in
5642                 /*) ;;
5643                 *)
5644                   if test -f "$destdir/$arg"/gnulib-cache.m4; then
5645                     func_append m4dirs " $arg"
5646                     m4dirs_count=`expr $m4dirs_count + 1`
5647                   fi
5648                   ;;
5649               esac
5650               m4dir_is_next=
5651             else
5652               if test "X$arg" = "X-I"; then
5653                 m4dir_is_next=yes
5654               else
5655                 m4dir_is_next=
5656               fi
5657             fi
5658           done
5659         else
5660           # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
5661           if test -f "$destdir"/aclocal.m4; then
5662             sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
5663             sedexpr2='s,^[^/]*$,.,'
5664             sedexpr3='s,/[^/]*$,,'
5665             m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
5666             m4dirs=`for arg in $m4dirs; do if test -f "$destdir/$arg"/gnulib-cache.m4; then echo $arg; fi; done`
5667             m4dirs_count=`for arg in $m4dirs; do echo "$arg"; done | wc -l`
5668           fi
5669         fi
5670         if test $m4dirs_count = 0; then
5671           # First use of gnulib in a package.
5672           # Any number of additional modules can be given.
5673           test -n "$supplied_libname" || supplied_libname=true
5674           test -n "$sourcebase" || sourcebase="lib"
5675           m4base="m4"
5676           test -n "$docbase" || docbase="doc"
5677           test -n "$testsbase" || testsbase="tests"
5678           test -n "$macro_prefix" || macro_prefix="gl"
5679           func_import "$*"
5680         else
5681           if test $m4dirs_count = 1; then
5682             # There's only one use of gnulib here. Assume the user means it.
5683             # Any number of additional modules can be given.
5684             for m4base in $m4dirs; do
5685               func_import "$*"
5686             done
5687           else
5688             # Ambiguous - guess what the user meant.
5689             if test $# = 0; then
5690               # No further arguments. Guess the user wants to update all of them.
5691               for m4base in $m4dirs; do
5692                 # Perform func_import in a subshell, so that variable values
5693                 # such as
5694                 #   local_gnulib_dir, incobsolete, inc_cxx_tests,
5695                 #   inc_longrunning_tests, inc_privileged_tests,
5696                 #   inc_unportable_tests, inc_all_tests, avoidlist, sourcebase,
5697                 #   m4base, pobase, docbase, testsbase, inctests, libname, lgpl,
5698                 #   makefile_name, libtool, macro_prefix, po_domain, vc_files
5699                 # don't propagate from one directory to another.
5700                 (func_import) || func_exit 1
5701               done
5702             else
5703               # Really ambiguous.
5704               func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
5705             fi
5706           fi
5707         fi
5708       fi
5709     fi
5710     ;;
5711
5712   create-testdir )
5713     if test -z "$destdir"; then
5714       func_fatal_error "please specify --dir option"
5715     fi
5716     mkdir "$destdir"
5717     test -d "$destdir" \
5718       || func_fatal_error "could not create destination directory"
5719     test -n "$auxdir" || auxdir="build-aux"
5720     func_create_testdir "$destdir" "$*"
5721     ;;
5722
5723   create-megatestdir )
5724     if test -z "$destdir"; then
5725       func_fatal_error "please specify --dir option"
5726     fi
5727     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5728     test -n "$auxdir" || auxdir="build-aux"
5729     func_create_megatestdir "$destdir" "$*"
5730     ;;
5731
5732   test )
5733     test -n "$destdir" || destdir=testdir$$
5734     mkdir "$destdir" || func_fatal_error "could not create destination directory"
5735     test -n "$auxdir" || auxdir="build-aux"
5736     func_create_testdir "$destdir" "$*"
5737     cd "$destdir"
5738       mkdir build
5739       cd build
5740         ../configure || func_exit 1
5741         $MAKE || func_exit 1
5742         $MAKE check || func_exit 1
5743         $MAKE distclean || func_exit 1
5744         remaining=`find . -type f -print`
5745         if test -n "$remaining"; then
5746           echo "Remaining files:" $remaining 1>&2
5747           echo "gnulib-tool: *** Stop." 1>&2
5748           func_exit 1
5749         fi
5750       cd ..
5751     cd ..
5752     rm -rf "$destdir"
5753     ;;
5754
5755   megatest )
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_megatestdir "$destdir" "$*"
5760     cd "$destdir"
5761       mkdir build
5762       cd build
5763         ../configure
5764         $MAKE
5765         $MAKE check
5766         $MAKE distclean
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   extract-description )
5779     for module
5780     do
5781       func_verify_module
5782       if test -n "$module"; then
5783         func_get_description "$module"
5784       fi
5785     done
5786     ;;
5787
5788   extract-comment )
5789     for module
5790     do
5791       func_verify_module
5792       if test -n "$module"; then
5793         func_get_comment "$module"
5794       fi
5795     done
5796     ;;
5797
5798   extract-status )
5799     for module
5800     do
5801       func_verify_module
5802       if test -n "$module"; then
5803         func_get_status "$module"
5804       fi
5805     done
5806     ;;
5807
5808   extract-notice )
5809     for module
5810     do
5811       func_verify_module
5812       if test -n "$module"; then
5813         func_get_notice "$module"
5814       fi
5815     done
5816     ;;
5817
5818   extract-applicability )
5819     for module
5820     do
5821       func_verify_module
5822       if test -n "$module"; then
5823         func_get_applicability "$module"
5824       fi
5825     done
5826     ;;
5827
5828   extract-filelist )
5829     for module
5830     do
5831       func_verify_module
5832       if test -n "$module"; then
5833         func_get_filelist "$module"
5834       fi
5835     done
5836     ;;
5837
5838   extract-dependencies )
5839     for module
5840     do
5841       func_verify_module
5842       if test -n "$module"; then
5843         func_get_dependencies "$module"
5844       fi
5845     done
5846     ;;
5847
5848   extract-autoconf-snippet )
5849     for module
5850     do
5851       func_verify_module
5852       if test -n "$module"; then
5853         func_get_autoconf_snippet "$module"
5854       fi
5855     done
5856     ;;
5857
5858   extract-automake-snippet )
5859     for module
5860     do
5861       func_verify_module
5862       if test -n "$module"; then
5863         func_get_automake_snippet "$module"
5864       fi
5865     done
5866     ;;
5867
5868   extract-include-directive )
5869     for module
5870     do
5871       func_verify_module
5872       if test -n "$module"; then
5873         func_get_include_directive "$module"
5874       fi
5875     done
5876     ;;
5877
5878   extract-link-directive )
5879     for module
5880     do
5881       func_verify_module
5882       if test -n "$module"; then
5883         func_get_link_directive "$module"
5884       fi
5885     done
5886     ;;
5887
5888   extract-license )
5889     for module
5890     do
5891       func_verify_module
5892       if test -n "$module"; then
5893         func_get_license "$module"
5894       fi
5895     done
5896     ;;
5897
5898   extract-maintainer )
5899     for module
5900     do
5901       func_verify_module
5902       if test -n "$module"; then
5903         func_get_maintainer "$module"
5904       fi
5905     done
5906     ;;
5907
5908   extract-tests-module )
5909     for module
5910     do
5911       func_verify_module
5912       if test -n "$module"; then
5913         func_get_tests_module "$module"
5914       fi
5915     done
5916     ;;
5917
5918   copy-file )
5919     # Verify the number of arguments.
5920     if test $# -lt 1 || test $# -gt 2; then
5921       func_fatal_error "invalid number of arguments for --$mode"
5922     fi
5923
5924     # The first argument is the file to be copied.
5925     f="$1"
5926     # Verify the file exists.
5927     func_lookup_file "$f"
5928
5929     # The second argument is the destination; either a directory ot a file.
5930     # It defaults to the current directory.
5931     dest="$2"
5932     test -n "$dest" || dest='.'
5933     test -n "$sourcebase" || sourcebase="lib"
5934     test -n "$m4base" || m4base="m4"
5935     test -n "$docbase" || docbase="doc"
5936     test -n "$testsbase" || testsbase="tests"
5937     test -n "$auxdir" || auxdir="build-aux"
5938     rewritten='%REWRITTEN%'
5939     sed_rewrite_files="\
5940       s,^build-aux/,$rewritten$auxdir/,
5941       s,^doc/,$rewritten$docbase/,
5942       s,^lib/,$rewritten$sourcebase/,
5943       s,^m4/,$rewritten$m4base/,
5944       s,^tests/,$rewritten$testsbase/,
5945       s,^top/,$rewritten,
5946       s,^$rewritten,,"
5947     if test -d "$dest"; then
5948       destdir="$dest"
5949       g=`echo "$f" | sed -e "$sed_rewrite_files"`
5950     else
5951       destdir=`dirname "$dest"`
5952       g=`basename "$dest"`
5953     fi
5954
5955     # Create the directory for destfile.
5956     d=`dirname "$destdir/$g"`
5957     if $doit; then
5958       if test -n "$d" && test ! -d "$d"; then
5959         mkdir -p "$d" || func_fatal_error "failed"
5960       fi
5961     fi
5962     # Copy the file.
5963     func_dest_tmpfilename "$g"
5964     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
5965     already_present=true
5966     if test -f "$destdir/$g"; then
5967       # The file already exists.
5968       func_update_file
5969     else
5970       # Install the file.
5971       # Don't protest if the file should be there but isn't: it happens
5972       # frequently that developers don't put autogenerated files under version
5973       # control.
5974       func_add_file
5975     fi
5976     rm -f "$tmpfile"
5977     ;;
5978
5979   * )
5980     func_fatal_error "unknown operation mode --$mode" ;;
5981 esac
5982
5983 rm -rf "$tmp"
5984 # Undo the effect of the previous 'trap' command. Some shellology:
5985 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
5986 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
5987 # exit); for the others we need to call 'exit' explicitly. The value of $? is
5988 # 128 + signal number and is set before the trap-registered command is run.
5989 trap '' 0
5990 trap 'func_exit $?' 1 2 3 13 15
5991
5992 exit 0
5993
5994 # Local Variables:
5995 # indent-tabs-mode: nil
5996 # whitespace-check-buffer-indent: nil
5997 # End: