#! /bin/csh -f
#
# A fresh clean install of unsio and the python tools associated with it
#
# https://projets.lam.fr/projects/unsio/wiki/InstallationL
#
# a quick hack                 - May 2010
# some changed dir structure   - Jan 2013
# install_prefix added           Jun 2018
# added NEMO/opt check           Dec 2019
#
# g77:        -lfrtbegin -lg2c
# gfortran:   -lgfortran

# ubuntu requirements: swig	python-numpy	libhdf5-dev	libsqlite3-dev


#  -DCMAKE_INSTALL_PREFIX=<dir>          installation directory [${NEMO}]
#  -DCMAKE_BUILD_TYPE=<Debug|Release>    build type [Debug]
#  -DBUILD_SHARED_LIBS=<TRUE|FALSE>      shared or static libraries [TRUE]
#  -DCMAKE_DISABLE_FORTRAN=1

set dir=$NEMO/usr/jcl/unsio

# for linux
set args=""

# wrapper compiler: h5cc h5pcc

if (-e $NEMO/opt/include/hdf5.h) then
  echo Found HDF5 under NEMO/opt
  # HDF5_LIBRARIES
  set h5=(-DHDF5_INCLUDE_DIRS=$NEMO/opt/include -DHDF5_CXX_LIBRARIES=$NEMO/lib)
else
  set h5=()
endif

if ( ! -e ${dir} ) then
  #echo "mknemo.d: $dir does not exist; try"
  #echo '    (cd $NEMO/usr/jcl; make unsio; mknemo unsio)'
  # we clone first time
  cd $NEMO/usr/jcl
  git clone https://gitlab.lam.fr/jclamber/unsio
endif

if ( -e $dir ) then
  rm -rf $dir/build
  mkdir -p $dir/build
  cd $dir/build
  cmake -DCMAKE_INSTALL_PREFIX=$NEMO $h5 ..
  make
  make install
endif


echo Warning:  python interface is not yet installed. See $NEMO/usr/jcl/unsio/py/INSTALL
echo Basically:   pip install python-unsio
echo but consult your local python installation before blindly doing this.
