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