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