Product SiteDocumentation Site

Chapter 9. Working with Spec Files

9.1. Reading Spec Files
9.2. Writing Spec Files
9.2.1. Comments
9.2.2. Storing spec files on disk
9.3. Defining Package Information
9.3.1. Describing the package
9.3.2. Setting build locations
9.3.3. Naming source files
9.3.4. Naming patches
9.4. Controlling the Build
9.4.1. Preparing for the build
9.4.2. Building the software
9.4.3. Installing the software
9.4.4. Cleaning up after the build
9.4.5. Defining installation scripts
9.5. Filling the List of Files
9.5.1. Using wildcards
9.5.2. Naming directories of files
9.5.3. Marking files as documentation or configuration files
9.5.4. Setting file attributes
9.5.5. Verifying the %files section
9.5.6. Filling the list of files automatically
9.5.7. Handling RPM build errors for unpackaged files
9.6. Adding Change Log Entries
9.7. Defining Spec File Macros
9.7.1. Built-in macros
9.7.2. Spec file-specific macros
9.7.3. Defining new macros
9.7.4. Specifying parameters to macros
9.8. Creating XML Spec Files
9.9. Summary
This chapter covers:
The previous chapter introduces the concepts of how to build RPMs, and briefly covered the spec file, which controls how RPM packages are built and installed. This chapter delves into how to create spec files and the next chapter covers advanced spec file topics such as using conditional commands and making relocatable packages.
A spec file defines all the commands and values that are required for creating a package, everything from the name and version number to the actual commands used to build the program you are packaging.
This chapter covers the spec file syntax and how to write spec files. In goes in depth into defining information about your package, controlling how the software will be built, defining what exactly should go into the package, and customizing your build with RPM macros.

9.1. Reading Spec Files

The first step to learning more about spec files is to read through some of the huge number of spec files for the source RPMs that come with your Linux distribution. Looking at these files will show two things right away:
*You will see that the spec file syntax is not really as complicated as it appears.
*You will see how many others have solved problems similar to those you need to solve.
I’ve used real-world examples throughout this book, to show how the RPMs you need to deal with actually work. Some of the more interesting packages include anything that has a client and a server component, anything with networking or e-mail, and anything that installs a system service. All these types of packages solve problems that you will commonly face. Some useful spec files to look at are those for anonftp, telnet, vnc, and sendmail. To get these spec files, you need to install the corresponding source RPMs for each of these packages.
As you read through spec files, you’ll start to see common patterns in how packages are defined, named, the macros used, and common elements in the build section of the spec files. You’ll also see how network services are installed on Linux, as well as example install and uninstall scripts. The next section provide more information on the things to look for within spec files.
Furthermore, even with the plethora of options RPM provides, if you know shell scripting basics and something about how C programs are normally built, with configure scripts and make commands, you will find most spec files relatively easy to understand.
The following section go into the details of writing your own spec files. Keep your example spec files handy as you read through these section.