#!/bin/bash
#--------------------------------------------------------------------
#  $Id: gmt-config.in 12822 2014-01-31 23:39:56Z remko $
#
#  Copyright (c) 1991-2014 by P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis and F. Wobbe
#  See LICENSE.TXT file for copying and redistribution conditions.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; version 3 or any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#
#  Contact info: gmt.soest.hawaii.edu
#
# gmt-config simply reports various paths and settings that are useful
# to developers that need to include/link GMT5 resources.
#--------------------------------------------------------------------*/
#
GMT_EXEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CONFIG_CFLAGS="-I@CMAKE_INSTALL_PREFIX@/@GMT_INCLUDEDIR@"
CONFIG_DATA=$($GMT_EXEDIR/gmt --show-datadir)
CONFIG_DEP_LIBS="@NETCDF_LIBRARIES@ @GMT_OPTIONAL_LIBRARIES@"
CONFIG_GSHHG=$($GMT_EXEDIR/gmt gmtget DIR_GSHHG)
CONFIG_DCW=$($GMT_EXEDIR/gmt gmtget DIR_DCW)
CONFIG_INCLUDEDIR="@CMAKE_INSTALL_PREFIX@/@GMT_INCLUDEDIR@"
CONFIG_LIBS="-L@CMAKE_INSTALL_PREFIX@/@GMT_LIBDIR@ -lgmt"
CONFIG_PREFIX="@CMAKE_INSTALL_PREFIX@"
CONFIG_VERSION="@GMT_PACKAGE_VERSION_WITH_SVN_REVISION@"

if [ "@HAVE_FFTW3F@" == "TRUE" ]; then
  CONFIG_FFTW_ENABLED=yes
else
  CONFIG_FFTW_ENABLED=no
fi

if [ "@HAVE_GDAL@" == "TRUE" ]; then
  CONFIG_GDAL_ENABLED=yes
else
  CONFIG_GDAL_ENABLED=no
fi

if [ "@HAVE_PCRE@" == "TRUE" ]; then
  CONFIG_PCRE_ENABLED=yes
else
  CONFIG_PCRE_ENABLED=no
fi

if [ @CMAKE_SIZEOF_VOID_P@ -eq 8 ]; then
  CONFIG_BITS=64
else
  CONFIG_BITS=32
fi

usage()
{
  cat <<EOF
Usage: gmt-config [OPTIONS]

Available values for OPTIONS include:

  --help        display this help message and exit
  --bits        whether library is build 32-bit or 64-bit
  --cflags      pre-processor and compiler flags
  --datadir     GMT's data directory
  --dcw         location of used DCW
  --dep-libs    dependent libraries
  --gshhg       location of used GSHHG
  --has-fftw    whether FFTW is used in build
  --has-gdal    whether GDAL is used in build
  --has-pcre    whether PCRE is used in build
  --includedir  include directory
  --libs        library linking information
  --prefix      install prefix
  --version     library version
EOF
  exit $1
}

[ -z "$1" ] && usage 1 1>&2

for arg in "$@"; do
  case $arg in
    --bits)
    echo $CONFIG_BITS
    ;;

    --cflags)
    echo $CONFIG_CFLAGS
    ;;

    --datadir)
    echo $CONFIG_DATA
    ;;

    --dcw)
    echo $CONFIG_DCW
    ;;

    --dep-libs)
    echo ${CONFIG_DEP_LIBS//;/ }
    ;;

    --gshhg)
    echo $CONFIG_GSHHG
    ;;

    --has-fftw)
    echo $CONFIG_FFTW_ENABLED
    ;;

    --has-gdal)
    echo $CONFIG_GDAL_ENABLED
    ;;

    --has-pcre)
    echo $CONFIG_PCRE_ENABLED
    ;;

    --includedir)
    echo $CONFIG_INCLUDEDIR
    ;;

    --libs)
    echo $CONFIG_LIBS
    ;;

    --prefix)
    echo $CONFIG_PREFIX
    ;;

    --version)
    echo $CONFIG_VERSION
    ;;

    *)
    usage 1 1>&2
    ;;
  esac
done
