#!/bin/sh 
#
# turns one or more package source files (orig and diffs) into .vrp packages
# by calling vrpprep and vrpbuild 
#

if [ ! $1 ]; then
	BUILDFILES=*.orig.tar.gz
	if test $VERBOSITY -gt 0; then
		echo "Building all source files in this directory."
	fi
else
	BUILDFILES=$1
fi

for BUILDFILE in $BUILDFILES; do
	BUILDPACKNAME=${BUILDFILE%%.orig.tar.gz*}
	if [ "${BUILDPACKNAME}.vrp" -nt "${BUILDPACKNAME}-1.diff.gz" ]; then
		if [ "${BUILDPACKNAME}.vrp" -nt "${BUILDPACKNAME}.orig.tar.gz" ]; then
			if test $VERBOSITY -gt 0; then
				echo "Skipping ${BUILDPACKNAME} - vrp newer than the source files."
			fi
			continue;
		fi
	fi
	if ! vrpprep $BUILDPACKNAME; then
		echo "Error in vrpprep $BUILDPACKNAME."
		exit 1
	fi
	oDIR=`pwd`
	if [ -d $BUILDPACKNAME ]; then
		cd $BUILDPACKNAME
		if vrpbuild $BUILDPACKNAME; then
			mv ${BUILDPACKNAME}.vrp $oDIR
			cd $oDIR
			rm -f -r ${BUILDPACKNAME}
		else
			echo "Error in vrpbuild $BUILDPACKNAME."
			exit 1
		fi
	else
		echo "Error - vrpprep didn't create directory $BUILDPACKNAME."
		exit 1
	fi
done 
