Product SiteDocumentation Site

9.2. Writing Spec Files

Spec files are text files containing RPM directives. These directives use a simple syntax of a tag name, a colon, and a value:
TagName: value
For example:
Version: 1.15
This example sets the package version to 1.15. The name of the item is not case sensitive, so tag names of version, Version, or VERSION all set the same value. This syntax works for most settings, including Name, Release, and so on.
In addition to this directive syntax, you can define macros using the RPM %define syntax. For example:
%define major 2
This example defines a macro named major with a value of 2. Once defined, you can access macros using the %{macro_name} or just %macro_name syntaxes. For example:
source: %{name}-%{version}.tar.gz
See the section "Defining Spec File Macros" later in this chapter for more options for macros.
Major section in the spec file are also delimited with % markers. For example, the build section starts with %build on a line by itself.
Note
The multiple uses of the % sign aren’t really that confusing in practice. Read through some spec files and you should find most of the commands are easily understood.
Blank lines separate section in the spec file, which makes sense for readability as well.

9.2.1. Comments

To help document your work, you can include comments (to yourself and others reading the spec file). Any line starting with a hash character, #, holds a comment. RPM will ignore comments.
# This is a comment.
In spec files, comments are mostly to help explain your syntax choices to yourself should you view the spec file later. Comments are a good thing. You should comment heavily, especially for any choice that deviates from the norm. For example, if you provide special C compiler options for building the package, add comments to describe why you picked the options and how necessary they are. Such comments help immensely should you need to port the RPM to another architecture or modify how it was built.
Tip
Avoid single percent signs, %, in comments. For example:
# Added new commands to %prep
The rpmbuild command may report an error of a second %prep section. To get around this problem, use two percent signs, such as %%prep, in spec file comments.