Patching a Source RPM, .spec file, and so forth - moving toward a systematic protocol 0. This is outside of the scope of patching RPM content, but it has long been known that one builds as an unprivileged user, and only installs as 'root'. Better still, one only builds in a fully patched, fresh copy of a 'virgin' install building chroot. That is, we do NOT risk our system unnecessarily, nor carry a lot of random packages in our build environment. To set such an environment up with the mediation of 'yum', see: ftp://ftp.owlriver.com/pub/local/ORC/ORCrebuild/ORCyum-chroot-caos 1. Obtain an existing SRPM -- for this example, we'll use the long present 'joe' package (a Word*Star like text editor, long present the Open Source world. We use the word 'whatever' as a stand in for the Release and Version parts of the SRPM name. For convenience, I have placed a copy of joe-2.9.8-4.src.rpm at: http://www.herrold.com/caos/joe-2.9.8-4.src.rpm which may be retrieved and installed thus: rpm -Uvh http://www.herrold.com/caos/joe-2.9.8-4.src.rpm 2. Install the SRPM rpm -Uvh joe-whatever.src.rpm 3. Move into the %(_topdir)/SPECS/ This is part of the RPM macro expansion process. This is a very useful function of RPM. Try this for an example: rpm --showrc | grep top which (on my host and build environment) yields: bash-2.05b$ rpm --showrc | grep top -14: _builddir %{_topdir}/BUILD -14: _rpmdir %{_topdir}/RPMS -14: _sourcedir %{_topdir}/SOURCES -14: _specdir %{_topdir}/SPECS -14: _srcrpmdir %{_topdir}/SRPMS -14: _topdir /home/herrold/rpmbuild bash-2.05b$ In my case, this is therefore the command: cd /home/herrold/rpmbuild/SPECS/ 4. Try an initial partial build, with it being patched by the rpmbuild process -- rpmbuild -bp joe(-possibly versioned).spec The -bp option is not often used outside of the context of patch management; in this context, however, it is invaluable, compared with, say, interrupting the process manually, for it stops after the %prep stanza of the .spec file, and before the %build stanza 5. Move into the %(_topdir)/BUILD/ thus: cd /home/herrold/rpmbuild/BUILD/ 6. Save a copy of its initial (as previously packaged and patched) state thus: mv ./joe-whatever ./joe-whatever-ORIG This represents the file with application of all the patches to that point. In the case, for example, of joe-2.9.8-4.src.rpm which exists at: ftp://ftp.owlriver.com/pub/mirror/ORC/joe/joe-2.9.8-4.src.rpm There are two patch files already present: bash-2.05b$ rpm -qlp /var/ftp/pub/mirror/ORC/joe/joe-2.9.8-4.src.rpm joe-2.9.8-joerc.patch joe-2.9.8-zerorc.patch joe-2.9.8.tar.gz joe.spec bash-2.05b$ 7. Lets do a small, cosmetic change -- the program version display on the initial splash screen. Currently, this is in the file 'main.c' in the lines: if (!nonotice) msgnw(((BASE *)lastw(maint)->object)->parent, "\\i** Joe's Own Editor v" VERSION " ** Copyright (C) 2003 **\\i"); edloop(0); Change line 382 to read: msgnw(((BASE *)lastw(maint)->object)->parent, "\\i** Joe's Own Editor version" VERSION " ** Copyright (C) 2003 **\\i"); using the second build copy (from %(_topdir)/BUILD/): joe ./joe-2.9.8-ORIG/main.c [Note that line 382 is spread over two lines in this example, to fit within an 80 column display] 8. Lets take a look at it: bash-2.05b$ diff -u joe-2.9.8-ORIG/main.c joe-2.9.8/main.c --- joe-2.9.8-ORIG/main.c 2003-05-05 03:14:25.000000000 -0400 +++ joe-2.9.8/main.c 2003-12-03 21:41:40.000000000 -0500 @@ -379,7 +379,7 @@ help_on(maint); } if (!nonotice) - msgnw(((BASE *)lastw(maint)->object)->parent, "\\i** Joe's Own Editor v" VERSION " ** Copyright (C) 2003 **\\i"); + msgnw(((BASE *)lastw(maint)->object)->parent, "\\i** Joe's Own Editor version" VERSION " ** Copyright (C) 2003 **\\i"); edloop(0); vclose(vmem); nclose(n); bash-2.05b$ 9. The line starting with a single '+' is the changed line. It looks good here. Now let's capture it into a new .patch file in the ./SOURCES/ directory. bash-2.05b$ diff -u joe-2.9.8-ORIG/main.c joe-2.9.8/main.c \ > ../SOURCES/joe-version.patch 10. Now, tell the .spec file about it. Let's save a copy of the original .spec file, so we can see the difference. cp ../SPECS/joe.spec ../SPECS/joe-ORIG.spec We add another PatchN: line, identifying the newly added .patch file, and an entry for the %prep stanza to apply it. The 'diff' looks like this: bash-2.05b$ diff -u ../SPECS/joe-ORIG.spec ../SPECS/joe.spec --- ../SPECS/joe-ORIG.spec 2003-12-03 21:49:04.000000000 -0500 +++ ../SPECS/joe.spec 2003-12-03 21:49:39.000000000 -0500 @@ -13,6 +13,7 @@ Buildroot: %{_tmppath}/%{name}-%{version}-root Patch0: joe-2.9.8-zerorc.patch Patch1: joe-2.9.8-joerc.patch +Patch2: joe-version.patch %description Joe is a powerful, easy to use, modeless text editor. @@ -23,6 +24,7 @@ %setup -q %patch0 -p1 %patch1 -p1 +%patch2 -p1 %build ./configure --prefix=/usr --sysconfdir=/etc/joe bash-2.05b$ Again, the lines with the single '+' indicate added lines. a matching entry in the %prep stanza to apply it. 11. Building it, installing and starting it, it seems to have worked: $ rpmbuild -ba ../SPECS/joe.spec $ sudo rpm -Uvh ../RPMS/i386/joe-2.9.8-4.i386.rpm 12. We do not address the need to add a %changelog stanza entry, and to bump the Release: tag, as outside of the scope of getting to a clean patch. ============================================ Outside master at: ftp://ftp.owlriver.com/pub/local/ORC/ORCrebuild/RPM-patch-protocol.txt linked and copy at: http://www.herrold.com/caos/ Rev: RPH 040219 - section 0 Initial: RPH 031202 couch:/~rpm/RPM-patch-protocol.txt