rpmbuild 需要取决于将安装 rpm 的 OS 版本

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

我正在使用 rpmbuild 构建一个 rpm。已经构建的 rpm 将安装在 rhel6、rhel7 或 rhel8 机器上。在 rhel8 上,需要一些在其他分发版本(rhel6 和 rhel7)中不需要的依赖项。 在包的名称上使用条件(如下所示)不是一个选项。

Requires: (pkgA >= 3.2 or pkgB)

我想在规范文件中做的是:

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

如何定义变量 VERSIONMAJOS? 我无法使用宏 %{rhel}(如此处所示 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)。 当我在 rhel6、rhel7 或 rhel8 上使用命令 yum -y nameOfRmp.rpm 时,我需要的是不同的库要求。

使用%{?rhel}宏。在基于 RHEL 的发行版中,它将等同于主要发行版。它通常与前导 0 一起使用,以便当规范文件更有可能在未定义它的其他发行版上成功构建时。

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

对于每个 分布有不同的Requires,你需要建立一个单独的RPM包。

基于分布的动态需求根本不可能。这不是 RPM 的工作方式。