- = do { maybe_exec_dir <- getExecDir -- Get directory of executable
- ; case maybe_exec_dir of -- (only works on Windows)
- Nothing -> throwDyn (InstallationError ("missing -B<dir> option"))
- Just dir -> return dir }
-
- remove_suffix dir -- "/...stuff.../ghc/compiler" --> "/...stuff..."
- = ASSERT2( not (null p1) &&
- not (null p2) &&
- dosifyPath dir == dosifyPath (top_dir ++ "/ghc/compiler"),
- text dir )
- top_dir
+ = do { maybe_exec_dir <- getExecDir -- Get directory of executable
+ ; case maybe_exec_dir of -- (only works on Windows;
+ -- returns Nothing on Unix)
+ Nothing -> throwDyn (InstallationError "missing -B<dir> option")
+ Just dir -> return (remove_suffix dir)
+ }
+
+ -- In an installed tree, the ghc binary lives in $libexecdir, which
+ -- is normally $libdir/bin. So we strip off a /bin suffix here.
+ -- In a build tree, the ghc binary lives in $fptools/ghc/compiler,
+ -- so we strip off the /ghc/compiler suffix here too, leaving a
+ -- standard TOPDIR.
+ remove_suffix ghc_bin_dir -- ghc_bin_dir is in standard Unix format
+ | "/ghc/compiler" `isSuffixOf` ghc_bin_dir = back_two
+ | "/bin" `isSuffixOf` ghc_bin_dir = back_one
+ | otherwise = ghc_bin_dir