Short Tip: Create a patch and use it in rpm

Create a patch and use it in rpm
Sometimes there is the need for simple patches to build rpm packages properly. Most packages know this one by heart, but just in case I wont to write it down here.

To create patches, first unpack the sources and create a copy of the sources under a new name. The best is to use a name with a suffix, like ProgramDir_new. Afterwards, change into the _new directory, modify whatever you need to modify and go back to the main directory.

After that, call the diff tool, save the ouput as a patch and move the patch to where you need it:

diff -uNr ProgramDir ProgramDir_new > my-changes.patch
mv my-changes.patch ~/rpm-system/SOURCES/.

The u is for the right patch format, the N includes new files, the r is for recursive.

Now add the patch as another source in your rpm spec file and call the patch algorithm during the preparations:

Patch0:         my-changes.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%setup -q
%patch -p1

That’s it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s