summaryrefslogtreecommitdiff
path: root/hadrian/src/Settings/Builders/Hsc2Hs.hs
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2018-10-23 14:20:13 -0400
committerBen Gamari <ben@smart-cactus.org>2018-10-23 14:20:13 -0400
commit94756201349685a34c4495addd3484fdfcc8b498 (patch)
treefd4a9cee20d3c2b79f56ded7e02fb0c01b26b6c9 /hadrian/src/Settings/Builders/Hsc2Hs.hs
parent575b35f4cdc18045bccd42d341d6f25d95c0696c (diff)
parent45f3bff7016a2a0cd9a5455a882ced984655e90b (diff)
downloadhaskell-94756201349685a34c4495addd3484fdfcc8b498.tar.gz
Add 'hadrian/' from commit '45f3bff7016a2a0cd9a5455a882ced984655e90b'
git-subtree-dir: hadrian git-subtree-mainline: 575b35f4cdc18045bccd42d341d6f25d95c0696c git-subtree-split: 45f3bff7016a2a0cd9a5455a882ced984655e90b
Diffstat (limited to 'hadrian/src/Settings/Builders/Hsc2Hs.hs')
-rw-r--r--hadrian/src/Settings/Builders/Hsc2Hs.hs58
1 files changed, 58 insertions, 0 deletions
diff --git a/hadrian/src/Settings/Builders/Hsc2Hs.hs b/hadrian/src/Settings/Builders/Hsc2Hs.hs
new file mode 100644
index 0000000000..0d5363d413
--- /dev/null
+++ b/hadrian/src/Settings/Builders/Hsc2Hs.hs
@@ -0,0 +1,58 @@
+module Settings.Builders.Hsc2Hs (hsc2hsBuilderArgs) where
+
+import Hadrian.Haskell.Cabal.Type
+
+import Builder
+import Packages
+import Settings.Builders.Common
+
+hsc2hsBuilderArgs :: Args
+hsc2hsBuilderArgs = builder Hsc2Hs ? do
+ stage <- getStage
+ ccPath <- getBuilderPath $ Cc CompileC stage
+ gmpDir <- getSetting GmpIncludeDir
+ top <- expr topDirectory
+ hArch <- getSetting HostArch
+ hOs <- getSetting HostOs
+ tArch <- getSetting TargetArch
+ tOs <- getSetting TargetOs
+ version <- if stage == Stage0
+ then expr ghcCanonVersion
+ else getSetting ProjectVersionInt
+ tmpl <- (top -/-) <$> expr (templateHscPath Stage0)
+ mconcat [ arg $ "--cc=" ++ ccPath
+ , arg $ "--ld=" ++ ccPath
+ , notM windowsHost ? notM (flag CrossCompiling) ? arg "--cross-safe"
+ , pure $ map ("-I" ++) (words gmpDir)
+ , map ("--cflag=" ++) <$> getCFlags
+ , map ("--lflag=" ++) <$> getLFlags
+ , notStage0 ? flag CrossCompiling ? arg "--cross-compile"
+ , stage0 ? arg ("--cflag=-D" ++ hArch ++ "_HOST_ARCH=1")
+ , stage0 ? arg ("--cflag=-D" ++ hOs ++ "_HOST_OS=1" )
+ , notStage0 ? arg ("--cflag=-D" ++ tArch ++ "_HOST_ARCH=1")
+ , notStage0 ? arg ("--cflag=-D" ++ tOs ++ "_HOST_OS=1" )
+ , arg $ "--cflag=-D__GLASGOW_HASKELL__=" ++ version
+ , arg $ "--template=" ++ tmpl
+ , arg =<< getInput
+ , arg "-o", arg =<< getOutput ]
+
+getCFlags :: Expr [String]
+getCFlags = do
+ context <- getContext
+ autogen <- expr $ autogenPath context
+ mconcat [ remove ["-O"] (cArgs <> getStagedSettingList ConfCcArgs)
+ , getStagedSettingList ConfCppArgs
+ , cIncludeArgs
+ , getContextData ccOpts
+ -- we might be able to leave out cppOpts, to be investigated.
+ , getContextData cppOpts
+ , getContextData depCcOpts
+ , cWarnings
+ , arg "-include", arg $ autogen -/- "cabal_macros.h" ]
+
+getLFlags :: Expr [String]
+getLFlags =
+ mconcat [ getStagedSettingList ConfGccLinkerArgs
+ , ldArgs
+ , getContextData ldOpts
+ , getContextData depLdOpts ]