I am building a kernel module and will need to provide a version for each minor release of the distro. I plan to follow the release naming convention of .elX_Y
to designate the major version X and minor Y for the rpm. I am trying to use the following but do not understand why the macro does not seem to get properly defined and/or expanded.
# The macro in question, should evaluate to the minor rev
%define minor %(grep -oP '.*8\.\K([0-9]+)' /etc/redhat-release | tr -d '\n')
# Package meta
<other fields>
Release: 3%{?dist}_%{minor}
But when this is run, %{minor}
expands to nothing. The resulting package is simply named with .el8_.x86_64
rather than the expected .el8_5.x86_64
(showing minor rev 5). I tried replacing %define
with %global
but that still did not work.
I have confirmed the expansion of the grep command itself works fine in the %pre
section but %{minor}
is still empty.
%pre
# Successfully prints 5 on my install
echo %(grep -oP '.*8\.\K([0-9]+)' /etc/redhat-release | tr -d '\n')
# Prints empty new line
echo %{minor}
The only success I've had is to use the command directly in the Release
tag. The package built is then named <name-version>.el8_5.x86_64.rpm
as expected.
# Package meta
<other fields>
Release: 3%{?dist}_%(grep -oP '.*8\.\K([0-9]+)' /etc/redhat-release | tr -d '\n')
While I have an acceptable workaround, I would like to be able to use the minor
macro in other parts of the spec file. Why is the macro define not working as I expect?