From 572bd71ab1333a82fb808ce84e8e364eaad960e8 Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Fri, 20 Nov 2015 10:25:59 -0800
Subject: [PATCH] add GNUR_NOCLEAN option for native project; add Rblas,Rlapack
 libs to stats.so link

---
 com.oracle.truffle.r.native/Makefile               | 1 +
 com.oracle.truffle.r.native/gnur/Makefile          | 4 ++++
 com.oracle.truffle.r.native/gnur/Makefile.platform | 4 +++-
 com.oracle.truffle.r.native/gnur/edAddFASTR        | 1 +
 com.oracle.truffle.r.native/gnur/sedMakeconf       | 4 +++-
 com.oracle.truffle.r.native/library/lib.mk         | 2 +-
 com.oracle.truffle.r.native/library/stats/Makefile | 7 +++++++
 com.oracle.truffle.r.native/run/Makefile           | 1 -
 8 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/com.oracle.truffle.r.native/Makefile b/com.oracle.truffle.r.native/Makefile
index f44d911756..b180b74236 100644
--- a/com.oracle.truffle.r.native/Makefile
+++ b/com.oracle.truffle.r.native/Makefile
@@ -26,6 +26,7 @@
 .PHONY: all clean 
 
 export TOPDIR = $(CURDIR)
+export FASTR_R_HOME=$(abspath $(TOPDIR)/..)
 export R_VERSION = 3.1.3
 export GNUR_HOME = $(TOPDIR)/gnur/R-$(R_VERSION)
 
diff --git a/com.oracle.truffle.r.native/gnur/Makefile b/com.oracle.truffle.r.native/gnur/Makefile
index 8b03467838..af3055b9ce 100644
--- a/com.oracle.truffle.r.native/gnur/Makefile
+++ b/com.oracle.truffle.r.native/gnur/Makefile
@@ -34,5 +34,9 @@ clean: cleangnur
 	$(MAKE) -f Makefile.libs clean
 	$(MAKE) -f Makefile.platform clean
 
+ifdef GNUR_NOCLEAN
+cleangnur:
+else
 cleangnur:
 	$(MAKE) -f Makefile.gnur clean
+endif
diff --git a/com.oracle.truffle.r.native/gnur/Makefile.platform b/com.oracle.truffle.r.native/gnur/Makefile.platform
index 87d020acba..0ddd1dd4b3 100644
--- a/com.oracle.truffle.r.native/gnur/Makefile.platform
+++ b/com.oracle.truffle.r.native/gnur/Makefile.platform
@@ -29,10 +29,12 @@
 OS_NAME := $(shell uname)
 OS_DIR := $(shell echo $(OS_NAME) | tr '[:upper:]' '[:lower:]' )
 
+# need to work from etc/Makeconf as that is the package building version
+
 all: $(TOPDIR)/platform.mk
 
 $(TOPDIR)/platform.mk: sedMakeconf $(GNUR_HOME)/Makeconf Makefile
-	sed -f sedMakeconf $(GNUR_HOME)/Makeconf > /dev/null 2>&1
+	sed -f sedMakeconf $(GNUR_HOME)/etc/Makeconf > /dev/null 2>&1
 	ed platform.mk.temp < edAddFASTR
 	echo OS_NAME = $(OS_NAME) >> platform.mk.temp
 ifeq ($(OS_NAME),SunOS)
diff --git a/com.oracle.truffle.r.native/gnur/edAddFASTR b/com.oracle.truffle.r.native/gnur/edAddFASTR
index 10c04ca978..68d400296b 100644
--- a/com.oracle.truffle.r.native/gnur/edAddFASTR
+++ b/com.oracle.truffle.r.native/gnur/edAddFASTR
@@ -1,3 +1,4 @@
+/R_HOME/s/R_HOME/FASTR_R_HOME
 /^CFLAGS/s/$/ -DFASTR/
 w
 q
diff --git a/com.oracle.truffle.r.native/gnur/sedMakeconf b/com.oracle.truffle.r.native/gnur/sedMakeconf
index 8c1c92bd3c..2669ec6bef 100644
--- a/com.oracle.truffle.r.native/gnur/sedMakeconf
+++ b/com.oracle.truffle.r.native/gnur/sedMakeconf
@@ -4,5 +4,7 @@
 /^F77 =.*/ w platform.mk.temp
 /^FFLAGS =.*/ w platform.mk.temp
 /^FPICFLAGS =.*/ w platform.mk.temp
-/^FLIBS_IN_SO =.*/ w platform.mk.temp
+/^FLIBS =.*/ w platform.mk.temp
+/^BLAS_LIBS =.*/ w platform.mk.temp
+/^LAPACK_LIBS =.*/ w platform.mk.temp
 /^SHLIB_.* = .*/ w platform.mk.temp
diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk
index b043cac179..e525e23d1b 100644
--- a/com.oracle.truffle.r.native/library/lib.mk
+++ b/com.oracle.truffle.r.native/library/lib.mk
@@ -89,7 +89,7 @@ $(OBJ):
 
 $(LIB_PKG): $(C_OBJECTS) $(F_OBJECTS) $(PKGDIR)
 	mkdir -p $(LIBDIR)
-	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_PKG) $(C_OBJECTS) $(F_OBJECTS) $(FLIBS_IN_SO)
+	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_PKG) $(C_OBJECTS) $(F_OBJECTS) $(PKG_LIBS)
 	mkdir -p $(FASTR_LIBDIR)/$(PKG)/libs
 	cp $(LIB_PKG) $(FASTR_LIBDIR)/$(PKG)/libs
 
diff --git a/com.oracle.truffle.r.native/library/stats/Makefile b/com.oracle.truffle.r.native/library/stats/Makefile
index 38f19a3912..a899a33821 100644
--- a/com.oracle.truffle.r.native/library/stats/Makefile
+++ b/com.oracle.truffle.r.native/library/stats/Makefile
@@ -27,6 +27,13 @@ LIB_PKG_PRE = $(OBJ)/fft.o
 GNUR_FFT := $(GNUR_HOME)/src/library/stats/src/fft.c
 CLEAN_PKG := cleanfft
 
+# have to incldue this here for PKG_LIBS
+ifneq ($(MAKECMDGOALS),clean)
+include $(TOPDIR)/platform.mk
+endif
+
+PKG_LIBS := $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
+
 include ../lib.mk
 
 # The above will set set C_SOURCES to all the .c files in src
diff --git a/com.oracle.truffle.r.native/run/Makefile b/com.oracle.truffle.r.native/run/Makefile
index 2fef3f4024..c627402916 100644
--- a/com.oracle.truffle.r.native/run/Makefile
+++ b/com.oracle.truffle.r.native/run/Makefile
@@ -37,7 +37,6 @@
 
 .PHONY: bindir all rcmd
 
-FASTR_R_HOME := $(abspath $(TOPDIR)/..)
 FASTR_BIN_DIR := $(FASTR_R_HOME)/bin
 FASTR_ETC_DIR := $(FASTR_R_HOME)/etc
 FASTR_SHARE_DIR := $(FASTR_R_HOME)/share
-- 
GitLab