-->
Page 387
Page 388
Comments are a way to make RPM ignore a line in the spec file. To create a comment, enter a pound sign (#) at the start of the line. Any text following the comment character will be ignored by RPM:
# This is the spec file for playmidi 2.3...
Comments can be placed in any section of the spec file.
For more information, see section 13.1 in Chapter 13, "Inside the Spec File."
The preamble contains information that will be displayed when users request information about the package.
Package-naming tags are used to define the parts of the package's label. For more information about these tags, see section 13.2.1.
The name tag is used to define the name of the software being packaged:
Name: cdplayer
The version tag defines the version of the software being packaged:
Version: 1.2
The release tag can be thought of as the package's version:
Release: 5
Descriptive tags are used to define various types of information about the package. For more information about these tags, see section 13.2.2.
Page 389
The %description tag is used to define an in-depth description of the packaged software. In the descriptive text, a space in the first column indicates that that line of text should be presented to users as is, with no formatting done by RPM. Blank lines in the descriptive text denote paragraphs:
%description It slices! It dices! It's a CD player app that can't be beat. By using the resonant frequency of the CD itself, it is able to simulate 20X oversampling. This leads to sound quality that cannot be equaled with more mundane software...
You can make the %description tag specific to a particular subpackage by adding the subpackage name and, optionally, the -n option:
%description bar %description -n bar
The subpackage name and the usage of the -n option must match those defined with the %package directive.
The summary tag is used to define a one-line description of the packaged software:
Summary: A CD player app that rocks!
The copyright tag is used to define the copyright terms applicable to the software being packaged:
Copyright: GPL
The distribution tag is used to define a group of packages of which this package is a part:
Distribution: Doors '95
The icon tag is used to name a file containing an icon representing the packaged software:
Icon: foo.xpm
The file may be in either GIF or XPM format, although XPM is preferred. In either case, the background of the icon should be transparent.
Page 390
The vendor tag is used to define the name of the entity that is responsible for packaging the software:
Vendor: White Socks Software, Inc.
The url tag is used to define a uniform resource locator that can be used to obtain additional information about the packaged software:
URL: http://www.gnomovision.com/cdplayer.html
The group tag is used to group packages together by the types of functionality they provide:
Group: Applications/Editors
The packager tag is used to hold the name and contact information for the person or persons who built the package:
Packager: Fred Foonly <[email protected]>
Dependency tags are used to define a package's dependency-related requirements. For more information about these tags, see section 13.2.3.
The provides tag is used to specify a "virtual package" that the packaged software makes available when it is installed:
Provides: module-info
The requires tag is used to make RPM aware that the package needs to have certain capabilities available in order to operate properly:
Requires: playmidi
A version may be specified, following the package specification. The following comparison operators may be placed between the package and version: <, >, =, >=, and <=. Here's an example:
Requires: playmidi >= 2.3
Page 391
If the requires tag needs to perform a comparison against a serial number defined with the serial tag, the proper format would be
Requires: playmidi =S 4
The serial tag is used to define a serial number for a package:
Serial: 4
This is only necessary if RPM is unable to determine the ordering of a package's version numbers.
The conflicts tag is used to make RPM aware that the package is not compatible with other packages:
Conflicts: playmidi
A version may be specified, following the package specification. The following comparison operators may be placed between the package and version: <, >, =, >=, and <=. Here's an example:
Conflicts: playmidi >= 2.3
If the conflicts tag needs to perform a comparison against a serial number defined with the serial tag, the proper format would be
Conflicts: playmidi =S 4
The autoreqprov tag is used to control the automatic dependency processing performed when the package is being built. To disable automatic dependency processing, add the following line:
AutoReqProv: no
(The number 0 may be used instead of no.) Although RPM defaults to performing automatic dependency processing, the effect of the autoreqprov tag can be reversed by changing no to yes. (The number 1 may be used instead of yes.)
These tags are used to control RPM's behavior when the package is built on different platforms. For more information about these tags, see section 13.2.4.
Page 392
The excludearch tag is used to direct RPM to ensure that the package does not attempt to build on the excluded architecture(s):
ExcludeArch: sparc alpha
The exclusivearch tag is used to direct RPM to ensure the package is only built on the specified architecture(s):
ExclusiveArch: sparc alpha
The excludeos tag is used to direct RPM to ensure that the package does not attempt to build on the excluded operating system(s):
ExcludeOS: linux irix
The exclusiveos tag is used to denote which operating system(s) should be exclusively permitted to build the package:
ExclusiveOS: linux
Directory-related tags are used to define certain directory-related aspects of RPM's operation. For more information about these tags, see section 13.2.5.
The prefix tag is used to define part of the path RPM will use when installing the package's files:
Prefix: /opt
The prefix can be redefined by the user when the package is installed, thereby changing where the package is installed.
The buildroot tag is used to define an alternate build root, where the software will be installed during the build process:
BuildRoot: /tmp/cdplayer
Page 393
The source and patch tags are used to define the names of the files that contain the package's source code, and patches. For more information about these tags see section 13.2.6 in Chapter 13.
The source tag is used to define the filename of the sources to be packaged:
Source0: ftp://ftp.gnomovision.com/pub/cdplayer-1.0.tgz Source1: foo.tgz
When there is more than one source tag in a spec file, each one must be numbered so it is unique, starting with the number 0. When there is only one tag, it does not need to be numbered. By convention, the source filename is usually preceded by a URL pointing to the location of the original sources, but RPM does not require this.
The nosource tag is used to make RPM aware that one or more source files should be excluded from the source package file:
NoSource: 0, 3
The tag is followed by one or more numbers. The numbers correspond to the numbers following the source tags that are to be excluded from packaging.
The patch tag is used to define the name of a patch file to be applied to the package's sources:
Patch: cdp-0.33-fsstnd.patch
When there is more than one patch tag in a spec file, each one must be numbered so it is unique, starting with the number 0. When there is only one tag, it does not need to be numbered.
The nopatch tag is used to make RPM aware that one or more patch files should be excluded from the source package file:
NoPatch: 2 3
The tag is followed by one or more numbers. The numbers correspond to the numbers following the patch tags that are to be excluded from packaging.
Page 394
Scripts are used by RPM to perform processing at various times.
Every build time script has the following environment variables defined:
For more information on these environment variables and build time scripts, see section 13.3.1 in Chapter 13.
The %prep script is the first script RPM executes during a build:
%prep
As the name implies, it is normally used to prepare the sources for building. The commands in the script can be any valid sh commands.
The %build script is the second script RPM executes during a build:
%build
As the name implies, it is normally used to build the software. The commands in the script can be any valid sh commands.
Page 395
The %install script is the third script RPM executes during a build:
%install
As the name implies, it is normally used to install the software. The commands in the script can be any valid sh commands.
The %clean script, as the name implies, is used to clean up the software's build directory tree:
%clean
RPM will normally do this for you, but in certain cases (most notably in those packages that use a build root) you'll need to include a %clean script. The commands in the script can be any valid sh commands.
Install time and erase time scripts are executed whenever the package is installed or erased, respectively. Each script can consist of any valid sh commands.
You can make each of the following scripts specific to a particular subpackage by adding the subpackage name and, optionally, the -n option:
%post bar %preun -n bar
The subpackage name and usage of the -n option must match those defined with the %package directive.
Each script has the following environment variable defined:
For more information on this environment variable and the associated scripts, see section 13.3.2 in Chapter 13.
The %pre script executes just before the package is to be installed:
%pre
The %post script executes just after the package is to be installed:
%post
Page 396
The %preun script executes just before the package is to be erased:
%preun
The %postun script executes just after the package is to be erased:
%postun
Verification scripts are executed when an installed package is to be verified.
The %verifyscript script executes whenever the package is verified using RPM's -V option. The script can consist of any valid sh commands.
For more information, see section 13.3.3 in Chapter 13.
Macros are used to simplify certain types of repetitive operations.
The %setup macro is used to unpack the original sources in preparation for the build. It is used in the %prep script:
%prep %setup
For more information about the %setup macro and the related options described in this section, see section 13.4.1 in Chapter 13.
The -n option is used to set the name of the software's build directory:
%setup -n cd-player
This is necessary only when the source archive unpacks into a directory named other than <name>-<version>.
Page 397
The -c option is used to direct %setup to create the top-level build directory before unpacking the sources:
%setup -c
The -D option is used to direct %setup to not delete the build directory prior to unpacking the sources:
%setup -D -T -b 3
This option is used when more than one source archive is to be unpacked into the build directory, normally with the -b or -a option.
The -T option is used to direct %setup to not perform the default unpacking of the source archive specified by the first source tag. It is used with the -a or -b options:
%setup -D -T -a 1
The -b option is used to direct %setup to unpack the source archive specified on the nth source tag line before changing directories into the build directory:
%setup -D -T -b 2
The -a option is used to direct %setup to unpack the source archive specified on the nth source tag line after changing directories into the build directory:
%setup -D -T -a 5
The %patch macro, as its name implies, is used to apply patches to the unpacked sources. With no additional options specified, it will apply the patch file specified by the patch (or patch0) tag:
%patch
When there is more than one patch tag line in a spec file, they can be specified by appending the number of the patch tag to the %patch macro name itself:
%patch2
Page 398
For more information about the patch tag and the related options described in this section, see section 13.4.2 in Chapter 13.
The -P option is another method of applying a specific patch. The number from the patch tag follows the -P option. The following %patch macros both apply the patch specified on the patch2 tag line:
%patch -P 2 %patch2
The -p option is sent directly to the patch command. It is followed by a number that specifies the number of leading slashes (and the directories in between) to strip from any filenames present in the patch file:
%patch -p2
When the patch command is used to apply a patch, unmodified copies of the files patched are renamed to end with the extension .orig. The -b option is used to change the extension used by patch:
%patch -b .fsstnd
The -E option is sent directly to the patch command. It is used to direct patch to remove any empty files after the patches have been applied.
%patch -E
The %files list indicates which files on the build system are to be packaged. The list consists of one file per line:
%files /etc/foo.conf /sbin/foo /usr/bin/foocmd
Page 399
If a directory is specified, by default all files and subdirectories will be packaged.
You can make the %files list specific to a particular subpackage by adding the subpackage name and, optionally, the -n option:
%files bar %files -n bar
The subpackage name and the usage of the -n option must match those defined with the %package directive.
The %files list can also use the contents of a file as the list of files to be packaged. This is done by using the -f option, which is then followed by a filename:
%files -f files.list
For more information, see section 13.5 in Chapter 13.
The directives outlined in the following sections are used to modify various attributes of one or more entries in the %files list.
The directives outlined in the following sections modify %files list entries that are files. For more information about these directives, see section 13.6.1.
The %doc directive flags the filename(s) that follow it as being documentation:
%doc README
The %config directive is used to flag the specified file as being a configuration file:
%config /etc/fstab
The %attr directive is used to permit RPM to directly control a file's permissions and ownership. It is normally used when non-root users build packages. The %attr directive has the following format:
%attr(<mode>, <user>, <group>) file
Page 400
The user and group identifiers must be non-numeric. Attributes that do not need to be set by %attr may be replaced with a dash:
%attr(755, root, -) foo.bar
The %verify directive is used to control which of nine different file attributes are to be verified by RPM. The attributes are
One or more of these attributes may be listed in each %verify directive:
%verify(mode md5 size maj min symlink mtime) /dev/ttyS0
If the keyword not precedes the list of attributes, every attribute except those listed will be verified.
The directives outlined in the following sections modify %files list entries that are directories. For more information about these directives, see section 13.6.2 in Chapter 13.
The %docdir directive is used to add the specified directory to RPM's internal list of directories containing documentation. When a directory is added to this list, every file packaged in this directory (and any subdirectories) will automatically be marked as documentation.
The %dir directive is used to direct RPM to package only the directory itself, regardless of what files may reside in the directory at the time the package is created:
%dir /usr/blather
Page 401
The %package directive is used to control the creation of subpackages. The subpackage name is derived from the first name tag in the spec file, followed by the name specified after the %package directive. Therefore, if the first name tag is
Name: foo
and a subpackage is defined with the following %package directive:
%package bar
the subpackage name will be foo-bar.
For more information on this package and its options, see section 13.7 in Chapter 13.
The -n option is used to change how RPM derives the subpackage name. When the -n option is used, the name following the %package directive becomes the complete subpackage name. Therefore, if a subpackage is defined with the following %package directive:
%package -n bar
the subpackage name will be bar.
The %ifxxx conditionals are used to begin a section of the spec file that is specific to a particular architecture or operating system. They are followed by one or more architecture or operating system specifiers, each separated by commas or whitespace.
Conditionals may be nested within other conditionals, provided that the inner conditional is completely enclosed by the outer conditional. For more information about conditionals, see section 13.8 in Chapter 13.
If the build system's architecture is specified, the part of the spec file following the %ifarch but before an %else or %endif will be used during the build:
%ifarch i386 sparc
Page 402
If the build system's architecture is specified, the part of the spec file following the %ifarch but before an %else or %endif will not be used during the build:
%ifnarch i386 sparc
If the build system is running one of the specified operating systems, the part of the spec file following the %ifos but before an %else or %endif will be used during the build:
%ifos linux
If the build system is running one of the specified operating systems, the part of the spec file following the %ifnos but before an %else or %endif will not be used during the build:
%ifnos linux
The %else conditional is placed between an %if conditional of some persuasion and an %endif. It is used to create two blocks of spec file statements, only one of which will be used in any given case:
%ifarch alpha make RPM_OPT_FLAGS="$RPM_OPT_FLAGS -I ." %else make RPM_OPT_FLAGS="$RPM_OPT_FLAGS" %endif
An %endif is used to end a conditional block of spec file statements. The %endif is always needed after a conditional; otherwise, the build will fail:
%ifarch i386 make INTELFLAG=-DINTEL %endif