I would like to tests to see if a system has full support for gcc -m32. I tried using AX_CHECK_COMPILE_FLAG([-m32], ..., ...). That test doesn't do what I would like it to do. It seems to test whether -m32 is a valid option to gcc, NOT that it actually can compile a code.
I know that if I test -m33 then AX_CHECK_COMPILE_FLAG correctly says that there is no option -m33 as expected.
On this particular system compiling a simple hello world program does the following:
$ gcc -m32 -c hello.c
In file included from /usr/include/features.h:385,
from /usr/include/stdio.h:28,
from hello.c:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
and returns a non-zero status. This non-zero status is what I like to be able to test for.
I was able to find a solution to the problem. Basically, I took the AX_CHECK_COMPILE_FLAG test and change the internals to use AC_RUN_IFELSE instead of AC_COMPILE_IFELSE. I have changed the name to AX_TEST_COMPILE_FLAG and here is how use it:
AX_TEST_COMPILE_FLAG([-m32],[HAVE_32BIT=yes],[HAVE_32BIT=no])
and here is the definition:
AC_DEFUN([AX_TEST_COMPILE_FLAG],
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
AS_VAR_PUSHDEF([CACHEVAR] [ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
AC_CACHE_CHECK([whether _AC_LANG compiler can build and run with $1], CACHEVAR, [
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
AC_RUN_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
AS_VAR_IF(CACHEVAR,yes,
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_COMPILE_FLAGS