Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
999 views
in Technique[技术] by (71.8m points)

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

question from:https://stackoverflow.com/questions/65884208/rpmbuild-requires-depending-on-the-os-version-where-the-rpm-will-be-installed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...