summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-12-06 12:43:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-12-06 12:43:30 -0400
commit7bc8f5a93ada714a83e244870638fdca2e65fc78 (patch)
treec271ff48c03c05c855b61f7c8c79793d391ac361 /Build
parent1f4c26566509a07335751e95c464c08e3debcb86 (diff)
EvilLinker stage 2
Diffstat (limited to 'Build')
-rw-r--r--Build/EvilLinker.hs28
1 files changed, 26 insertions, 2 deletions
diff --git a/Build/EvilLinker.hs b/Build/EvilLinker.hs
index a3e838038..a30636204 100644
--- a/Build/EvilLinker.hs
+++ b/Build/EvilLinker.hs
@@ -19,10 +19,12 @@ import Control.Monad
import Utility.Monad
import Utility.Process
+import System.Directory
-data CmdParams = CmdParams String String
+data CmdParams = CmdParams { cmd :: String, opts :: String }
deriving (Show)
+{- Find where ghc calls gcc to link the executable. -}
parseGhcLink :: Parser CmdParams
parseGhcLink = do
many prelinklines
@@ -40,6 +42,14 @@ parseGhcLink = do
notFollowedBy linkheaderline
restOfLine
+{- Find where gcc calls collect1. -}
+parseCollect1 :: Parser CmdParams
+parseCollect1 = error "TODO"
+
+{- Find where collect1 calls ld. -}
+parseLd :: Parser CmdParams
+parseLd = error "TODO"
+
restOfLine :: Parser String
restOfLine = newline `after` many (noneOf "\n")
@@ -54,7 +64,21 @@ getOutput cmd params = do
runParser' :: Parser a -> String -> a
runParser' p s = either (error . show) id (parse p "" s)
+atFile :: FilePath -> String
+atFile f = '@':f
+
+runAtFile :: Parser CmdParams -> String -> FilePath -> [String] -> IO String
+runAtFile p s f extraparams = do
+ writeFile f (opts c)
+ out <- getOutput (cmd c) (atFile f:extraparams)
+ removeFile f
+ return out
+ where
+ c = runParser' p s
+
main = do
ghcout <- getOutput "cabal"
["build", "--ghc-options=-v -keep-tmp-files"]
- print $ runParser' parseGhcLink ghcout
+ gccout <- runAtFile parseGhcLink ghcout "gcc.opt" ["-v"]
+ collect1out <- runAtFile parseCollect1 gccout "collect1.opt" ["-v"]
+ void $ runAtFile parseLd collect1out "ld.opt" []