Building patched SRPM software

Free software has the great advantage of allowing you to modify it. This however is done rarely because of the perceived difficulty of setting up the build environment of the specific software you want to modify.

With this small guide I want to show that it is actually extremely easy to modify and install a new version of a software that is packaged in Fedora.

If the developer of a package you use decided to change things in a way you don’t like you can use this procedure to make the software do what you want it to do.

Setup your environment

The first step is to configure rpm for your user:

mkdir -p ~/Overlays/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

echo '%_topdir %(echo $HOME)/Overlays/rpmbuild' > ~/.rpmmacros

Then install the basic tools to build:

sudo yum install rpm-build redhat-rpm-config yum-utils

You will probably also need to install some other stuff:

sudo yum install make gcc

For every package you have you will keep track of patches.

You need to create a folder like this to store them:

mkdir ~/Overlays/patches

Obtain the source package and modify it

To download the source package you can do as follows:

yumdownloader --source package-name

Now you can install (as your user) the sources:

rpm -i package-name-X.X.X-X.fcXX.src.rpm

The rpm will be unpacked to ~/Overlays/rpmbuild.

Next you need to download all the dependencies:

cd ~/Overlays/rpmbuild/SPECS && sudo yum-builddep package-name.spec

You can now uncompress the sources as follows:

cd ~/Overlays/rpmbuild/SPECS && rpmbuild -bp package-name.spec

The sources unpacked sources will be in ~/Overlays/rpmbuild/BUILD.

You can now prepare to overlay the package:

cd ~/Overlays/rpmbuild/BUILD/package-name-X.X.X

git init .

git add .

git commit -a -q -m "baseline"

Now you are ready to do your modifications. After you are done just commit them as normal commits in git:

git add .
git commit -m "My customizations"

Once you are done you must backup your changes (the BUILD directory is cleaned after each build) :

git format-patch HEAD^
mkdir ~/Overlays/patches/package-name-X.X.X-X.overlay/
cp *.patch ~/Overlays/patches/package-name-X.X.X-X.overlay/

And you need to adapt the spec file adding these lines1:

Release: XXXX.overlay


%setup -q
git init
git add .
git commit -a -q -m "%{version} baseline."
git am ~/Overlays/patches/%{name}-%{version}-%{release}/*.patch

You can also back up the new spec file:

cp package-name.spec ~/Overlays/patches/package-name-X.X.X-X.overlay/

Building the package

You are now finally ready to build the new package:

rpmbuild -ba mypackage.spec

If you re-run the unpacking command rpmbuild -bp you will automatically have a git repository available to work on.

Installing the modified version

To install the modified version is straightforward:

sudo dnf reinstall ~/Overlays/rpmbuild/RPMS/x86_64/*.x86_64.rpm
  1. This approach is inspired form this post