radare2/sys/ndk-gcc
2014-11-11 02:14:19 +01:00

102 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# android gcc wrapper
if [ -n "${NDK_ARCH}" ]; then
ARCH=${NDK_ARCH}
else
ARCH=mips
ARCH=arm
ARCH=x86
fi
#------------------------------------------#
PROGDIR=`dirname $0`
PROGDIR=`cd $PROGDIR && pwd`
OS=`uname | tr 'A-Z' 'a-z'`
[ "${OS}" = macos ] && OS=darwin
ARCH2=${ARCH}
case "${ARCH}" in
aarch64)
ANDROID_SDK_VERSION=21
NDKPFX=${ARCH}-linux-android
ARCH2=arm64
;;
arm)
ANDROID_SDK_VERSION=14
NDKPFX=${ARCH}-linux-androideabi
;;
mips)
ANDROID_SDK_VERSION=9 #mips
NDKPFX=mipsel-linux-android
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=mipsel-linux-android
fi
;;
mips64)
ANDROID_SDK_VERSION=21 #mips64
NDKPFX=mips64el-linux-android
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=mips64el-linux-android
fi
;;
x86)
ANDROID_SDK_VERSION=9 #x86
NDKPFX=i686-android-linux
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=i686-linux-android
fi
;;
esac
if [ -d "${PROGDIR}/platforms/android-L/arch-${ARCH}" ]; then
ANDROID_SDK_VERSION=L
fi
PROGDIR=${NDK}
PLATFORM=android-${ANDROID_SDK_VERSION}
PLATFORM_ROOT=${PROGDIR}/platforms/${PLATFORM}/arch-${ARCH2}
PLATFORM_PATH=${PLATFORM_ROOT}/usr
NDK_BINS=`ls ${PROGDIR}/toolchains/*/prebuilt/${OS}*/bin |grep prebuilt | grep "/${ARCH}-" |sort |tail -n 1`
[ -z "${NDK_BINS}" ] && \
NDK_BINS=`ls ${PROGDIR}/toolchains/*/prebuilt/${OS}*/bin |grep prebuilt | grep "/${ARCH}" |sort |tail -n 1`
#echo "ls ${PROGDIR}/toolchains/*/prebuilt/linux*/bin |grep prebuilt | grep "/${ARCH}-" |sort |tail -n 1"
#echo NDKBINS=${NDK_BINS}
if [ -z "${NDK_BINS}" ]; then
echo "Cant find NDK_BINS"
exit 1
fi
CFLAGS="--sysroot=${PLATFORM_ROOT}"
CFLAGS="${CFLAGS} -I${PLATFORM_PATH}/include"
CFLAGS="${CFLAGS} -pie -fPIC"
case "${ARCH}" in
mips64)
LDFLAGS=-L${PLATFORM_PATH}/lib64
;;
*)
LDFLAGS=-L${PLATFORM_PATH}/lib
;;
esac
#LDFLAGS="${LDFLAGS} -nostdlib"
#LDFLAGS="${LDFLAGS} -lc -ldl"
#LDFLAGS="${LDFLAGS} -Wl,-dynamic-linker=/system/bin/linker"
LDFLAGS="${LDFLAGS} --sysroot=${PLATFORM_ROOT}"
#if [ -z "`echo $@ | grep shared`" ]; then
#LDFLAGS="${LDFLAGS} ${PLATFORM_PATH}/lib/crtbegin_dynamic.o"
#fi
CC=${NDKPFX}-gcc
AR=${NDKPFX}-ar
EXT_SO=so
export PATH=${NDK_BINS}:$PATH
export EXT_SO AR CC CFLAGS LDFLAGS PATH
# echo ${CC} ${CFLAGS} ${LDFLAGS} $@
${CC} ${CFLAGS} ${LDFLAGS} $@