#!/bin/bash

#Get number of cpus on current platform
NUMCPUS=`grep -c processor /proc/cpuinfo`;

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

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

#Create src and install directories
mkdir src install

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

#Move gdal into src directory
mv gdal-$version/* src
rm -rf gdal-$version

#Configure gdal
cd src
./configure --prefix="$ISSM_DIR/packages/gdal/install" --without-python --with-netcdf=no --with-jasper=no --without-ld-shared --with-unix-stdio-64=no

#Patch GDALmake.opt
patch -R GDALmake.opt ../GDALmake.opt.patch

#Compile gdal
make  -j $NUMCPUS

#Install gdal
make  install
