Setting up for Building RPM

Before you can run rpmbuild, you need to setup a directory tree and a .rpmmacros file.

Prerequisites

You'll need the rpmbuild tool itself and a redhat config package which enables the generation of debuginfo packages:

sudo yum install rpm-build redhat-rpm-config

Setup directory tree

You may already have one in /usr/src/RPM, but as rebuilding packages as root is evil, we recommend that you create one in a place where your normal user account allows you to write, such as your home directory. This build tree should have the following structure:

rpm
|-- BUILD
|-- RPMS
|-- SOURCES
|-- SPECS
|-- SRPMS
`-- tmp

The following command should build what you need:

mkdir -p ${HOME}/rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}

Setup rpmbuild configuration file

Now you need to do some rpm configuration. A simple ~/.rpmmacros with the following contents should be enough:

cat > ~/.rpmmacros <<EOF
%_topdir        %(echo ${HOME}/rpm)
%_tmppath       %{_topdir}/tmp

%packager       Firstname Lastname <your.address@here>

# Have built RPMs land in RPMS/ instead of RPMS/<arch>/
%_rpmfilename  %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
EOF

Make sure to replace the %packager fields with your actual name and email address.

Testing 1 2 3