diff options
-rw-r--r-- | Build/EvilLinker.hs | 28 |
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" [] |