Commit f0781a7c authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Refactor Gmp and Libffi rules.

parent a88253a9
{-# LANGUAGE DeriveGeneric, LambdaCase #-}
module Builder (
CompilerMode (..), Builder (..),
builderPath, getBuilderPath, specified, needBuilder
builderPath, getBuilderPath, builderEnvironment, specified, needBuilder
) where
import Control.Monad.Trans.Reader
......@@ -134,6 +134,13 @@ builderPath builder = case builderProvenance builder of
getBuilderPath :: Builder -> ReaderT a Action FilePath
getBuilderPath = lift . builderPath
-- | Write a Builder's path into a given environment variable.
builderEnvironment :: String -> Builder -> Action CmdOption
builderEnvironment variable builder = do
needBuilder builder
path <- builderPath builder
return $ AddEnv variable path
specified :: Builder -> Action Bool
specified = fmap (not . null) . builderPath
......
module Rules.Gmp (gmpRules) where
import Base
import Builder
import Expression
import GHC
import Oracles.Config.Setting
......@@ -11,31 +12,22 @@ import Settings.Paths
import Target
gmpBase :: FilePath
gmpBase = "libraries/integer-gmp/gmp"
gmpBase = pkgPath integerGmp -/- "gmp"
gmpContext :: Context
gmpContext = vanillaContext Stage1 integerGmp
-- TODO: Noone needs this file, but we build it. Why?
gmpLibraryInTreeH :: FilePath
gmpLibraryInTreeH = gmpBuildPath -/- "include/gmp.h"
gmpLibraryFakeH :: FilePath
gmpLibraryFakeH = gmpBase -/- "ghc-gmp.h"
gmpPatches :: [FilePath]
gmpPatches = (gmpBase -/-) <$> ["gmpsrc.patch", "tarball/gmp-5.0.4.patch"]
-- TODO: See Libffi.hs about removing code duplication.
configureEnvironment :: Action [CmdOption]
configureEnvironment = do
sequence [ builderEnv "CC" $ Cc Compile Stage1
, builderEnv "AR" Ar
, builderEnv "NM" Nm ]
where
builderEnv var bld = do
needBuilder bld
path <- builderPath bld
return $ AddEnv var path
configureEnvironment = sequence [ builderEnvironment "CC" $ Cc Compile Stage1
, builderEnvironment "AR" Ar
, builderEnvironment "NM" Nm ]
-- TODO: we rebuild gmp every time.
gmpRules :: Rules ()
......@@ -53,7 +45,7 @@ gmpRules = do
then do
putBuild "| GMP library/framework detected and will be used"
createDirectory $ takeDirectory gmpLibraryH
copyFile gmpLibraryFakeH gmpLibraryH
copyFile (gmpBase -/- "ghc-gmp.h") gmpLibraryH
else do
putBuild "| No GMP library/framework detected; in tree GMP will be built"
......
module Rules.Libffi (rtsBuildPath, libffiRules, libffiDependencies) where
import Base
import Builder
import Expression
import GHC
import Oracles.Config.Flag
......@@ -43,19 +44,14 @@ configureEnvironment = do
[ cArgs
, argStagedSettingList ConfCcArgs ]
ldFlags <- interpretInContext libffiContext $ fromDiffExpr ldArgs
sequence [ builderEnv "CC" $ Cc Compile Stage1
, builderEnv "CXX" $ Cc Compile Stage1
, builderEnv "LD" Ld
, builderEnv "AR" Ar
, builderEnv "NM" Nm
, builderEnv "RANLIB" Ranlib
sequence [ builderEnvironment "CC" $ Cc Compile Stage1
, builderEnvironment "CXX" $ Cc Compile Stage1
, builderEnvironment "LD" Ld
, builderEnvironment "AR" Ar
, builderEnvironment "NM" Nm
, builderEnvironment "RANLIB" Ranlib
, return . AddEnv "CFLAGS" $ unwords cFlags ++ " -w"
, return . AddEnv "LDFLAGS" $ unwords ldFlags ++ " -w" ]
where
builderEnv var b = do
needBuilder b
path <- builderPath b
return $ AddEnv var path
-- TODO: remove code duplication (need sourcePath)
-- TODO: split into multiple rules
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment