#!/bin/bash

#Get number of cpus on current platform
NUMCPUS=$1;

#version of petsc?
#version='2.3.2-p3';
version='3.1-p7'
#version='3.2-p3'

#Some cleanup
rm -rf install petsc-$version src

#Create src and install directories
mkdir install src

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

#Untar 
tar -zxvf  petsc-$version.tar.gz

#Move petsc to install directory or src depending on the version
if [[ $version != "2.3.2-p3" ]]
then	
	mv petsc-$version/* src/
	rm -rf petsc-$version
	cd src
else
	mv petsc-$version/* install/
	rm -rf petsc-$version
	cd install
fi

#configure
../configure.sh

#Compile petsc and install it
if [ -z $NUMCPUS ];
then
	make
else
	make -j $NUMCPUS
fi
make install
