HowTo Create A Patch File For A RPM
Often when building packages, you will find yourself where you need to "tweak" or "fix" the base software distribution in order to get the desired results of the generated binary RPM package.
This page outlines the steps used to create a patch for the BASE package and is intended to serve as a model for NST developers (though others might find it useful as well).
Get A Base Copy Of The Original Source Tree
The following commands will extract the contents of the original source tar ball into the directory /tmp/patch/base-1.4.4:
[root@f12-64 ~]# rmdir /tmp/patch [root@f12-64 ~]# cd /tmp [root@f12-64 tmp]# mkdir patch [root@f12-64 tmp]# cd patch [root@f12-64 patch]# tar xzf /tmp/base-1.4.4.tar.gz
Make a Copy of the Original Source Tree
The following saves a copy of the original source files (which will be used later in finding the differences necessary for the patch).
[root@f12-64 patch]# cp -rp base-1.4.4 base-1.4.4-orig [root@f12-64 patch]# ls base-1.4.4 base-1.4.4-orig [root@f12-64 patch]#
Make Changes
At this point, we will make our changes to the source files found under the /tmp/patch/base-1.4.4 directory.
Use diff to Create the Patch File
Once we've completed our updates to the source code, we'll use the diff command to create a patch file for us in the following mannder:
[root@f12-64 patch]# diff -ru base-1.4.4-orig base-1.4.4 >| $HOME/rpmbuild/SOURCES/base-1.4.4-f12.patch [root@f12-64 patch]#
NOTE: The $HOME/rpmbuild/SOURCES directory may need to be created (or changed) depending on the version of rpmbuild you are using. When we create packages for the NST project we save these patch files under subversion and then install them to the $HOME/rpmbuild/SOURCES directory when the package is built.
Update the RPM Spec File to Apply the Patch
Now that we've created the patch file base-1.4.4-f12.patch, we'll need to update the RPM spec file to make use of the package. This requires two new entries. One to indicate that there is a new patch file and another in the %setup section to apply the patch.
# In the top section (near Source line) Patch1: base-1.4.4.patch # And at the end of the %prep area %prep %setup -q -n %{name}-%{version} %patch0 -p0 %patch1 -p0
Build the RPM
Assuming all of the necessary source files are installed under the $HOME/rpmbuild directory and the spec file is installed at $HOME/rpmbuild/SPECS/base.spec, you should be able to build the source RPM with the following command:
need to validate and finish...