File nvidia-uvm-gfxG03.spec of Package nvidia-gfxG03

# spec file for package nvidia-uvm-gfxG03
# Copyright (c) 2017 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# kABI symbols are no longer generated with openSUSE >= 13.1, since they
# became useless with zypper's 'multiversion' feature enabled for the kernel
# as default (multiple kernels can be installed at the same time; with
# different kABI symbols of course!). So it has been decided to match on the
# uname output of the kernel only. We cannot use that one for NVIDIA, since we
# only build against GA kernel. So let's get rid of this requirement.
%global __requires_exclude kernel-uname-r*

Name:           nvidia-uvm-gfxG03
Version:        340.108
Release:        0
License:        SUSE-NonFree
Summary:        NVIDIA Unified Memory kernel module
Group:          System/Kernel
Source3:        preamble-uvm
Source4:        pci_ids-%{version}
Source5:        pci_ids-%{version}.new
Source6:        pci_ids-%{version}.legacy
Source7:        README
Source8:        kmp-filelist-uvm
Source12:       my-find-supplements
NoSource:       0
NoSource:       1
NoSource:       7
Patch0:         kernel-4.11.patch
BuildRequires:  kernel-source
BuildRequires:  kernel-syms
%if 0%{?sle_version} >= 120400 && !0%{?is_opensuse} 
BuildRequires:  kernel-syms-azure
BuildRequires:  module-init-tools
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
ExclusiveArch:  %ix86 x86_64
# patch the kmp template
%define kmp_template -t
%define kmp_filelist kmp-filelist-uvm
%define kmp_post
%define kmp_preun
%if 0%{!?kmp_template_name:1}
%define kmp_template_name /usr/lib/rpm/kernel-module-subpackage
%(sed -e '/^%%post\>/ r %_sourcedir/%kmp_post' -e '/^%%preun\>/ r %_sourcedir/%kmp_preun' -e '/^Provides: multiversion(kernel)/d' %kmp_template_name >%_builddir/nvidia-kmp-template)
# moved from %kmp_post snippet to this place (boo#1145316)
%(sed -i '/^%%posttrans/i \
exit $RES' %_builddir/nvidia-kmp-template)
%define x_flavors kdump um debug xen xenpae
%if 0%{!?nvbuild:1}
%define kver %(for dir in /usr/src/linux-obj/*/*/; do make -s -C "$dir" kernelversion; break; done |perl -ne '/(\\d+)\\.(\\d+)\\.(\\d+)?/&&printf "%%d%%02d%%03d\\n",$1,$2,$3')
%if %kver >= 206027
%if %kver < 206031
%define x_flavors kdump um debug
%kernel_module_package %kmp_template %_builddir/nvidia-kmp-template -p %_sourcedir/preamble-uvm -f %_sourcedir/%kmp_filelist -x %x_flavors

# supplements no longer depend on the driver
%if 0%{?suse_version} > 1220
%if 0%{?suse_version} > 1320 || (0%{?suse_version} == 1315 && 0%{?is_opensuse})
%define pci_id_file %_sourcedir/pci_ids-%version.legacy
%define pci_id_file %_sourcedir/pci_ids-%version
%define pci_id_file %_sourcedir/
# rpm 4.9+ using the internal dependency generators
%define __ksyms_supplements %_sourcedir/my-find-supplements %pci_id_file %name
# older rpm
%define __find_supplements %_sourcedir/my-find-supplements %pci_id_file %name

The package provides the NVIDIA Unified Memory kernel module.

%package KMP
License:        SUSE-NonFree
Summary:        NVIDIA Unified Memory kernel module
Group:          System/Kernel

%description KMP
The package provides the NVIDIA Unified Memory kernel module.

echo "kver = %kver"
%setup -T -c %{name}-%{version}
%ifarch %ix86
 sh %{SOURCE0} -x
%ifarch x86_64
 sh %{SOURCE1} -x
pushd NVIDIA-Linux-x86*-%{version}*/
# apply patches here ...
%patch0 -p1
mkdir -p source/%{version}
cp -R NVIDIA-Linux-x86*-%{version}*/kernel/uvm/* source/%{version} || :
mkdir -p %{_builddir}/rm_build_dir
cp -R NVIDIA-Linux-x86*-%{version}*/kernel/* %{_builddir}/rm_build_dir
pushd source/%{version}
 # Missing PCI IDs in sle11(bnc#920799), G04 (also convering these) cannot be used for sle11!
%if 0%{?suse_version} < 1120
 cat >> %_sourcedir/pci_ids-%{version}.new << EOF
0x1340 GeForce 830A
0x1341 GeForce 840A
0x1380 GeForce GTX 750 Ti
0x1381 GeForce GTX 750
0x1382 GeForce GTX 745
0x1390 GeForce 845M
0x1391 GeForce GTX 850A
0x1392 GeForce GTX 750 Ti
0x1393 GeForce 840M
0x13BA Quadro K2200
0x13BB Quadro K620
 chmod 755 %_sourcedir/my-find-supplements*
mkdir obj
sed -i -e 's,-o "$ARCH" = "x86_64",-o "$ARCH" = "x86_64" -o "$ARCH" = "x86",' source/*/

export EXTRA_CFLAGS='-DVERSION=\"%{version}\"'
for flavor in %flavors_to_build; do
    src=/lib/modules/$(make -siC %{kernel_source $flavor} kernelrelease)/source
    rm -rf obj/$flavor
    cp -r source obj/$flavor
    make -C /usr/src/linux-obj/%_target_cpu/$flavor modules M=$PWD/obj/$flavor/%{version} SYSSRC="$src" SYSOUT=/usr/src/linux-obj/%_target_cpu/$flavor RM_OUT_DIR=%{_builddir}/rm_build_dir

### do not sign the ghost .ko file, it is generated on target system anyway
export INSTALL_MOD_PATH=%{buildroot}
export INSTALL_MOD_DIR=updates
export RM_OUT_DIR=%{_builddir}/rm_build_dir
for flavor in %flavors_to_build; do
    export SYSSRC=/lib/modules/$(make -siC %{kernel_source $flavor} kernelrelease)/source
    make -C /usr/src/linux-obj/%_target_cpu/$flavor modules_install M=$PWD/obj/$flavor/%{version}
    mkdir -p %{buildroot}/usr/src/kernel-modules/nvidia-uvm-%{version}-${flavor}
    cp -R source/%{version}/* %{buildroot}/usr/src/kernel-modules/nvidia-uvm-%{version}-${flavor}
    cp -R $RM_OUT_DIR %{buildroot}/usr/src/kernel-modules/nvidia-uvm-%{version}-${flavor}/rm
    rm -rf %{buildroot}/usr/src/kernel-modules/nvidia-uvm-%{version}-${flavor}/rm/uvm