[project @ 2002-12-17 13:50:28 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPipeline.hs
index 1e573c2..0721c72 100644 (file)
@@ -301,8 +301,17 @@ link' Interactive dflags batch_attempt_linking linkables
 
 link' Batch dflags batch_attempt_linking linkables
    | batch_attempt_linking
-   = do when (verb >= 1) $
-             hPutStrLn stderr "ghc: linking ..."
+   = do 
+       -- check for the -no-link flag
+       omit_linking <- readIORef v_NoLink
+       if omit_linking 
+         then do when (verb >= 3) $
+                   hPutStrLn stderr "link(batch): linking omitted (-no-link flag given)."
+                 return Succeeded
+         else do
+
+       when (verb >= 1) $
+             hPutStrLn stderr "Linking ..."
 
        -- Don't showPass in Batch mode; doLink will do that for us.
         staticLink (concatMap getOfiles linkables)
@@ -461,9 +470,9 @@ genPipeline todo stop_flag persistent_output lang (filename,suffix)
                     ++ filename ++ "'" ++ show pipeline ++ show stop_phase)))
    let
        -- .o and .hc suffixes can be overriden by command-line options:
-      myPhaseInputExt Ln  | Just s <- osuf  = s
       myPhaseInputExt HCc | Just s <- hcsuf = s
-      myPhaseInputExt other                 = phaseInputExt other
+      myPhaseInputExt Ln    = osuf
+      myPhaseInputExt other = phaseInputExt other
 
       annotatePipeline
         :: [Phase]             -- raw pipeline
@@ -687,10 +696,7 @@ run_phase MkDependHS basename suff input_fn output_fn
       deps_normals <- mapM (findDependency False orig_fn) import_normals
       let deps = deps_sources ++ deps_normals
 
-      osuf_opt <- readIORef v_Object_suf
-      let osuf = case osuf_opt of
-                  Nothing -> phaseInputExt Ln
-                  Just s  -> s
+      osuf <- readIORef v_Object_suf
 
       extra_suffixes <- readIORef v_Dep_suffixes
       let suffixes = osuf : map (++ ('_':osuf)) extra_suffixes
@@ -749,7 +755,7 @@ run_phase Hsc basename suff input_fn output_fn
   -- we add the current directory (i.e. the directory in which
   -- the .hs files resides) to the import path, since this is
   -- what gcc does, and it's probably what you want.
-       let current_dir = getdir basename
+       let current_dir = directoryOf basename
        
        paths <- readIORef v_Include_paths
        writeIORef v_Include_paths (current_dir : paths)
@@ -779,8 +785,8 @@ run_phase Hsc basename suff input_fn output_fn
               getImportsFromFile input_fn
 
   -- build a ModLocation to pass to hscMain.
-       (mod, location')
-          <- mkHomeModuleLocn mod_name basename (basename ++ '.':suff)
+       let (path,file) = splitFilenameDir basename
+       (mod, location') <- mkHomeModLocation mod_name True path file suff
 
   -- take -ohi into account if present
        ohi <- readIORef v_Output_hi
@@ -993,8 +999,9 @@ run_phase SplitAs basename _suff _input_fn output_fn
 
        let assemble_file n
              = do  let input_s  = split_s_prefix ++ "__" ++ show n ++ ".s"
-                   let output_o = newdir real_odir 
+                   let output_o = replaceFilenameDirectory
                                        (basename ++ "__" ++ show n ++ ".o")
+                                        real_odir
                    real_o <- osuf_ify output_o
                    SysTools.runAs (map SysTools.Option as_opts ++
                                    [ SysTools.Option "-c"
@@ -1147,13 +1154,7 @@ staticLink o_files = do
     lib_paths <- readIORef v_Library_paths
     let lib_path_opts = map ("-L"++) lib_paths
 
-    pkg_libs <- getPackageLibraries
-    let imp         = if static then "" else "_imp"
-        pkg_lib_opts = map (\lib -> "-l" ++ lib ++ imp) pkg_libs
-
-    libs <- readIORef v_Cmdline_libraries
-    let lib_opts = map ("-l"++) (reverse libs)
-        -- reverse because they're added in reverse order from the cmd line
+    pkg_link_opts <- getPackageLinkOpts
 
 #ifdef darwin_TARGET_OS
     pkg_framework_paths <- getPackageFrameworkPath
@@ -1170,15 +1171,13 @@ staticLink o_files = do
         -- reverse because they're added in reverse order from the cmd line
 #endif
 
-    pkg_extra_ld_opts <- getPackageExtraLdOpts
-
        -- probably _stub.o files
     extra_ld_inputs <- readIORef v_Ld_inputs
 
-       -- opts from -optl-<blah>
+       -- opts from -optl-<blah> (including -l<blah> options)
     extra_ld_opts <- getStaticOpts v_Opt_l
 
-    [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, preludePackage]
+    [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, basePackage]
 
     let extra_os = if static || no_hs_main
                    then []
@@ -1196,19 +1195,17 @@ staticLink o_files = do
                      ++ extra_os
                      ++ extra_ld_inputs
                      ++ lib_path_opts
-                     ++ lib_opts
+                     ++ extra_ld_opts
 #ifdef darwin_TARGET_OS
                      ++ framework_path_opts
                      ++ framework_opts
 #endif
                      ++ pkg_lib_path_opts
-                     ++ pkg_lib_opts
+                     ++ pkg_link_opts
 #ifdef darwin_TARGET_OS
                      ++ pkg_framework_path_opts
                      ++ pkg_framework_opts
 #endif
-                     ++ pkg_extra_ld_opts
-                     ++ extra_ld_opts
                      ++ if static && not no_hs_main then
                            [ "-u", prefixUnderscore "Main_zdmain_closure"] 
                         else []))
@@ -1238,15 +1235,7 @@ doMkDLL o_files = do
     lib_paths <- readIORef v_Library_paths
     let lib_path_opts = map ("-L"++) lib_paths
 
-    pkg_libs <- getPackageLibraries
-    let imp = if static then "" else "_imp"
-        pkg_lib_opts = map (\lib -> "-l" ++ lib ++ imp) pkg_libs
-
-    libs <- readIORef v_Cmdline_libraries
-    let lib_opts = map ("-l"++) (reverse libs)
-        -- reverse because they're added in reverse order from the cmd line
-
-    pkg_extra_ld_opts <- getPackageExtraLdOpts
+    pkg_link_opts <- getPackageLinkOpts
 
        -- probably _stub.o files
     extra_ld_inputs <- readIORef v_Ld_inputs
@@ -1254,7 +1243,7 @@ doMkDLL o_files = do
        -- opts from -optdll-<blah>
     extra_ld_opts <- getStaticOpts v_Opt_dll
 
-    [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, preludePackage]
+    [rts_pkg, std_pkg] <- getPackageDetails [rtsPackage, basePackage]
 
     let extra_os = if static || no_hs_main
                    then []
@@ -1274,12 +1263,10 @@ doMkDLL o_files = do
         ++ [ "--target=i386-mingw32" ]
         ++ extra_ld_inputs
         ++ lib_path_opts
-        ++ lib_opts
+        ++ extra_ld_opts
         ++ pkg_lib_path_opts
-        ++ pkg_lib_opts
-        ++ pkg_extra_ld_opts
+        ++ pkg_link_opts
          ++ (if "--def" `elem` (concatMap words extra_ld_opts)
               then [ "" ]
                else [ "--export-all" ])
-        ++ extra_ld_opts
        ))