#! /bin/sh

if [ -e /usr/bin/rpmbuild ]; then
    rpm=/usr/bin/rpmbuild
else
    rpm=/bin/rpm
fi

tmpdir=$(mktemp -d /tmp/${0##*/}.XXXXXX)
wd=$PWD
mkdir -p $wd/src

onexit() {
    rm -rf $tmpdir
    rmdir --ignore-fail-on-non-empty $wd/src
}
trap onexit EXIT

$rpm --eval "%define _sourcedir $wd" \
     --eval "%define _srcrpmdir $wd/src" \
     --eval "%define _rpmdir $wd" \
     --eval "%define _builddir $tmpdir" \
     --eval "%define _specdir $wd" \
     "$@"
