Библиотека сайта rus-linux.net
|Maximum RPM: Taking the Red Hat Package Manager to the Limit|
|Prev||Chapter 19. Building Packages for Multiple Architectures and Operating Systems||Next|
Of course, the control exerted by the
xxx 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
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.
There are a few things that 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.
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 the characters %if and is followed by one of four platform-related conditions. Every conditional ends with a line containing the characters %endif.
It's a one-line block, but a block nonetheless.
Here we've replaced one summary tag with another.
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 was Intel-based, the %ifos conditional would be tested. If the build system was not Intel-based, the %ifos conditional would not be tested.
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, if you like. 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.
xxxconditionals are used to control the inclusion of a block, as long as the platform-dependent information is true. Here are two examples:
This example would include the block following the conditional only if the operating system was Linux.
xxxconditionals are used to control the inclusion of a block, as long as the platform-dependent information is not true. Here are two examples:
This example would include the block following the conditional only if the operating system was not Linux.