1

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?

Tom
  • 111
  • 3

1 Answers1

0

According to this question, the command to get the minor version might not be working correctly in rpmbuild %define statement.

Below commands seems to work for me.

%define minor       %(grep -o '8\.[0-9.]*' /etc/redhat-release |  cut -d '.' -f2)
OR
%define minor       %(awk '{ print $4 }' /etc/redhat-release | cut -d '.' -f2)

EDIT 1:

It seems that your command can also work with a minor tweak. i.e., escape the slash before K by adding an extra slash.

%define minor       %(grep -oP '.*8\.\\K([0-9]+)' /etc/redhat-release | tr -d '\n')