Add --version to runghc. Trac #2757.
authorIan Lynagh <igloo@earth.li>
Thu, 5 Mar 2009 16:20:45 +0000 (16:20 +0000)
committerIan Lynagh <igloo@earth.li>
Thu, 5 Mar 2009 16:20:45 +0000 (16:20 +0000)
We use the GHC version number, as the old runghc one doesn't seem very
useful.

configure.ac
utils/runghc/Makefile
utils/runghc/runghc.cabal.in [moved from utils/runghc/runghc.cabal with 93% similarity]
utils/runghc/runghc.hs

index d298af8..85e0617 100644 (file)
@@ -1290,7 +1290,7 @@ else
 fi
 AC_SUBST(HavePapi)
 
-AC_CONFIG_FILES([mk/config.mk compiler/ghc.cabal ghc/ghc-bin.cabal ghc.spec extra-gcc-opts docs/users_guide/ug-book.xml])
+AC_CONFIG_FILES([mk/config.mk compiler/ghc.cabal ghc/ghc-bin.cabal utils/runghc/runghc.cabal ghc.spec extra-gcc-opts docs/users_guide/ug-book.xml])
 AC_CONFIG_COMMANDS([mk/stamp-h],[echo timestamp > mk/stamp-h])
 AC_OUTPUT
 
index 0b606de..1415921 100644 (file)
@@ -5,5 +5,8 @@ ENABLE_SHELL_WRAPPERS = YES
 include $(TOP)/mk/boilerplate.mk
 include $(TOP)/mk/cabal.mk
 
+distclean maintainer-clean:
+       $(RM) -f runghc.cabal
+
 # XXX Need to make runhaskell somehow
 
similarity index 93%
rename from utils/runghc/runghc.cabal
rename to utils/runghc/runghc.cabal.in
index 876e97d..7b3fc1b 100644 (file)
@@ -1,6 +1,5 @@
 Name: runghc
--- XXX version number:
-Version: 0.67
+Version: @ProjectVersion@
 Copyright: XXX
 License: BSD3
 -- XXX License-File: LICENSE
index bfdcc96..47615de 100644 (file)
 
 module Main (main) where
 
+import Paths_runghc
+
 import Control.Exception
 import Data.Char
 import Data.List
 import Data.Monoid
+import Data.Version
 import System.Cmd
 import System.Directory
 import System.Environment
@@ -44,6 +47,7 @@ main = do
     args <- getArgs
     case parseRunGhcFlags args of
         (Help, _) -> printUsage
+        (ShowVersion, _) -> printVersion
         (RunGhcFlags (Just ghc), args') -> doIt ghc args'
         (RunGhcFlags Nothing, args') -> do
             mbPath <- getExecPath
@@ -55,11 +59,14 @@ main = do
 
 data RunGhcFlags = RunGhcFlags (Maybe FilePath) -- GHC location
                  | Help -- Print help text
+                 | ShowVersion -- Print version info
 
 instance Monoid RunGhcFlags where
     mempty = RunGhcFlags Nothing
     Help `mappend` _ = Help
     _ `mappend` Help = Help
+    ShowVersion `mappend` _ = ShowVersion
+    _ `mappend` ShowVersion = ShowVersion
     RunGhcFlags _ `mappend` right@(RunGhcFlags (Just _)) = right
     left@(RunGhcFlags _) `mappend` RunGhcFlags Nothing = left
 
@@ -70,11 +77,16 @@ parseRunGhcFlags = f mempty
           f flags (('-' : 'f' : ghc) : args)
               = f (flags `mappend` RunGhcFlags (Just ghc)) args
           f flags ("--help" : args) = f (flags `mappend` Help) args
+          f flags ("--version" : args) = f (flags `mappend` ShowVersion) args
           -- If you need the first GHC flag to be a -f flag then
           -- you can pass -- first
           f flags ("--" : args) = (flags, args)
           f flags         args  = (flags, args)
 
+printVersion :: IO ()
+printVersion = do
+    putStrLn ("runghc " ++ showVersion version)
+
 printUsage :: IO ()
 printUsage = do
     putStrLn "Usage: runghc [runghc flags] [GHC flags] module [program args]"
@@ -82,6 +94,7 @@ printUsage = do
     putStrLn "The runghc flags are"
     putStrLn "    -f /path/to/ghc       Tell runghc where GHC is"
     putStrLn "    --help                Print this usage information"
+    putStrLn "    --version             Print version number"
 
 doIt :: String -> [String] -> IO ()
 doIt ghc args = do