From f64f44e9ebbe4ed59265d91bd3b483c1fbcd5b0e Mon Sep 17 00:00:00 2001
From: John Ericson <John.Ericson@Obsidian.Systems>
Date: Fri, 5 Nov 2021 04:58:29 +0000
Subject: [PATCH] Split libm check between top level and RTS

---
 configure.ac     | 12 +++---------
 rts/configure.ac |  9 +++++++++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index a8a66c27c040..8318d6cf4dda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -951,15 +951,9 @@ dnl    Keep that check as early as possible.
 dnl    as we need to know whether we need libm
 dnl    for math functions or not
 dnl    (see https://gitlab.haskell.org/ghc/ghc/issues/3730)
-AC_CHECK_LIB(m, atan, HaveLibM=YES, HaveLibM=NO)
-if test $HaveLibM = YES
-then
-  AC_DEFINE([HAVE_LIBM], [1], [Define to 1 if you need to link with libm])
-  AC_SUBST([UseLibm],[YES])
-else
-  AC_SUBST([UseLibm],[NO])
-fi
-TargetHasLibm=$HaveLibM
+AC_CHECK_LIB(m, atan, UseLibm=YES, UseLibm=NO)
+AC_SUBST([UseLibm])
+TargetHasLibm=$UseLibm
 AC_SUBST(TargetHasLibm)
 
 FP_BFD_FLAG
diff --git a/rts/configure.ac b/rts/configure.ac
index 1fbd2164070e..3e64d2f03da5 100644
--- a/rts/configure.ac
+++ b/rts/configure.ac
@@ -33,6 +33,15 @@ GHC_CONVERT_PLATFORM_PARTS([host], [Host])
 FPTOOLS_SET_PLATFORM_VARS([host], [Host])
 FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
 
+dnl ** check for math library
+dnl    Keep that check as early as possible.
+dnl    as we need to know whether we need libm
+dnl    for math functions or not
+dnl    (see https://gitlab.haskell.org/ghc/ghc/issues/3730)
+AS_IF(
+  [test "$CABAL_FLAG_libm" = 1],
+  [AC_DEFINE([HAVE_LIBM], [1], [Define to 1 if you need to link with libm])])
+
 AS_IF([test "$CABAL_FLAG_libbfd" = 1], [FP_WHEN_ENABLED_BFD])
 
 dnl ################################################################
-- 
GitLab