Last active
December 3, 2020 17:53
-
-
Save derselbst/885641b86b8bd0e5fd1b1d846d4b286b to your computer and use it in GitHub Desktop.
Shell file to set up various environment variables to allow cross compilation for Android
This file contains 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/bash | |
# Android cross-compile environment setup script for Glib | |
# Author : Zengwen Yuan | |
# Date : 2016-07-16 | |
# License : Creative Commons Attribution-ShareAlike 4.0 | |
# http://zwyuan.github.io/2016/07/17/cross-compile-glib-for-android/ | |
# | |
# Modified by Tom Moebert to provide an Android cross compilation toolchain for fluidsynth 2.0 | |
# Date: 2018-09-06 | |
# Android NDK sources and standalone toolchain is put here | |
export DEV=${HOME}/ANDROID | |
# This is a symlink pointing to the real Android NDK r10e | |
export NDK=${DEV}/android-ndk-r17c | |
# All the built binaries, libs and their headers will be installed here | |
export PREFIX=${DEV}/opt/android | |
# The path of standalone NDK toolchain | |
# Refer to https://developer.android.com/ndk/guides/standalone_toolchain.html | |
export NDK_TOOLCHAIN=${DEV}/android-ndk-toolchain | |
# Don't mix up .pc files from your host and build target | |
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig | |
# setting PKG_CONFIG_PATH alone does not seem to be enough to avoid mixing up with the host, also set PKG_CONFIG_LIBDIR | |
export PKG_CONFIG_LIBDIR=${PKG_CONFIG_PATH} | |
# Set Android target API level | |
# when compiling with clang use at least 28 as this makes sure that android provides the posix_spawn functions, so the compilation of gettext will (should) work out of the box | |
# it's probably a bug of gettext, if posix_spawn is not available it replaces it with its own implementation. Autotools of gettext set HAVE_POSIX_SPAWN==0 (which is correct) but for some reason REPLACE_POSIX_SPAWN==0 (which is wrong, as it should be 1). | |
export ANDROID_API=28 | |
# Set Android target arch | |
export ANDROID_ARCH=arm | |
# The cross-compile toolchain we use | |
export ANDROID_TARGET=${ANDROID_ARCH}-linux-androideabi | |
# the --target to be used by autotools | |
export TARGET=${ANDROID_ARCH}-eabi | |
# the target to be used by cmake, keep both in sync! | |
# https://developer.android.com/ndk/guides/cmake | |
export ANDROID_ABI_CMAKE=armeabi-v7a | |
# Add the standalone toolchain to the search path. | |
export PATH=$PATH:${PREFIX}/bin:${PREFIX}/lib:${PREFIX}/include:${NDK_TOOLCHAIN}/bin | |
# Tell configure what tools to use. | |
export AR=${ANDROID_TARGET}-ar | |
export AS=${ANDROID_TARGET}-clang | |
export CC=${ANDROID_TARGET}-clang | |
export CXX=${ANDROID_TARGET}-clang++ | |
export LD=${ANDROID_TARGET}-ld | |
export STRIP=${ANDROID_TARGET}-strip | |
# Tell configure what flags Android requires. | |
# Using C99 for all compilations by default. Turn Wimplicit-function-declaration into errors. Else autotools will be fooled when checking for available functions (that in fact are NOT available) and compilation will fail later on. | |
# Also disable clangs integrated assembler, as the hand written assembly of libffi is not recognized by it, cf. https://crbug.com/801303 | |
export CFLAGS="-fPIE -fPIC -I${PREFIX}/include --sysroot=${NDK_TOOLCHAIN}/sysroot -I${NDK_TOOLCHAIN}/sysroot/include -Werror=implicit-function-declaration -fno-integrated-as" | |
export CXXFLAGS=${CFLAGS} | |
export CPPFLAGS=${CFLAGS} | |
export LDFLAGS="-pie -Wl,-rpath-link=-I${NDK_TOOLCHAIN}/sysroot/usr/lib -L${NDK_TOOLCHAIN}/sysroot/usr/lib -L${PREFIX}/lib -L${NDK_TOOLCHAIN}/lib" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, here you can find my updated scripts
https://gist.github.com/santoxyz