Commit 7cf7210e authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Decompose Settings/Builders/GhcCabal.hs (see #60).

parent 109a6f84
......@@ -60,6 +60,7 @@ executable ghc-shake
, Settings.Builders.Alex
, Settings.Builders.Ar
, Settings.Builders.Common
, Settings.Builders.DeriveConstants
, Settings.Builders.Gcc
, Settings.Builders.GenPrimopCode
, Settings.Builders.Ghc
......@@ -71,11 +72,15 @@ executable ghc-shake
, Settings.Builders.HsCpp
, Settings.Builders.Ld
, Settings.Packages
, Settings.Packages.Base
, Settings.Packages.Compiler
, Settings.Packages.Directory
, Settings.Packages.Ghc
, Settings.Packages.GhcCabal
, Settings.Packages.GhcPrim
, Settings.Packages.Haddock
, Settings.Packages.Hp2ps
, Settings.Packages.IntegerGmp
, Settings.Packages.RunGhc
, Settings.TargetDirectory
, Settings.User
......
......@@ -16,11 +16,15 @@ import Settings.Builders.Happy
import Settings.Builders.Hsc2Hs
import Settings.Builders.HsCpp
import Settings.Builders.Ld
import Settings.Packages.Base
import Settings.Packages.Compiler
import Settings.Packages.Directory
import Settings.Packages.Ghc
import Settings.Packages.GhcCabal
import Settings.Packages.GhcPrim
import Settings.Packages.Haddock
import Settings.Packages.Hp2ps
import Settings.Packages.IntegerGmp
import Settings.Packages.RunGhc
import Settings.User
......@@ -37,13 +41,12 @@ defaultBuilderArgs :: Args
defaultBuilderArgs = mconcat
[ alexArgs
, arArgs
, cabalArgs
, customPackageArgs
, deriveConstantsArgs
, gccArgs
, gccMArgs
, genPrimopCodeArgs
, ghcArgs
, ghcCabalArgs
, ghcCabalHsColourArgs
, ghcMArgs
, ghcPkgArgs
......@@ -55,9 +58,13 @@ defaultBuilderArgs = mconcat
defaultPackageArgs :: Args
defaultPackageArgs = mconcat
[ compilerPackageArgs
[ basePackageArgs
, compilerPackageArgs
, directoryPackageArgs
, ghcPackageArgs
, ghcCabalPackageArgs
, ghcPrimPackageArgs
, haddockPackageArgs
, hp2psPackageArgs
, integerGmpPackageArgs
, runGhcPackageArgs ]
module Settings.Builders.Common (includesArgs, cIncludeArgs) where
module Settings.Builders.Common (
includesArgs, cIncludeArgs, cArgs, cWarnings,
argSetting, argSettingList, argStagedBuilderPath, argStagedSettingList
) where
import Base
import Expression
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.PackageData
import Settings
......@@ -22,3 +27,32 @@ cIncludeArgs = do
, arg $ "-I" ++ buildPath -/- "autogen"
, append [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
, append [ "-I" ++ dir | dir <- depDirs ] ]
-- TODO: put all validating options together in one file
cArgs :: Args
cArgs = validating ? cWarnings
-- TODO: should be in a different file
cWarnings :: Args
cWarnings = do
let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
mconcat [ turnWarningsIntoErrors ? arg "-Werror"
, arg "-Wall"
, flag GccIsClang ? arg "-Wno-unknown-pragmas"
, gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
, gccGe46 ? arg "-Wno-error=inline" ]
argM :: Action String -> Args
argM = (arg =<<) . lift
argSetting :: Setting -> Args
argSetting = argM . setting
argSettingList :: SettingList -> Args
argSettingList = (append =<<) . lift . settingList
argStagedSettingList :: (Stage -> SettingList) -> Args
argStagedSettingList ss = (argSettingList . ss) =<< getStage
argStagedBuilderPath :: (Stage -> Builder) -> Args
argStagedBuilderPath sb = (argM . builderPath . sb) =<< getStage
......@@ -8,7 +8,6 @@ import Oracles.Config.Flag
import Oracles.Config.Setting
import Predicates (builder, file)
import Settings.Builders.Common
import Settings.Builders.GhcCabal
derivedConstantsPath :: FilePath
derivedConstantsPath = "includes/dist-derivedconstants/header"
......@@ -30,14 +29,14 @@ deriveConstantsArgs = builder DeriveConstants ? do
, arg "--nm-program", arg =<< getBuilderPath Nm
, specified Objdump ? mconcat [ arg "--objdump-program"
, arg =<< getBuilderPath Objdump ]
, arg "--target-os", arg =<< getSetting TargetOs ]
, arg "--target-os", argSetting TargetOs ]
includeCcArgs :: Args
includeCcArgs = do
confCcArgs <- lift . settingList $ ConfCcArgs Stage1
mconcat
[ ccArgs
, ccWarnings
[ cArgs
, cWarnings
, append confCcArgs
, flag GhcUnregisterised ? arg "-DUSE_MINIINTERPRETER"
, includesArgs
......
module Settings.Builders.GhcCabal (
cabalArgs, ghcCabalHsColourArgs, bootPackageDbArgs,
customPackageArgs, ccArgs, cppArgs, ccWarnings, argStagedSettingList, needDll0
ghcCabalArgs, ghcCabalHsColourArgs, bootPackageDbArgs, cppArgs, needDll0
) where
import Base
......@@ -16,8 +15,8 @@ import Predicates hiding (stage)
import Settings
import Settings.Builders.Common
cabalArgs :: Args
cabalArgs = builder GhcCabal ? do
ghcCabalArgs :: Args
ghcCabalArgs = builder GhcCabal ? do
path <- getPackagePath
dir <- getTargetDirectory
mconcat [ arg "configure"
......@@ -68,7 +67,7 @@ libraryArgs = do
configureArgs :: Args
configureArgs = do
let conf key = appendSubD $ "--configure-option=" ++ key
cFlags = mconcat [ ccArgs
cFlags = mconcat [ cArgs
, remove ["-Werror"]
, argStagedSettingList ConfCcArgs ]
ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
......@@ -97,81 +96,12 @@ packageConstraints = stage0 ? do
constraints <- lift . readFileLines $ bootPackageConstraints
append $ concat [ ["--constraint", c] | c <- constraints ]
-- TODO: should be in a different file
-- TODO: put all validating options together in one file
ccArgs :: Args
ccArgs = validating ? ccWarnings
-- TODO: should be in a different file
ccWarnings :: Args
ccWarnings = do
let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
mconcat [ turnWarningsIntoErrors ? arg "-Werror"
, arg "-Wall"
, flag GccIsClang ? arg "-Wno-unknown-pragmas"
, gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
, gccGe46 ? arg "-Wno-error=inline" ]
ldArgs :: Args
ldArgs = mempty
cppArgs :: Args
cppArgs = includesArgs
-- TODO: Is this needed?
-- ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
-- libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
-- endif
-- TODO: move this somewhere
customPackageArgs :: Args
customPackageArgs = do
stage <- getStage
rtsWays <- getRtsWays
mconcat
[ package integerGmp ?
mconcat [ windowsHost ? builder GhcCabal ?
arg "--configure-option=--with-intree-gmp"
, appendCcArgs ["-I" ++ pkgPath integerGmp -/- "gmp"] ]
, package base ?
builder GhcCabal ?
arg ("--flags=" ++ takeFileName (pkgPath integerLibrary))
, package ghcPrim ?
builder GhcCabal ? arg "--flag=include-ghc-prim"
, package compiler ?
builder GhcCabal ?
mconcat [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
, arg "--disable-library-for-ghci"
, anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
, flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
, notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
, notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
, (threaded `elem` rtsWays) ?
notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
, ghcWithNativeCodeGen ? arg "--flags=ncg"
, ghcWithInterpreter ?
notStage0 ? arg "--flags=ghci"
, ghcWithInterpreter ?
ghcEnableTablesNextToCode ?
notM (flag GhcUnregisterised) ?
notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
, ghcWithInterpreter ?
ghciWithDebugger ?
notStage0 ? arg "--ghc-option=-DDEBUGGER"
, ghcProfiled ?
notStage0 ? arg "--ghc-pkg-option=--force" ]
, package ghc ?
builder GhcCabal ?
mconcat [ ghcWithInterpreter ?
notStage0 ? arg "--flags=ghci" ]
, package haddock ?
builder GhcCabal ? append ["--flag", "in-ghc-tree"] ]
withBuilderKey :: Builder -> String
withBuilderKey b = case b of
Ar -> "--with-ar="
......@@ -195,30 +125,6 @@ with b = specified b ? do
withStaged :: (Stage -> Builder) -> Args
withStaged sb = (with . sb) =<< getStage
argM :: Action String -> Args
argM = (arg =<<) . lift
argSetting :: Setting -> Args
argSetting = argM . setting
argSettingList :: SettingList -> Args
argSettingList = (append =<<) . lift . settingList
argStagedSettingList :: (Stage -> SettingList) -> Args
argStagedSettingList ss = (argSettingList . ss) =<< getStage
argStagedBuilderPath :: (Stage -> Builder) -> Args
argStagedBuilderPath sb = (argM . builderPath . sb) =<< getStage
-- Pass arguments to Gcc and corresponding lists of sub-arguments of GhcCabal
-- TODO: simplify
appendCcArgs :: [String] -> Args
appendCcArgs xs = do
mconcat [ stagedBuilder Gcc ? append xs
, stagedBuilder GccM ? append xs
, builder GhcCabal ? appendSub "--configure-option=CFLAGS" xs
, builder GhcCabal ? appendSub "--gcc-options" xs ]
needDll0 :: Stage -> Package -> Action Bool
needDll0 stage pkg = do
windows <- windowsHost
......
......@@ -8,8 +8,7 @@ import Expression
import Oracles
import Predicates (builder, stage0, notStage0)
import Settings
import Settings.Builders.GhcCabal hiding (cppArgs)
import Settings.Builders.Common (cIncludeArgs)
import Settings.Builders.Common
templateHsc :: FilePath
templateHsc = "inplace/lib/template-hsc.h"
......@@ -52,14 +51,14 @@ getCFlags = fromDiffExpr $ do
path <- getTargetPath
cppArgs <- getPkgDataList CppArgs
depCcArgs <- getPkgDataList DepCcArgs
mconcat [ ccArgs
mconcat [ cArgs
, argStagedSettingList ConfCcArgs
, remove ["-O"]
, argStagedSettingList ConfCppArgs
, cIncludeArgs
, append cppArgs
, append depCcArgs
, ccWarnings
, cWarnings
, arg "-include", arg $ path -/- "build/autogen/cabal_macros.h" ]
getLFlags :: Expr [String]
......
module Settings.Packages.Base (basePackageArgs) where
import Base
import Expression
import GHC (base)
import Predicates (builder, package)
import Settings
basePackageArgs :: Args
basePackageArgs = package base ?
builder GhcCabal ? arg ("--flags=" ++ takeFileName (pkgPath integerLibrary))
......@@ -3,11 +3,37 @@ module Settings.Packages.Compiler (compilerPackageArgs) where
import Base
import Expression
import GHC (compiler)
import Predicates (builder, builderGhc, package)
import Oracles.Config.Setting
import Oracles.Config.Flag
import Predicates (builder, builderGhc, package, notStage0)
import Settings
compilerPackageArgs :: Args
compilerPackageArgs = package compiler ? do
stage <- getStage
stage <- getStage
rtsWays <- getRtsWays
mconcat [ builder Alex ? arg "--latin1"
, builderGhc ? arg ("-I" ++ pkgPath compiler -/- stageString stage) ]
, builderGhc ? arg ("-I" ++ pkgPath compiler -/- stageString stage)
, builder GhcCabal ? mconcat
[ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
, arg "--disable-library-for-ghci"
, anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
, flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
, notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
, notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
, (threaded `elem` rtsWays) ?
notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
, ghcWithNativeCodeGen ? arg "--flags=ncg"
, ghcWithInterpreter ?
notStage0 ? arg "--flags=ghci"
, ghcWithInterpreter ?
ghcEnableTablesNextToCode ?
notM (flag GhcUnregisterised) ?
notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
, ghcWithInterpreter ?
ghciWithDebugger ?
notStage0 ? arg "--ghc-option=-DDEBUGGER"
, ghcProfiled ?
notStage0 ? arg "--ghc-pkg-option=--force" ] ]
......@@ -3,11 +3,15 @@ module Settings.Packages.Ghc (ghcPackageArgs) where
import Base
import Expression
import GHC (ghc, compiler)
import Predicates (builderGhc, package)
import Oracles.Config.Setting
import Predicates (builder, builderGhc, package, notStage0)
ghcPackageArgs :: Args
ghcPackageArgs = package ghc ? do
stage <- getStage
mconcat [ builderGhc ?
mconcat [ arg ("-I" ++ pkgPath compiler -/- stageString stage)
, arg "-no-hs-main" ] ]
mconcat [ builderGhc ? mconcat
[ arg ("-I" ++ pkgPath compiler -/- stageString stage)
, arg "-no-hs-main" ]
, builder GhcCabal ?
ghcWithInterpreter ? notStage0 ? arg "--flags=ghci" ]
module Settings.Packages.GhcPrim (ghcPrimPackageArgs) where
import Expression
import GHC (ghcPrim)
import Predicates (builder, package)
ghcPrimPackageArgs :: Args
ghcPrimPackageArgs = package ghcPrim ?
builder GhcCabal ? arg "--flag=include-ghc-prim"
module Settings.Packages.Haddock (haddockPackageArgs) where
import Expression
import GHC (haddock)
import Predicates (builder, package)
haddockPackageArgs :: Args
haddockPackageArgs = package haddock ?
builder GhcCabal ? append ["--flag", "in-ghc-tree"]
module Settings.Packages.IntegerGmp (integerGmpPackageArgs) where
import Base
import Expression
import GHC (integerGmp)
import Predicates (builder, package)
-- TODO: Is this needed?
-- ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
-- libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
-- endif
integerGmpPackageArgs :: Args
integerGmpPackageArgs = package integerGmp ?
builder GhcCabal ? mconcat
[ arg "--configure-option=--with-intree-gmp"
, appendSub "--configure-option=CFLAGS" includeGmp
, appendSub "--gcc-options" includeGmp ]
where
includeGmp = ["-I" ++ pkgPath integerGmp -/- "gmp"]
Supports Markdown
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