Add x11-drivers/nvidia-drivers-180.{29,60}.
[overlay.git] / x11-drivers / nvidia-drivers / nvidia-drivers-180.29.ebuild
1 # Copyright 1999-2009 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/x11-drivers/nvidia-drivers/nvidia-drivers-180.29.ebuild,v 1.5 2009/06/12 19:53:35 cardoe Exp $
4
5 inherit eutils multilib versionator linux-mod flag-o-matic nvidia-driver
6
7 X86_NV_PACKAGE="NVIDIA-Linux-x86-${PV}"
8 AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${PV}"
9 X86_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86-${PV}"
10
11 DESCRIPTION="NVIDIA X11 driver and GLX libraries"
12 HOMEPAGE="http://www.nvidia.com/"
13 SRC_URI="x86? ( ftp://download.nvidia.com/XFree86/Linux-x86/${PV}/${X86_NV_PACKAGE}-pkg0.run )
14          amd64? ( ftp://download.nvidia.com/XFree86/Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}-pkg2.run )
15          x86-fbsd? ( ftp://download.nvidia.com/freebsd/${PV}/${X86_FBSD_NV_PACKAGE}.tar.gz )"
16
17 LICENSE="NVIDIA"
18 SLOT="0"
19 KEYWORDS="-* amd64 x86 ~x86-fbsd"
20 IUSE="acpi custom-cflags gtk multilib kernel_linux"
21 RESTRICT="strip"
22 EMULTILIB_PKG="true"
23
24 COMMON="<x11-base/xorg-server-1.6.99
25         multilib? ( app-emulation/emul-linux-x86-xlibs )
26         kernel_FreeBSD? ( !media-video/nvidia-freebsd )
27         !app-emulation/emul-linux-x86-nvidia
28         !x11-drivers/nvidia-legacy-drivers"
29 DEPEND="${COMMON}
30         kernel_linux? ( virtual/linux-sources )
31         app-admin/eselect-opengl"
32 RDEPEND="${COMMON}
33         kernel_linux? ( virtual/modutils )
34         media-libs/mesa
35         acpi? ( sys-power/acpid )"
36 PDEPEND="gtk? ( media-video/nvidia-settings )"
37
38 QA_TEXTRELS_x86="usr/lib/libXvMCNVIDIA.so.${PV}
39         usr/lib/opengl/nvidia/no-tls/libnvidia-tls.so.${PV}
40         usr/lib/opengl/nvidia/tls/libnvidia-tls.so.${PV}
41         usr/lib/opengl/nvidia/lib/libGL.so.${PV}
42         usr/lib/opengl/nvidia/lib/libnvidia-cfg.so.${PV}
43         usr/lib/opengl/nvidia/lib/libGLcore.so.${PV}
44         usr/lib/opengl/nvidia/extensions/libglx.so
45         usr/lib/xorg/modules/drivers/nvidia_drv.so
46         usr/lib/libcuda.so.${PV}"
47
48 QA_TEXTRELS_x86_fbsd="boot/modules/nvidia.ko
49         usr/lib/opengl/nvidia/lib/libGL.so.1
50         usr/lib/opengl/nvidia/lib/libGLcore.so.1
51         usr/lib/opengl/nvidia/lib/libnvidia-cfg.so.1
52         usr/lib/opengl/nvidia/no-tls/libnvidia-tls.so.1
53         usr/lib/opengl/nvidia/extensions/libglx.so
54         usr/lib/xorg/modules/drivers/nvidia_drv.so"
55
56 QA_TEXTRELS_amd64="usr/lib32/opengl/nvidia/tls/libnvidia-tls.so.${PV}
57         usr/lib32/opengl/nvidia/no-tls/libnvidia-tls.so.${PV}
58         usr/lib32/opengl/nvidia/lib/libGLcore.so.${PV}
59         usr/lib32/opengl/nvidia/lib/libGL.so.${PV}
60         usr/lib32/opengl/nvidia/lib/libnvidia-cfg.so.${PV}
61         usr/lib32/libcuda.so.${PV}"
62
63 QA_EXECSTACK_x86="usr/lib/opengl/nvidia/lib/libGL.so.${PV}
64         usr/lib/opengl/nvidia/lib/libGLcore.so.${PV}
65         usr/lib/opengl/nvidia/extensions/libglx.so"
66
67 QA_EXECSTACK_amd64="usr/lib32/opengl/nvidia/lib/libGLcore.so.${PV}
68         usr/lib32/opengl/nvidia/lib/libGL.so.${PV}
69         usr/lib64/xorg/modules/drivers/nvidia_drv.so
70         usr/lib64/libXvMCNVIDIA.so.${PV}
71         usr/lib64/opengl/nvidia/tls/libnvidia-tls.so.${PV}
72         usr/lib64/opengl/nvidia/no-tls/libnvidia-tls.so.${PV}
73         usr/lib64/opengl/nvidia/lib/libGLcore.so.${PV}
74         usr/lib64/opengl/nvidia/lib/libGL.so.${PV}
75         usr/lib64/opengl/nvidia/lib/libnvidia-cfg.so.${PV}
76         usr/lib64/opengl/nvidia/extensions/libglx.so
77         usr/bin/nvidia-xconfig"
78
79 QA_WX_LOAD_x86="usr/lib/opengl/nvidia/lib/libGLcore.so.${PV}
80         usr/lib/opengl/nvidia/lib/libGL.so.${PV}
81         usr/lib/opengl/nvidia/extensions/libglx.so"
82
83 QA_WX_LOAD_amd64="usr/lib32/opengl/nvidia/lib/libGLcore.so.${PV}
84         usr/lib32/opengl/nvidia/lib/libGL.so.${PV}
85         usr/lib64/opengl/nvidia/lib/libGLcore.so.${PV}
86         usr/lib64/opengl/nvidia/lib/libGL.so.${PV}
87         usr/lib64/opengl/nvidia/extensions/libglx.so"
88
89 if use x86; then
90         PKG_V="-pkg0"
91         NV_PACKAGE="${X86_NV_PACKAGE}"
92 elif use amd64; then
93         PKG_V="-pkg2"
94         NV_PACKAGE="${AMD64_NV_PACKAGE}"
95 elif use x86-fbsd; then
96         PKG_V=""
97         NV_PACKAGE="${X86_FBSD_NV_PACKAGE}"
98 fi
99
100 S="${WORKDIR}/${NV_PACKAGE}${PKG_V}"
101
102 mtrr_check() {
103         ebegin "Checking for MTRR support"
104         linux_chkconfig_present MTRR
105         eend $?
106
107         if [[ $? -ne 0 ]] ; then
108                 eerror "Please enable MTRR support in your kernel config, found at:"
109                 eerror
110                 eerror "  Processor type and features"
111                 eerror "    [*] MTRR (Memory Type Range Register) support"
112                 eerror
113                 eerror "and recompile your kernel ..."
114                 die "MTRR support not detected!"
115         fi
116 }
117
118 paravirt_check() {
119         ebegin "Checking for Paravirtualized guest support"
120         linux_chkconfig_present PARAVIRT_GUEST
121
122         if [[ $? -eq 0 ]]; then
123                 eerror "Please disable PARAVIRT_GUEST in your kernel config, found at:"
124                 eerror
125                 eerror "  Processor type and features"
126                 eerror "    [*] Paravirtualized guest support"
127                 eerror
128                 eerror "or XEN support"
129                 eerror
130                 eerror "and recompile your kernel .."
131                 die "PARAVIRT_GUEST support detected!"
132         fi
133 }
134
135 pkg_setup() {
136         # try to turn off distcc and ccache for people that have a problem with it
137         export DISTCC_DISABLE=1
138         export CCACHE_DISABLE=1
139
140         if use amd64 && has_multilib_profile && [ "${DEFAULT_ABI}" != "amd64" ]; then
141                 eerror "This ebuild doesn't currently support changing your default abi."
142                 die "Unexpected \${DEFAULT_ABI} = ${DEFAULT_ABI}"
143         fi
144
145         if use kernel_linux; then
146                 linux-mod_pkg_setup
147                 MODULE_NAMES="nvidia(video:${S}/usr/src/nv)"
148                 BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
149                 SYSOUT=${KV_OUT_DIR} HOST_CC=$(tc-getBUILD_CC)"
150                 mtrr_check
151                 paravirt_check
152         fi
153
154         # On BSD userland it wants real make command
155         use userland_BSD && MAKE="$(get_bmake)"
156
157         export _POSIX2_VERSION="199209"
158
159         # Since Nvidia ships 3 different series of drivers, we need to give the user
160         # some kind of guidance as to what version they should install. This tries
161         # to point the user in the right direction but can't be perfect. check
162         # nvidia-driver.eclass
163         nvidia-driver-check-warning
164
165         # set variables to where files are in the package structure
166         if use kernel_FreeBSD; then
167                 NV_DOC="${S}/doc"
168                 NV_EXEC="${S}/obj"
169                 NV_SRC="${S}/src"
170         elif use kernel_linux; then
171                 NV_DOC="${S}/usr/share/doc"
172                 NV_EXEC="${S}/usr/bin"
173                 NV_SRC="${S}/usr/src/nv"
174         else
175                 die "Could not determine proper NVIDIA package"
176         fi
177 }
178
179 src_unpack() {
180         if use kernel_linux && kernel_is lt 2 6 7; then
181                 echo
182                 ewarn "Your kernel version is ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
183                 ewarn "This is not officially supported for ${P}. It is likely you"
184                 ewarn "will not be able to compile or use the kernel module."
185                 ewarn "It is recommended that you upgrade your kernel to a version >= 2.6.7"
186                 echo
187                 ewarn "DO NOT file bug reports for kernel versions less than 2.6.7 as they will be ignored."
188         fi
189
190         if ! use x86-fbsd; then
191                 mkdir "${S}"
192                 cd "${S}"
193                 unpack_makeself
194         else
195                 unpack ${A}
196         fi
197
198         # Patches go below here, add brief description
199         cd "${S}"
200         use x86-fbsd && cd doc
201
202         # Use the correct defines to make gtkglext build work
203         epatch "${FILESDIR}"/NVIDIA_glx-defines.patch
204         # Use some more sensible gl headers and make way for new glext.h
205         epatch "${FILESDIR}"/NVIDIA_glx-glheader.patch
206
207         # only apply for > 2.6.30
208         if use kernel_linux && kernel_is gt 2 6 30; then
209                 # fix for >2.6.30.* kernels
210                 epatch "${FILESDIR}"/linux-kernel-agp_memory.patch
211         fi
212
213         # only apply for > 2.6.30
214         if use kernel_linux && kernel_is gt 2 6 29; then
215                 # fix for >2.6.30.* kernels
216                 epatch "${FILESDIR}"/linux-kernel-proc-owner.patch
217         fi
218
219         if use kernel_linux; then
220                 # Quiet down warnings the user does not need to see
221                 sed -i \
222                         -e 's:-Wpointer-arith::g' \
223                         -e 's:-Wsign-compare::g' \
224                         "${NV_SRC}"/Makefile.kbuild
225
226                 # If you set this then it's your own fault when stuff breaks :)
227                 use custom-cflags && sed -i "s:-O:${CFLAGS}:" "${NV_SRC}"/Makefile.*
228
229                 # If greater than 2.6.5 use M= instead of SUBDIR=
230                 convert_to_m "${NV_SRC}"/Makefile.kbuild
231         fi
232 }
233
234 src_compile() {
235         # This is already the default on Linux, as there's no toplevel Makefile, but
236         # on FreeBSD there's one and triggers the kernel module build, as we install
237         # it by itself, pass this.
238
239         cd "${NV_SRC}"
240         if use x86-fbsd; then
241                 MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
242                         LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
243         elif use kernel_linux; then
244                 linux-mod_src_compile
245         fi
246 }
247
248 src_install() {
249         local MLTEST=$(type dyn_unpack)
250
251         cd "${S}"
252
253         if use kernel_linux; then
254                 linux-mod_src_install
255
256                 VIDEOGROUP="$(egetent group video | cut -d ':' -f 3)"
257                 if [ -z "$VIDEOGROUP" ]; then
258                         eerror "Failed to determine the video group gid."
259                         die "Failed to determine the video group gid."
260                 fi
261
262                 # Add the aliases
263                 [ -f "${FILESDIR}/nvidia" ] || die "nvidia missing in FILESDIR"
264                 sed -e 's:PACKAGE:'${PF}':g' \
265                         -e 's:VIDEOGID:'${VIDEOGROUP}':' "${FILESDIR}"/nvidia-169.07 > \
266                         "${WORKDIR}"/nvidia
267                 insinto /etc/modprobe.d
268                 newins "${WORKDIR}"/nvidia nvidia.conf || die
269         elif use x86-fbsd; then
270                 insinto /boot/modules
271                 doins "${WORKDIR}/${NV_PACKAGE}/src/nvidia.kld" || die
272
273                 exeinto /boot/modules
274                 doexe "${WORKDIR}/${NV_PACKAGE}/src/nvidia.ko" || die
275         fi
276
277         if has_multilib_profile ; then
278                 local OABI=${ABI}
279                 for ABI in $(get_install_abis) ; do
280                         src_install-libs
281                 done
282                 ABI=${OABI}
283                 unset OABI
284         elif use amd64 ; then
285                 src_install-libs lib32 $(get_multilibdir)
286                 src_install-libs lib $(get_libdir)
287
288                 rm -rf "${D}"/usr/$(get_multilibdir)/opengl/nvidia/include
289                 rm -rf "${D}"/usr/$(get_multilibdir)/opengl/nvidia/extensions
290         else
291                 src_install-libs
292         fi
293
294         is_final_abi || return 0
295
296         # Documentation
297         dodoc "${NV_DOC}"/{XF86Config.sample,Copyrights}
298         dohtml "${NV_DOC}"/html/*
299         if use x86-fbsd; then
300                 dodoc "${NV_DOC}/README"
301         else
302                 # Docs
303                 newdoc "${NV_DOC}/README.txt" README
304                 dodoc "${NV_DOC}/NVIDIA_Changelog"
305         fi
306
307         # Helper Apps
308         dobin ${NV_EXEC}/nvidia-xconfig || die
309         dobin ${NV_EXEC}/nvidia-bug-report.sh || die
310 }
311
312 # Install nvidia library:
313 # the first parameter is the place where to install it
314 # the second parameter is the base name of the library
315 # the third parameter is the provided soversion
316 donvidia() {
317         dodir $1
318         exeinto $1
319
320         libname=$(basename $2)
321
322         # libnvidia-cfg.so is no longer supplied in lib32; step over it gracefully
323         if [ -e $2.$3 ] ; then
324                 doexe $2.$3
325                 dosym ${libname}.$3 $1/${libname}
326                 [[ $3 != "1" ]] && dosym ${libname}.$3 $1/${libname}.1
327         fi
328 }
329
330 src_install-libs() {
331         local pkglibdir=lib
332         local inslibdir=$(get_libdir)
333
334         if [[ ${#} -eq 2 ]] ; then
335                 pkglibdir=${1}
336                 inslibdir=${2}
337         elif has_multilib_profile && [[ ${ABI} == "x86" ]] ; then
338                 pkglibdir=lib32
339         fi
340
341         local usrpkglibdir=usr/${pkglibdir}
342         local libdir=usr/X11R6/${pkglibdir}
343         local drvdir=${libdir}/modules/drivers
344         local extdir=${libdir}/modules/extensions
345         local incdir=usr/include/GL
346         local sover=${PV}
347         local NV_ROOT="/usr/${inslibdir}/opengl/nvidia"
348         local NO_TLS_ROOT="${NV_ROOT}/no-tls"
349         local TLS_ROOT="${NV_ROOT}/tls"
350         local X11_LIB_DIR="/usr/${inslibdir}/xorg"
351
352         if use x86-fbsd; then
353                 # on FreeBSD everything is on obj/
354                 pkglibdir=obj
355                 usrpkglibdir=obj
356                 x11pkglibdir=obj
357                 drvdir=obj
358                 extdir=obj
359
360                 # don't ask me why the headers are there.. glxext.h is missing
361                 incdir=doc
362
363                 # on FreeBSD it has just .1 suffix
364                 sover=1
365         fi
366
367         # The GLX libraries
368         donvidia ${NV_ROOT}/lib ${usrpkglibdir}/libGL.so ${sover}
369         donvidia ${NV_ROOT}/lib ${usrpkglibdir}/libGLcore.so ${sover}
370
371         donvidia ${NV_ROOT}/lib ${usrpkglibdir}/libnvidia-cfg.so ${sover}
372
373         dodir ${NO_TLS_ROOT}
374         donvidia ${NO_TLS_ROOT} ${usrpkglibdir}/libnvidia-tls.so ${sover}
375
376         if ! use x86-fbsd; then
377                 donvidia ${TLS_ROOT} ${usrpkglibdir}/tls/libnvidia-tls.so ${sover}
378         fi
379
380         if want_tls ; then
381                 dosym ../tls/libnvidia-tls.so ${NV_ROOT}/lib
382                 dosym ../tls/libnvidia-tls.so.1 ${NV_ROOT}/lib
383                 dosym ../tls/libnvidia-tls.so.${sover} ${NV_ROOT}/lib
384         else
385                 dosym ../no-tls/libnvidia-tls.so ${NV_ROOT}/lib
386                 dosym ../no-tls/libnvidia-tls.so.1 ${NV_ROOT}/lib
387                 dosym ../no-tls/libnvidia-tls.so.${sover} ${NV_ROOT}/lib
388         fi
389
390         if ! use x86-fbsd; then
391                 # Install the .la file for libtool, to prevent e.g. bug #176423
392                 [ -f "${FILESDIR}/libGL.la-r2" ] || die "libGL.la-r2 missing in FILESDIR"
393                 local ver1=$(get_version_component_range 1)
394                 local ver2=$(get_version_component_range 2)
395                 local ver3=$(get_version_component_range 3)
396                 sed -e "s:\${PV}:${PV}:"     \
397                         -e "s:\${ver1}:${ver1}:" \
398                         -e "s:\${ver2}:${ver2}:" \
399                         -e "s:\${ver3}:${ver3}:" \
400                         -e "s:\${libdir}:${inslibdir}:" \
401                         "${FILESDIR}"/libGL.la-r2 > "${D}"/${NV_ROOT}/lib/libGL.la
402         fi
403
404         exeinto ${X11_LIB_DIR}/modules/drivers
405
406         [[ -f ${drvdir}/nvidia_drv.so ]] && \
407                 doexe ${drvdir}/nvidia_drv.so
408
409         insinto /usr/${inslibdir}
410         [[ -f ${libdir}/libXvMCNVIDIA.a ]] && \
411                 doins ${libdir}/libXvMCNVIDIA.a
412         exeinto /usr/${inslibdir}
413         # fix Bug 131315
414         [[ -f ${libdir}/libXvMCNVIDIA.so.${PV} ]] && \
415                 doexe ${libdir}/libXvMCNVIDIA.so.${PV} && \
416                 dosym libXvMCNVIDIA.so.${PV} \
417                         /usr/${inslibdir}/libXvMCNVIDIA.so
418
419         exeinto ${NV_ROOT}/extensions
420         [[ -f ${libdir}/modules/libnvidia-wfb.so.${sover} ]] && \
421                 newexe ${libdir}/modules/libnvidia-wfb.so.${sover} libwfb.so
422         [[ -f ${extdir}/libglx.so.${sover} ]] && \
423                 newexe ${extdir}/libglx.so.${sover} libglx.so
424
425         # Includes
426         insinto ${NV_ROOT}/include
427         doins ${incdir}/*.h
428
429         #cuda
430         if [[ -f usr/include/cuda/cuda.h ]]; then
431                 dodir /usr/include/cuda
432                 insinto /usr/include/cuda
433                 doins usr/include/cuda/*.h
434
435                 if [[ -f usr/${pkglibdir}/libcuda.so.${PV} ]]; then
436                         dolib.so usr/${pkglibdir}/libcuda.so.${PV}
437                         dosym libcuda.so.${PV} /usr/${inslibdir}/libcuda.so.1
438                         dosym libcuda.so.1 /usr/${inslibdir}/libcuda.so
439                 fi
440         fi
441
442         #vdpau
443         if [[ -f usr/include/vdpau/vdpau.h ]]; then
444                 dodir /usr/include/vdpau
445                 insinto /usr/include/vdpau
446                 doins usr/include/vdpau/*.h
447
448                 for vdpaulib in vdpau_nvidia vdpau vdpau_trace; do
449                         dolib.so usr/${pkglibdir}/lib${vdpaulib}.so.${PV}
450                         dosym lib${vdpaulib}.so.${PV} /usr/${inslibdir}/lib${vdpaulib}.so.1
451                         dosym lib${vdpaulib}.so.1 /usr/${inslibdir}/lib${vdpaulib}.so
452                 done
453         fi
454 }
455
456 pkg_preinst() {
457
458         # Clean the dynamic libGL stuff's home to ensure
459         # we dont have stale libs floating around
460         if [ -d "${ROOT}"/usr/lib/opengl/nvidia ] ; then
461                 rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
462         fi
463         # Make sure we nuke the old nvidia-glx's env.d file
464         if [ -e "${ROOT}"/etc/env.d/09nvidia ] ; then
465                 rm -f "${ROOT}"/etc/env.d/09nvidia
466         fi
467 }
468
469 pkg_postinst() {
470         if use kernel_linux; then
471                 linux-mod_pkg_postinst
472         fi
473
474         # Switch to the nvidia implementation
475         eselect opengl set --use-old nvidia
476
477         echo
478         elog "You must be in the video group to use the NVIDIA device"
479         elog "For more info, read the docs at"
480         elog "http://www.gentoo.org/doc/en/nvidia-guide.xml#doc_chap3_sect6"
481         elog
482
483         elog "This ebuild installs a kernel module and X driver. Both must"
484         elog "match explicitly in their version. This means, if you restart"
485         elog "X, you most modprobe -r nvidia before starting it back up"
486         elog
487
488         elog "To use the NVIDIA GLX, run \"eselect opengl set nvidia\""
489         elog
490         elog "nVidia has requested that any bug reports submitted have the"
491         elog "output of /usr/bin/nvidia-bug-report.sh included."
492         elog
493         elog "To work with compiz, you must enable the AddARGBGLXVisuals option."
494         elog
495         elog "If you are having resolution problems, try disabling DynamicTwinView."
496         echo
497 }
498
499 want_tls() {
500         # For uclibc or anything non glibc, return false
501         has_version sys-libs/glibc || return 1
502
503         # Old versions of glibc were lt/no-tls only
504         has_version '<sys-libs/glibc-2.3.2' && return 1
505
506         if use x86 ; then
507                 case ${CHOST/-*} in
508                         i486|i586|i686) ;;
509                         *) return 1 ;;
510                 esac
511         fi
512
513         # If we've got nptl, we've got tls
514         built_with_use --missing true sys-libs/glibc nptl && return 0
515
516         # 2.3.5 turned off tls for linuxthreads glibc on i486 and i586
517         if use x86 && has_version '>=sys-libs/glibc-2.3.5' ; then
518                 case ${CHOST/-*} in
519                         i486|i586) return 1 ;;
520                 esac
521         fi
522
523         # These versions built linuxthreads version to support tls, too
524         has_version '>=sys-libs/glibc-2.3.4.20040619-r2' && return 0
525
526         return 1
527 }
528
529 pkg_postrm() {
530         if use kernel_linux; then
531                 linux-mod_pkg_postrm
532         fi
533         eselect opengl set --use-old xorg-x11
534 }