-
-
Save z3ntu/57b95b02ebe8e153d5a8 to your computer and use it in GitHub Desktop.
Use this for cross-compiling native Applications for Android! Place this script preferably in ~/bin and add this folder to your path variable. Instead of using ./configure just call this script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# THIS SCRIPT IS FOR A STANDALONE TOOLCHAIN!! | |
# For more information please consult https://z3ntu.github.io/2015/12/12/Cross-compiling-native-linux-applications-for-android.html | |
# Don't forget to adjust this to your standalone toolchain path | |
export TOOLCHAIN_PATH=$HOME/Android/standalone-toolchain/ | |
# This is just an empty directory where I want the built objects to be installed | |
export PREFIX=$HOME/Android/out/prefix | |
# There should be no need to edit anything between this line and the next | |
# ----------------------------------------------------------------------- | |
export CROSS_COMPILE=arm-linux-androideabi | |
export SYSROOT=${TOOLCHAIN_PATH}/sysroot/ | |
export CROSS_PATH=${TOOLCHAIN_PATH}/bin | |
# Set the compiler and linker | |
export CPP=${CROSS_PATH}/${CROSS_COMPILE}-cpp | |
export AR=${CROSS_PATH}/${CROSS_COMPILE}-ar | |
export AS=${CROSS_PATH}/${CROSS_COMPILE}-as | |
export NM=${CROSS_PATH}/${CROSS_COMPILE}-nm | |
export CC=${CROSS_PATH}/${CROSS_COMPILE}-gcc | |
export CXX=${CROSS_PATH}/${CROSS_COMPILE}-g++ | |
export LD=${CROSS_PATH}/${CROSS_COMPILE}-ld | |
export RANLIB=${CROSS_PATH}/${CROSS_COMPILE}-ranlib | |
# Don't mix up .pc files from your host and build target | |
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig | |
# ----------------------------------------------------------------------- | |
# You can customize these flags if you have additional subdirectories that should be included/should be used by the linker. | |
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${TOOLCHAIN_PATH}/include -I${PREFIX}/include" | |
export CPPFLAGS="${CFLAGS}" | |
export CXXFLAGS="${CFLAGS}" | |
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${TOOLCHAIN_PATH}/lib -L${PREFIX}/lib -lgnustl_shared" | |
# Do now run ./configure when using the "source" command. | |
if [ $_ != $0 ]; then | |
echo "Set the environment variables!" | |
echo "Not executing ./configure because this was executed with 'source'" | |
else | |
./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment