File dkms-nvidia-uvm.spec of Package dkms-nvidia
#
# spec file for package dkms-nvidia-uvm
#
# Copyright (c) 2008 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 bumblebee.obs@gmail.com
#
# norootforbuild
#
%define modname nvidia-uvm
#define mirror1 http://download.nvidia.com/XFree86
#define mirror1 http://uk.download.nvidia.com/XFree86
%define mirror1 http://us.download.nvidia.com/XFree86
Name: dkms-%{modname}
Summary: Installer for the CUDA UVM kernel module
Version: %{package_ver}
Release: 0.1
Url: https://build.opensuse.org/project/show/home:Bumblebee-Project
Group: System/Kernel
License: GPL-2.0+
Vendor: The Bumblebee Project
Source0: README
Source1000: %{name}-rpmlintrc
%if 0%{?suse_version}
Conflicts: nvidia-uvm-kmp-default
Conflicts: nvidia-uvm-kmp-desktop
Conflicts: nvidia-uvm-kmp-pae
Conflicts: nvidia-uvm-kmp-xen
Conflicts: nvidia-uvm-kmp
%endif
Provides: nvidia-uvm-kernel-module = %{version}-%{release}
Requires: wget binutils gcc make patch
%if 0%{?mdkversion}
Requires: dkms-minimal
%else
Requires: dkms
%endif
Requires: nvidia-kernel-module = %{version}
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
This package will download and install the proprietary NVIDIA CUDA UVM kernel module.
http://www.nvidia.com
%prep
%if %{undefined package_name}
%{error:%%package_name missing in the Project Config}
exit -1
%endif
%if %{undefined package_ver}
%{error:%%package_ver missing in the Project Config}
exit -1
%endif
%if %{undefined md5_x86}
%{error:%%md5_x86 missing in the Project Config}
exit -1
%endif
%if %{undefined md5_x86_64}
%{error:%%md5_x86_64 missing in the Project Config}
exit -1
%endif
#
cp %SOURCE0 .
%build
%install
%pre
pushd /usr/src >/dev/null 2>&1
#
# Get the nVidia package and unpack
#
%ifarch x86_64
NV_NAME=%{package_name}_64-%{version}
if [ -f $NV_NAME.run ] ; then
#
# Check the package
#
md5sum --status -c <<EOF || rm -f $NV_NAME.run
%{md5_x86_64}
EOF
fi
#
if [ -x /usr/bin/wget ] && [ ! -f $NV_NAME.run ] ; then
#
# Get the package
#
wget %{mirror1}/Linux-x86_64/%{version}/$NV_NAME.run || { rm -f $NV_NAME.run ; exit -1 ; }
#
# Check the package
#
md5sum --status -c <<EOF || { rm -f $NV_NAME.run ; exit -1 ; }
%{md5_x86_64}
EOF
fi
%else
NV_NAME=%{package_name}-%{version}
if [ -f $NV_NAME.run ] ; then
#
# Check the nVidia package
#
md5sum --status -c <<EOF || rm -f $NV_NAME.run
%{md5_x86}
EOF
fi
#
if [ -x /usr/bin/wget ] && [ ! -f $NV_NAME.run ] ; then
#
# Get the package
#
wget %{mirror1}/Linux-x86/%{version}/$NV_NAME.run || { rm -f $NV_NAME.run ; exit -1 ; }
#
# Check the package
#
md5sum --status -c <<EOF || { rm -f $NV_NAME.run ; exit -1 ; }
%{md5_x86}
EOF
fi
%endif
#
if [ -f $NV_NAME.run ] ; then
#
# Check the nVidia package
#
sh $NV_NAME.run --check || { rm -f $NV_NAME.run ; exit -2 ; }
fi
#
if [ ! -d $NV_NAME ] && [ -f $NV_NAME.run ] ; then
#
# Unpack
#
sh $NV_NAME.run -x || { rm -f $NV_NAME.run ; exit -3 ; }
fi
#
NV_USAGE_FILE=/usr/src/$NV_NAME.usage
#
NV_USED=0
touch $NV_USAGE_FILE
source $NV_USAGE_FILE
NV_USED=$((NV_USED + 1))
echo "NV_USED=$NV_USED" > $NV_USAGE_FILE
#
popd >/dev/null 2>&1
%post
pushd /usr/src >/dev/null 2>&1
#
%ifarch x86_64
NV_NAME=%{package_name}_64-%{version}
%else
NV_NAME=%{package_name}-%{version}
%endif
#
MAJOR_VER=$( echo %{version} | cut -d '.' -f 1 )
MINOR_VER=$( echo %{version} | cut -d '.' -f 2 )
PATCH_VER=$( echo %{version} | cut -d '.' -f 3 )
#
if [ -d $NV_NAME ] ; then
#
# Install dkms sources
#
rm -rf /usr/src/%{modname}-%{version}-%{release}
mkdir -p /usr/src/%{modname}-%{version}-%{release}
cp -R $NV_NAME/kernel/* /usr/src/%{modname}-%{version}-%{release}/
cp -R $NV_NAME/LICENSE /usr/src/%{modname}-%{version}-%{release}/
cp -R $NV_NAME/README.txt /usr/src/%{modname}-%{version}-%{release}/
pushd /usr/src/%{modname}-%{version}-%{release} >/dev/null 2>&1
echo "nvidia.ko external" > Module.supported
#
# Kernel x.x patch
#
# patch -p0 < /usr/share/doc/packages/dkms-nvidia/kernel-x.x.patch
popd >/dev/null 2>&1
#
# Setup dkms.conf
#
cat > /usr/src/%{modname}-%{version}-%{release}/dkms.conf << EOF
PACKAGE_NAME=%{modname}
PACKAGE_VERSION=%{version}-%{release}
MAKE[0]="make module KERNEL_UNAME=\${kernelver} ; cd uvm ; make module KERNEL_UNAME=\${kernelver}"
CLEAN="make clean ; cd uvm ; make clean"
DEST_MODULE_LOCATION[0]="/updates/"
BUILT_MODULE_NAME[0]=%{modname}
BUILT_MODULE_LOCATION[0]="uvm/"
AUTOINSTALL="yes"
REMAKE_INITRD="yes"
NO_WEAK_MODULES="yes"
EOF
fi
#
set -x
if [ -x /usr/sbin/dkms ] ; then
/usr/sbin/dkms add -m %{modname} -v %{version}-%{release} --rpm_safe_upgrade
/usr/sbin/dkms build -m %{modname} -v %{version}-%{release}
/usr/sbin/dkms install --force -m %{modname} -v %{version}-%{release}
fi
#
popd >/dev/null 2>&1
%preun
#
# Remove the module, rmmod can fail
#
if [ -x /sbin/rmmod ] ; then
/sbin/rmmod %{modname} >/dev/null 2>&1
fi
#
# Remove the module from dkms
#
set -x
if [ -x /usr/sbin/dkms ] ; then
/usr/sbin/dkms remove -m %{modname} -v %{version}-%{release} --all --rpm_safe_upgrade || :
fi
%postun
%ifarch x86_64
NV_NAME=%{package_name}_64-%{version}
%else
NV_NAME=%{package_name}-%{version}
%endif
#
[ -d /usr/src/%{modname}-%{version}-%{release} ] && rm -rf /usr/src/%{modname}-%{version}-%{release}
#
NV_USAGE_FILE=/usr/src/$NV_NAME.usage
#
NV_USED=1
touch $NV_USAGE_FILE
source $NV_USAGE_FILE
NV_USED=$((NV_USED - 1))
echo "NV_USED=$NV_USED" > $NV_USAGE_FILE
if [ $NV_USED == 0 ] ; then
#
# Remove the sources
#
[ -d /usr/src/$NV_NAME ] && rm -rf /usr/src/$NV_NAME
[ -f /usr/src/$NV_NAME.run ] && rm -f /usr/src/$NV_NAME.run
[ -f /usr/src/$NV_NAME.usage ] && rm -f /usr/src/$NV_NAME.usage
fi
%clean
rm -rf %{buildroot}
%files
%defattr(-, root, root)
%doc README
%changelog