Add arm support

This commit is contained in:
xerial 2017-01-19 11:28:50 -08:00
parent c365c444a5
commit fb530fd0fb
8 changed files with 120 additions and 40 deletions

View File

@ -167,6 +167,8 @@ freebsd64:
$(MAKE) native OS_NAME=FreeBSD OS_ARCH=x86_64
# For ARM
native-arm: linux-arm linux-armv6 linux-armv7 linux-android-arm
linux-arm: jni-header
./docker/dockcross-armv5 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=arm-linux-gnueabi- OS_NAME=Linux OS_ARCH=arm'

View File

@ -42,7 +42,7 @@ endif
# os=Default is meant to be generic unix/linux
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armhf Linux-aarch64 Linux-ppc Linux-ppc64 Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-aarch64 Linux-ppc Linux-ppc64 Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64
os_arch := $(OS_NAME)-$(OS_ARCH)
IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7"))
@ -188,17 +188,31 @@ SunOS-x86_64_SNAPPY_FLAGS :=
Linux-arm_CXX := $(CROSS_PREFIX)g++
Linux-arm_STRIP := $(CROSS_PREFIX)strip
Linux-arm_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=softfp
Linux-arm_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=softfp
Linux-arm_LINKFLAGS := -shared -static-libgcc
Linux-arm_LIBNAME := libsnappyjava.so
Linux-arm_SNAPPY_FLAGS:=
Linux-armhf_CXX := $(CROSS_PREFIX)g++
Linux-armhf_STRIP := $(CROSS_PREFIX)strip
Linux-armhf_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=hard
Linux-armhf_LINKFLAGS := -shared -static-libgcc
Linux-armhf_LIBNAME := libsnappyjava.so
Linux-armhf_SNAPPY_FLAGS:=
Linux-armv6_CXX := $(CROSS_PREFIX)g++
Linux-armv6_STRIP := $(CROSS_PREFIX)strip
Linux-armv6_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=hard
Linux-armv6_LINKFLAGS := -shared -static-libgcc
Linux-armv6_LIBNAME := libsnappyjava.so
Linux-armv6_SNAPPY_FLAGS:=
Linux-armv7_CXX := $(CROSS_PREFIX)g++
Linux-armv7_STRIP := $(CROSS_PREFIX)strip
Linux-armv7_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=hard
Linux-armv7_LINKFLAGS := -shared -static-libgcc
Linux-armv7_LIBNAME := libsnappyjava.so
Linux-armv7_SNAPPY_FLAGS:=
Linux-android-arm_CXX := $(CROSS_PREFIX)g++
Linux-android-arm_STRIP := $(CROSS_PREFIX)strip
Linux-android-arm_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden
Linux-android-arm_LINKFLAGS := -shared -static-libgcc
Linux-android-arm_LIBNAME := libsnappyjava.so
Linux-android-arm_SNAPPY_FLAGS:=
Linux-aarch64_CXX := $(CROSS_PREFIX)g++
Linux-aarch64_STRIP := $(CROSS_PREFIX)strip

View File

@ -24,7 +24,9 @@
//--------------------------------------
package org.xerial.snappy;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
@ -33,8 +35,7 @@ import java.util.Locale;
*
* @author leo
*/
public class OSInfo
{
public class OSInfo {
private static HashMap<String, String> archMapping = new HashMap<String, String>();
public static final String X86 = "x86";
@ -94,14 +95,13 @@ public class OSInfo
archMapping.put(AARCH_64, AARCH_64);
}
public static void main(String[] args)
{
if (args.length >= 1) {
if ("--os".equals(args[0])) {
public static void main(String[] args) {
if(args.length >= 1) {
if("--os".equals(args[0])) {
System.out.print(getOSName());
return;
}
else if ("--arch".equals(args[0])) {
else if("--arch".equals(args[0])) {
System.out.print(getArchName());
return;
}
@ -110,60 +110,125 @@ public class OSInfo
System.out.print(getNativeLibFolderPathForCurrentOS());
}
public static String getNativeLibFolderPathForCurrentOS()
{
public static String getNativeLibFolderPathForCurrentOS() {
return getOSName() + "/" + getArchName();
}
public static String getOSName()
{
public static String getOSName() {
return translateOSNameToFolderName(System.getProperty("os.name"));
}
public static String getArchName()
{
// if running Linux on ARM, need to determine ABI of JVM
String osArch = System.getProperty("os.arch");
if (osArch.startsWith("arm") && System.getProperty("os.name").contains("Linux")) {
public static boolean isAndroid() {
return System.getProperty("java.runtime.name", "").toLowerCase().contains("android");
}
static String getHardwareName() {
try {
Process p = Runtime.getRuntime().exec("uname -m");
p.waitFor();
InputStream in = p.getInputStream();
try {
int readLen = 0;
ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] buf = new byte[32];
while((readLen = in.read(buf, 0, buf.length)) >= 0) {
b.write(buf, 0, readLen);
}
return b.toString();
}
finally {
if(in != null) {
in.close();
}
}
}
catch(Throwable e) {
System.err.println("Error while running uname -m: " + e.getMessage());
return "unknown";
}
}
static String resolveArmArchType() {
// For Android
if(isAndroid()) {
return "android-arm";
}
if(System.getProperty("os.name").contains("Linux")) {
String armType = getHardwareName();
// armType (uname -m) can be armv5t, armv5te, armv5tej, armv5tejl, armv6, armv7, armv7l, i686
if(armType.startsWith("armv6")) {
// Raspberry PI
return "armv6";
}
else if(armType.startsWith("armv7")) {
// Generic
return "armv7";
}
// Java 1.8 introduces a system property to determine armel or armhf
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8005545
String abi = System.getProperty("sun.arch.abi");
if(abi != null && abi.startsWith("gnueabihf")) {
return "armv7";
}
// For java7, we stil need to if run some shell commands to determine ABI of JVM
String javaHome = System.getProperty("java.home");
try {
// determine if first JVM found uses ARM hard-float ABI
String[] cmdarray = {"/bin/sh", "-c", "find '" + javaHome +
int exitCode = Runtime.getRuntime().exec("which readelf").waitFor();
if(exitCode == 0) {
String[] cmdarray = {"/bin/sh", "-c", "find '" + javaHome +
"' -name 'libjvm.so' | head -1 | xargs readelf -A | " +
"grep 'Tag_ABI_VFP_args: VFP registers'"};
int exitCode = Runtime.getRuntime().exec(cmdarray).waitFor();
if (exitCode == 0) {
return "armhf";
exitCode = Runtime.getRuntime().exec(cmdarray).waitFor();
if(exitCode == 0) {
return "armv7";
}
}
else {
System.err.println("WARNING! readelf not found. Cannot check if running on an armhf system, " +
"armel architecture will be presumed.");
}
}
catch (IOException e) {
catch(IOException e) {
// ignored: fall back to "arm" arch (soft-float ABI)
}
catch (InterruptedException e) {
catch(InterruptedException e) {
// ignored: fall back to "arm" arch (soft-float ABI)
}
}
// Use armv5, soft-float ABI
return "arm";
}
public static String getArchName() {
String osArch = System.getProperty("os.arch");
if(osArch.startsWith("arm")) {
osArch = resolveArmArchType();
}
else {
String lc = osArch.toLowerCase(Locale.US);
if (archMapping.containsKey(lc)) {
if(archMapping.containsKey(lc))
return archMapping.get(lc);
}
}
return translateArchNameToFolderName(osArch);
}
static String translateOSNameToFolderName(String osName)
{
if (osName.contains("Windows")) {
static String translateOSNameToFolderName(String osName) {
if(osName.contains("Windows")) {
return "Windows";
}
else if (osName.contains("Mac")) {
else if(osName.contains("Mac")) {
return "Mac";
}
else if (osName.contains("Linux")) {
else if(osName.contains("Linux")) {
return "Linux";
}
else if (osName.contains("AIX")) {
else if(osName.contains("AIX")) {
return "AIX";
}
else {
@ -171,8 +236,7 @@ public class OSInfo
}
}
static String translateArchNameToFolderName(String archName)
{
static String translateArchNameToFolderName(String archName) {
return archName.replaceAll("\\W", "");
}
}