# -----------------------------------------------------------------------------
-# $Id: Makefile,v 1.186 2001/08/15 14:02:54 sewardj Exp $
+# $Id: Makefile,v 1.187 2001/08/15 14:36:21 rrt Exp $
TOP = ..
include $(TOP)/mk/boilerplate.mk
# GHC with GHC 5.02 or better, but lacking that we have the following
# hack:
# copy rawSystem.c from hslibs/lang/cbits
-# and SystemExts.lhs from hslibs/lang
-# into main/ (where they'll be compiled and linked with the compiler)
+# into main/ (where it'll be compiled and linked with the compiler)
+# (the Haskell-side code is ifdefed into main/SysTools.lhs)
ifneq "$(ghc_502_at_least)" "YES"
C_SRCS += main/rawSystem.c
-HS_SRCS := $(filter-out main/SystemExts.lhs,$(HS_SRCS)) main/SystemExts.lhs
SRC_CC_OPTS += -I$(GHC_LIB_DIR)/std/cbits
SRC_MKDEPENDC_OPTS += -I$(GHC_LIB_DIR)/std/cbits
HS_OBJS += main/rawSystem.o
main/rawSystem.c : $(FPTOOLS_TOP)/hslibs/lang/cbits/rawSystem.c
$(CP) $< main
-main/SystemExts.lhs: $(FPTOOLS_TOP)/hslibs/lang/SystemExts.lhs
- $(CP) $< main
endif
endif
# End of system hack
-----------------------------------------------------------------------------
--- $Id: SysTools.lhs,v 1.49 2001/08/15 09:32:40 rrt Exp $
+-- $Id: SysTools.lhs,v 1.50 2001/08/15 14:36:21 rrt Exp $
--
-- (c) The University of Glasgow 2001
--
#else
import List ( isPrefixOf )
import MarshalArray
-import SystemExts ( rawSystem )
+-- use the line below when we can be sure of compiling with GHC >=
+-- 5.02, and remove the implementation of rawSystem at the end of this
+-- file
+import PrelIOBase -- this can be removed when SystemExts is used
+import CError ( throwErrnoIfMinus1 ) -- as can this
+-- import SystemExts ( rawSystem )
#endif
#include "HsVersions.h"
getProcessID :: IO Int
getProcessID = Posix.getProcessID
#endif
+
+rawSystem :: String -> IO ExitCode
+rawSystem "" = ioException (IOError Nothing InvalidArgument "rawSystem" "null command" Nothing)
+rawSystem cmd =
+ withUnsafeCString cmd $ \s -> do
+ status <- throwErrnoIfMinus1 "rawSystem" (primRawSystem s)
+ case status of
+ 0 -> return ExitSuccess
+ n -> return (ExitFailure n)
+
+foreign import ccall "rawSystemCmd" unsafe primRawSystem :: UnsafeCString -> IO Int
+
\end{code}