further stub filename fix: I managed to break non-stubdir -fvia-C compilation
[ghc-hetmet.git] / compiler / main / Finder.lhs
index df1fa3e..5419112 100644 (file)
@@ -4,6 +4,13 @@
 \section[Finder]{Module Finder}
 
 \begin{code}
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 module Finder (
     flushFinderCaches,
     FindResult(..),
@@ -243,6 +250,14 @@ findHomeModule hsc_env mod_name =
      exts | isOneShot (ghcMode dflags) = hi_exts
           | otherwise                 = source_exts
    in
+
+  -- special case for GHC.Prim; we won't find it in the filesystem.
+  -- This is important only when compiling the base package (where GHC.Prim
+  -- is a home module).
+  if mod == gHC_PRIM 
+        then return (Found (error "GHC.Prim ModLocation") mod)
+        else 
+
    searchPathExts home_path mod exts
 
 
@@ -453,7 +468,7 @@ mkStubPaths
   :: DynFlags
   -> ModuleName
   -> ModLocation
-  -> (FilePath,FilePath)
+  -> (FilePath,FilePath,FilePath)
 
 mkStubPaths dflags mod location
   = let
@@ -468,9 +483,23 @@ mkStubPaths dflags mod location
                        | otherwise           = src_basename
 
                stub_basename = stub_basename0 ++ "_stub"
+
+                -- this is the filename we're going to use when
+                -- #including the stub_h file from the .hc file.
+                -- Without -stubdir, we just #include the basename
+                -- (eg. for a module A.B, we #include "B_stub.h"),
+                -- relying on the fact that we add an implicit -I flag
+                -- for the directory in which the source file resides
+                -- (see DriverPipeline.hs).  With -stubdir, we
+                -- #include "A/B.h", assuming that the user has added
+                -- -I<dir> along with -stubdir <dir>.
+                include_basename
+                        | Just _ <- stubdir = mod_basename 
+                        | otherwise         = filenameOf src_basename
      in
         (stub_basename `joinFileExt` "c",
-        stub_basename `joinFileExt` "h")
+        stub_basename `joinFileExt` "h",
+         (include_basename ++ "_stub") `joinFileExt` "h")
        -- the _stub.o filename is derived from the ml_obj_file.
 
 -- -----------------------------------------------------------------------------