[commit: ghc] wip/angerman/llvmng: Relocatable GHC (0c31b32)
git at git.haskell.org
git at git.haskell.org
Sat Nov 11 08:34:51 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/angerman/llvmng
Link : http://ghc.haskell.org/trac/ghc/changeset/0c31b32607ca8829793b355420759284d2d64d2e/ghc
>---------------------------------------------------------------
commit 0c31b32607ca8829793b355420759284d2d64d2e
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date: Fri Nov 10 10:00:09 2017 +0800
Relocatable GHC
GHC and the binary distribution that's produced is
not relocatable outside of Windows. This diff tries to
address this for at least Linux and macOS.
Reviewers: austin, hvr, bgamari, erikd
Subscribers: rwbarton, thomie, erikd
Differential Revision: https://phabricator.haskell.org/D4121
>---------------------------------------------------------------
0c31b32607ca8829793b355420759284d2d64d2e
compiler/main/SysTools.hs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 21ed03b..625552b 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -48,6 +48,7 @@ import Platform
import Util
import DynFlags
+import System.Environment (getExecutablePath)
import System.FilePath
import System.IO
import System.Directory
@@ -530,6 +531,26 @@ type GetFinalPath = HANDLE -> LPTSTR -> DWORD -> DWORD -> IO DWORD
foreign import WINDOWS_CCONV unsafe "dynamic"
makeGetFinalPathNameByHandle :: FunPtr GetFinalPath -> GetFinalPath
+#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS)
+-- on unix, this is a bit more confusing.
+-- The layout right now is somehting like
+--
+-- /bin/ghc-X.Y.Z <- wrapper script (1)
+-- /bin/ghc <- symlink to wrapper script (2)
+-- /lib/ghc-X.Y.Z/bin/ghc <- ghc executable (3)
+-- /lib/ghc-X.Y.Z <- $topdir (4)
+--
+-- As such, we fist need to find the absolute location to the
+-- binary.
+--
+-- getExecutablePath will return (3). One takeDirectory will
+-- give use /lib/ghc-X.Y.Z/bin, and another will give us (4).
+--
+-- This of course only works due to the current layout. If
+-- the layout is changed, such that we have ghc-X.Y.Z/{bin,lib}
+-- this would need to be changed accordingly.
+--
+getBaseDir = Just . (\p -> p </> "lib") . takeDirectory . takeDirectory <$> getExecutablePath
#else
getBaseDir = return Nothing
#endif
More information about the ghc-commits
mailing list