Commit 6c9dce4c authored by Christiaan Baaij's avatar Christiaan Baaij
Browse files

Enable support for relocatable libraries

parent 06a713e1
......@@ -93,7 +93,7 @@ import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..), compilerVersion
, OptimisationLevel(..), PackageDB(..), PackageDBStack, AbiTag(..)
, Flag )
, Flag, packageKeySupported )
import Distribution.Version
( Version(..), anyVersion, orLaterVersion )
import Distribution.System
......@@ -907,13 +907,12 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptNoAutoLinkPackages = toFlag True,
ghcOptPackageDBs = withPackageDB lbi,
ghcOptPackages = toNubListR $ mkGhcOptPackages clbi,
ghcOptLinkOptions = if (hostOS == OSX
&& relocatable lbi)
then toRPaths lbi clbi
else mempty,
ghcOptLinkLibs = toNubListR $ extraLibs libBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs libBi,
ghcOptNoRPath = toFlag (relocatable lbi)
ghcOptRPaths = if (hostOS == OSX
&& relocatable lbi)
then toRPaths False lbi clbi
else mempty
}
info verbosity (show (ghcOptPackages ghcSharedLinkArgs))
......@@ -932,10 +931,25 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
whenSharedLib False $
runGhcProg ghcSharedLinkArgs
toRPaths :: LocalBuildInfo
-- | Derive relative RPATHs
toRPaths :: Bool -- ^ Building exe?
-> LocalBuildInfo
-> ComponentLocalBuildInfo
-> NubListR String
toRPaths = undefined
-> NubListR FilePath
toRPaths buildE lbi clbi = toNubListR $ map (libPref </>) depsK
where
(Platform _hostArch hostOS) = hostPlatform lbi
ipkgs = installedPkgs lbi
deps = map fst (componentPackageDeps clbi)
depsP = catMaybes (map (PackageIndex.lookupInstalledPackageId ipkgs) deps)
depsK = if packageKeySupported (compiler lbi)
then map (display . InstalledPackageInfo.packageKey) depsP
else map (display . snd) (componentPackageDeps clbi)
hostPref = case hostOS of
OSX -> "@origin"
_ -> "$ORIGIN"
libPref = hostPref </> (if buildE then ".." </> "lib" else "..")
-- | Start a REPL without loading any source files.
startInterpreter :: Verbosity -> ProgramConfiguration -> Compiler
......@@ -966,6 +980,7 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
(ghcProg, _) <- requireProgram verbosity ghcProgram (withPrograms lbi)
let comp = compiler lbi
runGhcProg = runGHC verbosity ghcProg comp
(Platform _hostArch hostOS) = hostPlatform lbi
exeBi <- hackThreadedFlag verbosity
comp (withProfExe lbi) (buildInfo exe)
......@@ -1035,7 +1050,10 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
ghcOptLinkFrameworks = toNubListR $ PD.frameworks exeBi,
ghcOptInputFiles = toNubListR
[exeDir </> x | x <- cObjs],
ghcOptNoRPath = toFlag (relocatable lbi)
ghcOptRPaths = if (hostOS == OSX
&& relocatable lbi)
then toRPaths True lbi clbi
else mempty
}
replOpts = baseOpts {
ghcOptExtra = overNubListR filterGhciFlags
......
......@@ -189,7 +189,7 @@ data GhcOptions = GhcOptions {
ghcOptShared :: Flag Bool,
ghcOptFPic :: Flag Bool,
ghcOptDylibName :: Flag String,
ghcOptNoRPath :: Flag Bool, -- ^ Don't embed any runtime paths.
ghcOptRPaths :: NubListR FilePath,
---------------
-- Misc flags
......@@ -337,7 +337,9 @@ renderGhcOptions comp opts
, ["-L" ++ dir | dir <- flags ghcOptLinkLibPath ]
, concat [ ["-framework", fmwk] | fmwk <- flags ghcOptLinkFrameworks ]
, [ "-no-hs-main" | flagBool ghcOptLinkNoHsMain ]
, [ "-dynload deploy" | flagBool ghcOptNoRPath ]
, [ "-dynload deploy" | not (null (flags ghcOptRPaths)) ]
, concat [ [ "-optl-Wl,-rpath," ++ dir]
| dir <- flags ghcOptRPaths ]
-------------
-- Packages
......@@ -490,7 +492,7 @@ instance Monoid GhcOptions where
ghcOptShared = mempty,
ghcOptFPic = mempty,
ghcOptDylibName = mempty,
ghcOptNoRPath = mempty,
ghcOptRPaths = mempty,
ghcOptVerbosity = mempty,
ghcOptCabal = mempty
}
......@@ -542,7 +544,7 @@ instance Monoid GhcOptions where
ghcOptShared = combine ghcOptShared,
ghcOptFPic = combine ghcOptFPic,
ghcOptDylibName = combine ghcOptDylibName,
ghcOptNoRPath = combine ghcOptNoRPath,
ghcOptRPaths = combine ghcOptRPaths,
ghcOptVerbosity = combine ghcOptVerbosity,
ghcOptCabal = combine ghcOptCabal
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment