diff options
Diffstat (limited to 'utils/runghc')
-rw-r--r-- | utils/runghc/Main.hs | 22 | ||||
-rw-r--r-- | utils/runghc/ghc.mk | 1 |
2 files changed, 18 insertions, 5 deletions
diff --git a/utils/runghc/Main.hs b/utils/runghc/Main.hs index 42ddb83f25..d048125fd0 100644 --- a/utils/runghc/Main.hs +++ b/utils/runghc/Main.hs @@ -52,9 +52,24 @@ main = do mbPath <- getExecPath case mbPath of Nothing -> dieProg ("cannot find ghc") - Just path -> - let ghc = takeDirectory (normalise path) </> "ghc" - in uncurry (doIt ghc) $ getGhcArgs args' + Just path -> do + ghc <- findGhc path + uncurry (doIt ghc) $ getGhcArgs args' + +-- In some cases, runghc isn't given a path to ghc explicitly. This can occur +-- if $1_$2_SHELL_WRAPPER = NO (which is always the case on Windows). In such +-- a scenario, we must guess where ghc lives. Given a path where ghc might +-- live, we check for the existence of ghc. If we can't find it, we assume that +-- we're building ghc from source, in which case we fall back on ghc-stage2. +-- (See Trac #1185.) +findGhc :: FilePath -> IO FilePath +findGhc path = do + let ghcDir = takeDirectory (normalise path) + ghc = ghcDir </> "ghc" <.> exeExtension + ghcExists <- doesFileExist ghc + return $ if ghcExists + then ghc + else ghcDir </> "ghc-stage2" <.> exeExtension data RunGhcFlags = RunGhcFlags (Maybe FilePath) -- GHC location | Help -- Print help text @@ -177,4 +192,3 @@ foreign import WINDOWS_CCONV unsafe "windows.h GetModuleFileNameW" #else getExecPath = return Nothing #endif - diff --git a/utils/runghc/ghc.mk b/utils/runghc/ghc.mk index e981abf9a5..9169ca21bd 100644 --- a/utils/runghc/ghc.mk +++ b/utils/runghc/ghc.mk @@ -42,4 +42,3 @@ install_runhaskell: $(call removeFiles,"$(DESTDIR)$(bindir)/runghc") $(LN_S) runghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/runghc" endif - |