[don't leave temp dir aronud when user interrupts compiliation with ^C, pass cc options to hsc2hs.
John Meacham <john@repetae.net>**20120124120929
 Ignore-this: 88c700ac7865547b0e36aae3e6c1f3cc
] hunk ./src/Grin/Main.hs 5
-import Directory
hunk ./src/Grin/Main.hs 21
+import Ho.ReadSource
hunk ./src/Grin/Main.hs 23
+import Support.TempDir
hunk ./src/Grin/Main.hs 28
-import qualified FlagOpts as FO
hunk ./src/Grin/Main.hs 83
-        cf = case (optOutName options,optMode options) of
-            (Just fn,StopC) -> fn
-            _ -> (fn ++ "_code.c")
hunk ./src/Grin/Main.hs 84
+    cf <- case (optOutName options,optMode options) of
+            (Just fn,StopC) -> return fn
+            _ | dump FD.C -> return (fn ++ "_code.c")
+              | otherwise -> fileInTempDir (fn ++ "_code.c") (\_ -> return ())
hunk ./src/Grin/Main.hs 89
-    let
-        boehmOpts | fopts FO.Boehm = ["-D_JHC_GC=_JHC_GC_BOEHM", "-lgc"]
-                  | fopts FO.Jgc   = ["-D_JHC_GC=_JHC_GC_JGC"]
-                  | otherwise = []
-        profileOpts | fopts FO.Profile || lup "profile" == "true" = ["-D_JHC_PROFILE=1"]
-                    | otherwise = []
-        comm = shellQuote $ [lup "cc"] ++ words (lup "cflags") ++ ["-o", fn, cf] ++
-                            (map ("-l" ++) rls) ++ debug ++ optCCargs options  ++ boehmOpts ++ profileOpts
-        debug = if fopts FO.Debug then words (lup "cflags_debug") else words (lup "cflags_nodebug")
+    (cc,args) <- fetchCompilerFlags
+    let comm = shellQuote $ [cc] ++ ["-o", fn, cf] ++ args ++ (map ("-l" ++) rls)
hunk ./src/Grin/Main.hs 99
-    unless (dump FD.C) $ removeFile cf
hunk ./src/Ho/ReadSource.hs 6
+   fetchCompilerFlags,
hunk ./src/Ho/ReadSource.hs 13
-import System.Directory
hunk ./src/Ho/ReadSource.hs 18
-import qualified Data.Set as Set
hunk ./src/Ho/ReadSource.hs 19
+import qualified Data.Set as Set
hunk ./src/Ho/ReadSource.hs 46
-        _ | FO.Cpp `Set.member` optFOptsSet opt -> readSystem "cpp" $ ["-CC","-traditional"] ++ incFlags ++ defFlags ++ [fn]
-          | FO.M4 `Set.member` optFOptsSet opt -> do
-            m4p <- m4Prelude
-            result <- readSystem "m4" $ ["-s", "-P"] ++ incFlags ++ defFlags ++ [m4p,fn]
-            removeFile m4p >> return result
+        _ | fopts FO.Cpp -> readSystem "cpp" $ ["-CC","-traditional"] ++ incFlags ++ defFlags ++ [fn]
+          | fopts FO.M4  -> do
+                m4p <- m4Prelude
+                readSystem "m4" $ ["-s", "-P"] ++ incFlags ++ defFlags ++ [m4p,fn]
hunk ./src/Ho/ReadSource.hs 53
-m4Prelude = do
-    fp <- fileInTempDir "prelude.m4"
-    BS.writeFile fp prelude_m4
-    return fp
+m4Prelude = fileInTempDir "prelude.m4" $ \fp -> do putStrLn $ "Writing stuff:" ++ fp ; BS.writeFile fp prelude_m4 ; return ()
hunk ./src/Ho/ReadSource.hs 76
-
hunk ./src/Ho/ReadSource.hs 91
+    (cc,cflags) <- fetchCompilerFlags
hunk ./src/Ho/ReadSource.hs 93
-    let hscargs =   [fp, "-o", tdir </> out] ++ incFlags
+    let hscargs =   [fp, "-o", tdir </> out] ++ incFlags ++ concatMap (\x -> ["-C",x]) cflags ++ ["-c", cc]
hunk ./src/Ho/ReadSource.hs 119
+
+fetchCompilerFlags :: IO (FilePath,     -- ^ file path to compiler
+                          [String])     -- ^ compiler arguments
+fetchCompilerFlags = return (cc,args) where
+    lup k = maybe "" id $ Map.lookup k (optInis options)
+    boehmOpts | fopts FO.Boehm = ["-D_JHC_GC=_JHC_GC_BOEHM", "-lgc"]
+              | fopts FO.Jgc   = ["-D_JHC_GC=_JHC_GC_JGC"]
+              | otherwise = []
+    profileOpts | fopts FO.Profile || lup "profile" == "true" = ["-D_JHC_PROFILE=1"]
+                | otherwise = []
+    debug = if fopts FO.Debug then words (lup "cflags_debug") else words (lup "cflags_nodebug")
+    cc = lup "cc"
+    args = words (lup "cflags") ++ debug ++ optCCargs options  ++ boehmOpts ++ profileOpts
hunk ./src/Options.hs 259
-    , Option []    ["build-hl"]  (ReqArg (optMode_s . BuildHl) "file.cabal") "Build hakell library from given library description file"
+    , Option []    ["build-hl"]  (ReqArg (optMode_s . BuildHl) "desc.yaml") "Build hakell library from given library description file"
hunk ./src/Support/TempDir.hs 7
+    cleanTempDir,
hunk ./src/Support/TempDir.hs 23
+import qualified Data.Set as Set
hunk ./src/Support/TempDir.hs 26
-    tempDirClean :: Bool,  -- ^ whether to delete the directory afterwords.
-    tempDirDump :: Bool,
-    tempDirPath :: Maybe String,
-    tempDirCleanup :: [FilePath]
+    tempDirClean   :: Bool,  -- ^ whether to delete the directory afterwords.
+    tempDirDump    :: Bool,
+    tempDirPath    :: Maybe String,
+    tempDirCleanup :: Set.Set FilePath
hunk ./src/Support/TempDir.hs 36
+cleanTempDir :: Bool -> IO ()
+cleanTempDir b = modifyIORef tdRef $ \x -> x { tempDirClean = b }
+
+
hunk ./src/Support/TempDir.hs 59
-fileInTempDir :: FilePath -> IO FilePath
-fileInTempDir fp = do
+fileInTempDir :: FilePath -> (FilePath -> IO ()) -> IO FilePath
+fileInTempDir fp action = do
hunk ./src/Support/TempDir.hs 62
-    addCleanup fp
-    return (dir </> fp)
+    let nfp = dir </> fp
+    b <- addCleanup fp
+    when b $ action nfp
+    return nfp
hunk ./src/Support/TempDir.hs 72
-    forM_ (tempDirCleanup td) $ \fp -> do
+    forM_ (Set.toList $ tempDirCleanup td) $ \fp -> do
hunk ./src/Support/TempDir.hs 78
-addCleanup :: FilePath -> IO ()
+addCleanup :: FilePath -> IO Bool
hunk ./src/Support/TempDir.hs 81
-    writeIORef tdRef td { tempDirCleanup = fp:tempDirCleanup td }
+    if fp `Set.member` tempDirCleanup td then
+        return False
+        else writeIORef tdRef td { tempDirCleanup = fp `Set.insert` tempDirCleanup td } >> return True
hunk ./src/Support/TempDir.hs 86
-wrapMain main = E.catch (main >> cleanUp) $ \e -> case fromException e of
-    Just code -> cleanUp >>  exitWith code
-    Nothing -> do
+wrapMain main = E.catch (main >> cleanUp) f where
+    f (fromException -> Just code) = cleanUp >> exitWith code
+    f (fromException -> Just UserInterrupt) = cleanUp >> throwIO UserInterrupt
+    f e = do
hunk ./src/Support/TempDir.hs 106
-    tempDirClean = True,
-    tempDirDump = False,
-    tempDirPath = Nothing,
-    tempDirCleanup = []
+    tempDirClean   = True,
+    tempDirDump    = False,
+    tempDirPath    = Nothing,
+    tempDirCleanup = Set.empty