summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Angermann <moritz.angermann@gmail.com>2021-04-22 18:14:15 +0800
committerZubin <zubin.duggal@gmail.com>2021-10-12 06:43:25 +0000
commit26cb292d46ca22c3c2d19356ef9544916914e26d (patch)
tree35239abde15c4c062a23735fba3057ccd1ebf6bc
parent7e0e4b5a70e117ad7ed3e45ac6270f60b28448f7 (diff)
downloadhaskell-26cb292d46ca22c3c2d19356ef9544916914e26d.tar.gz
[hadrian] Properly build hsc2hs wrapper
(cherry picked from commit 50c3061db2d8f8a179519eba8c989f492dd5baa5)
-rw-r--r--hadrian/src/Rules/BinaryDist.hs41
1 files changed, 23 insertions, 18 deletions
diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs
index a527664b23..360992c563 100644
--- a/hadrian/src/Rules/BinaryDist.hs
+++ b/hadrian/src/Rules/BinaryDist.hs
@@ -218,8 +218,9 @@ bindistRules = do
top <- topDirectory
copyFile (top -/- "hadrian" -/- "bindist" -/- "Makefile") makefilePath
- root -/- "bindist" -/- "ghc-*" -/- "wrappers/*" %> \wrapperPath ->
- writeFile' wrapperPath $ wrapper (takeFileName wrapperPath)
+ root -/- "bindist" -/- "ghc-*" -/- "wrappers/*" %> \wrapperPath -> do
+ content <- wrapper (takeFileName wrapperPath)
+ writeFile' wrapperPath content
-- Copy various configure-related files needed for a working
-- './configure [...] && make install' workflow
@@ -266,7 +267,7 @@ pkgTarget pkg
| isLibrary pkg = pkgConfFile (vanillaContext Stage1 pkg)
| otherwise = programPath =<< programContext Stage1 pkg
-wrapper :: FilePath -> String
+wrapper :: FilePath -> Action String
wrapper "ghc" = ghcWrapper
wrapper "ghc-pkg" = ghcPkgWrapper
wrapper "ghci-script" = ghciScriptWrapper
@@ -277,23 +278,27 @@ wrapper _ = commonWrapper
-- | Wrapper scripts for different programs. Common is default wrapper.
-ghcWrapper :: String
-ghcWrapper = "exec \"$executablename\" -B\"$libdir\" ${1+\"$@\"}\n"
+ghcWrapper :: Action String
+ghcWrapper = pure $ "exec \"$executablename\" -B\"$libdir\" ${1+\"$@\"}\n"
-ghcPkgWrapper :: String
-ghcPkgWrapper = unlines
+ghcPkgWrapper :: Action String
+ghcPkgWrapper = pure $ unlines
[ "PKGCONF=\"$libdir/package.conf.d\""
, "exec \"$executablename\" --global-package-db \"$PKGCONF\" ${1+\"$@\"}" ]
-haddockWrapper :: String
-haddockWrapper = "exec \"$executablename\" -B\"$libdir\" -l\"$libdir\" ${1+\"$@\"}\n"
+haddockWrapper :: Action String
+haddockWrapper = pure $ "exec \"$executablename\" -B\"$libdir\" -l\"$libdir\" ${1+\"$@\"}\n"
-commonWrapper :: String
-commonWrapper = "exec \"$executablename\" ${1+\"$@\"}\n"
+commonWrapper :: Action String
+commonWrapper = pure $ "exec \"$executablename\" ${1+\"$@\"}\n"
-hsc2hsWrapper :: String
-hsc2hsWrapper = unlines
- [ "HSC2HS_EXTRA=\"--cflag=-fno-stack-protector --lflag=-fuse-ld=gold\""
+-- echo 'HSC2HS_EXTRA="$(addprefix --cflag=,$(CONF_CC_OPTS_STAGE1)) $(addprefix --lflag=,$(CONF_GCC_LINKER_OPTS_STAGE1))"' >> "$(WRAPPER)"
+hsc2hsWrapper :: Action String
+hsc2hsWrapper = do
+ ccArgs <- map ("--cflag=" <>) <$> settingList (ConfCcArgs Stage1)
+ ldFlags <- map ("--lflag=" <>) <$> settingList (ConfGccLinkerArgs Stage1)
+ return $ unlines
+ [ "HSC2HS_EXTRA=\"" <> unwords ccArgs <> unwords ldFlags <> "\""
, "tflag=\"--template=$libdir/template-hsc.h\""
, "Iflag=\"-I$includedir/\""
, "for arg do"
@@ -313,13 +318,13 @@ hsc2hsWrapper = unlines
, "done"
, "exec \"$executablename\" ${tflag:+\"$tflag\"} $HSC2HS_EXTRA ${1+\"$@\"} \"$Iflag\"" ]
-runGhcWrapper :: String
-runGhcWrapper = "exec \"$executablename\" -f \"$exedir/ghc\" ${1+\"$@\"}\n"
+runGhcWrapper :: Action String
+runGhcWrapper = pure $ "exec \"$executablename\" -f \"$exedir/ghc\" ${1+\"$@\"}\n"
-- | We need to ship ghci executable, which basically just calls ghc with
-- | --interactive flag.
-ghciScriptWrapper :: String
-ghciScriptWrapper = unlines
+ghciScriptWrapper :: Action String
+ghciScriptWrapper = pure $ unlines
[ "DIR=`dirname \"$0\"`"
, "executable=\"$DIR/ghc\""
, "exec $executable --interactive \"$@\"" ]