x11-drivers/xf86-video-amdgpu: Update dep for IUSE=glamor removal
[gentoo.git] / x11-drivers / nvidia-drivers / nvidia-drivers-340.107-r1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 inherit eutils flag-o-matic linux-info linux-mod multilib-minimal nvidia-driver \
6         portability toolchain-funcs unpacker user udev
7
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}"
13
14 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
15 HOMEPAGE="https://www.nvidia.com/"
16 SRC_URI="
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 )
21         tools? (
22                 https://download.nvidia.com/XFree86/nvidia-settings/nvidia-settings-${PV}.tar.bz2
23         )
24 "
25
26 EMULTILIB_PKG="true"
27 IUSE="acpi multilib kernel_FreeBSD kernel_linux static-libs +tools +X"
28 KEYWORDS="-* amd64 x86"
29 LICENSE="GPL-2 NVIDIA-r2"
30 SLOT="0/${PV%.*}"
31
32 COMMON="
33         app-eselect/eselect-opencl
34         kernel_linux? ( >=sys-libs/glibc-2.6.1 )
35         tools? (
36                 >=x11-libs/gtk+-2.4:2
37                 dev-libs/atk
38                 dev-libs/glib:2
39                 dev-libs/jansson
40                 x11-libs/gdk-pixbuf[X]
41                 x11-libs/libX11
42                 x11-libs/libXext
43                 x11-libs/libXv
44                 x11-libs/pango[X]
45         )
46         X? (
47                 >=app-eselect/eselect-opengl-1.0.9
48         )
49 "
50 DEPEND="
51         ${COMMON}
52         app-arch/xz-utils
53         kernel_linux? ( virtual/linux-sources )
54 "
55 RDEPEND="
56         ${COMMON}
57         acpi? ( sys-power/acpid )
58         tools? ( !media-video/nvidia-settings )
59         X? (
60                 <x11-base/xorg-server-1.20.99:=
61                 >=x11-libs/libvdpau-0.3-r1
62                 sys-libs/zlib[${MULTILIB_USEDEP}]
63                 multilib? (
64                         >=x11-libs/libX11-1.6.2[${MULTILIB_USEDEP}]
65                         >=x11-libs/libXext-1.3.2[${MULTILIB_USEDEP}]
66                 )
67         )
68 "
69
70 REQUIRED_USE="tools? ( X )"
71
72 QA_PREBUILT="opt/* usr/lib*"
73
74 S=${WORKDIR}/
75
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}"
81         fi
82
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"
88                 ewarn ""
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."
92                 ewarn ""
93                 ewarn "Do not file a bug report about this."
94                 ewarn ""
95         fi
96
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
102
103         # Kernel features/options to check for
104         CONFIG_CHECK="!DEBUG_MUTEXES ~!LOCKDEP ~MTRR ~SYSVIPC ~ZONE_DMA"
105         use x86 && CONFIG_CHECK+=" ~HIGHMEM"
106
107         # Now do the above checks
108         use kernel_linux && check_extra_config
109 }
110
111 pkg_pretend() {
112         nvidia_drivers_versions_check
113 }
114
115 pkg_setup() {
116         nvidia_drivers_versions_check
117
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
121
122         if use kernel_linux; then
123                 MODULE_NAMES="nvidia(video:${S}/kernel)"
124
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).
128                 linux-mod_pkg_setup
129
130                 BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
131                 SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC)"
132
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/')"
138         fi
139
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}"
144                 NV_DOC="${S}/doc"
145                 NV_OBJ="${S}/obj"
146                 NV_SRC="${S}/src"
147                 NV_MAN="${S}/x11/man"
148                 NV_X11="${S}/obj"
149                 NV_SOVER=1
150         elif use kernel_linux; then
151                 NV_DOC="${S}"
152                 NV_OBJ="${S}"
153                 NV_SRC="${S}/kernel"
154                 NV_MAN="${S}"
155                 NV_X11="${S}"
156                 NV_SOVER=${PV}
157         else
158                 die "Could not determine proper NVIDIA package"
159         fi
160 }
161
162 src_prepare() {
163         # Please add a brief description for every added patch
164
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."
168                 fi
169
170                 # If greater than 2.6.5 use M= instead of SUBDIR=
171 #               convert_to_m "${NV_SRC}"/Makefile.kbuild
172         fi
173
174         local man_file
175         for man_file in "${NV_MAN}"/*1.gz; do
176                 gunzip $man_file || die
177         done
178
179         # Allow user patches so they can support RC kernels and whatever else
180         eapply_user
181 }
182
183 src_compile() {
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.
187
188         cd "${NV_SRC}"
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
194         fi
195
196         if use tools; then
197                 emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl clean
198                 emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl \
199                         AR="$(tc-getAR)" \
200                         CC="$(tc-getCC)" \
201                         RANLIB="$(tc-getRANLIB)" \
202                         libXNVCtrl.a
203                 emake -C "${S}"/nvidia-settings-${PV}/src \
204                         AR="$(tc-getAR)" \
205                         CC="$(tc-getCC)" \
206                         LD="$(tc-getCC)" \
207                         LIBDIR="$(get_libdir)" \
208                         NVML_ENABLED=0 \
209                         NV_USE_BUNDLED_LIBJANSSON=0 \
210                         NV_VERBOSE=1 \
211                         RANLIB="$(tc-getRANLIB)" \
212                         STRIP_CMD=true
213         fi
214 }
215
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
220 donvidia() {
221         # Full path to library minus SOVER
222         MY_LIB="$1"
223
224         # SOVER to use
225         MY_SOVER="$2"
226
227         # Where to install
228         MY_DEST="$3"
229
230         if [[ -z "${MY_DEST}" ]]; then
231                 MY_DEST="/usr/$(get_libdir)"
232                 action="dolib.so"
233         else
234                 exeinto ${MY_DEST}
235                 action="doexe"
236         fi
237
238         # Get just the library name
239         libname=$(basename $1)
240
241         # Install the library with the correct SOVER
242         ${action} ${MY_LIB}.${MY_SOVER} || \
243                 die "failed to install ${libname}"
244
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"
250         fi
251
252         # Always create the symlink from the raw lib to the .1
253         dosym ${libname}.1 \
254                 ${MY_DEST}/${libname} || \
255                 die "failed to create ${libname} symlink"
256 }
257
258 src_install() {
259         if use kernel_linux; then
260                 linux-mod_src_install
261
262                 # Add the aliases
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
267
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"
276                 fi
277
278                 exeinto /boot/modules
279                 doexe "${S}/src/nvidia.ko"
280         fi
281
282         # NVIDIA kernel <-> userspace driver config lib
283         donvidia "${NV_OBJ}"/libnvidia-cfg.so ${NV_SOVER}
284
285         # NVIDIA framebuffer capture library
286         donvidia "${NV_OBJ}"/libnvidia-fbc.so ${NV_SOVER}
287
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}
292         fi
293
294         if use X; then
295                 # Xorg DDX driver
296                 insinto /usr/$(get_libdir)/xorg/modules/drivers
297                 doins "${NV_X11}"/nvidia_drv.so
298
299                 # Xorg GLX driver
300                 donvidia "${NV_X11}"/libglx.so ${NV_SOVER} \
301                         /usr/$(get_libdir)/opengl/nvidia/extensions
302         fi
303
304         # OpenCL ICD for NVIDIA
305         if use kernel_linux; then
306                 insinto /etc/OpenCL/vendors
307                 doins "${NV_OBJ}"/nvidia.icd
308         fi
309
310         # Helper Apps
311         exeinto /opt/bin/
312
313         if use X; then
314                 doexe "${NV_OBJ}"/nvidia-xconfig
315         fi
316
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
323
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
329
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
336         fi
337
338         if use tools; then
339                 emake -C "${S}"/nvidia-settings-${PV}/src/ \
340                         DESTDIR="${D}" \
341                         LIBDIR="${D}/usr/$(get_libdir)" \
342                         PREFIX=/usr \
343                         NV_USE_BUNDLED_LIBJANSSON=0 \
344                         install
345
346                 if use static-libs; then
347                         dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
348
349                         insinto /usr/include/NVCtrl
350                         doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
351                 fi
352
353                 insinto /usr/share/nvidia/
354                 doins nvidia-application-profiles-${PV}-key-documentation
355
356                 insinto /etc/nvidia
357                 newins \
358                         nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
359
360                 # There is no icon in the FreeBSD tarball.
361                 use kernel_FreeBSD || \
362                         doicon "${NV_OBJ}"/nvidia-settings.png
363
364                 domenu "${FILESDIR}"/nvidia-settings.desktop
365
366                 exeinto /etc/X11/xinit/xinitrc.d
367                 newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
368
369         fi
370
371         dobin "${NV_OBJ}"/nvidia-bug-report.sh
372
373         #doenvd "${FILESDIR}"/50nvidia-prelink-blacklist
374
375         if has_multilib_profile && use multilib ; then
376                 local OABI=${ABI}
377                 for ABI in $(get_install_abis) ; do
378                         src_install-libs
379                 done
380                 ABI=${OABI}
381                 unset OABI
382         else
383                 src_install-libs
384         fi
385
386         is_final_abi || die "failed to iterate through all ABIs"
387
388         # Documentation
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
393         else
394                 # Docs
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
401         fi
402
403         readme.gentoo_create_doc
404
405         docinto html
406         dodoc -r "${NV_DOC}"/html/*
407 }
408
409 src_install-libs() {
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}"
414
415         if use kernel_linux && has_multilib_profile && \
416                         [[ ${ABI} == "x86" ]] ; then
417                 nv_libdir="${NV_OBJ}"/32
418         fi
419
420         if use X; then
421                 # The GLX libraries
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}
431                 else
432                         donvidia "${nv_libdir}"/tls/libnvidia-tls.so ${NV_SOVER}
433                 fi
434
435                 # VDPAU
436                 donvidia "${nv_libdir}"/libvdpau_nvidia.so ${NV_SOVER}
437
438                 # GLES v2 libraries
439                 insinto ${GL_ROOT}
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
443         fi
444
445         # NVIDIA monitoring library
446         if use kernel_linux ; then
447                 donvidia "${nv_libdir}"/libnvidia-ml.so ${NV_SOVER}
448         fi
449
450         # CUDA & OpenCL
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}
456         fi
457 }
458
459 pkg_preinst() {
460         if use kernel_linux; then
461                 linux-mod_pkg_preinst
462
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"
467                 else
468                         sed -i \
469                                 -e "s:PACKAGE:${PF}:g" \
470                                 -e "s:VIDEOGID:${videogroup}:" \
471                                 "${D}"/etc/modprobe.d/nvidia.conf || die
472                 fi
473         fi
474
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/*
479         fi
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
483         fi
484 }
485
486 pkg_postinst() {
487         use kernel_linux && linux-mod_pkg_postinst
488
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
492
493         readme.gentoo_print_elog
494
495         if ! use X; then
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."
502                 elog
503         fi
504         if ! use tools; then
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"
509                 elog
510         fi
511 }
512
513 pkg_prerm() {
514         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
515 }
516
517 pkg_postrm() {
518         use kernel_linux && linux-mod_pkg_postrm
519         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
520 }