Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ capstone_get_setup
*.s

cstool/cstool

# android
android-ndk-*
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ endif

ifeq ($(CROSS),)
RANLIB ?= ranlib
else ifeq ($(ANDROID), 1)
CC = $(CROSS)/../../bin/clang
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a standard place for clang??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. $(CROSS)/../../bin/clang means ${STANDALONE}/bin/clang, in that dir, you can find all versions of clang, as the following:

root@xxx:~/workspace/capstone# ls android-ndk-arm64-android-21/bin/*clang*
android-ndk-arm64-android-21/bin/aarch64-linux-android-clang
android-ndk-arm64-android-21/bin/aarch64-linux-android-clang++
android-ndk-arm64-android-21/bin/aarch64-linux-android21-clang
android-ndk-arm64-android-21/bin/aarch64-linux-android21-clang++
...
...

AR = $(CROSS)/ar
RANLIB = $(CROSS)/ranlib
STRIP = $(CROSS)/strip
else
CC = $(CROSS)gcc
AR = $(CROSS)ar
Expand Down Expand Up @@ -437,6 +442,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)))
Expand Down
19 changes: 12 additions & 7 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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)

Expand All @@ -24,13 +25,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
;;

*)
Expand All @@ -39,10 +38,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
Expand Down