+2006-07-07 Paolo Bonzini <bonzini@gnu.org>
+
+ * doc/autoconf.texi (Generic compiler characteristics):
+ Document AC_COMPUTE_INT. Fix wrong statements on Default
+ Includes for AC_CHECK_SIZEOF and AC_CHECK_ALIGNOF.
+
+ * lib/autoconf/general.m4 (AC_COMPUTE_INT): New.
+ (_AC_COMPUTE_INT): Add obsoletion warnings.
+ * lib/autoconf/types.m4 (AC_CHECK_SIZEOF, AC_CHECK_ALIGNOF): Use
+ AC_COMPUTE_INT.
+
+ * NEWS: Document change.
+
2006-07-05 Paul Eggert <eggert@cs.ucla.edu>
* doc/autoconf.texi (Volatile Objects): New section.
* Major changes in Autoconf 2.60a
+** The functionality of the undocumented _AC_COMPUTE_INT is now provided
+ by a public and documented macro, AC_COMPUTE_INT. The parameters to the
+ two macros are different, so autoupdate will not change the old private name
+ to the new one. _AC_COMPUTE_INT may be removed in a future release.
+
** AC_TYPE_LONG_LONG_INT and AC_TYPE_UNSIGNED_LONG_LONG_INT now require
that long long types be at least 64 bits wide, as C99 and tradition
requires. Formerly, they accepted implementations of any width.
Define @code{SIZEOF_@var{type}} (@pxref{Standard Symbols}) to be the
size in bytes of @var{type}. If @samp{type} is unknown, it gets a size
of 0. If no @var{includes} are specified, the default includes are used
-(@pxref{Default Includes}). If you provide @var{include}, be sure to
-include @file{stdio.h} which is required for this macro to run.
+(@pxref{Default Includes}).
This macro now works even when cross-compiling. The @var{unused}
argument was used when cross-compiling.
Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
alignment in bytes of @var{type}. If @samp{type} is unknown, it gets a size
of 0. If no @var{includes} are specified, the default includes are used
-(@pxref{Default Includes}). If you provide @var{include}, be sure to
-include @file{stddef.h} and @file{stdio.h} which are required for this
-macro to work correctly.
+(@pxref{Default Includes}).
+@end defmac
+
+@defmac AC_COMPUTE_INT (@var{message}, @var{cache-id}, @var{expression}, @dvar{includes, default-includes}, @ovar{if-fails})
+@acindex{COMPUTE_INT}
+Compute the value of the integer @var{expression} in @var{cache-id}. The
+value should fit in an initializer in a C variable of type @code{signed
+long}. To support cross compilation (in which case, the macro only works on
+hosts that use twos-complement arithmetic), it should be possible to evaluate
+the expression at compile-time. If no @var{includes} are specified, the default
+includes are used (@pxref{Default Includes}).
+
+The macro also takes care of checking if the result is already in the
+cache, and of reporting the test on the standard output
+with @code{AC_MSG_CHECKING} (which prints @var{message}) and
+@code{AC_MSG_RESULT}.
+
+If the value cannot be determined correctly, the code in @var{if-fails}
+is executed. The @var{if-fails} commands @emph{must have no side effects}
+except for possibly setting the variable @var{cache-id}.
+@xref{Caching Results}, for more information.
@end defmac
@defmac AC_LANG_WERROR
[$2=`cat conftest.val`], [$4])])
-# _AC_COMPUTE_INT(EXPRESSION, VARIABLE, PROLOGUE, IF-FAILS)
+# _AC_COMPUTE_INT(EXPRESSION, VARIABLE, PROLOGUE, [IF-FAILS])
# ---------------------------------------------------------
-m4_define([_AC_COMPUTE_INT],
+# FIXME: this private interface was used by several packages.
+# Give them time to transition to AC_COMPUTE_INT (which is cleaner)
+# and then delete this one. Or if they do not transition,
+# it may make sense to limit the code duplication and use
+# _AC_COMPUTE_INT from within the public macro.
+AC_DEFUN([_AC_COMPUTE_INT],
[AC_LANG_COMPILER_REQUIRE()dnl
if test "$cross_compiling" = yes; then
_AC_COMPUTE_INT_COMPILE([$1], [$2], [$3], [$4])
_AC_COMPUTE_INT_RUN([$1], [$2], [$3], [$4])
fi
rm -f conftest.val[]dnl
+AC_DIAGNOSE([obsolete],
+[The macro `_AC_COMPUTE_INT' is obsolete and will be deleted in a
+future version or Autoconf. Hence, it is suggested that you use
+instead the public AC_COMPUTE_INT macro. Note that the arguments are
+slightly different between the two.])dnl
])# _AC_COMPUTE_INT
+
+# AC_COMPUTE_INT(MESSAGE, CACHE-ID, EXPRESSION, [PROLOGUE = DEFAULT-INCLUDES],
+# [IF-FAILS])
+# ---------------------------------------------------------
+AC_DEFUN([AC_COMPUTE_INT],
+[AC_LANG_COMPILER_REQUIRE()dnl
+AC_CACHE_CHECK([$1], [$2],
+[if test "$cross_compiling" = yes; then
+ _AC_COMPUTE_INT_COMPILE([$3], [$2], [AC_INCLUDES_DEFAULT([$4])], [$5])
+else
+ _AC_COMPUTE_INT_RUN([$3], [$2], [AC_INCLUDES_DEFAULT([$4])], [$5])
+fi
+rm -f conftest.val[]dnl
+])
+])# AC_COMPUTE_INT
[AS_LITERAL_IF([$1], [],
[AC_FATAL([$0: requires literal arguments])])dnl
AC_CHECK_TYPE([$1], [], [], [$3])
-AC_CACHE_CHECK([size of $1], AS_TR_SH([ac_cv_sizeof_$1]),
-[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
- # The cast to long int works around a bug in the HP C Compiler
- # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
- # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
- # This bug is HP SR number 8606223364.
- _AC_COMPUTE_INT([(long int) (sizeof (ac__type_sizeof_))],
- [AS_TR_SH([ac_cv_sizeof_$1])],
- [AC_INCLUDES_DEFAULT([$3])
- typedef $1 ac__type_sizeof_;],
- [AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)])
-else
- AS_TR_SH([ac_cv_sizeof_$1])=0
-fi])dnl
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+AC_COMPUTE_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
+ [(long int) (sizeof (ac__type_sizeof_))],
+ [AC_INCLUDES_DEFAULT([$3])
+ typedef $1 ac__type_sizeof_;],
+ [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
+ AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
+ else
+ AS_TR_SH([ac_cv_sizeof_$1])=0
+ fi])
+
AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
[The size of `$1', as computed by sizeof.])
])# AC_CHECK_SIZEOF
[AS_LITERAL_IF([$1], [],
[AC_FATAL([$0: requires literal arguments])])dnl
AC_CHECK_TYPE([$1], [], [], [$2])
-AC_CACHE_CHECK([alignment of $1], AS_TR_SH([ac_cv_alignof_$1]),
-[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
- # The cast to long int works around a bug in the HP C Compiler,
- # see AC_CHECK_SIZEOF for more information.
- _AC_COMPUTE_INT([(long int) offsetof (ac__type_alignof_, y)],
- [AS_TR_SH([ac_cv_alignof_$1])],
- [AC_INCLUDES_DEFAULT([$2])
+# The cast to long int works around a bug in the HP C Compiler,
+# see AC_CHECK_SIZEOF for more information.
+AC_COMPUTE_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$1])],
+ [(long int) offsetof (ac__type_alignof_, y)],
+ [AC_INCLUDES_DEFAULT([$2])
#ifndef offsetof
# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
#endif
typedef struct { char x; $1 y; } ac__type_alignof_;],
- [AC_MSG_FAILURE([cannot compute alignment of ($1)], 77)])
-else
- AS_TR_SH([ac_cv_alignof_$1])=0
-fi])dnl
+ [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
+ AC_MSG_FAILURE([cannot compute alignment of $1], 77)
+ else
+ AS_TR_SH([ac_cv_alignof_$1])=0
+ fi])
+
AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$1), $AS_TR_SH([ac_cv_alignof_$1]),
[The normal alignment of `$1', in bytes.])
])# AC_CHECK_ALIGNOF
# Need an argument.
/^AC_(CANONICALIZE|PREFIX_PROGRAM|PREREQ)$/ {next}
/^AC_(SEARCH_LIBS|REPLACE_FUNCS)$/ {next}
+ /^AC_COMPUTE_INT$/ {next}
# Performed in the semantics tests.
/^AC_CHECK_(ALIGNOF|DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|(TARGET_)?TOOL|TYPE)S?$/ {next}