From de84602b65ffb3b914c3120a0abf78baff7959ee Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Mon, 9 Nov 2015 19:57:03 -0800
Subject: [PATCH] native project restructure; headers are not jni dependent

---
 .hgignore                                     |  3 +-
 .../builtinlibs/Makefile                      |  2 +-
 .../fficall/jni/Makefile                      |  6 +-
 com.oracle.truffle.r.native/include/Makefile  | 37 ++++++++++--
 .../include/{jni => }/ed_Rinterface           |  2 +-
 .../include/{jni => }/ed_Rinternals           |  2 +-
 .../include/jni/Makefile                      | 59 -------------------
 .../{jni => }/src/R_ext/GraphicsDevice.h.stub |  0
 .../{jni => }/src/R_ext/GraphicsEngine.h.stub |  0
 .../include/{jni => }/src/libintl.h           |  0
 com.oracle.truffle.r.native/library/lib.mk    |  2 +-
 com.oracle.truffle.r.native/run/Makefile      |  4 +-
 12 files changed, 44 insertions(+), 73 deletions(-)
 rename com.oracle.truffle.r.native/include/{jni => }/ed_Rinterface (85%)
 rename com.oracle.truffle.r.native/include/{jni => }/ed_Rinternals (96%)
 delete mode 100644 com.oracle.truffle.r.native/include/jni/Makefile
 rename com.oracle.truffle.r.native/include/{jni => }/src/R_ext/GraphicsDevice.h.stub (100%)
 rename com.oracle.truffle.r.native/include/{jni => }/src/R_ext/GraphicsEngine.h.stub (100%)
 rename com.oracle.truffle.r.native/include/{jni => }/src/libintl.h (100%)

diff --git a/.hgignore b/.hgignore
index fa55b77165..8274d5f41b 100644
--- a/.hgignore
+++ b/.hgignore
@@ -103,7 +103,8 @@ com.oracle.truffle.r.native/library/stats/src/fft.c
 com.oracle.truffle.r.native/platform.mk
 com.oracle.truffle.r.native/gnur/Makeconf.done
 com.oracle.truffle.r.native/run/Makeconf.etc
-com.oracle.truffle.r.native/include/jni/include
+com.oracle.truffle.r.native/include/*.h
+com.oracle.truffle.r.native/include/R_ext/*.h
 com.oracle.truffle.r.native/include/jni/linked
 com.oracle.truffle.r.test.native/packages/*/lib/*
 
diff --git a/com.oracle.truffle.r.native/builtinlibs/Makefile b/com.oracle.truffle.r.native/builtinlibs/Makefile
index 258e508941..4f93140735 100644
--- a/com.oracle.truffle.r.native/builtinlibs/Makefile
+++ b/com.oracle.truffle.r.native/builtinlibs/Makefile
@@ -77,7 +77,7 @@ cleanlibr:
 
 endif
 
-FFI_INCLUDES = -I$(TOPDIR)/include/jni/include -I$(TOPDIR)/include/jni/include/R_ext
+FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/include/R_ext
 
 $(OBJ)/%.o: $(SRC)/%.c
 	$(CC) $(CFLAGS) $(FFI_INCLUDES) -c $< -o $@
diff --git a/com.oracle.truffle.r.native/fficall/jni/Makefile b/com.oracle.truffle.r.native/fficall/jni/Makefile
index e73e29b359..3baea0dd10 100644
--- a/com.oracle.truffle.r.native/fficall/jni/Makefile
+++ b/com.oracle.truffle.r.native/fficall/jni/Makefile
@@ -40,7 +40,7 @@ C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
 C_LIB := $(TOPDIR)/../lib/$(C_LIBNAME)
 
 JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(JDK_OS_DIR)
-FFI_INCLUDES = -I$(TOPDIR)/include/jni/include -I$(TOPDIR)/gnur/R-3.1.3/src/include -I$(TOPDIR)/include/jni/include/R_ext
+FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/gnur/R-3.1.3/src/include -I$(TOPDIR)/include/R_ext
 
 INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 
@@ -52,10 +52,10 @@ $(C_LIB): $(OBJ) $(C_OBJECTS)
 $(OBJ):
 	mkdir -p $(OBJ)
 
-$(OBJ)/%.o: $(SRC)/%.c $(TOPDIR)/include/jni/include/Rinternals.h $(C_HDRS)
+$(OBJ)/%.o: $(SRC)/%.c $(TOPDIR)/include/Rinternals.h $(C_HDRS)
 	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
 	
-$(OBJ)/%.E: $(SRC)/%.c $(TOPDIR)/include/jni/include/Rinternals.h
+$(OBJ)/%.E: $(SRC)/%.c $(TOPDIR)/include/Rinternals.h
 	$(CC) -E $(CFLAGS) $(INCLUDES) -c $< > $@
 
 clean:
diff --git a/com.oracle.truffle.r.native/include/Makefile b/com.oracle.truffle.r.native/include/Makefile
index adb3cf69ca..fd396a5530 100644
--- a/com.oracle.truffle.r.native/include/Makefile
+++ b/com.oracle.truffle.r.native/include/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 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,9 +21,38 @@
 # questions.
 #
 
+# links to the standard R header files with some modifications for JNI-based RFFI
+
 .PHONY: all clean
 
-all:
-	$(MAKE) -C jni
+SRC=src
+
+R_EXT_HEADERS := $(wildcard $(GNUR_HOME)/include/R_ext/*.h)
+#$(info R_EXT_HEADERS=$(R_EXT_HEADERS))
+R_EXT_HEADERS_FILENAMES := $(notdir $(R_EXT_HEADERS))
+R_EXT_HEADERS_LOCAL := $(wildcard $(SRC)/R_ext/*.h)
+#$(info R_EXT_HEADERS_LOCAL=$(R_EXT_HEADERS_LOCAL))
+R_EXT_HEADERS_TO_LINK := $(filter-out $(notdir $(R_EXT_HEADERS_LOCAL)),$(R_EXT_HEADERS_FILENAMES))
+#$(info R_EXT_HEADERS_TO_LINK=$(R_EXT_HEADERS_TO_LINK))
+R_HEADERS := $(wildcard $(GNUR_HOME)/include/*.h)
+R_HEADERS_FILENAMES := $(notdir $(R_HEADERS))
+#$(info R_HEADERS_FILENAMES=$(R_HEADERS_FILENAMES))
+R_HEADERS_LOCAL := src/libintl.h src/Rinternals.h src/Rinterface.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: ed_Rinternals
+	mkdir -p R_ext
+	$(foreach file,$(R_HEADERS_TO_LINK),ln -sf $(GNUR_HOME)/include/$(file) $(file);)
+	ln -sf src/libintl.h
+	ed $(GNUR_HOME)/include/Rinternals.h < ed_Rinternals
+	ed $(GNUR_HOME)/include/Rinterface.h < ed_Rinterface
+	$(foreach file,$(R_EXT_HEADERS_TO_LINK),ln -sf $(GNUR_HOME)/include/R_ext/$(file) R_ext/$(file);)
+#	cp $(R_EXT_HEADERS_LOCAL) R_ext
+	touch linked
+
 clean:
-	$(MAKE) -C jni clean
+	rm -rf include linked
diff --git a/com.oracle.truffle.r.native/include/jni/ed_Rinterface b/com.oracle.truffle.r.native/include/ed_Rinterface
similarity index 85%
rename from com.oracle.truffle.r.native/include/jni/ed_Rinterface
rename to com.oracle.truffle.r.native/include/ed_Rinterface
index c8e97b9b39..48066ad11f 100644
--- a/com.oracle.truffle.r.native/include/jni/ed_Rinterface
+++ b/com.oracle.truffle.r.native/include/ed_Rinterface
@@ -9,4 +9,4 @@ LibExtern Rboolean FASTR_Interactive();
 a
 #endif
 .
-w include/Rinterface.h
+w Rinterface.h
diff --git a/com.oracle.truffle.r.native/include/jni/ed_Rinternals b/com.oracle.truffle.r.native/include/ed_Rinternals
similarity index 96%
rename from com.oracle.truffle.r.native/include/jni/ed_Rinternals
rename to com.oracle.truffle.r.native/include/ed_Rinternals
index 247b85858f..f8b46edd3c 100644
--- a/com.oracle.truffle.r.native/include/jni/ed_Rinternals
+++ b/com.oracle.truffle.r.native/include/ed_Rinternals
@@ -52,4 +52,4 @@ LibExtern SEXP FASTR_R_NamespaceRegistry();
 a
 #endif
 .
-w include/Rinternals.h
+w Rinternals.h
diff --git a/com.oracle.truffle.r.native/include/jni/Makefile b/com.oracle.truffle.r.native/include/jni/Makefile
deleted file mode 100644
index ce7f4e7478..0000000000
--- a/com.oracle.truffle.r.native/include/jni/Makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# 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_HOME)/include/R_ext/*.h)
-#$(info R_EXT_HEADERS=$(R_EXT_HEADERS))
-R_EXT_HEADERS_FILENAMES := $(notdir $(R_EXT_HEADERS))
-R_EXT_HEADERS_LOCAL := $(wildcard $(SRC)/R_ext/*.h)
-#$(info R_EXT_HEADERS_LOCAL=$(R_EXT_HEADERS_LOCAL))
-R_EXT_HEADERS_TO_LINK := $(filter-out $(notdir $(R_EXT_HEADERS_LOCAL)),$(R_EXT_HEADERS_FILENAMES))
-#$(info R_EXT_HEADERS_TO_LINK=$(R_EXT_HEADERS_TO_LINK))
-R_HEADERS := $(wildcard $(GNUR_HOME)/include/*.h)
-R_HEADERS_FILENAMES := $(notdir $(R_HEADERS))
-#$(info R_HEADERS_FILENAMES=$(R_HEADERS_FILENAMES))
-R_HEADERS_LOCAL := src/libintl.h src/Rinternals.h src/Rinterface.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: ed_Rinternals
-	mkdir -p include
-	mkdir -p include/R_ext
-	$(foreach file,$(R_HEADERS_TO_LINK),ln -sf $(GNUR_HOME)/include/$(file) include/$(file);)
-	cp src/libintl.h include
-	ed $(GNUR_HOME)/include/Rinternals.h < ed_Rinternals
-	ed $(GNUR_HOME)/include/Rinterface.h < ed_Rinterface
-	$(foreach file,$(R_EXT_HEADERS_TO_LINK),ln -sf $(GNUR_HOME)/include/R_ext/$(file) include/R_ext/$(file);)
-#	cp $(R_EXT_HEADERS_LOCAL) include/R_ext
-	touch linked
-
-clean:
-	rm -rf include linked
diff --git a/com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsDevice.h.stub b/com.oracle.truffle.r.native/include/src/R_ext/GraphicsDevice.h.stub
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsDevice.h.stub
rename to com.oracle.truffle.r.native/include/src/R_ext/GraphicsDevice.h.stub
diff --git a/com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsEngine.h.stub b/com.oracle.truffle.r.native/include/src/R_ext/GraphicsEngine.h.stub
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/src/R_ext/GraphicsEngine.h.stub
rename to com.oracle.truffle.r.native/include/src/R_ext/GraphicsEngine.h.stub
diff --git a/com.oracle.truffle.r.native/include/jni/src/libintl.h b/com.oracle.truffle.r.native/include/src/libintl.h
similarity index 100%
rename from com.oracle.truffle.r.native/include/jni/src/libintl.h
rename to com.oracle.truffle.r.native/include/src/libintl.h
diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk
index 8caa7e6da1..b82be56ff4 100644
--- a/com.oracle.truffle.r.native/library/lib.mk
+++ b/com.oracle.truffle.r.native/library/lib.mk
@@ -62,7 +62,7 @@ LIBDIR := $(OBJ)
 LIB_PKG := $(OBJ)/$(PKG).so
 
 JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(JDK_OS_DIR)
-FFI_INCLUDES = -I$(TOPDIR)/include/jni/include
+FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/include/R_ext
 
 INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES)
 
diff --git a/com.oracle.truffle.r.native/run/Makefile b/com.oracle.truffle.r.native/run/Makefile
index 3c8c911fe6..f7ab3752dc 100644
--- a/com.oracle.truffle.r.native/run/Makefile
+++ b/com.oracle.truffle.r.native/run/Makefile
@@ -84,9 +84,9 @@ $(FASTR_BIN_DIR)/R: Makefile R.sh Rscript.sh Rscript_exec.sh
 	# overrides
 	cp examples-header.R examples-footer.R $(FASTR_SHARE_DIR)/R
 
-includedir: Makefile $(TOPDIR)/include/jni/include/Rinternals.h
+includedir: Makefile $(TOPDIR)/include/Rinternals.h
 	mkdir -p $(FASTR_R_HOME)/include
-	cp -r $(TOPDIR)/include/jni/include/* $(FASTR_R_HOME)/include
+	cp -r $(TOPDIR)/include/* $(FASTR_R_HOME)/include
 
 clean:
 	rm -rf $(FASTR_BIN_DIR)
-- 
GitLab