-----------------------------------------------------------------------------
--- $Id: Main.hs,v 1.18 2001/02/13 15:09:02 rrt Exp $
+-- $Id: Main.hs,v 1.24 2001/03/04 11:18:03 qrczak Exp $
--
-- (originally "GlueHsc.hs" by Marcin 'Qrczak' Kowalczyk)
--
import GetOpt
import System (getProgName, getArgs, ExitCode(..), exitWith, exitFailure)
-import KludgedSystem (system)
+import KludgedSystem (system, defaultCompiler)
import Directory (removeFile)
import Parsec
import ParsecError
import List (intersperse)
version :: String
-version = "hsc2hs-0.64"
+version = "hsc2hs-0.65"
data Flag
= Help
| Linker String
| CompFlag String
| LinkFlag String
+ | Keep
| Include String
include :: String -> Flag
options :: [OptDescr Flag]
options = [
Option "t" ["template"] (ReqArg Template "FILE") "template file",
- Option "" ["cc"] (ReqArg Compiler "PROG") "C compiler to use",
- Option "" ["ld"] (ReqArg Linker "PROG") "linker to use",
- Option "" ["cflag"] (ReqArg CompFlag "FLAG") "flag to pass to the C compiler",
+ Option "c" ["cc"] (ReqArg Compiler "PROG") "C compiler to use",
+ Option "l" ["ld"] (ReqArg Linker "PROG") "linker to use",
+ Option "C" ["cflag"] (ReqArg CompFlag "FLAG") "flag to pass to the C compiler",
Option "I" [] (ReqArg (CompFlag . ("-I"++))
"DIR") "passed to the C compiler",
- Option "" ["lflag"] (ReqArg LinkFlag "FLAG") "flag to pass to the linker",
- Option "" ["include"] (ReqArg include "FILE") "as if placed in the source",
+ Option "L" ["lflag"] (ReqArg LinkFlag "FLAG") "flag to pass to the linker",
+ Option "" ["keep"] (NoArg Keep) "don't delete *.hs_make.c",
+ Option "i" ["include"] (ReqArg include "FILE") "as if placed in the source",
Option "" ["help"] (NoArg Help) "display this help and exit",
Option "" ["version"] (NoArg Version) "output version information and exit"]
pos <- getPosition
char '#'
skipMany (oneOf " \t")
+ keyArg pos pzero <|> do
+ char '{'
+ skipMany (oneOf " \t")
+ sp <- keyArg pos (string "\n")
+ char '}'
+ return sp
+
+keyArg :: SourcePos -> Parser String -> Parser Token
+keyArg pos eol = do
key <- liftM2 (:) (letter <|> char '_') (many (alphaNum <|> char '_'))
<?> "hsc directive"
skipMany (oneOf " \t")
- arg <- argument pzero
+ arg <- argument eol
return (Special pos key arg)
argument :: Parser String -> Parser String
baseName = case reverse name of
'c':base -> reverse base
_ -> name++".hs"
- cProgName = baseName++"c_make_hs.c"
- oProgName = baseName++"c_make_hs.o"
- progName = baseName++"c_make_hs"
+ cProgName = baseName++"_make.c"
+ oProgName = baseName++"_make.o"
+ progName = baseName++"_make"
outHsName = baseName
outHName = baseName++".h"
outCName = baseName++".c"
[c] -> return c
_ -> onlyOne "compiler"
linker <- case [l | Linker l <- flags] of
-#ifndef mingw32_TARGET_OS
- [] -> return "gcc"
-#else
- [] -> return "gcc -mno-cygwin"
-#endif
+ [] -> return defaultCompiler
[l] -> return l
_ -> onlyOne "linker"
case compilerStatus of
e@(ExitFailure _) -> exitWith e
_ -> return ()
- removeFile cProgName
+ when (null [() | Keep <- flags]) $ removeFile cProgName
linkerStatus <- system $
linker++