- osuf <- readIORef v_Object_suf
- extra_suffixes <- readIORef v_Dep_suffixes
- let suffixes = map (++ ('_':osuf)) extra_suffixes
- obj_file = ml_obj_file location
- objs = obj_file : map (replaceFilenameSuffix obj_file) suffixes
-
- -- Handle for file that accumulates dependencies
- hdl <- readIORef v_Dep_tmp_hdl
-
- -- std dependency of the object(s) on the source file
- hPutStrLn hdl (unwords (map escapeSpaces objs) ++ " : " ++
- escapeSpaces (basename ++ '.':suff))
+-----------------------------------------------------------------
+--
+-- processDeps
+--
+-----------------------------------------------------------------
+
+processDeps :: DynFlags
+ -> Handle -- Write dependencies to here
+ -> SCC ModSummary
+ -> IO ()
+-- Write suitable dependencies to handle
+-- Always:
+-- this.o : this.hs
+--
+-- If the dependency is on something other than a .hi file:
+-- this.o this.p_o ... : dep
+-- otherwise
+-- this.o ... : dep.hi
+-- this.p_o ... : dep.p_hi
+-- ...
+-- (where .o is $osuf, and the other suffixes come from
+-- the cmdline -s options).
+--
+-- For {-# SOURCE #-} imports the "hi" will be "hi-boot".
+
+processDeps dflags hdl (CyclicSCC nodes)
+ = -- There shouldn't be any cycles; report them
+ throwDyn (ProgramError (showSDoc $ cyclicModuleErr nodes))
+
+processDeps dflags hdl (AcyclicSCC node)
+ = do { extra_suffixes <- readIORef v_Dep_suffixes
+ ; let src_file = msHsFilePath node
+ obj_file = msObjFilePath node
+ obj_files = insertSuffixes obj_file extra_suffixes
+
+ do_imp is_boot imp_mod
+ = do { mb_hi <- findDependency dflags src_file imp_mod is_boot
+ ; case mb_hi of {
+ Nothing -> return () ;
+ Just hi_file -> do
+ { let hi_files = insertSuffixes hi_file extra_suffixes
+ write_dep (obj,hi) = writeDependency hdl [obj] hi
+
+ -- Add one dependency for each suffix;
+ -- e.g. A.o : B.hi
+ -- A.x_o : B.x_hi
+ ; mapM_ write_dep (obj_files `zip` hi_files) }}}
+
+
+ -- Emit std dependency of the object(s) on the source file
+ -- Something like A.o : A.hs
+ ; writeDependency hdl obj_files src_file
+
+ -- Emit a dependency for each import
+ ; mapM_ (do_imp True) (ms_srcimps node) -- SOURCE imports
+ ; mapM_ (do_imp False) (ms_imps node) -- regular imports
+ }
+
+
+findDependency :: DynFlags
+ -> FilePath -- Importing module: used only for error msg
+ -> Module -- Imported module
+ -> IsBootInterface -- Source import
+ -> IO (Maybe FilePath) -- Interface file file
+findDependency dflags src imp is_boot
+ = do { excl_mods <- readIORef v_Dep_exclude_mods
+ ; include_prelude <- readIORef v_Dep_include_prelude
+
+ -- Deal with the excluded modules
+ ; let imp_mod = moduleUserString imp
+ ; if imp_mod `elem` excl_mods
+ then return Nothing
+ else do
+ { -- Find the module; this will be fast because
+ -- we've done it once during downsweep
+ r <- findModule dflags imp True {-explicit-}
+ ; case r of
+ Found loc pkg
+ -- Not in this package: we don't need a dependency
+ | ExtPackage _ <- pkg, not include_prelude
+ -> return Nothing