Skip to content

Instantly share code, notes, and snippets.

@seven332
Last active July 5, 2016 12:10
Show Gist options
  • Select an option

  • Save seven332/6904d173f195e0fe948e7ebd80af6127 to your computer and use it in GitHub Desktop.

Select an option

Save seven332/6904d173f195e0fe948e7ebd80af6127 to your computer and use it in GitHub Desktop.
#!/bin/bash
#APS_ABI=armeabi
. ./android-prepare.sh
if (( $? != 0 )); then exit -1; fi
export AR="$APS_CROSS"ar
export AS="$APS_CROSS"as
export CC="$APS_CROSS"gcc
export CXX="$APS_CROSS"g++
export LD="$APS_CROSS"ld
export NM="$APS_CROSS"nm
export OBJDUMP="$APS_CROSS"objdump
export RANLIB="$APS_CROSS"ranlib
export STRIP="$APS_CROSS"strip
export CPPFLAGS=$APS_CPPFLAGS
export LDFLAGS=$APS_LDFLAGS
./configure \
--prefix=$APS_PREFIX\
--host=$APS_HOST \
--with-sysroot=$APS_SYSROOT
#
# Must set APS_ABI
# Set APS_API 9 as default
# Set APS_BUILD linux-x86_86 as default
#
#!/bin/bash
APS_API=${APS_API:=9}
APS_BUILD=${APS_BUILD:=linux-x86_64}
APS_NDK=${APS_NDK:=$HOME/android/android-ndk-r12}
APS_PREFIX_BASE=${APS_PREFIX_BASE:=$HOME/android/local}
ALL_APS_ABI=(
"arm64-v8a"
"x86_64"
"mips64"
"armeabi-v7a"
"armeabi"
"x86"
"mips"
)
ALL_APS_MIN_API=(
21
21
21
9
9
9
9
)
ALL_APS_TOOLCHAIN=(
"arm64"
"x86_64"
"mips64"
"arm"
"arm"
"x86"
"mips"
)
ALL_APS_ARCH=(
"aarch64"
"x86_64"
"mips64el"
"arm"
"arm"
"x86"
"mipsel"
)
ALL_APS_CPU=(
"armv8-a"
"atom"
"mips64r6"
"armv7-a"
"armv5te"
"atom"
"mips32r6"
)
ALL_APS_HOST=(
"aarch64-linux-android"
"x86_64-linux-android"
"mips64el-linux-android"
"arm-linux-androideabi"
"arm-linux-androideabi"
"i686-linux-android"
"mipsel-linux-android"
)
ALL_APS_GCC=(
"aarch64-linux-android-4.9"
"x86_64-4.9"
"mips64el-linux-android-4.9"
"arm-linux-androideabi-4.9"
"arm-linux-androideabi-4.9"
"x86-4.9"
"mipsel-linux-android-4.9"
)
ALL_APS_CPPFLAGS=(
#arm64-v8a
"-MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -g -O2 -DNDEBUG -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
#x86_64
"-MMD -MP -MF -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -g -O2 -DNDEBUG -DANDROID -Wformat -Wa,--noexecstack -Werror=format-security"
#mips64
"-MMD -MP -MF -fpic -finline-functions -ffunction-sections -funwind-tables -fstack-protector-strong -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -no-canonical-prefixes -g -O2 -DNDEBUG -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
#armeabi-v7a
"-MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -g -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -Os -DNDEBUG -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
#armeabi
"-MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -g -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -DNDEBUG -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
#x86
"-MMD -MP -MF -ffunction-sections -funwind-tables -no-canonical-prefixes -g -fstack-protector-strong -O2 -DNDEBUG -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
#mips
"-MMD -MP -MF -fpic -finline-functions -ffunction-sections -funwind-tables -fstack-protector-strong -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -no-canonical-prefixes -g -O2 -DNDEBUG -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security"
)
ALL_APS_LDFLAGS=(
#arm64-v8a
"-no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
#x86_64
"-no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
#mips64
"-no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
#armeabi-v7a
"-no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
#armeabi
"-no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
#x86
"-no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
#mips
"-no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings"
)
# Check APS_ABI
if [ -z ${APS_ABI+x} ]
then
echo "Please set ABI in '${ALL_APS_ABI[@]}'"
exit -1
fi
# Get APS_INDEX
APS_LENGTH=${#ALL_APS_ABI[@]}
APS_INDEX=-1
for i in $(seq 0 $(($APS_LENGTH-1)) )
do
if [ "$APS_ABI" = "${ALL_APS_ABI[$i]}" ]
then
APS_INDEX=$i
fi
done
if (( $APS_INDEX == -1 ))
then
echo "Unsupported ABI:" $APS_ABI
exit -1;
fi
# Fix api
APS_MIN_API=${ALL_APS_MIN_API[$APS_INDEX]}
if [ $APS_MIN_API -gt $APS_API ]; then APS_API=$APS_MIN_API; fi
# Variables
APS_CPPFLAGS=${ALL_APS_CPPFLAGS[$APS_INDEX]}
APS_LDFLAGS=${ALL_APS_LDFLAGS[$APS_INDEX]}
APS_ARCH=${ALL_APS_ARCH[$APS_INDEX]}
APS_CPU=${ALL_APS_CPU[$APS_INDEX]}
APS_HOST=${ALL_APS_HOST[$APS_INDEX]}
APS_SYSROOT=$APS_NDK/platforms/android-$APS_API/arch-${ALL_APS_TOOLCHAIN[$APS_INDEX]}
APS_PREFIX=$APS_PREFIX_BASE/$APS_ABI
APS_CROSS_BIN=$APS_NDK/toolchains/${ALL_APS_GCC[APS_INDEX]}/prebuilt/$APS_BUILD/bin
APS_CROSS=$APS_CROSS_BIN/$APS_HOST-
# Check if dirs exist
if [ ! -d "$APS_SYSROOT" ]; then
echo "APS_SYSROOT doesn't exist."
echo "$APS_SYSROOT"
exit -1
fi
if [ ! -d "$APS_CROSS_BIN" ]; then
echo "APS_CROSS_BIN doesn't exist."
echo "$APS_CROSS_BIN"
exit -1
fi
# Print variables
echo "APS_ABI = $APS_ABI"
echo "APS_API = $APS_API"
echo "APS_CPPFLAGS = $APS_CPPFLAGS"
echo "APS_LDFLAGS = $APS_LDFLAGS"
echo "APS_ARCH = $APS_ARCH"
echo "APS_CPU = $APS_CPU"
echo "APS_HOST = $APS_HOST"
echo "APS_SYSROOT = $APS_SYSROOT"
echo "APS_PREFIX = $APS_PREFIX"
echo "APS_CROSS = $APS_CROSS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment