#!/bin/sh

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
pkglibdir=${libdir}/vala

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 ^[/.]`
PKGFILES="${PKGFILES}\
	 `cat $PKGBASE.files | grep ^[a-zA-Z] | sed -e "s@^@$PKGPREFIX/@"`"

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

