Skip to content

Commit

Permalink
Install binutils as well
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 committed Sep 20, 2022
1 parent 8cbb560 commit a42a757
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ source $_SCRIPTDIR/common-files/termux_download.sh
: ${_MAKE_PROCESSES:=$(nproc)}
: ${GCC_VERSION:=9.5.0}
: ${GCC_SHA256:=15b34072105272a3eb37f6927409f7ce9aa0dd1498efebc35f851d6e6f029a4d}
: ${BINUTILS_VERSION:=2.39}
: ${BINUTILS_SHA256:=d12ea6f239f1ffe3533ea11ad6e224ffcb89eb5d01bbea589e9158780fa11f10}

export TOOLCHAIN_ARCH

Expand All @@ -39,16 +41,18 @@ mkdir -p $_TMP_DIR

_HOST_PLATFORM="${TOOLCHAIN_ARCH}-linux-android"

_EXTRA_HOST_BUILD=""
_GCC_EXTRA_HOST_BUILD=""
_BINUTILS_EXTRA_HOST_BUILD="--enable-gold=default"
if [ "$TOOLCHAIN_ARCH" = "arm" ]; then
_HOST_PLATFORM="${_HOST_PLATFORM}eabi"
_EXTRA_HOST_BUILD="--with-arch=armv7-a --with-float=soft --with-fpu=vfp"
_GCC_EXTRA_HOST_BUILD="--with-arch=armv7-a --with-float=soft --with-fpu=vfp"
elif [ "$TOOLCHAIN_ARCH" = "aarch64" ]; then
_EXTRA_HOST_BUILD="--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419"
_GCC_EXTRA_HOST_BUILD="--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419"
_BINUTILS_EXTRA_HOST_BUILD="--enable-gold $_GCC_EXTRA_HOST_BUILD"
elif [ "$TOOLCHAIN_ARCH" = "i686" ]; then
_EXTRA_HOST_BUILD="--with-arch=i686 --with-fpmath=sse "
_GCC_EXTRA_HOST_BUILD="--with-arch=i686 --with-fpmath=sse "
elif [ "$TOOLCHAIN_ARCH" = "x86_64" ]; then
_EXTRA_HOST_BUILD="--with-arch=x86-64 --with-fpmath=sse"
_GCC_EXTRA_HOST_BUILD="--with-arch=x86-64 --with-fpmath=sse"
fi

# Install dependencies
Expand All @@ -59,39 +63,57 @@ sudo apt install -y libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev libisl-dev libt
pushd $_TMP_DIR

# Download source
SRC_URL=https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
SRC_FILE=$_CACHE_DIR/gcc-${GCC_VERSION}.tar.gz
SRC_DIR=$_TMP_DIR/gcc-${GCC_VERSION}
termux_download $SRC_URL $SRC_FILE $GCC_SHA256
GCC_SRC_URL=https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
GCC_SRC_FILE=$_CACHE_DIR/gcc-${GCC_VERSION}.tar.gz
GCC_SRC_DIR=$_TMP_DIR/gcc-${GCC_VERSION}
termux_download $GCC_SRC_URL $GCC_SRC_FILE $GCC_SHA256
BINUTILS_SRC_URL=https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz
BINUTILS_SRC_FILE=$_CACHE_DIR/binutils-${BINUTILS_VERSION}.tar.gz
BINUTILS_SRC_DIR=$_TMP_DIR/binutils-${BINUTILS_VERSION}
termux_download $BINUTILS_SRC_URL $BINUTILS_SRC_FILE $BINUTILS_SHA256

# Setup a standalone toolchain
_setup_standalone_toolchain_ndk_r17c $_TMP_DIR/standalone-toolchain
cp -R $_TMP_DIR/standalone-toolchain/sysroot/usr/include/$_HOST_PLATFORM/* $_TMP_DIR/standalone-toolchain/sysroot/usr/include/

PATH="$_TMP_DIR/standalone-toolchain/bin:$PATH"

# Extract source
tar -xf $SRC_FILE -C $_TMP_DIR/
tar -xf $GCC_SRC_FILE -C $_TMP_DIR/
pushd $_TMP_DIR
PATCHES="$(find "$_SCRIPTDIR/patches/" -maxdepth 1 -type f -name *.patch | sort)"
for f in $PATCHES; do
echo "Applying patch: $(basename $f)"
patch -d "$SRC_DIR/" -p1 < "$f";
patch -d "$GCC_SRC_DIR/" -p1 < "$f";
done
tar -xf $BINUTILS_SRC_FILE -C $_TMP_DIR/
popd

# Build a custom toolchain
# Copy sysroot
mkdir -p $_TMP_DIR/newer-toolchain
cp -R $_TMP_DIR/standalone-toolchain/sysroot $_TMP_DIR/newer-toolchain/

# Build binutils
mkdir -p binutils-build
pushd binutils-build
$BINUTILS_SRC_DIR/configure \
--target=$_HOST_PLATFORM \
--prefix=$_TMP_DIR/newer-toolchain \
--with-sysroot=$_TMP_DIR/newer-toolchain/sysroot \
$_BINUTILS_EXTRA_HOST_BUILD
make -j $_MAKE_PROCESSES
make -j $_MAKE_PROCESSES install-strip
popd # binutils-build

export PATH="$_TMP_DIR/newer-toolchain/bin:$PATH"

# Build GCC toolchain
mkdir -p newer-toolchain-build
pushd newer-toolchain-build

export CFLAGS="-D__ANDROID_API__=$_API_LEVEL"
export CPPFLAGS="-D__ANDROID_API__=$_API_LEVEL"
export CXXFLAGS="-D__ANDROID_API__=$_API_LEVEL"

$SRC_DIR/configure \
$GCC_SRC_DIR/configure \
--host=x86_64-linux-gnu \
--build=x86_64-linux-gnu \
--target=$_HOST_PLATFORM \
Expand All @@ -102,6 +124,7 @@ $SRC_DIR/configure \
--with-gnu-as --with-gnu-ld \
--disable-libstdc__-v3 \
--disable-tls \
--disable-ssp \
--disable-bootstrap \
--enable-initfini-array \
--enable-libatomic-ifuncs=no \
Expand All @@ -115,12 +138,12 @@ $SRC_DIR/configure \
--enable-eh-frame-hdr-for-static \
--enable-graphite=yes --with-isl \
--disable-multilib \
$_EXTRA_HOST_BUILD \
$_GCC_EXTRA_HOST_BUILD \
--with-sysroot=$_TMP_DIR/newer-toolchain/sysroot \
--with-gxx-include-dir=$_TMP_DIR/newer-toolchain/include/c++/$GCC_VERSION

make -j $_MAKE_PROCESSES
make -j $_MAKE_PROCESSES install
make -j $_MAKE_PROCESSES install-strip

popd # newer-toolchain-build

Expand Down

0 comments on commit a42a757

Please sign in to comment.