radare2/sys/ndk-gcc
2014-09-26 17:20:16 +02:00

77 lines
1.9 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
case "${ARCH}" in
arm)
ANDROID_SDK_VERSION=14
NDKPFX=${ARCH}-linux-androideabi
;;
mips)
ANDROID_SDK_VERSION=9 #mips
NDKPFX=mips-linux-android
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=mipsel-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-${ARCH}
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"
if [ -z "${NDK_BINS}" ]; then
echo "Cant find NDK_BINS"
exit 1
fi
CFLAGS="--sysroot=${PLATFORM_ROOT}"
CFLAGS="${CFLAGS} -I${PLATFORM_PATH}/include"
LDFLAGS=-L${PLATFORM_PATH}/lib
#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} $@