Building RPMS

Sometimes you want to customize an existing rpm. For example, in 2017, firefox on Fedora and some others requires pulseaudio. This can be changed by rebuilding its rpm.

This is a very simplified quick start to setting up rpmbuilds. For more detail about working with spec files, see the Fedora project's article.

There are now tools that make it easier than it used to be. Old articles talk about creating your $HOME/.rpmacros and build tree, but newer tools automate this. I'm going to be using Fedora as an example, but if using CentOS, just substitute yum for dnf, unless specified.

First we need some basic build tools. I find that, on a minimal install (which sometimes doesn't include tar and bzip2) that the following is (usually) sufficient.
dnf -y install gcc gcc-c++ make automake kernel-devel tar bzip2 rpm-build
rpmdevtools dnf-plugins-core mock

The Fedora project's page says to add your user to mock. You can skip this, but to avoid errors later (when installing srpms), add a mockbuild user. The mockbuild user doesn't need a password.
sudo useradd mockbuild

Next create the build environment.

Now we can get the srpm. We'll use firefox for this example, since, as mentioned many are displeased with the decision to use pulse, but for now, at least, it's easy to rebuild to use alsa.

For CentOS install yum-utils with yum install yum-utils. To get the source rpm there are various, mostly untested by me, suggestions, such as creating an srpm repo (which some people find to not work). I've only done this on CentOS-6 and 7 on occasion, so I've just googled for the srpm and downloaded it.

With Fedora and the dnf core plugin, it's easy.
dnf download firefox --source --destdir ~/rpmbuild/SOURCES

If you cd to ~/rpmbuild/SOURCES, you'll see a firefox srpm file. Install it with rpm -ivh firefox-<version>.srpm, or possibly .src.rpm. (This is why we created the mockbuild user, if there is no such user, one gets errors about can't find mockbuild, using root.)

Once you've installed the source rpm, you will have a firefox.spec in ~/rpmbuild/SPECS. As of June 2017, if you look at the spec file, you'll see
%define alsa_backend      0

Change the 0 to a 1 so that it reads
%define alsa_backend      1

Check for dependencies. In Fedora, while in the SPECS directory
sudo dnf builddep firefox.spec

In CentOS it's yum-builddep. This will pull in any packages that will be necessary for the build. You may see some pulseaudio-libs, but it won't pull in pulseaudio itself. Once it's pulled in everything it needs, you can build the rpm. Still in the SPECS directory
rpmbuild -ba firefox.spec

In the case of firefox, this will take awhile. When it completes, it will create a ~/rpmbuild/RPM/x86_64/firefox-<version>.rpm. It will also create a few other rpms but you don't need them. In the case of firefox, I just remove the old one with sudo dnf remove firefox, which, on my setup, also removed mozilla-filesystem. Using dnf on your rpm will pull it back in though.
sudo dnf -y install ~/rmpbuild/RPMS/x86_64/firefox-<version>.rpm. 

(If mozilla-filesystem was removed, this will replace it.) You can now enjoy sound in firefox without pulse audio.