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

#xz
gmp="$1"
shift

#xz
mpfr="$1"
shift

#gz
mpc="$1"
shift

# isl stands for Integer Set Library.  The version of fsf is older (0.16.1) than the one at inria (0.17.1), but we use the recommended fsf version.  There is no cryptographic signature.

#bz2
#isl=0.16.1

#lets try the inria version, dl bz2 version even though xz exists
isl="$1"
shift

#bz2
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++
cd /tmp
cat > a.c <<EOF
#include <stdio.h>
int main(void){
printf("straight c\n");
return 0;
}
EOF
gcc a.c
ldd ./a.out
./a.out
cat > a.cpp <<EOF
#include <iostream>
int main(){
std::cout << "cplusplus" << std::endl;
}
EOF
g++ a.cpp
ldd ./a.out
./a.out

install_location=/tmp/do72b
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  > configure.ken.log 2>&1

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

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

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 > configure.ken.log 2>&1

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


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

true $0 all done
