From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1048118-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 E02E1138334
	for <garchives@archives.gentoo.org>; Thu, 20 Sep 2018 10:10:58 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id EBF3AE08DA;
	Thu, 20 Sep 2018 10:10:57 +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 A8264E08DA
	for <gentoo-commits@lists.gentoo.org>; Thu, 20 Sep 2018 10:10:57 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(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 EB37A335CB7
	for <gentoo-commits@lists.gentoo.org>; Thu, 20 Sep 2018 10:10:55 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 2D06B3D3
	for <gentoo-commits@lists.gentoo.org>; Thu, 20 Sep 2018 10:10:54 +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: <1537438251.d137f978e66dc9c32fa68273c42a8cd3e821087e.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-410.57.ebuild
X-VCS-Directories: x11-drivers/nvidia-drivers/
X-VCS-Committer: jer
X-VCS-Committer-Name: Jeroen Roovers
X-VCS-Revision: d137f978e66dc9c32fa68273c42a8cd3e821087e
X-VCS-Branch: master
Date: Thu, 20 Sep 2018 10:10:54 +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: 6eefea05-24a3-4d6e-ab59-fa196cd680d4
X-Archives-Hash: efd5290246e8e3ee15d31980becb20fa

commit:     d137f978e66dc9c32fa68273c42a8cd3e821087e
Author:     Jeroen Roovers <jer <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 20 10:09:51 2018 +0000
Commit:     Jeroen Roovers <jer <AT> gentoo <DOT> org>
CommitDate: Thu Sep 20 10:10:51 2018 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d137f978

x11-drivers/nvidia-drivers: Version 410.57.

Package-Manager: Portage-2.3.49, Repoman-2.3.10

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

diff --git a/x11-drivers/nvidia-drivers/Manifest b/x11-drivers/nvidia-drivers/Manifest
index dc242c51638..148f3f2d503 100644
--- a/x11-drivers/nvidia-drivers/Manifest
+++ b/x11-drivers/nvidia-drivers/Manifest
@@ -15,6 +15,7 @@ DIST NVIDIA-FreeBSD-x86_64-384.130.tar.gz 62901704 BLAKE2B 50be9af398f88caa012a7
 DIST NVIDIA-FreeBSD-x86_64-387.34.tar.gz 63387097 BLAKE2B 53689ba098b4a4de08dca056618ea533c92d17137ec954dea0ae71e1b2c825c021979871e4ff82c820be0a78d3c365f282b760940ebe2caa1ca5bfd2453e178e SHA512 0a905ee72ee6f4e9c941e5dd1f7cddf96bfb20c6da32fd05599258e1bb154f68463d775ba8ff4f67f0d4b8e637e9ed9624fc9a4873a1f2621dc86732f0d6d70d
 DIST NVIDIA-FreeBSD-x86_64-390.87.tar.gz 63648591 BLAKE2B 88aa38b11b64b2ad91f723ec84a2adb6829571136aabb1441a9119418395d5f143736487902f0c60b49ebc1284f3100fbd089e4c941cdd3519ab8511cc1d3261 SHA512 0865fef8b8a3be8f6d9fc81908b162fd6062ba0ea81fd00200e7b2a1e3149ef62408b46bc4ccb7a77f1ac943557a22b13a10cfdde084f0b76cf2b23432e57540
 DIST NVIDIA-FreeBSD-x86_64-396.54.tar.gz 60938322 BLAKE2B a23488b625a15703b0c40bc6871314b05d117d489f64a6f7c70ac3c934b02028b9623be10f0369c98c7d3b5e018e1eb6f1d2cde9d9e1b90be5065f06f6a646dd SHA512 52df85364bfd45a23394078855859ce85de996f7990bb96ba63eb33e516c3cf8e72c4391af9817213f735286f2cf6444bc8ed00312365f12ae17373cfbdc3fc7
+DIST NVIDIA-FreeBSD-x86_64-410.57.tar.gz 62103893 BLAKE2B 30313d5d0759e85ca9679e2fd5f7a6b816bf9d7b3afcb068b9de50639461d15ef3e1e0b552430271cfbfed32b20762f9bf439ed5f9450b3741c8b3436ac12cdf SHA512 1a7f0d32ce7619ebb9f6f1c1de3c1ef50747fe10864480529d6602534657cc8b9200970da080dfc0440963c00e9fb23f11e1904ced4898010757946c967af8a1
 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
@@ -38,6 +39,7 @@ DIST NVIDIA-Linux-x86_64-384.130.run 82260837 BLAKE2B 55b6f3627680c881821f5d20f0
 DIST NVIDIA-Linux-x86_64-387.34.run 82784271 BLAKE2B b7140d5d6a693892df50b3ad2e20387673dec6b5ac609cc0300bdc4b4a93ca94849255699126e4d55e67f10e488bfe6008e987197ea239b1a1b643b4ae5c7808 SHA512 6742768f1258a028c9ba56ad1d72f27d7eea4b6bfd324ba29c7f057ab5819816bd728aeaf2a8058031dadcd4c51bc6d08f0e0e0e26c68ed57955e90d68ac5a4b
 DIST NVIDIA-Linux-x86_64-390.87.run 82690871 BLAKE2B b43a45a7d48160a72185417360a4ff4238922f6d77c7b58c0562f0e01c8aa33e89057e8a5d354e8d3c8e6fa86acf8908a6c2eab81e06158a92908eec18a9b02e SHA512 f4883744f5e07150677918669eed03c7b87774f752112aabd52d903a09ae16351b34105075da2ff0fcb7a847cf66ec17e9797826859fcaecc44fdcd464a61805
 DIST NVIDIA-Linux-x86_64-396.54.run 86946680 BLAKE2B 9b3ab39c9d09c663238d0fac6346c24feea6ecc44b0ecaf3de871522697685c1c474ec4cc83f3bab0a2bcfecc7c77acea0e6bfee6e8ca8e6883bd338fd6da8a2 SHA512 17139abe99d4f32ec87379ee57af2cc0fec7d24605b2be7e3cd6609d9fcdf871e3c1cb7414b3544e14eb32d2213fec7ac45b3261f27c8d6565d510ccb14a1247
+DIST NVIDIA-Linux-x86_64-410.57.run 107221029 BLAKE2B e873c9a21422fde847c10fd4286705e6ad6942c8a8f86cd514cbb8782f792051b1b1645990bd3a8ad025eeded853d23f9925b16a5bb108524346602462eaa1b8 SHA512 2ba6b4b7829410152e0fa57772969ca59f134995ef93d08c12cc6a7a97e081c1d718600a25f541444ce66603ed84b99e66b0ced6fb773ca40f98cd5dc1348d79
 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
@@ -47,3 +49,4 @@ DIST nvidia-settings-384.130.tar.bz2 1633217 BLAKE2B ffc1381e680e94aee95752074c3
 DIST nvidia-settings-387.34.tar.gz 1267616 BLAKE2B 62d2fd329417f54bf384918889603921065e0ef6d4fb691e914534a75ab0062a17d8f886c593cf772d29bb6b56ce30aaf7b1548191b2f9ad5fbee71770ed5308 SHA512 559c859c0740575ab93edce013587250b98d7d2cd55198b5103fe97423d31ed9f113d83c240c402404de88074c285a07e46342538610d3d5dade7bed59d60090
 DIST nvidia-settings-390.87.tar.bz2 1109274 BLAKE2B 20eb809ceeade932e89592ac91071e6d3311f4a075812225d68342806b7ab1f9f8ed0399ea7a47241b7974311794852fd932fd8e824065589de6c124a3c81ef3 SHA512 cafdf2bfefac187409dfcffd593ff23eaba5ab7ab8dd85a9f14a4b6a47ffb3649af770bd2615887af9d30de3ef8fedaad7afc2ebe9f60a8ba7355a9004702959
 DIST nvidia-settings-396.54.tar.bz2 1116371 BLAKE2B 114b88f393b0909c8d84a56a280854e258d0e7e7ce800ee58547ef68b4989f22a3bbb380795472b8222493a988dc9308fc20ef03c81589448b518a12285cf204 SHA512 23dc3c61bef71200b3e8185940dd52a50dae7ca7f2b8a68fa96eaa937aabc87ded5d5f73081af51d1e7af2b78b0ec10ab80d28dadbcf10a046c32ec14db1d83c
+DIST nvidia-settings-410.57.tar.bz2 1115668 BLAKE2B 7c6554226110da4dcff9b71bde0f1caa9c857a170da65d0224db0c1c0445b34a91db2858d371cc1f0ddc895d361fe074b95c7c421dc55eeebe478a7faa313db8 SHA512 c909af30b31d32e1369970c9a52eae0cf8018be509ce8297f5a60d25a937ec1abe18dc6462f12c9b20fb52d83157c60af53eb599a353748ad976f7a0a67cd756

diff --git a/x11-drivers/nvidia-drivers/nvidia-drivers-410.57.ebuild b/x11-drivers/nvidia-drivers/nvidia-drivers-410.57.ebuild
new file mode 100644
index 00000000000..76fd7d20ca9
--- /dev/null
+++ b/x11-drivers/nvidia-drivers/nvidia-drivers-410.57.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 19; then
+		ewarn "Gentoo supports kernels which are supported by NVIDIA"
+		ewarn "which are limited to the following kernels:"
+		ewarn "<sys-kernel/gentoo-sources-4.19"
+		ewarn "<sys-kernel/vanilla-sources-4.19"
+		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}/libglxserver_nvidia.so.${NV_SOVER} \
+			/usr/$(get_libdir)/xorg/modules/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.1.0"
+			)
+		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
+}