ClearFoundation

Developer Packaging Building An RPM - The Basics - 5.x

Building An RPM - The Basics - 5.x

Overview

If you have never built an RPM or need to know about the ClearOS package build environment, then this document is for you. The information provided here gives you an overview of what is needed to manually build your own RPMs. Though ClearOS uses a build system for creating RPMs, it is still worthwhile learning the manual procedure described here.

Install the Build Tools

Before getting underway, the first thing you need to do is install a ClearOS system. Thanks to the age of virtual machines, you no longer need dedicated hardware. Go ahead and install ClearOS on your favorite virtual machine (or dedicated hardware) and get it up and running.

Once you have the system up and running, you can install a basic set of developer tools with the following command:

 yum groupinstall "Development Tools"

Create a User Account

Since it is a bad idea to build packages with the root account, create a separate user account. To avoid some chicken and egg scenarios with LDAP, you can create a plain old /etc/passwd (non-LDAP) account with following command:

useradd -s /bin/bash -u 500 david

The -u 500 flag ensures that you are using a user ID that will not interfere with those in LDAP. On a ClearOS system, the user ID range from 500-999 is reserved for non-LDAP user accounts. Please make sure you pick a user ID that is not already in use (in other words, if you add another user, set the ID to 501). If you are curious, more information on ClearOS ID ranges is here.

Once you have the account created, you can create a password for it:

passwd david

Logout of your root shell and then login with your new build account.

Create the RPM Directory Structure

Before you start building RPMs, you need to create a directory structure for the build environment. The RPM build system uses the directories described in the following table:

DirectoryDescription
BUILDOutput for the build process
RPMS/*Where the build puts the RPMs
SOURCESSource code and patches needed to build an RPM
SPECSRPM spec files
SRPMSWhere build puts the source RPMs

To create this RPM structure in your ~/localrpms directory, run the following:

cd ~
mkdir -p --verbose ~/localrpms/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mkdir -p --verbose ~/localrpms/RPMS/{i386,i686,x86_64,noarch}
echo "%_topdir $HOME/localrpms" >> ~/.rpmmacros
echo "%dist .mydist" >> ~/.rpmmacros

Make sure you change the mydist tag to something that distinguishes your rpms. When you are done with your first RPM build, you will see the dist tag in the filename, for example myapp-1.0-1.1.mydist.i386.rpm.

Prepare the Source Code

With the directory structure ready to go, it is now time to prepare the source code. To get the ball rolling, we are going to start with a source RPM. In our example, we are using the dnsmasq software since it is small and straightforward.

rpm -Uvh http://download.clearfoundation.com/clearos/enterprise/sources/5.x/dnsmasq-2.49-1.1.v5.src.rpm

You can ignore those warnings about user/groups not existing. Installing the source RPM added three files to the RPM build directory:

  • localrpms/SPECS/dnsmasq.spec
  • localrpms/SOURCES/dnsmasq.init
  • localrpms/SOURCES/dnsmasq-2.49.tar.gz

In more complex packages, you will see patches and other helper files in the SOURCES directory. In our example, we only have the single dnsmasq tar-zip along with a ClearOS compatible start/stop script (/etc/rc.d/init.d/dnsmasq). Of course, you don't need a source RPM to put these files in the SPECS and SOURCES directories. We simply used a source RPM for convenience.

Build the RPM

Now it is time to actually build the rpm!

 rpmbuild -ba localrpms/SPECS/dnsmasq.spec

Uh-oh. Something went wrong:

error: Failed build dependencies:
  dbus-devel is needed by dnsmasq-2.49-1.1.mydist.i386

The dnsmasq build requires the dbus-devel package. You will find that you may need to install other *-devel packages to build an RPM. As root, go ahead and install dbus-devel:

su -c 'yum install dbus-devel' -

Then re-rerun the rpmbuild command:

rpmbuild -ba localrpms/SPECS/dnsmasq.spec

If all goes well, you should get both your RPM and source RPM files built:

  • localrpms/SRPMS/dnsmasq-2.49-1.1.mydist.src.rpm
  • localrpms/RPMS/i386/dnsmasq-2.49-1.1.mydist.i386.rpm
  • localrpms/RPMS/i386/dnsmasq-debuginfo-2.49-1.1.mydist.i386.rpm

Next Steps

If this is your first time building an RPM, then you have just started a journey of learning and discovery! The Fedora RPM Guide is a good place to go for a lot more detail. Also take a look at the links listed at the end of this document. From spec files, to good 64-bit habits, to cross-distribution support – there is quite a bit of ground to cover.

Once you have the hang of it, you can start to delve into the ClearFoundation build system.

Related Links



Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
Video demonstrations - Copyright © 2010 ClearCenter Corporation