#!/bin/bash -e

VERSION=3.0.1

part1a ()
{
cd /opt/src/R-$VERSION
echo "**********************"
echo "*** configure (32bit) "
echo "**********************"
cp ../R-config.site-32 config.site
./configure --prefix=/opt/R/R-$VERSION --with-blas --with-lapack --enable-R-shlib r_arch=32 | tee CONFIGURE_32
echo "*********************"
echo "*** make (32 bit)    "
echo "*********************"
make -j6
}

part2()
{
echo "*********************"
echo "*** make check       "
echo "*********************"
make check
make install    
}

part1b ()
{
echo "**********************"
echo "*** configure (64bit) "
echo "**********************"
make distclean
cp ../R-config.site-64 config.site
./configure --prefix=/opt/R/R-$VERSION --with-blas --with-lapack  --enable-R-shlib | tee CONFIGURE_64
echo "*********************"
echo "*** make (64 bit)    "
echo "*********************"
make -j6
}

part3 ()
{
echo "**********************"
echo "*** make documentation"
echo "**********************"
make pdf info
make install-pdf install-info
}

export http_proxy=http://proxy.uwa.edu.au:8888
export LANG=en_AU.UTF-8
echo "Installing R-$VERSION"
part1a  > /opt/src/R-$VERSION-LOG 2>&1
part2   > /opt/src/R-$VERSION-CheckLOG 2>&1
part1b >> /opt/src/R-$VERSION-LOG 2>&1
part2  >> /opt/src/R-$VERSION-CheckLOG 2>&1
part3  >> /opt/src/R-$VERSION-LOG 2>&1
echo "Done"
