Skip to content

Instantly share code, notes, and snippets.

@PedroHLC
Created July 27, 2014 17:02
Show Gist options
  • Save PedroHLC/2192babf0f99fbf5cf6f to your computer and use it in GitHub Desktop.
Save PedroHLC/2192babf0f99fbf5cf6f to your computer and use it in GitHub Desktop.
Generate an Android standalone toolchain for use with Avalanche
#!/usr/bin/sh
# Created by: PedroHLC <[email protected]>
# Version: 1.0
# This:
# 1. Compiles SDL2*, Chipmunk, GLib and libgee for Android (Platform-9 ARM)
# 2. Creates a standalone toolchain
# 3. Move some dynamics libraries that you should never use for an Android project
# 4. Points libpthread to Androd's libc
# Compatible with ArchLinux only
# User Configuration
[ "$OUTPATH" == "" ] && export OUTPATH='/tmp/android-toolchain'
[ "$NDK" == "" ] && export NDK='/opt/android-ndk'
# Predefined Info
export ANDROID_PLAT='9'
export ANDROID_ARCH='arm'
export ANDROID_TC="arm-linux-androideabi-4.8"
export CONFLICTING_ITENS='libgthread-*.so* libSDL2.so* libgobject-*.so* libgmodule-*.so* libglib-*.so* libgio-*.so* libgee-*.so*'
export CONFLICTING_ITENSPATH="$OUTPATH/sysroot/usr/lib"
export CONFLICTING_OUTPATH="$CONFLICTING_ITENSPATH/confliting_dynamics"
export ANDROIDPKGS_DEPS='chipmunk ffi iconv gettextlib glib-2.0 gee-0.8 SDL2 SDL2_image SDL2_mixer SDL2_ttf SDL2_gfx'
export ANDROIDPKGS_REPO='https://github.com/PedroHLC/android9arm-archrepo.git'
export ANDROIDPKGS_WORKDIR='/tmp/androidpkgs'
export ANDROIDPKGS_MAKEANDISNTALL='makepkg -i'
export ANDORID_LIBPATH="$NDK/platforms/android-$ANDROID_PLAT/arch-$ANDROID_ARCH/usr/lib"
# Code
if [ ! -f "$NDK/ndk-build" ]; then
echo "### Please enter a valid NDK path!"
exit
fi
if [ -d "$ANDROIDPKGS_WORKDIR" ] || [ -d "$OUTPATH" ]; then
if [ "$FORCE" == "RM" ]; then
echo 'Removing old files'
rm -rf "$ANDROIDPKGS_WORKDIR/"
rm -rf "$OUTPATH/"
elif [ "$FORCE" != "USE" ]; then
echo '### You should clean ANDROIDPKGS_WORKDIR and OUTPATH or set FORCE=USE or set FORCE=RM'
exit
fi
fi
git clone "$ANDROIDPKGS_REPO" "$ANDROIDPKGS_WORKDIR"
cd "$ANDROIDPKGS_WORKDIR"
for _pkg in ${ANDROIDPKGS_DEPS}; do
cd "${_pkg}"
# No need to recompile the already installed ones (:D)
if [ ! -f "$ANDORID_LIBPATH/lib${_pkg}.so" ]; then
$ANDROIDPKGS_MAKEANDISNTALL || exit
fi
cd ".."
done
cd "$ANDROIDPKGS_WORKDIR"
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-$ANDROID_PLAT --toolchain=$ANDROID_TC --install-dir=$OUTPATH
mkdir -p $CONFLICTING_OUTPATH
cd "$CONFLICTING_ITENSPATH"
for _item in ${CONFLICTING_ITENS}; do
mv ${_item} "$CONFLICTING_OUTPATH/"
done
ln -sf ./libc.a ./libpthread.a
ln -sf ./libc.so ./libpthread.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment