Commit 8ba58271 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

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

parent 7ca8be77
......@@ -72,6 +72,10 @@ executable ghc-shake
, Settings.Packages
, Settings.Packages.Compiler
, Settings.Packages.Directory
, Settings.Packages.Ghc
, Settings.Packages.GhcCabal
, Settings.Packages.Hp2ps
, Settings.Packages.RunGhc
, Settings.TargetDirectory
, Settings.User
, Settings.Ways
......
......@@ -18,6 +18,10 @@ import Settings.Builders.HsCpp
import Settings.Builders.Ld
import Settings.Packages.Compiler
import Settings.Packages.Directory
import Settings.Packages.Ghc
import Settings.Packages.GhcCabal
import Settings.Packages.Hp2ps
import Settings.Packages.RunGhc
import Settings.User
getArgs :: Expr [String]
......@@ -51,5 +55,9 @@ defaultBuilderArgs = mconcat
defaultPackageArgs :: Args
defaultPackageArgs = mconcat
[ compilerArgs
, directoryArgs ]
[ compilerPackageArgs
, directoryPackageArgs
, ghcPackageArgs
, ghcCabalPackageArgs
, hp2psPackageArgs
, runGhcPackageArgs ]
......@@ -4,7 +4,6 @@ import Expression
import Predicates (builder, file)
-- Stdin/stdout are handled in a special way. See Rules/Actions.hs.
-- TODO: Do we want to keep "--usage"? It seems to be unused.
genPrimopCodeArgs :: Args
genPrimopCodeArgs = builder GenPrimopCode ? mconcat
[ file "//PrimopWrappers.hs" ? arg "--make-haskell-wrappers"
......
......@@ -3,7 +3,6 @@ module Settings.Builders.Ghc (ghcArgs, ghcMArgs, commonGhcArgs) where
import Base
import Expression
import Oracles
import GHC
import Predicates hiding (way, stage)
import Settings
import Settings.Builders.GhcCabal (bootPackageDbArgs)
......@@ -22,20 +21,14 @@ ghcArgs = stagedBuilder Ghc ? do
let buildObj = ("//*." ++ osuf way) ?== output || ("//*." ++ obootsuf way) ?== output
libs <- getPkgDataList DepExtraLibs
libDirs <- getPkgDataList DepLibDirs
version <- getSetting ProjectVersion
mconcat [ commonGhcArgs
, ghcCabalBootArgs
, arg "-H32m"
, stage0 ? arg "-O"
, notStage0 ? arg "-O2"
, arg "-Wall"
, arg "-fwarn-tabs"
, isLibrary pkg ? splitObjects ? arg "-split-objs"
, package ghc ? arg "-no-hs-main" -- TODO: simplify
, package hp2ps ? arg "-no-hs-main"
, (pkg /= ghcCabal) ? not buildObj ? arg "-no-auto-link-packages"
, package runghc ? file "//Main.o" ?
append ["-cpp", "-DVERSION=\"" ++ version ++ "\""]
, not buildObj ? arg "-no-auto-link-packages"
, not buildObj ? append [ "-optl-l" ++ lib | lib <- libs ]
, not buildObj ? append [ "-optl-L" ++ dir | dir <- libDirs ]
, buildObj ? arg "-c"
......@@ -98,8 +91,7 @@ packageGhcArgs = do
compId <- getPkgData ComponentId
pkgDepIds <- getPkgDataList DepIds
mconcat
[ not (pkg == hp2ps || pkg == ghcCabal && stage == Stage0) ?
arg "-hide-all-packages"
[ arg "-hide-all-packages"
, arg "-no-user-package-db"
, bootPackageDbArgs
, isLibrary pkg ?
......@@ -111,7 +103,6 @@ packageGhcArgs = do
-- TODO: Improve handling of "cabal_macros.h"
includeGhcArgs :: Args
includeGhcArgs = do
stage <- getStage
pkg <- getPackage
path <- getTargetPath
srcDirs <- getPkgDataList SrcDirs
......@@ -122,26 +113,8 @@ includeGhcArgs = do
, arg $ "-i" ++ autogenPath
, append [ "-i" ++ pkgPath pkg -/- dir | dir <- srcDirs ]
, cIncludeArgs
, (pkg == compiler || pkg == ghc) ?
arg ("-I" ++ pkgPath compiler -/- "stage" ++ show (fromEnum stage))
, not (pkg == hp2ps || pkg == ghcCabal && stage == Stage0) ?
append [ "-optP-include"
, "-optP" ++ autogenPath -/- "cabal_macros.h" ] ]
-- Boostrapping ghcCabal
-- TODO: do we need -DCABAL_VERSION=$(CABAL_VERSION)?
ghcCabalBootArgs :: Args
ghcCabalBootArgs = package ghcCabal ? stage0 ? mconcat
[ arg "--make"
, arg "-DBOOTSTRAPPING"
, arg "-DMIN_VERSION_binary_0_8_0"
, arg "-DGENERICS"
, arg "-optP-include"
, arg $ "-optP" ++ pkgPath ghcCabal -/- "cabal_macros_boot.h"
, arg "-ilibraries/Cabal/Cabal"
, arg "-ilibraries/binary/src"
, arg "-ilibraries/filepath"
, arg "-ilibraries/hpc" ]
, arg "-optP-include"
, arg $ "-optP" ++ autogenPath -/- "cabal_macros.h" ]
-- # Options for passing to plain ld
-- $1_$2_$3_ALL_LD_OPTS = \
......
......@@ -89,8 +89,7 @@ bootPackageDbArgs :: Args
bootPackageDbArgs = stage0 ? do
path <- getSetting GhcSourcePath
lift $ need [bootstrappingConfInitialised]
isGhc <- stagedBuilder Ghc ||^ stagedBuilder GhcM
let prefix = if isGhc then "-package-db " else "--package-db="
prefix <- ifM builderGhc (return "-package-db ") (return "--package-db=")
arg $ prefix ++ path -/- bootstrappingConf
packageConstraints :: Args
......
......@@ -11,7 +11,7 @@ hsCppArgs = builder HsCpp ? do
mconcat [ append =<< getSettingList HsCppArgs
, arg "-P"
, cppArgs
, arg $ "-Icompiler/stage" ++ show (fromEnum stage)
, arg $ "-Icompiler/" ++ stageString stage
, arg "-x"
, arg "c"
, arg =<< getInput ]
module Settings.Packages.Compiler (compilerArgs) where
module Settings.Packages.Compiler (compilerPackageArgs) where
import Base
import Expression
import GHC (compiler)
import Predicates (builder, package)
import Predicates (builder, builderGhc, package)
compilerArgs :: Args
compilerArgs = package compiler ?
mconcat [ builder Alex ? arg "--latin1" ]
compilerPackageArgs :: Args
compilerPackageArgs = package compiler ? do
stage <- getStage
mconcat [ builder Alex ? arg "--latin1"
, builderGhc ? arg ("-I" ++ pkgPath compiler -/- stageString stage) ]
module Settings.Packages.Directory (directoryArgs) where
module Settings.Packages.Directory (directoryPackageArgs) where
import Expression
import GHC (directory)
......@@ -8,6 +8,6 @@ import Predicates (stagedBuilder, package)
-- effectively empty. I presume it was expected that GHC will be used for
-- compiling all C files, but I don't know why. It seems that directory.c is the
-- only file which requires special treatment when using GCC.
directoryArgs :: Args
directoryArgs = package directory ?
directoryPackageArgs :: Args
directoryPackageArgs = package directory ?
stagedBuilder Gcc ? arg "-D__GLASGOW_HASKELL__"
module Settings.Packages.Ghc (ghcPackageArgs) where
import Base
import Expression
import GHC (ghc, compiler)
import Predicates (builderGhc, package)
ghcPackageArgs :: Args
ghcPackageArgs = package ghc ? do
stage <- getStage
mconcat [ builderGhc ?
mconcat [ arg ("-I" ++ pkgPath compiler -/- stageString stage)
, arg "-no-hs-main" ] ]
module Settings.Packages.GhcCabal (ghcCabalPackageArgs) where
import Base
import Expression
import GHC (ghcCabal)
import Predicates (builderGhc, package, stage0)
import Settings
ghcCabalPackageArgs :: Args
ghcCabalPackageArgs = package ghcCabal ? mconcat
[ builderGhc ?
mconcat [ ghcCabalBootArgs
, remove ["-no-auto-link-packages"] ] ]
-- Boostrapping ghcCabal
-- TODO: do we need -DCABAL_VERSION=$(CABAL_VERSION)?
ghcCabalBootArgs :: Args
ghcCabalBootArgs = stage0 ? do
path <- getTargetPath
let cabalMacros = path -/- "build/autogen/cabal_macros.h"
cabalMacrosBoot = pkgPath ghcCabal -/- "cabal_macros_boot.h"
mconcat
[ remove ["-hide-all-packages"]
, removePair "-optP-include" $ "-optP" ++ cabalMacros
, arg "--make"
, arg "-DBOOTSTRAPPING"
, arg "-DMIN_VERSION_binary_0_8_0"
, arg "-DGENERICS"
, arg "-optP-include"
, arg $ "-optP" ++ cabalMacrosBoot
, arg "-ilibraries/Cabal/Cabal"
, arg "-ilibraries/binary/src"
, arg "-ilibraries/filepath"
, arg "-ilibraries/hpc" ]
module Settings.Packages.Hp2ps (hp2psPackageArgs) where
import Base
import Expression
import GHC (hp2ps)
import Predicates (builderGhc, package)
import Settings
hp2psPackageArgs :: Args
hp2psPackageArgs = package hp2ps ? do
path <- getTargetPath
let cabalMacros = path -/- "build/autogen/cabal_macros.h"
mconcat [ builderGhc ?
mconcat [ arg "-no-hs-main"
, remove ["-hide-all-packages"]
, removePair "-optP-include" $ "-optP" ++ cabalMacros ] ]
module Settings.Packages.RunGhc (runGhcPackageArgs) where
import Expression
import GHC (runGhc)
import Oracles.Config.Setting
import Predicates (builderGhc, file, package)
runGhcPackageArgs :: Args
runGhcPackageArgs = package runGhc ? do
version <- getSetting ProjectVersion
mconcat [ builderGhc ?
file "//Main.o" ?
append ["-cpp", "-DVERSION=\"" ++ version ++ "\""] ]
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