#! /bin/bash
# Author: Bradley M. Bell
# version="ADOL-C-2.0.0"
# version="ADOL-C-2.1.0"
# version="ADOL-C-2.1.1"
version="ADOL-C-2.1.2"
web_page="http://www.coin-or.org/download/source/ADOL-C"
# This case does not work.
# version="adolc-1.10.2"
# --------------------------------------------------------------------------
#
# exit immediately if a simple command exits with a non-zero status
set -e
#
echo "configure and install adolc"
if ! cd $HOME/install
then
	echo "install_adolc.sh: cannot change into $HOME/install directory"
	exit 1
fi
#
if [ ! -e $version.tgz ]
then
	echo "wget $web_page/$version.tgz"
	wget "$web_page/$version.tgz"
fi
if [ -e $version ]
then
	echo "rm -rf $version"
	rm -rf $version
fi
if [ -e $HOME/prefix/adolc ]
then
	echo "rm -r $HOME/prefix/adolc"
	rm -r $HOME/prefix/adolc
fi
echo "tar -xvzf $version.tgz"
tar -xvzf $version.tgz
#
echo "cd $version"
cd $version
# ----------------------------------------------------------------------------
echo "Changing some includes to use local instead of system addressing"
if [ -d "ADOL-C/src" ]
then
	dir="ADOL-C/src"
else
	dir="adolc"
fi
#
list="
	adouble.h
	taping.h
	interfaces.h
"
for file in $list
do
	if [ -e "$dir/$file" ]
	then
		echo "$dir/$file"
		sed -i $dir/$file \
			-e 's/#include <common.h>/#include "common.h"/'
	fi
done
echo "$dir/drivers/drivers.h"
sed -i $dir/drivers/drivers.h \
	-e 's|#include <common.h>|#include "../common.h"|'
#
echo "$dir/common.h"
sed -i $dir/common.h \
	-e 's/#include <dvlparms.h>/#include "dvlparms.h"/' \
	-e 's/#include <usrparms.h>/#include "usrparms.h"/'
#
echo "$dir/usrparms.h"
sed -i $dir/usrparms.h \
	-e 's/BUFSIZE  65536/BUFSIZE  524288/'
# -----------------------------------------------------------------------
#
echo "./configure --prefix=$HOME/prefix/adolc"
./configure --prefix=$HOME/prefix/adolc 
#
echo "make install"
make install