microoptimization of lib/poll.c
[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 *+\{0,1\}= *$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 ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[ ||"
2072   echo "      for gl_file in ]${macro_prefix_arg}_LIBSOURCES_LIST[ ; do"
2073   echo "        if test ! -r ]m4_defn([${macro_prefix_arg}_LIBSOURCES_DIR])[/\$gl_file ; then"
2074   echo "          echo \"missing file ]m4_defn([${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([${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         ta
2201         :a
2202           s/)/)/
2203           tb
2204           N
2205           ba
2206         :b
2207         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
2208       }
2209       /gl_AVOID(/ {
2210         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
2211       }
2212       /gl_SOURCE_BASE(/ {
2213         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
2214       }
2215       /gl_M4_BASE(/ {
2216         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
2217       }
2218       /gl_PO_BASE(/ {
2219         s,^.*gl_PO_BASE([[ ]*\([^])]*\).*$,cached_pobase="\1",p
2220       }
2221       /gl_DOC_BASE(/ {
2222         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
2223       }
2224       /gl_TESTS_BASE(/ {
2225         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
2226       }
2227       /gl_WITH_TESTS/ {
2228         s,^.*$,cached_inctests=true,p
2229       }
2230       /gl_LIB(/ {
2231         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
2232       }
2233       /gl_LGPL(/ {
2234         s,^.*gl_LGPL([[ ]*\([^])]*\).*$,cached_lgpl="\1",p
2235       }
2236       /gl_LGPL/ {
2237         s,^.*$,cached_lgpl=yes,p
2238       }
2239       /gl_MAKEFILE_NAME(/ {
2240         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
2241       }
2242       /gl_LIBTOOL/ {
2243         s,^.*$,cached_libtool=true,p
2244       }
2245       /gl_MACRO_PREFIX(/ {
2246         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
2247       }
2248       /gl_PO_DOMAIN(/ {
2249         s,^.*gl_PO_DOMAIN([[ ]*\([^])]*\).*$,cached_po_domain="\1",p
2250       }
2251       /gl_VC_FILES(/ {
2252         s,^.*gl_VC_FILES([[ ]*\([^])]*\).*$,cached_vc_files="\1",p
2253       }'
2254     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
2255     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2256       my_sed_traces='
2257         s,#.*$,,
2258         s,^dnl .*$,,
2259         s, dnl .*$,,
2260         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
2261           s,^.*$,cached_files=",p
2262           n
2263           ta
2264           :a
2265           s,^\]).*$,",
2266           tb
2267           p
2268           n
2269           ba
2270           :b
2271           p
2272         }'
2273       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
2274     fi
2275   fi
2276
2277   # Merge the cached settings with the specified ones.
2278   # The m4base must be the same as expected from the pathname.
2279   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
2280     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
2281   fi
2282   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
2283   # is relative to $destdir, whereas the one we use is relative to . or absolute.
2284   if test -z "$local_gnulib_dir"; then
2285     if test -n "$cached_local_gnulib_dir"; then
2286       case "$destdir" in
2287         /*)
2288           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2289         *)
2290           case "$cached_local_gnulib_dir" in
2291             /*)
2292               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2293             *)
2294               func_relconcat "$destdir" "$cached_local_gnulib_dir"
2295               local_gnulib_dir="$relconcat" ;;
2296           esac ;;
2297       esac
2298     fi
2299   fi
2300   # Append the cached and the specified module names. So that
2301   # "gnulib-tool --import foo" means to add the module foo.
2302   specified_modules="$cached_specified_modules $1"
2303   # Append the cached and the specified avoidlist. This is probably better
2304   # than dropping the cached one when --avoid is specified at least once.
2305   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
2306   avoidlist=`echo $avoidlist`
2307
2308   # The sourcebase defaults to the cached one.
2309   if test -z "$sourcebase"; then
2310     sourcebase="$cached_sourcebase"
2311     if test -z "$sourcebase"; then
2312       func_fatal_error "missing --source-base option"
2313     fi
2314   fi
2315   # The pobase defaults to the cached one.
2316   if test -z "$pobase"; then
2317     pobase="$cached_pobase"
2318   fi
2319   # The docbase defaults to the cached one.
2320   if test -z "$docbase"; then
2321     docbase="$cached_docbase"
2322     if test -z "$docbase"; then
2323       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."
2324     fi
2325   fi
2326   # The testsbase defaults to the cached one.
2327   if test -z "$testsbase"; then
2328     testsbase="$cached_testsbase"
2329     if test -z "$testsbase"; then
2330       func_fatal_error "missing --tests-base option"
2331     fi
2332   fi
2333   # Require the tests if specified either way.
2334   if test -z "$inctests"; then
2335     inctests="$cached_inctests"
2336   fi
2337   # The libname defaults to the cached one.
2338   if test -z "$supplied_libname"; then
2339     libname="$cached_libname"
2340     if test -z "$libname"; then
2341       func_fatal_error "missing --lib option"
2342     fi
2343   fi
2344   # Require LGPL if specified either way.
2345   if test -z "$lgpl"; then
2346     lgpl="$cached_lgpl"
2347   fi
2348   # The makefile_name defaults to the cached one.
2349   if test -z "$makefile_name"; then
2350     makefile_name="$cached_makefile_name"
2351   fi
2352   # Use libtool if specified either way, or if guessed.
2353   if test -z "$libtool"; then
2354     if test -n "$cached_m4base"; then
2355       libtool="$cached_libtool"
2356     else
2357       libtool="$guessed_libtool"
2358     fi
2359   fi
2360   # The macro_prefix defaults to the cached one.
2361   if test -z "$macro_prefix"; then
2362     macro_prefix="$cached_macro_prefix"
2363     if test -z "$macro_prefix"; then
2364       func_fatal_error "missing --macro-prefix option"
2365     fi
2366   fi
2367   # The po_domain defaults to the cached one.
2368   if test -z "$po_domain"; then
2369     po_domain="$cached_po_domain"
2370   fi
2371   # The vc_files defaults to the cached one.
2372   if test -z "$vc_files"; then
2373     vc_files="$cached_vc_files"
2374   fi
2375
2376   # Canonicalize the list of specified modules.
2377   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
2378
2379   # Determine final module list.
2380   modules="$specified_modules"
2381   func_modules_transitive_closure
2382   if test $verbose -ge 0; then
2383     echo "Module list with included dependencies:"
2384     echo "$modules" | sed -e 's/^/  /'
2385   fi
2386   final_modules="$modules"
2387
2388   # Determine main module list and tests-related module list separately.
2389   # The main module list is the transitive closure of the specified modules,
2390   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2391   # is specified, it will consist only of LGPLed source.
2392   # The tests-related module list is the transitive closure of the specified
2393   # modules, including tests modules, minus the main module list. Its lib/*
2394   # sources (brought in through dependencies of *-tests modules) go into
2395   # $testsbase/. It may contain GPLed source, even if --lgpl is specified.
2396   # Determine main module list.
2397   saved_inctests="$inctests"
2398   inctests=""
2399   modules="$specified_modules"
2400   func_modules_transitive_closure
2401   main_modules="$modules"
2402   inctests="$saved_inctests"
2403   if test $verbose -ge 1; then
2404     echo "Main module list:"
2405     echo "$main_modules" | sed -e 's/^/  /'
2406   fi
2407   # Determine tests-related module list.
2408   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
2409   testsrelated_modules=`echo "$main_modules" | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
2410   if test $verbose -ge 1; then
2411     echo "Tests-related module list:"
2412     echo "$testsrelated_modules" | sed -e 's/^/  /'
2413   fi
2414
2415   # Add the dummy module to the main module list if needed.
2416   modules="$main_modules"
2417   func_modules_add_dummy
2418   main_modules="$modules"
2419
2420   # Determine whether a $testsbase/libtests.a is needed.
2421   use_libtests=false
2422   for module in $testsrelated_modules; do
2423     func_verify_nontests_module
2424     if test -n "$module"; then
2425       all_files=`func_get_filelist $module`
2426       lib_files=`for f in $all_files; do \
2427                    case $f in \
2428                      lib/*) echo $f ;; \
2429                    esac; \
2430                  done | sed -e 's,^lib/,,'`
2431       if test -n "$lib_files"; then
2432         use_libtests=true
2433         break
2434       fi
2435     fi
2436   done
2437
2438   # Add the dummy module to the tests-related module list if needed.
2439   if $use_libtests; then
2440     modules="$testsrelated_modules"
2441     func_modules_add_dummy
2442     testsrelated_modules="$modules"
2443   fi
2444
2445   # If --lgpl, verify that the licenses of modules are compatible.
2446   if test -n "$lgpl"; then
2447     for module in $main_modules; do
2448       license=`func_get_license $module`
2449       case $license in
2450         'GPLed build tool') ;;
2451         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2452         *)
2453           case "$lgpl" in
2454             yes | 3)
2455               case $license in
2456                 LGPL | LGPLv2+) ;;
2457                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2458               esac
2459               ;;
2460             2)
2461               case $license in
2462                 LGPLv2+) ;;
2463                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2464               esac
2465               ;;
2466             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2467           esac
2468           ;;
2469       esac
2470     done
2471   fi
2472
2473   # Show banner notice of every module.
2474   modules="$main_modules"
2475   func_modules_notice
2476
2477   # Determine script to apply to imported library files.
2478   sed_transform_lib_file=
2479   for module in $main_modules; do
2480     if test $module = config-h; then
2481       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
2482       sed_transform_lib_file=$sed_transform_lib_file'
2483         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
2484       '
2485       break
2486     fi
2487   done
2488   sed_transform_main_lib_file="$sed_transform_lib_file"
2489   if test -n "$do_copyrights"; then
2490     if test -n "$lgpl"; then
2491       # Update license.
2492       case "$lgpl" in
2493         yes | 3)
2494           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2495             s/GNU General/GNU Lesser General/g
2496           '
2497           ;;
2498         2)
2499           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2500             s/GNU General/GNU Lesser General/g
2501             s/version [23]\([ ,]\)/version 2.1\1/g
2502           '
2503           ;;
2504         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2505       esac
2506     else
2507       # Update license.
2508       sed_transform_main_lib_file=$sed_transform_main_lib_file'
2509         s/GNU Lesser General/GNU General/g
2510         s/GNU Library General/GNU General/g
2511         s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2512       '
2513     fi
2514   fi
2515
2516   # Determine script to apply to library files that go into $testsbase/.
2517   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
2518   if test -n "$do_copyrights"; then
2519     # Update license.
2520     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
2521       s/GNU Lesser General/GNU General/g
2522       s/GNU Library General/GNU General/g
2523       s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2524     '
2525   fi
2526
2527   # Determine the final file lists.
2528   # They must be computed separately, because files in lib/* go into
2529   # $sourcebase/ if they are in the main file list but into $testsbase/
2530   # if they are in the tests-related file list. Furthermore lib/dummy.c
2531   # can be in both.
2532   # Determine final main file list.
2533   modules="$main_modules"
2534   func_modules_to_filelist
2535   main_files="$files"
2536   # Determine final tests-related file list.
2537   modules="$testsrelated_modules"
2538   func_modules_to_filelist
2539   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
2540   # Merge both file lists.
2541   sed_remove_empty_lines='/^$/d'
2542   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
2543   if test $verbose -ge 0; then
2544     echo "File list:"
2545     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
2546     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
2547   fi
2548
2549   test -n "$files" \
2550     || func_fatal_error "refusing to do nothing"
2551
2552   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2553   new_files="$files m4/gnulib-tool.m4"
2554   old_files="$cached_files"
2555   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2556     func_append old_files " m4/gnulib-tool.m4"
2557   fi
2558
2559   sed_rewrite_old_files="\
2560     s,^build-aux/,$auxdir/,
2561     s,^doc/,$cached_docbase/,
2562     s,^lib/,$cached_sourcebase/,
2563     s,^m4/,$cached_m4base/,
2564     s,^tests/,$cached_testsbase/,
2565     s,^tests=lib/,$cached_testsbase/,
2566     s,^top/,,"
2567   sed_rewrite_new_files="\
2568     s,^build-aux/,$auxdir/,
2569     s,^doc/,$docbase/,
2570     s,^lib/,$sourcebase/,
2571     s,^m4/,$m4base/,
2572     s,^tests/,$testsbase/,
2573     s,^tests=lib/,$testsbase/,
2574     s,^top/,,"
2575
2576   # Create directories.
2577   { echo "$sourcebase"
2578     echo "$m4base"
2579     if test -n "$pobase"; then
2580       echo "$pobase"
2581     fi
2582     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2583     if test -n "$docfiles"; then
2584       echo "$docbase"
2585     fi
2586     if test -n "$inctests"; then
2587       echo "$testsbase"
2588     fi
2589     echo "$auxdir"
2590     for f in $files; do echo $f; done \
2591       | sed -e "$sed_rewrite_new_files" \
2592       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2593       | LC_ALL=C sort -u
2594   } > "$tmp"/dirs
2595   { # Rearrange file descriptors. Needed because "while ... done < ..."
2596     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2597     exec 5<&0 < "$tmp"/dirs
2598     while read d; do
2599       if test ! -d "$destdir/$d"; then
2600         if $doit; then
2601           echo "Creating directory $destdir/$d"
2602           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2603         else
2604           echo "Create directory $destdir/$d"
2605         fi
2606       fi
2607     done
2608     exec 0<&5 5<&-
2609   }
2610
2611   # func_dest_tmpfilename file
2612   # determines the name of a temporary file (file is relative to destdir).
2613   # Sets variable:
2614   #   - tmpfile       absolute filename of the temporary file
2615   func_dest_tmpfilename ()
2616   {
2617     if $doit; then
2618       # Put the new contents of $file in a file in the same directory (needed
2619       # to guarantee that an 'mv' to "$destdir/$file" works).
2620       tmpfile="$destdir/$1.tmp"
2621     else
2622       # Put the new contents of $file in a file in a temporary directory
2623       # (because the directory of "$file" might not exist).
2624       tmpfile="$tmp"/`basename "$1"`.tmp
2625     fi
2626   }
2627
2628   # Copy files or make symbolic links. Remove obsolete files.
2629   added_files=''
2630   removed_files=''
2631   delimiter='   '
2632   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2633   # representing the files according to the last gnulib-tool invocation.
2634   for f in $old_files; do echo $f; done \
2635     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2636     | LC_ALL=C sort \
2637     > "$tmp"/old-files
2638   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2639   # representing the files after this gnulib-tool invocation.
2640   for f in $new_files; do echo $f; done \
2641     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2642     | LC_ALL=C sort \
2643     > "$tmp"/new-files
2644   # First the files that are in old-files, but not in new-files:
2645   sed_take_first_column='s,'"$delimiter"'.*,,'
2646   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2647     # Remove the file. Do nothing if the user already removed it.
2648     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
2649       if $doit; then
2650         echo "Removing file $g (backup in ${g}~)"
2651         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2652       else
2653         echo "Remove file $g (backup in ${g}~)"
2654       fi
2655       func_append removed_files "$g$nl"
2656     fi
2657   done
2658   # func_add_or_update handles a file that ought to be present afterwards.
2659   # Uses parameters
2660   # - f             the original file name
2661   # - g             the rewritten file name
2662   # - already_present  nonempty if the file already exists, empty otherwise
2663   func_add_or_update ()
2664   {
2665     of="$f"
2666     case "$f" in
2667       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
2668     esac
2669     func_dest_tmpfilename "$g"
2670     func_lookup_file "$f"
2671     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2672     if test -n "$sed_transform_main_lib_file"; then
2673       case "$of" in
2674         lib/*)
2675           sed -e "$sed_transform_main_lib_file" \
2676             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2677           ;;
2678       esac
2679     fi
2680     if test -n "$sed_transform_testsrelated_lib_file"; then
2681       case "$of" in
2682         tests=lib/*)
2683           sed -e "$sed_transform_testsrelated_lib_file" \
2684             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2685           ;;
2686       esac
2687     fi
2688     if test -f "$destdir/$g"; then
2689       # The file already exists.
2690       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2691         : # The file has not changed.
2692       else
2693         # Replace the file.
2694         if $doit; then
2695           if test -n "$already_present"; then
2696             echo "Updating file $g (backup in ${g}~)"
2697           else
2698             echo "Replacing file $g (non-gnulib code backed up in ${g}~) !!"
2699           fi
2700           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2701           if { test -n "$symbolic" \
2702                || { test -n "$lsymbolic" \
2703                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2704              && test -z "$lookedup_tmp" \
2705              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2706             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2707           else
2708             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2709           fi
2710         else
2711           if test -n "$already_present"; then
2712             echo "Update file $g (backup in ${g}~)"
2713           else
2714             echo "Replace file $g (non-gnulib code backed up in ${g}~) !!"
2715           fi
2716         fi
2717       fi
2718     else
2719       # Install the file.
2720       # Don't protest if the file should be there but isn't: it happens
2721       # frequently that developers don't put autogenerated files into CVS.
2722       if $doit; then
2723         echo "Copying file $g"
2724         if { test -n "$symbolic" \
2725              || { test -n "$lsymbolic" \
2726                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2727            && test -z "$lookedup_tmp" \
2728            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2729           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2730         else
2731           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2732         fi
2733       else
2734         echo "Copy file $g"
2735       fi
2736       func_append added_files "$g$nl"
2737     fi
2738     rm -f "$tmpfile"
2739   }
2740   # Then the files that are in new-files, but not in old-files:
2741   sed_take_last_column='s,^.*'"$delimiter"',,'
2742   already_present=
2743   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2744     | sed -e "$sed_take_last_column" \
2745     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2746   { # Rearrange file descriptors. Needed because "while ... done < ..."
2747     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2748     exec 5<&0 < "$tmp"/added-files
2749     while read g f; do
2750       func_add_or_update
2751     done
2752     exec 0<&5 5<&-
2753   }
2754   # Then the files that are in new-files and in old-files:
2755   already_present=true
2756   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2757     | sed -e "$sed_take_last_column" \
2758     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2759   { # Rearrange file descriptors. Needed because "while ... done < ..."
2760     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2761     exec 5<&0 < "$tmp"/kept-files
2762     while read g f; do
2763       func_add_or_update
2764     done
2765     exec 0<&5 5<&-
2766   }
2767
2768   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2769   actioncmd="gnulib-tool --import"
2770   func_append actioncmd " --dir=$destdir"
2771   if test -n "$local_gnulib_dir"; then
2772     func_append actioncmd " --local-dir=$local_gnulib_dir"
2773   fi
2774   func_append actioncmd " --lib=$libname"
2775   func_append actioncmd " --source-base=$sourcebase"
2776   func_append actioncmd " --m4-base=$m4base"
2777   if test -n "$pobase"; then
2778     func_append actioncmd " --po-base=$pobase"
2779   fi
2780   func_append actioncmd " --doc-base=$docbase"
2781   func_append actioncmd " --aux-dir=$auxdir"
2782   if test -n "$inctests"; then
2783     func_append actioncmd " --with-tests"
2784   fi
2785   for module in $avoidlist; do
2786     func_append actioncmd " --avoid=$module"
2787   done
2788   if test -n "$lgpl"; then
2789     if test "$lgpl" = yes; then
2790       func_append actioncmd " --lgpl"
2791     else
2792       func_append actioncmd " --lgpl=$lgpl"
2793     fi
2794   fi
2795   if test -n "$makefile_name"; then
2796     func_append actioncmd " --makefile-name=$makefile_name"
2797   fi
2798   if test "$libtool" = true; then
2799     func_append actioncmd " --libtool"
2800   else
2801     func_append actioncmd " --no-libtool"
2802   fi
2803   func_append actioncmd " --macro-prefix=$macro_prefix"
2804   if test -n "$po_domain"; then
2805     func_append actioncmd " --po-domain=$po_domain"
2806   fi
2807   if test -n "$vc_files"; then
2808     if test "$vc_files" = true; then
2809       func_append actioncmd " --vc-files"
2810     else
2811       func_append actioncmd " --no-vc-files"
2812     fi
2813   fi
2814   func_append actioncmd " `echo $specified_modules`"
2815
2816   # Default the makefile name to Makefile.am.
2817   if test -n "$makefile_name"; then
2818     makefile_am=$makefile_name
2819   else
2820     makefile_am=Makefile.am
2821   fi
2822
2823   # Create normal Makefile.ams.
2824   for_test=false
2825
2826   # Create library makefile.
2827   func_dest_tmpfilename $sourcebase/$makefile_am
2828   modules="$main_modules"
2829   func_emit_lib_Makefile_am > "$tmpfile"
2830   if test -f "$destdir"/$sourcebase/$makefile_am; then
2831     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2832       rm -f "$tmpfile"
2833     else
2834       if $doit; then
2835         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2836         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2837         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2838       else
2839         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2840         rm -f "$tmpfile"
2841       fi
2842     fi
2843   else
2844     if $doit; then
2845       echo "Creating $sourcebase/$makefile_am"
2846       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2847     else
2848       echo "Create $sourcebase/$makefile_am"
2849       rm -f "$tmpfile"
2850     fi
2851     func_append added_files "$sourcebase/$makefile_am$nl"
2852   fi
2853
2854   # Create po/ directory.
2855   if test -n "$pobase"; then
2856     # Create po makefile and auxiliary files.
2857     for file in Makefile.in.in remove-potcdate.sin; do
2858       func_dest_tmpfilename $pobase/$file
2859       func_lookup_file build-aux/po/$file
2860       cat "$lookedup_file" > "$tmpfile"
2861       if test -f "$destdir"/$pobase/$file; then
2862         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
2863           rm -f "$tmpfile"
2864         else
2865           if $doit; then
2866             echo "Updating $pobase/$file (backup in $pobase/$file~)"
2867             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
2868             mv -f "$tmpfile" "$destdir"/$pobase/$file
2869           else
2870             echo "Update $pobase/$file (backup in $pobase/$file~)"
2871             rm -f "$tmpfile"
2872           fi
2873         fi
2874       else
2875         if $doit; then
2876           echo "Creating $pobase/$file"
2877           mv -f "$tmpfile" "$destdir"/$pobase/$file
2878         else
2879           echo "Create $pobase/$file"
2880           rm -f "$tmpfile"
2881         fi
2882         func_append added_files "$pobase/$file$nl"
2883       fi
2884     done
2885     # Create po makefile parameterization, part 1.
2886     func_dest_tmpfilename $pobase/Makevars
2887     func_emit_po_Makevars > "$tmpfile"
2888     if test -f "$destdir"/$pobase/Makevars; then
2889       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
2890         rm -f "$tmpfile"
2891       else
2892         if $doit; then
2893           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
2894           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
2895           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2896         else
2897           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
2898           rm -f "$tmpfile"
2899         fi
2900       fi
2901     else
2902       if $doit; then
2903         echo "Creating $pobase/Makevars"
2904         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2905       else
2906         echo "Create $pobase/Makevars"
2907         rm -f "$tmpfile"
2908       fi
2909       func_append added_files "$pobase/Makevars$nl"
2910     fi
2911     # Create po makefile parameterization, part 2.
2912     func_dest_tmpfilename $pobase/POTFILES.in
2913     func_emit_po_POTFILES_in > "$tmpfile"
2914     if test -f "$destdir"/$pobase/POTFILES.in; then
2915       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
2916         rm -f "$tmpfile"
2917       else
2918         if $doit; then
2919           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2920           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
2921           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2922         else
2923           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2924           rm -f "$tmpfile"
2925         fi
2926       fi
2927     else
2928       if $doit; then
2929         echo "Creating $pobase/POTFILES.in"
2930         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2931       else
2932         echo "Create $pobase/POTFILES.in"
2933         rm -f "$tmpfile"
2934       fi
2935       func_append added_files "$pobase/POTFILES.in$nl"
2936     fi
2937     # Fetch PO files.
2938     TP_URL="http://translationproject.org/latest/"
2939     TP_RSYNC_URI="translationproject.org::tp/latest/"
2940     if $doit; then
2941       echo "Fetching gnulib PO files from $TP_URL"
2942       (cd "$destdir"/$pobase \
2943        && { # Prefer rsync over wget if it is available, since it consumes
2944             # less network bandwidth, due to compression.
2945             if type rsync 2>/dev/null | grep / > /dev/null; then
2946               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
2947             else
2948               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
2949             fi
2950           }
2951       )
2952     else
2953       echo "Fetch gnulib PO files from $TP_URL"
2954     fi
2955     # Create po/LINGUAS.
2956     if $doit; then
2957       func_dest_tmpfilename $pobase/LINGUAS
2958       (cd "$destdir"/$pobase \
2959        && { echo '# Set of available languages.'
2960             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
2961           }
2962       ) > "$tmpfile"
2963       if test -f "$destdir"/$pobase/LINGUAS; then
2964         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
2965           rm -f "$tmpfile"
2966         else
2967           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2968           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
2969           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2970         fi
2971       else
2972         echo "Creating $pobase/LINGUAS"
2973         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2974         func_append added_files "$pobase/LINGUAS$nl"
2975       fi
2976     else
2977       if test -f "$destdir"/$pobase/LINGUAS; then
2978         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2979       else
2980         echo "Create $pobase/LINGUAS"
2981       fi
2982     fi
2983   fi
2984
2985   # Create m4/gnulib-cache.m4.
2986   func_dest_tmpfilename $m4base/gnulib-cache.m4
2987   (
2988     func_emit_copyright_notice
2989     echo "#"
2990     echo "# This file represents the specification of how gnulib-tool is used."
2991     echo "# It acts as a cache: It is written and read by gnulib-tool."
2992     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2993     echo "# like the configure.ac and various Makefile.am files."
2994     echo
2995     echo
2996     echo "# Specification in the form of a command-line invocation:"
2997     echo "#   $actioncmd"
2998     echo
2999     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
3000     # Store the local_gnulib_dir relative to destdir.
3001     case "$local_gnulib_dir" in
3002       "" | /*)
3003         relative_local_gnulib_dir="$local_gnulib_dir" ;;
3004       * )
3005         case "$destdir" in
3006           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
3007           *)
3008             # destdir, local_gnulib_dir are both relative.
3009             func_relativize "$destdir" "$local_gnulib_dir"
3010             relative_local_gnulib_dir="$reldir" ;;
3011         esac ;;
3012     esac
3013     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
3014     echo "gl_MODULES(["
3015     echo "$specified_modules" | sed 's/^/  /g'
3016     echo "])"
3017     echo "gl_AVOID([$avoidlist])"
3018     echo "gl_SOURCE_BASE([$sourcebase])"
3019     echo "gl_M4_BASE([$m4base])"
3020     echo "gl_PO_BASE([$pobase])"
3021     echo "gl_DOC_BASE([$docbase])"
3022     echo "gl_TESTS_BASE([$testsbase])"
3023     test -z "$inctests" || echo "gl_WITH_TESTS"
3024     echo "gl_LIB([$libname])"
3025     if test -n "$lgpl"; then
3026       if test "$lgpl" = yes; then
3027         echo "gl_LGPL"
3028       else
3029         echo "gl_LGPL([$lgpl])"
3030       fi
3031     fi
3032     echo "gl_MAKEFILE_NAME([$makefile_name])"
3033     if test "$libtool" = true; then
3034       echo "gl_LIBTOOL"
3035     fi
3036     echo "gl_MACRO_PREFIX([$macro_prefix])"
3037     echo "gl_PO_DOMAIN([$po_domain])"
3038     if test -n "$vc_files"; then
3039       echo "gl_VC_FILES([$vc_files])"
3040     fi
3041   ) > "$tmpfile"
3042   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
3043     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
3044       rm -f "$tmpfile"
3045     else
3046       if $doit; then
3047         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
3048         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
3049         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
3050       else
3051         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
3052         if false; then
3053           cat "$tmpfile"
3054           echo
3055           echo "# gnulib-cache.m4 ends here"
3056         fi
3057         rm -f "$tmpfile"
3058       fi
3059     fi
3060   else
3061     if $doit; then
3062       echo "Creating $m4base/gnulib-cache.m4"
3063       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
3064     else
3065       echo "Create $m4base/gnulib-cache.m4"
3066       cat "$tmpfile"
3067       rm -f "$tmpfile"
3068     fi
3069   fi
3070
3071   # Create m4/gnulib-comp.m4.
3072   func_dest_tmpfilename $m4base/gnulib-comp.m4
3073   (
3074     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
3075     func_emit_copyright_notice
3076     echo "#"
3077     echo "# This file represents the compiled summary of the specification in"
3078     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
3079     echo "# to be invoked from configure.ac."
3080     echo "# In projects using CVS, this file can be treated like other built files."
3081     echo
3082     echo
3083     echo "# This macro should be invoked from $configure_ac, in the section"
3084     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
3085     echo "# any checks for libraries, header files, types and library functions."
3086     echo "AC_DEFUN([${macro_prefix}_EARLY],"
3087     echo "["
3088     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3089     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3090     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3091     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3092     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
3093     if test -n "$uses_subdirs"; then
3094       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
3095     fi
3096     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
3097       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
3098     fi
3099     for module in $final_modules; do
3100       func_verify_module
3101       if test -n "$module"; then
3102         func_get_autoconf_early_snippet "$module"
3103       fi
3104     done \
3105       | sed -e '/^$/d;' -e 's/^/  /'
3106     echo "])"
3107     echo
3108     echo "# This macro should be invoked from $configure_ac, in the section"
3109     echo "# \"Check for header files, types and library functions\"."
3110     echo "AC_DEFUN([${macro_prefix}_INIT],"
3111     echo "["
3112     if test "$libtool" = true; then
3113       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3114       echo "  gl_cond_libtool=true"
3115     else
3116       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3117       echo "  gl_cond_libtool=false"
3118       echo "  gl_libdeps="
3119       echo "  gl_ltlibdeps="
3120     fi
3121     if test "$auxdir" != "build-aux"; then
3122       sed_replace_build_aux='
3123         :a
3124         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3125           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3126           ba
3127         }'
3128     else
3129       sed_replace_build_aux=
3130     fi
3131     func_emit_initmacro_start $macro_prefix
3132     echo "  gl_source_base='$sourcebase'"
3133     for module in $main_modules; do
3134       func_verify_module
3135       if test -n "$module"; then
3136         func_get_autoconf_snippet "$module" \
3137           | sed -e '/^$/d;' -e 's/^/  /' \
3138                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3139                 -e "$sed_replace_build_aux"
3140         if test "$module" = 'alloca' && test "$libtool" = true; then
3141           echo 'changequote(,)dnl'
3142           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3143           echo 'changequote([, ])dnl'
3144           echo 'AC_SUBST([LTALLOCA])'
3145         fi
3146       fi
3147     done
3148     func_emit_initmacro_end $macro_prefix
3149     echo "  gltests_libdeps="
3150     echo "  gltests_ltlibdeps="
3151     func_emit_initmacro_start ${macro_prefix}tests
3152     echo "  gl_source_base='$testsbase'"
3153     for module in $testsrelated_modules; do
3154       func_verify_module
3155       if test -n "$module"; then
3156         func_get_autoconf_snippet "$module" \
3157           | sed -e '/^$/d;' -e 's/^/  /' \
3158                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3159                 -e "$sed_replace_build_aux" \
3160                 -e 's/\$gl_cond_libtool/false/g' \
3161                 -e 's/gl_libdeps/gltests_libdeps/g' \
3162                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3163       fi
3164     done
3165     func_emit_initmacro_end ${macro_prefix}tests
3166     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3167     # created using libtool, because libtool already handles the dependencies.
3168     if test "$libtool" != true; then
3169       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3170       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3171       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3172       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3173       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3174     fi
3175     if $use_libtests; then
3176       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
3177       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
3178     fi
3179     echo "])"
3180     func_emit_initmacro_done $macro_prefix $sourcebase
3181     func_emit_initmacro_done ${macro_prefix}tests $testsbase
3182     echo
3183     echo "# This macro records the list of files which have been installed by"
3184     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
3185     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
3186     echo "$files" | sed -e 's,^,  ,'
3187     echo "])"
3188   ) > "$tmpfile"
3189   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3190     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
3191       rm -f "$tmpfile"
3192     else
3193       if $doit; then
3194         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3195         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
3196         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3197       else
3198         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3199         if false; then
3200           cat "$tmpfile"
3201           echo
3202           echo "# gnulib-comp.m4 ends here"
3203         fi
3204         rm -f "$tmpfile"
3205       fi
3206     fi
3207   else
3208     if $doit; then
3209       echo "Creating $m4base/gnulib-comp.m4"
3210       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3211     else
3212       echo "Create $m4base/gnulib-comp.m4"
3213       cat "$tmpfile"
3214       rm -f "$tmpfile"
3215     fi
3216   fi
3217
3218   if test -n "$inctests"; then
3219     # Create tests makefile.
3220     func_dest_tmpfilename $testsbase/$makefile_am
3221     modules="$testsrelated_modules"
3222     func_emit_tests_Makefile_am > "$tmpfile"
3223     if test -f "$destdir"/$testsbase/$makefile_am; then
3224       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
3225         rm -f "$tmpfile"
3226       else
3227         if $doit; then
3228           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3229           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
3230           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3231         else
3232           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3233           rm -f "$tmpfile"
3234         fi
3235       fi
3236     else
3237       if $doit; then
3238         echo "Creating $testsbase/$makefile_am"
3239         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3240       else
3241         echo "Create $testsbase/$makefile_am"
3242         rm -f "$tmpfile"
3243       fi
3244     func_append added_files "$testsbase/$makefile_am$nl"
3245     fi
3246   fi
3247
3248   if test "$vc_files" != false; then
3249     # Update the .cvsignore and .gitignore files.
3250     { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
3251       echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
3252       # Treat gnulib-comp.m4 like an added file, even if it already existed.
3253       echo "$m4base/|A|gnulib-comp.m4"
3254     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
3255     { # Rearrange file descriptors. Needed because "while ... done < ..."
3256       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3257       exec 5<&0 < "$tmp"/fileset-changes
3258       func_update_ignorelist ()
3259       {
3260         ignore="$1"
3261         if test "$ignore" = .gitignore; then
3262           # In a .gitignore file, "foo" applies to the current directory and all
3263           # subdirectories, whereas "/foo" applies to the current directory only.
3264           anchor='/'
3265           escaped_anchor='\/'
3266           doubly_escaped_anchor='\\/'
3267         else
3268           anchor=''
3269           escaped_anchor=''
3270           doubly_escaped_anchor=''
3271         fi
3272         if test -f "$destdir/$dir$ignore"; then
3273           if test -n "$dir_added" || test -n "$dir_removed"; then
3274             sed -e "s|^$anchor||" < "$destdir/$dir$ignore" | LC_ALL=C sort > "$tmp"/ignore
3275             echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
3276               | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
3277             echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
3278               | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
3279             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
3280               if $doit; then
3281                 echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3282                 mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
3283                 { sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed
3284                   if test -n "$anchor"; then sed -e "s,^,/^${doubly_escaped_anchor}," -e 's,$,\$/d,' < "$tmp"/ignore-removed; fi
3285                 } > "$tmp"/sed-ignore-removed
3286                 { cat "$destdir/$dir$ignore"~
3287                   sed -e "s|^|$anchor|" < "$tmp"/ignore-added
3288                 } | sed -f "$tmp"/sed-ignore-removed \
3289                   > "$destdir/$dir$ignore"
3290               else
3291                 echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3292               fi
3293             fi
3294           fi
3295         else
3296           if test -n "$dir_added"; then
3297             if $doit; then
3298               echo "Creating $destdir/$dir$ignore"
3299               {
3300                 if test "$ignore" = .cvsignore; then
3301                   echo ".deps"
3302                   # Automake generates Makefile rules that create .dirstamp files.
3303                   echo ".dirstamp"
3304                 fi
3305                 echo "$dir_added" | sed -e '/^$/d' -e "s|^|$anchor|" | LC_ALL=C sort -u
3306               } > "$destdir/$dir$ignore"
3307             else
3308               echo "Create $destdir/$dir$ignore"
3309             fi
3310           fi
3311         fi
3312       }
3313       func_done_dir ()
3314       {
3315         dir="$1"
3316         dir_added="$2"
3317         dir_removed="$3"
3318         if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
3319           func_update_ignorelist .cvsignore
3320         fi
3321         if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
3322           func_update_ignorelist .gitignore
3323         fi
3324       }
3325       last_dir=
3326       last_dir_added=
3327       last_dir_removed=
3328       while read line; do
3329         # Why not ''read next_dir op file'' ? Because the dir column can be empty.
3330         next_dir=`echo "$line" | sed -e 's,|.*,,'`
3331         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
3332         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
3333         if test "$next_dir" != "$last_dir"; then
3334           func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3335           last_dir="$next_dir"
3336           last_dir_added=
3337           last_dir_removed=
3338         fi
3339         case $op in
3340           A) func_append last_dir_added "$file$nl";;
3341           R) func_append last_dir_removed "$file$nl";;
3342         esac
3343       done
3344       func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3345       exec 0<&5 5<&-
3346     }
3347   fi
3348
3349   echo "Finished."
3350   echo
3351   echo "You may need to add #include directives for the following .h files."
3352   # Intersect $specified_modules and $main_modules
3353   # (since $specified_modules is not necessarily of subset of $main_modules
3354   # - some may have been skipped through --avoid, and since the elements of
3355   # $main_modules but not in $specified_modules can go away without explicit
3356   # notice - through changes in the module dependencies).
3357   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
3358   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
3359   # First the #include <...> directives without #ifs, sorted for convenience,
3360   # then the #include "..." directives without #ifs, sorted for convenience,
3361   # then the #include directives that are surrounded by #ifs. Not sorted.
3362   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
3363     include_directive=`func_get_include_directive "$module"`
3364     case "$nl$include_directive" in
3365       *"$nl#if"*)
3366         echo "$include_directive" 1>&5
3367         ;;
3368       *)
3369         echo "$include_directive" | grep -v 'include "' 1>&6
3370         echo "$include_directive" | grep 'include "' 1>&7
3371         ;;
3372     esac
3373   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
3374   (
3375    LC_ALL=C sort -u "$tmp"/include-angles
3376    LC_ALL=C sort -u "$tmp"/include-quotes
3377    cat "$tmp"/include-if
3378   ) | sed -e '/^$/d' -e 's/^/  /'
3379   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
3380
3381   for module in $main_modules; do
3382     func_get_link_directive "$module"
3383   done \
3384     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
3385   if test `wc -l < "$tmp"/link` != 0; then
3386     echo
3387     echo "You may need to use the following Makefile variables when linking."
3388     echo "Use them in <program>_LDADD when linking a program, or"
3389     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
3390     cat "$tmp"/link
3391   fi
3392   rm -f "$tmp"/link
3393
3394   echo
3395   echo "Don't forget to"
3396   if test "$makefile_am" = Makefile.am; then
3397     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3398   else
3399     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
3400   fi
3401   if test -n "$pobase"; then
3402     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
3403   fi
3404   if test -n "$inctests"; then
3405     if test "$makefile_am" = Makefile.am; then
3406       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3407     else
3408       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
3409     fi
3410   fi
3411   if test "$makefile_am" = Makefile.am; then
3412     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
3413     sourcebase_base=`basename "$sourcebase"`
3414     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
3415   fi
3416   if test -n "$pobase"; then
3417     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
3418     pobase_base=`basename "$pobase"`
3419     echo "  - mention \"${pobase_base}\" in SUBDIRS in ${pobase_dir}Makefile.am,"
3420   fi
3421   if test -n "$inctests"; then
3422     if test "$makefile_am" = Makefile.am; then
3423       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
3424       testsbase_base=`basename "$testsbase"`
3425       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
3426     fi
3427   fi
3428   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
3429   {
3430     # Find the first parent directory of $m4base that contains a Makefile.am.
3431     sed_last='s,^.*/\([^/][^/]*\)//*$,\1/,
3432 s,//*$,/,'
3433     sed_butlast='s,[^/][^/]*//*$,,'
3434     dir1="${m4base}/"; dir2=""
3435     while test -n "$dir1" && test ! -f "${destdir}/${dir1}Makefile.am"; do
3436       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
3437       dir1=`echo "$dir1" | sed -e "$sed_butlast"`
3438     done
3439     echo "  - mention ${dir2}gnulib-cache.m4 in EXTRA_DIST in ${dir1}Makefile.am."
3440   }
3441   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
3442   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
3443 }
3444
3445 # func_create_testdir testdir modules
3446 # Input:
3447 # - local_gnulib_dir  from --local-dir
3448 # - auxdir          directory relative to destdir where to place build aux files
3449 func_create_testdir ()
3450 {
3451   testdir="$1"
3452   modules="$2"
3453   if test -z "$modules"; then
3454     # All modules together.
3455     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3456     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3457     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
3458     modules=`func_all_modules`
3459     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
3460   fi
3461   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
3462
3463   # Check that the license of every module is consistent with the license of
3464   # its dependencies.
3465   saved_modules="$modules"
3466   saved_inctests="$inctests"
3467   # When computing transitive closures, don't consider $module to depend on
3468   # $module-tests. Need this becauses tests are implicitly GPL and may depend
3469   # on GPL modules - therefore we don't want a warning in this case.
3470   inctests=""
3471   for requested_module in $saved_modules; do
3472     requested_license=`func_get_license "$requested_module"`
3473     if test "$requested_license" != GPL; then
3474       # Here we use func_modules_transitive_closure, not just
3475       # func_get_dependencies, so that we also detect weird situations like
3476       # an LGPL module which depends on a GPLed build tool module which depends
3477       # on a GPL module.
3478       modules="$requested_module"
3479       func_modules_transitive_closure
3480       for module in $modules; do
3481         license=`func_get_license "$module"`
3482         case "$license" in
3483           'GPLed build tool') ;;
3484           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3485           *)
3486             case "$requested_license" in
3487               GPLv2+)
3488                 case "$license" in
3489                   GPLv2+ | LGPLv2+) ;;
3490                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3491                 esac
3492                 ;;
3493               LGPL)
3494                 case "$license" in
3495                   LGPL | LGPLv2+) ;;
3496                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3497                 esac
3498                 ;;
3499               LGPLv2+)
3500                 case "$license" in
3501                   LGPLv2+) ;;
3502                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3503                 esac
3504                 ;;
3505             esac
3506             ;;
3507         esac
3508       done
3509     fi
3510   done
3511   modules="$saved_modules"
3512   inctests="$saved_inctests"
3513
3514   # Subdirectory names.
3515   sourcebase=gllib
3516   m4base=glm4
3517   pobase=
3518   docbase=gldoc
3519   testsbase=gltests
3520   macro_prefix=gl
3521   po_domain=
3522   vc_files=
3523
3524   # Determine final module list.
3525   func_modules_transitive_closure
3526   if test $verbose -ge 0; then
3527     echo "Module list with included dependencies:"
3528     echo "$modules" | sed -e 's/^/  /'
3529   fi
3530
3531   # Add the dummy module if needed.
3532   func_modules_add_dummy
3533
3534   # Show banner notice of every module.
3535   func_modules_notice
3536
3537   # Determine final file list.
3538   func_modules_to_filelist
3539   if test $verbose -ge 0; then
3540     echo "File list:"
3541     echo "$files" | sed -e 's/^/  /'
3542   fi
3543
3544   sed_rewrite_files="\
3545     s,^build-aux/,$auxdir/,
3546     s,^doc/,$docbase/,
3547     s,^lib/,$sourcebase/,
3548     s,^m4/,$m4base/,
3549     s,^tests/,$testsbase/,
3550     s,^top/,,"
3551
3552   # Create directories.
3553   for f in $files; do echo $f; done \
3554     | sed -e "$sed_rewrite_files" \
3555     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3556     | LC_ALL=C sort -u \
3557     > "$tmp"/dirs
3558   { # Rearrange file descriptors. Needed because "while ... done < ..."
3559     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3560     exec 5<&0 < "$tmp"/dirs
3561     while read d; do
3562       mkdir -p "$testdir/$d"
3563     done
3564     exec 0<&5 5<&-
3565   }
3566
3567   # Copy files or make symbolic links.
3568   delimiter='   '
3569   for f in $files; do echo $f; done \
3570     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
3571     | LC_ALL=C sort \
3572     > "$tmp"/files
3573   { # Rearrange file descriptors. Needed because "while ... done < ..."
3574     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3575     exec 5<&0 < "$tmp"/files
3576     while read g f; do
3577       func_lookup_file "$f"
3578       if test -n "$lookedup_tmp"; then
3579         cp -p "$lookedup_file" "$testdir/$g"
3580       else
3581         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
3582         if { test -n "$symbolic" \
3583              || { test -n "$lsymbolic" \
3584                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
3585           func_ln "$lookedup_file" "$testdir/$g"
3586         else
3587           cp -p "$lookedup_file" "$testdir/$g"
3588         fi
3589       fi
3590     done
3591     exec 0<&5 5<&-
3592   }
3593
3594   # Create Makefile.ams that are for testing.
3595   for_test=true
3596
3597   # Create $sourcebase/Makefile.am.
3598   mkdir -p "$testdir/$sourcebase"
3599   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
3600   any_uses_subdirs="$uses_subdirs"
3601
3602   # Create $m4base/Makefile.am.
3603   mkdir -p "$testdir/$m4base"
3604   (echo "## Process this file with automake to produce Makefile.in."
3605    echo
3606    echo "EXTRA_DIST ="
3607    for f in $files; do
3608      case "$f" in
3609        m4/* )
3610          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
3611      esac
3612    done
3613   ) > "$testdir/$m4base/Makefile.am"
3614
3615   subdirs="$sourcebase $m4base"
3616   subdirs_with_configure_ac=""
3617
3618   if false && test -f "$testdir"/$m4base/gettext.m4; then
3619     # Avoid stupid error message from automake:
3620     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
3621     mkdir -p "$testdir/po"
3622     (echo "## Process this file with automake to produce Makefile.in."
3623     ) > "$testdir/po/Makefile.am"
3624     func_append subdirs " po"
3625   fi
3626
3627   if test -n "$inctests"; then
3628     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
3629     # Viewed from the $testsbase subdirectory, $auxdir is different.
3630     saved_auxdir="$auxdir"
3631     auxdir=`echo "$testsbase/"|sed 's%[^/][^/]*//*%../%g'`"$auxdir"
3632     # Create $testsbase/Makefile.am.
3633     use_libtests=false
3634     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
3635     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
3636     # Create $testsbase/configure.ac.
3637     (echo "# Process this file with autoconf to produce a configure script."
3638      echo "AC_INIT([dummy], [0])"
3639      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3640      echo "AM_INIT_AUTOMAKE"
3641      echo
3642      echo "AM_CONFIG_HEADER([config.h])"
3643      echo
3644      echo "AC_PROG_CC"
3645      echo "AC_PROG_INSTALL"
3646      echo "AC_PROG_MAKE_SET"
3647      echo "AC_PROG_RANLIB"
3648      echo
3649      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3650        echo "AC_GNU_SOURCE"
3651        echo
3652      fi
3653      for module in $modules; do
3654        func_verify_module
3655        if test -n "$module"; then
3656          func_get_autoconf_early_snippet "$module"
3657        fi
3658      done \
3659        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3660      if test "$libtool" = true; then
3661        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3662        echo "gl_cond_libtool=true"
3663      else
3664        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3665        echo "gl_cond_libtool=false"
3666        echo "gl_libdeps="
3667        echo "gl_ltlibdeps="
3668      fi
3669      # Wrap the set of autoconf snippets into an autoconf macro that is then
3670      # invoked. This is needed because autoconf does not support AC_REQUIRE
3671      # at the top level:
3672      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3673      # but we want the AC_REQUIRE to have its normal meaning (provide one
3674      # expansion of the required macro before the current point, and only one
3675      # expansion total).
3676      echo "AC_DEFUN([gl_INIT], ["
3677      sed_replace_build_aux='
3678        :a
3679        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3680          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3681          ba
3682        }'
3683      func_emit_initmacro_start $macro_prefix
3684      # We don't have explicit ordering constraints between the various
3685      # autoconf snippets. It's cleanest to put those of the library before
3686      # those of the tests.
3687      echo "gl_source_base='../$sourcebase'"
3688      for module in $modules; do
3689        func_verify_nontests_module
3690        if test -n "$module"; then
3691          func_get_autoconf_snippet "$module" \
3692            | sed -e "$sed_replace_build_aux"
3693        fi
3694      done
3695      echo "gl_source_base='.'"
3696      for module in $modules; do
3697        func_verify_tests_module
3698        if test -n "$module"; then
3699          func_get_autoconf_snippet "$module" \
3700            | sed -e "$sed_replace_build_aux"
3701        fi
3702      done
3703      func_emit_initmacro_end $macro_prefix
3704      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3705      # created using libtool, because libtool already handles the dependencies.
3706      if test "$libtool" != true; then
3707        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3708        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3709        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3710        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3711        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3712      fi
3713      echo "])"
3714      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
3715      echo
3716      echo "gl_INIT"
3717      echo
3718      # Usually $testsbase/config.h will be a superset of config.h. Verify this
3719      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
3720      echo "AH_TOP([#include \"../config.h\"])"
3721      echo
3722      echo "AC_OUTPUT([Makefile])"
3723     ) > "$testdir/$testsbase/configure.ac"
3724     auxdir="$saved_auxdir"
3725     func_append subdirs " $testsbase"
3726     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
3727   fi
3728
3729   # Create Makefile.am.
3730   (echo "## Process this file with automake to produce Makefile.in."
3731    echo
3732    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3733    echo
3734    echo "SUBDIRS = $subdirs"
3735    echo
3736    echo "ACLOCAL_AMFLAGS = -I $m4base"
3737   ) > "$testdir/Makefile.am"
3738
3739   # Create configure.ac.
3740   (echo "# Process this file with autoconf to produce a configure script."
3741    echo "AC_INIT([dummy], [0])"
3742    if test "$auxdir" != "."; then
3743      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3744    fi
3745    echo "AM_INIT_AUTOMAKE"
3746    echo
3747    echo "AM_CONFIG_HEADER([config.h])"
3748    echo
3749    echo "AC_PROG_CC"
3750    echo "AC_PROG_INSTALL"
3751    echo "AC_PROG_MAKE_SET"
3752    echo
3753    echo "# For autobuild."
3754    echo "AC_CANONICAL_BUILD"
3755    echo "AC_CANONICAL_HOST"
3756    echo
3757    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3758    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3759    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3760    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3761    echo
3762    echo "AC_PROG_RANLIB"
3763    echo
3764    if test -n "$any_uses_subdirs"; then
3765      echo "AM_PROG_CC_C_O"
3766      echo
3767    fi
3768    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3769      echo "AC_GNU_SOURCE"
3770      echo
3771    fi
3772    for module in $modules; do
3773      func_verify_nontests_module
3774      if test -n "$module"; then
3775        func_get_autoconf_early_snippet "$module"
3776      fi
3777    done \
3778      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3779    if test "$libtool" = true; then
3780      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3781      echo "gl_cond_libtool=true"
3782    else
3783      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3784      echo "gl_cond_libtool=false"
3785      echo "gl_libdeps="
3786      echo "gl_ltlibdeps="
3787    fi
3788    # Wrap the set of autoconf snippets into an autoconf macro that is then
3789    # invoked. This is needed because autoconf does not support AC_REQUIRE
3790    # at the top level:
3791    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3792    # but we want the AC_REQUIRE to have its normal meaning (provide one
3793    # expansion of the required macro before the current point, and only one
3794    # expansion total).
3795    echo "AC_DEFUN([gl_INIT], ["
3796    if test "$auxdir" != "build-aux"; then
3797      sed_replace_build_aux='
3798        :a
3799        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3800          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3801          ba
3802        }'
3803    else
3804      sed_replace_build_aux=
3805    fi
3806    func_emit_initmacro_start $macro_prefix
3807    echo "gl_source_base='$sourcebase'"
3808    for module in $modules; do
3809      func_verify_nontests_module
3810      if test -n "$module"; then
3811        func_get_autoconf_snippet "$module" \
3812          | sed -e "$sed_replace_build_aux"
3813      fi
3814    done
3815    func_emit_initmacro_end $macro_prefix
3816    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3817    # created using libtool, because libtool already handles the dependencies.
3818    if test "$libtool" != true; then
3819      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3820      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3821      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3822      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3823      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3824    fi
3825    echo "])"
3826    func_emit_initmacro_done $macro_prefix $sourcebase
3827    echo
3828    echo "gl_INIT"
3829    echo
3830    if test -n "$subdirs_with_configure_ac"; then
3831      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3832    fi
3833    makefiles="Makefile"
3834    for d in $subdirs; do
3835      # For subdirs that have a configure.ac by their own, it's the subdir's
3836      # configure.ac which creates the subdir's Makefile.am, not this one.
3837      case " $subdirs_with_configure_ac " in
3838        *" $d "*) ;;
3839        *) func_append makefiles " $d/Makefile" ;;
3840      esac
3841    done
3842    echo "AC_OUTPUT([$makefiles])"
3843   ) > "$testdir/configure.ac"
3844
3845   # Create autogenerated files.
3846   (cd "$testdir"
3847    # Do not use "${AUTORECONF} --force --install", because it may invoke
3848    # autopoint, which brings in older versions of some of our .m4 files.
3849    if test -f $m4base/gettext.m4; then
3850      func_execute_command ${AUTOPOINT} --force || func_exit 1
3851      for f in $m4base/*.m4~; do
3852        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3853      done
3854    fi
3855    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
3856    if ! test -d build-aux; then
3857      func_execute_command mkdir build-aux || func_exit 1
3858    fi
3859    func_execute_command ${AUTOCONF} || func_exit 1
3860    func_execute_command ${AUTOHEADER} || func_exit 1
3861    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3862   ) || func_exit 1
3863   if test -n "$inctests"; then
3864     # Create autogenerated files.
3865     (cd "$testdir/$testsbase" || func_exit 1
3866      # Do not use "${AUTORECONF} --force --install", because it may invoke
3867      # autopoint, which brings in older versions of some of our .m4 files.
3868      if test -f ../$m4base/gettext.m4; then
3869        func_execute_command ${AUTOPOINT} --force || func_exit 1
3870        for f in ../$m4base/*.m4~; do
3871          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3872        done
3873      fi
3874      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
3875      if ! test -d ../build-aux; then
3876        func_execute_command mkdir ../build-aux
3877      fi
3878      func_execute_command ${AUTOCONF} || func_exit 1
3879      func_execute_command ${AUTOHEADER} || func_exit 1
3880      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3881     ) || func_exit 1
3882   fi
3883   # Need to run configure and make once, to create built files that are to be
3884   # distributed (such as getdate.c).
3885   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3886   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3887                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3888   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3889   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3890   # such $(FOO_H) because they don't refer to distributed files.
3891   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3892   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3893                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3894                  | sed -e "$sed_remove_make_variables"`
3895   distributed_built_sources=`for file in $built_sources; do
3896                                case "$cleaned_files" in
3897                                  *" "$file" "*) ;;
3898                                  *) echo $file ;;
3899                                esac;
3900                              done`
3901   if test -n "$distributed_built_sources"; then
3902     (cd "$testdir"
3903      ./configure || func_exit 1
3904        cd "$sourcebase"
3905        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3906        make built_sources || func_exit 1
3907        cd ..
3908      make distclean || func_exit 1
3909     ) || func_exit 1
3910   fi
3911 }
3912
3913 # func_create_megatestdir megatestdir allmodules
3914 # Input:
3915 # - local_gnulib_dir  from --local-dir
3916 # - auxdir          directory relative to destdir where to place build aux files
3917 func_create_megatestdir ()
3918 {
3919   megatestdir="$1"
3920   allmodules="$2"
3921   if test -z "$allmodules"; then
3922     allmodules=`func_all_modules`
3923   fi
3924
3925   megasubdirs=
3926   # First, all modules one by one.
3927   for onemodule in $allmodules; do
3928     func_create_testdir "$megatestdir/$onemodule" $onemodule
3929     func_append megasubdirs "$onemodule "
3930   done
3931   # Then, all modules all together.
3932   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3933   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3934   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3935   func_create_testdir "$megatestdir/ALL" "$allmodules"
3936   func_append megasubdirs "ALL"
3937
3938   # Create autobuild.
3939   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
3940              vc_witness="$gnulib_dir/CVS/Entries"; \
3941            else \
3942              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
3943            fi; \
3944            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
3945              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3946                    -e 's,February,02,'  -e 's,Feb,02,' \
3947                    -e 's,March,03,'     -e 's,Mar,03,' \
3948                    -e 's,April,04,'     -e 's,Apr,04,' \
3949                    -e 's,May,05,'                      \
3950                    -e 's,June,06,'      -e 's,Jun,06,' \
3951                    -e 's,July,07,'      -e 's,Jul,07,' \
3952                    -e 's,August,08,'    -e 's,Aug,08,' \
3953                    -e 's,September,09,' -e 's,Sep,09,' \
3954                    -e 's,October,10,'   -e 's,Oct,10,' \
3955                    -e 's,November,11,'  -e 's,Nov,11,' \
3956                    -e 's,December,12,'  -e 's,Dec,12,' \
3957                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3958                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3959   (echo '#!/bin/sh'
3960    echo "CVSDATE=$cvsdate"
3961    echo "test -d logs || mkdir logs"
3962    echo "for module in $megasubdirs; do"
3963    echo "  echo \"Working on module \$module...\""
3964    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3965    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3966    echo "   echo"
3967    echo "   set -x"
3968    echo "   : autobuild project... \$module"
3969    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3970    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3971    echo "   : autobuild hostname... \`hostname\`"
3972    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3973    echo "   echo rc=\$?"
3974    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3975    echo "done"
3976   ) > "$megatestdir/do-autobuild"
3977   chmod a+x "$megatestdir/do-autobuild"
3978
3979   # Create Makefile.am.
3980   (echo "## Process this file with automake to produce Makefile.in."
3981    echo
3982    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3983    echo
3984    echo "SUBDIRS = $megasubdirs"
3985    echo
3986    echo "EXTRA_DIST = do-autobuild"
3987   ) > "$megatestdir/Makefile.am"
3988
3989   # Create configure.ac.
3990   (echo "# Process this file with autoconf to produce a configure script."
3991    echo "AC_INIT([dummy], [0])"
3992    if test "$auxdir" != "."; then
3993      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3994    fi
3995    echo "AM_INIT_AUTOMAKE"
3996    echo
3997    echo "AC_PROG_MAKE_SET"
3998    echo
3999    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
4000    echo "AC_OUTPUT([Makefile])"
4001   ) > "$megatestdir/configure.ac"
4002
4003   # Create autogenerated files.
4004   (cd "$megatestdir"
4005    # Do not use "${AUTORECONF} --install", because autoreconf operates
4006    # recursively, but the subdirectories are already finished, therefore
4007    # calling autoreconf here would only waste lots of CPU time.
4008    func_execute_command ${ACLOCAL} || func_exit 1
4009    func_execute_command mkdir build-aux
4010    func_execute_command ${AUTOCONF} || func_exit 1
4011    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
4012   ) || func_exit 1
4013 }
4014
4015 case $mode in
4016   "" )
4017     func_fatal_error "no mode specified" ;;
4018
4019   list )
4020     func_all_modules
4021     ;;
4022
4023   import | update )
4024
4025     # Where to import.
4026     if test -z "$destdir"; then
4027       destdir=.
4028     fi
4029     test -d "$destdir" \
4030       || func_fatal_error "destination directory does not exist: $destdir"
4031
4032     # Prefer configure.ac to configure.in.
4033     if test -f "$destdir"/configure.ac; then
4034       configure_ac="$destdir/configure.ac"
4035     else
4036       if test -f "$destdir"/configure.in; then
4037         configure_ac="$destdir/configure.in"
4038       else
4039         func_fatal_error "cannot find $destdir/configure.ac"
4040       fi
4041     fi
4042
4043     # Analyze configure.ac.
4044     guessed_auxdir="."
4045     guessed_libtool=false
4046     my_sed_traces='
4047       s,#.*$,,
4048       s,^dnl .*$,,
4049       s, dnl .*$,,
4050       /AC_CONFIG_AUX_DIR/ {
4051         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
4052       }
4053       /A[CM]_PROG_LIBTOOL/ {
4054         s,^.*$,guessed_libtool=true,p
4055       }'
4056     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
4057
4058     if test -z "$auxdir"; then
4059       auxdir="$guessed_auxdir"
4060     fi
4061
4062     # Determine where to apply func_import.
4063     if test -n "$m4base"; then
4064       # Apply func_import to a particular gnulib directory.
4065       # Any number of additional modules can be given.
4066       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
4067         # First use of gnulib in the given m4base.
4068         test -n "$supplied_libname" || supplied_libname=true
4069         test -n "$sourcebase" || sourcebase="lib"
4070         test -n "$docbase" || docbase="doc"
4071         test -n "$testsbase" || testsbase="tests"
4072         test -n "$macro_prefix" || macro_prefix="gl"
4073       fi
4074       func_import "$*"
4075     else
4076       # Apply func_import to all gnulib directories.
4077       # To get this list of directories, look at Makefile.am. (Not at
4078       # configure, because it may be omitted from CVS. Also, don't run
4079       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
4080       m4dirs=
4081       m4dirs_count=0
4082       if test -f "$destdir"/Makefile.am; then
4083         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
4084         m4dir_is_next=
4085         for arg in $aclocal_amflags; do
4086           if test -n "$m4dir_is_next"; then
4087             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
4088             case "$arg" in
4089               /*) ;;
4090               *)
4091                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
4092                   func_append m4dirs " $arg"
4093                   m4dirs_count=`expr $m4dirs_count + 1`
4094                 fi
4095                 ;;
4096             esac
4097             m4dir_is_next=
4098           else
4099             if test "X$arg" = "X-I"; then
4100               m4dir_is_next=yes
4101             else
4102               m4dir_is_next=
4103             fi
4104           fi
4105         done
4106       else
4107         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
4108         if test -f "$destdir"/aclocal.m4; then
4109           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
4110           sedexpr2='s,^[^/]*$,.,'
4111           sedexpr3='s,/[^/]*$,,'
4112           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
4113           m4dirs_count=`echo "$m4dirs" | wc -l`
4114         fi
4115       fi
4116       if test $m4dirs_count = 0; then
4117         # First use of gnulib in a package.
4118         # Any number of additional modules can be given.
4119         test -n "$supplied_libname" || supplied_libname=true
4120         test -n "$sourcebase" || sourcebase="lib"
4121         m4base="m4"
4122         test -n "$docbase" || docbase="doc"
4123         test -n "$testsbase" || testsbase="tests"
4124         test -n "$macro_prefix" || macro_prefix="gl"
4125         func_import "$*"
4126       else
4127         if test $m4dirs_count = 1; then
4128           # There's only one use of gnulib here. Assume the user means it.
4129           # Any number of additional modules can be given.
4130           for m4base in $m4dirs; do
4131             func_import "$*"
4132           done
4133         else
4134           # Ambiguous - guess what the user meant.
4135           if test $# = 0; then
4136             # No further arguments. Guess the user wants to update all of them.
4137             for m4base in $m4dirs; do
4138               # Perform func_import in a subshell, so that variable values
4139               # such as
4140               #   local_gnulib_dir, avoidlist, sourcebase, m4base, pobase,
4141               #   docbase, testsbase, inctests, libname, lgpl, makefile_name,
4142               #   libtool, macro_prefix, po_domain, vc_files
4143               # don't propagate from one directory to another.
4144               (func_import) || func_exit 1
4145             done
4146           else
4147             # Really ambiguous.
4148             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
4149           fi
4150         fi
4151       fi
4152     fi
4153     ;;
4154
4155   create-testdir )
4156     if test -z "$destdir"; then
4157       func_fatal_error "please specify --dir option"
4158     fi
4159     mkdir "$destdir"
4160     test -d "$destdir" \
4161       || func_fatal_error "could not create destination directory"
4162     test -n "$auxdir" || auxdir="build-aux"
4163     func_create_testdir "$destdir" "$*"
4164     ;;
4165
4166   create-megatestdir )
4167     if test -z "$destdir"; then
4168       func_fatal_error "please specify --dir option"
4169     fi
4170     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4171     test -n "$auxdir" || auxdir="build-aux"
4172     func_create_megatestdir "$destdir" "$*"
4173     ;;
4174
4175   test )
4176     test -n "$destdir" || destdir=testdir$$
4177     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4178     test -n "$auxdir" || auxdir="build-aux"
4179     func_create_testdir "$destdir" "$*"
4180     cd "$destdir"
4181       mkdir build
4182       cd build
4183         ../configure || func_exit 1
4184         make || func_exit 1
4185         make check || func_exit 1
4186         make distclean || func_exit 1
4187         remaining=`find . -type f -print`
4188         if test -n "$remaining"; then
4189           echo "Remaining files:" $remaining 1>&2
4190           echo "gnulib-tool: *** Stop." 1>&2
4191           func_exit 1
4192         fi
4193       cd ..
4194     cd ..
4195     rm -rf "$destdir"
4196     ;;
4197
4198   megatest )
4199     test -n "$destdir" || destdir=testdir$$
4200     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4201     test -n "$auxdir" || auxdir="build-aux"
4202     func_create_megatestdir "$destdir" "$*"
4203     cd "$destdir"
4204       mkdir build
4205       cd build
4206         ../configure
4207         make
4208         make check
4209         make distclean
4210         remaining=`find . -type f -print`
4211         if test -n "$remaining"; then
4212           echo "Remaining files:" $remaining 1>&2
4213           echo "gnulib-tool: *** Stop." 1>&2
4214           func_exit 1
4215         fi
4216       cd ..
4217     cd ..
4218     rm -rf "$destdir"
4219     ;;
4220
4221   extract-description )
4222     for module
4223     do
4224       func_verify_module
4225       if test -n "$module"; then
4226         func_get_description "$module"
4227       fi
4228     done
4229     ;;
4230
4231   extract-notice )
4232     for module
4233     do
4234       func_verify_module
4235       if test -n "$module"; then
4236         func_get_notice "$module"
4237       fi
4238     done
4239     ;;
4240
4241   extract-filelist )
4242     for module
4243     do
4244       func_verify_module
4245       if test -n "$module"; then
4246         func_get_filelist "$module"
4247       fi
4248     done
4249     ;;
4250
4251   extract-dependencies )
4252     for module
4253     do
4254       func_verify_module
4255       if test -n "$module"; then
4256         func_get_dependencies "$module"
4257       fi
4258     done
4259     ;;
4260
4261   extract-autoconf-snippet )
4262     for module
4263     do
4264       func_verify_module
4265       if test -n "$module"; then
4266         func_get_autoconf_snippet "$module"
4267       fi
4268     done
4269     ;;
4270
4271   extract-automake-snippet )
4272     for module
4273     do
4274       func_verify_module
4275       if test -n "$module"; then
4276         func_get_automake_snippet "$module"
4277       fi
4278     done
4279     ;;
4280
4281   extract-include-directive )
4282     for module
4283     do
4284       func_verify_module
4285       if test -n "$module"; then
4286         func_get_include_directive "$module"
4287       fi
4288     done
4289     ;;
4290
4291   extract-link-directive )
4292     for module
4293     do
4294       func_verify_module
4295       if test -n "$module"; then
4296         func_get_link_directive "$module"
4297       fi
4298     done
4299     ;;
4300
4301   extract-license )
4302     for module
4303     do
4304       func_verify_module
4305       if test -n "$module"; then
4306         func_get_license "$module"
4307       fi
4308     done
4309     ;;
4310
4311   extract-maintainer )
4312     for module
4313     do
4314       func_verify_module
4315       if test -n "$module"; then
4316         func_get_maintainer "$module"
4317       fi
4318     done
4319     ;;
4320
4321   extract-tests-module )
4322     for module
4323     do
4324       func_verify_module
4325       if test -n "$module"; then
4326         func_get_tests_module "$module"
4327       fi
4328     done
4329     ;;
4330
4331   * )
4332     func_fatal_error "unknown operation mode --$mode" ;;
4333 esac
4334
4335 rm -rf "$tmp"
4336 # Undo the effect of the previous 'trap' command. Some shellology:
4337 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
4338 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
4339 # exit); for the others we need to call 'exit' explicitly. The value of $? is
4340 # 128 + signal number and is set before the trap-registered command is run.
4341 trap '' 0
4342 trap 'func_exit $?' 1 2 3 13 15
4343
4344 exit 0
4345
4346 # Local Variables:
4347 # indent-tabs-mode: nil
4348 # whitespace-check-buffer-indent: nil
4349 # End: