diff --git a/com.oracle.truffle.r.native/fficall/jni/Makefile b/com.oracle.truffle.r.native/fficall/jni/Makefile
index decaee24ccafd8c0beb85d57996c6fcdef4364b4..a333075f36cc56828bb60574433a6e9917993473 100644
--- a/com.oracle.truffle.r.native/fficall/jni/Makefile
+++ b/com.oracle.truffle.r.native/fficall/jni/Makefile
@@ -49,7 +49,7 @@ $(C_LIB): $(OBJ) $(C_OBJECTS)
 $(OBJ):
 	mkdir -p $(OBJ)
 
-$(OBJ)/%.o: $(SRC)/%.c $(TOPDIR)/include/jni/Rinternals.h
+$(OBJ)/%.o: $(SRC)/%.c $(TOPDIR)/include/jni/include/Rinternals.h
 	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
 
 clean:
diff --git a/com.oracle.truffle.r.native/gnur/Makefile b/com.oracle.truffle.r.native/gnur/Makefile
index 40283af702454cee5bbd35dde9765457178e10bc..0b0329e6fc4c32287c2f367dd88d4e94117fdb44 100644
--- a/com.oracle.truffle.r.native/gnur/Makefile
+++ b/com.oracle.truffle.r.native/gnur/Makefile
@@ -50,7 +50,10 @@ build: $(GNUR_DIR)/bin/R
 $(GNUR_DIR)/bin/R:
 	(cd $(GNUR_DIR); make >& make.log)
 
-copy: $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET)
+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)
@@ -63,4 +66,4 @@ $(PCRE_TARGET):
 
 clean:
 	rm -rf $(GNUR_DIR)
-	rm $(TARGET_DIR)/*
+	rm -f $(BLAS_TARGET) $(LAPACK_TARGET) $(PCRE_TARGET)
diff --git a/com.oracle.truffle.r.native/include/jni/Makefile b/com.oracle.truffle.r.native/include/jni/Makefile
index 8fc940d8f85c2d694e5b71a576842ca1ef2cabf7..77442b1d075a8046372db2c8c025afb0fab6e6e1 100644
--- a/com.oracle.truffle.r.native/include/jni/Makefile
+++ b/com.oracle.truffle.r.native/include/jni/Makefile
@@ -46,10 +46,10 @@ 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
+	cp src/libintl.h include
+	ed $(GNUR_DIR)/include/Rinternals.h < ed_Rinternals
 	$(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
+	cp $(R_EXT_HEADERS_LOCAL) include/R_ext
 	touch linked
 
 clean:
diff --git a/com.oracle.truffle.r.native/include/jni/ed_Rinternals b/com.oracle.truffle.r.native/include/jni/ed_Rinternals
new file mode 100644
index 0000000000000000000000000000000000000000..3be21b755b500f156b3811b7fb4213ae889f1ff9
--- /dev/null
+++ b/com.oracle.truffle.r.native/include/jni/ed_Rinternals
@@ -0,0 +1,12 @@
+/typedef struct SEXPREC \*SEXP;/
+i
+#ifdef FASTR
+#include <jni.h>
+typedef jobject SEXP;
+#else
+.
++1
+a
+#endif
+.
+w include/Rinternals.h
diff --git a/com.oracle.truffle.r.native/include/jni/sed_Rinternals b/com.oracle.truffle.r.native/include/jni/sed_Rinternals
deleted file mode 100644
index f5c6a0d20102bc000ba924b876e11643bf53049b..0000000000000000000000000000000000000000
--- a/com.oracle.truffle.r.native/include/jni/sed_Rinternals
+++ /dev/null
@@ -1,7 +0,0 @@
-/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/library/base/sed_profile b/com.oracle.truffle.r.native/library/base/sed_profile
index 98ccfd58682fb42ae30c0ab8e388917cd1e6fa53..1b6fd22615e50e175a604016ff60c9662f598437 100644
--- a/com.oracle.truffle.r.native/library/base/sed_profile
+++ b/com.oracle.truffle.r.native/library/base/sed_profile
@@ -1 +1 @@
-/           dp <- c("datasets", "utils", "grDevices", "graphics",/s/c("/c("fastr", /
+/           dp <- c("datasets", "utils", "grDevices", "graphics",/s/c("/c("fastr", "/
diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk
index fdab1f1ade59e34076bb562086f2c494691cbb50..1419d513be58f558ad13c4e7f38880046a1a9682 100644
--- a/com.oracle.truffle.r.native/library/lib.mk
+++ b/com.oracle.truffle.r.native/library/lib.mk
@@ -52,7 +52,7 @@ LIBDIR := $(OBJ)
 LIB_PKG := $(OBJ)/$(PKG).so
 
 JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(OS_DIR)
-FFI_INCLUDES = -I$(TOPDIR)/include/jni
+FFI_INCLUDES = -I$(TOPDIR)/include/jni/include
 
 INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 
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 8abbc3b2c6f4d4d552cd4cc1139c05bea29c91c8..5d01a5cd904368fd580c7c00db20fad3d7226b33 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
@@ -40,7 +40,7 @@ ifeq ($(FASTR_INSTALL), GNUR)
     endif
     LDFLAGS :=  $(LDFLAGS) $(FRAMEWORKFLAGS)
 else
-    INCLUDES := -I $(NATIVE_PROJECT)/include/jni -I $(FASTR_JAVA_HOME)/include -I $(FASTR_JAVA_HOME)/include/$(OS_DIR)
+    INCLUDES := -I $(NATIVE_PROJECT)/include/jni/include -I $(FASTR_JAVA_HOME)/include -I $(FASTR_JAVA_HOME)/include/$(OS_DIR)
 endif
 
 
diff --git a/com.oracle.truffle.r.test.native/urand/Makefile b/com.oracle.truffle.r.test.native/urand/Makefile
index cec8681d96cba241e380441d8ecab53b1fe62783..615dc22c37233da72c025cda523f154fe0427e7e 100644
--- a/com.oracle.truffle.r.test.native/urand/Makefile
+++ b/com.oracle.truffle.r.test.native/urand/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 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
@@ -41,7 +41,7 @@ C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
 C_LIB := $(OBJ)/$(C_LIBNAME)
 
 
-INCLUDE_DIR := $(NATIVE_PROJECT)/include/jni
+INCLUDE_DIR := $(NATIVE_PROJECT)/include/jni/include
 
 all: $(C_LIB)