# This script will install the madd program.
# An internet connection is required in order to download 
# the Triangle and Metis libraries.

echo
mkdir tmp

#create Triangle library
mkdir triangle
cd tmp
ftp http://cm.bell-labs.com/netlib/voronoi/triangle.zip
if [ ! -f triangle.zip ]; then
	echo
	echo ** Failed to download the Triangle library. Instalation aborted. **
	exit
fi

unzip triangle.zip
cp ../makefile.triangle makefile
make trilibrary showme
if [ ! -f triangle.o ]; then
	echo
	echo ** Failed to create the Triangle library. Instalation aborted. **
	exit
fi
cp triangle.o ../triangle
cp showme ../triangle
rm -r -f *

#create Metis library
cd ..
mkdir metis
cd tmp
ftp http://www-users.cs.umn.edu/~karypis/metis/metis/files/metis-4.0.tar.gz
if [ ! -f metis-4.0.tar.gz ]; then
	echo 
	echo ** Failed to download the Metis library. Instalation aborted. **
	exit
fi
gunzip metis-4.0.tar.gz
tar -xvf metis-4.0.tar
cd metis-4.0
cp ../../Makefile.in.metis Makefile.in
make
if [ ! -f libmetis.a ]; then
	echo 
	echo ** Failed to create the Metis library. Instalation aborted. *
	exit
fi
cp libmetis.a ../../metis
cd ..
rm -r -f -d *

cd ../madd
make
if [ ! -f maddi ]; then
	echo 
	echo ** Failed to create the madd library. Instalation aborted. *
	exit
fi

cd ../data
./runtests
./showresults
