[project @ 2003-05-20 11:07:54 by stolz]
[ghc-hetmet.git] / ghc / utils / hsc2hs / Main.hs
index ea842f5..4456ae7 100644 (file)
@@ -1,7 +1,7 @@
 {-# OPTIONS -fglasgow-exts #-}
 
 ------------------------------------------------------------------------
--- $Id: Main.hs,v 1.44 2003/02/07 21:55:36 sof Exp $
+-- $Id: Main.hs,v 1.47 2003/05/20 11:07:54 stolz Exp $
 --
 -- Program for converting .hsc files to .hs files, by converting the
 -- file into a C program which is run to generate the Haskell source.
@@ -101,12 +101,17 @@ main = do
     flags_w_tpl <- if any template_flag flags then
                        return flags
                   else 
-                       do { mb_path <- getExecDir "/bin/hsc2hs.exe" ;
-                            case mb_path of
-                               Nothing   -> return flags
-
-                               Just path -> return (Template (path ++ "/template-hsc.h") : flags) }
-
+                       do mb_path <- getExecDir "/bin/hsc2hs.exe"
+                          add_opt <-
+                           case mb_path of
+                             Nothing   -> return id
+                             Just path -> do
+                               let templ = path ++ "/template-hsc.h"
+                               flg <- doesFileExist templ
+                               if flg 
+                                then return ((Template templ):)
+                                else return id
+                          return (add_opt flags) 
     case (files, errs) of
         (_, _)
             | any isHelp    flags_w_tpl -> putStrLn (usageInfo header options)
@@ -512,14 +517,14 @@ output flags name toks = do
         _   -> onlyOne "compiler"
     
     linker <- case [l | Linker l <- flags] of
-        []  -> locateGhc "ghc"
+        []  -> locateGhc compiler
         [l] -> return l
         _   -> onlyOne "linker"
 
     writeFile cProgName $
         concatMap outFlagHeaderCProg flags++
         concatMap outHeaderCProg specials++
-        "\nint main (void)\n{\n"++
+        "\nint main (int argc, char *argv [])\n{\n"++
         outHeaderHs flags (if needsH then Just outHName else Nothing) specials++
         outHsLine (SourcePos name 0)++
         concatMap outTokenHs toks++
@@ -806,7 +811,7 @@ getExecDir cmd
   where
     len = 2048::Int -- Plenty, PATH_MAX is 512 under Win32.
 
-foreign import stdcall unsafe "GetModuleFileNameA"
+foreign import stdcall "GetModuleFileNameA" unsafe
   getModuleFileName :: Ptr () -> CString -> Int -> IO Int32
 
 #else