Search code examples
dependenciesdependency-managementyumrpmbuildrpm-spec

rpmbuild requires depending on the OS version where the rpm will be installed


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.


Solution

  • 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.