diff --git a/.gitignore b/.gitignore index 1d328b0922..e9f057cbd0 100644 --- a/.gitignore +++ b/.gitignore @@ -124,3 +124,6 @@ capstone_get_setup *.s cstool/cstool + +# android +android-ndk-* diff --git a/Makefile b/Makefile index ff240cf78d..db477d7184 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,11 @@ endif ifeq ($(CROSS),) RANLIB ?= ranlib +else ifeq ($(ANDROID), 1) +CC = $(CROSS)/../../bin/clang +AR = $(CROSS)/ar +RANLIB = $(CROSS)/ranlib +STRIP = $(CROSS)/strip else CC = $(CROSS)gcc AR = $(CROSS)ar @@ -467,6 +472,7 @@ clean: rm -f $(LIBOBJ) rm -f $(BLDIR)/lib$(LIBNAME).* $(BLDIR)/$(LIBNAME).pc rm -f $(PKGCFGF) + [ ${ANDROID} -eq 1 ] && rm -rf android-ndk-* $(MAKE) -C cstool clean ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY))) diff --git a/make.sh b/make.sh index ddc1791cff..6c29abb033 100755 --- a/make.sh +++ b/make.sh @@ -13,6 +13,7 @@ build_android() { echo "ERROR! Please set \$NDK to point at your Android NDK directory." exit 1 fi + HOSTOS=$(uname -s | tr 'LD' 'ld') HOSTARCH=$(uname -m) @@ -22,13 +23,11 @@ build_android() { case "$TARGARCH" in arm) [ -n "$APILEVEL" ] || APILEVEL="android-14" # default to ICS - [ -n "$GCCVER" ] || GCCVER="4.8" - CROSS=arm-linux-androideabi- + CROSS=arm-linux-androideabi ;; arm64) [ -n "$APILEVEL" ] || APILEVEL="android-21" # first with arm64 - [ -n "$GCCVER" ] || GCCVER="4.9" - CROSS=aarch64-linux-android- + CROSS=aarch64-linux-android ;; *) @@ -37,10 +36,16 @@ build_android() { ;; esac - TOOLCHAIN="$NDK/toolchains/$CROSS$GCCVER/prebuilt/$HOSTOS-$HOSTARCH" - PLATFORM="$NDK/platforms/$APILEVEL/arch-$TARGARCH" + STANDALONE=`realpath android-ndk-${TARGARCH}-${APILEVEL}` + + [ -d $STANDALONE ] || { + python ${NDK}/build/tools/make_standalone_toolchain.py \ + --arch ${TARGARCH} \ + --api ${APILEVEL##*-} \ + --install-dir ${STANDALONE} + } - CROSS="$TOOLCHAIN/bin/$CROSS" CFLAGS="--sysroot=$PLATFORM" LDFLAGS="--sysroot=$PLATFORM" ${MAKE} $* + ANDROID=1 CROSS="${STANDALONE}/${CROSS}/bin" CFLAGS="--sysroot=${STANDALONE}/sysroot" ${MAKE} $* } # build iOS lib for all iDevices, or only specific device