#!/bin/bash

SPECDIR=`rpm --eval %_specdir`
SRCDIR=`rpm --eval %_sourcedir`
USERID=`id -u`
GRPID=`id -g`
SPECFILE="likewise-open.spec"

## get utility functions
. `dirname $0`/functions
VERSION=$(get_lwopen_version)
if [ "x${VERSION}" = "x" ]; then
	echo "Failed to get Likewise Open Version."
	exit 1
fi
. `dirname $0`/../suse/release-info

## create the %_topdir heirarchy
create_rpmbuild_directory || exit 1

## check for some necessary files first
type gmcs 2>&1 > /dev/null
if [ $? != 0 ]; then
	echo "Cannot locate gmcs.  Please ensure it can be found in your PATH"
	exit 1
fi

cd `dirname $0`

(cd ../suse && tar cvf - setup | gzip -9 > ${SRCDIR}/setup.tar.gz) || exit 1
cp -p ../../../likewise-open-${VERSION}.tar.gz ${SRCDIR}/ || exit 1
cat ../suse/${SPECFILE} |\
	sed -e s/__RPM_VER/${VERSION}/g \
		-e s/__RPM_RELEASE/${RELEASE}/g > ${SPECDIR}/${SPECFILE} || exit 1
rpmbuild -ba ${SPECDIR}/${SPECFILE}



