94dc93ea03c0aaba76b1571b7643fa88b1426da8
[ghc.git] / src / Settings / Builders / Hsc2Hs.hs
1 module Settings.Builders.Hsc2Hs (hsc2hsBuilderArgs) where
2
3 import Control.Monad.Extra
4 import Control.Monad.Trans.Class
5
6 import Base
7 import Expression
8 import Oracles.Config.Flag
9 import Oracles.Config.Setting
10 import Oracles.PackageData
11 import Predicates
12 import Settings
13 import Settings.Builders.Common
14
15 templateHsc :: FilePath
16 templateHsc = "inplace/lib/template-hsc.h"
17
18 hsc2hsBuilderArgs :: Args
19 hsc2hsBuilderArgs = builder Hsc2Hs ? do
20 stage <- getStage
21 ccPath <- getBuilderPath $ Cc Compile stage
22 gmpDir <- getSetting GmpIncludeDir
23 cFlags <- getCFlags
24 lFlags <- getLFlags
25 top <- getTopDirectory
26 hArch <- getSetting HostArch
27 hOs <- getSetting HostOs
28 tArch <- getSetting TargetArch
29 tOs <- getSetting TargetOs
30 version <- if stage == Stage0
31 then lift $ ghcCanonVersion
32 else getSetting ProjectVersionInt
33 lift $ need [templateHsc]
34 mconcat [ arg $ "--cc=" ++ ccPath
35 , arg $ "--ld=" ++ ccPath
36 , notM windowsHost ? arg "--cross-safe"
37 , append . map ("-I" ++) $ words gmpDir
38 , append $ map ("--cflag=" ++) cFlags
39 , append $ map ("--lflag=" ++) lFlags
40 , notStage0 ? crossCompiling ? arg "--cross-compile"
41 , stage0 ? arg ("--cflag=-D" ++ hArch ++ "_HOST_ARCH=1")
42 , stage0 ? arg ("--cflag=-D" ++ hOs ++ "_HOST_OS=1" )
43 , notStage0 ? arg ("--cflag=-D" ++ tArch ++ "_HOST_ARCH=1")
44 , notStage0 ? arg ("--cflag=-D" ++ tOs ++ "_HOST_OS=1" )
45 , arg ("--cflag=-D__GLASGOW_HASKELL__=" ++ version)
46 , arg $ "--template=" ++ top -/- templateHsc
47 , arg $ "-I" ++ top -/- "inplace/lib/include/"
48 , arg =<< getInput
49 , arg "-o", arg =<< getOutput ]
50
51 getCFlags :: Expr [String]
52 getCFlags = fromDiffExpr $ do
53 path <- getBuildPath
54 cppArgs <- getPkgDataList CppArgs
55 depCcArgs <- getPkgDataList DepCcArgs
56 mconcat [ cArgs
57 , argStagedSettingList ConfCcArgs
58 , remove ["-O"]
59 , argStagedSettingList ConfCppArgs
60 , cIncludeArgs
61 , append cppArgs
62 , append depCcArgs
63 , cWarnings
64 , arg "-include", arg $ path -/- "autogen/cabal_macros.h" ]
65
66 getLFlags :: Expr [String]
67 getLFlags = fromDiffExpr $ do
68 pkgLdArgs <- getPkgDataList LdArgs
69 libDirs <- getPkgDataList DepLibDirs
70 extraLibs <- getPkgDataList DepExtraLibs
71 depLdArgs <- getPkgDataList DepLdArgs
72 mconcat [ argStagedSettingList ConfGccLinkerArgs
73 , ldArgs
74 , append pkgLdArgs
75 , append $ [ "-L" ++ unifyPath dir | dir <- libDirs ]
76 , append $ [ "-l" ++ unifyPath dir | dir <- extraLibs ]
77 , append depLdArgs ]