[project @ 2005-09-18 07:09:50 by wolfgang]
authorwolfgang <unknown>
Sun, 18 Sep 2005 07:09:50 +0000 (07:09 +0000)
committerwolfgang <unknown>
Sun, 18 Sep 2005 07:09:50 +0000 (07:09 +0000)
A hack to make -dynamic work again:
when a library listed in extraLibraries ends with "_cbits", append "_dyn"
when -dynamic is passed, i.e. extraLibraries = ["foo", "HSbase_cbits"]
loads -lfoo and -lHSbase_cbits in the static case, but -lfoo and
-lHSbase_cbits_dyn in the -dynamic case.

It's an ugly hack, but it affects only the case when -dynamic is passed,
which would not work otherwise right now, so let's

MERGE TO STABLE

ghc/compiler/main/Packages.lhs

index 79fd2d0..5f10fe3 100644 (file)
@@ -71,6 +71,7 @@ import Data.List      ( nub, partition, sortBy )
 #ifdef mingw32_TARGET_OS
 import Data.List       ( isPrefixOf )
 #endif
+import Data.List        ( isSuffixOf )
 
 import FastString
 import EXCEPTION       ( throwDyn )
@@ -538,7 +539,8 @@ getPackageLinkOpts dflags pkgs = do
       rts_tag = rtsBuildTag dflags
   let 
        imp        = if opt_Static then "" else "_dyn"
-       libs p     = map ((++imp) . addSuffix) (hACK (hsLibraries p)) ++ extraLibraries p
+       libs p     = map ((++imp) . addSuffix) (hACK (hsLibraries p))
+                        ++ hACK_dyn (extraLibraries p)
        all_opts p = map ("-l" ++) (libs p) ++ ldOptions p
 
        suffix     = if null tag then "" else  '_':tag
@@ -547,6 +549,15 @@ getPackageLinkOpts dflags pkgs = do
         addSuffix rts@"HSrts"    = rts       ++ rts_suffix
         addSuffix other_lib      = other_lib ++ suffix
 
+        -- This is a hack that's even more horrible (and hopefully more temporary)
+        -- than the one below. HSbase_cbits and friends require the _dyn suffix
+        -- for dynamic linking, but not _p or other 'way' suffix. So we just add
+        -- _dyn to extraLibraries if they already have a _cbits suffix.
+        
+        hACK_dyn = map hack
+          where hack lib | not static && "_cbits" `isSuffixOf` lib = lib ++ "_dyn"
+                         | otherwise = lib
+
   return (concat (map all_opts ps))
   where
 
@@ -583,6 +594,7 @@ getPackageLinkOpts dflags pkgs = do
          libs
 #      endif
 
+
 getPackageExtraCcOpts :: DynFlags -> [PackageId] -> IO [String]
 getPackageExtraCcOpts dflags pkgs = do
   ps <- getExplicitPackagesAnd dflags pkgs