* m4/time_h.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Fix misspelling
[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-08-26 10:36:54 $'
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 -h "$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   fi
2035   # The docbase defaults to the cached one.
2036   if test -z "$docbase"; then
2037     docbase="$cached_docbase"
2038     if test -z "$docbase"; then
2039       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."
2040     fi
2041   fi
2042   # The testsbase defaults to the cached one.
2043   if test -z "$testsbase"; then
2044     testsbase="$cached_testsbase"
2045     if test -z "$testsbase"; then
2046       func_fatal_error "missing --tests-base option"
2047     fi
2048   fi
2049   # Require the tests if specified either way.
2050   if test -z "$inctests"; then
2051     inctests="$cached_inctests"
2052   fi
2053   # The libname defaults to the cached one.
2054   if test -z "$supplied_libname"; then
2055     libname="$cached_libname"
2056     if test -z "$libname"; then
2057       func_fatal_error "missing --lib option"
2058     fi
2059   fi
2060   # Require LGPL if specified either way.
2061   if test -z "$lgpl"; then
2062     lgpl="$cached_lgpl"
2063   fi
2064   # The makefile_name defaults to the cached one.
2065   if test -z "$makefile_name"; then
2066     makefile_name="$cached_makefile_name"
2067   fi
2068   # Use libtool if specified either way, or if guessed.
2069   if test -z "$libtool"; then
2070     if test -n "$cached_m4base"; then
2071       libtool="$cached_libtool"
2072     else
2073       libtool="$guessed_libtool"
2074     fi
2075   fi
2076   # The macro_prefix defaults to the cached one.
2077   if test -z "$macro_prefix"; then
2078     macro_prefix="$cached_macro_prefix"
2079     if test -z "$macro_prefix"; then
2080       func_fatal_error "missing --macro-prefix option"
2081     fi
2082   fi
2083   # The po_domain defaults to the cached one.
2084   if test -z "$po_domain"; then
2085     po_domain="$cached_po_domain"
2086   fi
2087
2088   # Canonicalize the list of specified modules.
2089   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
2090
2091   # Determine final module list.
2092   modules="$specified_modules"
2093   func_modules_transitive_closure
2094   echo "Module list with included dependencies:"
2095   echo "$modules" | sed -e 's/^/  /'
2096
2097   # Add the dummy module if needed.
2098   func_modules_add_dummy
2099
2100   # If --lgpl, verify that the licenses of modules are compatible.
2101   if test -n "$lgpl"; then
2102     for module in $modules; do
2103       license=`func_get_license $module`
2104       case $license in
2105         LGPL | LGPLv2+ | 'GPLed build tool') ;;
2106         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2107         *) func_fatal_error "incompatible license on module $module: $license" ;;
2108       esac
2109     done
2110   fi
2111
2112   # Determine script to apply to imported library files.
2113   sed_transform_lib_file=
2114   for module in $modules; do
2115     if test $module = config-h; then
2116       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
2117       sed_transform_lib_file=$sed_transform_lib_file'
2118         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
2119       '
2120       break
2121     fi
2122   done
2123   if test -n "$do_copyrights"; then
2124     if test -n "$lgpl"; then
2125       # Update license.
2126       sed_transform_lib_file=$sed_transform_lib_file'
2127         s/GNU General/GNU Lesser General/g
2128         s/version 2\([ ,]\)/version 2.1\1/g
2129       '
2130     fi
2131   fi
2132
2133   # Determine final file list.
2134   func_modules_to_filelist
2135   echo "File list:"
2136   echo "$files" | sed -e 's/^/  /'
2137
2138   test -n "$files" \
2139     || func_fatal_error "refusing to do nothing"
2140
2141   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2142   new_files="$files m4/gnulib-tool.m4"
2143   old_files="$cached_files"
2144   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2145     func_append old_files " m4/gnulib-tool.m4"
2146   fi
2147
2148   sed_rewrite_old_files="\
2149     s,^build-aux/,$auxdir/,
2150     s,^doc/,$cached_docbase/,
2151     s,^lib/,$cached_sourcebase/,
2152     s,^m4/,$cached_m4base/,
2153     s,^tests/,$cached_testsbase/,"
2154   sed_rewrite_new_files="\
2155     s,^build-aux/,$auxdir/,
2156     s,^doc/,$docbase/,
2157     s,^lib/,$sourcebase/,
2158     s,^m4/,$m4base/,
2159     s,^tests/,$testsbase/,"
2160
2161   # Create directories.
2162   { echo "$sourcebase"
2163     echo "$m4base"
2164     if test -n "$pobase"; then
2165       echo "$pobase"
2166     fi
2167     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2168     if test -n "$docfiles"; then
2169       echo "$docbase"
2170     fi
2171     if test -n "$inctests"; then
2172       echo "$testsbase"
2173     fi
2174     echo "$auxdir"
2175     for f in $files; do echo $f; done \
2176       | sed -e "$sed_rewrite_new_files" \
2177       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2178       | LC_ALL=C sort -u
2179   } > "$tmp"/dirs
2180   { # Rearrange file descriptors. Needed because "while ... done < ..."
2181     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2182     exec 5<&0 < "$tmp"/dirs
2183     while read d; do
2184       if test ! -d "$destdir/$d"; then
2185         if $doit; then
2186           echo "Creating directory $destdir/$d"
2187           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2188         else
2189           echo "Create directory $destdir/$d"
2190         fi
2191       fi
2192     done
2193     exec 0<&5 5<&-
2194   }
2195
2196   # func_dest_tmpfilename file
2197   # determines the name of a temporary file (file is relative to destdir).
2198   # Sets variable:
2199   #   - tmpfile       absolute filename of the temporary file
2200   func_dest_tmpfilename ()
2201   {
2202     if $doit; then
2203       # Put the new contents of $file in a file in the same directory (needed
2204       # to guarantee that an 'mv' to "$destdir/$file" works).
2205       tmpfile="$destdir/$1.tmp"
2206     else
2207       # Put the new contents of $file in a file in a temporary directory
2208       # (because the directory of "$file" might not exist).
2209       tmpfile="$tmp"/`basename "$1"`.tmp
2210     fi
2211   }
2212
2213   # Copy files or make symbolic links. Remove obsolete files.
2214   added_files=''
2215   removed_files=''
2216   delimiter='   '
2217   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2218   # representing the files according to the last gnulib-tool invocation.
2219   for f in $old_files; do echo $f; done \
2220     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2221     | LC_ALL=C sort \
2222     > "$tmp"/old-files
2223   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2224   # representing the files after this gnulib-tool invocation.
2225   for f in $new_files; do echo $f; done \
2226     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2227     | LC_ALL=C sort \
2228     > "$tmp"/new-files
2229   # First the files that are in old-files, but not in new-files:
2230   sed_take_first_column='s,'"$delimiter"'.*,,'
2231   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2232     # Remove the file. Do nothing if the user already removed it.
2233     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
2234       if $doit; then
2235         echo "Removing file $g (backup in ${g}~)"
2236         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2237       else
2238         echo "Remove file $g (backup in ${g}~)"
2239       fi
2240       func_append removed_files "$g$nl"
2241     fi
2242   done
2243   # func_add_or_update handles a file that ought to be present afterwards.
2244   # Uses parameters
2245   # - f             the original file name
2246   # - g             the rewritten file name
2247   # - already_present  nonempty if the file already exists, empty otherwise
2248   func_add_or_update ()
2249   {
2250     func_dest_tmpfilename "$g"
2251     func_lookup_file "$f"
2252     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2253     if test -n "$sed_transform_lib_file"; then
2254       case "$f" in
2255         lib/*)
2256           sed -e "$sed_transform_lib_file" \
2257             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2258           ;;
2259       esac
2260     fi
2261     if test -f "$destdir/$g"; then
2262       # The file already exists.
2263       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2264         : # The file has not changed.
2265       else
2266         # Replace the file.
2267         if $doit; then
2268           if test -n "$already_present"; then
2269             echo "Updating file $g (backup in ${g}~)"
2270           else
2271             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
2272           fi
2273           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2274           if { test -n "$symbolic" \
2275                || { test -n "$lsymbolic" \
2276                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2277              && test -z "$lookedup_tmp" \
2278              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2279             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2280           else
2281             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2282           fi
2283         else
2284           if test -n "$already_present"; then
2285             echo "Update file $g (backup in ${g}~)"
2286           else
2287             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
2288           fi
2289         fi
2290       fi
2291     else
2292       # Install the file.
2293       # Don't protest if the file should be there but isn't: it happens
2294       # frequently that developers don't put autogenerated files into CVS.
2295       if $doit; then
2296         echo "Copying file $g"
2297         if { test -n "$symbolic" \
2298              || { test -n "$lsymbolic" \
2299                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2300            && test -z "$lookedup_tmp" \
2301            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2302           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2303         else
2304           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2305         fi
2306       else
2307         echo "Copy file $g"
2308       fi
2309       func_append added_files "$g$nl"
2310     fi
2311     rm -f "$tmpfile"
2312   }
2313   # Then the files that are in new-files, but not in old-files:
2314   sed_take_last_column='s,^.*'"$delimiter"',,'
2315   already_present=
2316   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2317     | sed -e "$sed_take_last_column" \
2318     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2319   { # Rearrange file descriptors. Needed because "while ... done < ..."
2320     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2321     exec 5<&0 < "$tmp"/added-files
2322     while read g f; do
2323       func_add_or_update
2324     done
2325     exec 0<&5 5<&-
2326   }
2327   # Then the files that are in new-files and in old-files:
2328   already_present=true
2329   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2330     | sed -e "$sed_take_last_column" \
2331     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2332   { # Rearrange file descriptors. Needed because "while ... done < ..."
2333     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2334     exec 5<&0 < "$tmp"/kept-files
2335     while read g f; do
2336       func_add_or_update
2337     done
2338     exec 0<&5 5<&-
2339   }
2340
2341   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2342   actioncmd="gnulib-tool --import"
2343   func_append actioncmd " --dir=$destdir"
2344   if test -n "$local_gnulib_dir"; then
2345     func_append actioncmd " --local-dir=$local_gnulib_dir"
2346   fi
2347   func_append actioncmd " --lib=$libname"
2348   func_append actioncmd " --source-base=$sourcebase"
2349   func_append actioncmd " --m4-base=$m4base"
2350   if test -n "$pobase"; then
2351     func_append actioncmd " --po-base=$pobase"
2352   fi
2353   func_append actioncmd " --doc-base=$docbase"
2354   func_append actioncmd " --aux-dir=$auxdir"
2355   if test -n "$inctests"; then
2356     func_append actioncmd " --with-tests"
2357   fi
2358   for module in $avoidlist; do
2359     func_append actioncmd " --avoid=$module"
2360   done
2361   if test -n "$lgpl"; then
2362     func_append actioncmd " --lgpl"
2363   fi
2364   if test -n "$makefile_name"; then
2365     func_append actioncmd " --makefile-name=$makefile_name"
2366   fi
2367   if test "$libtool" = true; then
2368     func_append actioncmd " --libtool"
2369   else
2370     func_append actioncmd " --no-libtool"
2371   fi
2372   func_append actioncmd " --macro-prefix=$macro_prefix"
2373   if test -n "$po_domain"; then
2374     func_append actioncmd " --po-domain=$po_domain"
2375   fi
2376   func_append actioncmd " `echo $specified_modules`"
2377
2378   # Default the makefile name to Makefile.am.
2379   if test -n "$makefile_name"; then
2380     makefile_am=$makefile_name
2381   else
2382     makefile_am=Makefile.am
2383   fi
2384
2385   # Create normal Makefile.ams.
2386   for_test=false
2387
2388   # Create library makefile.
2389   func_dest_tmpfilename $sourcebase/$makefile_am
2390   func_emit_lib_Makefile_am > "$tmpfile"
2391   if test -f "$destdir"/$sourcebase/$makefile_am; then
2392     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2393       rm -f "$tmpfile"
2394     else
2395       if $doit; then
2396         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2397         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2398         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2399       else
2400         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2401         rm -f "$tmpfile"
2402       fi
2403     fi
2404   else
2405     if $doit; then
2406       echo "Creating $sourcebase/$makefile_am"
2407       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2408     else
2409       echo "Create $sourcebase/$makefile_am"
2410       rm -f "$tmpfile"
2411     fi
2412     func_append added_files "$sourcebase/$makefile_am$nl"
2413   fi
2414
2415   # Create po/ directory.
2416   if test -n "$pobase"; then
2417     # Create po makefile and auxiliary files.
2418     for file in Makefile.in.in remove-potcdate.sin; do
2419       func_dest_tmpfilename $pobase/$file
2420       func_lookup_file build-aux/po/$file
2421       cat "$lookedup_file" > "$tmpfile"
2422       if test -f "$destdir"/$pobase/$file; then
2423         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
2424           rm -f "$tmpfile"
2425         else
2426           if $doit; then
2427             echo "Updating $pobase/$file (backup in $pobase/$file~)"
2428             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
2429             mv -f "$tmpfile" "$destdir"/$pobase/$file
2430           else
2431             echo "Update $pobase/$file (backup in $pobase/$file~)"
2432             rm -f "$tmpfile"
2433           fi
2434         fi
2435       else
2436         if $doit; then
2437           echo "Creating $pobase/$file"
2438           mv -f "$tmpfile" "$destdir"/$pobase/$file
2439         else
2440           echo "Create $pobase/$file"
2441           rm -f "$tmpfile"
2442         fi
2443         func_append added_files "$pobase/$file$nl"
2444       fi
2445     done
2446     # Create po makefile parametrization, part 1.
2447     func_dest_tmpfilename $pobase/Makevars
2448     func_emit_po_Makevars > "$tmpfile"
2449     if test -f "$destdir"/$pobase/Makevars; then
2450       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
2451         rm -f "$tmpfile"
2452       else
2453         if $doit; then
2454           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
2455           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
2456           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2457         else
2458           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
2459           rm -f "$tmpfile"
2460         fi
2461       fi
2462     else
2463       if $doit; then
2464         echo "Creating $pobase/Makevars"
2465         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2466       else
2467         echo "Create $pobase/Makevars"
2468         rm -f "$tmpfile"
2469       fi
2470       func_append added_files "$pobase/Makevars$nl"
2471     fi
2472     # Create po makefile parametrization, part 2.
2473     func_dest_tmpfilename $pobase/POTFILES.in
2474     func_emit_po_POTFILES_in > "$tmpfile"
2475     if test -f "$destdir"/$pobase/POTFILES.in; then
2476       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
2477         rm -f "$tmpfile"
2478       else
2479         if $doit; then
2480           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2481           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
2482           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2483         else
2484           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2485           rm -f "$tmpfile"
2486         fi
2487       fi
2488     else
2489       if $doit; then
2490         echo "Creating $pobase/POTFILES.in"
2491         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2492       else
2493         echo "Create $pobase/POTFILES.in"
2494         rm -f "$tmpfile"
2495       fi
2496       func_append added_files "$pobase/POTFILES.in$nl"
2497     fi
2498     # Fetch PO files.
2499     TP_URL="http://translationproject.org/latest/"
2500     if $doit; then
2501       echo "Fetching gnulib PO files from $TP_URL"
2502       (cd "$destdir"/$pobase \
2503        && wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
2504       )
2505     else
2506       echo "Fetch gnulib PO files from $TP_URL"
2507     fi
2508     # Create po/LINGUAS.
2509     if $doit; then
2510       func_dest_tmpfilename $pobase/LINGUAS
2511       (cd "$destdir"/$pobase \
2512        && { echo '# Set of available languages.'
2513             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
2514           }
2515       ) > "$tmpfile"
2516       if test -f "$destdir"/$pobase/LINGUAS; then
2517         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
2518           rm -f "$tmpfile"
2519         else
2520           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2521           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
2522           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2523         fi
2524       else
2525         echo "Creating $pobase/LINGUAS"
2526         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2527         func_append added_files "$pobase/LINGUAS$nl"
2528       fi
2529     else
2530       if test -f "$destdir"/$pobase/LINGUAS; then
2531         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2532       else
2533         echo "Create $pobase/LINGUAS"
2534       fi
2535     fi
2536   fi
2537
2538   # Create m4/gnulib-cache.m4.
2539   func_dest_tmpfilename $m4base/gnulib-cache.m4
2540   (
2541     func_emit_copyright_notice
2542     echo "#"
2543     echo "# This file represents the specification of how gnulib-tool is used."
2544     echo "# It acts as a cache: It is written and read by gnulib-tool."
2545     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2546     echo "# like the configure.ac and various Makefile.am files."
2547     echo
2548     echo
2549     echo "# Specification in the form of a command-line invocation:"
2550     echo "#   $actioncmd"
2551     echo
2552     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
2553     # Store the local_gnulib_dir relative to destdir.
2554     case "$local_gnulib_dir" in
2555       "" | /*)
2556         relative_local_gnulib_dir="$local_gnulib_dir" ;;
2557       * )
2558         case "$destdir" in
2559           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
2560           *)
2561             # destdir, local_gnulib_dir are both relative.
2562             func_relativize "$destdir" "$local_gnulib_dir"
2563             relative_local_gnulib_dir="$reldir" ;;
2564         esac ;;
2565     esac
2566     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
2567     echo "gl_MODULES(["`echo $specified_modules`"])"
2568     echo "gl_AVOID([$avoidlist])"
2569     echo "gl_SOURCE_BASE([$sourcebase])"
2570     echo "gl_M4_BASE([$m4base])"
2571     echo "gl_PO_BASE([$pobase])"
2572     echo "gl_DOC_BASE([$docbase])"
2573     echo "gl_TESTS_BASE([$testsbase])"
2574     test -z "$inctests" || echo "gl_WITH_TESTS"
2575     echo "gl_LIB([$libname])"
2576     test -z "$lgpl" || echo "gl_LGPL"
2577     echo "gl_MAKEFILE_NAME([$makefile_name])"
2578     if test "$libtool" = true; then
2579       echo "gl_LIBTOOL"
2580     fi
2581     echo "gl_MACRO_PREFIX([$macro_prefix])"
2582     echo "gl_PO_DOMAIN([$po_domain])"
2583   ) > "$tmpfile"
2584   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2585     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2586       rm -f "$tmpfile"
2587     else
2588       if $doit; then
2589         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2590         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2591         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2592       else
2593         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2594         if false; then
2595           cat "$tmpfile"
2596           echo
2597           echo "# gnulib-cache.m4 ends here"
2598         fi
2599         rm -f "$tmpfile"
2600       fi
2601     fi
2602   else
2603     if $doit; then
2604       echo "Creating $m4base/gnulib-cache.m4"
2605       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2606     else
2607       echo "Create $m4base/gnulib-cache.m4"
2608       cat "$tmpfile"
2609       rm -f "$tmpfile"
2610     fi
2611   fi
2612
2613   # Create m4/gnulib-comp.m4.
2614   func_dest_tmpfilename $m4base/gnulib-comp.m4
2615   (
2616     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2617     func_emit_copyright_notice
2618     echo "#"
2619     echo "# This file represents the compiled summary of the specification in"
2620     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2621     echo "# to be invoked from configure.ac."
2622     echo "# In projects using CVS, this file can be treated like other built files."
2623     echo
2624     echo
2625     echo "# This macro should be invoked from $configure_ac, in the section"
2626     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2627     echo "# any checks for libraries, header files, types and library functions."
2628     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2629     echo "["
2630     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2631     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2632     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2633     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2634     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2635     if test -n "$uses_subdirs"; then
2636       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2637     fi
2638     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2639       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2640     fi
2641     for module in $modules; do
2642       func_verify_module
2643       if test -n "$module"; then
2644         func_get_autoconf_early_snippet "$module"
2645       fi
2646     done \
2647       | sed -e '/^$/d;' -e 's/^/  /'
2648     echo "])"
2649     echo
2650     echo "# This macro should be invoked from $configure_ac, in the section"
2651     echo "# \"Check for header files, types and library functions\"."
2652     echo "AC_DEFUN([${macro_prefix}_INIT],"
2653     echo "["
2654     func_emit_initmacro_start
2655     if test "$libtool" = true; then
2656       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2657       echo "  gl_cond_libtool=true"
2658     else
2659       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2660       echo "  gl_cond_libtool=false"
2661       echo "  gl_libdeps="
2662       echo "  gl_ltlibdeps="
2663     fi
2664     echo "  gl_source_base='$sourcebase'"
2665     if test "$auxdir" != "build-aux"; then
2666       sed_replace_build_aux='
2667         :a
2668         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2669           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2670           ba
2671         }'
2672     else
2673       sed_replace_build_aux=
2674     fi
2675     for module in $modules; do
2676       func_verify_module
2677       if test -n "$module"; then
2678         func_get_autoconf_snippet "$module" \
2679           | sed -e '/^$/d;' -e 's/^/  /' \
2680                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
2681                 -e "$sed_replace_build_aux"
2682         if test "$module" = 'alloca' && test "$libtool" = true; then
2683           echo 'changequote(,)dnl'
2684           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
2685           echo 'changequote([, ])dnl'
2686           echo 'AC_SUBST([LTALLOCA])'
2687         fi
2688       fi
2689     done
2690     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2691     # created using libtool, because libtool already handles the dependencies.
2692     if test "$libtool" != true; then
2693       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
2694       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2695       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
2696       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2697       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
2698     fi
2699     func_emit_initmacro_end
2700     echo "])"
2701     func_emit_initmacro_done
2702     echo
2703     echo "# This macro records the list of files which have been installed by"
2704     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
2705     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
2706     echo "$files" | sed -e 's,^,  ,'
2707     echo "])"
2708   ) > "$tmpfile"
2709   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2710     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
2711       rm -f "$tmpfile"
2712     else
2713       if $doit; then
2714         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2715         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
2716         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2717       else
2718         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2719         if false; then
2720           cat "$tmpfile"
2721           echo
2722           echo "# gnulib-comp.m4 ends here"
2723         fi
2724         rm -f "$tmpfile"
2725       fi
2726     fi
2727   else
2728     if $doit; then
2729       echo "Creating $m4base/gnulib-comp.m4"
2730       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2731     else
2732       echo "Create $m4base/gnulib-comp.m4"
2733       cat "$tmpfile"
2734       rm -f "$tmpfile"
2735     fi
2736   fi
2737
2738   if test -n "$inctests"; then
2739     # Create tests makefile.
2740     func_dest_tmpfilename $testsbase/$makefile_am
2741     func_emit_tests_Makefile_am > "$tmpfile"
2742     if test -f "$destdir"/$testsbase/$makefile_am; then
2743       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
2744         rm -f "$tmpfile"
2745       else
2746         if $doit; then
2747           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2748           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
2749           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2750         else
2751           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2752           rm -f "$tmpfile"
2753         fi
2754       fi
2755     else
2756       if $doit; then
2757         echo "Creating $testsbase/$makefile_am"
2758         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2759       else
2760         echo "Create $testsbase/$makefile_am"
2761         rm -f "$tmpfile"
2762       fi
2763     func_append added_files "$testsbase/$makefile_am$nl"
2764     fi
2765   fi
2766
2767   # Update the .cvsignore and .gitignore files.
2768   { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
2769     echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
2770   } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
2771   { # Rearrange file descriptors. Needed because "while ... done < ..."
2772     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2773     exec 5<&0 < "$tmp"/fileset-changes
2774     func_update_ignorelist ()
2775     {
2776       ignore="$1"
2777       if test -f "$destdir/$dir$ignore"; then
2778         if test -n "$dir_added" || test -n "$dir_removed"; then
2779           LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
2780           echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
2781             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
2782           echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
2783             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
2784           if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
2785             if $doit; then
2786               echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
2787               mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
2788               sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
2789               cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
2790                 | sed -f "$tmp"/sed-ignore-removed \
2791                 > "$destdir/$dir$ignore"
2792             else
2793               echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
2794             fi
2795           fi
2796         fi
2797       else
2798         if test -n "$dir_added"; then
2799           if $doit; then
2800             echo "Creating $destdir/$dir$ignore"
2801             {
2802               if test "$ignore" = .cvsignore; then
2803                 echo ".deps"
2804                 # Automake generates Makefile rules that create .dirstamp files.
2805                 echo ".dirstamp"
2806               fi
2807               echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u
2808             } > "$destdir/$dir$ignore"
2809           else
2810             echo "Create $destdir/$dir$ignore"
2811           fi
2812         fi
2813       fi
2814     }
2815     func_done_dir ()
2816     {
2817       dir="$1"
2818       dir_added="$2"
2819       dir_removed="$3"
2820       if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
2821         func_update_ignorelist .cvsignore
2822       fi
2823       if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
2824         func_update_ignorelist .gitignore
2825       fi
2826     }
2827     last_dir=
2828     last_dir_added=
2829     last_dir_removed=
2830     while read line; do
2831       # Why not ''read next_dir op file'' ? Because the dir column can be empty.
2832       next_dir=`echo "$line" | sed -e 's,|.*,,'`
2833       op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
2834       file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
2835       if test "$next_dir" != "$last_dir"; then
2836         func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
2837         last_dir="$next_dir"
2838         last_dir_added=
2839         last_dir_removed=
2840       fi
2841       case $op in
2842         A) func_append last_dir_added "$file$nl";;
2843         R) func_append last_dir_removed "$file$nl";;
2844       esac
2845     done
2846     func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
2847     exec 0<&5 5<&-
2848   }
2849
2850   echo "Finished."
2851   echo
2852   echo "You may need to add #include directives for the following .h files."
2853   # Intersect $specified_modules and $modules
2854   # (since $specified_modules is not necessarily of subset of $modules - some
2855   # may have been skipped through --avoid, and since the elements of $modules
2856   # but not in $specified_modules can go away without explicit notice - through
2857   # changes in the module dependencies).
2858   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
2859   echo "$modules" > "$tmp"/modules2 # also a sorted list, one module per line
2860   # First the #include <...> directives without #ifs, sorted for convenience,
2861   # then the #include "..." directives without #ifs, sorted for convenience,
2862   # then the #include directives that are surrounded by #ifs. Not sorted.
2863   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
2864     include_directive=`func_get_include_directive "$module"`
2865     case "$nl$include_directive" in
2866       *"$nl#if"*)
2867         echo "$include_directive" 1>&5
2868         ;;
2869       *)
2870         echo "$include_directive" | grep -v 'include "' 1>&6
2871         echo "$include_directive" | grep 'include "' 1>&7
2872         ;;
2873     esac
2874   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2875   (
2876    LC_ALL=C sort -u "$tmp"/include-angles
2877    LC_ALL=C sort -u "$tmp"/include-quotes
2878    cat "$tmp"/include-if
2879   ) | sed -e '/^$/d' -e 's/^/  /'
2880   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2881
2882   for module in $modules; do
2883     func_get_link_directive "$module"
2884   done \
2885     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
2886   if test `wc -l < "$tmp"/link` != 0; then
2887     echo
2888     echo "You may need to use the following Makefile variables when linking."
2889     echo "Use them in <program>_LDADD when linking a program, or"
2890     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
2891     cat "$tmp"/link
2892   fi
2893   rm -f "$tmp"/link
2894
2895   echo
2896   echo "Don't forget to"
2897   if test "$makefile_am" = Makefile.am; then
2898     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2899   else
2900     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2901   fi
2902   if test -n "$pobase"; then
2903     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
2904   fi
2905   if test -n "$inctests"; then
2906     if test "$makefile_am" = Makefile.am; then
2907       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2908     else
2909       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2910     fi
2911   fi
2912   if test "$makefile_am" = Makefile.am; then
2913     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2914     sourcebase_base=`basename "$sourcebase"`
2915     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2916   fi
2917   if test -n "$pobase"; then
2918     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
2919     pobase_base=`basename "$pobase"`
2920     echo "  - mention \"${pobase_base}\" in SUBDIRS in ${pobase_dir}Makefile.am,"
2921   fi
2922   if test -n "$inctests"; then
2923     if test "$makefile_am" = Makefile.am; then
2924       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2925       testsbase_base=`basename "$testsbase"`
2926       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2927     fi
2928   fi
2929   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2930   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2931   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
2932 }
2933
2934 # func_create_testdir testdir modules
2935 # Input:
2936 # - local_gnulib_dir  from --local-dir
2937 # - auxdir          directory relative to destdir where to place build aux files
2938 func_create_testdir ()
2939 {
2940   testdir="$1"
2941   modules="$2"
2942   if test -z "$modules"; then
2943     # All modules together.
2944     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2945     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2946     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
2947     modules=`func_all_modules`
2948     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
2949   fi
2950   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2951
2952   # Check that the license of every module is consistent with the license of
2953   # its dependencies.
2954   saved_modules="$modules"
2955   saved_inctests="$inctests"
2956   # When computing transitive closures, don't consider $module to depend on
2957   # $module-tests. Need this becauses tests are implicitly GPL and may depend
2958   # on GPL modules - therefore we don't want a warning in this case.
2959   inctests=""
2960   for requested_module in $saved_modules; do
2961     requested_license=`func_get_license "$requested_module"`
2962     if test "$requested_license" != GPL; then
2963       # Here we use func_modules_transitive_closure, not just
2964       # func_get_dependencies, so that we also detect weird situations like
2965       # an LGPL module which depends on a GPLed build tool module which depends
2966       # on a GPL module.
2967       modules="$requested_module"
2968       func_modules_transitive_closure
2969       for module in $modules; do
2970         license=`func_get_license "$module"`
2971         case "$license" in
2972           'GPLed build tool') ;;
2973           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2974           *)
2975             case "$requested_license" in
2976               GPLv2+)
2977                 case "$license" in
2978                   GPLv2+ | LGPLv2+) ;;
2979                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2980                 esac
2981                 ;;
2982               LGPL)
2983                 case "$license" in
2984                   LGPL | LGPLv2+) ;;
2985                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2986                 esac
2987                 ;;
2988               LGPLv2+)
2989                 case "$license" in
2990                   LGPLv2+) ;;
2991                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
2992                 esac
2993                 ;;
2994             esac
2995             ;;
2996         esac
2997       done
2998     fi
2999   done
3000   modules="$saved_modules"
3001   inctests="$saved_inctests"
3002
3003   # Subdirectory names.
3004   sourcebase=gllib
3005   m4base=glm4
3006   pobase=
3007   docbase=gldoc
3008   testsbase=gltests
3009   macro_prefix=gl
3010   po_domain=
3011
3012   # Determine final module list.
3013   func_modules_transitive_closure
3014   echo "Module list with included dependencies:"
3015   echo "$modules" | sed -e 's/^/  /'
3016
3017   # Add the dummy module if needed.
3018   func_modules_add_dummy
3019
3020   # Determine final file list.
3021   func_modules_to_filelist
3022   echo "File list:"
3023   echo "$files" | sed -e 's/^/  /'
3024
3025   sed_rewrite_files="\
3026     s,^build-aux/,$auxdir/,
3027     s,^doc/,$docbase/,
3028     s,^lib/,$sourcebase/,
3029     s,^m4/,$m4base/,
3030     s,^tests/,$testsbase/,"
3031
3032   # Create directories.
3033   for f in $files; do echo $f; done \
3034     | sed -e "$sed_rewrite_files" \
3035     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3036     | LC_ALL=C sort -u \
3037     > "$tmp"/dirs
3038   { # Rearrange file descriptors. Needed because "while ... done < ..."
3039     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3040     exec 5<&0 < "$tmp"/dirs
3041     while read d; do
3042       mkdir -p "$testdir/$d"
3043     done
3044     exec 0<&5 5<&-
3045   }
3046
3047   # Copy files or make symbolic links.
3048   delimiter='   '
3049   for f in $files; do echo $f; done \
3050     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
3051     | LC_ALL=C sort \
3052     > "$tmp"/files
3053   { # Rearrange file descriptors. Needed because "while ... done < ..."
3054     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3055     exec 5<&0 < "$tmp"/files
3056     while read g f; do
3057       func_lookup_file "$f"
3058       if test -n "$lookedup_tmp"; then
3059         cp -p "$lookedup_file" "$testdir/$g"
3060       else
3061         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
3062         if { test -n "$symbolic" \
3063              || { test -n "$lsymbolic" \
3064                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
3065           func_ln "$lookedup_file" "$testdir/$g"
3066         else
3067           cp -p "$lookedup_file" "$testdir/$g"
3068         fi
3069       fi
3070     done
3071     exec 0<&5 5<&-
3072   }
3073
3074   # Create Makefile.ams that are for testing.
3075   for_test=true
3076
3077   # Create $sourcebase/Makefile.am.
3078   mkdir -p "$testdir/$sourcebase"
3079   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
3080
3081   # Create $m4base/Makefile.am.
3082   mkdir -p "$testdir/$m4base"
3083   (echo "## Process this file with automake to produce Makefile.in."
3084    echo
3085    echo "EXTRA_DIST ="
3086    for f in $files; do
3087      case "$f" in
3088        m4/* )
3089          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
3090      esac
3091    done
3092   ) > "$testdir/$m4base/Makefile.am"
3093
3094   subdirs="$sourcebase $m4base"
3095   subdirs_with_configure_ac=""
3096
3097   if false && test -f "$testdir"/$m4base/gettext.m4; then
3098     # Avoid stupid error message from automake:
3099     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
3100     mkdir -p "$testdir/po"
3101     (echo "## Process this file with automake to produce Makefile.in."
3102     ) > "$testdir/po/Makefile.am"
3103     func_append subdirs " po"
3104   fi
3105
3106   if test -n "$inctests"; then
3107     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
3108     # Create $testsbase/Makefile.am.
3109     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
3110     # Create $testsbase/configure.ac.
3111     (echo "# Process this file with autoconf to produce a configure script."
3112      echo "AC_INIT([dummy], [0])"
3113      echo "AC_CONFIG_AUX_DIR([../$auxdir])"
3114      echo "AM_INIT_AUTOMAKE"
3115      echo
3116      echo "AM_CONFIG_HEADER([config.h])"
3117      echo
3118      echo "AC_PROG_CC"
3119      echo "AC_PROG_INSTALL"
3120      echo "AC_PROG_MAKE_SET"
3121      echo "AC_PROG_RANLIB"
3122      echo
3123      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3124        echo "AC_GNU_SOURCE"
3125        echo
3126      fi
3127      for module in $modules; do
3128        func_verify_module
3129        if test -n "$module"; then
3130          func_get_autoconf_early_snippet "$module"
3131        fi
3132      done \
3133        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3134      if test "$libtool" = true; then
3135        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3136        echo "gl_cond_libtool=true"
3137      else
3138        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3139        echo "gl_cond_libtool=false"
3140        echo "gl_libdeps="
3141        echo "gl_ltlibdeps="
3142      fi
3143      # Wrap the set of autoconf snippets into an autoconf macro that is then
3144      # invoked. This is needed because autoconf does not support AC_REQUIRE
3145      # at the top level:
3146      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3147      # but we want the AC_REQUIRE to have its normal meaning (provide one
3148      # expansion of the required macro before the current point, and only one
3149      # expansion total).
3150      echo "AC_DEFUN([gl_INIT], ["
3151      func_emit_initmacro_start
3152      sed_replace_build_aux='
3153        :a
3154        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3155          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
3156          ba
3157        }'
3158      # We don't have explicit ordering constraints between the various
3159      # autoconf snippets. It's cleanest to put those of the library before
3160      # those of the tests.
3161      echo "gl_source_base='../$sourcebase'"
3162      for module in $modules; do
3163        func_verify_nontests_module
3164        if test -n "$module"; then
3165          func_get_autoconf_snippet "$module" \
3166            | sed -e "$sed_replace_build_aux"
3167        fi
3168      done
3169      echo "gl_source_base='.'"
3170      for module in $modules; do
3171        func_verify_tests_module
3172        if test -n "$module"; then
3173          func_get_autoconf_snippet "$module" \
3174            | sed -e "$sed_replace_build_aux"
3175        fi
3176      done
3177      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3178      # created using libtool, because libtool already handles the dependencies.
3179      if test "$libtool" != true; then
3180        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3181        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3182        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3183        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3184        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3185      fi
3186      func_emit_initmacro_end
3187      echo "])"
3188      func_emit_initmacro_done
3189      echo
3190      echo "gl_INIT"
3191      echo
3192      # Usually $testsbase/config.h will be a superset of config.h. Verify this
3193      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
3194      echo "AH_TOP([#include \"../config.h\"])"
3195      echo
3196      echo "AC_OUTPUT([Makefile])"
3197     ) > "$testdir/$testsbase/configure.ac"
3198     func_append subdirs " $testsbase"
3199     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
3200   fi
3201
3202   # Create Makefile.am.
3203   (echo "## Process this file with automake to produce Makefile.in."
3204    echo
3205    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3206    echo
3207    echo "SUBDIRS = $subdirs"
3208    echo
3209    echo "ACLOCAL_AMFLAGS = -I $m4base"
3210   ) > "$testdir/Makefile.am"
3211
3212   # Create configure.ac.
3213   (echo "# Process this file with autoconf to produce a configure script."
3214    echo "AC_INIT([dummy], [0])"
3215    if test "$auxdir" != "."; then
3216      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3217    fi
3218    echo "AM_INIT_AUTOMAKE"
3219    echo
3220    echo "AM_CONFIG_HEADER([config.h])"
3221    echo
3222    echo "AC_PROG_CC"
3223    echo "AC_PROG_INSTALL"
3224    echo "AC_PROG_MAKE_SET"
3225    echo
3226    echo "# For autobuild."
3227    echo "AC_CANONICAL_BUILD"
3228    echo "AC_CANONICAL_HOST"
3229    echo
3230    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3231    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3232    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3233    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3234    echo
3235    echo "AC_PROG_RANLIB"
3236    echo
3237    if test -n "$uses_subdirs"; then
3238      echo "AM_PROG_CC_C_O"
3239      echo
3240    fi
3241    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3242      echo "AC_GNU_SOURCE"
3243      echo
3244    fi
3245    for module in $modules; do
3246      func_verify_nontests_module
3247      if test -n "$module"; then
3248        func_get_autoconf_early_snippet "$module"
3249      fi
3250    done \
3251      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3252    if test "$libtool" = true; then
3253      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3254      echo "gl_cond_libtool=true"
3255    else
3256      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3257      echo "gl_cond_libtool=false"
3258      echo "gl_libdeps="
3259      echo "gl_ltlibdeps="
3260    fi
3261    echo "gl_source_base='$sourcebase'"
3262    # Wrap the set of autoconf snippets into an autoconf macro that is then
3263    # invoked. This is needed because autoconf does not support AC_REQUIRE
3264    # at the top level:
3265    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3266    # but we want the AC_REQUIRE to have its normal meaning (provide one
3267    # expansion of the required macro before the current point, and only one
3268    # expansion total).
3269    echo "AC_DEFUN([gl_INIT], ["
3270    func_emit_initmacro_start
3271    if test "$auxdir" != "build-aux"; then
3272      sed_replace_build_aux='
3273        :a
3274        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3275          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3276          ba
3277        }'
3278    else
3279      sed_replace_build_aux=
3280    fi
3281    for module in $modules; do
3282      func_verify_nontests_module
3283      if test -n "$module"; then
3284        func_get_autoconf_snippet "$module" \
3285          | sed -e "$sed_replace_build_aux"
3286      fi
3287    done
3288    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3289    # created using libtool, because libtool already handles the dependencies.
3290    if test "$libtool" != true; then
3291      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3292      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3293      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3294      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3295      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3296    fi
3297    func_emit_initmacro_end
3298    echo "])"
3299    func_emit_initmacro_done
3300    echo
3301    echo "gl_INIT"
3302    echo
3303    if test -n "$subdirs_with_configure_ac"; then
3304      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3305    fi
3306    makefiles="Makefile"
3307    for d in $subdirs; do
3308      # For subdirs that have a configure.ac by their own, it's the subdir's
3309      # configure.ac which creates the subdir's Makefile.am, not this one.
3310      case " $subdirs_with_configure_ac " in
3311        *" $d "*) ;;
3312        *) func_append makefiles " $d/Makefile" ;;
3313      esac
3314    done
3315    echo "AC_OUTPUT([$makefiles])"
3316   ) > "$testdir/configure.ac"
3317
3318   # Create autogenerated files.
3319   (cd "$testdir"
3320    # Do not use "${AUTORECONF} --force --install", because it may invoke
3321    # autopoint, which brings in older versions of some of our .m4 files.
3322    if test -f $m4base/gettext.m4; then
3323      echo "executing ${AUTOPOINT} --force"
3324      ${AUTOPOINT} --force || func_exit 1
3325      for f in $m4base/*.m4~; do
3326        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3327      done
3328    fi
3329    echo "executing ${ACLOCAL} -I $m4base"
3330    ${ACLOCAL} -I $m4base || func_exit 1
3331    if ! test -d build-aux; then
3332      echo "executing mkdir build-aux"
3333      mkdir build-aux || func_exit 1
3334    fi
3335    echo "executing ${AUTOCONF}"
3336    ${AUTOCONF} || func_exit 1
3337    echo "executing ${AUTOHEADER}"
3338    ${AUTOHEADER} || func_exit 1
3339    echo "executing ${AUTOMAKE} --add-missing --copy"
3340    ${AUTOMAKE} --add-missing --copy || func_exit 1
3341   ) || func_exit 1
3342   if test -n "$inctests"; then
3343     # Create autogenerated files.
3344     (cd "$testdir/$testsbase" || func_exit 1
3345      # Do not use "${AUTORECONF} --force --install", because it may invoke
3346      # autopoint, which brings in older versions of some of our .m4 files.
3347      if test -f ../$m4base/gettext.m4; then
3348        echo "executing ${AUTOPOINT} --force"
3349        ${AUTOPOINT} --force || func_exit 1
3350        for f in ../$m4base/*.m4~; do
3351          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3352        done
3353      fi
3354      echo "executing ${ACLOCAL} -I ../$m4base"
3355      ${ACLOCAL} -I ../$m4base || func_exit 1
3356      if ! test -d ../build-aux; then
3357        echo "executing mkdir ../build-aux"
3358        mkdir ../build-aux
3359      fi
3360      echo "executing ${AUTOCONF}"
3361      ${AUTOCONF} || func_exit 1
3362      echo "executing ${AUTOHEADER}"
3363      ${AUTOHEADER} || func_exit 1
3364      echo "executing ${AUTOMAKE} --add-missing --copy"
3365      ${AUTOMAKE} --add-missing --copy || func_exit 1
3366     ) || func_exit 1
3367   fi
3368   # Need to run configure and make once, to create built files that are to be
3369   # distributed (such as getdate.c).
3370   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3371   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3372                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3373   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3374   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3375   # such $(FOO_H) because they don't refer to distributed files.
3376   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3377   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3378                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3379                  | sed -e "$sed_remove_make_variables"`
3380   distributed_built_sources=`for file in $built_sources; do
3381                                case "$cleaned_files" in
3382                                  *" "$file" "*) ;;
3383                                  *) echo $file ;;
3384                                esac;
3385                              done`
3386   if test -n "$distributed_built_sources"; then
3387     (cd "$testdir"
3388      ./configure || func_exit 1
3389        cd "$sourcebase"
3390        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3391        make built_sources || func_exit 1
3392        cd ..
3393      make distclean || func_exit 1
3394     ) || func_exit 1
3395   fi
3396 }
3397
3398 # func_create_megatestdir megatestdir allmodules
3399 # Input:
3400 # - local_gnulib_dir  from --local-dir
3401 # - auxdir          directory relative to destdir where to place build aux files
3402 func_create_megatestdir ()
3403 {
3404   megatestdir="$1"
3405   allmodules="$2"
3406   if test -z "$allmodules"; then
3407     allmodules=`func_all_modules`
3408   fi
3409
3410   megasubdirs=
3411   # First, all modules one by one.
3412   for onemodule in $allmodules; do
3413     func_create_testdir "$megatestdir/$onemodule" $onemodule
3414     func_append megasubdirs "$onemodule "
3415   done
3416   # Then, all modules all together.
3417   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3418   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3419   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3420   func_create_testdir "$megatestdir/ALL" "$allmodules"
3421   func_append megasubdirs "ALL"
3422
3423   # Create autobuild.
3424   cvsdate=`sh "$gnulib_dir/build-aux/mdate-sh" "$gnulib_dir/CVS/Entries" \
3425              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3426                    -e 's,February,02,'  -e 's,Feb,02,' \
3427                    -e 's,March,03,'     -e 's,Mar,03,' \
3428                    -e 's,April,04,'     -e 's,Apr,04,' \
3429                    -e 's,May,05,'                      \
3430                    -e 's,June,06,'      -e 's,Jun,06,' \
3431                    -e 's,July,07,'      -e 's,Jul,07,' \
3432                    -e 's,August,08,'    -e 's,Aug,08,' \
3433                    -e 's,September,09,' -e 's,Sep,09,' \
3434                    -e 's,October,10,'   -e 's,Oct,10,' \
3435                    -e 's,November,11,'  -e 's,Nov,11,' \
3436                    -e 's,December,12,'  -e 's,Dec,12,' \
3437                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3438                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3439   (echo '#!/bin/sh'
3440    echo "CVSDATE=$cvsdate"
3441    echo "test -d logs || mkdir logs"
3442    echo "for module in $megasubdirs; do"
3443    echo "  echo \"Working on module \$module...\""
3444    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3445    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3446    echo "   echo"
3447    echo "   set -x"
3448    echo "   : autobuild project... \$module"
3449    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3450    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3451    echo "   : autobuild hostname... \`hostname\`"
3452    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3453    echo "   echo rc=\$?"
3454    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3455    echo "done"
3456   ) > "$megatestdir/do-autobuild"
3457   chmod a+x "$megatestdir/do-autobuild"
3458
3459   # Create Makefile.am.
3460   (echo "## Process this file with automake to produce Makefile.in."
3461    echo
3462    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3463    echo
3464    echo "SUBDIRS = $megasubdirs"
3465    echo
3466    echo "EXTRA_DIST = do-autobuild"
3467   ) > "$megatestdir/Makefile.am"
3468
3469   # Create configure.ac.
3470   (echo "# Process this file with autoconf to produce a configure script."
3471    echo "AC_INIT([dummy], [0])"
3472    if test "$auxdir" != "."; then
3473      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3474    fi
3475    echo "AM_INIT_AUTOMAKE"
3476    echo
3477    echo "AC_PROG_MAKE_SET"
3478    echo
3479    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
3480    echo "AC_OUTPUT([Makefile])"
3481   ) > "$megatestdir/configure.ac"
3482
3483   # Create autogenerated files.
3484   (cd "$megatestdir"
3485    # Do not use "${AUTORECONF} --install", because autoreconf operates
3486    # recursively, but the subdirectories are already finished, therefore
3487    # calling autoreconf here would only waste lots of CPU time.
3488    echo "executing ${ACLOCAL}"
3489    ${ACLOCAL} || func_exit 1
3490    echo "executing mkdir build-aux"
3491    mkdir build-aux
3492    echo "executing ${AUTOCONF}"
3493    ${AUTOCONF} || func_exit 1
3494    echo "executing ${AUTOMAKE} --add-missing --copy"
3495    ${AUTOMAKE} --add-missing --copy || func_exit 1
3496   ) || func_exit 1
3497 }
3498
3499 case $mode in
3500   "" )
3501     func_fatal_error "no mode specified" ;;
3502
3503   list )
3504     func_all_modules
3505     ;;
3506
3507   import | update )
3508
3509     # Where to import.
3510     if test -z "$destdir"; then
3511       destdir=.
3512     fi
3513     test -d "$destdir" \
3514       || func_fatal_error "destination directory does not exist: $destdir"
3515
3516     # Prefer configure.ac to configure.in.
3517     if test -f "$destdir"/configure.ac; then
3518       configure_ac="$destdir/configure.ac"
3519     else
3520       if test -f "$destdir"/configure.in; then
3521         configure_ac="$destdir/configure.in"
3522       else
3523         func_fatal_error "cannot find $destdir/configure.ac"
3524       fi
3525     fi
3526
3527     # Analyze configure.ac.
3528     guessed_auxdir="."
3529     guessed_libtool=false
3530     my_sed_traces='
3531       s,#.*$,,
3532       s,^dnl .*$,,
3533       s, dnl .*$,,
3534       /AC_CONFIG_AUX_DIR/ {
3535         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
3536       }
3537       /A[CM]_PROG_LIBTOOL/ {
3538         s,^.*$,guessed_libtool=true,p
3539       }'
3540     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
3541
3542     if test -z "$auxdir"; then
3543       auxdir="$guessed_auxdir"
3544     fi
3545
3546     # Determine where to apply func_import.
3547     if test -n "$m4base"; then
3548       # Apply func_import to a particular gnulib directory.
3549       # Any number of additional modules can be given.
3550       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
3551         # First use of gnulib in the given m4base.
3552         test -n "$supplied_libname" || supplied_libname=true
3553         test -n "$sourcebase" || sourcebase="lib"
3554         test -n "$docbase" || docbase="doc"
3555         test -n "$testsbase" || testsbase="tests"
3556         test -n "$macro_prefix" || macro_prefix="gl"
3557       fi
3558       func_import "$*"
3559     else
3560       # Apply func_import to all gnulib directories.
3561       # To get this list of directories, look at Makefile.am. (Not at
3562       # configure, because it may be omitted from CVS. Also, don't run
3563       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
3564       m4dirs=
3565       m4dirs_count=0
3566       if test -f "$destdir"/Makefile.am; then
3567         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
3568         m4dir_is_next=
3569         for arg in $aclocal_amflags; do
3570           if test -n "$m4dir_is_next"; then
3571             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
3572             case "$arg" in
3573               /*) ;;
3574               *)
3575                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
3576                   func_append m4dirs " $arg"
3577                   m4dirs_count=`expr $m4dirs_count + 1`
3578                 fi
3579                 ;;
3580             esac
3581             m4dir_is_next=
3582           else
3583             if test "X$arg" = "X-I"; then
3584               m4dir_is_next=yes
3585             else
3586               m4dir_is_next=
3587             fi
3588           fi
3589         done
3590       else
3591         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
3592         if test -f "$destdir"/aclocal.m4; then
3593           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
3594           sedexpr2='s,^[^/]*$,.,'
3595           sedexpr3='s,/[^/]*$,,'
3596           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
3597           m4dirs_count=`echo "$m4dirs" | wc -l`
3598         fi
3599       fi
3600       if test $m4dirs_count = 0; then
3601         # First use of gnulib in a package.
3602         # Any number of additional modules can be given.
3603         test -n "$supplied_libname" || supplied_libname=true
3604         test -n "$sourcebase" || sourcebase="lib"
3605         m4base="m4"
3606         test -n "$docbase" || docbase="doc"
3607         test -n "$testsbase" || testsbase="tests"
3608         test -n "$macro_prefix" || macro_prefix="gl"
3609         func_import "$*"
3610       else
3611         if test $m4dirs_count = 1; then
3612           # There's only one use of gnulib here. Assume the user means it.
3613           # Any number of additional modules can be given.
3614           for m4base in $m4dirs; do
3615             func_import "$*"
3616           done
3617         else
3618           # Ambiguous - guess what the user meant.
3619           if test $# = 0; then
3620             # No further arguments. Guess the user wants to update all of them.
3621             for m4base in $m4dirs; do
3622               # Perform func_import in a subshell, so that variable values
3623               # such as
3624               #   local_gnulib_dir, avoidlist, sourcebase, m4base, pobase,
3625               #   docbase, testsbase, inctests, libname, lgpl, makefile_name,
3626               #   libtool, macro_prefix, po_domain
3627               # don't propagate from one directory to another.
3628               (func_import) || func_exit 1
3629             done
3630           else
3631             # Really ambiguous.
3632             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
3633           fi
3634         fi
3635       fi
3636     fi
3637     ;;
3638
3639   create-testdir )
3640     if test -z "$destdir"; then
3641       func_fatal_error "please specify --dir option"
3642     fi
3643     mkdir "$destdir"
3644     test -d "$destdir" \
3645       || func_fatal_error "could not create destination directory"
3646     test -n "$auxdir" || auxdir="build-aux"
3647     func_create_testdir "$destdir" "$*"
3648     ;;
3649
3650   create-megatestdir )
3651     if test -z "$destdir"; then
3652       func_fatal_error "please specify --dir option"
3653     fi
3654     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3655     test -n "$auxdir" || auxdir="build-aux"
3656     func_create_megatestdir "$destdir" "$*"
3657     ;;
3658
3659   test )
3660     test -n "$destdir" || destdir=testdir$$
3661     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3662     test -n "$auxdir" || auxdir="build-aux"
3663     func_create_testdir "$destdir" "$*"
3664     cd "$destdir"
3665       mkdir build
3666       cd build
3667         ../configure || func_exit 1
3668         make || func_exit 1
3669         make check || func_exit 1
3670         make distclean || func_exit 1
3671         remaining=`find . -type f -print`
3672         if test -n "$remaining"; then
3673           echo "Remaining files:" $remaining 1>&2
3674           echo "gnulib-tool: *** Stop." 1>&2
3675           func_exit 1
3676         fi
3677       cd ..
3678     cd ..
3679     rm -rf "$destdir"
3680     ;;
3681
3682   megatest )
3683     test -n "$destdir" || destdir=testdir$$
3684     mkdir "$destdir" || func_fatal_error "could not create destination directory"
3685     test -n "$auxdir" || auxdir="build-aux"
3686     func_create_megatestdir "$destdir" "$*"
3687     cd "$destdir"
3688       mkdir build
3689       cd build
3690         ../configure
3691         make
3692         make check
3693         make distclean
3694         remaining=`find . -type f -print`
3695         if test -n "$remaining"; then
3696           echo "Remaining files:" $remaining 1>&2
3697           echo "gnulib-tool: *** Stop." 1>&2
3698           func_exit 1
3699         fi
3700       cd ..
3701     cd ..
3702     rm -rf "$destdir"
3703     ;;
3704
3705   extract-description )
3706     for module
3707     do
3708       func_verify_module
3709       if test -n "$module"; then
3710         func_get_description "$module"
3711       fi
3712     done
3713     ;;
3714
3715   extract-filelist )
3716     for module
3717     do
3718       func_verify_module
3719       if test -n "$module"; then
3720         func_get_filelist "$module"
3721       fi
3722     done
3723     ;;
3724
3725   extract-dependencies )
3726     for module
3727     do
3728       func_verify_module
3729       if test -n "$module"; then
3730         func_get_dependencies "$module"
3731       fi
3732     done
3733     ;;
3734
3735   extract-autoconf-snippet )
3736     for module
3737     do
3738       func_verify_module
3739       if test -n "$module"; then
3740         func_get_autoconf_snippet "$module"
3741       fi
3742     done
3743     ;;
3744
3745   extract-automake-snippet )
3746     for module
3747     do
3748       func_verify_module
3749       if test -n "$module"; then
3750         func_get_automake_snippet "$module"
3751       fi
3752     done
3753     ;;
3754
3755   extract-include-directive )
3756     for module
3757     do
3758       func_verify_module
3759       if test -n "$module"; then
3760         func_get_include_directive "$module"
3761       fi
3762     done
3763     ;;
3764
3765   extract-link-directive )
3766     for module
3767     do
3768       func_verify_module
3769       if test -n "$module"; then
3770         func_get_link_directive "$module"
3771       fi
3772     done
3773     ;;
3774
3775   extract-license )
3776     for module
3777     do
3778       func_verify_module
3779       if test -n "$module"; then
3780         func_get_license "$module"
3781       fi
3782     done
3783     ;;
3784
3785   extract-maintainer )
3786     for module
3787     do
3788       func_verify_module
3789       if test -n "$module"; then
3790         func_get_maintainer "$module"
3791       fi
3792     done
3793     ;;
3794
3795   extract-tests-module )
3796     for module
3797     do
3798       func_verify_module
3799       if test -n "$module"; then
3800         func_get_tests_module "$module"
3801       fi
3802     done
3803     ;;
3804
3805   * )
3806     func_fatal_error "unknown operation mode --$mode" ;;
3807 esac
3808
3809 rm -rf "$tmp"
3810 # Undo the effect of the previous 'trap' command. Some shellology:
3811 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
3812 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
3813 # exit); for the others we need to call 'exit' explicitly. The value of $? is
3814 # 128 + signal number and is set before the trap-registered command is run.
3815 trap '' 0
3816 trap 'func_exit $?' 1 2 3 13 15
3817
3818 exit 0
3819
3820 # Local Variables:
3821 # indent-tabs-mode: nil
3822 # whitespace-check-buffer-indent: nil
3823 # End: