[project @ 2003-07-21 14:33:19 by simonmar]
[ghc-hetmet.git] / ghc / compiler / compMan / CompManager.lhs
index 1f5aa9a..1722ddc 100644 (file)
@@ -57,7 +57,7 @@ where
 #include "HsVersions.h"
 
 import DriverPipeline  ( CompResult(..), preprocess, compile, link )
-import DriverState     ( v_Output_file )
+import DriverState     ( v_Output_file, v_NoHsMain )
 import DriverPhases
 import DriverUtil
 import Finder
@@ -638,15 +638,22 @@ cmLoadModules cmstate1 dflags mg2unsorted
              -- clean up after ourselves
              cleanTempFilesExcept verb (ppFilesFromSummaries modsDone)
 
-             -- issue a warning for the confusing case where the user said '-o foo'
-             -- but we're not going to do any linking.
              ofile <- readIORef v_Output_file
-             when (ghci_mode == Batch && isJust ofile && not a_root_is_Main
+             no_hs_main <- readIORef v_NoHsMain
+
+             -- Issue a warning for the confusing case where the user
+             -- said '-o foo' but we're not going to do any linking.
+             -- We attempt linking if either (a) one of the modules is
+             -- called Main, or (b) the user said -no-hs-main, indicating
+             -- that main() is going to come from somewhere else.
+             --
+             let do_linking = a_root_is_Main || no_hs_main
+             when (ghci_mode == Batch && isJust ofile && not do_linking
                     && verb > 0) $
                 hPutStrLn stderr "Warning: output was redirected with -o, but no output will be generated\nbecause there is no Main module."
 
              -- link everything together
-              linkresult <- link ghci_mode dflags a_root_is_Main hpt3 
+              linkresult <- link ghci_mode dflags do_linking hpt3 
 
              cmLoadFinish Succeeded linkresult 
                           hpt3 modsDone ghci_mode pcs3
@@ -698,18 +705,11 @@ cmLoadFinish ok Succeeded hpt mods ghci_mode pcs
 
        return (new_cmstate, ok, mods_loaded)
 
--- used to fish out the preprocess output files for the purposes
--- of cleaning up.
+-- used to fish out the preprocess output files for the purposes of
+-- cleaning up.  The preprocessed file *might* be the same as the
+-- source file, but that doesn't do any harm.
 ppFilesFromSummaries summaries
-  = [ fn | Just fn <- map toPpFile summaries ]
-  where
-   toPpFile sum
-     | hspp /= ml_hs_file loc = hspp
-     | otherwise              = Nothing
-    where
-      loc  = ms_location sum
-      hspp = ml_hspp_file loc
-
+  = [ fn | Just fn <- map (ml_hspp_file.ms_location) summaries ]
 
 -----------------------------------------------------------------------------
 -- getValidLinkables
@@ -1219,12 +1219,10 @@ summariseFile file
    = do hspp_fn <- preprocess file
         (srcimps,imps,mod_name) <- getImportsFromFile hspp_fn
 
-        let (path, basename, ext) = splitFilename3 file
-            -- GHC.Prim doesn't exist physically, so don't go looking for it.
+        let -- GHC.Prim doesn't exist physically, so don't go looking for it.
             the_imps = filter (/= gHC_PRIM_Name) imps
 
-       (mod, location) <- mkHomeModLocation mod_name True{-is a root-}
-                               path basename ext
+       (mod, location) <- mkHomeModLocation mod_name file
 
         src_timestamp
            <- case ml_hs_file location of