[project @ 2005-01-28 12:55:17 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / Packages.lhs
index 081e801..8a4009d 100644 (file)
@@ -12,7 +12,8 @@ module Packages (
        extendPackageConfigMap, dumpPackages,
 
        -- * Reading the package config, and processing cmdline args
-       PackageState(..),
+       PackageIdH(..), isHomePackage,
+       PackageState(..), 
        initPackages,
        moduleToPackageConfig,
        getPackageDetails,
@@ -33,9 +34,6 @@ module Packages (
     )
 where
 
-#include "../includes/ghcconfig.h"
--- Needed for mingw32_TARGET_OS defn
-
 #include "HsVersions.h"
 
 import PackageConfig   
@@ -43,7 +41,7 @@ import DriverState    ( v_Build_tag, v_RTS_Build_tag, v_Static )
 import SysTools                ( getTopDir, getPackageConfigPath )
 import ParsePkgConf    ( loadPackageConfig )
 import CmdLineOpts     ( DynFlags(..), PackageFlag(..), opt_Static )
-import Config          ( cTARGETARCH, cTARGETOS, cProjectVersion )
+import Config          ( cProjectVersion )
 import Name            ( Name, nameModule_maybe )
 import Module          ( Module, mkModule )
 import UniqFM
@@ -147,12 +145,22 @@ data PackageState = PackageState {
        -- exposed is True if the package exposes that module.
 
   -- The PackageIds of some known packages
-  basePackageId                :: Maybe PackageId,
-  rtsPackageId         :: Maybe PackageId,
-  haskell98PackageId   :: Maybe PackageId,
-  thPackageId          :: Maybe PackageId
+  basePackageId                :: PackageIdH,
+  rtsPackageId         :: PackageIdH,
+  haskell98PackageId   :: PackageIdH,
+  thPackageId          :: PackageIdH
   }
 
+data PackageIdH 
+   = HomePackage               -- The "home" package is the package curently
+                               -- being compiled
+   | ExtPackage PackageId      -- An "external" package is any other package
+
+
+isHomePackage :: PackageIdH -> Bool
+isHomePackage HomePackage    = True
+isHomePackage (ExtPackage _) = False
+
 -- A PackageConfigMap maps a PackageId to a PackageConfig
 type PackageConfigMap = UniqFM PackageConfig
 
@@ -195,7 +203,7 @@ readPackageConfigs dflags = do
        -- (GHC >= 6.3).
    appdir <- getAppUserDataDirectory "ghc"
    let 
-        pkgconf = appdir ++ '/':cTARGETARCH ++ '-':cTARGETOS
+        pkgconf = appdir ++ '/':TARGET_ARCH ++ '-':TARGET_OS
                        ++ '-':cProjectVersion ++ "/package.conf"
    --
    exists <- doesFileExist pkgconf
@@ -223,8 +231,8 @@ readPackageConfig dflags pkg_map conf_file = do
 
 
 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
--- Replace the string "$libdir" at the beginning of a path
--- with the current libdir (obtained from the -B option).
+-- Replace the string "$topdir" at the beginning of a path
+-- with the current topdir (obtained from the -B option).
 mungePackagePaths top_dir ps = map munge_pkg ps
  where 
   munge_pkg p = p{ importDirs  = munge_paths (importDirs p),
@@ -235,7 +243,7 @@ mungePackagePaths top_dir ps = map munge_pkg ps
   munge_paths = map munge_path
 
   munge_path p 
-         | Just p' <- maybePrefixMatch "$libdir" p = top_dir ++ p'
+         | Just p' <- maybePrefixMatch "$topdir" p = top_dir ++ p'
          | otherwise                               = p
 
 
@@ -311,12 +319,13 @@ mkPackageState dflags pkg_db = do
   -- Look up some known PackageIds
   --
   let
+       lookupPackageByName :: FastString -> PackageIdH
        lookupPackageByName nm = 
          case [ conf | p <- dep_exposed,
                        Just conf <- [lookupPackage pkg_db p],
                        nm == mkFastString (pkgName (package conf)) ] of
-               []     -> Nothing
-               (p:ps) -> Just (mkPackageId (package p))
+               []     -> HomePackage
+               (p:ps) -> ExtPackage (mkPackageId (package p))
 
        -- Get the PackageIds for some known packages (we know the names,
        -- but we don't know the versions).  Some of these packages might
@@ -329,7 +338,7 @@ mkPackageState dflags pkg_db = do
        -- add base & rts to the explicit packages
        basicLinkedPackages = [basePackageId,rtsPackageId]
        explicit' = addListToUniqSet explicit 
-                       [ p | Just p <- basicLinkedPackages ]
+                       [ p | ExtPackage p <- basicLinkedPackages ]
   --
   -- Close the explicit packages with their dependencies
   --