summaryrefslogtreecommitdiff
path: root/docs/manual/conditionalbuilds.md
blob: a64f87d9a88085737eaeaa7212ade51ead31ccbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
layout: default
title: rpm.org - Conditional Builds
---
# Conditional Builds

Rpmbuild supports conditional package builds with the command line switches
`--with` and `--without`.

Here is an example of how to enable gnutls and disable openssl support:

```
$ rpmbuild -ba newpackage.spec --with gnutls --without openssl
```

## Enable `--with`/`--without` parameters

To use this feature in a spec file, add this to the beginning of the file:

```
# add --with gnutls option, i.e. disable gnutls by default
%bcond_with gnutls
# add --without openssl option, i.e. enable openssl by default
%bcond_without openssl
```

If you want to change whether or not an option is enabled by default, only
change `%bcond_with` to `%bcond_without` or vice versa. In such a case, the
remainder of the spec file can be left unchanged.

## Check whether an option is enabled or disabled

To define `BuildRequires` depending on the command-line switch, you can use the
`%{with foo}` macro:

```
%if %{with gnutls}
BuildRequires:  gnutls-devel
%endif
%if %{with openssl}
BuildRequires:  openssl-devel
%endif
```

Alternatively, you can test the presence (or lack thereof) of `%with_foo`
macros which is nicer in other situations, e.g.:

```
%configure \
   %{?with_static:--enable-static} \
   %{!?with_static:--disable-static}
```

Always test for the `with`-condition, not the `without`-counterpart!

## Pass it to `%configure`

To pass options to configure or other scripts that understand a `--with-foo` or
`--without-foo` parameter, you can use the `%{?_with_foo}` macro:

```
%configure \
        %{?_with_gnutls} \
        %{?_with_openssl}
```

## References
* [macros](https://github.com/rpm-software-management/rpm/blob/master/macros.in)