radare2/sys/ndk-gcc

121 lines
2.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# android gcc wrapper
2016-01-16 12:15:25 +00:00
if [ -z "${NDK}" ]; then
NDK=~/Downloads/android-ndk-r10e
if [ ! -d "${NDK}" ]; then
echo "Invalid path in NDK environment"
exit 1
fi
fi
if [ -n "${NDK_ARCH}" ]; then
ARCH=${NDK_ARCH}
else
2012-03-30 11:33:38 +00:00
ARCH=mips
ARCH=arm
ARCH=x86
fi
#------------------------------------------#
PROGDIR="$(dirname "$0")"
PROGDIR="$(cd "$PROGDIR" && pwd)"
ANDROID_KITKAT=19
ANDROID_LOLIPOP=21
2015-06-17 02:59:01 +00:00
# shellcheck disable=SC2019
# shellcheck disable=SC2018
2015-06-17 02:59:01 +00:00
OS="$(uname | tr 'A-Z' 'a-z')"
2012-03-31 01:54:44 +00:00
[ "${OS}" = macos ] && OS=darwin
2014-11-10 00:09:38 +00:00
ARCH2=${ARCH}
2012-03-30 11:33:38 +00:00
case "${ARCH}" in
2014-11-10 00:09:38 +00:00
aarch64)
ANDROID_SDK_VERSION=${ANDROID_LOLIPOP}
2014-11-10 00:09:38 +00:00
NDKPFX=${ARCH}-linux-android
ARCH2=arm64
;;
2012-03-30 11:33:38 +00:00
arm)
ANDROID_SDK_VERSION=${ANDROID_KITKAT}
2012-03-30 11:33:38 +00:00
NDKPFX=${ARCH}-linux-androideabi
;;
mips)
2015-04-12 23:16:01 +00:00
ANDROID_SDK_VERSION=${ANDROID_KITKAT}
NDKPFX=mipsel-linux-android
2012-09-20 02:10:08 +00:00
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=mipsel-linux-android
fi
2012-03-30 11:33:38 +00:00
;;
mips64)
2015-04-12 23:16:01 +00:00
ANDROID_SDK_VERSION=${ANDROID_LOLIPOP}
NDKPFX=mips64el-linux-android
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=mips64el-linux-android
fi
;;
2012-03-30 11:33:38 +00:00
x86)
ANDROID_SDK_VERSION=${ANDROID_KITKAT} #x86
2012-03-30 11:33:38 +00:00
NDKPFX=i686-android-linux
2012-09-20 02:10:08 +00:00
${NDKPFX}-gcc 2>/dev/null
if [ $? -gt 1 ]; then
NDKPFX=i686-linux-android
fi
2012-03-30 11:33:38 +00:00
;;
esac
2014-08-01 10:44:43 +00:00
if [ -d "${PROGDIR}/platforms/android-L/arch-${ARCH}" ]; then
ANDROID_SDK_VERSION=L
fi
2013-04-12 00:39:46 +00:00
2014-09-23 22:40:33 +00:00
PROGDIR=${NDK}
PLATFORM=android-${ANDROID_SDK_VERSION}
2014-11-10 00:09:38 +00:00
PLATFORM_ROOT=${PROGDIR}/platforms/${PLATFORM}/arch-${ARCH2}
2011-09-26 00:10:25 +00:00
PLATFORM_PATH=${PLATFORM_ROOT}/usr
# shellcheck disable=SC2010
2015-06-17 02:59:01 +00:00
NDK_BINS=$(ls "${PROGDIR}"/toolchains/*/prebuilt/"${OS}"*/bin |grep prebuilt | grep "/${ARCH}-" |sort |tail -n 1)
# shellcheck disable=SC2010
2014-09-24 01:49:28 +00:00
[ -z "${NDK_BINS}" ] && \
NDK_BINS=$(ls "${PROGDIR}"/toolchains/*/prebuilt/"${OS}"*/bin |grep prebuilt | grep "/${ARCH}" |sort |tail -n 1)
2014-09-24 01:37:22 +00:00
#echo "ls ${PROGDIR}/toolchains/*/prebuilt/linux*/bin |grep prebuilt | grep "/${ARCH}-" |sort |tail -n 1"
2014-11-10 00:09:38 +00:00
#echo NDKBINS=${NDK_BINS}
2014-09-23 22:40:33 +00:00
if [ -z "${NDK_BINS}" ]; then
echo "Cant find NDK_BINS"
exit 1
fi
CFLAGS="${CFLAGS} --sysroot=${PLATFORM_ROOT}"
2011-09-26 00:10:25 +00:00
CFLAGS="${CFLAGS} -I${PLATFORM_PATH}/include"
CFLAGS="${CFLAGS} -fPIC -fPIE"
2014-11-11 01:14:19 +00:00
case "${ARCH}" in
mips64)
LDFLAGS=-L${PLATFORM_PATH}/lib64
;;
*)
LDFLAGS=-L${PLATFORM_PATH}/lib
;;
esac
2011-09-26 00:10:25 +00:00
#LDFLAGS="${LDFLAGS} -nostdlib"
#LDFLAGS="${LDFLAGS} -lc -ldl"
#LDFLAGS="${LDFLAGS} -Wl,-dynamic-linker=/system/bin/linker"
LDFLAGS="${LDFLAGS} --sysroot=${PLATFORM_ROOT}"
2015-04-29 08:41:18 +00:00
#if [ -z "`echo $*" | grep shared`" ]; then
2011-09-26 00:10:25 +00:00
#LDFLAGS="${LDFLAGS} ${PLATFORM_PATH}/lib/crtbegin_dynamic.o"
#fi
CC="${NDKPFX}-gcc"
AR="${NDKPFX}-ar"
EXT_SO=so
export PATH="${NDK_BINS}:$PATH"
2013-04-12 00:39:46 +00:00
export EXT_SO AR CC CFLAGS LDFLAGS PATH
#shellcheck disable=SC2048
#shellcheck disable=SC2086
echo ${CC} ${LDFLAGS} ${CFLAGS} $*
${CC} ${LDFLAGS} ${CFLAGS} $*