Skip to content

Instantly share code, notes, and snippets.

@mssun
Last active Dec 10, 2016
Embed
What would you like to do?
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

heyligengregory commented Apr 21, 2016

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 ?

Loading

@mittorn
Copy link

mittorn commented Dec 10, 2016

@heyligengregory it exist only during binutils build

Loading

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