summaryrefslogtreecommitdiff
path: root/utils/runghc
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2006-04-07 02:05:11 +0000
committerSimon Marlow <simonmar@microsoft.com>2006-04-07 02:05:11 +0000
commit0065d5ab628975892cea1ec7303f968c3338cbe1 (patch)
tree8e2afe0ab48ee33cf95009809d67c9649573ef92 /utils/runghc
parent28a464a75e14cece5db40f2765a29348273ff2d2 (diff)
downloadhaskell-0065d5ab628975892cea1ec7303f968c3338cbe1.tar.gz
Reorganisation of the source tree
Most of the other users of the fptools build system have migrated to Cabal, and with the move to darcs we can now flatten the source tree without losing history, so here goes. The main change is that the ghc/ subdir is gone, and most of what it contained is now at the top level. The build system now makes no pretense at being multi-project, it is just the GHC build system. No doubt this will break many things, and there will be a period of instability while we fix the dependencies. A straightforward build should work, but I haven't yet fixed binary/source distributions. Changes to the Building Guide will follow, too.
Diffstat (limited to 'utils/runghc')
-rw-r--r--utils/runghc/Makefile32
-rw-r--r--utils/runghc/runghc.hs66
2 files changed, 98 insertions, 0 deletions
diff --git a/utils/runghc/Makefile b/utils/runghc/Makefile
new file mode 100644
index 0000000000..90e4949530
--- /dev/null
+++ b/utils/runghc/Makefile
@@ -0,0 +1,32 @@
+TOP=../..
+include $(TOP)/mk/boilerplate.mk
+
+HS_PROG = runghc$(exeext)
+INSTALL_PROGS += $(HS_PROG)
+
+UseGhcForCc = YES
+SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
+
+# This causes libghccompat.a to be used:
+include $(GHC_COMPAT_DIR)/compat.mk
+
+# This is required because libghccompat.a must be built with
+# $(GhcHcOpts) because it is linked to the compiler, and hence
+# we must also build with $(GhcHcOpts) here:
+SRC_HC_OPTS += $(GhcHcOpts)
+
+all :: runhaskell
+
+runhaskell : $(HS_PROG)
+ $(CP) $< runhaskell$(exeext)
+
+CLEAN_FILES += runhaskell
+
+# Only install runhaskell if there isn't already one installed
+ifneq "$(findstring install, $(MAKECMDGOALS))" ""
+ifeq "$(wildcard $(bindir)/runhaskell)" ""
+INSTALL_PROGS += runhaskell$(exeext)
+endif
+endif
+
+include $(TOP)/mk/target.mk
diff --git a/utils/runghc/runghc.hs b/utils/runghc/runghc.hs
new file mode 100644
index 0000000000..f8330b5721
--- /dev/null
+++ b/utils/runghc/runghc.hs
@@ -0,0 +1,66 @@
+{-# OPTIONS -cpp -fffi #-}
+#if __GLASGOW_HASKELL__ < 603
+#include "config.h"
+#else
+#include "ghcconfig.h"
+#endif
+-----------------------------------------------------------------------------
+--
+-- (c) The University of Glasgow, 2004
+--
+-- runghc program, for invoking from a #! line in a script. For example:
+--
+-- script.lhs:
+-- #! /usr/bin/runghc
+-- > main = putStrLn "hello!"
+--
+-- runghc accepts one flag:
+--
+-- -f <path> specify the path
+--
+-- -----------------------------------------------------------------------------
+
+module Main where
+
+import System.Environment
+import System.IO
+import Data.List
+import System.Exit
+import Data.Char
+
+import Compat.RawSystem ( rawSystem )
+import Compat.Directory ( findExecutable )
+
+main = do
+ args <- getArgs
+ case args of
+ ('-':'f' : ghc) : args -> do
+ doIt (dropWhile isSpace ghc) args
+ args -> do
+ mb_ghc <- findExecutable "ghc"
+ case mb_ghc of
+ Nothing -> dieProg ("cannot find ghc")
+ Just ghc -> doIt ghc args
+
+doIt ghc args = do
+ let
+ (ghc_args, rest) = break notArg args
+ --
+ case rest of
+ [] -> dieProg "syntax: runghc [-f GHCPATH] [GHC-ARGS] FILE ARG..."
+ filename : prog_args -> do
+ res <- rawSystem ghc (
+ "-ignore-dot-ghci" : ghc_args ++
+ [ "-e","System.Environment.withProgName "++show filename++" (System.Environment.withArgs ["
+ ++ concat (intersperse "," (map show prog_args))
+ ++ "] Main.main)", filename])
+ exitWith res
+
+notArg ('-':_) = False
+notArg _ = True
+
+dieProg :: String -> IO a
+dieProg msg = do
+ p <- getProgName
+ hPutStrLn stderr (p ++ ": " ++ msg)
+ exitWith (ExitFailure 1)