#! /bin/sh
#
# sc68-config is a very simple replacement to pkg-config.
#
# $Id: sc68-config.in,v 2.3 2003/09/25 01:00:00 benjihan Exp $
#

prefix="/usr"
exec_prefix="/usr"
libdir="/usr/libx32"
includedir="/usr/include"
pkgincludedir="${includedir}/sc68"

modversion="2.2.1"

cflags="-DHAVE_CONFIG_CONFIG68_H=1 -DNO_FALLBACK_CONFIG=1"
iflags="-I${pkgincludedir}"
lflags="-lapi68 -lfile68 -lunice68 -lemu68 -lio68 -lz"
Lflags="-L${libdir}"

RETURN=""

VersionToNumber()
{
    ver="$1"

    n=`expr "${ver}" : '[0-9]\{1,2\}\.[0-9]\{1,2\}\.[0-9]\{1,2\}$'`
    if test $n -eq 0; then
	echo "${ver}: bad version number" 1>&2
	return 1
    fi

    a=`expr "${ver}" : '\([0-9]\{1,2\}\)'`
    b=`expr "${ver}" : '[0-9]\{1,2\}\.\([0-9]\{1,2\}\)'`
    c=`expr "${ver}" : '[0-9]\{1,2\}\.[0-9]\{1,2\}\.\([0-9]\{1,2\}\)'`

    expr "$a" '*' '10000' +  "$b" '*' '100' + "$c"
}

while test $# -ge 1; do
    case "$1" in
	--help)
	    cat <<EOF
Usage: sc68-config [OPTION...] [sc68]
  --help                     output this message and exit
  --version                  output version and exit

  --exists                   True if module exist
  --modversion               output version for package
  --atleast-version=VERSION  True if modversion is at least VERSION
  --exact-version=VERSION    True if modversion is at exactly VERSION
  --max-version=VERSION      True if modversion is greater or equal to VERSION

  --libs                     output all linker flags
  --libs-only-l              output -l flags
  --libs-only-other          output other libs
  --libs-only-L              output -L flags

  --cflags                   output all pre-processor and compiler flags
  --cflags-only-I            output -I flags
  --cflags-only-other        output cflags not covered by --cflags-only-I

EOF
	    exit 1
	    ;;
	--version)
	    echo "1.0.0"
	    exit 0;
	    ;;

	--exists)
	    exit 0
	    ;;
	--modversion)
	    echo "${modversion}"
	    ;;
	--exact-version=*)
	    optversion="`expr "$1" : '--exact-version=\(.*\)'`"
	    test "${optversion}" = "${modversion}"
	    exit $?
	    ;;
	--atleast-version=*)
	    optversion="`expr "$1" : '--atleast-version=\(.*\)'`"
	    verA=`VersionToNumber ${modversion}`
	    verB=`VersionToNumber ${optversion}`
	    test -n "${verA}" &&
	    test -n "${verB}" &&
	    test ${verA} -ge ${verB}
	    exit $?
	    ;;
	--max-version=*)
	    optversion="`expr "$1" : '--max-version=\(.*\)'`"
	    verA=`VersionToNumber ${modversion}`
	    verB=`VersionToNumber ${optversion}`
	    test -n "${verA}" &&
	    test -n "${verB}" &&
	    test ${verA} -le ${verB}
	    exit $?
	    ;;

	--libs)
	    RETURN="${RETURN} ${Lflags} ${lflags}"
	    ;;
	--libs-only-l)
	    RETURN="${RETURN} ${lflags}"
	    ;;
	--libs-only-L)
	    RETURN="${RETURN} ${Lflags}"
	    ;;
	--libs-only-other)
	    ;;

	--cflags)
	    RETURN="${RETURN} ${iflags} ${cflags}"
	    ;;
	--cflags-only-I)
	    RETURN="${RETURN} ${iflags}"
	    ;;
	--cflags-only-other)
	    RETURN="${RETURN} ${cflags}"
	    ;;

	--*)
	    echo "$1: unknown option" 1>&2
	    exit 255
	    ;;
	*)
	    if test "x$1" != "xsc68"; then
		echo "$1: wrong package name" 1>&2
		exit 255
	    fi
	    ;;
    esac
    shift
done

test "x${RETURN}" == "x" || echo "${RETURN}"

