Advertisement
theroot

nvidia-drivers-313.18.ebuild

Feb 19th, 2013
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 15.95 KB | None | 0 0
  1. # Copyright 1999-2013 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-313.18.ebuild,v 1.3 2013/02/12 04:40:01 vapier Exp $
  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. X86_NV_PACKAGE="NVIDIA-Linux-x86-${PV}"
  11. AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${PV}"
  12. X86_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86-${PV}"
  13. AMD64_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86_64-${PV}"
  14.  
  15. DESCRIPTION="NVIDIA X11 driver and GLX libraries"
  16. HOMEPAGE="http://www.nvidia.com/"
  17. SRC_URI="x86? ( ftp://download.nvidia.com/XFree86/Linux-x86/${PV}/${X86_NV_PACKAGE}.run )
  18.         amd64? ( ftp://download.nvidia.com/XFree86/Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}.run )
  19.         amd64-fbsd? ( ftp://download.nvidia.com/XFree86/FreeBSD-x86_64/${PV}/${AMD64_FBSD_NV_PACKAGE}.tar.gz )
  20.         x86-fbsd? ( ftp://download.nvidia.com/XFree86/FreeBSD-x86/${PV}/${X86_FBSD_NV_PACKAGE}.tar.gz )"
  21.  
  22. LICENSE="NVIDIA"
  23. SLOT="0"
  24. KEYWORDS="-* ~amd64 ~x86 ~amd64-fbsd ~x86-fbsd"
  25. IUSE="acpi multilib kernel_FreeBSD kernel_linux pax_kernel +tools +X"
  26. RESTRICT="strip"
  27. EMULTILIB_PKG="true"
  28.  
  29. COMMON="app-admin/eselect-opencl
  30.        kernel_linux? ( >=sys-libs/glibc-2.6.1 )
  31.        multilib? ( app-emulation/emul-linux-x86-xlibs )
  32.        X? (
  33.                <x11-base/xorg-server-1.14.99
  34.                >=app-admin/eselect-opengl-1.0.9
  35.        )"
  36. DEPEND="${COMMON}
  37.        kernel_linux? (
  38.                virtual/linux-sources
  39.        )"
  40. RDEPEND="${COMMON}
  41.        acpi? ( sys-power/acpid )
  42.        tools? (
  43.                dev-libs/atk
  44.                dev-libs/glib
  45.                x11-libs/gdk-pixbuf
  46.                x11-libs/gtk+:2
  47.                x11-libs/libX11
  48.                x11-libs/libXext
  49.                x11-libs/pango[X]
  50.                || ( x11-libs/pangox-compat <x11-libs/pango-1.31[X] )
  51.        )
  52.        X? ( >=x11-libs/libvdpau-0.3-r1 )"
  53.  
  54. REQUIRED_USE="tools? ( X )"
  55.  
  56. QA_PREBUILT="opt/* usr/lib*"
  57.  
  58. S=${WORKDIR}/
  59.  
  60. pkg_pretend() {
  61.  
  62.         if use amd64 && has_multilib_profile && \
  63.                 [ "${DEFAULT_ABI}" != "amd64" ]; then
  64.                 eerror "This ebuild doesn't currently support changing your default ABI"
  65.                 die "Unexpected \${DEFAULT_ABI} = ${DEFAULT_ABI}"
  66.         fi
  67.  
  68.         # Kernel features/options to check for
  69.         CONFIG_CHECK="~ZONE_DMA ~MTRR ~SYSVIPC ~!LOCKDEP"
  70.         use x86 && CONFIG_CHECK+=" ~HIGHMEM"
  71.  
  72.         # Now do the above checks
  73.         use kernel_linux && check_extra_config
  74. }
  75.  
  76. pkg_setup() {
  77.         # try to turn off distcc and ccache for people that have a problem with it
  78.         export DISTCC_DISABLE=1
  79.         export CCACHE_DISABLE=1
  80.  
  81.         if use kernel_linux; then
  82.                 linux-mod_pkg_setup
  83.                 MODULE_NAMES="nvidia(video:${S}/kernel)"
  84.                 BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
  85.                SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC)"
  86.                 # linux-mod_src_compile calls set_arch_to_kernel, which
  87.                 # sets the ARCH to x86 but NVIDIA's wrapping Makefile
  88.                 # expects x86_64 or i386 and then converts it to x86
  89.                 # later on in the build process
  90.                 BUILD_FIXES="ARCH=$(uname -m | sed -e 's/i.86/i386/')"
  91.         fi
  92.  
  93.         # Since Nvidia ships 3 different series of drivers, we need to give the user
  94.         # some kind of guidance as to what version they should install. This tries
  95.         # to point the user in the right direction but can't be perfect. check
  96.         # nvidia-driver.eclass
  97.         nvidia-driver-check-warning
  98.  
  99.         # set variables to where files are in the package structure
  100.         if use kernel_FreeBSD; then
  101.                 use x86-fbsd   && S="${WORKDIR}/${X86_FBSD_NV_PACKAGE}"
  102.                 use amd64-fbsd && S="${WORKDIR}/${AMD64_FBSD_NV_PACKAGE}"
  103.                 NV_DOC="${S}/doc"
  104.                 NV_OBJ="${S}/obj"
  105.                 NV_SRC="${S}/src"
  106.                 NV_MAN="${S}/x11/man"
  107.                 NV_X11="${S}/obj"
  108.                 NV_SOVER=1
  109.         elif use kernel_linux; then
  110.                 NV_DOC="${S}"
  111.                 NV_OBJ="${S}"
  112.                 NV_SRC="${S}/kernel"
  113.                 NV_MAN="${S}"
  114.                 NV_X11="${S}"
  115.                 NV_SOVER=${PV}
  116.         else
  117.                 die "Could not determine proper NVIDIA package"
  118.         fi
  119. }
  120.  
  121. src_unpack() {
  122.         if ! use kernel_FreeBSD; then
  123.                 cd "${S}"
  124.                 unpack_makeself
  125.         else
  126.                 unpack ${A}
  127.         fi
  128. }
  129.  
  130. src_prepare() {
  131.         # Please add a brief description for every added patch
  132.  
  133.         if use kernel_linux; then
  134.                 if kernel_is lt 2 6 9 ; then
  135.                         eerror "You must build this against 2.6.9 or higher kernels."
  136.                 fi
  137.  
  138.                 # If greater than 2.6.5 use M= instead of SUBDIR=
  139.                 convert_to_m "${NV_SRC}"/Makefile.kbuild
  140.         fi
  141.  
  142.         if use pax_kernel; then
  143.                 ewarn "Using PAX patches is not supported. You will be asked to"
  144.                 ewarn "use a standard kernel should you have issues. Should you"
  145.                 ewarn "need support with these patches, contact the PaX team."
  146.             epatch "${FILESDIR}"/nvidia-drivers-pax-const.patch
  147.             epatch "${FILESDIR}"/nvidia-drivers-pax-usercopy.patch
  148.         fi
  149.  
  150.         epatch "${FILESDIR}"/${PN}-313.18-builddir-config.patch
  151.         epatch "${FILESDIR}"/${PN}-313.18-linux-3.7+.patch #447566
  152.         epatch "${FILESDIR}"/${PN}-313.18-linux-3.8+.patch
  153.  
  154.         # Allow user patches so they can support RC kernels and whatever else
  155.         epatch_user
  156. }
  157.  
  158. src_compile() {
  159.         # This is already the default on Linux, as there's no toplevel Makefile, but
  160.         # on FreeBSD there's one and triggers the kernel module build, as we install
  161.         # it by itself, pass this.
  162.  
  163.         cd "${NV_SRC}"
  164.         if use kernel_FreeBSD; then
  165.                 MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
  166.                         LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
  167.         elif use kernel_linux; then
  168.                 linux-mod_src_compile
  169.         fi
  170. }
  171.  
  172. # Install nvidia library:
  173. # the first parameter is the library to install
  174. # the second parameter is the provided soversion
  175. # the third parameter is the target directory if its not /usr/lib
  176. donvidia() {
  177.         # Full path to library minus SOVER
  178.         MY_LIB="$1"
  179.  
  180.         # SOVER to use
  181.         MY_SOVER="$2"
  182.  
  183.         # Where to install
  184.         MY_DEST="$3"
  185.  
  186.         if [[ -z "${MY_DEST}" ]]; then
  187.                 MY_DEST="/usr/$(get_libdir)"
  188.                 action="dolib.so"
  189.         else
  190.                 exeinto ${MY_DEST}
  191.                 action="doexe"
  192.         fi
  193.  
  194.         # Get just the library name
  195.         libname=$(basename $1)
  196.  
  197.         # Install the library with the correct SOVER
  198.         ${action} ${MY_LIB}.${MY_SOVER} || \
  199.                 die "failed to install ${libname}"
  200.  
  201.         # If SOVER wasn't 1, then we need to create a .1 symlink
  202.         if [[ "${MY_SOVER}" != "1" ]]; then
  203.                 dosym ${libname}.${MY_SOVER} \
  204.                         ${MY_DEST}/${libname}.1 || \
  205.                         die "failed to create ${libname} symlink"
  206.         fi
  207.  
  208.         # Always create the symlink from the raw lib to the .1
  209.         dosym ${libname}.1 \
  210.                 ${MY_DEST}/${libname} || \
  211.                 die "failed to create ${libname} symlink"
  212. }
  213.  
  214. src_install() {
  215.         if use kernel_linux; then
  216.                 linux-mod_src_install
  217.  
  218.                 VIDEOGROUP="$(egetent group video | cut -d ':' -f 3)"
  219.                 if [ -z "$VIDEOGROUP" ]; then
  220.                         eerror "Failed to determine the video group gid."
  221.                         die "Failed to determine the video group gid."
  222.                 fi
  223.  
  224.                 # Add the aliases
  225.                 [ -f "${FILESDIR}/nvidia-169.07" ] || die "nvidia missing in FILESDIR"
  226.                 sed -e 's:PACKAGE:'${PF}':g' \
  227.                         -e 's:VIDEOGID:'${VIDEOGROUP}':' "${FILESDIR}"/nvidia-169.07 > \
  228.                         "${WORKDIR}"/nvidia
  229.                 insinto /etc/modprobe.d
  230.                 newins "${WORKDIR}"/nvidia nvidia.conf || die
  231.  
  232.                 # Ensures that our device nodes are created when not using X
  233.                 exeinto "$(udev_get_udevdir)"
  234.                 doexe "${FILESDIR}"/nvidia-udev.sh
  235.                 udev_newrules "${FILESDIR}"/nvidia.udev-rule 99-nvidia.rules
  236.  
  237.         elif use kernel_FreeBSD; then
  238.                 if use x86-fbsd; then
  239.                         insinto /boot/modules
  240.                         doins "${S}/src/nvidia.kld" || die
  241.                 fi
  242.  
  243.                 exeinto /boot/modules
  244.                 doexe "${S}/src/nvidia.ko" || die
  245.         fi
  246.  
  247.         # NVIDIA kernel <-> userspace driver config lib
  248.         donvidia ${NV_OBJ}/libnvidia-cfg.so ${NV_SOVER}
  249.  
  250.         # NVIDIA video encode/decode <-> CUDA
  251.         if use kernel_linux; then
  252.                 donvidia ${NV_OBJ}/libnvcuvid.so ${NV_SOVER}
  253.                 donvidia ${NV_OBJ}/libnvidia-encode.so ${NV_SOVER}
  254.         fi
  255.  
  256.         if use X; then
  257.                 # Xorg DDX driver
  258.                 insinto /usr/$(get_libdir)/xorg/modules/drivers
  259.                 doins ${NV_X11}/nvidia_drv.so || die "failed to install nvidia_drv.so"
  260.  
  261.                 # Xorg GLX driver
  262.                 donvidia ${NV_X11}/libglx.so ${NV_SOVER} \
  263.                         /usr/$(get_libdir)/opengl/nvidia/extensions
  264.         fi
  265.  
  266.         # OpenCL ICD for NVIDIA
  267.         if use kernel_linux; then
  268.                 insinto /etc/OpenCL/vendors
  269.                 doins ${NV_OBJ}/nvidia.icd
  270.         fi
  271.  
  272.         # Documentation
  273.         dohtml ${NV_DOC}/html/*
  274.         if use kernel_FreeBSD; then
  275.                 dodoc "${NV_DOC}/README"
  276.                 use X && doman "${NV_MAN}/nvidia-xconfig.1"
  277.                 use tools && doman "${NV_MAN}/nvidia-settings.1"
  278.         else
  279.                 # Docs
  280.                 newdoc "${NV_DOC}/README.txt" README
  281.                 dodoc "${NV_DOC}/NVIDIA_Changelog"
  282.                 doman "${NV_MAN}/nvidia-smi.1.gz"
  283.                 use X && doman "${NV_MAN}/nvidia-xconfig.1.gz"
  284.                 use tools && doman "${NV_MAN}/nvidia-settings.1.gz"
  285.                 doman "${NV_MAN}/nvidia-cuda-proxy-control.1.gz"
  286.         fi
  287.  
  288.         # Helper Apps
  289.         exeinto /opt/bin/
  290.  
  291.         if use X; then
  292.                 doexe ${NV_OBJ}/nvidia-xconfig || die
  293.         fi
  294.  
  295.         if use kernel_linux ; then
  296.                 doexe ${NV_OBJ}/nvidia-debugdump || die
  297.                 doexe ${NV_OBJ}/nvidia-cuda-proxy-control || die
  298.                 doexe ${NV_OBJ}/nvidia-cuda-proxy-server || die
  299.                 doexe ${NV_OBJ}/nvidia-smi || die
  300.                 newinitd "${FILESDIR}/nvidia-smi.init" nvidia-smi
  301.         fi
  302.  
  303.         if use tools; then
  304.                 doexe ${NV_OBJ}/nvidia-settings || die
  305.         fi
  306.  
  307.         exeinto /usr/bin/
  308.         doexe ${NV_OBJ}/nvidia-bug-report.sh || die
  309.  
  310.         # Desktop entries for nvidia-settings
  311.         if use tools ; then
  312.                 # There is no icon in the FreeBSD tarball.
  313.                 use kernel_FreeBSD || newicon ${NV_OBJ}/nvidia-settings.png nvidia-drivers-settings.png
  314.                 domenu "${FILESDIR}"/nvidia-drivers-settings.desktop
  315.                 exeinto /etc/X11/xinit/xinitrc.d
  316.                 doexe "${FILESDIR}"/95-nvidia-settings
  317.         fi
  318.  
  319.         #doenvd "${FILESDIR}"/50nvidia-prelink-blacklist
  320.  
  321.         if has_multilib_profile && use multilib ; then
  322.                 local OABI=${ABI}
  323.                 for ABI in $(get_install_abis) ; do
  324.                         src_install-libs
  325.                 done
  326.                 ABI=${OABI}
  327.                 unset OABI
  328.         else
  329.                 src_install-libs
  330.         fi
  331.  
  332.         is_final_abi || die "failed to iterate through all ABIs"
  333. }
  334.  
  335. src_install-libs() {
  336.         local inslibdir=$(get_libdir)
  337.         local GL_ROOT="/usr/$(get_libdir)/opengl/nvidia/lib"
  338.         local CL_ROOT="/usr/$(get_libdir)/OpenCL/vendors/nvidia"
  339.         local libdir=${NV_OBJ}
  340.  
  341.         if use kernel_linux && has_multilib_profile && \
  342.                         [[ ${ABI} == "x86" ]] ; then
  343.                 libdir=${NV_OBJ}/32
  344.         fi
  345.  
  346.         if use X; then
  347.                 # The GLX libraries
  348.                 donvidia ${libdir}/libGL.so ${NV_SOVER} ${GL_ROOT}
  349.                 donvidia ${libdir}/libnvidia-glcore.so ${NV_SOVER}
  350.                 if use kernel_FreeBSD; then
  351.                         donvidia ${libdir}/libnvidia-tls.so ${NV_SOVER}
  352.                 else
  353.                         donvidia ${libdir}/tls/libnvidia-tls.so ${NV_SOVER}
  354.                 fi
  355.  
  356.                 # VDPAU
  357.                 donvidia ${libdir}/libvdpau_nvidia.so ${NV_SOVER}
  358.         fi
  359.  
  360.         # NVIDIA monitoring library
  361.         if use kernel_linux ; then
  362.                 donvidia ${libdir}/libnvidia-ml.so ${NV_SOVER}
  363.         fi
  364.  
  365.         # CUDA & OpenCL
  366.         if use kernel_linux; then
  367.                 donvidia ${libdir}/libcuda.so ${NV_SOVER}
  368.                 donvidia ${libdir}/libnvidia-compiler.so ${NV_SOVER}
  369.                 donvidia ${libdir}/libOpenCL.so 1.0.0 ${CL_ROOT}
  370.                 donvidia ${libdir}/libnvidia-opencl.so ${NV_SOVER}
  371.         fi
  372. }
  373.  
  374. pkg_preinst() {
  375.         use kernel_linux && linux-mod_pkg_preinst
  376.  
  377.         # Clean the dynamic libGL stuff's home to ensure
  378.         # we dont have stale libs floating around
  379.         if [ -d "${ROOT}"/usr/lib/opengl/nvidia ] ; then
  380.                 rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
  381.         fi
  382.         # Make sure we nuke the old nvidia-glx's env.d file
  383.         if [ -e "${ROOT}"/etc/env.d/09nvidia ] ; then
  384.                 rm -f "${ROOT}"/etc/env.d/09nvidia
  385.         fi
  386. }
  387.  
  388. pkg_postinst() {
  389.         use kernel_linux && linux-mod_pkg_postinst
  390.  
  391.         # Switch to the nvidia implementation
  392.         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old nvidia
  393.         "${ROOT}"/usr/bin/eselect opencl set --use-old nvidia
  394.  
  395.         elog "You must be in the video group to use the NVIDIA device"
  396.         elog "For more info, read the docs at"
  397.         elog "http://www.gentoo.org/doc/en/nvidia-guide.xml#doc_chap3_sect6"
  398.         elog
  399.         elog "This ebuild installs a kernel module and X driver. Both must"
  400.         elog "match explicitly in their version. This means, if you restart"
  401.         elog "X, you must modprobe -r nvidia before starting it back up"
  402.         elog
  403.         elog "To use the NVIDIA GLX, run \"eselect opengl set nvidia\""
  404.         elog
  405.         elog "To use the NVIDIA CUDA/OpenCL, run \"eselect opencl set nvidia\""
  406.         elog
  407.         elog "NVIDIA has requested that any bug reports submitted have the"
  408.         elog "output of /opt/bin/nvidia-bug-report.sh included."
  409.         elog
  410.         if ! use X; then
  411.                 elog "You have elected to not install the X.org driver. Along with"
  412.                 elog "this the OpenGL libraries and VDPAU libraries were not"
  413.                 elog "installed. Additionally, once the driver is loaded your card"
  414.                 elog "and fan will run at max speed which may not be desirable."
  415.                 elog "Use the 'nvidia-smi' init script to have your card and fan"
  416.                 elog "speed scale appropriately."
  417.                 elog
  418.         fi
  419.         if ! use tools; then
  420.                 elog "USE=tools controls whether the nvidia-settings application"
  421.                 elog "is installed. If you would like to use it, enable that"
  422.                 elog "flag and re-emerge this ebuild. Optionally you can install"
  423.                 elog "media-video/nvidia-settings"
  424.                 elog
  425.         fi
  426. }
  427.  
  428. pkg_prerm() {
  429.         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
  430. }
  431.  
  432. pkg_postrm() {
  433.         use kernel_linux && linux-mod_pkg_postrm
  434.         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement