1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils flag-o-matic linux-info linux-mod multilib nvidia-driver \
8 portability toolchain-funcs unpacker user udev
10 NV_URI="http://us.download.nvidia.com/XFree86/"
11 X86_NV_PACKAGE="NVIDIA-Linux-x86-${PV}"
12 AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${PV}"
13 X86_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86-${PV}"
14 AMD64_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86_64-${PV}"
16 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
17 HOMEPAGE="http://www.nvidia.com/ http://www.nvidia.com/Download/Find.aspx"
19 amd64-fbsd? ( ${NV_URI}FreeBSD-x86_64/${PV}/${AMD64_FBSD_NV_PACKAGE}.tar.gz )
20 amd64? ( ${NV_URI}Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}.run )
21 x86-fbsd? ( ${NV_URI}FreeBSD-x86/${PV}/${X86_FBSD_NV_PACKAGE}.tar.gz )
22 x86? ( ${NV_URI}Linux-x86/${PV}/${X86_NV_PACKAGE}.run )
23 tools? ( ftp://download.nvidia.com/XFree86/nvidia-settings/nvidia-settings-${PV}.tar.bz2 )
26 LICENSE="GPL-2 NVIDIA-r2"
28 KEYWORDS="-* ~amd64 ~x86 ~amd64-fbsd ~x86-fbsd"
29 RESTRICT="bindist mirror"
32 IUSE="acpi compat +driver gtk3 kernel_FreeBSD kernel_linux +kms multilib pax_kernel static-libs +tools uvm +X"
35 static-libs? ( tools )
39 app-eselect/eselect-opencl
40 kernel_linux? ( >=sys-libs/glibc-2.6.1 )
45 gtk3? ( x11-libs/gtk+:3 )
47 x11-libs/gdk-pixbuf[X]
57 >=app-eselect/eselect-opengl-1.0.9
63 kernel_linux? ( virtual/linux-sources )
67 acpi? ( sys-power/acpid )
68 tools? ( !media-video/nvidia-settings )
70 <x11-base/xorg-server-1.18.99:=
71 >=x11-libs/libvdpau-1.0
73 >=x11-libs/libX11-1.6.2[abi_x86_32]
74 >=x11-libs/libXext-1.3.2[abi_x86_32]
79 QA_PREBUILT="opt/* usr/lib*"
84 if use amd64 && has_multilib_profile && \
85 [ "${DEFAULT_ABI}" != "amd64" ]; then
86 eerror "This ebuild doesn't currently support changing your default ABI"
87 die "Unexpected \${DEFAULT_ABI} = ${DEFAULT_ABI}"
90 if use kernel_linux && kernel_is ge 4 5; then
91 ewarn "Gentoo supports kernels which are supported by NVIDIA"
92 ewarn "which are limited to the following kernels:"
93 ewarn "<sys-kernel/gentoo-sources-4.5"
94 ewarn "<sys-kernel/vanilla-sources-4.5"
96 ewarn "You are free to utilize epatch_user to provide whatever"
97 ewarn "support you feel is appropriate, but will not receive"
98 ewarn "support as a result of those changes."
100 ewarn "Do not file a bug report about this."
104 # Since Nvidia ships many different series of drivers, we need to give the user
105 # some kind of guidance as to what version they should install. This tries
106 # to point the user in the right direction but can't be perfect. check
107 # nvidia-driver.eclass
108 nvidia-driver-check-warning
110 # Kernel features/options to check for
111 CONFIG_CHECK="~ZONE_DMA ~MTRR ~SYSVIPC ~!LOCKDEP"
112 use x86 && CONFIG_CHECK+=" ~HIGHMEM"
114 # Now do the above checks
115 use kernel_linux && check_extra_config
119 # try to turn off distcc and ccache for people that have a problem with it
120 export DISTCC_DISABLE=1
121 export CCACHE_DISABLE=1
123 if use driver && use kernel_linux; then
124 MODULE_NAMES="nvidia(video:${S}/kernel)"
125 use uvm && MODULE_NAMES+=" nvidia-uvm(video:${S}/kernel)"
126 use kms && MODULE_NAMES+=" nvidia-modeset(video:${S}/kernel)"
128 # This needs to run after MODULE_NAMES (so that the eclass checks
129 # whether the kernel supports loadable modules) but before BUILD_PARAMS
130 # is set (so that KV_DIR is populated).
133 BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
134 SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC) NV_VERBOSE=1"
136 # linux-mod_src_compile calls set_arch_to_kernel, which
137 # sets the ARCH to x86 but NVIDIA's wrapping Makefile
138 # expects x86_64 or i386 and then converts it to x86
139 # later on in the build process
140 BUILD_FIXES="ARCH=$(uname -m | sed -e 's/i.86/i386/')"
143 if use kernel_linux && kernel_is lt 2 6 9; then
144 eerror "You must build this against 2.6.9 or higher kernels."
147 # set variables to where files are in the package structure
148 if use kernel_FreeBSD; then
149 use x86-fbsd && S="${WORKDIR}/${X86_FBSD_NV_PACKAGE}"
150 use amd64-fbsd && S="${WORKDIR}/${AMD64_FBSD_NV_PACKAGE}"
154 NV_MAN="${S}/x11/man"
157 elif use kernel_linux; then
165 die "Could not determine proper NVIDIA package"
170 if use pax_kernel; then
171 ewarn "Using PAX patches is not supported. You will be asked to"
172 ewarn "use a standard kernel should you have issues. Should you"
173 ewarn "need support with these patches, contact the PaX team."
174 epatch "${FILESDIR}"/${PN}-361.28-pax.patch
177 # Allow user patches so they can support RC kernels and whatever else
182 # This is already the default on Linux, as there's no toplevel Makefile, but
183 # on FreeBSD there's one and triggers the kernel module build, as we install
184 # it by itself, pass this.
187 if use kernel_FreeBSD; then
188 MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
189 LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
190 elif use driver && use kernel_linux; then
191 MAKEOPTS=-j1 linux-mod_src_compile
195 emake -C "${S}"/nvidia-settings-${PV}/src \
198 LIBDIR="$(get_libdir)" \
199 RANLIB="$(tc-getRANLIB)" \
202 emake -C "${S}"/nvidia-settings-${PV}/src \
204 GTK3_AVAILABLE=$(usex gtk3 1 0) \
206 LIBDIR="$(get_libdir)" \
208 NV_USE_BUNDLED_LIBJANSSON=0 \
214 # Install nvidia library:
215 # the first parameter is the library to install
216 # the second parameter is the provided soversion
217 # the third parameter is the target directory if it is not /usr/lib
219 # Full path to library
223 nv_SOVER="$(scanelf -qF'%S#F' ${nv_LIB})"
228 # Get just the library name
229 nv_LIBNAME=$(basename "${nv_LIB}")
231 if [[ "${nv_DEST}" ]]; then
235 nv_DEST="/usr/$(get_libdir)"
239 # Install the library
240 ${action} ${nv_LIB} || die "failed to install ${nv_LIBNAME}"
242 # If the library has a SONAME and SONAME does not match the library name,
243 # then we need to create a symlink
244 if [[ ${nv_SOVER} ]] && ! [[ "${nv_SOVER}" = "${nv_LIBNAME}" ]]; then
245 dosym ${nv_LIBNAME} ${nv_DEST}/${nv_SOVER} \
246 || die "failed to create ${nv_DEST}/${nv_SOVER} symlink"
249 dosym ${nv_LIBNAME} ${nv_DEST}/${nv_LIBNAME/.so*/.so} \
250 || die "failed to create ${nv_LIBNAME/.so*/.so} symlink"
254 if use driver && use kernel_linux; then
255 linux-mod_src_install
258 # This file is tweaked with the appropriate video group in
259 # pkg_preinst, see bug #491414
260 insinto /etc/modprobe.d
261 newins "${FILESDIR}"/nvidia-169.07 nvidia.conf
262 doins "${FILESDIR}"/nvidia-rmmod.conf
264 # Ensures that our device nodes are created when not using X
265 exeinto "$(get_udevdir)"
266 newexe "${FILESDIR}"/nvidia-udev.sh-r1 nvidia-udev.sh
267 udev_newrules "${FILESDIR}"/nvidia.udev-rule 99-nvidia.rules
268 elif use kernel_FreeBSD; then
269 if use x86-fbsd; then
270 insinto /boot/modules
271 doins "${S}/src/nvidia.kld"
274 exeinto /boot/modules
275 doexe "${S}/src/nvidia.ko"
278 # NVIDIA kernel <-> userspace driver config lib
279 donvidia ${NV_OBJ}/libnvidia-cfg.so.${NV_SOVER}
281 # NVIDIA framebuffer capture library
282 donvidia ${NV_OBJ}/libnvidia-fbc.so.${NV_SOVER}
284 # NVIDIA video encode/decode <-> CUDA
285 if use kernel_linux; then
286 donvidia ${NV_OBJ}/libnvcuvid.so.${NV_SOVER}
287 donvidia ${NV_OBJ}/libnvidia-encode.so.${NV_SOVER}
292 insinto /usr/$(get_libdir)/xorg/modules/drivers
293 doins ${NV_X11}/nvidia_drv.so
296 donvidia ${NV_X11}/libglx.so.${NV_SOVER} \
297 /usr/$(get_libdir)/opengl/nvidia/extensions
300 if has_version '>=x11-base/xorg-server-1.16'; then
301 insinto /usr/share/X11/xorg.conf.d
302 newins {,50-}nvidia-drm-outputclass.conf
306 # OpenCL ICD for NVIDIA
307 if use kernel_linux; then
308 insinto /etc/OpenCL/vendors
309 doins ${NV_OBJ}/nvidia.icd
313 dohtml ${NV_DOC}/html/*
314 if use kernel_FreeBSD; then
315 dodoc "${NV_DOC}/README"
316 use X && doman "${NV_MAN}/nvidia-xconfig.1"
317 use tools && doman "${NV_MAN}/nvidia-settings.1"
320 newdoc "${NV_DOC}/README.txt" README
321 dodoc "${NV_DOC}/NVIDIA_Changelog"
322 doman "${NV_MAN}/nvidia-smi.1.gz"
323 use X && doman "${NV_MAN}/nvidia-xconfig.1.gz"
324 use tools && doman "${NV_MAN}/nvidia-settings.1.gz"
325 doman "${NV_MAN}/nvidia-cuda-mps-control.1.gz"
332 doexe ${NV_OBJ}/nvidia-xconfig
335 if use kernel_linux; then
336 doexe ${NV_OBJ}/nvidia-cuda-mps-control
337 doexe ${NV_OBJ}/nvidia-cuda-mps-server
338 doexe ${NV_OBJ}/nvidia-debugdump
339 doexe ${NV_OBJ}/nvidia-persistenced
340 doexe ${NV_OBJ}/nvidia-smi
342 # install nvidia-modprobe setuid and symlink in /usr/bin (bug #505092)
343 doexe ${NV_OBJ}/nvidia-modprobe
344 fowners root:video /opt/bin/nvidia-modprobe
345 fperms 4710 /opt/bin/nvidia-modprobe
346 dosym /{opt,usr}/bin/nvidia-modprobe
348 doman nvidia-cuda-mps-control.1.gz
349 doman nvidia-modprobe.1.gz
350 doman nvidia-persistenced.1.gz
351 newinitd "${FILESDIR}/nvidia-smi.init" nvidia-smi
352 newconfd "${FILESDIR}/nvidia-persistenced.conf" nvidia-persistenced
353 newinitd "${FILESDIR}/nvidia-persistenced.init" nvidia-persistenced
357 emake -C "${S}"/nvidia-settings-${PV}/src/ \
359 GTK3_AVAILABLE=$(usex gtk3 1 0) \
360 LIBDIR="${D}/usr/$(get_libdir)" \
362 NV_USE_BUNDLED_LIBJANSSON=0 \
365 if use static-libs; then
366 dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
368 insinto /usr/include/NVCtrl
369 doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
372 insinto /usr/share/nvidia/
373 doins nvidia-application-profiles-${PV}-key-documentation
377 nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
379 # There is no icon in the FreeBSD tarball.
380 use kernel_FreeBSD || \
381 doicon ${NV_OBJ}/nvidia-settings.png
383 domenu "${FILESDIR}"/nvidia-settings.desktop
385 exeinto /etc/X11/xinit/xinitrc.d
386 newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
389 dobin ${NV_OBJ}/nvidia-bug-report.sh
391 if has_multilib_profile && use multilib; then
393 for ABI in $(get_install_abis); do
402 is_final_abi || die "failed to iterate through all ABIs"
404 readme.gentoo_create_doc
408 local inslibdir=$(get_libdir)
409 local GL_ROOT="/usr/$(get_libdir)/opengl/nvidia/lib"
410 local CL_ROOT="/usr/$(get_libdir)/OpenCL/vendors/nvidia"
411 local libdir=${NV_OBJ}
413 if use kernel_linux && has_multilib_profile && [[ ${ABI} == "x86" ]]; then
419 "libEGL.so.1 ${GL_ROOT}"
420 "libEGL_nvidia.so.${NV_SOVER} ${GL_ROOT}"
421 "libGL.so.$(usex compat ${NV_SOVER} 1.0.0) ${GL_ROOT}"
422 "libGLESv1_CM.so.1 ${GL_ROOT}"
423 "libGLESv1_CM_nvidia.so.${NV_SOVER} ${GL_ROOT}"
424 "libGLESv2.so.2 ${GL_ROOT}"
425 "libGLESv2_nvidia.so.${NV_SOVER} ${GL_ROOT}"
426 "libGLX.so.0 ${GL_ROOT}"
427 "libGLX_nvidia.so.${NV_SOVER} ${GL_ROOT}"
428 "libGLdispatch.so.0 ${GL_ROOT}"
429 "libOpenCL.so.1.0.0 ${CL_ROOT}"
430 "libOpenGL.so.0 ${GL_ROOT}"
431 "libcuda.so.${NV_SOVER}"
432 "libnvcuvid.so.${NV_SOVER}"
433 "libnvidia-compiler.so.${NV_SOVER}"
434 "libnvidia-eglcore.so.${NV_SOVER}"
435 "libnvidia-encode.so.${NV_SOVER}"
436 "libnvidia-fatbinaryloader.so.${NV_SOVER}"
437 "libnvidia-fbc.so.${NV_SOVER}"
438 "libnvidia-glcore.so.${NV_SOVER}"
439 "libnvidia-glsi.so.${NV_SOVER}"
440 "libnvidia-ifr.so.${NV_SOVER}"
441 "libnvidia-opencl.so.${NV_SOVER}"
442 "libnvidia-ptxjitcompiler.so.${NV_SOVER}"
443 "libvdpau_nvidia.so.${NV_SOVER}"
446 if use kernel_linux && has_multilib_profile && [[ ${ABI} == "amd64" ]];
448 NV_GLX_LIBRARIES+=( "libnvidia-wfb.so.${NV_SOVER}" )
451 if use kernel_FreeBSD; then
452 NV_GLX_LIBRARIES+=( "libnvidia-tls.so.${NV_SOVER}" )
455 if use kernel_linux; then
457 "libnvidia-ml.so.${NV_SOVER}"
458 "tls/libnvidia-tls.so.${NV_SOVER}"
462 for NV_LIB in "${NV_GLX_LIBRARIES[@]}"; do
463 donvidia ${libdir}/${NV_LIB}
469 if use driver && use kernel_linux; then
470 linux-mod_pkg_preinst
472 local videogroup="$(egetent group video | cut -d ':' -f 3)"
473 if [ -z "${videogroup}" ]; then
474 eerror "Failed to determine the video group gid"
475 die "Failed to determine the video group gid"
478 -e "s:PACKAGE:${PF}:g" \
479 -e "s:VIDEOGID:${videogroup}:" \
480 "${D}"/etc/modprobe.d/nvidia.conf || die
484 # Clean the dynamic libGL stuff's home to ensure
485 # we dont have stale libs floating around
486 if [ -d "${ROOT}"/usr/lib/opengl/nvidia ]; then
487 rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
489 # Make sure we nuke the old nvidia-glx's env.d file
490 if [ -e "${ROOT}"/etc/env.d/09nvidia ]; then
491 rm -f "${ROOT}"/etc/env.d/09nvidia
496 use driver && use kernel_linux && linux-mod_pkg_postinst
498 # Switch to the nvidia implementation
499 use X && "${ROOT}"/usr/bin/eselect opengl set --use-old nvidia
500 "${ROOT}"/usr/bin/eselect opencl set --use-old nvidia
502 readme.gentoo_print_elog
505 elog "You have elected to not install the X.org driver. Along with"
506 elog "this the OpenGL libraries and VDPAU libraries were not"
507 elog "installed. Additionally, once the driver is loaded your card"
508 elog "and fan will run at max speed which may not be desirable."
509 elog "Use the 'nvidia-smi' init script to have your card and fan"
510 elog "speed scale appropriately."
514 elog "USE=tools controls whether the nvidia-settings application"
515 elog "is installed. If you would like to use it, enable that"
516 elog "flag and re-emerge this ebuild. Optionally you can install"
517 elog "media-video/nvidia-settings"
523 use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
527 use driver && use kernel_linux && linux-mod_pkg_postrm
528 use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11