Product SiteDocumentation Site

22.2. Macros

You can define macros in your spec files to help control how the package gets built. The following section describes these macros.

22.2.1. Variable definition macros

The %define macro allows you to define new macros from within your spec file. A common usage is to define top-level directories with %define macros at the top of a spec file and then reference these directories throughout the file. For example:
%define_bindir/bin
This allows you to change the setting in one place, which is very handy for directory paths used throughout your spec files.
Cross Reference
See the section on Defining Macros in Spec Files in Chapter 22, Spec File Syntax for more on this subject.
You can use this syntax for other things that may commonly change, such as version numbers. For example:
%define major 2
%define minor 2
%define patchlevel 7
Version: %{major}.%{minor}.%{patchlevel}
Table B-1 lists more special macros used within spec files.
Table B-1 Special spec file macros
Macro
Usage
%dump
Prints out macro values
%{echo:message}
Prints message to stderr
%{error:message}
Prints message to stderr and returns BADSPEC
%{expand:expression}
Like eval, expands expression
%{F:file_exp}
Expands file_exp to a file name
%global name value
Defines a global macro
%{P:patch_exp}
Expands patch_exp to a patch file name
%{S:source_exp}
Expands source_exp to a source file name
%trace
Toggles the printing of debugging information
%{uncompress:filename}
Tests if file filename is compressed. If so, uncompresses and includes in the given context. If not compressed, calls cat to include file in given context.
%undefine macro
Undefines the given macro
%{warn:message}
Prints message to stderr