#!/bin/bash
set -x
set -e
set -o pipefail
set -u

gmp="$1"
shift

mpfr="$1"
shift

mpc="$1"
shift

isl="$1"
shift

gcc="$1"
shift

if [ -z "$gcc" ]
    then false "Failed to pass version numbers as arguments"
    exit 1
fi

echo user is $USER
echo home is $HOME

# argh, $HOME still retains its value from outside the container!
# e.g., /hdd-scratch/kenta2

udir=/home/$USER/i
onedir=$udir/1
twodir=$udir/2

. $udir/env.sh
which gcc
which g++

export CC=gnatgcc

install_location=/tmp/uball
mkdir -p $install_location

for target in $onedir $twodir
do pushd $target/gcc-$gcc
ln -s ../gmp-$gmp gmp
ln -s ../mpfr-$mpfr mpfr
ln -s ../mpc-$mpc mpc
ln -s ../isl-$isl isl
popd


mkdir $target/build
# making target needed for isl configure
#mkdir $target/install
done

####################################################

cd $onedir/build

# --enable-languages=jit
#--disable-multilib --enable-multilib-list=m64
../gcc-$gcc/configure --prefix=$install_location --enable-languages=jit --enable-host-shared --enable-threads=posix --with-tune=generic --with-system-zlib --with-multilib-list=m64,m32,x32 > configure.ken.log 2>&1

if false
    then :
bash $udir/make.sh -j9 > make01.log 2>&1
fi

########################################

cd $twodir/build

# --enable-languages=all,ada,go,jit,obj-c++
# --enable-languages=all,ada,go,obj-c++
../gcc-$gcc/configure --prefix=$install_location --enable-languages=all,ada,go,obj-c++ --disable-host-shared --enable-threads=posix --with-tune=generic --with-system-zlib --with-multilib-list=m64,m32,x32 > configure.ken.log 2>&1

bash $udir/make.sh -j9 > make01.log 2>&1


########################################

true $0 all done
