Stop passing -Wl,-macosx_version_min to gcc
[ghc-hetmet.git] / compiler / main / DriverPipeline.hs
index 0bac958..f748f7c 100644 (file)
@@ -35,7 +35,7 @@ import Finder
 import HscTypes
 import Outputable
 import Module
-import LazyUniqFM              ( eltsUFM )
+import UniqFM          ( eltsUFM )
 import ErrUtils
 import DynFlags
 import StaticFlags     ( v_Ld_inputs, opt_Static, WayName(..) )
@@ -826,6 +826,7 @@ runPhase (Hsc src_flavour) stop hsc_env basename suff input_fn get_output_fn _ma
        src_timestamp <- liftIO $ getModificationTime (basename <.> suff)
 
        let force_recomp = dopt Opt_ForceRecomp dflags
+           hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags)
        source_unchanged <-
           if force_recomp || not (isStopLn stop)
                -- Set source_unchanged to False unconditionally if
@@ -842,7 +843,6 @@ runPhase (Hsc src_flavour) stop hsc_env basename suff input_fn get_output_fn _ma
                                  else return False
 
   -- get the DynFlags
-       let hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags)
        let next_phase = hscNextPhase dflags src_flavour hsc_lang
        output_fn  <- liftIO $ get_output_fn dflags next_phase (Just location4)
 
@@ -1299,6 +1299,22 @@ wrapper_behaviour dflags mode dep_packages =
        putStrLn (unwords (map (packageIdString . packageConfigId) allpkg))
        return $ 'F':s ++ ';':(seperateBySemiColon (map (packageIdString . packageConfigId) allpkg))
 
+mkExtraCObj :: DynFlags -> [String] -> IO FilePath
+mkExtraCObj dflags xs
+ = do cFile <- newTempName dflags "c"
+      oFile <- newTempName dflags "o"
+      writeFile cFile $ unlines xs
+      let rtsDetails = getPackageDetails (pkgState dflags) rtsPackageId
+          (md_c_flags, _) = machdepCCOpts dflags
+      SysTools.runCc dflags
+                     ([Option        "-c",
+                       FileOption "" cFile,
+                       Option        "-o",
+                       FileOption "" oFile] ++
+                      map (FileOption "-I") (includeDirs rtsDetails) ++
+                      map Option md_c_flags)
+      return oFile
+
 -- generates a Perl skript starting a parallel prg under PVM
 mk_pvm_wrapper_script :: String -> String -> String -> String
 mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan = unlines $
@@ -1409,6 +1425,20 @@ linkBinary dflags o_files dep_packages = do
     let no_hs_main = dopt Opt_NoHsMain dflags
     let main_lib | no_hs_main = []
                  | otherwise  = [ "-lHSrtsmain" ]
+    rtsEnabledObj <- if dopt Opt_RtsOptsEnabled dflags
+                     then do fn <- mkExtraCObj dflags
+                                    ["#include \"Rts.h\"",
+                                     "const rtsBool rtsOptsEnabled = rtsTrue;"]
+                             return [fn]
+                     else return []
+    rtsOptsObj <- case rtsOpts dflags of
+                  Just opts ->
+                      do fn <- mkExtraCObj dflags
+                                 -- We assume that the Haskell "show" does
+                                 -- the right thing here
+                                 ["char *ghc_rts_opts = " ++ show opts ++ ";"]
+                         return [fn]
+                  Nothing -> return []
 
     pkg_link_opts <- getPackageLinkOpts dflags dep_packages
 
@@ -1483,6 +1513,8 @@ linkBinary dflags o_files dep_packages = do
 #endif
                      ++ pkg_lib_path_opts
                       ++ main_lib
+                      ++ rtsEnabledObj
+                      ++ rtsOptsObj
                      ++ pkg_link_opts
 #ifdef darwin_TARGET_OS
                      ++ pkg_framework_path_opts
@@ -1657,10 +1689,6 @@ linkDynLib dflags o_files dep_packages = do
     --  Build the dynamic library as a single "module", i.e. no dynamic binding
     --  nonsense when referring to symbols from within the library. The NCG
     --  assumes that this option is specified (on i386, at least).
-    -- -Wl,-macosx_version_min -Wl,10.3
-    --  Tell the linker its safe to assume that the library will run on 10.3 or
-    --  later, so that it will not complain about the use of the option
-    --  -undefined dynamic_lookup above.
     -- -install_name
     --   Mac OS/X stores the path where a dynamic library is (to be) installed
     --   in the library itself.  It's called the "install name" of the library.
@@ -1687,7 +1715,7 @@ linkDynLib dflags o_files dep_packages = do
         ++ map SysTools.Option (
            md_c_flags
         ++ o_files
-        ++ [ "-undefined", "dynamic_lookup", "-single_module", "-Wl,-macosx_version_min","-Wl,10.5",
+        ++ [ "-undefined", "dynamic_lookup", "-single_module",
               "-Wl,-read_only_relocs,suppress", "-install_name", instName ]
         ++ extra_ld_inputs
         ++ lib_path_opts
@@ -1701,6 +1729,14 @@ linkDynLib dflags o_files dep_packages = do
     -----------------------------------------------------------------------------
 
     let output_fn = case o_file of { Just s -> s; Nothing -> "a.out"; }
+    let buildingRts = thisPackage dflags == rtsPackageId
+    let bsymbolicFlag = if buildingRts
+                        then -- -Bsymbolic breaks the way we implement
+                             -- hooks in the RTS
+                             []
+                        else -- we need symbolic linking to resolve
+                             -- non-PIC intra-package-relocations
+                             ["-Wl,-Bsymbolic"]
 
     SysTools.runLink dflags
         ([ SysTools.Option verb
@@ -1710,7 +1746,8 @@ linkDynLib dflags o_files dep_packages = do
         ++ map SysTools.Option (
            md_c_flags
         ++ o_files
-        ++ [ "-shared", "-Wl,-Bsymbolic" ] -- we need symbolic linking to resolve non-PIC intra-package-relocations
+        ++ [ "-shared" ]
+        ++ bsymbolicFlag
          ++ [ "-Wl,-soname," ++ takeFileName output_fn ] -- set the library soname
         ++ extra_ld_inputs
         ++ lib_path_opts