<sect2>
<title>Command line syntax</title>
- <para>glue-hsc takes input files as arguments, and flags that
- modify its behavior:</para>
+ <para><command>hsc2hs</command> takes input files as arguments,
+ and flags that modify its behavior:</para>
<variablelist>
<varlistentry>
</varlistentry>
<varlistentry>
+ <term><literal>-I DIR</literal></term>
+ <listitem>
+ <para>Passed to the C compiler.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>--lflag=FLAG</literal></term>
<listitem>
<para>An extra flag to pass to the linker.</para>
</varlistentry>
<varlistentry>
+ <term><literal>--include=FILE</literal></term>
+ <listitem>
+ <para>As if the appropriate <literal>#include</literal>
+ directive was placed in the source.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>--help</literal></term>
<listitem>
<para>Display a summary of the available flags.</para>
<entry>Haskell file</entry>
</row>
<row>
- <entry><literal>_hsc.h</literal></entry>
+ <entry><literal>.hs.h</literal></entry>
<entry>C header</entry>
</row>
<row>
- <entry><literal>_hsc.c</literal></entry>
+ <entry><literal>.hs.c</literal></entry>
<entry>C file</entry>
</row>
</tbody>
is placed in the <literal>{-# OPTIONS #-}</literal> pragma
at the top of the Haskell file (see <xref
linkend="source-file-options">). This is needed because
- glue-hsc emits its own <literal>OPTIONS</literal> pragma,
+ <command>hsc2hs</command> emits its own <literal>OPTIONS</literal> pragma,
and only one such pragma is interpreted by GHC.</para>
</listitem>
</varlistentry>
prefixed by <literal>hsc_</literal> that handles the construct
by emitting the expansion to stdout. See
<filename>template-hsc.h</filename> for examples.</para>
+
+ <para>Such macros can also be defined directly in the
+ source. They are useful for making a <literal>#let</literal>-like
+ macro whose expansion uses other <literal>#let</literal> macros.
+ Plain <literal>#let</literal> prepends <literal>hsc_</literal>
+ to the macro name and wraps the defininition in a
+ <literal>printf</literal> call.
</sect2>
-----------------------------------------------------------------------------
--- $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)
--
= 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
_ -> 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 $
\#include <Rts.h>\n\
\#endif\n\
\#include <HsFFI.h>\n"++
+ concat ["#include "++name++"\n" | Include name <- flags]++
concatMap outTokenH specials++
"#endif\n"
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
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