Use Cabal directly in place of ghc-cabal + make build root configurable (#531)
[hadrian.git] / src / Settings / Builders / Hsc2Hs.hs
1 module Settings.Builders.Hsc2Hs (hsc2hsBuilderArgs) where
2
3 import Builder ()
4 import GHC (autogenPath)
5 import Hadrian.Builder (getBuilderPath)
6 import Hadrian.Haskell.Cabal.PackageData as PD
7 import Settings.Builders.Common
8
9 hsc2hsBuilderArgs :: Args
10 hsc2hsBuilderArgs = builder Hsc2Hs ? do
11 stage <- getStage
12 ccPath <- getBuilderPath $ Cc CompileC stage
13 gmpDir <- getSetting GmpIncludeDir
14 top <- expr topDirectory
15 hArch <- getSetting HostArch
16 hOs <- getSetting HostOs
17 tArch <- getSetting TargetArch
18 tOs <- getSetting TargetOs
19 version <- if stage == Stage0
20 then expr ghcCanonVersion
21 else getSetting ProjectVersionInt
22 tmpl <- (top -/-) <$> expr (templateHscPath Stage0)
23 mconcat [ arg $ "--cc=" ++ ccPath
24 , arg $ "--ld=" ++ ccPath
25 , notM windowsHost ? notM crossCompiling ? arg "--cross-safe"
26 , pure $ map ("-I" ++) (words gmpDir)
27 , map ("--cflag=" ++) <$> getCFlags
28 , map ("--lflag=" ++) <$> getLFlags
29 , notStage0 ? crossCompiling ? arg "--cross-compile"
30 , stage0 ? arg ("--cflag=-D" ++ hArch ++ "_HOST_ARCH=1")
31 , stage0 ? arg ("--cflag=-D" ++ hOs ++ "_HOST_OS=1" )
32 , notStage0 ? arg ("--cflag=-D" ++ tArch ++ "_HOST_ARCH=1")
33 , notStage0 ? arg ("--cflag=-D" ++ tOs ++ "_HOST_OS=1" )
34 , arg $ "--cflag=-D__GLASGOW_HASKELL__=" ++ version
35 , arg $ "--template=" ++ tmpl
36 , arg =<< getInput
37 , arg "-o", arg =<< getOutput ]
38
39 getCFlags :: Expr [String]
40 getCFlags = do
41 context <- getContext
42 autogen <- expr $ autogenPath context
43 mconcat [ remove ["-O"] (cArgs <> getStagedSettingList ConfCcArgs)
44 , getStagedSettingList ConfCppArgs
45 , cIncludeArgs
46 , getPackageData PD.ccOpts
47 -- we might be able to leave out cppOpts, to be investigated.
48 , getPackageData PD.cppOpts
49 , getPackageData PD.depCcOpts
50 , cWarnings
51 , arg "-include", arg $ autogen -/- "cabal_macros.h" ]
52
53 getLFlags :: Expr [String]
54 getLFlags =
55 mconcat [ getStagedSettingList ConfGccLinkerArgs
56 , ldArgs
57 , getPackageData PD.ldOpts
58 , getPackageData PD.depLdOpts ]