From: simonmar Date: Tue, 21 Oct 2003 11:42:30 +0000 (+0000) Subject: [project @ 2003-10-21 11:42:30 by simonmar] X-Git-Tag: Approx_11550_changesets_converted~348 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=8449f6e5ad31e045379ccdf78f479e6e6cb5ce24;p=ghc-hetmet.git [project @ 2003-10-21 11:42:30 by simonmar] Change the filename policies (again). Now the interface file and object file always follow the source file unless the -odir or -hidir options are specified. --- diff --git a/ghc/compiler/main/Finder.lhs b/ghc/compiler/main/Finder.lhs index adc33c7..3137fa2 100644 --- a/ghc/compiler/main/Finder.lhs +++ b/ghc/compiler/main/Finder.lhs @@ -230,16 +230,17 @@ mkPackageModLocation hisuf mod_name path basename _ext = do return result hiOnlyModLocation path basename hisuf - = do { obj_fn <- mkObjPath path basename ; - return (ModLocation{ ml_hspp_file = Nothing, + = do let full_basename = path++'/':basename + obj_fn <- mkObjPath full_basename basename + return ModLocation{ ml_hspp_file = Nothing, ml_hs_file = Nothing, - ml_hi_file = path ++ '/':basename ++ '.':hisuf, + ml_hi_file = full_basename ++ '.':hisuf, -- Remove the .hi-boot suffix from -- hi_file, if it had one. We always -- want the name of the real .hi file -- in the ml_hi_file field. ml_obj_file = obj_fn - })} + } -- ----------------------------------------------------------------------------- -- Constructing a home module location @@ -275,59 +276,57 @@ hiOnlyModLocation path basename hisuf -- 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 maybePrefixMatch (reverse mod_basename) (reverse basename) of - Just "" -> - mkHomeModLocationSearched mod_name "." mod_basename extension - Just rest@(r:_) | isPathSeparator r -> do - let path = reverse (dropWhile (=='/') rest) - mkHomeModLocationSearched mod_name path mod_basename extension - _ -> 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 - hisuf <- readIORef v_Hi_suf - hidir <- readIORef v_Hi_dir - - let mod_basename = dots_to_slashes (moduleNameUserString mod_name) - - obj_fn <- mkObjPath path mod_basename + let (basename,extension) = splitFilename src_filename + mkHomeModLocation' mod_name basename extension - let -- hi filename, always follows the module name - hi_path | Just d <- hidir = d - | otherwise = path +mkHomeModLocationSearched mod_name path basename ext = + mkHomeModLocation' mod_name (path ++ '/':basename) ext - hi_fn = hi_path ++ '/':mod_basename ++ '.':hisuf +mkHomeModLocation' mod_name src_basename ext = do + let mod_basename = dots_to_slashes (moduleNameUserString mod_name) - -- source filename - source_fn = path ++ '/':src_basename ++ '.':ext + obj_fn <- mkObjPath src_basename mod_basename + hi_fn <- mkHiPath src_basename mod_basename - result = ( mkHomeModule mod_name, - ModLocation{ ml_hspp_file = Nothing, - ml_hs_file = Just source_fn, - ml_hi_file = hi_fn, - ml_obj_file = obj_fn, + let result = ( mkHomeModule mod_name, + ModLocation{ ml_hspp_file = Nothing, + ml_hs_file = Just (src_basename ++ '.':ext), + ml_hi_file = hi_fn, + ml_obj_file = obj_fn }) addToFinderCache mod_name result return result -mkObjPath :: FilePath -> String -> IO FilePath --- Construct the filename of a .o file. --- Does *not* check whether the .o file exists -mkObjPath path basename +-- | Constructs the filename of a .o file for a given source file. +-- Does /not/ check whether the .o file exists +mkObjPath + :: FilePath -- the filename of the source file, minus the extension + -> String -- the module name with dots replaced by slashes + -> IO FilePath +mkObjPath basename mod_basename = do odir <- readIORef v_Output_dir osuf <- readIORef v_Object_suf - let obj_path | Just d <- odir = d - | otherwise = path + let obj_basename | Just dir <- odir = dir ++ '/':mod_basename + | otherwise = basename + + return (obj_basename ++ '.':osuf) + +-- | Constructs the filename of a .hi file for a given source file. +-- Does /not/ check whether the .hi file exists +mkHiPath + :: FilePath -- the filename of the source file, minus the extension + -> String -- the module name with dots replaced by slashes + -> IO FilePath +mkHiPath basename mod_basename + = do hidir <- readIORef v_Hi_dir + hisuf <- readIORef v_Hi_suf + + let hi_basename | Just dir <- hidir = dir ++ '/':mod_basename + | otherwise = basename - return (obj_path ++ '/':basename ++ '.':osuf) + return (hi_basename ++ '.':hisuf) -- ----------------------------------------------------------------------------- -- findLinkable isn't related to the other stuff in here, diff --git a/ghc/docs/users_guide/separate_compilation.sgml b/ghc/docs/users_guide/separate_compilation.sgml index f9a06bf..fe51108 100644 --- a/ghc/docs/users_guide/separate_compilation.sgml +++ b/ghc/docs/users_guide/separate_compilation.sgml @@ -79,121 +79,61 @@ Every module has a module name defined in its source code (module A.B.C where - ...). Unless overridden with the - -o and -ohi flags - respectively, GHC always puts the object file for module - A.B.C in - odir/A/B/C.osuf, - and the interface file in the file - hidir/A/B/C.hisuf, - where hidir, - hisuf, - odir, and - osuf, defined as follows: + ...). - - - hidir - - is the value of the option if - one was given (), or - root-path otherwise. - - - - hisuf - - is the value of the option if - one was given (), or hi - otherwise. - - - - - odir - - is the value of the option if - one was given (), or - root-path otherwise. - - - - osuf - - is the value of the option if - one was given (), or o - otherwise (obj on Windows). - - - - - The root-path, used in the above definitions, is derived from the - location of the source file, source-filename, as follows: + The name of the object file generated by GHC is derived + according to the following rules, where + osuf is the object-file suffix (this + can be changed with the option). - - - Rule 1 - - GHC matches source-filename against the pattern: - - root-path/A/B/C.extension - - where: + + + If there is no option (the + default), then the object filename is derived from the + source filename by replacing the suffix with + osuf. + + + If +  dir + has been specified, then the object filename is + dir/mod.osuf, + where mod is the module name with + dots replaced by slashes. + + - - - extension - - is the source file extension (usually - .hs or .lhs). - - - - root-path - - is what is left after A/B/C.extension - has been stripped off the end of source-file. - - - - - - - - - Rule 2 - - If source-filename does not match the pattern - above (presumably because it doesn't finish with A/B/C.hs - or A/B/C.lhs) - then root-path becomes the - whole of the directory portion of the filename. - - - + The name of the interface file is derived using the same + rules, except that the suffix is + hisuf (.hi by + default) instead of osuf, and the + relevant options are and + instead of and + respectively. - For example, if GHC compiles the module + For example, if GHC compiles the module A.B.C in the file - src/A/B/C.hs, with no -odir or -hidir flags, - the interface file will be put in src/A/B/C.hi and the object file in - src/A/B/C.o (using Rule 1). - If the same module A.B.C was in file - src/ABC.hs, - the interface file will still be put in src/A/B/C.hi and the object file in - src/A/B/C.o (using Rule 2). - - A common use for Rule 2 is to have many modules all called Main held in - files Test1.hs Test2.hs, etc. Beware, though: when compiling - (say) Test2.hs, GHC will consult Main.hi for version information - from the last recompilation. Currently (a bug, really) GHC is not clever enough to spot that the source file has changed, - and so there is a danger that the recompilation checker will declare that no recompilation is needed when in fact it is. - Solution: delete the interface file first. - - Notice that (unless overriden with or ) the filenames - of the object and interface files are always based on the module name. The reason for this is so that - GHC can find the interface file for module A.B.C when compiling the declaration - "import A.B.C". - + src/A/B/C.hs, with no + -odir or -hidir flags, the + interface file will be put in src/A/B/C.hi + and the object file in src/A/B/C.o. + + Note that it is reasonable to have a module + Main in a file named + foo.hs, but this only works because GHC + never needs to search for the interface for module + Main (because it is never imported). It is + therefore possible to have several Main + modules in separate source files in the same directory, and GHC + will not get confused. For modules other than + Main, it is strongly recommended that you + name the source file after the module name, replacing dots with + slashes in hierarchical module names. + + In batch compilation mode, the name of the object file can + also be overriden using the option, and the + name of the interface file can be specified directly using the + option.