0

I am building an rpm with rpmbuild. That already build rpm will be installed on rhel6, rhel7 or rhel8 machines. On rhel8, some dependencies are needed that are not needed in the other distribution versions (rhel6 and rhel7). Using a condition (as follow) on the name of the packages is then not an option.

Requires: (pkgA >= 3.2 or pkgB)

What I want to do in the spec file is something like :

%if %{VERSIONMAJOS} < 8
Requires: sssd >= 1.15 , sudo >= 1.8.6p3
%else
Requires: sssd >= 1.15 , sudo , oddjob , oddjob-mkhomedir
%endif

How can I define the variable VERSIONMAJOS? I can not use the macro %{rhel} (as shown here https://unix.stackexchange.com/questions/9296/how-can-i-specify-os-conditional-build-requirements-in-an-rpm-spec-file) as that variable is defined during the build of the rpm (if I understand correctly the DistTag page https://fedoraproject.org/wiki/Packaging:DistTag). What I need is the library requirement to be different when I use the command yum -y nameOfRmp.rpm on an rhel6, rhel7 or rhel8.

Kevin
  • 31
  • 1
  • 7
  • Does this answer your question? [RPM Spec file conditional Requires per distribution AFTER build](https://stackoverflow.com/questions/37007873/rpm-spec-file-conditional-requires-per-distribution-after-build) – omajid Jan 25 '21 at 16:10

1 Answers1

2

Use %{?rhel} macro. In RHEL based distros it will be equal to the major distribution version. It is typically used together with leading 0 so that when the spec file is more likely to successfully built on other distros where it's not defined.

%if 0%{?rhel} < 8
Requires: sssd >= 1.15 , sudo >= 1.8.6p3
%else
Requires: sssd >= 1.15 , sudo , oddjob , oddjob-mkhomedir
%endif

For each distribution which has different set of Requires, you need to build a separate RPM package.

Dynamic Requires based on distribution are simply not possible. This is just not how RPM works.

Danila Vershinin
  • 8,725
  • 2
  • 29
  • 35
  • 1
    I've expanded my answer a bit. You don't build just one RPM file that satisfies all distros through some "dynamic requires per-distro" (there is no such thing). You build multiple RPMs, one for each distribution that you intend to support. The dist of the RPM goes into the filename so then it's easy to distinguish which RPM file is meant for which version of a which distro. – Danila Vershinin Jan 26 '21 at 07:55
  • Here's an example - Fedora 32 and RHEL 8 moved from "docker" to "podman" - https://github.com/AaronDMarasco/packpack/blob/b1d61a1c1b2c2b71e15627f65f0e817decbdd47d/rpm/packpack.spec#L14 – Aaron D. Marasco Feb 22 '21 at 02:00