#!/bin/bash
set -x
set -e

datestring=build-2016120723-1418-0500
target=/afs/sipb.mit.edu/project/gcc-6plus/.install/$datestring
pushd $target
mkdir selflaunch
cat > selflaunch/selflaunch.sh <<EOF
#!/bin/bash

# we need to set LD_LIBRARY_PATH because otherwise gcc only looks in
# system locations for the shared libraries it needs to function, most
# notably isl, which is a new requirement not present in gcc included
# with ubuntu 14.04.

#set -x
set -e

# skip gcc libraries because we assume gcc knows where to find them if
# it needs them.  this assumption has yet to be tested.

for i in gmp isl mpc mpfr
do export LD_LIBRARY_PATH=$target/\$i/lib:"\$LD_LIBRARY_PATH"
done

$target/gcc/bin/"\$(basename "\$0")" "\$@"
EOF
chmod a+x selflaunch/selflaunch.sh

mkdir bin
pushd bin
for file in ../gcc/bin/*
do ln -s ../selflaunch/selflaunch.sh "$(basename "$file")"
done
popd
popd
