#!/bin/sh

prefix=/usr/local
exec_prefix=/usr/local
exec_prefix_set=no

old_include_names=yes

usage()
{
  cat <<EOF 1>&2
Usage: lqt-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--use-lqt-includes] 
                  [--plugin-dir] [--version] [--libs | --plugin-libs] 
                  [--cflags | --plugin-cflags] [modules...]

Available modules are: quicktime1394 cinelerra (prints libs for cinelerra)
EOF
  exit 1
}

if test $# -eq 0; then
    usage
fi

the_libs="-lquicktime -pthread -lz "
the_cflags=""

echo_libs=no
echo_cflags=no

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

  case $1 in
# modules
    quicktime1394)
      the_libs="$the_libs  -lquicktime1394"
      the_cflags="$the_cflags "
      ;;
# cinelerra
    cinelerra)
      the_libs="$the_libs -lquicktime_mjpeg -ljpeg  -lvorbisfile -lvorbisenc -L${exec_prefix}/lib -lvorbis -logg -lm  -lquicktime1394"
      the_cflags="$the_cflags "
      ;;
# options
    --prefix=*)
      prefix=$optarg
      if test $exec_prefix_set = no ; then
        exec_prefix=$optarg
      fi
      ;;
    --prefix)
      echo $prefix
      ;;
    --exec-prefix=*)
      exec_prefix=$optarg
      exec_prefix_set=yes
      ;;
    --exec-prefix)
      echo $exec_prefix
      ;;
    --use-lqt-includes)
      old_include_names=no
      ;;
    --version)
      echo 0.9.3
      ;;
    --plugin-dir)
      echo /usr/local/lib/libquicktime
      ;;
    --cflags|--plugin-cflags)
      if test ${prefix}/include != /usr/include ; then
          # Handle oddities in Win32 path handling (assumes prefix)
          prefix=`echo ${prefix} | sed 's,^//\([A-Z]\),\1:,'`

          includes=-I${prefix}/include
      fi
      if test x$old_include_names = xyes; then
	the_cflags="$includes -I${prefix}/include/quicktime $the_cflags"
      else
	the_cflags="$includes $the_cflags"
      fi
      echo_cflags=yes
      ;;
    --libs|--plugin-libs)
      the_libs="-L${exec_prefix}/lib $the_libs"
      echo_libs=yes
      ;;
    *)
      usage
      ;;
  esac
  shift
done

if test x$echo_libs = xyes; then
  echo $the_libs
fi

if test x$echo_cflags = xyes; then
  echo $the_cflags
fi
