Product SiteDocumentation Site

18.2.5.2. Build environment and macros

Once you can detect the Linux vendor, you can create macros based on the differences between Linux distributions that affect your applications.
Cross Reference
Chapter 20, Customizing RPM Behavior covers RPM macros.
The macros that specifically help you with platform differences include the %if .. %endif conditional. You can use this in combination with special macros you define. In addition, command-line options such as --with, --without, and --target allow you to control features and the build target within an RPM.
The %if macro allows you to specify a condition within your spec file. For example:
%if %{old_5x} && %{old_6x}
%{error: You cannot build for .5x and .6x at the same time}
%quit
%endif
%if %{old_5x}
%define b5x 1
%undefine b6x
%endif
%if %{old_6x}
%define b6x 1
%undefine b5x
%endif
You can also use %if to control settings such as the Requires:, as shown in the following example:
%if %{build6x}
Requires: util-linux, pam >= 0.66-5
%else
Requires: util-linux, pam >= 0.75-37, /etc/pam.d/system-auth
%endif
The --with command-line option defines a special macro starting with _with_. For example, the following command-line option defines a feature to use:
$ rpmbuild –bc --with ssh filename.spec
This example defines the macro _with_ssh to --with-ssh. This format was specially designed to work with GNU configure. You can use this for conditional builds for platform-dependent issues.
The --without command-line option similarly defines a macro starting with _without_. The convention is that this option defines a feature the code should not use.
You can combine --with and --without to turn on and off features referenced in your spec files. For example:
./configure %{?_with_ssh}
This will pass the following command line if the _with_ssh macro is defined:
./configure --with-ssh
If this option is not defined, the command will be:
./configure
The --target option sets the spec file macros %_target, %_target_arch, and %_target_os . For example:
$ rpmbuild -bc --target ppc-ibm-aix /usr/src/redhat/SPECS/jikes.spec