RFR: better support for cross compilation

Sergey Nazarkin snazarkin at azul.com
Mon Jun 25 15:10:16 UTC 2018


Hi!

With the last commit, I occasionally broke build process of some projects. So here is the patch that reverts initial behavior and also makes the lib be built on non-linux hosts. 


diff -r 1b3d9720d724 Makefile
--- a/Makefile	Tue Jun 19 19:15:30 2018 +0300
+++ b/Makefile	Mon Jun 25 17:54:14 2018 +0300
@@ -40,14 +40,19 @@
 
 ###########################################################
 # check for required env vars
-ifeq ($(CROSS_TOOL),)
-  $(error "CROSS_TOOL is not defined. Please set CROSS_TOOL to point to the location of the raspberry pi GNU toolchain")
+
+ifeq ($(CROSS_TOOL_PREFIX)$(PI_TOOLS),)
+  $(error "Neither CROSS_TOOL_PREFIX nor PI_TOOLS are defined. Please set one of them to point to the location of the raspberry pi GNU toolchain")
 endif
 
 ifeq ($(JAVA_HOME),)
   $(error "JAVA_HOME is not defined. Please set JAVA_HOME to point to the location of the JDK8 installation")
 endif
 
+# Target device JDK build, required for cross compilation, should contain "include /jni.h" and "inlude/linux/jni_md.h"
+# Default value points to host JDK
+TARGET_JDK_PATH ?= $(JAVA_HOME)
+
 BUILD_DEVICEACCESS := true
 
 DIO_JAVA_API_DIRS := \
@@ -79,10 +84,10 @@
 BUILD_NUMBER ?= dev
 
 ifneq ($(BUILD_NUMBER),dev)
-  # only include 'b' when you have an actual build number 
+  # only include 'b' when you have an actual build number
   B := b
 endif
-  
+
 
 ifeq ($(TARGET_CPU_LEGACY_LIB),arm)
   OSGI_ARCH := arm
@@ -165,15 +170,21 @@
 
 #######################################################################################################
 # tool and flag setup for arm (rasp pi) build
-TARGET_TOOLCHAIN := $(CROSS_TOOL)
-TARGET_CC := $(TARGET_TOOLCHAIN)gcc
-TARGET_CXX := $(TARGET_TOOLCHAIN)g++
-TARGET_LD := $(TARGET_TOOLCHAIN)gcc
+ifeq ($(PI_TOOLS),)
+TARGET_CC := $(CROSS_TOOL_PREFIX)gcc
+TARGET_CXX := $(CROSS_TOOL_PREFIX)g++
+TARGET_LD := $(CROSS_TOOL_PREFIX)gcc
+else
+TARGET_TOOLCHAIN := $(PI_TOOLS)
+TARGET_CC := $(TARGET_TOOLCHAIN)/bin/gcc
+TARGET_CXX := $(TARGET_TOOLCHAIN)/bin/g++
+TARGET_LD := $(TARGET_TOOLCHAIN)/bin/gcc
+endif
 JAVAC := $(JAVA_HOME)/bin/javac
 JAR := $(JAVA_HOME)/bin/jar
 MKDIR := mkdir -p
 TARGET_C_FLAGS = $(USER_C_FLAGS) -fPIC -Wno-psabi -DJAVACALL_REPORT_LEVEL=0 -DENABLE_DEVICEACCESS -c -MMD -MF $(NATIVE_OUT_DIR)/$(@).d
-TARGET_INCLUDES = $(foreach d,$(DIO_INCLUDE_DIRS),-I$(d)) -I$(JAVA_TARGET_HOME)/include -I$(JAVA_TARGET_HOME)/include/linux
+TARGET_INCLUDES = $(foreach d,$(DIO_INCLUDE_DIRS),-I$(d)) -I$(TARGET_JDK_PATH)/include -I$(TARGET_JDK_PATH)/include/linux
 TARGET_CXX_FLAGS = $(USER_CXX_FLAGS) -fPIC -Wno-psabi -DJAVACALL_REPORT_LEVEL=4 -DENABLE_DEVICEACCESS -c
 TARGET_LD_FLAGS= $(USER_LD_FLAGS) -Xlinker -z -Xlinker defs -Xlinker -O1 \
           -shared \






More information about the dio-dev mailing list