#!/usr/bin/env bash

comp_prefix=@prefix@
moddir=$comp_prefix/finclude
libdir=$comp_prefix/lib
version=@version@

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

Known values for OPTION are:

  --libs		print library linking information
  --fcflags		print pre-processor and compiler flags
  --help		display this help and exit
  --version		display version information
EOF

    exit $1
}

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

    case "$1" in
    --version)
	echo ${version}
	exit 0
	;;

    --help)
	usage 0
	;;

    --fcflags)
        FLAGS=FC
       	;;

    --libs)
        FLAGS=LD
       	;;

    --wxml)
        MODULES="$MODULES wxml common fsys"
        ;;
    --wcml)
        MODULES="$MODULES wcml wxml utils common fsys"
        ;;
    --sax)
        MODULES="$MODULES sax common fsys"
        ;;
    --dom)
        MODULES="$MODULES dom sax wxml common fsys"
        ;;

    *)
	usage
	exit 1
	;;
    esac
    shift
done

if [[ $MODULES = *fsys* ]]; then
  LIBS=-lfsys
fi
if [[ $MODULES = *common* ]]; then
  LIBS="-lFoX_common $LIBS"
fi
if [[ $MODULES = *utils* ]]; then
  LIBS="-lFoX_utils $LIBS"
fi
if [[ $MODULES = *wxml* ]]; then
  LIBS="-lFoX_wxml $LIBS"
fi
if [[ $MODULES = *wcml* ]]; then
  LIBS="-lFoX_wcml $LIBS"
fi
if [[ $MODULES = *sax* ]]; then
  LIBS="-lFoX_sax $LIBS"
fi
if [[ $MODULES = *dom* ]]; then
  LIBS="-lFoX_dom $LIBS"
fi
if [ -z "$LIBS" ]; then
  LIBS="-lFoX_sax -lFoX_wcml -lFoX_wxml -lFoX_common -lfsys"
fi

case $FLAGS in
  FC)
    echo @FC_MOD_FLAG@"$(@CYGPATH_W@ $moddir)"
    ;;
  LD)
    echo -L"$(@CYGPATH_W@ $libdir)" $LIBS
    ;;
  both)
    echo @FC_MOD_FLAG@"$(@CYGPATH_W@ $moddir)" -L"$(@CYGPATH_W@ $libdir)" $LIBS
esac 

exit 0
