4794ee830141b7ed91eb2b2a268edaa29894b21a
[ghc-hetmet.git] / ghc / utils / hsc2hs / KludgedSystem.hs
1 {-# OPTIONS -cpp -fglasgow-exts #-}
2 -----------------------------------------------------------------------------
3 -- $Id: KludgedSystem.hs,v 1.3 2001/03/13 17:46:56 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     tmp_dir <- readIORef v_TmpDir
31     let tmp = tmp_dir++"/sh"++show pid
32     writeFile tmp (cmd++"\n")
33     bracket_ (return tmp) removeFile $ System.system ("sh - "++tmp)
34
35 foreign import "_getpid" unsafe getProcessID :: IO Int
36
37 defaultCompiler :: String
38 defaultCompiler = "gcc -mno-cygwin"
39
40 #endif /* mingw32_TARGET_OS */