[project @ 2001-07-03 16:57:03 by sewardj]
[ghc-hetmet.git] / ghc / utils / hsc2hs / KludgedSystem.hs
1 {-# OPTIONS -cpp -fglasgow-exts #-}
2 -----------------------------------------------------------------------------
3 -- $Id: KludgedSystem.hs,v 1.7 2001/07/03 16:57:03 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 #ifndef mingw32_TARGET_OS
13
14 import System (system)
15
16 defaultCompiler :: String
17 defaultCompiler = cGCC
18 progNameSuffix = ""
19
20 #else
21
22 import qualified System
23 import System    (ExitCode)
24 import IO        (bracket_)
25 import Directory (removeFile)
26 import Config
27
28 system :: String -> IO ExitCode
29 system cmd = do
30     pid <- getProcessID
31     let tmp = cDEFAULT_TMPDIR++"/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 = cGCC ++ " -mno-cygwin"
39 progNameSuffix = ".exe"
40
41 #endif /* mingw32_TARGET_OS */