File x11-video-nvidia.spec of Package x11-video-nvidia

#
# spec file for package x11-video-bumblebee-nvidia
#
# Copyright (c) 2009 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
# nodebuginfo


#define mirror1  http://download.nvidia.com/XFree86
#define mirror1  http://uk.download.nvidia.com/XFree86
%define mirror1  http://us.download.nvidia.com/XFree86


Name:    x11-video-nvidia
Summary: Installer for the proprietary graphics driver for GeForce 6xxx and newer GPUs
Version: %{package_ver}
Release: 0.1
Url:     https://build.opensuse.org/project/show/home:Bumblebee-Project
Group:   System/Libraries
License: GPL-2.0+
Vendor:  The Bumblebee Project
#Source0: nvidia-settings.desktop
Source1:  xorg.conf
Source2:  xorg.conf-x86_64
Source3:  README
Source4:  switch-libGL.sh
Source100: %{name}-rpmlintrc
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version}
BuildRequires: update-desktop-files
%endif
Requires:  nvidia-kernel-module = %{version}
Requires:  nvidia-compute = %{version}-%{release}
Requires:  %{name}-devel = %{version}-%{release}
#Requires:  xorg-x11-glvnd
Provides:  x11-video-nvidiaG02 = %{version}-%{release}
Provides:  x11-video-bumblebee-nvidiaG02 = %{version}-%{release}
Obsoletes: x11-video-nvidiaG02 < %{version}-%{release}
Obsoletes: x11-video-bumblebee-nvidiaG02 < %{version}-%{release}
ExclusiveArch: %ix86 x86_64


%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


%package devel
License:  GPL-2.0+
Summary:  Installer for the proprietary graphics driver for GeForce 6xxx and newer GPUs
Group:    Development/Libraries/Other
Requires: %{name} = %{version}-%{release}


%description devel
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


%ifarch x86_64
%package 32bit
License:  GPL-2.0+
Summary:  Installer for the proprietary graphics driver for GeForce 6xxx and newer GPUs
Group:    System/Libraries
Requires: %{name} = %{version}-%{release}
Requires: nvidia-compute-32bit = %{version}-%{release}
Requires: %{name}-devel-32bit = %{version}-%{release}


%description 32bit
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


%package devel-32bit
License:  GPL-2.0+
Summary:  Installer for the proprietary graphics driver for GeForce 6xxx and newer GPUs
Group:    Development/Libraries/Other
Requires: %{name}-32bit = %{version}-%{release}


%description devel-32bit
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

%endif


%package -n nvidia-compute
Summary:   Installer for the proprietary NVIDIA driver for computing with GPGPU
Group:     System/Libraries
Requires:  nvidia-kernel-module = %{version}
Provides:  nvidia-computeG02 = %{version}-%{release}
Obsoletes: nvidia-computeG02 < %{version}-%{release}


%description -n nvidia-compute
This package will download and install the proprietary NVIDIA driver
for computing with GPGPUs using CUDA or OpenCL


%package -n nvidia-compute-devel
Summary:  Installer for the proprietary NVIDIA driver for computing with GPGPU
Group:    Development/Libraries/Other
Requires: nvidia-compute = %{version}-%{release}


%description -n nvidia-compute-devel
This package will download and install the proprietary NVIDIA driver
for computing with GPGPUs using CUDA or OpenCL


%ifarch x86_64
%package -n nvidia-compute-32bit
Summary:  Installer for the proprietary NVIDIA driver for computing with GPGPU
Group:    System/Libraries
Requires: nvidia-compute = %{version}-%{release}


%description -n nvidia-compute-32bit
This package will download and install the proprietary NVIDIA driver
for computing with GPGPUs using CUDA or OpenCL


%package -n nvidia-compute-devel-32bit
Summary:  Installer for the proprietary NVIDIA driver for computing with GPGPU
Group:    Development/Libraries/Other
Requires: nvidia-compute-32bit = %{version}-%{release}


%description -n nvidia-compute-devel-32bit
This package will download and install the proprietary NVIDIA driver
for computing with GPGPUs using CUDA or OpenCL

%endif


%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 %SOURCE3 README.x11-video-nvidia
cp %SOURCE3 README.x11-video-nvidia-devel
cp %SOURCE3 README.nvidia-compute
cp %SOURCE3 README.nvidia-compute-devel
%ifarch x86_64
cp %SOURCE3 README.x11-video-nvidia-32bit
cp %SOURCE3 README.x11-video-nvidia-devel-32bit
cp %SOURCE3 README.nvidia-compute-32bit
cp %SOURCE3 README.nvidia-compute-devel-32bit
%endif


%build


%install
#
#	Setup
#
install -d %{buildroot}/etc/X11
install -d 755 %{buildroot}/usr/lib/nvidia
install -m 755 %{SOURCE4} %{buildroot}/usr/lib/nvidia/switch-libGL.sh
sed -i "s/nvidia_version/%{version}/" %{buildroot}/usr/lib/nvidia/switch-libGL.sh
%ifarch x86_64
install -d 755 %{buildroot}/usr/lib64/nvidia
install -m 755 %{SOURCE4} %{buildroot}/usr/lib64/nvidia/switch-libGL.sh
sed -i "s/nvidia_version/%{version}/" %{buildroot}/usr/lib64/nvidia/switch-libGL.sh
install -m 644 %{SOURCE2} %{buildroot}/etc/X11/xorg.conf.nvidia-example
%else
install -m 644 %{SOURCE1} %{buildroot}/etc/X11/xorg.conf.nvidia-example
%endif


%pre
pushd /usr/src >/dev/null 2>&1
#
#	Get the nVidia package and unpack
#
%ifarch x86_64
LIB=lib64
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
LIB=lib
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


%posttrans
pushd /usr/src >/dev/null 2>&1
#
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
if [ -d $NV_NAME ] ; then
	#
	#	Install
	#
	pushd $NV_NAME >/dev/null 2>&1
	install -d /usr/bin
	install -d /usr/$LIB/nvidia
	install -d /usr/$LIB/nvidia/tls
	install -d /usr/$LIB/nvidia/vdpau
	install -d /usr/$LIB/nvidia/xorg/modules/updates/drivers
	install -d /usr/$LIB/nvidia/xorg/modules/updates/extensions
	install -d /usr/share/nvidia
	install nvidia-settings /usr/bin
	install nvidia-bug-report.sh /usr/bin
	install nvidia-xconfig /usr/bin
	install nvidia-application-profiles-%{version}-key-documentation /usr/share/nvidia
	install nvidia-application-profiles-%{version}-rc /usr/share/nvidia
	install tls/libnvidia-tls.so.%{version} /usr/$LIB/nvidia/tls
	install libnvidia-cfg.so.%{version} /usr/$LIB/nvidia
	install libnvidia-compiler.so.%{version} /usr/$LIB/nvidia
	install libnvidia-eglcore.so.%{version} /usr/$LIB/nvidia
	install libnvidia-encode.so.%{version} /usr/$LIB/nvidia
	install libnvidia-fatbinaryloader.so.%{version} /usr/$LIB/nvidia
	install libnvidia-fbc.so.%{version} /usr/$LIB/nvidia
	install libnvidia-glcore.so.%{version} /usr/$LIB/nvidia
	install libnvidia-glsi.so.%{version} /usr/$LIB/nvidia
	install libnvidia-gtk2.so.%{version} /usr/$LIB/nvidia
	install libnvidia-gtk3.so.%{version} /usr/$LIB/nvidia
	install libnvidia-ifr.so.%{version} /usr/$LIB/nvidia
	install libnvidia-opencl.so.%{version} /usr/$LIB/nvidia
	install libnvidia-ptxjitcompiler.so.%{version} /usr/$LIB/nvidia
	install libnvidia-tls.so.%{version} /usr/$LIB/nvidia
	install libnvcuvid.so.%{version} /usr/$LIB/nvidia
	install libvdpau_nvidia.so.%{version} /usr/$LIB/nvidia/vdpau
#	install libvdpau_trace.so.{version} /usr/$LIB/nvidia/vdpau
	install libEGL.so.1 /usr/$LIB/nvidia
	install libEGL_nvidia.so.%{version} /usr/$LIB/nvidia
	install libGL.so.%{version} /usr/$LIB/nvidia
#	install libGL.so.1 /usr/$LIB/nvidia
	install libGLESv1_CM.so.1 /usr/$LIB/nvidia
	install libGLESv1_CM_nvidia.so.%{version} /usr/$LIB/nvidia
	install libGLESv2.so.2 /usr/$LIB/nvidia
	install libGLESv2_nvidia.so.%{version} /usr/$LIB/nvidia
#	install libGLX.so.0 /usr/$LIB/nvidia
#	install libGLX_nvidia.so.%{version} /usr/$LIB/nvidia
	install libGLdispatch.so.0 /usr/$LIB/nvidia
#	install libnvidia-wfb.so.{version} /usr/$LIB/nvidia/xorg/modules/updates
	install nvidia_drv.so /usr/$LIB/nvidia/xorg/modules/updates/drivers
	install libglx.so.%{version} /usr/$LIB/nvidia/xorg/modules/updates/extensions
	#
	#	Links
	#
#	ln -sf libnvidia-wfb.so.{version} /usr/$LIB/nvidia/xorg/modules/updates/libnvidia-wfb.so.1
	# still a lot of applications make a dlopen to the .so file
	ln -sf libnvcuvid.so.%{version} /usr/$LIB/nvidia/libnvcuvid.so.1
	ln -sf libnvidia-cfg.so.%{version} /usr/$LIB/nvidia/libnvidia-cfg.so.1
	ln -sf libvdpau_nvidia.so.%{version} /usr/$LIB/nvidia/vdpau/libvdpau_nvidia.so.1
#	ln -sf libvdpau_trace.so.{version} /usr/$LIB/nvidia/vdpau/libvdpau_trace.so.1
	ln -sf libGL.so.%{version} /usr/$LIB/nvidia/libGL.so.1
	#
	#	Documentation
	#
	install -d /usr/share/doc/packages/%name
	cp -a html /usr/share/doc/packages/%name
	install -m 644 LICENSE /usr/share/doc/packages/%name
	install -d %{_mandir}/man1
	install -m 644 *.1.gz %{_mandir}/man1
	#
	#	Setup
	#
	install -d /usr/share/pixmaps
	install -m 644 nvidia-settings.png /usr/share/pixmaps
	popd >/dev/null 2>&1
fi
#
popd >/dev/null 2>&1
#
#	Funcs
#
setup_nvidia_xorg_conf()
{
	#
	#	Is the current xorg.conf for nVidia ?
	#
	if [[ ! -n "$(cat /etc/X11/xorg.conf | sed 's/^\([ \t]*Driver[ \t]*\"nvidia\"\)/FoundMagic/' | grep 'FoundMagic')" ]] ; then
		#
		#	No nVidia driver selected in current xorg.conf, start a new one
		#
		rm -f /etc/X11/xorg.conf
		cp /etc/X11/xorg.conf.nvidia-example /etc/X11/xorg.conf
	else
		#
		#	nVidia xorg.conf found, change the module paths
		#
		if [[ ! -n "$(grep '\"Files\"' /etc/X11/xorg.conf)" ]] ; then
			#
			#	Add new section
			#
			cat >> /etc/X11/xorg.conf << EOF

Section "Files"
EndSection
EOF
		fi
		#
		#	Remove all module paths
		#
		sed -i "/^[ \t]*ModulePath.*/d" /etc/X11/xorg.conf
		#
		#	Add new paths
		#
		sed -i "s?\"Files\"?\"Files\"\n    ModulePath    \"$MODULE_PATH1\"\n    ModulePath    \"$MODULE_PATH2\"\n    ModulePath    \"$MODULE_PATH3\"?" /etc/X11/xorg.conf
	fi
}
#
#	Main
#
ARCH=$(uname -m)

if [ "$ARCH" == "x86_64" ] ; then
	MODULE_PATH1="/usr/lib64/nvidia/xorg/modules/updates"
	MODULE_PATH2="/usr/lib64/xorg/modules/updates"
	MODULE_PATH3="/usr/lib64/xorg/modules"
else
	MODULE_PATH1="/usr/lib/nvidia/xorg/modules/updates"
	MODULE_PATH2="/usr/lib/xorg/modules/updates"
	MODULE_PATH3="/usr/lib/xorg/modules"
fi

#
#	Install / Upgrade
#

#
#	Get the number of video cards
#
if [ -x /sbin/lspci ] ; then
	VIDEO_CARDS=$(/sbin/lspci -n | grep "^.* 030[02]:" | wc -l)
	NVIDIA_CARDS=$(/sbin/lspci -n -d 10de: | grep "^.* 030[02]:" | wc -l)
else
	VIDEO_CARDS=1
	NVIDIA_CARDS=0
fi
#
if [ $NVIDIA_CARDS -eq $VIDEO_CARDS ] ; then
	#
	#	All nvidia cards, install xorg.conf, library paths and Wrapper
	#
	if [ -f /etc/X11/xorg.conf ] ; then
		cp -f /etc/X11/xorg.conf /etc/X11/xorg.conf.nvidia_post
		#
		#	Check xorg.conf
		#
		setup_nvidia_xorg_conf
	else
		#
		#	If configuration for proprietary driver already exists, bring it back 
		#
		if [ -f /etc/X11/xorg.conf.nvidia_postun ] ; then
			mv /etc/X11/xorg.conf.nvidia_postun /etc/X11/xorg.conf
			#
			#	Check xorg.conf
			#
			setup_nvidia_xorg_conf
		else
			#
			#	Clean  machine, use the example
			#
			cp -f /etc/X11/xorg.conf.nvidia-example /etc/X11/xorg.conf
		fi
	fi
	#
	#	Add the libs to the dynamic lib search path
	#
%if 0%{?suse_version}
%if 0%{?suse_version} <= 1140
	#
	#	There is no nice way to add the new lib paths.
	#	We need to edit the ld.so.conf file to ensure they are first in the path.
	#
	sed -i "/^.*\/lib\/nvidia.*/d" /etc/ld.so.conf
	if [[ "$ARCH" == "x86_64" ]] ; then
		sed -i "/^.*\/lib64\/nvidia.*/d" /etc/ld.so.conf
	fi
	#
	> /etc/ld.so.conf.new
	if [[ "$ARCH" == "x86_64" ]] ; then
		echo "/usr/lib64/nvidia" >> /etc/ld.so.conf.new
		echo "/usr/lib64/nvidia/vdpau" >> /etc/ld.so.conf.new
		echo "/usr/lib64/nvidia/tls" >> /etc/ld.so.conf.new
	fi
	echo "/usr/lib/nvidia" >> /etc/ld.so.conf.new
	echo "/usr/lib/nvidia/vdpau" >> /etc/ld.so.conf.new
	echo "/usr/lib/nvidia/tls" >> /etc/ld.so.conf.new
	cat /etc/ld.so.conf >> /etc/ld.so.conf.new
	mv -f /etc/ld.so.conf.new /etc/ld.so.conf
	#
	#	Activate new search path
	#
	/sbin/ldconfig
%else
	#
	#	Use the ld.so.conf.d ( make sure it is first in the list )
	#
	> /etc/ld.so.conf.d/00-nvidia.conf
	if [[ "$ARCH" == "x86_64" ]] ; then
		echo "/usr/lib64/nvidia" >> /etc/ld.so.conf.d/00-nvidia.conf
		echo "/usr/lib64/nvidia/vdpau" >> /etc/ld.so.conf.d/00-nvidia.conf
		echo "/usr/lib64/nvidia/tls" >> /etc/ld.so.conf.d/00-nvidia.conf
	fi
	echo "/usr/lib/nvidia" >> /etc/ld.so.conf.d/00-nvidia.conf
	echo "/usr/lib/nvidia/vdpau" >> /etc/ld.so.conf.d/00-nvidia.conf
	echo "/usr/lib/nvidia/tls" >> /etc/ld.so.conf.d/00-nvidia.conf
%endif
%else
	#
	#	Use the ld.so.conf.d ( make sure it is first in the list )
	#
	> /etc/ld.so.conf.d/00-nvidia.conf
	if [[ "$ARCH" == "x86_64" ]] ; then
		echo "/usr/lib64/nvidia" >> /etc/ld.so.conf.d/00-nvidia.conf
		echo "/usr/lib64/nvidia/vdpau" >> /etc/ld.so.conf.d/00-nvidia.conf
		echo "/usr/lib64/nvidia/tls" >> /etc/ld.so.conf.d/00-nvidia.conf
	fi
	echo "/usr/lib/nvidia" >> /etc/ld.so.conf.d/00-nvidia.conf
	echo "/usr/lib/nvidia/vdpau" >> /etc/ld.so.conf.d/00-nvidia.conf
	echo "/usr/lib/nvidia/tls" >> /etc/ld.so.conf.d/00-nvidia.conf
%endif
	#
	if [[ "$ARCH" == "x86_64" ]] ; then
		pushd /usr/lib64/nvidia
		if [ -x switch-libGL.sh ] ; then
			./switch-libGL.sh nvidia 64
		fi
		popd
	else
		pushd /usr/lib/nvidia
		if [ -x switch-libGL.sh ] ; then
			./switch-libGL.sh nvidia 32
		fi
		popd
	fi
fi


%preun
%ifarch x86_64
pushd /usr/lib64/nvidia >/dev/null 2>&1
if [ -x switch-libGL.sh ] ; then
	./switch-libGL.sh mesa 64
fi
popd >/dev/null 2>&1
%else
pushd /usr/lib/nvidia >/dev/null 2>&1
if [ -x switch-libGL.sh ] ; then
	./switch-libGL.sh mesa 32
fi
popd >/dev/null 2>&1
%endif


%postun
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
#if [ "$1" == "0" ] ; then
#
rm -f /usr/bin/nvidia-settings
rm -f /usr/bin/nvidia-bug-report.sh
rm -f /usr/bin/nvidia-xconfig
rm -f /usr/$LIB/nvidia/tls/libnvidia-tls.so.*
rm -f /usr/$LIB/nvidia/libnvidia-cfg.so.*
rm -f /usr/$LIB/nvidia/libnvidia-compiler.so.*
rm -f /usr/$LIB/nvidia/libnvidia-glcore.so.*
rm -f /usr/$LIB/nvidia/libnvidia-eglcore.so.*
rm -f /usr/$LIB/nvidia/libnvidia-encode.so.*
rm -f /usr/$LIB/nvidia/libnvidia-fatbinaryloader.so.*
rm -f /usr/$LIB/nvidia/libnvidia-fbc.so.*
rm -f /usr/$LIB/nvidia/libnvidia-glsi.so.*
rm -f /usr/$LIB/nvidia/libnvidia-gtk2.so.*
rm -f /usr/$LIB/nvidia/libnvidia-gtk3.so.*
rm -f /usr/$LIB/nvidia/libnvidia-ifr.so.*
rm -f /usr/$LIB/nvidia/libnvidia-opencl.so.*
rm -f /usr/$LIB/nvidia/libnvidia-ptxjitcompiler.so.*
rm -f /usr/$LIB/nvidia/libnvidia-tls.so.*
rm -f /usr/$LIB/nvidia/libnvcuvid.so.*
rm -f /usr/$LIB/nvidia/vdpau/libvdpau_nvidia.so.*
#rm -f /usr/$LIB/nvidia/vdpau/libvdpau_trace.so.*
rm -f /usr/$LIB/nvidia/libEGL.so.*
rm -f /usr/$LIB/nvidia/libEGL_nvidia.so.*
rm -f /usr/$LIB/nvidia/libGL.so.*
rm -f /usr/$LIB/nvidia/libGLdispatch.so.*
rm -f /usr/$LIB/nvidia/libGLX.so.*
rm -f /usr/$LIB/nvidia/libGLX_nvidia.so.*
rm -f /usr/$LIB/nvidia/libGLES*
rm -f /usr/$LIB/nvidia/libXvMCNVIDIA.so.*
rm -f /usr/$LIB/nvidia/libXvMCNVIDIA_dynamic.so.*
#rm -f /usr/$LIB/nvidia/xorg/modules/updates/libnvidia-wfb.so.*
rm -f /usr/$LIB/nvidia/xorg/modules/updates/drivers/nvidia_drv.so
rm -f /usr/$LIB/nvidia/xorg/modules/updates/extensions/libglx.so.*
rm -f /usr/share/doc/packages/%name/LICENSE
rm -rf /usr/share/doc/packages/%name/html
rm -f %{_mandir}/man1/nvidia-installer.*
rm -f %{_mandir}/man1/nvidia-settings.*
rm -f %{_mandir}/man1/nvidia-smi.*
rm -f %{_mandir}/man1/nvidia-xconfig.*
#
if [ -d  /usr/$LIB/nvidia/tls ] ; then
	rm -rf /usr/$LIB/nvidia/tls
fi
if [ -d  /usr/$LIB/nvidia/vdpau ] ; then
	rm -rf /usr/$LIB/nvidia/vdpau
fi
if [ -d  /usr/$LIB/nvidia/xorg ] ; then
	rm -rf /usr/$LIB/nvidia/xorg
fi
if [ -d  /usr/share/nvidia ] ; then
	rm -rf /usr/share/nvidia
fi
#
ARCH=$(uname -m)
#
#	Cleanup dynamic library search path
#
%if 0%{?suse_version}
%if 0%{?suse_version} <= 1140
sed -i "/^.*\/lib\/nvidia.*/d" /etc/ld.so.conf
if [[ "$ARCH" == "x86_64" ]] ; then
	sed -i "/^.*\/lib64\/nvidia.*/d" /etc/ld.so.conf
fi
%else
rm -f /etc/ld.so.conf.d/00-nvidia.conf
%endif
%else
rm -f /etc/ld.so.conf.d/00-nvidia.conf
%endif
#
#	Restore xorg.conf
#
if [ -f /etc/X11/xorg.conf ] ; then
	mv -f /etc/X11/xorg.conf /etc/X11/xorg.conf.nvidia_postun
fi
if [ -r /etc/X11/xorg.conf.nvidia_post ] ; then
	mv -f /etc/X11/xorg.conf.nvidia_post /etc/X11/xorg.conf
fi
#
#fi
#
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
#
#	Activate new search path
#
/sbin/ldconfig


%pre devel
pushd /usr/src >/dev/null 2>&1
#
#	Get the nVidia package and unpack
#
%ifarch x86_64
LIB=lib64
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
LIB=lib
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


%posttrans devel
pushd /usr/src >/dev/null 2>&1
#
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
if [ -d $NV_NAME ] ; then
	#
	#	Install
	#
	pushd $NV_NAME >/dev/null 2>&1
	install -d /usr/$LIB/nvidia
	install -d /usr/$LIB/nvidia/vdpau
	install -d /usr/$LIB/nvidia/xorg/modules/updates/extensions
	#
	#	Links
	#
	ln -sf libglx.so.%{version} /usr/$LIB/nvidia/xorg/modules/updates/extensions/libglx.so
	#ln -sf libnvidia-wfb.so.{version} /usr/$LIB/nvidia/xorg/modules/updates/libnvidia-wfb.so
	# still a lot of applications make a dlopen to the .so file
	ln -sf libnvcuvid.so.%{version} /usr/$LIB/nvidia/libnvcuvid.so
	ln -sf libnvidia-cfg.so.%{version} /usr/$LIB/nvidia/libnvidia-cfg.so
	ln -sf libvdpau_nvidia.so.%{version} /usr/$LIB/nvidia/vdpau/libvdpau_nvidia.so
	#ln -sf libvdpau_trace.so.{version} /usr/$LIB/nvidia/vdpau/libvdpau_trace.so
	ln -sf libEGL.so.1 /usr/$LIB/nvidia/libEGL.so
	ln -sf libGL.so.1 /usr/$LIB/nvidia/libGL.so
	ln -sf libGLESv1_CM.so.1 /usr/$LIB/nvidia/libGLESv1_CM.so
	ln -sf libGLESv2.so.2 /usr/$LIB/nvidia/libGLESv2.so
#	ln -sf libGLX.so.0 /usr/$LIB/nvidia/libGLX.so
	popd >/dev/null 2>&1
fi
#
popd >/dev/null 2>&1
#
/sbin/ldconfig


%postun devel
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
#if [ "$1" == "0" ] ; then
#
rm -f /usr/$LIB/nvidia/libXvMCNVIDIA.a
rm -f /usr/$LIB/nvidia/xorg/modules/updates/extensions/libglx.so
#rm -f /usr/$LIB/nvidia/xorg/modules/updates/libnvidia-wfb.so
rm -f /usr/$LIB/nvidia/libnvcuvid.so
rm -f /usr/$LIB/nvidia/libnvidia-cfg.so
rm -f /usr/$LIB/nvidia/vdpau/libvdpau_nvidia.so
#rm -f /usr/$LIB/nvidia/vdpau/libvdpau_trace.so
rm -f /usr/$LIB/nvidia/libEGL.so
rm -f /usr/$LIB/nvidia/libGL.so
rm -f /usr/$LIB/nvidia/libGLESv1_CM.so
rm -f /usr/$LIB/nvidia/libGLESv2.so
rm -f /usr/$LIB/nvidia/libGLX.so
rm -f /usr/$LIB/nvidia/libXvMCNVIDIA_dynamic.so
#
#fi
#
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
#
/sbin/ldconfig


%ifarch x86_64
%pre 32bit
pushd /usr/src >/dev/null 2>&1
#
#	Get the nVidia package and unpack
#
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
#
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 /usr/src/$NV_NAME.run ] ; then
	#
	#	Unpack
	#
	sh /usr/src/$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


%posttrans 32bit
pushd /usr/src >/dev/null 2>&1
#
NV_NAME=%{package_name}_64-%{version}
#
if [ -d $NV_NAME ] ; then
	#
	#	Install
	#
	pushd $NV_NAME >/dev/null 2>&1
	install -d /usr/lib/nvidia
	install -d /usr/lib/nvidia/tls
	install -d /usr/lib/nvidia/vdpau
	install 32/tls/libnvidia-tls.so.* /usr/lib/nvidia/tls
	install 32/libnvidia-compiler.so.* /usr/lib/nvidia
	install 32/libnvidia-eglcore.so.* /usr/lib/nvidia
	install 32/libnvidia-encode.so.* /usr/lib/nvidia
	install 32/libnvidia-fatbinaryloader.so.* /usr/lib/nvidia
	install 32/libnvidia-fbc.so.* /usr/lib/nvidia
	install 32/libnvidia-glcore.so.* /usr/lib/nvidia
	install 32/libnvidia-glsi.so.* /usr/lib/nvidia
#	install 32/libnvidia-gtk2.so.* /usr/lib/nvidia
#	install 32/libnvidia-gtk3.so.* /usr/lib/nvidia
	install 32/libnvidia-ifr.so.* /usr/lib/nvidia
	install 32/libnvidia-opencl.so.* /usr/lib/nvidia
	install 32/libnvidia-ptxjitcompiler.so.* /usr/lib/nvidia
	install 32/libnvidia-tls.so.* /usr/lib/nvidia
	install 32/libvdpau_nvidia.so.* /usr/lib/nvidia/vdpau
	#install 32/libvdpau_trace.so.* /usr/lib/nvidia/vdpau
	install 32/libEGL* /usr/lib/nvidia
	install 32/libGL.so.%{version} /usr/lib/nvidia
	install 32/libGLdispatch.so.* /usr/lib/nvidia
	install 32/libGLES* /usr/lib/nvidia
#	install 32/libGLX* /usr/lib/nvidia
	install 32/libOpen* /usr/lib/nvidia
	popd  >/dev/null 2>&1
	#
	#	Links
	#
	ln -sf libvdpau_nvidia.so.%{version} /usr/lib/nvidia/vdpau/libvdpau_nvidia.so.1
	ln -sf libGL.so.%{version} /usr/lib/nvidia/libGL.so.1
	#
	#	Switch libGL
	#
	pushd /usr/lib/nvidia
	if [ -x switch-libGL.sh ] ; then
		./switch-libGL.sh nvidia 32
	fi
	popd
fi
#
popd  >/dev/null 2>&1
#
/sbin/ldconfig


%preun 32bit
pushd /usr/lib/nvidia >/dev/null 2>&1
if [ -x switch-libGL.sh ] ; then
    ./switch-libGL.sh mesa 32
fi
popd >/dev/null 2>&1


%postun 32bit
NV_NAME=%{package_name}_64-%{version}
#
#if [ "$1" == "0" ] ; then
#
rm -f /usr/lib/nvidia/tls/libnvidia-tls.so.*
rm -f /usr/lib/nvidia/libnvidia-compiler.so.*
rm -f /usr/lib/nvidia/libnvidia-eglcore.so.*
rm -f /usr/lib/nvidia/libnvidia-encode.so.*
rm -f /usr/lib/nvidia/libnvidia-fatbinaryloader.so.*
rm -f /usr/lib/nvidia/libnvidia-fbc.so.*
rm -f /usr/lib/nvidia/libnvidia-glcore.so.*
rm -f /usr/lib/nvidia/libnvidia-glsi.so.*
#rm -f /usr/lib/nvidia/libnvidia-gtk2.so.*
#rm -f /usr/lib/nvidia/libnvidia-gtk3.so.*
rm -f /usr/lib/nvidia/libnvidia-ifr.so.*
rm -f /usr/lib/nvidia/libnvidia-opencl.so.*
rm -f /usr/lib/nvidia/libnvidia-ptxjitcompiler.so.*
rm -f /usr/lib/nvidia/libnvidia-tls.so.*
rm -f /usr/lib/nvidia/vdpau/libvdpau_nvidia.so.*
rm -f /usr/lib/nvidia/vdpau/libvdpau_trace.so.*
rm -f /usr/lib/nvidia/libEGL*
rm -f /usr/lib/nvidia/libGL.so.*
rm -f /usr/lib/nvidia/libGLdispatch.so.*
rm -f /usr/lib/nvidia/libGLES*
rm -f /usr/lib/nvidia/libGLX*
rm -f /usr/lib/nvidia/libOpen*
#
if [ -d  /usr/lib/nvidia/tls ] ; then
	rm -rf /usr/lib/nvidia/tls
fi
if [ -d  /usr/lib/nvidia/vdpau ] ; then
	rm -rf /usr/lib/nvidia/vdpau
fi
#
#fi
#
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
#
/sbin/ldconfig


%posttrans devel-32bit
install -d /usr/lib/nvidia
install -d /usr/lib/nvidia/vdpau
ln -sf libvdpau_nvidia.so.%{version} /usr/lib/nvidia/vdpau/libvdpau_nvidia.so
ln -sf libEGL.so.1 /usr/lib/nvidia/libEGL.so
ln -sf libGL.so.1 /usr/lib/nvidia/libGL.so
ln -sf libGLESv1_CM.so.1 /usr/lib/nvidia/libGLESv1_CM.so
ln -sf libGLESv2.so.2 /usr/lib/nvidia/libGLESv2.so
#ln -sf libGLX.so.0 /usr/lib/nvidia/libGLX.so


%postun devel-32bit
NV_NAME=%{package_name}_64-%{version}
#
#if [ "$1" == "0" ] ; then
#
rm -f /usr/lib/nvidia/vdpau/libvdpau_nvidia.so
rm -f /usr/lib/nvidia/libEGL.so
rm -f /usr/lib/nvidia/libGL.so
rm -f /usr/lib/nvidia/libGLESv1_CM.so
rm -f /usr/lib/nvidia/libGLESv2.so
rm -f /usr/lib/nvidia/libGLX.so
#
#fi
#
/sbin/ldconfig

%endif


%pre -n nvidia-compute
pushd /usr/src >/dev/null 2>&1
#
#	Get the nVidia package and unpack
#
%ifarch x86_64
LIB=lib64
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
LIB=lib
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


%posttrans -n nvidia-compute
pushd /usr/src >/dev/null 2>&1
#
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
if [ -d $NV_NAME ] ; then
	#
	#	Install
	#
	pushd $NV_NAME >/dev/null 2>&1
	install -d /etc/OpenCL/vendors
	install -m 644 nvidia.icd /etc/OpenCL/vendors
	install -d /usr/bin
	install -d /usr/$LIB/nvidia
	install nvidia-smi /usr/bin
	install libcuda.so.* /usr/$LIB/nvidia
	install libOpenCL.so.* /usr/$LIB/nvidia
	install libOpenGL.so.* /usr/$LIB/nvidia
	install libnvidia-ml.so.* /usr/$LIB/nvidia
	OPENCL_LIB=`ls libOpenCL.so.*`
	popd >/dev/null 2>&1
	#
	#	Links
	#
	ln -sf libcuda.so.%{version} /usr/$LIB/nvidia/libcuda.so.1
	ln -sf $OPENCL_LIB /usr/$LIB/nvidia/libOpenCL.so.1
	ln -sf libnvidia-ml.so.%{version} /usr/$LIB/nvidia/libnvidia-ml.so.1
fi
#
popd >/dev/null 2>&1
#
/sbin/ldconfig


%postun -n nvidia-compute
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
#if [ "$1" == "0" ] ; then
#
rm -f /etc/OpenCL/vendors/nvidia.icd
rm -f /usr/bin/nvidia-smi
rm -f /usr/$LIB/nvidia/libcuda.so.*
rm -f /usr/$LIB/nvidia/libOpenCL.so.*
rm -f /usr/$LIB/nvidia/libOpenGL.so.*
rm -f /usr/$LIB/nvidia/libnvidia-ml.so.*
#
if [ -d  /etc/OpenCL ] ; then
	rmdir --ignore-fail-on-non-empty /etc/OpenCL/vendors
	rmdir --ignore-fail-on-non-empty /etc/OpenCL
fi
#
#fi
#
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
#
/sbin/ldconfig


%pre -n nvidia-compute-devel
pushd /usr/src >/dev/null 2>&1
#
#	Get the nVidia package and unpack
#
%ifarch x86_64
LIB=lib64
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
LIB=lib
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


%posttrans -n nvidia-compute-devel
pushd /usr/src >/dev/null 2>&1
#
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
if [ -d $NV_NAME ] ; then
	#
	#	Install
	#
	pushd $NV_NAME >/dev/null 2>&1
	install -d /usr/$LIB/nvidia
	OPENCL_LIB=`ls libOpenCL.so.*`  
	popd >/dev/null 2>&1
	#
	#	Links
	#
	ln -sf libcuda.so.%{version} /usr/$LIB/nvidia/libcuda.so
	ln -sf $OPENCL_LIB /usr/$LIB/nvidia/libOpenCL.so
	ln -sf libOpenGL.so.0 /usr/$LIB/nvidia/libOpenGL.so
	ln -sf libnvidia-ml.so.%{version} /usr/$LIB/nvidia/libnvidia-ml.so
fi
#
popd >/dev/null 2>&1
#
/sbin/ldconfig


%postun -n nvidia-compute-devel
%ifarch x86_64
LIB=lib64
NV_NAME=%{package_name}_64-%{version}
%else
LIB=lib
NV_NAME=%{package_name}-%{version}
%endif
#
#if [ "$1" == "0" ] ; then
#
rm -f /usr/$LIB/nvidia/libcuda.so
rm -f /usr/$LIB/nvidia/libOpenCL.so
rm -f /usr/$LIB/nvidia/libOpenGL.so
rm -f /usr/$LIB/nvidia/libnvidia-ml.so
#
#if [ -d  /usr/$LIB/nvidia ] ; then
#	rmdir --ignore-fail-on-non-empty /usr/$LIB/nvidia
#fi
#
#fi
#
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
#
/sbin/ldconfig


%files
%defattr(-,root,root)
%doc README.x11-video-nvidia
%config /etc/X11/xorg.conf.nvidia-example
%{_libdir}/nvidia


%files devel
%defattr(-,root,root)
%doc README.x11-video-nvidia-devel


%ifarch x86_64
%files 32bit
%defattr(-,root,root)
%doc README.x11-video-nvidia-32bit
/usr/lib/nvidia


%files devel-32bit
%defattr(-,root,root)
%doc README.x11-video-nvidia-devel-32bit
%endif


%files -n nvidia-compute
%defattr(-,root,root)
%doc README.nvidia-compute


%files -n nvidia-compute-devel
%defattr(-,root,root)
%doc README.nvidia-compute-devel


%ifarch x86_64
%files -n nvidia-compute-32bit
%defattr(-,root,root)
%doc README.nvidia-compute-32bit


%files -n nvidia-compute-devel-32bit
%defattr(-,root,root)
%doc README.nvidia-compute-devel-32bit
%endif


%changelog