#!/bin/sh

## variables

CONFIG_PREFIX=/usr/local
CONFIG_MAPNIK_LIBNAME=mapnik2
CONFIG_MAPNIK_INCLUDE=${CONFIG_PREFIX}/include
CONFIG_MAPNIK_LIB=${CONFIG_PREFIX}/lib
CONFIG_MAPNIK_VERSION='2.0.0'
CONFIG_MAPNIK_LDFLAGS=' -L/usr/local/lib -L/usr/lib'
CONFIG_DEP_LIBS='  -lfreetype -lltdl -lpng -ltiff -lz -ljpeg -lproj -licuuc -lboost_filesystem -lboost_regex -lxml2 -lboost_thread -lboost_system -lcairomm-1.0 -lcairo -lsigc-2.0'
CONFIG_OTHER_INCLUDES=' -I/usr/local/include/libxml2 -I/usr/local/include/freetype2 -I/usr/local/include -I/usr/include -DHAVE_JPEG -DBOOST_REGEX_HAS_ICU -ansi -Wall -pthread -ftemplate-depth-300 -DFREEBSD -DBOOST_SPIRIT_THREADSAFE -DMAPNIK_THREADSAFE -O3 -finline-functions -Wno-inline -DNDEBUG -DHAVE_CAIRO -DLIBTOOL_SUPPORTS_ADVISE -DHAVE_LIBXML2  -I/usr/local/include/cairomm-1.0 -I/usr/local/lib/cairomm-1.0/include -I/usr/local/include/cairo -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -I/usr/local/include/glib-2.0 -I/usr/local/include/pixman-1 -I/usr/local/include/libpng'
CONFIG_FONTS='/usr/local/lib/mapnik2/fonts'
CONFIG_INPUT_PLUGINS='/usr/local/lib/mapnik2/input'
CONFIG_SVN_REVISION='None'

CONFIG_JSON="{
  \"prefix\": \"${CONFIG_PREFIX}\",
  \"mapnik_libname\": \"${CONFIG_MAPNIK_LIBNAME}\",
  \"mapnik_include\": \"${CONFIG_MAPNIK_INCLUDE}\",
  \"mapnik_lib\": \"${CONFIG_MAPNIK_LIB}\",
  \"version\": \"${CONFIG_MAPNIK_VERSION}\",
  \"ldflags\": \"${CONFIG_MAPNIK_LDFLAGS}\",
  \"dep_libs\": \"${CONFIG_DEP_LIBS}\",
  \"other_includes\": \"${CONFIG_OTHER_INCLUDES}\",
  \"fonts\": \"${CONFIG_FONTS}\",
  \"input_plugins\": \"${CONFIG_INPUT_PLUGINS}\",
  \"svn_revision\": ${CONFIG_SVN_REVISION}
}"


## program below

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

Known values for OPTION are:

  --prefix          display mapnik prefix [default $CONFIG_PREFIX]
  --prefix=DIR      change mapnik prefix [default $CONFIG_PREFIX]
  --libs            print library linking information
  --dep-libs        print library linking information for mapnik depedencies
  --ldflags         print library paths (-L) information
  --cflags          print pre-processor and compiler flags
  --fonts           print default fonts directory
  --input-plugins   print default input plugins directory
  --json            print all config options as json object
  --help            display this help and exit
  -v --version      output version information
  --svn-revision    output svn revision information
EOF

    exit $1
}

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

while test $# -gt 0; do
    case "$1" in
    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
    *) optarg= ;;
    esac

    case "$1" in
    
    --prefix=*)
      prefix=$optarg
      includedir=$CONFIG_PREFIX/include
      CONFIG_MAPNIK_LIB=$CONFIG_PREFIX/lib
      ;;

    --prefix)
      echo $CONFIG_PREFIX
      ;;

    -v)
      echo $CONFIG_MAPNIK_VERSION
      ;;

    --version)
      echo $CONFIG_MAPNIK_VERSION
      ;;

    --json)
      echo $CONFIG_JSON
      ;;

    --svn-revision)
      echo ${CONFIG_SVN_REVISION}
      ;;

    --help)
      usage 0
      ;;

    --fonts)
      echo ${CONFIG_FONTS} 
      ;;

    --input-plugins)
      echo ${CONFIG_INPUT_PLUGINS} 
      ;;
      
    --cflags)
      echo -I${CONFIG_MAPNIK_INCLUDE} ${CONFIG_OTHER_INCLUDES}
      ;;

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

    --ldflags)
      echo ${CONFIG_MAPNIK_LDFLAGS}
      ;;

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

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

    *)
  # if no matches, return 'usage 1' meaning usage + 1 (error return type)
  usage 1
  exit 1
  ;;
    esac
    shift
done

exit 0
