RPM Build

References:

Build Environment Setup

Create a dedicated build user. Never build RPMs as root.

1
2
# useradd mockbuild
# passwd mockbuild

Install the required tools:

1
# dnf install @development-tools fedora-packager rpmdevtools wget

Login as the build user and set up the build tree:

1
$ rpmdev-setuptree

This creates the standard ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} directory structure.

Working with Existing Source Packages

Download an existing source RPM and install it into your build tree:

1
2
3
$ dnf download --source nginx
$ rpm -ivh nginx*.src.rpm
$ rm nginx*.src.rpm

Building from a Spec File

1
$ rpmbuild -ba ~/rpmbuild/SPECS/nginx.spec

You will likely encounter missing build dependencies. Install them as needed. The dnf builddep command can handle this automatically:

1
# dnf builddep ~/rpmbuild/SPECS/nginx.spec

Adding Custom Modules

When adding third-party modules to an existing package, you need to:

  1. Download the module source tarballs into ~/rpmbuild/SOURCES/
  2. Add Source entries to the spec file pointing to the tarballs
  3. Add any new BuildRequires and Requires dependencies
  4. Add %setup lines after the main %setup -q to extract the additional sources:
    • Use -T to prevent re-extracting the original tarball
    • Use -D to preserve existing directories
    • Use -a N where N is the source number
    • Use -n dirname to set the expected directory name
  5. Add --add-module=./module-dir flags to the ./configure invocation in the %build section

Signing Packages

RPM packages can be signed with a GPG key to verify their authenticity. First set the signing key in your ~/.rpmmacros:

%_signature gpg
%_gpg_name Your Name <[email protected]>

Then sign packages with:

1
$ rpm --addsign ~/rpmbuild/RPMS/x86_64/your-package.rpm