1 -----------------------------------------------------------------------------
5 -- (c) The University of Glasgow 2005
7 -----------------------------------------------------------------------------
9 module DriverPipeline (
10 -- Run a series of compilation steps in a pipeline, for a
11 -- collection of source files.
14 -- Interfaces for the batch-mode driver
17 -- Interfaces for the compilation manager (interpreted/batch-mode)
19 compile, CompResult(..),
27 #include "HsVersions.h"
33 import qualified SysTools
39 import UniqFM ( eltsUFM )
42 import StaticFlags ( v_Ld_inputs, opt_Static, WayName(..) )
46 import StringBuffer ( hGetStringBuffer )
47 import BasicTypes ( SuccessFlag(..) )
48 import Maybes ( expectJust )
49 import ParserCoreUtils ( getCoreModuleName )
50 import SrcLoc ( unLoc )
51 import SrcLoc ( Located(..) )
53 import Control.Exception as Exception
54 import Data.IORef ( readIORef, writeIORef, IORef )
55 import GHC.Exts ( Int(..) )
56 import System.Directory
58 import SYSTEM_IO_ERROR as IO
60 import Data.List ( isSuffixOf )
64 import System.Environment
66 -- ---------------------------------------------------------------------------
69 -- Just preprocess a file, put the result in a temp. file (used by the
70 -- compilation manager during the summary phase).
72 -- We return the augmented DynFlags, because they contain the result
73 -- of slurping in the OPTIONS pragmas
75 preprocess :: DynFlags -> (FilePath, Maybe Phase) -> IO (DynFlags, FilePath)
76 preprocess dflags (filename, mb_phase) =
77 ASSERT2(isJust mb_phase || isHaskellSrcFilename filename, text filename)
78 runPipeline anyHsc dflags (filename, mb_phase)
79 Nothing Temporary Nothing{-no ModLocation-}
81 -- ---------------------------------------------------------------------------
84 -- Compile a single module, under the control of the compilation manager.
86 -- This is the interface between the compilation manager and the
87 -- compiler proper (hsc), where we deal with tedious details like
88 -- reading the OPTIONS pragma from the source file, and passing the
89 -- output of hsc through the C compiler.
91 -- NB. No old interface can also mean that the source has changed.
95 -> Maybe Linkable -- Just linkable <=> source unchanged
96 -> Maybe ModIface -- Old interface, if available
101 = CompOK ModDetails -- New details
102 ModIface -- New iface
103 (Maybe Linkable) -- a Maybe, for the same reasons as hm_linkable
108 compile hsc_env mod_summary maybe_old_linkable old_iface mod_index nmods = do
110 let dflags0 = ms_hspp_opts mod_summary
111 this_mod = ms_mod mod_summary
112 src_flavour = ms_hsc_src mod_summary
115 | Just l <- maybe_old_linkable, isObjectLinkable l = True
118 -- FIXME: We need to know whether or not we're recompiling the file. Move this to HscMain?
119 --showPass dflags0 ("Compiling " ++ showModMsg have_object mod_summary)
121 let location = ms_location mod_summary
122 let input_fn = expectJust "compile:hs" (ml_hs_file location)
123 let input_fnpp = ms_hspp_file mod_summary
125 debugTraceMsg dflags0 2 (text "compile: input file" <+> text input_fnpp)
127 let (basename, _) = splitFilename input_fn
129 -- We add the directory in which the .hs files resides) to the import path.
130 -- This is needed when we try to compile the .hc file later, if it
131 -- imports a _stub.h file that we created here.
132 let current_dir = directoryOf basename
133 old_paths = includePaths dflags0
134 dflags = dflags0 { includePaths = current_dir : old_paths }
136 -- Figure out what lang we're generating
137 let hsc_lang = hscMaybeAdjustTarget dflags StopLn src_flavour (hscTarget dflags)
138 -- ... and what the next phase should be
139 let next_phase = hscNextPhase dflags src_flavour hsc_lang
140 -- ... and what file to generate the output into
141 output_fn <- getOutputFilename next_phase
142 Temporary basename dflags next_phase (Just location)
144 let dflags' = dflags { hscTarget = hsc_lang,
145 hscOutName = output_fn,
146 extCoreName = basename ++ ".hcr" }
148 -- -no-recomp should also work with --make
149 let force_recomp = dopt Opt_ForceRecomp dflags
150 source_unchanged = isJust maybe_old_linkable && not force_recomp
151 hsc_env' = hsc_env { hsc_dflags = dflags' }
152 object_filename = ml_obj_file location
154 let getStubLinkable False = return []
156 = do stub_o <- compileStub dflags' this_mod location
157 return [ DotO stub_o ]
159 handleBatch (HscNoRecomp, iface, details)
160 = ASSERT (isJust maybe_old_linkable)
161 return (CompOK details iface maybe_old_linkable)
162 handleBatch (HscRecomp hasStub, iface, details)
163 | isHsBoot src_flavour
164 = return (CompOK details iface Nothing)
166 = do stub_unlinked <- getStubLinkable hasStub
167 (hs_unlinked, unlinked_time) <-
170 -> return ([], ms_hs_date mod_summary)
171 -- We're in --make mode: finish the compilation pipeline.
173 -> do runPipeline StopLn dflags (output_fn,Nothing)
177 -- The object filename comes from the ModLocation
178 o_time <- getModificationTime object_filename
179 return ([DotO object_filename], o_time)
180 let linkable = LM unlinked_time this_mod
181 (hs_unlinked ++ stub_unlinked)
182 return (CompOK details iface (Just linkable))
184 handleInterpreted (InteractiveNoRecomp, iface, details)
185 = ASSERT (isJust maybe_old_linkable)
186 return (CompOK details iface maybe_old_linkable)
187 handleInterpreted (InteractiveRecomp hasStub comp_bc, iface, details)
188 = do stub_unlinked <- getStubLinkable hasStub
189 let hs_unlinked = [BCOs comp_bc]
190 unlinked_time = ms_hs_date mod_summary
191 -- Why do we use the timestamp of the source file here,
192 -- rather than the current time? This works better in
193 -- the case where the local clock is out of sync
194 -- with the filesystem's clock. It's just as accurate:
195 -- if the source is modified, then the linkable will
197 let linkable = LM unlinked_time this_mod
198 (hs_unlinked ++ stub_unlinked)
199 return (CompOK details iface (Just linkable))
201 let runCompiler compiler handle
202 = do mbResult <- compiler hsc_env' mod_summary
203 source_unchanged old_iface
204 (Just (mod_index, nmods))
206 Nothing -> return CompErrs
207 Just result -> handle result
210 HscInterpreted | not (isHsBoot src_flavour) -- We can't compile boot files to
211 -- bytecode so don't even try.
212 -> runCompiler hscCompileInteractive handleInterpreted
214 -> runCompiler hscCompileNothing handleBatch
216 -> runCompiler hscCompileBatch handleBatch
218 -----------------------------------------------------------------------------
219 -- stub .h and .c files (for foreign export support)
221 -- The _stub.c file is derived from the haskell source file, possibly taking
222 -- into account the -stubdir option.
224 -- Consequently, we derive the _stub.o filename from the haskell object
227 -- This isn't necessarily the same as the object filename we
228 -- would get if we just compiled the _stub.c file using the pipeline.
231 -- ghc src/A.hs -odir obj
233 -- results in obj/A.o, and src/A_stub.c. If we compile src/A_stub.c with
234 -- -odir obj, we would get obj/src/A_stub.o, which is wrong; we want
237 compileStub :: DynFlags -> Module -> ModLocation -> IO FilePath
238 compileStub dflags mod location = do
239 let (o_base, o_ext) = splitFilename (ml_obj_file location)
240 stub_o = o_base ++ "_stub" `joinFileExt` o_ext
242 -- compile the _stub.c file w/ gcc
243 let (stub_c,_) = mkStubPaths dflags (moduleName mod) location
244 runPipeline StopLn dflags (stub_c,Nothing) Nothing
245 (SpecificFile stub_o) Nothing{-no ModLocation-}
250 -- ---------------------------------------------------------------------------
253 link :: GhcLink -- interactive or batch
254 -> DynFlags -- dynamic flags
255 -> Bool -- attempt linking in batch mode?
256 -> HomePackageTable -- what to link
259 -- For the moment, in the batch linker, we don't bother to tell doLink
260 -- which packages to link -- it just tries all that are available.
261 -- batch_attempt_linking should only be *looked at* in batch mode. It
262 -- should only be True if the upsweep was successful and someone
263 -- exports main, i.e., we have good reason to believe that linking
267 link LinkInMemory dflags batch_attempt_linking hpt
268 = do -- Not Linking...(demand linker will do the job)
272 link NoLink dflags batch_attempt_linking hpt
275 link LinkBinary dflags batch_attempt_linking hpt
276 | batch_attempt_linking
279 home_mod_infos = eltsUFM hpt
281 -- the packages we depend on
282 pkg_deps = concatMap (dep_pkgs . mi_deps . hm_iface) home_mod_infos
284 -- the linkables to link
285 linkables = map (expectJust "link".hm_linkable) home_mod_infos
287 debugTraceMsg dflags 3 (text "link: linkables are ..." $$ vcat (map ppr linkables))
289 -- check for the -no-link flag
290 if isNoLink (ghcLink dflags)
291 then do debugTraceMsg dflags 3 (text "link(batch): linking omitted (-c flag given).")
295 let getOfiles (LM _ _ us) = map nameOfObject (filter isObject us)
296 obj_files = concatMap getOfiles linkables
298 exe_file = exeFileName dflags
300 -- if the modification time on the executable is later than the
301 -- modification times on all of the objects, then omit linking
302 -- (unless the -no-recomp flag was given).
303 e_exe_time <- IO.try $ getModificationTime exe_file
305 | Left _ <- e_exe_time = True
306 | Right t <- e_exe_time =
307 any (t <) (map linkableTime linkables)
309 if not (dopt Opt_ForceRecomp dflags) && not linking_needed
310 then do debugTraceMsg dflags 2 (text exe_file <+> ptext SLIT("is up to date, linking not required."))
314 debugTraceMsg dflags 1 (ptext SLIT("Linking") <+> text exe_file
317 -- Don't showPass in Batch mode; doLink will do that for us.
318 let link = case ghcLink dflags of
320 LinkBinary -> staticLink
321 link dflags obj_files pkg_deps
323 debugTraceMsg dflags 3 (text "link: done")
325 -- staticLink only returns if it succeeds
329 = do debugTraceMsg dflags 3 (text "link(batch): upsweep (partially) failed OR" $$
330 text " Main.main not exported; not linking.")
334 -- -----------------------------------------------------------------------------
335 -- Compile files in one-shot mode.
337 oneShot :: DynFlags -> Phase -> [(String, Maybe Phase)] -> IO ()
338 oneShot dflags stop_phase srcs = do
339 o_files <- mapM (compileFile dflags stop_phase) srcs
340 doLink dflags stop_phase o_files
342 compileFile :: DynFlags -> Phase -> (FilePath, Maybe Phase) -> IO FilePath
343 compileFile dflags stop_phase (src, mb_phase) = do
344 exists <- doesFileExist src
346 throwDyn (CmdLineError ("does not exist: " ++ src))
349 split = dopt Opt_SplitObjs dflags
350 mb_o_file = outputFile dflags
351 ghc_link = ghcLink dflags -- Set by -c or -no-link
353 -- When linking, the -o argument refers to the linker's output.
354 -- otherwise, we use it as the name for the pipeline's output.
356 | StopLn <- stop_phase, not (isNoLink ghc_link) = Persistent
357 -- -o foo applies to linker
358 | Just o_file <- mb_o_file = SpecificFile o_file
359 -- -o foo applies to the file we are compiling now
360 | otherwise = Persistent
362 stop_phase' = case stop_phase of
363 As | split -> SplitAs
366 (_, out_file) <- runPipeline stop_phase' dflags
367 (src, mb_phase) Nothing output
368 Nothing{-no ModLocation-}
372 doLink :: DynFlags -> Phase -> [FilePath] -> IO ()
373 doLink dflags stop_phase o_files
374 | not (isStopLn stop_phase)
375 = return () -- We stopped before the linking phase
378 = case ghcLink dflags of
380 LinkBinary -> staticLink dflags o_files link_pkgs
381 MkDLL -> doMkDLL dflags o_files link_pkgs
383 -- Always link in the haskell98 package for static linking. Other
384 -- packages have to be specified via the -package flag.
385 link_pkgs = [haskell98PackageId]
388 -- ---------------------------------------------------------------------------
389 -- Run a compilation pipeline, consisting of multiple phases.
391 -- This is the interface to the compilation pipeline, which runs
392 -- a series of compilation steps on a single source file, specifying
393 -- at which stage to stop.
395 -- The DynFlags can be modified by phases in the pipeline (eg. by
396 -- GHC_OPTIONS pragmas), and the changes affect later phases in the
401 -- output should be to a temporary file: we're going to
402 -- run more compilation steps on this output later
404 -- we want a persistent file, i.e. a file in the current directory
405 -- derived from the input filename, but with the appropriate extension.
406 -- eg. in "ghc -c Foo.hs" the output goes into ./Foo.o.
407 | SpecificFile FilePath
408 -- the output must go into the specified file.
411 :: Phase -- When to stop
412 -> DynFlags -- Dynamic flags
413 -> (FilePath,Maybe Phase) -- Input filename (and maybe -x suffix)
414 -> Maybe FilePath -- original basename (if different from ^^^)
415 -> PipelineOutput -- Output filename
416 -> Maybe ModLocation -- A ModLocation, if this is a Haskell module
417 -> IO (DynFlags, FilePath) -- (final flags, output filename)
419 runPipeline stop_phase dflags (input_fn, mb_phase) mb_basename output maybe_loc
421 let (input_basename, suffix) = splitFilename input_fn
422 basename | Just b <- mb_basename = b
423 | otherwise = input_basename
425 -- If we were given a -x flag, then use that phase to start from
426 start_phase = fromMaybe (startPhase suffix) mb_phase
428 -- We want to catch cases of "you can't get there from here" before
429 -- we start the pipeline, because otherwise it will just run off the
432 -- There is a partial ordering on phases, where A < B iff A occurs
433 -- before B in a normal compilation pipeline.
435 when (not (start_phase `happensBefore` stop_phase)) $
437 ("cannot compile this file to desired target: "
440 -- this is a function which will be used to calculate output file names
441 -- as we go along (we partially apply it to some of its inputs here)
442 let get_output_fn = getOutputFilename stop_phase output basename
444 -- Execute the pipeline...
445 (dflags', output_fn, maybe_loc) <-
446 pipeLoop dflags start_phase stop_phase input_fn
447 basename suffix get_output_fn maybe_loc
449 -- Sometimes, a compilation phase doesn't actually generate any output
450 -- (eg. the CPP phase when -fcpp is not turned on). If we end on this
451 -- stage, but we wanted to keep the output, then we have to explicitly
452 -- copy the file, remembering to prepend a {-# LINE #-} pragma so that
453 -- further compilation stages can tell what the original filename was.
456 return (dflags', output_fn)
458 do final_fn <- get_output_fn dflags' stop_phase maybe_loc
459 when (final_fn /= output_fn) $ do
460 let msg = ("Copying `" ++ output_fn ++"' to `" ++ final_fn ++ "'")
461 line_prag = Just ("{-# LINE 1 \"" ++ input_fn ++ "\" #-}\n")
462 copyWithHeader dflags msg line_prag output_fn final_fn
463 return (dflags', final_fn)
467 pipeLoop :: DynFlags -> Phase -> Phase
468 -> FilePath -> String -> Suffix
469 -> (DynFlags -> Phase -> Maybe ModLocation -> IO FilePath)
471 -> IO (DynFlags, FilePath, Maybe ModLocation)
473 pipeLoop dflags phase stop_phase
474 input_fn orig_basename orig_suff
475 orig_get_output_fn maybe_loc
477 | phase `eqPhase` stop_phase -- All done
478 = return (dflags, input_fn, maybe_loc)
480 | not (phase `happensBefore` stop_phase)
481 -- Something has gone wrong. We'll try to cover all the cases when
482 -- this could happen, so if we reach here it is a panic.
483 -- eg. it might happen if the -C flag is used on a source file that
484 -- has {-# OPTIONS -fasm #-}.
485 = panic ("pipeLoop: at phase " ++ show phase ++
486 " but I wanted to stop at phase " ++ show stop_phase)
489 = do { (next_phase, dflags', maybe_loc, output_fn)
490 <- runPhase phase stop_phase dflags orig_basename
491 orig_suff input_fn orig_get_output_fn maybe_loc
492 ; pipeLoop dflags' next_phase stop_phase output_fn
493 orig_basename orig_suff orig_get_output_fn maybe_loc }
496 :: Phase -> PipelineOutput -> String
497 -> DynFlags -> Phase{-next phase-} -> Maybe ModLocation -> IO FilePath
498 getOutputFilename stop_phase output basename
501 func dflags next_phase maybe_location
502 | is_last_phase, Persistent <- output = persistent_fn
503 | is_last_phase, SpecificFile f <- output = return f
504 | keep_this_output = persistent_fn
505 | otherwise = newTempName dflags suffix
508 odir = objectDir dflags
509 osuf = objectSuf dflags
510 keep_hc = dopt Opt_KeepHcFiles dflags
511 keep_raw_s = dopt Opt_KeepRawSFiles dflags
512 keep_s = dopt Opt_KeepSFiles dflags
514 myPhaseInputExt HCc = hcsuf
515 myPhaseInputExt StopLn = osuf
516 myPhaseInputExt other = phaseInputExt other
518 is_last_phase = next_phase `eqPhase` stop_phase
520 -- sometimes, we keep output from intermediate stages
524 Mangle | keep_raw_s -> True
526 HCc | keep_hc -> True
529 suffix = myPhaseInputExt next_phase
531 -- persistent object files get put in odir
533 | StopLn <- next_phase = return odir_persistent
534 | otherwise = return persistent
536 persistent = basename `joinFileExt` suffix
539 | Just loc <- maybe_location = ml_obj_file loc
540 | Just d <- odir = d `joinFileName` persistent
541 | otherwise = persistent
544 -- -----------------------------------------------------------------------------
545 -- Each phase in the pipeline returns the next phase to execute, and the
546 -- name of the file in which the output was placed.
548 -- We must do things dynamically this way, because we often don't know
549 -- what the rest of the phases will be until part-way through the
550 -- compilation: for example, an {-# OPTIONS -fasm #-} at the beginning
551 -- of a source file can change the latter stages of the pipeline from
552 -- taking the via-C route to using the native code generator.
554 runPhase :: Phase -- Do this phase first
555 -> Phase -- Stop just before this phase
557 -> String -- basename of original input source
558 -> String -- its extension
559 -> FilePath -- name of file which contains the input to this phase.
560 -> (DynFlags -> Phase -> Maybe ModLocation -> IO FilePath)
561 -- how to calculate the output filename
562 -> Maybe ModLocation -- the ModLocation, if we have one
563 -> IO (Phase, -- next phase
564 DynFlags, -- new dynamic flags
565 Maybe ModLocation, -- the ModLocation, if we have one
566 FilePath) -- output filename
568 -- Invariant: the output filename always contains the output
569 -- Interesting case: Hsc when there is no recompilation to do
570 -- Then the output filename is still a .o file
572 -------------------------------------------------------------------------------
575 runPhase (Unlit sf) _stop dflags _basename _suff input_fn get_output_fn maybe_loc
576 = do let unlit_flags = getOpts dflags opt_L
577 -- The -h option passes the file name for unlit to put in a #line directive
578 output_fn <- get_output_fn dflags (Cpp sf) maybe_loc
580 SysTools.runUnlit dflags
581 (map SysTools.Option unlit_flags ++
582 [ SysTools.Option "-h"
583 , SysTools.Option input_fn
584 , SysTools.FileOption "" input_fn
585 , SysTools.FileOption "" output_fn
588 return (Cpp sf, dflags, maybe_loc, output_fn)
590 -------------------------------------------------------------------------------
591 -- Cpp phase : (a) gets OPTIONS out of file
592 -- (b) runs cpp if necessary
594 runPhase (Cpp sf) _stop dflags0 basename suff input_fn get_output_fn maybe_loc
595 = do src_opts <- getOptionsFromFile input_fn
596 (dflags,unhandled_flags) <- parseDynamicFlags dflags0 (map unLoc src_opts)
597 checkProcessArgsResult unhandled_flags (basename `joinFileExt` suff)
599 if not (dopt Opt_Cpp dflags) then
600 -- no need to preprocess CPP, just pass input file along
601 -- to the next phase of the pipeline.
602 return (HsPp sf, dflags, maybe_loc, input_fn)
604 output_fn <- get_output_fn dflags (HsPp sf) maybe_loc
605 doCpp dflags True{-raw-} False{-no CC opts-} input_fn output_fn
606 return (HsPp sf, dflags, maybe_loc, output_fn)
608 -------------------------------------------------------------------------------
611 runPhase (HsPp sf) _stop dflags basename suff input_fn get_output_fn maybe_loc
612 = do if not (dopt Opt_Pp dflags) then
613 -- no need to preprocess, just pass input file along
614 -- to the next phase of the pipeline.
615 return (Hsc sf, dflags, maybe_loc, input_fn)
617 let hspp_opts = getOpts dflags opt_F
618 let orig_fn = basename `joinFileExt` suff
619 output_fn <- get_output_fn dflags (Hsc sf) maybe_loc
620 SysTools.runPp dflags
621 ( [ SysTools.Option orig_fn
622 , SysTools.Option input_fn
623 , SysTools.FileOption "" output_fn
625 map SysTools.Option hspp_opts
627 return (Hsc sf, dflags, maybe_loc, output_fn)
629 -----------------------------------------------------------------------------
632 -- Compilation of a single module, in "legacy" mode (_not_ under
633 -- the direction of the compilation manager).
634 runPhase (Hsc src_flavour) stop dflags0 basename suff input_fn get_output_fn _maybe_loc
635 = do -- normal Hsc mode, not mkdependHS
637 -- we add the current directory (i.e. the directory in which
638 -- the .hs files resides) to the import path, since this is
639 -- what gcc does, and it's probably what you want.
640 let current_dir = directoryOf basename
642 paths = includePaths dflags0
643 dflags = dflags0 { includePaths = current_dir : paths }
645 -- gather the imports and module name
646 (hspp_buf,mod_name) <-
648 ExtCoreFile -> do { -- no explicit imports in ExtCore input.
649 ; m <- getCoreModuleName input_fn
650 ; return (Nothing, mkModuleName m) }
652 other -> do { buf <- hGetStringBuffer input_fn
653 ; (_,_,L _ mod_name) <- getImports dflags buf input_fn
654 ; return (Just buf, mod_name) }
656 -- Build a ModLocation to pass to hscMain.
657 -- The source filename is rather irrelevant by now, but it's used
658 -- by hscMain for messages. hscMain also needs
659 -- the .hi and .o filenames, and this is as good a way
660 -- as any to generate them, and better than most. (e.g. takes
661 -- into accout the -osuf flags)
662 location1 <- mkHomeModLocation2 dflags mod_name basename suff
664 -- Boot-ify it if necessary
665 let location2 | isHsBoot src_flavour = addBootSuffixLocn location1
666 | otherwise = location1
669 -- Take -ohi into account if present
670 -- This can't be done in mkHomeModuleLocation because
671 -- it only applies to the module being compiles
672 let ohi = outputHi dflags
673 location3 | Just fn <- ohi = location2{ ml_hi_file = fn }
674 | otherwise = location2
676 -- Take -o into account if present
677 -- Very like -ohi, but we must *only* do this if we aren't linking
678 -- (If we're linking then the -o applies to the linked thing, not to
679 -- the object file for one module.)
680 -- Note the nasty duplication with the same computation in compileFile above
681 let expl_o_file = outputFile dflags
682 location4 | Just ofile <- expl_o_file
683 , isNoLink (ghcLink dflags)
684 = location3 { ml_obj_file = ofile }
685 | otherwise = location3
687 o_file = ml_obj_file location4 -- The real object file
690 -- Figure out if the source has changed, for recompilation avoidance.
692 -- Setting source_unchanged to True means that M.o seems
693 -- to be up to date wrt M.hs; so no need to recompile unless imports have
694 -- changed (which the compiler itself figures out).
695 -- Setting source_unchanged to False tells the compiler that M.o is out of
696 -- date wrt M.hs (or M.o doesn't exist) so we must recompile regardless.
697 src_timestamp <- getModificationTime (basename `joinFileExt` suff)
699 let force_recomp = dopt Opt_ForceRecomp dflags
701 if force_recomp || not (isStopLn stop)
702 -- Set source_unchanged to False unconditionally if
703 -- (a) recompilation checker is off, or
704 -- (b) we aren't going all the way to .o file (e.g. ghc -S)
706 -- Otherwise look at file modification dates
707 else do o_file_exists <- doesFileExist o_file
709 then return False -- Need to recompile
710 else do t2 <- getModificationTime o_file
711 if t2 > src_timestamp
716 let hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags)
717 let next_phase = hscNextPhase dflags src_flavour hsc_lang
718 output_fn <- get_output_fn dflags next_phase (Just location4)
720 let dflags' = dflags { hscTarget = hsc_lang,
721 hscOutName = output_fn,
722 extCoreName = basename ++ ".hcr" }
724 hsc_env <- newHscEnv dflags'
726 -- Tell the finder cache about this module
727 mod <- addHomeModuleToFinder hsc_env mod_name location4
729 -- Make the ModSummary to hand to hscMain
731 unused_field = panic "runPhase:ModSummary field"
732 -- Some fields are not looked at by hscMain
733 mod_summary = ModSummary { ms_mod = mod,
734 ms_hsc_src = src_flavour,
735 ms_hspp_file = input_fn,
736 ms_hspp_opts = dflags,
737 ms_hspp_buf = hspp_buf,
738 ms_location = location4,
739 ms_hs_date = src_timestamp,
740 ms_obj_date = Nothing,
741 ms_imps = unused_field,
742 ms_srcimps = unused_field }
745 mbResult <- hscCompileOneShot hsc_env
746 mod_summary source_unchanged
748 Nothing -- No "module i of n" progress info
751 Nothing -> throwDyn (PhaseFailed "hsc" (ExitFailure 1))
753 -> do SysTools.touch dflags' "Touching object file" o_file
754 -- The .o file must have a later modification date
755 -- than the source file (else we wouldn't be in HscNoRecomp)
756 -- but we touch it anyway, to keep 'make' happy (we think).
757 return (StopLn, dflags', Just location4, o_file)
758 Just (HscRecomp hasStub)
760 do stub_o <- compileStub dflags' mod location4
761 consIORef v_Ld_inputs stub_o
762 -- In the case of hs-boot files, generate a dummy .o-boot
763 -- stamp file for the benefit of Make
764 when (isHsBoot src_flavour) $
765 SysTools.touch dflags' "Touching object file" o_file
766 return (next_phase, dflags', Just location4, output_fn)
768 -----------------------------------------------------------------------------
771 runPhase CmmCpp stop dflags basename suff input_fn get_output_fn maybe_loc
773 output_fn <- get_output_fn dflags Cmm maybe_loc
774 doCpp dflags False{-not raw-} True{-include CC opts-} input_fn output_fn
775 return (Cmm, dflags, maybe_loc, output_fn)
777 runPhase Cmm stop dflags basename suff input_fn get_output_fn maybe_loc
779 let hsc_lang = hscMaybeAdjustTarget dflags stop HsSrcFile (hscTarget dflags)
780 let next_phase = hscNextPhase dflags HsSrcFile hsc_lang
781 output_fn <- get_output_fn dflags next_phase maybe_loc
783 let dflags' = dflags { hscTarget = hsc_lang,
784 hscOutName = output_fn,
785 extCoreName = basename ++ ".hcr" }
787 ok <- hscCmmFile dflags' input_fn
789 when (not ok) $ throwDyn (PhaseFailed "cmm" (ExitFailure 1))
791 return (next_phase, dflags, maybe_loc, output_fn)
793 -----------------------------------------------------------------------------
796 -- we don't support preprocessing .c files (with -E) now. Doing so introduces
797 -- way too many hacks, and I can't say I've ever used it anyway.
799 runPhase cc_phase stop dflags basename suff input_fn get_output_fn maybe_loc
800 | cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc
801 = do let cc_opts = getOpts dflags opt_c
802 hcc = cc_phase `eqPhase` HCc
804 let cmdline_include_paths = includePaths dflags
806 -- HC files have the dependent packages stamped into them
807 pkgs <- if hcc then getHCFilePackages input_fn else return []
809 -- add package include paths even if we're just compiling .c
810 -- files; this is the Value Add(TM) that using ghc instead of
812 pkg_include_dirs <- getPackageIncludePath dflags pkgs
813 let include_paths = foldr (\ x xs -> "-I" : x : xs) []
814 (cmdline_include_paths ++ pkg_include_dirs)
816 let (md_c_flags, md_regd_c_flags) = machdepCCOpts dflags
817 let pic_c_flags = picCCOpts dflags
819 let verb = getVerbFlag dflags
821 pkg_extra_cc_opts <- getPackageExtraCcOpts dflags pkgs
823 let split_objs = dopt Opt_SplitObjs dflags
824 split_opt | hcc && split_objs = [ "-DUSE_SPLIT_MARKERS" ]
827 let excessPrecision = dopt Opt_ExcessPrecision dflags
829 let cc_opt | optLevel dflags >= 2 = "-O2"
834 let mangle = dopt Opt_DoAsmMangling dflags
836 | hcc && mangle = Mangle
838 output_fn <- get_output_fn dflags next_phase maybe_loc
843 -- on x86 the floating point regs have greater precision
844 -- than a double, which leads to unpredictable results.
845 -- By default, we turn this off with -ffloat-store unless
846 -- the user specified -fexcess-precision.
847 (if excessPrecision then [] else [ "-ffloat-store" ]) ++
849 -- gcc's -fstrict-aliasing allows two accesses to memory
850 -- to be considered non-aliasing if they have different types.
851 -- This interacts badly with the C code we generate, which is
852 -- very weakly typed, being derived from C--.
853 ["-fno-strict-aliasing"]
857 SysTools.runCc dflags (
858 -- force the C compiler to interpret this file as C when
859 -- compiling .hc files, by adding the -x c option.
860 -- Also useful for plain .c files, just in case GHC saw a
862 [ SysTools.Option "-x", if cc_phase `eqPhase` Ccpp
863 then SysTools.Option "c++" else SysTools.Option "c"] ++
864 [ SysTools.FileOption "" input_fn
865 , SysTools.Option "-o"
866 , SysTools.FileOption "" output_fn
868 ++ map SysTools.Option (
871 #ifdef sparc_TARGET_ARCH
872 -- We only support SparcV9 and better because V8 lacks an atomic CAS
873 -- instruction. Note that the user can still override this
874 -- (e.g., -mcpu=ultrasparc) as GCC picks the "best" -mcpu flag
875 -- regardless of the ordering.
877 -- This is a temporary hack.
886 ++ [ verb, "-S", "-Wimplicit", cc_opt ]
887 ++ [ "-D__GLASGOW_HASKELL__="++cProjectVersionInt ]
892 #ifdef HAVE_GCC_HAS_WRAPV
893 -- We need consistent integer overflow (trac #952)
898 return (next_phase, dflags, maybe_loc, output_fn)
900 -- ToDo: postprocess the output from gcc
902 -----------------------------------------------------------------------------
905 runPhase Mangle stop dflags _basename _suff input_fn get_output_fn maybe_loc
906 = do let mangler_opts = getOpts dflags opt_m
909 machdep_opts <- return [ show (stolen_x86_regs dflags) ]
911 machdep_opts <- return []
914 let split = dopt Opt_SplitObjs dflags
916 | split = SplitMangle
918 output_fn <- get_output_fn dflags next_phase maybe_loc
920 SysTools.runMangle dflags (map SysTools.Option mangler_opts
921 ++ [ SysTools.FileOption "" input_fn
922 , SysTools.FileOption "" output_fn
924 ++ map SysTools.Option machdep_opts)
926 return (next_phase, dflags, maybe_loc, output_fn)
928 -----------------------------------------------------------------------------
931 runPhase SplitMangle stop dflags _basename _suff input_fn get_output_fn maybe_loc
932 = do -- tmp_pfx is the prefix used for the split .s files
933 -- We also use it as the file to contain the no. of split .s files (sigh)
934 split_s_prefix <- SysTools.newTempName dflags "split"
935 let n_files_fn = split_s_prefix
937 SysTools.runSplit dflags
938 [ SysTools.FileOption "" input_fn
939 , SysTools.FileOption "" split_s_prefix
940 , SysTools.FileOption "" n_files_fn
943 -- Save the number of split files for future references
944 s <- readFile n_files_fn
945 let n_files = read s :: Int
946 writeIORef v_Split_info (split_s_prefix, n_files)
948 -- Remember to delete all these files
949 addFilesToClean [ split_s_prefix ++ "__" ++ show n ++ ".s"
952 return (SplitAs, dflags, maybe_loc, "**splitmangle**")
953 -- we don't use the filename
955 -----------------------------------------------------------------------------
958 runPhase As stop dflags _basename _suff input_fn get_output_fn maybe_loc
959 = do let as_opts = getOpts dflags opt_a
960 let cmdline_include_paths = includePaths dflags
962 output_fn <- get_output_fn dflags StopLn maybe_loc
964 -- we create directories for the object file, because it
965 -- might be a hierarchical module.
966 createDirectoryHierarchy (directoryOf output_fn)
968 SysTools.runAs dflags
969 (map SysTools.Option as_opts
970 ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
971 #ifdef sparc_TARGET_ARCH
972 -- We only support SparcV9 and better because V8 lacks an atomic CAS
973 -- instruction so we have to make sure that the assembler accepts the
974 -- instruction set. Note that the user can still override this
975 -- (e.g., -mcpu=ultrasparc). GCC picks the "best" -mcpu flag
976 -- regardless of the ordering.
978 -- This is a temporary hack.
979 ++ [ SysTools.Option "-mcpu=v9" ]
981 ++ [ SysTools.Option "-c"
982 , SysTools.FileOption "" input_fn
983 , SysTools.Option "-o"
984 , SysTools.FileOption "" output_fn
987 return (StopLn, dflags, maybe_loc, output_fn)
990 runPhase SplitAs stop dflags basename _suff _input_fn get_output_fn maybe_loc
992 output_fn <- get_output_fn dflags StopLn maybe_loc
994 let (base_o, _) = splitFilename output_fn
995 split_odir = base_o ++ "_split"
996 osuf = objectSuf dflags
998 createDirectoryHierarchy split_odir
1000 -- remove M_split/ *.o, because we're going to archive M_split/ *.o
1001 -- later and we don't want to pick up any old objects.
1002 fs <- getDirectoryContents split_odir
1003 mapM_ removeFile $ map (split_odir `joinFileName`)
1004 $ filter (osuf `isSuffixOf`) fs
1006 let as_opts = getOpts dflags opt_a
1008 (split_s_prefix, n) <- readIORef v_Split_info
1010 let split_s n = split_s_prefix ++ "__" ++ show n `joinFileExt` "s"
1011 split_obj n = split_odir `joinFileName`
1012 filenameOf base_o ++ "__" ++ show n
1016 = SysTools.runAs dflags
1017 (map SysTools.Option as_opts ++
1018 [ SysTools.Option "-c"
1019 , SysTools.Option "-o"
1020 , SysTools.FileOption "" (split_obj n)
1021 , SysTools.FileOption "" (split_s n)
1024 mapM_ assemble_file [1..n]
1026 -- and join the split objects into a single object file:
1027 let ld_r args = SysTools.runLink dflags ([
1028 SysTools.Option "-nostdlib",
1029 SysTools.Option "-nodefaultlibs",
1030 SysTools.Option "-Wl,-r",
1031 SysTools.Option ld_x_flag,
1032 SysTools.Option "-o",
1033 SysTools.FileOption "" output_fn ] ++ args)
1034 ld_x_flag | null cLD_X = ""
1035 | otherwise = "-Wl,-x"
1037 if cLdIsGNULd == "YES"
1039 let script = split_odir `joinFileName` "ld.script"
1041 "INPUT(" ++ unwords (map split_obj [1..n]) ++ ")"
1042 ld_r [SysTools.FileOption "" script]
1044 ld_r (map (SysTools.FileOption "" . split_obj) [1..n])
1046 return (StopLn, dflags, maybe_loc, output_fn)
1049 -----------------------------------------------------------------------------
1050 -- MoveBinary sort-of-phase
1051 -- After having produced a binary, move it somewhere else and generate a
1052 -- wrapper script calling the binary. Currently, we need this only in
1053 -- a parallel way (i.e. in GUM), because PVM expects the binary in a
1054 -- central directory.
1055 -- This is called from staticLink below, after linking. I haven't made it
1056 -- a separate phase to minimise interfering with other modules, and
1057 -- we don't need the generality of a phase (MoveBinary is always
1058 -- done after linking and makes only sense in a parallel setup) -- HWL
1060 runPhase_MoveBinary dflags input_fn
1062 let sysMan = pgm_sysman dflags
1063 pvm_root <- getEnv "PVM_ROOT"
1064 pvm_arch <- getEnv "PVM_ARCH"
1066 pvm_executable_base = "=" ++ input_fn
1067 pvm_executable = pvm_root ++ "/bin/" ++ pvm_arch ++ "/" ++ pvm_executable_base
1068 -- nuke old binary; maybe use configur'ed names for cp and rm?
1069 Panic.try (removeFile pvm_executable)
1070 -- move the newly created binary into PVM land
1071 copy dflags "copying PVM executable" input_fn pvm_executable
1072 -- generate a wrapper script for running a parallel prg under PVM
1073 writeFile input_fn (mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan)
1076 -- generates a Perl skript starting a parallel prg under PVM
1077 mk_pvm_wrapper_script :: String -> String -> String -> String
1078 mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan = unlines $
1080 "eval 'exec perl -S $0 ${1+\"$@\"}'",
1081 " if $running_under_some_shell;",
1082 "# =!=!=!=!=!=!=!=!=!=!=!",
1083 "# This script is automatically generated: DO NOT EDIT!!!",
1084 "# Generated by Glasgow Haskell Compiler",
1085 "# ngoqvam choHbogh vaj' vIHoHnISbej !!!!",
1087 "$pvm_executable = '" ++ pvm_executable ++ "';",
1088 "$pvm_executable_base = '" ++ pvm_executable_base ++ "';",
1089 "$SysMan = '" ++ sysMan ++ "';",
1091 {- ToDo: add the magical shortcuts again iff we actually use them -- HWL
1092 "# first, some magical shortcuts to run "commands" on the binary",
1093 "# (which is hidden)",
1094 "if ($#ARGV == 1 && $ARGV[0] eq '+RTS' && $ARGV[1] =~ /^--((size|file|strip|rm|nm).*)/ ) {",
1095 " local($cmd) = $1;",
1096 " system("$cmd $pvm_executable");",
1097 " exit(0); # all done",
1100 "# Now, run the real binary; process the args first",
1101 "$ENV{'PE'} = $pvm_executable_base;", -- ++ pvm_executable_base,
1103 "$nprocessors = 0; # the default: as many PEs as machines in PVM config",
1104 "@nonPVM_args = ();",
1105 "$in_RTS_args = 0;",
1107 "args: while ($a = shift(@ARGV)) {",
1108 " if ( $a eq '+RTS' ) {",
1109 " $in_RTS_args = 1;",
1110 " } elsif ( $a eq '-RTS' ) {",
1111 " $in_RTS_args = 0;",
1113 " if ( $a eq '-d' && $in_RTS_args ) {",
1115 " } elsif ( $a =~ /^-qN(\\d+)/ && $in_RTS_args ) {",
1116 " $nprocessors = $1;",
1117 " } elsif ( $a =~ /^-qp(\\d+)/ && $in_RTS_args ) {",
1118 " $nprocessors = $1;",
1120 " push(@nonPVM_args, $a);",
1124 "local($return_val) = 0;",
1125 "# Start the parallel execution by calling SysMan",
1126 "system(\"$SysMan $debug $pvm_executable $nprocessors @nonPVM_args\");",
1127 "$return_val = $?;",
1128 "# ToDo: fix race condition moving files and flushing them!!",
1129 "system(\"cp $ENV{'HOME'}/$pvm_executable_base.???.gr .\") if -f \"$ENV{'HOME'}/$pvm_executable_base.002.gr\";",
1130 "exit($return_val);"
1133 -----------------------------------------------------------------------------
1134 -- Complain about non-dynamic flags in OPTIONS pragmas
1136 checkProcessArgsResult flags filename
1137 = do when (notNull flags) (throwDyn (ProgramError (
1138 showSDoc (hang (text filename <> char ':')
1139 4 (text "unknown flags in {-# OPTIONS #-} pragma:" <+>
1140 hsep (map text flags)))
1143 -----------------------------------------------------------------------------
1144 -- Look for the /* GHC_PACKAGES ... */ comment at the top of a .hc file
1146 getHCFilePackages :: FilePath -> IO [PackageId]
1147 getHCFilePackages filename =
1148 Exception.bracket (openFile filename ReadMode) hClose $ \h -> do
1151 '/':'*':' ':'G':'H':'C':'_':'P':'A':'C':'K':'A':'G':'E':'S':rest ->
1152 return (map stringToPackageId (words rest))
1156 -----------------------------------------------------------------------------
1157 -- Static linking, of .o files
1159 -- The list of packages passed to link is the list of packages on
1160 -- which this program depends, as discovered by the compilation
1161 -- manager. It is combined with the list of packages that the user
1162 -- specifies on the command line with -package flags.
1164 -- In one-shot linking mode, we can't discover the package
1165 -- dependencies (because we haven't actually done any compilation or
1166 -- read any interface files), so the user must explicitly specify all
1169 staticLink :: DynFlags -> [FilePath] -> [PackageId] -> IO ()
1170 staticLink dflags o_files dep_packages = do
1171 let verb = getVerbFlag dflags
1172 output_fn = exeFileName dflags
1174 -- get the full list of packages to link with, by combining the
1175 -- explicit packages with the auto packages and all of their
1176 -- dependencies, and eliminating duplicates.
1178 pkg_lib_paths <- getPackageLibraryPath dflags dep_packages
1179 let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
1181 let lib_paths = libraryPaths dflags
1182 let lib_path_opts = map ("-L"++) lib_paths
1184 pkg_link_opts <- getPackageLinkOpts dflags dep_packages
1186 #ifdef darwin_TARGET_OS
1187 pkg_framework_paths <- getPackageFrameworkPath dflags dep_packages
1188 let pkg_framework_path_opts = map ("-F"++) pkg_framework_paths
1190 let framework_paths = frameworkPaths dflags
1191 framework_path_opts = map ("-F"++) framework_paths
1193 pkg_frameworks <- getPackageFrameworks dflags dep_packages
1194 let pkg_framework_opts = concat [ ["-framework", fw] | fw <- pkg_frameworks ]
1196 let frameworks = cmdlineFrameworks dflags
1197 framework_opts = concat [ ["-framework", fw] | fw <- reverse frameworks ]
1198 -- reverse because they're added in reverse order from the cmd line
1201 -- probably _stub.o files
1202 extra_ld_inputs <- readIORef v_Ld_inputs
1204 -- opts from -optl-<blah> (including -l<blah> options)
1205 let extra_ld_opts = getOpts dflags opt_l
1207 let ways = wayNames dflags
1209 -- Here are some libs that need to be linked at the *end* of
1210 -- the command line, because they contain symbols that are referred to
1211 -- by the RTS. We can't therefore use the ordinary way opts for these.
1213 debug_opts | WayDebug `elem` ways = [
1214 #if defined(HAVE_LIBBFD)
1221 thread_opts | WayThreaded `elem` ways = [
1222 #if !defined(mingw32_TARGET_OS) && !defined(freebsd_TARGET_OS)
1225 #if defined(osf3_TARGET_OS)
1231 let (md_c_flags, _) = machdepCCOpts dflags
1232 SysTools.runLink dflags (
1233 [ SysTools.Option verb
1234 , SysTools.Option "-o"
1235 , SysTools.FileOption "" output_fn
1237 ++ map SysTools.Option (
1243 #ifdef darwin_TARGET_OS
1244 ++ framework_path_opts
1247 ++ pkg_lib_path_opts
1249 #ifdef darwin_TARGET_OS
1250 ++ pkg_framework_path_opts
1251 ++ pkg_framework_opts
1257 -- parallel only: move binary to another dir -- HWL
1258 when (WayPar `elem` ways)
1259 (do success <- runPhase_MoveBinary dflags output_fn
1260 if success then return ()
1261 else throwDyn (InstallationError ("cannot move binary to PVM dir")))
1264 exeFileName :: DynFlags -> FilePath
1266 | Just s <- outputFile dflags =
1267 #if defined(mingw32_HOST_OS)
1268 if null (suffixOf s)
1269 then s `joinFileExt` "exe"
1275 #if defined(mingw32_HOST_OS)
1281 -----------------------------------------------------------------------------
1282 -- Making a DLL (only for Win32)
1284 doMkDLL :: DynFlags -> [String] -> [PackageId] -> IO ()
1285 doMkDLL dflags o_files dep_packages = do
1286 let verb = getVerbFlag dflags
1287 let static = opt_Static
1288 let no_hs_main = dopt Opt_NoHsMain dflags
1289 let o_file = outputFile dflags
1290 let output_fn = case o_file of { Just s -> s; Nothing -> "HSdll.dll"; }
1292 pkg_lib_paths <- getPackageLibraryPath dflags dep_packages
1293 let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
1295 let lib_paths = libraryPaths dflags
1296 let lib_path_opts = map ("-L"++) lib_paths
1298 pkg_link_opts <- getPackageLinkOpts dflags dep_packages
1300 -- probably _stub.o files
1301 extra_ld_inputs <- readIORef v_Ld_inputs
1303 -- opts from -optdll-<blah>
1304 let extra_ld_opts = getOpts dflags opt_dll
1306 let pstate = pkgState dflags
1307 rts_pkg = getPackageDetails pstate rtsPackageId
1308 base_pkg = getPackageDetails pstate basePackageId
1310 let extra_os = if static || no_hs_main
1312 else [ head (libraryDirs rts_pkg) ++ "/Main.dll_o",
1313 head (libraryDirs base_pkg) ++ "/PrelMain.dll_o" ]
1315 let (md_c_flags, _) = machdepCCOpts dflags
1316 SysTools.runMkDLL dflags
1317 ([ SysTools.Option verb
1318 , SysTools.Option "-o"
1319 , SysTools.FileOption "" output_fn
1321 ++ map SysTools.Option (
1325 ++ [ "--target=i386-mingw32" ]
1329 ++ pkg_lib_path_opts
1331 ++ (if "--def" `elem` (concatMap words extra_ld_opts)
1333 else [ "--export-all" ])
1336 -- -----------------------------------------------------------------------------
1339 doCpp :: DynFlags -> Bool -> Bool -> FilePath -> FilePath -> IO ()
1340 doCpp dflags raw include_cc_opts input_fn output_fn = do
1341 let hscpp_opts = getOpts dflags opt_P
1342 let cmdline_include_paths = includePaths dflags
1344 pkg_include_dirs <- getPackageIncludePath dflags []
1345 let include_paths = foldr (\ x xs -> "-I" : x : xs) []
1346 (cmdline_include_paths ++ pkg_include_dirs)
1348 let verb = getVerbFlag dflags
1351 | not include_cc_opts = []
1352 | otherwise = (optc ++ md_c_flags)
1354 optc = getOpts dflags opt_c
1355 (md_c_flags, _) = machdepCCOpts dflags
1357 let cpp_prog args | raw = SysTools.runCpp dflags args
1358 | otherwise = SysTools.runCc dflags (SysTools.Option "-E" : args)
1361 [ "-D" ++ HOST_OS ++ "_BUILD_OS=1",
1362 "-D" ++ HOST_ARCH ++ "_BUILD_ARCH=1",
1363 "-D" ++ TARGET_OS ++ "_HOST_OS=1",
1364 "-D" ++ TARGET_ARCH ++ "_HOST_ARCH=1" ]
1365 -- remember, in code we *compile*, the HOST is the same our TARGET,
1366 -- and BUILD is the same as our HOST.
1368 cpp_prog ([SysTools.Option verb]
1369 ++ map SysTools.Option include_paths
1370 ++ map SysTools.Option hsSourceCppOpts
1371 ++ map SysTools.Option hscpp_opts
1372 ++ map SysTools.Option cc_opts
1373 ++ map SysTools.Option target_defs
1374 ++ [ SysTools.Option "-x"
1375 , SysTools.Option "c"
1376 , SysTools.Option input_fn
1377 -- We hackily use Option instead of FileOption here, so that the file
1378 -- name is not back-slashed on Windows. cpp is capable of
1379 -- dealing with / in filenames, so it works fine. Furthermore
1380 -- if we put in backslashes, cpp outputs #line directives
1381 -- with *double* backslashes. And that in turn means that
1382 -- our error messages get double backslashes in them.
1383 -- In due course we should arrange that the lexer deals
1384 -- with these \\ escapes properly.
1385 , SysTools.Option "-o"
1386 , SysTools.FileOption "" output_fn
1389 cHaskell1Version = "5" -- i.e., Haskell 98
1391 -- Default CPP defines in Haskell source
1393 [ "-D__HASKELL1__="++cHaskell1Version
1394 , "-D__GLASGOW_HASKELL__="++cProjectVersionInt
1396 , "-D__CONCURRENT_HASKELL__"
1400 -- -----------------------------------------------------------------------------
1403 hscNextPhase :: DynFlags -> HscSource -> HscTarget -> Phase
1404 hscNextPhase dflags HsBootFile hsc_lang = StopLn
1405 hscNextPhase dflags other hsc_lang =
1408 HscAsm | dopt Opt_SplitObjs dflags -> SplitMangle
1410 HscNothing -> StopLn
1411 HscInterpreted -> StopLn
1415 hscMaybeAdjustTarget :: DynFlags -> Phase -> HscSource -> HscTarget -> HscTarget
1416 hscMaybeAdjustTarget dflags stop HsBootFile current_hsc_lang
1417 = HscNothing -- No output (other than Foo.hi-boot) for hs-boot files
1418 hscMaybeAdjustTarget dflags stop other current_hsc_lang
1421 keep_hc = dopt Opt_KeepHcFiles dflags
1423 -- don't change the lang if we're interpreting
1424 | current_hsc_lang == HscInterpreted = current_hsc_lang
1426 -- force -fvia-C if we are being asked for a .hc file
1427 | HCc <- stop = HscC
1429 -- otherwise, stick to the plan
1430 | otherwise = current_hsc_lang
1432 GLOBAL_VAR(v_Split_info, ("",0), (String,Int))
1433 -- The split prefix and number of files