Skip to content

Instantly share code, notes, and snippets.

@alekfrohlich
Last active December 2, 2019 17:23
Show Gist options
  • Save alekfrohlich/799009824b91d56b53a8ad0e940ff376 to your computer and use it in GitHub Desktop.
Save alekfrohlich/799009824b91d56b53a8ad0e940ff376 to your computer and use it in GitHub Desktop.
#!/bin/bash
GCC=gcc-7.3.0
BINUTILS=binutils-2.30
echo installing gcc dependencies
sudo apt install -y bison
sudo apt install -y flex
sudo apt install -y libgmp3-dev
sudo apt install -y libmpc-dev
sudo apt install -y libmpfr-dev
sudo apt install -y texinfo
TMP=`mktemp -d`
cd $TMP
echo building toolchain inside `pwd` ...
echo downloading gcc and binutils src ...
wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/$GCC.tar.gz
wget https://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.gz
echo extracting gcc and binutils ...
tar xvzf $GCC.tar.gz
tar xvzf $BINUTILS.tar.gz
echo exporting environment variables ...
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
echo adding binary to /usr/bin ...
#TODO add tools to path
echo building binutils ...
cd $TMP
mkdir build-binutils
cd build-binutils
../$BINUTILS/configure --target=$TARGET --prefix="$PREFIX" --disable-nls
make -j4
make install -j4
echo building gcc ...
cd $TMP
mkdir build-gcc
cd build-gcc
../$GCC/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers -disable-shared --with-gnu-as --with-gnu-ld --disable-threads --disable-libssp
make all-gcc -j4
make all-target-libgcc -j4
make install-gcc -j4
make install-target-libgcc -j4
rm -rf $TMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment