#!/bin/sh

#FEEL FREE TO MODIFY THIS SHELL AT YOUR CONVENIENCE !!
# (FOR ROOT INSTALLATION, PARTIAL INSTALLATION, ETC... )


# (0) Creating local directories

ROOTDIR=$PWD
mkdir VirtualRetina/local
mkdir VirtualRetina/local/bin
mkdir VirtualRetina/local/lib
mkdir VirtualRetina/local/include



# (1) CMake (to compile / install xmlParameters++ and VirtualRetina)
echo ----------------------------------------
echo
echo
echo Downloading CMAKE
echo
echo
echo ----------------------------------------

cd $ROOTDIR
wget http://www.cmake.org/files/v2.4/cmake-2.4.7-Linux-i386.tar.gz .
tar -zxf cmake-2.4.7-Linux-i386.tar.gz
rm cmake-2.4.7-Linux-i386.tar.gz*
mv cmake-2.4.7-Linux-i386 External_Libraries/CMake



# (2) CImg

echo ----------------------------------------
echo
echo
echo Downloading CIMG #and installing inrcast.cpp
echo
echo
echo ----------------------------------------

cd $ROOTDIR
wget http://downloads.sourceforge.net/cimg/CImg-1.2.9.zip .
unzip CImg-1.2.9.zip
rm CImg-1.2.9.zip
mv CImg-1.2.9 External_Libraries/CImg
cp External_Libraries/CImg/CImg.h $ROOTDIR/VirtualRetina/local/include

#DOES NOT COMPILE FOR THE MOMENT !!??
#cd External_Libraries/CImg/examples
#make inrcast
#mv inrcast $ROOTDIR/VirtualRetina/local/bin



# (3) MvaSpike
echo ----------------------------------------
echo
echo
echo Downloading MVASPIKE and installing it locally
echo
echo
echo ----------------------------------------

cd $ROOTDIR
wget http://gforge.inria.fr/frs/download.php/2517/mvaspike-1.0.16.tar.gz .
tar -zxf mvaspike-1.0.16.tar.gz
rm mvaspike-1.0.16.tar.gz
mv mvaspike-1.0.16 External_Libraries/MvaSpike

cd External_Libraries/MvaSpike
./configure --prefix=$ROOTDIR/VirtualRetina/local
make
make install
make clean




#(4) libxml++
echo ----------------------------------------
echo
echo
echo Downloading LIBXML++ wrapper, and installing it locally
echo
echo
echo ----------------------------------------

cd $ROOTDIR
wget http://ftp.gnome.org/pub/GNOME/sources/libxml++/1.0/libxml++-1.0.5.tar.gz .
tar -zxf libxml++-1.0.5.tar.gz
rm libxml++-1.0.5.tar.gz
mv libxml++-1.0.5 External_Libraries/

cd External_Libraries/libxml++-1.0.5
./configure --prefix=$ROOTDIR/VirtualRetina/local
make
make install
make clean


# (5) xmlParameters
echo ----------------------------------------
echo
echo
echo Compiling and installing xmlParameters++ with CMake
echo
echo
echo ----------------------------------------


cd $ROOTDIR/External_Libraries/xmlParameters++
$ROOTDIR/External_Libraries/CMake/bin/cmake CMakeLists.txt -DLIBRARY_OUTPUT_PATH:PATH=$ROOTDIR/VirtualRetina/local/lib
make
#Not really necessary, but cleaner ??
mkdir $ROOTDIR/VirtualRetina/local/include/xml_parameters++
cp *.h $ROOTDIR/VirtualRetina/local/include/xml_parameters++


# (6) VirtualRetina
echo ----------------------------------------
echo
echo
echo Compiling and installing VirtualRetina with CMake
echo
echo
echo ----------------------------------------

cd  $ROOTDIR/VirtualRetina
$ROOTDIR/External_Libraries/CMake/bin/cmake CMakeLists.txt
make
#Not really necessary, but cleaner ??
mkdir $ROOTDIR/VirtualRetina/local/include/virtual_retina
cp src/*.h $ROOTDIR/VirtualRetina/local/include/virtual_retina
mkdir $ROOTDIR/VirtualRetina/local/include/retina_tools
cp src/tools/*.h $ROOTDIR/VirtualRetina/local/include/retina_tools


cd $ROOTDIR
echo "DONE !"
echo
