Home Home > 2008 > 09 > 12 > Conditional features aka “use flags”
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

Conditional features aka “use flags”

September 12th, 2008 by

In a coordinated effort with Manfred Tremmel, the xine maintainer at Packman, we’ve reworked the xine spec file. Most of it can now be shared between Packman and openSUSE Factory so packaging work doesn’t need to be duplicated. The spec file now makes heavy use of conditional build macros to enable or disable certain features.
For openSUSE we do not want to (or can’t) ship certain features. For example we decided that the arts plugin isn’t of much use and therefore only adds an unecessary build dependeny on openSUSE. Packman however wants to offer all featues and therefore ship the arts plugin. To resolve that conflict the arts plugin ended up in it’s own subpackage but buidling it is disabled by default. To enable arts support locally Manfred can call rpmbuild (or the openSUSE build script) with the parameters “–with arts” . It’s not necessary to edit the spec file anymore. That –with switch works because the spec file uses some rpm macros that change things depending on whether arts support was requested. Hopefully other packages that can be built with different features but need to be shipped on openSUSE with a certain configuration will pick up this mechanism too. So let’s explain how it works.

The spec file starts with %bcond_with arts
at the top. That basically tells rpmbuild to define a global macro “with_arts” if “–with arts” was specified. Later we have
%if %{with arts}
BuildRequires: arts-devel

That means we depend on arts-devel only if requested. Similar blocks are used to enable or disable the subpackage, files section etc.

Other features like e.g. pulseaudio are enabled by default but allow disabling using e.g. “rpmbuild –without pulseaudio”. The macro to get that behavior is “%bcond_without pulseaudio”.

So how to make use of that in the build service?

Let’s assume you have a project “artsfans” where you compile packages without pulseaudio but with arts support and want a xine-lib that matches this configuration. First you need to modify your project config and define macros that disable pulseaudio and enable arts. Run meta prjconf artsfans -e and enter the following:
%define _without_pulseaudio 1
%define _with_arts 1
%_without_pulseaudio 1
%_with_arts 1

Then link xine-lib from Factory into your project:
osc linkpac openSUSE:Factory xine-lib artsfans and watch your xine building with arts support. Piece of cake, isn’t it? 🙂

Both comments and pings are currently closed.

2 Responses to “Conditional features aka “use flags””

  1. Really, really nice. 🙂

  2. Yeah, very useful, but it has been there for a very long time 😉

    Might be helpful to define canonical macros for the Build Service (yes, I know, there’s %opensuse_bs), for Factory (I mean packages that supposedly go into the distribution) and for Packman (as well as other 3rd party repositories) in order to share spec files.

    Let’s have %opensuse_bs, %opensuse_dist and %packman… but OTOH it might be even better to have it on “features” instead;
    %define _with_uncrippled 1
    in Packman, videolan, …