Add --keep-files flag; patch from Brian Bloniarz
authorIan Lynagh <igloo@earth.li>
Wed, 23 Mar 2011 17:18:56 +0000 (17:18 +0000)
committerIan Lynagh <igloo@earth.li>
Wed, 23 Mar 2011 17:18:56 +0000 (17:18 +0000)
DirectCodegen.hs
Main.hs

index dd051e6..368e332 100644 (file)
@@ -40,6 +40,7 @@ data Flag
     | Include   String
     | Define    String (Maybe String)
     | Output    String
+    | KeepFiles
     | Verbose
 
 die :: String -> IO a
@@ -110,6 +111,10 @@ output mb_libdir flags name toks = do
 
     let needsC = any (\(_, key, _) -> key == "def") specials
         needsH = needsC
+        keepFiles = not $ null [() | KeepFiles <- flags]
+        possiblyRemove = if keepFiles
+                         then flip const
+                         else finallyRemove
 
     let includeGuard = map fixChar outHName
             where
@@ -159,17 +164,17 @@ output mb_libdir flags name toks = do
         ++ ["-o", oProgName]
         ++ [f | CompFlag f <- flags]
        )
-    finallyRemove cProgName $ do
+    possiblyRemove cProgName $ do
 
       rawSystemL ("linking " ++ oProgName) beVerbose linker
         (  [oProgName]
         ++ ["-o", progName]
         ++ [f | LinkFlag f <- flags]
        )
-      finallyRemove oProgName $ do
+      possiblyRemove oProgName $ do
 
         rawSystemWithStdOutL ("running " ++ execProgName) beVerbose execProgName [] outName
-        finallyRemove progName $ do
+        possiblyRemove progName $ do
 
           when needsH $ writeBinaryFile outHName $
             "#ifndef "++includeGuard++"\n" ++
diff --git a/Main.hs b/Main.hs
index a68c832..2d07989 100644 (file)
--- a/Main.hs
+++ b/Main.hs
@@ -83,6 +83,8 @@ options = [
         "as if placed in the source",
     Option []    ["no-compile"] (NoArg  NoCompile)
         "stop after writing *_hsc_make.c",
+    Option ['k'] ["keep-files"] (NoArg KeepFiles)
+        "do not remove temporary files",
     Option ['v'] ["verbose"]    (NoArg  Verbose)
         "dump commands to stderr",
     Option ['?'] ["help"]       (NoArg  Help)