Skip to content

Commit

Permalink
added android aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
xuchen committed Apr 21, 2017
1 parent a6f5bf1 commit 4bb50d6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 23 deletions.
4 changes: 4 additions & 0 deletions examples/Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Note:

cd swig/Android
make

To make for ARMv8 64bit:

make BIT=64

Ths will generate a cross-compiled library for ARM:

Expand Down
Binary file added lib/android/armv8-aarch64/libsnowboy-detect.a
Binary file not shown.
64 changes: 45 additions & 19 deletions swig/Android/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# Example Makefile that wrappers snowboy c++ library (snowboy-detect.a) through
# JNI interface, using swig.

# This Makefile is optimized for armv7-a architecture. Also, please make sure
# This Makefile is optimized for armv7-a/armv8 architecture. Also, please make sure
# "unzip" is installed.
# Usage:
# make # for 32bit ARM
# make BIT=64 # for 64bit ARM

# Please use swig-3.0.10 or up.
SWIG := swig

# Please specify your NDK root directory here.
NDK_VERSION="r14b"
NDKINSTALLEDROOT := $(PWD)/ndk_install
NDK_VERSION=r14b
BIT = 32
ifeq ($(BIT), 64)
NDKINSTALLEDROOT := $(PWD)/ndk_install_64bit
OPENBLASTARGET := ARMV8
else
NDKINSTALLEDROOT := $(PWD)/ndk_install_32bit
OPENBLASTARGET := ARMV7
endif
NDKROOT := $(PWD)/android-ndk-${NDK_VERSION}

SNOWBOYDETECTSWIGITF = snowboy-detect-swig.i
Expand All @@ -28,21 +38,37 @@ CXXFLAGS := -O3 --sysroot=$(NDKINSTALLEDROOT)/sysroot
LDLIBS := -L$(NDKINSTALLEDROOT)/sysroot/usr/lib

ifeq ($(ARCH), arm)
AR := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-ar
CC := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-gcc
CXX := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-g++
STRIP := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-strip
OPENBLASTARGET := ARMV7
SNOWBOYDETECTLIBFILE = $(TOPDIR)/lib/android/armv7a/libsnowboy-detect.a
CXXFLAGS += -std=c++0x -rdynamic -I$(TOPDIR) -Werror -Wall \
-fsigned-char -fpic -fPIC -mfloat-abi=softfp -march=armv7-a -mfpu=neon \
-DNDEBUG -ffast-math -fomit-frame-pointer -O3 -pie -fPIE -DHAVE_NEON=1 \
-fno-strict-aliasing -Wno-unused-function -shared
LDLIBS += \
-L$(NDKROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a \
-lgnustl_static -lsupc++ -lgcc -ldl -lc -lm -llog -pthread
SNOWBOYDETECTSWIGLIBFILE := jniLibs/armeabi-v7a/$(SNOWBOYDETECTSWIGLIBFILE)
SNOWBOYDETECTSWIGLIBNAME := $(shell basename $(SNOWBOYDETECTSWIGLIBFILE))
ifeq ($(BIT), 64)
AR := $(NDKINSTALLEDROOT)/bin/aarch64-linux-android-ar
CC := $(NDKINSTALLEDROOT)/bin/aarch64-linux-android-gcc
CXX := $(NDKINSTALLEDROOT)/bin/aarch64-linux-android-g++
STRIP := $(NDKINSTALLEDROOT)/bin/aarch64-linux-android-strip
SNOWBOYDETECTLIBFILE = $(TOPDIR)/lib/android/armv8-aarch64/libsnowboy-detect.a
CXXFLAGS += -std=c++0x -rdynamic -I$(TOPDIR) -Werror -Wall \
-fsigned-char -fpic -fPIC -march=armv8-a \
-DNDEBUG -ffast-math -fomit-frame-pointer -O3 -pie -fPIE -DHAVE_NEON=1 \
-fno-strict-aliasing -Wno-unused-function -shared
LDLIBS += \
-L$(NDKROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a \
-lgnustl_static -lsupc++ -lgcc -ldl -lc -lm -llog -pthread
SNOWBOYDETECTSWIGLIBFILE := jniLibs/arm64-v8a/$(SNOWBOYDETECTSWIGLIBFILE)
SNOWBOYDETECTSWIGLIBNAME := $(shell basename $(SNOWBOYDETECTSWIGLIBFILE))
else
AR := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-ar
CC := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-gcc
CXX := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-g++
STRIP := $(NDKINSTALLEDROOT)/bin/arm-linux-androideabi-strip
SNOWBOYDETECTLIBFILE = $(TOPDIR)/lib/android/armv7a/libsnowboy-detect.a
CXXFLAGS += -std=c++0x -rdynamic -I$(TOPDIR) -Werror -Wall \
-fsigned-char -fpic -fPIC -mfloat-abi=softfp -march=armv7-a -mfpu=neon \
-DNDEBUG -ffast-math -fomit-frame-pointer -O3 -pie -fPIE -DHAVE_NEON=1 \
-fno-strict-aliasing -Wno-unused-function -shared
LDLIBS += \
-L$(NDKROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a \
-lgnustl_static -lsupc++ -lgcc -ldl -lc -lm -llog -pthread
SNOWBOYDETECTSWIGLIBFILE := jniLibs/armeabi-v7a/$(SNOWBOYDETECTSWIGLIBFILE)
SNOWBOYDETECTSWIGLIBNAME := $(shell basename $(SNOWBOYDETECTSWIGLIBFILE))
endif
endif

all: $(SNOWBOYSWIGLIBFILE) $(SNOWBOYDETECTSWIGLIBFILE)
Expand All @@ -51,7 +77,7 @@ all: $(SNOWBOYSWIGLIBFILE) $(SNOWBOYDETECTSWIGLIBFILE)
$(MAKE) -C ${@D} ${@F}

$(NDKINSTALLEDROOT):
@-./install_ndk.sh ${NDK_VERSION}
@-./install_ndk.sh ${NDK_VERSION} ${BIT}

$(OPENBLASLIBFILE): $(NDKINSTALLEDROOT)
@-./install_openblas.sh $(CC) $(AR) $(OPENBLASTARGET)
Expand Down
14 changes: 10 additions & 4 deletions swig/Android/install_ndk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@
UNAME_INFO=`uname -a`
NDK_REPOSITORY_URL="https://dl.google.com/android/repository/"
NDK_VERSION=$1
BIT=$2

if [[ $UNAME_INFO == *"Darwin"* ]]; then
if [ ! -d "android-ndk-${NDK_VERSION}" ]; then
wget -T 10 -t 3 ${NDK_REPOSITORY_URL}/android-ndk-${NDK_VERSION}-darwin-x86_64.zip \
-O android-ndk-${NDK_VERSION}-darwin-x86_64.zip || exit 1;
unzip android-ndk-${NDK_VERSION}-darwin-x86_64.zip 1>/dev/null || exit 1;
fi
unzip android-ndk-${NDK_VERSION}-darwin-x86_64.zip 1>/dev/null || exit 1;
elif [[ $UNAME_INFO == *"Linux"* ]]; then
if [ ! -d "android-ndk-${NDK_VERSION}" ]; then
wget -T 10 -t 3 ${NDK_REPOSITORY_URL}/android-ndk-${NDK_VERSION}-linux-x86_64.zip \
-O android-ndk-${NDK_VERSION}-linux-x86_64.zip || exit 1;
unzip android-ndk-${NDK_VERSION}-linux-x86_64.zip 1>/dev/null || exit 1;
fi
unzip android-ndk-${NDK_VERSION}-linux-x86_64.zip 1>/dev/null || exit 1;
else
echo "Your platform is not supported yet." || exit 1;
fi

./android-ndk-${NDK_VERSION}/build/tools/make-standalone-toolchain.sh \
--arch=arm --platform=android-14 --install-dir=`pwd`/ndk_install || exit 1;
if [[ $BIT == *"64"* ]]; then
./android-ndk-${NDK_VERSION}/build/tools/make-standalone-toolchain.sh --verbose \
--arch=arm64 --platform=android-21 --install-dir=`pwd`/ndk_install_64bit || exit 1;
else
./android-ndk-${NDK_VERSION}/build/tools/make-standalone-toolchain.sh --verbose \
--arch=arm --platform=android-14 --install-dir=`pwd`/ndk_install_32bit || exit 1;
fi

0 comments on commit 4bb50d6

Please sign in to comment.