[project @ 2002-01-16 23:34:31 by chak]
[ghc-hetmet.git] / ghc / utils / hsc2hs / KludgedSystem.hs
1 {-# OPTIONS -cpp -fglasgow-exts #-}
2 -----------------------------------------------------------------------------
3 -- $Id: KludgedSystem.hs,v 1.8 2001/07/04 09:18:38 sewardj 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, progNameSuffix) where
9
10 #include "../../includes/config.h"
11
12 import Config
13
14 #ifndef mingw32_TARGET_OS
15
16 import System (system)
17
18 defaultCompiler :: String
19 defaultCompiler = cGCC
20 progNameSuffix = ""
21
22 #else
23
24 import qualified System
25 import System    (ExitCode)
26 import IO        (bracket_)
27 import Directory (removeFile)
28
29 system :: String -> IO ExitCode
30 system cmd = do
31     pid <- getProcessID
32     let tmp = cDEFAULT_TMPDIR++"/sh"++show pid
33     writeFile tmp (cmd++"\n")
34     bracket_ (return tmp) removeFile $ System.system ("sh - "++tmp)
35
36 foreign import "_getpid" unsafe getProcessID :: IO Int
37
38 defaultCompiler :: String
39 defaultCompiler = cGCC ++ " -mno-cygwin"
40 progNameSuffix = ".exe"
41
42 #endif /* mingw32_TARGET_OS */