diff --git a/Makefile b/Makefile index 0f14338c..57ece653 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ $(SNAPPY_GIT_UNPACKED): git clone $(GIT_REPO_URL) $(SNAPPY_SRC_DIR) git --git-dir=$(SNAPPY_SRC_DIR)/.git --work-tree=$(SNAPPY_SRC_DIR) checkout -b local/snappy-$(GIT_SNAPPY_BRANCH) $(GIT_SNAPPY_BRANCH) touch $@ - cd $(SNAPPY_SRC_DIR) && ./configure + cd $(SNAPPY_SRC_DIR) && ./autogen.sh && ./configure jni-header: $(SRC)/org/xerial/snappy/SnappyNative.h diff --git a/Makefile.common b/Makefile.common index 7b22f07d..edba3c75 100755 --- a/Makefile.common +++ b/Makefile.common @@ -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-ppc64 Mac-x86 Mac-x86_64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc64 +known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armhf 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-ppc64 os_arch := $(OS_NAME)-$(OS_ARCH) IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7")) @@ -94,12 +94,23 @@ Linux-x86_64_LINKFLAGS := -shared -static-libgcc -static-libstdc++ Linux-x86_64_LIBNAME := libsnappyjava.so Linux-x86_64_SNAPPY_FLAGS := +Linux-ppc_CXX := g++ +Linux-ppc_STRIP := strip +ifeq ($(IBM_JDK_7),) + Linux-ppc_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m32 +else + Linux-ppc_CXXFLAGS := -DHAVE_CONFIG_H -include lib/inc_linux/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC -m32 +endif +Linux-ppc_LINKFLAGS := -shared -static-libgcc -static-libstdc++ +Linux-ppc_LIBNAME := libsnappyjava.so +Linux-ppc_SNAPPY_FLAGS := + Linux-ppc64_CXX := g++ Linux-ppc64_STRIP := strip ifeq ($(IBM_JDK_7),) Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64 else - Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC + Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC -m64 endif Linux-ppc64_LINKFLAGS := -shared -static-libgcc -static-libstdc++ Linux-ppc64_LIBNAME := libsnappyjava.so @@ -116,6 +127,29 @@ endif AIX-ppc64_LINKFLAGS := -shared -static-libgcc -static-libstdc++ -lcrypt AIX-ppc64_SNAPPY_FLAGS := +Linux-s390_CXX := g++ +Linux-s390_STRIP := strip +ifeq ($(IBM_JDK_7),) + Linux-s390_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m31 +else + Linux-s390_CXXFLAGS := -DHAVE_CONFIG_H -I$(JAVA_HOME)/include/linux -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -m31 +endif +Linux-s390_LINKFLAGS := -shared -static-libgcc -static-libstdc++ +Linux-s390_LIBNAME := libsnappyjava.so +Linux-s390_SNAPPY_FLAGS := + +Linux-s390x_CXX := g++ +Linux-s390x_STRIP := strip +ifeq ($(IBM_JDK_7),) + Linux-s390x_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64 +else + Linux-s390x_CXXFLAGS := -DHAVE_CONFIG_H -I$(JAVA_HOME)/include/linux -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -m64 +endif +#Linux-s390x_LINKFLAGS := -shared -static-libgcc -static-libstdc++ +Linux-s390x_LINKFLAGS := -shared -static-libgcc +Linux-s390x_LIBNAME := libsnappyjava.so +Linux-s390x_SNAPPY_FLAGS := + SunOS-x86_CXX := g++ SunOS-x86_STRIP := strip SunOS-x86_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden diff --git a/README.md b/README.md index d2fe0048..5cf02dff 100755 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ When building on Solaris use A file `target/snappy-java-$(version).jar` is the product additionally containing the native library built for your platform. -## Building linux x86_64 binary +## Building linux x86\_64 binary snappy-java tries to static link libstdc++ to increase the availability for various Linux versions. However, standard distributions of 64-bit Linux OS rarely provide libstdc++ compiled with `-fPIC` option. I currently uses custom g++, compiled as follows: @@ -128,6 +128,14 @@ $ make install This g++ build enables static linking of libstdc++. For more infomation on building GCC, see GCC's home page. +## Building Linux s390/s390x binaries + +Older snapshots of snappy contain a buggy config.h.in that does not work properly on some big-endian platforms like Linux on IBM z (s390/s390x). Building snappy-java on s390/s390x requires fetching the snappy source from GitHub, and processing the source with autoconf to obtain a usable config.h. On a RHEL s390x system, these steps produced a working 64-bit snappy-java build (the process should be similar for other distributions): + + $ sudo yum install java-1.7.1-ibm-devel libstdc++-static-devel + $ export JAVA_HOME=/usr/lib/jvm/java-1.7.1-ibm-1.7.1.2.10-1jpp.3.el7_0.s390x + $ make USE_GIT=1 GIT_REPO_URL=https://github.com/google/snappy.git GIT_SNAPPY_BRANCH=master IBM_JDK_7=1 + ## Cross-compiling for other platforms The Makefile contains rules for cross-compiling the native library for other platforms so that the snappy-java JAR can support multiple platforms. For example, to build the native libraries for x86 Linux, x86 and x86-64 Windows, and soft- and hard-float ARM: diff --git a/build.sbt b/build.sbt index dab77b0c..9c2c3159 100644 --- a/build.sbt +++ b/build.sbt @@ -95,6 +95,7 @@ OsgiKeys.additionalHeaders := Map( "org/xerial/snappy/native/Linux/arm/libsnappyjava.so;osname=linux;processor=arm", "org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64", "org/xerial/snappy/native/Linux/ppc64le/libsnappyjava.so;osname=linux;processor=ppc64le", +"org/xerial/snappy/native/Linux/s390x/libsnappyjava.so;osname=linux;processor=s390x", "org/xerial/snappy/native/AIX/ppc64/libsnappyjava.a;osname=aix;processor=ppc64", "org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86", "org/xerial/snappy/native/SunOS/x86_64/libsnappyjava.so;osname=sunos;processor=x86-64", diff --git a/src/main/java/org/xerial/snappy/OSInfo.java b/src/main/java/org/xerial/snappy/OSInfo.java index 1ed7a842..fc4d926f 100755 --- a/src/main/java/org/xerial/snappy/OSInfo.java +++ b/src/main/java/org/xerial/snappy/OSInfo.java @@ -44,6 +44,8 @@ public class OSInfo public static final String IA64 = "ia64"; public static final String PPC = "ppc"; public static final String PPC64 = "ppc64"; + public static final String IBMZ = "s390"; + public static final String IBMZ_64 = "s390x"; static { // x86 mappings @@ -81,6 +83,12 @@ public class OSInfo archMapping.put("powerpc64", PPC64); archMapping.put("power_pc64", PPC64); archMapping.put("power_rs64", PPC64); + + // IBM z mappings + archMapping.put(IBMZ, IBMZ); + + // IBM z 64-bit mappings + archMapping.put(IBMZ_64, IBMZ_64); } diff --git a/src/main/resources/org/xerial/snappy/native/Linux/s390x/libsnappyjava.so b/src/main/resources/org/xerial/snappy/native/Linux/s390x/libsnappyjava.so new file mode 100755 index 00000000..b87e9be5 Binary files /dev/null and b/src/main/resources/org/xerial/snappy/native/Linux/s390x/libsnappyjava.so differ