#!/bin/sh

prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
pkglibdir=${libdir}/vala@PACKAGE_SUFFIX@

if [ $# -ne 2 ]
then
	echo "Usage: `basename $0` PKGNAME BASEPATH"
	exit 1
fi

PKGNAME=$1
PKGBASE=$2/$1
PKGPREFIX=`pkg-config --variable=prefix $PKGNAME`

PKGFILES=`cat $PKGBASE.files | grep ^[/.]`

# This is to avoid adding a leading / in case the prefix is ""
if [ "x$PKGPREFIX" != "x" ]; then
        PKGPREFIXPLUSDELIMIT="$PKGPREFIX/"
fi

PKGFILES="${PKGFILES}\
	`cat $PKGBASE.files | grep ^[a-zA-Z.] | sed -e "s@^@$PKGPREFIXPLUSDELIMIT@"`"

if [ -e $PKGBASE.excludes ]
then
	FILES=`find $PKGFILES -name "*.h" -or -name "*.so" | grep -v -f $PKGBASE.excludes`
else
	FILES=`find $PKGFILES -name "*.h" -or -name "*.so"`
fi

if [ -e $PKGBASE.defines ]
then
	PKGDEFINES=$(cat $PKGBASE.defines)
fi

$pkglibdir/gen-introspect@PACKAGE_SUFFIX@ --namespace=`cat $PKGBASE.namespace` $PKGDEFINES `pkg-config --cflags $PKGNAME | sed 's/-pthread//g'` $FILES > $PKGBASE.gi

