[project @ 2001-08-16 11:06:10 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverUtil.hs
index 77c0f4c..264be5c 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
--- $Id: DriverUtil.hs,v 1.24 2001/06/14 12:50:06 simonpj Exp $
+-- $Id: DriverUtil.hs,v 1.27 2001/08/16 11:06:10 simonmar Exp $
 --
 -- Utils for the driver
 --
@@ -14,6 +14,7 @@ module DriverUtil where
 
 import Util
 import Panic
+import Config          ( cLeadingUnderscore )
 
 import IOExts
 import Exception
@@ -38,7 +39,7 @@ getOptionsFromSource
        -> IO [String]          -- options, if any
 getOptionsFromSource file
   = do h <- openFile file ReadMode
-       catchJust ioErrors (look h)
+       catchJust ioErrors (look h `finally` hClose h)
          (\e -> if isEOFError e then return [] else ioError e)
   where
        look h = do
@@ -60,12 +61,19 @@ optionRegex = mkRegex "\\{-#[ \t]+OPTIONS[ \t]+(.*)#-\\}"   -- -}
 
 softGetDirectoryContents d
    = IO.catch (getDirectoryContents d)
-         (\_ -> do hPutStr stderr 
+         (\_ -> do hPutStrLn stderr 
                          ("WARNING: error while reading directory " ++ d)
                    return []
          )
 
 -----------------------------------------------------------------------------
+-- Prefixing underscore to linker-level names
+prefixUnderscore :: String -> String
+prefixUnderscore
+ | cLeadingUnderscore == "YES" = ('_':)
+ | otherwise                   = id
+
+-----------------------------------------------------------------------------
 -- Utils
 
 unknownFlagErr :: String -> a