Commit 062952ca authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Split Targets.hs and Settings.hs into multiple logically separate files.

parent 2f70955b
{-# LANGUAGE NoImplicitPrelude, FlexibleInstances #-}
module Expression (
module Control.Monad.Reader,
module Data.Monoid,
Expr, DiffExpr, fromDiff,
Predicate,
Settings, Ways, Packages,
......@@ -16,6 +17,7 @@ import Base hiding (arg, args, Args, TargetDir)
import Ways
import Oracles
import Package
import Data.Monoid
import Control.Monad.Reader
data Environment = Environment
......
......@@ -7,10 +7,10 @@ module Rules (
import Base hiding (arg, args, Args)
import Control.Monad
import Targets
import Settings
import Package
import Expression
import Rules.Package
import Settings.Packages
-- generateTargets needs package-data.mk files of all target packages
-- TODO: make interpret total
......@@ -28,6 +28,6 @@ generateTargets = action $
packageRules :: Rules ()
packageRules =
forM_ [Stage0, Stage1] $ \stage -> do
forM_ allPackages $ \pkg -> do
forM_ knownPackages $ \pkg -> do
let env = defaultEnvironment { getStage = stage, getPackage = pkg }
buildPackage env
......@@ -9,6 +9,8 @@ import Oracles.Flag (when)
import Oracles.Builder
import Targets
import Settings
import Settings.GhcPkg
import Settings.GhcCabal
import Util
-- Prepare a given 'packaga-data.mk' file for parsing by readConfigFile:
......
{-# LANGUAGE FlexibleInstances #-}
module Settings (
settings, ways, packages,
cabalSettings, ghcPkgSettings
settings
) where
import Base hiding (arg, args, Args)
import Base hiding (arg, args)
import Oracles.Builder
import Ways
import Util
import Targets
import Package
import Switches
import Oracles.Base
import Settings.Util
import Settings.GhcPkg
import Settings.GhcCabal
import UserSettings
import Expression hiding (when, liftIO)
settings :: Settings
settings = defaultSettings <> userSettings
ways :: Ways
ways = targetWays <> userWays
packages :: Packages
packages = targetPackages <> userPackages
defaultSettings :: Settings
defaultSettings = do
stage <- asks getStage
mconcat [ builder GhcCabal ? cabalSettings
, builder (GhcPkg stage) ? ghcPkgSettings ]
-- Builder settings
-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
librarySettings :: Settings
librarySettings = do
ways <- fromDiff Settings.ways
ghcInterpreter <- ghcWithInterpreter
dynamicPrograms <- dynamicGhcPrograms
append [ if vanilla `elem` ways
then "--enable-library-vanilla"
else "--disable-library-vanilla"
, if vanilla `elem` ways && ghcInterpreter && not dynamicPrograms
then "--enable-library-for-ghci"
else "--disable-library-for-ghci"
, if profiling `elem` ways
then "--enable-library-profiling"
else "--disable-library-profiling"
, if dynamic `elem` ways
then "--enable-shared"
else "--disable-shared" ]
configureSettings :: Settings
configureSettings = do
let conf key = appendSubD $ "--configure-option=" ++ key
stage <- asks getStage
mconcat
[ conf "CFLAGS" ccSettings
, conf "LDFLAGS" ldSettings
, conf "CPPFLAGS" cppSettings
, appendSubD "--gcc-options" $ ccSettings <> ldSettings
, conf "--with-iconv-includes" $ argConfig "iconv-include-dirs"
, conf "--with-iconv-libraries" $ argConfig "iconv-lib-dirs"
, conf "--with-gmp-includes" $ argConfig "gmp-include-dirs"
, conf "--with-gmp-libraries" $ argConfig "gmp-lib-dirs"
-- TODO: why TargetPlatformFull and not host?
, crossCompiling ? (conf "--host" $ argConfig "target-platform-full")
, conf "--with-cc" . argM . showArg $ Gcc stage ]
bootPackageDbSettings :: Settings
bootPackageDbSettings = do
sourcePath <- lift $ askConfig "ghc-source-path"
arg $ "--package-db=" ++ sourcePath </> "libraries/bootstrapping.conf"
dllSettings :: Settings
dllSettings = arg ""
with' :: Builder -> Settings
with' builder = appendM $ with builder
packageConstraints :: Settings
packageConstraints = do
pkgs <- fromDiff targetPackages
constraints <- lift $ forM pkgs $ \pkg -> do
let cabal = pkgPath pkg </> pkgCabal pkg
prefix = dropExtension (pkgCabal pkg) ++ " == "
need [cabal]
content <- lines <$> liftIO (readFile cabal)
let vs = filter (("ersion:" `isPrefixOf`) . drop 1) content
case vs of
[v] -> return $ prefix ++ dropWhile (not . isDigit) v
_ -> redError $ "Cannot determine package version in '"
++ cabal ++ "'."
args $ concatMap (\c -> ["--constraint", c]) $ constraints
cabalSettings :: Settings
cabalSettings = do
stage <- asks getStage
pkg <- asks getPackage
mconcat [ arg "configure"
, arg $ pkgPath pkg
, arg $ targetDirectory stage pkg
, dllSettings
, with' $ Ghc stage
, with' $ GhcPkg stage
, customConfigureSettings
, Expression.stage Stage0 ? bootPackageDbSettings
, librarySettings
, configKeyNonEmpty "hscolour" ? with' HsColour -- TODO: generalise?
, configureSettings
, Expression.stage Stage0 ? packageConstraints
, with' $ Gcc stage
, notStage Stage0 ? with' Ld
, with' Ar
, with' Alex
, with' Happy ] -- TODO: reorder with's
ghcPkgSettings :: Settings
ghcPkgSettings = do
stage <- asks getStage
pkg <- asks getPackage
let dir = pkgPath pkg </> targetDirectory stage pkg
mconcat [ arg "update"
, arg "--force"
, Expression.stage Stage0 ? bootPackageDbSettings
, arg $ dir </> "inplace-pkg-config" ]
ccSettings :: Settings
ccSettings = do
let gccGe46 = liftM not gccLt46
mconcat
[ package integerLibrary ? arg "-Ilibraries/integer-gmp2/gmp"
, builder GhcCabal ? argStagedConfig "conf-cc-args"
, validating ? mconcat
[ notBuilder GhcCabal ? arg "-Werror"
, arg "-Wall"
, gccIsClang ??
( arg "-Wno-unknown-pragmas" <>
gccGe46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
, gccGe46 ? arg "-Wno-error=inline" )]
]
ldSettings :: Settings
ldSettings = builder GhcCabal ? argStagedConfig "conf-gcc-linker-args"
cppSettings :: Settings
cppSettings = builder GhcCabal ? argStagedConfig "conf-cpp-args"
module Settings.GhcCabal (
cabalSettings, bootPackageDbSettings
) where
import Base hiding (arg, args)
import Oracles.Base
import Oracles.Builder
import Ways
import Util
import Package
import Targets
import Switches
import Expression hiding (when, liftIO)
import Settings.Ways
import Settings.Util
import Settings.Packages
cabalSettings :: Settings
cabalSettings = do
stage <- asks getStage
pkg <- asks getPackage
mconcat [ arg "configure"
, arg $ pkgPath pkg
, arg $ targetDirectory stage pkg
, dllSettings
, with' $ Ghc stage
, with' $ GhcPkg stage
, customConfigureSettings
, Expression.stage Stage0 ? bootPackageDbSettings
, librarySettings
, configKeyNonEmpty "hscolour" ? with' HsColour -- TODO: generalise?
, configureSettings
, Expression.stage Stage0 ? packageConstraints
, with' $ Gcc stage
, notStage Stage0 ? with' Ld
, with' Ar
, with' Alex
, with' Happy ] -- TODO: reorder with's
-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
librarySettings :: Settings
librarySettings = do
ways <- fromDiff Settings.Ways.ways
ghcInterpreter <- ghcWithInterpreter
dynamicPrograms <- dynamicGhcPrograms
append [ if vanilla `elem` ways
then "--enable-library-vanilla"
else "--disable-library-vanilla"
, if vanilla `elem` ways && ghcInterpreter && not dynamicPrograms
then "--enable-library-for-ghci"
else "--disable-library-for-ghci"
, if profiling `elem` ways
then "--enable-library-profiling"
else "--disable-library-profiling"
, if dynamic `elem` ways
then "--enable-shared"
else "--disable-shared" ]
configureSettings :: Settings
configureSettings = do
let conf key = appendSubD $ "--configure-option=" ++ key
stage <- asks getStage
mconcat
[ conf "CFLAGS" ccSettings
, conf "LDFLAGS" ldSettings
, conf "CPPFLAGS" cppSettings
, appendSubD "--gcc-options" $ ccSettings <> ldSettings
, conf "--with-iconv-includes" $ argConfig "iconv-include-dirs"
, conf "--with-iconv-libraries" $ argConfig "iconv-lib-dirs"
, conf "--with-gmp-includes" $ argConfig "gmp-include-dirs"
, conf "--with-gmp-libraries" $ argConfig "gmp-lib-dirs"
-- TODO: why TargetPlatformFull and not host?
, crossCompiling ? (conf "--host" $ argConfig "target-platform-full")
, conf "--with-cc" . argM . showArg $ Gcc stage ]
bootPackageDbSettings :: Settings
bootPackageDbSettings = do
sourcePath <- lift $ askConfig "ghc-source-path"
arg $ "--package-db=" ++ sourcePath </> "libraries/bootstrapping.conf"
dllSettings :: Settings
dllSettings = arg ""
with' :: Builder -> Settings
with' builder = appendM $ with builder
packageConstraints :: Settings
packageConstraints = do
pkgs <- fromDiff packages
constraints <- lift $ forM pkgs $ \pkg -> do
let cabal = pkgPath pkg </> pkgCabal pkg
prefix = dropExtension (pkgCabal pkg) ++ " == "
need [cabal]
content <- lines <$> liftIO (readFile cabal)
let vs = filter (("ersion:" `isPrefixOf`) . drop 1) content
case vs of
[v] -> return $ prefix ++ dropWhile (not . isDigit) v
_ -> redError $ "Cannot determine package version in '"
++ cabal ++ "'."
args $ concatMap (\c -> ["--constraint", c]) $ constraints
ccSettings :: Settings
ccSettings = do
let gccGe46 = liftM not gccLt46
mconcat
[ package integerLibrary ? arg "-Ilibraries/integer-gmp2/gmp"
, builder GhcCabal ? argStagedConfig "conf-cc-args"
, validating ? mconcat
[ notBuilder GhcCabal ? arg "-Werror"
, arg "-Wall"
, gccIsClang ??
( arg "-Wno-unknown-pragmas" <>
gccGe46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
, gccGe46 ? arg "-Wno-error=inline" )]
]
ldSettings :: Settings
ldSettings = builder GhcCabal ? argStagedConfig "conf-gcc-linker-args"
cppSettings :: Settings
cppSettings = builder GhcCabal ? argStagedConfig "conf-cpp-args"
module Settings.GhcPkg (
ghcPkgSettings
) where
import Base hiding (arg, args)
import Package
import Targets
import Expression hiding (when, liftIO)
import Settings.Util
import Settings.GhcCabal
ghcPkgSettings :: Settings
ghcPkgSettings = do
stg <- asks getStage
pkg <- asks getPackage
let dir = pkgPath pkg </> targetDirectory stg pkg
mconcat [ arg "update"
, arg "--force"
, stage Stage0 ? bootPackageDbSettings
, arg $ dir </> "inplace-pkg-config" ]
module Settings.Packages (
packages
) where
import Base
import Targets
import Switches
import Expression
import UserSettings
-- Combining default list of packages with user modifications
packages :: Packages
packages = defaultPackages <> userPackages
-- These are the packages we build by default
defaultPackages :: Packages
defaultPackages = mconcat
[ stage Stage0 ? packagesStage0
, stage Stage1 ? packagesStage1 ]
packagesStage0 :: Packages
packagesStage0 = mconcat
[ append [binPackageDb, binary, cabal, compiler, hoopl, hpc, transformers]
, notWindowsHost ? notTargetOs "ios" ? append [terminfo] ]
packagesStage1 :: Packages
packagesStage1 = mconcat
[ append [ array, base, bytestring, containers, deepseq, directory
, filepath, ghcPrim, haskeline, integerLibrary, parallel
, pretty, primitive, process, stm, templateHaskell, time ]
, windowsHost ? append [win32]
, notWindowsHost ? append [unix]
, buildHaddock ? append [xhtml] ]
module Settings.Ways (
ways
) where
import Base
import Ways hiding (defaultWays)
import Switches
import Expression
import UserSettings
-- Combining default ways with user modifications
ways :: Ways
ways = defaultWays <> userWays
-- These are default ways
defaultWays :: Ways
defaultWays = mconcat
[ append [vanilla] -- always build vanilla
, notStage Stage0 ? append [profiling]
, platformSupportsSharedLibs ? append [dynamic] ]
module Targets (
targetWays, targetPackages, targetDirectory,
allPackages,
targetDirectory,
knownPackages,
customConfigureSettings,
array, base, binPackageDb, binary, bytestring, cabal, compiler, containers,
deepseq, directory, filepath, ghcPrim, haskeline, hoopl, hpc,
......@@ -8,39 +8,11 @@ module Targets (
terminfo, time, transformers, unix, win32, xhtml
) where
import Ways hiding (parallel)
import Base hiding (arg, args, Args, TargetDir)
import Base hiding (arg, args)
import Package
import Switches
import Expression
-- These are the packages we build
targetPackages :: Packages
targetPackages = mconcat
[ stage Stage0 ? packagesStage0
, stage Stage1 ? packagesStage1 ]
packagesStage0 :: Packages
packagesStage0 = mconcat
[ append [binPackageDb, binary, cabal, compiler, hoopl, hpc, transformers]
, notWindowsHost ? notTargetOs "ios" ? append [terminfo] ]
packagesStage1 :: Packages
packagesStage1 = mconcat
[ append [ array, base, bytestring, containers, deepseq, directory
, filepath, ghcPrim, haskeline, integerLibrary, parallel
, pretty, primitive, process, stm, templateHaskell, time ]
, windowsHost ? append [win32]
, notWindowsHost ? append [unix]
, buildHaddock ? append [xhtml] ]
-- Packages will be build these ways
targetWays :: Ways
targetWays = mconcat
[ append [vanilla] -- always build vanilla
, notStage Stage0 ? append [profiling]
, platformSupportsSharedLibs ? append [dynamic] ]
-- Build results will be placed into a target directory with the following
-- typical structure:
-- * build/ : contains compiled object code
......@@ -52,14 +24,19 @@ targetDirectory stage package
| stage == Stage0 = "dist-boot"
| otherwise = "dist-install"
-- Package definitions
allPackages :: [Package]
allPackages =
-- These are all packages we know about. Build rules will be generated for
-- all of them. However, not all of these packages will be built. For example,
-- package 'win32' is built only on Windows.
-- Settings/Packages.hs defines default conditions for building each package,
-- which can be overridden in UserSettings.hs.
knownPackages :: [Package]
knownPackages =
[ array, base, binPackageDb, binary, bytestring, cabal, compiler
, containers, deepseq, directory, filepath, ghcPrim, haskeline
, hoopl, hpc, integerLibrary, parallel, pretty, primitive, process
, stm, templateHaskell, terminfo, time, transformers, unix, win32, xhtml ]
-- Package definitions
array = library "array"
base = library "base"
binPackageDb = library "bin-package-db"
......
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