#!/bin/sh

prefix=/usr
exec_prefix=${prefix}
libdir=/usr/lib64
pkglibdir=${libdir}/vala-0.42

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-0.42 --namespace=`cat $PKGBASE.namespace` $PKGDEFINES `pkg-config --cflags $PKGNAME | sed 's/-pthread//g'` $FILES > $PKGBASE.gi

