From 2a2f51d79f145e015cc089d97cf71c19dd27bee4 Mon Sep 17 00:00:00 2001
From: Sylvain Henry <sylvain@haskus.fr>
Date: Thu, 27 Feb 2020 12:59:02 +0100
Subject: [PATCH] Use configure script to detect that we should use in-tree GMP
 on Windows

---
 configure.ac                     | 7 +++++++
 hadrian/src/Rules/Gmp.hs         | 6 +++---
 hadrian/src/Settings/Packages.hs | 7 +------
 libraries/integer-gmp/gmp/ghc.mk | 6 ------
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/configure.ac b/configure.ac
index 778588429659..fcc0a75ca672 100644
--- a/configure.ac
+++ b/configure.ac
@@ -458,6 +458,12 @@ FP_ICONV
 FP_GMP
 FP_CURSES
 
+dnl On Windows we force in-tree GMP build until we support dynamic linking
+if test "$HostOS" = "mingw32"
+then
+  GMP_FORCE_INTREE="YES"
+fi
+
 XCODE_VERSION()
 
 
@@ -1453,6 +1459,7 @@ echo "\
    Building a cross compiler : $CrossCompiling
    Unregisterised            : $Unregisterised
    TablesNextToCode          : $TablesNextToCode
+   Build GMP in tree         : $GMP_FORCE_INTREE
    hs-cpp       : $HaskellCPPCmd
    hs-cpp-flags : $HaskellCPPArgs
    ar           : $ArCmd
diff --git a/hadrian/src/Rules/Gmp.hs b/hadrian/src/Rules/Gmp.hs
index 2bf41d99e2e5..405c251b8b3f 100644
--- a/hadrian/src/Rules/Gmp.hs
+++ b/hadrian/src/Rules/Gmp.hs
@@ -66,14 +66,14 @@ gmpRules = do
 
         isInTree <- flag GmpInTree
 
-        if windowsHost || isInTree  -- TODO: We don't use system GMP on Windows. Fix?
+        if isInTree
         then do
-            putBuild "| No GMP library/framework detected; in tree GMP will be built"
+            putBuild "| In tree GMP will be built"
             let intreeHeader = stageP -/- "gmp/gmp.h"
             need [intreeHeader]
             copyFile intreeHeader header
         else do
-            putBuild "| GMP library/framework detected and will be used"
+            putBuild "| System GMP library/framework will be used"
             copyFile (gmpBase -/- "ghc-gmp.h") header
 
     -- Build in-tree GMP library for the current stage, prioritised so that it
diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs
index 02f483cc538a..d06d4292ddb2 100644
--- a/hadrian/src/Settings/Packages.hs
+++ b/hadrian/src/Settings/Packages.hs
@@ -176,14 +176,9 @@ gmpPackageArgs = do
         librariesGmp <- getSetting GmpLibDir
         includesGmp  <- getSetting GmpIncludeDir
 
-        -- Windows is always built with inplace GMP until we have dynamic
-        -- linking working.
-        inTreeFlag <- getFlag GmpInTree
-        let inTree = inTreeFlag || windowsHost
-
         mconcat
           [ builder (Cabal Setup) ? mconcat
-            [ inTree ? arg "--configure-option=--with-intree-gmp"
+            [ flag GmpInTree ? arg "--configure-option=--with-intree-gmp"
             , flag GmpFrameworkPref ?
               arg "--configure-option=--with-gmp-framework-preferred"
 
diff --git a/libraries/integer-gmp/gmp/ghc.mk b/libraries/integer-gmp/gmp/ghc.mk
index c9dd69953b28..4272e86924f8 100644
--- a/libraries/integer-gmp/gmp/ghc.mk
+++ b/libraries/integer-gmp/gmp/ghc.mk
@@ -39,12 +39,6 @@ clean_gmp:
 	$(call removeTrees,libraries/integer-gmp/gmp/gmpbuild)
 endif
 
-ifeq "$(Windows_Host)" "YES"
-# Apparently building on Windows fails when there is a system gmp
-# available, so we never try to use the system gmp on Windows
-libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp
-endif
-
 ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
 libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
 endif
-- 
GitLab