uname -r does not reflect target kernel version

I am building a kernel module in my package just to make sure it builds successfully not to actually include the binary kernel module. I will have the kernel module source code included with my package so it can be re-built if the user want to use my kernel module (not required).

So my kernel module Makefile uses “uname -r” to configure KDIR for the kernel build location. This is resulting in the build hosts kernel version of 4.4.22-1-default. The build works for 13.2 so the kernel version must match that.

Anyway is there a way to overwrite uname -r or someway to detect what kernel package is installed into the build root?

My approach is to query rpm (with rpm -q --qf). For examples see home:repabuild:withupdates, I build the EtherCAT kernel modules there.