- (_,_,mod_name) <-
- if extcoreish_suffix suff
- then do
- -- no explicit imports in ExtCore input.
- m <- getCoreModuleName input_fn
- return ([], [], mkModuleName m)
- else
- getImportsFromFile input_fn
-
- -- build a ModLocation to pass to hscMain.
- (mod, location') <- mkHomeModLocation mod_name (basename ++ '.':suff)
-
- -- take -ohi into account if present
- ohi <- readIORef v_Output_hi
- let location | Just fn <- ohi = location'{ ml_hi_file = fn }
- | otherwise = location'
-
- -- figure out if the source has changed, for recompilation avoidance.
- -- only do this if we're eventually going to generate a .o file.
- -- (ToDo: do when generating .hc files too?)
+ (hspp_buf,mod_name) <-
+ case src_flavour of
+ ExtCoreFile -> do { -- no explicit imports in ExtCore input.
+ ; m <- getCoreModuleName input_fn
+ ; return (Nothing, mkModule m) }
+
+ other -> do { buf <- hGetStringBuffer input_fn
+ ; (_,_,L _ mod_name) <- getImports dflags buf input_fn
+ ; return (Just buf, mod_name) }
+
+ -- Build a ModLocation to pass to hscMain.
+ -- The source filename is rather irrelevant by now, but it's used
+ -- by hscMain for messages. hscMain also needs
+ -- the .hi and .o filenames, and this is as good a way
+ -- as any to generate them, and better than most. (e.g. takes
+ -- into accout the -osuf flags)
+ location1 <- mkHomeModLocation2 dflags mod_name basename suff
+
+ -- Boot-ify it if necessary
+ let location2 | isHsBoot src_flavour = addBootSuffixLocn location1
+ | otherwise = location1
+
+
+ -- Take -ohi into account if present
+ -- This can't be done in mkHomeModuleLocation because
+ -- it only applies to the module being compiles
+ let ohi = outputHi dflags
+ location3 | Just fn <- ohi = location2{ ml_hi_file = fn }
+ | otherwise = location2
+
+ -- Take -o into account if present
+ -- Very like -ohi, but we must *only* do this if we aren't linking
+ -- (If we're linking then the -o applies to the linked thing, not to
+ -- the object file for one module.)
+ -- Note the nasty duplication with the same computation in compileFile above
+ let expl_o_file = outputFile dflags
+ location4 | Just ofile <- expl_o_file
+ , isNoLink (ghcLink dflags)
+ = location3 { ml_obj_file = ofile }
+ | otherwise = location3
+
+ -- Make the ModSummary to hand to hscMain
+ src_timestamp <- getModificationTime (basename `joinFileExt` suff)
+ let
+ unused_field = panic "runPhase:ModSummary field"
+ -- Some fields are not looked at by hscMain
+ mod_summary = ModSummary { ms_mod = mod_name,
+ ms_hsc_src = src_flavour,
+ ms_hspp_file = input_fn,
+ ms_hspp_opts = dflags,
+ ms_hspp_buf = hspp_buf,
+ ms_location = location4,
+ ms_hs_date = src_timestamp,
+ ms_obj_date = Nothing,
+ ms_imps = unused_field,
+ ms_srcimps = unused_field }
+
+ o_file = ml_obj_file location4 -- The real object file
+
+
+ -- Figure out if the source has changed, for recompilation avoidance.