[commit: ghc] wip/nfs-locking: fix handling of FFI library configure params (6abfdfa)

git at git.haskell.org git at git.haskell.org
Thu Oct 26 23:53:59 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/6abfdfaec035057a956ded2dad8695c4c600e24c/ghc

>---------------------------------------------------------------

commit 6abfdfaec035057a956ded2dad8695c4c600e24c
Author: Karel Gardas <karel.gardas at centrum.cz>
Date:   Sun Jan 17 22:55:57 2016 +0100

    fix handling of FFI library configure params


>---------------------------------------------------------------

6abfdfaec035057a956ded2dad8695c4c600e24c
 cfg/system.config.in          |  3 ++
 src/Oracles/Config/Setting.hs |  6 +++
 src/Rules/Libffi.hs           | 87 ++++++++++++++++++++++++-------------------
 src/Settings/Packages/Rts.hs  |  8 +++-
 4 files changed, 65 insertions(+), 39 deletions(-)

diff --git a/cfg/system.config.in b/cfg/system.config.in
index dfde8e3..ecbf18d 100644
--- a/cfg/system.config.in
+++ b/cfg/system.config.in
@@ -127,6 +127,9 @@ iconv-lib-dirs     = @ICONV_LIB_DIRS@
 gmp-include-dirs   = @GMP_INCLUDE_DIRS@
 gmp-lib-dirs       = @GMP_LIB_DIRS@
 
+use-system-ffi     = @UseSystemLibFFI@
+ffi-include-dirs   = @FFIIncludeDir@
+ffi-lib-dirs       = @FFILibDir@
 
 # Optional Dependencies:
 #=======================
diff --git a/src/Oracles/Config/Setting.hs b/src/Oracles/Config/Setting.hs
index 46d0d33..7b5d71e 100644
--- a/src/Oracles/Config/Setting.hs
+++ b/src/Oracles/Config/Setting.hs
@@ -47,6 +47,7 @@ data Setting = BuildArch
              | TargetPlatform
              | TargetPlatformFull
              | TargetVendor
+             | UseSystemFfi
 
 data SettingList = ConfCcArgs Stage
                  | ConfCppArgs Stage
@@ -57,6 +58,8 @@ data SettingList = ConfCcArgs Stage
                  | HsCppArgs
                  | IconvIncludeDirs
                  | IconvLibDirs
+                 | FfiIncludeDirs
+                 | FfiLibDirs
 
 setting :: Setting -> Action String
 setting key = askConfig $ case key of
@@ -88,6 +91,7 @@ setting key = askConfig $ case key of
     TargetPlatform     -> "target-platform"
     TargetPlatformFull -> "target-platform-full"
     TargetVendor       -> "target-vendor"
+    UseSystemFfi       -> "use-system-ffi"
 
 settingList :: SettingList -> Action [String]
 settingList key = fmap words $ askConfig $ case key of
@@ -100,6 +104,8 @@ settingList key = fmap words $ askConfig $ case key of
     HsCppArgs               -> "hs-cpp-args"
     IconvIncludeDirs        -> "iconv-include-dirs"
     IconvLibDirs            -> "iconv-lib-dirs"
+    FfiIncludeDirs          -> "ffi-include-dirs"
+    FfiLibDirs              -> "ffi-lib-dirs"
 
 getSetting :: Setting -> ReaderT a Action String
 getSetting = lift . setting
diff --git a/src/Rules/Libffi.hs b/src/Rules/Libffi.hs
index dbf50dc..5f23cad 100644
--- a/src/Rules/Libffi.hs
+++ b/src/Rules/Libffi.hs
@@ -70,44 +70,55 @@ configureArguments = do
 libffiRules :: Rules ()
 libffiRules = do
     libffiDependencies &%> \_ -> do
-        when trackBuildSystem $ need [sourcePath -/- "Rules/Libffi.hs"]
-        removeDirectory libffiBuild
-        createDirectory $ buildRootPath -/- stageString Stage0
-
-        tarballs <- getDirectoryFiles "" ["libffi-tarballs/libffi*.tar.gz"]
-        when (length tarballs /= 1) $
-            putError $ "libffiRules: exactly one libffi tarball expected"
-                     ++ "(found: " ++ show tarballs ++ ")."
-
-        need tarballs
-        let libname = dropExtension . dropExtension . takeFileName $ head tarballs
-
-        removeDirectory (buildRootPath -/- libname)
-        actionFinally (do
-            build $ fullTarget libffiTarget Tar tarballs [buildRootPath]
-            moveDirectory (buildRootPath -/- libname) libffiBuild) $
-                removeFiles buildRootPath [libname <//> "*"]
-
-        fixFile (libffiBuild -/- "Makefile.in") fixLibffiMakefile
-
-        forM_ ["config.guess", "config.sub"] $ \file ->
-            copyFile file (libffiBuild -/- file)
-
-        envs <- configureEnvironment
-        args <- configureArguments
-        runConfigure libffiBuild envs args
-
-        runMake libffiBuild ["MAKEFLAGS="]
-        runMake libffiBuild ["MAKEFLAGS=", "install"]
-
-        forM_ ["ffi.h", "ffitarget.h"] $ \file -> do
-            let src = libffiBuild -/- "inst/lib" -/- libname -/- "include" -/- file
-            copyFile src (rtsBuildPath -/- file)
-
-        libffiName <- rtsLibffiLibraryName
-        copyFile libffiLibrary (rtsBuildPath -/- "lib" ++ libffiName <.> "a")
-
-        putSuccess $ "| Successfully built custom library 'libffi'"
+        use_system_ffi <- setting UseSystemFfi
+        ffi_header_dirs <- settingList FfiIncludeDirs
+        if use_system_ffi == "YES"
+        then do
+          putBuild "| System supplied FFI library will be used"
+          let ffi_header_dir = head ffi_header_dirs
+          forM_ ["ffi.h", "ffitarget.h"] $ \file -> do
+              let src = ffi_header_dir  -/- file
+              copyFile src (rtsBuildPath -/- file)
+          putSuccess $ "| Successfully copied system supplied FFI library header files"
+        else do
+            when trackBuildSystem $ need [sourcePath -/- "Rules/Libffi.hs"]
+            removeDirectory libffiBuild
+            createDirectory $ buildRootPath -/- stageString Stage0
+
+            tarballs <- getDirectoryFiles "" ["libffi-tarballs/libffi*.tar.gz"]
+            when (length tarballs /= 1) $
+                 putError $ "libffiRules: exactly one libffi tarball expected"
+                              ++ "(found: " ++ show tarballs ++ ")."
+
+            need tarballs
+            let libname = dropExtension . dropExtension . takeFileName $ head tarballs
+
+            removeDirectory (buildRootPath -/- libname)
+            actionFinally (do
+                            build $ fullTarget libffiTarget Tar tarballs [buildRootPath]
+                            moveDirectory (buildRootPath -/- libname) libffiBuild) $
+                            removeFiles buildRootPath [libname <//> "*"]
+
+            fixFile (libffiBuild -/- "Makefile.in") fixLibffiMakefile
+
+            forM_ ["config.guess", "config.sub"] $ \file ->
+              copyFile file (libffiBuild -/- file)
+
+            envs <- configureEnvironment
+            args <- configureArguments
+            runConfigure libffiBuild envs args
+
+            runMake libffiBuild ["MAKEFLAGS="]
+            runMake libffiBuild ["MAKEFLAGS=", "install"]
+
+            forM_ ["ffi.h", "ffitarget.h"] $ \file -> do
+                                   let src = libffiBuild -/- "inst/lib" -/- libname -/- "include" -/- file
+                                   copyFile src (rtsBuildPath -/- file)
+
+            libffiName <- rtsLibffiLibraryName
+            copyFile libffiLibrary (rtsBuildPath -/- "lib" ++ libffiName <.> "a")
+
+            putSuccess $ "| Successfully built custom library 'libffi'"
 
 -- chmod +x libffi/ln
 -- # wc on OS X has spaces in its output, which libffi's Makefile
diff --git a/src/Settings/Packages/Rts.hs b/src/Settings/Packages/Rts.hs
index f1d67d9..26fce73 100644
--- a/src/Settings/Packages/Rts.hs
+++ b/src/Settings/Packages/Rts.hs
@@ -20,8 +20,14 @@ rtsConf = pkgPath rts -/- targetDirectory Stage1 rts -/- "package.conf.inplace"
 
 rtsLibffiLibraryName :: Action FilePath
 rtsLibffiLibraryName = do
+    use_system_ffi <- setting UseSystemFfi
     windows <- windowsHost
-    return $ if windows then "Cffi-6" else "Cffi"
+    case (use_system_ffi, windows) of
+      ("YES", False) -> return "ffi"
+      ("NO", False) -> return "Cffi"
+      (_, True) -> return "Cffi-6"
+      (_, _) -> error "Unsupported FFI library configuration case"
+
 
 rtsPackageArgs :: Args
 rtsPackageArgs = package rts ? do



More information about the ghc-commits mailing list