Product SiteDocumentation Site

8.2. Building RPMs

In previous chapters, just about everything you want to do with RPMs is accomplished with the rpm command. Building RPMs is one exception. Just about everything you want to do to build an RPM is done by the rpmbuild command, often with a single command.
Older RPM manuals refer to using the –b option to the rpm command to create RPMs. Don’t use that option. Instead, always use the rpmbuild command. The reason for this change is that starting with version 4.1, RPM no longer maps the rpm -b command to the real command, rpmbuild.
When building RPMs, go through the following steps:
1.Set up the directory structure.
2.Place the sources in the right directory.
3.Create a spec file that tells the rpmbuild command what to do.
4.Build the source and binary RPMs.
The following section provide details for these steps.

8.2.1. Setting up the directory structure

The RPM system expects five directories, as listed in Table 9-1.
Table 9-1 RPM directories
The rpmbuild command builds software in this directory.
The rpmbuild command stores binary RPMs it creates in this directory.
You should put the sources for the application in this directory.
You should place the spec file for each RPM you plan to make in this directory.
The rpmbuild command places source RPMs in this directory.
The RPMS directory usually has a number of architecture-specific subdirectories, such as the following (on an Intel architecture system):
$ ls RPMS
By default, Red Hat Linux systems expect RPMs to be built in the /usr/src/redhat directory.
This directory is obviously specific to Red Hat Linux. On other Linux distributions, you'll likely see other directories.
Within the /usr/src/redhat directory, you’ll see the subdirectories listed in Table 9-1, as follows:
$ ls /usr/src/redhat
At first, it seems rather odd to be using a system directory to build RPMs. But remember that the RPM system was originally built to create Linux distributions. You can also change the default directories by modifying your rpmrc settings.
Cross Reference
See Chapter 20, Customizing RPM Behavior for more on the use of the rpmrc settings.
For now, it is easiest to just change to the /usr/src/redhat directory and work from this location. To start, you will need to change ownership or permissions on these files so you can build RPMs while logged in as a normal user.
Do not build RPMs while logged in as root. Mistakes in building packages can have serious consequences if you are logged in as root.
To build RPMs, you really need only two things:
*Your sources in the SOURCES directory
*Your spec file in the SPECS directory