#!/bin/sh

MAJOR=5
MINOR=0
SUBMINOR=1
BUILD=6388
TAG=

DIR=`dirname $0`
PYLON_ROOT=`cd $DIR/.. && pwd`

CFLAGS_I="-I$PYLON_ROOT/include"
CFLAGS_EXTRA=

LIBDIR="$PYLON_ROOT/lib64"
LIBS_L="-L$LIBDIR"
LIBS_EXTRA="-Wl,-E"
LIBS_l="-lpylonbase -lpylonutility -lGenApi_gcc_v3_0_Basler_pylon_v5_0 -lGCBase_gcc_v3_0_Basler_pylon_v5_0"
LIBS_RPATH="-Wl,--enable-new-dtags -Wl,-rpath,$LIBDIR"
LIBS_RPATH_LINK="-Wl,-rpath-link,$LIBDIR"


printHelp() {
  echo  "\
Usage: $0 <command>...

  Allowed Commands:  
    -h, --help          This help.
    --version           Prints the full pylon version
    --version-major     Prints the major version
    --version-minor     Prints the minor version
    --version-subminor  Prints the subminor version
    --version-build     Prints the build version

    --cflags            output all pre-processor and compiler flags
    --cflags-only-I     output -I flags
    --cflags-only-other output cflags not covered by the cflags-only-I option
    --libs              output all linker flags (except rpath flags)
    --libs-only-l       output -l flags
    --libs-only-other   output other libs (e.g. -pthread)
    --libs-only-L       output -L flags
    --libs-rpath        output rpath flags (for library dependencies at build and runtime)
    --libs-rpath-link   output rpath-link flags (for second level library dependencies at build time)
    --libdir            output absolute path to pylon library directory
"
}

cmd=$1
if [ -z "$cmd" ]; then
    cmd="--help"
fi

while [ -n "${cmd}" ]; do
    case $cmd in
        --version) echo -n $MAJOR.$MINOR.$SUBMINOR.$BUILD$TAG ;;
        --version-major) echo -n $MAJOR ;;
        --version-minor) echo -n $MINOR ;;
        --version-subminor|--version-tiny) echo -n $SUBMINOR ;;
        --version-build) echo -n $BUILD ;;

        --cflags) echo -n "$CFLAGS_I $CFLAGS_EXTRA";;
        --cflags-only-I) echo -n "$CFLAGS_I";;
        --cflags-only-other) echo -n "$CFLAGS_EXTRA";;

        --libs) echo -n "$LIBS_L $LIBS_EXTRA $LIBS_l";;
        --libs-only-l) echo -n "$LIBS_l";;
        --libs-only-other) echo -n "$LIBS_EXTRA";;
        --libs-only-L) echo -n "$LIBS_L";;
        --libs-rpath) echo -n "$LIBS_RPATH";;
        --libs-rpath-link) echo -n "$LIBS_RPATH_LINK";;
        --libdir) echo -n "$LIBDIR";;

        -h|--help) printHelp; exit 1 ;;
        *)
          echo "Unknown command $cmd"
          printHelp
          exit 1
          ;;
    esac
    shift
    cmd=$1
    if [ -n "$cmd" ]; then
        echo -n " "
    fi
done

echo ""
