From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1037854-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id B219D138334
	for <garchives@archives.gentoo.org>; Sat, 21 Jul 2018 12:35:56 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 892F7E083B;
	Sat, 21 Jul 2018 12:35:55 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 47280E083B
	for <gentoo-commits@lists.gentoo.org>; Sat, 21 Jul 2018 12:35:55 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 6D546335CA0
	for <gentoo-commits@lists.gentoo.org>; Sat, 21 Jul 2018 12:35:53 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 3F02837C
	for <gentoo-commits@lists.gentoo.org>; Sat, 21 Jul 2018 12:35:51 +0000 (UTC)
From: "Jeroen Roovers" <jer@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Jeroen Roovers" <jer@gentoo.org>
Message-ID: <1532176547.be1bc16c9619240b206625cf49818e002ce597eb.jer@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: x11-drivers/nvidia-drivers/
X-VCS-Repository: repo/gentoo
X-VCS-Files: x11-drivers/nvidia-drivers/Manifest x11-drivers/nvidia-drivers/nvidia-drivers-396.45.ebuild
X-VCS-Directories: x11-drivers/nvidia-drivers/
X-VCS-Committer: jer
X-VCS-Committer-Name: Jeroen Roovers
X-VCS-Revision: be1bc16c9619240b206625cf49818e002ce597eb
X-VCS-Branch: master
Date: Sat, 21 Jul 2018 12:35:51 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: fb59799d-4293-4190-924f-1a4083a1f594
X-Archives-Hash: ec266b201ccc344b59961e6cea6fa3d2

commit:     be1bc16c9619240b206625cf49818e002ce597eb
Author:     Jeroen Roovers <jer <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 21 12:35:24 2018 +0000
Commit:     Jeroen Roovers <jer <AT> gentoo <DOT> org>
CommitDate: Sat Jul 21 12:35:47 2018 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=be1bc16c

x11-drivers/nvidia-drivers: Version 396.45.

Package-Manager: Portage-2.3.43, Repoman-2.3.10

 x11-drivers/nvidia-drivers/Manifest                |   3 +
 .../nvidia-drivers/nvidia-drivers-396.45.ebuild    | 581 +++++++++++++++++++++
 2 files changed, 584 insertions(+)

diff --git a/x11-drivers/nvidia-drivers/Manifest b/x11-drivers/nvidia-drivers/Manifest
index faa5cd3f8f6..afb46c9e3c0 100644
--- a/x11-drivers/nvidia-drivers/Manifest
+++ b/x11-drivers/nvidia-drivers/Manifest
@@ -17,6 +17,7 @@ DIST NVIDIA-FreeBSD-x86_64-387.34.tar.gz 63387097 BLAKE2B 53689ba098b4a4de08dca0
 DIST NVIDIA-FreeBSD-x86_64-390.67.tar.gz 63611003 BLAKE2B 093d61fa03a64e6c61920cb23cf0d269a8933a6533dcb22c35c390d3b054a77aa0127e9c78df102ce4ba6ac333c194e6494e4700552159a798042cceeec1ce07 SHA512 c25bcc91147491762155cd6189b8b39de7529c16fc4aa30d454caf3338f11e1429c53575190f3a0afd05a77dd4a31407f941cff5608bb81a0df9b49c558b364e
 DIST NVIDIA-FreeBSD-x86_64-390.77.tar.gz 63638514 BLAKE2B 8a63f1c93cb24400ce099ffe76d2453e6980674554378a2e135e32a976212f75c335e104e52ad5039216b06286bc350e49a8fd1c61b987e1be3f3cf3bdd08f38 SHA512 f2bb8f9b5afe6ddaaa6395835592763d6f36814b37d8234f7372a0039324bcd88fa4e7f1ff5da7205bcdaac0f0d96ac8d72fe66db15e2adeee06a86fcb4d3199
 DIST NVIDIA-FreeBSD-x86_64-396.24.tar.gz 60839222 BLAKE2B 4baa266d945525a8f43d69e14df1b045d5a2e7212eb3a92208f8efb454642e657ea3cf00a9e625ef5efa9f54c8a9e2f87ef4847696368de13b88a0721364d9af SHA512 28c456cfc9f779bed84d671e104f2ea68940053aed2dc7964390e84ec553a9062be6b5108a78f123c129c25548a7b3027060da67417c64f857b23c95ae9f908b
+DIST NVIDIA-FreeBSD-x86_64-396.45.tar.gz 60850050 BLAKE2B 1bc8e761fbe38637ee17f996ec74f63c4e9da7cea6d38029fe2fcad5cd85da73e10773e019e2744d522aefecee2d6a8d3852db6ad5b9e1e746bc36ccdb4b7c9c SHA512 76955be8e86645376856bdbda7339601b88067e6b4d39b768ec86586eced7e77a437eb990bcf0fa77b3671968b00df91b53be53e1cdcd45d3e0c6a96ab5f1d77
 DIST NVIDIA-Linux-armv7l-gnueabihf-375.82.run 26650801 BLAKE2B 31446667065c56b48f6a3e737afe29a4517459d3462138136bffe383bc6fe514d6e80b49c391c27edc96b8abc3da3dd4d6ee3f3dca17f3c9a0f1cdf0e72cf099 SHA512 28554f1c24fe63c9257c0de3e84e4e739a45bf1c20ec7a53bc2c1b69b4e2355675061491ef5b03f3ae489cf623e553cfa68442f5536f137837327036d1c53d63
 DIST NVIDIA-Linux-armv7l-gnueabihf-378.13.run 26514235 BLAKE2B 2b3c540704496a290be7ae3f1ff378487c75af2298c12488da8b3a1814446e5df02a1ed99afd8ee7fc459d950aab472155359eae0bf56ac83389711d70638152 SHA512 253786a821df85fa926ae842114321b3c70502f887ea7c2b6790dfe3836039ee5d390e6722ca8785904ec6487e465916923d3042dc6191b3b4522c3161b80cb0
 DIST NVIDIA-Linux-armv7l-gnueabihf-381.22.run 26815484 BLAKE2B e5f0241b07d1e54edea2025dd30061d1018c68cc2c7136c507eb894bbad5be3d0724494e2b9f33d1f8f60da4904999bbb964e6f2e78d045d7cd86bcd46b7f6d0 SHA512 934cda37c7aed26243b5b661122e1c060de5b4df890aaf2295b6650dddea37cb4f0e3f0bebddb00b5d687b66ab5e028a203195c4d4ad3379593babda42febe77
@@ -43,6 +44,7 @@ DIST NVIDIA-Linux-x86_64-387.34.run 82784271 BLAKE2B b7140d5d6a693892df50b3ad2e2
 DIST NVIDIA-Linux-x86_64-390.67.run 82272406 BLAKE2B b0aafce048e6cf62fde5d86a2829788575709250783922d7a77c48c978dcc36961e83e2c8335ae634bef11e75e92000ffa6c5fdca56a2e6213b152f8f06cd702 SHA512 51478099a0f28674b04e87e26e0e142a0e55cc089e325de791f6b3ed99ef8d7bab074cd97e5e5144d046e970616201b0eba59f55ad958e3c435311d40e3e8dae
 DIST NVIDIA-Linux-x86_64-390.77.run 82722543 BLAKE2B 46bc7b365b4a8bd2d9444ccccec0ef427a1bbf19546db21c01d765332e8ff12fd297991166895815c96bb8d1a6153df5178578ebfaffbf7875396a8bb5578ad8 SHA512 6273ab0dee2fb70a5675166d4a49059f2cb46528408e292ac334b6210eb54be7caa56479274404ab773a4e9ba4c5a9a2e0568cb5ca7f15dea448a59ec2e72cde
 DIST NVIDIA-Linux-x86_64-396.24.run 86545234 BLAKE2B be297b4585275362608cb5119c9f7f77bcf7895bd1320603cb5f8034ee5f1dfa6d0150e58d4a11dd4656b50476d6cb6a372c18db54d33fdd685250ceb0793d3f SHA512 dfe837804d01e903cdf980353add0227362771cd252e4a7d8aff99fc489e5535edfda51ed1a20b9d60e23f1a9e7312f23309c59c67ff0a09a9b9214e52f09077
+DIST NVIDIA-Linux-x86_64-396.45.run 87016131 BLAKE2B 988392f69fc4f1f60acd03bee50245d836976728c81bbd21e5542b13e0bd93589a2bf8482d544e868f294e32de65b62c13512e465ec25afaae1ae405ae4beb3c SHA512 243253ebc83e4bc5116223ecaa29e55786a611484d9a0fba302f9f87961576bbd7f367422635725173662f013e27ef88a09f7282c9fe9912f9fe4665bdf06822
 DIST nvidia-settings-304.137.tar.bz2 1481361 BLAKE2B cf52a55a34eeb03a685a683487af6a198ba467dd8ba9983cc75624a37a226373cd931d98e8448b7b8ed430c54be2118c7b240ed2a9100b19bec5e832e2f6cdad SHA512 676d1f70c9a78ee234f5f1a283412430a386fa604de211afba02806a45906c5e246a002989b724d74752178d28c92a268de1c98d4c87876797d991253f16b0cc
 DIST nvidia-settings-340.107.tar.bz2 1549413 BLAKE2B 127442ee2c35ceec47ab4f103bdd2d0278c621fcb9be47051111f6f8728ef5699bdc95fe33a3812a807c38c4868b04c2176e2ed218a422171d2a88ac0c00de96 SHA512 593e7e83aa350a3a7beaaa32aca8660d7e203f6f2e460a6e6eabcdc092087f9917ee4e6d141e37ad4e3b0a1b9908c085e4a71d2f579e481a03bbd1c6f75ca776
 DIST nvidia-settings-375.82.tar.gz 2114647 BLAKE2B 26413fde8397e748fae362984039286c53a7fe104228452f3188b5e77b084ff4bf00131e77359ff5e92dfc325680c1f662950175cf806403d2a524ba86158f51 SHA512 7a374be56c8be52767d73a048029d9e55dc2abcf2f6a97eb4931544c927c85a1103a206be9e8d1ffcef36fec2caf2416f33699ad4d51e7dca17e4e844c37a595
@@ -53,3 +55,4 @@ DIST nvidia-settings-387.34.tar.gz 1267616 BLAKE2B 62d2fd329417f54bf384918889603
 DIST nvidia-settings-390.67.tar.bz2 1109133 BLAKE2B 3ac68f374d439c900ddbaa5eda9e3499b0f2b82871155d97319184feed0259a54d9c703d6ce98f03c15a5f47c9aa90f0684c298c7c380dbd112a67a3f89044e9 SHA512 b14df52ebf4640030ecc3a99aa42c97c361ba2c4c777a28813ab83e4ba120693b898a760846e2da33b81fc9ce2a6505c67e818ab3dc6fc580bb6cccbfcab695c
 DIST nvidia-settings-390.77.tar.bz2 1109358 BLAKE2B ee59fff5a679301b0e1f24fce3a13ee4e216d48afd73473a1ec3729067e85308d3df3b8ce1d4394b5a7836e40298c6623a0652ee3f23fbdd1a00ebdc82136f22 SHA512 130c8b9382984df597040475b29a8b61cad6eb76ef241214ab327f08a4c335176f3bda49a0c1a565a1bd8d64ab70cf1c00b7d316f343b7387dd03be7c9684f21
 DIST nvidia-settings-396.24.tar.bz2 1115673 BLAKE2B 5b0bd156505e99a5b788fc61458c902cc1760d999b18c8c6309986d8c315eabc65cb2fea9ef6a823acbe57c4a11bf67938575afffb36fea91320416fe40a7507 SHA512 841470a324bb09683fcd863474f987a525a38213432be3bf4288a48671c674692f44642d260f3d2d0710e485e323153f867d0bda4cfa9b11d0e3c61a36370353
+DIST nvidia-settings-396.45.tar.bz2 1116216 BLAKE2B 85769b7e3152bf2ff029083d5e1cf695751fa713b9db858d77f344f19266b545e8f70a07dcb3b017dd6ab901e25df6acd15a1e584bc65efec1a3d24cdd56cfca SHA512 2ec1c1e2ba79a95c1199724c476b8433ea34b7c88acfabf9b49484073d8b0251a7f466bfe71f501772915ea77fdc34b4bc539fc62e8844a06c28af7570fe0bee

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-396.45.ebuild b/x11-drivers/nvidia-drivers/nvidia-drivers-396.45.ebuild
new file mode 100644
index 00000000000..49a63be0210
--- /dev/null
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-396.45.ebuild
@@ -0,0 +1,581 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+inherit eutils flag-o-matic linux-info linux-mod multilib-minimal nvidia-driver \
+	portability toolchain-funcs unpacker user udev
+
+DESCRIPTION="NVIDIA Accelerated Graphics Driver"
+HOMEPAGE="http://www.nvidia.com/ http://www.nvidia.com/Download/Find.aspx"
+
+AMD64_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86_64-${PV}"
+AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${PV}"
+ARM_NV_PACKAGE="NVIDIA-Linux-armv7l-gnueabihf-${PV}"
+
+NV_URI="http://us.download.nvidia.com/XFree86/"
+SRC_URI="
+	amd64-fbsd? ( ${NV_URI}FreeBSD-x86_64/${PV}/${AMD64_FBSD_NV_PACKAGE}.tar.gz )
+	amd64? ( ${NV_URI}Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}.run )
+	tools? (
+		https://download.nvidia.com/XFree86/nvidia-settings/nvidia-settings-${PV}.tar.bz2
+	)
+"
+
+LICENSE="GPL-2 NVIDIA-r2"
+SLOT="0/${PV%.*}"
+KEYWORDS="-* ~amd64 ~amd64-fbsd"
+RESTRICT="bindist mirror"
+EMULTILIB_PKG="true"
+
+IUSE="acpi compat +driver gtk3 kernel_FreeBSD kernel_linux +kms multilib pax_kernel static-libs +tools uvm wayland +X"
+REQUIRED_USE="
+	tools? ( X )
+	static-libs? ( tools )
+"
+
+COMMON="
+	app-eselect/eselect-opencl
+	kernel_linux? ( >=sys-libs/glibc-2.6.1 )
+	tools? (
+		dev-libs/atk
+		dev-libs/glib:2
+		dev-libs/jansson
+		gtk3? (
+			x11-libs/gtk+:3
+		)
+		x11-libs/cairo
+		x11-libs/gdk-pixbuf[X]
+		x11-libs/gtk+:2
+		x11-libs/libX11
+		x11-libs/libXext
+		x11-libs/libXrandr
+		x11-libs/libXv
+		x11-libs/libXxf86vm
+		x11-libs/pango[X]
+	)
+	X? (
+		>=app-eselect/eselect-opengl-1.0.9
+		app-misc/pax-utils
+	)
+"
+DEPEND="
+	${COMMON}
+	kernel_linux? ( virtual/linux-sources )
+	tools? ( sys-apps/dbus )
+"
+RDEPEND="
+	${COMMON}
+	acpi? ( sys-power/acpid )
+	tools? ( !media-video/nvidia-settings )
+	wayland? ( dev-libs/wayland[${MULTILIB_USEDEP}] )
+	X? (
+		<x11-base/xorg-server-1.20.99:=
+		>=x11-libs/libX11-1.6.2[${MULTILIB_USEDEP}]
+		>=x11-libs/libXext-1.3.2[${MULTILIB_USEDEP}]
+		>=x11-libs/libvdpau-1.0[${MULTILIB_USEDEP}]
+		sys-libs/zlib[${MULTILIB_USEDEP}]
+	)
+"
+QA_PREBUILT="opt/* usr/lib*"
+S=${WORKDIR}/
+
+nvidia_drivers_versions_check() {
+	if use amd64 && has_multilib_profile && \
+		[ "${DEFAULT_ABI}" != "amd64" ]; then
+		eerror "This ebuild doesn't currently support changing your default ABI"
+		die "Unexpected \${DEFAULT_ABI} = ${DEFAULT_ABI}"
+	fi
+
+	if use kernel_linux && kernel_is ge 4 18; then
+		ewarn "Gentoo supports kernels which are supported by NVIDIA"
+		ewarn "which are limited to the following kernels:"
+		ewarn "<sys-kernel/gentoo-sources-4.18"
+		ewarn "<sys-kernel/vanilla-sources-4.18"
+		ewarn ""
+		ewarn "You are free to utilize epatch_user to provide whatever"
+		ewarn "support you feel is appropriate, but will not receive"
+		ewarn "support as a result of those changes."
+		ewarn ""
+		ewarn "Do not file a bug report about this."
+		ewarn ""
+	fi
+
+	# Since Nvidia ships many different series of drivers, we need to give the user
+	# some kind of guidance as to what version they should install. This tries
+	# to point the user in the right direction but can't be perfect. check
+	# nvidia-driver.eclass
+	nvidia-driver-check-warning
+
+	# Kernel features/options to check for
+	CONFIG_CHECK="~ZONE_DMA ~MTRR ~SYSVIPC ~!LOCKDEP"
+
+	# Now do the above checks
+	use kernel_linux && check_extra_config
+}
+
+pkg_pretend() {
+	nvidia_drivers_versions_check
+}
+
+pkg_setup() {
+	nvidia_drivers_versions_check
+
+	# try to turn off distcc and ccache for people that have a problem with it
+	export DISTCC_DISABLE=1
+	export CCACHE_DISABLE=1
+
+	if use driver && use kernel_linux; then
+		MODULE_NAMES="nvidia(video:${S}/kernel)"
+		use uvm && MODULE_NAMES+=" nvidia-uvm(video:${S}/kernel)"
+		use kms && MODULE_NAMES+=" nvidia-modeset(video:${S}/kernel) nvidia-drm(video:${S}/kernel)"
+
+		# This needs to run after MODULE_NAMES (so that the eclass checks
+		# whether the kernel supports loadable modules) but before BUILD_PARAMS
+		# is set (so that KV_DIR is populated).
+		linux-mod_pkg_setup
+
+		BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
+		SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC) NV_VERBOSE=1"
+
+		# linux-mod_src_compile calls set_arch_to_kernel, which
+		# sets the ARCH to x86 but NVIDIA's wrapping Makefile
+		# expects x86_64 or i386 and then converts it to x86
+		# later on in the build process
+		BUILD_FIXES="ARCH=$(uname -m | sed -e 's/i.86/i386/')"
+	fi
+
+	if use kernel_linux && kernel_is lt 2 6 9; then
+		eerror "You must build this against 2.6.9 or higher kernels."
+	fi
+
+	# set variables to where files are in the package structure
+	if use kernel_FreeBSD; then
+		use amd64-fbsd && S="${WORKDIR}/${AMD64_FBSD_NV_PACKAGE}"
+		NV_DOC="${S}/doc"
+		NV_OBJ="${S}/obj"
+		NV_SRC="${S}/src"
+		NV_MAN="${S}/x11/man"
+		NV_X11="${S}/obj"
+		NV_SOVER=1
+	elif use kernel_linux; then
+		NV_DOC="${S}"
+		NV_OBJ="${S}"
+		NV_SRC="${S}/kernel"
+		NV_MAN="${S}"
+		NV_X11="${S}"
+		NV_SOVER=${PV}
+	else
+		die "Could not determine proper NVIDIA package"
+	fi
+}
+
+src_prepare() {
+	if use pax_kernel; then
+		ewarn "Using PAX patches is not supported. You will be asked to"
+		ewarn "use a standard kernel should you have issues. Should you"
+		ewarn "need support with these patches, contact the PaX team."
+		eapply "${FILESDIR}"/${PN}-375.20-pax.patch
+	fi
+
+	local man_file
+	for man_file in "${NV_MAN}"/*1.gz; do
+		gunzip $man_file || die
+	done
+
+	if use tools; then
+		cp "${FILESDIR}"/nvidia-settings-linker.patch "${WORKDIR}" || die
+		sed -i \
+			-e "s:@PV@:${PV}:g" \
+			"${WORKDIR}"/nvidia-settings-linker.patch || die
+		eapply "${WORKDIR}"/nvidia-settings-linker.patch
+	fi
+
+	default
+
+	if ! [ -f nvidia_icd.json ]; then
+		cp nvidia_icd.json.template nvidia_icd.json || die
+		sed -i -e 's:__NV_VK_ICD__:libGLX_nvidia.so.0:g' nvidia_icd.json || die
+	fi
+}
+
+src_compile() {
+	# This is already the default on Linux, as there's no toplevel Makefile, but
+	# on FreeBSD there's one and triggers the kernel module build, as we install
+	# it by itself, pass this.
+
+	cd "${NV_SRC}"
+	if use kernel_FreeBSD; then
+		MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
+			LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
+	elif use driver && use kernel_linux; then
+		MAKEOPTS=-j1 linux-mod_src_compile
+	fi
+
+	if use tools; then
+		emake -C "${S}"/nvidia-settings-${PV}/src \
+			AR="$(tc-getAR)" \
+			CC="$(tc-getCC)" \
+			DO_STRIP= \
+			LD="$(tc-getCC)" \
+			LIBDIR="$(get_libdir)" \
+			NVLD="$(tc-getLD)" \
+			NV_VERBOSE=1 \
+			RANLIB="$(tc-getRANLIB)" \
+			build-xnvctrl
+
+		emake -C "${S}"/nvidia-settings-${PV}/src \
+			CC="$(tc-getCC)" \
+			DO_STRIP= \
+			GTK3_AVAILABLE=$(usex gtk3 1 0) \
+			LD="$(tc-getCC)" \
+			LIBDIR="$(get_libdir)" \
+			NVLD="$(tc-getLD)" \
+			NVML_ENABLED=0 \
+			NV_USE_BUNDLED_LIBJANSSON=0 \
+			NV_VERBOSE=1
+	fi
+}
+
+# Install nvidia library:
+# the first parameter is the library to install
+# the second parameter is the provided soversion
+# the third parameter is the target directory if it is not /usr/lib
+donvidia() {
+	# Full path to library
+	nv_LIB="${1}"
+
+	# SOVER to use
+	nv_SOVER="$(scanelf -qF'%S#F' ${nv_LIB})"
+
+	# Where to install
+	nv_DEST="${2}"
+
+	# Get just the library name
+	nv_LIBNAME=$(basename "${nv_LIB}")
+
+	if [[ "${nv_DEST}" ]]; then
+		exeinto ${nv_DEST}
+		action="doexe"
+	else
+		nv_DEST="/usr/$(get_libdir)"
+		action="dolib.so"
+	fi
+
+	# Install the library
+	${action} ${nv_LIB} || die "failed to install ${nv_LIBNAME}"
+
+	# If the library has a SONAME and SONAME does not match the library name,
+	# then we need to create a symlink
+	if [[ ${nv_SOVER} ]] && ! [[ "${nv_SOVER}" = "${nv_LIBNAME}" ]]; then
+		dosym ${nv_LIBNAME} ${nv_DEST}/${nv_SOVER} \
+			|| die "failed to create ${nv_DEST}/${nv_SOVER} symlink"
+	fi
+
+	dosym ${nv_LIBNAME} ${nv_DEST}/${nv_LIBNAME/.so*/.so} \
+		|| die "failed to create ${nv_LIBNAME/.so*/.so} symlink"
+}
+
+src_install() {
+	if use driver && use kernel_linux; then
+		linux-mod_src_install
+
+		# Add the aliases
+		# This file is tweaked with the appropriate video group in
+		# pkg_preinst, see bug #491414
+		insinto /etc/modprobe.d
+		newins "${FILESDIR}"/nvidia-169.07 nvidia.conf
+		doins "${FILESDIR}"/nvidia-rmmod.conf
+
+		# Ensures that our device nodes are created when not using X
+		exeinto "$(get_udevdir)"
+		newexe "${FILESDIR}"/nvidia-udev.sh-r1 nvidia-udev.sh
+		udev_newrules "${FILESDIR}"/nvidia.udev-rule 99-nvidia.rules
+	elif use kernel_FreeBSD; then
+		if use x86-fbsd; then
+			insinto /boot/modules
+			doins "${S}/src/nvidia.kld"
+		fi
+
+		exeinto /boot/modules
+		doexe "${S}/src/nvidia.ko"
+	fi
+
+	# NVIDIA kernel <-> userspace driver config lib
+	donvidia ${NV_OBJ}/libnvidia-cfg.so.${NV_SOVER}
+
+	# NVIDIA framebuffer capture library
+	donvidia ${NV_OBJ}/libnvidia-fbc.so.${NV_SOVER}
+
+	# NVIDIA video encode/decode <-> CUDA
+	if use kernel_linux; then
+		donvidia ${NV_OBJ}/libnvcuvid.so.${NV_SOVER}
+		donvidia ${NV_OBJ}/libnvidia-encode.so.${NV_SOVER}
+	fi
+
+	if use X; then
+		# Xorg DDX driver
+		insinto /usr/$(get_libdir)/xorg/modules/drivers
+		doins ${NV_X11}/nvidia_drv.so
+
+		# Xorg GLX driver
+		donvidia ${NV_X11}/libglx.so.${NV_SOVER} \
+			/usr/$(get_libdir)/opengl/nvidia/extensions
+
+		# Xorg nvidia.conf
+		if has_version '>=x11-base/xorg-server-1.16'; then
+			insinto /usr/share/X11/xorg.conf.d
+			newins {,50-}nvidia-drm-outputclass.conf
+		fi
+
+		insinto /usr/share/glvnd/egl_vendor.d
+		doins ${NV_X11}/10_nvidia.json
+	fi
+
+	if use wayland; then
+		insinto /usr/share/egl/egl_external_platform.d
+		doins ${NV_X11}/10_nvidia_wayland.json
+	fi
+
+	# OpenCL ICD for NVIDIA
+	if use kernel_linux; then
+		insinto /etc/OpenCL/vendors
+		doins ${NV_OBJ}/nvidia.icd
+	fi
+
+	# Documentation
+	if use kernel_FreeBSD; then
+		dodoc "${NV_DOC}/README"
+		use X && doman "${NV_MAN}"/nvidia-xconfig.1
+		use tools && doman "${NV_MAN}"/nvidia-settings.1
+	else
+		# Docs
+		newdoc "${NV_DOC}/README.txt" README
+		dodoc "${NV_DOC}/NVIDIA_Changelog"
+		doman "${NV_MAN}"/nvidia-smi.1
+		use X && doman "${NV_MAN}"/nvidia-xconfig.1
+		use tools && doman "${NV_MAN}"/nvidia-settings.1
+		doman "${NV_MAN}"/nvidia-cuda-mps-control.1
+	fi
+
+	docinto html
+	dodoc -r ${NV_DOC}/html/*
+
+	# Helper Apps
+	exeinto /opt/bin/
+
+	if use X; then
+		doexe ${NV_OBJ}/nvidia-xconfig
+
+		insinto /etc/vulkan/icd.d
+		doins nvidia_icd.json
+	fi
+
+	if use kernel_linux; then
+		doexe ${NV_OBJ}/nvidia-cuda-mps-control
+		doexe ${NV_OBJ}/nvidia-cuda-mps-server
+		doexe ${NV_OBJ}/nvidia-debugdump
+		doexe ${NV_OBJ}/nvidia-persistenced
+		doexe ${NV_OBJ}/nvidia-smi
+
+		# install nvidia-modprobe setuid and symlink in /usr/bin (bug #505092)
+		doexe ${NV_OBJ}/nvidia-modprobe
+		fowners root:video /opt/bin/nvidia-modprobe
+		fperms 4710 /opt/bin/nvidia-modprobe
+		dosym /{opt,usr}/bin/nvidia-modprobe
+
+		doman nvidia-cuda-mps-control.1
+		doman nvidia-modprobe.1
+		doman nvidia-persistenced.1
+		newinitd "${FILESDIR}/nvidia-smi.init" nvidia-smi
+		newconfd "${FILESDIR}/nvidia-persistenced.conf" nvidia-persistenced
+		newinitd "${FILESDIR}/nvidia-persistenced.init" nvidia-persistenced
+	fi
+
+	if use tools; then
+		emake -C "${S}"/nvidia-settings-${PV}/src/ \
+			DESTDIR="${D}" \
+			GTK3_AVAILABLE=$(usex gtk3 1 0) \
+			LIBDIR="${D}/usr/$(get_libdir)" \
+			NV_USE_BUNDLED_LIBJANSSON=0 \
+			NV_VERBOSE=1 \
+			PREFIX=/usr \
+			DO_STRIP= \
+			install
+
+		if use static-libs; then
+			dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
+
+			insinto /usr/include/NVCtrl
+			doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
+		fi
+
+		insinto /usr/share/nvidia/
+		doins nvidia-application-profiles-${PV}-key-documentation
+
+		insinto /etc/nvidia
+		newins \
+			nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
+
+		# There is no icon in the FreeBSD tarball.
+		use kernel_FreeBSD || \
+			doicon ${NV_OBJ}/nvidia-settings.png
+
+		domenu "${FILESDIR}"/nvidia-settings.desktop
+
+		exeinto /etc/X11/xinit/xinitrc.d
+		newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
+	fi
+
+	dobin ${NV_OBJ}/nvidia-bug-report.sh
+
+	if has_multilib_profile && use multilib; then
+		local OABI=${ABI}
+		for ABI in $(get_install_abis); do
+			src_install-libs
+		done
+		ABI=${OABI}
+		unset OABI
+	else
+		src_install-libs
+	fi
+
+	is_final_abi || die "failed to iterate through all ABIs"
+
+	readme.gentoo_create_doc
+}
+
+src_install-libs() {
+	local inslibdir=$(get_libdir)
+	local GL_ROOT="/usr/$(get_libdir)/opengl/nvidia/lib"
+	local CL_ROOT="/usr/$(get_libdir)/OpenCL/vendors/nvidia"
+	local nv_libdir="${NV_OBJ}"
+
+	if use kernel_linux && has_multilib_profile && [[ ${ABI} == "x86" ]]; then
+		nv_libdir="${NV_OBJ}"/32
+	fi
+
+	if use X; then
+		NV_GLX_LIBRARIES=(
+			"libEGL.so.$(usex compat ${NV_SOVER} 1.1.0) ${GL_ROOT}"
+			"libEGL_nvidia.so.${NV_SOVER} ${GL_ROOT}"
+			"libGL.so.$(usex compat ${NV_SOVER} 1.7.0) ${GL_ROOT}"
+			"libGLESv1_CM.so.1.2.0 ${GL_ROOT}"
+			"libGLESv1_CM_nvidia.so.${NV_SOVER} ${GL_ROOT}"
+			"libGLESv2.so.2.1.0 ${GL_ROOT}"
+			"libGLESv2_nvidia.so.${NV_SOVER} ${GL_ROOT}"
+			"libGLX.so.0 ${GL_ROOT}"
+			"libGLX_nvidia.so.${NV_SOVER} ${GL_ROOT}"
+			"libGLdispatch.so.0 ${GL_ROOT}"
+			"libOpenCL.so.1.0.0 ${CL_ROOT}"
+			"libOpenGL.so.0 ${GL_ROOT}"
+			"libcuda.so.${NV_SOVER}"
+			"libnvcuvid.so.${NV_SOVER}"
+			"libnvidia-compiler.so.${NV_SOVER}"
+			"libnvidia-eglcore.so.${NV_SOVER}"
+			"libnvidia-encode.so.${NV_SOVER}"
+			"libnvidia-fatbinaryloader.so.${NV_SOVER}"
+			"libnvidia-fbc.so.${NV_SOVER}"
+			"libnvidia-glcore.so.${NV_SOVER}"
+			"libnvidia-glsi.so.${NV_SOVER}"
+			"libnvidia-glvkspirv.so.${NV_SOVER}"
+			"libnvidia-ifr.so.${NV_SOVER}"
+			"libnvidia-opencl.so.${NV_SOVER}"
+			"libnvidia-ptxjitcompiler.so.${NV_SOVER}"
+			"libvdpau_nvidia.so.${NV_SOVER}"
+		)
+
+		if use wayland && has_multilib_profile && [[ ${ABI} == "amd64" ]];
+		then
+			NV_GLX_LIBRARIES+=(
+				"libnvidia-egl-wayland.so.1.0.3"
+			)
+		fi
+
+		if use kernel_linux && has_multilib_profile && [[ ${ABI} == "amd64" ]];
+		then
+			NV_GLX_LIBRARIES+=(
+				"libnvidia-wfb.so.${NV_SOVER}"
+			)
+		fi
+
+		if use kernel_FreeBSD; then
+			NV_GLX_LIBRARIES+=(
+				"libnvidia-tls.so.${NV_SOVER}"
+			)
+		fi
+
+		if use kernel_linux; then
+			NV_GLX_LIBRARIES+=(
+				"libnvidia-ml.so.${NV_SOVER}"
+				"tls/libnvidia-tls.so.${NV_SOVER}"
+			)
+		fi
+
+		for NV_LIB in "${NV_GLX_LIBRARIES[@]}"; do
+			donvidia "${nv_libdir}"/${NV_LIB}
+		done
+	fi
+}
+
+pkg_preinst() {
+	if use driver && use kernel_linux; then
+		linux-mod_pkg_preinst
+
+		local videogroup="$(egetent group video | cut -d ':' -f 3)"
+		if [ -z "${videogroup}" ]; then
+			eerror "Failed to determine the video group gid"
+			die "Failed to determine the video group gid"
+		else
+			sed -i \
+				-e "s:PACKAGE:${PF}:g" \
+				-e "s:VIDEOGID:${videogroup}:" \
+				"${D}"/etc/modprobe.d/nvidia.conf || die
+		fi
+	fi
+
+	# Clean the dynamic libGL stuff's home to ensure
+	# we dont have stale libs floating around
+	if [ -d "${ROOT}"/usr/lib/opengl/nvidia ]; then
+		rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
+	fi
+	# Make sure we nuke the old nvidia-glx's env.d file
+	if [ -e "${ROOT}"/etc/env.d/09nvidia ]; then
+		rm -f "${ROOT}"/etc/env.d/09nvidia
+	fi
+}
+
+pkg_postinst() {
+	use driver && use kernel_linux && linux-mod_pkg_postinst
+
+	# Switch to the nvidia implementation
+	use X && "${ROOT}"/usr/bin/eselect opengl set --use-old nvidia
+	"${ROOT}"/usr/bin/eselect opencl set --use-old nvidia
+
+	readme.gentoo_print_elog
+
+	if ! use X; then
+		elog "You have elected to not install the X.org driver. Along with"
+		elog "this the OpenGL libraries and VDPAU libraries were not"
+		elog "installed. Additionally, once the driver is loaded your card"
+		elog "and fan will run at max speed which may not be desirable."
+		elog "Use the 'nvidia-smi' init script to have your card and fan"
+		elog "speed scale appropriately."
+		elog
+	fi
+	if ! use tools; then
+		elog "USE=tools controls whether the nvidia-settings application"
+		elog "is installed. If you would like to use it, enable that"
+		elog "flag and re-emerge this ebuild. Optionally you can install"
+		elog "media-video/nvidia-settings"
+		elog
+	fi
+}
+
+pkg_prerm() {
+	use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
+}
+
+pkg_postrm() {
+	use driver && use kernel_linux && linux-mod_pkg_postrm
+	use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
+}