query: if Kernel-Version >= 4.5 in .spec-File

Can somebody help me to apply a patch only if kernel >= 4.5 in a spec-File?
I do not know, how to do this, get only errors…

In my spec-File:

%prep
%setup -q

if ((uname -r | awk -F. '{print $1"."$2}') >= 4.5);
then %patch0 -p1
fi

Error:

   52s] + /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
   52s] /var/tmp/rpm-tmp.gEvT9Z: line 37: syntax error near unexpected token `4.5'
   52s] error: Bad exit status from /var/tmp/rpm-tmp.gEvT9Z (%prep)
   52s] 
%if %version >= 4.5
%patch235 -p1
%endif

That results in: (same in kernel 4.5)

   44s] + exec rpmbuild -ba --define '_srcdefattr (-,root,root)' --nosignature --define 'disturl obs://build.opensuse.org/home:Sauerland/openSUSE_13.1_Update/e8ddc18d06036f0ecf3e18ed1abc1ae0-r8168' /home/abuild/rpmbuild/SOURCES/r8168.spec
   44s] /usr/src/linux-3.12.53-40/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
   45s] /usr/src/linux-3.12.53-40/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
   45s] /usr/src/linux-3.12.53-40/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
   46s] error: parse error in expression
   46s] error: /home/abuild/rpmbuild/SOURCES/r8168.spec:49: bad %if condition
   46s] 
   46s] lamb20 failed "build r8168.spec" at Sun Mar 20 12:56:04 UTC 2016.

In the spec-file:

%description KMP
Realtek r8168 kernel module for RealTek RTL8111/8168, Gigabit Ethernet controllers with PCI-Express interface.

%{kernel_module_package -p %{_sourcedir}/preamble}

%prep
%setup -q

%if %version >= 4.5
%patch0 -p1
%endif

set -- *
mkdir source
mv "$@" source/

Right, sorry. Of course, it is not simple numeral so comparison fails. You probably can beef up something using Lua (see http://www.rpm.org/wiki/PackagerDocs/RpmLua) but I ask myself why you need it? Package version is not something variable. It makes sense to be conditional depending on architecture or distribution version, because you use the same spec file everywhere. But you do not use the same spec file for different versions - your spec is either for version < 4.5 or for version >= 4.5. So as soon as you bump spec file version you add patch.

Please explain what you are trying to achieve using this condition?

Hi
Normally I would rebase the patch to use IFDEF statements defining the kernel version around the code… I may be an option depending on what the OP is patching.

I want to build the original r8168 from Realtek, in Kernel 4.5 I get an error:

   82s] /home/abuild/rpmbuild/BUILD/r8168-8.041.01/obj/default/r8168_n.c:4212:30: error: 'NETIF_F_ALL_CSUM' undeclared (first use in this function)
   82s]                  features &= ~NETIF_F_ALL_CSUM;

A kernel < 4.5 will build.
So I made a patch:

--- r8168-8.041.01/src/r8168_n.c.orig	2015-10-06 08:33:04.000000000 +0200
+++ r8168-8.041.01/src/r8168_n.c	2016-03-19 18:14:35.691263375 +0100
@@ -4209,7 +4209,7 @@
         spin_lock_irqsave(&tp->lock, flags);
         if (dev->mtu > ETH_DATA_LEN) {
                 features &= ~NETIF_F_ALL_TSO;
-                features &= ~NETIF_F_ALL_CSUM;
+                features &= ~NETIF_F_CSUM_MASK;
         }
         spin_unlock_irqrestore(&tp->lock, flags);
 

Now it builds without any error, but only for Kernel 4.5.
In any kernel < 4.5 I get:

   46s] /home/abuild/rpmbuild/BUILD/r8168-8.041.01/obj/default/r8168_n.c:4212:30: error: 'NETIF_F_CSUM_MASK' undeclared (first use in this function)
   46s]                  features &= ~NETIF_F_CSUM_MASK;

https://build.opensuse.org/package/show/home:Sauerland/r8168
https://build.opensuse.org/package/view_file/home:Sauerland/r8168/r8168.spec?expand=1

So I want to know, how to fix this.

PS
I know, the r8169 is in the Kernel…

On Sun 20 Mar 2016 05:46:03 PM CDT, Sauerland wrote:

I want to build the original r8168 from Realtek, in Kernel 4.5 I get an
error:

Code:

82s] /home/abuild/rpmbuild/BUILD/r8168-8.041.01/obj/default/r8168_n.c:4212:30:
error: ‘NETIF_F_ALL_CSUM’ undeclared (first use in this function)
82s] features &= ~NETIF_F_ALL_CSUM;

A kernel > 4.5 will build.
So I made a patch:

Code:

— r8168-8.041.01/src/r8168_n.c.orig 2015-10-06
08:33:04.000000000 +0200 +++ r8168-8.041.01/src/r8168_n.c
2016-03-19 18:14:35.691263375 +0100 @@ -4209,7 +4209,7 @@
spin_lock_irqsave(&tp->lock, flags);
if (dev->mtu > ETH_DATA_LEN) {
features &= ~NETIF_F_ALL_TSO;

  •            features &= ~NETIF_F_ALL_CSUM;
    
  •            features &= ~NETIF_F_CSUM_MASK;
    

}
spin_unlock_irqrestore(&tp->lock, flags);


Now it builds without any error, but only for Kernel 4.5.
In any kernel < 4.5 I get:

Code:

46s] /home/abuild/rpmbuild/BUILD/r8168-8.041.01/obj/default/r8168_n.c:4212:30:
error: ‘NETIF_F_CSUM_MASK’ undeclared (first use in this function)
46s] features &= ~NETIF_F_CSUM_MASK;

Show home:Sauerland / r8168 - openSUSE Build Service
File r8168.spec of Package r8168 - openSUSE Build Service

So I want to know, how to fix this.

Hi
Add statement around it, something like or vis-versa for versions and
statement;


#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0))
features &= ~NETIF_F_CSUM_MASK;
#else
features &= ~NETIF_F_ALL_CSUM;
#endif

Then rebase your patch.


Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
SUSE Linux Enterprise Desktop 12 SP1|GNOME 3.10.4|3.12.53-60.30-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

As already mentioned you should check kernel version in patch.

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
               features &= ~NETIF_F_ALL_CSUM;
#else
               features &= ~NETIF_F_CSUM_MASK;
#endif

Thanks, I have done it in the src, here is the patch:

--- r8168-8.041.01/src/r8168_n.c.orig	2015-10-06 08:33:04.000000000 +0200
+++ r8168-8.041.01/src/r8168_n.c	2016-03-20 19:38:27.755054590 +0100
@@ -4209,7 +4209,11 @@
         spin_lock_irqsave(&tp->lock, flags);
         if (dev->mtu > ETH_DATA_LEN) {
                 features &= ~NETIF_F_ALL_TSO;
-                features &= ~NETIF_F_ALL_CSUM;
+ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0))
+features &= ~NETIF_F_CSUM_MASK;
+#else
+features &= ~NETIF_F_ALL_CSUM;
+#endif
         }
         spin_unlock_irqrestore(&tp->lock, flags);
 

Now it builds without any error, but if it works I can check only next week…

So thanks to arvidjaar and malcolmlewis

Hi
You should advise the folks you downloaded it from and send them the patch… :wink: