Skip to content

Instantly share code, notes, and snippets.

@mssun
Last active December 10, 2016 14:31
Show Gist options
  • Save mssun/19070cc35d7a38c9ea21 to your computer and use it in GitHub Desktop.
Save mssun/19070cc35d7a38c9ea21 to your computer and use it in GitHub Desktop.
Script for Building Android Toolchain (both host and target arm-linux-androideabi)
#!/bin/bash
# You need to fix several header error before compiling.
# For more information, please read: http://blog.mssun.me/technology/android/build-android-toolchain/
export PWD=`pwd`
export PREFIX=${PWD}/system
export NDK_HOME=/xxx/aosp/android-ndk-r10e
export CROSS_COMPILE=${NDK_HOME}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
export PATH=${NDK_HOME}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
export SYSROOT=${NDK_HOME}/platforms/android-21/arch-arm
make distclean
rm */config.cache
sed -i 's/^#include <stdio_ext.h>/\/* #include <stdio_ext.h> *\//' libiberty/fopen_unlocked.c
sed -i 's/^# include <sys\/sysctl.h>/\/* # include <sys\/sysctl.h> *\//' libiberty/physmem.c
ln -s ${NDK_HOME}/platforms/android-21/arch-arm/usr/lib/crtbegin_so.o ld/
ln -s ${NDK_HOME}/platforms/android-21/arch-arm/usr/lib/crtend_so.o ld/
./configure \
--prefix=$PREFIX \
--host=arm-linux-androideabi \
--target=arm-linux-androideabi \
--disable-option-checking \
CC=${CROSS_COMPILE}gcc \
CXX=${CROSS_COMPILE}g++ \
CFLAGS="-g -I -O2 -mandroid -mbionic -I${NDK_HOME}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9/include -I${SYSROOT}/usr/include/ --sysroot=${SYSROOT} -Wno-error -fPIE" \
LDFLAGS="-L${NDK_HOME}/platforms/android-21/arch-arm/usr/lib -pie" \
CPP=${CROSS_COMPILE}cpp \
CPPFLAGS="-I${NDK_HOME}/platforms/android-21/arch-arm/usr/include/" \
AR=${CROSS_COMPILE}ar
make -j4
mkdir -p $PREFIX
make install
@heyligengregory
Copy link

This script is helpful but it seems that there is still a problem with "crtbegin_so.o" --> ld/ doesn't exist or am I blind ?

@mittorn
Copy link

mittorn commented Dec 10, 2016

@heyligengregory it exist only during binutils build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment