-->

Previous | Table of Contents | Next

Page 270

19.5.1. The excludexxx Tags

excludexxx tags are used to direct RPM to ensure that the package does not attempt to build on the excluded platforms. One or more platforms may be specified after the excludexxx tags, separated by either spaces or commas. Here are two examples:


ExcludeArch:  sparc  alpha

ExcludeOS:  Irix

The first line prevents systems based on the Sun SPARC and Digital Alpha/AXP architectures from attempting to build the package. The second line ensures that the package will not be built for the Silicon Graphics operating system Irix.

If a build is attempted on an excluded architecture or operating system, the following message will be displayed, and the build will fail:


#  rpm  -ba  cdplayer-1.0.spec

Arch  mismatch!

cdplayer-1.0.spec doesn't build on this architecture

#

excludexxx tags are meant to explicitly prevent a finite set of architectures or operating systems from building a package. If your goal is to ensure that a package will build on only one architecture, you should use the exclusivexxx tags.

19.5.2. The exclusivexxx Tags

exclusivexxx tags are used to direct RPM to only build the package on the specified platforms. These tags ensure that in the future no brand-new platform will mistakenly attempt to build the package. RPM will build the package on the specified platforms only.

The syntax of the exclusivexxx tags is identical to that of excludexxx:


ExclusiveArch:  sparc  alpha

ExclusiveOS:   Irix

In the first line, the package will only build on a Sun SPARC or Digital Alpha/AXP system. In the second, the package will only be built on the Irix operating system.

exclusivexxx tags are meant to explicitly allow a finite set of architectures or operating systems to build a package. If your goal is to ensure that a package will not build on a specific platform, you should use the excludexxx tag.

19.6. Platform-Dependent Conditionals

Of course, the control exerted by the excludexxx and exclusivexxx tags over package building is often too coarse. There may be packages, for example, that would build just fine on another platform, if only you could substitute a platform-specific patch file or change some paths in the %files list.

Page 271

The key to exerting this kind of platform-specific control in the spec file is to use RPM's conditionals. The conditionals provide a general-purpose means of constructing a platform-
specific version of the spec file during the actual build process.

19.6.1. Common Features of All Conditionals

A few things are common to each conditional, so let's discuss them first. The first thing is that conditionals are block structured. The second is that conditionals can be nested. Finally, conditionals can span any part of the spec file.

19.6.1.1. Conditionals Are Block Structured

Every conditional is block structured—in other words, the conditional begins at a certain point within the spec file and continues some number of lines until it is ended. This forms a block that will be used or ignored, depending on the platform the conditional is checking for as well as the build platform itself.

Every conditional starts with a line beginning with %if and is followed by one of four platform-related conditions. Every conditional ends with a line containing %endif.

Ignoring the platform-related conditions for a moment, here's an example of a conditional block:


%ifos Linux

Summary: This is a package for the Linux operating system

%endif

It's a one-line block, but a block nonetheless.

There's also another style of conditional block. As before, it starts with %if and ends with %endif. But there's something new in the middle:


%ifos Linux

Summary: This is a package for the Linux operating system

%else

Summary: This is a package for some other operating system

%endif

Here we've replaced one summary tag with another.

19.6.1.2. Conditionals Can Be Nested

Conditionals can be nested—that is, the block formed by one conditional can enclose another conditional. Here's an example:


%ifarch i386



echo "This is an i386"



%ifos Linux

echo "This is a Linux system"





Page 272


%else

echo "This is not a Linux system"

%endif



%else



echo "This is not an i386"



%endif

In this example, the first conditional block formed by the %ifarch i386 line contains a complete %ifos...%else...%endif conditional. Therefore, if the build system were Intel based, the %ifos conditional would be tested. If the build system were not Intel based, the %ifos conditional would not be tested.

19.6.1.3. Conditionals Can Cross Spec File Sections

The next thing each conditional has in common is that there is no limit to the number of lines a conditional block can contain. You could enclose the entire spec file within a conditional. But it's much better to use conditionals to insert only the appropriate platform-specific contents.

Now that we have the basics out of the way, let's take a look at each of the conditionals and see how they work.

19.6.2. %ifxxx

The %ifxxx conditionals are used to control the inclusion of a block as long as the platform-dependent information is true. Here is an example:


%ifarch i386 alpha

In this case, the block following the conditional would be included only if the build architecture were i386 or alpha.

Here's another example:


%ifos Linux

This example would include the block following the conditional only if the operating system were Linux.

19.6.3. %ifnxxx

The %ifnxxx conditionals are used to control the inclusion of a block as long as the platform-dependent information is not true. Here is an example:


%ifnarch i386 alpha



Previous | Table of Contents | Next