[project @ 2000-11-09 12:54:08 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPipeline.hs
index 4f06e11..2542e10 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.15 2000/11/02 13:58:45 sewardj Exp $
+-- $Id: DriverPipeline.hs,v 1.18 2000/11/09 12:54:08 simonmar Exp $
 --
 -- GHC Driver
 --
@@ -134,6 +134,7 @@ genPipeline todo stop_flag filename
    keep_hc    <- readIORef v_Keep_hc_files
    keep_raw_s <- readIORef v_Keep_raw_s_files
    keep_s     <- readIORef v_Keep_s_files
+   osuf       <- readIORef v_Object_suf
 
    let
    ----------- -----  ----   ---   --   --  -  -  -
@@ -195,6 +196,10 @@ genPipeline todo stop_flag filename
 
    let
    ----------- -----  ----   ---   --   --  -  -  -
+      myPhaseInputExt Ln = case osuf of Nothing -> phaseInputExt Ln
+                                       Just s  -> s
+      myPhaseInputExt other = phaseInputExt other
+
       annotatePipeline
         :: [Phase]             -- raw pipeline
         -> Phase               -- phase to stop before
@@ -202,7 +207,7 @@ genPipeline todo stop_flag filename
       annotatePipeline []     _    = []
       annotatePipeline (Ln:_) _    = []
       annotatePipeline (phase:next_phase:ps) stop = 
-         (phase, keep_this_output, phaseInputExt next_phase)
+         (phase, keep_this_output, myPhaseInputExt next_phase)
             : annotatePipeline (next_phase:ps) stop
          where
                keep_this_output
@@ -276,8 +281,7 @@ pipeLoop ((phase, keep, o_suffix):phases)
                       Just s  -> return s
                       Nothing -> error "outputFileName"
               else if keep == Persistent
-                          then do f <- odir_ify (orig_basename ++ '.':suffix)
-                                  osuf_ify f
+                          then odir_ify (orig_basename ++ '.':suffix)
                           else newTempName suffix
 
 -------------------------------------------------------------------------------
@@ -342,9 +346,9 @@ run_phase MkDependHS basename suff input_fn _output_fn = do
 
    deps <- mapM (findDependency basename) imports
 
-   osuf_opt <- readIORef v_Output_suf
+   osuf_opt <- readIORef v_Object_suf
    let osuf = case osuf_opt of
-                       Nothing -> "o"
+                       Nothing -> phaseInputExt Ln
                        Just s  -> s
 
    extra_suffixes <- readIORef v_Dep_suffixes
@@ -528,6 +532,10 @@ run_phase cc_phase _basename _suff input_fn output_fn
 
        pkg_extra_cc_opts <- getPackageExtraCcOpts
 
+       split_objs <- readIORef v_Split_object_files
+       let split_opt | hcc && split_objs = [ "-DUSE_SPLIT_MARKERS" ]
+                     | otherwise         = [ ]
+
        excessPrecision <- readIORef v_Excess_precision
 
        run_something "C Compiler"
@@ -539,6 +547,7 @@ run_phase cc_phase _basename _suff input_fn output_fn
                   ++ [ verb, "-S", "-Wimplicit", opt_flag ]
                   ++ [ "-D__GLASGOW_HASKELL__="++cProjectVersionInt ]
                   ++ cc_opts
+                  ++ split_opt
 #ifdef mingw32_TARGET_OS
                    ++ [" -mno-cygwin"]
 #endif
@@ -647,6 +656,10 @@ doLink :: [String] -> IO ()
 doLink o_files = do
     ln <- readIORef v_Pgm_l
     verb <- is_verbose
+    static <- readIORef v_Static
+    let imp = if static then "" else "_imp"
+    no_hs_main <- readIORef v_NoHsMain
+
     o_file <- readIORef v_Output_file
     let output_fn = case o_file of { Just s -> s; Nothing -> "a.out"; }
 
@@ -657,7 +670,7 @@ doLink o_files = do
     let lib_path_opts = map ("-L"++) lib_paths
 
     pkg_libs <- getPackageLibraries
-    let pkg_lib_opts = map (\lib -> "-l"++lib) pkg_libs
+    let pkg_lib_opts = map (\lib -> "-l" ++ lib ++ imp) pkg_libs
 
     libs <- readIORef v_Cmdline_libraries
     let lib_opts = map ("-l"++) (reverse libs)
@@ -671,10 +684,23 @@ doLink o_files = do
        -- opts from -optl-<blah>
     extra_ld_opts <- getStaticOpts v_Opt_l
 
+    rts_pkg <- getPackageDetails ["rts"]
+    std_pkg <- getPackageDetails ["std"]
+#ifdef mingw32_TARGET_OS
+    let extra_os = if static || no_hs_main
+                   then []
+                   else [ head (library_dirs (head rts_pkg)) ++ "/Main.dll_o",
+                          head (library_dirs (head std_pkg)) ++ "/PrelMain.dll_o" ]
+#endif
+    (md_c_flags, _) <- machdepCCOpts
     run_something "Linker"
-       (unwords 
+       (unwords
         ([ ln, verb, "-o", output_fn ]
+        ++ md_c_flags
         ++ o_files
+#ifdef mingw32_TARGET_OS
+        ++ extra_os
+#endif
         ++ extra_ld_inputs
         ++ lib_path_opts
         ++ lib_opts
@@ -682,6 +708,11 @@ doLink o_files = do
         ++ pkg_lib_opts
         ++ pkg_extra_ld_opts
         ++ extra_ld_opts
+#ifdef mingw32_TARGET_OS
+         ++ if static then [ "-u _PrelMain_mainIO_closure" , "-u ___init_PrelMain"] else []
+#else
+        ++ [ "-u PrelMain_mainIO_closure" , "-u __init_PrelMain"]
+#endif
        )
        )