diff --git a/com.oracle.truffle.r.native/builtinlibs/Makefile b/com.oracle.truffle.r.native/builtinlibs/Makefile
index 5a83c345990fb3bdce7eb6fc6b05c1fc2af1dc6f..cb12f95b38c02b4bbdcf1a2161a126837999a6db 100644
--- a/com.oracle.truffle.r.native/builtinlibs/Makefile
+++ b/com.oracle.truffle.r.native/builtinlibs/Makefile
@@ -28,7 +28,7 @@
 # that refers to GnuR-internal symbols.
 #
 
-include ../platform.mk
+include $(TOPDIR)/platform.mk
 
 .PHONY: all clean cleanlib cleanobj force libr
 
@@ -41,22 +41,22 @@ C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
 F_OBJECTS := $(wildcard $(GNUR_DIR)/src/appl/d*.o)
 
 LIBDIR := $(OBJ)
-LIB_APPL := $(OBJ)/libappl.$(SHARED_EXT)
+LIB_APPL := $(OBJ)/libappl$(DYLIB_EXT)
 
 all: $(LIB_APPL) libr
 
 $(LIB_APPL): $(C_OBJECTS) $(F_OBJECTS)
 	mkdir -p $(LIBDIR)
-	$(CC) $(LDFLAGS) -o $(LIB_APPL) $(C_OBJECTS) $(F_OBJECTS) $(LIBS)
+	$(DYLIB_LD) $(DYLIB_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)
+ifeq ($(OS_NAME), Darwin)
+LIB_RDUMMY := $(OBJ)/libR$(DYLIB_EXT)
 
 libr: $(LIB_RDUMMY)
 $(LIB_RDUMMY): $(OBJ)/rdummy.o
 	mkdir -p $(LIBDIR)
-	$(CC) $(LDFLAGS) -o $(LIB_RDUMMY) -current_version $(R_VERSION) -compatibility_version $(R_VERSION) $(OBJ)/rdummy.o
+	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_RDUMMY) -current_version $(R_VERSION) -compatibility_version $(R_VERSION) $(OBJ)/rdummy.o
 
 cleanlibr:
 	rm -f $(LIB_RDUMMY)
@@ -71,10 +71,6 @@ endif
 $(OBJ)/%.o: $(SRC)/%.c
 	$(CC) $(CFLAGS) -c $< -o $@
 
-$(OBJ)/%.o: $(SRC)/%.f
-	$(FC) $(CFLAGS) -c $< -o $@
-
-
 cleanlib:
 	rm -f $(LIBDIR)/libappl.*
 
diff --git a/com.oracle.truffle.r.native/fficall/jni/Makefile b/com.oracle.truffle.r.native/fficall/jni/Makefile
index a333075f36cc56828bb60574433a6e9917993473..273f98512c54180795a018befdeb8cc0ce1e629d 100644
--- a/com.oracle.truffle.r.native/fficall/jni/Makefile
+++ b/com.oracle.truffle.r.native/fficall/jni/Makefile
@@ -32,9 +32,10 @@ include $(TOPDIR)/platform.mk
 OBJ = lib
 SRC = src
 C_SOURCES := $(wildcard $(SRC)/*.c)
-C_LIBNAME := librfficall.$(SHARED_EXT)
+C_LIBNAME := librfficall$(DYLIB_EXT)
 C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
 C_LIB := $(TOPDIR)/builtinlibs/$(OBJ)/$(C_LIBNAME)
+CFLAGS := $(CFLAGS) -DFASTR
 
 JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(OS_DIR)
 FFI_INCLUDES = -I$(TOPDIR)/include/jni/include -I$(TOPDIR)/include/jni/include/R_ext
@@ -44,7 +45,7 @@ INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 all: $(C_LIB)
 
 $(C_LIB): $(OBJ) $(C_OBJECTS)
-	$(CC) $(LDFLAGS) -o $(C_LIB) $(C_OBJECTS)
+	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(C_LIB) $(C_OBJECTS)
 
 $(OBJ):
 	mkdir -p $(OBJ)
diff --git a/com.oracle.truffle.r.native/gnur/Makefile b/com.oracle.truffle.r.native/gnur/Makefile
index 5d07efb3a096c59f1d8aa66d94c3fda27b44295d..1d878478b8e52c11b497d84430dd7e64c1335404 100644
--- a/com.oracle.truffle.r.native/gnur/Makefile
+++ b/com.oracle.truffle.r.native/gnur/Makefile
@@ -21,49 +21,12 @@
 # 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
+.PHONY: all clean
 
-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 --enable-R-shlib >& /dev/null)
-
-build: $(GNUR_DIR)/bin/R
-
-$(GNUR_DIR)/bin/R:
-	(cd $(GNUR_DIR); make >& make.log)
-
-copy: $(TARGET_DIR) $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET)
-
-$(TARGET_DIR):
-	mkdir -p $(TARGET_DIR)
-
-$(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
+all: 
+	$(MAKE) -f Makefile.gnur
+	$(MAKE) -f Makefile.libs
 
 clean:
-	rm -rf $(GNUR_DIR)
-	rm -f $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET)
+	$(MAKE) -f Makefile.gnur clean
+	$(MAKE) -f Makefile.libs clean
diff --git a/com.oracle.truffle.r.native/gnur/Makefile.gnur b/com.oracle.truffle.r.native/gnur/Makefile.gnur
new file mode 100644
index 0000000000000000000000000000000000000000..66d9cfcc7287f7874871f9bac8b420ee6db815fa
--- /dev/null
+++ b/com.oracle.truffle.r.native/gnur/Makefile.gnur
@@ -0,0 +1,82 @@
+#
+# 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 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.
+#
+# The configuration of GnuR for FastR is platform specific and a special step
+# is needed for Linux where, ordinarily, the PCRE library is compiled non-PIC
+# as it is built as a library archive. FastR needs a shared library, which can be
+# enabled by setting --enable-R-shlib, but unfortunately this also sets the visibility
+# of the functions to hidden, so FastR cannot find them. There does not appear to be a 
+# way to fix this simply using configure args, so we patch up the Makeconf file.
+
+# Portions of the Makeconf file are then extracted to use in building the native
+# parts of FastR, especially packages with native code.
+
+# Building GnuR takes several minutes, so in some environments, e.g. repository gates,
+# referring to a pre-built GnuR would be of value. This is TBD.
+
+.PHONY: all config config_update build clean
+
+OSNAME := $(shell uname)
+ifeq ($(OSNAME), Linux)
+else ifeq ($(OSNAME), SunOS)
+else ifeq ($(OSNAME), Darwin)
+else
+all:
+	@echo "This Makefile does not know how to compile for $(OSNAME)"
+	@false
+endif
+
+all: Makefile $(GNUR_DIR) config build
+
+$(GNUR_DIR): 
+	tar xf $(TOPDIR)/../lib/R-$(R_VERSION).tar.gz
+
+config: $(GNUR_DIR)/Makefile config_update
+
+ifeq ($(OSNAME), Linux)
+config_update: Makeconf.done
+
+Makeconf.done: edMakeconf
+	ed $(GNUR_DIR)/Makeconf < edMakeconf
+	touch Makeconf.done
+else
+config_update:
+endif
+
+$(GNUR_DIR)/Makefile:
+	(cd $(GNUR_DIR); ./configure --with-x=no --without-recommended-packages >& gnur_configure.log)
+
+
+build: $(GNUR_DIR)/bin/R
+
+$(GNUR_DIR)/bin/R: $(GNUR_DIR)/Makeconf 
+	(cd $(GNUR_DIR); make >& gnur_make.log)
+
+clean:
+	rm Makeconf.done
+	(cd $(GNUR_DIR); make distclean)
diff --git a/com.oracle.truffle.r.native/platform.mk b/com.oracle.truffle.r.native/gnur/Makefile.libs
similarity index 51%
rename from com.oracle.truffle.r.native/platform.mk
rename to com.oracle.truffle.r.native/gnur/Makefile.libs
index a695488a79001dfbc78f901fc45ace7062f0bc73..57e6ab32700a941b2c9eaba7e87a48250221578f 100644
--- a/com.oracle.truffle.r.native/platform.mk
+++ b/com.oracle.truffle.r.native/gnur/Makefile.libs
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+# 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
@@ -21,35 +21,32 @@
 # questions.
 #
 
-OSNAME := $(shell uname)
-
-ifeq ($(OSNAME), Linux)
-  OS_DIR      := linux
-  CC          := gcc
-  FC          := gfortran
-  CFLAGS      := -fPIC -O2
-  LDFLAGS     := -fPIC -shared
-  SHARED_EXT  := so
-  LIBS        := -lgfortran
-else ifeq ($(OSNAME), SunOS)
-  OS_DIR      := solaris
-  CC          := cc
-  FC          := f90
-  CFLAGS      := -m64 -O -xcode=pic13
-  LDFLAGS     := -G -m64
-  SHARED_EXT  := so
-  LIBS        := -lgfortran
-else ifeq ($(OSNAME), Darwin)
-  OS_DIR      := darwin
-  CC          := gcc
-  FC          := gfortran
-  CFLAGS      := -fPIC -O2
-  LDFLAGS     := -dynamiclib -undefined dynamic_lookup
-  SHARED_EXT  := dylib
-else
-all:
-	@echo "This Makefile does not know how to compile for $(OSNAME)"
-	@false
-endif
-
-CFLAGS := $(CFLAGS) -DFASTR
+# Copies the Lbas and lapack libraries and builds the pcre library
+
+include $(TOPDIR)/platform.mk
+
+TARGET_DIR := $(TOPDIR)/builtinlibs/lib
+BLAS_TARGET := $(TARGET_DIR)/libRblas$(DYLIB_EXT)
+LAPACK_TARGET := $(TARGET_DIR)/libRlapack$(DYLIB_EXT)
+PCRE_TARGET := $(TARGET_DIR)/libpcre$(DYLIB_EXT)
+
+all: $(TARGET_DIR) $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET) 
+
+$(TARGET_DIR):
+	mkdir -p $(TARGET_DIR)
+
+$(BLAS_TARGET): $(GNUR_DIR)/lib/libRblas$(DYLIB_EXT)
+	cp $(GNUR_DIR)/lib/libRblas$(DYLIB_EXT) $(BLAS_TARGET)
+
+$(LAPACK_TARGET): $(GNUR_DIR)/lib/libRlapack$(DYLIB_EXT)
+	cp $(GNUR_DIR)/lib/libRlapack$(DYLIB_EXT) $(LAPACK_TARGET)
+
+PCRE_OBJS := $(wildcard $(GNUR_DIR)/src/extra/pcre/pcre_*.o)
+
+$(PCRE_TARGET): $(PCRE_OBJS) $(TOPDIR)/platform.mk
+	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(PCRE_TARGET) $(PCRE_OBJS)
+
+clean:
+	rm -f $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET)
+
+		
diff --git a/com.oracle.truffle.r.native/gnur/Makefile.pcre b/com.oracle.truffle.r.native/gnur/Makefile.platform
similarity index 68%
rename from com.oracle.truffle.r.native/gnur/Makefile.pcre
rename to com.oracle.truffle.r.native/gnur/Makefile.platform
index e539c755ac9d21744771c928e8be44c58d991517..bff6250fe88bd520efd4e18f96b4eb4412645001 100644
--- a/com.oracle.truffle.r.native/gnur/Makefile.pcre
+++ b/com.oracle.truffle.r.native/gnur/Makefile.platform
@@ -21,13 +21,20 @@
 # questions.
 #
 
-# This is separate because at the time the parent Makefile is analyzed
-# the pcre object files do not exist
+# Extracts relevant parts of the generated GnuR Makeconf file into FastR's platform.mk
 
-include ../platform.mk
+.PHONY: all clean
 
-PCRE_OBJS := $(wildcard $(GNUR_DIR)/src/extra/pcre/pcre_*.o)
+OS_NAME := $(shell uname)
+OS_DIR := $(shell echo $(OS_NAME) | tr '[:upper:]' '[:lower:]' )
 
-$(PCRE_TARGET): $(PCRE_OBJS)
-	$(CC) $(LDFLAGS) -o $(PCRE_TARGET) $(PCRE_OBJS)
-		
+all: $(TOPDIR)/platform.mk
+
+$(TOPDIR)/platform.mk: sedMakeconf
+	sed -f sedMakeconf $(GNUR_DIR)/Makeconf >& /dev/null
+	echo OS_NAME = $(OS_NAME) >> platform.mk.temp
+	echo OS_DIR = $(OS_DIR) >> platform.mk.temp
+	cp platform.mk.temp $(TOPDIR)/platform.mk
+
+clean:
+	rm -f $(TOPDIR)/platform.mk
diff --git a/com.oracle.truffle.r.native/gnur/edMakeconf b/com.oracle.truffle.r.native/gnur/edMakeconf
new file mode 100644
index 0000000000000000000000000000000000000000..d8c2b4553f4f8fc2c602d50f568db72c632b20e6
--- /dev/null
+++ b/com.oracle.truffle.r.native/gnur/edMakeconf
@@ -0,0 +1,4 @@
+/^CFLAGS/s/$/ -fpic/
+/^FFLAGS/s/$/ -fpic/
+w
+q
diff --git a/com.oracle.truffle.r.native/gnur/sedMakeconf b/com.oracle.truffle.r.native/gnur/sedMakeconf
new file mode 100644
index 0000000000000000000000000000000000000000..17cd71c7e9145e2349cf85eb9cb68d8a53f6784a
--- /dev/null
+++ b/com.oracle.truffle.r.native/gnur/sedMakeconf
@@ -0,0 +1,7 @@
+/^CC =.*/ w platform.mk.temp
+/^CFLAGS =.*/ w platform.mk.temp
+/^DYLIB_.* =.*/ w platform.mk.temp
+/^F77 =.*/ w platform.mk.temp
+/^FFLAGS =.*/ w platform.mk.temp
+/^FPICFLAGS =.*/ w platform.mk.temp
+/^FLIBS_IN_SO =.*/ w platform.mk.temp
diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk
index e3b2f9d34103343b17d4005639ab55c46a7bd6df..cccf72cc7ee497fb52b3172a53121f4876917274 100644
--- a/com.oracle.truffle.r.native/library/lib.mk
+++ b/com.oracle.truffle.r.native/library/lib.mk
@@ -27,7 +27,7 @@
 # and overwrites the default. The libraries are stored in the directory denoted
 # FASTR_LIBDIR.
 
-include ../../platform.mk
+include $(TOPDIR)/platform.mk
 
 .PHONY: all clean cleanlib cleanobj force libr libcommon 
 
@@ -57,7 +57,6 @@ FFI_INCLUDES = -I$(TOPDIR)/include/jni/include
 INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 
 PKGDIR := $(FASTR_LIBDIR)/$(PKG)
-PKGTAR := $(SRC)/$(OS_DIR)/$(PKG).tar.gz
 
 ifneq ($(C_SOURCES),)
 all: libcommon $(LIB_PKG) $(PKG_EXTRAS)
@@ -76,16 +75,13 @@ $(OBJ):
 
 $(LIB_PKG): $(OBJ) $(C_OBJECTS) $(PKGDIR)
 	mkdir -p $(LIBDIR)
-	$(CC) $(LDFLAGS) -o $(LIB_PKG) $(C_OBJECTS)
+	$(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_PKG) $(C_OBJECTS)
 	mkdir -p $(FASTR_LIBDIR)/$(PKG)/libs
 	cp $(LIB_PKG) $(FASTR_LIBDIR)/$(PKG)/libs
 
 $(OBJ)/%.o: $(SRC)/%.c  $(H_SOURCES)
 	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
 
-$(OBJ)/%.o: $(SRC)/%.f
-	$(FC) $(CFLAGS) -c $< -o $@
-
 clean: 
 	rm -rf $(LIBDIR)/*
 	rm -rf $(FASTR_LIBDIR)/$(PKG)
diff --git a/com.oracle.truffle.r.test.native/packages/testrffi/src/src/Makefile b/com.oracle.truffle.r.test.native/packages/testrffi/src/src/Makefile
index 5d01a5cd904368fd580c7c00db20fad3d7226b33..688c4e2c39e984e1e190eb80c1eb95913c9f3e55 100644
--- a/com.oracle.truffle.r.test.native/packages/testrffi/src/src/Makefile
+++ b/com.oracle.truffle.r.test.native/packages/testrffi/src/src/Makefile
@@ -33,7 +33,7 @@ include $(NATIVE_PROJECT)/platform.mk
 
 ifeq ($(FASTR_INSTALL), GNUR)
     INCLUDES := -I $(R_HOME)/include
-    ifeq ($(OSNAME), Darwin)
+    ifeq ($(OS_NAME), Darwin)
         FRAMEWORKFLAGS := -F${R_HOME}/../.. -framework R
     else
         FRAMEWORKFLAGS :=
diff --git a/com.oracle.truffle.r.test.native/urand/Makefile b/com.oracle.truffle.r.test.native/urand/Makefile
index 615dc22c37233da72c025cda523f154fe0427e7e..65bb933d03492b3a15894ce6d684d6a19fa1c441 100644
--- a/com.oracle.truffle.r.test.native/urand/Makefile
+++ b/com.oracle.truffle.r.test.native/urand/Makefile
@@ -46,7 +46,7 @@ INCLUDE_DIR := $(NATIVE_PROJECT)/include/jni/include
 all: $(C_LIB)
 
 $(C_LIB): $(OBJ) $(C_OBJECTS)
-	$(CC) $(LDFLAGS)  -o $(C_LIB) $(C_OBJECTS)
+	$(DYLIB_LD) $(DYLIB_LDFLAGS)  -o $(C_LIB) $(C_OBJECTS)
 
 $(OBJ):
 	mkdir -p $(OBJ)
diff --git a/com.oracle.truffle.r.test/rpackages/rffi/testrffi/src/Makefile b/com.oracle.truffle.r.test/rpackages/rffi/testrffi/src/Makefile
index 4a67ee84de8830ba776c885e8e62da285d4b1958..1686772388329ad1b630b7e050951026c42db339 100644
--- a/com.oracle.truffle.r.test/rpackages/rffi/testrffi/src/Makefile
+++ b/com.oracle.truffle.r.test/rpackages/rffi/testrffi/src/Makefile
@@ -33,7 +33,7 @@ include $(NATIVE_PROJECT)/platform.mk
 
 ifeq ($(FASTR_INSTALL), GNUR)
     INCLUDES := -I $(R_HOME)/include
-    ifeq ($(OSNAME), Darwin)
+    ifeq ($(OS_NAME), Darwin)
         FRAMEWORKFLAGS := -F${R_HOME}/../.. -framework R
     else
         FRAMEWORKFLAGS :=
@@ -47,7 +47,7 @@ endif
 all: $(C_LIB)
 
 $(C_LIB): $(C_OBJECTS)
-	$(CC) $(LDFLAGS)  -o $(C_LIB) $(C_OBJECTS)
+	$(DYLIB_LD) $(DYLIB_LDFLAGS)  -o $(C_LIB) $(C_OBJECTS)
 
 %.o: %.c
 	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@