Building+an+RPM

=How to Build an RPM from source code=

Download and unpack the source package

 1. wget   2. untar -xvzf hello-2.7.tar.gz

Use the following command to create a directory structure under ~/rpmbuild

3. rpmdev-buildtree

The directory structure will contain these 5 folders:
 * **BUILD.** BUILD is used as scratch space to actually compile the software.
 * **RPMS.** RPMS contains the binary RPM that rpmbuild builds.
 * **SOURCES:** Contains the packages source tar ball.
 * **SPECS.** SPECS contains your spec file or files—one spec file per RPM you want to build.
 * **SRPMS.** SRPMS contains the source RPM built during the process.

This command will also create a sample SPEC file located in ~/rpmbuild/SPECS/ .spec.

Sample SPEC File

 * Summary**//: //
 * Name**//: //
 * Version**//: //
 * Release**//: //
 * Copyright**//: //
 * Group**//: //
 * Source**//: //
 * URL**//: //
 * Distribution**//: //
 * Vendor**//: //
 * Packager**//: //

%description <Brief description of the application>

The spec file will detail the neccessary information on how to build the package. Once the spec file is complete you can run the following commands to build the package:

Build package with Source and Binary RPMs

<span style="font-family: 'Courier New',Courier,monospace;"> rpmbuild -ba .spec

Build package with Source RPMs

<span style="font-family: 'Courier New',Courier,monospace;">rpmbuild -bs .spec

Source RPMs are stored here: ~/rpmbuild/SRPMS Binary RPMs are stored here: ~/rpmbuild/RPMS/

Testing RPMS Using rpmlint
<span style="font-family: 'Courier New',Courier,monospace;">1. # cd ~/rpmbuild/SPECS <span style="font-family: 'Courier New',Courier,monospace;">2. # rpmlint .spec ../RPMS/*///NAME//*.rpm ../SRPMS///NAME// *.

Rpmlint will tell you if there are warnings and/or errors with the spec file. The following link will detail common rpmlint errors and warnings that I have encountered and their solutions. rpmlint errors

Once you can run rpmlint with zero errors you are ready to test your package in mock.