Merge remote branch 'origin'
[ghc-hetmet.git] / compiler / main / DriverPipeline.hs
index 13c91c2..8d31fd9 100644 (file)
@@ -986,7 +986,7 @@ runPhase Cmm input_fn dflags
 -- way too many hacks, and I can't say I've ever used it anyway.
 
 runPhase cc_phase input_fn dflags
-   | cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc
+   | cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc || cc_phase `eqPhase` Cobjc
    = do
         let cc_opts = getOpts dflags opt_c
             hcc = cc_phase `eqPhase` HCc
@@ -1054,15 +1054,16 @@ runPhase cc_phase input_fn dflags
                 -- very weakly typed, being derived from C--.
                 ["-fno-strict-aliasing"]
 
+        let gcc_lang_opt | cc_phase `eqPhase` Ccpp  = "c++"
+                         | cc_phase `eqPhase` Cobjc = "objective-c"
+                         | otherwise                = "c"
         io $ SysTools.runCc dflags (
                 -- force the C compiler to interpret this file as C when
                 -- compiling .hc files, by adding the -x c option.
                 -- Also useful for plain .c files, just in case GHC saw a
                 -- -x c option.
-                        [ SysTools.Option "-x", if cc_phase `eqPhase` Ccpp
-                                                then SysTools.Option "c++"
-                                                else SysTools.Option "c"] ++
-                        [ SysTools.FileOption "" input_fn
+                        [ SysTools.Option "-x", SysTools.Option gcc_lang_opt
+                        , SysTools.FileOption "" input_fn
                         , SysTools.Option "-o"
                         , SysTools.FileOption "" output_fn
                         ]
@@ -1178,7 +1179,9 @@ runPhase As input_fn dflags
 
 runPhase SplitAs _input_fn dflags
   = do
-        next_phase <- maybeMergeStub
+        -- we'll handle the stub_o file in this phase, so don't MergeStub,
+        -- just jump straight to StopLn afterwards.
+        let next_phase = StopLn
         output_fn <- phaseOutputFilename next_phase
 
         let base_o = dropExtension output_fn
@@ -1226,8 +1229,15 @@ runPhase SplitAs _input_fn dflags
 
         io $ mapM_ assemble_file [1..n]
 
+        -- If there's a stub_o file, then we make it the n+1th split object.
+        PipeState{maybe_stub_o} <- getPipeState
+        n' <- case maybe_stub_o of
+                  Nothing     -> return n
+                  Just stub_o -> do io $ copyFile stub_o (split_obj (n+1))
+                                    return (n+1)
+
         -- join them into a single .o file
-        io $ joinObjectFiles dflags (map split_obj [1..n]) output_fn
+        io $ joinObjectFiles dflags (map split_obj [1..n']) output_fn
 
         return (next_phase, output_fn)