+
+
+dnl
+dnl determine how to get IEEE math working
+dnl AC_IEEE(MESSAGE, set rd_cv_ieee_[var] variable, INCLUDES,
+dnl FUNCTION-BODY, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
+dnl
+
+dnl substitute them in all the files listed in AC_OUTPUT
+AC_SUBST(PERLFLAGS)
+
+AC_DEFUN([AC_IEEE], [
+AC_MSG_CHECKING([if IEEE math works $1])
+AC_CACHE_VAL([rd_cv_ieee_$2],
+[AC_RUN_IFELSE([AC_LANG_SOURCE([[$3
+
+#if HAVE_MATH_H
+# include <math.h>
+#endif
+
+#if HAVE_FLOAT_H
+# include <float.h>
+#endif
+
+#if HAVE_IEEEFP_H
+# include <ieeefp.h>
+#endif
+
+#if HAVE_FP_CLASS_H
+# include <fp_class.h>
+#endif
+
+/* Solaris */
+#if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASS))
+# define HAVE_ISINF 1
+# define isinf(a) (fpclass(a) == FP_NINF || fpclass(a) == FP_PINF)
+#endif
+
+/* Digital UNIX */
+#if (! defined(HAVE_ISINF) && defined(HAVE_FP_CLASS) && defined(HAVE_FP_CLASS_H))
+# define HAVE_ISINF 1
+# define isinf(a) (fp_class(a) == FP_NEG_INF || fp_class(a) == FP_POS_INF)
+#endif
+
+/* AIX */
+#if (! defined(HAVE_ISINF) && defined(HAVE_CLASS))
+# define HAVE_ISINF 1
+# define isinf(a) (class(a) == FP_MINUS_INF || class(a) == FP_PLUS_INF)
+#endif
+
+#if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_PLUS_INF) && defined(FP_MINUS_INF))
+# define HAVE_ISINF 1
+# define isinf(a) (fpclassify(a) == FP_MINUS_INF || fpclassify(a) == FP_PLUS_INF)
+#endif
+
+#if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_INFINITE))
+# define HAVE_ISINF 1
+# define isinf(a) (fpclassify(a) == FP_INFINITE)
+#endif
+
+#include <stdio.h>
+int main(void){
+ double nan,inf,c,zero;
+ $4;
+ /* some math to see if we get a floating point exception */
+ zero=sin(0.0); /* don't let the compiler optimize us away */
+ nan=0.0/zero; /* especially here */
+ inf=1.0/zero; /* and here. I want to know if it can do the magic */
+ /* at run time without sig fpe */
+ c = inf + nan;
+ c = inf / nan;
+ if (! isnan(nan)) {printf ("not isnan(NaN) ... "); return 1;}
+ if (nan == nan) {printf ("nan == nan ... "); return 1;}
+ if (! isinf(inf)) {printf ("not isinf(oo) ... "); return 1;}
+ if (! isinf(-inf)) {printf ("not isinf(-oo) ... "); return 1;}
+ if (! inf > 0) {printf ("not inf > 0 ... "); return 1;}
+ if (! -inf < 0) {printf ("not -inf < 0 ... "); return 1;}
+ return 0;
+ }]])],[rd_cv_ieee_$2=yes],[rd_cv_ieee_$2=no],[:])])
+dnl these we run regardles is cached or not
+if test x${rd_cv_ieee_$2} = "xyes"; then
+ AC_MSG_RESULT(yes)
+ $5
+else
+ AC_MSG_RESULT(no)
+ $6
+fi
+
+])
+
+AC_DEFUN([AC_FULL_IEEE],[
+AC_LANG_PUSH(C)
+_cflags=${CFLAGS}
+AC_IEEE([out of the box], works, , , ,
+ [CFLAGS="$_cflags -ieee"
+ AC_IEEE([with the -ieee switch], switch, , , ,
+ [CFLAGS="$_cflags -qfloat=nofold"
+ AC_IEEE([with the -qfloat=nofold switch], nofold, , , ,
+ [CFLAGS="$_cflags -w -qflttrap=enable:zerodivide"
+ AC_IEEE([with the -w -qflttrap=enable:zerodivide], flttrap, , , ,
+ [CFLAGS="$_cflags -mieee"
+ AC_IEEE([with the -mieee switch], mswitch, , , ,
+ [CFLAGS="$_cflags -q float=rndsngl"
+ AC_IEEE([with the -q float=rndsngl switch], qswitch, , , ,
+ [CFLAGS="$_cflags -OPT:IEEE_NaN_inf=ON"
+ AC_IEEE([with the -OPT:IEEE_NaN_inf=ON switch], ieeenaninfswitch, , , ,
+ [CFLAGS="$_cflags -OPT:IEEE_comparisons=ON"
+ AC_IEEE([with the -OPT:IEEE_comparisons=ON switch], ieeecmpswitch, , , ,
+ [CFLAGS=$_cflags
+ AC_IEEE([with fpsetmask(0)], mask,
+ [#include <floatingpoint.h>], [fpsetmask(0)],
+ [AC_DEFINE(MUST_DISABLE_FPMASK)
+ PERLFLAGS="CCFLAGS=-DMUST_DISABLE_FPMASK"],
+ [AC_IEEE([with signal(SIGFPE,SIG_IGN)], sigfpe,
+ [#include <signal.h>], [signal(SIGFPE,SIG_IGN)],
+ [AC_DEFINE(MUST_DISABLE_SIGFPE)
+ PERLFLAGS="CCFLAGS=-DMUST_DISABLE_SIGFPE"],
+ AC_MSG_ERROR([
+Your Compiler does not do propper IEEE math ... Please find out how to
+make IEEE math work with your compiler and let me know (oetiker@ee.ethz.ch).
+Check config.log to see what went wrong ...
+]))])])])])])])])])])
+
+AC_LANG_POP(C)
+
+])
+
+
+dnl a macro to check for ability to create python extensions
+dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
+dnl function also defines PYTHON_INCLUDES
+AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
+[AC_REQUIRE([AM_PATH_PYTHON])
+AC_MSG_CHECKING(for headers required to compile python extensions)
+dnl deduce PYTHON_INCLUDES
+py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
+py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
+PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
+if test "$py_prefix" != "$py_exec_prefix"; then
+ PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
+fi
+AC_SUBST(PYTHON_INCLUDES)
+dnl check if the headers exist:
+save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
+AC_TRY_CPP([#include <Python.h>],dnl
+[AC_MSG_RESULT(found)
+$1],dnl
+[AC_MSG_RESULT(not found)
+$2])
+CPPFLAGS="$save_CPPFLAGS"
+])
+
+dnl a macro to add some color to the build process.
+dnl CONFIGURE_PART(MESSAGE)
+
+AC_DEFUN([CONFIGURE_PART],[
+case $TERM in
+ # for the most important terminal types we directly know the sequences
+ xterm|xterm*|vt220|vt220*)
+ T_MD=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
+ T_ME=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
+ ;;
+ vt100|vt100*|cygwin)
+ T_MD=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
+ T_ME=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
+ ;;
+ *)
+ T_MD=''
+ T_ME=''
+ ;;
+esac
+ AC_MSG_RESULT()
+ AC_MSG_RESULT([${T_MD}$1${T_ME}])
+])
+
+