ORC Owl Logo 2  

Owl River Company

  Your IP is:

Up More Tips

Adding a patch to SRPM packaged content


In our previous writeup, we discussed building SRPMs as a non-root user under CentOS. The next step, to 'kick it up a notch', is to actually make some changes in the sources, in a 'proper' fashion under RPM packaging discipline, to get a creation unlike any other [being an analog to doing some substantive change].

We note that creation of a brand new .spec file 'from scratch' is a harder than than modifying an existing one. Indeed, it is silly not to study and follow the pattern of examples of existing .spec files (found in ~/rpmbuild/SPECS/ after unpacking a few SRPMs).

We assume you have the non-root build environment set up per our prior tip.

First, start by retrieving the same sample SRPM into a new testing directory; we also install the SRPM, and copy the underlying .spec file and the tarball to the current working directory, so we can work on them:
[herrold@centos-4 ~$ cd [herrold@centos-4 ~$ cd build [herrold@centos-4 build]$ mkdir patching-example [herrold@centos-4 build]$ cd patching-example [herrold@centos-4 patching-example]$ wget ftp://ftp.owlriver.com/pub/mirror/ORC/joe/joe-2.9.8-4.src.rpm [herrold@centos-4 patching-example]$ ls joe-2.9.8-4.src.rpm [herrold@centos-4 patching-example]$ rpm -qlp joe-2.9.8-4.src.rpm warning: joe-2.9.8-4.src.rpm: V3 DSA signature: NOKEY, key ID 897da07a joe-2.9.8-joerc.patch joe-2.9.8-zerorc.patch joe-2.9.8.tar.gz joe.spec [herrold@centos-4 patching-example]$ rpm -U joe-2.9.8-4.src.rpm [herrold@centos-4 patching-example]$ cp ~/rpmbuild/SPECS/joe.spec joe-2.9.8.spec [herrold@centos-4 patching-example]$ cp ~/rpmbuild/SOURCES/joe-2.9.8.tar.gz . [herrold@centos-4 patching-example]$ ls joe-2.9.8-4.src.rpm joe-2.9.8.spec joe-2.9.8.tar.gz [herrold@centos-4 patching-example]$
Second, let's find a trivial change to make. In the prior example, the 'version banner' line started: ** Joe's Own Editor. Assume, for the sake of this demonstration that we want it to read: ** Big Joe's Editor [we choose a change which will show up well in a 'diff']. We make sure it is safe to unpack the tarball in the CWD (that is, that it unpacks to a subdirectory we do not mind over-writing), and then unpack it, rename the new directory to one side, and unpack it again [we do this, so that we have a pristine copy to run 'diff' against]:
[herrold@centos-4 patching-example]$ tar ztvf joe-2.9.8.tar.gz drwxr-xr-x root/root 0 2003-05-05 03:15:34 joe-2.9.8/ -rw-r--r-- root/root 2607 2002-01-15 08:20:35 joe-2.9.8/acinclude.m4 -rw-r--r-- root/root 12488 2001-05-11 00:38:36 joe-2.9.8/COPYING ... -rw-r--r-- root/root 25647 2003-05-05 03:15:32 joe-2.9.8/Makefile.in -rwxr-xr-x root/root 264207 2003-05-05 03:15:34 joe-2.9.8/configure [herrold@centos-4 patching-example]$ [herrold@centos-4 patching-example]$ tar zxvf joe-2.9.8.tar.gz joe-2.9.8/ joe-2.9.8/acinclude.m4 ... joe-2.9.8/Makefile.in joe-2.9.8/configure [herrold@centos-4 patching-example]$ mv joe-2.9.8 joe-2.9.8-pristine [herrold@centos-4 patching-example]$ tar zxvf joe-2.9.8.tar.gz joe-2.9.8/ joe-2.9.8/acinclude.m4 ... joe-2.9.8/Makefile.in joe-2.9.8/configure [herrold@centos-4 patching-example]$
We find the relevant file, using 'grep', and edit it (using 'sed', so that the edit is visible) in the non-pristine tree. Then we verify the patch is done:
[herrold@centos-4 patching-example]$ cd joe-2.9.8 [herrold@centos-4 joe-2.9.8]$ grep Joe *.c | grep Copyright main.c: msgnw(((BASE *)lastw(maint)->object)->parent, "\\i** Joe's Own Editor v" VERSION " ** Copyright (C) 2003 **\\i"); [herrold@centos-4 joe-2.9.8]$ sed -i -e "s/Joe's Own/Big Joe's/" main.c [herrold@centos-4 joe-2.9.8]$ grep Joe *.c | grep Copyright main.c: msgnw(((BASE *)lastw(maint)->object)->parent, "\\i** Big Joe's Editor v" VERSION " ** Copyright (C) 2003 **\\i"); [herrold@centos-4 joe-2.9.8]$
We can verify that it works; we need to override the location of the 'joerc' file in the configure stage, to 'cheat' and use the previously installed one in our testing.
[herrold@centos-4 joe-2.9.8]$ ./configure --sysconfdir=/etc/joe [herrold@centos-4 joe-2.9.8]$ make [herrold@centos-4 joe-2.9.8]$ ./joe
Which returns:
  I A Unnamed y x Row 1 Col 1 6:39 Ctrl-K H for help ... snip ... ** Big Joe's Editor v2.9.8 ** Copyright (C) 2003 **  
so we know the patch seems to work as we expect it to. Now we clean up for doing the 'diff', look at it, and place a copy where a 'rpmbuild -ba' can use it:
[herrold@centos-4 joe-2.9.8]$ make distclean test -z "joe termidx" || rm -f joe termidx rm -f *.o core *.core rm -f *.tab.c rm -rf ./.deps rm -f Makefile joe.1 joerc jmacsrc jstarrc rjoerc jpicorc rm -f autoconf.h stamp-h1 rm -f *~ rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags rm -f config.status config.cache config.log configure.lineno [herrold@centos-4 joe-2.9.8]$ cd .. [herrold@centos-4 patching-example]$ diff -u joe-2.9.8-pristine joe-2.9.8 Common subdirectories: joe-2.9.8-pristine/docs and joe-2.9.8/docs diff -u joe-2.9.8-pristine/main.c joe-2.9.8/main.c --- joe-2.9.8-pristine/main.c 2003-05-05 03:14:25.000000000 -0400 +++ joe-2.9.8/main.c 2007-07-02 18:26:11.000000000 -0400 @@ -3,7 +3,7 @@ * Copyright * (C) 1992 Joseph H. Allen * - * This file is part of JOE (Joe's Own Editor) + * This file is part of JOE (Big Joe's Editor) */ #include "config.h" #include "types.h" @@ -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** Big Joe's Editor v" VERSION " ** Copyright (C) 2003 **\\i"); edloop(0); vclose(vmem); nclose(n); [herrold@centos-4 patching-example]$ diff -u joe-2.9.8-pristine joe-2.9.8 > joe-bigjoe.patch [herrold@centos-4 patching-example]$ cp joe-bigjoe.patch ~/rpmbuild/SOURCES/ [herrold@centos-4 patching-example]$
We also make a pristine copy of the local .spec file,
[herrold@centos-4 patching-example]$ cp joe-2.9.8.spec joe-2.9.8.spec-orig
and then edit the test copy to reflect the patch. Our patches bump the Release number, adding a 'brand' for packagings we have done, adds the patch file name, adds the patch process itself, and updates the Changelog:
[herrold@centos-4 patching-example]$ diff -u joe-2.9.8.spec-orig joe-2.9.8.spec --- joe-2.9.8.spec-orig 2007-07-02 18:45:43.000000000 -0400 +++ joe-2.9.8.spec 2007-07-02 18:47:33.000000000 -0400 @@ -3,7 +3,7 @@ Summary: An easy to use, modeless text editor. Name: joe Version: 2.9.8 -Release: 4 +Release: 5orc License: GPL Group: Applications/Editors Source: http://prdownloads.sourceforge.net/joe-editor/joe-%{version}.tar.gz @@ -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-bigjoe.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 @@ -56,6 +58,10 @@ rm -rf $RPM_BUILD_ROOT %changelog +* Mon Jul 2 2007 R P Herrold 2.9.8-5orc +- patch for SRPM demo example changes; see: + http://www.owlriver.com/tips/patching_srpms/ + * Tue Jun 17 2003 Lon Hohberger 2.9.8-4 - Fixed incomplete patch for #80657 [herrold@centos-4 patching-example]$
We rebuild from the local patched .spec file, and then test the result.
[herrold@centos-4 patching-example]$ rpmbuild -ba joe-2.9.8.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.65416 + umask 022 + cd /home/herrold/rpmbuild/BUILD ... snip ... Wrote: /home/herrold/rpmbuild/SRPMS/joe-2.9.8-5orc.src.rpm Wrote: /home/herrold/rpmbuild/RPMS/i386/joe-2.9.8-5orc.i386.rpm Wrote: /home/herrold/rpmbuild/RPMS/i386/joe-debuginfo-2.9.8-5orc.i386.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.78146 + umask 022 + cd /home/herrold/rpmbuild/BUILD + cd joe-2.9.8 + rm -rf /var/tmp/joe-2.9.8-root + exit 0 [herrold@centos-4 patching-example]$ sudo rpm -e joe Password: [herrold@centos-4 patching-example]$ sudo rpm -U /home/herrold/rpmbuild/RPMS/i386/joe-2.9.8-5orc.i386.rpm [herrold@centos-4 patching-example]$ rpm -q joe joe-2.9.8-5orc [herrold@centos-4 patching-example]$
and we get the same result as above in our testing (note from the timestamp that we are running the packaged version).
  [herrold@centos-4 patching-example]$ rpm -qi joe Name : joe Relocations: (not relocatable) Version : 2.9.8 Vendor: (none) Release : 5orc Build Date: Mon 02 Jul 2007 06:48:16 PM EDT Install Date: Mon 02 Jul 2007 06:48:50 PM EDT Build Host: centos-4.first.lan Group : Applications/Editors Source RPM: joe-2.9.8-5orc.src.rpm Size : 284835 License: GPL Signature : (none) URL : http://sourceforge.net/projects/joe-editor/ Summary : An easy to use, modeless text editor. Description : Joe is a powerful, easy to use, modeless text editor. It uses the same WordStar keybindings used in Borland's development environment. [herrold@centos-4 patching-example]$ joe IW Unnamed Row 1 Col 1 6:56 Ctrl-K H for help ... snip ... ** Big Joe's Editor v2.9.8 ** Copyright (C) 2003 **  
Once we are done, we can clean up and get back to a current 'joe' version in the customary fashion with 'yum'.

Thanks to our reviewer, MSamir <my007ms yahoo com>, our friend in Cairo, for corrections and suggestions for clarification.

We make this available for non-commercial and individual use. Please respect our copyright, and consider contacting us for all your Open Source and *nix design, architect / systems analysis, and administration needs.

See also:
Building Source RPM as non-root under CentOS
Creating Quality RPMs Guru Labs - Courseware discussion (oldrpm.org archival PDF copy)
Bero's Ark Linux .spec file packaging introduction
Old RPM website
New RPM5 website


Up More Tips

Back to Top Page
[legal] [ no spam policy ] [ Copyright] © 2008 Owl River Company
All rights reserved.

Last modified: Mon, 22 Nov 2010 15:06:48 -0500