[commit: ghc] master: Get dynamic-by-default mostly working on OS X (0271742)

Ian Lynagh <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/0271742138ffc55d992be549c027ae690fde5080

>---------------------------------------------------------------

commit 0271742138ffc55d992be549c027ae690fde5080
Author: Ian Lynagh <[email protected]>
Date:   Sun Oct 14 13:36:08 2012 +0100

    Get dynamic-by-default mostly working on OS X

>---------------------------------------------------------------

 rts/ghc.mk                 |    3 +++
 rules/build-package-way.mk |    3 ++-
 rules/build-package.mk     |    4 ++++
 rules/build-prog.mk        |   15 +++++++++++++++
 rules/shell-wrapper.mk     |    4 ++++
 5 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/rts/ghc.mk b/rts/ghc.mk
index 2147c1f..36df61d 100644
--- a/rts/ghc.mk
+++ b/rts/ghc.mk
@@ -16,6 +16,9 @@
 # We build the RTS with stage 1
 rts_dist_HC = $(GHC_STAGE1)
 
+rts_INSTALL_INFO = rts
+rts_VERSION = 1.0
+
 # merge GhcLibWays and GhcRTSWays but strip out duplicates
 rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
 rts_dist_WAYS = $(rts_WAYS)
diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk
index aa3f277..7a028d5 100644
--- a/rules/build-package-way.mk
+++ b/rules/build-package-way.mk
@@ -25,7 +25,8 @@ $(call hs-objs,$1,$2,$3)
 # The .a/.so library file, indexed by two different sets of vars:
 # the first is indexed by the dir, distdir and way
 # the second is indexed by the package id, distdir and way
-$1_$2_$3_LIB = $1/$2/build/libHS$$($1_PACKAGE)-$$($1_$2_VERSION)$$($3_libsuf)
+$1_$2_$3_LIB_NAME = libHS$$($1_PACKAGE)-$$($1_$2_VERSION)$$($3_libsuf)
+$1_$2_$3_LIB = $1/$2/build/$$($1_$2_$3_LIB_NAME)
 $$($1_PACKAGE)-$$($1_$2_VERSION)_$2_$3_LIB = $$($1_$2_$3_LIB)
 
 # Note [inconsistent distdirs]
diff --git a/rules/build-package.mk b/rules/build-package.mk
index d21f449..c0b9902 100644
--- a/rules/build-package.mk
+++ b/rules/build-package.mk
@@ -66,6 +66,10 @@ define build-package-helper
 
 $(call package-config,$1,$2,$3)
 
+ifeq "$3" "1"
+$$($1_PACKAGE)_INSTALL_INFO = $1_$2
+endif
+
 # Bootstrapping libs are only built one way
 ifeq "$3" "0"
 $1_$2_WAYS = v
diff --git a/rules/build-prog.mk b/rules/build-prog.mk
index a0cb9e6..df96598 100644
--- a/rules/build-prog.mk
+++ b/rules/build-prog.mk
@@ -173,9 +173,13 @@ endif
 
 ifneq "$3" "0"
 ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$$(TargetOS_CPP)" "linux"
 $1_$2_GHC_LD_OPTS = \
     -fno-use-rpaths \
     $$(foreach d,$$($1_$2_TRANSITIVE_DEPS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d')
+else ifeq "$$(TargetOS_CPP)" "darwin"
+$1_$2_GHC_LD_OPTS = -optl-Wl,-headerpad_max_install_names
+endif
 endif
 endif
 
@@ -194,6 +198,17 @@ $1/$2/build/tmp/$$($1_$2_PROG) : \
 ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
 $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 $$$$@)/.
 	$$(call cmd,$1_$2_HC) -o $$@ $$($1_$2_$$($1_$2_PROGRAM_WAY)_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_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 "$$(TargetOS_CPP)" "darwin"
+ifneq "$3" "0"
+ifeq "$$($1_$2_PROGRAM_WAY)" "dyn"
+# Use relative paths for all the libraries
+	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)) $$@
+# 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/../$$d-$$(rts_VERSION)/$$(rts_$$w_LIB_NAME)) $$@
+endif
+endif
+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 $$$$@)/.
 	$$(call cmd,$1_$2_CC) -o $$@ $$($1_$2_$$($1_$2_PROGRAM_WAY)_ALL_CC_OPTS) $$(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) $$($1_$2_$$($1_$2_PROGRAM_WAY)_EXTRA_CC_OPTS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
diff --git a/rules/shell-wrapper.mk b/rules/shell-wrapper.mk
index 8085ad1..395968a 100644
--- a/rules/shell-wrapper.mk
+++ b/rules/shell-wrapper.mk
@@ -45,7 +45,11 @@ $$(INPLACE_WRAPPER): $$($1_$2_INPLACE)
 	$$($1_$2_SHELL_WRAPPER_EXTRA)
 	$$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
 ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$$(TargetOS_CPP)" "linux"
 	echo 'export LD_LIBRARY_PATH="$$($1_$2_DEP_LIB_DIRS_SEARCHPATH)"'  >> $$@
+else ifeq "$$(TargetOS_CPP)" "darwin"
+	echo 'export DYLD_LIBRARY_PATH="$$($1_$2_DEP_LIB_DIRS_SEARCHPATH)"' >> $$@
+endif
 endif
 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
 	cat $$($1_$2_SHELL_WRAPPER_NAME)                                   >> $$@
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.