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

Continue refactoring.

parent 2be9217d
......@@ -8,13 +8,13 @@ import Base hiding (arg, args, Args)
import Util
import Control.Monad
import Targets
import Settings
-- import Settings
import Package
import Expression.Base
import Expression
import Rules.Package
generateTargets :: Rules ()
generateTargets = action $
generateTargets = action $ do
forM_ [Stage0 ..] $ \stage -> do
pkgs <- evaluate $ project stage targetPackages
case linearise pkgs of
......@@ -28,7 +28,7 @@ generateTargets = action $
_ -> redError "Cannot determine target directory."
packageRules :: Rules ()
packageRules = do
packageRules =
forM_ [Stage0 ..] $ \stage -> do
forM_ (support $ simplify $ project stage targetPackages) $ \pkg -> do
let dirs = project (stage, pkg) targetDirectories
......
......@@ -6,11 +6,11 @@ module Rules.Data (
import qualified Ways
import Base hiding (arg, args, Args)
import Package
import Expression.Base
import Expression
import Oracles.Flag (when)
import Oracles.Builder
import Targets
import Switches
-- import Switches
import Util
librarySettings :: Ways -> Settings
......@@ -36,6 +36,7 @@ configureSettings =
, conf "CPPFLAGS" cppSettings
, argPrefix "--gcc-options=" $
argConcatSpace (ccSettings <|> ldSettings)
-- TODO: drop if empty
, conf "--with-iconv-includes" (argConfig "iconv-include-dirs")
, conf "--with-iconv-libraries" (argConfig "iconv-lib-dirs")
, conf "--with-gmp-includes" (argConfig "gmp-include-dirs")
......@@ -47,10 +48,9 @@ configureSettings =
bootPackageDbSettings :: Settings
bootPackageDbSettings =
stage Stage0 ?
argPrefix "--package-db="
(argConcatPath $ argConfig "ghc-source-path" |>
argPath "libraries/bootstrapping.conf")
argPrefix "--package-db="
(argConcatPath $ argConfig "ghc-source-path" |>
argPath "libraries/bootstrapping.conf")
dllSettings :: Settings
dllSettings = arg ""
......@@ -68,9 +68,9 @@ cabalSettings =
, customConfigureSettings
, stage Stage0 ? bootPackageDbSettings
, librarySettings targetWays
, configNonEmpty "hscolour" ? argWithBuilder HsColour -- TODO: more reuse
, configNonEmpty "hscolour" ? argWithBuilder HsColour -- TODO: generalise
, configureSettings
, argPackageConstraints (stage Stage0 ? targetPackages)
, stage Stage0 ? argPackageConstraints targetPackages
, argWithStagedBuilder Gcc
, notStage Stage0 ? argWithBuilder Ld
, argWithBuilder Ar
......@@ -165,6 +165,10 @@ run' builder settings = do
-- run (GhcPkg stage) $ ghcPkgArgs pkg todo
-- postProcessPackageData $ pathDist </> "package-data.mk"
buildSettings = + builder Gcc ? ccSettings
builder Gcc ? "-tricky-flag"
ccSettings :: Settings
ccSettings = msum
[ package integerLibrary ? argPath "-Ilibraries/integer-gmp2/gmp"
......@@ -175,7 +179,8 @@ ccSettings = msum
, gccIsClang ??
( arg "-Wno-unknown-pragmas" <|>
not gccLt46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
, not gccLt46 ? arg "-Wno-error=inline" )]]
, not gccLt46 ? arg "-Wno-error=inline" )]
]
ldSettings :: Settings
ldSettings = builder GhcCabal ? argStagedConfig "conf-gcc-linker-args"
......
......@@ -5,7 +5,7 @@ module Rules.Package (
import Base
import Package
import Rules.Data
import Expression.Base
import Expression
buildPackage :: Stage -> Package -> FilePath -> Ways -> Settings -> Rules ()
buildPackage = buildPackageData
......@@ -14,14 +14,3 @@ buildSettings :: Settings
buildSettings = msum
[ builder GhcCabal ? cabalSettings
, stagedBuilder GhcPkg ? ghcPkgSettings ]
packageSettings :: Settings
packageSettings = msum
[ args ["-hide-all-packages", "-no-user-package-db", "-include-pkg-deps"]
, stage Stage0 ?
(arg "-package-db" |> argPath "libraries/bootstrapping.conf")
, supportsPackageKey ? notStage Stage0 ??
( argPairs "-this-package-key" argPackageKey <|>
argPairs "-package-key" argPackageDepKeys
, argPairs "-package-name" argPackageKey <|>
argPairs "-package" argPackageDeps )]
{-# LANGUAGE NoImplicitPrelude #-}
module Switches (
buildHaddock, validating,
IntegerLibraryImpl (..), integerLibraryImpl,
supportsPackageKey, targetPlatforms, targetPlatform,
targetOss, targetOs, targetArchs, dynamicGhcPrograms, ghcWithInterpreter,
targetOss, targetOs, notTargetOs,
targetArchs, dynamicGhcPrograms, ghcWithInterpreter,
platformSupportsSharedLibs, crossCompiling,
gccIsClang, gccLt46, windowsHost
gccIsClang, gccLt46, windowsHost, notWindowsHost
) where
import Expression.Base
import Base
import Expression
-- User-defined switches
buildHaddock :: BuildPredicate
buildHaddock = true
buildHaddock :: Monad m => Predicate m
buildHaddock = return True
validating :: BuildPredicate
validating = false
validating :: Monad m => Predicate m
validating = return False
-- Support for multiple integer library implementations
data IntegerLibraryImpl = IntegerGmp | IntegerGmp2 | IntegerSimple
......@@ -25,54 +25,59 @@ integerLibraryImpl :: IntegerLibraryImpl
integerLibraryImpl = IntegerGmp2
-- Predicates based on configuration files
supportsPackageKey :: BuildPredicate
supportsPackageKey = configYes "supports-package-key"
supportsPackageKey :: Predicate Action
supportsPackageKey = configKeyYes "supports-package-key"
targetPlatforms :: [String] -> BuildPredicate
targetPlatforms = configValues "target-platform-full"
targetPlatforms :: [String] -> Predicate Action
targetPlatforms = configKeyValues "target-platform-full"
targetPlatform :: String -> BuildPredicate
targetPlatform :: String -> Predicate Action
targetPlatform s = targetPlatforms [s]
targetOss :: [String] -> BuildPredicate
targetOss = configValues "target-os"
targetOss :: [String] -> Predicate Action
targetOss = configKeyValues "target-os"
targetOs :: String -> BuildPredicate
targetOs :: String -> Predicate Action
targetOs s = targetOss [s]
targetArchs :: [String] -> BuildPredicate
targetArchs = configValues "target-arch"
notTargetOs :: String -> Predicate Action
notTargetOs = fmap not . targetOs
targetArchs :: [String] -> Predicate Action
targetArchs = configKeyValues "target-arch"
solarisBrokenShld :: BuildPredicate
solarisBrokenShld = configYes "solaris-broken-shld"
platformSupportsSharedLibs :: Predicate Action
platformSupportsSharedLibs = do
badPlatform <- targetPlatforms [ "powerpc-unknown-linux"
, "x86_64-unknown-mingw32"
, "i386-unknown-mingw32" ]
solaris <- targetPlatform "i386-unknown-solaris2"
solarisBroken <- configKeyYes "solaris-broken-shld"
return $ not (badPlatform || solaris && solarisBroken)
platformSupportsSharedLibs :: BuildPredicate
platformSupportsSharedLibs =
not (targetPlatforms [ "powerpc-unknown-linux"
, "x86_64-unknown-mingw32"
, "i386-unknown-mingw32" ]
||
solarisBrokenShld && targetPlatform "i386-unknown-solaris2")
dynamicGhcPrograms :: Predicate Action
dynamicGhcPrograms = configKeyYes "dynamic-ghc-programs"
dynamicGhcPrograms :: BuildPredicate
dynamicGhcPrograms = configYes "dynamic-ghc-programs"
ghcWithInterpreter :: Predicate Action
ghcWithInterpreter = do
goodOs <- targetOss [ "mingw32", "cygwin32", "linux", "solaris2"
, "freebsd", "dragonfly", "netbsd", "openbsd"
, "darwin", "kfreebsdgnu" ]
goodArch <- targetArchs [ "i386", "x86_64", "powerpc", "sparc"
, "sparc64", "arm" ]
return $ goodOs && goodArch
ghcWithInterpreter :: BuildPredicate
ghcWithInterpreter =
targetOss [ "mingw32", "cygwin32", "linux", "solaris2"
, "freebsd", "dragonfly", "netbsd", "openbsd"
, "darwin", "kfreebsdgnu" ]
&&
targetArchs ["i386", "x86_64", "powerpc", "sparc", "sparc64", "arm"]
crossCompiling :: Predicate Action
crossCompiling = configKeyYes "cross-compiling"
crossCompiling :: BuildPredicate
crossCompiling = configYes "cross-compiling"
gccIsClang :: Predicate Action
gccIsClang = configKeyYes "gcc-is-clang"
gccIsClang :: BuildPredicate
gccIsClang = configYes "gcc-is-clang"
gccLt46 :: Predicate Action
gccLt46 = configKeyYes "gcc-lt-46"
gccLt46 :: BuildPredicate
gccLt46 = configYes "gcc-lt-46"
windowsHost :: Predicate Action
windowsHost = configKeyValues "host-os-cpp" ["mingw32", "cygwin32"]
windowsHost :: BuildPredicate
windowsHost = configValues "host-os-cpp" ["mingw32", "cygwin32"]
notWindowsHost :: Predicate Action
notWindowsHost = fmap not windowsHost
{-# LANGUAGE NoImplicitPrelude #-}
module Targets (
targetWays, targetPackages, targetDirectories,
customConfigureSettings,
......@@ -9,48 +8,54 @@ module Targets (
) where
import qualified Ways
import Base hiding (arg, args, Args)
import Switches
import Base hiding (arg, args, Args, TargetDir)
import Package
import Expression.Base
import Switches
import Expression
import Expression.Settings
-- These are the packages we build
targetPackages :: Packages
targetPackages = msum
targetPackages :: Packages Action
targetPackages = mconcat
[ stage Stage0 ? packagesStage0
, stage Stage1 ? packagesStage1 ]
packagesStage0 :: Packages
packagesStage0 = msum
[ fromList [ binPackageDb, binary, cabal, hoopl, hpc, transformers ]
, not windowsHost ? not (targetOs "ios") ? return terminfo ]
packagesStage0 :: Packages Action
packagesStage0 = mconcat
[ return [ binPackageDb, binary, cabal, hoopl, hpc, transformers ]
, notWindowsHost ? notTargetOs "ios" ? return [terminfo] ]
packagesStage1 :: Packages
packagesStage1 = msum
packagesStage1 :: Packages Action
packagesStage1 = mconcat
[ packagesStage0
, fromList [ array, base, bytestring, containers, deepseq, directory
, filepath, ghcPrim, haskeline, integerLibrary, parallel
, pretty, primitive, process, stm, templateHaskell, time ]
, not windowsHost ? return unix
, windowsHost ? return win32
, buildHaddock ? return xhtml ]
, return [ array, base, bytestring, containers, deepseq, directory
, filepath, ghcPrim, haskeline, integerLibrary, parallel
, pretty, primitive, process, stm, templateHaskell, time ]
, notWindowsHost ? return [unix]
, windowsHost ? return [win32]
, buildHaddock ? return [xhtml] ]
-- Packages will be build these ways
targetWays :: Ways
targetWays = msum
[ return Ways.vanilla -- always build vanilla
, notStage Stage0 ? return Ways.profiling
, platformSupportsSharedLibs ? return Ways.dynamic ]
targetWays :: Ways Action
targetWays = mconcat
[ return [Ways.vanilla] -- always build vanilla
, notStage Stage0 ? return [Ways.profiling]
, platformSupportsSharedLibs ? return [Ways.dynamic] ]
-- Build results will be placed into a target directory with the following
-- typical structure:
-- * build/ : contains compiled object code
-- * doc/ : produced by haddock
-- * package-data.mk : contains output of ghc-cabal applied to pkgCabal
targetDirectories :: TargetDirs
targetDirectories =
stage Stage0 ?? ( return $ TargetDir "dist-boot"
, return $ TargetDir "dist-install")
targetDirectories :: Monad m => TargetDir m
targetDirectories = do
stage <- asks getStage
package <- asks getPackage
let targetDir
| package == compiler = "stage" ++ show (succ stage)
| stage == Stage0 = "dist-boot"
| otherwise = "dist-install"
return targetDir
-- Package definitions
array, base, binPackageDb, binary, bytestring, cabal, containers, deepseq,
......@@ -58,33 +63,34 @@ array, base, binPackageDb, binary, bytestring, cabal, containers, deepseq,
parallel, pretty, primitive, process, stm, templateHaskell, terminfo, time,
transformers, unix, win32, xhtml :: Package
array = library "array"
base = library "base"
binPackageDb = library "bin-package-db"
binary = library "binary"
bytestring = library "bytestring"
cabal = library "Cabal/Cabal" `setCabal` "Cabal.cabal"
containers = library "containers"
deepseq = library "deepseq"
directory = library "directory"
filepath = library "filepath"
ghcPrim = library "ghc-prim"
haskeline = library "haskeline"
hoopl = library "hoopl"
hpc = library "hpc"
integerLibrary = library integerLibraryName `setCabal` integerLibraryCabal
parallel = library "parallel"
pretty = library "pretty"
primitive = library "primitive"
process = library "process"
stm = library "stm"
templateHaskell = library "template-haskell"
terminfo = library "terminfo"
time = library "time"
transformers = library "transformers"
unix = library "unix"
win32 = library "Win32"
xhtml = library "xhtml"
array = library "array"
base = library "base"
binPackageDb = library "bin-package-db"
binary = library "binary"
bytestring = library "bytestring"
cabal = library "Cabal/Cabal" `setCabal` "Cabal.cabal"
compiler = topLevel "compiler" `setCabal` "ghc.cabal"
containers = library "containers"
deepseq = library "deepseq"
directory = library "directory"
filepath = library "filepath"
ghcPrim = library "ghc-prim"
haskeline = library "haskeline"
hoopl = library "hoopl"
hpc = library "hpc"
integerLibrary = library integerLibraryName `setCabal` integerLibraryCabal
parallel = library "parallel"
pretty = library "pretty"
primitive = library "primitive"
process = library "process"
stm = library "stm"
templateHaskell = library "template-haskell"
terminfo = library "terminfo"
time = library "time"
transformers = library "transformers"
unix = library "unix"
win32 = library "Win32"
xhtml = library "xhtml"
integerLibraryName :: String
integerLibraryName = case integerLibraryImpl of
......@@ -95,17 +101,17 @@ integerLibraryName = case integerLibraryImpl of
-- see Note [Cabal name weirdness]
integerLibraryCabal :: FilePath
integerLibraryCabal = case integerLibraryImpl of
IntegerGmp -> "integer-gmp.cabal"
IntegerGmp2 -> "integer-gmp.cabal" -- Indeed, why make life easier?
IntegerSimple -> "integer-simple.cabal"
IntegerGmp -> "integer-gmp.cabal"
IntegerGmp2 -> "integer-gmp.cabal" -- Indeed, why make life easier?
IntegerSimple -> "integer-simple.cabal"
-- Custom configure settings for packages
customConfigureSettings :: Settings
customConfigureSettings = msum
[ package base ? arg ("--flags=" ++ integerLibraryName)
, package ghcPrim ? arg "--flag=include-ghc-prim"
, package integerLibrary ? windowsHost ?
arg "--configure-option=--with-intree-gmp"
customConfigureSettings :: Settings Action
customConfigureSettings = mconcat
[ package base ? arg ("--flags=" ++ integerLibraryName)
, package ghcPrim ? arg "--flag=include-ghc-prim"
, package integerLibrary ?
windowsHost ? arg "--configure-option=--with-intree-gmp"
]
-- Note [Cabal name weirdness]
......
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