Hello,

can you check the following patch?

On 22-04-13 17:27:11, FX wrote:
> Hi,
> 
> > the problem is that configure checks for feenableexcept() in libm:
> > AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes 
> > AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
> > 
> > FreeBSD doesn't have this function in libm, it's implemented in 
> > /usr/include/fenv.h.
> 
> I see. Then we probably can use AC_CHECK_FUNCS, or design a specific check, 
> so that it gives the right value on both glibc and FreeBSD targets.
> 
> Could you test something on your end?
> 
> FX

-- 
From d5e255f09b4cfd2cb3688d0e2d5feba85d1f5dc8 Mon Sep 17 00:00:00 2001
From: Piotr Kubaj <pku...@freebsd.org>
Date: Thu, 14 Apr 2022 02:35:26 +0200
Subject: [PATCH] powerpc: properly detect feenableexcept on FreeBSD

FreeBSD doesn't have feenableexcept in libm, but in fenv.h.

Signed-off-by: Piotr Kubaj <pku...@freebsd.org>
---
 libgfortran/configure    | 48 +++++++++++++++++++++++++++++++++++++++-
 libgfortran/configure.ac | 18 ++++++++++++++-
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/libgfortran/configure b/libgfortran/configure
index ae64dca3114..2f1011d7fdc 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -27338,8 +27338,52 @@ fi
 
 
 
+case x$target in
+  xpowerpc*-freebsd*)
+    # Check for the existence of <fenv.h> functions.
+    for ac_header in fenv.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "fenv.h" "ac_cv_header_fenv_h" "$ac_includes_default"
+if test "x$ac_cv_header_fenv_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_FENV_H 1
+_ACEOF
+ ac_has_fenv_h=yes
+else
+  ac_has_fenv_h=no
+fi
+
+done
+
+    if test x"$ac_has_fenv_h" = x"yes"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in <fenv.h>" >&5
+$as_echo_n "checking for feenableexcept in <fenv.h>... " >&6; }
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <fenv.h>
+int
+main ()
+{
+int except, ret;
+                      ret = feenableexcept(except);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  have_feenableexcept=yes
+$as_echo "#define HAVE_FEENABLEEXCEPT 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_feenableexcept" >&5
+$as_echo "$have_feenableexcept" >&6; }
+    fi
+    ;;
+  *)
 # Check for GNU libc feenableexcept
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in -lm" >&5
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in -lm" >&5
 $as_echo_n "checking for feenableexcept in -lm... " >&6; }
 if ${ac_cv_lib_m_feenableexcept+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -27384,6 +27428,8 @@ $as_echo "#define HAVE_FEENABLEEXCEPT 1" >>confdefs.h
 
 fi
 
+    ;;
+esac
 
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 97cc490cb5e..7c285aaf79c 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -602,8 +602,24 @@ fi
 # Check whether we have a __float128 type, depends on enable_libquadmath_support
 LIBGFOR_CHECK_FLOAT128
 
+case x$target in
+  xpowerpc*-freebsd*)
+    # Check for the existence of <fenv.h> functions.
+    AC_CHECK_HEADERS(fenv.h, ac_has_fenv_h=yes, ac_has_fenv_h=no)
+    if test x"$ac_has_fenv_h" = x"yes"; then
+      AC_MSG_CHECKING([for feenableexcept in <fenv.h>])
+      AC_TRY_COMPILE([#include <fenv.h>],
+                     [int except, ret;
+                      ret = feenableexcept(except);
+                     ],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[fenv.h includes feenableexcept])])
+      AC_MSG_RESULT($have_feenableexcept)
+    fi
+    ;;
+  *)
 # Check for GNU libc feenableexcept
-AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+    AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+    ;;
+esac
 
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
-- 
2.35.1

Attachment: signature.asc
Description: PGP signature

Reply via email to