From 3e18f8be62b06c846b52d79717f79d51e2060593 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Fri, 4 Dec 2009 14:36:14 +0000 Subject: [PATCH] Link all dynamic libraries with the correct install_name on Mac OS/X. This is a rerecord of Stephen Blackheath **20090930222855 to avoid conflicts. --- ghc.mk | 7 +------ libffi/ghc.mk | 8 ++++++++ mk/fix_install_names.sh | 32 -------------------------------- rts/ghc.mk | 7 ++++++- rules/build-package-way.mk | 1 + 5 files changed, 16 insertions(+), 39 deletions(-) delete mode 100644 mk/fix_install_names.sh diff --git a/ghc.mk b/ghc.mk index 706136b..56be5fa 100644 --- a/ghc.mk +++ b/ghc.mk @@ -751,9 +751,6 @@ install_bins: $(INSTALL_BINS) $(INSTALL_DIR) "$(DESTDIR)$(bindir)" for i in $(INSTALL_BINS); do \ $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(bindir)" ; \ - if test "$(darwin_TARGET_OS)" = "1"; then \ - sh mk/fix_install_names.sh $(ghclibdir) "$(DESTDIR)$(bindir)/$$i" ; \ - fi ; \ done install_libs: $(INSTALL_LIBS) @@ -768,8 +765,7 @@ install_libs: $(INSTALL_LIBS) *.so) \ $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)" ;; \ *.dylib) \ - $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)"; \ - install_name_tool -id "$(DESTDIR)$(ghclibdir)/`basename $$i`" "$(DESTDIR)$(ghclibdir)/`basename $$i`" ;; \ + $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)";; \ *) \ $(INSTALL_DATA) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)"; \ esac; \ @@ -930,7 +926,6 @@ $(eval $(call bindist,.,\ $(wildcard libraries/*/dist-install/doc/) \ $(filter-out extra-gcc-opts,$(INSTALL_LIBS)) \ $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \ - mk/fix_install_names.sh \ mk/project.mk \ mk/install.mk.in \ bindist.mk \ diff --git a/libffi/ghc.mk b/libffi/ghc.mk index 7104d04..92e11dd 100644 --- a/libffi/ghc.mk +++ b/libffi/ghc.mk @@ -84,10 +84,14 @@ libffi_DYNAMIC_PROG = $(libffi_HS_DYN_LIB).a libffi_DYNAMIC_LIBS = $(libffi_HS_DYN_LIB) else libffi_DYNAMIC_PROG = +ifeq "$(darwin_TARGET_OS)" "1" +libffi_DYNAMIC_LIBS = libffi/libffi$(soext) libffi/libffi.5$(soext) libffi/libffi.5.0.9$(soext) +else libffi_DYNAMIC_LIBS = libffi/dist-install/build/libffi.so \ libffi/dist-install/build/libffi.so.5 \ libffi/dist-install/build/libffi.so.5.0.9 endif +endif ifeq "$(BuildSharedLibs)" "YES" libffi_EnableShared=yes @@ -200,6 +204,10 @@ $(libffi_DYNAMIC_LIBS): $(libffi_STAMP_BUILD) # Rename libffi.so to libHSffi...so $(libffi_HS_DYN_LIB): $(libffi_DYNAMIC_LIBS) | $$(dir $$@)/. "$(CP)" $(word 1,$(libffi_DYNAMIC_LIBS)) $(libffi_HS_DYN_LIB) +ifeq "$(darwin_TARGET_OS)" "1" + # Ensure library's install name is correct before anyone links with it. + install_name_tool -id $(ghclibdir)/$(libffi_HS_DYN_LIB_NAME) $(libffi_HS_DYN_LIB) +endif $(eval $(call all-target,libffi,$(libffi_HS_DYN_LIB))) endif diff --git a/mk/fix_install_names.sh b/mk/fix_install_names.sh deleted file mode 100644 index f6278ce..0000000 --- a/mk/fix_install_names.sh +++ /dev/null @@ -1,32 +0,0 @@ -# Darwin / Mac OS X only -# sh fix_install_names.sh directory binary -# -# Changes 'binary' to assume that all libHS*_dyn.dylib libraries -# are to be found in 'directory'. - -prefix=$1 -file=$2 - -type=`file "$file"` - -if `test "${type/Mach-O}" == "$type"` -then - exit -fi - -if `test x${prefix%/} != x"" ` -then - prefix=${prefix%/}/ -fi - -for i in `otool -L $file \ - | grep 'libHS.*_dyn.dylib' \ - | sed 's/.\(.*libHS.*_dyn.dylib\).*/\1/'` -do - install_name_tool -change $i "$prefix`basename $i`" $file -done - -if `test "${file%.dylib}" != "${file}"` -then - install_name_tool -id "$prefix`basename $file`" $file -fi diff --git a/rts/ghc.mk b/rts/ghc.mk index 853e3d8..f973b67 100644 --- a/rts/ghc.mk +++ b/rts/ghc.mk @@ -141,7 +141,8 @@ $(call cmm-suffix-rules,rts,dist,$1) $(call hs-suffix-rules-srcdir,rts,dist,$1,$$(dir)) # hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules -rts_$1_LIB = rts/dist/build/libHSrts$$($1_libsuf) +rts_$1_LIB_NAME = libHSrts$$($1_libsuf) +rts_$1_LIB = rts/dist/build/$$(rts_$1_LIB_NAME) rts_$1_C_OBJS = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS)) rts_$1_S_OBJS = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS)) @@ -158,6 +159,10 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend "$$(RM)" $$(RM_OPTS) $$@ "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \ -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@ +ifeq "$(darwin_TARGET_OS)" "1" + # Ensure library's install name is correct before anyone links with it. + install_name_tool -id $(ghclibdir)/$$(rts_$1_LIB_NAME) $$@ +endif else $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend "$$(RM)" $$(RM_OPTS) $$@ diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk index 26eacfe..ef4477f 100644 --- a/rules/build-package-way.mk +++ b/rules/build-package-way.mk @@ -67,6 +67,7 @@ $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS) "$$($1_$2_HC)" $$($1_$2_$3_ALL_OBJS) \ `$$($1_$2_$3_MKSTUBOBJS)` \ -shared -dynamic -dynload deploy \ + -dylib-install-name $(ghclibdir)/`basename "$$@" | sed 's/^libHS//;s/[-]ghc.*//'`/`basename "$$@"` \ -no-auto-link-packages $$(addprefix -package,$$($1_$2_DEPS)) \ -o $$@ endif -- 1.7.10.4