head 1.1; branch 1.1.1; access ; symbols MAXIMUM_RPM_1_0:1.1.1.1 VENDOR:1.1.1; locks ; strict; comment @# @; 1.1 date 2001.08.28.12.07.09; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.08.28.12.07.09; author rse; state Exp; branches ; next ; desc @@ 1.1 log @Initial revision @ text @ 11. The Basics of Developing With RPM Subsections

   
11. The Basics of Developing With RPM

Now that we've seen the design philosophy of RPM, let's look at the nuts and bolts of RPM's build process. Building a package is similar to compiling code - there are inputs, an engine that does the dirty work, and outputs.

   
11.1 The Inputs

There are three different kinds of inputs that are used to drive RPM's build process. Two of the three inputs are required, and the third, strictly speaking, is optional. But unless you're packaging your own code, chances are you'll need it.

   
11.1.1 The Sources

First and foremost, are the sources. After all, without them, there wouldn't be much to build! In the case of packaging someone else's software, the sources should be kept as the author distributed them, which usually means a compressed tar file. RPM can handle other archive formats, but a bit more up-front effort is required.

In any case, you should not modify the sources used in the package building process. If you're a third-party package builder, that means the sources should be just the way you got them from the author's FTP site. If it's your own software, the choice is up to you, but you should consider starting with your mainstream sources.  

   
11.1.2 The Patches

Why all the emphasis on unmodified sources? Because RPM gives you the ability to automatically apply patches to them. Usually, the nature of these patches falls into one of the following categories:

   
11.1.2.1 Creating the Patches

While it might sound a bit daunting to take into account the types of patches outlined above, it's really quite simple. Here's how it's done:

  1. Unpack the sources.

  2. Rename the top-level directory. Make it end with ``.orig'', for example.

  3. Unpack the sources again, leaving the top-level directory name unchanged.

The source tree that you created the second time will be the one you'll use to get the software to build.

If the software builds with no changes required, that's great - you won't need a patch. But if you had to make any changes, you'll have to create a set of patches. To do so, simply clean the source directory of any binaries. Then, issue a recursive diff command to compare the source tree you used for the build, against the original, unmodified source tree. It's as easy as that!   

   
11.1.3 The Spec File

The spec file is at the heart of RPM's packaging building process. Similar in concept to a makefile, it contains information required by RPM to build the package, as well as instructions telling RPM how to build it. The spec file also dictates exactly what files are a part of the package, and where they should be installed.

As you might imagine, with this many responsibilities, the spec file format can be a bit complex. However, it's broken into several sections, making it easier to handle. All told, there are eight sections:

   
11.1.3.0.1 The Preamble

The preamble contains information that will be displayed when users request information about the package. This would include a description of the package's function, the version number of the software, and so on. Also contained in the preamble are lines identifying sources, patches, and even an icon to be used if the package is manipulated by graphical interface.  

11.1.3.0.2 The Prep Section

 

The prep section is where the actual work of building a package starts. As the name implies, this section is where the necessary preparations are made prior to the actual building of the software. In general, if anything needs to be done to the sources prior to building the software, it needs to happen in the prep section. Usually, this boils down to unpacking the sources.

The contents of this section are an ordinary shell script. However, RPM does provide two macros to make life easier. One macro can unpack a compressed tar file and cd into the source directory. The other macro easily applies patches to the unpacked sources.  

11.1.3.0.3 The Build Section

 

Like the prep section, the build section consists of a shell script. As you might guess, this section is used to perform whatever commands are required to actually compile the sources. This section could consist of a single make command, or be more complex if the build process requires it. Since most software is built today using make, there are no macros available in this section.  

11.1.3.0.4 The Install Section

 

Also containing a shell script, the install section is used to perform the commands required to actually install the software. If the software's author added an install target in the makefile, this section might only consist of a make install command. Otherwise, you'll need to add the usual assortment of cp, mv, or install commands to get the job done.  

   
11.1.3.0.5 Install and Uninstall Scripts

While the previous sections contained either information required by RPM to build the package, or the actual commands to do the deed, this section is different. It consists of scripts that will be run, on the user's system, when the package is actually installed or removed. RPM can execute a script:

One example of when this capability would be required is when a package contains shared libraries. In this case, ldconfig would need to be run after the package is installed or erased. As another example, if a package contains a shell, the file /etc/shells would need to be updated appropriately when the package was installed or erased.

11.1.3.0.6 The Verify Script

This is another script that is executed on the user's system. It is executed when RPM verifies the package's proper installation. While RPM does most of the work verifying packages, this script can be used to verify aspects of the package that are beyond RPM's capabilities.

11.1.3.0.7 The Clean Section

Another script that can be present is a script that can clean things up after the build. This script is rarely used, since RPM normally does a good job of clean-up in most build environments.  

11.1.3.0.8 The File List

 

The last section consists of a list of files that will comprise the package. Additionally, a number of macros can be used to control file attributes when installed, as well as to denote which files are documentation, and which contain configuration information. The file list is very important -- if it is missing, no package will be built.    

   
11.2 The Engine: RPM

At the center of the action is RPM. It performs a number of steps during the build process:

By using different options on the RPM command line, the build process can be stopped at any of the steps above. This makes the initial building of a package that much easier, as it is then possible to see whether each step completed successfully before continuing on to the next step.  

   
11.3 The Outputs

The end product of this entire process is a source package file and a binary package file.

   
11.3.1 The Source Package File

The source package file is a specially formatted archive that contains the following files:

Since the source package contains everything needed to create the binary package, the source package, and provide the original sources, it's a great way to distribute source code. As mentioned earlier, it's also a great way to archive all the information needed to rebuild a particular version of the package.  

   
11.3.2 The Binary RPM

The binary package file is the one part of the entire RPM building process that is most visible to the user. It contains the files that comprise the application, along with any additional information needed to install and erase it. The binary package file is where the ``rubber hits the road.''   

11.4 And Now...

Now that we've seen, in broad brush terms, the way RPM builds packages, let's take a look at an actual build. The next chapter will do just that, showing how simple it can be to build a package.  



Ralf S. Engelschall 2000-12-15
@ 1.1.1.1 log @Import book 'Maximum RPM' by Ed Bailey, version 1.0 @ text @@