#!/bin/bash

#Some cleanup
rm -rf src install mpich2-1.0.2p1
mkdir src install

#Download from ISSM server
$ISSM_DIR/scripts/DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/mpich2-1.0.2p1.tar.gz' 'mpich2-1.0.2p1.tar.gz'

#Untar 
tar -zxvf  mpich2-1.0.2p1.tar.gz

#Move mpich2 into src directory
mv mpich2-1.0.2p1/* src
rm -rf mpich2-1.0.2p1

#Configure mpich2
cd src
make distclean
export CFLAGS="$CFLAGS -fPIC"
export FFLAGS="$FFLAGS -fPIC"
./configure \
	--prefix="$ISSM_DIR/externalpackages/mpich2/install" \
	--enable-sharedlibs=gcc \
	--enable-f91=gfortran 

#Apply Patch to examples
patch ./examples/Makefile ../configs/1.0.2/linux64/Examples.Makefile.patch
patch -R ./src/binding/cxx/mpicxx.h ../configs/1.0.2/linux64/mpicxx.h.patch
patch -R ./src/include/mpicxx.h ../configs/1.0.2/linux64/mpicxx.h.patch

#Compile mpich2 (parallel make not supported)
make
make install 
