Manually Prepare the RPM Building Environment

About three years ago I had posted a general guide on how to create RPM packages. According to that guide the RPM building environment was prepared using the handy utility rpmdev-setuptree (part of the rpmdevtools package in Fedora). This post describes the manual preparation of the RPM building environment.

As an unprivileged user create the following directory tree:

mkdir ~/rpmbuild \
    ~/rpmbuild/BUILD \
    ~/rpmbuild/RPMS \
    ~/rpmbuild/SOURCES \
    ~/rpmbuild/SPECS \
    ~/rpmbuild/SRPMS

Now, create the 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

The %_topdir macro is set to the path of the root directory of your RPM building environment, /home/[user]/rpmbuild in this case.

The %_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, the smp flags are set to -j3.

The %__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.

All macros that are set in ~/.rpmmacros override the system-wide macros that have been set in other locations. To check which paths are checked for macro files, enter the following command:

rpm --showrc | grep macrofiles

The following command shows the current configuration for RPM building:

rpm --showrc

All the available macros can be found in /usr/lib/rpm/macros.

Manually Prepare the RPM Building Environment by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2009 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of the G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.

2 responses on “Manually Prepare the RPM Building Environment

  1. MikeT Permalink →

    Thanks for the explaination, very helpful.

    A “short cut” you might want to consider is EPM. (http://www.epmhome.org/)

    I’ve used this software to quickly build a package across different platforms using the same basic packaging files. In my case, I was building RPMs for Red hat Linux, from V7 to RHEL 4, 32 bit and 64 bit as well as some Solaris installations using all the same files with the only difference being the output location (and files) of the compiled software and the built package.

    Thanks for your time.

    1. George Notaras Post authorPermalink →

      Hi, I had never heard of it, but looks very interesting. I’ll check it out.

      Thanks for your feedback.