#! /bin/sh

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

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

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

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