{-# OPTIONS -fglasgow-exts #-}
------------------------------------------------------------------------
--- $Id: Main.hs,v 1.49 2003/10/01 16:45:10 sof Exp $
+-- $Id: Main.hs,v 1.50 2004/02/07 16:37:06 panne 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.
import GetOpt
#endif
-import Config
import System (getProgName, getArgs, ExitCode(..), exitWith, system)
import Directory (removeFile,doesFileExist)
import Monad (MonadPlus(..), liftM, liftM2, when, unless)
import List (intersperse, isSuffixOf)
import IO (hPutStr, hPutStrLn, stderr)
-#include "../../includes/config.h"
-
-#ifdef mingw32_HOST_OS
+#if defined(mingw32_HOST_OS)
import Foreign
-
#if __GLASGOW_HASKELL__ >= 504
import Foreign.C.String
#else
#endif
-
version :: String
-version = "hsc2hs version 0.65\n"
+version = "hsc2hs version 0.66\n"
data Flag
= Help
| Output String
| Verbose
+template_flag :: Flag -> Bool
template_flag (Template _) = True
template_flag _ = False
where
isHelp Help = True; isHelp _ = False
isVersion Version = True; isVersion _ = False
- (files@(_:_), []) -> mapM_ (processFile flags_w_tpl) files
- (_, errs) -> die (concat errs ++ usageInfo header options)
+ ((_:_), []) -> mapM_ (processFile flags_w_tpl) files
+ (_, _ ) -> die (concat errs ++ usageInfo header options)
getProgramName :: IO String
getProgramName = liftM (`withoutSuffix` "-bin") getProgName
let cProgName = outDir++outBase++"_hsc_make.c"
oProgName = outDir++outBase++"_hsc_make.o"
- progName = outDir++outBase++"_hsc_make" ++ progNameSuffix
+ progName = outDir++outBase++"_hsc_make" ++ EXEEXT
outHFile = outBase++"_hsc.h"
outHName = outDir++outHFile
outCName = outDir++outBase++"_hsc.c"
beVerbose = any (\ x -> case x of { Verbose{} -> True; _ -> False}) flags
let execProgName
- | null outDir = '.':pathSep:progName
+ | null outDir = dosifyPath ("./" ++ progName)
| otherwise = progName
let specials = [(pos, key, arg) | Special pos key arg <- toks]
showCString s++"\");\n"
outTokenHs :: Token -> String
-outTokenHs (Text pos text) =
- case break (== '\n') text of
- (all, []) -> outText all
+outTokenHs (Text pos txt) =
+ case break (== '\n') txt of
+ (allTxt, []) -> outText allTxt
(first, _:rest) ->
outText (first++"\n")++
outHsLine pos++
-- Cut and pasted from ghc/compiler/SysTools
-- Convert paths foo/baz to foo\baz on Windows
-
+dosifyPath :: String -> String
#if defined(mingw32_HOST_OS)
-subst a b ls = map (\ x -> if x == a then b else x) ls
-unDosifyPath xs = subst '\\' '/' xs
dosifyPath xs = subst '/' '\\' xs
+unDosifyPath :: String -> String
+unDosifyPath xs = subst '\\' '/' xs
+
+subst :: Eq a => a -> a -> [a] -> [a]
+subst a b ls = map (\ x -> if x == a then b else x) ls
+
getExecDir :: String -> IO (Maybe String)
-- (getExecDir cmd) returns the directory in which the current
-- executable, which should be called 'cmd', is running
dosifyPath xs = xs
getExecDir :: String -> IO (Maybe String)
-getExecDir s = do return Nothing
+getExecDir _ = return Nothing
#endif
# -----------------------------------------------------------------------------
-# $Id: Makefile,v 1.38 2003/06/04 15:18:30 panne Exp $
TOP=../..
include $(TOP)/mk/boilerplate.mk
SRC_HC_OPTS += -package util
endif
-SRC_HC_OPTS += -cpp
+SRC_HC_OPTS += -Wall -cpp '-DEXEEXT="$(exeext)"'
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+SRC_HC_OPTS += -Dmingw32_HOST_OS=1
+endif
ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
INSTALLED_SCRIPT_PROG = hsc2hs
INSTALL_DATAS += template-hsc.h
# -----------------------------------------------------------------------------
-# Create driver configuration
-
-CONFIG_HS = Config.hs
-CLEAN_FILES += $(CONFIG_HS)
-EXTRA_SRCS += $(CONFIG_HS)
-
-boot :: $(CONFIG_HS)
-
-$(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
- @$(RM) -f $(CONFIG_HS)
- @echo -n "Creating $(CONFIG_HS) ... "
- @echo "module Config where" >>$(CONFIG_HS)
- @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
- @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
- @echo "progNameSuffix = \"$(exeext)\"" >> $(CONFIG_HS)
-ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
- @echo "pathSep = '/'" >> $(CONFIG_HS)
-else
- @echo "pathSep = (toEnum 92 :: Char)" >> $(CONFIG_HS)
-endif
- @echo done.
-
-# -----------------------------------------------------------------------------
# don't recurse on 'make install'
#
ifeq "$(INSTALLING)" "1"