Get dynamic-by-default mostly working on OS X
authorIan Lynagh <igloo@earth.li>
Sun, 14 Oct 2012 12:36:08 +0000 (13:36 +0100)
committerIan Lynagh <igloo@earth.li>
Sun, 14 Oct 2012 14:31:07 +0000 (15:31 +0100)
rts/ghc.mk
rules/build-package-way.mk
rules/build-package.mk
rules/build-prog.mk
rules/shell-wrapper.mk

index 2147c1f..36df61d 100644 (file)
@@ -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)
index aa3f277..7a028d5 100644 (file)
@@ -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]
index d21f449..c0b9902 100644 (file)
@@ -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
index a0cb9e6..df96598 100644 (file)
@@ -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))
index 8085ad1..395968a 100644 (file)
@@ -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)                                   >> $$@