[project @ 2001-06-13 10:23:23 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / Main.hs
index 60b1d6e..1b9f220 100644 (file)
@@ -1,6 +1,6 @@
 {-# OPTIONS -fno-warn-incomplete-patterns #-}
 -----------------------------------------------------------------------------
--- $Id: Main.hs,v 1.66 2001/05/28 03:31:19 sof Exp $
+-- $Id: Main.hs,v 1.68 2001/06/13 10:23:23 simonmar Exp $
 --
 -- GHC Driver program
 --
@@ -63,7 +63,6 @@ import Maybe
 -----------------------------------------------------------------------------
 -- ToDo:
 
--- -nohi doesn't work
 -- new mkdependHS doesn't support all the options that the old one did (-X et al.)
 -- time commands when run with -v
 -- split marker
@@ -168,7 +167,7 @@ main =
        Left err -> throwDyn (InstallationError (showSDoc err));
        Right pkg_details -> do
 
-   writeIORef v_Package_details pkg_details
+   writeIORef v_Package_details (mungePackagePaths top_dir pkg_details)
 
        -- find the phase to stop after (i.e. -E, -C, -c, -S flags)
    (flags2, mode, stop_flag) <- getGhcMode argv'
@@ -318,8 +317,10 @@ main =
    when (mode == DoLink) (doLink o_files)
    when (mode == DoMkDLL) (doMkDLL o_files)
   }
-       -- grab the last -B option on the command line, and
-       -- set topDir to its value.
+
+
+-- grab the last -B option on the command line, and
+-- set topDir to its value.
 setTopDir :: [String] -> IO [String]
 setTopDir args = do
   let (minusbs, others) = partition (prefixMatch "-B") args
@@ -328,6 +329,23 @@ setTopDir args = do
     some -> writeIORef v_TopDir (drop 2 (last some)))
   return others
 
+
+-- replace the string "$libdir" at the beginning of a path with the
+-- current TOPDIR (obtained from the -B option if present, or the
+-- wired-in libdir otherwise).
+mungePackagePaths top_dir ps = map munge_pkg ps
+ where 
+  munge_pkg p = p{ import_dirs  = munge_paths (import_dirs p),
+                  include_dirs = munge_paths (include_dirs p),
+                  library_dirs = munge_paths (library_dirs p) }
+
+  munge_paths = map munge_path
+
+  munge_path p 
+         | Just p' <- my_prefix_match "$libdir" p = top_dir ++ p'
+         | otherwise = trace ("not: " ++ p) p
+
+
 beginMake :: [String] -> IO ()
 beginMake fileish_args
   = do let (objs, mods) = partition objish_file fileish_args