Updated. AC_CHECK_SIZEOF has never been released with support of
shell variables, not my stepping back is backward compatible, and
there is no real loss.
/tmp % ./configure nostromo 12:08
checking for gcc... gcc
checking whether the C compiler works... yes
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for EMX OS/2 environment... no
checking for executable suffix...
checking for object suffix... o
checking how to run the C preprocessor... gcc -E
5 * 3 = 15
~17 = -18
checking for ANSI C header files... yes
checking for short... yes
checking size of short... 2
checking for tiny... no
checking size of tiny... 0
5 * 3 = 15
~17 = -18
checking for int... yes
checking size of int... 4
checking for integer... no
checking size of integer... 0
Akim
# ======================================== aclang.m4
# AC_LANG_BOLL_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_BOLL_COMPILE_TRY],
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
define([AC_LANG_BOLL_COMPILE_TRY(C)],
[AC_LANG_PROGRAM([$1], [int _array_ @<:@1 - 2 * !($2)@:>@])])
define([AC_LANG_BOLL_COMPILE_TRY(C++)],
defn([AC_LANG_BOLL_COMPILE_TRY(C)]))
# AC_LANG_COMPUTE(PROLOGUE, EXPRESSION)
# -------------------------------------
# Produce a program that saves the runtime evaluation of the integer
# EXPRESSION into `conftestval'.
AC_DEFUN([AC_LANG_COMPUTE],
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
# We need `stdio.h' to open a `FILE', so the prologue defaults to the
# inclusion of `stdio.h'.
define([AC_LANG_COMPUTE(C)],
[AC_LANG_PROGRAM([m4_default([$1], [@%:@include "stdio.h"])],
[FILE *f = fopen ("conftestval", "w");
if (!f)
exit (1);
fprintf (f, "%d\n", ($2));])])
define([AC_LANG_COMPUTE(C++)],
defn([AC_LANG_COMPUTE(C)]))
# ======================================== acgeneral.m4
# _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_BOLL_COMPILE_TRY([$3], [($1) >= 0])],
[ac_lo=0 ac_try=0
while true; do
AC_COMPILE_IFELSE([AC_LANG_BOLL_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_BOLL_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_BOLL_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_COMPUTE([$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_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES])
# --------------------------------------------
AC_DEFUN([AC_CHECK_SIZEOF],
[AC_VAR_IF_INDIR([$1], [AC_FATAL([$0: requires literal arguments])])dnl
AC_CHECK_TYPE([$1], [], [], [$3])
AC_CACHE_CHECK([size of $1], ac_cv_sizeof_$1,
[if test "$ac_cv_type_$1" = yes; then
_AC_COMPUTE_INT([sizeof ($1)], ac_cv_sizeof_$1, [AC_INCLUDES_DEFAULT([$3])])
else
ac_cv_sizeof_$1=0
fi])dnl
AC_DEFINE_UNQUOTED(AC_TR_CPP(sizeof_$1), $ac_cv_sizeof_$1,
[The size of a `$1', as computed by sizeof.])
])
# ======================================================================
AC_INIT
AC_PROG_CC
AC_PROG_CPP
# Not cross
_AC_COMPUTE_INT(5 * 3, foo)
echo "5 * 3 = $foo"
_AC_COMPUTE_INT(~17, bar)
echo "~17 = $bar"
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(tiny)
# Cross.
cross_compiling=yes
_AC_COMPUTE_INT(5 * 3, foo)
echo "5 * 3 = $foo"
_AC_COMPUTE_INT(~17, bar)
echo "~17 = $bar"
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(integer)