Product SiteDocumentation Site

Conditional macros

You can use a special syntax to test for the existence of macros. For example:
%{?macro_to_test: expression}
This syntax tells RPM to expand the expression if macro_to_test exists, otherwise ignore. A leading exclamation point, !, tests for the non-existence of a macro:
%{!?macro_to_test: expression}
In this example, if the macro_to_test macro does not exist, then expand the expression.
The %if macro performs an if test much like scripting languages. For example:
%if %{old_5x}
%define b5x 1
%undefine b6x
%endif
A %else allows you to specify what to do if the test is not successful. For example:
%if %{old_5x}
%define b5x 1
%undefine b6x
%else
%define b6x 1
%undefine b5x
%endif
Again, use an exclamation point to negate the test. For example:
%if ! %{old_5x}
%define b5x 1
%undefine b6x
%endif
You can use a && for an and test. For example:
%if %{old_5x} && %{old_6x}
%{error: You cannot build for .5x and .6x at the same time}
%quit
%endif