jbigi: Support android builds using NDK

Prep for GMP 6.1.2
This commit is contained in:
zzz
2019-06-05 17:13:15 +00:00
parent aab6529f62
commit 4bd0f06cd6
4 changed files with 73 additions and 13 deletions

View File

@@ -6,8 +6,8 @@
# Set $I2P to point to your I2P installation
# Set $JAVA_HOME to point to your Java SDK
# build.sh
# This script downloads gmp-4.3.2.tar.bz2 to this directory
# (if a different version, change the GMP_VER= line below)
# This script downloads gmp-6.1.2.tar.bz2 to this directory
# (if a different version, change the GMP_VER= line in download_gmp.sh)
#
# To build a dynamic library (you must have a libgmp.so somewhere in your system)
# Set $I2P to point to your I2P installation

View File

@@ -77,6 +77,16 @@ sunos*|openbsd*|netbsd*|*freebsd*|linux*)
fi
LINKFLAGS="-shared -Wl,-soname,libjbigi.so"
LIBFILE="libjbigi.so";;
android)
BUILD_OS="linux"
if [ $BITS -eq 32 ]; then
COMPILEFLAGS="-O2 -pedantic -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mtune=cortex-a5 -fPIC -DPIC"
else
COMPILEFLAGS="-O2 -pedantic -march=armv8-a -Wa,--noexecstack -fPIC -DPIC"
fi
LINKFLAGS="-shared -Wl,-soname,libjbigi.so"
INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/$BUILD_OS -I/usr/local/include"
LIBFILE="libjbigi.so";;
*)
echo "Unsupported system type."
exit 1;;
@@ -110,5 +120,8 @@ else
fi
echo "Link: \"$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS $LIBPATH\""
$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS $LIBPATH || exit 1
if [ ! -z "$STRIP" ]; then
echo "Strip: \"$STRIP $LIBFILE\""
$STRIP $LIBFILE
fi
exit 0

View File

@@ -1,4 +1,8 @@
#!/bin/sh
#
# This script downloads gmp-6.1.2.tar.bz2 to this directory
# (if a different version, change the GMP_VER= line below)
#
export GMP_VER=6.1.2
export GMP_TARVER=${GMP_VER}

View File

@@ -50,7 +50,7 @@ TRANSLATE_NAME_armv7a="armv7"
# Note! these build on 32bit as 32bit when operating as 32bit...
# starting with k10 added for 6.0.0
# As of GMP 6.0.0, libgmp 3,
X86_64_PLATFORMS="coreisbr coreihwl coreibwl bobcat jaguar bulldozer piledriver steamroller excavator atom athlon64 core2 corei nano pentium4 k10 x86_64"
X86_64_PLATFORMS="skylake coreisbr coreihwl coreibwl bobcat jaguar bulldozer piledriver steamroller excavator atom athlon64 core2 corei nano pentium4 k10 x86_64"
TRANSLATE_NAME_x86_64="none" # Rename x86_64 to none_64, since that is what NativeBigInteger refers to it as
# Note! these are 32bit _ONLY_ (after the 64 bit ones)
@@ -66,6 +66,12 @@ FREEBSD_PLATFORMS="${X86_PLATFORMS} ${MISC_FREEBSD_PLATFORMS}"
NETBSD_PLATFORMS="${FREEBSD_PLATFORMS} ${MISC_LINUX_PLATFORMS} ${MISC_NETBSD_PLATFORMS}"
OPENBSD_PLATFORM="${X86_PLATFORMS} ${MISC_OPENBSD_PLATFORMS}"
# Android
# https://developer.android.com/ndk/guides/other_build_systems
ANDROID_64_PLATFORMS="aarch64"
ANDROID_32_PLATFORMS="armv7a"
# Import gmp version variables and download gmp.
. ./download_gmp.sh
@@ -114,15 +120,21 @@ if [ -z $CC ]; then
printf "\aCC variable not set, defaulting to $CC\n\a" >&2
fi
# FIXME -m32 and -m64 are only for x86
# Allow TARGET to be overridden (e.g. for use with cross compilers)
[ -z $TARGET ] && TARGET=$(uname -s |tr "[A-Z]" "[a-z]")
if [ $BITS -eq 32 ]; then
export ABI=32
export CFLAGS="-m32"
export LDFLAGS="-m32"
if [ "$TARGET" != "android" ]; then
export CFLAGS="-m32"
export LDFLAGS="-m32"
fi
elif [ $BITS -eq 64 ]; then
export ABI=64
export CFLAGS="-m64"
export LDFLAGS="-m64"
if [ "$TARGET" != "android" ]; then
export CFLAGS="-m64"
export LDFLAGS="-m64"
fi
else
printf "\aBITS value \"$BITS\" not valid, please select 32 or 64\n\a" >&2
exit 1
@@ -134,13 +146,10 @@ if ! command -v ${CC} > /dev/null; then
fi
# Set the "_64" filname filename suffix for 64-bit builds
if [ $BITS -ne 32 ]; then
if [ $BITS -ne 32 -a "$TARGET" != "android" ]; then
[ -z $SUFFIX ] && SUFFIX="_64"
fi
# Allow TARGET to be overridden (e.g. for use with cross compilers)
[ -z $TARGET ] && TARGET=$(uname -s |tr "[A-Z]" "[a-z]")
# Note, this line does not support windows (and needs to generate a win32/win64 string for that to work)
BUILD_OS=$(uname -s | tr "[A-Z]" "[a-z]")
@@ -189,6 +198,29 @@ if [ "$TARGET" != "$BUILD_OS" ]; then
# ;;
# esac
# ;;
android)
ANDROID_NDK=`realpath ../../../../android-ndk-r19c`
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
if [ $BITS -eq 32 ]; then
HOST_CONFIGURE_FLAG=armv7a-linux-androideabi
export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
export AS=$TOOLCHAIN/bin/arm-linux-androideabi-as
export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi16-clang
export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi16-clang++
export LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
export RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
export STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip
else
HOST_CONFIGURE_FLAG=aarch64-linux-android
export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
fi
;;
esac
fi
@@ -277,6 +309,17 @@ netbsd*|freebsd*|openbsd*)
esac
esac
echo "Building ${TARGET} .sos for ${ARCH}";;
android)
NAME="libjbigi"
TYPE="so"
if [ $BITS -eq 32 ]; then
PLATFORM_LIST="${ANDROID_32_PLATFORMS}"
ARCH="armv7a"
else
PLATFORM_LIST="${ANDROID_64_PLATFORMS}"
ARCH="aarch64"
fi
echo "Building Android .so for ${PLATFORM_LIST}";;
*)
echo "Unsupported build environment"
exit;;