#!/bin/bash
mkdir -p psx-gcc
cd psx-gcc

echo "clone binutils"
git clone git://sourceware.org/git/binutils-gdb.git
cd binutils-gdb

mkdir -p build
cd build

echo "Configure binutils"
../configure --target=mipsel-linux-gnu --with-sysroot --disable-nls --disable-werror
if [ $? -ne 0 ]; then
  exit 1
fi
echo "Make binutils"
make
if [ $? -ne 0 ]; then
  exit 1
fi
echo "Install binutils"
sudo make install
if [ $? -ne 0 ]; then
  exit 1
fi

cd ../..

echo "clone gcc"
git clone --recurse-submodules git://gcc.gnu.org/git/gcc.git
cd gcc

echo "checkout gcc 13.1.0"
git checkout releases/gcc-13.1.0

mkdir -p build
cd build
echo "configure gcc"
../configure --target=mipsel-linux-gnu --disable-nls --enable-languages=c,c++ --without-headers
if [ $? -ne 0 ]; then
  exit 1
fi

echo "Make gcc"
make all-gcc
if [ $? -ne 0 ]; then
  exit 1
fi

echo "Install gcc"
sudo make install-gcc
if [ $? -ne 0 ]; then
  exit 1
fi
