How to unpack, modify, rebuild and install a SRPM
What I do, as the ROOT user:
Install the SRPM as you would any other package (
rpm --install [source-rpm-filename]
)Examine
/root/rpmbuild/SPECS
directory and find the specs file that matches your packagerpmbuild -bb /root/rpmbuild/SPECS/[found-filename]
The resulting binary packages are then located in the /root/rpmbuild/RPMS/
directory which are ready to be installed via the standard rpm --install
command.
NOTE: This just builds what is in the standard binary package. I am posting this answering the specific question, not how to go about making changes to the source and generating new packages.
To do the modifications, you could either provide patches as input and changing the SPECS file....or you could replace the standard *.tar.bz2
located in /root/rpmbuild/SOURCES
with your own with the change and then do the build as described above.
Beware you might have to change the SPECS package to make it work (usually by pulling out the patching, and changing some filenames that is programmed by the SPECS file).
EDIT
It seems building rpms as root is a bad practice (source). It works fine as a non-root user.
Step by step instructions to add a patch (from here):
- Copy your patch to
rpmbuild/SOURCES
. - Edit the
rpmbuild/SPECS/package.spec
and add aPatch0: mypatch.patch
right after theSource0: ...
line. - After the
%setup ...
line add a%patch0 -p1
line
Now it will build normally, ie. with: rpmbuild -ba SPECS/package.spec
OpenSSL Package Rebuild CentOS 6.4 is a detailed example of an SRPM package rebuild.
The above example uses Mock - the Jedi Light Saber of package builders.
Mock was created to reliably populate a chroot, then rebuild a package in that chroot.
For more, see http://fedoraproject.org/wiki/Projects/Mock
In the example mock is used 3 times - once to "unpack" the package, then to rebuild the .src.rpm, and finally to create the .rpm.