#!/bin/sh

rpm --showrc | grep macrofiles | sed 's/$/:\.\/rpmmacros/' > rpmrc
echo %_sourcedir $PWD/SOURCES > rpmmacros
echo %_rpmdir $PWD/RPMS >> rpmmacros
echo %_srcrpmdir $PWD/SRPMS >> rpmmacros
echo >> rpmmacros

if test -f $HOME/.rpmrc; then
	mv $HOME/.rpmrc $HOME/.rpmrcsave
	cat $HOME/.rpmrcsave ./rpmrc > $HOME/.rpmrc
else
	cat ./rpmrc > $HOME/.rpmrc
fi

rpm $@

if test -f $HOME/.rpmrcsave; then
	mv $HOME/.rpmrcsave $HOME/.rpmrc
else
	rm $HOME/.rpmrc
fi