#!/bin/sh

build()
{
#sudo apt update -qq
#sudo apt install -qq -y git-core gnupg flex bison lftp gperf m4 build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev libx11-dev lib32z-dev libxml2-utils xsltproc schedtool gettext texinfo nodejs npm
#sudo npm config set strict-ssl false
#sudo npm install -g surge
#sudo apt-get clean
export TUPLE="danio"
for i in aarch64-${TUPLE}-linux-gnu alpha-${TUPLE}-linux-gnu arm-${TUPLE}-eabi arc-${TUPLE}-linux-gnu c6x-${TUPLE}-linux-gnu h8300-${TUPLE}-elf parisc64-${TUPLE}-linux-gnu parisc-${TUPLE}-linux-gnu i386-${TUPLE}-linux-gnu i686-${TUPLE}-gnu -${TUPLE}-linux-gnu ia64-${TUPLE}-linux-gnu m68k-${TUPLE}-linux-gnu microblaze-${TUPLE}-linux-gnu mips64-${TUPLE}-linux-gnu mips-${TUPLE}-linux-gnu nios2-${TUPLE}-elf powerpc64-${TUPLE}-linux-gnu powerpc64-${TUPLE}-linux-gnu s390-${TUPLE}-linux-gnu sh2-${TUPLE}-linux-gnu sh4-${TUPLE}-linux-gnu riscv32-${TUPLE}-linux-gnu riscv64-${TUPLE}-linux-gnu sparc-${TUPLE}-linux-gnu sparc64-${TUPLE}-linux-gnu x86_64-${TUPLE}-linux-gnu xtensa-${TUPLE}-linux-gnu nds32le-${TUPLE}-linux-gnu or1k-${TUPLE}-linux-gnu hexagon-${TUPLE}-linux-gnu am33_2.0-${TUPLE}-linux-gnu bfin-${TUPLE}-uclinux crisv32-${TUPLE}-linux-gnu frv-${TUPLE}-linux-gnu m32r-${TUPLE}-linux-gnu tilepro-${TUPLE}-linux-gnu tilegx-${TUPLE}-linux-gnu; do
	if [ -e .error ]; then
		. ./.error
		break
	else

		rm -rf build-* #LATEST-* gcc-* newlib-* binutils-*
		./danio_gcc.sh ${i} ${1} | tee out/${i}.log
	fi
done
if [ -e .error ]; then
	echo "error detected @ ${STAGE} !"
	exit 1
fi
}

mkdir -p out

case ${1} in
64) build 64;;
32) build 32;;
--build-upload) ${0} 64 && ${0} 32 && surge ./out gcc.danio.ga ;;
--build) ${0} 64 && ${0} 32 ;;
esac

exit ${?}
