Prepare the RPM Building Environment

Some days ago, I posted some examples on the common usage of RPM. Now, this post describes a manual preparation of a RPM building environment. With the help of this environment, you can generate upated RPM packages and patch your RPM-based system from source code.

Before this configuration, please make sure you have these packages installed already:

make, GCC, rpm-build, redhat-rpm-config

If they havn’t installed yet, you can start the installation by yum like this “yum install make“. After finished, run the “rpmbuild –showrc” or the more terse “rpmbuild –version command” to check that it’s OK. Then let’s start the configuration.

As an unprivileged user create the following directories:


These directories are the exact working place, which are actually alternative ones that are different from system default path /usr/src/redhat.

Then, create a new file ~/.rpmmacros and put the following basic macros in it:

%_topdir      %(echo $HOME)/rpmbuild
%_smp_mflags  -j3
%__arch_install_post   /usr/lib/rpm/check-rpaths   /usr/lib/rpm/check-buildroot

All macros that are set in ~/.rpmmacros override the system-wide macros that have been set in other locations. The meaning of these directives are listed below:
%_topdir macro is the path of the root directory of your RPM building environment, ~/rpmbuild in this case.

%_smp_mflags macro usually contains only the -j (–jobs) option for the make command, which defines the number of jobs (make commands) that may run simultaneously. Usually, this is set to the number of CPU cores plus one. So, on a dual core CPU, this flags are set to -j3.

%__arch_install_post macro contains various checks that should be run on the files in the BUILDROOT location. I trust Fedora guys and use the defaults check-rpaths and check-buildroot on Fedora and CentOS. This macro is optional.

To check which paths are checked for macro files, enter the following command:

rpm --showrc | grep macrofiles

For the whole current configuration for RPM building, run “rpm –showrc“. All the available macros can be found in /usr/lib/rpm/macros. From that point you’re ready to go. Simply install the src.rpm as normal and the files will be unpacked in your new build tree.

It’s very helpful for you to keep your RHEL installations up-to-date without paying to Redhat, as RHSA releases all updated source code in SRPM package.

Share this post

Post Comment