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) : args -> do
38 doIt (dropWhile isSpace ghc) args
40 mb_ghc <- findExecutable "ghc"
42 Nothing -> dieProg ("cannot find ghc")
43 Just ghc -> doIt ghc args
47 (ghc_args, rest) = break notArg args
50 [] -> dieProg "syntax: runghc [-f GHCPATH] [GHC-ARGS] FILE ARG..."
51 filename : prog_args -> do
52 res <- rawSystem ghc (
53 "-ignore-dot-ghci" : ghc_args ++
54 [ "-e","System.Environment.withProgName "++show filename++" (System.Environment.withArgs ["
55 ++ concat (intersperse "," (map show prog_args))
56 ++ "] Main.main)", filename])
59 notArg ('-':_) = False
62 dieProg :: String -> IO a
65 hPutStrLn stderr (p ++ ": " ++ msg)
66 exitWith (ExitFailure 1)