#!/bin/bash

GCC_VERSION=$1

export PREFIX=$2
#export TARGET=x86_64-elf
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"

cd $PREFIX/src/gcc-${GCC_VERSION}/gcc
patch < config.gcc.patch

cd $PREFIX/src
mkdir build-gcc
cd build-gcc
../gcc-${GCC_VERSION}/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make -j `nproc` all-gcc
make -j `nproc` all-target-libgcc
make install-gcc
make install-target-libgcc

cd $PREFIX/src
#rm -rf build-gcc.sh gcc-${GCC_VERSION}
# rm -rf build-gcc