#!/bin/bash

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

#version of petsc
version=`echo *.tar.gz | sed 's/\.tar\.gz//g' | sed 's/petsc-//g'`

#Some cleanup
rm -rf install petsc-$version

#Create install directories
mkdir install

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

#Move petsc to install directory
rm -rf install/*
mv petsc-$version/* install/
rm -rf petsc-$version

#Configure petsc
cd install
../configure.sh

#symlink some missing stuff.
cd conf
ln -s ../$ISSM_ARCH/conf/petscrules petscrules 
ln -s ../$ISSM_ARCH/conf/petscvariables petscvariables 
cd ../
cd include
ln -s ../$ISSM_ARCH/include/petscconf.h petscconf.h 
cd ../

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