+2005-02-23 Paul Eggert <eggert@cs.ucla.edu>
+ Alexandre Duret-Lutz <adl@gnu.org>
+
+ * lib/autoconf/general.m4 (_AC_INIT_DEFAULTS): Redirect stdin from
+ /dev/null, as "configure" shouldn't read stdin, and this insulates
+ us from problems (e.g., when testing for "cl"). Also, do this
+ redirection before invoking "hostname" or "uname", and keep the
+ original input stream available via...
+ (AS_ORIGINAL_STDIN_FD): ... this new macro.
+ (_AC_PREPROC_IFELSE, _AC_COMPILE_IFELSE, _AC_LINK_IFELSE): Don't
+ bother with "</dev/null" since it's now done at the top of
+ 'configure'.
+ * lib/autoconf/c.m4 (AC_PROG_CC, AC_PROG_CXX): Likewise.
+ * lib/autoconf/fortran.m4 (_AC_PROG_FC): Likewise.
+ * lib/autoconf/programs.m4 (_AC_PATH_PROG_FLAVOR_GNU): Likewise.
+ * doc/autoconf.texi (File Descriptor Macros): New section.
+ (Printing Messages): Mention it.
+ * tests/base.at (Input/Output): New test.
+
2005-02-23 Paul Eggert <eggert@cs.ucla.edu>
* lib/m4sugar/m4sh.m4 (_AS_ECHO_N_PREPARE): Don't set ECHO_C to
* Major changes in Autoconf 2.59c
+** The configure command now redirects standard input from /dev/null,
+ to help avoid problems with subsidiary commands that might mistakenly
+ read standard input. AS_ORIGINAL_STDIN_FD points to the original
+ standard input before this redirection, if you really want configure to
+ read from standard input.
+
** Directory variables adjusted to recent changes in the GNU Coding Standards.
The following directory variables are new:
* Declarations:: Declarations that may be missing
* Structures:: Structures or members that might be missing
* Types:: Types that might be missing
-* Compilers and Preprocessors:: Checking for compiling programs
+* Compilers and Preprocessors:: Checking for compiling programs
* System Services:: Operating system services
* Posix Variants:: Special kludges for specific Posix variants
* Using autom4te:: The Autoconf executables backbone
* Programming in M4sugar:: Convenient pure M4 macros
* Programming in M4sh:: Common shell Constructs
+* File Descriptor Macros:: File descriptor macros for input and output
M4 Quotation
@ovindex ECHO_C
@ovindex ECHO_N
@ovindex ECHO_T
-How does one suppress the trailing newline from @code{echo} for
+How does one suppress the trailing newline from @command{echo} for
question-answer message pairs? These variables provide a way:
@example
@end example
@noindent
-Some old and uncommon @code{echo} implementations offer no means to
+Some old and uncommon @command{echo} implementations offer no means to
achieve this, in which case @code{ECHO_T} is set to tab. You might not
want to use it.
@end defvar
* Types:: Types that might be missing
* Compilers and Preprocessors:: Checking for compiling programs
* System Services:: Operating system services
-* Posix Variants:: Special kludges for specific Posix variants
+* Posix Variants:: Special kludges for specific Posix variants
@end menu
@node Common Behavior
double quotes, so the shell performs variable and back-quote
substitution on them.
-These macros are all wrappers around the @code{echo} shell command.
-@command{configure} scripts should rarely need to run @code{echo} directly
+These macros are all wrappers around the @command{echo} shell command,
+and will direct output to the appropriate file descriptor (@pxref{File
+Descriptor Macros}).
+@command{configure} scripts should rarely need to run @command{echo} directly
to print messages for the user. Using these macros makes it easy to
change how and when each kind of message is printed; such changes need
-only be made to the macro definitions and all of the callers will change
+only be made to the macro definitions and all the callers will change
automatically.
To diagnose static issues, i.e., when @command{autoconf} is run, see
* Using autom4te:: The Autoconf executables backbone
* Programming in M4sugar:: Convenient pure M4 macros
* Programming in M4sh:: Common shell Constructs
+* File Descriptor Macros:: File descriptor macros for input and output
@end menu
@node M4 Quotation
@end defmac
+@node File Descriptor Macros
+@section File Descriptor Macros
+@cindex input
+@cindex standard input
+@cindex file descriptors
+@cindex descriptors
+@cindex low-level output
+@cindex output, low-level
+
+The following macros define file descriptors used to output messages
+(or input values) from @file{configure} scripts.
+For example:
+
+@example
+echo "$wombats found" >&AS_MESSAGE_LOG_FD
+echo 'Enter desired kangaroo count:' >&AS_MESSAGE_FD
+read kangaroos <&AS_ORIGINAL_STDIN_FD`
+@end example
+
+@noindent
+However doing so is seldom needed, because Autoconf provides higher
+level macros as described below.
+
+@defmac AS_MESSAGE_FD
+@asindex{MESSAGE_FD}
+The file descriptor for @samp{checking for...} messages and results.
+Normally this directs messages to the standard output, however when
+@command{configure} is run with the @code{-q} option, messages sent to
+@code{AS_MESSAGE_FD} will be discarded.
+
+If you want to display some messages, consider using one of the printing
+macros (@pxref{Printing Messages}) instead. Copies of messages output
+via these macros will additionally be recorded in @file{config.log}.
+@end defmac
+
+@defmac AS_MESSAGE_LOG_FD
+@asindex{MESSAGE_LOG_FD}
+
+The file descriptor for messages logged to @file{config.log}. Macros
+that run tools, like @code{AC_COMPILE_IFELSE} (@pxref{Running the
+Compiler}), redirect all output to this descriptor. You may want to do
+so if you develop such a low-level macro.
+@end defmac
+
+@defmac AS_ORIGINAL_STDIN_FD
+@asindex{ORIGINAL_STDIN_FD}
+The file descriptor for the original standard input.
+
+When @command{configure} runs, it may accidentally execute an
+interactive command that has the same name as the non-interactive meant
+to be used or checked. If the standard input was the terminal, such
+interactive programs would cause @command{configure} to stop, pending
+some user input. Therefore @command{configure} redirects its standard
+input from @file{/dev/null} during its initialization. This is not
+normally a problem, since @command{configure} normally does not need
+user input.
+
+In the extreme case where your @file{configure} script really needs to
+obtain some values from the original standard input, you can read them
+explicitly from @code{AS_ORIGINAL_STDIN_FD}.
+@end defmac
+
@c=================================================== Writing Autoconf Macros.
@item @command{echo}
@c -----------------
@prindex @command{echo}
-The simple @code{echo} is probably the most surprising source of
+The simple @command{echo} is probably the most surprising source of
portability troubles. It is not possible to use @samp{echo} portably
unless both options and escape sequences are omitted. New applications
which are not aiming at portability should use @samp{printf} instead of
On some old @acronym{BSD} systems, @command{touch} or any command that
results in an empty file does not update the timestamps, so use a
-command like @code{echo} as a workaround.
+command like @command{echo} as a workaround.
@acronym{GNU} @command{touch} 3.16r (and presumably all before that)
fails to work on SunOS 4.1.3 when the empty file is on an
your @command{configure} script will generally work better if you follow
the advice that is printed about what to replace the obsolete macros with. In
particular, the mechanism for reporting the results of tests has
-changed. If you were using @code{echo} or @code{AC_VERBOSE} (perhaps
+changed. If you were using @command{echo} or @code{AC_VERBOSE} (perhaps
via @code{AC_COMPILE_CHECK}), your @command{configure} script's output will
look better if you switch to @code{AC_MSG_CHECKING} and
@code{AC_MSG_RESULT}. @xref{Printing Messages}. Those macros work best
echo "$as_me:$LINENO:" \
"checking for _AC_LANG compiler version" >&AS_MESSAGE_LOG_FD
ac_compiler=`set X $ac_compile; echo $[2]`
-_AC_EVAL([$ac_compiler --version </dev/null >&AS_MESSAGE_LOG_FD])
-_AC_EVAL([$ac_compiler -v </dev/null >&AS_MESSAGE_LOG_FD])
-_AC_EVAL([$ac_compiler -V </dev/null >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
echo "$as_me:$LINENO:" \
"checking for _AC_LANG compiler version" >&AS_MESSAGE_LOG_FD
ac_compiler=`set X $ac_compile; echo $[2]`
-_AC_EVAL([$ac_compiler --version </dev/null >&AS_MESSAGE_LOG_FD])
-_AC_EVAL([$ac_compiler -v </dev/null >&AS_MESSAGE_LOG_FD])
-_AC_EVAL([$ac_compiler -V </dev/null >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
echo "$as_me:__oline__:" \
"checking for _AC_LANG compiler version" >&AS_MESSAGE_LOG_FD
ac_compiler=`set X $ac_compile; echo $[2]`
-_AC_EVAL([$ac_compiler --version </dev/null >&AS_MESSAGE_LOG_FD])
-_AC_EVAL([$ac_compiler -v </dev/null >&AS_MESSAGE_LOG_FD])
-_AC_EVAL([$ac_compiler -V </dev/null >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
+_AC_EVAL([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
rm -f a.out
m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
# ----------------
# Set up the file descriptors used by `configure'.
# File descriptor usage:
-# 0 standard input
+# 0 standard input (/dev/null)
# 1 file creation
# 2 errors and warnings
# AS_MESSAGE_LOG_FD compiler messages saved in config.log
# AS_MESSAGE_FD checking for... messages and results
-
+# AS_ORIGINAL_STDIN_FD original standard input (still open)
+#
+# stdin is /dev/null because checks that run programs may
+# inadvertently run interactive ones, which would stop configuration
+# until someone typed an EOF.
m4_define([AS_MESSAGE_FD], 6)
+m4_define([AS_ORIGINAL_STDIN_FD], 7)
# That's how they used to be named.
AU_ALIAS([AC_FD_CC], [AS_MESSAGE_LOG_FD])
AU_ALIAS([AC_FD_MSG], [AS_MESSAGE_FD])
m4_define([_AC_INIT_DEFAULTS],
[m4_divert_push([DEFAULTS])dnl
+exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_FD>&1
+
# Name of the host.
# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
# so uname gets run too.
ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
-exec AS_MESSAGE_FD>&1
-
#
# Initializations.
#
# to expand ac_cpp.
AC_DEFUN([_AC_PREPROC_IFELSE],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
-if _AC_EVAL_STDERR([$ac_cpp conftest.$ac_ext]) </dev/null >/dev/null; then
+if _AC_EVAL_STDERR([$ac_cpp conftest.$ac_ext]) >/dev/null; then
if test -s conftest.err; then
ac_cpp_err=$ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag
ac_cpp_err=$ac_cpp_err$ac_[]_AC_LANG_ABBREV[]_werror_flag
m4_define([_AC_COMPILE_IFELSE],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
rm -f conftest.$ac_objext
-AS_IF([_AC_EVAL_STDERR($ac_compile) </dev/null &&
+AS_IF([_AC_EVAL_STDERR($ac_compile) &&
AC_TRY_COMMAND([test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag"
|| test ! -s conftest.err]) &&
AC_TRY_COMMAND([test -s conftest.$ac_objext])],
m4_define([_AC_LINK_IFELSE],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
rm -f conftest.$ac_objext conftest$ac_exeext
-AS_IF([_AC_EVAL_STDERR($ac_link) </dev/null &&
+AS_IF([_AC_EVAL_STDERR($ac_link) &&
AC_TRY_COMMAND([test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag"
|| test ! -s conftest.err]) &&
AC_TRY_COMMAND([test -s conftest$ac_exeext])],
# ----------------------------------------------------------------
m4_define([_AC_PATH_PROG_FLAVOR_GNU],
[# Check for GNU $1
-case `"$1" --version </dev/null 2>&1` in
+case `"$1" --version 2>&1` in
*GNU*)
$2;;
m4_ifval([$3],
AT_BANNER([Autoconf base layer.])
-# Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
AT_CHECK_CONFIGURE([-q])
AT_CLEANUP
+
+
+## ------------ ##
+## Input/Output ##
+## ------------ ##
+
+AT_SETUP([Input/Output])
+
+m4_pattern_allow([^AS_(MESSAGE|ORIGINAL_STDIN)_FD$])
+AT_DATA([configure.ac],
+[[AC_INIT
+cat <&AS_ORIGINAL_STDIN_FD >&AS_MESSAGE_FD
+]])
+AT_CHECK_AUTOCONF
+AT_CHECK([echo Hello | top_srcdir=$abs_top_srcdir ./configure],, [Hello
+])
+AT_CHECK([echo Hello | top_srcdir=$abs_top_srcdir ./configure --silent])
+
+AT_CLEANUP