Fix the dynmaic library paths in the libs, as well as in the programs
authorIan Lynagh <ian@well-typed.com>
Sat, 22 Jun 2013 19:34:12 +0000 (20:34 +0100)
committerIan Lynagh <ian@well-typed.com>
Sat, 22 Jun 2013 19:34:12 +0000 (20:34 +0100)
Part of #7833

ghc.mk
rules/build-package-way.mk
rules/build-prog.mk
rules/relative-dynlib-references.mk [new file with mode: 0644]

diff --git a/ghc.mk b/ghc.mk
index e337ddd..87b6ac8 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -283,6 +283,11 @@ include rules/build-dependencies.mk
 include rules/include-dependencies.mk
 
 # -----------------------------------------------------------------------------
+# Dynamic library references
+
+include rules/relative-dynlib-references.mk
+
+# -----------------------------------------------------------------------------
 # Build package-data.mk files
 
 include rules/build-package-data.mk
index b772317..780b8b0 100644 (file)
@@ -91,6 +91,7 @@ $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
         $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES)) $$(addprefix -L,$$($1_$2_EXTRA_LIBDIRS)) \
          -no-auto-link-packages \
          -o $$@
+       $(call relative-dynlib-references,$1,$2,$4)
 endif
 else
 # Build the ordinary .a library
index 17d64da..8c49946 100644 (file)
@@ -260,19 +260,9 @@ else
 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_$$($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 "$$(TargetOS_CPP)" "darwin"
-ifneq "$3" "0"
+
 ifeq "$$($1_$2_PROGRAM_WAY)" "dyn"
-# 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)) $$@
-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 $$@
-endif
-endif
+    $(call relative-dynlib-references,$1,$2,$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
new file mode 100644 (file)
index 0000000..03dabc1
--- /dev/null
@@ -0,0 +1,35 @@
+# -----------------------------------------------------------------------------
+#
+# (c) 2009 The University of Glasgow
+#
+# This file is part of the GHC build system.
+#
+# To understand how the build system works and how to modify it, see
+#      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
+#      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
+#
+# -----------------------------------------------------------------------------
+
+
+# Make dynlib references use relative paths, so that everything works
+# without the build tree.
+
+define relative-dynlib-references
+# $1 = dir
+# $2 = distdir
+# $3 = GHC stage to use (0 == bootstrapping compiler)
+
+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)) $$@
+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 $$@
+endif
+endif
+
+endef