1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 inherit eutils flag-o-matic linux-info linux-mod multilib-minimal nvidia-driver \
6 portability toolchain-funcs unpacker user udev
8 NV_URI="https://us.download.nvidia.com/XFree86/"
9 X86_NV_PACKAGE="NVIDIA-Linux-x86-${PV}"
10 AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${PV}"
11 X86_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86-${PV}"
12 AMD64_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86_64-${PV}"
14 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
15 HOMEPAGE="https://www.nvidia.com/"
17 amd64-fbsd? ( ${NV_URI}FreeBSD-x86_64/${PV}/${AMD64_FBSD_NV_PACKAGE}.tar.gz )
18 amd64? ( ${NV_URI}Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}.run )
19 x86-fbsd? ( ${NV_URI}FreeBSD-x86/${PV}/${X86_FBSD_NV_PACKAGE}.tar.gz )
20 x86? ( ${NV_URI}Linux-x86/${PV}/${X86_NV_PACKAGE}.run )
22 https://download.nvidia.com/XFree86/nvidia-settings/nvidia-settings-${PV}.tar.bz2
27 IUSE="acpi multilib kernel_FreeBSD kernel_linux static-libs +tools +X"
28 KEYWORDS="-* amd64 x86"
29 LICENSE="GPL-2 NVIDIA-r2"
33 app-eselect/eselect-opencl
34 kernel_linux? ( >=sys-libs/glibc-2.6.1 )
40 x11-libs/gdk-pixbuf[X]
47 >=app-eselect/eselect-opengl-1.0.9
53 kernel_linux? ( virtual/linux-sources )
57 acpi? ( sys-power/acpid )
58 tools? ( !media-video/nvidia-settings )
60 <x11-base/xorg-server-1.20.99:=
61 >=x11-libs/libvdpau-0.3-r1
62 sys-libs/zlib[${MULTILIB_USEDEP}]
64 >=x11-libs/libX11-1.6.2[${MULTILIB_USEDEP}]
65 >=x11-libs/libXext-1.3.2[${MULTILIB_USEDEP}]
70 REQUIRED_USE="tools? ( X )"
72 QA_PREBUILT="opt/* usr/lib*"
76 nvidia_drivers_versions_check() {
77 if use amd64 && has_multilib_profile && \
78 [ "${DEFAULT_ABI}" != "amd64" ]; then
79 eerror "This ebuild doesn't currently support changing your default ABI"
80 die "Unexpected \${DEFAULT_ABI} = ${DEFAULT_ABI}"
83 if use kernel_linux && kernel_is ge 4 18; then
84 ewarn "Gentoo supports kernels which are supported by NVIDIA"
85 ewarn "which are limited to the following kernels:"
86 ewarn "<sys-kernel/gentoo-sources-4.18"
87 ewarn "<sys-kernel/vanilla-sources-4.18"
89 ewarn "You are free to utilize eapply_user to provide whatever"
90 ewarn "support you feel is appropriate, but will not receive"
91 ewarn "support as a result of those changes."
93 ewarn "Do not file a bug report about this."
97 # Since Nvidia ships many different series of drivers, we need to give the user
98 # some kind of guidance as to what version they should install. This tries
99 # to point the user in the right direction but can't be perfect. check
100 # nvidia-driver.eclass
101 nvidia-driver-check-warning
103 # Kernel features/options to check for
104 CONFIG_CHECK="!DEBUG_MUTEXES ~!LOCKDEP ~MTRR ~SYSVIPC ~ZONE_DMA"
105 use x86 && CONFIG_CHECK+=" ~HIGHMEM"
107 # Now do the above checks
108 use kernel_linux && check_extra_config
112 nvidia_drivers_versions_check
116 nvidia_drivers_versions_check
118 # try to turn off distcc and ccache for people that have a problem with it
119 export DISTCC_DISABLE=1
120 export CCACHE_DISABLE=1
122 if use kernel_linux; then
123 MODULE_NAMES="nvidia(video:${S}/kernel)"
125 # This needs to run after MODULE_NAMES (so that the eclass checks
126 # whether the kernel supports loadable modules) but before BUILD_PARAMS
127 # is set (so that KV_DIR is populated).
130 BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
131 SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC)"
133 # linux-mod_src_compile calls set_arch_to_kernel, which
134 # sets the ARCH to x86 but NVIDIA's wrapping Makefile
135 # expects x86_64 or i386 and then converts it to x86
136 # later on in the build process
137 BUILD_FIXES="ARCH=$(uname -m | sed -e 's/i.86/i386/')"
140 # set variables to where files are in the package structure
141 if use kernel_FreeBSD; then
142 use x86-fbsd && S="${WORKDIR}/${X86_FBSD_NV_PACKAGE}"
143 use amd64-fbsd && S="${WORKDIR}/${AMD64_FBSD_NV_PACKAGE}"
147 NV_MAN="${S}/x11/man"
150 elif use kernel_linux; then
158 die "Could not determine proper NVIDIA package"
163 # Please add a brief description for every added patch
165 if use kernel_linux; then
166 if kernel_is lt 2 6 9 ; then
167 eerror "You must build this against 2.6.9 or higher kernels."
170 # If greater than 2.6.5 use M= instead of SUBDIR=
171 # convert_to_m "${NV_SRC}"/Makefile.kbuild
175 for man_file in "${NV_MAN}"/*1.gz; do
176 gunzip $man_file || die
179 # Allow user patches so they can support RC kernels and whatever else
184 # This is already the default on Linux, as there's no toplevel Makefile, but
185 # on FreeBSD there's one and triggers the kernel module build, as we install
186 # it by itself, pass this.
189 if use kernel_FreeBSD; then
190 MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
191 LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
192 elif use kernel_linux; then
193 BUILD_TARGETS=module linux-mod_src_compile
197 emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl clean
198 emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl \
201 RANLIB="$(tc-getRANLIB)" \
203 emake -C "${S}"/nvidia-settings-${PV}/src \
207 LIBDIR="$(get_libdir)" \
209 NV_USE_BUNDLED_LIBJANSSON=0 \
211 RANLIB="$(tc-getRANLIB)" \
216 # Install nvidia library:
217 # the first parameter is the library to install
218 # the second parameter is the provided soversion
219 # the third parameter is the target directory if its not /usr/lib
221 # Full path to library minus SOVER
230 if [[ -z "${MY_DEST}" ]]; then
231 MY_DEST="/usr/$(get_libdir)"
238 # Get just the library name
239 libname=$(basename $1)
241 # Install the library with the correct SOVER
242 ${action} ${MY_LIB}.${MY_SOVER} || \
243 die "failed to install ${libname}"
245 # If SOVER wasn't 1, then we need to create a .1 symlink
246 if [[ "${MY_SOVER}" != "1" ]]; then
247 dosym ${libname}.${MY_SOVER} \
248 ${MY_DEST}/${libname}.1 || \
249 die "failed to create ${libname} symlink"
252 # Always create the symlink from the raw lib to the .1
254 ${MY_DEST}/${libname} || \
255 die "failed to create ${libname} symlink"
259 if use kernel_linux; then
260 linux-mod_src_install
263 # This file is tweaked with the appropriate video group in
264 # pkg_preinst, see bug #491414
265 insinto /etc/modprobe.d
266 newins "${FILESDIR}"/nvidia-169.07 nvidia.conf
268 # Ensures that our device nodes are created when not using X
269 exeinto "$(get_udevdir)"
270 newexe "${FILESDIR}"/nvidia-udev.sh-r1 nvidia-udev.sh
271 udev_newrules "${FILESDIR}"/nvidia.udev-rule 99-nvidia.rules
272 elif use kernel_FreeBSD; then
273 if use x86-fbsd; then
274 insinto /boot/modules
275 doins "${S}/src/nvidia.kld"
278 exeinto /boot/modules
279 doexe "${S}/src/nvidia.ko"
282 # NVIDIA kernel <-> userspace driver config lib
283 donvidia "${NV_OBJ}"/libnvidia-cfg.so ${NV_SOVER}
285 # NVIDIA framebuffer capture library
286 donvidia "${NV_OBJ}"/libnvidia-fbc.so ${NV_SOVER}
288 # NVIDIA video encode/decode <-> CUDA
289 if use kernel_linux; then
290 donvidia "${NV_OBJ}"/libnvcuvid.so ${NV_SOVER}
291 donvidia "${NV_OBJ}"/libnvidia-encode.so ${NV_SOVER}
296 insinto /usr/$(get_libdir)/xorg/modules/drivers
297 doins "${NV_X11}"/nvidia_drv.so
300 donvidia "${NV_X11}"/libglx.so ${NV_SOVER} \
301 /usr/$(get_libdir)/opengl/nvidia/extensions
304 # OpenCL ICD for NVIDIA
305 if use kernel_linux; then
306 insinto /etc/OpenCL/vendors
307 doins "${NV_OBJ}"/nvidia.icd
314 doexe "${NV_OBJ}"/nvidia-xconfig
317 if use kernel_linux ; then
318 doexe "${NV_OBJ}"/nvidia-cuda-mps-control
319 doexe "${NV_OBJ}"/nvidia-cuda-mps-server
320 doexe "${NV_OBJ}"/nvidia-debugdump
321 doexe "${NV_OBJ}"/nvidia-persistenced
322 doexe "${NV_OBJ}"/nvidia-smi
324 # install nvidia-modprobe setuid and symlink in /usr/bin (bug #505092)
325 doexe "${NV_OBJ}"/nvidia-modprobe
326 fowners root:video /opt/bin/nvidia-modprobe
327 fperms 4710 /opt/bin/nvidia-modprobe
328 dosym /{opt,usr}/bin/nvidia-modprobe
330 doman nvidia-cuda-mps-control.1
331 doman nvidia-modprobe.1
332 doman nvidia-persistenced.1
333 newinitd "${FILESDIR}/nvidia-smi.init" nvidia-smi
334 newconfd "${FILESDIR}/nvidia-persistenced.conf" nvidia-persistenced
335 newinitd "${FILESDIR}/nvidia-persistenced.init" nvidia-persistenced
339 emake -C "${S}"/nvidia-settings-${PV}/src/ \
341 LIBDIR="${D}/usr/$(get_libdir)" \
343 NV_USE_BUNDLED_LIBJANSSON=0 \
346 if use static-libs; then
347 dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
349 insinto /usr/include/NVCtrl
350 doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
353 insinto /usr/share/nvidia/
354 doins nvidia-application-profiles-${PV}-key-documentation
358 nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
360 # There is no icon in the FreeBSD tarball.
361 use kernel_FreeBSD || \
362 doicon "${NV_OBJ}"/nvidia-settings.png
364 domenu "${FILESDIR}"/nvidia-settings.desktop
366 exeinto /etc/X11/xinit/xinitrc.d
367 newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
371 dobin "${NV_OBJ}"/nvidia-bug-report.sh
373 #doenvd "${FILESDIR}"/50nvidia-prelink-blacklist
375 if has_multilib_profile && use multilib ; then
377 for ABI in $(get_install_abis) ; do
386 is_final_abi || die "failed to iterate through all ABIs"
389 if use kernel_FreeBSD; then
390 dodoc "${NV_DOC}"/README
391 use X && doman "${NV_MAN}"/nvidia-xconfig.1
392 use tools && doman "${NV_MAN}"/nvidia-settings.1
395 newdoc "${NV_DOC}"/README.txt README
396 dodoc "${NV_DOC}"/NVIDIA_Changelog
397 doman "${NV_MAN}"/nvidia-smi.1
398 use X && doman "${NV_MAN}"/nvidia-xconfig.1
399 use tools && doman "${NV_MAN}"/nvidia-settings.1
400 doman "${NV_MAN}"/nvidia-cuda-mps-control.1
403 readme.gentoo_create_doc
406 dodoc -r "${NV_DOC}"/html/*
410 local inslibdir=$(get_libdir)
411 local GL_ROOT="/usr/$(get_libdir)/opengl/nvidia/lib"
412 local CL_ROOT="/usr/$(get_libdir)/OpenCL/vendors/nvidia"
413 local nv_libdir="${NV_OBJ}"
415 if use kernel_linux && has_multilib_profile && \
416 [[ ${ABI} == "x86" ]] ; then
417 nv_libdir="${NV_OBJ}"/32
422 donvidia "${nv_libdir}"/libEGL.so ${NV_SOVER} ${GL_ROOT}
423 donvidia "${nv_libdir}"/libGL.so ${NV_SOVER} ${GL_ROOT}
424 donvidia "${nv_libdir}"/libGLESv1_CM.so ${NV_SOVER} ${GL_ROOT}
425 donvidia "${nv_libdir}"/libnvidia-eglcore.so ${NV_SOVER}
426 donvidia "${nv_libdir}"/libnvidia-glcore.so ${NV_SOVER}
427 donvidia "${nv_libdir}"/libnvidia-glsi.so ${NV_SOVER}
428 donvidia "${nv_libdir}"/libnvidia-ifr.so ${NV_SOVER}
429 if use kernel_FreeBSD; then
430 donvidia "${nv_libdir}"/libnvidia-tls.so ${NV_SOVER}
432 donvidia "${nv_libdir}"/tls/libnvidia-tls.so ${NV_SOVER}
436 donvidia "${nv_libdir}"/libvdpau_nvidia.so ${NV_SOVER}
440 doexe "${nv_libdir}"/libGLESv2.so.${PV}
441 dosym libGLESv2.so.${PV} ${GL_ROOT}/libGLESv2.so.2
442 dosym libGLESv2.so.2 ${GL_ROOT}/libGLESv2.so
445 # NVIDIA monitoring library
446 if use kernel_linux ; then
447 donvidia "${nv_libdir}"/libnvidia-ml.so ${NV_SOVER}
451 if use kernel_linux; then
452 donvidia "${nv_libdir}"/libcuda.so ${NV_SOVER}
453 donvidia "${nv_libdir}"/libnvidia-compiler.so ${NV_SOVER}
454 donvidia "${nv_libdir}"/libOpenCL.so 1.0.0 ${CL_ROOT}
455 donvidia "${nv_libdir}"/libnvidia-opencl.so ${NV_SOVER}
460 if use kernel_linux; then
461 linux-mod_pkg_preinst
463 local videogroup="$(egetent group video | cut -d ':' -f 3)"
464 if [ -z "${videogroup}" ]; then
465 eerror "Failed to determine the video group gid"
466 die "Failed to determine the video group gid"
469 -e "s:PACKAGE:${PF}:g" \
470 -e "s:VIDEOGID:${videogroup}:" \
471 "${D}"/etc/modprobe.d/nvidia.conf || die
475 # Clean the dynamic libGL stuff's home to ensure
476 # we dont have stale libs floating around
477 if [ -d "${ROOT}"/usr/lib/opengl/nvidia ] ; then
478 rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
480 # Make sure we nuke the old nvidia-glx's env.d file
481 if [ -e "${ROOT}"/etc/env.d/09nvidia ] ; then
482 rm -f "${ROOT}"/etc/env.d/09nvidia
487 use kernel_linux && linux-mod_pkg_postinst
489 # Switch to the nvidia implementation
490 use X && "${ROOT}"/usr/bin/eselect opengl set --use-old nvidia
491 "${ROOT}"/usr/bin/eselect opencl set --use-old nvidia
493 readme.gentoo_print_elog
496 elog "You have elected to not install the X.org driver. Along with"
497 elog "this the OpenGL libraries and VDPAU libraries were not"
498 elog "installed. Additionally, once the driver is loaded your card"
499 elog "and fan will run at max speed which may not be desirable."
500 elog "Use the 'nvidia-smi' init script to have your card and fan"
501 elog "speed scale appropriately."
505 elog "USE=tools controls whether the nvidia-settings application"
506 elog "is installed. If you would like to use it, enable that"
507 elog "flag and re-emerge this ebuild. Optionally you can install"
508 elog "media-video/nvidia-settings"
514 use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
518 use kernel_linux && linux-mod_pkg_postrm
519 use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11