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