File dkms-nvidia.spec of Package dkms-nvidia

#
# spec file for package dkms-nvidia
#
# 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


#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 nVidia graphics driver kernel modules
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
Source1: kernel-4.2.patch
Source2: 99-nvidia-uvm.rules
Source1000: %{name}-rpmlintrc
%if 0%{?suse_version}
Conflicts: nvidia-kmp-default
Conflicts: nvidia-kmp-desktop
Conflicts: nvidia-kmp-pae
Conflicts: nvidia-kmp-xen
Conflicts: nvidia-kmp
Conflicts: nvidia-gfxG02-kmp-default
Conflicts: nvidia-gfxG02-kmp-desktop
Conflicts: nvidia-gfxG02-kmp-pae
Conflicts: nvidia-gfxG02-kmp-xen
Conflicts: nvidia-gfxG02-kmp
Obsoletes: dkms-nvidia-modeset
Obsoletes: dkms-nvidia-uvm
Obsoletes: dkms-nvidia-drm
%endif
Provides:  nvidia-kernel-module = %{version}-%{release}
Provides:  nvidia-uvm-kernel-module = %{version}-%{release}
Provides:  nvidia-modeset-kernel-module = %{version}-%{release}
Provides:  nvidia-drm-kernel-module = %{version}-%{release}
Requires:  wget binutils gcc make patch
%if 0%{?mdkversion}
Requires:  dkms-minimal
%else
Requires:  dkms
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-build


%description
This package will download and install the proprietary NVIDIA
Accelerated Linux Graphics Driver that brings accelerated 2D functionality
and high-performance OpenGL support to Linux x86 with the
use of NVIDIA graphics processing units (GPUs).

These drivers provide optimized hardware acceleration for OpenGL and X
applications and support nearly all recent NVIDIA GPU products
(see README.txt, Appendix A for a complete list of supported GPUs).
TwinView, TV-Out and flat panel displays are also supported.

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 .
#
cp %SOURCE1 .


%build


%install
install -d 755 %{buildroot}/etc/modprobe.d
echo "blacklist nouveau" > %{buildroot}/etc/modprobe.d/50-blacklist-nouveau.conf
#
install -d 755 %{buildroot}%{_libexecdir}/udev/rules.d
install -m 644 %{SOURCE2} %{buildroot}%{_libexecdir}/udev/rules.d/99-nvidia-uvm.rules

%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 4.2 patch
	#
	patch -p1 < /usr/share/doc/packages/dkms-nvidia/kernel-4.2.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' KERNEL_UNAME=\${kernelver} modules"
MAKE[1]=""
MAKE[2]=""
MAKE[3]=""
CLEAN="'make' clean"
DEST_MODULE_LOCATION[0]="/updates/"
DEST_MODULE_LOCATION[1]="/updates/"
DEST_MODULE_LOCATION[2]="/updates/"
DEST_MODULE_LOCATION[3]="/updates/"
BUILT_MODULE_NAME[0]=%{modname}
BUILT_MODULE_NAME[1]=%{modname}-modeset
BUILT_MODULE_NAME[2]=%{modname}-uvm
BUILT_MODULE_NAME[3]=%{modname}-drm
AUTOINSTALL="yes"
REMAKE_INITRD="yes"
NO_WEAK_MODULES="yes"
EOF
fi
#
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
#
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
%doc kernel-4.2.patch
%dir /etc/modprobe.d
%config /etc/modprobe.d/50-blacklist-nouveau.conf
%dir %{_libexecdir}/udev
%dir %{_libexecdir}/udev/rules.d
%{_libexecdir}/udev/rules.d/99-nvidia-uvm.rules

%changelog
openSUSE Build Service is sponsored by