2011-09-25 04:57:13 +00:00
|
|
|
#!/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
|
|
|
|
|
2011-09-25 04:57:13 +00:00
|
|
|
if [ -n "${NDK_ARCH}" ]; then
|
|
|
|
ARCH=${NDK_ARCH}
|
|
|
|
else
|
2012-03-30 11:33:38 +00:00
|
|
|
ARCH=mips
|
2011-09-25 04:57:13 +00:00
|
|
|
ARCH=arm
|
|
|
|
ARCH=x86
|
|
|
|
fi
|
|
|
|
|
|
|
|
#------------------------------------------#
|
|
|
|
|
2015-06-17 03:09:21 +00:00
|
|
|
PROGDIR="$(dirname "$0")"
|
|
|
|
PROGDIR="$(cd "$PROGDIR" && pwd)"
|
2011-09-25 04:57:13 +00:00
|
|
|
|
2015-04-12 13:46:37 +00:00
|
|
|
ANDROID_KITKAT=19
|
|
|
|
ANDROID_LOLIPOP=21
|
|
|
|
|
2015-06-17 02:59:01 +00:00
|
|
|
# shellcheck disable=SC2019
|
2015-06-17 03:09:21 +00:00
|
|
|
# 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
|
2011-09-25 04:57:13 +00:00
|
|
|
|
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)
|
2015-04-12 13:46:37 +00:00
|
|
|
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)
|
2015-04-12 13:46:37 +00:00
|
|
|
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}
|
2014-11-11 00:26:05 +00:00
|
|
|
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
|
|
|
;;
|
2014-11-11 00:26:05 +00:00
|
|
|
mips64)
|
2015-04-12 23:16:01 +00:00
|
|
|
ANDROID_SDK_VERSION=${ANDROID_LOLIPOP}
|
2014-11-11 00:26:05 +00:00
|
|
|
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)
|
2015-04-12 13:46:37 +00:00
|
|
|
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
|
2011-09-25 04:57:13 +00:00
|
|
|
|
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}
|
2011-09-25 04:57:13 +00:00
|
|
|
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
|
2015-06-17 03:09:21 +00:00
|
|
|
# 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)
|
2015-06-17 03:09:21 +00:00
|
|
|
# shellcheck disable=SC2010
|
2014-09-24 01:49:28 +00:00
|
|
|
[ -z "${NDK_BINS}" ] && \
|
2015-06-17 03:09:21 +00:00
|
|
|
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
|
2015-09-14 17:21:57 +00:00
|
|
|
CFLAGS="${CFLAGS} --sysroot=${PLATFORM_ROOT}"
|
2011-09-26 00:10:25 +00:00
|
|
|
CFLAGS="${CFLAGS} -I${PLATFORM_PATH}/include"
|
2015-09-14 17:21:57 +00:00
|
|
|
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
|
2015-09-14 17:21:57 +00:00
|
|
|
CC="${NDKPFX}-gcc"
|
|
|
|
AR="${NDKPFX}-ar"
|
2011-09-25 04:57:13 +00:00
|
|
|
EXT_SO=so
|
|
|
|
|
2015-09-14 17:21:57 +00:00
|
|
|
export PATH="${NDK_BINS}:$PATH"
|
2013-04-12 00:39:46 +00:00
|
|
|
export EXT_SO AR CC CFLAGS LDFLAGS PATH
|
2015-06-17 03:09:21 +00:00
|
|
|
|
|
|
|
#shellcheck disable=SC2048
|
|
|
|
#shellcheck disable=SC2086
|
2015-09-14 17:21:57 +00:00
|
|
|
echo ${CC} ${LDFLAGS} ${CFLAGS} $*
|
|
|
|
${CC} ${LDFLAGS} ${CFLAGS} $*
|