1 /*! \page conditionalbuilds Passing conditional parameters into a rpm build
3 Source code is often built with optional features enabled or disabled.
4 When source code is packaged using rpm, the various features can be
5 chosen, added to a spec file, and a package will be produced with
6 binaries compiled with that feature set. This mechanism works fine
7 for packages with small feature sets, but does not work so well
8 for large, complicated, packages like the Linux kernel and/or
9 the Pine mailer which have a large number of features, as a given
10 feature set may not "work" for everyone.
12 RPM now has a supported mechanism to pass information from the rpm
13 command line to enable/disable features during a build. Two options have
14 been added to pass feature names from the rpm command line:
16 --with <feature> Enable <feature>
17 --without <feature> Disable <feature>
19 The new options are implemented using popt to add aliases to the existing rpm
20 options --define to specify macros from the command line. The magic necessary
21 to add the new options is (from the file /usr/lib/rpm/rpmpopt*)
23 rpmb alias --with --define "_with_!#:+ --with-!#:+"
24 rpmb alias --without --define "_without_!#:+ --without-!#:+"
26 (Note: The obscure "!#:+" popt token above says "substitute the next command
27 line argument found here, and, additionally, mark the argument as used.")
29 For example, when rpm is invoked as
31 rpm ... --with ldap ...
33 then the popt aliases will cause the options to be rewritten as
35 rpm ... --define "_with_ldap --with-ldap" ...
37 which causes a "%_with_ldap" macro to be defined with value "--with-ldap"
40 The macro defined on the rpm command line can be used to conditionalize
41 portions of the spec file for the package. For example, let's say you
42 are trying to build the pine package using "--with ldap" to enable the
43 LDAP support in the pine mailer (i.e. configuring with "--with-ldap").
44 So the spec file should be written
51 so that, if "--with ldap" was used as a build option, then configure
52 will be invoked (after macro expansion) as
54 ./configure --with-ldap ...
56 (Note: The obscure "%{?_with_ldap: ...}" rpm macro syntax above says "if the
57 macro "_with_ldap" exists, then expand "...", else ignore.")
59 The spec file should include a default value for the "_with_ldap" macro,
60 and should support "--without ldap" as well. Here's a more complete example
63 # Default values are --without-ldap --with-ssl.
65 # Read: If neither macro exists, then add the default definition.
66 %{!?_with_ldap: %{!?_without_ldap: %define _without_ldap --without-ldap}}
67 %{!?_with_ssl: %{!?_without_ssl: %define _with_ssl --with-ssl}}
70 # You might want to make sure that one and only one of required and
71 # mutually exclusive options exists.
73 # Read: It's an error if both or neither required options exist.
74 %{?_with_ssl: %{?_without_ssl: %{error: both _with_ssl and _without_ssl}}}
75 %{!?_with_ssl: %{!?_without_ssl: %{error: neither _with_ssl nor _without_ssl}}}
77 # Add build dependencies for ssl and ldap features if enabled.
78 # Note: Tag tokens must start at beginning-of-line.
80 # Read: If feature is enabled, then add the build dependency.
81 %{?_with_ssl:BuildRequires: openssl-devel}
82 %{?_with_ldap:BuildRequires: openldap-devel}
85 # Configure with desired features.
87 # Read: Add any defined feature values to the configure invocation.
95 # Conditional tests for desired features.
97 # Read: true if _with_ssl is defined, false if not defined.
98 %if %{?_with_ssl:1}%{!?_with_ssl:0}