Using printf format %P with find in RPM spec file

While creating a spec file for an RPM, I needed to generate the list of files installed by the RPM. Solution is simple, use the UNIX command find. Right..

My first attempt was the following:

%install
# copy the files
( cd %{buildroot} ; find -type f -print "/%P\n" ) > INSTALLED_FILES

If you do the above, you’ll find that all entries in INSTALLED_FILES are wrong: file name have ‘ATCH’ at the end. Why is this? Because %p is a special macro in RPM spec files.

You can try to escape %P in an RPM spec file. If you manage that, let me know, I couldn’t.

Here is the solution I came up with after lots of hacking: it defines the pattern used in the find command as a macro.

%define findpat %( echo "/%""P" )

%install
# copy the files
( cd %{buildroot} ; find -type f -print "%{findpat}\n" ) > INSTALLED_FILES

I hope you never have to do this though.