sys-power/powerman: Remove last-rited pkg
[gentoo.git] / x11-drivers / nvidia-drivers / nvidia-drivers-361.45.18.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils flag-o-matic linux-info linux-mod multilib nvidia-driver \
8         portability toolchain-funcs unpacker user udev
9
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}"
15
16 DESCRIPTION="NVIDIA Accelerated Graphics Driver"
17 HOMEPAGE="http://www.nvidia.com/ http://www.nvidia.com/Download/Find.aspx"
18 SRC_URI="
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 )
24 "
25
26 LICENSE="GPL-2 NVIDIA-r2"
27 SLOT="0/${PV%.*}"
28 KEYWORDS="-* ~amd64 ~x86 ~amd64-fbsd ~x86-fbsd"
29 RESTRICT="bindist mirror"
30 EMULTILIB_PKG="true"
31
32 IUSE="acpi compat +driver gtk3 kernel_FreeBSD kernel_linux +kms multilib pax_kernel static-libs +tools uvm +X"
33 REQUIRED_USE="
34         tools? ( X )
35         static-libs? ( tools )
36 "
37
38 COMMON="
39         app-eselect/eselect-opencl
40         kernel_linux? ( >=sys-libs/glibc-2.6.1 )
41         tools? (
42                 dev-libs/atk
43                 dev-libs/glib:2
44                 dev-libs/jansson
45                 gtk3? ( x11-libs/gtk+:3 )
46                 x11-libs/cairo
47                 x11-libs/gdk-pixbuf[X]
48                 x11-libs/gtk+:2
49                 x11-libs/libX11
50                 x11-libs/libXext
51                 x11-libs/libXrandr
52                 x11-libs/libXv
53                 x11-libs/libXxf86vm
54                 x11-libs/pango[X]
55         )
56         X? (
57                 >=app-eselect/eselect-opengl-1.0.9
58                 app-misc/pax-utils
59         )
60 "
61 DEPEND="
62         ${COMMON}
63         kernel_linux? ( virtual/linux-sources )
64 "
65 RDEPEND="
66         ${COMMON}
67         acpi? ( sys-power/acpid )
68         tools? ( !media-video/nvidia-settings )
69         X? (
70                 <x11-base/xorg-server-1.18.99:=
71                 >=x11-libs/libvdpau-1.0
72                 multilib? (
73                         >=x11-libs/libX11-1.6.2[abi_x86_32]
74                         >=x11-libs/libXext-1.3.2[abi_x86_32]
75                 )
76         )
77 "
78
79 QA_PREBUILT="opt/* usr/lib*"
80
81 S=${WORKDIR}/
82
83 pkg_pretend() {
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}"
88         fi
89
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"
95                 ewarn ""
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."
99                 ewarn ""
100                 ewarn "Do not file a bug report about this."
101                 ewarn ""
102         fi
103
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
109
110         # Kernel features/options to check for
111         CONFIG_CHECK="~ZONE_DMA ~MTRR ~SYSVIPC ~!LOCKDEP"
112         use x86 && CONFIG_CHECK+=" ~HIGHMEM"
113
114         # Now do the above checks
115         use kernel_linux && check_extra_config
116 }
117
118 pkg_setup() {
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
122
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)"
127
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).
131                 linux-mod_pkg_setup
132
133                 BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
134                 SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC) NV_VERBOSE=1"
135
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/')"
141         fi
142
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."
145         fi
146
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}"
151                 NV_DOC="${S}/doc"
152                 NV_OBJ="${S}/obj"
153                 NV_SRC="${S}/src"
154                 NV_MAN="${S}/x11/man"
155                 NV_X11="${S}/obj"
156                 NV_SOVER=1
157         elif use kernel_linux; then
158                 NV_DOC="${S}"
159                 NV_OBJ="${S}"
160                 NV_SRC="${S}/kernel"
161                 NV_MAN="${S}"
162                 NV_X11="${S}"
163                 NV_SOVER=${PV}
164         else
165                 die "Could not determine proper NVIDIA package"
166         fi
167 }
168
169 src_prepare() {
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
175         fi
176
177         # Allow user patches so they can support RC kernels and whatever else
178         epatch_user
179 }
180
181 src_compile() {
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.
185
186         cd "${NV_SRC}"
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
192         fi
193
194         if use tools; then
195                 emake -C "${S}"/nvidia-settings-${PV}/src \
196                         AR="$(tc-getAR)" \
197                         CC="$(tc-getCC)" \
198                         LIBDIR="$(get_libdir)" \
199                         RANLIB="$(tc-getRANLIB)" \
200                         build-xnvctrl
201
202                 emake -C "${S}"/nvidia-settings-${PV}/src \
203                         CC="$(tc-getCC)" \
204                         GTK3_AVAILABLE=$(usex gtk3 1 0) \
205                         LD="$(tc-getCC)" \
206                         LIBDIR="$(get_libdir)" \
207                         NVML_ENABLED=0 \
208                         NV_USE_BUNDLED_LIBJANSSON=0 \
209                         NV_VERBOSE=1 \
210                         STRIP_CMD=true
211         fi
212 }
213
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
218 donvidia() {
219         # Full path to library
220         nv_LIB="${1}"
221
222         # SOVER to use
223         nv_SOVER="$(scanelf -qF'%S#F' ${nv_LIB})"
224
225         # Where to install
226         nv_DEST="${2}"
227
228         # Get just the library name
229         nv_LIBNAME=$(basename "${nv_LIB}")
230
231         if [[ "${nv_DEST}" ]]; then
232                 exeinto ${nv_DEST}
233                 action="doexe"
234         else
235                 nv_DEST="/usr/$(get_libdir)"
236                 action="dolib.so"
237         fi
238
239         # Install the library
240         ${action} ${nv_LIB} || die "failed to install ${nv_LIBNAME}"
241
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"
247         fi
248
249         dosym ${nv_LIBNAME} ${nv_DEST}/${nv_LIBNAME/.so*/.so} \
250                 || die "failed to create ${nv_LIBNAME/.so*/.so} symlink"
251 }
252
253 src_install() {
254         if use driver && use kernel_linux; then
255                 linux-mod_src_install
256
257                 # Add the aliases
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
263
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"
272                 fi
273
274                 exeinto /boot/modules
275                 doexe "${S}/src/nvidia.ko"
276         fi
277
278         # NVIDIA kernel <-> userspace driver config lib
279         donvidia ${NV_OBJ}/libnvidia-cfg.so.${NV_SOVER}
280
281         # NVIDIA framebuffer capture library
282         donvidia ${NV_OBJ}/libnvidia-fbc.so.${NV_SOVER}
283
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}
288         fi
289
290         if use X; then
291                 # Xorg DDX driver
292                 insinto /usr/$(get_libdir)/xorg/modules/drivers
293                 doins ${NV_X11}/nvidia_drv.so
294
295                 # Xorg GLX driver
296                 donvidia ${NV_X11}/libglx.so.${NV_SOVER} \
297                         /usr/$(get_libdir)/opengl/nvidia/extensions
298
299                 # Xorg nvidia.conf
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
303                 fi
304         fi
305
306         # OpenCL ICD for NVIDIA
307         if use kernel_linux; then
308                 insinto /etc/OpenCL/vendors
309                 doins ${NV_OBJ}/nvidia.icd
310         fi
311
312         # Documentation
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"
318         else
319                 # Docs
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"
326         fi
327
328         # Helper Apps
329         exeinto /opt/bin/
330
331         if use X; then
332                 doexe ${NV_OBJ}/nvidia-xconfig
333         fi
334
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
341
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
347
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
354         fi
355
356         if use tools; then
357                 emake -C "${S}"/nvidia-settings-${PV}/src/ \
358                         DESTDIR="${D}" \
359                         GTK3_AVAILABLE=$(usex gtk3 1 0) \
360                         LIBDIR="${D}/usr/$(get_libdir)" \
361                         PREFIX=/usr \
362                         NV_USE_BUNDLED_LIBJANSSON=0 \
363                         install
364
365                 if use static-libs; then
366                         dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
367
368                         insinto /usr/include/NVCtrl
369                         doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
370                 fi
371
372                 insinto /usr/share/nvidia/
373                 doins nvidia-application-profiles-${PV}-key-documentation
374
375                 insinto /etc/nvidia
376                 newins \
377                         nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
378
379                 # There is no icon in the FreeBSD tarball.
380                 use kernel_FreeBSD || \
381                         doicon ${NV_OBJ}/nvidia-settings.png
382
383                 domenu "${FILESDIR}"/nvidia-settings.desktop
384
385                 exeinto /etc/X11/xinit/xinitrc.d
386                 newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
387         fi
388
389         dobin ${NV_OBJ}/nvidia-bug-report.sh
390
391         if has_multilib_profile && use multilib; then
392                 local OABI=${ABI}
393                 for ABI in $(get_install_abis); do
394                         src_install-libs
395                 done
396                 ABI=${OABI}
397                 unset OABI
398         else
399                 src_install-libs
400         fi
401
402         is_final_abi || die "failed to iterate through all ABIs"
403
404         readme.gentoo_create_doc
405 }
406
407 src_install-libs() {
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}
412
413         if use kernel_linux && has_multilib_profile && [[ ${ABI} == "x86" ]]; then
414                 libdir=${NV_OBJ}/32
415         fi
416
417         if use X; then
418                 NV_GLX_LIBRARIES=(
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}"
444                 )
445
446                 if use kernel_linux && has_multilib_profile && [[ ${ABI} == "amd64" ]];
447                 then
448                         NV_GLX_LIBRARIES+=( "libnvidia-wfb.so.${NV_SOVER}" )
449                 fi
450
451                 if use kernel_FreeBSD; then
452                         NV_GLX_LIBRARIES+=( "libnvidia-tls.so.${NV_SOVER}" )
453                 fi
454
455                 if use kernel_linux; then
456                         NV_GLX_LIBRARIES+=(
457                                 "libnvidia-ml.so.${NV_SOVER}"
458                                 "tls/libnvidia-tls.so.${NV_SOVER}"
459                         )
460                 fi
461
462                 for NV_LIB in "${NV_GLX_LIBRARIES[@]}"; do
463                         donvidia ${libdir}/${NV_LIB}
464                 done
465         fi
466 }
467
468 pkg_preinst() {
469         if use driver && use kernel_linux; then
470                 linux-mod_pkg_preinst
471
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"
476                 else
477                         sed -i \
478                                 -e "s:PACKAGE:${PF}:g" \
479                                 -e "s:VIDEOGID:${videogroup}:" \
480                                 "${D}"/etc/modprobe.d/nvidia.conf || die
481                 fi
482         fi
483
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/*
488         fi
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
492         fi
493 }
494
495 pkg_postinst() {
496         use driver && use kernel_linux && linux-mod_pkg_postinst
497
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
501
502         readme.gentoo_print_elog
503
504         if ! use X; then
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."
511                 elog
512         fi
513         if ! use tools; then
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"
518                 elog
519         fi
520 }
521
522 pkg_prerm() {
523         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
524 }
525
526 pkg_postrm() {
527         use driver && use kernel_linux && linux-mod_pkg_postrm
528         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
529 }