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