rpmbuild %clean phase without removing files

devios1 picture devios1 · Dec 12, 2012 · Viewed 10.2k times · Source

I am getting the following in my build log:

Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.CgE2Qn
+ umask 022
+ cd /export/home/svn_checkouts/*snip*/Output/release/bin/packaging/BUILD
+ /bin/rm -rf /export/home/svn_checkouts/*snip*/Output/release/bin
+ exit 0

I'd like to avoid rpmbuild deleting all the files in my build directory as I need them for other things after the RPM is built. Can I override this behavior?

I read that some versions of RPM support a --noclean argument, but ours doesn't unfortunately.

Answer

devios1 picture devios1 · Dec 12, 2012

Turns out I just needed to provide my own %clean directive in the spec file and leave it blank to override the default. For some reason I didn't expect that to work. ;)

A define can conditionalize the %Clean% phase so that the same effect as --noclean can be achieved.

%Clean
%if "%{noclean}" == ""
   rm -rf $RPM_BUILD_ROOT
%endif

Called with rpmbuild --define 'noclean 1' to disable cleaning.