[project @ 2001-02-13 15:53:10 by qrczak]
[ghc-hetmet.git] / ghc / utils / hsc2hs / KludgedSystem.hs
1 {-# OPTIONS -cpp -fglasgow-exts #-}
2 -----------------------------------------------------------------------------
3 -- $Id: KludgedSystem.hs,v 1.2 2001/02/13 15:53:10 qrczak 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
26 system :: String -> IO ExitCode
27 system cmd = do
28     pid <- getProcessID
29     let tmp = "/tmp/sh"++show pid
30     writeFile tmp (cmd++"\n")
31     bracket_ (return tmp) removeFile $ System.system ("sh - "++tmp)
32
33 foreign import "_getpid" unsafe getProcessID :: IO Int
34
35 defaultCompiler :: String
36 defaultCompiler = "gcc -mno-cygwin"
37
38 #endif /* mingw32_TARGET_OS */