|
|
> Major caveat: I realized after I'd finished uploading that the default
> compiler flags also assume Pentium and are probably fairly gcc-specific. I
> need to implement some decent configure options in that regard.
Here is an autoconf macro that you can use for this purpose
(put it in acinclude.m4):
# POV_TRY_CFLAGS(CFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS])
# ------------------------------------------------------------
# Check whether compiler supports a given set of cflags, cache result,
# and update CFLAGS.
#
AC_DEFUN([POV_TRY_CFLAGS],
[
# Create a unique cache-id name.
pov_try_cflags_var=pov_cv_try_cflags`echo "$1" | sed 's/[[^a-zA-Z0-9]]/_/g'`
# Cannot use AC_CACHE_CHECK() due to the nature of the cache-id variable.
AC_MSG_CHECKING([whether $CC accepts $1])
AC_CACHE_VAL(
[$pov_try_cflags_var],
[
# AC_TRY_COMPILE() is not appropriate any longer since autoconf-2.5x.
# Compile and inspect standard error for given flags.
echo 'int main(void){ return 0; }' > conftest.c
if test -z "`$CC -c $1 conftest.c 2>&1 | grep '\$1'`"; then
eval "$pov_try_cflags_var=yes"
else
eval "$pov_try_cflags_var=no"
fi
rm -f conftest.c conftest.o
]
)
eval "pov_try_cflags_value=\$$pov_try_cflags_var"
AC_MSG_RESULT([$pov_try_cflags_value])
# Update CFLAGS when flags are working, and run provided actions.
if test x"$pov_try_cflags_value" = x"yes"; then
CFLAGS="$CFLAGS $1"
ifelse([$2],[],[:],[$2])
else
ifelse([$3],[],[:],[$3])
fi
])
In the configure.ac (or configure.in) file you just call it,
for instance:
TRIP_TRY_CFLAGS([-O2], [], [TRIP_TRY_CFLAGS([-O])])
will try first flag -O2 and, if not recognized, try -O and then
simply nothing. CFLAGS is updated accordingly and the result is cached.
This macro normally works okay with gcc on Linux and gcc/cc on
SGI (didn't tested anything else). Hope I didn't put any typo while
copying/editing the macro from my own packages devels.
- N.C.
Post a reply to this message
|
|