From f1045a61a97fabac9288717fa702c17bffc473ec Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Fri, 18 Mar 2016 18:23:03 -0700
Subject: [PATCH] make .dylib id absolute; fixes install of packages that
 reference Rblas etc.

---
 com.oracle.truffle.r.native/gnur/Makefile.libs     | 10 ++++++++--
 com.oracle.truffle.r.native/library/lib.mk         |  3 +++
 com.oracle.truffle.r.native/library/stats/Makefile | 10 +---------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/com.oracle.truffle.r.native/gnur/Makefile.libs b/com.oracle.truffle.r.native/gnur/Makefile.libs
index 684c391b72..e71c08f885 100644
--- a/com.oracle.truffle.r.native/gnur/Makefile.libs
+++ b/com.oracle.truffle.r.native/gnur/Makefile.libs
@@ -21,10 +21,14 @@
 # questions.
 #
 
-# Copies the Blas and lapack libraries and builds the pcre library
+# Copies the Blas and lapack libraries and (maybe) builds the pcre library
 
-ifneq ($(MAKECMDGOALS),clean)
+ifneq (,$(wildcard $(TOPDIR)/platform.mk))
 include $(TOPDIR)/platform.mk
+else
+ifneq ($(MAKECMDGOALS),clean)
+$(error no platform.mk available)
+endif
 endif
 
 TARGET_DIR := $(abspath $(TOPDIR)/../lib)
@@ -45,6 +49,8 @@ $(LAPACK_TARGET): $(GNUR_HOME)/lib/libRlapack$(DYLIB_EXT)
 ifeq ($(OS_NAME),Darwin)
 	install_name_tool -change libRblas.dylib $(BLAS_TARGET) $(LAPACK_TARGET)
 	install_name_tool -change libR.dylib $(TARGET_DIR)/libR.dylib $(LAPACK_TARGET)
+	install_name_tool -id $(BLAS_TARGET) $(BLAS_TARGET)
+	install_name_tool -id $(LAPACK_TARGET) $(LAPACK_TARGET)
 endif
 
 PCRE_OBJS := $(wildcard $(GNUR_HOME)/src/extra/pcre/pcre_*.o)
diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk
index 4ca0f7eeaf..ea7cec010d 100644
--- a/com.oracle.truffle.r.native/library/lib.mk
+++ b/com.oracle.truffle.r.native/library/lib.mk
@@ -108,6 +108,9 @@ $(LIB_PKG): $(C_OBJECTS) $(F_OBJECTS) $(GNUR_C_OBJECTS) $(GNUR_F_OBJECTS) $(PKGD
 	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_PKG) $(C_OBJECTS) $(F_OBJECTS) $(GNUR_C_OBJECTS) $(GNUR_F_OBJECTS) $(PKG_LIBS)
 	mkdir -p $(FASTR_LIBRARY_DIR)/$(PKG)/libs
 	cp $(LIB_PKG) $(FASTR_LIBRARY_DIR)/$(PKG)/libs
+ifeq ($(OS_NAME),Darwin)
+	install_name_tool -id $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so
+endif
 
 $(OBJ)/%.o: $(SRC)/%.c $(H_SOURCES)
 	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
diff --git a/com.oracle.truffle.r.native/library/stats/Makefile b/com.oracle.truffle.r.native/library/stats/Makefile
index 338aa50c54..70d012c0e1 100644
--- a/com.oracle.truffle.r.native/library/stats/Makefile
+++ b/com.oracle.truffle.r.native/library/stats/Makefile
@@ -26,12 +26,11 @@
 # GnuR stats library source - those that do not depend on GnuR internals (always true for .f)
 # Also do some necessary modifications to a copy of fft.c.
 
-.PHONY: cleanpkg nametool
+.PHONY: cleanpkg
 
 GNUR_FFT = $(addprefix $(GNUR_HOME)/src/library/stats/src/, fft.c)
 FFT_OBJECT = $(addprefix $(OBJ)/, fft.o)
 LIB_PKG_PRE = $(FFT_OBJECT)
-LIB_PKG_POST = nametool
 CLEAN_PKG := cleanpkg
 
 
@@ -71,12 +70,5 @@ $(OBJ)/%.o: $(GNUR_SRC)/%.c
 $(OBJ)/%.o: $(GNUR_SRC)/%.f
 	$(F77) $(FFLAGS) $(FPICFLAGS) -c $< -o $@
 
-# ensure that the references to Rblas, Rlapack and appl are absolute
-nametool:
-ifeq ($(OS_NAME),Darwin)
-	install_name_tool -change libRblas.dylib $(FASTR_R_HOME)/lib/libRblas.dylib $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so
-	install_name_tool -change libRlapack.dylib $(FASTR_R_HOME)/lib/libRlapack.dylib $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so
-endif
-
 cleanpkg:
 	rm -f $(SRC)/fft.c
-- 
GitLab