#!/bin/sh
set -eu

# ensure that we're in the repo root
if [ ! -d .git ]; then
	echo please cd to the repo\'s main directory
	exit
fi

export PREFIX="$(pwd)/toolchain/prefix/"
export PATH="$(pwd)/toolchain/prefix/bin/:$PATH"
BUILDDIR="$(pwd)/toolchain/binutils-build/"
SYSROOT="$(pwd)/out/sysrootu/"
mkdir -p $PREFIX
mkdir -p $BUILDDIR
make out/sysrootu/usr/include/

cd $BUILDDIR

../binutils/configure \
	--target=x86_64-camellia \
	--prefix="$PREFIX" \
	--with-sysroot="$SYSROOT" \
	--disable-nls \
	--disable-werror
mkdir -p gas/doc/ # stupid workaround for the broken build
make
make install