Need to differentiate a package dependency between RHEL 7.2/7.3 v/s RHEL 7.4 and above. There is rhel
macro available in rpm spec file but that evaluates to 7 for all RHEL 7.x and 6 for all RHEL 6.x versions.
I can possibly read /etc/redhat-release
file and determine the minor version in %pre
section but unclear whether that's too late to specify package dependency using Requires
directive.
I tried defining a macro that reads /etc/redhat-release
file and then using the macro like following
%define rhel_minor_version %(rhel_version_file="/etc/redhat-release";
if [ -f $rhel_version_file ]; then echo $(cat $rhel_version_file |
grep -oP '.*7\.\K([0-9]+)'); else echo 0; fi)
%if 0%{?rhel} == 7
%if 0%{?rhel_minor_version} >= 4
Requires: iperf3
%endif
%endif
However this macro gets evaluated on the system where rpmbuild
is invoked to build the rpm package and not the system where the rpm package is installed. So doesn't work.
There is a mechanism to specify weak dependency i.e. optional dependency in rpm spec file. This way if the package is available it’ll be installed else dependency will be ignored. https://rpm.org/user_doc/dependencies.html
“Recommends” directive appears valid on Fedora but not available on RHEL https://bugzilla.redhat.com/show_bug.cgi?id=1427674
After much thought I don't think it's possible to differentiate dependencies based on RHEL minor version without shipping different el7 packages for RHEL 7.2/7.3 v/s RHEL 7.4+ which is not an option...