#!/usr/bin/env bash

## variables

CONFIG_PREFIX="$( cd "$( dirname $( dirname "$0" ))" && pwd )"

CONFIG_MAPNIK_VERSION_STRING='3.1.0'
CONFIG_MAPNIK_VERSION='300100'
CONFIG_GIT_REVISION='N/A'
CONFIG_GIT_DESCRIBE='3.1.0'
CONFIG_FONTS="${CONFIG_PREFIX}/lib/mapnik/fonts"
CONFIG_INPUT_PLUGINS="${CONFIG_PREFIX}/lib/mapnik/input"
CONFIG_MAPNIK_DEFINES=' -DMAPNIK_MEMORY_MAPPED_FILE -DMAPNIK_HAS_DLCFN -DBIGINT -DBOOST_REGEX_HAS_ICU -DHAVE_JPEG -DMAPNIK_USE_PROJ4 -DHAVE_PNG -DHAVE_WEBP -DHAVE_TIFF -DDARWIN -DMAPNIK_THREADSAFE -DBOOST_SPIRIT_NO_PREDEFINED_TERMINALS=1 -DBOOST_PHOENIX_NO_PREDEFINED_TERMINALS=1 -DBOOST_SPIRIT_USE_PHOENIX_V3=1 -DNDEBUG -DGRID_RENDERER'
CONFIG_MAPNIK_LIBNAME='mapnik'
CONFIG_MAPNIK_LIBPATH="${CONFIG_PREFIX}/lib"
CONFIG_DEP_LIBS='  -lboost_filesystem-mt -lboost_regex-mt -lpng -lproj -ltiff -lwebp -licui18n -lboost_system-mt -lharfbuzz -ljpeg -licuuc -lfreetype -lz'
CONFIG_MAPNIK_LDFLAGS="-L/opt/local/lib -L/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_gis_mapnik/mapnik/work/mapnik-v3.1.0/freetype -L/opt/local/lib/proj49/lib -L/opt/local/libexec/boost/1.76/lib -L/opt/local/lib/postgresql10 -stdlib=libc++ -L/opt/local/libexec/boost/1.76/lib -L/opt/local/lib -Wl,-headerpad_max_install_names -arch x86_64"
CONFIG_MAPNIK_INCLUDE="${CONFIG_PREFIX}/include -I${CONFIG_PREFIX}/include/mapnik/agg -I${CONFIG_PREFIX}/include/mapnik"
CONFIG_DEP_INCLUDES=" -I${NODE_CONFIG_PREFIX:-""}/opt/local/include -I${NODE_CONFIG_PREFIX:-""}/opt/local/include/freetype2 -I${NODE_CONFIG_PREFIX:-""}/opt/local/include/libpng16 -I${NODE_CONFIG_PREFIX:-""}/opt/local/lib/proj49/include -I${NODE_CONFIG_PREFIX:-""}/opt/local/libexec/boost/1.76/include -I${NODE_CONFIG_PREFIX:-""}/opt/local/include/postgresql10 "
CONFIG_CXXFLAGS="-std=c++14 -DU_USING_ICU_NAMESPACE=0 -stdlib=libc++ -I/opt/local/libexec/boost/1.76/include -I/opt/local/include -pipe -I/opt/local/libexec/boost/1.76/include -Os -stdlib=libc++ -arch x86_64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -ftemplate-depth-300 -Wsign-compare -Wshadow -O3"
CONFIG_CXX='/opt/local/bin/clang++-mp-16'
CONFIG_MAPNIK_GDAL_DATA=''
CONFIG_MAPNIK_PROJ_LIB='/opt/local/lib/proj49/share/proj/'
CONFIG_MAPNIK_ICU_DATA='b'/opt/local/share/icu/74.2''


## program below

usage()
{
    cat <<EOF
Usage: mapnik-config [OPTION]

Known values for OPTION are:

  -h --help         display this help and exit
  -v --version      version information (MAPNIK_VERSION_STRING)
  --version-number  version number (MAPNIK_VERSION) (new in 2.2.0)
  --git-revision    git hash from "git rev-list --max-count=1 HEAD"
  --git-describe    git decribe output (new in 2.2.0)
  --fonts           default fonts directory
  --input-plugins   default input plugins directory
  --defines         pre-processor defines for Mapnik build (new in 2.2.0)
  --prefix          Mapnik prefix [default $CONFIG_PREFIX]
  --lib-name        Mapnik library name
  --libs            library linking information
  --dep-libs        library linking information for Mapnik dependencies
  --ldflags         library paths (-L) information
  --includes        include paths (-I) for Mapnik headers (new in 2.2.0)
  --dep-includes    include paths (-I) for Mapnik dependencies (new in 2.2.0)
  --cxxflags        c++ compiler flags and pre-processor defines (new in 2.2.0)
  --cflags          all include paths, compiler flags, and pre-processor defines (for back-compatibility)
  --cxx             c++ compiler used to build mapnik (new in 2.2.0)
  --all-flags       all compile and link flags (new in 2.2.0)
  --gdal-data       path to GDAL_DATA directory, if detected at build time (new in 3.0.16)
  --proj-lib        path to PROJ_LIB directory, if detected at build time (new in 3.0.16)
  --icu-data        path to ICU_DATA directory, if detected at build time (new in 3.0.16)
EOF

    exit $1
}

echoerr() { echo "$@" 1>&2; }

if test $# -eq 0; then
    usage 1
fi

while test $# -gt 0; do
    case "$1" in
    esac

    case "$1" in

    --help)
      usage 0
      ;;

    -h)
      usage 0
      ;;

    -v)
      echo ${CONFIG_MAPNIK_VERSION_STRING}
      ;;

    --version)
      echo ${CONFIG_MAPNIK_VERSION_STRING}
      ;;

    --version-number)
      echo ${CONFIG_MAPNIK_VERSION}
      ;;

    --git-revision)
      echo ${CONFIG_GIT_REVISION}
      ;;

    --git-describe)
      echo ${CONFIG_GIT_DESCRIBE}
      ;;

    --fonts)
      echo ${CONFIG_FONTS}
      ;;

    --input-plugins)
      echo ${CONFIG_INPUT_PLUGINS}
      ;;

    --defines)
      echo ${CONFIG_MAPNIK_DEFINES}
      ;;

    --prefix)
      echo ${CONFIG_PREFIX}
      ;;

    --lib-name)
      echo ${CONFIG_MAPNIK_LIBNAME}
      ;;

    --libs)
      echo -L${CONFIG_MAPNIK_LIBPATH} -l${CONFIG_MAPNIK_LIBNAME}
      ;;

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

    --ldflags)
      echo ${CONFIG_MAPNIK_LDFLAGS}
      ;;

    --includes)
      echo -I${CONFIG_MAPNIK_INCLUDE}
      ;;

    --dep-includes)
      echo ${CONFIG_DEP_INCLUDES}
      ;;

    --cxxflags)
      echo ${CONFIG_CXXFLAGS}
      ;;

    --cflags)
      echo -I${CONFIG_MAPNIK_INCLUDE} ${CONFIG_DEP_INCLUDES} ${CONFIG_MAPNIK_DEFINES} ${CONFIG_CXXFLAGS}
      ;;

    --cxx)
      echo ${CONFIG_CXX}
      ;;

    --all-flags)
      echo -I${CONFIG_MAPNIK_INCLUDE} ${CONFIG_DEP_INCLUDES} ${CONFIG_MAPNIK_DEFINES} ${CONFIG_CXXFLAGS} -L${CONFIG_MAPNIK_LIBPATH} -l${CONFIG_MAPNIK_LIBNAME} ${CONFIG_MAPNIK_LDFLAGS} ${CONFIG_DEP_LIBS}
      ;;

    --gdal-data)
      if [[ ${CONFIG_MAPNIK_GDAL_DATA:-unset} != "unset" ]]; then echo ${CONFIG_MAPNIK_GDAL_DATA}; fi;
      ;;

    --proj-lib)
      if [[ ${CONFIG_MAPNIK_PROJ_LIB:-unset} != "unset" ]]; then echo ${CONFIG_MAPNIK_PROJ_LIB}; fi;
      ;;

    --icu-data)
      if [[ ${CONFIG_MAPNIK_ICU_DATA:-unset} != "unset" ]]; then echo ${CONFIG_MAPNIK_ICU_DATA}; fi;
      ;;

    *)
  # push to stderr any invalid options
  echo "unknown option $1" 1>&2;
  ;;
    esac
    shift
done

exit 0
