# This script is to install atlas-optimised lapack, blas and also atlas itself. 
# It is meant to be installed in a Rocks Linux cluster. Must run as su. 
# lapack version: 3-1-1, to be installed in /share/apps/lapack-3-1-1
# atlas version: 3-8-1, to be installed in /share/apps/atlas-3-8-1

#Reference http://forum.webfaction.com/viewtopic.php?id=1633 to 

########################################################################
#Installation of lapack-3-1-1

cd /share/apps
wget -c http://www.netlib.org/lapack/lapack-3.1.1.tgz

tar zxf lapack-3.1.1.tgz
cd lapack-3.1.1/

cp INSTALL/make.inc.LINUX make.inc  ||  cp make.inc.example 

which g77 || sed -i -e 's/g77/gfortran/' make.inc 

make blaslib #to generate blas_LINUX.a in /share/apps/lapack-3.1.1

make lapacklib #to generate lapack_LINUX.a in /share/apps/lapack-3.1.1

########################################################################
#Installation of atlas 3.8.1, to be done after installation of lapack-3-1-1

cd ~/share/apps
wget -c 'http://voxel.dl.sourceforge.net/sourceforge/math-atlas/atlas3.8.1.tar.bz2'
tar jxf atlas3.8.1.tar.bz2
cd ATLAS/
mkdir build
cd build
../configure -b 64 --prefix=/share/apps/atlas-3-8-1
make #takes about a few hours

make install 
# Note that /share/apps/ATLAS now contain the installation files of atlas-3-8-1
# Note /share/apps/atlas-3-8-1 now contain a liblapack.a, not fully optimised.

########################################################################
# Integrate lapack with atlas:

cd /share/apps/ATLAS/build/lib
mkdir tmp
cd tmp/

ar x ../liblapack.a
cp /share/apps/lapack-3.1.1/lapack_LINUX.a ../liblapack.a

ar r ../liblapack.a *.o

cd ../..
make check
make ptcheck
make time
make install 


# I suppose that now /share/apps/ATLAS/lib/liblapack.a is the optimised lapack library.  

#cp include/* ~/include/
#cp lib/*.a ~/lib/




