1 {-# OPTIONS -cpp -fffi #-}
2 #if __GLASGOW_HASKELL__ < 603
7 -----------------------------------------------------------------------------
9 -- (c) The University of Glasgow, 2004
11 -- runghc program, for invoking from a #! line in a script. For example:
15 -- > main = putStrLn "hello!"
17 -- runghc accepts one flag:
19 -- -f <path> specify the path
21 -- -----------------------------------------------------------------------------
25 import System.Environment
31 import Compat.RawSystem ( rawSystem )
32 import Compat.Directory ( findExecutable )
37 ('-':'f' : ghc) : filename : args -> do
38 doIt (dropWhile isSpace ghc) filename args
40 mb_ghc <- findExecutable "ghc"
42 Nothing -> dieProg ("cannot find ghc")
43 Just ghc -> doIt ghc filename args
45 dieProg "syntax: runghc [-f GHCPATH] FILE ARG..."
47 doIt ghc filename args = do
48 res <- rawSystem ghc ["-e","System.Environment.withProgName "++show filename++" (System.Environment.withArgs ["
49 ++ concat (intersperse "," (map show args))
50 ++ "] Main.main)", filename]
53 dieProg :: String -> IO a
56 hPutStr stderr (p ++ ": " ++ msg)
57 exitWith (ExitFailure 1)