Fix 'gnulib-tool --version' output to work with git.
[pspp] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2008 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 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
44 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
45 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
46   AUTOCONF="${AUTOCONFPATH}autoconf"
47 fi
48 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
49   AUTOHEADER="${AUTOCONFPATH}autoheader"
50 fi
51 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
52   ACLOCAL="${AUTOMAKEPATH}aclocal"
53 fi
54 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
55   AUTOMAKE="${AUTOMAKEPATH}automake"
56 fi
57 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
58   AUTORECONF="${AUTOCONFPATH}autoreconf"
59 fi
60
61 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
62 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
63   AUTOPOINT="${GETTEXTPATH}autopoint"
64 fi
65
66 # When using GNU sed, turn off as many GNU extensions as possible,
67 # to minimize the risk of accidentally using non-portable features.
68 # However, do this only for gnulib-tool itself, not for the code that
69 # gnulib-tool generates, since we don't want "sed --posix" to leak
70 # into makefiles.
71 if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then
72   # Define sed as an alias.
73   # It is not always possible to use aliases. Aliases are guaranteed to work
74   # if the executing shell is bash and either it is invoked as /bin/sh or
75   # is a version >= 2.0, supporting shopt. This is the common case.
76   # Two other approaches (use of a variable $sed or of a function func_sed
77   # instead of an alias) require massive, fragile code changes.
78   # An other approach (use of function sed) requires `which sed` - but 'which'
79   # is hard to emulate, due to missing "test -x" on some platforms.
80   if test -n "$BASH_VERSION"; then
81     shopt -s expand_aliases >/dev/null 2>&1
82   fi
83   alias sed='sed --posix'
84 fi
85
86 # func_usage
87 # outputs to stdout the --help usage message.
88 func_usage ()
89 {
90   echo "\
91 Usage: gnulib-tool --list
92        gnulib-tool --import [module1 ... moduleN]
93        gnulib-tool --update
94        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
95        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
96        gnulib-tool --test --dir=directory module1 ... moduleN
97        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
98        gnulib-tool --extract-description module
99        gnulib-tool --extract-notice module
100        gnulib-tool --extract-filelist module
101        gnulib-tool --extract-dependencies module
102        gnulib-tool --extract-autoconf-snippet module
103        gnulib-tool --extract-automake-snippet module
104        gnulib-tool --extract-include-directive module
105        gnulib-tool --extract-link-directive module
106        gnulib-tool --extract-license module
107        gnulib-tool --extract-maintainer module
108        gnulib-tool --extract-tests-module module
109
110 Operation modes:
111       --list                print the available module names
112       --import              import the given modules into the current package;
113                             if no modules are specified, update the current
114                             package from the current gnulib
115       --update              update the current package, restore files omitted
116                             from CVS
117       --create-testdir      create a scratch package with the given modules
118       --create-megatestdir  create a mega scratch package with the given modules
119                             one by one and all together
120       --test                test the combination of the given modules
121                             (recommended to use CC=\"gcc -Wall\" here)
122       --megatest            test the given modules one by one and all together
123                             (recommended to use CC=\"gcc -Wall\" here)
124       --extract-description        extract the description
125       --extract-notice             extract the notice or banner
126       --extract-filelist           extract the list of files
127       --extract-dependencies       extract the dependencies
128       --extract-autoconf-snippet   extract the snippet for configure.ac
129       --extract-automake-snippet   extract the snippet for library makefile
130       --extract-include-directive  extract the #include directive
131       --extract-link-directive     extract the linker directive
132       --extract-license            report the license terms of the source files
133                                    under lib/
134       --extract-maintainer         report the maintainer(s) inside gnulib
135       --extract-tests-module       report the unit test module, if it exists
136
137 General options:
138       --dir=DIRECTORY       Specify the target directory.
139                             For --import, this specifies where your
140                             configure.ac can be found.  Defaults to current
141                             directory.
142       --local-dir=DIRECTORY  Specify a local override directory where to look
143                             up files before looking in gnulib's directory.
144       --verbose             Increase verbosity. May be repeated.
145       --quiet               Decrease verbosity. May be repeated.
146
147 Options for --import:
148       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
149       --source-base=DIRECTORY
150                             Directory relative to --dir where source code is
151                             placed (default \"lib\").
152       --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
153                             placed (default \"m4\").
154       --po-base=DIRECTORY   Directory relative to --dir where *.po files are
155                             placed (default \"po\").
156       --doc-base=DIRECTORY  Directory relative to --dir where doc files are
157                             placed (default \"doc\").
158       --tests-base=DIRECTORY
159                             Directory relative to --dir where unit tests are
160                             placed (default \"tests\").
161       --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
162                             tools are placed (default \"build-aux\").
163       --with-tests          Include unit tests for the included modules.
164       --avoid=MODULE        Avoid including the given MODULE. Useful if you
165                             have code that provides equivalent functionality.
166                             This option can be repeated.
167       --lgpl[=2|=3]         Abort if modules aren't available under the LGPL.
168                             Also modify license template from GPL to LGPL.
169                             The version number of the LGPL can be specified;
170                             the default is currently LGPLv3.
171       --makefile-name=NAME  Name of makefile in automake syntax in the
172                             source-base and tests-base directories
173                             (default \"Makefile.am\").
174       --libtool             Use libtool rules.
175       --no-libtool          Don't use libtool rules.
176       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
177                             'gl_INIT'. Default is 'gl'.
178       --po-domain=NAME      Specify the prefix of the i18n domain. Usually use
179                             the package name. A suffix '-gnulib' is appended.
180       --no-changelog        don't update or create ChangeLog files
181
182 Options for --import and --update:
183       --dry-run             For --import, only print what would have been done.
184   -s, --symbolic, --symlink Make symbolic links instead of copying files.
185       --local-symlink       Make symbolic links instead of copying files, only
186                             for files from the local override directory.
187   -S, --more-symlinks       Make symbolic links instead of copying files, and
188                             don't replace copyright notices.
189
190 Report bugs to <bug-gnulib@gnu.org>."
191 }
192
193 # func_version
194 # outputs to stdout the --version message.
195 func_version ()
196 {
197   func_gnulib_dir
198   version=`"$gnulib_dir"/build-aux/git-version-gen /dev/null`
199   year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
200   echo "\
201 $progname (GNU $package) $version
202 Copyright (C) $year Free Software Foundation, Inc.
203 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
204 This is free software: you are free to change and redistribute it.
205 There is NO WARRANTY, to the extent permitted by law.
206
207 Written by" "Bruno Haible" "and" "Simon Josefsson"
208 }
209
210 # func_emit_copyright_notice
211 # outputs to stdout a header for a generated file.
212 func_emit_copyright_notice ()
213 {
214   echo "# Copyright (C) 2004-2007 Free Software Foundation, Inc."
215   echo "#"
216   echo "# This file is free software, distributed under the terms of the GNU"
217   echo "# General Public License.  As a special exception to the GNU General"
218   echo "# Public License, this file may be distributed as part of a program"
219   echo "# that contains a configuration script generated by Autoconf, under"
220   echo "# the same distribution terms as the rest of that program."
221   echo "#"
222   echo "# Generated by gnulib-tool."
223 }
224
225 # func_exit STATUS
226 # exit with status
227 func_exit ()
228 {
229   (exit $1); exit $1
230 }
231
232 # func_gnulib_dir
233 # locates the directory where the gnulib repository lives
234 # Sets variables
235 # - self_abspathname         absolute pathname of gnulib-tool
236 # - gnulib_dir               absolute pathname of gnulib repository
237 func_gnulib_dir ()
238 {
239   case "$0" in
240     /*) self_abspathname="$0" ;;
241     */*) self_abspathname=`pwd`/"$0" ;;
242     *)
243       # Look in $PATH.
244       # Iterate through the elements of $PATH.
245       # We use IFS=: instead of
246       #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
247       # because the latter does not work when some PATH element contains spaces.
248       # We use a canonicalized $pathx instead of $PATH, because empty PATH
249       # elements are by definition equivalent to '.', however field splitting
250       # according to IFS=: loses empty fields in many shells:
251       #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
252       #     beginning, at the end, and in the middle),
253       #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
254       #     at the beginning and at the end,
255       #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
256       #     Solaris lose empty fields at the end.
257       # The 'case' statement is an optimization, to avoid evaluating the
258       # explicit canonicalization command when $PATH contains no empty fields.
259       self_abspathname=
260       if test "${PATH_SEPARATOR+set}" != set; then
261         func_tmpdir
262         { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
263         chmod +x "$tmp"/conf.sh
264         if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
265           PATH_SEPARATOR=';'
266         else
267           PATH_SEPARATOR=:
268         fi
269         rm -rf "$tmp"
270       fi
271       if test "$PATH_SEPARATOR" = ";"; then
272         # On Windows, programs are searched in "." before $PATH.
273         pathx=".;$PATH"
274       else
275         # On Unix, we have to convert empty PATH elements to ".".
276         pathx="$PATH"
277         case :$PATH: in
278           *::*)
279             pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
280             ;;
281         esac
282       fi
283       save_IFS="$IFS"
284       IFS="$PATH_SEPARATOR"
285       for d in $pathx; do
286         IFS="$save_IFS"
287         test -z "$d" && d=.
288         if test -x "$d/$0" && test ! -d "$d/$0"; then
289           self_abspathname="$d/$0"
290           break
291         fi
292       done
293       IFS="$save_IFS"
294       if test -z "$self_abspathname"; then
295         func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
296       fi
297       ;;
298   esac
299   while test -h "$self_abspathname"; do
300     # Resolve symbolic link.
301     linkval=`func_readlink "$self_abspathname"`
302     test -n "$linkval" || break
303     case "$linkval" in
304       /* ) self_abspathname="$linkval" ;;
305       * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
306     esac
307   done
308   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
309 }
310
311 # func_tmpdir
312 # creates a temporary directory.
313 # Sets variable
314 # - tmp             pathname of freshly created temporary directory
315 func_tmpdir ()
316 {
317   # Use the environment variable TMPDIR, falling back to /tmp. This allows
318   # users to specify a different temporary directory, for example, if their
319   # /tmp is filled up or too small.
320   : ${TMPDIR=/tmp}
321   {
322     # Use the mktemp program if available. If not available, hide the error
323     # message.
324     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
325     test -n "$tmp" && test -d "$tmp"
326   } ||
327   {
328     # Use a simple mkdir command. It is guaranteed to fail if the directory
329     # already exists.  $RANDOM is bash specific and expands to empty in shells
330     # other than bash, ksh and zsh.  Its use does not increase security;
331     # rather, it minimizes the probability of failure in a very cluttered /tmp
332     # directory.
333     tmp=$TMPDIR/gl$$-$RANDOM
334     (umask 077 && mkdir "$tmp")
335   } ||
336   {
337     echo "$0: cannot create a temporary directory in $TMPDIR" >&2
338     func_exit 1
339   }
340 }
341
342 # func_append var value
343 # appends the given value to the shell variable var.
344 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
345   # Use bash's += operator. It reduces complexity of appending repeatedly to
346   # a single variable from O(n^2) to O(n).
347   func_append ()
348   {
349     eval "$1+=\"\$2\""
350   }
351 else
352   func_append ()
353   {
354     eval "$1=\"\$$1\$2\""
355   }
356 fi
357
358 # func_fatal_error message
359 # outputs to stderr a fatal error message, and terminates the program.
360 func_fatal_error ()
361 {
362   echo "gnulib-tool: *** $1" 1>&2
363   echo "gnulib-tool: *** Stop." 1>&2
364   func_exit 1
365 }
366
367 # func_readlink SYMLINK
368 # outputs the target of the given symlink.
369 if (type -p readlink) > /dev/null 2>&1; then
370   func_readlink ()
371   {
372     # Use the readlink program from GNU coreutils.
373     readlink "$1"
374   }
375 else
376   func_readlink ()
377   {
378     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
379     # would do the wrong thing if the link target contains " -> ".
380     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
381   }
382 fi
383
384 # func_relativize DIR1 DIR2
385 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
386 # Input:
387 # - DIR1            relative pathname, relative to the current directory
388 # - DIR2            relative pathname, relative to the current directory
389 # Output:
390 # - reldir          relative pathname of DIR2, relative to DIR1
391 func_relativize ()
392 {
393   dir0=`pwd`
394   dir1="$1"
395   dir2="$2"
396   sed_first='s,^\([^/]*\)/.*$,\1,'
397   sed_rest='s,^[^/]*/*,,'
398   sed_last='s,^.*/\([^/]*\)$,\1,'
399   sed_butlast='s,/*[^/]*$,,'
400   while test -n "$dir1"; do
401     first=`echo "$dir1" | sed -e "$sed_first"`
402     if test "$first" != "."; then
403       if test "$first" = ".."; then
404         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
405         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
406       else
407         first2=`echo "$dir2" | sed -e "$sed_first"`
408         if test "$first2" = "$first"; then
409           dir2=`echo "$dir2" | sed -e "$sed_rest"`
410         else
411           dir2="../$dir2"
412         fi
413         dir0="$dir0"/"$first"
414       fi
415     fi
416     dir1=`echo "$dir1" | sed -e "$sed_rest"`
417   done
418   reldir="$dir2"
419 }
420
421 # func_relconcat DIR1 DIR2
422 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
423 # Input:
424 # - DIR1            relative pathname, relative to the current directory
425 # - DIR2            relative pathname, relative to DIR1
426 # Output:
427 # - relconcat       DIR1/DIR2, relative to the current directory
428 func_relconcat ()
429 {
430   dir1="$1"
431   dir2="$2"
432   sed_first='s,^\([^/]*\)/.*$,\1,'
433   sed_rest='s,^[^/]*/*,,'
434   sed_last='s,^.*/\([^/]*\)$,\1,'
435   sed_butlast='s,/*[^/]*$,,'
436   while true; do
437     first=`echo "$dir2" | sed -e "$sed_first"`
438     if test "$first" = "."; then
439       dir2=`echo "$dir2" | sed -e "$sed_rest"`
440       if test -z "$dir2"; then
441         relconcat="$dir1"
442         break
443       fi
444     else
445       last=`echo "$dir1" | sed -e "$sed_last"`
446       while test "$last" = "."; do
447         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
448         last=`echo "$dir1" | sed -e "$sed_last"`
449       done
450       if test -z "$dir1"; then
451         relconcat="$dir2"
452         break
453       fi
454       if test "$first" = ".."; then
455         if test "$last" = ".."; then
456           relconcat="$dir1/$dir2"
457           break
458         fi
459         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
460         dir2=`echo "$dir2" | sed -e "$sed_rest"`
461         if test -z "$dir1"; then
462           relconcat="$dir2"
463           break
464         fi
465         if test -z "$dir2"; then
466           relconcat="$dir1"
467           break
468         fi
469       else
470         relconcat="$dir1/$dir2"
471         break
472       fi
473     fi
474   done
475 }
476
477 # func_ln SRC DEST
478 # Like ln -s, except that SRC is given relative to the current directory (or
479 # absolute), not given relative to the directory of DEST.
480 func_ln ()
481 {
482   case "$1" in
483     /*)
484       ln -s "$1" "$2" ;;
485     *) # SRC is relative.
486       case "$2" in
487         /*)
488           ln -s "`pwd`/$1" "$2" ;;
489         *) # DEST is relative too.
490           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
491           test -n "$ln_destdir" || ln_destdir="."
492           func_relativize "$ln_destdir" "$1"
493           ln -s "$reldir" "$2"
494           ;;
495       esac
496       ;;
497   esac
498 }
499
500 # func_ln_if_changed SRC DEST
501 # Like func_ln, but avoids munging timestamps if the link is correct.
502 func_ln_if_changed ()
503 {
504   if test $# -ne 2; then
505     echo "usage: func_ln_if_changed SRC DEST" >&2
506   fi
507   ln_target=`func_readlink "$2"`
508   if test -h "$2" && test "$1" = "$ln_target"; then
509     :
510   else
511     rm -f "$2"
512     func_ln "$1" "$2"
513   fi
514 }
515
516 # Ensure an 'echo' command that does not interpret backslashes.
517 # Test cases:
518 #   echo '\n' | wc -l                 prints 1 when OK, 2 when KO
519 #   echo '\t' | grep t > /dev/null    has return code 0 when OK, 1 when KO
520 # This problem is a weird heritage from SVR4. BSD got it right (except that
521 # BSD echo interprets '-n' as an option, which is also not desirable).
522 # Nowadays the problem occurs in 4 situations:
523 # - in bash, when the shell option xpg_echo is set (bash >= 2.04)
524 #            or when it was built with --enable-usg-echo-default (bash >= 2.0)
525 #            or when it was built with DEFAULT_ECHO_TO_USG (bash < 2.0),
526 # - in zsh, when sh-emulation is not set,
527 # - in ksh (e.g. AIX /bin/sh and Solaris /usr/xpg4/bin/sh are ksh instances,
528 #           and HP-UX /bin/sh and IRIX /bin/sh behave similarly),
529 # - in Solaris /bin/sh and OSF/1 /bin/sh.
530 # We try the following workarounds:
531 # - for all: respawn using $CONFIG_SHELL if that is set and works.
532 # - for bash >= 2.04: unset the shell option xpg_echo.
533 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
534 # - for bash < 2.0: define echo to a function that uses cat of a here document.
535 # - for zsh: turn sh-emulation on.
536 # - for ksh: alias echo to 'print -r'.
537 # - for ksh: alias echo to a function that uses cat of a here document.
538 # - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
539 #   the ksh workaround.
540 # - otherwise: respawn using /bin/sh and rely on the workarounds.
541 # When respawning, we pass --no-reexec as first argument, so as to avoid
542 # turning this script into a fork bomb in unlucky situations.
543 have_echo=
544 if echo '\t' | grep t > /dev/null; then
545   have_echo=yes # Lucky!
546 fi
547 # Try the workarounds.
548 # Respawn using $CONFIG_SHELL if that is set and works.
549 if test -z "$have_echo" \
550    && test "X$1" != "X--no-reexec" \
551    && test -n "$CONFIG_SHELL" \
552    && test -f "$CONFIG_SHELL" \
553    && $CONFIG_SHELL -c 'echo '\t' | grep t > /dev/null'; then
554   exec $CONFIG_SHELL "$0" --no-reexec "$@"
555   exit 127
556 fi
557 # For bash >= 2.04: unset the shell option xpg_echo.
558 if test -z "$have_echo" \
559    && test -n "$BASH_VERSION" \
560    && (shopt -o xpg_echo; echo '\t' | grep t > /dev/null) 2>/dev/null; then
561   shopt -o xpg_echo
562   have_echo=yes
563 fi
564 # For bash >= 2.0: define echo to a function that uses the printf built-in.
565 # For bash < 2.0: define echo to a function that uses cat of a here document.
566 # (There is no win in using 'printf' over 'cat' if it is not a shell built-in.)
567 if test -z "$have_echo" \
568    && test -n "$BASH_VERSION"; then \
569   if type printf 2>/dev/null | grep / > /dev/null; then
570     # 'printf' is not a shell built-in.
571 echo ()
572 {
573 cat <<EOF
574 $*
575 EOF
576 }
577   else
578     # 'printf' is a shell built-in.
579 echo ()
580 {
581   printf '%s\n' "$*"
582 }
583   fi
584   if echo '\t' | grep t > /dev/null; then
585     have_echo=yes
586   fi
587 fi
588 # For zsh: turn sh-emulation on.
589 if test -z "$have_echo" \
590    && test -n "$ZSH_VERSION" \
591    && (emulate sh) >/dev/null 2>&1; then
592   emulate sh
593 fi
594 # For ksh: alias echo to 'print -r'.
595 if test -z "$have_echo" \
596    && (type print) >/dev/null 2>&1; then
597   # A 'print' command exists.
598   if type print 2>/dev/null | grep / > /dev/null; then
599     :
600   else
601     # 'print' is a shell built-in.
602     if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
603       # 'print' is the ksh shell built-in.
604       alias echo='print -r'
605     fi
606   fi
607 fi
608 if test -z "$have_echo" \
609    && echo '\t' | grep t > /dev/null; then
610   have_echo=yes
611 fi
612 # For ksh: alias echo to a function that uses cat of a here document.
613 # The ksh manual page says:
614 #   "Aliasing is performed when scripts are read, not while they are executed.
615 #    Therefore, for an alias to take effect, the alias definition command has
616 #    to be executed before the command which references the alias is read."
617 # Because of this, we have to play strange tricks with have_echo, to ensure
618 # that the top-level statement containing the test starts after the 'alias'
619 # command.
620 if test -z "$have_echo"; then
621 bsd_echo ()
622 {
623 cat <<EOF
624 $*
625 EOF
626 }
627 alias echo=bsd_echo 2>/dev/null
628 fi
629 if test -z "$have_echo" \
630    && echo '\t' | grep t > /dev/null; then
631   have_echo=yes
632 fi
633 if test -z "$have_echo"; then
634   unalias echo 2>/dev/null
635 fi
636 # For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
637 if test -z "$have_echo" \
638    && test "X$1" != "X--no-reexec" \
639    && test -f /bin/ksh; then
640   exec /bin/ksh "$0" --no-reexec "$@"
641   exit 127
642 fi
643 # Otherwise: respawn using /bin/sh.
644 if test -z "$have_echo" \
645    && test "X$1" != "X--no-reexec" \
646    && test -f /bin/sh; then
647   exec /bin/sh "$0" --no-reexec "$@"
648   exit 127
649 fi
650 if test -z "$have_echo"; then
651   func_fatal_error "Shell does not support 'echo' correctly. Please install GNU bash and set the environment variable CONFIG_SHELL to point to it."
652 fi
653 if echo '\t' | grep t > /dev/null; then
654   : # Works fine now.
655 else
656   func_fatal_error "Shell does not support 'echo' correctly. Workaround does not work. Please report this as a bug to bug-gnulib@gnu.org."
657 fi
658 if test "X$1" = "X--no-reexec"; then
659   shift
660 fi
661
662 # Command-line option processing.
663 # Removes the OPTIONS from the arguments. Sets the variables:
664 # - mode            list or import or create-testdir or create-megatestdir
665 # - destdir         from --dir
666 # - local_gnulib_dir  from --local-dir
667 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
668 # - libname, supplied_libname  from --lib
669 # - sourcebase      from --source-base
670 # - m4base          from --m4-base
671 # - pobase          from --po-base
672 # - docbase         from --doc-base
673 # - testsbase       from --tests-base
674 # - auxdir          from --aux-dir
675 # - inctests        true if --with-tests was given, blank otherwise
676 # - avoidlist       list of modules to avoid, from --avoid
677 # - lgpl            yes or a number if --lgpl was given, blank otherwise
678 # - makefile_name   from --makefile-name
679 # - libtool         true if --libtool was given, false if --no-libtool was
680 #                   given, blank otherwise
681 # - macro_prefix    from --macro-prefix
682 # - po_domain       from --po-domain
683 # - autoconf_minversion  minimum supported autoconf version
684 # - do_changelog    false if --no-changelog was given, : otherwise
685 # - doit            : if actions shall be executed, false if only to be printed
686 # - symbolic        true if --symlink or --more-symlinks was given, blank
687 #                   otherwise
688 # - lsymbolic       true if --local-symlink was given, blank otherwise
689 # - do_copyrights   blank if --more-symlinks was given, true otherwise
690 {
691   mode=
692   destdir=
693   local_gnulib_dir=
694   verbose=0
695   libname=libgnu
696   supplied_libname=
697   sourcebase=
698   m4base=
699   pobase=
700   docbase=
701   testsbase=
702   auxdir=
703   inctests=
704   avoidlist=
705   lgpl=
706   makefile_name=
707   libtool=
708   macro_prefix=
709   po_domain=
710   do_changelog=:
711   doit=:
712   symbolic=
713   lsymbolic=
714   do_copyrights=true
715
716   supplied_opts="$@"
717
718   while test $# -gt 0; do
719     case "$1" in
720       --list | --lis )
721         mode=list
722         shift ;;
723       --import | --impor | --impo | --imp | --im | --i )
724         mode=import
725         shift ;;
726       --update | --updat | --upda | --upd | --up | --u )
727         mode=update
728         shift ;;
729       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
730         mode=create-testdir
731         shift ;;
732       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
733         mode=create-megatestdir
734         shift ;;
735       --test | --tes | --te | --t )
736         mode=test
737         shift ;;
738       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
739         mode=megatest
740         shift ;;
741       --extract-* )
742         mode=`echo "X$1" | sed -e 's/^X--//'`
743         shift ;;
744       --dir )
745         shift
746         if test $# = 0; then
747           func_fatal_error "missing argument for --dir"
748         fi
749         destdir=$1
750         shift ;;
751       --dir=* )
752         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
753         shift ;;
754       --local-dir )
755         shift
756         if test $# = 0; then
757           func_fatal_error "missing argument for --local-dir"
758         fi
759         local_gnulib_dir=$1
760         shift ;;
761       --local-dir=* )
762         local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
763         shift ;;
764       --verbose | --verbos | --verbo | --verb )
765         verbose=`expr $verbose + 1`
766         shift ;;
767       --quiet | --quie | --qui | --qu | --q )
768         verbose=`expr $verbose - 1`
769         shift ;;
770       --lib )
771         shift
772         if test $# = 0; then
773           func_fatal_error "missing argument for --lib"
774         fi
775         libname=$1
776         supplied_libname=true
777         shift ;;
778       --lib=* )
779         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
780         supplied_libname=true
781         shift ;;
782       --source-base )
783         shift
784         if test $# = 0; then
785           func_fatal_error "missing argument for --source-base"
786         fi
787         sourcebase=$1
788         shift ;;
789       --source-base=* )
790         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
791         shift ;;
792       --m4-base )
793         shift
794         if test $# = 0; then
795           func_fatal_error "missing argument for --m4-base"
796         fi
797         m4base=$1
798         shift ;;
799       --m4-base=* )
800         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
801         shift ;;
802       --po-base )
803         shift
804         if test $# = 0; then
805           func_fatal_error "missing argument for --po-base"
806         fi
807         pobase=$1
808         shift ;;
809       --po-base=* )
810         pobase=`echo "X$1" | sed -e 's/^X--po-base=//'`
811         shift ;;
812       --doc-base )
813         shift
814         if test $# = 0; then
815           func_fatal_error "missing argument for --doc-base"
816         fi
817         docbase=$1
818         shift ;;
819       --doc-base=* )
820         docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
821         shift ;;
822       --tests-base )
823         shift
824         if test $# = 0; then
825           func_fatal_error "missing argument for --tests-base"
826         fi
827         testsbase=$1
828         shift ;;
829       --tests-base=* )
830         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
831         shift ;;
832       --aux-dir )
833         shift
834         if test $# = 0; then
835           func_fatal_error "missing argument for --aux-dir"
836         fi
837         auxdir=$1
838         shift ;;
839       --aux-dir=* )
840         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
841         shift ;;
842       --with-tests )
843         inctests=true
844         shift ;;
845       --avoid )
846         shift
847         if test $# = 0; then
848           func_fatal_error "missing argument for --avoid"
849         fi
850         func_append avoidlist " $1"
851         shift ;;
852       --avoid=* )
853         arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
854         func_append avoidlist " $arg"
855         shift ;;
856       --lgpl )
857         lgpl=yes
858         shift ;;
859       --lgpl=* )
860         arg=`echo "X$1" | sed -e 's/^X--lgpl=//'`
861         case "$arg" in
862           2 | 3) ;;
863           *) func_fatal_error "invalid LGPL version number for --lgpl" ;;
864         esac
865         lgpl=$arg
866         shift ;;
867       --makefile-name )
868         shift
869         if test $# = 0; then
870           func_fatal_error "missing argument for --makefile-name"
871         fi
872         makefile_name="$1"
873         shift ;;
874       --makefile-name=* )
875         makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
876         shift ;;
877       --libtool )
878         libtool=true
879         shift ;;
880       --no-libtool )
881         libtool=false
882         shift ;;
883       --macro-prefix )
884         shift
885         if test $# = 0; then
886           func_fatal_error "missing argument for --macro-prefix"
887         fi
888         macro_prefix="$1"
889         shift ;;
890       --macro-prefix=* )
891         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
892         shift ;;
893       --po-domain )
894         shift
895         if test $# = 0; then
896           func_fatal_error "missing argument for --po-domain"
897         fi
898         po_domain="$1"
899         shift ;;
900       --po-domain=* )
901         po_domain=`echo "X$1" | sed -e 's/^X--po-domain=//'`
902         shift ;;
903       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
904         do_changelog=false
905         shift ;;
906       --dry-run )
907         doit=false
908         shift ;;
909       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
910         symbolic=true
911         shift ;;
912       --local-symlink | --local-symlin | --local-symli | --local-syml | --local-sym | --local-sy | --local-s )
913         lsymbolic=true
914         shift ;;
915       -S | --more-symlinks | --more-symlink | --more-symlin | --more-symli | --more-syml | --more-sym | --more-sy | --more-s | --more- | --more | --mor | --mo )
916         symbolic=true
917         do_copyrights=
918         shift ;;
919       --help | --hel | --he | --h )
920         func_usage
921         func_exit $? ;;
922       --version | --versio | --versi | --vers )
923         func_version
924         func_exit $? ;;
925       -- )
926         # Stop option processing
927         shift
928         break ;;
929       -* )
930         echo "gnulib-tool: unknown option $1" 1>&2
931         echo "Try 'gnulib-tool --help' for more information." 1>&2
932         func_exit 1 ;;
933       * )
934         break ;;
935     esac
936   done
937
938   if test "$mode" = update; then
939     if test $# != 0; then
940       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
941       echo "Try 'gnulib-tool --help' for more information." 1>&2
942       echo "If you really want to modify the gnulib configuration of your project," 1>&2
943       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
944       func_exit 1
945     fi
946     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
947        || test -n "$sourcebase" || test -n "$m4base" || test -n "$pobase" \
948        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
949        || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
950        || test -n "$makefile_name" || test -n "$macro_prefix" \
951        || test -n "$po_domain"; then
952       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
953       echo "Try 'gnulib-tool --help' for more information." 1>&2
954       echo "If you really want to modify the gnulib configuration of your project," 1>&2
955       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
956       func_exit 1
957     fi
958     do_changelog=false
959   fi
960   if test -n "$pobase" && test -z "$po_domain"; then
961     echo "gnulib-tool: together with --po-base, you need to specify --po-domain" 1>&2
962     echo "Try 'gnulib-tool --help' for more information." 1>&2
963     func_exit 1
964   fi
965   if test -z "$pobase" && test -n "$po_domain"; then
966     echo "gnulib-tool: warning: --po-domain has no effect without a --po-base option" 1>&2
967   fi
968
969   # Determine the minimum supported autoconf version from the project's
970   # configure.ac.
971   DEFAULT_AUTOCONF_MINVERSION="2.59"
972   autoconf_minversion=
973   configure_ac=
974   if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
975     if test -f "$destdir"/configure.ac; then
976       configure_ac="$destdir/configure.ac"
977     else
978       if test -f "$destdir"/configure.in; then
979         configure_ac="$destdir/configure.in"
980       fi
981     fi
982   else
983     if test -f configure.ac; then
984       configure_ac="configure.ac"
985     else
986       if test -f configure.in; then
987         configure_ac="configure.in"
988       fi
989     fi
990   fi
991   if test -n "$configure_ac"; then
992     # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
993     # because when some m4 files are omitted from a CVS repository,
994     # "autoconf --trace=AC_PREREQ" fails with an error message like this:
995     #   m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
996     #   autom4te: m4 failed with exit status: 1
997     prereqs=
998     my_sed_traces='
999       s,#.*$,,
1000       s,^dnl .*$,,
1001       s, dnl .*$,,
1002       /AC_PREREQ/ {
1003         s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,\1,p
1004       }'
1005     prereqs=`sed -n -e "$my_sed_traces" < "$configure_ac"`
1006     if test -n "$prereqs"; then
1007       autoconf_minversion=`
1008         for version in $prereqs; do echo $version; done |
1009         LC_ALL=C sort -nru | sed 1q
1010       `
1011     fi
1012   fi
1013   if test -z "$autoconf_minversion"; then
1014     autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
1015   fi
1016   case "$autoconf_minversion" in
1017     1.* | 2.[0-4]* | 2.5[0-8]*)
1018       func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
1019   esac
1020
1021   # Remove trailing slashes from the directory names. This is necessary for
1022   # m4base (to avoid an error in func_import) and optional for the others.
1023   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
1024   case "$local_gnulib_dir" in
1025     */ ) local_gnulib_dir=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
1026   esac
1027   case "$sourcebase" in
1028     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
1029   esac
1030   case "$m4base" in
1031     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
1032   esac
1033   case "$pobase" in
1034     */ ) pobase=`echo "$pobase" | sed -e "$sed_trimtrailingslashes"` ;;
1035   esac
1036   case "$docbase" in
1037     */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
1038   esac
1039   case "$testsbase" in
1040     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
1041   esac
1042   case "$auxdir" in
1043     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
1044   esac
1045 }
1046
1047 func_gnulib_dir
1048 func_tmpdir
1049 trap 'exit_status=$?
1050       if test "$signal" != 0; then
1051         echo "caught signal $signal" >&2
1052       fi
1053       rm -rf "$tmp"
1054       exit $exit_status' 0
1055 for signal in 1 2 3 13 15; do
1056   trap '{ signal='$signal'; func_exit 1; }' $signal
1057 done
1058 signal=0
1059
1060 # func_lookup_file file
1061 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
1062 # 'patch'.
1063 # Input:
1064 # - local_gnulib_dir  from --local-dir
1065 # Output:
1066 # - lookedup_file   name of the merged (combined) file
1067 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
1068 func_lookup_file ()
1069 {
1070   lkfile="$1"
1071   if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
1072     lookedup_file="$local_gnulib_dir/$lkfile"
1073     lookedup_tmp=
1074   else
1075     if test -f "$gnulib_dir/$lkfile"; then
1076       if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
1077         lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
1078         rm -f "$tmp/$lkbase"
1079         cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
1080         patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
1081           || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
1082         lookedup_file="$tmp/$lkbase"
1083         lookedup_tmp=true
1084       else
1085         lookedup_file="$gnulib_dir/$lkfile"
1086         lookedup_tmp=
1087       fi
1088     else
1089       func_fatal_error "file $gnulib_dir/$lkfile not found"
1090     fi
1091   fi
1092 }
1093
1094 # func_all_modules
1095 # Input:
1096 # - local_gnulib_dir  from --local-dir
1097 func_all_modules ()
1098 {
1099   # Filter out metainformation files like README, which are not modules.
1100   # Filter out unit test modules; they can be retrieved through
1101   # --extract-tests-module if desired.
1102   {
1103     (cd "$gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,')
1104     if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
1105       (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,')
1106     fi
1107   } \
1108       | sed -e '/^CVS\//d' -e '/\/CVS\//d' \
1109             -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
1110             -e '/^COPYING$/d' -e '/\/COPYING$/d' \
1111             -e '/^README$/d' -e '/\/README$/d' \
1112             -e '/^TEMPLATE$/d' \
1113             -e '/^TEMPLATE-EXTENDED$/d' \
1114             -e '/^TEMPLATE-TESTS$/d' \
1115             -e '/^\..*/d' \
1116             -e '/~$/d' \
1117       | sed -e '/-tests$/d' \
1118       | LC_ALL=C sort -u
1119 }
1120
1121 # func_verify_module
1122 # verifies a module name
1123 # Input:
1124 # - local_gnulib_dir  from --local-dir
1125 # - module          module name argument
1126 func_verify_module ()
1127 {
1128   if { test -f "$gnulib_dir/modules/$module" \
1129        || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1130             && test -f "$local_gnulib_dir/modules/$module"; }; } \
1131      && test "CVS" != "$module" \
1132      && test "ChangeLog" != "$module" \
1133      && test "COPYING" != "$module" \
1134      && test "README" != "$module" \
1135      && test "TEMPLATE" != "$module" \
1136      && test "TEMPLATE-EXTENDED" != "$module" \
1137      && test "TEMPLATE-TESTS" != "$module"; then
1138     # OK, $module is a correct module name.
1139     # Verify that building the module description with 'patch' succeeds.
1140     func_lookup_file "modules/$module"
1141   else
1142     echo "gnulib-tool: module $module doesn't exist" 1>&2
1143     module=
1144   fi
1145 }
1146
1147 # func_verify_nontests_module
1148 # verifies a module name, excluding tests modules
1149 # Input:
1150 # - local_gnulib_dir  from --local-dir
1151 # - module          module name argument
1152 func_verify_nontests_module ()
1153 {
1154   case "$module" in
1155     *-tests ) module= ;;
1156     * ) func_verify_module ;;
1157   esac
1158 }
1159
1160 # func_verify_tests_module
1161 # verifies a module name, considering only tests modules
1162 # Input:
1163 # - local_gnulib_dir  from --local-dir
1164 # - module          module name argument
1165 func_verify_tests_module ()
1166 {
1167   case "$module" in
1168     *-tests ) func_verify_module ;;
1169     * ) module= ;;
1170   esac
1171 }
1172
1173 sed_extract_prog=':[     ]*$/ {
1174   :a
1175     n
1176     s/^Description:[     ]*$//
1177     s/^Notice:[  ]*$//
1178     s/^Files:[   ]*$//
1179     s/^Depends-on:[      ]*$//
1180     s/^configure\.ac-early:[     ]*$//
1181     s/^configure\.ac:[   ]*$//
1182     s/^Makefile\.am:[    ]*$//
1183     s/^Include:[         ]*$//
1184     s/^Link:[    ]*$//
1185     s/^License:[         ]*$//
1186     s/^Maintainer:[      ]*$//
1187     tb
1188     p
1189     ba
1190   :b
1191 }'
1192
1193 # func_get_description module
1194 # Input:
1195 # - local_gnulib_dir  from --local-dir
1196 func_get_description ()
1197 {
1198   func_lookup_file "modules/$1"
1199   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
1200 }
1201
1202 # func_get_notice module
1203 # Input:
1204 # - local_gnulib_dir  from --local-dir
1205 func_get_notice ()
1206 {
1207   func_lookup_file "modules/$1"
1208   sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"
1209 }
1210
1211 # func_get_filelist module
1212 # Input:
1213 # - local_gnulib_dir  from --local-dir
1214 func_get_filelist ()
1215 {
1216   func_lookup_file "modules/$1"
1217   sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
1218   echo m4/gnulib-common.m4
1219   case "$autoconf_minversion" in
1220     2.59)
1221       #echo m4/onceonly.m4
1222       echo m4/onceonly_2_57.m4
1223       ;;
1224   esac
1225 }
1226
1227 # func_get_dependencies module
1228 # Input:
1229 # - local_gnulib_dir  from --local-dir
1230 func_get_dependencies ()
1231 {
1232   # ${module}-tests always implicitly depends on ${module}.
1233   echo "$1" | sed -n -e 's/-tests$//p'
1234   # Then the explicit dependencies listed in the module description.
1235   func_lookup_file "modules/$1"
1236   sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
1237 }
1238
1239 # func_get_autoconf_early_snippet module
1240 # Input:
1241 # - local_gnulib_dir  from --local-dir
1242 func_get_autoconf_early_snippet ()
1243 {
1244   func_lookup_file "modules/$1"
1245   sed -n -e "/^configure\.ac-early$sed_extract_prog" < "$lookedup_file"
1246 }
1247
1248 # func_get_autoconf_snippet module
1249 # Input:
1250 # - local_gnulib_dir  from --local-dir
1251 func_get_autoconf_snippet ()
1252 {
1253   func_lookup_file "modules/$1"
1254   sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
1255 }
1256
1257 # func_get_automake_snippet module
1258 # Input:
1259 # - local_gnulib_dir  from --local-dir
1260 func_get_automake_snippet ()
1261 {
1262   func_lookup_file "modules/$1"
1263   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
1264   case "$1" in
1265     *-tests)
1266       # *-tests module live in tests/, not lib/.
1267       # Synthesize an EXTRA_DIST augmentation.
1268       all_files=`func_get_filelist $1`
1269       tests_files=`for f in $all_files; do \
1270                      case $f in \
1271                        tests/*) echo $f ;; \
1272                      esac; \
1273                    done | sed -e 's,^tests/,,'`
1274       extra_files="$tests_files"
1275       if test -n "$extra_files"; then
1276         echo "EXTRA_DIST +=" $extra_files
1277         echo
1278       fi
1279       ;;
1280     *)
1281       # Synthesize an EXTRA_DIST augmentation.
1282       sed_combine_lines='/\\$/{
1283         :a
1284         N
1285         s/\\\n/ /
1286         s/\\$/\\/
1287         ta
1288       }'
1289       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
1290       already_mentioned_files=` \
1291         sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
1292         | sed -e "$sed_combine_lines" \
1293         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
1294       all_files=`func_get_filelist $1`
1295       lib_files=`for f in $all_files; do \
1296                    case $f in \
1297                      lib/*) echo $f ;; \
1298                    esac; \
1299                  done | sed -e 's,^lib/,,'`
1300       # Remove $already_mentioned_files from $lib_files.
1301       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
1302       extra_files=`for f in $already_mentioned_files; do echo $f; done \
1303                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
1304       if test -n "$extra_files"; then
1305         echo "EXTRA_DIST +=" $extra_files
1306         echo
1307       fi
1308       # Synthesize also an EXTRA_lib_SOURCES augmentation.
1309       # This is necessary so that automake can generate the right list of
1310       # dependency rules.
1311       # A possible approach would be to use autom4te --trace of the redefined
1312       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
1313       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
1314       # inside autoconf's built-in macros are not missed).
1315       # But it's simpler and more robust to do it here, based on the file list.
1316       # If some .c file exists and is not used with AC_LIBOBJ - for example,
1317       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
1318       # automake will generate a useless dependency; this is harmless.
1319       case "$1" in
1320         relocatable-prog-wrapper) ;;
1321         *)
1322           sed_extract_c_files='/\.c$/p'
1323           extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
1324           if test -n "$extra_files"; then
1325             echo "EXTRA_lib_SOURCES +=" $extra_files
1326             echo
1327           fi
1328           ;;
1329       esac
1330       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
1331       buildaux_files=`for f in $all_files; do \
1332                         case $f in \
1333                           build-aux/*) echo $f ;; \
1334                         esac; \
1335                       done | sed -e 's,^build-aux/,,'`
1336       if test -n "$buildaux_files"; then
1337         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
1338         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
1339         echo
1340       fi
1341       ;;
1342   esac
1343 }
1344
1345 # func_get_include_directive module
1346 # Input:
1347 # - local_gnulib_dir  from --local-dir
1348 func_get_include_directive ()
1349 {
1350   func_lookup_file "modules/$1"
1351   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1352   sed -e 's/^\(["<]\)/#include \1/'
1353 }
1354
1355 # func_get_link_directive module
1356 # Input:
1357 # - local_gnulib_dir  from --local-dir
1358 func_get_link_directive ()
1359 {
1360   func_lookup_file "modules/$1"
1361   sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
1362 }
1363
1364 # func_get_license module
1365 # Input:
1366 # - local_gnulib_dir  from --local-dir
1367 func_get_license ()
1368 {
1369   func_lookup_file "modules/$1"
1370   { sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1371     # The default is GPL.
1372     echo "GPL"
1373   } | sed -e 's,^ *$,,' | sed -e 1q
1374 }
1375
1376 # func_get_maintainer module
1377 # Input:
1378 # - local_gnulib_dir  from --local-dir
1379 func_get_maintainer ()
1380 {
1381   func_lookup_file "modules/$1"
1382   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1383 }
1384
1385 # func_get_tests_module module
1386 # Input:
1387 # - local_gnulib_dir  from --local-dir
1388 func_get_tests_module ()
1389 {
1390   # The naming convention for tests modules is hardwired: ${module}-tests.
1391   if test -f "$gnulib_dir/modules/$1"-tests \
1392      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1393           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1394     echo "$1"-tests
1395   fi
1396 }
1397
1398 # func_acceptable module
1399 # tests whether a module is acceptable.
1400 # Input:
1401 # - avoidlist       list of modules to avoid
1402 func_acceptable ()
1403 {
1404   for avoid in $avoidlist; do
1405     if test "$avoid" = "$1"; then
1406       return 1
1407     fi
1408   done
1409   return 0
1410 }
1411
1412 # func_modules_transitive_closure
1413 # Input:
1414 # - local_gnulib_dir  from --local-dir
1415 # - modules         list of specified modules
1416 # - inctests        true if tests should be included, blank otherwise
1417 # - avoidlist       list of modules to avoid
1418 # - tmp             pathname of a temporary directory
1419 # Output:
1420 # - modules         list of modules, including dependencies
1421 func_modules_transitive_closure ()
1422 {
1423   # In order to process every module only once (for speed), process an "input
1424   # list" of modules, producing an "output list" of modules. During each round,
1425   # more modules can be queued in the input list. Once a module on the input
1426   # list has been processed, it is added to the "handled list", so we can avoid
1427   # to process it again.
1428   handledmodules=
1429   inmodules="$modules"
1430   outmodules=
1431   while test -n "$inmodules"; do
1432     inmodules_this_round="$inmodules"
1433     inmodules=                    # Accumulator, queue for next round
1434     for module in $inmodules_this_round; do
1435       func_verify_module
1436       if test -n "$module"; then
1437         if func_acceptable $module; then
1438           func_append outmodules " $module"
1439           deps=`func_get_dependencies $module`
1440           # Duplicate dependencies are harmless, but Jim wants a warning.
1441           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1442           if test -n "$duplicated_deps"; then
1443             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1444           fi
1445           func_append inmodules " $deps"
1446           if test -n "$inctests"; then
1447             testsmodule=`func_get_tests_module $module`
1448             if test -n "$testsmodule"; then
1449               func_append inmodules " $testsmodule"
1450             fi
1451           fi
1452         fi
1453       fi
1454     done
1455     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1456     # Remove $handledmodules from $inmodules.
1457     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1458     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1459   done
1460   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1461   rm -f "$tmp"/queued-modules
1462 }
1463
1464 # func_modules_add_dummy
1465 # Input:
1466 # - local_gnulib_dir  from --local-dir
1467 # - modules         list of modules, including dependencies
1468 # Output:
1469 # - modules         list of modules, including 'dummy' if needed
1470 func_modules_add_dummy ()
1471 {
1472   have_lib_SOURCES=
1473   sed_remove_backslash_newline=':a
1474 /\\$/{
1475 s/\\$//
1476 N
1477 s/\n//
1478 ba
1479 }'
1480   for module in $modules; do
1481     func_verify_nontests_module
1482     if test -n "$module"; then
1483       # Extract the value of "lib_SOURCES += ...".
1484       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1485         # Ignore .h files since they are not compiled.
1486         case "$file" in
1487           *.h) ;;
1488           *) have_lib_SOURCES=yes ;;
1489         esac
1490       done
1491     fi
1492   done
1493   # Add the dummy module, to make sure the library will be non-empty.
1494   if test -z "$have_lib_SOURCES"; then
1495     if func_acceptable "dummy"; then
1496       func_append modules " dummy"
1497     fi
1498   fi
1499 }
1500
1501 # func_modules_notice
1502 # Input:
1503 # - local_gnulib_dir  from --local-dir
1504 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1505 # - modules         list of modules, including dependencies
1506 func_modules_notice ()
1507 {
1508   if test $verbose -ge -1; then
1509     for module in $modules; do
1510       func_verify_module
1511       if test -n "$module"; then
1512         msg=`func_get_notice $module`
1513         if test -n "$msg"; then
1514           echo "Notice from module $module:"
1515           echo "$msg" | sed -e 's/^/  /'
1516         fi
1517       fi
1518     done
1519   fi
1520 }
1521
1522 # func_modules_to_filelist
1523 # Input:
1524 # - local_gnulib_dir  from --local-dir
1525 # - modules         list of modules, including dependencies
1526 # Output:
1527 # - files           list of files
1528 func_modules_to_filelist ()
1529 {
1530   files=
1531   for module in $modules; do
1532     func_verify_module
1533     if test -n "$module"; then
1534       fs=`func_get_filelist $module`
1535       func_append files " $fs"
1536     fi
1537   done
1538   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1539 }
1540
1541 # func_execute_command command [args...]
1542 # Executes a command.
1543 # Uses also the variables
1544 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1545 func_execute_command ()
1546 {
1547   if test $verbose -ge 0; then
1548     echo "executing $*"
1549     "$@"
1550   else
1551     # Commands like automake produce output to stderr even when the succeed.
1552     # Turn this output off if the command succeeds.
1553     "$@" > "$tmp"/cmdout 2>&1
1554     cmdret=$?
1555     if test $cmdret = 0; then
1556       rm -f "$tmp"/cmdout
1557     else
1558       echo "executing $*"
1559       cat "$tmp"/cmdout 1>&2
1560       rm -f "$tmp"/cmdout
1561       (exit $cmdret)
1562     fi
1563   fi
1564 }
1565
1566 # func_emit_lib_Makefile_am
1567 # emits the contents of library makefile to standard output.
1568 # Input:
1569 # - local_gnulib_dir  from --local-dir
1570 # - modules         list of modules, including dependencies
1571 # - libname         library name
1572 # - pobase          directory relative to destdir where to place *.po files
1573 # - auxdir          directory relative to destdir where to place build aux files
1574 # - makefile_name   from --makefile-name
1575 # - libtool         true if libtool will be used, false or blank otherwise
1576 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1577 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
1578 # - actioncmd       (optional) command that will reproduce this invocation
1579 # - for_test        true if creating a package for testing, false otherwise
1580 # Output:
1581 # - uses_subdirs    nonempty if object files in subdirs exist
1582 func_emit_lib_Makefile_am ()
1583 {
1584   # When creating an includable Makefile.am snippet, augment variables with
1585   # += instead of assigning them.
1586   if test -n "$makefile_name"; then
1587     assign='+='
1588   else
1589     assign='='
1590   fi
1591   if test "$libtool" = true; then
1592     libext=la
1593     perhapsLT=LT
1594     sed_eliminate_LDFLAGS=
1595   else
1596     libext=a
1597     perhapsLT=
1598     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1599   fi
1600   if $for_test; then
1601     # When creating a package for testing: Attempt to provoke failures,
1602     # especially link errors, already during "make" rather than during
1603     # "make check", because "make check" is not possible in a cross-compiling
1604     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1605     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1606   else
1607     sed_transform_check_PROGRAMS=
1608   fi
1609   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1610   echo "## Process this file with automake to produce Makefile.in."
1611   func_emit_copyright_notice
1612   if test -n "$actioncmd"; then
1613     echo "# Reproduce by: $actioncmd"
1614   fi
1615   echo
1616   uses_subdirs=
1617   {
1618     for module in $modules; do
1619       func_verify_nontests_module
1620       if test -n "$module"; then
1621         {
1622           func_get_automake_snippet "$module" |
1623             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1624                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1625                 -e "$sed_eliminate_LDFLAGS" \
1626                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1627                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1628                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1629                 -e "$sed_transform_check_PROGRAMS"
1630           if test "$module" = 'alloca'; then
1631             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1632             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1633           fi
1634         } > amsnippet.tmp
1635         # Skip the contents if its entirely empty.
1636         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1637           echo "## begin gnulib module $module"
1638           echo
1639           cat amsnippet.tmp
1640           echo "## end   gnulib module $module"
1641           echo
1642         fi
1643         rm -f amsnippet.tmp
1644         # Test whether there are some source files in subdirectories.
1645         for f in `func_get_filelist "$module"`; do
1646           case $f in
1647             lib/*/*.c) uses_subdirs=yes ;;
1648           esac
1649         done
1650       fi
1651     done
1652   } > allsnippets.tmp
1653   if test -z "$makefile_name"; then
1654     # If there are source files in subdirectories, prevent collision of the
1655     # object files (example: hash.c and libxml/hash.c).
1656     subdir_options=
1657     if test -n "$uses_subdirs"; then
1658       subdir_options=' subdir-objects'
1659     fi
1660     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1661   fi
1662   echo
1663   if test -z "$makefile_name"; then
1664     echo "noinst_HEADERS ="
1665     echo "noinst_LIBRARIES ="
1666     echo "noinst_LTLIBRARIES ="
1667     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1668     # if you specify pkgdata_DATA to empty. This is a workaround.
1669     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1670       echo "pkgdata_DATA ="
1671     fi
1672     echo "EXTRA_DIST ="
1673     echo "BUILT_SOURCES ="
1674     echo "SUFFIXES ="
1675   fi
1676   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1677   if test -z "$makefile_name"; then
1678     echo "MOSTLYCLEANDIRS ="
1679     echo "CLEANFILES ="
1680     echo "DISTCLEANFILES ="
1681     echo "MAINTAINERCLEANFILES ="
1682     echo
1683     echo "AM_CPPFLAGS ="
1684   fi
1685   echo
1686   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1687     # One of the snippets already specifies an installation location for the
1688     # library. Don't confuse automake by saying it should not be installed.
1689     :
1690   else
1691     # By default, the generated library should not be installed.
1692     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1693   fi
1694   echo
1695   echo "${libname}_${libext}_SOURCES ="
1696   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1697   # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1698   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1699   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1700   echo "EXTRA_${libname}_${libext}_SOURCES ="
1701   if test "$libtool" = true; then
1702     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1703   fi
1704   echo
1705   if test -n "$pobase"; then
1706     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
1707     echo
1708   fi
1709   cat allsnippets.tmp \
1710     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1711   echo
1712   echo "mostlyclean-local: mostlyclean-generic"
1713   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1714   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1715   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1716   echo "          fi; \\"
1717   echo "        done; \\"
1718   echo "        :"
1719   rm -f allsnippets.tmp
1720 }
1721
1722 # func_emit_po_Makevars
1723 # emits the contents of po/ makefile parametrization to standard output.
1724 # Input:
1725 # - local_gnulib_dir  from --local-dir
1726 # - sourcebase      directory relative to destdir where to place source code
1727 # - pobase          directory relative to destdir where to place *.po files
1728 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
1729 func_emit_po_Makevars ()
1730 {
1731   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1732   func_emit_copyright_notice
1733   echo
1734   echo "# Usually the message domain is the same as the package name."
1735   echo "# But here it has a '-gnulib' suffix."
1736   echo "DOMAIN = ${po_domain}-gnulib"
1737   echo
1738   echo "# These two variables depend on the location of this directory."
1739   echo "subdir = ${pobase}"
1740   echo "top_builddir = "`echo "$pobase" | sed -e 's,//*,/,g' -e 's,[^/][^/]*,..,g'`
1741   echo
1742   cat <<\EOF
1743 # These options get passed to xgettext.
1744 XGETTEXT_OPTIONS = \
1745   --keyword=_ --flag=_:1:pass-c-format \
1746   --keyword=N_ --flag=N_:1:pass-c-format \
1747   --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \
1748   --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \
1749   --flag=error:3:c-format --flag=error_at_line:5:c-format
1750
1751 # This is the copyright holder that gets inserted into the header of the
1752 # $(DOMAIN).pot file.  gnulib is copyrighted by the FSF.
1753 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
1754
1755 # This is the email address or URL to which the translators shall report
1756 # bugs in the untranslated strings:
1757 # - Strings which are not entire sentences, see the maintainer guidelines
1758 #   in the GNU gettext documentation, section 'Preparing Strings'.
1759 # - Strings which use unclear terms or require additional context to be
1760 #   understood.
1761 # - Strings which make invalid assumptions about notation of date, time or
1762 #   money.
1763 # - Pluralisation problems.
1764 # - Incorrect English spelling.
1765 # - Incorrect formatting.
1766 # It can be your email address, or a mailing list address where translators
1767 # can write to without being subscribed, or the URL of a web page through
1768 # which the translators can contact you.
1769 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
1770
1771 # This is the list of locale categories, beyond LC_MESSAGES, for which the
1772 # message catalogs shall be used.  It is usually empty.
1773 EXTRA_LOCALE_CATEGORIES =
1774
1775 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
1776 # context.  Possible values are "yes" and "no".  Set this to yes if the
1777 # package uses functions taking also a message context, like pgettext(), or
1778 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
1779 USE_MSGCTXT = no
1780 EOF
1781 }
1782
1783 # func_emit_po_POTFILES_in
1784 # emits the file list to be passed to xgettext to standard output.
1785 # Input:
1786 # - local_gnulib_dir  from --local-dir
1787 # - sourcebase      directory relative to destdir where to place source code
1788 # - files           list of new files
1789 func_emit_po_POTFILES_in ()
1790 {
1791   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1792   func_emit_copyright_notice
1793   echo
1794   echo "# List of files which contain translatable strings."
1795   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
1796 }
1797
1798 # func_emit_tests_Makefile_am
1799 # emits the contents of tests makefile to standard output.
1800 # Input:
1801 # - local_gnulib_dir  from --local-dir
1802 # - modules         list of modules, including dependencies
1803 # - libname         library name
1804 # - auxdir          directory relative to destdir where to place build aux files
1805 # - makefile_name   from --makefile-name
1806 # - libtool         true if libtool will be used, false or blank otherwise
1807 # - sourcebase      relative directory containing lib source code
1808 # - m4base          relative directory containing autoconf macros
1809 # - testsbase       relative directory containing unit test code
1810 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1811 # - for_test        true if creating a package for testing, false otherwise
1812 # - use_libtests    true if a libtests.a should be built, false otherwise
1813 # Output:
1814 # - uses_subdirs    nonempty if object files in subdirs exist
1815 func_emit_tests_Makefile_am ()
1816 {
1817   if test "$libtool" = true; then
1818     libext=la
1819     sed_eliminate_LDFLAGS=
1820   else
1821     libext=a
1822     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1823   fi
1824   if $for_test; then
1825     # When creating a package for testing: Attempt to provoke failures,
1826     # especially link errors, already during "make" rather than during
1827     # "make check", because "make check" is not possible in a cross-compiling
1828     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1829     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1830   else
1831     sed_transform_check_PROGRAMS=
1832   fi
1833   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1834   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1835   echo "## Process this file with automake to produce Makefile.in."
1836   func_emit_copyright_notice
1837   echo
1838   uses_subdirs=
1839   (
1840     for module in $modules; do
1841       if $for_test; then
1842         func_verify_tests_module
1843       else
1844         func_verify_module
1845       fi
1846       if test -n "$module"; then
1847         {
1848           func_get_automake_snippet "$module" |
1849             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1850                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1851                 -e "$sed_eliminate_LDFLAGS" \
1852                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
1853                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1854                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1855                 -e "$sed_transform_check_PROGRAMS"
1856           if $use_libtests && test "$module" = 'alloca'; then
1857             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
1858             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1859           fi
1860         } > amsnippet.tmp
1861         # Skip the contents if its entirely empty.
1862         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1863           echo "## begin gnulib module $module"
1864           echo
1865           cat amsnippet.tmp
1866           echo "## end   gnulib module $module"
1867           echo
1868         fi
1869         rm -f amsnippet.tmp
1870         # Test whether there are some source files in subdirectories.
1871         for f in `func_get_filelist "$module"`; do
1872           case $f in
1873             lib/*/*.c | tests/*/*.c) uses_subdirs=yes ;;
1874           esac
1875         done
1876       fi
1877     done
1878   ) > allsnippets.tmp
1879   # Generate dependencies here, since it eases the debugging of test failures.
1880   # If there are source files in subdirectories, prevent collision of the
1881   # object files (example: hash.c and libxml/hash.c).
1882   subdir_options=
1883   if test -n "$uses_subdirs"; then
1884     subdir_options=' subdir-objects'
1885   fi
1886   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
1887   echo
1888   if $for_test; then
1889     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1890     echo
1891   fi
1892   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1893   # variable is needed to avoid an error from automake:
1894   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1895   echo "SUBDIRS ="
1896   echo "TESTS ="
1897   echo "TESTS_ENVIRONMENT ="
1898   echo "noinst_PROGRAMS ="
1899   if ! $for_test; then
1900     echo "check_PROGRAMS ="
1901   fi
1902   echo "noinst_HEADERS ="
1903   echo "noinst_LIBRARIES ="
1904   if $use_libtests; then
1905     if $for_test; then
1906       echo "noinst_LIBRARIES += libtests.a"
1907     else
1908       echo "check_LIBRARIES = libtests.a"
1909     fi
1910   fi
1911   # Automake versions < 1.9b create an empty pkgdatadir at installation time
1912   # if you specify pkgdata_DATA to empty. This is a workaround.
1913   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1914     echo "pkgdata_DATA ="
1915   fi
1916   echo "EXTRA_DIST ="
1917   echo "BUILT_SOURCES ="
1918   echo "SUFFIXES ="
1919   echo "MOSTLYCLEANFILES = core *.stackdump"
1920   echo "MOSTLYCLEANDIRS ="
1921   echo "CLEANFILES ="
1922   echo "DISTCLEANFILES ="
1923   echo "MAINTAINERCLEANFILES ="
1924   echo
1925   echo "AM_CPPFLAGS = \\"
1926   echo "  -I. -I\$(srcdir) \\"
1927   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1928   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1929   echo
1930   local_ldadd_before=''
1931   local_ldadd_after=''
1932   if $use_libtests; then
1933     # All test programs need to be linked with libtests.a.
1934     # It needs to be passed to the linker before ${libname}.${libext}, since
1935     # the tests-related modules depend on the main modules.
1936     # It also needs to be passed to the linker after ${libname}.${libext}
1937     # because the latter might contain incomplete modules (such as the 'error'
1938     # module whose dependency to 'progname' is voluntarily omitted).
1939     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
1940     # not matter.
1941     local_ldadd_before=' libtests.a'
1942     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
1943   fi
1944   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
1945   echo
1946   if $use_libtests; then
1947     echo "libtests_a_SOURCES ="
1948     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1949     # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1950     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
1951     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
1952     echo "EXTRA_libtests_a_SOURCES ="
1953     # The circular dependency in LDADD requires this.
1954     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
1955     echo
1956   fi
1957   cat allsnippets.tmp \
1958     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1959   echo "# Clean up after Solaris cc."
1960   echo "clean-local:"
1961   echo "        rm -rf SunWS_cache"
1962   echo
1963   echo "mostlyclean-local: mostlyclean-generic"
1964   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1965   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1966   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1967   echo "          fi; \\"
1968   echo "        done; \\"
1969   echo "        :"
1970   rm -f allsnippets.tmp
1971 }
1972
1973 # func_emit_initmacro_start macro_prefix
1974 # emits the first few statements of the gl_INIT macro to standard output.
1975 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1976 func_emit_initmacro_start ()
1977 {
1978   macro_prefix_arg="$1"
1979   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1980   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
1981   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1982   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1983   # flexibility.)
1984   # Furthermore it avoids an automake error like this when a Makefile.am
1985   # that uses pieces of gnulib also uses $(LIBOBJ):
1986   #   automatically discovered file `error.c' should not be explicitly mentioned
1987   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
1988   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
1989   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1990   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1991   #   automatically discovered file `error.c' should not be explicitly mentioned
1992   # We let automake know about the files to be distributed through the
1993   # EXTRA_lib_SOURCES variable.
1994   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
1995 }
1996
1997 # func_emit_initmacro_end macro_prefix
1998 # emits the last few statements of the gl_INIT macro to standard output.
1999 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2000 func_emit_initmacro_end ()
2001 {
2002   macro_prefix_arg="$1"
2003   echo "  m4_popdef([AC_LIBSOURCES])"
2004   echo "  m4_popdef([AC_REPLACE_FUNCS])"
2005   echo "  m4_popdef([AC_LIBOBJ])"
2006   echo "  AC_CONFIG_COMMANDS_PRE(["
2007   echo "    ${macro_prefix_arg}_libobjs="
2008   echo "    ${macro_prefix_arg}_ltlibobjs="
2009   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
2010   echo "      # Remove the extension."
2011   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
2012   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
2013   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
2014   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
2015   echo "      done"
2016   echo "    fi"
2017   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
2018   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
2019   echo "  ])"
2020 }
2021
2022 # func_emit_initmacro_done macro_prefix sourcebase
2023 # emits a few statements after the gl_INIT macro to standard output.
2024 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2025 # - sourcebase      directory relative to destdir where to place source code
2026 func_emit_initmacro_done ()
2027 {
2028   macro_prefix_arg="$1"
2029   sourcebase_arg="$2"
2030   echo
2031   echo "# Like AC_LIBOBJ, except that the module name goes"
2032   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2033   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
2034   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
2035   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
2036   echo "])"
2037   echo
2038   echo "# m4_foreach_w is provided by autoconf-2.59c and later."
2039   echo "# This definition is to accommodate developers using versions"
2040   echo "# of autoconf older than that."
2041   echo "m4_ifndef([m4_foreach_w],"
2042   echo "  [m4_define([m4_foreach_w],"
2043   echo "    [m4_foreach([\$1], m4_split(m4_normalize([\$2]), [ ]), [\$3])])])"
2044   echo
2045   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
2046   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2047   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
2048   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
2049   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
2050   echo "])"
2051   echo
2052   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
2053   echo "# expected is derived from the gnulib-tool parametrization,"
2054   echo "# and alloca is special cased (for the alloca-opt module)."
2055   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
2056   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
2057   echo "  m4_foreach([_gl_NAME], [\$1], ["
2058   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
2059   echo "      m4_syscmd([test -r $sourcebase_arg/]_gl_NAME[ || test ! -d $sourcebase_arg])dnl"
2060   echo "      m4_if(m4_sysval, [0], [],"
2061   echo "        [AC_FATAL([missing $sourcebase_arg/]_gl_NAME)])"
2062   echo "    ])"
2063   echo "  ])"
2064   echo "])"
2065 }
2066
2067 # func_import modules
2068 # Uses also the variables
2069 # - destdir         target directory
2070 # - local_gnulib_dir  from --local-dir
2071 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2072 # - libname         library name
2073 # - sourcebase      directory relative to destdir where to place source code
2074 # - m4base          directory relative to destdir where to place *.m4 macros
2075 # - pobase          directory relative to destdir where to place *.po files
2076 # - docbase         directory relative to destdir where to place doc files
2077 # - testsbase       directory relative to destdir where to place unit test code
2078 # - auxdir          directory relative to destdir where to place build aux files
2079 # - inctests        true if --with-tests was given, blank otherwise
2080 # - avoidlist       list of modules to avoid, from --avoid
2081 # - lgpl            yes or a number if library's license shall be LGPL,
2082 #                   blank otherwise
2083 # - makefile_name   from --makefile-name
2084 # - libtool         true if --libtool was given, false if --no-libtool was
2085 #                   given, blank otherwise
2086 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
2087 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2088 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
2089 # - autoconf_minversion  minimum supported autoconf version
2090 # - doit            : if actions shall be executed, false if only to be printed
2091 # - symbolic        true if files should be symlinked, copied otherwise
2092 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
2093 #                   copied otherwise
2094 # - do_copyrights   true if copyright notices in files should be replaced,
2095 #                   blank otherwise
2096 func_import ()
2097 {
2098   # Get the cached settings.
2099   cached_local_gnulib_dir=
2100   cached_specified_modules=
2101   cached_avoidlist=
2102   cached_sourcebase=
2103   cached_m4base=
2104   cached_pobase=
2105   cached_docbase=
2106   cached_testsbase=
2107   cached_inctests=
2108   cached_libname=
2109   cached_lgpl=
2110   cached_makefile_name=
2111   cached_libtool=
2112   cached_macro_prefix=
2113   cached_po_domain=
2114   cached_files=
2115   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2116     cached_libtool=false
2117     my_sed_traces='
2118       s,#.*$,,
2119       s,^dnl .*$,,
2120       s, dnl .*$,,
2121       /gl_LOCAL_DIR(/ {
2122         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
2123       }
2124       /gl_MODULES(/ {
2125         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
2126       }
2127       /gl_AVOID(/ {
2128         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
2129       }
2130       /gl_SOURCE_BASE(/ {
2131         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
2132       }
2133       /gl_M4_BASE(/ {
2134         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
2135       }
2136       /gl_PO_BASE(/ {
2137         s,^.*gl_PO_BASE([[ ]*\([^])]*\).*$,cached_pobase="\1",p
2138       }
2139       /gl_DOC_BASE(/ {
2140         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
2141       }
2142       /gl_TESTS_BASE(/ {
2143         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
2144       }
2145       /gl_WITH_TESTS/ {
2146         s,^.*$,cached_inctests=true,p
2147       }
2148       /gl_LIB(/ {
2149         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
2150       }
2151       /gl_LGPL(/ {
2152         s,^.*gl_LGPL([[ ]*\([^])]*\).*$,cached_lgpl="\1",p
2153       }
2154       /gl_LGPL/ {
2155         s,^.*$,cached_lgpl=yes,p
2156       }
2157       /gl_MAKEFILE_NAME(/ {
2158         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
2159       }
2160       /gl_LIBTOOL/ {
2161         s,^.*$,cached_libtool=true,p
2162       }
2163       /gl_MACRO_PREFIX(/ {
2164         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
2165       }
2166       /gl_PO_DOMAIN(/ {
2167         s,^.*gl_PO_DOMAIN([[ ]*\([^])]*\).*$,cached_po_domain="\1",p
2168       }'
2169     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
2170     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2171       my_sed_traces='
2172         s,#.*$,,
2173         s,^dnl .*$,,
2174         s, dnl .*$,,
2175         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
2176           s,^.*$,cached_files=",p
2177           n
2178           ta
2179           :a
2180           s,^\]).*$,",
2181           tb
2182           p
2183           n
2184           ba
2185           :b
2186           p
2187         }'
2188       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
2189     fi
2190   fi
2191
2192   # Merge the cached settings with the specified ones.
2193   # The m4base must be the same as expected from the pathname.
2194   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
2195     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
2196   fi
2197   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
2198   # is relative to $destdir, whereas the one we use is relative to . or absolute.
2199   if test -z "$local_gnulib_dir"; then
2200     if test -n "$cached_local_gnulib_dir"; then
2201       case "$destdir" in
2202         /*)
2203           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2204         *)
2205           case "$cached_local_gnulib_dir" in
2206             /*)
2207               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2208             *)
2209               func_relconcat "$destdir" "$cached_local_gnulib_dir"
2210               local_gnulib_dir="$relconcat" ;;
2211           esac ;;
2212       esac
2213     fi
2214   fi
2215   # Append the cached and the specified module names. So that
2216   # "gnulib-tool --import foo" means to add the module foo.
2217   specified_modules="$cached_specified_modules $1"
2218   # Append the cached and the specified avoidlist. This is probably better
2219   # than dropping the cached one when --avoid is specified at least once.
2220   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
2221   avoidlist=`echo $avoidlist`
2222
2223   # The sourcebase defaults to the cached one.
2224   if test -z "$sourcebase"; then
2225     sourcebase="$cached_sourcebase"
2226     if test -z "$sourcebase"; then
2227       func_fatal_error "missing --source-base option"
2228     fi
2229   fi
2230   # The pobase defaults to the cached one.
2231   if test -z "$pobase"; then
2232     pobase="$cached_pobase"
2233   fi
2234   # The docbase defaults to the cached one.
2235   if test -z "$docbase"; then
2236     docbase="$cached_docbase"
2237     if test -z "$docbase"; then
2238       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."
2239     fi
2240   fi
2241   # The testsbase defaults to the cached one.
2242   if test -z "$testsbase"; then
2243     testsbase="$cached_testsbase"
2244     if test -z "$testsbase"; then
2245       func_fatal_error "missing --tests-base option"
2246     fi
2247   fi
2248   # Require the tests if specified either way.
2249   if test -z "$inctests"; then
2250     inctests="$cached_inctests"
2251   fi
2252   # The libname defaults to the cached one.
2253   if test -z "$supplied_libname"; then
2254     libname="$cached_libname"
2255     if test -z "$libname"; then
2256       func_fatal_error "missing --lib option"
2257     fi
2258   fi
2259   # Require LGPL if specified either way.
2260   if test -z "$lgpl"; then
2261     lgpl="$cached_lgpl"
2262   fi
2263   # The makefile_name defaults to the cached one.
2264   if test -z "$makefile_name"; then
2265     makefile_name="$cached_makefile_name"
2266   fi
2267   # Use libtool if specified either way, or if guessed.
2268   if test -z "$libtool"; then
2269     if test -n "$cached_m4base"; then
2270       libtool="$cached_libtool"
2271     else
2272       libtool="$guessed_libtool"
2273     fi
2274   fi
2275   # The macro_prefix defaults to the cached one.
2276   if test -z "$macro_prefix"; then
2277     macro_prefix="$cached_macro_prefix"
2278     if test -z "$macro_prefix"; then
2279       func_fatal_error "missing --macro-prefix option"
2280     fi
2281   fi
2282   # The po_domain defaults to the cached one.
2283   if test -z "$po_domain"; then
2284     po_domain="$cached_po_domain"
2285   fi
2286
2287   # Canonicalize the list of specified modules.
2288   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
2289
2290   # Determine final module list.
2291   modules="$specified_modules"
2292   func_modules_transitive_closure
2293   if test $verbose -ge 0; then
2294     echo "Module list with included dependencies:"
2295     echo "$modules" | sed -e 's/^/  /'
2296   fi
2297   final_modules="$modules"
2298
2299   # Determine main module list and tests-related module list separately.
2300   # The main module list is the transitive closure of the specified modules,
2301   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2302   # is specified, it will consist only of LGPLed source.
2303   # The tests-related module list is the transitive closure of the specified
2304   # modules, including tests modules, minus the main module list. Its lib/*
2305   # sources (brought in through dependencies of *-tests modules) go into
2306   # $testsbase/. It may contain GPLed source, even if --lgpl is specified.
2307   # Determine main module list.
2308   saved_inctests="$inctests"
2309   inctests=""
2310   modules="$specified_modules"
2311   func_modules_transitive_closure
2312   main_modules="$modules"
2313   inctests="$saved_inctests"
2314   if test $verbose -ge 1; then
2315     echo "Main module list:"
2316     echo "$main_modules" | sed -e 's/^/  /'
2317   fi
2318   # Determine tests-related module list.
2319   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
2320   testsrelated_modules=`echo "$main_modules" | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
2321   if test $verbose -ge 1; then
2322     echo "Tests-related module list:"
2323     echo "$testsrelated_modules" | sed -e 's/^/  /'
2324   fi
2325
2326   # Add the dummy module to the main module list if needed.
2327   modules="$main_modules"
2328   func_modules_add_dummy
2329   main_modules="$modules"
2330
2331   # Determine whether a $testsbase/libtests.a is needed.
2332   use_libtests=false
2333   for module in $testsrelated_modules; do
2334     func_verify_nontests_module
2335     if test -n "$module"; then
2336       all_files=`func_get_filelist $module`
2337       lib_files=`for f in $all_files; do \
2338                    case $f in \
2339                      lib/*) echo $f ;; \
2340                    esac; \
2341                  done | sed -e 's,^lib/,,'`
2342       if test -n "$lib_files"; then
2343         use_libtests=true
2344         break
2345       fi
2346     fi
2347   done
2348
2349   # Add the dummy module to the tests-related module list if needed.
2350   if $use_libtests; then
2351     modules="$testsrelated_modules"
2352     func_modules_add_dummy
2353     testsrelated_modules="$modules"
2354   fi
2355
2356   # If --lgpl, verify that the licenses of modules are compatible.
2357   if test -n "$lgpl"; then
2358     for module in $main_modules; do
2359       license=`func_get_license $module`
2360       case $license in
2361         'GPLed build tool') ;;
2362         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2363         *)
2364           case "$lgpl" in
2365             yes | 3)
2366               case $license in
2367                 LGPL | LGPLv2+) ;;
2368                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2369               esac
2370               ;;
2371             2)
2372               case $license in
2373                 LGPLv2+) ;;
2374                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2375               esac
2376               ;;
2377             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2378           esac
2379           ;;
2380       esac
2381     done
2382   fi
2383
2384   # Show banner notice of every module.
2385   modules="$main_modules"
2386   func_modules_notice
2387
2388   # Determine script to apply to imported library files.
2389   sed_transform_lib_file=
2390   for module in $main_modules; do
2391     if test $module = config-h; then
2392       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
2393       sed_transform_lib_file=$sed_transform_lib_file'
2394         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
2395       '
2396       break
2397     fi
2398   done
2399   sed_transform_main_lib_file="$sed_transform_lib_file"
2400   if test -n "$do_copyrights"; then
2401     if test -n "$lgpl"; then
2402       # Update license.
2403       case "$lgpl" in
2404         yes | 3)
2405           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2406             s/GNU General/GNU Lesser General/g
2407           '
2408           ;;
2409         2)
2410           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2411             s/GNU General/GNU Lesser General/g
2412             s/version [23]\([ ,]\)/version 2.1\1/g
2413           '
2414           ;;
2415         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2416       esac
2417     else
2418       # Update license.
2419       sed_transform_main_lib_file=$sed_transform_main_lib_file'
2420         s/GNU Lesser General/GNU General/g
2421         s/GNU Library General/GNU General/g
2422         s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2423       '
2424     fi
2425   fi
2426
2427   # Determine script to apply to library files that go into $testsbase/.
2428   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
2429   if test -n "$do_copyrights"; then
2430     # Update license.
2431     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
2432       s/GNU Lesser General/GNU General/g
2433       s/GNU Library General/GNU General/g
2434       s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2435     '
2436   fi
2437
2438   # Determine the final file lists.
2439   # They must be computed separately, because files in lib/* go into
2440   # $sourcebase/ if they are in the main file list but into $testsbase/
2441   # if they are in the tests-related file list. Furthermore lib/dummy.c
2442   # can be in both.
2443   # Determine final main file list.
2444   modules="$main_modules"
2445   func_modules_to_filelist
2446   main_files="$files"
2447   # Determine final tests-related file list.
2448   modules="$testsrelated_modules"
2449   func_modules_to_filelist
2450   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
2451   # Merge both file lists.
2452   sed_remove_empty_lines='/^$/d'
2453   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
2454   if test $verbose -ge 0; then
2455     echo "File list:"
2456     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
2457     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
2458   fi
2459
2460   test -n "$files" \
2461     || func_fatal_error "refusing to do nothing"
2462
2463   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2464   new_files="$files m4/gnulib-tool.m4"
2465   old_files="$cached_files"
2466   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2467     func_append old_files " m4/gnulib-tool.m4"
2468   fi
2469
2470   sed_rewrite_old_files="\
2471     s,^build-aux/,$auxdir/,
2472     s,^doc/,$cached_docbase/,
2473     s,^lib/,$cached_sourcebase/,
2474     s,^m4/,$cached_m4base/,
2475     s,^tests/,$cached_testsbase/,
2476     s,^tests=lib/,$cached_testsbase/,"
2477   sed_rewrite_new_files="\
2478     s,^build-aux/,$auxdir/,
2479     s,^doc/,$docbase/,
2480     s,^lib/,$sourcebase/,
2481     s,^m4/,$m4base/,
2482     s,^tests/,$testsbase/,
2483     s,^tests=lib/,$testsbase/,"
2484
2485   # Create directories.
2486   { echo "$sourcebase"
2487     echo "$m4base"
2488     if test -n "$pobase"; then
2489       echo "$pobase"
2490     fi
2491     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2492     if test -n "$docfiles"; then
2493       echo "$docbase"
2494     fi
2495     if test -n "$inctests"; then
2496       echo "$testsbase"
2497     fi
2498     echo "$auxdir"
2499     for f in $files; do echo $f; done \
2500       | sed -e "$sed_rewrite_new_files" \
2501       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2502       | LC_ALL=C sort -u
2503   } > "$tmp"/dirs
2504   { # Rearrange file descriptors. Needed because "while ... done < ..."
2505     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2506     exec 5<&0 < "$tmp"/dirs
2507     while read d; do
2508       if test ! -d "$destdir/$d"; then
2509         if $doit; then
2510           echo "Creating directory $destdir/$d"
2511           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2512         else
2513           echo "Create directory $destdir/$d"
2514         fi
2515       fi
2516     done
2517     exec 0<&5 5<&-
2518   }
2519
2520   # func_dest_tmpfilename file
2521   # determines the name of a temporary file (file is relative to destdir).
2522   # Sets variable:
2523   #   - tmpfile       absolute filename of the temporary file
2524   func_dest_tmpfilename ()
2525   {
2526     if $doit; then
2527       # Put the new contents of $file in a file in the same directory (needed
2528       # to guarantee that an 'mv' to "$destdir/$file" works).
2529       tmpfile="$destdir/$1.tmp"
2530     else
2531       # Put the new contents of $file in a file in a temporary directory
2532       # (because the directory of "$file" might not exist).
2533       tmpfile="$tmp"/`basename "$1"`.tmp
2534     fi
2535   }
2536
2537   # Copy files or make symbolic links. Remove obsolete files.
2538   added_files=''
2539   removed_files=''
2540   delimiter='   '
2541   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2542   # representing the files according to the last gnulib-tool invocation.
2543   for f in $old_files; do echo $f; done \
2544     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2545     | LC_ALL=C sort \
2546     > "$tmp"/old-files
2547   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2548   # representing the files after this gnulib-tool invocation.
2549   for f in $new_files; do echo $f; done \
2550     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2551     | LC_ALL=C sort \
2552     > "$tmp"/new-files
2553   # First the files that are in old-files, but not in new-files:
2554   sed_take_first_column='s,'"$delimiter"'.*,,'
2555   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2556     # Remove the file. Do nothing if the user already removed it.
2557     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
2558       if $doit; then
2559         echo "Removing file $g (backup in ${g}~)"
2560         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2561       else
2562         echo "Remove file $g (backup in ${g}~)"
2563       fi
2564       func_append removed_files "$g$nl"
2565     fi
2566   done
2567   # func_add_or_update handles a file that ought to be present afterwards.
2568   # Uses parameters
2569   # - f             the original file name
2570   # - g             the rewritten file name
2571   # - already_present  nonempty if the file already exists, empty otherwise
2572   func_add_or_update ()
2573   {
2574     of="$f"
2575     case "$f" in
2576       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
2577     esac
2578     func_dest_tmpfilename "$g"
2579     func_lookup_file "$f"
2580     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2581     if test -n "$sed_transform_main_lib_file"; then
2582       case "$of" in
2583         lib/*)
2584           sed -e "$sed_transform_main_lib_file" \
2585             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2586           ;;
2587       esac
2588     fi
2589     if test -n "$sed_transform_testsrelated_lib_file"; then
2590       case "$of" in
2591         tests=lib/*)
2592           sed -e "$sed_transform_testsrelated_lib_file" \
2593             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2594           ;;
2595       esac
2596     fi
2597     if test -f "$destdir/$g"; then
2598       # The file already exists.
2599       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2600         : # The file has not changed.
2601       else
2602         # Replace the file.
2603         if $doit; then
2604           if test -n "$already_present"; then
2605             echo "Updating file $g (backup in ${g}~)"
2606           else
2607             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
2608           fi
2609           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2610           if { test -n "$symbolic" \
2611                || { test -n "$lsymbolic" \
2612                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2613              && test -z "$lookedup_tmp" \
2614              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2615             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2616           else
2617             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2618           fi
2619         else
2620           if test -n "$already_present"; then
2621             echo "Update file $g (backup in ${g}~)"
2622           else
2623             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
2624           fi
2625         fi
2626       fi
2627     else
2628       # Install the file.
2629       # Don't protest if the file should be there but isn't: it happens
2630       # frequently that developers don't put autogenerated files into CVS.
2631       if $doit; then
2632         echo "Copying file $g"
2633         if { test -n "$symbolic" \
2634              || { test -n "$lsymbolic" \
2635                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2636            && test -z "$lookedup_tmp" \
2637            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2638           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2639         else
2640           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2641         fi
2642       else
2643         echo "Copy file $g"
2644       fi
2645       func_append added_files "$g$nl"
2646     fi
2647     rm -f "$tmpfile"
2648   }
2649   # Then the files that are in new-files, but not in old-files:
2650   sed_take_last_column='s,^.*'"$delimiter"',,'
2651   already_present=
2652   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2653     | sed -e "$sed_take_last_column" \
2654     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2655   { # Rearrange file descriptors. Needed because "while ... done < ..."
2656     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2657     exec 5<&0 < "$tmp"/added-files
2658     while read g f; do
2659       func_add_or_update
2660     done
2661     exec 0<&5 5<&-
2662   }
2663   # Then the files that are in new-files and in old-files:
2664   already_present=true
2665   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2666     | sed -e "$sed_take_last_column" \
2667     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2668   { # Rearrange file descriptors. Needed because "while ... done < ..."
2669     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2670     exec 5<&0 < "$tmp"/kept-files
2671     while read g f; do
2672       func_add_or_update
2673     done
2674     exec 0<&5 5<&-
2675   }
2676
2677   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2678   actioncmd="gnulib-tool --import"
2679   func_append actioncmd " --dir=$destdir"
2680   if test -n "$local_gnulib_dir"; then
2681     func_append actioncmd " --local-dir=$local_gnulib_dir"
2682   fi
2683   func_append actioncmd " --lib=$libname"
2684   func_append actioncmd " --source-base=$sourcebase"
2685   func_append actioncmd " --m4-base=$m4base"
2686   if test -n "$pobase"; then
2687     func_append actioncmd " --po-base=$pobase"
2688   fi
2689   func_append actioncmd " --doc-base=$docbase"
2690   func_append actioncmd " --aux-dir=$auxdir"
2691   if test -n "$inctests"; then
2692     func_append actioncmd " --with-tests"
2693   fi
2694   for module in $avoidlist; do
2695     func_append actioncmd " --avoid=$module"
2696   done
2697   if test -n "$lgpl"; then
2698     if test "$lgpl" = yes; then
2699       func_append actioncmd " --lgpl"
2700     else
2701       func_append actioncmd " --lgpl=$lgpl"
2702     fi
2703   fi
2704   if test -n "$makefile_name"; then
2705     func_append actioncmd " --makefile-name=$makefile_name"
2706   fi
2707   if test "$libtool" = true; then
2708     func_append actioncmd " --libtool"
2709   else
2710     func_append actioncmd " --no-libtool"
2711   fi
2712   func_append actioncmd " --macro-prefix=$macro_prefix"
2713   if test -n "$po_domain"; then
2714     func_append actioncmd " --po-domain=$po_domain"
2715   fi
2716   func_append actioncmd " `echo $specified_modules`"
2717
2718   # Default the makefile name to Makefile.am.
2719   if test -n "$makefile_name"; then
2720     makefile_am=$makefile_name
2721   else
2722     makefile_am=Makefile.am
2723   fi
2724
2725   # Create normal Makefile.ams.
2726   for_test=false
2727
2728   # Create library makefile.
2729   func_dest_tmpfilename $sourcebase/$makefile_am
2730   modules="$main_modules"
2731   func_emit_lib_Makefile_am > "$tmpfile"
2732   if test -f "$destdir"/$sourcebase/$makefile_am; then
2733     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2734       rm -f "$tmpfile"
2735     else
2736       if $doit; then
2737         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2738         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2739         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2740       else
2741         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2742         rm -f "$tmpfile"
2743       fi
2744     fi
2745   else
2746     if $doit; then
2747       echo "Creating $sourcebase/$makefile_am"
2748       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2749     else
2750       echo "Create $sourcebase/$makefile_am"
2751       rm -f "$tmpfile"
2752     fi
2753     func_append added_files "$sourcebase/$makefile_am$nl"
2754   fi
2755
2756   # Create po/ directory.
2757   if test -n "$pobase"; then
2758     # Create po makefile and auxiliary files.
2759     for file in Makefile.in.in remove-potcdate.sin; do
2760       func_dest_tmpfilename $pobase/$file
2761       func_lookup_file build-aux/po/$file
2762       cat "$lookedup_file" > "$tmpfile"
2763       if test -f "$destdir"/$pobase/$file; then
2764         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
2765           rm -f "$tmpfile"
2766         else
2767           if $doit; then
2768             echo "Updating $pobase/$file (backup in $pobase/$file~)"
2769             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
2770             mv -f "$tmpfile" "$destdir"/$pobase/$file
2771           else
2772             echo "Update $pobase/$file (backup in $pobase/$file~)"
2773             rm -f "$tmpfile"
2774           fi
2775         fi
2776       else
2777         if $doit; then
2778           echo "Creating $pobase/$file"
2779           mv -f "$tmpfile" "$destdir"/$pobase/$file
2780         else
2781           echo "Create $pobase/$file"
2782           rm -f "$tmpfile"
2783         fi
2784         func_append added_files "$pobase/$file$nl"
2785       fi
2786     done
2787     # Create po makefile parametrization, part 1.
2788     func_dest_tmpfilename $pobase/Makevars
2789     func_emit_po_Makevars > "$tmpfile"
2790     if test -f "$destdir"/$pobase/Makevars; then
2791       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
2792         rm -f "$tmpfile"
2793       else
2794         if $doit; then
2795           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
2796           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
2797           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2798         else
2799           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
2800           rm -f "$tmpfile"
2801         fi
2802       fi
2803     else
2804       if $doit; then
2805         echo "Creating $pobase/Makevars"
2806         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2807       else
2808         echo "Create $pobase/Makevars"
2809         rm -f "$tmpfile"
2810       fi
2811       func_append added_files "$pobase/Makevars$nl"
2812     fi
2813     # Create po makefile parametrization, part 2.
2814     func_dest_tmpfilename $pobase/POTFILES.in
2815     func_emit_po_POTFILES_in > "$tmpfile"
2816     if test -f "$destdir"/$pobase/POTFILES.in; then
2817       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
2818         rm -f "$tmpfile"
2819       else
2820         if $doit; then
2821           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2822           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
2823           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2824         else
2825           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2826           rm -f "$tmpfile"
2827         fi
2828       fi
2829     else
2830       if $doit; then
2831         echo "Creating $pobase/POTFILES.in"
2832         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2833       else
2834         echo "Create $pobase/POTFILES.in"
2835         rm -f "$tmpfile"
2836       fi
2837       func_append added_files "$pobase/POTFILES.in$nl"
2838     fi
2839     # Fetch PO files.
2840     TP_URL="http://translationproject.org/latest/"
2841     TP_RSYNC_URI="translationproject.org::tp/latest/"
2842     if $doit; then
2843       echo "Fetching gnulib PO files from $TP_URL"
2844       (cd "$destdir"/$pobase \
2845        && { # Prefer rsync over wget if it is available, since it consumes
2846             # less network bandwidth, due to compression.
2847             if type rsync 2>/dev/null | grep / > /dev/null; then
2848               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
2849             else
2850               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
2851             fi
2852           }
2853       )
2854     else
2855       echo "Fetch gnulib PO files from $TP_URL"
2856     fi
2857     # Create po/LINGUAS.
2858     if $doit; then
2859       func_dest_tmpfilename $pobase/LINGUAS
2860       (cd "$destdir"/$pobase \
2861        && { echo '# Set of available languages.'
2862             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
2863           }
2864       ) > "$tmpfile"
2865       if test -f "$destdir"/$pobase/LINGUAS; then
2866         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
2867           rm -f "$tmpfile"
2868         else
2869           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2870           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
2871           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2872         fi
2873       else
2874         echo "Creating $pobase/LINGUAS"
2875         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2876         func_append added_files "$pobase/LINGUAS$nl"
2877       fi
2878     else
2879       if test -f "$destdir"/$pobase/LINGUAS; then
2880         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2881       else
2882         echo "Create $pobase/LINGUAS"
2883       fi
2884     fi
2885   fi
2886
2887   # Create m4/gnulib-cache.m4.
2888   func_dest_tmpfilename $m4base/gnulib-cache.m4
2889   (
2890     func_emit_copyright_notice
2891     echo "#"
2892     echo "# This file represents the specification of how gnulib-tool is used."
2893     echo "# It acts as a cache: It is written and read by gnulib-tool."
2894     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2895     echo "# like the configure.ac and various Makefile.am files."
2896     echo
2897     echo
2898     echo "# Specification in the form of a command-line invocation:"
2899     echo "#   $actioncmd"
2900     echo
2901     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
2902     # Store the local_gnulib_dir relative to destdir.
2903     case "$local_gnulib_dir" in
2904       "" | /*)
2905         relative_local_gnulib_dir="$local_gnulib_dir" ;;
2906       * )
2907         case "$destdir" in
2908           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
2909           *)
2910             # destdir, local_gnulib_dir are both relative.
2911             func_relativize "$destdir" "$local_gnulib_dir"
2912             relative_local_gnulib_dir="$reldir" ;;
2913         esac ;;
2914     esac
2915     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
2916     echo "gl_MODULES(["`echo $specified_modules`"])"
2917     echo "gl_AVOID([$avoidlist])"
2918     echo "gl_SOURCE_BASE([$sourcebase])"
2919     echo "gl_M4_BASE([$m4base])"
2920     echo "gl_PO_BASE([$pobase])"
2921     echo "gl_DOC_BASE([$docbase])"
2922     echo "gl_TESTS_BASE([$testsbase])"
2923     test -z "$inctests" || echo "gl_WITH_TESTS"
2924     echo "gl_LIB([$libname])"
2925     if test -n "$lgpl"; then
2926       if test "$lgpl" = yes; then
2927         echo "gl_LGPL"
2928       else
2929         echo "gl_LGPL([$lgpl])"
2930       fi
2931     fi
2932     echo "gl_MAKEFILE_NAME([$makefile_name])"
2933     if test "$libtool" = true; then
2934       echo "gl_LIBTOOL"
2935     fi
2936     echo "gl_MACRO_PREFIX([$macro_prefix])"
2937     echo "gl_PO_DOMAIN([$po_domain])"
2938   ) > "$tmpfile"
2939   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2940     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2941       rm -f "$tmpfile"
2942     else
2943       if $doit; then
2944         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2945         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2946         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2947       else
2948         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2949         if false; then
2950           cat "$tmpfile"
2951           echo
2952           echo "# gnulib-cache.m4 ends here"
2953         fi
2954         rm -f "$tmpfile"
2955       fi
2956     fi
2957   else
2958     if $doit; then
2959       echo "Creating $m4base/gnulib-cache.m4"
2960       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2961     else
2962       echo "Create $m4base/gnulib-cache.m4"
2963       cat "$tmpfile"
2964       rm -f "$tmpfile"
2965     fi
2966   fi
2967
2968   # Create m4/gnulib-comp.m4.
2969   func_dest_tmpfilename $m4base/gnulib-comp.m4
2970   (
2971     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2972     func_emit_copyright_notice
2973     echo "#"
2974     echo "# This file represents the compiled summary of the specification in"
2975     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2976     echo "# to be invoked from configure.ac."
2977     echo "# In projects using CVS, this file can be treated like other built files."
2978     echo
2979     echo
2980     echo "# This macro should be invoked from $configure_ac, in the section"
2981     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2982     echo "# any checks for libraries, header files, types and library functions."
2983     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2984     echo "["
2985     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2986     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2987     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2988     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2989     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2990     if test -n "$uses_subdirs"; then
2991       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2992     fi
2993     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2994       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2995     fi
2996     for module in $final_modules; do
2997       func_verify_module
2998       if test -n "$module"; then
2999         func_get_autoconf_early_snippet "$module"
3000       fi
3001     done \
3002       | sed -e '/^$/d;' -e 's/^/  /'
3003     echo "])"
3004     echo
3005     echo "# This macro should be invoked from $configure_ac, in the section"
3006     echo "# \"Check for header files, types and library functions\"."
3007     echo "AC_DEFUN([${macro_prefix}_INIT],"
3008     echo "["
3009     if test "$libtool" = true; then
3010       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3011       echo "  gl_cond_libtool=true"
3012     else
3013       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3014       echo "  gl_cond_libtool=false"
3015       echo "  gl_libdeps="
3016       echo "  gl_ltlibdeps="
3017     fi
3018     if test "$auxdir" != "build-aux"; then
3019       sed_replace_build_aux='
3020         :a
3021         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3022           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3023           ba
3024         }'
3025     else
3026       sed_replace_build_aux=
3027     fi
3028     func_emit_initmacro_start $macro_prefix
3029     echo "  gl_source_base='$sourcebase'"
3030     for module in $main_modules; do
3031       func_verify_module
3032       if test -n "$module"; then
3033         func_get_autoconf_snippet "$module" \
3034           | sed -e '/^$/d;' -e 's/^/  /' \
3035                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3036                 -e "$sed_replace_build_aux"
3037         if test "$module" = 'alloca' && test "$libtool" = true; then
3038           echo 'changequote(,)dnl'
3039           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3040           echo 'changequote([, ])dnl'
3041           echo 'AC_SUBST([LTALLOCA])'
3042         fi
3043       fi
3044     done
3045     func_emit_initmacro_end $macro_prefix
3046     echo "  gltests_libdeps="
3047     echo "  gltests_ltlibdeps="
3048     func_emit_initmacro_start ${macro_prefix}tests
3049     echo "  gl_source_base='$testsbase'"
3050     for module in $testsrelated_modules; do
3051       func_verify_module
3052       if test -n "$module"; then
3053         func_get_autoconf_snippet "$module" \
3054           | sed -e '/^$/d;' -e 's/^/  /' \
3055                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3056                 -e "$sed_replace_build_aux" \
3057                 -e 's/\$gl_cond_libtool/false/g' \
3058                 -e 's/gl_libdeps/gltests_libdeps/g' \
3059                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3060       fi
3061     done
3062     func_emit_initmacro_end ${macro_prefix}tests
3063     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3064     # created using libtool, because libtool already handles the dependencies.
3065     if test "$libtool" != true; then
3066       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3067       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3068       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3069       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3070       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3071     fi
3072     if $use_libtests; then
3073       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
3074       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
3075     fi
3076     echo "])"
3077     func_emit_initmacro_done $macro_prefix $sourcebase
3078     func_emit_initmacro_done ${macro_prefix}tests $testsbase
3079     echo
3080     echo "# This macro records the list of files which have been installed by"
3081     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
3082     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
3083     echo "$files" | sed -e 's,^,  ,'
3084     echo "])"
3085   ) > "$tmpfile"
3086   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3087     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
3088       rm -f "$tmpfile"
3089     else
3090       if $doit; then
3091         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3092         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
3093         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3094       else
3095         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3096         if false; then
3097           cat "$tmpfile"
3098           echo
3099           echo "# gnulib-comp.m4 ends here"
3100         fi
3101         rm -f "$tmpfile"
3102       fi
3103     fi
3104   else
3105     if $doit; then
3106       echo "Creating $m4base/gnulib-comp.m4"
3107       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3108     else
3109       echo "Create $m4base/gnulib-comp.m4"
3110       cat "$tmpfile"
3111       rm -f "$tmpfile"
3112     fi
3113   fi
3114
3115   if test -n "$inctests"; then
3116     # Create tests makefile.
3117     func_dest_tmpfilename $testsbase/$makefile_am
3118     modules="$testsrelated_modules"
3119     func_emit_tests_Makefile_am > "$tmpfile"
3120     if test -f "$destdir"/$testsbase/$makefile_am; then
3121       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
3122         rm -f "$tmpfile"
3123       else
3124         if $doit; then
3125           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3126           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
3127           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3128         else
3129           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3130           rm -f "$tmpfile"
3131         fi
3132       fi
3133     else
3134       if $doit; then
3135         echo "Creating $testsbase/$makefile_am"
3136         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3137       else
3138         echo "Create $testsbase/$makefile_am"
3139         rm -f "$tmpfile"
3140       fi
3141     func_append added_files "$testsbase/$makefile_am$nl"
3142     fi
3143   fi
3144
3145   # Update the .cvsignore and .gitignore files.
3146   { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
3147     echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
3148   } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
3149   { # Rearrange file descriptors. Needed because "while ... done < ..."
3150     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3151     exec 5<&0 < "$tmp"/fileset-changes
3152     func_update_ignorelist ()
3153     {
3154       ignore="$1"
3155       if test -f "$destdir/$dir$ignore"; then
3156         if test -n "$dir_added" || test -n "$dir_removed"; then
3157           LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
3158           echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
3159             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
3160           echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
3161             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
3162           if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
3163             if $doit; then
3164               echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3165               mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
3166               sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
3167               cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
3168                 | sed -f "$tmp"/sed-ignore-removed \
3169                 > "$destdir/$dir$ignore"
3170             else
3171               echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3172             fi
3173           fi
3174         fi
3175       else
3176         if test -n "$dir_added"; then
3177           if $doit; then
3178             echo "Creating $destdir/$dir$ignore"
3179             {
3180               if test "$ignore" = .cvsignore; then
3181                 echo ".deps"
3182                 # Automake generates Makefile rules that create .dirstamp files.
3183                 echo ".dirstamp"
3184               fi
3185               echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u
3186             } > "$destdir/$dir$ignore"
3187           else
3188             echo "Create $destdir/$dir$ignore"
3189           fi
3190         fi
3191       fi
3192     }
3193     func_done_dir ()
3194     {
3195       dir="$1"
3196       dir_added="$2"
3197       dir_removed="$3"
3198       if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
3199         func_update_ignorelist .cvsignore
3200       fi
3201       if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
3202         func_update_ignorelist .gitignore
3203       fi
3204     }
3205     last_dir=
3206     last_dir_added=
3207     last_dir_removed=
3208     while read line; do
3209       # Why not ''read next_dir op file'' ? Because the dir column can be empty.
3210       next_dir=`echo "$line" | sed -e 's,|.*,,'`
3211       op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
3212       file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
3213       if test "$next_dir" != "$last_dir"; then
3214         func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3215         last_dir="$next_dir"
3216         last_dir_added=
3217         last_dir_removed=
3218       fi
3219       case $op in
3220         A) func_append last_dir_added "$file$nl";;
3221         R) func_append last_dir_removed "$file$nl";;
3222       esac
3223     done
3224     func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3225     exec 0<&5 5<&-
3226   }
3227
3228   echo "Finished."
3229   echo
3230   echo "You may need to add #include directives for the following .h files."
3231   # Intersect $specified_modules and $main_modules
3232   # (since $specified_modules is not necessarily of subset of $main_modules
3233   # - some may have been skipped through --avoid, and since the elements of
3234   # $main_modules but not in $specified_modules can go away without explicit
3235   # notice - through changes in the module dependencies).
3236   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
3237   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
3238   # First the #include <...> directives without #ifs, sorted for convenience,
3239   # then the #include "..." directives without #ifs, sorted for convenience,
3240   # then the #include directives that are surrounded by #ifs. Not sorted.
3241   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
3242     include_directive=`func_get_include_directive "$module"`
3243     case "$nl$include_directive" in
3244       *"$nl#if"*)
3245         echo "$include_directive" 1>&5
3246         ;;
3247       *)
3248         echo "$include_directive" | grep -v 'include "' 1>&6
3249         echo "$include_directive" | grep 'include "' 1>&7
3250         ;;
3251     esac
3252   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
3253   (
3254    LC_ALL=C sort -u "$tmp"/include-angles
3255    LC_ALL=C sort -u "$tmp"/include-quotes
3256    cat "$tmp"/include-if
3257   ) | sed -e '/^$/d' -e 's/^/  /'
3258   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
3259
3260   for module in $main_modules; do
3261     func_get_link_directive "$module"
3262   done \
3263     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
3264   if test `wc -l < "$tmp"/link` != 0; then
3265     echo
3266     echo "You may need to use the following Makefile variables when linking."
3267     echo "Use them in <program>_LDADD when linking a program, or"
3268     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
3269     cat "$tmp"/link
3270   fi
3271   rm -f "$tmp"/link
3272
3273   echo
3274   echo "Don't forget to"
3275   if test "$makefile_am" = Makefile.am; then
3276     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3277   else
3278     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
3279   fi
3280   if test -n "$pobase"; then
3281     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
3282   fi
3283   if test -n "$inctests"; then
3284     if test "$makefile_am" = Makefile.am; then
3285       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3286     else
3287       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
3288     fi
3289   fi
3290   if test "$makefile_am" = Makefile.am; then
3291     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
3292     sourcebase_base=`basename "$sourcebase"`
3293     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
3294   fi
3295   if test -n "$pobase"; then
3296     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
3297     pobase_base=`basename "$pobase"`
3298     echo "  - mention \"${pobase_base}\" in SUBDIRS in ${pobase_dir}Makefile.am,"
3299   fi
3300   if test -n "$inctests"; then
3301     if test "$makefile_am" = Makefile.am; then
3302       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
3303       testsbase_base=`basename "$testsbase"`
3304       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
3305     fi
3306   fi
3307   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
3308   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
3309   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
3310 }
3311
3312 # func_create_testdir testdir modules
3313 # Input:
3314 # - local_gnulib_dir  from --local-dir
3315 # - auxdir          directory relative to destdir where to place build aux files
3316 func_create_testdir ()
3317 {
3318   testdir="$1"
3319   modules="$2"
3320   if test -z "$modules"; then
3321     # All modules together.
3322     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3323     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3324     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
3325     modules=`func_all_modules`
3326     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
3327   fi
3328   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
3329
3330   # Check that the license of every module is consistent with the license of
3331   # its dependencies.
3332   saved_modules="$modules"
3333   saved_inctests="$inctests"
3334   # When computing transitive closures, don't consider $module to depend on
3335   # $module-tests. Need this becauses tests are implicitly GPL and may depend
3336   # on GPL modules - therefore we don't want a warning in this case.
3337   inctests=""
3338   for requested_module in $saved_modules; do
3339     requested_license=`func_get_license "$requested_module"`
3340     if test "$requested_license" != GPL; then
3341       # Here we use func_modules_transitive_closure, not just
3342       # func_get_dependencies, so that we also detect weird situations like
3343       # an LGPL module which depends on a GPLed build tool module which depends
3344       # on a GPL module.
3345       modules="$requested_module"
3346       func_modules_transitive_closure
3347       for module in $modules; do
3348         license=`func_get_license "$module"`
3349         case "$license" in
3350           'GPLed build tool') ;;
3351           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3352           *)
3353             case "$requested_license" in
3354               GPLv2+)
3355                 case "$license" in
3356                   GPLv2+ | LGPLv2+) ;;
3357                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3358                 esac
3359                 ;;
3360               LGPL)
3361                 case "$license" in
3362                   LGPL | LGPLv2+) ;;
3363                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3364                 esac
3365                 ;;
3366               LGPLv2+)
3367                 case "$license" in
3368                   LGPLv2+) ;;
3369                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3370                 esac
3371                 ;;
3372             esac
3373             ;;
3374         esac
3375       done
3376     fi
3377   done
3378   modules="$saved_modules"
3379   inctests="$saved_inctests"
3380
3381   # Subdirectory names.
3382   sourcebase=gllib
3383   m4base=glm4
3384   pobase=
3385   docbase=gldoc
3386   testsbase=gltests
3387   macro_prefix=gl
3388   po_domain=
3389
3390   # Determine final module list.
3391   func_modules_transitive_closure
3392   if test $verbose -ge 0; then
3393     echo "Module list with included dependencies:"
3394     echo "$modules" | sed -e 's/^/  /'
3395   fi
3396
3397   # Add the dummy module if needed.
3398   func_modules_add_dummy
3399
3400   # Show banner notice of every module.
3401   func_modules_notice
3402
3403   # Determine final file list.
3404   func_modules_to_filelist
3405   if test $verbose -ge 0; then
3406     echo "File list:"
3407     echo "$files" | sed -e 's/^/  /'
3408   fi
3409
3410   sed_rewrite_files="\
3411     s,^build-aux/,$auxdir/,
3412     s,^doc/,$docbase/,
3413     s,^lib/,$sourcebase/,
3414     s,^m4/,$m4base/,
3415     s,^tests/,$testsbase/,"
3416
3417   # Create directories.
3418   for f in $files; do echo $f; done \
3419     | sed -e "$sed_rewrite_files" \
3420     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3421     | LC_ALL=C sort -u \
3422     > "$tmp"/dirs
3423   { # Rearrange file descriptors. Needed because "while ... done < ..."
3424     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3425     exec 5<&0 < "$tmp"/dirs
3426     while read d; do
3427       mkdir -p "$testdir/$d"
3428     done
3429     exec 0<&5 5<&-
3430   }
3431
3432   # Copy files or make symbolic links.
3433   delimiter='   '
3434   for f in $files; do echo $f; done \
3435     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
3436     | LC_ALL=C sort \
3437     > "$tmp"/files
3438   { # Rearrange file descriptors. Needed because "while ... done < ..."
3439     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3440     exec 5<&0 < "$tmp"/files
3441     while read g f; do
3442       func_lookup_file "$f"
3443       if test -n "$lookedup_tmp"; then
3444         cp -p "$lookedup_file" "$testdir/$g"
3445       else
3446         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
3447         if { test -n "$symbolic" \
3448              || { test -n "$lsymbolic" \
3449                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
3450           func_ln "$lookedup_file" "$testdir/$g"
3451         else
3452           cp -p "$lookedup_file" "$testdir/$g"
3453         fi
3454       fi
3455     done
3456     exec 0<&5 5<&-
3457   }
3458
3459   # Create Makefile.ams that are for testing.
3460   for_test=true
3461
3462   # Create $sourcebase/Makefile.am.
3463   mkdir -p "$testdir/$sourcebase"
3464   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
3465   any_uses_subdirs="$uses_subdirs"
3466
3467   # Create $m4base/Makefile.am.
3468   mkdir -p "$testdir/$m4base"
3469   (echo "## Process this file with automake to produce Makefile.in."
3470    echo
3471    echo "EXTRA_DIST ="
3472    for f in $files; do
3473      case "$f" in
3474        m4/* )
3475          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
3476      esac
3477    done
3478   ) > "$testdir/$m4base/Makefile.am"
3479
3480   subdirs="$sourcebase $m4base"
3481   subdirs_with_configure_ac=""
3482
3483   if false && test -f "$testdir"/$m4base/gettext.m4; then
3484     # Avoid stupid error message from automake:
3485     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
3486     mkdir -p "$testdir/po"
3487     (echo "## Process this file with automake to produce Makefile.in."
3488     ) > "$testdir/po/Makefile.am"
3489     func_append subdirs " po"
3490   fi
3491
3492   if test -n "$inctests"; then
3493     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
3494     # Viewed from the $testsbase subdirectory, $auxdir is different.
3495     saved_auxdir="$auxdir"
3496     auxdir=`echo "$testsbase/"|sed 's%[^/][^/]*//*%../%g'`"$auxdir"
3497     # Create $testsbase/Makefile.am.
3498     use_libtests=false
3499     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
3500     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
3501     # Create $testsbase/configure.ac.
3502     (echo "# Process this file with autoconf to produce a configure script."
3503      echo "AC_INIT([dummy], [0])"
3504      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3505      echo "AM_INIT_AUTOMAKE"
3506      echo
3507      echo "AM_CONFIG_HEADER([config.h])"
3508      echo
3509      echo "AC_PROG_CC"
3510      echo "AC_PROG_INSTALL"
3511      echo "AC_PROG_MAKE_SET"
3512      echo "AC_PROG_RANLIB"
3513      echo
3514      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3515        echo "AC_GNU_SOURCE"
3516        echo
3517      fi
3518      for module in $modules; do
3519        func_verify_module
3520        if test -n "$module"; then
3521          func_get_autoconf_early_snippet "$module"
3522        fi
3523      done \
3524        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3525      if test "$libtool" = true; then
3526        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3527        echo "gl_cond_libtool=true"
3528      else
3529        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3530        echo "gl_cond_libtool=false"
3531        echo "gl_libdeps="
3532        echo "gl_ltlibdeps="
3533      fi
3534      # Wrap the set of autoconf snippets into an autoconf macro that is then
3535      # invoked. This is needed because autoconf does not support AC_REQUIRE
3536      # at the top level:
3537      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3538      # but we want the AC_REQUIRE to have its normal meaning (provide one
3539      # expansion of the required macro before the current point, and only one
3540      # expansion total).
3541      echo "AC_DEFUN([gl_INIT], ["
3542      sed_replace_build_aux='
3543        :a
3544        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3545          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3546          ba
3547        }'
3548      func_emit_initmacro_start $macro_prefix
3549      # We don't have explicit ordering constraints between the various
3550      # autoconf snippets. It's cleanest to put those of the library before
3551      # those of the tests.
3552      echo "gl_source_base='../$sourcebase'"
3553      for module in $modules; do
3554        func_verify_nontests_module
3555        if test -n "$module"; then
3556          func_get_autoconf_snippet "$module" \
3557            | sed -e "$sed_replace_build_aux"
3558        fi
3559      done
3560      echo "gl_source_base='.'"
3561      for module in $modules; do
3562        func_verify_tests_module
3563        if test -n "$module"; then
3564          func_get_autoconf_snippet "$module" \
3565            | sed -e "$sed_replace_build_aux"
3566        fi
3567      done
3568      func_emit_initmacro_end $macro_prefix
3569      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3570      # created using libtool, because libtool already handles the dependencies.
3571      if test "$libtool" != true; then
3572        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3573        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3574        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3575        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3576        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3577      fi
3578      echo "])"
3579      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
3580      echo
3581      echo "gl_INIT"
3582      echo
3583      # Usually $testsbase/config.h will be a superset of config.h. Verify this
3584      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
3585      echo "AH_TOP([#include \"../config.h\"])"
3586      echo
3587      echo "AC_OUTPUT([Makefile])"
3588     ) > "$testdir/$testsbase/configure.ac"
3589     auxdir="$saved_auxdir"
3590     func_append subdirs " $testsbase"
3591     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
3592   fi
3593
3594   # Create Makefile.am.
3595   (echo "## Process this file with automake to produce Makefile.in."
3596    echo
3597    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3598    echo
3599    echo "SUBDIRS = $subdirs"
3600    echo
3601    echo "ACLOCAL_AMFLAGS = -I $m4base"
3602   ) > "$testdir/Makefile.am"
3603
3604   # Create configure.ac.
3605   (echo "# Process this file with autoconf to produce a configure script."
3606    echo "AC_INIT([dummy], [0])"
3607    if test "$auxdir" != "."; then
3608      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3609    fi
3610    echo "AM_INIT_AUTOMAKE"
3611    echo
3612    echo "AM_CONFIG_HEADER([config.h])"
3613    echo
3614    echo "AC_PROG_CC"
3615    echo "AC_PROG_INSTALL"
3616    echo "AC_PROG_MAKE_SET"
3617    echo
3618    echo "# For autobuild."
3619    echo "AC_CANONICAL_BUILD"
3620    echo "AC_CANONICAL_HOST"
3621    echo
3622    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3623    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3624    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3625    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3626    echo
3627    echo "AC_PROG_RANLIB"
3628    echo
3629    if test -n "$any_uses_subdirs"; then
3630      echo "AM_PROG_CC_C_O"
3631      echo
3632    fi
3633    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3634      echo "AC_GNU_SOURCE"
3635      echo
3636    fi
3637    for module in $modules; do
3638      func_verify_nontests_module
3639      if test -n "$module"; then
3640        func_get_autoconf_early_snippet "$module"
3641      fi
3642    done \
3643      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3644    if test "$libtool" = true; then
3645      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3646      echo "gl_cond_libtool=true"
3647    else
3648      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3649      echo "gl_cond_libtool=false"
3650      echo "gl_libdeps="
3651      echo "gl_ltlibdeps="
3652    fi
3653    # Wrap the set of autoconf snippets into an autoconf macro that is then
3654    # invoked. This is needed because autoconf does not support AC_REQUIRE
3655    # at the top level:
3656    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3657    # but we want the AC_REQUIRE to have its normal meaning (provide one
3658    # expansion of the required macro before the current point, and only one
3659    # expansion total).
3660    echo "AC_DEFUN([gl_INIT], ["
3661    if test "$auxdir" != "build-aux"; then
3662      sed_replace_build_aux='
3663        :a
3664        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3665          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3666          ba
3667        }'
3668    else
3669      sed_replace_build_aux=
3670    fi
3671    func_emit_initmacro_start $macro_prefix
3672    echo "gl_source_base='$sourcebase'"
3673    for module in $modules; do
3674      func_verify_nontests_module
3675      if test -n "$module"; then
3676        func_get_autoconf_snippet "$module" \
3677          | sed -e "$sed_replace_build_aux"
3678      fi
3679    done
3680    func_emit_initmacro_end $macro_prefix
3681    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3682    # created using libtool, because libtool already handles the dependencies.
3683    if test "$libtool" != true; then
3684      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3685      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3686      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3687      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3688      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3689    fi
3690    echo "])"
3691    func_emit_initmacro_done $macro_prefix $sourcebase
3692    echo
3693    echo "gl_INIT"
3694    echo
3695    if test -n "$subdirs_with_configure_ac"; then
3696      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3697    fi
3698    makefiles="Makefile"
3699    for d in $subdirs; do
3700      # For subdirs that have a configure.ac by their own, it's the subdir's
3701      # configure.ac which creates the subdir's Makefile.am, not this one.
3702      case " $subdirs_with_configure_ac " in
3703        *" $d "*) ;;
3704        *) func_append makefiles " $d/Makefile" ;;
3705      esac
3706    done
3707    echo "AC_OUTPUT([$makefiles])"
3708   ) > "$testdir/configure.ac"
3709
3710   # Create autogenerated files.
3711   (cd "$testdir"
3712    # Do not use "${AUTORECONF} --force --install", because it may invoke
3713    # autopoint, which brings in older versions of some of our .m4 files.
3714    if test -f $m4base/gettext.m4; then
3715      func_execute_command ${AUTOPOINT} --force || func_exit 1
3716      for f in $m4base/*.m4~; do
3717        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3718      done
3719    fi
3720    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
3721    if ! test -d build-aux; then
3722      func_execute_command mkdir build-aux || func_exit 1
3723    fi
3724    func_execute_command ${AUTOCONF} || func_exit 1
3725    func_execute_command ${AUTOHEADER} || func_exit 1
3726    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3727   ) || func_exit 1
3728   if test -n "$inctests"; then
3729     # Create autogenerated files.
3730     (cd "$testdir/$testsbase" || func_exit 1
3731      # Do not use "${AUTORECONF} --force --install", because it may invoke
3732      # autopoint, which brings in older versions of some of our .m4 files.
3733      if test -f ../$m4base/gettext.m4; then
3734        func_execute_command ${AUTOPOINT} --force || func_exit 1
3735        for f in ../$m4base/*.m4~; do
3736          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3737        done
3738      fi
3739      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
3740      if ! test -d ../build-aux; then
3741        func_execute_command mkdir ../build-aux
3742      fi
3743      func_execute_command ${AUTOCONF} || func_exit 1
3744      func_execute_command ${AUTOHEADER} || func_exit 1
3745      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3746     ) || func_exit 1
3747   fi
3748   # Need to run configure and make once, to create built files that are to be
3749   # distributed (such as getdate.c).
3750   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3751   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3752                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3753   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3754   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3755   # such $(FOO_H) because they don't refer to distributed files.
3756   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3757   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3758                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3759                  | sed -e "$sed_remove_make_variables"`
3760   distributed_built_sources=`for file in $built_sources; do
3761                                case "$cleaned_files" in
3762                                  *" "$file" "*) ;;
3763                                  *) echo $file ;;
3764                                esac;
3765                              done`
3766   if test -n "$distributed_built_sources"; then
3767     (cd "$testdir"
3768      ./configure || func_exit 1
3769        cd "$sourcebase"
3770        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3771        make built_sources || func_exit 1
3772        cd ..
3773      make distclean || func_exit 1
3774     ) || func_exit 1
3775   fi
3776 }
3777
3778 # func_create_megatestdir megatestdir allmodules
3779 # Input:
3780 # - local_gnulib_dir  from --local-dir
3781 # - auxdir          directory relative to destdir where to place build aux files
3782 func_create_megatestdir ()
3783 {
3784   megatestdir="$1"
3785   allmodules="$2"
3786   if test -z "$allmodules"; then
3787     allmodules=`func_all_modules`
3788   fi
3789
3790   megasubdirs=
3791   # First, all modules one by one.
3792   for onemodule in $allmodules; do
3793     func_create_testdir "$megatestdir/$onemodule" $onemodule
3794     func_append megasubdirs "$onemodule "
3795   done
3796   # Then, all modules all together.
3797   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3798   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3799   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3800   func_create_testdir "$megatestdir/ALL" "$allmodules"
3801   func_append megasubdirs "ALL"
3802
3803   # Create autobuild.
3804   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
3805              vc_witness="$gnulib_dir/CVS/Entries"; \
3806            else \
3807              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
3808            fi; \
3809            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
3810              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3811                    -e 's,February,02,'  -e 's,Feb,02,' \
3812                    -e 's,March,03,'     -e 's,Mar,03,' \
3813                    -e 's,April,04,'     -e 's,Apr,04,' \
3814                    -e 's,May,05,'                      \
3815                    -e 's,June,06,'      -e 's,Jun,06,' \
3816                    -e 's,July,07,'      -e 's,Jul,07,' \
3817                    -e 's,August,08,'    -e 's,Aug,08,' \
3818                    -e 's,September,09,' -e 's,Sep,09,' \
3819                    -e 's,October,10,'   -e 's,Oct,10,' \
3820                    -e 's,November,11,'  -e 's,Nov,11,' \
3821                    -e 's,December,12,'  -e 's,Dec,12,' \
3822                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3823                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3824   (echo '#!/bin/sh'
3825    echo "CVSDATE=$cvsdate"
3826    echo "test -d logs || mkdir logs"
3827    echo "for module in $megasubdirs; do"
3828    echo "  echo \"Working on module \$module...\""
3829    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3830    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3831    echo "   echo"
3832    echo "   set -x"
3833    echo "   : autobuild project... \$module"
3834    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3835    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3836    echo "   : autobuild hostname... \`hostname\`"
3837    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3838    echo "   echo rc=\$?"
3839    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3840    echo "done"
3841   ) > "$megatestdir/do-autobuild"
3842   chmod a+x "$megatestdir/do-autobuild"
3843
3844   # Create Makefile.am.
3845   (echo "## Process this file with automake to produce Makefile.in."
3846    echo
3847    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3848    echo
3849    echo "SUBDIRS = $megasubdirs"
3850    echo
3851    echo "EXTRA_DIST = do-autobuild"
3852   ) > "$megatestdir/Makefile.am"
3853
3854   # Create configure.ac.
3855   (echo "# Process this file with autoconf to produce a configure script."
3856    echo "AC_INIT([dummy], [0])"
3857    if test "$auxdir" != "."; then
3858      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3859    fi
3860    echo "AM_INIT_AUTOMAKE"
3861    echo
3862    echo "AC_PROG_MAKE_SET"
3863    echo
3864    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
3865    echo "AC_OUTPUT([Makefile])"
3866   ) > "$megatestdir/configure.ac"
3867
3868   # Create autogenerated files.
3869   (cd "$megatestdir"
3870    # Do not use "${AUTORECONF} --install", because autoreconf operates
3871    # recursively, but the subdirectories are already finished, therefore
3872    # calling autoreconf here would only waste lots of CPU time.
3873    func_execute_command ${ACLOCAL} || func_exit 1
3874    func_execute_command mkdir build-aux
3875    func_execute_command ${AUTOCONF} || func_exit 1
3876    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3877   ) || func_exit 1
3878 }
3879
3880 case $mode in
3881   "" )
3882     func_fatal_error "no mode specified" ;;
3883
3884   list )
3885     func_all_modules
3886     ;;
3887
3888   import | update )
3889
3890     # Where to import.
3891     if test -z "$destdir"; then
3892       destdir=.
3893     fi
3894     test -d "$destdir" \
3895       || func_fatal_error "destination directory does not exist: $destdir"
3896
3897     # Prefer configure.ac to configure.in.
3898     if test -f "$destdir"/configure.ac; then
3899       configure_ac="$destdir/configure.ac"
3900     else
3901       if test -f "$destdir"/configure.in; then
3902         configure_ac="$destdir/configure.in"
3903       else
3904         func_fatal_error "cannot find $destdir/configure.ac"
3905       fi
3906     fi
3907
3908     # Analyze configure.ac.
3909     guessed_auxdir="."
3910     guessed_libtool=false
3911     my_sed_traces='
3912       s,#.*$,,
3913       s,^dnl .*$,,
3914       s, dnl .*$,,
3915       /AC_CONFIG_AUX_DIR/ {
3916         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
3917       }
3918       /A[CM]_PROG_LIBTOOL/ {
3919         s,^.*$,guessed_libtool=true,p
3920       }'
3921     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
3922
3923     if test -z "$auxdir"; then
3924       auxdir="$guessed_auxdir"
3925     fi
3926
3927     # Determine where to apply func_import.
3928     if test -n "$m4base"; then
3929       # Apply func_import to a particular gnulib directory.
3930       # Any number of additional modules can be given.
3931       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
3932         # First use of gnulib in the given m4base.
3933         test -n "$supplied_libname" || supplied_libname=true
3934         test -n "$sourcebase" || sourcebase="lib"
3935         test -n "$docbase" || docbase="doc"
3936         test -n "$testsbase" || testsbase="tests"
3937         test -n "$macro_prefix" || macro_prefix="gl"
3938       fi
3939       func_import "$*"
3940     else
3941       # Apply func_import to all gnulib directories.
3942       # To get this list of directories, look at Makefile.am. (Not at
3943       # configure, because it may be omitted from CVS. Also, don't run
3944       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
3945       m4dirs=
3946       m4dirs_count=0
3947       if test -f "$destdir"/Makefile.am; then
3948         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
3949         m4dir_is_next=
3950         for arg in $aclocal_amflags; do
3951           if test -n "$m4dir_is_next"; then
3952             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
3953             case "$arg" in
3954               /*) ;;
3955               *)
3956                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
3957                   func_append m4dirs " $arg"
3958                   m4dirs_count=`expr $m4dirs_count + 1`
3959                 fi
3960                 ;;
3961             esac
3962             m4dir_is_next=
3963           else
3964             if test "X$arg" = "X-I"; then
3965               m4dir_is_next=yes
3966             else
3967               m4dir_is_next=
3968             fi
3969           fi
3970         done
3971       else
3972         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
3973         if test -f "$destdir"/aclocal.m4; then
3974           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
3975           sedexpr2='s,^[^/]*$,.,'
3976           sedexpr3='s,/[^/]*$,,'
3977           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
3978           m4dirs_count=`echo "$m4dirs" | wc -l`
3979         fi
3980       fi
3981       if test $m4dirs_count = 0; then
3982         # First use of gnulib in a package.
3983         # Any number of additional modules can be given.
3984         test -n "$supplied_libname" || supplied_libname=true
3985         test -n "$sourcebase" || sourcebase="lib"
3986         m4base="m4"
3987         test -n "$docbase" || docbase="doc"
3988         test -n "$testsbase" || testsbase="tests"
3989         test -n "$macro_prefix" || macro_prefix="gl"
3990         func_import "$*"
3991       else
3992         if test $m4dirs_count = 1; then
3993           # There's only one use of gnulib here. Assume the user means it.
3994           # Any number of additional modules can be given.
3995           for m4base in $m4dirs; do
3996             func_import "$*"
3997           done
3998         else
3999           # Ambiguous - guess what the user meant.
4000           if test $# = 0; then
4001             # No further arguments. Guess the user wants to update all of them.
4002             for m4base in $m4dirs; do
4003               # Perform func_import in a subshell, so that variable values
4004               # such as
4005               #   local_gnulib_dir, avoidlist, sourcebase, m4base, pobase,
4006               #   docbase, testsbase, inctests, libname, lgpl, makefile_name,
4007               #   libtool, macro_prefix, po_domain
4008               # don't propagate from one directory to another.
4009               (func_import) || func_exit 1
4010             done
4011           else
4012             # Really ambiguous.
4013             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
4014           fi
4015         fi
4016       fi
4017     fi
4018     ;;
4019
4020   create-testdir )
4021     if test -z "$destdir"; then
4022       func_fatal_error "please specify --dir option"
4023     fi
4024     mkdir "$destdir"
4025     test -d "$destdir" \
4026       || func_fatal_error "could not create destination directory"
4027     test -n "$auxdir" || auxdir="build-aux"
4028     func_create_testdir "$destdir" "$*"
4029     ;;
4030
4031   create-megatestdir )
4032     if test -z "$destdir"; then
4033       func_fatal_error "please specify --dir option"
4034     fi
4035     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4036     test -n "$auxdir" || auxdir="build-aux"
4037     func_create_megatestdir "$destdir" "$*"
4038     ;;
4039
4040   test )
4041     test -n "$destdir" || destdir=testdir$$
4042     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4043     test -n "$auxdir" || auxdir="build-aux"
4044     func_create_testdir "$destdir" "$*"
4045     cd "$destdir"
4046       mkdir build
4047       cd build
4048         ../configure || func_exit 1
4049         make || func_exit 1
4050         make check || func_exit 1
4051         make distclean || func_exit 1
4052         remaining=`find . -type f -print`
4053         if test -n "$remaining"; then
4054           echo "Remaining files:" $remaining 1>&2
4055           echo "gnulib-tool: *** Stop." 1>&2
4056           func_exit 1
4057         fi
4058       cd ..
4059     cd ..
4060     rm -rf "$destdir"
4061     ;;
4062
4063   megatest )
4064     test -n "$destdir" || destdir=testdir$$
4065     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4066     test -n "$auxdir" || auxdir="build-aux"
4067     func_create_megatestdir "$destdir" "$*"
4068     cd "$destdir"
4069       mkdir build
4070       cd build
4071         ../configure
4072         make
4073         make check
4074         make distclean
4075         remaining=`find . -type f -print`
4076         if test -n "$remaining"; then
4077           echo "Remaining files:" $remaining 1>&2
4078           echo "gnulib-tool: *** Stop." 1>&2
4079           func_exit 1
4080         fi
4081       cd ..
4082     cd ..
4083     rm -rf "$destdir"
4084     ;;
4085
4086   extract-description )
4087     for module
4088     do
4089       func_verify_module
4090       if test -n "$module"; then
4091         func_get_description "$module"
4092       fi
4093     done
4094     ;;
4095
4096   extract-notice )
4097     for module
4098     do
4099       func_verify_module
4100       if test -n "$module"; then
4101         func_get_notice "$module"
4102       fi
4103     done
4104     ;;
4105
4106   extract-filelist )
4107     for module
4108     do
4109       func_verify_module
4110       if test -n "$module"; then
4111         func_get_filelist "$module"
4112       fi
4113     done
4114     ;;
4115
4116   extract-dependencies )
4117     for module
4118     do
4119       func_verify_module
4120       if test -n "$module"; then
4121         func_get_dependencies "$module"
4122       fi
4123     done
4124     ;;
4125
4126   extract-autoconf-snippet )
4127     for module
4128     do
4129       func_verify_module
4130       if test -n "$module"; then
4131         func_get_autoconf_snippet "$module"
4132       fi
4133     done
4134     ;;
4135
4136   extract-automake-snippet )
4137     for module
4138     do
4139       func_verify_module
4140       if test -n "$module"; then
4141         func_get_automake_snippet "$module"
4142       fi
4143     done
4144     ;;
4145
4146   extract-include-directive )
4147     for module
4148     do
4149       func_verify_module
4150       if test -n "$module"; then
4151         func_get_include_directive "$module"
4152       fi
4153     done
4154     ;;
4155
4156   extract-link-directive )
4157     for module
4158     do
4159       func_verify_module
4160       if test -n "$module"; then
4161         func_get_link_directive "$module"
4162       fi
4163     done
4164     ;;
4165
4166   extract-license )
4167     for module
4168     do
4169       func_verify_module
4170       if test -n "$module"; then
4171         func_get_license "$module"
4172       fi
4173     done
4174     ;;
4175
4176   extract-maintainer )
4177     for module
4178     do
4179       func_verify_module
4180       if test -n "$module"; then
4181         func_get_maintainer "$module"
4182       fi
4183     done
4184     ;;
4185
4186   extract-tests-module )
4187     for module
4188     do
4189       func_verify_module
4190       if test -n "$module"; then
4191         func_get_tests_module "$module"
4192       fi
4193     done
4194     ;;
4195
4196   * )
4197     func_fatal_error "unknown operation mode --$mode" ;;
4198 esac
4199
4200 rm -rf "$tmp"
4201 # Undo the effect of the previous 'trap' command. Some shellology:
4202 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
4203 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
4204 # exit); for the others we need to call 'exit' explicitly. The value of $? is
4205 # 128 + signal number and is set before the trap-registered command is run.
4206 trap '' 0
4207 trap 'func_exit $?' 1 2 3 13 15
4208
4209 exit 0
4210
4211 # Local Variables:
4212 # indent-tabs-mode: nil
4213 # whitespace-check-buffer-indent: nil
4214 # End: