- hs = basename ++ ".hs"
- lhs = basename ++ ".lhs"
-
- found <- findOnPath home_path hs
- case found of {
- -- special case to avoid getting "./foo.hs" all the time
- Just "." -> mkHomeModuleLocn mod_name basename (Just hs);
- Just path -> mkHomeModuleLocn mod_name
- (path ++ '/':basename) (Just (path ++ '/':hs));
- Nothing -> do
-
- found <- findOnPath home_path lhs
- case found of {
- -- special case to avoid getting "./foo.hs" all the time
- Just "." -> mkHomeModuleLocn mod_name basename (Just lhs);
- Just path -> mkHomeModuleLocn mod_name
- (path ++ '/':basename) (Just (path ++ '/':lhs));
- Nothing -> do
-
- -- can't find a source file anywhere, check for a lone .hi file.
- hisuf <- readIORef v_Hi_suf
- let hi = basename ++ '.':hisuf
- found <- findOnPath home_path hi
- case found of {
- Just path -> mkHiOnlyModuleLocn mod_name hi;
- Nothing -> do
-
- -- last chance: .hi-boot-<ver> and .hi-boot
- let hi_boot = basename ++ ".hi-boot"
- let hi_boot_ver = basename ++ ".hi-boot-" ++ cHscIfaceFileVersion
- found <- findOnPath home_path hi_boot_ver
- case found of {
- Just path -> mkHiOnlyModuleLocn mod_name hi;
- Nothing -> do
- found <- findOnPath home_path hi_boot
- case found of {
- Just path -> mkHiOnlyModuleLocn mod_name hi;
- Nothing -> return Nothing
- }}}}}
-
-
-mkHiOnlyModuleLocn mod_name hi_file = do
- return (Just (mkHomeModule mod_name,
- ModuleLocation{
- ml_hspp_file = Nothing,
- ml_hs_file = Nothing,
- ml_hi_file = hi_file,
- ml_obj_file = Nothing
- }
- ))
+
+ -- In compilation manager modes, we look for source files in the home
+ -- package because we can compile these automatically. In one-shot
+ -- compilation mode we look for .hi files only.
+ --
+ -- When generating dependencies, we're interested in either category.
+ --
+ source_exts =
+ [ ("hs", \ _ fName path -> mkHomeModuleLocn mod_name path fName)
+ , ("lhs", \ _ fName path -> mkHomeModuleLocn mod_name path fName)
+ ]
+ hi_exts = [ (hisuf, \ _ fName path -> mkHiOnlyModuleLocn mod_name fName) ]
+
+ std_exts
+ | mode == DoMkDependHS = hi_exts ++ source_exts
+ | isCompManagerMode mode = source_exts
+ | otherwise = hi_exts
+
+ -- last chance: .hi-boot-<ver> and .hi-boot
+ hi_boot_ver = "hi-boot-" ++ cHscIfaceFileVersion
+
+ boot_exts =
+ [ (hi_boot_ver, \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
+ , ("hi-boot", \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
+ ]
+
+ searchPathExts
+ (map ((,) undefined) home_path)
+ basename
+ (if is_source then (boot_exts++std_exts) else std_exts ++ boot_exts)
+ -- for SOURCE imports, check the hi-boot extensions
+ -- before the source/iface ones, to avoid
+ -- creating circ Makefile deps.
+
+mkHiOnlyModuleLocn mod_name hi_file =
+ return
+ ( mkHomeModule mod_name
+ , ModuleLocation{ ml_hspp_file = Nothing
+ , ml_hs_file = Nothing
+ , ml_hi_file = hi_file
+ , ml_obj_file = Nothing
+ }
+ )