[commit: ghc] master: Correctly set relative rpath for OS X (#8266) (f213e48)
git at git.haskell.org
git at git.haskell.org
Fri Oct 25 14:22:18 UTC 2013
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/f213e48447050bf468bc4d91fc4d810402c23b85/ghc
>---------------------------------------------------------------
commit f213e48447050bf468bc4d91fc4d810402c23b85
Author: Austin Seipp <austin at well-typed.com>
Date: Fri Oct 25 03:26:23 2013 -0500
Correctly set relative rpath for OS X (#8266)
This includes both executables (by correcly setting the rpath to the
topDir) and libffi, and GHC itself, so that everything works with no
build tree.
Authored-by: Christiaan Baaj <christiaan.baaij at gmail.com>
Signed-off-by: Austin Seipp <austin at well-typed.com>
>---------------------------------------------------------------
f213e48447050bf468bc4d91fc4d810402c23b85
compiler/main/DriverPipeline.hs | 7 +++++++
rts/ghc.mk | 5 ++++-
rules/build-prog.mk | 3 ++-
rules/relative-dynlib-references.mk | 26 +++++++++++++++++++++++---
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 44a6fa5..337778e 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1900,6 +1900,13 @@ linkBinary' staticLink dflags o_files dep_packages = do
then ["-Wl,-read_only_relocs,suppress"]
else [])
+ ++ (if platformOS platform == OSDarwin &&
+ not staticLink &&
+ not (gopt Opt_Static dflags) &&
+ gopt Opt_RPath dflags
+ then ["-Wl,-rpath","-Wl," ++ topDir dflags]
+ else [])
+
++ o_files
++ lib_path_opts)
++ extra_ld_inputs
diff --git a/rts/ghc.mk b/rts/ghc.mk
index 9f36811..9ed64c6 100644
--- a/rts/ghc.mk
+++ b/rts/ghc.mk
@@ -116,6 +116,9 @@ else
# depend on libffi.so, but copy libffi.so*
rts/dist/build/lib$(LIBFFI_NAME)$(soext): libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)
cp libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)* rts/dist/build
+ifeq "$(TargetOS_CPP)" "darwin"
+ install_name_tool -id @rpath/rts-$(rts_VERSION)/lib$(LIBFFI_NAME)$(soext) rts/dist/build/lib$(LIBFFI_NAME)$(soext)
+endif
endif
endif
endif
@@ -204,7 +207,7 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
-no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/dist/libs.depend` $$(rts_$1_OBJS) \
$$(rts_$1_DTRACE_OBJS) -o $$@
- $(call relative-dynlib-references,rts,dist,1)
+ $(call relative-dynlib-references,rts,dist,1,$1)
endif
else
$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
diff --git a/rules/build-prog.mk b/rules/build-prog.mk
index 437cfbd..54424cf 100644
--- a/rules/build-prog.mk
+++ b/rules/build-prog.mk
@@ -262,7 +262,8 @@ $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$
$$(call cmd,$1_$2_HC) -o $$@ $$($1_$2_$$($1_$2_PROGRAM_WAY)_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_GHC_LD_OPTS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
ifeq "$$($1_$2_PROGRAM_WAY)" "dyn"
- $(call relative-dynlib-references,$1,$2,$3)
+ $(call relative-dynlib-references,$1,$2,$3)
+ $(call relative-dynlib-path,$3)
endif
else
$1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
diff --git a/rules/relative-dynlib-references.mk b/rules/relative-dynlib-references.mk
index 923ef08..e117dde 100644
--- a/rules/relative-dynlib-references.mk
+++ b/rules/relative-dynlib-references.mk
@@ -18,17 +18,37 @@ define relative-dynlib-references
# $1 = dir
# $2 = distdir
# $3 = GHC stage to use (0 == bootstrapping compiler)
+# $4 = RTSway
ifeq "$$(TargetOS_CPP)" "darwin"
ifneq "$3" "0"
# Use relative paths for all the libraries
ifneq "$$($1_$2_TRANSITIVE_DEP_NAMES)" ""
- install_name_tool $$(foreach d,$$($1_$2_TRANSITIVE_DEP_NAMES), -change $$(TOP)/$$($$($$d_INSTALL_INFO)_dyn_LIB) @loader_path/../$$d-$$($$($$d_INSTALL_INFO)_VERSION)/$$($$($$d_INSTALL_INFO)_dyn_LIB_NAME)) $$@
+ install_name_tool $$(foreach d,$$($1_$2_TRANSITIVE_DEP_NAMES), -change $$(TOP)/$$($$($$d_INSTALL_INFO)_dyn_LIB) @rpath/$$d-$$($$($$d_INSTALL_INFO)_VERSION)/$$($$($$d_INSTALL_INFO)_dyn_LIB_NAME)) $$@
+endif
+# Change absolute library name/path to a relative name/path
+ifeq "$$($1_$2_PROGNAME)" ""
+ifeq "$1" "rts"
+ install_name_tool -id @rpath/rts-$$(rts_VERSION)/$$(rts_$4_LIB_NAME) $$@
+else
+ install_name_tool -id @rpath/$$($1_PACKAGE)-$$($1_$2_VERSION)/$$($1_$2_dyn_LIB_NAME) $$@
+endif
endif
# Use relative paths for the RTS. Rather than try to work out which RTS
# way is being linked, we just change it for all ways
- install_name_tool $$(foreach w,$$(rts_WAYS), -change $$(TOP)/$$(rts_$$w_LIB) @loader_path/../rts-$$(rts_VERSION)/$$(rts_$$w_LIB_NAME)) $$@
- install_name_tool -change $$(TOP)/$$(wildcard libffi/build/inst/lib/libffi.*.dylib) @loader_path/../rts-$$(rts_VERSION)/libffi.dylib $$@
+ install_name_tool $$(foreach w,$$(rts_WAYS), -change $$(TOP)/$$(rts_$$w_LIB) @rpath/rts-$$(rts_VERSION)/$$(rts_$$w_LIB_NAME)) $$@
+ install_name_tool -change $$(TOP)/$$(wildcard libffi/build/inst/lib/libffi.*.dylib) @rpath/rts-$$(rts_VERSION)/libffi.dylib $$@
+endif
+endif
+
+endef
+
+define relative-dynlib-path
+# $1 = GHC stage to use (0 == bootstrapping compiler)
+
+ifeq "$$(TargetOS_CPP)" "darwin"
+ifneq "$1" "0"
+ install_name_tool -rpath $$(TOP)/inplace/lib @loader_path/.. $$@
endif
endif
More information about the ghc-commits
mailing list