From 2a4197e53fc0dde1b2942963fd89b7358bdd98a1 Mon Sep 17 00:00:00 2001 From: qrczak Date: Sat, 30 Dec 2000 20:06:00 +0000 Subject: [PATCH] [project @ 2000-12-30 20:06:00 by qrczak] Add -I and --include options. Small corrections and clarifications in the documentation. --- ghc/docs/users_guide/utils.sgml | 32 +++++++++++++++++++---- ghc/utils/hsc2hs/Main.hs | 53 ++++++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/ghc/docs/users_guide/utils.sgml b/ghc/docs/users_guide/utils.sgml index 796ee90..4117f8d 100644 --- a/ghc/docs/users_guide/utils.sgml +++ b/ghc/docs/users_guide/utils.sgml @@ -135,8 +135,8 @@ tags: Command line syntax - glue-hsc takes input files as arguments, and flags that - modify its behavior: + hsc2hs takes input files as arguments, + and flags that modify its behavior: @@ -171,6 +171,13 @@ tags: + -I DIR + + Passed to the C compiler. + + + + --lflag=FLAG An extra flag to pass to the linker. @@ -178,6 +185,14 @@ tags: + --include=FILE + + As if the appropriate #include + directive was placed in the source. + + + + --help Display a summary of the available flags. @@ -196,11 +211,11 @@ tags: Haskell file - _hsc.h + .hs.h C header - _hsc.c + .hs.c C file @@ -280,7 +295,7 @@ tags: is placed in the {-# OPTIONS #-} pragma at the top of the Haskell file (see ). This is needed because - glue-hsc emits its own OPTIONS pragma, + hsc2hs emits its own OPTIONS pragma, and only one such pragma is interpreted by GHC. @@ -393,6 +408,13 @@ tags: prefixed by hsc_ that handles the construct by emitting the expansion to stdout. See template-hsc.h for examples. + + Such macros can also be defined directly in the + source. They are useful for making a #let-like + macro whose expansion uses other #let macros. + Plain #let prepends hsc_ + to the macro name and wraps the defininition in a + printf call. diff --git a/ghc/utils/hsc2hs/Main.hs b/ghc/utils/hsc2hs/Main.hs index 5ff8e44..5d88e60 100644 --- a/ghc/utils/hsc2hs/Main.hs +++ b/ghc/utils/hsc2hs/Main.hs @@ -1,5 +1,5 @@ ----------------------------------------------------------------------------- --- $Id: Main.hs,v 1.3 2000/12/28 10:34:56 qrczak Exp $ +-- $Id: Main.hs,v 1.4 2000/12/30 20:06:00 qrczak Exp $ -- -- (originally "GlueHsc.hs" by Marcin 'Qrczak' Kowalczyk) -- @@ -23,18 +23,27 @@ data Flag = Help | Template String | Compiler String - | Linker String + | Linker String | CompFlag String | LinkFlag String + | Include String + +include :: String -> Flag +include s@('\"':_) = Include s +include s@('<' :_) = Include s +include s = Include ("\""++s++"\"") 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 "" ["lflag"] (ReqArg LinkFlag "FLAG") "flag to pass to the linker", - Option "" ["help"] (NoArg Help) "display this help and exit"] + 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 "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 "" ["help"] (NoArg Help) "display this help and exit"] main :: IO () main = do @@ -145,11 +154,12 @@ output flags name toks = let _ -> onlyOne "linker" writeFile cProgName $ - concat ["#include \""++t++"\"\n" | Template t <- flags] ++ - outHeaderCProg specials ++ - "\nint main (void)\n{\n" ++ - outHeaderHs (if needsH then Just outHName else Nothing) specials ++ - concatMap outTokenHs toks ++ + concat ["#include \""++t++"\"\n" | Template t <- flags]++ + concat ["#include "++f++"\n" | Include f <- flags]++ + outHeaderCProg specials++ + "\nint main (void)\n{\n"++ + outHeaderHs flags (if needsH then Just outHName else Nothing) specials++ + concatMap outTokenHs toks++ " return 0;\n}\n" compilerStatus <- system $ @@ -183,6 +193,7 @@ output flags name toks = let \#include \n\ \#endif\n\ \#include \n"++ + concat ["#include "++name++"\n" | Include name <- flags]++ concatMap outTokenH specials++ "#endif\n" @@ -215,11 +226,11 @@ outHeaderCProg = concatMap $ \(key, arg) -> case key of where joinLines = concat . intersperse " \\\n" . lines -outHeaderHs :: Maybe String -> [(String, String)] -> String -outHeaderHs inH toks = +outHeaderHs :: [Flag] -> Maybe String -> [(String, String)] -> String +outHeaderHs flags inH toks = " hsc_begin_options();\n"++ - concatMap outSpecial toks ++ - includeH ++ + includeH++ + concatMap outSpecial toks++ " hsc_end_options();\n\n" where outSpecial (key, arg) = case key of @@ -240,9 +251,11 @@ outHeaderHs inH toks = toOptD arg = case break isSpace arg of (name, "") -> name (name, _:value) -> name++'=':dropWhile isSpace value - includeH = case inH of - Nothing -> "" - Just name -> outOption ("-#include \""++name++"\"") + includeH = concat [ + outOption ("-#include "++name++"") + | name <- case inH of + Nothing -> [name | Include name <- flags] + Just name -> ["\""++name++"\""]] outOption s = " hsc_option (\""++showCString s++"\");\n" outTokenHs :: Token -> String -- 1.7.10.4