Hadrian: support in-tree GMP
authorAlec Theriault <alec.theriault@gmail.com>
Thu, 6 Dec 2018 04:46:21 +0000 (20:46 -0800)
committerBen Gamari <ben@well-typed.com>
Wed, 23 Jan 2019 19:07:28 +0000 (14:07 -0500)
Summary:
This adds top-level configure flags '--with-intree-gmp' and
'--with-framework-preferred', both of which are especially relevant
on MacOS.

Besides gaining two new flags, Hadrian also had to be taught what to
do with the 'framework' in .cabal files.

Test Plan:
./boot && ./configure --with-intree-gmp && ./hadrian/build.sh
./boot && ./configure --with-gmp-framework-preferred && ./hadrian/build.sh # on macos

Reviewers: carter, snowleopard, alpmestan, hvr, goldfire, bgamari

Subscribers: rwbarton, erikd

GHC Trac Issues: #16001

Differential Revision: https://phabricator.haskell.org/D5417

aclocal.m4
hadrian/cfg/system.config.in
hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
hadrian/src/Hadrian/Haskell/Cabal/Type.hs
hadrian/src/Oracles/Flag.hs
hadrian/src/Settings/Builders/Ghc.hs
hadrian/src/Settings/Packages.hs
libraries/integer-gmp/config.mk.in
libraries/integer-gmp/configure.ac
mk/config.mk.in
rules/build-package-data.mk

index a7026e2..62825c3 100644 (file)
@@ -1780,8 +1780,22 @@ AC_DEFUN([FP_GMP],
       [directory containing gmp library])],
       [GMP_LIB_DIRS=$withval])
 
+  AC_ARG_ENABLE([intree-gmp],
+    [AC_HELP_STRING([--with-intree-gmp],
+      [force using the in-tree GMP])],
+      [GMP_FORCE_INTREE=YES],
+      [GMP_FORCE_INTREE=NO])
+
+  AC_ARG_ENABLE([gmp-framework-preferred],
+    [AC_HELP_STRING([--with-gmp-framework-preferred],
+      [on OSX, prefer the GMP framework to the gmp lib])],
+      [GMP_PREFER_FRAMEWORK=YES],
+      [GMP_PREFER_FRAMEWORK=NO])
+
   AC_SUBST(GMP_INCLUDE_DIRS)
   AC_SUBST(GMP_LIB_DIRS)
+  AC_SUBST(GMP_FORCE_INTREE)
+  AC_SUBST(GMP_PREFER_FRAMEWORK)
 ])# FP_GMP
 
 # FP_CURSES
index 7e132f7..7b92b29 100644 (file)
@@ -118,8 +118,10 @@ curses-lib-dir    = @CURSES_LIB_DIRS@
 iconv-include-dir = @ICONV_INCLUDE_DIRS@
 iconv-lib-dir     = @ICONV_LIB_DIRS@
 
-gmp-include-dir   = @GMP_INCLUDE_DIRS@
-gmp-lib-dir       = @GMP_LIB_DIRS@
+intree-gmp              = @GMP_FORCE_INTREE@
+gmp-framework-preferred = @GMP_PREFER_FRAMEWORK@
+gmp-include-dir         = @GMP_INCLUDE_DIRS@
+gmp-lib-dir             = @GMP_LIB_DIRS@
 
 use-system-ffi    = @UseSystemLibFFI@
 ffi-include-dir   = @FFIIncludeDir@
index 9952701..8df343b 100644 (file)
@@ -280,7 +280,8 @@ resolveContextData context@Context {..} = do
           , depIncludeDirs  = forDeps Installed.includeDirs
           , depCcOpts       = forDeps Installed.ccOptions
           , depLdOpts       = forDeps Installed.ldOptions
-          , buildGhciLib    = C.withGHCiLib lbi' }
+          , buildGhciLib    = C.withGHCiLib lbi'
+          , frameworks      = C.frameworks buildInfo }
 
 -- | Look for a @.buildinfo@ in all of the specified directories, stopping on
 -- the first one we find.
index dd6e4bd..b2a7002 100644 (file)
@@ -64,6 +64,7 @@ data ContextData = ContextData
     , depCcOpts       :: [String]
     , depLdOpts       :: [String]
     , buildGhciLib    :: Bool
+    , frameworks      :: [String]
     } deriving (Eq, Generic, Show, Typeable)
 
 instance Binary   PackageData
index 57dbf2d..b294ceb 100644 (file)
@@ -13,6 +13,8 @@ data Flag = ArSupportsAtFile
           | CrossCompiling
           | GccIsClang
           | GhcUnregisterised
+          | GmpInTree
+          | GmpFrameworkPref
           | LeadingUnderscore
           | SolarisBrokenShld
           | SplitObjectsBroken
@@ -29,6 +31,8 @@ flag f = do
             CrossCompiling     -> "cross-compiling"
             GccIsClang         -> "gcc-is-clang"
             GhcUnregisterised  -> "ghc-unregisterised"
+            GmpInTree          -> "intree-gmp"
+            GmpFrameworkPref   -> "gmp-framework-preferred"
             LeadingUnderscore  -> "leading-underscore"
             SolarisBrokenShld  -> "solaris-broken-shld"
             SplitObjectsBroken -> "split-objects-broken"
index 4957de7..488e551 100644 (file)
@@ -45,6 +45,7 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
     pkg     <- getPackage
     libs    <- getContextData extraLibs
     libDirs <- getContextData extraLibDirs
+    fmwks   <- getContextData frameworks
     dynamic <- requiresDynamic
     darwin  <- expr osxHost
 
@@ -71,6 +72,7 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
             , not (nonHsMainPackage pkg) ? arg "-rtsopts"
             , pure [ "-l" ++ lib    | lib <-    libs    ]
             , pure [ "-L" ++ libDir | libDir <- libDirs ]
+            , darwin ? pure (concat [ ["-framework", fmwk] | fmwk <- fmwks ])
             ]
 
 findHsDependencies :: Args
index 5993723..4be0fba 100644 (file)
@@ -136,14 +136,10 @@ packageArgs = do
           [ builder Cc ? arg includeGmp
 
           , builder (Cabal Setup) ? mconcat
-            [ -- TODO: This should respect some settings flag "InTreeGmp".
-              -- Depending on @IncludeDir@ and @LibDir@ is bound to fail, since
-              -- these are only set if the configure script was explicilty
-              -- called with GMP include and lib dirs. Their absense as such
-              -- does not imply @in-tree-gmp@.
-              -- (null gmpIncludeDir && null gmpLibDir) ?
-              -- arg "--configure-option=--with-intree-gmp"
-              arg ("--configure-option=CFLAGS=" ++ includeGmp)
+            [ flag GmpInTree ? arg "--configure-option=--with-intree-gmp"
+            , flag GmpFrameworkPref ?
+              arg "--configure-option=--with-gmp-framework-preferred"
+            , arg ("--configure-option=CFLAGS=" ++ includeGmp)
             , arg ("--gcc-options="             ++ includeGmp) ] ]
 
         ---------------------------------- rts ---------------------------------
index b66f94c..2556326 100644 (file)
@@ -10,6 +10,8 @@ ifeq "$(HaveFrameworkGMP)" ""
  HaveFrameworkGMP = @HaveFrameworkGMP@
 endif
 
+GMP_FORCE_INTREE = @GMP_FORCE_INTREE@
+GMP_PREFER_FRAMEWORK = @GMP_PREFER_FRAMEWORK@
 GMP_INCLUDE_DIRS = @GMP_INCLUDE_DIRS@
 GMP_LIB_DIRS = @GMP_LIB_DIRS@
 
index 1ccd48e..d189375 100644 (file)
@@ -27,13 +27,13 @@ AC_ARG_WITH([gmp-libraries],
     [GMP_LIB_DIRS=$withval; LDFLAGS="-L$withval"],
     [GMP_LIB_DIRS=])
 
-AC_ARG_WITH([gmp-framework-preferred],
+AC_ARG_ENABLE([gmp-framework-preferred],
   [AC_HELP_STRING([--with-gmp-framework-preferred],
     [on OSX, prefer the GMP framework to the gmp lib])],
     [GMP_PREFER_FRAMEWORK=YES],
     [GMP_PREFER_FRAMEWORK=NO])
 
-AC_ARG_WITH([intree-gmp],
+AC_ARG_ENABLE([intree-gmp],
   [AC_HELP_STRING([--with-intree-gmp],
     [force using the in-tree GMP])],
     [GMP_FORCE_INTREE=YES],
index fb823ae..0119e9a 100644 (file)
@@ -898,6 +898,8 @@ ICONV_LIB_DIRS = @ICONV_LIB_DIRS@
 
 GMP_INCLUDE_DIRS = @GMP_INCLUDE_DIRS@
 GMP_LIB_DIRS = @GMP_LIB_DIRS@
+GMP_PREFER_FRAMEWORK = @GMP_PREFER_FRAMEWORK@
+GMP_FORCE_INTREE = @GMP_FORCE_INTREE@
 
 CURSES_LIB_DIRS = @CURSES_LIB_DIRS@
 
index 2f0d7c9..af1ead8 100644 (file)
@@ -90,6 +90,14 @@ ifneq "$$(GMP_LIB_DIRS)" ""
 $1_$2_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="$$(GMP_LIB_DIRS)"
 endif
 
+ifeq "$$(GMP_PREFER_FRAMEWORK)" "YES"
+$1_$2_CONFIGURE_OPTS += --configure-option=--with-gmp-framework-preferred
+endif
+
+ifeq "$$(GMP_FORCE_INTREE)" "YES"
+$1_$2_CONFIGURE_OPTS += --configure-option=--with-intree-gmp
+endif
+
 ifneq "$$(CURSES_LIB_DIRS)" ""
 $1_$2_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="$$(CURSES_LIB_DIRS)"
 endif