summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-12-06 12:27:21 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-12-06 12:27:21 -0400
commit1f4c26566509a07335751e95c464c08e3debcb86 (patch)
tree1ceda06c825a816cfc8bf5220993a0aa4822bbf1
parent83242b603a8d1393eaa0be310638ca7bddf8e40b (diff)
EvilLinker, stage 1
-rw-r--r--Build/EvilLinker.hs60
-rwxr-xr-xstandalone/windows/build-simple.sh13
2 files changed, 68 insertions, 5 deletions
diff --git a/Build/EvilLinker.hs b/Build/EvilLinker.hs
new file mode 100644
index 000000000..a3e838038
--- /dev/null
+++ b/Build/EvilLinker.hs
@@ -0,0 +1,60 @@
+{- Allows linking haskell programs too big for all the files to fit in a
+ - command line.
+ -
+ -
+ - Copyright 2013 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Main where
+
+import Data.Maybe
+import Data.Either
+import Data.List
+import Text.Parsec
+import Text.Parsec.String
+import Control.Applicative ((<$>))
+import Control.Monad
+
+import Utility.Monad
+import Utility.Process
+
+data CmdParams = CmdParams String String
+ deriving (Show)
+
+parseGhcLink :: Parser CmdParams
+parseGhcLink = do
+ many prelinklines
+ linkheaderline
+ char '"'
+ gcccmd <- many1 (noneOf "\"")
+ string "\" "
+ gccparams <- restOfLine
+ return $ CmdParams gcccmd gccparams
+ where
+ linkheaderline = do
+ string "*** Linker"
+ restOfLine
+ prelinklines = do
+ notFollowedBy linkheaderline
+ restOfLine
+
+restOfLine :: Parser String
+restOfLine = newline `after` many (noneOf "\n")
+
+getOutput :: String -> [String] -> IO String
+getOutput cmd params = do
+ putStrLn $ unwords [cmd, show params]
+ (log, ok) <- processTranscript cmd params Nothing
+ unless ok $
+ error $ cmd ++ " failed:\n\n" ++ log
+ return log
+
+runParser' :: Parser a -> String -> a
+runParser' p s = either (error . show) id (parse p "" s)
+
+main = do
+ ghcout <- getOutput "cabal"
+ ["build", "--ghc-options=-v -keep-tmp-files"]
+ print $ runParser' parseGhcLink ghcout
diff --git a/standalone/windows/build-simple.sh b/standalone/windows/build-simple.sh
index cdda36feb..209758aff 100755
--- a/standalone/windows/build-simple.sh
+++ b/standalone/windows/build-simple.sh
@@ -28,8 +28,11 @@ withcyg cabal build || true
# Works around link failure https://ghc.haskell.org/trac/ghc/ticket/8596
# using a response file.
-withcyg rm -f build.log gcc.opt
-withcyg cabal build --ghc-options='-v -keep-tmp-files' > build.log 2>&1 || true
-withcyg grep 'dist\\build\\git-annex\\git-annex.exe' build.log | withcyg grep -v Linking | withcyg sed -e 's/^"[^"]*" //' -e 's/\\/\//g' > gcc.opt
-PATH="$HP/mingw/bin:$PATH"
-gcc @gcc.opt
+ghc --make Build/EvilLinker
+Build/EvilLinker
+
+#withcyg rm -f build.log gcc.opt
+#withcyg cabal build --ghc-options='-v -keep-tmp-files' > build.log 2>&1 || true
+#withcyg grep 'dist\\build\\git-annex\\git-annex.exe' build.log | withcyg grep -v Linking | withcyg sed -e 's/^"[^"]*" //' -e 's/\\/\//g' > gcc.opt
+#PATH="$HP/mingw/bin:$PATH"
+#gcc @gcc.opt