Packaging RPMs
Packaging RPMs
Introduction
The Linux operating system we have deployed most widely is Scientific Linux (SL), which is a respin of Red Hat Enterprise Linux (RHEL). Software for RHEL, and respins thereof, is packaged for distribution and installation in the Red Hat Package Manager package format. These packages are known as RPMs. Prerequisits
You will need access to a host running Scientific Linux or a Red Hat Enterprise Linux equivalent. The currently recommended distribution is SL 6x or SL 7x. Your development environment will need these packages installed: rpm-build rpmdevtools rpmlint gcc-c++ If you are developing and packaging software with git and github, you will also need: git It will create the non-privileged user and group bob:builder. It will create the following directories: "/home/bob/{Development,Documents,Downloads}". RPMs should be build by a non-privileged user, such as yourself, not root.
Setting Up the RPM Build Environment
To setup the build environment, run the following command:
[user@host ~]$ rpmdev-setuptree
This will create a directory in your home directory with the following structure:
[user@host ~]$ ~/rpmbuild/
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
Open the file /home/$user/.rpmmacros in vim and find a line with 'echo "-j3";' in it. Change the number after the letter 'j' to the number of cpu cores available on the build host + 1. This will paralellise the build process and thus accelerate it.
Setup your global git configuration:
[user@host ~]$ git config --global user.name "Your Name" [user@host ~]$ git config --global user.email "your.name@example.com" [user@host ~]$ git config --global color.ui "auto" [user@host ~]$ git config --global core.editor "vim" [user@host ~]$ git config --global alias.st "status" [user@host ~]$ git config --global alias.br "branch" [user@host ~]$ git config --global alias.cm "commit" [user@host ~]$ git config --global alias.co "checkout"
Clone a github project and configure 'remotes' for development:
[user@host ~]$ cd ~/Development [user@host ~]$ git clone https://github.com/$YOUR_GITHUB_USERNAME/$YOUR_FORK.git [user@host ~]$ git remote add upstream https://github.com/$ORIGINAL_GITHUB_OWNER/$ORIGINAL_REPOSITORY.git [user@host ~]$ git remote set-url origin git@github.com:$YOUR_GITHUB_USERNAME/$YOUR_FORK.git
You need to use ssh keys to push to github, so make sure this is configured (this assumes your github ssh keys are present in /home/$user/.ssh/ and are called github-id_rsa{,.pub}) in ~/.ssh/config:
Host github.com
Hostname ssh.github.com Port 443 IdentityFile ~/.ssh/id_rsa User $YOUR_GITHUB_USERNAME
Copy the source tarball (including any patch files) and spec file from your code development environment to your RPM development environment:
[user@host ~]$ cp ~/Development/$project/$project-$version.tar.gz ~/rpmbuild/SOURCES/ [user@host ~]$ cp ~/Development/$project/$project-$version.spec ~/rpmbuild/SPECS/
To build the RPMs, run the following command:
[user@host ~]$ rpmbuild -ba ~/rpmbuild/SPECS/$project-$version.spec
The -ba option will build binary (and noarch, if present) RPMs after doing the %prep, %build, and %install stages in the spec file, it will also build an SRPM. Please upload the SRPM as well as the binary RPMs to install server when you create/update your repositories. This is good practice and is essential if someone else needs to repeat your work. Uploading Your Packages to our Repository Server
The man page for rpmbuild is useful and concise.
The reference manual for building RPMs is: "Maximum RPM: Taking the Red Hat Package Manager to the Limit", Auth: Edward C. Bailey, Pub: Red Hat Software, 2000, and is available online via this web-link.