Skip to content

Instantly share code, notes, and snippets.

@shawnanastasio
Last active January 25, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnanastasio/146882a73ee66ab30d9fce96dc86ddb4 to your computer and use it in GitHub Desktop.
Save shawnanastasio/146882a73ee66ab30d9fce96dc86ddb4 to your computer and use it in GitHub Desktop.
Automatic GCC/Binutils Cross Toolchain script
#!/bin/bash
set -e
# Number of threads to compile with
THREADS=15
# GCC/Binutils download URL
GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.xz"
BINUTILS_URL="ftp://ftp.gnu.org/gnu/binutils/binutils-2.30.tar.xz"
# GCC/Binutils installation path
PREFIX="$HOME/opt/cross"
# GCC/Binutils target
TARGET=i686-elf
# GCC/Binutils src directory
SRCDIR="$HOME/opt/cross-src"
# wget path
WGET=$(which wget)
# Install prereqs (distro specific)
echo "Installing prerequisites"
if [ -f /etc/fedora-release ]; then
sudo dnf install gmp-devel mpfr-devel isl-devel cloog-devel mpc texinfo libmpc-devel
elif [ -f /etc/gentoo-release ]; then
sudo emerge -av gmp mpfr isl cloog mpc texinfo
elif [ -f /etc/debian_version ]; then
sudo apt-get install build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libcloog-isl-dev
else
echo "Unsupported distribution!"
exit 1
fi
# Download GCC/Binutils
mkdir $SRCDIR
cd $SRCDIR
if [ ! -x $WGET ]; then
echo "Please make sure wget is installed an in your path!"
exit 1
fi
$WGET $GCC_URL
$WGET $BINUTILS_URL
# Extract and build binutils
tar -xvf binutils*.tar*
mkdir build-binutils
cd build-binutils
../binutils*/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make -j$THREADS
make install
cd ..
# Extract and build GCC
tar -xvf gcc*.tar*
mkdir build-gcc
cd build-gcc
../gcc*/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc -j$THREADS
make all-target-libgcc -j$THREADS
make install-gcc
make install-target-libgcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment