--- path: "/P/Q/R"
--- basename: "foo"
--- extension: "hs"
---
--- and we set the flag is_root to True, to indicate that the basename
--- portion for the .hi file should be replaced by the last component
--- of the module name. eg. if the module name is "A.B.C" then basename
--- will be replaced by "C" for the .hi file only, resulting in an
--- .hi file like "/P/Q/R/C.hi" (subject to -hidir and -hisuf as usual).
-
-mkHomeModLocation mod_name is_root path basename extension = do
-
+-- Parameters are:
+--
+-- mod_name
+-- The name of the module
+--
+-- path
+-- (a): The search path component where the source file was found.
+-- (b) and (c): "."
+--
+-- src_basename
+-- (a): dots_to_slashes (moduleNameUserString mod_name)
+-- (b) and (c): The filename of the source file, minus its extension
+--
+-- ext
+-- The filename extension of the source file (usually "hs" or "lhs").
+
+mkHomeModLocation mod_name src_filename = do
+ let mod_basename = dots_to_slashes (moduleNameUserString mod_name)
+ (basename,extension) = splitFilename src_filename
+
+ case my_prefix_match (reverse mod_basename) (reverse basename) of
+ Just "" ->
+ mkHomeModLocationSearched mod_name "." mod_basename extension
+ Just rest -> do
+ let path = reverse (dropWhile (=='/') rest)
+ mkHomeModLocationSearched mod_name path mod_basename extension
+ Nothing -> do
+ hPutStrLn stderr ("Warning: " ++ src_filename ++
+ ": filename and module name do not match")
+ let (dir,basename,ext) = splitFilename3 src_filename
+ mkHomeModLocationSearched mod_name dir basename ext
+
+mkHomeModLocationSearched mod_name path src_basename ext = do