6f160d79f343b136c906eed7ee446baff198e102
[ghc-hetmet.git] / ghc / utils / hsc2hs / KludgedSystem.hs
1 {-# OPTIONS -cpp -fglasgow-exts #-}
2 -----------------------------------------------------------------------------
3 -- $Id: KludgedSystem.hs,v 1.5 2001/03/27 16:33:17 rrt Exp $
4
5 -- system that works feasibly under Windows (i.e. passes the command line to sh,
6 -- because system() under Windows doesn't look at SHELL, and always uses CMD.EXE)
7
8 module KludgedSystem (system, defaultCompiler) where
9
10 #include "../../includes/config.h"
11
12 #ifndef mingw32_TARGET_OS
13
14 import System (system)
15
16 defaultCompiler :: String
17 defaultCompiler = "gcc"
18
19 #else
20
21 import qualified System
22 import System    (ExitCode)
23 import IO        (bracket_)
24 import Directory (removeFile)
25 import Config
26
27 system :: String -> IO ExitCode
28 system cmd = do
29     pid <- getProcessID
30     let tmp = cDEFAULT_TMPDIR++"/sh"++show pid
31     writeFile tmp (cmd++"\n")
32     bracket_ (return tmp) removeFile $ System.system ("sh - "++tmp)
33
34 foreign import "_getpid" unsafe getProcessID :: IO Int
35
36 defaultCompiler :: String
37 defaultCompiler = "gcc -mno-cygwin -mwin32"
38
39 #endif /* mingw32_TARGET_OS */