[project @ 2001-08-17 16:06:30 by sof]
[ghc-hetmet.git] / ghc / compiler / main / SysTools.lhs
index 5469d2c..596e6f2 100644 (file)
@@ -1,5 +1,4 @@
 -----------------------------------------------------------------------------
--- $Id: SysTools.lhs,v 1.51 2001/08/15 14:59:34 rrt Exp $
 --
 -- (c) The University of Glasgow 2001
 --
@@ -76,12 +75,20 @@ import List         ( isPrefixOf )
 import MarshalArray
 #endif
 
+-- This is a kludge for bootstrapping with 4.08.X.  Given that
+-- all distributed compilers >= 5.0 will be compiled with themselves.
+-- I don't think this kludge is a problem.  And we have to start
+-- building with >= 5.0 on Win32 anyway.
+#if __GLASGOW_HASKELL__ > 408
 -- use the line below when we can be sure of compiling with GHC >=
 -- 5.02, and remove the implementation of rawSystem at the end of this
 -- file
 import PrelIOBase -- this can be removed when SystemExts is used
 import CError     ( throwErrnoIfMinus1 ) -- as can this
 -- import SystemExts       ( rawSystem )
+#else
+import System          ( system )
+#endif
 
 #include "HsVersions.h"
 
@@ -436,16 +443,17 @@ between filepaths and 'other stuff'. [The reason being, of course, that
 this type gives us a handle on transforming filenames, and filenames only,
 to whatever format they're expected to be on a particular platform.]
 
-
 \begin{code}
 data Option
- = FileOption String
+ = FileOption -- an entry that _contains_ filename(s) / filepaths.
+              String  -- a non-filepath prefix that shouldn't be transformed (e.g., "/out=" 
+             String  -- the filepath/filename portion
  | Option     String
  
 showOptions :: [Option] -> String
 showOptions ls = unwords (map (quote.showOpt) ls)
  where
-   showOpt (FileOption f) = dosifyPath f
+   showOpt (FileOption pre f) = pre ++ dosifyPath f
    showOpt (Option s)     = s
 
 #if defined(mingw32_TARGET_OS)
@@ -495,11 +503,11 @@ runLink args = do p <- readIORef v_Pgm_l
                  runSomething "Linker" p args
 
 #ifdef ILX
-runIlx2il :: [String] -> IO ()
+runIlx2il :: [Option] -> IO ()
 runIlx2il args = do p <- readIORef v_Pgm_I
                    runSomething "Ilx2Il" p args
 
-runIlasm :: [String] -> IO ()
+runIlasm :: [Option] -> IO ()
 runIlasm args = do p <- readIORef v_Pgm_i
                   runSomething "Ilasm" p args
 #endif
@@ -510,7 +518,7 @@ runMkDLL args = do p <- readIORef v_Pgm_MkDLL
 
 touch :: String -> String -> IO ()
 touch purpose arg =  do p <- readIORef v_Pgm_T
-                       runSomething purpose p [FileOption arg]
+                       runSomething purpose p [FileOption "" arg]
 
 copy :: String -> String -> String -> IO ()
 copy purpose from to = do
@@ -720,11 +728,6 @@ unDosifyPath xs = subst '\\' '/' xs
 
 pgmPath dir pgm = dosifyPath dir ++ '\\' : pgm
 
--- HACK!
-dosifyPath "\"/DLL\"" = "\"/DLL\""
-dosifyPath "\"/QUIET\"" = "\"/QUIET\""
-dosifyPath l@('"':'/':'O':'U':'T':_) = l
--- end of HACK!
 dosifyPath stuff
   = subst '/' '\\' real_stuff
  where
@@ -803,14 +806,19 @@ getProcessID = Posix.getProcessID
 #endif
 
 rawSystem :: String -> IO ExitCode
+#if __GLASGOW_HASKELL__ > 408
 rawSystem "" = ioException (IOError Nothing InvalidArgument "rawSystem" "null command" Nothing)
 rawSystem cmd =
-  withUnsafeCString cmd $ \s -> do
+  withCString cmd $ \s -> do
     status <- throwErrnoIfMinus1 "rawSystem" (primRawSystem s)
     case status of
         0  -> return ExitSuccess
         n  -> return (ExitFailure n)
 
-foreign import ccall "rawSystemCmd" unsafe primRawSystem :: UnsafeCString -> IO Int
+foreign import ccall "rawSystemCmd" unsafe primRawSystem :: CString -> IO Int
+#else
+rawSystem = System.system
+#endif
+
 
 \end{code}