Geert JM Vanderkelen

Using printf format %P with find in RPM spec file

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

74 − = 68

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>