diff --git a/.hgignore b/.hgignore
index 88e3ab3800e428e7323802d4dcc73d7bd33fdf09..1cb5e1e72c01b766f4261937ffe19cf4bab5ba30 100644
--- a/.hgignore
+++ b/.hgignore
@@ -10,6 +10,7 @@
 ^mx.fastr/netbeans-config.zip
 ^com.oracle.truffle.r.test/rpackages/testrlibs_user
 ^com.oracle.truffle.r.test.native/urand/lib/liburand.so
+^com.oracle.truffle.r.native/gnur/R-*
 ^library/
 ^build/
 ^build-nograal/
@@ -88,8 +89,9 @@ R.tokens
 .tmp.unit.knucleotide.input
 *.o
 findbugs.html
-com.oracle.truffle.r.native/builtinlibs/lib/*/librfficall.*
-com.oracle.truffle.r.native/builtinlibs/lib/*/libR.dylib
-com.oracle.truffle.r.native/library/*/lib/*/*.*
-com.oracle.truffle.r.native/library/fastr/lib/*
-com.oracle.truffle.r.test.native/packages/*/lib/*
\ No newline at end of file
+com.oracle.truffle.r.native/builtinlibs/lib/*
+com.oracle.truffle.r.native/library/*/lib/*
+com.oracle.truffle.r.native/include/jni/include
+com.oracle.truffle.r.native/include/jni/linked
+com.oracle.truffle.r.test.native/packages/*/lib/*
+
diff --git a/com.oracle.truffle.r.native/Makefile b/com.oracle.truffle.r.native/Makefile
index 46f3d0bcd5ff2183634826b957d69567dcad7bf4..79096582ac720790a5fc60b6a8d0ffe7aae05dd9 100644
--- a/com.oracle.truffle.r.native/Makefile
+++ b/com.oracle.truffle.r.native/Makefile
@@ -24,14 +24,20 @@
 .PHONY: all clean
 
 export TOPDIR = $(CURDIR)
+export R_VERSION = 3.1.3
+export GNUR_DIR = $(TOPDIR)/gnur/R-$(R_VERSION)
 
 all:
+	$(MAKE) -C gnur
+	$(MAKE) -C include
 	$(MAKE) -C builtinlibs
 	$(MAKE) -C fficall
 	$(MAKE) -C library
 	$(MAKE) -C run
 
 clean:
+	$(MAKE) -C gnur clean
+	$(MAKE) -C include clean
 	$(MAKE) -C builtinlibs clean
 	$(MAKE) -C fficall clean
 	$(MAKE) -C library clean
diff --git a/com.oracle.truffle.r.native/builtinlibs/Makefile b/com.oracle.truffle.r.native/builtinlibs/Makefile
index 44ce75f9cabf0247ab324b7a38f9a007a3f1a406..5a83c345990fb3bdce7eb6fc6b05c1fc2af1dc6f 100644
--- a/com.oracle.truffle.r.native/builtinlibs/Makefile
+++ b/com.oracle.truffle.r.native/builtinlibs/Makefile
@@ -22,9 +22,10 @@
 #
 
 #
-# 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.
+# This Makefile contains the recipe for creating a modified version of 
+# GnuR's libappl, essentially just the Fortran components. Unfortunately
+# we can't just copy the GnuR library as it contains some compiled C code
+# that refers to GnuR-internal symbols.
 #
 
 include ../platform.mk
@@ -32,38 +33,30 @@ include ../platform.mk
 .PHONY: all clean cleanlib cleanobj force libr
 
 SRC = src
-OBJ = lib/$(OS_DIR)
+OBJ = lib
 
 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))
+F_OBJECTS := $(wildcard $(GNUR_DIR)/src/appl/d*.o)
 
 LIBDIR := $(OBJ)
-LIB_DERIVED := $(OBJ)/libRDerived.$(SHARED_EXT)
+LIB_APPL := $(OBJ)/libappl.$(SHARED_EXT)
 
-all: libr
-	@echo $(LIB_DERIVED) is up to date
+all: $(LIB_APPL) libr
 
-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)
+$(LIB_APPL): $(C_OBJECTS) $(F_OBJECTS)
 	mkdir -p $(LIBDIR)
-	$(CC) $(LDFLAGS) -o $(LIB_DERIVED) $(C_OBJECTS) $(F_OBJECTS) $(LIBS)
+	$(CC) $(LDFLAGS) -o $(LIB_APPL) $(C_OBJECTS) $(F_OBJECTS) $(LIBS)
 
+# On Darwin we need to create a dummy libR.dylib
 ifeq ($(OSNAME), Darwin)
 LIB_RDUMMY := $(OBJ)/libR.$(SHARED_EXT)
 
 libr: $(LIB_RDUMMY)
 $(LIB_RDUMMY): $(OBJ)/rdummy.o
 	mkdir -p $(LIBDIR)
-	$(CC) $(LDFLAGS) -o $(LIB_RDUMMY) -current_version 3.1.3 -compatibility_version 3.1.3 $(OBJ)/rdummy.o
+	$(CC) $(LDFLAGS) -o $(LIB_RDUMMY) -current_version $(R_VERSION) -compatibility_version $(R_VERSION) $(OBJ)/rdummy.o
 
 cleanlibr:
 	rm -f $(LIB_RDUMMY)
@@ -83,11 +76,9 @@ $(OBJ)/%.o: $(SRC)/%.f
 
 
 cleanlib:
-	rm -f $(LIBDIR)/libRDerived.* $(LIBDIR)/libRblas.$(SHARED_EXT) $(LIBDIR)/libRlapack.$(SHARED_EXT)
+	rm -f $(LIBDIR)/libappl.*
 
 clean: cleanobj cleanlibr
-#	$(MAKE) -C src/blas clean
-#	$(MAKE) -C src/lapack clean
 
 cleanobj:
 	rm -f $(LIBDIR)/*.o
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/LICENSE b/com.oracle.truffle.r.native/builtinlibs/lib/LICENSE
deleted file mode 100644
index 98b79eb674562d3e3accfdd54a99c85849a82dc4..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/lib/LICENSE
+++ /dev/null
@@ -1,48 +0,0 @@
-Copyright (c) 1992-2011 The University of Tennessee and The University
-                        of Tennessee Research Foundation.  All rights
-                        reserved.
-Copyright (c) 2000-2011 The University of California Berkeley. All
-                        rights reserved.
-Copyright (c) 2006-2012 The University of Colorado Denver.  All rights
-                        reserved.
-
-$COPYRIGHT$
-
-Additional copyrights may follow
-
-$HEADER$
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-- Redistributions of source code must retain the above copyright
-  notice, this list of conditions and the following disclaimer.
-
-- Redistributions in binary form must reproduce the above copyright
-  notice, this list of conditions and the following disclaimer listed
-  in this license in the documentation and/or other materials
-  provided with the distribution.
-
-- Neither the name of the copyright holders nor the names of its
-  contributors may be used to endorse or promote products derived from
-  this software without specific prior written permission.
-
-The copyright holders provide no reassurances that the source code
-provided does not infringe any patent, copyright, or any other
-intellectual property rights of third parties.  The copyright holders
-disclaim any liability to any recipient for claims brought against
-recipient by any third party for infringement of that parties
-intellectual property rights.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRDerived.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRDerived.dylib
deleted file mode 100755
index 33a90aba51f6a92daa32e19f1838a01e54381154..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRDerived.dylib and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRblas.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRblas.dylib
deleted file mode 100755
index f3c0c588196607344bb492514b153ac443b868d7..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRblas.dylib and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRlapack.dylib b/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRlapack.dylib
deleted file mode 100755
index c8d0940bcb24ecc40f9318f8f1682b4485fdc00d..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/darwin/libRlapack.dylib and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRDerived.so b/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRDerived.so
deleted file mode 100755
index f1baa25c44c6dfd1638c2092596acd382bf35ba7..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRDerived.so and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRblas.so b/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRblas.so
deleted file mode 100755
index ace618bd51d66627df7e22eed5efa978c0b831d1..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRblas.so and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRlapack.so b/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRlapack.so
deleted file mode 100755
index 33624257f5a8daa54f19142b5e0e75c379324858..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/linux/libRlapack.so and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRDerived.so b/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRDerived.so
deleted file mode 100755
index b7f9c91a8b0a887b420232014f574ed7c668de60..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRDerived.so and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRblas.so b/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRblas.so
deleted file mode 100755
index 41e5dcacad83081fb9a2790af2ce858422d96d73..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRblas.so and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRlapack.so b/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRlapack.so
deleted file mode 100755
index b2a3820fd3ce44bf563f3f5907867c57f5039c31..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/builtinlibs/lib/solaris/libRlapack.so and /dev/null differ
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dchdc.f b/com.oracle.truffle.r.native/builtinlibs/src/dchdc.f
deleted file mode 100644
index 81b6786bde7f53ae804c641e6f7a66ce12734ef5..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dchdc.f
+++ /dev/null
@@ -1,234 +0,0 @@
-      subroutine dchdc(a,lda,p,work,jpvt,job,info)
-      integer lda,p,jpvt(p),job,info
-      double precision a(lda,p),work(*)
-c
-c     dchdc computes the cholesky decomposition of a positive definite
-c     matrix.  a pivoting option allows the user to estimate the
-c     condition of a positive definite matrix or determine the rank
-c     of a positive semidefinite matrix.
-c
-c     on entry
-c
-c         a      double precision(lda,p).
-c                a contains the matrix whose decomposition is to
-c                be computed.  onlt the upper half of a need be stored.
-c                the lower part of the array a is not referenced.
-c
-c         lda    integer.
-c                lda is the leading dimension of the array a.
-c
-c         p      integer.
-c                p is the order of the matrix.
-c
-c         work   double precision.
-c                work is a work array.
-c
-c         jpvt   integer(p).
-c                jpvt contains integers that control the selection
-c                of the pivot elements, if pivoting has been requested.
-c                each diagonal element a(k,k)
-c                is placed in one of three classes according to the
-c                value of jpvt(k).
-c
-c                   if jpvt(k) .gt. 0, then x(k) is an initial
-c                                      element.
-c
-c                   if jpvt(k) .eq. 0, then x(k) is a free element.
-c
-c                   if jpvt(k) .lt. 0, then x(k) is a final element.
-c
-c                before the decomposition is computed, initial elements
-c                are moved by symmetric row and column interchanges to
-c                the beginning of the array a and final
-c                elements to the end.  both initial and final elements
-c                are frozen in place during the computation and only
-c                free elements are moved.  at the k-th stage of the
-c                reduction, if a(k,k) is occupied by a free element
-c                it is interchanged with the largest free element
-c                a(l,l) with l .ge. k.  jpvt is not referenced if
-c                job .eq. 0.
-c
-c        job     integer.
-c                job is an integer that initiates column pivoting.
-c                if job .eq. 0, no pivoting is done.
-c                if job .ne. 0, pivoting is done.
-c
-c     on return
-c
-c         a      a contains in its upper half the cholesky factor
-c                of the matrix a as it has been permuted by pivoting.
-c
-c         jpvt   jpvt(j) contains the index of the diagonal element
-c                of a that was moved into the j-th position,
-c                provided pivoting was requested.
-c
-c         info   contains the index of the last positive diagonal
-c                element of the cholesky factor.
-c
-c     for positive definite matrices info = p is the normal return.
-c     for pivoting with positive semidefinite matrices info will
-c     in general be less than p.  however, info may be greater than
-c     the rank of a, since rounding error can cause an otherwise zero
-c     element to be positive. indefinite systems will always cause
-c     info to be less than p.
-c
-c     linpack. this version dated 08/14/78 .
-c     j.j. dongarra and g.w. stewart, argonne national laboratory and
-c     university of maryland.
-c
-c
-c     blas daxpy,dswap
-c     fortran dsqrt
-c
-c     internal variables
-c
-      integer pu,pl,plp1,j,jp,jt,k,kb,km1,kp1,l,maxl
-      double precision temp
-      double precision maxdia
-      logical swapk,negk
-c
-      pl = 1
-      pu = 0
-      info = p
-      if (job .eq. 0) go to 160
-c
-c        pivoting has been requested. rearrange the
-c        the elements according to jpvt.
-c
-         do 70 k = 1, p
-            swapk = jpvt(k) .gt. 0
-            negk = jpvt(k) .lt. 0
-            jpvt(k) = k
-            if (negk) jpvt(k) = -jpvt(k)
-            if (.not.swapk) go to 60
-               if (k .eq. pl) go to 50
-                  call dswap(pl-1,a(1,k),1,a(1,pl),1)
-                  temp = a(k,k)
-                  a(k,k) = a(pl,pl)
-                  a(pl,pl) = temp
-                  plp1 = pl + 1
-                  if (p .lt. plp1) go to 40
-                  do 30 j = plp1, p
-                     if (j .ge. k) go to 10
-                        temp = a(pl,j)
-                        a(pl,j) = a(j,k)
-                        a(j,k) = temp
-                     go to 20
-   10                continue
-                     if (j .eq. k) go to 20
-                        temp = a(k,j)
-                        a(k,j) = a(pl,j)
-                        a(pl,j) = temp
-   20                continue
-   30             continue
-   40             continue
-                  jpvt(k) = jpvt(pl)
-                  jpvt(pl) = k
-   50          continue
-               pl = pl + 1
-   60       continue
-   70    continue
-         pu = p
-         if (p .lt. pl) go to 150
-         do 140 kb = pl, p
-            k = p - kb + pl
-            if (jpvt(k) .ge. 0) go to 130
-               jpvt(k) = -jpvt(k)
-               if (pu .eq. k) go to 120
-                  call dswap(k-1,a(1,k),1,a(1,pu),1)
-                  temp = a(k,k)
-                  a(k,k) = a(pu,pu)
-                  a(pu,pu) = temp
-                  kp1 = k + 1
-                  if (p .lt. kp1) go to 110
-                  do 100 j = kp1, p
-                     if (j .ge. pu) go to 80
-                        temp = a(k,j)
-                        a(k,j) = a(j,pu)
-                        a(j,pu) = temp
-                     go to 90
-   80                continue
-                     if (j .eq. pu) go to 90
-                        temp = a(k,j)
-                        a(k,j) = a(pu,j)
-                        a(pu,j) = temp
-   90                continue
-  100             continue
-  110             continue
-                  jt = jpvt(k)
-                  jpvt(k) = jpvt(pu)
-                  jpvt(pu) = jt
-  120          continue
-               pu = pu - 1
-  130       continue
-  140    continue
-  150    continue
-  160 continue
-      do 270 k = 1, p
-c
-c        reduction loop.
-c
-         maxdia = a(k,k)
-         kp1 = k + 1
-         maxl = k
-c
-c        determine the pivot element.
-c
-         if (k .lt. pl .or. k .ge. pu) go to 190
-            do 180 l = kp1, pu
-               if (a(l,l) .le. maxdia) go to 170
-                  maxdia = a(l,l)
-                  maxl = l
-  170          continue
-  180       continue
-  190    continue
-c
-c        quit if the pivot element is not positive.
-c
-         if (maxdia .gt. 0.0d0) go to 200
-            info = k - 1
-c     ......exit
-            go to 280
-  200    continue
-         if (k .eq. maxl) go to 210
-c
-c           start the pivoting and update jpvt.
-c
-            km1 = k - 1
-            call dswap(km1,a(1,k),1,a(1,maxl),1)
-            a(maxl,maxl) = a(k,k)
-            a(k,k) = maxdia
-            jp = jpvt(maxl)
-            jpvt(maxl) = jpvt(k)
-            jpvt(k) = jp
-  210    continue
-c
-c        reduction step. pivoting is contained across the rows.
-c
-         work(k) = dsqrt(a(k,k))
-         a(k,k) = work(k)
-         if (p .lt. kp1) go to 260
-         do 250 j = kp1, p
-            if (k .eq. maxl) go to 240
-               if (j .ge. maxl) go to 220
-                  temp = a(k,j)
-                  a(k,j) = a(j,maxl)
-                  a(j,maxl) = temp
-               go to 230
-  220          continue
-               if (j .eq. maxl) go to 230
-                  temp = a(k,j)
-                  a(k,j) = a(maxl,j)
-                  a(maxl,j) = temp
-  230          continue
-  240       continue
-            a(k,j) = a(k,j)/work(k)
-            work(j) = a(k,j)
-            temp = -a(k,j)
-            call daxpy(j-k,temp,work(kp1),1,a(kp1,j),1)
-  250    continue
-  260    continue
-  270 continue
-  280 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dpbfa.f b/com.oracle.truffle.r.native/builtinlibs/src/dpbfa.f
deleted file mode 100644
index 3c22a86094bd3ddb31493f63f09115d0106124fd..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dpbfa.f
+++ /dev/null
@@ -1,100 +0,0 @@
-      subroutine dpbfa(abd,lda,n,m,info)
-
-      integer lda,n,m,info
-      double precision abd(lda,n)
-c
-c     dpbfa factors a double precision symmetric positive definite
-c     matrix stored in band form.
-c
-c     dpbfa is usually called by dpbco, but it can be called
-c     directly with a saving in time if  rcond  is not needed.
-c
-c     on entry
-c
-c        abd     double precision(lda, n)
-c                the matrix to be factored.  the columns of the upper
-c                triangle are stored in the columns of abd and the
-c                diagonals of the upper triangle are stored in the
-c                rows of abd .  see the comments below for details.
-c
-c        lda     integer
-c                the leading dimension of the array  abd .
-c                lda must be .ge. m + 1 .
-c
-c        n       integer
-c                the order of the matrix  a .
-c
-c        m       integer
-c                the number of diagonals above the main diagonal.
-c                0 .le. m .lt. n .
-c
-c     on return
-c
-c        abd     an upper triangular matrix  r , stored in band
-c                form, so that  a = trans(r)*r .
-c
-c        info    integer
-c                = 0  for normal return.
-c                = k  if the leading minor of order  k  is not
-c                     positive definite.
-c
-c     band storage
-c
-c           if  a  is a symmetric positive definite band matrix,
-c           the following program segment will set up the input.
-c
-c                   m = (band width above diagonal)
-c                   do 20 j = 1, n
-c                      i1 = max0(1, j-m)
-c                      do 10 i = i1, j
-c                         k = i-j+m+1
-c                         abd(k,j) = a(i,j)
-c                10    continue
-c                20 continue
-c
-c     linpack.  this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas ddot
-c     fortran max0,sqrt
-c
-c     internal variables
-c
-      double precision ddot,t
-      double precision s
-      integer ik,j,jk,k,mu
-c     begin block with ...exits to 40
-c
-c
-         do 30 j = 1, n
-            info = j
-            s = 0.0d0
-            ik = m + 1
-            jk = max0(j-m,1)
-            mu = max0(m+2-j,1)
-            if (m .lt. mu) go to 20
-            do 10 k = mu, m
-
-               t = abd(k,j) - ddot(k-mu,abd(ik,jk),1,abd(mu,j),1)
-               t = t/abd(m+1,jk)
-               abd(k,j) = t
-               s = s + t*t
-               ik = ik - 1
-               jk = jk + 1
-   10       continue
-   20       continue
-
-            s = abd(m+1,j) - s
-c     ......exit
-            if (s .le. 0.0d0) go to 40
-
-            abd(m+1,j) = sqrt(s)
-
-   30    continue
-         info = 0
-   40 continue
-      return
-      end
-
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dpbsl.f b/com.oracle.truffle.r.native/builtinlibs/src/dpbsl.f
deleted file mode 100644
index d910deef88ecd031b13d86af743201e31b49be0d..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dpbsl.f
+++ /dev/null
@@ -1,83 +0,0 @@
-      subroutine dpbsl(abd,lda,n,m,b)
-
-      integer lda,n,m
-      double precision abd(lda,n),b(n)
-c
-c     dpbsl solves the double precision symmetric positive definite
-c     band system  a*x = b
-c     using the factors computed by dpbco or dpbfa.
-c
-c     on entry
-c
-c        abd     double precision(lda, n)
-c                the output from dpbco or dpbfa.
-c
-c        lda     integer
-c                the leading dimension of the array  abd .
-c
-c        n       integer
-c                the order of the matrix  a .
-c
-c        m       integer
-c                the number of diagonals above the main diagonal.
-c
-c        b       double precision(n)
-c                the right hand side vector.
-c
-c     on return
-c
-c        b       the solution vector  x .
-c
-c     error condition
-c
-c        a division by zero will occur if the input factor contains
-c        a zero on the diagonal.  technically this indicates
-c        singularity but it is usually caused by improper subroutine
-c        arguments.  it will not occur if the subroutines are called
-c        correctly and  info .eq. 0 .
-c
-c     to compute  inverse(a) * c  where  c  is a matrix
-c     with  p  columns
-c           call dpbco(abd,lda,n,rcond,z,info)
-c           if (rcond is too small .or. info .ne. 0) go to ...
-c           do 10 j = 1, p
-c              call dpbsl(abd,lda,n,c(1,j))
-c        10 continue
-c
-c     linpack.  this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas daxpy,ddot
-c     fortran min0
-c
-c     internal variables
-c
-      double precision ddot,t
-      integer k,kb,la,lb,lm
-c
-c     solve trans(r)*y = b
-c
-      do 10 k = 1, n
-         lm = min0(k-1,m)
-         la = m + 1 - lm
-         lb = k - lm
-         t = ddot(lm,abd(la,k),1,b(lb),1)
-         b(k) = (b(k) - t)/abd(m+1,k)
-   10 continue
-c
-c     solve r*x = y
-c
-      do 20 kb = 1, n
-         k = n + 1 - kb
-         lm = min0(k-1,m)
-         la = m + 1 - lm
-         lb = k - lm
-         b(k) = b(k)/abd(m+1,k)
-         t = -b(k)
-         call daxpy(lm,t,abd(la,k),1,b(lb),1)
-   20 continue
-      return
-      end
-
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dpoco.f b/com.oracle.truffle.r.native/builtinlibs/src/dpoco.f
deleted file mode 100644
index 83a7f1bd9b5f259f6e04549adec7d692a8011200..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dpoco.f
+++ /dev/null
@@ -1,195 +0,0 @@
-c
-c     dpoco factors a double precision symmetric positive definite
-c     matrix and estimates the condition of the matrix.
-c
-c     if  rcond  is not needed, dpofa is slightly faster.
-c     to solve  a*x = b , follow dpoco by dposl.
-c     to compute  inverse(a)*c , follow dpoco by dposl.
-c     to compute  determinant(a) , follow dpoco by dpodi.
-c     to compute  inverse(a) , follow dpoco by dpodi.
-c
-c     on entry
-c
-c        a       double precision(lda, n)
-c                the symmetric matrix to be factored.  only the
-c                diagonal and upper triangle are used.
-c
-c        lda     integer
-c                the leading dimension of the array  a .
-c
-c        n       integer
-c                the order of the matrix  a .
-c
-c     on return
-c
-c        a       an upper triangular matrix  r  so that  a = trans(r)*r
-c                where  trans(r)  is the transpose.
-c                the strict lower triangle is unaltered.
-c                if  info .ne. 0 , the factorization is not complete.
-c
-c        rcond   double precision
-c                an estimate of the reciprocal condition of  a .
-c                for the system  a*x = b , relative perturbations
-c                in  a  and  b  of size  epsilon  may cause
-c                relative perturbations in  x  of size  epsilon/rcond .
-c                if  rcond  is so small that the logical expression
-c                           1.0 + rcond .eq. 1.0
-c                is true, then  a  may be singular to working
-c                precision.  in particular,  rcond  is zero  if
-c                exact singularity is detected or the estimate
-c                underflows.  if info .ne. 0 , rcond is unchanged.
-c
-c        z       double precision(n)
-c                a work vector whose contents are usually unimportant.
-c                if  a  is close to a singular matrix, then  z  is
-c                an approximate null vector in the sense that
-c                norm(a*z) = rcond*norm(a)*norm(z) .
-c                if  info .ne. 0 , z  is unchanged.
-c
-c        info    integer
-c                = 0  for normal return.
-c                = k  signals an error condition.  the leading minor
-c                     of order  k  is not positive definite.
-c
-c     linpack.  this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     linpack dpofa
-c     blas daxpy,ddot,dscal,dasum
-c     fortran dabs,dmax1,dreal,dsign
-c
-      subroutine dpoco(a,lda,n,rcond,z,info)
-      integer lda,n,info
-      double precision a(lda,*),z(*)
-      double precision rcond
-c
-c     internal variables
-c
-      double precision ddot,ek,t,wk,wkm
-      double precision anorm,s,dasum,sm,ynorm
-      integer i,j,jm1,k,kb,kp1
-c
-c
-c     find norm of a using only upper half
-c
-      do 30 j = 1, n
-         z(j) = dasum(j,a(1,j),1)
-         jm1 = j - 1
-         if (jm1 .lt. 1) go to 20
-         do 10 i = 1, jm1
-            z(i) = z(i) + dabs(a(i,j))
-   10    continue
-   20    continue
-   30 continue
-      anorm = 0.0d0
-      do 40 j = 1, n
-         anorm = dmax1(anorm,z(j))
-   40 continue
-c
-c     factor
-c
-      call dpofa(a,lda,n,info)
-      if (info .ne. 0) go to 180
-c
-c        rcond = 1/(norm(a)*(estimate of norm(inverse(a)))) .
-c        estimate = norm(z)/norm(y) where  a*z = y  and  a*y = e .
-c        the components of  e  are chosen to cause maximum local
-c        growth in the elements of w  where  trans(r)*w = e .
-c        the vectors are frequently rescaled to avoid overflow.
-c
-c        solve trans(r)*w = e
-c
-         ek = 1.0d0
-         do 50 j = 1, n
-            z(j) = 0.0d0
-   50    continue
-         do 110 k = 1, n
-            if (z(k) .ne. 0.0d0) ek = dsign(ek,-z(k))
-            if (dabs(ek-z(k)) .le. a(k,k)) go to 60
-               s = a(k,k)/dabs(ek-z(k))
-               call dscal(n,s,z,1)
-               ek = s*ek
-   60       continue
-            wk = ek - z(k)
-            wkm = -ek - z(k)
-            s = dabs(wk)
-            sm = dabs(wkm)
-            wk = wk/a(k,k)
-            wkm = wkm/a(k,k)
-            kp1 = k + 1
-            if (kp1 .gt. n) go to 100
-               do 70 j = kp1, n
-                  sm = sm + dabs(z(j)+wkm*a(k,j))
-                  z(j) = z(j) + wk*a(k,j)
-                  s = s + dabs(z(j))
-   70          continue
-               if (s .ge. sm) go to 90
-                  t = wkm - wk
-                  wk = wkm
-                  do 80 j = kp1, n
-                     z(j) = z(j) + t*a(k,j)
-   80             continue
-   90          continue
-  100       continue
-            z(k) = wk
-  110    continue
-         s = 1.0d0/dasum(n,z,1)
-         call dscal(n,s,z,1)
-c
-c        solve r*y = w
-c
-         do 130 kb = 1, n
-            k = n + 1 - kb
-            if (dabs(z(k)) .le. a(k,k)) go to 120
-               s = a(k,k)/dabs(z(k))
-               call dscal(n,s,z,1)
-  120       continue
-            z(k) = z(k)/a(k,k)
-            t = -z(k)
-            call daxpy(k-1,t,a(1,k),1,z(1),1)
-  130    continue
-         s = 1.0d0/dasum(n,z,1)
-         call dscal(n,s,z,1)
-c
-         ynorm = 1.0d0
-c
-c        solve trans(r)*v = y
-c
-         do 150 k = 1, n
-            z(k) = z(k) - ddot(k-1,a(1,k),1,z(1),1)
-            if (dabs(z(k)) .le. a(k,k)) go to 140
-               s = a(k,k)/dabs(z(k))
-               call dscal(n,s,z,1)
-               ynorm = s*ynorm
-  140       continue
-            z(k) = z(k)/a(k,k)
-  150    continue
-         s = 1.0d0/dasum(n,z,1)
-         call dscal(n,s,z,1)
-         ynorm = s*ynorm
-c
-c        solve r*z = v
-c
-         do 170 kb = 1, n
-            k = n + 1 - kb
-            if (dabs(z(k)) .le. a(k,k)) go to 160
-               s = a(k,k)/dabs(z(k))
-               call dscal(n,s,z,1)
-               ynorm = s*ynorm
-  160       continue
-            z(k) = z(k)/a(k,k)
-            t = -z(k)
-            call daxpy(k-1,t,a(1,k),1,z(1),1)
-  170    continue
-c        make znorm = 1.0
-         s = 1.0d0/dasum(n,z,1)
-         call dscal(n,s,z,1)
-         ynorm = s*ynorm
-c
-         if (anorm .ne. 0.0d0) rcond = ynorm/anorm
-         if (anorm .eq. 0.0d0) rcond = 0.0d0
-  180 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dpodi.f b/com.oracle.truffle.r.native/builtinlibs/src/dpodi.f
deleted file mode 100644
index 4d52c5998fbefb4cf81542a8966d757e80d7650c..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dpodi.f
+++ /dev/null
@@ -1,122 +0,0 @@
-c
-c     dpodi computes the determinant and inverse of a certain
-c     double precision symmetric positive definite matrix (see below)
-c     using the factors computed by dpoco, dpofa or dqrdc.
-c
-c     on entry
-c
-c        a       double precision(lda, n)
-c                the output  a  from dpoco or dpofa
-c                or the output  x  from dqrdc.
-c
-c        lda     integer
-c                the leading dimension of the array  a .
-c
-c        n       integer
-c                the order of the matrix  a .
-c
-c        job     integer
-c                = 11   both determinant and inverse.
-c                = 01   inverse only.
-c                = 10   determinant only.
-c
-c     on return
-c
-c        a       if dpoco or dpofa was used to factor  a  then
-c                dpodi produces the upper half of inverse(a) .
-c                if dqrdc was used to decompose  x  then
-c                dpodi produces the upper half of inverse(trans(x)*x)
-c                where trans(x) is the transpose.
-c                elements of  a  below the diagonal are unchanged.
-c                if the units digit of job is zero,  a  is unchanged.
-c
-c        det     double precision(2)
-c                determinant of  a  or of  trans(x)*x  if requested.
-c                otherwise not referenced.
-c                determinant = det(1) * 10.0**det(2)
-c                with  1.0 .le. det(1) .lt. 10.0
-c                or  det(1) .eq. 0.0 .
-c
-c     error condition
-c
-c        a division by zero will occur if the input factor contains
-c        a zero on the diagonal and the inverse is requested.
-c        it will not occur if the subroutines are called correctly
-c        and if dpoco or dpofa has set info .eq. 0 .
-c
-c     linpack.  this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas daxpy,dscal
-c     fortran mod
-c
-      subroutine dpodi(a,lda,n,det,job)
-      integer lda,n,job
-      double precision a(lda,*)
-      double precision det(2)
-c
-c     internal variables
-c
-      double precision t
-      double precision s
-      integer i,j,jm1,k,kp1
-c
-c     compute determinant
-c
-      if (job/10 .eq. 0) go to 70
-         det(1) = 1.0d0
-         det(2) = 0.0d0
-         s = 10.0d0
-         do 50 i = 1, n
-            det(1) = a(i,i)**2*det(1)
-c        ...exit
-            if (det(1) .eq. 0.0d0) go to 60
-   10       if (det(1) .ge. 1.0d0) go to 20
-               det(1) = s*det(1)
-               det(2) = det(2) - 1.0d0
-            go to 10
-   20       continue
-   30       if (det(1) .lt. s) go to 40
-               det(1) = det(1)/s
-               det(2) = det(2) + 1.0d0
-            go to 30
-   40       continue
-   50    continue
-   60    continue
-   70 continue
-c
-c     compute inverse(r)
-c
-      if (mod(job,10) .eq. 0) go to 140
-         do 100 k = 1, n
-            a(k,k) = 1.0d0/a(k,k)
-            t = -a(k,k)
-            call dscal(k-1,t,a(1,k),1)
-            kp1 = k + 1
-            if (n .lt. kp1) go to 90
-            do 80 j = kp1, n
-               t = a(k,j)
-               a(k,j) = 0.0d0
-               call daxpy(k,t,a(1,k),1,a(1,j),1)
-   80       continue
-   90       continue
-  100    continue
-c
-c        form  inverse(r) * trans(inverse(r))
-c
-         do 130 j = 1, n
-            jm1 = j - 1
-            if (jm1 .lt. 1) go to 120
-            do 110 k = 1, jm1
-               t = a(k,j)
-               call daxpy(k,t,a(1,j),1,a(1,k),1)
-  110       continue
-  120       continue
-            t = a(j,j)
-            call dscal(j,t,a(1,j),1)
-  130    continue
-  140 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dpofa.f b/com.oracle.truffle.r.native/builtinlibs/src/dpofa.f
deleted file mode 100644
index 94d71d20ede3f1788dd2bd6bf8ab9c11a23f6fef..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dpofa.f
+++ /dev/null
@@ -1,78 +0,0 @@
-C  Modified 2002-05-20 for R to add a tolerance of positive definiteness.
-C
-c
-c     dpofa factors a double precision symmetric positive definite
-c     matrix.
-c
-c     dpofa is usually called by dpoco, but it can be called
-c     directly with a saving in time if  rcond  is not needed.
-c     (time for dpoco) = (1 + 18/n)*(time for dpofa) .
-c
-c     on entry
-c
-c        a       double precision(lda, n)
-c                the symmetric matrix to be factored.  only the
-c                diagonal and upper triangle are used.
-c
-c        lda     integer
-c                the leading dimension of the array  a .
-c
-c        n       integer
-c                the order of the matrix  a .
-c
-c     on return
-c
-c        a       an upper triangular matrix  r  so that  a = trans(r)*r
-c                where  trans(r)  is the transpose.
-c                the strict lower triangle is unaltered.
-c                if  info .ne. 0 , the factorization is not complete.
-c
-c        info    integer
-c                = 0  for normal return.
-c                = k  signals an error condition.  the leading minor
-c                     of order  k  is not positive definite.
-c
-c     linpack.  this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas ddot
-c     fortran dsqrt
-c
-      subroutine dpofa(a,lda,n,info)
-      integer lda,n,info
-      double precision a(lda,*)
-c
-c     internal variables
-c
-      double precision ddot,t,eps
-      double precision s
-      integer j,jm1,k
-      data eps/1.d-14/
-
-c     begin block with ...exits to 40
-c
-c
-         do 30 j = 1, n
-            info = j
-            s = 0.0d0
-            jm1 = j - 1
-            if (jm1 .lt. 1) go to 20
-            do 10 k = 1, jm1
-               t = a(k,j) - ddot(k-1,a(1,k),1,a(1,j),1)
-               t = t/a(k,k)
-               a(k,j) = t
-               s = s + t*t
-   10       continue
-   20       continue
-            s = a(j,j) - s
-c     ......exit
-c            if (s .le. 0.0d0) go to 40
-            if (s .le. eps * abs(a(j,j))) go to 40
-            a(j,j) = dsqrt(s)
-   30    continue
-         info = 0
-   40 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dposl.f b/com.oracle.truffle.r.native/builtinlibs/src/dposl.f
deleted file mode 100644
index 41c0e69502fc3cd94e3301364059ce3c1bdae1ac..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dposl.f
+++ /dev/null
@@ -1,72 +0,0 @@
-c
-c     dposl solves the double precision symmetric positive definite
-c     system a * x = b
-c     using the factors computed by dpoco or dpofa.
-c
-c     on entry
-c
-c        a       double precision(lda, n)
-c                the output from dpoco or dpofa.
-c
-c        lda     integer
-c                the leading dimension of the array  a .
-c
-c        n       integer
-c                the order of the matrix  a .
-c
-c        b       double precision(n)
-c                the right hand side vector.
-c
-c     on return
-c
-c        b       the solution vector  x .
-c
-c     error condition
-c
-c        a division by zero will occur if the input factor contains
-c        a zero on the diagonal.  technically this indicates
-c        singularity but it is usually caused by improper subroutine
-c        arguments.  it will not occur if the subroutines are called
-c        correctly and  info .eq. 0 .
-c
-c     to compute  inverse(a) * c  where  c  is a matrix
-c     with  p  columns
-c           call dpoco(a,lda,n,rcond,z,info)
-c           if (rcond is too small .or. info .ne. 0) go to ...
-c           do 10 j = 1, p
-c              call dposl(a,lda,n,c(1,j))
-c        10 continue
-c
-c     linpack.  this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas daxpy,ddot
-c
-      subroutine dposl(a,lda,n,b)
-      integer lda,n
-      double precision a(lda,*),b(*)
-c
-c     internal variables
-c
-      double precision ddot,t
-      integer k,kb
-c
-c     solve trans(r)*y = b
-c
-      do 10 k = 1, n
-         t = ddot(k-1,a(1,k),1,b(1),1)
-         b(k) = (b(k) - t)/a(k,k)
-   10 continue
-c
-c     solve r*x = y
-c
-      do 20 kb = 1, n
-         k = n + 1 - kb
-         b(k) = b(k)/a(k,k)
-         t = -b(k)
-         call daxpy(k-1,t,a(1,k),1,b(1),1)
-   20 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dqrdc.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrdc.f
deleted file mode 100644
index 54c9320cbea64ada95353a5231b39b158e168794..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dqrdc.f
+++ /dev/null
@@ -1,208 +0,0 @@
-c
-c     dqrdc uses householder transformations to compute the qr
-c     factorization of an n by p matrix x.  column pivoting
-c     based on the 2-norms of the reduced columns may be
-c     performed at the users option.
-c
-c     on entry
-c
-c        x       double precision(ldx,p), where ldx .ge. n.
-c                x contains the matrix whose decomposition is to be
-c                computed.
-c
-c        ldx     integer.
-c                ldx is the leading dimension of the array x.
-c
-c        n       integer.
-c                n is the number of rows of the matrix x.
-c
-c        p       integer.
-c                p is the number of columns of the matrix x.
-c
-c        jpvt    integer(p).
-c                jpvt contains integers that control the selection
-c                of the pivot columns.  the k-th column x(k) of x
-c                is placed in one of three classes according to the
-c                value of jpvt(k).
-c
-c                   if jpvt(k) .gt. 0, then x(k) is an initial
-c                                      column.
-c
-c                   if jpvt(k) .eq. 0, then x(k) is a free column.
-c
-c                   if jpvt(k) .lt. 0, then x(k) is a final column.
-c
-c                before the decomposition is computed, initial columns
-c                are moved to the beginning of the array x and final
-c                columns to the end.  both initial and final columns
-c                are frozen in place during the computation and only
-c                free columns are moved.  at the k-th stage of the
-c                reduction, if x(k) is occupied by a free column
-c                it is interchanged with the free column of largest
-c                reduced norm.  jpvt is not referenced if
-c                job .eq. 0.
-c
-c        work    double precision(p).
-c                work is a work array.  work is not referenced if
-c                job .eq. 0.
-c
-c        job     integer.
-c                job is an integer that initiates column pivoting.
-c                if job .eq. 0, no pivoting is done.
-c                if job .ne. 0, pivoting is done.
-c
-c     on return
-c
-c        x       x contains in its upper triangle the upper
-c                triangular matrix r of the qr factorization.
-c                below its diagonal x contains information from
-c                which the orthogonal part of the decomposition
-c                can be recovered.  note that if pivoting has
-c                been requested, the decomposition is not that
-c                of the original matrix x but that of x
-c                with its columns permuted as described by jpvt.
-c
-c        qraux   double precision(p).
-c                qraux contains further information required to recover
-c                the orthogonal part of the decomposition.
-c
-c        jpvt    jpvt(k) contains the index of the column of the
-c                original matrix that has been interchanged into
-c                the k-th column, if pivoting was requested.
-c
-c     linpack. this version dated 08/14/78 .
-c     g.w. stewart, university of maryland, argonne national lab.
-c
-c     dqrdc uses the following functions and subprograms.
-c
-c     blas daxpy,ddot,dscal,dswap,dnrm2
-c     fortran dabs,dmax1,min0,dsqrt
-c
-      subroutine dqrdc(x,ldx,n,p,qraux,jpvt,work,job)
-      integer ldx,n,p,job
-      integer jpvt(*)
-      double precision x(ldx,*),qraux(*),work(*)
-c
-c     internal variables
-c
-      integer j,jp,jj, l,lp1,lup,maxj,pl,pu
-      double precision maxnrm,dnrm2,tt
-      double precision ddot,nrmxl,t
-      logical negj,swapj
-c
-c
-      pl = 1
-      pu = 0
-      if (job .eq. 0) go to 60
-c
-c        pivoting has been requested.  rearrange the columns
-c        according to jpvt.
-c
-         do 20 j = 1, p
-            swapj = jpvt(j) .gt. 0
-            negj = jpvt(j) .lt. 0
-            jpvt(j) = j
-            if (negj) jpvt(j) = -j
-            if (.not.swapj) go to 10
-               if (j .ne. pl) call dswap(n,x(1,pl),1,x(1,j),1)
-               jpvt(j) = jpvt(pl)
-               jpvt(pl) = j
-               pl = pl + 1
-   10       continue
-   20    continue
-         pu = p
-         do 50 jj = 1, p
-            j = p - jj + 1
-            if (jpvt(j) .ge. 0) go to 40
-               jpvt(j) = -jpvt(j)
-               if (j .eq. pu) go to 30
-                  call dswap(n,x(1,pu),1,x(1,j),1)
-                  jp = jpvt(pu)
-                  jpvt(pu) = jpvt(j)
-                  jpvt(j) = jp
-   30          continue
-               pu = pu - 1
-   40       continue
-   50    continue
-   60 continue
-c
-c     compute the norms of the free columns.
-c
-      if (pu .lt. pl) go to 80
-      do 70 j = pl, pu
-         qraux(j) = dnrm2(n,x(1,j),1)
-         work(j) = qraux(j)
-   70 continue
-   80 continue
-c
-c     perform the householder reduction of x.
-c
-      lup = min0(n,p)
-      do 200 l = 1, lup
-         if (l .lt. pl .or. l .ge. pu) go to 120
-c
-c           locate the column of largest norm and bring it
-c           into the pivot position.
-c
-            maxnrm = 0.0d0
-            maxj = l
-            do 100 j = l, pu
-               if (qraux(j) .le. maxnrm) go to 90
-                  maxnrm = qraux(j)
-                  maxj = j
-   90          continue
-  100       continue
-            if (maxj .eq. l) go to 110
-               call dswap(n,x(1,l),1,x(1,maxj),1)
-               qraux(maxj) = qraux(l)
-               work(maxj) = work(l)
-               jp = jpvt(maxj)
-               jpvt(maxj) = jpvt(l)
-               jpvt(l) = jp
-  110       continue
-  120    continue
-         qraux(l) = 0.0d0
-         if (l .eq. n) go to 190
-c
-c           compute the householder transformation for column l.
-c
-            nrmxl = dnrm2(n-l+1,x(l,l),1)
-            if (nrmxl .eq. 0.0d0) go to 180
-               if (x(l,l) .ne. 0.0d0) nrmxl = dsign(nrmxl,x(l,l))
-               call dscal(n-l+1,1.0d0/nrmxl,x(l,l),1)
-               x(l,l) = 1.0d0 + x(l,l)
-c
-c              apply the transformation to the remaining columns,
-c              updating the norms.
-c
-               lp1 = l + 1
-               if (p .lt. lp1) go to 170
-               do 160 j = lp1, p
-                  t = -ddot(n-l+1,x(l,l),1,x(l,j),1)/x(l,l)
-                  call daxpy(n-l+1,t,x(l,l),1,x(l,j),1)
-                  if (j .lt. pl .or. j .gt. pu) go to 150
-                  if (qraux(j) .eq. 0.0d0) go to 150
-                     tt = 1.0d0 - (dabs(x(l,j))/qraux(j))**2
-                     tt = dmax1(tt,0.0d0)
-                     t = tt
-                     tt = 1.0d0 + 0.05d0*tt*(qraux(j)/work(j))**2
-                     if (tt .eq. 1.0d0) go to 130
-                        qraux(j) = qraux(j)*dsqrt(t)
-                     go to 140
-  130                continue
-                        qraux(j) = dnrm2(n-l,x(l+1,j),1)
-                        work(j) = qraux(j)
-  140                continue
-  150             continue
-  160          continue
-  170          continue
-c
-c              save the transformation.
-c
-               qraux(l) = x(l,l)
-               x(l,l) = -nrmxl
-  180       continue
-  190    continue
-  200 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dqrdc2.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrdc2.f
deleted file mode 100644
index 6e9e23ff2d92bf847dbd2767ef3c426742b8a71a..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dqrdc2.f
+++ /dev/null
@@ -1,194 +0,0 @@
-c
-c     dqrdc2 uses householder transformations to compute the qr
-c     factorization of an n by p matrix x.  a limited column
-c     pivoting strategy based on the 2-norms of the reduced columns
-c     moves columns with near-zero norm to the right-hand edge of
-c     the x matrix.  this strategy means that sequential one
-c     degree-of-freedom effects can be computed in a natural way.
-c
-c     i am very nervous about modifying linpack code in this way.
-c     if you are a computational linear algebra guru and you really
-c     understand how to solve this problem please feel free to
-c     suggest improvements to this code.
-c
-c     Another change was to compute the rank.
-c
-c     on entry
-c
-c        x       double precision(ldx,p), where ldx .ge. n.
-c                x contains the matrix whose decomposition is to be
-c                computed.
-c
-c        ldx     integer.
-c                ldx is the leading dimension of the array x.
-c
-c        n       integer.
-c                n is the number of rows of the matrix x.
-c
-c        p       integer.
-c                p is the number of columns of the matrix x.
-c
-c        tol     double precision
-c                tol is the nonnegative tolerance used to
-c                determine the subset of the columns of x
-c                included in the solution.
-c
-c        jpvt    integer(p).
-c                integers which are swapped in the same way as the
-c                the columns of x during pivoting.  on entry these
-c                should be set equal to the column indices of the
-c                columns of the x matrix (typically 1 to p).
-c
-c        work    double precision(p,2).
-c                work is a work array.
-c
-c     on return
-c
-c        x       x contains in its upper triangle the upper
-c                triangular matrix r of the qr factorization.
-c                below its diagonal x contains information from
-c                which the orthogonal part of the decomposition
-c                can be recovered.  note that if pivoting has
-c                been requested, the decomposition is not that
-c                of the original matrix x but that of x
-c                with its columns permuted as described by jpvt.
-c
-c        k       integer.
-c                k contains the number of columns of x judged
-c                to be linearly independent.
-c
-c        qraux   double precision(p).
-c                qraux contains further information required to recover
-c                the orthogonal part of the decomposition.
-c
-c        jpvt    jpvt(k) contains the index of the column of the
-c                original matrix that has been interchanged into
-c                the k-th column.
-c
-c     original (dqrdc.f) linpack version dated 08/14/78 .
-c     g.w. stewart, university of maryland, argonne national lab.
-c
-c     this version dated 22 august 1995
-c     ross ihaka
-c
-c     bug fixes 29 September 1999 BDR (p > n case, inaccurate ranks)
-c
-c
-c     dqrdc2 uses the following functions and subprograms.
-c
-c     blas daxpy,ddot,dscal,dnrm2
-c     fortran dabs,dmax1,min0,dsqrt
-c
-      subroutine dqrdc2(x,ldx,n,p,tol,k,qraux,jpvt,work)
-      integer ldx,n,p
-      integer jpvt(*)
-      double precision x(ldx,*),qraux(*),work(p,2),tol
-c
-c     internal variables
-c
-      integer i,j,l,lp1,lup,k
-      double precision dnrm2,tt,ttt
-      double precision ddot,nrmxl,t
-c
-c
-c     compute the norms of the columns of x.
-c
-      do 70 j = 1, p
-         qraux(j) = dnrm2(n,x(1,j),1)
-         work(j,1) = qraux(j)
-         work(j,2) = qraux(j)
-         if(work(j,2) .eq. 0.0d0) work(j,2) = 1.0d0
-   70 continue
-c
-c     perform the householder reduction of x.
-c
-      lup = min0(n,p)
-      k = p + 1
-      do 200 l = 1, lup
-c
-c     previous version only cycled l to lup
-c
-c     cycle the columns from l to p left-to-right until one
-c     with non-negligible norm is located.  a column is considered
-c     to have become negligible if its norm has fallen below
-c     tol times its original norm.  the check for l .le. k
-c     avoids infinite cycling.
-c
-   80    continue
-         if (l .ge. k .or. qraux(l) .ge. work(l,2)*tol) go to 120
-            lp1 = l+1
-            do 100 i=1,n
-               t = x(i,l)
-               do 90 j=lp1,p
-                  x(i,j-1) = x(i,j)
-   90          continue
-               x(i,p) = t
-  100       continue
-            i = jpvt(l)
-            t = qraux(l)
-            tt = work(l,1)
-            ttt = work(l,2)
-            do 110 j=lp1,p
-               jpvt(j-1) = jpvt(j)
-               qraux(j-1) = qraux(j)
-               work(j-1,1) = work(j,1)
-               work(j-1,2) = work(j,2)
-  110       continue
-            jpvt(p) = i
-            qraux(p) = t
-            work(p,1) = tt
-            work(p,2) = ttt
-            k = k - 1
-            go to 80
-  120    continue
-         if (l .eq. n) go to 190
-c
-c           compute the householder transformation for column l.
-c
-            nrmxl = dnrm2(n-l+1,x(l,l),1)
-            if (nrmxl .eq. 0.0d0) go to 180
-               if (x(l,l) .ne. 0.0d0) nrmxl = dsign(nrmxl,x(l,l))
-               call dscal(n-l+1,1.0d0/nrmxl,x(l,l),1)
-               x(l,l) = 1.0d0 + x(l,l)
-c
-c              apply the transformation to the remaining columns,
-c              updating the norms.
-c
-               lp1 = l + 1
-               if (p .lt. lp1) go to 170
-               do 160 j = lp1, p
-                  t = -ddot(n-l+1,x(l,l),1,x(l,j),1)/x(l,l)
-                  call daxpy(n-l+1,t,x(l,l),1,x(l,j),1)
-                  if (qraux(j) .eq. 0.0d0) go to 150
-                     tt = 1.0d0 - (dabs(x(l,j))/qraux(j))**2
-                     tt = dmax1(tt,0.0d0)
-                     t = tt
-c
-c modified 9/99 by BDR. Re-compute norms if there is large reduction
-c The tolerance here is on the squared norm
-c In this version we need accurate norms, so re-compute often.
-c  work(j,1) is only updated in one case: looks like a bug -- no longer used
-c
-c                     tt = 1.0d0 + 0.05d0*tt*(qraux(j)/work(j,1))**2
-c                     if (tt .eq. 1.0d0) go to 130
-                     if (dabs(t) .lt. 1d-6) go to 130
-                        qraux(j) = qraux(j)*dsqrt(t)
-                     go to 140
-  130                continue
-                        qraux(j) = dnrm2(n-l,x(l+1,j),1)
-                        work(j,1) = qraux(j)
-  140                continue
-  150             continue
-  160          continue
-  170          continue
-c
-c              save the transformation.
-c
-               qraux(l) = x(l,l)
-               x(l,l) = -nrmxl
-  180       continue
-  190    continue
-  200 continue
-      k = min0(k - 1, n)
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dqrls.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrls.f
deleted file mode 100644
index 31e029f5a02fe6201476b3c26b24fb9a915c67f7..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dqrls.f
+++ /dev/null
@@ -1,116 +0,0 @@
-c
-c     dqrfit is a subroutine to compute least squares solutions
-c     to the system
-c
-c     (1)               x * b = y
-c
-c     which may be either under-determined or over-determined.
-c     the user must supply a tolerance to limit the columns of
-c     x used in computing the solution.  in effect, a set of
-c     columns with a condition number approximately bounded by
-c     1/tol is used, the other components of b being set to zero.
-c
-c     on entry
-c
-c        x      double precision(n,p).
-c               x contains n-by-p coefficient matrix of
-c               the system (1), x is destroyed by dqrfit.
-c
-c        n      the number of rows of the matrix x.
-c
-c        p      the number of columns of the matrix x.
-c
-c        y      double precision(n,ny)
-c               y contains the right hand side(s) of the system (1).
-c
-c        ny     the number of right hand sides of the system (1).
-c
-c        tol    double precision
-c               tol is the nonnegative tolerance used to
-c               determine the subset of columns of x included
-c               in the solution.  columns are pivoted out of
-c               decomposition if
-c
-c        jpvt   integer(p)
-c               the values in jpvt are permuted in the same
-c               way as the columns of x.  this can be useful
-c               in unscrambling coefficients etc.
-c
-c        work   double precision(2*p)
-c               work is an array used by dqrdc2 and dqrsl.
-c
-c     on return
-c
-c        x      contains the output array from dqrdc2.
-c               namely the qr decomposition of x stored in
-c               compact form.
-c
-c        b      double precision(p,ny)
-c               b contains the solution vectors with rows permuted
-c               in the same way as the columns of x.  components
-c               corresponding to columns not used are set to zero.
-c
-c        rsd    double precision(n,ny)
-c               rsd contains the residual vectors y-x*b.
-c
-c        qty    double precision(n,ny)     t
-c               qty contains the vectors  q y.   note that
-c               the initial p elements of this vector are
-c               permuted in the same way as the columns of x.
-c
-c        k      integer
-c               k contains the number of columns used in the
-c               solution.
-c
-c        jpvt   has its contents permuted as described above.
-c
-c        qraux  double precision(p)
-c               qraux contains auxiliary information on the
-c               qr decomposition of x.
-c
-c
-c     on return the arrays x, jpvt and qraux contain the
-c     usual output from dqrdc, so that the qr decomposition
-c     of x with pivoting is fully available to the user.
-c     in particular, columns jpvt(1), jpvt(2),...,jpvt(k)
-c     were used in the solution, and the condition number
-c     associated with those columns is estimated by
-c     abs(x(1,1)/x(k,k)).
-c
-c     dqrfit uses the linpack routines dqrdc and dqrsl.
-c
-      subroutine dqrls(x,n,p,y,ny,tol,b,rsd,qty,k,jpvt,qraux,work)
-      integer n,p,ny,k,jpvt(p)
-      double precision x(n,p),y(n,ny),tol,b(p,ny),rsd(n,ny),
-     .                 qty(n,ny),qraux(p),work(p)
-c
-c     internal variables.
-c
-      integer info,j,jj,kk
-c
-c     reduce x.
-c
-      call dqrdc2(x,n,n,p,tol,k,qraux,jpvt,work)
-c
-c     solve the truncated least squares problem for each rhs.
-c
-      if(k .gt. 0) then
-         do 20 jj=1,ny
-   20       call dqrsl(x,n,n,k,qraux,y(1,jj),rsd(1,jj),qty(1,jj),
-     1           b(1,jj),rsd(1,jj),rsd(1,jj),1110,info)
-      else
-         do 30 i=1,n
-            do 30 jj=1,ny
-   30           rsd(i,jj) = y(i,jj)
-      endif
-c
-c     set the unused components of b to zero.
-c
-      kk = k + 1
-      do 50 j=kk,p
-         do 40 jj=1,ny
-            b(j,jj) = 0.d0
-   40    continue
-   50 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dqrsl.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrsl.f
deleted file mode 100644
index aab138a5feb558905e7f4c597afdb2c1b14002a8..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dqrsl.f
+++ /dev/null
@@ -1,275 +0,0 @@
-c
-c     dqrsl applies the output of dqrdc to compute coordinate
-c     transformations, projections, and least squares solutions.
-c     for k .le. min(n,p), let xk be the matrix
-c
-c            xk = (x(jpvt(1)),x(jpvt(2)), ... ,x(jpvt(k)))
-c
-c     formed from columnns jpvt(1), ... ,jpvt(k) of the original
-c     n x p matrix x that was input to dqrdc (if no pivoting was
-c     done, xk consists of the first k columns of x in their
-c     original order).  dqrdc produces a factored orthogonal matrix q
-c     and an upper triangular matrix r such that
-c
-c              xk = q * (r)
-c                       (0)
-c
-c     this information is contained in coded form in the arrays
-c     x and qraux.
-c
-c     on entry
-c
-c        x      double precision(ldx,p).
-c               x contains the output of dqrdc.
-c
-c        ldx    integer.
-c               ldx is the leading dimension of the array x.
-c
-c        n      integer.
-c               n is the number of rows of the matrix xk.  it must
-c               have the same value as n in dqrdc.
-c
-c        k      integer.
-c               k is the number of columns of the matrix xk.  k
-c               must nnot be greater than min(n,p), where p is the
-c               same as in the calling sequence to dqrdc.
-c
-c        qraux  double precision(p).
-c               qraux contains the auxiliary output from dqrdc.
-c
-c        y      double precision(n)
-c               y contains an n-vector that is to be manipulated
-c               by dqrsl.
-c
-c        job    integer.
-c               job specifies what is to be computed.  job has
-c               the decimal expansion abcde, with the following
-c               meaning.
-c
-c                    if a.ne.0, compute qy.
-c                    if b,c,d, or e .ne. 0, compute qty.
-c                    if c.ne.0, compute b.
-c                    if d.ne.0, compute rsd.
-c                    if e.ne.0, compute xb.
-c
-c               note that a request to compute b, rsd, or xb
-c               automatically triggers the computation of qty, for
-c               which an array must be provided in the calling
-c               sequence.
-c
-c     on return
-c
-c        qy     double precision(n).
-c               qy conntains q*y, if its computation has been
-c               requested.
-c
-c        qty    double precision(n).
-c               qty contains trans(q)*y, if its computation has
-c               been requested.  here trans(q) is the
-c               transpose of the matrix q.
-c
-c        b      double precision(k)
-c               b contains the solution of the least squares problem
-c
-c                    minimize norm2(y - xk*b),
-c
-c               if its computation has been requested.  (note that
-c               if pivoting was requested in dqrdc, the j-th
-c               component of b will be associated with column jpvt(j)
-c               of the original matrix x that was input into dqrdc.)
-c
-c        rsd    double precision(n).
-c               rsd contains the least squares residual y - xk*b,
-c               if its computation has been requested.  rsd is
-c               also the orthogonal projection of y onto the
-c               orthogonal complement of the column space of xk.
-c
-c        xb     double precision(n).
-c               xb contains the least squares approximation xk*b,
-c               if its computation has been requested.  xb is also
-c               the orthogonal projection of y onto the column space
-c               of x.
-c
-c        info   integer.
-c               info is zero unless the computation of b has
-c               been requested and r is exactly singular.  in
-c               this case, info is the index of the first zero
-c               diagonal element of r and b is left unaltered.
-c
-c     the parameters qy, qty, b, rsd, and xb are not referenced
-c     if their computation is not requested and in this case
-c     can be replaced by dummy variables in the calling program.
-c     to save storage, the user may in some cases use the same
-c     array for different parameters in the calling sequence.  a
-c     frequently occuring example is when one wishes to compute
-c     any of b, rsd, or xb and does not need y or qty.  in this
-c     case one may identify y, qty, and one of b, rsd, or xb, while
-c     providing separate arrays for anything else that is to be
-c     computed.  thus the calling sequence
-c
-c          call dqrsl(x,ldx,n,k,qraux,y,dum,y,b,y,dum,110,info)
-c
-c     will result in the computation of b and rsd, with rsd
-c     overwriting y.  more generally, each item in the following
-c     list contains groups of permissible identifications for
-c     a single callinng sequence.
-c
-c          1. (y,qty,b) (rsd) (xb) (qy)
-c
-c          2. (y,qty,rsd) (b) (xb) (qy)
-c
-c          3. (y,qty,xb) (b) (rsd) (qy)
-c
-c          4. (y,qy) (qty,b) (rsd) (xb)
-c
-c          5. (y,qy) (qty,rsd) (b) (xb)
-c
-c          6. (y,qy) (qty,xb) (b) (rsd)
-c
-c     in any group the value returned in the array allocated to
-c     the group corresponds to the last member of the group.
-c
-c     linpack. this version dated 08/14/78 .
-c     g.w. stewart, university of maryland, argonne national lab.
-c
-c     dqrsl uses the following functions and subprograms.
-c
-c     BLAS      daxpy,dcopy,ddot
-c     Fortran   dabs,min0,mod
-c
-      subroutine dqrsl(x,ldx,n,k,qraux,y,qy,qty,b,rsd,xb,job,info)
-      integer ldx,n,k,job,info
-      double precision x(ldx,*),qraux(*),y(*),qy(*),qty(*),b(*),rsd(*),
-     *                 xb(*)
-c
-c     internal variables
-c
-      integer i,j,jj,ju,kp1
-      double precision ddot,t,temp
-      logical cb,cqy,cqty,cr,cxb
-c
-c
-c     set info flag.
-c
-      info = 0
-c
-c     determine what is to be computed.
-c
-      cqy = job/10000 .ne. 0
-      cqty = mod(job,10000) .ne. 0
-      cb = mod(job,1000)/100 .ne. 0
-      cr = mod(job,100)/10 .ne. 0
-      cxb = mod(job,10) .ne. 0
-      ju = min0(k,n-1)
-c
-c     special action when n=1.
-c
-      if (ju .ne. 0) go to 40
-         if (cqy) qy(1) = y(1)
-         if (cqty) qty(1) = y(1)
-         if (cxb) xb(1) = y(1)
-         if (.not.cb) go to 30
-            if (x(1,1) .ne. 0.0d0) go to 10
-               info = 1
-            go to 20
-   10       continue
-               b(1) = y(1)/x(1,1)
-   20       continue
-   30    continue
-         if (cr) rsd(1) = 0.0d0
-      go to 250
-   40 continue
-c
-c        set up to compute qy or qty.
-c
-         if (cqy) call dcopy(n,y,1,qy,1)
-         if (cqty) call dcopy(n,y,1,qty,1)
-         if (.not.cqy) go to 70
-c
-c           compute qy.
-c
-            do 60 jj = 1, ju
-               j = ju - jj + 1
-               if (qraux(j) .eq. 0.0d0) go to 50
-                  temp = x(j,j)
-                  x(j,j) = qraux(j)
-                  t = -ddot(n-j+1,x(j,j),1,qy(j),1)/x(j,j)
-                  call daxpy(n-j+1,t,x(j,j),1,qy(j),1)
-                  x(j,j) = temp
-   50          continue
-   60       continue
-   70    continue
-         if (.not.cqty) go to 100
-c
-c           compute trans(q)*y.
-c
-            do 90 j = 1, ju
-               if (qraux(j) .eq. 0.0d0) go to 80
-                  temp = x(j,j)
-                  x(j,j) = qraux(j)
-                  t = -ddot(n-j+1,x(j,j),1,qty(j),1)/x(j,j)
-                  call daxpy(n-j+1,t,x(j,j),1,qty(j),1)
-                  x(j,j) = temp
-   80          continue
-   90       continue
-  100    continue
-c
-c        set up to compute b, rsd, or xb.
-c
-         if (cb) call dcopy(k,qty,1,b,1)
-         kp1 = k + 1
-         if (cxb) call dcopy(k,qty,1,xb,1)
-         if (cr .and. k .lt. n) call dcopy(n-k,qty(kp1),1,rsd(kp1),1)
-         if (.not.cxb .or. kp1 .gt. n) go to 120
-            do 110 i = kp1, n
-               xb(i) = 0.0d0
-  110       continue
-  120    continue
-         if (.not.cr) go to 140
-            do 130 i = 1, k
-               rsd(i) = 0.0d0
-  130       continue
-  140    continue
-         if (.not.cb) go to 190
-c
-c           compute b.
-c
-            do 170 jj = 1, k
-               j = k - jj + 1
-               if (x(j,j) .ne. 0.0d0) go to 150
-                  info = j
-c           ......exit
-                  go to 180
-  150          continue
-               b(j) = b(j)/x(j,j)
-               if (j .eq. 1) go to 160
-                  t = -b(j)
-                  call daxpy(j-1,t,x(1,j),1,b,1)
-  160          continue
-  170       continue
-  180       continue
-  190    continue
-         if (.not.cr .and. .not.cxb) go to 240
-c
-c           compute rsd or xb as required.
-c
-            do 230 jj = 1, ju
-               j = ju - jj + 1
-               if (qraux(j) .eq. 0.0d0) go to 220
-                  temp = x(j,j)
-                  x(j,j) = qraux(j)
-                  if (.not.cr) go to 200
-                     t = -ddot(n-j+1,x(j,j),1,rsd(j),1)/x(j,j)
-                     call daxpy(n-j+1,t,x(j,j),1,rsd(j),1)
-  200             continue
-                  if (.not.cxb) go to 210
-                     t = -ddot(n-j+1,x(j,j),1,xb(j),1)/x(j,j)
-                     call daxpy(n-j+1,t,x(j,j),1,xb(j),1)
-  210             continue
-                  x(j,j) = temp
-  220          continue
-  230       continue
-  240    continue
-  250 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dqrutl.f b/com.oracle.truffle.r.native/builtinlibs/src/dqrutl.f
deleted file mode 100644
index 2d208ca0d8cb33e6215801c7637bc9465f167181..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dqrutl.f
+++ /dev/null
@@ -1,66 +0,0 @@
-c dqr Utilities:  Interface to the different "switches" of  dqrsl().
-c
-      subroutine dqrqty(x, n, k, qraux, y, ny, qty)
-
-      integer n, k, ny
-      double precision x(n,k), qraux(k), y(n,ny), qty(n,ny)
-      integer info, j
-      double precision dummy(1)
-      do 10 j = 1,ny
-          call dqrsl(x, n, n, k, qraux, y(1,j), dummy, qty(1,j),
-     &               dummy, dummy, dummy, 1000, info)
-   10 continue
-      return
-      end
-c
-      subroutine dqrqy(x, n, k, qraux, y, ny, qy)
-
-      integer n, k, ny
-      double precision x(n,k), qraux(k), y(n,ny), qy(n,ny)
-      integer info, j
-      double precision dummy(1)
-      do 10 j = 1,ny
-          call dqrsl(x, n, n, k, qraux, y(1,j), qy(1,j),
-     &               dummy,  dummy, dummy, dummy, 10000, info)
-   10 continue
-      return
-      end
-c
-      subroutine dqrcf(x, n, k, qraux, y, ny, b, info)
-
-      integer n, k, ny, info
-      double precision x(n,k), qraux(k), y(n,ny), b(k,ny)
-      integer j
-      double precision dummy(1)
-      do 10 j = 1,ny
-          call dqrsl(x, n, n, k, qraux, y(1,j), dummy,
-     &               y(1,j), b(1,j), dummy, dummy, 100, info)
-   10 continue
-      return
-      end
-c
-      subroutine dqrrsd(x, n, k, qraux, y, ny, rsd)
-
-      integer n, k, ny
-      double precision x(n,k), qraux(k), y(n,ny), rsd(n,ny)
-      integer info, j
-      double precision dummy(1)
-      do 10 j = 1,ny
-          call dqrsl(x, n, n, k, qraux, y(1,j), dummy,
-     &               y(1,j), dummy, rsd(1,j), dummy, 10, info)
-   10 continue
-      return
-      end
-c
-      subroutine dqrxb(x, n, k, qraux, y, ny, xb)
-
-      integer n, k, ny
-      double precision x(n,k), qraux(k), y(n,ny), xb(n,ny)
-      integer info, j
-      double precision dummy(1)
-      do 10 j = 1,ny
-          call dqrsl(x, n, n, k, qraux, y(1,j), dummy,
-     &               y(1,j), dummy, dummy, xb(1,j), 1, info)
-   10 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dsvdc.f b/com.oracle.truffle.r.native/builtinlibs/src/dsvdc.f
deleted file mode 100644
index bdfd97d77a42a9a378a9e2b06ab802e325ee9505..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dsvdc.f
+++ /dev/null
@@ -1,495 +0,0 @@
-c -- called from R's  svd(x, ..., LINPACK = TRUE)  , i.e, *NOT* by default -- 
-c
-c     dsvdc is a subroutine to reduce a double precision nxp matrix x
-c     by orthogonal transformations u and v to diagonal form.  the
-c     diagonal elements s(i) are the singular values of x.  the
-c     columns of u are the corresponding left singular vectors,
-c     and the columns of v the right singular vectors.
-c
-c     on entry
-c
-c         x         double precision(ldx,p), where ldx.ge.n.
-c                   x contains the matrix whose singular value
-c                   decomposition is to be computed.  x is
-c                   destroyed by dsvdc.
-c
-c         ldx       integer.
-c                   ldx is the leading dimension of the array x.
-c
-c         n         integer.
-c                   n is the number of rows of the matrix x.
-c
-c         p         integer.
-c                   p is the number of columns of the matrix x.
-c
-c         ldu       integer.
-c                   ldu is the leading dimension of the array u.
-c                   (see below).
-c
-c         ldv       integer.
-c                   ldv is the leading dimension of the array v.
-c                   (see below).
-c
-c         work      double precision(n).
-c                   work is a scratch array.
-c
-c         job       integer.
-c                   job controls the computation of the singular
-c                   vectors.  it has the decimal expansion ab
-c                   with the following meaning
-c
-c                        a.eq.0    do not compute the left singular
-c                                  vectors.
-c                        a.eq.1    return the n left singular vectors
-c                                  in u.
-c                        a.ge.2    return the first min(n,p) singular
-c                                  vectors in u.
-c                        b.eq.0    do not compute the right singular
-c                                  vectors.
-c                        b.eq.1    return the right singular vectors
-c                                  in v.
-c
-c     on return
-c
-c         s         double precision(mm), where mm=min(n+1,p).
-c                   the first min(n,p) entries of s contain the
-c                   singular values of x arranged in descending
-c                   order of magnitude.
-c
-c         e         double precision(p), 
-c                   e ordinarily contains zeros.  however see the
-c                   discussion of info for exceptions.
-c
-c         u         double precision(ldu,k), where ldu.ge.n.  if
-c                                   joba.eq.1 then k.eq.n, if joba.ge.2
-c                                   then k.eq.min(n,p).
-c                   u contains the matrix of left singular vectors.
-c                   u is not referenced if joba.eq.0.  if n.le.p
-c                   or if joba.eq.2, then u may be identified with x
-c                   in the subroutine call.
-c
-c         v         double precision(ldv,p), where ldv.ge.p.
-c                   v contains the matrix of right singular vectors.
-c                   v is not referenced if job.eq.0.  if p.le.n,
-c                   then v may be identified with x in the
-c                   subroutine call.
-c
-c         info      integer.
-c                   the singular values (and their corresponding
-c                   singular vectors) s(info+1),s(info+2),...,s(m)
-c                   are correct (here m=min(n,p)).  thus if
-c                   info.eq.0, all the singular values and their
-c                   vectors are correct.  in any event, the matrix
-c                   b = trans(u)*x*v is the bidiagonal matrix
-c                   with the elements of s on its diagonal and the
-c                   elements of e on its super-diagonal (trans(u)
-c                   is the transpose of u).  thus the singular
-c                   values of x and b are the same.
-c
-c     linpack. this version dated 08/14/78 .
-c              correction made to shift 2/84.
-c     g.w. stewart, university of maryland, argonne national lab.
-c
-c     Modified 2000-12-28 to use a relative convergence test,
-c     as this was infinite-looping on ix86.
-c
-c     dsvdc uses the following functions and subprograms.
-c
-c     external drot
-c     blas daxpy,ddot,dscal,dswap,dnrm2,drotg
-c     fortran dabs,dmax1,max0,min0,mod,dsqrt
-c
-      subroutine dsvdc(x,ldx,n,p,s,e,u,ldu,v,ldv,work,job,info)
-      integer ldx,n,p,ldu,ldv,job,info
-      double precision x(ldx,*),s(*),e(*),u(ldu,*),v(ldv,*),work(*)
-c
-c     internal variables
-c
-      integer i,iter,j,jobu,k,kase,kk,l,ll,lls,lm1,lp1,ls,lu,m,maxit,
-     *        mm,mm1,mp1,nct,nctp1,ncu,nrt,nrtp1
-      double precision ddot,t
-      double precision b,c,cs,el,emm1,f,g,dnrm2,scale,shift,sl,sm,sn,
-     *                 smm1,t1,test,ztest,acc
-      logical wantu,wantv
-c
-c     unnecessary initializations of l and ls to keep g77 -Wall happy
-c
-      l = 0
-      ls = 0
-c
-c
-c     set the maximum number of iterations.
-c
-      maxit = 30
-c
-c     determine what is to be computed.
-c
-      wantu = .false.
-      wantv = .false.
-      jobu = mod(job,100)/10
-      ncu = n
-      if (jobu .gt. 1) ncu = min0(n,p)
-      if (jobu .ne. 0) wantu = .true.
-      if (mod(job,10) .ne. 0) wantv = .true.
-c
-c     reduce x to bidiagonal form, storing the diagonal elements
-c     in s and the super-diagonal elements in e.
-c
-      info = 0
-      nct = min0(n-1,p)
-      nrt = max0(0,min0(p-2,n))
-      lu = max0(nct,nrt)
-      if (lu .lt. 1) go to 170
-      do 160 l = 1, lu
-         lp1 = l + 1
-         if (l .gt. nct) go to 20
-c
-c           compute the transformation for the l-th column and
-c           place the l-th diagonal in s(l).
-c
-            s(l) = dnrm2(n-l+1,x(l,l),1)
-            if (s(l) .eq. 0.0d0) go to 10
-               if (x(l,l) .ne. 0.0d0) s(l) = dsign(s(l),x(l,l))
-               call dscal(n-l+1,1.0d0/s(l),x(l,l),1)
-               x(l,l) = 1.0d0 + x(l,l)
-   10       continue
-            s(l) = -s(l)
-   20    continue
-         if (p .lt. lp1) go to 50
-         do 40 j = lp1, p
-            if (l .gt. nct) go to 30
-            if (s(l) .eq. 0.0d0) go to 30
-c
-c              apply the transformation.
-c
-               t = -ddot(n-l+1,x(l,l),1,x(l,j),1)/x(l,l)
-               call daxpy(n-l+1,t,x(l,l),1,x(l,j),1)
-   30       continue
-c
-c           place the l-th row of x into  e for the
-c           subsequent calculation of the row transformation.
-c
-            e(j) = x(l,j)
-   40    continue
-   50    continue
-         if (.not.wantu .or. l .gt. nct) go to 70
-c
-c           place the transformation in u for subsequent back
-c           multiplication.
-c
-            do 60 i = l, n
-               u(i,l) = x(i,l)
-   60       continue
-   70    continue
-         if (l .gt. nrt) go to 150
-c
-c           compute the l-th row transformation and place the
-c           l-th super-diagonal in e(l).
-c
-            e(l) = dnrm2(p-l,e(lp1),1)
-            if (e(l) .eq. 0.0d0) go to 80
-               if (e(lp1) .ne. 0.0d0) e(l) = dsign(e(l),e(lp1))
-               call dscal(p-l,1.0d0/e(l),e(lp1),1)
-               e(lp1) = 1.0d0 + e(lp1)
-   80       continue
-            e(l) = -e(l)
-            if (lp1 .gt. n .or. e(l) .eq. 0.0d0) go to 120
-c
-c              apply the transformation.
-c
-               do 90 i = lp1, n
-                  work(i) = 0.0d0
-   90          continue
-               do 100 j = lp1, p
-                  call daxpy(n-l,e(j),x(lp1,j),1,work(lp1),1)
-  100          continue
-               do 110 j = lp1, p
-                  call daxpy(n-l,-e(j)/e(lp1),work(lp1),1,x(lp1,j),1)
-  110          continue
-  120       continue
-            if (.not.wantv) go to 140
-c
-c              place the transformation in v for subsequent
-c              back multiplication.
-c
-               do 130 i = lp1, p
-                  v(i,l) = e(i)
-  130          continue
-  140       continue
-  150    continue
-  160 continue
-  170 continue
-c
-c     set up the final bidiagonal matrix or order m.
-c
-      m = min0(p,n+1)
-      nctp1 = nct + 1
-      nrtp1 = nrt + 1
-      if (nct .lt. p) s(nctp1) = x(nctp1,nctp1)
-      if (n .lt. m) s(m) = 0.0d0
-      if (nrtp1 .lt. m) e(nrtp1) = x(nrtp1,m)
-      e(m) = 0.0d0
-c
-c     if required, generate u.
-c
-      if (.not.wantu) go to 300
-         if (ncu .lt. nctp1) go to 200
-         do 190 j = nctp1, ncu
-            do 180 i = 1, n
-               u(i,j) = 0.0d0
-  180       continue
-            u(j,j) = 1.0d0
-  190    continue
-  200    continue
-         if (nct .lt. 1) go to 290
-         do 280 ll = 1, nct
-            l = nct - ll + 1
-            if (s(l) .eq. 0.0d0) go to 250
-               lp1 = l + 1
-               if (ncu .lt. lp1) go to 220
-               do 210 j = lp1, ncu
-                  t = -ddot(n-l+1,u(l,l),1,u(l,j),1)/u(l,l)
-                  call daxpy(n-l+1,t,u(l,l),1,u(l,j),1)
-  210          continue
-  220          continue
-               call dscal(n-l+1,-1.0d0,u(l,l),1)
-               u(l,l) = 1.0d0 + u(l,l)
-               lm1 = l - 1
-               if (lm1 .lt. 1) go to 240
-               do 230 i = 1, lm1
-                  u(i,l) = 0.0d0
-  230          continue
-  240          continue
-            go to 270
-  250       continue
-               do 260 i = 1, n
-                  u(i,l) = 0.0d0
-  260          continue
-               u(l,l) = 1.0d0
-  270       continue
-  280    continue
-  290    continue
-  300 continue
-c
-c     if it is required, generate v.
-c
-      if (.not.wantv) go to 350
-         do 340 ll = 1, p
-            l = p - ll + 1
-            lp1 = l + 1
-            if (l .gt. nrt) go to 320
-            if (e(l) .eq. 0.0d0) go to 320
-               do 310 j = lp1, p
-                  t = -ddot(p-l,v(lp1,l),1,v(lp1,j),1)/v(lp1,l)
-                  call daxpy(p-l,t,v(lp1,l),1,v(lp1,j),1)
-  310          continue
-  320       continue
-            do 330 i = 1, p
-               v(i,l) = 0.0d0
-  330       continue
-            v(l,l) = 1.0d0
-  340    continue
-  350 continue
-c
-c     main iteration loop for the singular values.
-c
-      mm = m
-      iter = 0
-  360 continue
-c
-c        quit if all the singular values have been found.
-c
-c     ...exit
-         if (m .eq. 0) go to 620
-c
-c        if too many iterations have been performed, set
-c        flag and return.
-c
-         if (iter .lt. maxit) go to 370
-            info = m
-c     ......exit
-            go to 620
-  370    continue
-c
-c        this section of the program inspects for
-c        negligible elements in the s and e arrays.  on
-c        completion the variables kase and l are set as follows.
-c
-c           kase = 1     if s(m) and e(l-1) are negligible and l.lt.m
-c           kase = 2     if s(l) is negligible and l.lt.m
-c           kase = 3     if e(l-1) is negligible, l.lt.m, and
-c                        s(l), ..., s(m) are not negligible (qr step).
-c           kase = 4     if e(m-1) is negligible (convergence).
-c
-         do 390 ll = 1, m
-            l = m - ll
-c        ...exit
-            if (l .eq. 0) go to 400
-            test = dabs(s(l)) + dabs(s(l+1))
-            ztest = test + dabs(e(l))
-            acc = dabs(test - ztest)/(1.0d-100 + test)
-            if (acc .gt. 1.d-15) goto 380
-c            if (ztest .ne. test) go to 380
-               e(l) = 0.0d0
-c        ......exit
-               go to 400
-  380       continue
-  390    continue
-  400    continue
-         if (l .ne. m - 1) go to 410
-            kase = 4
-         go to 480
-  410    continue
-            lp1 = l + 1
-            mp1 = m + 1
-            do 430 lls = lp1, mp1
-               ls = m - lls + lp1
-c           ...exit
-               if (ls .eq. l) go to 440
-               test = 0.0d0
-               if (ls .ne. m) test = test + dabs(e(ls))
-               if (ls .ne. l + 1) test = test + dabs(e(ls-1))
-               ztest = test + dabs(s(ls))
-c 1.0d-100 is to guard against a zero matrix, hence zero test
-               acc = dabs(test - ztest)/(1.0d-100 + test)
-               if (acc .gt. 1.d-15) goto 420
-c               if (ztest .ne. test) go to 420
-                  s(ls) = 0.0d0
-c           ......exit
-                  go to 440
-  420          continue
-  430       continue
-  440       continue
-            if (ls .ne. l) go to 450
-               kase = 3
-            go to 470
-  450       continue
-            if (ls .ne. m) go to 460
-               kase = 1
-            go to 470
-  460       continue
-               kase = 2
-               l = ls
-  470       continue
-  480    continue
-         l = l + 1
-c
-c        perform the task indicated by kase.
-c
-         go to (490,520,540,570), kase
-c
-c        deflate negligible s(m).
-c
-  490    continue
-            mm1 = m - 1
-            f = e(m-1)
-            e(m-1) = 0.0d0
-            do 510 kk = l, mm1
-               k = mm1 - kk + l
-               t1 = s(k)
-               call drotg(t1,f,cs,sn)
-               s(k) = t1
-               if (k .eq. l) go to 500
-                  f = -sn*e(k-1)
-                  e(k-1) = cs*e(k-1)
-  500          continue
-               if (wantv) call drot(p,v(1,k),1,v(1,m),1,cs,sn)
-  510       continue
-         go to 610
-c
-c        split at negligible s(l).
-c
-  520    continue
-            f = e(l-1)
-            e(l-1) = 0.0d0
-            do 530 k = l, m
-               t1 = s(k)
-               call drotg(t1,f,cs,sn)
-               s(k) = t1
-               f = -sn*e(k)
-               e(k) = cs*e(k)
-               if (wantu) call drot(n,u(1,k),1,u(1,l-1),1,cs,sn)
-  530       continue
-         go to 610
-c
-c        perform one qr step.
-c
-  540    continue
-c
-c           calculate the shift.
-c
-            scale = dmax1(dabs(s(m)),dabs(s(m-1)),dabs(e(m-1)),
-     *                    dabs(s(l)),dabs(e(l)))
-            sm = s(m)/scale
-            smm1 = s(m-1)/scale
-            emm1 = e(m-1)/scale
-            sl = s(l)/scale
-            el = e(l)/scale
-            b = ((smm1 + sm)*(smm1 - sm) + emm1**2)/2.0d0
-            c = (sm*emm1)**2
-            shift = 0.0d0
-            if (b .eq. 0.0d0 .and. c .eq. 0.0d0) go to 550
-               shift = dsqrt(b**2+c)
-               if (b .lt. 0.0d0) shift = -shift
-               shift = c/(b + shift)
-  550       continue
-            f = (sl + sm)*(sl - sm) + shift
-            g = sl*el
-c
-c           chase zeros.
-c
-            mm1 = m - 1
-            do 560 k = l, mm1
-               call drotg(f,g,cs,sn)
-               if (k .ne. l) e(k-1) = f
-               f = cs*s(k) + sn*e(k)
-               e(k) = cs*e(k) - sn*s(k)
-               g = sn*s(k+1)
-               s(k+1) = cs*s(k+1)
-               if (wantv) call drot(p,v(1,k),1,v(1,k+1),1,cs,sn)
-               call drotg(f,g,cs,sn)
-               s(k) = f
-               f = cs*e(k) + sn*s(k+1)
-               s(k+1) = -sn*e(k) + cs*s(k+1)
-               g = sn*e(k+1)
-               e(k+1) = cs*e(k+1)
-               if (wantu .and. k .lt. n)
-     *            call drot(n,u(1,k),1,u(1,k+1),1,cs,sn)
-  560       continue
-            e(m-1) = f
-            iter = iter + 1
-         go to 610
-c
-c        convergence.
-c
-  570    continue
-c
-c           make the singular value  positive.
-c
-            if (s(l) .ge. 0.0d0) go to 580
-               s(l) = -s(l)
-               if (wantv) call dscal(p,-1.0d0,v(1,l),1)
-  580       continue
-c
-c           order the singular value.
-c
-  590       if (l .eq. mm) go to 600
-c           ...exit
-               if (s(l) .ge. s(l+1)) go to 600
-               t = s(l)
-               s(l) = s(l+1)
-               s(l+1) = t
-               if (wantv .and. l .lt. p)
-     *            call dswap(p,v(1,l),1,v(1,l+1),1)
-               if (wantu .and. l .lt. n)
-     *            call dswap(n,u(1,l),1,u(1,l+1),1)
-               l = l + 1
-            go to 590
-  600       continue
-            iter = 0
-            m = m - 1
-  610    continue
-      go to 360
-  620 continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dtrco.f b/com.oracle.truffle.r.native/builtinlibs/src/dtrco.f
deleted file mode 100644
index 8f693e6a818fc23902117385b68d651a726fb556..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dtrco.f
+++ /dev/null
@@ -1,161 +0,0 @@
-      subroutine dtrco(t,ldt,n,rcond,z,job)
-      integer ldt,n,job
-      double precision t(ldt,*),z(*)
-      double precision rcond
-c
-c     dtrco estimates the condition of a double precision triangular
-c     matrix.
-c
-c     on entry
-c
-c        t       double precision(ldt,n)
-c                t contains the triangular matrix. the zero
-c                elements of the matrix are not referenced, and
-c                the corresponding elements of the array can be
-c                used to store other information.
-c
-c        ldt     integer
-c                ldt is the leading dimension of the array t.
-c
-c        n       integer
-c                n is the order of the system.
-c
-c        job     integer
-c                = 0         t  is lower triangular.
-c                = nonzero   t  is upper triangular.
-c
-c     on return
-c
-c        rcond   double precision
-c                an estimate of the reciprocal condition of  t .
-c                for the system  t*x = b , relative perturbations
-c                in  t  and  b  of size  epsilon  may cause
-c                relative perturbations in  x  of size  epsilon/rcond .
-c                if  rcond  is so small that the logical expression
-c                           1.0 + rcond .eq. 1.0
-c                is true, then  t  may be singular to working
-c                precision.  in particular,  rcond  is zero  if
-c                exact singularity is detected or the estimate
-c                underflows.
-c
-c        z       double precision(n)
-c                a work vector whose contents are usually unimportant.
-c                if  t  is close to a singular matrix, then  z  is
-c                an approximate null vector in the sense that
-c                norm(a*z) = rcond*norm(a)*norm(z) .
-c
-c     linpack. this version dated 08/14/78 .
-c     cleve moler, university of new mexico, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas daxpy,dscal,dasum
-c     fortran dabs,dmax1,dsign
-c
-c     internal variables
-c
-      double precision w,wk,wkm,ek
-      double precision tnorm,ynorm,s,sm,dasum
-      integer i1,j,j1,j2,k,kk,l
-      logical lower
-c
-      lower = job .eq. 0
-c
-c     compute 1-norm of t
-c
-      tnorm = 0.0d0
-      do 10 j = 1, n
-         l = j
-         if (lower) l = n + 1 - j
-         i1 = 1
-         if (lower) i1 = j
-         tnorm = dmax1(tnorm,dasum(l,t(i1,j),1))
-   10 continue
-c
-c     rcond = 1/(norm(t)*(estimate of norm(inverse(t)))) .
-c     estimate = norm(z)/norm(y) where  t*z = y  and  trans(t)*y = e .
-c     trans(t)  is the transpose of t .
-c     the components of  e  are chosen to cause maximum local
-c     growth in the elements of y .
-c     the vectors are frequently rescaled to avoid overflow.
-c
-c     solve trans(t)*y = e
-c
-      ek = 1.0d0
-      do 20 j = 1, n
-         z(j) = 0.0d0
-   20 continue
-      do 100 kk = 1, n
-         k = kk
-         if (lower) k = n + 1 - kk
-         if (z(k) .ne. 0.0d0) ek = dsign(ek,-z(k))
-         if (dabs(ek-z(k)) .le. dabs(t(k,k))) go to 30
-            s = dabs(t(k,k))/dabs(ek-z(k))
-            call dscal(n,s,z,1)
-            ek = s*ek
-   30    continue
-         wk = ek - z(k)
-         wkm = -ek - z(k)
-         s = dabs(wk)
-         sm = dabs(wkm)
-         if (t(k,k) .eq. 0.0d0) go to 40
-            wk = wk/t(k,k)
-            wkm = wkm/t(k,k)
-         go to 50
-   40    continue
-            wk = 1.0d0
-            wkm = 1.0d0
-   50    continue
-         if (kk .eq. n) go to 90
-            j1 = k + 1
-            if (lower) j1 = 1
-            j2 = n
-            if (lower) j2 = k - 1
-            do 60 j = j1, j2
-               sm = sm + dabs(z(j)+wkm*t(k,j))
-               z(j) = z(j) + wk*t(k,j)
-               s = s + dabs(z(j))
-   60       continue
-            if (s .ge. sm) go to 80
-               w = wkm - wk
-               wk = wkm
-               do 70 j = j1, j2
-                  z(j) = z(j) + w*t(k,j)
-   70          continue
-   80       continue
-   90    continue
-         z(k) = wk
-  100 continue
-      s = 1.0d0/dasum(n,z,1)
-      call dscal(n,s,z,1)
-c
-      ynorm = 1.0d0
-c
-c     solve t*z = y
-c
-      do 130 kk = 1, n
-         k = n + 1 - kk
-         if (lower) k = kk
-         if (dabs(z(k)) .le. dabs(t(k,k))) go to 110
-            s = dabs(t(k,k))/dabs(z(k))
-            call dscal(n,s,z,1)
-            ynorm = s*ynorm
-  110    continue
-         if (t(k,k) .ne. 0.0d0) z(k) = z(k)/t(k,k)
-         if (t(k,k) .eq. 0.0d0) z(k) = 1.0d0
-         i1 = 1
-         if (lower) i1 = k + 1
-         if (kk .ge. n) go to 120
-            w = -z(k)
-            call daxpy(n-kk,w,t(i1,k),1,z(i1),1)
-  120    continue
-  130 continue
-c     make znorm = 1.0
-      s = 1.0d0/dasum(n,z,1)
-      call dscal(n,s,z,1)
-      ynorm = s*ynorm
-c
-      if (tnorm .ne. 0.0d0) rcond = ynorm/tnorm
-      if (tnorm .eq. 0.0d0) rcond = 0.0d0
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/dtrsl.f b/com.oracle.truffle.r.native/builtinlibs/src/dtrsl.f
deleted file mode 100644
index b656627dfd5640eceb310ac6d8bffc1a209cdfac..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/builtinlibs/src/dtrsl.f
+++ /dev/null
@@ -1,141 +0,0 @@
-c Triangular Solve  dtrsl()
-c ----------------
-c     solves systems of the form
-c
-c                   t * x = b
-c     or
-c                   trans(t) * x = b
-c
-c     where t is a triangular matrix of order n. here trans(t)
-c     denotes the transpose of the matrix t.
-c
-c     on entry
-c
-c         t         double precision(ldt,n)
-c                   t contains the matrix of the system. the zero
-c                   elements of the matrix are not referenced, and
-c                   the corresponding elements of the array can be
-c                   used to store other information.
-c
-c         ldt       integer
-c                   ldt is the leading dimension of the array t.
-c
-c         n         integer
-c                   n is the order of the system.
-c
-c         b         double precision(n).
-c                   b contains the right hand side of the system.
-c
-c         job       integer
-c                   job specifies what kind of system is to be solved.
-c                   if job is
-c
-c                        00   solve t*x=b, t lower triangular,
-c                        01   solve t*x=b, t upper triangular,
-c                        10   solve trans(t)*x=b, t lower triangular,
-c                        11   solve trans(t)*x=b, t upper triangular.
-c
-c     on return
-c
-c         b         b contains the solution, if info .eq. 0.
-c                   otherwise b is unaltered.
-c
-c         info      integer
-c                   info contains zero if the system is nonsingular.
-c                   otherwise info contains the index of
-c                   the first zero diagonal element of t.
-c
-c     linpack. this version dated 08/14/78 .
-c     g. w. stewart, university of maryland, argonne national lab.
-c
-c     subroutines and functions
-c
-c     blas:     daxpy,ddot
-c     fortran   mod
-c
-      subroutine dtrsl(t,ldt,n,b,job,info)
-      integer ldt,n,job,info
-      double precision t(ldt,*),b(*)
-c
-c     internal variables
-c
-      double precision ddot,temp
-      integer case,j,jj
-c
-c     begin block permitting ...exits to 150
-c
-c        check for zero diagonal elements.
-c
-      do 10 info = 1, n
-         if (t(info,info) .eq. 0.0d0) go to 150
-c     ......exit
- 10   continue
-      info = 0
-c
-c     determine the task and go to it.
-c
-      case = 1
-      if (mod(job,10) .ne. 0) case = 2
-      if (mod(job,100)/10 .ne. 0) case = case + 2
-      go to (20,50,80,110), case
-c
-C Case 1 (job = 00):
-c        solve t*x=b for t lower triangular
-c
- 20   continue
-      b(1) = b(1)/t(1,1)
-      if (n .ge. 2) then
-      do 30 j = 2, n
-         temp = -b(j-1)
-         call daxpy(n-j+1,temp,t(j,j-1),1,b(j),1)
-         b(j) = b(j)/t(j,j)
- 30   continue
-      endif
-      go to 140
-c     
-C Case 2 (job = 01):
-c        solve t*x=b for t upper triangular.
-c
- 50   continue
-      b(n) = b(n)/t(n,n)
-      if (n .ge. 2) then
-         do 60 jj = 2, n
-            j = n - jj + 1
-            temp = -b(j+1)
-            call daxpy(j,temp,t(1,j+1),1,b(1),1)
-            b(j) = b(j)/t(j,j)
- 60      continue
-      endif
-      go to 140
-c     
-C Case 3 (job = 10):
-c        solve trans(t)*x=b for t lower triangular.
-c
- 80   continue
-      b(n) = b(n)/t(n,n)
-      if (n .ge. 2) then
-         do 90 jj = 2, n
-            j = n - jj + 1
-            b(j) = b(j) - ddot(jj-1,t(j+1,j),1,b(j+1),1)
-            b(j) = b(j)/t(j,j)
- 90      continue
-      endif
-      go to 140
-c     
-C Case 4 (job = 11):
-c        solve trans(t)*x=b for t upper triangular.
-c
- 110  continue
-      b(1) = b(1)/t(1,1)
-      if (n .ge. 2) then
-         do 120 j = 2, n
-            b(j) = b(j) - ddot(j-1,t(1,j),1,b(1),1)
-            b(j) = b(j)/t(j,j)
- 120     continue
-      endif
-C
- 140  continue
-c     EXIT:
- 150  continue
-      return
-      end
diff --git a/com.oracle.truffle.r.native/builtinlibs/src/fft.c b/com.oracle.truffle.r.native/builtinlibs/src/fft.c
index 5837f86b35255518fb6a4cbfbc8835f64f86c568..194aab1ca8a05d8e5e5c9a259848b0556c4ae713 100644
--- a/com.oracle.truffle.r.native/builtinlibs/src/fft.c
+++ b/com.oracle.truffle.r.native/builtinlibs/src/fft.c
@@ -17,6 +17,8 @@
 //#include <config.h>
 //#endif
 
+#include <limits.h> /* for INT_MAX */
+#include <stddef.h> /* for size_t */
 #include <stdlib.h> /* for abs */
 #include <math.h>
 
@@ -121,6 +123,8 @@
  * nfac[15] (array) is working storage for factoring n.	 the smallest
  *	number exceeding the 15 locations provided is 12,754,584.
  *
+ * Update in R 3.1.0: nfac[20], increased array size. It is now possible to
+ * factor any positive int n, up to 2^31 - 1.
  */
 
 static void fftmx(double *a, double *b, int ntot, int n, int nspan, int isn,
@@ -727,15 +731,15 @@ L570:
 
 static int old_n = 0;
 
-static int nfac[15];
+static int nfac[20];
 static int m_fac;
 static int kt;
 static int maxf;
 static int maxp;
 
-/* At the end of factorization,	 
+/* At the end of factorization,
  *	nfac[]	contains the factors,
- *	m_fac	contains the number of factors and 
+ *	m_fac	contains the number of factors and
  *	kt	contains the number of square factors  */
 
 /* non-API, but used by package RandomFields */
@@ -754,7 +758,7 @@ void fft_factor(int *nptr, int *pmaxf, int *pmaxp)
  *  If *pmaxp == 1  There we more than 15 factors to ntot.  */
 
     int n = *nptr;
-    int j, jj, k;
+    int j, jj, k, sqrtk, kchanged;
 
 	/* check series length */
 
@@ -781,10 +785,18 @@ void fft_factor(int *nptr, int *pmaxf, int *pmaxp)
     }
 
     /* extract 3^2, 5^2, ... */
-    for(j = 3; (jj= j*j) <= k; j += 2) {
+    kchanged = 0;
+    sqrtk = (int)sqrt(k);
+    for(j = 3; j <= sqrtk; j += 2) {
+	jj = j * j;
 	while(k % jj == 0) {
 	    nfac[m_fac++] = j;
 	    k /= jj;
+	    kchanged = 1;
+	}
+	if (kchanged) {
+	    kchanged = 0;
+	    sqrtk = (int)sqrt(k);
 	}
     }
 
@@ -809,6 +821,8 @@ void fft_factor(int *nptr, int *pmaxf, int *pmaxp)
 		nfac[m_fac++] = j;
 		k /= j;
 	    }
+	    if (j > INT_MAX - 2)
+		break;
 	    j = ((j+1)/2)*2 + 1;
 	}
 	while(j <= k);
@@ -816,7 +830,7 @@ void fft_factor(int *nptr, int *pmaxf, int *pmaxp)
 
     if (m_fac <= kt+1)
 	maxp = m_fac+kt+1;
-    if (m_fac+kt > 15) {		/* error - too many factors */
+    if (m_fac+kt > 20) {		/* error - too many factors */
 	old_n = 0; *pmaxf = 0; *pmaxp = 0;
 	return;
     }
@@ -866,7 +880,7 @@ Rboolean fft_work(double *a, int *nsegptr, int *nptr, int *nspnptr, int *isnptr,
     ntot = nspan * nseg;
 
     fftmx(a, b, ntot, nf, nspan, isn, m_fac, kt,
-	  &work[0], &work[maxf], &work[2*maxf], &work[3*maxf],
+    		  &work[0], &work[maxf], &work[2*(size_t)maxf], &work[3*(size_t)maxf],
 	  iwork, nfac);
 
     return TRUE;
diff --git a/com.oracle.truffle.r.native/fficall/jni/Makefile b/com.oracle.truffle.r.native/fficall/jni/Makefile
index 398464979426c0979c2f40d861a4648e00be43f0..decaee24ccafd8c0beb85d57996c6fcdef4364b4 100644
--- a/com.oracle.truffle.r.native/fficall/jni/Makefile
+++ b/com.oracle.truffle.r.native/fficall/jni/Makefile
@@ -34,10 +34,10 @@ SRC = src
 C_SOURCES := $(wildcard $(SRC)/*.c)
 C_LIBNAME := librfficall.$(SHARED_EXT)
 C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
-C_LIB := $(TOPDIR)/builtinlibs/$(OBJ)/$(OS_DIR)/$(C_LIBNAME)
+C_LIB := $(TOPDIR)/builtinlibs/$(OBJ)/$(C_LIBNAME)
 
 JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(OS_DIR)
-FFI_INCLUDES = -I$(TOPDIR)/include/jni -I$(TOPDIR)/include/jni/R_ext
+FFI_INCLUDES = -I$(TOPDIR)/include/jni/include -I$(TOPDIR)/include/jni/include/R_ext
 
 INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 
diff --git a/com.oracle.truffle.r.native/gnur/Makefile b/com.oracle.truffle.r.native/gnur/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..40283af702454cee5bbd35dde9765457178e10bc
--- /dev/null
+++ b/com.oracle.truffle.r.native/gnur/Makefile
@@ -0,0 +1,66 @@
+#
+# Copyright (c) 2014, 2015, 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 extracts, configures and builds GnuR for the current platform.
+# FastR does not, obviously, need all of GnuR to be built; only those pieces
+# that it shares, but is simpler and safer to just build all of it. The relevant 
+# pieces are then copied to other FastR directories
+
+include ../platform.mk
+
+.PHONY: all clean config build copy
+
+TARGET_DIR := ../builtinlibs/lib
+BLAS_TARGET := $(TARGET_DIR)/libRblas.$(SHARED_EXT)
+LAPACK_TARGET := $(TARGET_DIR)/libRlapack.$(SHARED_EXT)
+export PCRE_TARGET := $(TARGET_DIR)/libpcre.$(SHARED_EXT)
+
+all: Makefile $(GNUR_DIR) config build copy
+
+$(GNUR_DIR): 
+	tar xf $(TOPDIR)/../lib/R-$(R_VERSION).tar.gz
+	
+config: $(GNUR_DIR)/Makefile
+
+$(GNUR_DIR)/Makefile: 
+	(cd $(GNUR_DIR); ./configure --with-x=no --without-recommended-packages >& /dev/null)
+
+build: $(GNUR_DIR)/bin/R
+
+$(GNUR_DIR)/bin/R:
+	(cd $(GNUR_DIR); make >& make.log)
+
+copy: $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET)
+
+$(BLAS_TARGET): $(GNUR_DIR)/lib/libRblas.$(SHARED_EXT)
+	cp $(GNUR_DIR)/lib/libRblas.$(SHARED_EXT) $(BLAS_TARGET)
+
+$(LAPACK_TARGET): $(GNUR_DIR)/lib/libRlapack.$(SHARED_EXT)
+	cp $(GNUR_DIR)/lib/libRlapack.$(SHARED_EXT) $(LAPACK_TARGET)
+
+$(PCRE_TARGET):
+	$(MAKE) -f Makefile.pcre
+
+clean:
+	rm -rf $(GNUR_DIR)
+	rm $(TARGET_DIR)/*
diff --git a/com.oracle.truffle.r.native/gnur/Makefile.pcre b/com.oracle.truffle.r.native/gnur/Makefile.pcre
new file mode 100644
index 0000000000000000000000000000000000000000..e539c755ac9d21744771c928e8be44c58d991517
--- /dev/null
+++ b/com.oracle.truffle.r.native/gnur/Makefile.pcre
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2015, 2015, 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 is separate because at the time the parent Makefile is analyzed
+# the pcre object files do not exist
+
+include ../platform.mk
+
+PCRE_OBJS := $(wildcard $(GNUR_DIR)/src/extra/pcre/pcre_*.o)
+
+$(PCRE_TARGET): $(PCRE_OBJS)
+	$(CC) $(LDFLAGS) -o $(PCRE_TARGET) $(PCRE_OBJS)
+		
diff --git a/com.oracle.truffle.r.native/include/Makefile b/com.oracle.truffle.r.native/include/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..adb3cf69ca25fb11634e3a0ea269cce857b93a31
--- /dev/null
+++ b/com.oracle.truffle.r.native/include/Makefile
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2015, 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.
+#
+
+.PHONY: all clean
+
+all:
+	$(MAKE) -C jni
+clean:
+	$(MAKE) -C jni clean
diff --git a/com.oracle.truffle.r.native/include/README b/com.oracle.truffle.r.native/include/README
index b33473309d265d445dadafcb88de473df55e6b9d..86972bd087a49a82162f5e7c053aed9c5fb127e8 100644
--- a/com.oracle.truffle.r.native/include/README
+++ b/com.oracle.truffle.r.native/include/README
@@ -2,4 +2,4 @@ The header files that are included when compiling the code of native packages in
 
 The starting position is that these files are identical to those in GnuR and that the FastR implementation
 differences are entirely encapsulated in the method implementations in the fficall library. It is TBD whether
-this can be completely transparent but,if not, the goalk would be for minimal changes to the standard header files.
+this can be completely transparent but,if not, the goal would be for minimal changes to the standard header files.
diff --git a/com.oracle.truffle.r.native/include/jni/Makefile b/com.oracle.truffle.r.native/include/jni/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..8fc940d8f85c2d694e5b71a576842ca1ef2cabf7
--- /dev/null
+++ b/com.oracle.truffle.r.native/include/jni/Makefile
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2015, 2015, 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.
+#
+
+# links to the standard R header files with some modifications for JNI-based RFFI
+
+.PHONY: all clean
+
+SRC=src
+
+R_EXT_HEADERS := $(wildcard $(GNUR_DIR)/include/R_ext/*.h)
+R_EXT_HEADERS_FILENAMES := $(notdir $(R_EXT_HEADERS))
+R_EXT_HEADERS_LOCAL := $(wildcard $(SRC)/R_ext/*.h)
+R_EXT_HEADERS_TO_LINK := $(filter-out $(notdir $(R_EXT_HEADERS_LOCAL)),$(R_EXT_HEADERS_FILENAMES))
+
+R_HEADERS := $(wildcard $(GNUR_DIR)/include/*.h)
+R_HEADERS_FILENAMES := $(notdir $(R_HEADERS))
+#$(info R_HEADERS_FILENAMES=$(R_HEADERS_FILENAMES))
+R_HEADERS_LOCAL := src/libintl.h src/Rinternals.h
+#$(info R_HEADERS_LOCAL=$(R_HEADERS_LOCAL))
+R_HEADERS_TO_LINK := $(filter-out $(notdir $(R_HEADERS_LOCAL)),$(R_HEADERS_FILENAMES))
+#$(info R_HEADERS_TO_LINK=$(R_HEADERS_TO_LINK))
+
+all: linked
+
+linked:
+	mkdir -p include
+	mkdir -p include/R_ext
+	$(foreach file,$(R_HEADERS_TO_LINK),ln -sf $(GNUR_DIR)/include/$(file) include/$(file);)
+	cp src/libintl.h .
+	sed -f sed_Rinternals src/Rinternals.h > include/Rinternals.h
+	$(foreach file,$(R_EXT_HEADERS_TO_LINK),ln -sf $(GNUR_DIR)/include/R_ext/$(file) include/R_ext/$(file);)
+	cp $(R_EXT_HEADERS_LOCAL) R_ext
+	touch linked
+
+clean:
+	rm -rf include linked
diff --git a/com.oracle.truffle.r.native/include/jni/R.h b/com.oracle.truffle.r.native/include/jni/R.h
deleted file mode 100644
index 499d374cc9423702fc7ae5b1380a8472db19afe7..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2000-2013 The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-#ifndef R_R_H
-#define R_R_H
-
-#ifndef USING_R
-# define USING_R
-#endif
-
-#ifndef NO_C_HEADERS
-#include <stdlib.h>
-#include <stdio.h>  /* Used by several packages, remove in due course */
-#include <limits.h> /* for INT_MAX */
-#include <math.h>
-# if defined(__sun)
-# undef DO
-# undef DS
-# undef SO
-# undef SS
-# endif
-#endif
-
-#include <Rconfig.h>
-#include <R_ext/Arith.h>      /* R_FINITE, ISNAN, ... */
-#include <R_ext/Boolean.h>    /* Rboolean type */
-#include <R_ext/Complex.h>    /* Rcomplex type */
-#include <R_ext/Constants.h>  /* PI, DOUBLE_EPS, etc */
-#include <R_ext/Error.h>      /* error and warning */
-#include <R_ext/Memory.h>     /* R_alloc and S_alloc */
-#include <R_ext/Print.h>      /* Rprintf etc */
-#include <R_ext/Random.h>     /* RNG interface */
-#include <R_ext/Utils.h>      /* sort routines et al */
-#include <R_ext/RS.h>
-/* for PROBLEM ... Calloc, Realloc, Free, Memcpy, F77_xxxx */
-
-
-typedef double Sfloat;
-typedef int Sint;
-#define SINT_MAX INT_MAX
-#define SINT_MIN INT_MIN
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void R_FlushConsole(void);
-/* always declared, but only usable under Win32 and Aqua */
-void R_ProcessEvents(void);
-#ifdef Win32
-void R_WaitEvent(void);
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !R_R_H */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Applic.h b/com.oracle.truffle.r.native/include/jni/R_ext/Applic.h
deleted file mode 100644
index 71e342d6269019214971b4b497f41235d098a099..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Applic.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2013   The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- *
- *
- * Application Routines, typically implemented in  ../appl/
- * ----------------------------------------------  ========
- */
-
-/* This header file contains routines which are in the R API and ones which
-   are not.
-
-   Those which are not can be used only at the user's risk and may change
-   or disappear in a future release of R.
-*/
-
-
-#ifndef R_APPLIC_H_
-#define R_APPLIC_H_
-
-#include <R_ext/Boolean.h>
-#include <R_ext/RS.h>		/* F77_... */
-#include <R_ext/BLAS.h>
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* Entry points in the R API */
-
-/* appl/integrate.c */
-typedef void integr_fn(double *x, int n, void *ex);
-/* vectorizing function   f(x[1:n], ...) -> x[]  {overwriting x[]}. */
-
-void Rdqags(integr_fn f, void *ex, double *a, double *b,
-	    double *epsabs, double *epsrel,
-	    double *result, double *abserr, int *neval, int *ier,
-	    int *limit, int *lenw, int *last, int *iwork, double *work);
-
-void Rdqagi(integr_fn f, void *ex, double *bound, int *inf,
-	    double *epsabs, double *epsrel,
-	    double *result, double *abserr, int *neval, int *ier,
-	    int *limit, int *lenw, int *last,
-	    int *iwork, double *work);
-
-/* main/optim.c */
-typedef double optimfn(int, double *, void *);
-typedef void optimgr(int, double *, double *, void *);
-
-void vmmin(int n, double *b, double *Fmin,
-	   optimfn fn, optimgr gr, int maxit, int trace,
-	   int *mask, double abstol, double reltol, int nREPORT,
-	   void *ex, int *fncount, int *grcount, int *fail);
-void nmmin(int n, double *Bvec, double *X, double *Fmin, optimfn fn,
-	   int *fail, double abstol, double intol, void *ex,
-	   double alpha, double bet, double gamm, int trace,
-	   int *fncount, int maxit);
-void cgmin(int n, double *Bvec, double *X, double *Fmin,
-	   optimfn fn, optimgr gr,
-	   int *fail, double abstol, double intol, void *ex,
-	   int type, int trace, int *fncount, int *grcount, int maxit);
-void lbfgsb(int n, int m, double *x, double *l, double *u, int *nbd,
-	    double *Fmin, optimfn fn, optimgr gr, int *fail, void *ex,
-	    double factr, double pgtol, int *fncount, int *grcount,
-	    int maxit, char *msg, int trace, int nREPORT);
-void samin(int n, double *pb, double *yb, optimfn fn, int maxit,
-	   int tmax, double ti, int trace, void *ex);
-
-/* appl/interv.c: Also in Utils.h, used in package eco */
-int findInterval(double *xt, int n, double x,
-		 Rboolean rightmost_closed,  Rboolean all_inside, int ilo,
-		 int *mflag);
-
-
-/* ------------------ Entry points NOT in the R API --------------- */
-
-/* The following are registered for use in .C/.Fortran */
-
-/* appl/dqrutl.f: interfaces to dqrsl */
-void F77_NAME(dqrqty)(double *x, int *n, int *k, double *qraux,
-		      double *y, int *ny, double *qty);
-void F77_NAME(dqrqy)(double *x, int *n, int *k, double *qraux,
-		     double *y, int *ny, double *qy);
-void F77_NAME(dqrcf)(double *x, int *n, int *k, double *qraux,
-		     double *y, int *ny, double *b, int *info);
-void F77_NAME(dqrrsd)(double *x, int *n, int *k, double *qraux,
-		     double *y, int *ny, double *rsd);
-void F77_NAME(dqrxb)(double *x, int *n, int *k, double *qraux,
-		     double *y, int *ny, double *xb);
-
-/* end of registered */
-
-/* hidden, for use in R.bin/R.dll/libR.so */
-
-/* appl/pretty.c: for use in engine.c and util.c */
-double R_pretty(double *lo, double *up, int *ndiv, int min_n,
-		double shrink_sml, double high_u_fact[],
-		int eps_correction, int return_bounds);
-
-
-/* For use in package stats */
-
-/* appl/uncmin.c : */
-
-/* type of pointer to the target and gradient functions */
-typedef void (*fcn_p)(int, double *, double *, void *);
-
-/* type of pointer to the hessian functions */
-typedef void (*d2fcn_p)(int, int, double *, double *, void *);
-
-void fdhess(int n, double *x, double fval, fcn_p fun, void *state,
-	    double *h, int nfd, double *step, double *f, int ndigit,
-	    double *typx);
-
-/* Also used in packages nlme, pcaPP */
-void optif9(int nr, int n, double *x,
-	    fcn_p fcn, fcn_p d1fcn, d2fcn_p d2fcn,
-	    void *state, double *typsiz, double fscale, int method,
-	    int iexp, int *msg, int ndigit, int itnlim, int iagflg,
-	    int iahflg, double dlt, double gradtl, double stepmx,
-	    double steptl, double *xpls, double *fpls, double *gpls,
-	    int *itrmcd, double *a, double *wrk, int *itncnt);
-
-/* find qr decomposition, dqrdc2() is basis of R's qr(),
-   also used by nlme and many other packages. */
-void F77_NAME(dqrdc2)(double *x, int *ldx, int *n, int *p,
-		      double *tol, int *rank,
-		      double *qraux, int *pivot, double *work);
-void F77_NAME(dqrls)(double *x, int *n, int *p, double *y, int *ny,
-		     double *tol, double *b, double *rsd,
-		     double *qty, int *k,
-		     int *jpvt, double *qraux, double *work);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_APPLIC_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Arith.h b/com.oracle.truffle.r.native/include/jni/R_ext/Arith.h
deleted file mode 100644
index 1d4f2a72b48d33b75b85403483810a51dce8cd6a..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Arith.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
- *  Copyright (C) 1998--2007  The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_ARITH_H_
-#define R_ARITH_H_
-
-/* Only for use where config.h has not already been included */
-#if defined(HAVE_GLIBC2) && !defined(_BSD_SOURCE)
-/* ensure that finite and isnan are declared */
-# define _BSD_SOURCE 1
-#endif
-
-#include <R_ext/libextern.h>
-#ifdef  __cplusplus
-extern "C" {
-#elif !defined(NO_C_HEADERS)
-/* needed for isnan and isfinite, neither of which are used under C++ */
-# include <math.h>
-#endif
-
-/* implementation of these : ../../main/arithmetic.c */
-LibExtern double R_NaN;		/* IEEE NaN */
-LibExtern double R_PosInf;	/* IEEE Inf */
-LibExtern double R_NegInf;	/* IEEE -Inf */
-LibExtern double R_NaReal;	/* NA_REAL: IEEE */
-LibExtern int	 R_NaInt;	/* NA_INTEGER:= INT_MIN currently */
-#ifdef __MAIN__
-#undef extern
-#undef LibExtern
-#endif
-
-#define NA_LOGICAL	R_NaInt
-#define NA_INTEGER	R_NaInt
-/* #define NA_FACTOR	R_NaInt  unused */
-#define NA_REAL		R_NaReal
-/* NA_STRING is a SEXP, so defined in Rinternals.h */
-
-int R_IsNA(double);		/* True for R's NA only */
-int R_IsNaN(double);		/* True for special NaN, *not* for NA */
-int R_finite(double);		/* True if none of NA, NaN, +/-Inf */
-#define ISNA(x)	       R_IsNA(x)
-
-/* ISNAN(): True for *both* NA and NaN.
-   NOTE: some systems do not return 1 for TRUE.
-   Also note that C++ math headers specifically undefine
-   isnan if it is a macro (it is on OS X and in C99),
-   hence the workaround.  This code also appears in Rmath.h
-*/
-#ifdef __cplusplus
-  int R_isnancpp(double); /* in arithmetic.c */
-#  define ISNAN(x)     R_isnancpp(x)
-#else
-#  define ISNAN(x)     (isnan(x)!=0)
-#endif
-
-/* The following is only defined inside R */
-#ifdef HAVE_WORKING_ISFINITE
-/* isfinite is defined in <math.h> according to C99 */
-# define R_FINITE(x)    isfinite(x)
-#else
-# define R_FINITE(x)    R_finite(x)
-#endif
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_ARITH_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/BLAS.h b/com.oracle.truffle.r.native/include/jni/R_ext/BLAS.h
deleted file mode 100644
index fb6ae53c5efdc8be693110370469292c509dca61..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/BLAS.h
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2003-12 The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/*
-   C declarations of BLAS Fortran subroutines always available in R.
-
-   Part of the API.
-
-   R packages that use these should have PKG_LIBS in src/Makevars include
-   $(BLAS_LIBS) $(FLIBS)
- */
-
-/* Part of the API */
-
-#ifndef R_BLAS_H
-#define R_BLAS_H
-
-#include <R_ext/RS.h>		/* for F77_... */
-#include <R_ext/Complex.h>	/* for Rcomplex */
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-// never defined in R itself.
-#ifndef BLAS_extern
-#define BLAS_extern extern
-#endif
-
-/* Double Precision Level 1 BLAS */
-
-BLAS_extern double /* DASUM - sum of absolute values of a one-dimensional array */
-F77_NAME(dasum)(const int *n, const double *dx, const int *incx);
-BLAS_extern void   /* DAXPY - replace y by alpha*x + y */
-F77_NAME(daxpy)(const int *n, const double *alpha,
-		const double *dx, const int *incx,
-		double *dy, const int *incy);
-BLAS_extern void   /* DCOPY - copy x to y */
-F77_NAME(dcopy)(const int *n, const double *dx, const int *incx,
-		double *dy, const int *incy);
-BLAS_extern double /* DDOT - inner product of x and y */
-F77_NAME(ddot)(const int *n, const double *dx, const int *incx,
-	       const double *dy, const int *incy);
-BLAS_extern double /* DNRM2 - 2-norm of a vector */
-F77_NAME(dnrm2)(const int *n, const double *dx, const int *incx);
-BLAS_extern void   /* DROT - apply a Given's rotation */
-F77_NAME(drot)(const int *n, double *dx, const int *incx,
-	       double *dy, const int *incy, const double *c, const double *s);
-BLAS_extern void   /* DROTG - generate a Given's rotation */
-F77_NAME(drotg)(const double *a, const double *b, double *c, double *s);
-BLAS_extern void   /* DROTM - apply a modified Given's rotation */
-F77_NAME(drotm)(const int *n, double *dx, const int *incx,
-		double *dy, const int *incy, const double *dparam);
-BLAS_extern void   /* DROTMG - generate a modified Given's rotation */
-F77_NAME(drotmg)(const double *dd1, const double *dd2, const double *dx1,
-		 const double *dy1, double *param);
-BLAS_extern void   /* DSCAL - scale a one-dimensional array */
-F77_NAME(dscal)(const int *n, const double *alpha, double *dx, const int *incx);
-BLAS_extern void   /* DSWAP - interchange one-dimensional arrays */
-F77_NAME(dswap)(const int *n, double *dx, const int *incx,
-		double *dy, const int *incy);
-BLAS_extern int    /* IDAMAX - return the index of the element with max abs value */
-F77_NAME(idamax)(const int *n, const double *dx, const int *incx);
-
-/* Double Precision Level 2 BLAS */
-
-/* DGBMV - perform one of the matrix-vector operations */
-/* y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y, */
-BLAS_extern void
-F77_NAME(dgbmv)(const char *trans, const int *m, const int *n,
-		const int *kl,const int *ku,
-		const double *alpha, const double *a, const int *lda,
-		const double *x, const int *incx,
-		const double *beta, double *y, const int *incy);
-/* DGEMV - perform one of the matrix-vector operations */
-/* y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y,  */
-BLAS_extern void
-F77_NAME(dgemv)(const char *trans, const int *m, const int *n,
-		const double *alpha, const double *a, const int *lda,
-		const double *x, const int *incx, const double *beta,
-		double *y, const int *incy);
-/* DSBMV - perform the matrix-vector operation */
-/* y := alpha*A*x + beta*y, */
-BLAS_extern void
-F77_NAME(dsbmv)(const char *uplo, const int *n, const int *k,
-		const double *alpha, const double *a, const int *lda,
-		const double *x, const int *incx,
-		const double *beta, double *y, const int *incy);
-/* DSPMV - perform the matrix-vector operation */
-/* y := alpha*A*x + beta*y, */
-BLAS_extern void
-F77_NAME(dspmv)(const char *uplo, const int *n,
-		const double *alpha, const double *ap,
-		const double *x, const int *incx,
-		const double *beta, double *y, const int *incy);
-
-/* DSYMV - perform the matrix-vector operation */
-/*  y := alpha*A*x + beta*y, */
-BLAS_extern void
-F77_NAME(dsymv)(const char *uplo, const int *n, const double *alpha,
-		const double *a, const int *lda,
-		const double *x, const int *incx,
-		const double *beta, double *y, const int *incy);
-/* DTBMV - perform one of the matrix-vector operations */
-/* x := A*x, or x := A'*x, */
-BLAS_extern void
-F77_NAME(dtbmv)(const char *uplo, const char *trans,
-		const char *diag, const int *n, const int *k,
-		const double *a, const int *lda,
-		double *x, const int *incx);
-/* DTPMV - perform one of the matrix-vector operations */
-/* x := A*x, or x := A'*x, */
-BLAS_extern void
-F77_NAME(dtpmv)(const char *uplo, const char *trans, const char *diag,
-		const int *n, const double *ap,
-		double *x, const int *incx);
-/* DTRMV - perform one of the matrix-vector operations  */
-/* x := A*x, or x := A'*x, */
-BLAS_extern void
-F77_NAME(dtrmv)(const char *uplo, const char *trans, const char *diag,
-		const int *n, const double *a, const int *lda,
-		double *x, const int *incx);
-/* DTBSV - solve one of the systems of equations */
-/* A*x = b, or A'*x = b, */
-BLAS_extern void
-F77_NAME(dtbsv)(const char *uplo, const char *trans,
-		const char *diag, const int *n, const int *k,
-		const double *a, const int *lda,
-		double *x, const int *incx);
-/* DTPSV - solve one of the systems of equations */
-/* A*x = b, or A'*x = b, */
-BLAS_extern void
-F77_NAME(dtpsv)(const char *uplo, const char *trans,
-		const char *diag, const int *n,
-		const double *ap, double *x, const int *incx);
-/* DTRSV - solve one of the systems of equations */
-/* A*x = b, or A'*x = b, */
-BLAS_extern void
-F77_NAME(dtrsv)(const char *uplo, const char *trans,
-		const char *diag, const int *n,
-		const double *a, const int *lda,
-		double *x, const int *incx);
-/* DGER - perform the rank 1 operation   A := alpha*x*y' + A */
-BLAS_extern void
-F77_NAME(dger)(const int *m, const int *n, const double *alpha,
-	       const double *x, const int *incx,
-	       const double *y, const int *incy,
-	       double *a, const int *lda);
-/* DSYR - perform the symmetric rank 1 operation A := alpha*x*x' + A */
-BLAS_extern void
-F77_NAME(dsyr)(const char *uplo, const int *n, const double *alpha,
-	       const double *x, const int *incx,
-	       double *a, const int *lda);
-/* DSPR - perform the symmetric rank 1 operation A := alpha*x*x' + A */
-BLAS_extern void
-F77_NAME(dspr)(const char *uplo, const int *n, const double *alpha,
-	       const double *x, const int *incx, double *ap);
-/* DSYR2 - perform the symmetric rank 2 operation */
-/* A := alpha*x*y' + alpha*y*x' + A, */
-BLAS_extern void
-F77_NAME(dsyr2)(const char *uplo, const int *n, const double *alpha,
-		const double *x, const int *incx,
-		const double *y, const int *incy,
-		double *a, const int *lda);
-/* DSPR2 - perform the symmetric rank 2 operation */
-/* A := alpha*x*y' + alpha*y*x' + A,  */
-BLAS_extern void
-F77_NAME(dspr2)(const char *uplo, const int *n, const double *alpha,
-		const double *x, const int *incx,
-		const double *y, const int *incy, double *ap);
-
-/* Double Precision Level 3 BLAS */
-
-/* DGEMM - perform one of the matrix-matrix operations    */
-/* C := alpha*op( A )*op( B ) + beta*C */
-BLAS_extern void
-F77_NAME(dgemm)(const char *transa, const char *transb, const int *m,
-		const int *n, const int *k, const double *alpha,
-		const double *a, const int *lda,
-		const double *b, const int *ldb,
-		const double *beta, double *c, const int *ldc);
-/* DTRSM - solve one of the matrix equations  */
-/* op(A)*X = alpha*B, or  X*op(A) = alpha*B  */
-BLAS_extern void
-F77_NAME(dtrsm)(const char *side, const char *uplo,
-		const char *transa, const char *diag,
-		const int *m, const int *n, const double *alpha,
-		const double *a, const int *lda,
-		double *b, const int *ldb);
-/* DTRMM - perform one of the matrix-matrix operations */
-/* B := alpha*op( A )*B, or B := alpha*B*op( A ) */
-BLAS_extern void
-F77_NAME(dtrmm)(const char *side, const char *uplo, const char *transa,
-		const char *diag, const int *m, const int *n,
-		const double *alpha, const double *a, const int *lda,
-		double *b, const int *ldb);
-/* DSYMM - perform one of the matrix-matrix operations   */
-/*  C := alpha*A*B + beta*C, */
-BLAS_extern void
-F77_NAME(dsymm)(const char *side, const char *uplo, const int *m,
-		const int *n, const double *alpha,
-		const double *a, const int *lda,
-		const double *b, const int *ldb,
-		const double *beta, double *c, const int *ldc);
-/* DSYRK - perform one of the symmetric rank k operations */
-/* C := alpha*A*A' + beta*C or C := alpha*A'*A + beta*C */
-BLAS_extern void
-F77_NAME(dsyrk)(const char *uplo, const char *trans,
-		const int *n, const int *k,
-		const double *alpha, const double *a, const int *lda,
-		const double *beta, double *c, const int *ldc);
-/* DSYR2K - perform one of the symmetric rank 2k operations */
-/* C := alpha*A*B' + alpha*B*A' + beta*C or */
-/* C := alpha*A'*B + alpha*B'*A + beta*C */
-BLAS_extern void
-F77_NAME(dsyr2k)(const char *uplo, const char *trans,
-		 const int *n, const int *k,
-		 const double *alpha, const double *a, const int *lda,
-		 const double *b, const int *ldb,
-		 const double *beta, double *c, const int *ldc);
-/*
-  LSAME is a LAPACK support routine, not part of BLAS
-*/
-
-/* Double complex BLAS routines added for 2.3.0 */
-/* #ifdef HAVE_FORTRAN_DOUBLE_COMPLEX */
-    BLAS_extern double
-    F77_NAME(dcabs1)(double *z);
-    BLAS_extern double
-    F77_NAME(dzasum)(int *n, Rcomplex *zx, int *incx);
-    BLAS_extern double
-    F77_NAME(dznrm2)(int *n, Rcomplex *x, int *incx);
-    BLAS_extern int
-    F77_NAME(izamax)(int *n, Rcomplex *zx, int *incx);
-    BLAS_extern void
-    F77_NAME(zaxpy)(int *n, Rcomplex *za, Rcomplex *zx,
-		    int *incx, Rcomplex *zy, int *incy);
-    BLAS_extern void
-    F77_NAME(zcopy)(int *n, Rcomplex *zx, int *incx,
-		    Rcomplex *zy, int *incy);
-
-    /* WARNING!  The next two return a value that may not be
-       compatible between C and Fortran, and even if it is, this might
-       not be the right translation to C.  Only use after
-       configure-testing with your compilers.
-     */
-    BLAS_extern Rcomplex
-    F77_NAME(zdotc)(int *n,
-		    Rcomplex *zx, int *incx, Rcomplex *zy, int *incy);
-    BLAS_extern Rcomplex
-    F77_NAME(zdotu)(int *n,
-		    Rcomplex *zx, int *incx, Rcomplex *zy, int *incy);
-
-    BLAS_extern void
-    F77_NAME(zdrot)(int *n, Rcomplex *zx, int *incx, Rcomplex *zy,
-		int *incy, double *c, double *s);
-    BLAS_extern void
-    F77_NAME(zdscal)(int *n, double *da, Rcomplex *zx, int *incx);
-    BLAS_extern void
-    F77_NAME(zgbmv)(char *trans, int *m, int *n, int *kl,
-		    int *ku, Rcomplex *alpha, Rcomplex *a, int *lda,
-		    Rcomplex *x, int *incx, Rcomplex *beta, Rcomplex *y,
-		    int *incy);
-    BLAS_extern void
-    F77_NAME(zgemm)(const char *transa, const char *transb, const int *m,
-		    const int *n, const int *k, const Rcomplex *alpha,
-		    const Rcomplex *a, const int *lda,
-		    const Rcomplex *b, const int *ldb,
-		    const Rcomplex *beta, Rcomplex *c, const int *ldc);
-    BLAS_extern void
-    F77_NAME(zgemv)(char *trans, int *m, int *n, Rcomplex *alpha,
-		    Rcomplex *a, int *lda, Rcomplex *x, int *incx,
-		    Rcomplex *beta, Rcomplex *y, int * incy);
-    BLAS_extern void
-    F77_NAME(zgerc)(int *m, int *n, Rcomplex *alpha, Rcomplex *x,
-		    int *incx, Rcomplex *y, int *incy, Rcomplex *a, int *lda);
-    BLAS_extern void
-    F77_NAME(zgeru)(int *m, int *n, Rcomplex *alpha, Rcomplex *x,
-		    int *incx, Rcomplex *y, int *incy, Rcomplex *a, int *lda);
-    BLAS_extern void
-    F77_NAME(zhbmv)(char *uplo, int *n, int *k, Rcomplex *alpha,
-		    Rcomplex *a, int *lda, Rcomplex *x, int *incx,
-		    Rcomplex *beta, Rcomplex *y, int *incy);
-    BLAS_extern void
-    F77_NAME(zhemm)(char *side, char *uplo, int *m, int *n,
-		    Rcomplex *alpha, Rcomplex *a, int *lda, Rcomplex *b,
-		    int *ldb, Rcomplex *beta, Rcomplex *c, int *ldc);
-    BLAS_extern void
-    F77_NAME(zhemv)(char *uplo, int *n, Rcomplex *alpha, Rcomplex *a,
-		    int *lda, Rcomplex *x, int *incx, Rcomplex *beta,
-		    Rcomplex *y, int *incy);
-    BLAS_extern void
-    F77_NAME(zher)(char *uplo, int *n, double *alpha, Rcomplex *x,
-		   int *incx, Rcomplex *a, int *lda);
-    BLAS_extern void
-    F77_NAME(zher2)(char *uplo, int *n, Rcomplex *alpha, Rcomplex *x,
-		    int *incx, Rcomplex *y, int *incy, Rcomplex *a, int *lda);
-    BLAS_extern void
-    F77_NAME(zher2k)(char *uplo, char *trans, int *n, int *k,
-		     Rcomplex *alpha, Rcomplex *a, int *lda, Rcomplex *b,
-		     int *ldb, double *beta, Rcomplex *c, int *ldc);
-    BLAS_extern void
-    F77_NAME(zherk)(char *uplo, char *trans, int *n, int *k,
-		    double *alpha, Rcomplex *a, int *lda, double *beta,
-		    Rcomplex *c, int *ldc);
-    BLAS_extern void
-    F77_NAME(zhpmv)(char *uplo, int *n, Rcomplex *alpha, Rcomplex *ap,
-		    Rcomplex *x, int *incx, Rcomplex * beta, Rcomplex *y,
-		    int *incy);
-    BLAS_extern void
-    F77_NAME(zhpr)(char *uplo, int *n, double *alpha,
-		   Rcomplex *x, int *incx, Rcomplex *ap);
-    BLAS_extern void
-    F77_NAME(zhpr2)(char *uplo, int *n, Rcomplex *alpha, Rcomplex *x,
-		    int *incx, Rcomplex *y, int *incy, Rcomplex *ap);
-    BLAS_extern void
-    F77_NAME(zrotg)(Rcomplex *ca, Rcomplex *cb, double *c, Rcomplex *s);
-    BLAS_extern void
-    F77_NAME(zscal)(int *n, Rcomplex *za, Rcomplex *zx, int *incx);
-    BLAS_extern void
-    F77_NAME(zswap)(int *n, Rcomplex *zx, int *incx, Rcomplex *zy, int *incy);
-    BLAS_extern void
-    F77_NAME(zsymm)(char *side, char *uplo, int *m, int *n,
-		    Rcomplex *alpha, Rcomplex *a, int *lda, Rcomplex *b,
-		    int *ldb, Rcomplex *beta, Rcomplex *c, int *ldc);
-    BLAS_extern void
-    F77_NAME(zsyr2k)(char *uplo, char *trans, int *n, int *k,
-		     Rcomplex *alpha, Rcomplex *a, int *lda, Rcomplex *b,
-		     int *ldb, Rcomplex *beta, Rcomplex *c, int *ldc);
-    BLAS_extern void
-    F77_NAME(zsyrk)(char *uplo, char *trans, int *n, int *k,
-		    Rcomplex *alpha, Rcomplex *a, int *lda,
-		    Rcomplex *beta, Rcomplex *c, int *ldc);
-    BLAS_extern void
-    F77_NAME(ztbmv)(char *uplo, char *trans, char *diag, int *n, int *k,
-		    Rcomplex *a, int *lda, Rcomplex *x, int *incx);
-    BLAS_extern void
-    F77_NAME(ztbsv)(char *uplo, char *trans, char *diag, int *n, int *k,
-		    Rcomplex *a, int *lda, Rcomplex *x, int *incx);
-    BLAS_extern void
-    F77_NAME(ztpmv)(char *uplo, char *trans, char *diag, int *n,
-		    Rcomplex *ap, Rcomplex *x, int *incx);
-    BLAS_extern void
-    F77_NAME(ztpsv)(char *uplo, char *trans, char *diag, int *n,
-		    Rcomplex *ap, Rcomplex *x, int *incx);
-    BLAS_extern void
-    F77_NAME(ztrmm)(char *side, char *uplo, char *transa, char *diag,
-		    int *m, int *n, Rcomplex *alpha, Rcomplex *a,
-		    int *lda, Rcomplex *b, int *ldb);
-    BLAS_extern void
-    F77_NAME(ztrmv)(char *uplo, char *trans, char *diag, int *n,
-		    Rcomplex *a, int *lda, Rcomplex *x, int *incx);
-    BLAS_extern void
-    F77_NAME(ztrsm)(char *side, char *uplo, char *transa, char *diag,
-		    int *m, int *n, Rcomplex *alpha, Rcomplex *a,
-		    int *lda, Rcomplex *b, int *ldb);
-    BLAS_extern void
-    F77_NAME(ztrsv)(char *uplo, char *trans, char *diag, int *n,
-		    Rcomplex *a, int *lda, Rcomplex *x, int *incx);
-/* #endif */
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_BLAS_H */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Boolean.h b/com.oracle.truffle.r.native/include/jni/R_ext/Boolean.h
deleted file mode 100644
index 7c4afcf219edca2e7ee3d49c5a47b2bde54b875b..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Boolean.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2000, 2001 The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_EXT_BOOLEAN_H_
-#define R_EXT_BOOLEAN_H_
-
-#undef FALSE
-#undef TRUE
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-typedef enum { FALSE = 0, TRUE /*, MAYBE */ } Rboolean;
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_EXT_BOOLEAN_H_ */
-
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Callbacks.h b/com.oracle.truffle.r.native/include/jni/R_ext/Callbacks.h
deleted file mode 100644
index 19635f8a417a087db045aeb43830ba2df088645e..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Callbacks.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2001-2 The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/*
-   Not part of the API, subject to change at any time.
-*/
-
-#ifndef R_CALLBACKS_H
-#define R_CALLBACKS_H
-
-/**
-  These structures are for C (and R function) top-level task handlers.
-  Such routines are called at the end of every (successful) top-level task
-  in the regular REPL.
- */
-
-#include <Rinternals.h>
-/**
-  The signature of the C routine that a callback must implement.
-  expr - the expression for the top-level task that was evaluated.
-  value - the result of the top-level task, i.e. evaluating expr.
-  succeeded - a logical value indicating whether the task completed propertly.
-  visible - a logical value indicating whether the result was printed to the R ``console''/stdout.
-  data - user-level data passed to the registration routine.
- */
-typedef Rboolean (*R_ToplevelCallback)(SEXP expr, SEXP value, Rboolean succeeded, Rboolean visible, void *);
-
-typedef struct _ToplevelCallback  R_ToplevelCallbackEl;
-/**
- Linked list element for storing the top-level task callbacks.
- */
-struct _ToplevelCallback {
-    R_ToplevelCallback cb; /* the C routine to call. */
-    void *data;            /* the user-level data to pass to the call to cb() */
-    void (*finalizer)(void *data); /* Called when the callback is removed. */
-
-    char *name;  /* a name by which to identify this element. */
-
-    R_ToplevelCallbackEl *next; /* the next element in the linked list. */
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-Rboolean Rf_removeTaskCallbackByIndex(int id);
-Rboolean Rf_removeTaskCallbackByName(const char *name);
-SEXP R_removeTaskCallback(SEXP which);
-R_ToplevelCallbackEl* Rf_addTaskCallback(R_ToplevelCallback cb, void *data, void (*finalizer)(void *), const char *name, int *pos);
-
-
-
-/*
-  The following definitions are for callbacks to R functions and
-  methods related to user-level tables.  This was implemented in a
-  separate package on Omegahat and these declarations allow the package
-  to interface to the internal R code.
-
-  See http://developer.r-project.org/RObjectTables.pdf,
-  http://www.omegahat.org/RObjectTables/
-*/
-
-typedef struct  _R_ObjectTable R_ObjectTable;
-
-/* Do we actually need the exists() since it is never called but R
-   uses get to see if the symbol is bound to anything? */
-typedef Rboolean (*Rdb_exists)(const char * const name, Rboolean *canCache, R_ObjectTable *);
-typedef SEXP     (*Rdb_get)(const char * const name, Rboolean *canCache, R_ObjectTable *);
-typedef int      (*Rdb_remove)(const char * const name, R_ObjectTable *);
-typedef SEXP     (*Rdb_assign)(const char * const name, SEXP value, R_ObjectTable *);
-typedef SEXP     (*Rdb_objects)(R_ObjectTable *);
-typedef Rboolean (*Rdb_canCache)(const char * const name, R_ObjectTable *);
-
-typedef void     (*Rdb_onDetach)(R_ObjectTable *);
-typedef void     (*Rdb_onAttach)(R_ObjectTable *);
-
-struct  _R_ObjectTable{
-  int       type;
-  char    **cachedNames;
-  Rboolean  active;
-
-  Rdb_exists   exists;
-  Rdb_get      get;
-  Rdb_remove   remove;
-  Rdb_assign   assign;
-  Rdb_objects  objects;
-  Rdb_canCache canCache;
-
-  Rdb_onDetach onDetach;
-  Rdb_onAttach onAttach;
-
-  void     *privateData;
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* R_CALLBACKS_H */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Complex.h b/com.oracle.truffle.r.native/include/jni/R_ext/Complex.h
deleted file mode 100644
index 06417a7153fc04d723de74525791b1c17986b591..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Complex.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2001   The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_COMPLEX_H
-#define R_COMPLEX_H
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
-	double r;
-	double i;
-} Rcomplex;
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_COMPLEX_H */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Constants.h b/com.oracle.truffle.r.native/include/jni/R_ext/Constants.h
deleted file mode 100644
index 08e3d158953413cd08fb338ae8d11c7f259ddef0..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Constants.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
- *  Copyright (C) 1998-2012   The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_EXT_CONSTANTS_H_
-#define R_EXT_CONSTANTS_H_
-
-/* usually in math.h, but not with strict C99 compliance */
-#ifndef M_PI
-#define M_PI 3.141592653589793238462643383279502884197169399375
-#endif
-
-#ifndef STRICT_R_HEADERS
-#define PI             M_PI
-#include <float.h>  /* Defines the rest, at least in C99 */
-#define SINGLE_EPS     FLT_EPSILON
-#define SINGLE_BASE    FLT_RADIX
-#define SINGLE_XMIN    FLT_MIN
-#define SINGLE_XMAX    FLT_MAX
-#define DOUBLE_DIGITS  DBL_MANT_DIG
-#define DOUBLE_EPS     DBL_EPSILON
-#define DOUBLE_XMAX    DBL_MAX
-#define DOUBLE_XMIN    DBL_MIN
-#endif
-
-#endif /* R_EXT_CONSTANTS_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Error.h b/com.oracle.truffle.r.native/include/jni/R_ext/Error.h
deleted file mode 100644
index fbdceeca35ce18ca85fc211814364f82d4101e79..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Error.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2005   The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_ERROR_H_
-#define R_ERROR_H_
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* valid from gcc 2.95.3, at least.
-   Suggested by Anton Korobeynikov.
- */
-#if defined(__GNUC__) && __GNUC__ >= 3
-void Rf_error(const char *, ...) __attribute__((noreturn));
-void UNIMPLEMENTED(const char *) __attribute__((noreturn));
-void WrongArgCount(const char *) __attribute__((noreturn));
-#else
-void Rf_error(const char *, ...);
-void UNIMPLEMENTED(const char *);
-void WrongArgCount(const char *);
-#endif
-
-void	Rf_warning(const char *, ...);
-void 	R_ShowMessage(const char *s);
-    
-
-#ifdef  __cplusplus
-}
-#endif
-
-#ifndef R_NO_REMAP
-#define error Rf_error
-#define warning Rf_warning
-#endif
-
-
-#endif /* R_ERROR_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Linpack.h b/com.oracle.truffle.r.native/include/jni/R_ext/Linpack.h
deleted file mode 100644
index b2e2b7a0e3accddd7d17e626ad60e9caeeef111d..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Linpack.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1997        Robert Gentleman and Ross Ihaka
- *  Copyright (C) 1999-2015   The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* 
-   C declarations of double-precision LINPACK Fortran subroutines
-   included in R, and some others.
-   
-   Those which are listed as part of R are in the API
- */
-
-#ifndef R_LINPACK_H_
-#define R_LINPACK_H_
-
-#include <R_ext/RS.h>		/* for F77_... */
-#include <R_ext/BLAS.h>
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-	/* Double Precision LINPACK */
-
-extern void F77_NAME(dpbfa)(double*, int*, int*, int*, int*);
-extern void F77_NAME(dpbsl)(double*, int*, int*, int*, double*);
-extern void F77_NAME(dpoco)(double*, int*, int*, double*, double*, int*);
-extern void F77_NAME(dpodi)(double*, int*, int*, double*, int*);
-extern void F77_NAME(dpofa)(double*, int*, int*, int*);
-extern void F77_NAME(dposl)(double*, int*, int*, double*);
-extern void F77_NAME(dqrdc)(double*, int*, int*, int*, double*, int*, double*, int*);
-extern void F77_NAME(dqrsl)(double*, int*, int*, int*, double*, double*, double*, double*, double*, double*, double*, int*, int*);
-extern void F77_NAME(dsvdc)(double*, int*, int*, int*, double*, double*, double*, int*, double*, int*, double*, int*, int*);
-extern void F77_NAME(dtrco)(double*, int*, int*, double*, double*, int*);
-extern void F77_NAME(dtrsl)(double*, int*, int*, double*, int*, int*);
-
-
-/* The following routines are listed as they have always been declared
-   here, but they are not currently included in R */
-extern void F77_NAME(dchdc)(double*, int*, int*, double*, int*, int*, int*);
-extern void F77_NAME(dchdd)(double*, int*, int*, double*, double*, int*, int*, double*, double*, double*, double*, int*);
-extern void F77_NAME(dchex)(double*, int*, int*, int*, int*, double*, int*, int*, double*, double*, int*);
-extern void F77_NAME(dchud)(double*, int*, int*, double*, double*, int*, int*, double*, double*, double*, double*);
-extern void F77_NAME(dgbco)(double*, int*, int*, int*, int*, int*, double*, double*);
-extern void F77_NAME(dgbdi)(double*, int*, int*, int*, int*, int*, double*);
-extern void F77_NAME(dgbfa)(double*, int*, int*, int*, int*, int*, int*);
-extern void F77_NAME(dgbsl)(double*, int*, int*, int*, int*, int*, double*, int*);
-extern void F77_NAME(dgeco)(double*, int*, int*, int*, double*, double*);
-extern void F77_NAME(dgedi)(double*, int*, int*, int*, double*, double*, int*);
-extern void F77_NAME(dgefa)(double*, int*, int*, int*, int*);
-extern void F77_NAME(dgesl)(double*, int*, int*, int*, double*, int*);
-extern void F77_NAME(dgtsl)(int*, double*, double*, double*, double*, int*);
-extern void F77_NAME(dpbco)(double*, int*, int*, int*, double*, double*, int*);
-extern void F77_NAME(dpbdi)(double*, int*, int*, int*, double*);
-extern void F77_NAME(dppco)(double*, int*, double*, double*, int*);
-extern void F77_NAME(dppdi)(double*, int*, double*, int*);
-extern void F77_NAME(dppfa)(double*, int*, int*);
-extern void F77_NAME(dppsl)(double*, int*, double*);
-extern void F77_NAME(dptsl)(int*, double*, double*, double*);
-extern void F77_NAME(dsico)(double*, int*, int*, int*, double*, double*);
-extern void F77_NAME(dsidi)(double*, int*, int*, int*, double*, int*, double*, int*);
-extern void F77_NAME(dsifa)(double*, int*, int*, int*, int*);
-extern void F77_NAME(dsisl)(double*, int*, int*, int*, double*);
-extern void F77_NAME(dspco)(double*, int*, int*, double*, double*);
-extern void F77_NAME(dspdi)(double*, int*, int*, double*, int*, double*, int*);
-extern void F77_NAME(dspfa)(double*, int*, int*, int*);
-extern void F77_NAME(dspsl)(double*, int*, int*, double*);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_LINPACK_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Memory.h b/com.oracle.truffle.r.native/include/jni/R_ext/Memory.h
deleted file mode 100644
index 4b3e19e19241ecd0a087a121b35e67c1ff0c1778..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Memory.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2007  The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- *
- *
- * Memory Allocation (garbage collected) --- INCLUDING S compatibility ---
- */
-
-/* Included by R.h: API */
-
-#ifndef R_EXT_MEMORY_H_
-#define R_EXT_MEMORY_H_
-
-#ifndef NO_C_HEADERS
-# include <stddef.h> /* for size_t */
-#endif
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-void*	vmaxget(void);
-void	vmaxset(const void *);
-
-void	R_gc(void);
-int	R_gc_running();
-
-char*	R_alloc(size_t, int);
-char*	S_alloc(long, int);
-char*	S_realloc(char *, long, long, int);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_EXT_MEMORY_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Print.h b/com.oracle.truffle.r.native/include/jni/R_ext/Print.h
deleted file mode 100644
index 7beeaf171d867024f384eaf4a179ebf50efd030b..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Print.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2010    The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_EXT_PRINT_H_
-#define R_EXT_PRINT_H_
-
-#ifdef  __cplusplus
-/* If the vprintf interface is defined at all in C++ it may only be
-   defined in namespace std. */
-# ifdef R_USE_C99_IN_CXX
-#  include <cstdarg>
-#  ifdef __SUNPRO_CC
-using _STLP_VENDOR_CSTD::va_list;
-#  endif
-# endif
-extern "C" {
-#else
-# include <stdarg.h>
-#endif
-
-void Rprintf(const char *, ...);
-void REprintf(const char *, ...);
-#if !defined(__cplusplus) || defined R_USE_C99_IN_CXX
-void Rvprintf(const char *, va_list);
-void REvprintf(const char *, va_list);
-#endif
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_EXT_PRINT_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/RS.h b/com.oracle.truffle.r.native/include/jni/R_ext/RS.h
deleted file mode 100644
index 947884870356d218edf3c4b1a3e031d52acbd757..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/RS.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1999-2007 The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_RS_H
-#define R_RS_H
-
-#ifndef NO_C_HEADERS
-# include <string.h>		/* for memcpy, memset */
-#endif
-
-#include <Rconfig.h>		/* for F77_APPEND_UNDERSCORE */
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* S Like Error Handling */
-
-#include <R_ext/Error.h>	/* for error and warning */
-
-#ifndef STRICT_R_HEADERS
-
-#define R_PROBLEM_BUFSIZE	4096
-/* Parentheses added for FC4 with gcc4 and -D_FORTIFY_SOURCE=2 */
-#define PROBLEM			{char R_problem_buf[R_PROBLEM_BUFSIZE];(sprintf)(R_problem_buf,
-#define MESSAGE                 {char R_problem_buf[R_PROBLEM_BUFSIZE];(sprintf)(R_problem_buf,
-#define ERROR			),error(R_problem_buf);}
-#define RECOVER(x)		),error(R_problem_buf);}
-#define WARNING(x)		),warning(R_problem_buf);}
-#define LOCAL_EVALUATOR		/**/
-#define NULL_ENTRY		/**/
-#define WARN			WARNING(NULL)
-
-#endif
-
-/* S Like Memory Management */
-
-extern void *R_chk_calloc(size_t, size_t);
-extern void *R_chk_realloc(void *, size_t);
-extern void R_chk_free(void *);
-
-#ifndef STRICT_R_HEADERS
-/* S-PLUS 3.x but not 5.x NULLs the pointer in the following */
-#define Calloc(n, t)   (t *) R_chk_calloc( (size_t) (n), sizeof(t) )
-#define Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (size_t)((n) * sizeof(t)) )
-#define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
-#endif
-#define R_Calloc(n, t)   (t *) R_chk_calloc( (size_t) (n), sizeof(t) )
-#define R_Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (size_t)((n) * sizeof(t)) )
-#define R_Free(p)      (R_chk_free( (void *)(p) ), (p) = NULL)
-
-#define Memcpy(p,q,n)  memcpy( p, q, (size_t)(n) * sizeof(*p) )
-
-/* added for 3.0.0 */
-#define Memzero(p,n)  memset(p, 0, (size_t)(n) * sizeof(*p))
-
-#define CallocCharBuf(n) (char *) R_chk_calloc((size_t) ((n)+1), sizeof(char))
-
-/* S Like Fortran Interface */
-/* These may not be adequate everywhere. Convex had _ prepending common
-   blocks, and some compilers may need to specify Fortran linkage */
-
-#ifdef HAVE_F77_UNDERSCORE
-# define F77_CALL(x)	x ## _
-#else
-# define F77_CALL(x)	x
-#endif
-#define F77_NAME(x)    F77_CALL(x)
-#define F77_SUB(x)     F77_CALL(x)
-#define F77_COM(x)     F77_CALL(x)
-#define F77_COMDECL(x) F77_CALL(x)
-
-#ifndef NO_CALL_R
-void	call_R(char*, long, void**, char**, long*, char**, long, char**);
-#endif
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_RS_H */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Random.h b/com.oracle.truffle.r.native/include/jni/R_ext/Random.h
deleted file mode 100644
index 0a264a39540147d85028ee60d684e3403330cfc2..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Random.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2011    The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API */
-
-#ifndef R_RANDOM_H
-#define R_RANDOM_H
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-#include <R_ext/Boolean.h>
-
-typedef enum {
-    WICHMANN_HILL,
-    MARSAGLIA_MULTICARRY,
-    SUPER_DUPER,
-    MERSENNE_TWISTER,
-    KNUTH_TAOCP,
-    USER_UNIF,
-    KNUTH_TAOCP2,
-    LECUYER_CMRG
-} RNGtype;
-
-/* Different kinds of "N(0,1)" generators :*/
-typedef enum {
-    BUGGY_KINDERMAN_RAMAGE,
-    AHRENS_DIETER,
-    BOX_MULLER,
-    USER_NORM,
-    INVERSION,
-    KINDERMAN_RAMAGE
-} N01type;
-
-
-void GetRNGstate(void);
-void PutRNGstate(void);
-
-double unif_rand(void);
-/* These are also defined in Rmath.h */
-double norm_rand(void);
-double exp_rand(void);
-
-typedef unsigned int Int32;
-double * user_unif_rand(void);
-void user_unif_init(Int32);
-int * user_unif_nseed(void);
-int * user_unif_seedloc(void);
-
-double * user_norm_rand(void);
-
-void FixupProb(double *, int, int, Rboolean);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_RANDOM_H */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Rdynload.h b/com.oracle.truffle.r.native/include/jni/R_ext/Rdynload.h
deleted file mode 100644
index 108bf63359d3c17dbe0718b11c7f4ab239fa34c6..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Rdynload.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2001-12  The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/*
-  C functions used to register compiled code in packages.
-
-  Those needed for that purpose are part of the API.
- */
-
-#ifndef  R_EXT_DYNLOAD_H_
-#define  R_EXT_DYNLOAD_H_
-
-#include <R_ext/Boolean.h>
-
-/* called with a variable argument set */
-typedef void * (*DL_FUNC)();
-
-typedef unsigned int R_NativePrimitiveArgType;
-
-#define SINGLESXP 302 /* Don't have a single type for this. */
-
-/* In the future, we will want to allow people register their own types
-   and then refer to these in other contexts. Something like the Gtk type
-   system may be appropriate.
-*/
-typedef unsigned int R_NativeObjectArgType;
-
-
-/* In the near future, we may support registering
-   information about the arguments of native routines
-   and whether they are used to return information.
-   The hope is that we can minimize copying objects even
-   further. Not currently in use.
-*/
-typedef enum {R_ARG_IN, R_ARG_OUT, R_ARG_IN_OUT, R_IRRELEVANT} R_NativeArgStyle;
-
-
-
-/*
- These are very similar to those in  unix/dynload.c
- but we maintain them separately to give us more freedom to do
- some computations on the internal versions that are derived from
- these definitions.
-*/
-typedef struct {
-    const char *name;
-    DL_FUNC     fun;
-    int         numArgs;
-
-    R_NativePrimitiveArgType *types;
-    R_NativeArgStyle         *styles;
-
-} R_CMethodDef;
-
-typedef R_CMethodDef R_FortranMethodDef;
-
-
-
-typedef struct {
-    const char *name;
-    DL_FUNC     fun;
-    int         numArgs;
-/* In the future, we will put types in here for the different arguments.
-   We need a richer type system to do this effectively so that one
-   can specify types for new classes.
-*/
-} R_CallMethodDef;
-typedef R_CallMethodDef R_ExternalMethodDef;
-
-
-typedef struct _DllInfo DllInfo;
-
-/*
-  Currently ignore the graphics routines, accessible via .External.graphics()
-  and .Call.graphics().
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-int R_registerRoutines(DllInfo *info, const R_CMethodDef * const croutines,
-		       const R_CallMethodDef * const callRoutines,
-		       const R_FortranMethodDef * const fortranRoutines,
-                       const R_ExternalMethodDef * const externalRoutines);
-
-Rboolean R_useDynamicSymbols(DllInfo *info, Rboolean value);
-Rboolean R_forceSymbols(DllInfo *info, Rboolean value);
-
-DllInfo *R_getDllInfo(const char *name);
-
-/* to be used by applications embedding R to register their symbols
-   that are not related to any dynamic module */
-DllInfo *R_getEmbeddingDllInfo(void);
-
-typedef struct Rf_RegisteredNativeSymbol R_RegisteredNativeSymbol;
-typedef enum {R_ANY_SYM=0, R_C_SYM, R_CALL_SYM, R_FORTRAN_SYM, R_EXTERNAL_SYM} NativeSymbolType;
-
-
-DL_FUNC R_FindSymbol(char const *, char const *,
-                       R_RegisteredNativeSymbol *symbol);
-
-
-/* Experimental interface for exporting and importing functions from
-   one package for use from C code in a package.  The registration
-   part probably ought to be integrated with the other registrations.
-   The naming of these routines may be less than ideal. */
-
-void R_RegisterCCallable(const char *package, const char *name, DL_FUNC fptr);
-DL_FUNC R_GetCCallable(const char *package, const char *name);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* R_EXT_DYNLOAD_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Utils.h b/com.oracle.truffle.r.native/include/jni/R_ext/Utils.h
deleted file mode 100644
index 01cd2814ba99be8cf1b12d0fd111efe1a59bb5fd..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Utils.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1998-2012    The R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- *
- *
- * Generally useful  UTILITIES  *NOT* relying on R internals (from Defn.h)
- */
-
-/* Included by R.h: API */
-
-#ifndef R_EXT_UTILS_H_
-#define R_EXT_UTILS_H_
-
-#include <R_ext/Boolean.h>
-#include <R_ext/Complex.h>
-#include <stddef.h>
-
-#define revsort       Rf_revsort
-#define iPsort        Rf_iPsort
-#define rPsort        Rf_rPsort
-#define cPsort        Rf_cPsort
-#define IndexWidth    Rf_IndexWidth
-#define setIVector    Rf_setIVector
-#define setRVector    Rf_setRVector
-#define StringFalse   Rf_StringFalse
-#define StringTrue    Rf_StringTrue
-#define isBlankString Rf_isBlankString
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/* ../../main/sort.c : */
-void	R_isort(int*, int);
-void	R_rsort(double*, int);
-void	R_csort(Rcomplex*, int);
-void    rsort_with_index(double *, int *, int);
-void	revsort(double*, int*, int);/* reverse; sort i[] alongside */
-void	iPsort(int*,    int, int);
-void	rPsort(double*, int, int);
-void	cPsort(Rcomplex*, int, int);
-
-/* ../../main/qsort.c : */
-/* dummy renamed to II to avoid problems with g++ on Solaris */
-void R_qsort    (double *v,         size_t i, size_t j);
-void R_qsort_I  (double *v, int *II, int i, int j);
-void R_qsort_int  (int *iv,         size_t i, size_t j);
-void R_qsort_int_I(int *iv, int *II, int i, int j);
-#ifdef R_RS_H
-void F77_NAME(qsort4)(double *v, int *indx, int *ii, int *jj);
-void F77_NAME(qsort3)(double *v,            int *ii, int *jj);
-#endif
-
-/* ../../main/util.c  and others : */
-const char *R_ExpandFileName(const char *);
-void	setIVector(int*, int, int);
-void	setRVector(double*, int, double);
-Rboolean StringFalse(const char *);
-Rboolean StringTrue(const char *);
-Rboolean isBlankString(const char *);
-
-/* These two are guaranteed to use '.' as the decimal point,
-   and to accept "NA".
- */
-double R_atof(const char *str);
-double R_strtod(const char *c, char **end);
-
-char *R_tmpnam(const char *prefix, const char *tempdir);
-char *R_tmpnam2(const char *prefix, const char *tempdir, const char *fileext);
-
-void R_CheckUserInterrupt(void);
-void R_CheckStack(void);
-void R_CheckStack2(size_t);
-
-
-/* ../../appl/interv.c: also in Applic.h */
-int findInterval(double *xt, int n, double x,
-		 Rboolean rightmost_closed,  Rboolean all_inside, int ilo,
-		 int *mflag);
-#ifdef R_RS_H
-int F77_SUB(interv)(double *xt, int *n, double *x,
-		    Rboolean *rightmost_closed, Rboolean *all_inside,
-		    int *ilo, int *mflag);
-#endif
-void find_interv_vec(double *xt, int *n,	double *x,   int *nx,
-		     int *rightmost_closed, int *all_inside, int *indx);
-
-/* ../../appl/maxcol.c: also in Applic.h */
-void R_max_col(double *matrix, int *nr, int *nc, int *maxes, int *ties_meth);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif /* R_EXT_UTILS_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/Visibility.h b/com.oracle.truffle.r.native/include/jni/R_ext/Visibility.h
deleted file mode 100644
index aa35e34261e30db6c5102fb3587a05ccee32bc25..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/Visibility.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2008    the R Core Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/*
-  Definitions controlling visibility on some platforms.
-
-  Part of the API.
-*/
-
-#ifndef R_EXT_VISIBILITY_H_
-#define R_EXT_VISIBILITY_H_
-
-#include <Rconfig.h>
-
-#ifdef HAVE_VISIBILITY_ATTRIBUTE
-# define attribute_visible __attribute__ ((visibility ("default")))
-# define attribute_hidden __attribute__ ((visibility ("hidden")))
-#else
-# define attribute_visible
-# define attribute_hidden
-#endif
-
-#endif /* R_EXT_VISIBILITY_H_ */
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/libextern.h b/com.oracle.truffle.r.native/include/jni/R_ext/libextern.h
deleted file mode 100644
index 3f61fb1e3b8eb1661dd2f8593c796cd174205f6c..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/R_ext/libextern.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 2001, 2004  The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-/* Included by R.h: API on Windows */
-
-/* don't disallow including this one more than once */
-
-/* This is intended to be called from other header files, so not callable
-   from C++ */
-
-#undef LibExtern
-#undef LibImport
-#undef LibExport
-
-/* Don't try to include CYGWIN here: decorating some symbols breaks
-   the auto-export that it relies on, even if R_DLL_BUILD were set. */
-#ifdef WIN32 /* WIN32 as does not depend on config.h */
-#define LibImport __declspec(dllimport)
-#define LibExport __declspec(dllexport)
-#else
-#define LibImport
-#define LibExport
-#endif
-
-#ifdef __MAIN__
-#define LibExtern LibExport
-#define extern
-#elif defined(R_DLL_BUILD)
-#define LibExtern extern
-#else
-#define LibExtern extern LibImport
-#endif
diff --git a/com.oracle.truffle.r.native/include/jni/Rconfig.h b/com.oracle.truffle.r.native/include/jni/Rconfig.h
deleted file mode 100644
index 270af595e9f7e5d186c80324fb50bf1b9442196e..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/Rconfig.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Rconfig.h.  Generated automatically */
-#ifndef R_RCONFIG_H
-#define R_RCONFIG_H
-
-#ifndef R_CONFIG_H
-
-#define HAVE_F77_UNDERSCORE 1
-/* all R platforms have this */
-#define IEEE_754 1
-/* #undef WORDS_BIGENDIAN */
-#define R_INLINE inline
-/* #undef HAVE_VISIBILITY_ATTRIBUTE */
-/* all R platforms have the next two */
-#define SUPPORT_UTF8 1
-#define SUPPORT_MBCS 1
-#define ENABLE_NLS 1
-#define HAVE_AQUA 1
-/* #undef SUPPORT_OPENMP */
-#define SIZEOF_SIZE_T 8
-
-#endif /* not R_CONFIG_H */
-
-#endif /* not R_RCONFIG_H */
diff --git a/com.oracle.truffle.r.native/include/jni/Rdefines.h b/com.oracle.truffle.r.native/include/jni/Rdefines.h
deleted file mode 100644
index 2633f3fd7044337185f6e09cf828a3f8e5811eed..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/Rdefines.h
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- *  R : A Computer Language for Statistical Data Analysis
- *  Copyright (C) 1999-2013 The R Core Team.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this program; if not, a copy is available at
- *  http://www.r-project.org/Licenses/
- */
-
-#ifndef R_DEFINES_H
-#define R_DEFINES_H
-
-#if !defined(R_R_H) && !defined(R_S_H)
-/* user forgot to include R.h or S.h */
-# include <R_ext/Memory.h>
-# include <R_ext/RS.h>
-#endif
-
-#include <Rinternals.h>
-
-/*
- *  Much is from John Chambers' "Programming With Data".
- *  Some of this is from Doug Bates.
- *
- *  It is presented here to support a joint programming style which
- *  will work in both R and S.  In particular it helps with:
- *
- *    1. S/R <-> CORBA code.
- *    2. S/R <-> Java Code.
- *
- *  And to hide some internal nastiness.
- */
-
-
-/*
- *  Added some macros defined in S.h from Splus 5.1
- */
-
-#define NULL_USER_OBJECT	R_NilValue
-
-#define AS_LOGICAL(x)		coerceVector(x,LGLSXP)
-#define AS_INTEGER(x)		coerceVector(x,INTSXP)
-#define AS_NUMERIC(x)		coerceVector(x,REALSXP)
-#define AS_CHARACTER(x)		coerceVector(x,STRSXP)
-#define AS_COMPLEX(x)		coerceVector(x,CPLXSXP)
-#define AS_VECTOR(x)		coerceVector(x,VECSXP)
-#define AS_LIST(x)		coerceVector(x,VECSXP)
-#define AS_RAW(x)		coerceVector(x,RAWSXP)
-
-#define IS_LOGICAL(x)		isLogical(x)
-#define IS_INTEGER(x)		isInteger(x)
-#define IS_NUMERIC(x)		isReal(x)
-#define IS_CHARACTER(x)		isString(x)
-#define IS_COMPLEX(x)		isComplex(x)
-/* NB: is this right? It means atomic or VECSXP or EXPRSXP */
-#define IS_VECTOR(x)		isVector(x)
-/* And this cannot be right: isVectorList(x)? */
-#define IS_LIST(x)		IS_VECTOR(x)
-#define IS_RAW(x)		(TYPEOF(x) == RAWSXP)
-
-#define NEW_LOGICAL(n)		allocVector(LGLSXP,n)
-#define NEW_INTEGER(n)		allocVector(INTSXP,n)
-#define NEW_NUMERIC(n)		allocVector(REALSXP,n)
-#define NEW_CHARACTER(n)	allocVector(STRSXP,n)
-#define NEW_COMPLEX(n)		allocVector(CPLXSXP,n)
-#define NEW_LIST(n)		allocVector(VECSXP,n)
-#define NEW_STRING(n)		NEW_CHARACTER(n)
-#define NEW_RAW(n)		allocVector(RAWSXP,n)
-
-#define LOGICAL_POINTER(x)	LOGICAL(x)
-#define INTEGER_POINTER(x)	INTEGER(x)
-#define NUMERIC_POINTER(x)	REAL(x)
-#define CHARACTER_POINTER(x)	STRING_PTR(x)
-#define COMPLEX_POINTER(x)	COMPLEX(x)
-/* Use of VECTOR_PTR will fail unless USE_RINTERNALS is in use
-   This is probably unused.
-*/
-#define LIST_POINTER(x)		VECTOR_PTR(x)
-#define RAW_POINTER(x)		RAW(x)
-
-/* The following are not defined in `Programming with Data' but are
-   defined in S.h in Svr4 */
-
-/*
- * Note that LIST_DATA and RAW_DATA are missing.
- * This is consistent with Svr4.
- */
-
-#define LOGICAL_DATA(x)		(LOGICAL(x))
-#define INTEGER_DATA(x)		(INTEGER(x))
-#define DOUBLE_DATA(x)		(REAL(x))
-#define NUMERIC_DATA(x)		(REAL(x))
-#define CHARACTER_DATA(x)	(STRING_PTR(x))
-#define COMPLEX_DATA(x)		(COMPLEX(x))
-/* Use of VECTOR_PTR will fail unless USE_RINTERNALS is in use
-   VECTOR_DATA seems unused, and RECURSIVE_DATA is used only in
-   the Expat part of XML.
-*/
-#define RECURSIVE_DATA(x)	(VECTOR_PTR(x))
-#define VECTOR_DATA(x)		(VECTOR_PTR(x))
-
-#define LOGICAL_VALUE(x)	asLogical(x)
-#define INTEGER_VALUE(x)	asInteger(x)
-#define NUMERIC_VALUE(x)	asReal(x)
-#define CHARACTER_VALUE(x)	CHAR(asChar(x))
-#define STRING_VALUE(x)		CHAR(asChar(x))
-#define LIST_VALUE(x)		error("the 'value' of a list object is not defined")
-#define RAW_VALUE(x)		error("the 'value' of a raw object is not defined")
-
-#define SET_ELEMENT(x, i, val)	SET_VECTOR_ELT(x, i, val)
-#define GET_ATTR(x,what)       	getAttrib(x, what)
-#define GET_CLASS(x)       	getAttrib(x, R_ClassSymbol)
-#define GET_DIM(x)       	getAttrib(x, R_DimSymbol)
-#define GET_DIMNAMES(x)       	getAttrib(x, R_DimNamesSymbol)
-#define GET_COLNAMES(x)       	GetColNames(x)
-#define GET_ROWNAMES(x)       	GetRowNames(x)
-#define GET_LEVELS(x)       	getAttrib(x, R_LevelsSymbol)
-#define GET_TSP(x)       	getAttrib(x, R_TspSymbol)
-#define GET_NAMES(x)		getAttrib(x, R_NamesSymbol)
-#define SET_ATTR(x, what, n)     	setAttrib(x, what, n)
-#define SET_CLASS(x, n)     	setAttrib(x, R_ClassSymbol, n)
-#define SET_DIM(x, n)     	setAttrib(x, R_DimSymbol, n)
-#define SET_DIMNAMES(x, n)     	setAttrib(x, R_DimNamesSymbol, n)
-#define SET_LEVELS(x, l)       	setAttrib(x, R_LevelsSymbol, l)
-#define SET_NAMES(x, n)		setAttrib(x, R_NamesSymbol, n)
-/* These do not support long vectors */
-#define GET_LENGTH(x)		length(x)
-#define SET_LENGTH(x, n)	(x = lengthgets(x, n))
-
-#define GET_SLOT(x, what)       R_do_slot(x, what)
-#define SET_SLOT(x, what, value)  R_do_slot_assign(x, what, value)
-
-#define MAKE_CLASS(what)	R_do_MAKE_CLASS(what)
-/* NEW_OBJECT is recommended; NEW is for green book compatibility */
-#define NEW_OBJECT(class_def)	R_do_new_object(class_def)
-#define NEW(class_def)		R_do_new_object(class_def)
-
-#define s_object                SEXPREC
-#define S_EVALUATOR             /**/
-
-/* These conflict with definitions in R_ext/Boolean.h,
-   but spatstat relies on them in a C file */
-#ifdef __cplusplus
-# ifndef R_EXT_BOOLEAN_H_
-#  ifndef TRUE
-#   define TRUE 1
-#  endif
-#  ifndef FALSE
-#   define FALSE 0
-#  endif
-# endif
-#else
-#  ifndef TRUE
-#   define TRUE 1
-#  endif
-#  ifndef FALSE
-#   define FALSE 0
-#  endif
-#endif
-
-#define COPY_TO_USER_STRING(x)	mkChar(x)
-#define CREATE_STRING_VECTOR(x)	mkChar(x)
-
-#define CREATE_FUNCTION_CALL(name, argList) createFunctionCall(name, argList)
-
-#define EVAL(x)			eval(x,R_GlobalEnv)
-
-
-#endif
diff --git a/com.oracle.truffle.r.native/include/jni/sed_Rinternals b/com.oracle.truffle.r.native/include/jni/sed_Rinternals
new file mode 100644
index 0000000000000000000000000000000000000000..f5c6a0d20102bc000ba924b876e11643bf53049b
--- /dev/null
+++ b/com.oracle.truffle.r.native/include/jni/sed_Rinternals
@@ -0,0 +1,7 @@
+/typedef struct SEXPREC *SEXP;/i\
+#ifdef FASTR\
+#include <jni.h>\
+typedef jobject SEXP\
+#else
+/typedef struct SEXPREC *SEXP;/a\
+#endif
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/GraphicsDevice.h b/com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsDevice.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/R_ext/GraphicsDevice.h
rename to com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsDevice.h
diff --git a/com.oracle.truffle.r.native/include/jni/R_ext/GraphicsEngine.h b/com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsEngine.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/R_ext/GraphicsEngine.h
rename to com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsEngine.h
diff --git a/com.oracle.truffle.r.native/include/jni/Rinternals.h b/com.oracle.truffle.r.native/include/jni/src/Rinternals.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/Rinternals.h
rename to com.oracle.truffle.r.native/include/jni/src/Rinternals.h
diff --git a/com.oracle.truffle.r.native/include/jni/libintl.h b/com.oracle.truffle.r.native/include/jni/src/libintl.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/libintl.h
rename to com.oracle.truffle.r.native/include/jni/src/libintl.h
diff --git a/com.oracle.truffle.r.native/library/base/Makefile b/com.oracle.truffle.r.native/library/base/Makefile
index 3e168bf353985b0d0de6f655897bdfeda1eb2d0d..e5c14fcd55925836fcd02cc432ac6dafb6478fd5 100644
--- a/com.oracle.truffle.r.native/library/base/Makefile
+++ b/com.oracle.truffle.r.native/library/base/Makefile
@@ -25,7 +25,9 @@ PKG_EXTRAS = $(FASTR_LIBDIR)/$(PKG)/R/Rprofile
 
 include ../lib.mk
 
-# override the Rprofile
+# edit the Rprofile to add fastr as a default package
 
-$(PKG_EXTRAS): $(SRC)/Rprofile.R
-	cp $(SRC)/Rprofile.R $(PKG_EXTRAS)
+$(PKG_EXTRAS): $(FASTR_LIBDIR)/$(PKG)/R/Rprofile.orig
+
+$(FASTR_LIBDIR)/$(PKG)/R/Rprofile.orig:
+	sed -f sed_profile -i .orig $(FASTR_LIBDIR)/$(PKG)/R/Rprofile
diff --git a/com.oracle.truffle.r.native/library/base/sed_profile b/com.oracle.truffle.r.native/library/base/sed_profile
new file mode 100644
index 0000000000000000000000000000000000000000..98ccfd58682fb42ae30c0ab8e388917cd1e6fa53
--- /dev/null
+++ b/com.oracle.truffle.r.native/library/base/sed_profile
@@ -0,0 +1 @@
+/           dp <- c("datasets", "utils", "grDevices", "graphics",/s/c("/c("fastr", /
diff --git a/com.oracle.truffle.r.native/library/base/src/Rprofile.R b/com.oracle.truffle.r.native/library/base/src/Rprofile.R
deleted file mode 100644
index e86ad67f768827c1d875716a4246221e9acbcf37..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/library/base/src/Rprofile.R
+++ /dev/null
@@ -1,167 +0,0 @@
-### This is the system Rprofile file. It is always run on startup.
-### Additional commands can be placed in site or user Rprofile files
-#
-#  Copyright (C) 1995-2012 The R Core Team
-### (see ?Rprofile).
-
-### Notice that it is a bad idea to use this file as a template for
-### personal startup files, since things will be executed twice and in
-### the wrong environment (user profiles are run in .GlobalEnv).
-
-### This is the system Rprofile file. It is always run on startup.
-### Additional commands can be placed in site or user Rprofile files
-#
-#  Copyright (C) 1995-2012 The R Core Team
-### (see ?Rprofile).
-
-### Notice that it is a bad idea to use this file as a template for
-### personal startup files, since things will be executed twice and in
-### the wrong environment (user profiles are run in .GlobalEnv).
-
-### Slightly modified for FastR
-
-.GlobalEnv <- globalenv()
-attach(NULL, name = "Autoloads")
-.AutoloadEnv <- as.environment(2)
-assign(".Autoloaded", NULL, envir = .AutoloadEnv)
-T <- TRUE
-F <- FALSE
-R.version <- structure(R.Version(), class = "simple.list")
-version <- R.version            # for S compatibility
-
-## for backwards compatibility only
-R.version.string <- R.version$version.string
-#
-### NOTA BENE: options() for non-base package functionality are in places like
-###            --------- ../utils/R/zzz.R
-#
-options(keep.source = interactive())
-options(warn = 0)
-# options(repos = c(CRAN="@CRAN@"))
-# options(BIOC = "http://www.bioconductor.org")
-
-options(timeout = 60)
-options(encoding = "native.enc")
-options(show.error.messages = TRUE)
-## keep in sync with PrintDefaults() in  ../../main/print.c :
-options(scipen = 0)
-options(max.print = 99999)# max. #{entries} in internal printMatrix()
-options(add.smooth = TRUE)# currently only used in 'plot.lm'
-options(stringsAsFactors = TRUE)
-if(!interactive() && is.null(getOption("showErrorCalls")))
-    options(showErrorCalls = TRUE)
-
-local({dp <- Sys.getenv("R_DEFAULT_PACKAGES")
-       if(identical(dp, "")) # marginally faster to do methods last
-           dp <- c("fastr", "datasets", "utils", "grDevices", "graphics",
-                   "stats", "methods")
-       else if(identical(dp, "NULL")) dp <- character(0)
-       else dp <- strsplit(dp, ",")[[1]]
-	   # There is a problem with the \\1
-#       dp <- sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) # strip whitespace
-       options(defaultPackages = dp)
-    })
-
-## Expand R_LIBS_* environment variables.
-Sys.setenv(R_LIBS_SITE =
-           .expand_R_libs_env_var(Sys.getenv("R_LIBS_SITE")))
-Sys.setenv(R_LIBS_USER =
-           .expand_R_libs_env_var(Sys.getenv("R_LIBS_USER")))
-
-.First.sys <- function()
-{
-    for(pkg in getOption("defaultPackages")) {
-        res <- require(pkg, quietly = TRUE, warn.conflicts = FALSE,
-                       character.only = TRUE)
-        if(!res)
-            warning(gettextf('package %s in options("defaultPackages") was not found', sQuote(pkg)),
-                    call.=FALSE, domain = NA)
-    }
-}
-
-.OptRequireMethods <- function()
-{
-      if("methods" %in% getOption("defaultPackages")) {
-        res <- require("methods", quietly = TRUE, warn.conflicts = FALSE,
-                       character.only = TRUE)
-        if(!res)
-            warning('package "methods" in options("defaultPackages") was not found', call.=FALSE)
-    }
-}
-
-#if(nzchar(Sys.getenv("R_BATCH"))) {
-#    .Last.sys <- function()
-#    {
-#        cat("> proc.time()\n")
-#        print(proc.time())
-#    }
-#    ## avoid passing on to spawned R processes
-#    ## A system has been reported without Sys.unsetenv, so try this
-#    try(Sys.setenv(R_BATCH=""))
-#}
-####-*- R -*- Unix Specific ----
-
-.Library <- file.path(R.home(), "library")
-.Library.site <- Sys.getenv("R_LIBS_SITE")
-.Library.site <- if(!nchar(.Library.site)) file.path(R.home(), "site-library") else unlist(strsplit(.Library.site, ":"))
-.Library.site <- .Library.site[file.exists(.Library.site)]
-
-invisible(.libPaths(c(unlist(strsplit(Sys.getenv("R_LIBS"), ":")),
-                      unlist(strsplit(Sys.getenv("R_LIBS_USER"), ":")
-                      ))))
-local({
-    popath <- Sys.getenv("R_TRANSLATIONS", "")
-    if(!nzchar(popath)) {
-        paths <- file.path(.libPaths(), "translations", "DESCRIPTION")
-        popath <- dirname(paths[file.exists(paths)][1])
-    } else {
-    }
-#    bindtextdomain("R", popath)
-#    bindtextdomain("R-base", popath)
-    assign(".popath", popath, .BaseNamespaceEnv)
-})
-#local({
-### we distinguish between R_PAPERSIZE as set by the user and by configure
-#papersize <- Sys.getenv("R_PAPERSIZE_USER")
-#if(!nchar(papersize)) {
-#    lcpaper <- Sys.getlocale("LC_PAPER") # might be null: OK as nchar is 0
-#    papersize <- if(nchar(lcpaper))
-#        if(length(grep("(_US|_CA)", lcpaper))) "letter" else "a4"
-#    else Sys.getenv("R_PAPERSIZE")
-#}
-#options(papersize = papersize,
-#        printcmd = Sys.getenv("R_PRINTCMD"),
-#        dvipscmd = Sys.getenv("DVIPS", "dvips"),
-#        texi2dvi = Sys.getenv("R_TEXI2DVICMD"),
-#        browser = Sys.getenv("R_BROWSER"),
-#        pager = file.path(R.home(), "bin", "pager"),
-#        pdfviewer = Sys.getenv("R_PDFVIEWER"),
-#        useFancyQuotes = TRUE)
-#})
-#
-### non standard settings for the R.app GUI of the Mac OS X port
-#if(.Platform$GUI == "AQUA") {
-#    ## this is set to let RAqua use both X11 device and X11/TclTk
-#    if (Sys.getenv("DISPLAY") == "")
-#  Sys.setenv("DISPLAY" = ":0")
-#
-#    ## this is to allow gfortran compiler to work
-#    Sys.setenv("PATH" = paste(Sys.getenv("PATH"),":/usr/local/bin",sep = ""))
-#}## end "Aqua"
-## de-dupe the environment on OS X (bug in Yosemite which affects things like PATH)
-if (grepl("^darwin", R.version$os)) local({
-				## we have to de-dupe one at a time and re-check since the bug affects how
-				## environment modifications propagate
-				while(length(dupes <- names(Sys.getenv())[table(names(Sys.getenv())) > 1])) {
-					env <- dupes[1]
-					value <- Sys.getenv(env)
-					Sys.unsetenv(env)             ## removes the dupes, good
-					.Internal(Sys.setenv(env, value)) ## wrapper requries named vector, a pain, hence internal
-				}
-			})
-
-#
-#local({
-#    tests_startup <- Sys.getenv("R_TESTS")
-#    if(nzchar(tests_startup)) source(tests_startup)
-#})
diff --git a/com.oracle.truffle.r.native/library/base/src/darwin/base.tar.gz b/com.oracle.truffle.r.native/library/base/src/darwin/base.tar.gz
deleted file mode 100644
index 758dca1c28f113590c93216dcb456e6590752ff6..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/base/src/darwin/base.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/base/src/linux/base.tar.gz b/com.oracle.truffle.r.native/library/base/src/linux/base.tar.gz
deleted file mode 100644
index 2961c06cf4b8ab73fb687347b98caed6717e65a7..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/base/src/linux/base.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/datasets/src/darwin/datasets.tar.gz b/com.oracle.truffle.r.native/library/datasets/src/darwin/datasets.tar.gz
deleted file mode 100644
index cc4d521f82694d045cf631827eca11c4c37608ef..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/datasets/src/darwin/datasets.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/datasets/src/linux/datasets.tar.gz b/com.oracle.truffle.r.native/library/datasets/src/linux/datasets.tar.gz
deleted file mode 100644
index 070f281fa0c4c6bddb7e7ef30bf6871c12adc144..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/datasets/src/linux/datasets.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/grDevices/src/darwin/grDevices.tar.gz b/com.oracle.truffle.r.native/library/grDevices/src/darwin/grDevices.tar.gz
deleted file mode 100644
index 486f129ebbe91eb4492b4f805cd949efd7ad0988..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/grDevices/src/darwin/grDevices.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/grDevices/src/linux/grDevices.tar.gz b/com.oracle.truffle.r.native/library/grDevices/src/linux/grDevices.tar.gz
deleted file mode 100644
index fabc5a2174bd642871ddf35eb4be0ed8c59ae4bd..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/grDevices/src/linux/grDevices.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/graphics/src/darwin/graphics.tar.gz b/com.oracle.truffle.r.native/library/graphics/src/darwin/graphics.tar.gz
deleted file mode 100644
index 572f02598c7829ad9ce4135fc5fc71a325eaf7f8..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/graphics/src/darwin/graphics.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/graphics/src/linux/graphics.tar.gz b/com.oracle.truffle.r.native/library/graphics/src/linux/graphics.tar.gz
deleted file mode 100644
index 7f90fa5d90d6eab50c888781a646ca126c674dc0..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/graphics/src/linux/graphics.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk
index d0f1575f2303636ba86a39c7f5e6932f2baa0f0e..fdab1f1ade59e34076bb562086f2c494691cbb50 100644
--- a/com.oracle.truffle.r.native/library/lib.mk
+++ b/com.oracle.truffle.r.native/library/lib.mk
@@ -23,7 +23,7 @@
 
 # Common Makefile for creating FastR variants of the default packages
 # The common part of the archive (everything except the .so) is created
-# by untar'ing the comnressed archive (from GnuR). Then the FastR .so file is created
+# by copying the directory in the GnuR build. Then the FastR .so file is created
 # and overwrites the default. The libraries are stored in the directory denoted
 # FASTR_LIBDIR.
 
@@ -33,8 +33,12 @@ include ../../platform.mk
 
 PKG = $(PACKAGE)
 
+ifeq ($(GNUR_DIR),)
+$(error must be run from top-level)
+endif
+
 SRC = src
-OBJ = lib/$(OS_DIR)
+OBJ = lib
 
 C_SOURCES := $(wildcard $(SRC)/*.c)
 
@@ -63,8 +67,8 @@ endif
 
 libcommon: $(PKGDIR)
 
-$(PKGDIR): $(PKGTAR)
-	tar xf $(PKGTAR) -C $(FASTR_LIBDIR)
+$(PKGDIR): $(GNUR_DIR)/library/$(PKG)
+	(cd $(GNUR_DIR)/library; tar cf - $(PKG)) | (cd $(FASTR_LIBDIR); tar xf -)
 	touch $(FASTR_LIBDIR)/$(PKG)
 
 $(OBJ):
@@ -82,11 +86,7 @@ $(OBJ)/%.o: $(SRC)/%.c  $(H_SOURCES)
 $(OBJ)/%.o: $(SRC)/%.f
 	$(FC) $(CFLAGS) -c $< -o $@
 
-clean: cleanobj cleanlib
-
-cleanlib:
-	rm -f $(LIB_PKG)
-
-cleanobj:
-	rm -f $(LIBDIR)/*.o
+clean: 
+	rm -f $(LIBDIR)/*
+	rm -rf $(FASTR_LIBDIR)/$(PKG)
 
diff --git a/com.oracle.truffle.r.native/library/methods/src/darwin/methods.tar.gz b/com.oracle.truffle.r.native/library/methods/src/darwin/methods.tar.gz
deleted file mode 100644
index 6786f45d09465a41e97185926e80239096cbb4d3..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/methods/src/darwin/methods.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/methods/src/linux/methods.tar.gz b/com.oracle.truffle.r.native/library/methods/src/linux/methods.tar.gz
deleted file mode 100644
index 84985a89cdba351a6c3d475fd2f532616d3ce9b0..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/methods/src/linux/methods.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/stats/src/darwin/stats.tar.gz b/com.oracle.truffle.r.native/library/stats/src/darwin/stats.tar.gz
deleted file mode 100644
index 39580333dc98cc1a91fcd3e7cb8a25b3c4e58145..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/stats/src/darwin/stats.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/stats/src/linux/stats.tar.gz b/com.oracle.truffle.r.native/library/stats/src/linux/stats.tar.gz
deleted file mode 100644
index b6f263cf4d258bfcce280be44c5369dffd150d46..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/stats/src/linux/stats.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/tools/src/darwin/tools.tar.gz b/com.oracle.truffle.r.native/library/tools/src/darwin/tools.tar.gz
deleted file mode 100644
index 78545efb9e174cbf7c05c2b1c23e31291823522e..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/tools/src/darwin/tools.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/tools/src/linux/tools.tar.gz b/com.oracle.truffle.r.native/library/tools/src/linux/tools.tar.gz
deleted file mode 100644
index 664139ed758f43ff613bb0cce0acf6d88bf1d2a8..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/tools/src/linux/tools.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/utils/src/darwin/utils.tar.gz b/com.oracle.truffle.r.native/library/utils/src/darwin/utils.tar.gz
deleted file mode 100644
index a90d22baf9a3abe7faad13255860611b20a63ead..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/utils/src/darwin/utils.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.native/library/utils/src/linux/utils.tar.gz b/com.oracle.truffle.r.native/library/utils/src/linux/utils.tar.gz
deleted file mode 100644
index 56361665e8874f400af4ea7b8c1da4c818bd9123..0000000000000000000000000000000000000000
Binary files a/com.oracle.truffle.r.native/library/utils/src/linux/utils.tar.gz and /dev/null differ
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ForeignFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ForeignFunctions.java
index 311b43e344d2da928b78a3768578242a92e969e1..84ff98df525895bf6bdba6fcf914a02955129e12 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ForeignFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ForeignFunctions.java
@@ -101,7 +101,7 @@ public class ForeignFunctions {
                 int[] rank = rankVec.getDataTemp();
                 double[] qraux = qrauxVec.getDataTemp();
                 int[] pivot = pivotVec.getDataTemp();
-                RFFIFactory.getRFFI().getRDerivedRFFI().dqrdc2(x, ldx, n, p, tol, rank, qraux, pivot, workVec.getDataCopy());
+                RFFIFactory.getRFFI().getRApplRFFI().dqrdc2(x, ldx, n, p, tol, rank, qraux, pivot, workVec.getDataCopy());
                 // @formatter:off
                 Object[] data = new Object[]{
                             RDataFactory.createDoubleVector(x, RDataFactory.COMPLETE_VECTOR, xVec.getDimensions()),
@@ -144,7 +144,7 @@ public class ForeignFunctions {
                 double[] y = yVec.getDataTemp();
                 double[] b = bVec.getDataTemp();
                 int[] info = infoVec.getDataTemp();
-                RFFIFactory.getRFFI().getRDerivedRFFI().dqrcf(x, n, k.getDataAt(0), qraux, y, ny, b, info);
+                RFFIFactory.getRFFI().getRApplRFFI().dqrcf(x, n, k.getDataAt(0), qraux, y, ny, b, info);
                 RDoubleVector coef = RDataFactory.createDoubleVector(b, RDataFactory.COMPLETE_VECTOR);
                 coef.copyAttributesFrom(attrProfiles, bVec);
                 // @formatter:off
@@ -316,14 +316,14 @@ public class ForeignFunctions {
                 int[] maxp = new int[1];
                 if (noDims.profile(zVec.getDimensions() == null)) {
                     int n = zVec.getLength();
-                    RFFIFactory.getRFFI().getRDerivedRFFI().fft_factor(n, maxf, maxp);
+                    RFFIFactory.getRFFI().getStatsRFFI().fft_factor(n, maxf, maxp);
                     if (maxf[0] == 0) {
                         errorProfile.enter();
                         throw RError.error(getEncapsulatingSourceSection(), RError.Message.FFT_FACTORIZATION);
                     }
                     double[] work = new double[4 * maxf[0]];
                     int[] iwork = new int[maxp[0]];
-                    retCode = RFFIFactory.getRFFI().getRDerivedRFFI().fft_work(z, 1, n, 1, inv, work, iwork);
+                    retCode = RFFIFactory.getRFFI().getStatsRFFI().fft_work(z, 1, n, 1, inv, work, iwork);
                 } else {
                     int maxmaxf = 1;
                     int maxmaxp = 1;
@@ -332,7 +332,7 @@ public class ForeignFunctions {
                     /* do whole loop just for error checking and maxmax[fp] .. */
                     for (int i = 0; i < ndims; i++) {
                         if (d[i] > 1) {
-                            RFFIFactory.getRFFI().getRDerivedRFFI().fft_factor(d[i], maxf, maxp);
+                            RFFIFactory.getRFFI().getStatsRFFI().fft_factor(d[i], maxf, maxp);
                             if (maxf[0] == 0) {
                                 errorProfile.enter();
                                 throw RError.error(getEncapsulatingSourceSection(), RError.Message.FFT_FACTORIZATION);
@@ -355,8 +355,8 @@ public class ForeignFunctions {
                             nspn *= n;
                             n = d[i];
                             nseg /= n;
-                            RFFIFactory.getRFFI().getRDerivedRFFI().fft_factor(n, maxf, maxp);
-                            RFFIFactory.getRFFI().getRDerivedRFFI().fft_work(z, nseg, n, nspn, inv, work, iwork);
+                            RFFIFactory.getRFFI().getStatsRFFI().fft_factor(n, maxf, maxp);
+                            RFFIFactory.getRFFI().getStatsRFFI().fft_work(z, nseg, n, nspn, inv, work, iwork);
                         }
                     }
 
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java
index 26542304b672787192b65b7d54c519cbd81d38d7..c7a8271ed49d647523cc9d57ba83fb09737c8f83 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java
@@ -1,24 +1,13 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * This material is distributed under the GNU General Public License
+ * Version 2. You may review the terms of this license at
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
- * 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.
+ * Copyright (c) 1995-2015, The R Core Team
+ * Copyright (c) 2003, The R Foundation
+ * Copyright (c) 2015, Oracle and/or its affiliates
  *
- * 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.
+ * All rights reserved.
  */
 package com.oracle.truffle.r.nodes.builtin.base;
 
@@ -29,20 +18,35 @@ import java.util.regex.*;
 
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.dsl.*;
-import com.oracle.truffle.api.utilities.*;
 import com.oracle.truffle.r.nodes.builtin.*;
 import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.data.*;
 import com.oracle.truffle.r.runtime.data.model.*;
+import com.oracle.truffle.r.runtime.ffi.*;
 import com.oracle.truffle.r.runtime.ops.na.*;
 
 /**
- * {@code grep} in all its variants. Nothing in here merits being Truffle optimized.
+ * {@code grep} in all its variants. No usages in the general case merits being Truffle optimized,
+ * so everything is behind {@link TruffleBoundary}. It is possible that some special cases might
+ * show up on a hot path and be worthy of a custom specialization.
+ * <p>
+ * TODO implement all the options, in particular perl support for all functions.
+ * <p>
+ * A note on {@code useBytes}. We are currently ignoring this option completely. It's all related to
+ * locales and multi-byte character representations of non-ASCII locales. Since Java represents
+ * Unicode directly in strings and characters, it's not entirely clear what we should do but, since
+ * we are generally ignoring this issue everywhere in the code base, we are effectively assuming
+ * ASCII.
+ * <p>
+ * Parts of this code, notably the perl support, were translated from GnuR grep.c.
  */
 public class GrepFunctions {
     public abstract static class CommonCodeAdapter extends RBuiltinNode {
 
-        private final BranchProfile errorProfile = BranchProfile.create();
+        /**
+         * This profile is needed to satisfy API requirements.
+         */
+        protected final RAttributeProfiles attrProfiles = RAttributeProfiles.create();
 
         /**
          * Temporary method that handles the check for the arguments that are common to the majority
@@ -50,14 +54,39 @@ public class GrepFunctions {
          * then an NYI error will be thrown (in the first one). If any of the arguments do not
          * apply, pass {@link RRuntime#LOGICAL_FALSE}.
          */
-        protected void checkExtraArgs(byte ignoreCase, byte perl, byte fixed, byte useBytes, byte invert) {
+        protected void checkExtraArgs(byte ignoreCase, byte perl, byte fixed, @SuppressWarnings("unused") byte useBytes, byte invert) {
             checkNotImplemented(RRuntime.fromLogical(ignoreCase), "ignoreCase", true);
             checkNotImplemented(RRuntime.fromLogical(perl), "perl", true);
             checkNotImplemented(RRuntime.fromLogical(fixed), "fixed", true);
-            checkNotImplemented(RRuntime.fromLogical(useBytes), "useBytes", true);
+            // We just ignore useBytes
+            // checkNotImplemented(RRuntime.fromLogical(useBytes), "useBytes", true);
             checkNotImplemented(RRuntime.fromLogical(invert), "invert", true);
         }
 
+        protected void checkCaseFixed(boolean ignoreCase, boolean fixed) {
+            if (ignoreCase && fixed) {
+                RError.warning(getEncapsulatingSourceSection(), RError.Message.ARGUMENT_IGNORED, "ignore.case = TRUE");
+            }
+        }
+
+        protected boolean checkPerlFixed(boolean perl, boolean fixed) {
+            if (fixed && perl) {
+                RError.warning(getEncapsulatingSourceSection(), RError.Message.ARGUMENT_IGNORED, "perl = TRUE");
+                return false;
+            } else {
+                return perl;
+            }
+        }
+
+        protected String checkLength(RAbstractStringVector arg, String name) {
+            if (arg.getLength() < 1) {
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_ARGUMENT, name);
+            } else if (arg.getLength() > 1) {
+                RError.warning(getEncapsulatingSourceSection(), RError.Message.ARGUMENT_ONLY_FIRST, name);
+            }
+            return arg.getDataAt(0);
+        }
+
         /**
          * Temporary check for the {@code value} argument, which is only applicable to {@code grep}
          * and {@code agrep} (so not included in {@code checkExtraArgs}.
@@ -66,14 +95,12 @@ public class GrepFunctions {
          */
         protected void valueCheck(byte value) {
             if (RRuntime.fromLogical(value)) {
-                errorProfile.enter();
                 throw RError.nyi(getEncapsulatingSourceSection(), "value == true is not implemented");
             }
         }
 
         protected void checkNotImplemented(boolean condition, String arg, boolean b) {
             if (condition) {
-                errorProfile.enter();
                 throw RError.nyi(getEncapsulatingSourceSection(), arg + " == " + b + " not implemented");
             }
         }
@@ -93,186 +120,251 @@ public class GrepFunctions {
             }
         }
 
-        protected String[] trimStringResult(String[] tmp, int numMatches, int vecLength) {
-            if (numMatches == 0) {
-                return null;
-            } else if (numMatches == vecLength) {
-                return tmp;
-            } else {
-                // trim array to the appropriate size
-                String[] result = new String[numMatches];
-                for (int i = 0; i < result.length; i++) {
-                    result[i] = tmp[i];
-                }
-                return result;
-            }
-        }
-
         protected boolean isTrue(byte fixed) {
             return RRuntime.fromLogical(fixed);
         }
 
-    }
-
-    @RBuiltin(name = "grep", kind = INTERNAL, parameterNames = {"pattern", "x", "ignore.case", "perl", "value", "fixed", "useBytes", "invert"})
-    public abstract static class Grep extends CommonCodeAdapter {
+        protected RStringVector allStringNAResult(int len) {
+            String[] naData = new String[len];
+            for (int i = 0; i < len; i++) {
+                naData[i] = RRuntime.STRING_NA;
+            }
+            return RDataFactory.createStringVector(naData, RDataFactory.INCOMPLETE_VECTOR);
+        }
 
-        public static boolean isNAAndPerl(RAbstractStringVector vector, byte perl) {
-            return vector.getLength() == 1 && RRuntime.isNA(vector.getDataAt(0)) && perl == RRuntime.LOGICAL_TRUE;
+        protected RIntVector allIntNAResult(int len) {
+            int[] naData = new int[len];
+            for (int i = 0; i < len; i++) {
+                naData[i] = RRuntime.INT_NA;
+            }
+            return RDataFactory.createIntVector(naData, RDataFactory.INCOMPLETE_VECTOR);
         }
 
-        @Specialization(guards = "!isTrue(value)")
-        @TruffleBoundary
-        protected RIntVector grepValueFalse(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCase, @SuppressWarnings("unused") byte value, byte perl, byte fixed,
-                        byte useBytes, byte invert) {
+    }
+
+    private abstract static class GrepAdapter extends CommonCodeAdapter {
+        protected Object doGrep(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCaseLogical, byte valueLogical, byte perlLogical, byte fixedLogical,
+                        @SuppressWarnings("unused") byte useBytes, byte invertLogical, boolean grepl) {
             controlVisibility();
-            // HACK to finesse lack of perl==TRUE in utils::localeToCharset (on Linux)
-            if (isNAAndPerl(vector, perl)) {
-                return RDataFactory.createEmptyIntVector();
-            }
-            String patternArg = patternArgVec.getDataAt(0);
-            checkExtraArgs(ignoreCase, perl, RRuntime.LOGICAL_FALSE, useBytes, invert);
-            String pattern = fixed == RRuntime.LOGICAL_TRUE ? patternArg : RegExp.checkPreDefinedClasses(patternArg);
-            int[] result = findAllIndexes(pattern, vector, fixed);
-            if (result == null) {
-                return RDataFactory.createEmptyIntVector();
+            boolean value = RRuntime.fromLogical(valueLogical);
+            boolean invert = RRuntime.fromLogical(invertLogical);
+            boolean perl = RRuntime.fromLogical(perlLogical);
+            boolean ignoreCase = RRuntime.fromLogical(ignoreCaseLogical);
+            checkNotImplemented(!perl && ignoreCase, "ignoreCase", true);
+            boolean fixed = RRuntime.fromLogical(fixedLogical);
+            perl = checkPerlFixed(RRuntime.fromLogical(perlLogical), fixed);
+            checkCaseFixed(ignoreCase, fixed);
+            checkNotImplemented(invert, "invert", true);
+
+            String pattern = checkLength(patternArgVec, "pattern");
+            int len = vector.getLength();
+            if (RRuntime.isNA(pattern)) {
+                return value ? allStringNAResult(len) : allIntNAResult(len);
+            }
+            boolean[] matches = new boolean[len];
+            if (fixed && !perl) {
+                // TODO case
+                if (!fixed) {
+                    pattern = RegExp.checkPreDefinedClasses(pattern);
+                }
+                findAllMatches(matches, pattern, vector, fixed);
             } else {
-                return RDataFactory.createIntVector(result, RDataFactory.COMPLETE_VECTOR);
+                int cflags = ignoreCase ? PCRERFFI.CASELESS : 0;
+                long tables = RFFIFactory.getRFFI().getPCRERFFI().maketables();
+                PCRERFFI.Result pcre = RFFIFactory.getRFFI().getPCRERFFI().compile(pattern, cflags, tables);
+                if (pcre.result == 0) {
+                    // TODO output warning if pcre.errorMessage not NULL
+                    throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_REGEXP, pattern);
+                }
+                // TODO pcre_study for vectors > 10 ? (cf GnuR)
+                int[] ovector = new int[30];
+                for (int i = 0; i < len; i++) {
+                    String text = vector.getDataAt(i);
+                    if (!RRuntime.isNA(text)) {
+                        if (RFFIFactory.getRFFI().getPCRERFFI().exec(pcre.result, 0, text, 0, 0, ovector) >= 0) {
+                            matches[i] = true;
+                        }
+                    }
+                }
             }
-        }
 
-        protected int[] findAllIndexes(String pattern, RAbstractStringVector vector, byte fixed) {
-            int[] tmp = new int[vector.getLength()];
-            int numMatches = 0;
-            int ind = 0;
-            for (int i = 0; i < vector.getLength(); i++) {
-                String text = vector.getDataAt(i);
-                if (fixed == RRuntime.LOGICAL_TRUE ? text.contains(pattern) : findIndex(pattern, text)) {
-                    numMatches++;
-                    tmp[ind++] = i + 1;
+            if (grepl) {
+                byte[] data = new byte[len];
+                for (int i = 0; i < len; i++) {
+                    data[i] = RRuntime.asLogical(matches[i]);
                 }
+                return RDataFactory.createLogicalVector(data, RDataFactory.COMPLETE_VECTOR);
             }
-            return trimIntResult(tmp, numMatches, vector.getLength());
-        }
 
-        protected static boolean findIndex(String pattern, String text) {
-            Matcher m = Regexp.getPatternMatcher(pattern, text);
-            if (m.find()) {
-                return true;
-            } else {
-                return false;
+            int nmatches = 0;
+            for (int i = 0; i < len; i++) {
+                if (invert ^ matches[i]) {
+                    nmatches++;
+                }
             }
-        }
 
-        @Specialization(guards = "isTrue(value)")
-        @TruffleBoundary
-        protected RStringVector grepValueTrue(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCase, @SuppressWarnings("unused") byte value, byte perl, byte fixed,
-                        byte useBytes, byte invert) {
-            controlVisibility();
-            checkExtraArgs(ignoreCase, perl, RRuntime.LOGICAL_FALSE, useBytes, invert);
-            String patternArg = patternArgVec.getDataAt(0);
-            String pattern = fixed == RRuntime.LOGICAL_TRUE ? patternArg : RegExp.checkPreDefinedClasses(patternArg);
-            String[] result = findAllMatches(pattern, vector, fixed);
-            if (result == null) {
-                return RDataFactory.createEmptyStringVector();
+            if (nmatches == 0) {
+                return value ? RDataFactory.createEmptyStringVector() : RDataFactory.createEmptyIntVector();
             } else {
-                return RDataFactory.createStringVector(result, RDataFactory.COMPLETE_VECTOR);
+                if (value) {
+                    RStringVector oldNames = vector.getNames(attrProfiles);
+                    String[] newNames = null;
+                    if (oldNames != null) {
+                        newNames = new String[nmatches];
+                    }
+                    String[] data = new String[nmatches];
+                    int j = 0;
+                    for (int i = 0; i < len; i++) {
+                        if (invert ^ matches[i]) {
+                            if (newNames != null) {
+                                newNames[j] = oldNames.getDataAt(i);
+                            }
+                            data[j++] = vector.getDataAt(i);
+                        }
+                    }
+                    return RDataFactory.createStringVector(data, RDataFactory.COMPLETE_VECTOR, newNames == null ? null : RDataFactory.createStringVector(newNames, RDataFactory.COMPLETE_VECTOR));
+                } else {
+                    int[] data = new int[nmatches];
+                    int j = 0;
+                    for (int i = 0; i < len; i++) {
+                        if (invert ^ matches[i]) {
+                            data[j++] = i + 1;
+                        }
+                    }
+                    return RDataFactory.createIntVector(data, RDataFactory.COMPLETE_VECTOR);
+                }
             }
         }
 
-        protected String[] findAllMatches(String pattern, RAbstractStringVector vector, byte fixed) {
-            String[] tmp = new String[vector.getLength()];
-            int numMatches = 0;
-            int ind = 0;
-            for (int i = 0; i < vector.getLength(); i++) {
+        protected void findAllMatches(boolean[] result, String pattern, RAbstractStringVector vector, boolean fixed) {
+            for (int i = 0; i < result.length; i++) {
                 String text = vector.getDataAt(i);
-                String match;
-                if (fixed == RRuntime.LOGICAL_TRUE) {
-                    match = text.contains(pattern) ? text : null;
-                } else {
-                    match = findMatch(pattern, text);
-                }
-                if (match != null) {
-                    numMatches++;
-                    tmp[ind++] = match;
+                if (!RRuntime.isNA(text)) {
+                    if (fixed) {
+                        result[i] = text.contains(pattern);
+                    } else {
+                        result[i] = findMatch(pattern, text);
+                    }
                 }
             }
-            return trimStringResult(tmp, numMatches, vector.getLength());
         }
 
-        protected static String findMatch(String pattern, String text) {
+        protected static boolean findMatch(String pattern, String text) {
             Matcher m = Regexp.getPatternMatcher(pattern, text);
-            if (m.find()) {
-                return text;
-            } else {
-                return null;
-            }
+            return m.find();
         }
 
     }
 
-    @RBuiltin(name = "grepl", kind = INTERNAL, parameterNames = {"pattern", "x", "ignore.case", "value", "perl", "fixed", "useBytes", "invert"})
-    // invert is passed but is always FALSE
-    public abstract static class GrepL extends CommonCodeAdapter {
+    @RBuiltin(name = "grep", kind = INTERNAL, parameterNames = {"pattern", "x", "ignore.case", "perl", "value", "fixed", "useBytes", "invert"})
+    public abstract static class Grep extends GrepAdapter {
 
-        @Specialization(guards = "!isTrue(fixed)")
         @TruffleBoundary
-        @SuppressWarnings("unused")
-        protected Object grepl(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCase, byte value, byte perl, byte fixed, byte useBytes, byte invert) {
-            controlVisibility();
-            checkExtraArgs(ignoreCase, perl, RRuntime.LOGICAL_FALSE, useBytes, RRuntime.LOGICAL_FALSE);
-            String pattern = RegExp.checkPreDefinedClasses(patternArgVec.getDataAt(0));
-            byte[] data = new byte[vector.getLength()];
-            for (int i = 0; i < vector.getLength(); i++) {
-                data[i] = RRuntime.asLogical(Grep.findIndex(pattern, vector.getDataAt(i)));
-            }
-            return RDataFactory.createLogicalVector(data, RDataFactory.COMPLETE_VECTOR);
+        @Specialization
+        protected Object grepValueFalse(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCaseLogical, byte valueLogical, byte perlLogical, byte fixedLogical,
+                        byte useBytes, byte invertLogical) {
+            return doGrep(patternArgVec, vector, ignoreCaseLogical, valueLogical, perlLogical, fixedLogical, useBytes, invertLogical, false);
         }
+    }
 
-        @Specialization(guards = "isTrue(fixed)")
+    @RBuiltin(name = "grepl", kind = INTERNAL, parameterNames = {"pattern", "x", "ignore.case", "value", "perl", "fixed", "useBytes", "invert"})
+    public abstract static class GrepL extends GrepAdapter {
+
+        @Specialization
         @TruffleBoundary
-        @SuppressWarnings("unused")
-        protected Object greplFixed(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCase, byte value, byte perl, byte fixed, byte useBytes, byte invert) {
-            controlVisibility();
-            checkExtraArgs(ignoreCase, perl, RRuntime.LOGICAL_FALSE, useBytes, RRuntime.LOGICAL_FALSE);
-            byte[] data = new byte[vector.getLength()];
-            for (int i = 0; i < vector.getLength(); i++) {
-                data[i] = RRuntime.asLogical(vector.getDataAt(i).contains(patternArgVec.getDataAt(0)));
-            }
-            return RDataFactory.createLogicalVector(data, RDataFactory.COMPLETE_VECTOR);
+        protected Object grepl(RAbstractStringVector patternArgVec, RAbstractStringVector vector, byte ignoreCaseLogical, byte valueLogical, byte perlLogical, byte fixedLogical, byte useBytes,
+                        byte invertLogical) {
+            // invert is passed but is always FALSE
+            return doGrep(patternArgVec, vector, ignoreCaseLogical, valueLogical, perlLogical, fixedLogical, useBytes, invertLogical, true);
         }
-
     }
 
     protected abstract static class SubAdapter extends CommonCodeAdapter {
-        private final ConditionProfile fixedProfile = ConditionProfile.createBinaryProfile();
-        private final ConditionProfile gsubProfile = ConditionProfile.createBinaryProfile();
-        private final RAttributeProfiles attrProfiles = RAttributeProfiles.create();
-
-        protected RStringVector doSub(RAbstractStringVector patternArgVec, RAbstractStringVector replacementVec, RAbstractStringVector vector, boolean fixed, boolean gsub) {
-            // FIXME print a warning that only pattern[1] is used
-            String pattern;
-            if (fixedProfile.profile((fixed))) {
-                pattern = patternArgVec.getDataAt(0);
+
+        protected RStringVector doSub(RAbstractStringVector patternArgVec, RAbstractStringVector replacementVec, RAbstractStringVector vector, byte ignoreCaseLogical, byte perlLogical,
+                        byte fixedLogical, @SuppressWarnings("unused") byte useBytes, boolean gsub) {
+            boolean perl = RRuntime.fromLogical(perlLogical);
+            boolean fixed = RRuntime.fromLogical(fixedLogical);
+            boolean ignoreCase = RRuntime.fromLogical(ignoreCaseLogical);
+            checkNotImplemented(!(perl || fixed) && ignoreCase, "ignoreCase", true);
+            checkCaseFixed(ignoreCase, fixed);
+            perl = checkPerlFixed(perl, fixed);
+            String pattern = checkLength(patternArgVec, "pattern");
+            String replacement = checkLength(replacementVec, "replacement");
+
+            int len = vector.getLength();
+            if (RRuntime.isNA(pattern)) {
+                return allStringNAResult(len);
+            }
+
+            PCRERFFI.Result pcre = null;
+            if (fixed) {
+                // TODO case
+            } else if (perl) {
+                int cflags = ignoreCase ? PCRERFFI.CASELESS : 0;
+                long tables = RFFIFactory.getRFFI().getPCRERFFI().maketables();
+                pcre = RFFIFactory.getRFFI().getPCRERFFI().compile(pattern, cflags, tables);
+                if (pcre.result == 0) {
+                    // TODO output warning if pcre.errorMessage not NULL
+                    throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_REGEXP, pattern);
+                }
+                // TODO pcre_study for vectors > 10 ? (cf GnuR)
             } else {
-                pattern = RegExp.checkPreDefinedClasses(patternArgVec.getDataAt(0));
+                pattern = RegExp.checkPreDefinedClasses(pattern);
             }
-            String replacement = replacementVec.getDataAt(0);
-            int len = vector.getLength();
             String[] result = new String[len];
             for (int i = 0; i < len; i++) {
                 String input = vector.getDataAt(i);
+                if (RRuntime.isNA(input)) {
+                    result[i] = input;
+                    continue;
+                }
+
                 String value;
-                if (fixedProfile.profile((fixed))) {
-                    if (gsubProfile.profile(gsub)) {
+                if (fixed) {
+                    if (gsub) {
                         value = input.replace(pattern, replacement);
                     } else {
                         int ix = input.indexOf(pattern);
                         value = ix < 0 ? pattern : input.substring(0, ix) + replacement + input.substring(ix + 1);
                     }
+                } else if (perl) {
+                    int offset = 0;
+                    int[] ovector = new int[30];
+                    int nmatch = 0;
+                    int eflag = 0;
+                    int lastEnd = -1;
+                    StringBuffer sb = new StringBuffer();
+                    while (RFFIFactory.getRFFI().getPCRERFFI().exec(pcre.result, 0, input, offset, eflag, ovector) >= 0) {
+                        nmatch++;
+                        for (int j = offset; j < ovector[0]; j++) {
+                            sb.append(input.charAt(j));
+                        }
+                        if (ovector[1] > lastEnd) {
+                            pcreStringAdj(sb, input, replacement, ovector);
+                            lastEnd = ovector[1];
+                        }
+                        offset = ovector[1];
+                        if (offset >= input.length() || !gsub) {
+                            break;
+                        }
+                        if (ovector[0] == ovector[1]) {
+                            sb.append(input.charAt(offset++));
+                        }
+                        eflag |= PCRERFFI.NOTBOL;
+                    }
+                    if (nmatch == 0) {
+                        value = input;
+                    } else {
+                        /* copy the tail */
+                        for (int j = offset; j < input.length(); j++) {
+                            sb.append(input.charAt(j));
+                        }
+                        value = sb.toString();
+                    }
                 } else {
                     replacement = convertGroups(replacement);
-                    if (gsubProfile.profile(gsub)) {
+                    if (gsub) {
                         value = input.replaceAll(pattern, replacement);
                     } else {
                         value = input.replaceFirst(pattern, replacement);
@@ -285,6 +377,39 @@ public class GrepFunctions {
             return ret;
         }
 
+        private static void pcreStringAdj(StringBuffer sb, String input, String repl, int[] ovector) {
+            boolean upper = false;
+            boolean lower = false;
+            int px = 0;
+            while (px < repl.length()) {
+                char p = repl.charAt(px++);
+                if (p == '\\') {
+                    char p1 = repl.charAt(px++);
+                    if (p1 >= '1' && p1 <= '9') {
+                        int k = p1 - '0';
+                        for (int i = ovector[2 * k]; i < ovector[2 * k + 1]; i++) {
+                            char c = input.charAt(i);
+                            sb.append(upper ? Character.toUpperCase(c) : (lower ? Character.toLowerCase(c) : c));
+                        }
+
+                    } else if (p1 == 'U') {
+                        upper = true;
+                        lower = false;
+                    } else if (p1 == 'L') {
+                        upper = false;
+                        lower = true;
+                    } else if (p1 == 'E') {
+                        upper = false;
+                        lower = false;
+                    } else {
+                        sb.append(p);
+                    }
+                } else {
+                    sb.append(p);
+                }
+            }
+        }
+
         @TruffleBoundary
         private static String convertGroups(String value) {
             int x = 0;
@@ -325,10 +450,10 @@ public class GrepFunctions {
 
         @Specialization
         @TruffleBoundary
-        protected RStringVector subRegexp(RAbstractStringVector patternArgVec, RAbstractStringVector replacementVec, RAbstractStringVector x, byte ignoreCase, byte perl, byte fixed, byte useBytes) {
+        protected RStringVector subRegexp(RAbstractStringVector patternArgVec, RAbstractStringVector replacementVec, RAbstractStringVector x, byte ignoreCaseLogical, byte perlLogical,
+                        byte fixedLogical, byte useBytes) {
             controlVisibility();
-            checkExtraArgs(ignoreCase, perl, fixed, useBytes, RRuntime.LOGICAL_FALSE);
-            return doSub(patternArgVec, replacementVec, x, RRuntime.fromLogical(fixed), false);
+            return doSub(patternArgVec, replacementVec, x, ignoreCaseLogical, perlLogical, fixedLogical, useBytes, false);
         }
     }
 
@@ -337,10 +462,10 @@ public class GrepFunctions {
 
         @Specialization
         @TruffleBoundary
-        protected RStringVector gsub(RAbstractStringVector patternArgVec, RAbstractStringVector replacementVec, RAbstractStringVector x, byte ignoreCase, byte perl, byte fixed, byte useBytes) {
+        protected RStringVector gsub(RAbstractStringVector patternArgVec, RAbstractStringVector replacementVec, RAbstractStringVector x, byte ignoreCaseLogical, byte perlLogical, byte fixedLogical,
+                        byte useBytes) {
             controlVisibility();
-            checkExtraArgs(ignoreCase, perl, fixed, useBytes, RRuntime.LOGICAL_FALSE);
-            return doSub(patternArgVec, replacementVec, x, RRuntime.fromLogical(fixed), true);
+            return doSub(patternArgVec, replacementVec, x, ignoreCaseLogical, perlLogical, fixedLogical, useBytes, true);
         }
 
     }
@@ -536,26 +661,55 @@ public class GrepFunctions {
     public abstract static class Strsplit extends CommonCodeAdapter {
 
         private final NACheck na = NACheck.create();
-        private final ConditionProfile emptySplitProfile = ConditionProfile.createBinaryProfile();
-        private final RAttributeProfiles attrProfiles = RAttributeProfiles.create();
 
         @Specialization
-        protected RList split(RAbstractStringVector x, RAbstractStringVector split, byte fixed, byte perl, byte useBytes) {
+        @TruffleBoundary
+        protected RList split(RAbstractStringVector x, RAbstractStringVector splitArg, byte fixedLogical, byte perlLogical, @SuppressWarnings("unused") byte useBytes) {
             controlVisibility();
-            checkExtraArgs(RRuntime.LOGICAL_FALSE, perl, RRuntime.LOGICAL_FALSE, useBytes, RRuntime.LOGICAL_FALSE);
+            boolean fixed = RRuntime.fromLogical(fixedLogical);
+            boolean perl = checkPerlFixed(RRuntime.fromLogical(perlLogical), fixed);
             RStringVector[] result = new RStringVector[x.getLength()];
-            na.enable(x);
+            // treat split = NULL as split = ""
+            RAbstractStringVector split = splitArg.getLength() == 0 ? RDataFactory.createStringVectorFromScalar("") : splitArg;
             String[] splits = new String[split.getLength()];
+            long pcreTables = perl ? RFFIFactory.getRFFI().getPCRERFFI().maketables() : 0;
+            PCRERFFI.Result[] pcreSplits = perl ? new PCRERFFI.Result[splits.length] : null;
+
+            na.enable(x);
             for (int i = 0; i < splits.length; i++) {
-                splits[i] = fixed == RRuntime.LOGICAL_TRUE ? split.getDataAt(i) : RegExp.checkPreDefinedClasses(split.getDataAt(i));
+                String currentSplit = split.getDataAt(i);
+                splits[i] = fixed || perl ? split.getDataAt(i) : RegExp.checkPreDefinedClasses(split.getDataAt(i));
+                if (perl) {
+                    if (!currentSplit.isEmpty()) {
+                        pcreSplits[i] = RFFIFactory.getRFFI().getPCRERFFI().compile(currentSplit, 0, pcreTables);
+                        if (pcreSplits[i].result == 0) {
+                            // TODO output warning if pcre.errorMessage not NULL
+                            throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_REGEXP, currentSplit);
+                        }
+                        // TODO pcre_study for vectors > 10 ? (cf GnuR)
+                    }
+                }
             }
             for (int i = 0; i < x.getLength(); ++i) {
                 String data = x.getDataAt(i);
                 String currentSplit = splits[i % splits.length];
-                if (emptySplitProfile.profile(currentSplit.isEmpty())) {
+                if (currentSplit.isEmpty()) {
                     result[i] = na.check(data) ? RDataFactory.createNAStringVector() : emptySplitIntl(data);
+                } else if (RRuntime.isNA(currentSplit)) {
+                    // NA doesn't split
+                    result[i] = RDataFactory.createStringVectorFromScalar(data);
                 } else {
-                    result[i] = na.check(data) ? RDataFactory.createNAStringVector() : splitIntl(data, currentSplit);
+                    RStringVector resultItem;
+                    if (na.check(data)) {
+                        resultItem = RDataFactory.createNAStringVector();
+                    } else {
+                        if (perl) {
+                            resultItem = splitPerl(data, pcreSplits[i % splits.length]);
+                        } else {
+                            resultItem = splitIntl(data, currentSplit);
+                        }
+                    }
+                    result[i] = resultItem;
                 }
             }
             RList ret = RDataFactory.createList(result);
@@ -565,7 +719,6 @@ public class GrepFunctions {
             return ret;
         }
 
-        @TruffleBoundary
         private static RStringVector splitIntl(String input, String separator) {
             assert !RRuntime.isNA(input);
             return RDataFactory.createStringVector(input.split(separator), true);
@@ -579,6 +732,29 @@ public class GrepFunctions {
             }
             return RDataFactory.createStringVector(result, true);
         }
+
+        private static RStringVector splitPerl(String data, PCRERFFI.Result pcre) {
+            ArrayList<String> matches = new ArrayList<>();
+            int offset = 0;
+            int[] ovector = new int[30];
+            while (RFFIFactory.getRFFI().getPCRERFFI().exec(pcre.result, 0, data, offset, 0, ovector) >= 0) {
+                String match;
+                if (ovector[1] > 0) {
+                    match = data.substring(offset, ovector[0]);
+                    offset = ovector[1];
+                } else {
+                    match = data.substring(offset, offset + 1);
+                    offset++;
+                }
+                matches.add(match);
+            }
+            if (offset < data.length()) {
+                matches.add(data.substring(offset));
+            }
+            String[] result = new String[matches.size()];
+            matches.toArray(result);
+            return RDataFactory.createStringVector(result, RDataFactory.COMPLETE_VECTOR);
+        }
     }
 
 }
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java
index 3efcb94dc3f5f37cfbe6a8406172b0ebbdfab0c8..c13f88b95de3d20c5167c028f4658c8522dc55e3 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java
@@ -38,37 +38,58 @@ public class LocaleFunctions {
 
         @TruffleBoundary
         @Specialization
-        protected Object getLocal(RAbstractIntVector categoryVec) {
+        protected Object getLocale(RAbstractIntVector categoryVec) {
             controlVisibility();
+            // TODO implement all: for now just return not available (NULL)
             int category = categoryVec.getDataAt(0);
             switch (category) {
                 case 3: // "LC_CTYPE",
                     return RDataFactory.createStringVector(Charset.defaultCharset().name());
                 case 1: // "LC_ALL"
+                    break;
                 case 2: // "LC_COLLATE"
+                    break;
                 case 4: // "LC_MONETARY"
+                    break;
                 case 5: // "LC_NUMERIC"
+                    break;
                 case 6: // "LC_TIME"
+                    break;
                 case 7: // "LC_MESSAGES"
+                    break;
                 case 8: // "LC_PAPER"
+                    return RDataFactory.createStringVectorFromScalar("");
                 case 9: // "LC_MEASUREMENT"
+                    break;
                 default:
-                    RError.nyi(getEncapsulatingSourceSection(), "category not implemented: " + category);
-
+                    throw RInternalError.shouldNotReachHere();
             }
             return RNull.instance;
         }
 
     }
 
-    @RBuiltin(name = "Sys.setlocale", kind = RBuiltinKind.INTERNAL, parameterNames = {"category, locale"})
+    @RBuiltin(name = "Sys.setlocale", kind = RBuiltinKind.INTERNAL, parameterNames = {"category", "locale"})
     public abstract static class SetLocale extends RBuiltinNode {
 
+        @SuppressWarnings("unused")
         @TruffleBoundary
         @Specialization
-        protected Object setLocal(@SuppressWarnings("unused") RAbstractStringVector category) {
+        protected Object setLocale(RAbstractIntVector categoryVec, RAbstractStringVector locale) {
             controlVisibility();
-            RError.nyi(getEncapsulatingSourceSection(), "setlocale");
+            // TODO implement properly!!
+            return locale;
+        }
+    }
+
+    @RBuiltin(name = "Sys.localeconv", kind = RBuiltinKind.INTERNAL, parameterNames = {})
+    public abstract static class LocaleConv extends RBuiltinNode {
+
+        @TruffleBoundary
+        @Specialization
+        protected Object localeconv() {
+            controlVisibility();
+            RError.nyi(getEncapsulatingSourceSection(), "localeconv");
             return RNull.instance;
         }
     }
@@ -87,4 +108,32 @@ public class LocaleFunctions {
             return RDataFactory.createList(data, NAMES);
         }
     }
+
+    @RBuiltin(name = "enc2native", kind = RBuiltinKind.PRIMITIVE, parameterNames = "x")
+    public abstract static class Enc2Native extends RBuiltinNode {
+        @Specialization
+        protected Object enc2Native(RAbstractStringVector x) {
+            // TODO implement properly
+            return x;
+        }
+    }
+
+    @RBuiltin(name = "enc2utf8", kind = RBuiltinKind.PRIMITIVE, parameterNames = "x")
+    public abstract static class Enc2Utf8 extends RBuiltinNode {
+        @Specialization
+        protected Object enc2Native(RAbstractStringVector x) {
+            // TODO implement properly
+            return x;
+        }
+    }
+
+    @RBuiltin(name = "bindtextdomain", kind = RBuiltinKind.PRIMITIVE, parameterNames = {"domain", "dirname"})
+    public abstract static class BindTextDomain extends RBuiltinNode {
+        @SuppressWarnings("unused")
+        @Specialization
+        protected RNull bindtextdomain(RAbstractStringVector domain, Object dirname) {
+            // TODO implement properly
+            return RNull.instance;
+        }
+    }
 }
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SysFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SysFunctions.java
index d51dd89ce27036250c4020c1c58d594d355ded75..2ac2dbe59d3dcd38c0f9e6b1b08e23a0bf82dd27 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SysFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SysFunctions.java
@@ -324,29 +324,32 @@ public class SysFunctions {
             FileSystem fileSystem = FileSystems.getDefault();
             for (int i = 0; i < pathVec.getLength(); i++) {
                 String pathPattern = pathVec.getDataAt(i);
-                if (pathPattern.length() == 0) {
+                if (pathPattern.length() == 0 || RRuntime.isNA(pathPattern)) {
                     continue;
                 }
-                @SuppressWarnings("unused")
-                int firstGlobChar;
-                if ((firstGlobChar = containsGlobChar(pathPattern)) >= 0) {
+                pathPattern = Utils.tildeExpand(pathPattern);
+                if (containsGlobChar(pathPattern) >= 0) {
                     Path path = fileSystem.getPath(pathPattern);
-                    ArrayList<Path> components = components(path);
-                    if (components.size() > 1) {
-                        // No easy way to do this in a single shot
-                        throw RError.nyi(getEncapsulatingSourceSection(), " glob on dir");
-                    } else {
-                        try (Stream<Path> stream = Files.find(fileSystem.getPath(""), 1, new FileMatcher(pathPattern))) {
-                            Iterator<Path> iter = stream.iterator();
-                            while (iter.hasNext()) {
-                                String s = iter.next().getFileName().toString();
-                                if (s.length() > 0) {
-                                    matches.add(s);
-                                }
+                    Path root = path.getRoot();
+                    /*
+                     * Searching from the root can be super-expensive and hit unreadable directories
+                     * and we only need to start from the path containing the the first glob
+                     * character.
+                     */
+                    if (root != null) {
+                        root = findLowerStart(path);
+                    }
+                    try (Stream<Path> stream = Files.find(root != null ? root : fileSystem.getPath(""), path.getNameCount(), new FileMatcher(pathPattern))) {
+                        Iterator<Path> iter = stream.iterator();
+                        while (iter.hasNext()) {
+                            Path matchPath = iter.next();
+                            String s = matchPath.toString();
+                            if (s.length() > 0) {
+                                matches.add(s);
                             }
-                        } catch (IOException ex) {
-                            // ignored
                         }
+                    } catch (IOException ex) {
+                        // ignored
                     }
                 } else {
                     matches.add(pathPattern);
@@ -369,13 +372,22 @@ public class SysFunctions {
             return -1;
         }
 
-        private static ArrayList<Path> components(Path path) {
-            ArrayList<Path> list = new ArrayList<>();
-            Iterator<Path> iter = path.iterator();
-            while (iter.hasNext()) {
-                list.add(iter.next());
+        private static Path findLowerStart(Path path) {
+            int count = path.getNameCount();
+            for (int i = 0; i < count; i++) {
+                Path element = path.getName(i);
+                if (containsGlobChar(element.toString()) >= 0) {
+                    // can't use subpath as it's relative
+                    Path result = path;
+                    int j = count;
+                    while (j > i) {
+                        result = result.getParent();
+                        j--;
+                    }
+                    return result;
+                }
             }
-            return list;
+            throw RInternalError.shouldNotReachHere();
         }
 
         private static class FileMatcher implements BiPredicate<Path, BasicFileAttributes> {
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 9f697874f9b3839c84afdfc2fdfd2219749c1d5e..dd9a265dcf6e6dbb2bf3d9e35841c116d50d4c16 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
@@ -58,7 +58,7 @@ public class CallRFFIWithJNI implements CallRFFI {
         String rHome = REnvVars.rHome();
         String packageName = "com.oracle.truffle.r.native";
         OSInfo osInfo = RPlatform.getOSInfo();
-        Path path = FileSystems.getDefault().getPath(rHome, packageName, "builtinlibs", "lib", osInfo.osSubDir, "librfficall." + osInfo.libExt);
+        Path path = FileSystems.getDefault().getPath(rHome, packageName, "builtinlibs", "lib", "librfficall." + osInfo.libExt);
         try {
             DLL.load(path.toString(), ForceRTLDGlobal, false);
         } catch (DLLException ex) {
diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java
index 1d8844911d8942784f0957cb1cc6ddc362aa76ab..d386cc3f33624c670eb22da536c83ac10de5202c 100644
--- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java
+++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java
@@ -31,12 +31,13 @@ import jnr.ffi.annotations.*;
 import jnr.posix.*;
 
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.ffi.*;
 
 /**
  * JNR-based factory.
  */
-public class JNR_RFFIFactory extends RFFIFactory implements RFFI, BaseRFFI, RDerivedRFFI, LapackRFFI, UserRngRFFI {
+public class JNR_RFFIFactory extends RFFIFactory implements RFFI, BaseRFFI, StatsRFFI, RApplRFFI, LapackRFFI, UserRngRFFI, PCRERFFI {
 
     public JNR_RFFIFactory() {
     }
@@ -318,14 +319,11 @@ public class JNR_RFFIFactory extends RFFIFactory implements RFFI, BaseRFFI, RDer
     }
 
     /*
-     * Linpack functions
-     *
-     * TODO In order to finesse a problem that "libR" does not exists separately on Linux, the
-     * Linpack functions should be amalgamated with FFT in RDerived.
+     * Linpack (libappl) functions
      */
 
     @Override
-    public RDerivedRFFI getRDerivedRFFI() {
+    public RApplRFFI getRApplRFFI() {
         return this;
     }
 
@@ -340,9 +338,9 @@ public class JNR_RFFIFactory extends RFFIFactory implements RFFI, BaseRFFI, RDer
 
         @TruffleBoundary
         private static Linpack createAndLoadLib() {
-            // need to load blas lib as Fortran functions in RDerived lib need it
+            // need to load blas lib as Fortran functions in appl lib need it
             LibraryLoader.create(Linpack.class).load("Rblas");
-            return LibraryLoader.create(Linpack.class).load("RDerived");
+            return LibraryLoader.create(Linpack.class).load("appl");
         }
 
         static Linpack linpack() {
@@ -367,45 +365,53 @@ public class JNR_RFFIFactory extends RFFIFactory implements RFFI, BaseRFFI, RDer
         linpack().dqrcf_(x, wrapInt(n), wrapInt(k), qraux, y, wrapInt(ny), b, info);
     }
 
-    // fft functions
+    // Stats functions
 
-    public interface FFT {
-        // TODO add @In/@Out to any arrays that are known to be either @In or @Out (default is
-// @Inout)
+    @Override
+    public StatsRFFI getStatsRFFI() {
+        return this;
+    }
+
+    public interface Stats {
+        /*
+         * TODO add @In/@Out to any arrays that are known to be either @In or @Out (default is
+         * 
+         * @Inout)
+         */
 
         void fft_factor(@In int[] n, int[] pmaxf, int[] pmaxp);
 
         int fft_work(double[] a, @In int[] nseg, @In int[] n, @In int[] nspn, @In int[] isn, double[] work, int[] iwork);
     }
 
-    private static class FFTProvider {
-        private static FFT fft;
+    private static class StatsProvider {
+        private static Stats stats;
 
         @TruffleBoundary
-        private static FFT createAndLoadLib() {
-            return LibraryLoader.create(FFT.class).load("RDerived");
+        private static Stats createAndLoadLib() {
+            return LibraryLoader.create(Stats.class).load("appl");
         }
 
-        static FFT fft() {
-            if (fft == null) {
-                fft = createAndLoadLib();
+        static Stats fft() {
+            if (stats == null) {
+                stats = createAndLoadLib();
             }
-            return fft;
+            return stats;
         }
     }
 
-    private static FFT fft() {
-        return FFTProvider.fft();
+    private static Stats stats() {
+        return StatsProvider.fft();
     }
 
     @TruffleBoundary
     public void fft_factor(int n, int[] pmaxf, int[] pmaxp) {
-        fft().fft_factor(wrapInt(n), pmaxf, pmaxp);
+        stats().fft_factor(wrapInt(n), pmaxf, pmaxp);
     }
 
     @TruffleBoundary
     public int fft_work(double[] a, int nseg, int n, int nspn, int isn, double[] work, int[] iwork) {
-        return fft().fft_work(a, wrapInt(nseg), wrapInt(n), wrapInt(nspn), wrapInt(isn), work, iwork);
+        return stats().fft_work(a, wrapInt(nseg), wrapInt(n), wrapInt(nspn), wrapInt(isn), work, iwork);
     }
 
     /*
@@ -541,4 +547,62 @@ public class JNR_RFFIFactory extends RFFIFactory implements RFFI, BaseRFFI, RDer
         return zip().uncompress(dest, destlen, source, source.length);
     }
 
+    // PCRE
+
+    @Override
+    public PCRERFFI getPCRERFFI() {
+        return this;
+    }
+
+    public interface PCRE {
+        long pcre_maketables();
+
+        long pcre_compile(String pattern, int options, @Out byte[] errorMessage, @Out int[] errOffset, long tables);
+
+        int pcre_exec(long code, long extra, @In byte[] subject, int subjectLength, int startOffset, int options, @Out int[] ovector, int ovecSize);
+    }
+
+    private static class PCREProvider {
+        private static PCRE pcre;
+
+        @TruffleBoundary
+        private static PCRE createAndLoadLib() {
+            return LibraryLoader.create(PCRE.class).load("pcre");
+        }
+
+        static PCRE pcre() {
+            if (pcre == null) {
+                pcre = createAndLoadLib();
+            }
+            return pcre;
+        }
+    }
+
+    private static PCRE pcre() {
+        return PCREProvider.pcre();
+    }
+
+    public long maketables() {
+        return pcre().pcre_maketables();
+    }
+
+    public Result compile(String pattern, int options, long tables) {
+        int[] errOffset = new int[1];
+        byte[] errorMessage = new byte[512];
+        long result = pcre().pcre_compile(pattern, options, errorMessage, errOffset, tables);
+        if (result == 0) {
+            return new Result(result, new String(errorMessage), errOffset[0]);
+        } else {
+            return new Result(result, null, 0);
+        }
+    }
+
+    public Result study(long code, int options) {
+        throw RInternalError.unimplemented("pcre_study");
+    }
+
+    public int exec(long code, long extra, String subject, int offset, int options, int[] ovector) {
+        return pcre().pcre_exec(code, extra, subject.getBytes(), subject.length(), offset, options, ovector, ovector.length);
+    }
+
 }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java
index e948eab02e3d697fa29c4ab762912280f388d9ce..99df9c0c5b9032830b0936bb2be20349aa34e0b5 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java
@@ -436,7 +436,7 @@ public final class RError extends RuntimeException {
         INVALID_FORMAT_STRING("invalid format '%s'; use format %%s for character objects"),
         MUST_BE_CHARACTER("'%s' must be of mode character"),
         ALL_ATTRIBUTES_NAMES("all attributes must have names [%d does not]"),
-        INVALID_REGEXP("invalid '%s' regular expression"),
+        INVALID_REGEXP("invalid regular expression '%s'"),
         COERCING_ARGUMENT("coercing argument of type '%s' to %s"),
         MUST_BE_TRUE_FALSE_ENVIRONMENT("'%s' must be TRUE, FALSE or an environment"),
         UNKNOWN_OBJECT_MODE("object '%s' of mode '%s' was not found"),
@@ -453,6 +453,7 @@ public final class RError extends RuntimeException {
         RECURSIVE_INDEXING_FAILED("recursive indexing failed at level %d"),
         ARGUMENTS_PASSED("%d arguments passed to '%s' which requires %d"),
         ARGUMENTS_PASSED_0_1("0 arguments passed to '%s' which requires 1"),
+        ARGUMENT_IGNORED("argument '%s' will be ignored"),
         NOT_CHARACTER_VECTOR("'%s' must be a character vector"),
         CANNOT_MAKE_VECTOR_OF_MODE("vector: cannot make a vector of mode '%s'"),
         SET_ROWNAMES_NO_DIMS("attempt to set 'rownames' on an object with no dimensions"),
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/PCRERFFI.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/PCRERFFI.java
new file mode 100644
index 0000000000000000000000000000000000000000..c1dc5d0e0475cbe3f02ba38ec8b5c20f684f7459
--- /dev/null
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/PCRERFFI.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015, 2015, 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.ffi;
+
+/**
+ * An interface to the <a href="http://www.pcre.org/original/doc/html/index.html">PCRE</a> library
+ * for Perl regular expressions.
+ */
+public interface PCRERFFI {
+    int NOTBOL = 0x00000080;
+    int CASELESS = 0x1;
+
+    /**
+     * PCRE uses call by reference for error-related information, which we encapsulate and sanitize
+     * in this class. The {@code result} value (which is typically an opaque pointer to an internal
+     * C struct), is the actual result of the function as per the PCRE spec.
+     */
+    public class Result {
+        public final long result;
+        public final String errorMessage;
+        public final int errOffset;
+
+        public Result(long result, String errorMessage, int errOffset) {
+            this.result = result;
+            this.errorMessage = errorMessage;
+            this.errOffset = errOffset;
+        }
+
+    }
+
+    long maketables();
+
+    Result compile(String pattern, int options, long tables);
+
+    Result study(long code, int options);
+
+    int exec(long code, long extra, String subject, int offset, int options, int[] ovector);
+
+}
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RDerivedRFFI.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RApplRFFI.java
similarity index 82%
rename from com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RDerivedRFFI.java
rename to com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RApplRFFI.java
index 14ed8df6fcdee4aa672cfdee9ef2e0115b14c0f4..6d58cbc1eab0db3b8e356623d4c306671753e481 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RDerivedRFFI.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RApplRFFI.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, 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
@@ -24,17 +24,13 @@ package com.oracle.truffle.r.runtime.ffi;
 
 /**
  * Collection of statically typed methods (from Linpack and elsewhere) that are built in to a GnuR
- * implementation and factored out into a separate library in FastR.
+ * implementation and factored out into a separate library in FastR. This corresponds to the
+ * {@code libappl} library in GnuR.
  */
-public interface RDerivedRFFI {
+public interface RApplRFFI {
     // Linpack
     void dqrdc2(double[] x, int ldx, int n, int p, double tol, int[] rank, double[] qraux, int[] pivot, double[] work);
 
     void dqrcf(double[] x, int n, int k, double[] qraux, double[] y, int ny, double[] b, int[] info);
 
-    // fft
-    // Checkstyle: stop method name
-    void fft_factor(int n, int[] pmaxf, int[] pmaxp);
-
-    int fft_work(double[] a, int nseg, int n, int nspn, int isn, double[] work, int[] iwork);
 }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFI.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFI.java
index cd6df58bfaf23920ff3610f53273c99d968174c9..2965da136b11bdfe44be417e9b633379f0b0ad04 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFI.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFI.java
@@ -30,11 +30,13 @@ package com.oracle.truffle.r.runtime.ffi;
  * package.</li>
  * <li>{@link LapackRFFI}: the specific, typed, foreign functions required by the built-in
  * {@code Lapack} functions.</li>
- * <li>{@link RDerivedRFFI}: the specific, typed, foreign functions required by the built-in
+ * <li>{@link StatsRFFI}: native functions in the {@code stats} package.</li>
+ * <li>{@link RApplRFFI}: the specific, typed, foreign functions required by the built-in
  * {@code Linpack} functions.</li>
- * <li>{@link CRFFI}: {@code .C} and {@code .Fortran} call interface.
- * <li>{@link CallRFFI}: {@code .Call} and {@code .External} call interface.
- * <li>{@link UserRngRFFI}: specific interface to user-supplied random number generator.
+ * <li>{@link CRFFI}: {@code .C} and {@code .Fortran} call interface.</li>
+ * <li>{@link CallRFFI}: {@code .Call} and {@code .External} call interface.</li>
+ * <li>{@link UserRngRFFI}: specific interface to user-supplied random number generator.</li>
+ * <li>{@link PCRERFFI}: interface to PCRE library (Perl regexp).</li>
  * </ul>
  *
  * These interfaces may be implemented by one or more providers, specified either when the FastR
@@ -45,7 +47,9 @@ public interface RFFI {
 
     LapackRFFI getLapackRFFI();
 
-    RDerivedRFFI getRDerivedRFFI();
+    RApplRFFI getRApplRFFI();
+
+    StatsRFFI getStatsRFFI();
 
     CRFFI getCRFFI();
 
@@ -53,4 +57,6 @@ public interface RFFI {
 
     UserRngRFFI getUserRngRFFI();
 
+    PCRERFFI getPCRERFFI();
+
 }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFIFactory.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFIFactory.java
index d6f3aafb05aebffc7f673a23c7191db091fb283e..a8f537239686a909a26667dd25414e146afec890 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFIFactory.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/RFFIFactory.java
@@ -57,23 +57,35 @@ public abstract class RFFIFactory {
     protected abstract RFFI createRFFI();
 
     public LapackRFFI getLapackRFFI() {
-        throw Utils.fail("getLapackRFFI not implemented");
+        throw missing("Lapack");
     }
 
-    public RDerivedRFFI getRDerivedRFFI() {
-        throw Utils.fail("getRDerivedRFFI not implemented");
+    public StatsRFFI getStatsRFFI() {
+        throw missing("Stats");
+    }
+
+    public RApplRFFI getRApplRFFI() {
+        throw missing("RDerived");
     }
 
     public CRFFI getCRFFI() {
-        throw Utils.fail("getCRFFI not implemented");
+        throw missing("C");
     }
 
     public CallRFFI getCallRFFI() {
-        throw Utils.fail("getCallRFFI not implemented");
+        throw missing("Call");
     }
 
     public UserRngRFFI getUserRngRFFI() {
-        throw Utils.fail("getUserRngRFFI not implemented");
+        throw missing("UserRNG");
+    }
+
+    public PCRERFFI getPCRERFFI() {
+        throw missing("PCRE");
+    }
+
+    private static RuntimeException missing(String ffi) throws RuntimeException {
+        throw Utils.fail(ffi + " FFI not implemented");
     }
 
     @TruffleBoundary
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/StatsRFFI.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/StatsRFFI.java
new file mode 100644
index 0000000000000000000000000000000000000000..bc8d2c33006c421461af86e48287771acc7df034
--- /dev/null
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/StatsRFFI.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2015, 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.ffi;
+
+/**
+ * Interface to native (C) methods provides by the {@code stats} package.
+ */
+public interface StatsRFFI {
+    // Checkstyle: stop method name
+    void fft_factor(int n, int[] pmaxf, int[] pmaxp);
+
+    int fft_work(double[] a, int nseg, int n, int nspn, int isn, double[] work, int[] iwork);
+
+}
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
index 049563e1aec359aa79a227b61cfbff1bead2cf41..ba6d63af6b032f81323af30b156f044466d57547 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
@@ -15268,18 +15268,49 @@ a b
 [1] ""     "ello"
 
 
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ gsub("([a-e])","\\1\\1", "prague alley") }
+[1] "praaguee aalleey"
+
 ##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
 #{ gsub("a","aa", "prAgue alley") }
 [1] "prAgue aalley"
 
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ gsub("a","aa", "prAgue alley", fixed=TRUE) }
+[1] "prAgue aalley"
+
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ gsub("a","aa", "prAgue alley", fixed=TRUE, ignore.case=TRUE) }
+[1] "prAgue aalley"
+Warning message:
+In gsub("a", "aa", "prAgue alley", fixed = TRUE, ignore.case = TRUE) :
+  argument 'ignore.case = TRUE' will be ignored
+
 ##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
 #{ gsub("a","aa", "prague alley") }
 [1] "praague aalley"
 
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ gsub("a","aa", "prague alley", fixed=TRUE) }
+[1] "praague aalley"
+
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ gsub("h","", c("hello", "hi", "bye")) }
+[1] "ello" "i"    "bye"
+
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ gsub("h","", c("hello", "hi", "bye"), fixed=TRUE) }
+[1] "ello" "i"    "bye"
+
 ##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
 #{ sub("a","aa", "prague alley") }
 [1] "praague alley"
 
+##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSub
+#{ sub("a","aa", "prague alley", fixed=TRUE) }
+[1] "praague alley"
+
 ##com.oracle.truffle.r.test.library.base.TestSimpleBuiltins.testSubstitute
 #{ delayedAssign("expr", a * b) ; substitute(expr) }
 expr
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java
index dc489dac547ece7d8f3c4b543156811b1436743b..85ce50aeb6cacab54da160db6de5562c7d9fe8a6 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java
@@ -15235,43 +15235,43 @@ public class AllTests extends TestBase {
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_0902579a0dce5fa8d7a808155b8c09b0() {
+    public void TestSimpleBuiltins_testSub_0902579a0dce5fa8d7a808155b8c09b0() {
         assertEval("{ gsub(\"a\",\"aa\", \"prague alley\", fixed=TRUE) }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_fa9e3d4d6577b70532d26a56fc343b17() {
+    public void TestSimpleBuiltins_testSub_fa9e3d4d6577b70532d26a56fc343b17() {
         assertEval("{ sub(\"a\",\"aa\", \"prague alley\", fixed=TRUE) }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_dca0ae0449dfa1c58f334818a4b87673() {
+    public void TestSimpleBuiltins_testSub_dca0ae0449dfa1c58f334818a4b87673() {
         assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE) }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_3d79a5bb75bf60e95350618f5485daa6() {
-        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE, ignore.case=TRUE) }");
+    public void TestSimpleBuiltins_testSub_fec73fb8a79be7e6b705d46bbc16a617() {
+        assertEval("{ gsub(\"([a-e])\",\"\\\\1\\\\1\", \"prague alley\") }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_d1977e782dbbd1ca4da912d5f56d63ed() {
-        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", ignore.case=TRUE) }");
+    public void TestSimpleBuiltins_testSub_8df24d5d1e0149a6b232c373b6057aa7() {
+        assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\")) }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_fec73fb8a79be7e6b705d46bbc16a617() {
-        assertEval("{ gsub(\"([a-e])\",\"\\\\1\\\\1\", \"prague alley\") }");
+    public void TestSimpleBuiltins_testSub_42529469f0a7019b2a56e1e5312e0577() {
+        assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\"), fixed=TRUE) }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_8df24d5d1e0149a6b232c373b6057aa7() {
-        assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\")) }");
+    public void TestSimpleBuiltins_testSub_3d79a5bb75bf60e95350618f5485daa6() {
+        assertEvalWarning("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE, ignore.case=TRUE) }");
     }
 
     @Test
-    public void TestSimpleBuiltins_testSubIgnore_42529469f0a7019b2a56e1e5312e0577() {
-        assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\"), fixed=TRUE) }");
+    public void TestSimpleBuiltins_testSubIgnore_d1977e782dbbd1ca4da912d5f56d63ed() {
+        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", ignore.case=TRUE) }");
     }
 
     @Test
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java
index 3a354327db5a13aa779787306e2428890b39144c..98614a442c52c08135d7abf6f7719eaff2627f7f 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java
@@ -1227,54 +1227,12 @@ public class FailingTests extends TestBase {
         check("TestSimpleBuiltins_testSqrtBroken_d1949f3b9fbc81f7fe02ad4b8719bcaa");
     }
 
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_0902579a0dce5fa8d7a808155b8c09b0() {
-        assertEval("{ gsub(\"a\",\"aa\", \"prague alley\", fixed=TRUE) }");
-        check("TestSimpleBuiltins_testSubIgnore_0902579a0dce5fa8d7a808155b8c09b0");
-    }
-
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_fa9e3d4d6577b70532d26a56fc343b17() {
-        assertEval("{ sub(\"a\",\"aa\", \"prague alley\", fixed=TRUE) }");
-        check("TestSimpleBuiltins_testSubIgnore_fa9e3d4d6577b70532d26a56fc343b17");
-    }
-
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_dca0ae0449dfa1c58f334818a4b87673() {
-        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE) }");
-        check("TestSimpleBuiltins_testSubIgnore_dca0ae0449dfa1c58f334818a4b87673");
-    }
-
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_3d79a5bb75bf60e95350618f5485daa6() {
-        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE, ignore.case=TRUE) }");
-        check("TestSimpleBuiltins_testSubIgnore_3d79a5bb75bf60e95350618f5485daa6");
-    }
-
     @Test
     public void TestSimpleBuiltins_testSubIgnore_d1977e782dbbd1ca4da912d5f56d63ed() {
         assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", ignore.case=TRUE) }");
         check("TestSimpleBuiltins_testSubIgnore_d1977e782dbbd1ca4da912d5f56d63ed");
     }
 
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_fec73fb8a79be7e6b705d46bbc16a617() {
-        assertEval("{ gsub(\"([a-e])\",\"\\\\1\\\\1\", \"prague alley\") }");
-        check("TestSimpleBuiltins_testSubIgnore_fec73fb8a79be7e6b705d46bbc16a617");
-    }
-
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_8df24d5d1e0149a6b232c373b6057aa7() {
-        assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\")) }");
-        check("TestSimpleBuiltins_testSubIgnore_8df24d5d1e0149a6b232c373b6057aa7");
-    }
-
-    @Test
-    public void TestSimpleBuiltins_testSubIgnore_42529469f0a7019b2a56e1e5312e0577() {
-        assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\"), fixed=TRUE) }");
-        check("TestSimpleBuiltins_testSubIgnore_42529469f0a7019b2a56e1e5312e0577");
-    }
-
     @Test
     public void TestSimpleBuiltins_testSubstituteIgnore_d84d47dddb7bd0bf96bf16437eadd619() {
         assertEval("{ f <- function(y) { substitute(y) } ; f() }");
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleBuiltins.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleBuiltins.java
index cc040a664effd194e05236c03ffe4f6fa7a0e600..90688dbd2af3178d61955a0fd81bd74c47ecdffc 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleBuiltins.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleBuiltins.java
@@ -1731,21 +1731,21 @@ public class TestSimpleBuiltins extends TestBase {
         assertEval("{ gsub(\"a\",\"aa\", \"prague alley\") }");
         assertEval("{ sub(\"a\",\"aa\", \"prague alley\") }");
         assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\") }");
-    }
-
-    @Test
-    @Ignore
-    public void testSubIgnore() {
         assertEval("{ gsub(\"a\",\"aa\", \"prague alley\", fixed=TRUE) }");
         assertEval("{ sub(\"a\",\"aa\", \"prague alley\", fixed=TRUE) }");
         assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE) }");
-        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE, ignore.case=TRUE) }");
-        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", ignore.case=TRUE) }");
+        assertEvalWarning("{ gsub(\"a\",\"aa\", \"prAgue alley\", fixed=TRUE, ignore.case=TRUE) }");
         assertEval("{ gsub(\"([a-e])\",\"\\\\1\\\\1\", \"prague alley\") }");
         assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\")) }");
         assertEval("{ gsub(\"h\",\"\", c(\"hello\", \"hi\", \"bye\"), fixed=TRUE) }");
     }
 
+    @Test
+    @Ignore
+    public void testSubIgnore() {
+        assertEval("{ gsub(\"a\",\"aa\", \"prAgue alley\", ignore.case=TRUE) }");
+    }
+
     @Test
     public void testGrep() {
         assertEval("{ txt<-c(\"arm\",\"foot\",\"lefroo\", \"bafoobar\"); grep(\"foo\", txt) }");
diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides
index 2340747b25a217a99783a97c5c4039508750a40f..ad9f8e695cd40acf9616551b99eb452a548f4d00 100644
--- a/mx.fastr/copyrights/overrides
+++ b/mx.fastr/copyrights/overrides
@@ -73,6 +73,7 @@ com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/E
 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FileFunctions.java,gnu_r.copyright
 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ForeignFunctions.java,gnu_r.copyright
 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetClass.java,purdue.copyright
+com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java,gnu_r.copyright
 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Inherits.java,purdue.copyright
 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsArray.java,purdue.copyright
 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadFunctions.java,gnu_r_gentleman_ihaka.copyright
diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py
index 1ef05cee144c4e0096905301cee6e74b53529af2..99daa2afad9ec96f0b88ae2f81e77db75290ecd4 100644
--- a/mx.fastr/mx_fastr.py
+++ b/mx.fastr/mx_fastr.py
@@ -53,8 +53,7 @@ def runRscriptCommand(args, nonZeroIsFatal=True):
 
 def setREnvironment():
     osname = platform.system()
-    translatedOsname = "solaris" if osname.lower() == "sunos" else osname.lower()
-    lib_base = join(_fastr_suite.dir, 'com.oracle.truffle.r.native', 'builtinlibs', 'lib', translatedOsname)
+    lib_base = join(_fastr_suite.dir, 'com.oracle.truffle.r.native', 'builtinlibs', 'lib')
     lib_value = lib_base
     if osname == 'Darwin':
         lib_env = 'DYLD_FALLBACK_LIBRARY_PATH'
diff --git a/mx.fastr/suite.py b/mx.fastr/suite.py
index 6358ef94258744b3382570c0217941500ca098bd..c29a58ffedbec2a6276086d0efdff1e45fb5e34c 100644
--- a/mx.fastr/suite.py
+++ b/mx.fastr/suite.py
@@ -21,9 +21,15 @@
 # questions.
 #
 suite = {
-  "mxversion" : "2.9.2",
+  "mxversion" : "2.9.7",
   "name" : "fastr",
   "libraries" : {
+    "GNUR" : {
+        "path" : "lib/R-3.1.3.tar.gz",
+        "urls" : ["http://cran.rstudio.com/src/base/R-3/R-3.1.3.tar.gz"],
+        "sha1" : "2c9165060b91e45ac73d8cb7507ee9e52816f8b3"
+    },
+
     "JDK_TOOLS" : {
       "path" : "${JAVA_HOME}/lib/tools.jar",
       "sha1" : "NOCHECK",
@@ -338,6 +344,9 @@ suite = {
 
     "com.oracle.truffle.r.native" : {
       "sourceDirs" : [],
+      "dependencies" : [
+        "GNUR"
+      ],
       "native" : "true",
       "workingSets" : "FastR",
     },
@@ -401,6 +410,7 @@ suite = {
         "JLINE",
         "ANTLR-C",
         "ANTLR",
+        "GNUR",
       ],
       "distDependencies" : [
         "TRUFFLE",