#!/bin/bash
echo "Building PROJ.4 $1 version from source..."
if [[ $1 == "git" ]]; then
  git clone https://github.com/OSGeo/proj.git proj-git
else
  curl https://download.osgeo.org/proj/proj-$1.tar.gz > "proj-${1:0:5}.tar.gz"
  tar zxf "proj-${1:0:5}.tar.gz"
fi
cd "proj-${1:0:5}"

# Download and extract grids
curl http://download.osgeo.org/proj/proj-datumgrid-1.8.zip > proj-datumgrid-1.8.zip
cd data
unzip -o ../proj-datumgrid-1.8.zip
rm ../proj-datumgrid-1.8.zip
cd ..

# could be installed to a cached location (probably not git version)
# seems to take only about 13 seconds of build time
# build using autotools
sh autogen.sh
./configure --prefix=$PROJ_DIR
make 
make install
# build using cmake
#cmake . -DCMAKE_INSTALL_PREFIX=$PROJ_DIR
#cmake --build .
#make install
find $PROJ_DIR
# export PROJ_DIR="/tmp/proj_dl_install"
cd ..
