; let installed, installed_bin :: FilePath -> FilePath
installed_bin pgm = top_dir </> pgm
installed file = top_dir </> file
- inplace dir pgm = let real_top_dir = foldr (</>) ""
- $ reverse
- $ drop 4
- $ reverse
- $ splitDirectories top_dir
- in real_top_dir </> dir </> pgm
+ inplace dir pgm = top_dir </> dir </> pgm
; let pkgconfig_path
| am_installed = installed "package.conf"
- | otherwise = inplace cGHC_DRIVER_DIR_REL "package.conf.inplace"
+ | otherwise = inplace "inplace-datadir" "package.conf"
ghc_usage_msg_path
| am_installed = installed "ghc-usage.txt"
findTopDir mbMinusB
= do { top_dir <- get_proto
- -- Discover whether we're running in a build tree or in an installation,
- -- by looking for the package configuration file.
- ; am_installed <- doesFileExist (top_dir </> "package.conf")
+ ; exists1 <- doesFileExist (top_dir </> "package.conf")
+ ; exists2 <- doesFileExist (top_dir </> "inplace")
+ ; let amInplace = not exists1 -- On Windows, package.conf doesn't exist
+ -- when we are inplace
+ || exists2 -- On Linux, the presence of inplace signals
+ -- that we are inplace
- ; return (am_installed, top_dir)
+ ; let real_top = if exists2 then top_dir </> ".." else top_dir
+
+ ; return (not amInplace, real_top)
}
where
-- get_proto returns a Unix-format path (relying on getBaseDir to do so too)
rootDir s = case splitFileName $ normalise s of
(d, "ghc.exe") ->
case splitFileName $ takeDirectory d of
+ -- installed ghc.exe is in $topdir/bin/ghc.exe
(d', "bin") -> takeDirectory d'
- _ -> panic ("Expected \"bin\" in " ++ show s)
- _ -> panic ("Expected \"ghc.exe\" in " ++ show s)
+ -- inplace ghc.exe is in $topdir/ghc/stage1-inplace/ghc.exe
+ (d', x) | "-inplace" `isSuffixOf` x ->
+ takeDirectory d' </> ".."
+ _ -> fail
+ _ -> fail
+ where fail = panic ("can't decompose ghc.exe path: " ++ show s)
foreign import stdcall unsafe "GetModuleFileNameA"
getModuleFileName :: Ptr () -> CString -> Int -> IO Int32