From 3c050d288d6c7721f7231025b0c70121c652c974 Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Thu, 21 Aug 2014 16:57:25 -0700
Subject: [PATCH] consolidate native projects and be consistent in Makefiles

---
 com.oracle.truffle.r.native/Makefile          |  83 ++----------------
 .../builtinlibs/Makefile                      |  75 ++++++++++++++++
 .../{ => builtinlibs}/lib/darwin/libR.dylib   | Bin
 .../lib/darwin/libRDerived.dylib              | Bin
 .../lib/darwin/libRblas.dylib                 | Bin
 .../lib/darwin/libRlapack.dylib               | Bin
 .../lib/linux/libRDerived.so                  | Bin
 .../{ => builtinlibs}/lib/linux/libRblas.so   | Bin
 .../{ => builtinlibs}/lib/linux/libRlapack.so | Bin
 .../lib/sunos/libRDerived.so                  | Bin
 .../{ => builtinlibs}/lib/sunos/libRblas.so   | Bin
 .../{ => builtinlibs}/lib/sunos/libRlapack.so | Bin
 .../{ => builtinlibs}/src/dchdc.f             |   0
 .../{ => builtinlibs}/src/dpbfa.f             |   0
 .../{ => builtinlibs}/src/dpbsl.f             |   0
 .../{ => builtinlibs}/src/dpoco.f             |   0
 .../{ => builtinlibs}/src/dpodi.f             |   0
 .../{ => builtinlibs}/src/dpofa.f             |   0
 .../{ => builtinlibs}/src/dposl.f             |   0
 .../{ => builtinlibs}/src/dqrdc.f             |   0
 .../{ => builtinlibs}/src/dqrdc2.f            |   0
 .../{ => builtinlibs}/src/dqrls.f             |   0
 .../{ => builtinlibs}/src/dqrsl.f             |   0
 .../{ => builtinlibs}/src/dqrutl.f            |   0
 .../{ => builtinlibs}/src/dsvdc.f             |   0
 .../{ => builtinlibs}/src/dtrco.f             |   0
 .../{ => builtinlibs}/src/dtrsl.f             |   0
 .../{ => builtinlibs}/src/fft.c               |   0
 .../fficall}/Makefile                         |  10 +--
 .../fficall/jni}/Makefile                     |  45 +++++-----
 .../fficall/jni}/src/call.c                   |   0
 .../include/jni}/R.h                          |   0
 .../include/{ => jni}/R_ext/Boolean.h         |   0
 .../include/{ => jni}/R_ext/Random.h          |   0
 .../include/jni}/Rdefines.h                   |   0
 .../include/jni}/Rinternals.h                 |   0
 com.oracle.truffle.r.native/platform.mk       |  53 +++++++++++
 .../.project                                  |  11 ---
 .../r/runtime/ffi/jnr/CallRFFIWithJNI.java    |  23 +----
 .../oracle/truffle/r/runtime/RPlatform.java   |  66 ++++++++++++++
 com.oracle.truffle.r.test.native/Makefile     |   8 +-
 .../urand}/Makefile                           |  58 +++++-------
 .../truffle/r/test/rffi/TestUserRNG.java      |   2 +-
 mx.fastr/copyrights/overrides                 |  14 +--
 mx.fastr/mx_fastr.py                          |   2 +-
 mx.fastr/projects                             |   5 --
 46 files changed, 268 insertions(+), 187 deletions(-)
 create mode 100644 com.oracle.truffle.r.native/builtinlibs/Makefile
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/darwin/libR.dylib (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/darwin/libRDerived.dylib (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/darwin/libRblas.dylib (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/darwin/libRlapack.dylib (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/linux/libRDerived.so (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/linux/libRblas.so (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/linux/libRlapack.so (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/sunos/libRDerived.so (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/sunos/libRblas.so (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/lib/sunos/libRlapack.so (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dchdc.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dpbfa.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dpbsl.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dpoco.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dpodi.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dpofa.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dposl.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dqrdc.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dqrdc2.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dqrls.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dqrsl.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dqrutl.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dsvdc.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dtrco.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/dtrsl.f (100%)
 rename com.oracle.truffle.r.native/{ => builtinlibs}/src/fft.c (100%)
 rename {com.oracle.truffle.r.runtime.ffi.native => com.oracle.truffle.r.native/fficall}/Makefile (90%)
 rename {com.oracle.truffle.r.test.native/urand/src => com.oracle.truffle.r.native/fficall/jni}/Makefile (66%)
 rename {com.oracle.truffle.r.runtime.ffi.native/jni/call => com.oracle.truffle.r.native/fficall/jni}/src/call.c (100%)
 rename {com.oracle.truffle.r.runtime.ffi.native/jni/include => com.oracle.truffle.r.native/include/jni}/R.h (100%)
 rename com.oracle.truffle.r.native/include/{ => jni}/R_ext/Boolean.h (100%)
 rename com.oracle.truffle.r.native/include/{ => jni}/R_ext/Random.h (100%)
 rename {com.oracle.truffle.r.runtime.ffi.native/jni/include => com.oracle.truffle.r.native/include/jni}/Rdefines.h (100%)
 rename {com.oracle.truffle.r.runtime.ffi.native/jni/include => com.oracle.truffle.r.native/include/jni}/Rinternals.h (100%)
 create mode 100644 com.oracle.truffle.r.native/platform.mk
 delete mode 100644 com.oracle.truffle.r.runtime.ffi.native/.project
 create mode 100644 com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RPlatform.java
 rename {com.oracle.truffle.r.runtime.ffi.native/jni/call/src => com.oracle.truffle.r.test.native/urand}/Makefile (56%)

diff --git a/com.oracle.truffle.r.native/Makefile b/com.oracle.truffle.r.native/Makefile
index 6e94512f8c..9aeed08465 100644
--- a/com.oracle.truffle.r.native/Makefile
+++ b/com.oracle.truffle.r.native/Makefile
@@ -21,83 +21,14 @@
 # questions.
 #
 
-#
-# This Makefile contains the recipe for creating libRDerived. However, it is distributed
-# as a "source" in the repository file to avoid users having to have gfortran installed.
-# Use "make cleanlib; make force" to force a rebuild.
-#
-
-OSNAME := $(shell uname)
-
-ifeq ($(OSNAME), Linux)
-  OS_DIR      := linux
-  CC          := gcc
-  FC          := gfortran
-  CFLAGS      := -fPIC -O2
-  LDFLAGS     := -fPIC -shared
-  SHARED_EXT  := so
-  LIBS        := -lgfortran
-else ifeq ($(OSNAME), SunOS)
-  OS_DIR      := sunos
-  CC          := cc
-  FC          := f90
-  CFLAGS      := -m64 -O -xcode=pic13
-  LDFLAGS     := -G -m64
-  SHARED_EXT  := so
-else ifeq ($(OSNAME), Darwin)
-  OS_DIR      := darwin
-  CC          := gcc
-  FC          := gfortran
-  CFLAGS      := -fPIC -O2
-  LDFLAGS     := -dynamiclib -undefined dynamic_lookup
-  SHARED_EXT  := dylib
-else
-all:
-	@echo "This Makefile does not know how to compile for $(OSNAME)"
-	@false
-endif
-
-.PHONY: all clean cleanlib cleanobj force
-
-SRC = src
-OBJ = lib/$(OS_DIR)
-
-C_SOURCES := $(wildcard $(SRC)/*.c)
-F_SOURCES := $(wildcard $(SRC)/*.f)
+.PHONY: all clean
 
-C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
-F_OBJECTS := $(subst $(SRC),$(OBJ),$(F_SOURCES:.f=.o))
-
-LIBDIR := ./lib/$(OS_DIR)
-LIB_DERIVED := lib/$(OS_DIR)/libRDerived.$(SHARED_EXT)
+export TOPDIR = $(CURDIR)
 
 all:
-	@echo $(LIB_DERIVED) is up to date
-
-force: $(LIB_DERIVED)
-	mkdir -p $(LIBDIR)
-# build+install blas and lapack too
-#	$(MAKE) -C src/blas
-#	cp src/blas/libRblas.$(SHARED_EXT) $(LIBDIR)
-#	$(MAKE) -C src/lapack
-#	cp src/lapack/libRlapack.$(SHARED_EXT) $(LIBDIR)
-
-$(LIB_DERIVED): $(C_OBJECTS) $(F_OBJECTS)
-	$(CC) $(LDFLAGS) -o $(LIBDIR)/libRDerived.$(SHARED_EXT) $(C_OBJECTS) $(F_OBJECTS) $(LIBS)
-
-$(OBJ)/%.o: $(SRC)/%.c
-	$(CC) $(CFLAGS) -c $< -o $@
-
-$(OBJ)/%.o: $(SRC)/%.f
-	$(FC) $(CFLAGS) -c $< -o $@
-
-
-cleanlib:
-	rm -f $(LIBDIR)/libRDerived.* $(LIBDIR)/libRblas.$(SHARED_EXT) $(LIBDIR)/libRlapack.$(SHARED_EXT)
-
-clean: cleanobj
-#	$(MAKE) -C src/blas clean
-#	$(MAKE) -C src/lapack clean
+	$(MAKE) -C builtinlibs
+	$(MAKE) -C fficall
 
-cleanobj:
-	rm -f $(LIBDIR)/*.o
+clean:
+	$(MAKE) -C builtinlibs clean
+	$(MAKE) -C fficall clean
diff --git a/com.oracle.truffle.r.native/builtinlibs/Makefile b/com.oracle.truffle.r.native/builtinlibs/Makefile
new file mode 100644
index 0000000000..ff2dd2274f
--- /dev/null
+++ b/com.oracle.truffle.r.native/builtinlibs/Makefile
@@ -0,0 +1,75 @@
+#
+# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+#
+# This Makefile contains the recipe for creating libRDerived. However, it is distributed
+# as a "source" in the repository file to avoid users having to have gfortran installed.
+# Use "make cleanlib; make force" to force a rebuild.
+#
+
+include ../platform.mk
+
+.PHONY: all clean cleanlib cleanobj force
+
+SRC = src
+OBJ = lib/$(OS_DIR)
+
+C_SOURCES := $(wildcard $(SRC)/*.c)
+F_SOURCES := $(wildcard $(SRC)/*.f)
+
+C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
+F_OBJECTS := $(subst $(SRC),$(OBJ),$(F_SOURCES:.f=.o))
+
+LIBDIR := $(OBJ)/$(OS_DIR)
+LIB_DERIVED := $(OBJ)/$(OS_DIR)/libRDerived.$(SHARED_EXT)
+
+all:
+	@echo $(LIB_DERIVED) is up to date
+
+force: $(LIB_DERIVED)
+# build+install blas and lapack too
+#	$(MAKE) -C src/blas
+#	cp src/blas/libRblas.$(SHARED_EXT) $(LIBDIR)
+#	$(MAKE) -C src/lapack
+#	cp src/lapack/libRlapack.$(SHARED_EXT) $(LIBDIR)
+
+$(LIB_DERIVED): $(C_OBJECTS) $(F_OBJECTS)
+	mkdir -p $(LIBDIR)
+	$(CC) $(LDFLAGS) -o $(LIBDIR)/libRDerived.$(SHARED_EXT) $(C_OBJECTS) $(F_OBJECTS) $(LIBS)
+
+$(OBJ)/%.o: $(SRC)/%.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
+$(OBJ)/%.o: $(SRC)/%.f
+	$(FC) $(CFLAGS) -c $< -o $@
+
+
+cleanlib:
+	rm -f $(LIBDIR)/libRDerived.* $(LIBDIR)/libRblas.$(SHARED_EXT) $(LIBDIR)/libRlapack.$(SHARED_EXT)
+
+clean: cleanobj
+#	$(MAKE) -C src/blas clean
+#	$(MAKE) -C src/lapack clean
+
+cleanobj:
+	rm -f $(LIBDIR)/*.o
diff --git a/com.oracle.truffle.r.native/lib/darwin/libR.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libR.dylib
similarity index 100%
rename from com.oracle.truffle.r.native/lib/darwin/libR.dylib
rename to com.oracle.truffle.r.native/builtinlibs/lib/darwin/libR.dylib
diff --git a/com.oracle.truffle.r.native/lib/darwin/libRDerived.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRDerived.dylib
similarity index 100%
rename from com.oracle.truffle.r.native/lib/darwin/libRDerived.dylib
rename to com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRDerived.dylib
diff --git a/com.oracle.truffle.r.native/lib/darwin/libRblas.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRblas.dylib
similarity index 100%
rename from com.oracle.truffle.r.native/lib/darwin/libRblas.dylib
rename to com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRblas.dylib
diff --git a/com.oracle.truffle.r.native/lib/darwin/libRlapack.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRlapack.dylib
similarity index 100%
rename from com.oracle.truffle.r.native/lib/darwin/libRlapack.dylib
rename to com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRlapack.dylib
diff --git a/com.oracle.truffle.r.native/lib/linux/libRDerived.so b/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRDerived.so
similarity index 100%
rename from com.oracle.truffle.r.native/lib/linux/libRDerived.so
rename to com.oracle.truffle.r.native/builtinlibs/lib/linux/libRDerived.so
diff --git a/com.oracle.truffle.r.native/lib/linux/libRblas.so b/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRblas.so
similarity index 100%
rename from com.oracle.truffle.r.native/lib/linux/libRblas.so
rename to com.oracle.truffle.r.native/builtinlibs/lib/linux/libRblas.so
diff --git a/com.oracle.truffle.r.native/lib/linux/libRlapack.so b/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRlapack.so
similarity index 100%
rename from com.oracle.truffle.r.native/lib/linux/libRlapack.so
rename to com.oracle.truffle.r.native/builtinlibs/lib/linux/libRlapack.so
diff --git a/com.oracle.truffle.r.native/lib/sunos/libRDerived.so b/com.oracle.truffle.r.native/builtinlibs/lib/sunos/libRDerived.so
similarity index 100%
rename from com.oracle.truffle.r.native/lib/sunos/libRDerived.so
rename to com.oracle.truffle.r.native/builtinlibs/lib/sunos/libRDerived.so
diff --git a/com.oracle.truffle.r.native/lib/sunos/libRblas.so b/com.oracle.truffle.r.native/builtinlibs/lib/sunos/libRblas.so
similarity index 100%
rename from com.oracle.truffle.r.native/lib/sunos/libRblas.so
rename to com.oracle.truffle.r.native/builtinlibs/lib/sunos/libRblas.so
diff --git a/com.oracle.truffle.r.native/lib/sunos/libRlapack.so b/com.oracle.truffle.r.native/builtinlibs/lib/sunos/libRlapack.so
similarity index 100%
rename from com.oracle.truffle.r.native/lib/sunos/libRlapack.so
rename to com.oracle.truffle.r.native/builtinlibs/lib/sunos/libRlapack.so
diff --git a/com.oracle.truffle.r.native/src/dchdc.f b/com.oracle.truffle.r.native/builtinlibs/src/dchdc.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dchdc.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dchdc.f
diff --git a/com.oracle.truffle.r.native/src/dpbfa.f b/com.oracle.truffle.r.native/builtinlibs/src/dpbfa.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dpbfa.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dpbfa.f
diff --git a/com.oracle.truffle.r.native/src/dpbsl.f b/com.oracle.truffle.r.native/builtinlibs/src/dpbsl.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dpbsl.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dpbsl.f
diff --git a/com.oracle.truffle.r.native/src/dpoco.f b/com.oracle.truffle.r.native/builtinlibs/src/dpoco.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dpoco.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dpoco.f
diff --git a/com.oracle.truffle.r.native/src/dpodi.f b/com.oracle.truffle.r.native/builtinlibs/src/dpodi.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dpodi.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dpodi.f
diff --git a/com.oracle.truffle.r.native/src/dpofa.f b/com.oracle.truffle.r.native/builtinlibs/src/dpofa.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dpofa.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dpofa.f
diff --git a/com.oracle.truffle.r.native/src/dposl.f b/com.oracle.truffle.r.native/builtinlibs/src/dposl.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dposl.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dposl.f
diff --git a/com.oracle.truffle.r.native/src/dqrdc.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrdc.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dqrdc.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dqrdc.f
diff --git a/com.oracle.truffle.r.native/src/dqrdc2.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrdc2.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dqrdc2.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dqrdc2.f
diff --git a/com.oracle.truffle.r.native/src/dqrls.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrls.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dqrls.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dqrls.f
diff --git a/com.oracle.truffle.r.native/src/dqrsl.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrsl.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dqrsl.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dqrsl.f
diff --git a/com.oracle.truffle.r.native/src/dqrutl.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrutl.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dqrutl.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dqrutl.f
diff --git a/com.oracle.truffle.r.native/src/dsvdc.f b/com.oracle.truffle.r.native/builtinlibs/src/dsvdc.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dsvdc.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dsvdc.f
diff --git a/com.oracle.truffle.r.native/src/dtrco.f b/com.oracle.truffle.r.native/builtinlibs/src/dtrco.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dtrco.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dtrco.f
diff --git a/com.oracle.truffle.r.native/src/dtrsl.f b/com.oracle.truffle.r.native/builtinlibs/src/dtrsl.f
similarity index 100%
rename from com.oracle.truffle.r.native/src/dtrsl.f
rename to com.oracle.truffle.r.native/builtinlibs/src/dtrsl.f
diff --git a/com.oracle.truffle.r.native/src/fft.c b/com.oracle.truffle.r.native/builtinlibs/src/fft.c
similarity index 100%
rename from com.oracle.truffle.r.native/src/fft.c
rename to com.oracle.truffle.r.native/builtinlibs/src/fft.c
diff --git a/com.oracle.truffle.r.runtime.ffi.native/Makefile b/com.oracle.truffle.r.native/fficall/Makefile
similarity index 90%
rename from com.oracle.truffle.r.runtime.ffi.native/Makefile
rename to com.oracle.truffle.r.native/fficall/Makefile
index 87f1734188..c5ae2b2bb6 100644
--- a/com.oracle.truffle.r.runtime.ffi.native/Makefile
+++ b/com.oracle.truffle.r.native/fficall/Makefile
@@ -21,12 +21,10 @@
 # questions.
 #
 
-.PHONY: urand clean
+.PHONY: all clean
 
-export TOPDIR = $(CURDIR)
-
-jnicall:
-	$(MAKE) -C jni/call/src
+all:
+	$(MAKE) -C jni
 
 clean:
-	$(MAKE) -C jni/call/src clean
+	$(MAKE) -C jni clean
diff --git a/com.oracle.truffle.r.test.native/urand/src/Makefile b/com.oracle.truffle.r.native/fficall/jni/Makefile
similarity index 66%
rename from com.oracle.truffle.r.test.native/urand/src/Makefile
rename to com.oracle.truffle.r.native/fficall/jni/Makefile
index eba89f45ea..2f94f1122f 100644
--- a/com.oracle.truffle.r.test.native/urand/src/Makefile
+++ b/com.oracle.truffle.r.native/fficall/jni/Makefile
@@ -21,36 +21,37 @@
 # questions.
 #
 
-.PHONY: all clean
-
-BIN = ../bin
-SRC = $(CURDIR)
-C_SOURCES := $(wildcard *.c)
-C_LIBNAME := lib$(C_SOURCES:.c=.so)
-C_OBJECTS := $(BIN)/$(C_SOURCES:.c=.o)
-C_LIB := $(BIN)/$(C_LIBNAME)
-
-
 ifeq ($(TOPDIR),)
     TOPDIR = $(abspath ../..)
 endif
 
-INCLUDE_DIR := $(subst test.native,native,$(TOPDIR))/include
+$(warning $(TOPDIR))
+include $(TOPDIR)/platform.mk
+
+.PHONY: all clean
+
+OBJ = lib
+SRC = src
+C_SOURCES := $(wildcard $(SRC)/*.c)
+C_LIBNAME := libcall.$(SHARED_EXT)
+C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
+C_LIB := $(OBJ)/$(C_LIBNAME)
+
+JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(OS_DIR)
+FFI_INCLUDES = -I$(TOPDIR)/include/jni
+
+INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 
 all: $(C_LIB)
 
-$(C_LIB): $(BIN) $(C_OBJECTS)
-ifneq ($(shell uname), Darwin)
-	gcc -fPIC -shared -o $(C_LIB) $(C_OBJECTS)
-else
-	gcc -dynamiclib -undefined dynamic_lookup -o $(C_LIB) $(C_OBJECTS)
-endif
+$(C_LIB): $(OBJ) $(C_OBJECTS)
+	$(CC) $(LDFLAGS) -o $(C_LIB) $(C_OBJECTS)
 
-$(BIN):
-	mkdir -p $(BIN)
+$(OBJ):
+	mkdir -p $(OBJ)
 
-$(BIN)/%.o: %.c
-	gcc -I$(INCLUDE_DIR) -fPIC -O2 -c $< -o $@
+$(OBJ)/%.o: $(SRC)/%.c
+	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
 
 clean:
-	rm -rf $(BIN)
+	rm -rf $(OBJ)
diff --git a/com.oracle.truffle.r.runtime.ffi.native/jni/call/src/call.c b/com.oracle.truffle.r.native/fficall/jni/src/call.c
similarity index 100%
rename from com.oracle.truffle.r.runtime.ffi.native/jni/call/src/call.c
rename to com.oracle.truffle.r.native/fficall/jni/src/call.c
diff --git a/com.oracle.truffle.r.runtime.ffi.native/jni/include/R.h b/com.oracle.truffle.r.native/include/jni/R.h
similarity index 100%
rename from com.oracle.truffle.r.runtime.ffi.native/jni/include/R.h
rename to com.oracle.truffle.r.native/include/jni/R.h
diff --git a/com.oracle.truffle.r.native/include/R_ext/Boolean.h b/com.oracle.truffle.r.native/include/jni/R_ext/Boolean.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/R_ext/Boolean.h
rename to com.oracle.truffle.r.native/include/jni/R_ext/Boolean.h
diff --git a/com.oracle.truffle.r.native/include/R_ext/Random.h b/com.oracle.truffle.r.native/include/jni/R_ext/Random.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/R_ext/Random.h
rename to com.oracle.truffle.r.native/include/jni/R_ext/Random.h
diff --git a/com.oracle.truffle.r.runtime.ffi.native/jni/include/Rdefines.h b/com.oracle.truffle.r.native/include/jni/Rdefines.h
similarity index 100%
rename from com.oracle.truffle.r.runtime.ffi.native/jni/include/Rdefines.h
rename to com.oracle.truffle.r.native/include/jni/Rdefines.h
diff --git a/com.oracle.truffle.r.runtime.ffi.native/jni/include/Rinternals.h b/com.oracle.truffle.r.native/include/jni/Rinternals.h
similarity index 100%
rename from com.oracle.truffle.r.runtime.ffi.native/jni/include/Rinternals.h
rename to com.oracle.truffle.r.native/include/jni/Rinternals.h
diff --git a/com.oracle.truffle.r.native/platform.mk b/com.oracle.truffle.r.native/platform.mk
new file mode 100644
index 0000000000..3f33f273c4
--- /dev/null
+++ b/com.oracle.truffle.r.native/platform.mk
@@ -0,0 +1,53 @@
+#
+# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+OSNAME := $(shell uname)
+
+ifeq ($(OSNAME), Linux)
+  OS_DIR      := linux
+  CC          := gcc
+  FC          := gfortran
+  CFLAGS      := -fPIC -O2
+  LDFLAGS     := -fPIC -shared
+  SHARED_EXT  := so
+  LIBS        := -lgfortran
+else ifeq ($(OSNAME), SunOS)
+  OS_DIR      := sunos
+  CC          := cc
+  FC          := f90
+  CFLAGS      := -m64 -O -xcode=pic13
+  LDFLAGS     := -G -m64
+  SHARED_EXT  := so
+else ifeq ($(OSNAME), Darwin)
+  OS_DIR      := darwin
+  CC          := gcc
+  FC          := gfortran
+  CFLAGS      := -fPIC -O2
+  LDFLAGS     := -dynamiclib -undefined dynamic_lookup
+  SHARED_EXT  := dylib
+else
+all:
+	@echo "This Makefile does not know how to compile for $(OSNAME)"
+	@false
+endif
+
diff --git a/com.oracle.truffle.r.runtime.ffi.native/.project b/com.oracle.truffle.r.runtime.ffi.native/.project
deleted file mode 100644
index 38c243b362..0000000000
--- a/com.oracle.truffle.r.runtime.ffi.native/.project
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>com.oracle.truffle.r.runtime.ffi.native</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-	</buildSpec>
-	<natures>
-	</natures>
-</projectDescription>
diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIWithJNI.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIWithJNI.java
index 06bee7f302..b723ad3b4e 100644
--- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIWithJNI.java
+++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIWithJNI.java
@@ -26,6 +26,7 @@ import java.nio.file.*;
 
 import com.oracle.truffle.api.CompilerDirectives.SlowPath;
 import com.oracle.truffle.r.runtime.*;
+import com.oracle.truffle.r.runtime.RPlatform.OSInfo;
 import com.oracle.truffle.r.runtime.data.*;
 import com.oracle.truffle.r.runtime.ffi.*;
 import com.oracle.truffle.r.runtime.ffi.DLL.SymbolInfo;
@@ -44,26 +45,10 @@ public class CallRFFIWithJNI implements CallRFFI {
 
     @SlowPath
     private static void loadLibrary() {
-// System.loadLibrary("call");
         String rHome = REnvVars.rHome();
-        String packageName = "com.oracle.truffle.r.runtime.ffi.native";
-        String osName = System.getProperty("os.name");
-        String libExt = "so";
-        String subDir = null;
-        switch (osName) {
-            case "Mac OS X":
-                subDir = "darwin";
-                libExt = "dylib";
-                break;
-
-            case "Linux":
-                subDir = "linux";
-                break;
-
-            default:
-                Utils.fail("CallRFFI: unsupported OS: " + osName);
-        }
-        Path path = FileSystems.getDefault().getPath(rHome, packageName, "jni", "call", "bin", subDir, "libCall." + libExt);
+        String packageName = "com.oracle.truffle.r.native";
+        OSInfo osInfo = RPlatform.getOSInfo();
+        Path path = FileSystems.getDefault().getPath(rHome, packageName, "fficall", "jni", "lib", "libcall." + osInfo.libExt);
         System.load(path.toString());
     }
 
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RPlatform.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RPlatform.java
new file mode 100644
index 0000000000..fab2893ae5
--- /dev/null
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RPlatform.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.r.runtime;
+
+public class RPlatform {
+    public static class OSInfo {
+        public final String libExt;
+        public final String osSubDir;
+        public final String osName;
+
+        private OSInfo() {
+            osName = System.getProperty("os.name");
+            switch (osName) {
+                case "Mac OS X":
+                    osSubDir = "darwin";
+                    libExt = "dylib";
+                    break;
+
+                case "Linux":
+                    osSubDir = "linux";
+                    libExt = "so";
+                    break;
+
+                case "SunOS":
+                    osSubDir = "solaris";
+                    libExt = "so";
+                    break;
+
+                default:
+                    osSubDir = null;
+                    libExt = null;
+                    Utils.fail("CallRFFI: unsupported OS: " + osName);
+            }
+        }
+    }
+
+    private static OSInfo osInfo;
+
+    public static OSInfo getOSInfo() {
+        if (osInfo == null) {
+            osInfo = new OSInfo();
+        }
+        return osInfo;
+    }
+
+}
diff --git a/com.oracle.truffle.r.test.native/Makefile b/com.oracle.truffle.r.test.native/Makefile
index 67df1afff2..0b7d8c02ef 100644
--- a/com.oracle.truffle.r.test.native/Makefile
+++ b/com.oracle.truffle.r.test.native/Makefile
@@ -21,12 +21,12 @@
 # questions.
 #
 
-.PHONY: urand clean
+.PHONY: all clean
 
 export TOPDIR = $(CURDIR)
 
-urand:
-	$(MAKE) -C urand/src
+all:
+	$(MAKE) -C urand
 
 clean:
-	$(MAKE) -C urand/src clean
+	$(MAKE) -C urand clean
diff --git a/com.oracle.truffle.r.runtime.ffi.native/jni/call/src/Makefile b/com.oracle.truffle.r.test.native/urand/Makefile
similarity index 56%
rename from com.oracle.truffle.r.runtime.ffi.native/jni/call/src/Makefile
rename to com.oracle.truffle.r.test.native/urand/Makefile
index ed564bda71..8b8195dc66 100644
--- a/com.oracle.truffle.r.runtime.ffi.native/jni/call/src/Makefile
+++ b/com.oracle.truffle.r.test.native/urand/Makefile
@@ -21,50 +21,38 @@
 # questions.
 #
 
-.PHONY: all clean
-
-HOSTOS = $(shell uname)
-ifeq ($(HOSTOS),Darwin)
-   HOSTOS_LC = darwin
-endif
-ifeq ($(HOSTOS),Linux)
-   HOSTOS_LC = linux
-endif
-
 ifeq ($(TOPDIR),)
-    TOPDIR = $(abspath ../../..)
+    TOPDIR = $(abspath ..)
 endif
+$(warning  $(TOPDIR))
 
-BIN = ../bin/$(HOSTOS_LC)
-SRC = $(CURDIR)
-C_SOURCES := $(wildcard *.c)
-ifneq ($(HOSTOS), Darwin)
-    C_LIBNAME := lib$(C_SOURCES:.c=.so)
-else
-    C_LIBNAME := lib$(C_SOURCES:.c=.dylib)
-endif
-C_OBJECTS := $(BIN)/$(C_SOURCES:.c=.o)
-C_LIB := $(BIN)/$(C_LIBNAME)
+NATIVE_PROJECT = $(subst test.native,native,$(TOPDIR))
+$(warning $(NATIVE_PROJECT))
 
-JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(HOSTOS_LC)
-FFI_INCLUDES = -I$(TOPDIR)/jni/include
+include $(NATIVE_PROJECT)/platform.mk
+
+.PHONY: all clean
+
+OBJ = lib
+SRC = src
+C_SOURCES := $(wildcard $(SRC)/*.c)
+C_LIBNAME := lib$(subst $(SRC)/,,$(C_SOURCES:.c=.$(SHARED_EXT)))
+C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
+C_LIB := $(OBJ)/$(C_LIBNAME)
 
-INCLUDE_DIR := $(JNI_INCLUDES) $(FFI_INCLUDES)
+
+INCLUDE_DIR := $(NATIVE_PROJECT)/include/jni
 
 all: $(C_LIB)
 
-$(C_LIB): $(BIN) $(C_OBJECTS)
-ifneq ($HOSTOS, Darwin)
-	gcc -fPIC -shared -o $(C_LIB) $(C_OBJECTS)
-else
-	gcc -dynamiclib -undefined dynamic_lookup -o $(C_LIB) $(C_OBJECTS)
-endif
+$(C_LIB): $(OBJ) $(C_OBJECTS)
+	$(CC) $(LDFLAGS)  -o $(C_LIB) $(C_OBJECTS)
 
-$(BIN):
-	mkdir -p $(BIN)
+$(OBJ):
+	mkdir -p $(OBJ)
 
-$(BIN)/%.o: %.c
-	gcc $(INCLUDE_DIR) -fPIC -O2 -c $< -o $@
+$(OBJ)/%.o: $(SRC)/%.c
+	$(CC) $(CFLAGS) -I$(INCLUDE_DIR) -c $< -o $@
 
 clean:
-	rm -rf $(BIN)
+	rm -rf $(OBJ)
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestUserRNG.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestUserRNG.java
index bca4effc45..0385d45d54 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestUserRNG.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestUserRNG.java
@@ -39,7 +39,7 @@ public class TestUserRNG extends TestBase {
     @Test
     public void testUserRNG() {
         Path cwd = Paths.get(System.getProperty("user.dir"));
-        Path libPath = Paths.get(REnvVars.rHome(), "com.oracle.truffle.r.test.native/urand/bin/liburand.so");
+        Path libPath = Paths.get(REnvVars.rHome(), "com.oracle.truffle.r.test.native/urand/lib/liburand." + RPlatform.getOSInfo().libExt);
         Path relLibPath = cwd.relativize(libPath);
         assertTemplateEval(TestBase.template("{ dyn.load(\"%0\"); RNGkind(\"user\"); print(RNGkind()); set.seed(4567); runif(10) }", new String[]{relLibPath.toString()}));
     }
diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides
index b839a9cf14..1258683f0c 100644
--- a/mx.fastr/copyrights/overrides
+++ b/mx.fastr/copyrights/overrides
@@ -1,6 +1,10 @@
-com.oracle.truffle.r.native/include/R_ext/Boolean.h,no.copyright
-com.oracle.truffle.r.native/include/R_ext/Random.h,no.copyright
-com.oracle.truffle.r.native/src/fft.c,gnu_r_gentleman_ihaka.copyright
+com.oracle.truffle.r.native/builtinlibs/src/fft.c,gnu_r_gentleman_ihaka.copyright
+com.oracle.truffle.r.native/fficall/jni/src/call.c,gnu_r.copyright
+com.oracle.truffle.r.native/include/jni/R_ext/Boolean.h,no.copyright
+com.oracle.truffle.r.native/include/jni/R_ext/Random.h,no.copyright
+com.oracle.truffle.r.native/include/jni/R.h,gnu_r.copyright
+com.oracle.truffle.r.native/include/jni/Rdefines.h,gnu_r.copyright
+com.oracle.truffle.r.native/include/jni/Rinternals.h,gnu_r.copyright
 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/DispatchNode.java,purdue.copyright
 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/DispatchedCallNode.java,purdue.copyright
 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/GroupDispatchNode.java,purdue.copyright
@@ -120,10 +124,6 @@ com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RGroupGenerics.jav
 com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/gnur/SEXPTYPE.java,gnu_r.copyright
 com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ops/BinaryArithmetic.java,gnu_r_purdue.copyright
 com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ops/UnaryArithmetic.java,gnu_r_unary.copyright
-com.oracle.truffle.r.runtime.ffi.native/jni/call/src/call.c,gnu_r.copyright
-com.oracle.truffle.r.runtime.ffi.native/jni/include/R.h,gnu_r.copyright
-com.oracle.truffle.r.runtime.ffi.native/jni/include/Rdefines.h,gnu_r.copyright
-com.oracle.truffle.r.runtime.ffi.native/jni/include/Rinternals.h,gnu_r.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestBase.java,purdue.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java,no.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java,no.copyright
diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py
index 5e972160b7..10867d614e 100644
--- a/mx.fastr/mx_fastr.py
+++ b/mx.fastr/mx_fastr.py
@@ -52,7 +52,7 @@ def runRscriptCommand(args, nonZeroIsFatal=True):
 
 def _set_libpath():
     osname = platform.system()
-    lib_base = join(_fastr_suite.dir, 'com.oracle.truffle.r.native', 'lib', osname.lower())
+    lib_base = join(_fastr_suite.dir, 'com.oracle.truffle.r.native', 'builtinlibs', 'lib', osname.lower())
     lib_value = lib_base
     if osname == 'Darwin':
         lib_env = 'DYLD_FALLBACK_LIBRARY_PATH'
diff --git a/mx.fastr/projects b/mx.fastr/projects
index 75800e13b4..398090a565 100644
--- a/mx.fastr/projects
+++ b/mx.fastr/projects
@@ -168,11 +168,6 @@ project@com.oracle.truffle.r.runtime.ffi@checkstyle=com.oracle.truffle.r.runtime
 project@com.oracle.truffle.r.runtime.ffi@javaCompliance=1.8
 project@com.oracle.truffle.r.runtime.ffi@workingSets=Truffle,FastR
 
-# com.oracle.truffle.r.runtime.ffi.native
-project@com.oracle.truffle.r.runtime.ffi.native@sourceDirs=
-project@com.oracle.truffle.r.runtime.ffi.native@native=true
-project@com.oracle.truffle.r.runtime.ffi.native@workingSets=FastR
-
 # com.oracle.truffle.r.native
 project@com.oracle.truffle.r.native@sourceDirs=
 project@com.oracle.truffle.r.native@native=true
-- 
GitLab