Here is my proposal.
Index: ChangeLog
===================================================================
RCS file: /cvs/autoconf/ChangeLog,v
retrieving revision 1.652
diff -u -r1.652 ChangeLog
--- ChangeLog 2000/05/26 09:42:13 1.652
+++ ChangeLog 2000/05/26 10:15:47
@@ -1,3 +1,20 @@
+2000-05-26 Akim Demaille <[EMAIL PROTECTED]>
+
+ Find a means to extract integers from the compiler.
+ Use this technology to compute `sizeof' even when cross-compiling.
+ Ideas and initial suggestion by Kaveh Ghazi.
+ Binary search by Bruno Haible.
+
+ * aclang.m4 (AC_LANG_BOOL_COMPILE_TRY,
+ AC_LANG_BOOL_COMPILE_TRY(C), AC_LANG_BOOL_COMPILE_TRY(C++),
+ AC_LANG_INT_SAVE, AC_LANG_INT_SAVE(C), AC_LANG_INT_SAVE(C++)): New
+ macros.
+ * acgeneral.m4 (_AC_COMPUTE_INT_COMPILE, _AC_COMPUTE_INT_RUN,
+ _AC_COMPUTE_INT): New.
+ (AC_CHECK_SIZEOF): Use them.
+ Check whether the type exists beforehand.
+ * tests/semantics.m4 (AC_CHECK_SIZEOF): Strengthen.
+
2000-05-26 Ossama Othman <[EMAIL PROTECTED]>
* aclang.m4 (AC_PROG_CXX): Look for aCC KCC RCC xlC_r xlC.
Index: NEWS
===================================================================
RCS file: /cvs/autoconf/NEWS,v
retrieving revision 1.120
diff -u -r1.120 NEWS
--- NEWS 2000/05/22 13:31:00 1.120
+++ NEWS 2000/05/26 10:15:47
@@ -173,6 +173,9 @@
- AC_PROG_LEX
Now integrates `AC_DECL_YYTEXT' which is obsoleted.
+- AC_CHECK_SIZEOF
+ No longer needs a cross-compilation size.
+
** C++ compatibility
Every macro has been revisited in order to support at best CC=c++.
Index: acgeneral.m4
===================================================================
RCS file: /cvs/autoconf/acgeneral.m4,v
retrieving revision 1.476
diff -u -r1.476 acgeneral.m4
--- acgeneral.m4 2000/05/25 07:49:40 1.476
+++ acgeneral.m4 2000/05/26 10:15:48
@@ -3167,36 +3167,76 @@
])
+
## ----------------------------------- ##
## Checking compiler characteristics. ##
## ----------------------------------- ##
+
+# _AC_COMPUTE_INT_COMPILE(EXPRESSION, VARIABLE, [INCLUDES])
+# ---------------------------------------------------------
+# Compute the integer EXPRESSION and store the result in the VARIABLE.
+# Works OK if cross compiling.
+define([_AC_COMPUTE_INT_COMPILE],
+[# Depending upon the size, compute the lo and hi bounds.
+AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= 0])],
+ [ac_lo=0 ac_try=0
+ while true; do
+ AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_try])],
+ [ac_hi=$ac_try; break],
+ [ac_lo=`expr $ac_try + 1` ac_try=`expr 2 '*' $ac_try + 1`])
+ done],
+ [ac_hi=-1 ac_try=-1
+ while true; do
+ AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_try])],
+ [ac_lo=$ac_try; break],
+ [ac_hi=`expr $ac_try - 1` ac_try=`expr 2 '*' $ac_try`])
+ done])
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+ ac_try=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+ AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_try])],
+ [ac_hi=$ac_try], [ac_lo=`expr $ac_try + 1`])
+done
+$2=$ac_lo[]dnl
+])# _AC_COMPUTE_INT_COMPILE
+
+
+# _AC_COMPUTE_INT_RUN(EXPRESSION, VARIABLE, [INCLUDES], [IF-FAILS])
+# -----------------------------------------------------------------
+# Store the evaluation of the integer EXPRESSION in VARIABLE.
+define([_AC_COMPUTE_INT_RUN],
+[AC_RUN_IFELSE([AC_LANG_INT_SAVE([$3], [$1])],
+ [$2=`cat conftestval`], [$4])])
+
+
+# _AC_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
+# ---------------------------------------------------------
+define([_AC_COMPUTE_INT],
+[if test "$cross_compiling" = yes; then
+ _AC_COMPUTE_INT_COMPILE([$1], [$2], [$3])
+else
+ _AC_COMPUTE_INT_RUN([$1], [$2], [$3], [$4])
+fi[]dnl
+])# _AC_COMPUTE_INT
+
-# AC_CHECK_SIZEOF(TYPE, [CROSS-SIZE], [INCLUDES])
-# -----------------------------------------------
-# This macro will probably be obsoleted by the macros of Kaveh. In
-# addition `CHECK' is not a proper name (is not boolean).
+# AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES])
+# --------------------------------------------
AC_DEFUN([AC_CHECK_SIZEOF],
-[AC_VAR_PUSHDEF([ac_Sizeof], [ac_cv_sizeof_$1])dnl
-AC_CACHE_CHECK([size of $1], ac_Sizeof,
-[AC_TRY_RUN(AC_INCLUDES_DEFAULT([$3])
-[int
-main ()
-{
- FILE *f = fopen ("conftestval", "w");
- if (!f)
- exit (1);
- fprintf (f, "%d\n", sizeof ($1));
- exit (0);
-}],
- AC_VAR_SET(ac_Sizeof, `cat conftestval`),
- AC_VAR_SET(ac_Sizeof, 0),
- ifval([$2], AC_VAR_SET(ac_Sizeof, $2)))])
-AC_DEFINE_UNQUOTED(AC_TR_CPP(sizeof_$1),
- AC_VAR_GET(ac_Sizeof),
- [The number of bytes in a `]$1['.])
-AC_VAR_POPDEF([ac_Sizeof])dnl
-])
+[AC_VAR_IF_INDIR([$1], [AC_FATAL([$0: requires literal arguments])])dnl
+AC_CHECK_TYPE([$1], [], [], [$3])
+AC_CACHE_CHECK([size of $1], AC_TR_SH([ac_cv_sizeof_$1]),
+[if test "$AC_TR_SH([ac_cv_type_$1])" = yes; then
+ _AC_COMPUTE_INT([sizeof ($1)],
+ [AC_TR_SH([ac_cv_sizeof_$1])],
+ [AC_INCLUDES_DEFAULT([$3])])
+else
+ AC_TR_SH([ac_cv_sizeof_$1])=0
+fi])dnl
+AC_DEFINE_UNQUOTED(AC_TR_CPP(sizeof_$1), $AC_TR_SH([ac_cv_sizeof_$1]),
+ [The size of a `$1', as computed by sizeof.])
+])# AC_CHECK_SIZEOF
Index: aclang.m4
===================================================================
RCS file: /cvs/autoconf/aclang.m4,v
retrieving revision 1.25
diff -u -r1.25 aclang.m4
--- aclang.m4 2000/05/26 09:42:13 1.25
+++ aclang.m4 2000/05/26 10:15:48
@@ -263,7 +263,22 @@
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+# AC_LANG_BOOL_COMPILE_TRY(PROLOGUE, EXPRESSION)
+# ----------------------------------------------
+# Produce a program that compiles with success iff the boolean EXPRESSION
+# evaluates to true at compile time.
+AC_DEFUN([AC_LANG_BOOL_COMPILE_TRY],
+[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+
+# AC_LANG_INT_SAVE(PROLOGUE, EXPRESSION)
+# --------------------------------------
+# Produce a program that saves the runtime evaluation of the integer
+# EXPRESSION into `conftestval'.
+AC_DEFUN([AC_LANG_INT_SAVE],
+[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+
+
# --------------- #
# 2b. C sources. #
# --------------- #
@@ -338,6 +353,24 @@
])])
+# AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
+# -------------------------------------------------
+define([AC_LANG_BOOL_COMPILE_TRY(C)],
+[AC_LANG_PROGRAM([$1], [int _array_ @<:@1 - 2 * !($2)@:>@])])
+
+
+# AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
+# -----------------------------------------
+# We need `stdio.h' to open a `FILE', so the prologue defaults to the
+# inclusion of `stdio.h'.
+define([AC_LANG_INT_SAVE(C)],
+[AC_LANG_PROGRAM([m4_default([$1], [@%:@include "stdio.h"])],
+[FILE *f = fopen ("conftestval", "w");
+if (!f)
+ exit (1);
+fprintf (f, "%d\n", ($2));])])
+
+
# ----------------- #
# 2c. C++ sources. #
# ----------------- #
@@ -369,6 +402,18 @@
# ------------------------------------
# Same as C.
define([AC_LANG_FUNC_LINK_TRY(C++)], defn([AC_LANG_FUNC_LINK_TRY(C)]))
+
+
+# AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
+# ---------------------------------------------------
+# Same as C.
+define([AC_LANG_BOOL_COMPILE_TRY(C++)], defn([AC_LANG_BOOL_COMPILE_TRY(C)]))
+
+
+# AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
+# -------------------------------------------
+# Same as C.
+define([AC_LANG_INT_SAVE(C++)], defn([AC_LANG_INT_SAVE_TRY(C)]))
Index: doc/autoconf.texi
===================================================================
RCS file: /cvs/autoconf/doc/autoconf.texi,v
retrieving revision 1.297
diff -u -r1.297 autoconf.texi
--- doc/autoconf.texi 2000/05/26 09:42:14 1.297
+++ doc/autoconf.texi 2000/05/26 10:15:50
@@ -3907,7 +3907,7 @@
@c FIXME: What the heck is this macro doing here? Move it out of
@c the way, in its proper section!!!
-@defmac AC_CHECK_SIZEOF (@var{type}, @ovar{cross-size}, @ovar{includes})
+@defmac AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @ovar{includes})
@maindex CHECK_SIZEOF
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
@@ -3915,8 +3915,8 @@
(@pxref{Default Includes}). If you provide @var{include}, make sure to
include @file{stdio.h} which is required for this macro to run.
-If cross-compiling, the value @var{cross-size} is used if given,
-otherwise @code{configure} exits with an error message.
+This macro now works even when cross-compiling. The @var{unused}
+argument was used when cross-compiling.
For example, the call
Index: tests/semantics.m4
===================================================================
RCS file: /cvs/autoconf/tests/semantics.m4,v
retrieving revision 1.15
diff -u -r1.15 semantics.m4
--- tests/semantics.m4 2000/05/22 08:39:26 1.15
+++ tests/semantics.m4 2000/05/26 10:15:51
@@ -84,7 +84,6 @@
])])
-
# AC_CHECK_SIZEOF
# ---------------
AT_TEST_MACRO(AC_CHECK_SIZEOF,
@@ -95,12 +94,28 @@
{
char a;
char b;
-} charchar;])],
+} charchar;])
+AC_CHECK_SIZEOF(charcharchar)
+
+# Exercize the code used when cross-compiling
+cross_compiling=yes
+AC_CHECK_SIZEOF(unsigned char)
+AC_CHECK_SIZEOF(ucharchar,,
+[#include <stdio.h>
+typedef struct
+{
+ unsigned char a;
+ unsigned char b;
+} ucharchar;])
+AC_CHECK_SIZEOF(ucharcharchar)],
[AT_CHECK_DEFINES(
[#define SIZEOF_CHAR 1
#define SIZEOF_CHARCHAR 2
+#define SIZEOF_CHARCHARCHAR 0
+#define SIZEOF_UCHARCHAR 2
+#define SIZEOF_UCHARCHARCHAR 0
+#define SIZEOF_UNSIGNED_CHAR 1
])])
-
# AC_CHECK_TYPES