#!/bin/sh

# SS12 et HPC6
#SUNC=/opt/studio12/SUNWspro
#HPC=/opt/SUNWhpc/HPC6.0
#DEST=$HOME/hypre/2.0.0/hpc6/lib/amd64

# SS12u1 et HPC8.2
SUNC=/opt/sunstudio12.1
HPC=/opt/SUNWhpc/HPC8.2/sun
DEST=$HOME/lib/hypre/2.0.0/openmpi/sun/1.3.3/amd64

PATH=$SUNC/bin:$HPC/bin:$PATH:/usr/ccs/bin
export PATH

MESFLAGS="-fast -I$HPC/include -xmodel=medium"
export MESFLAGS

#set -x

./configure \
--prefix=$DEST \
--with-LD=/usr/ccs/bin/ld \
--with-MPI-include="$HPC/include" \
--with-MPI-libs="pthread nsl socket mpi" \
--with-MPI-lib-dirs="$HPC/lib/amd64" \
--with-blas  \
--with-lapack \
--with-babel \
CC=mpicc \
CFLAGS="$MESFLAGS -KPIC -m64" \
F77=mpif90 \
FFLAGS="$MESFLAGS -ext_names=plain -KPIC -dalign -m64" \
CXX=mpiCC \
CXXFLAGS="$MESFLAGS -KPIC -m64" \
LDFLAGS="-z textoff -L$HPC/lib/amd64 -R$HPC/lib/amd64 -xlic_lib=sunperf -m64"

sed 's/^HYPRE_LAPACK_SRC_DIR.*/HYPRE_LAPACK_SRC_DIR =/; s/^LAPACKLIBS.*/LAPACKLIBS = -xlic_lib=sunperf/; s/^LAPACKLIBDIRS.*/LAPACKLIBDIRS =/; s/^HYPRE_BLAS_SRC_DIR.*/HYPRE_BLAS_SRC_DIR =/; s/^BLASLIBS.*/BLASLIBS = -xlic_lib=sunperf/; s/^BLASLIBDIRS.*/BLASLIBDIRS =/' config/Makefile.config > /tmp/Makefile.config
sed 's/-L\/usr\/lib\/gcc-lib\/i386-redhat-linux\/3.2.3 //' /tmp/Makefile.config > config/Makefile.config

#sed 's/-z text//' babel-runtime/libtool > /tmp/libtool
#mv /tmp/libtool babel-runtime/libtool

#ans=`ckyorn -d y \
#-p "Avez vous modifie les fichiers comme indique ici: http://www.latp.univ-mrs.fr/informatique/doku.php?id=hypre_patches" ` || exit $?
#if [ "$ans" = n ]
#then
#exit
#fi


echo "make clean"
make clean

echo "make"
make
if [ $? -ne 0 ];then echo "make a echoue"; exit; fi


echo "make test"
make test
if [ $? -ne 0 ];then echo "make test a echoue"; exit; fi


echo "make install"
make install
if [ $? -ne 0 ];then echo "make install a echoue"; exit; fi

echo "on garde une copie de config.log et config.status"
cp -rp config.log config.log_`date '+%d%m%y_%H%M%S'`
cp -rp config.status config.status_`date '+%d%m%y_%H%M%S'`
