kosmik2001

nvidia-drivers-340.108-r1.ebuild changed

Aug 15th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.91 KB | None | 0 0
  1.  
  2. # Copyright 1999-2020 Gentoo Authors
  3. # Distributed under the terms of the GNU General Public License v2
  4.  
  5. EAPI=7
  6. inherit desktop flag-o-matic linux-info linux-mod multilib-minimal \
  7.     nvidia-driver portability toolchain-funcs unpacker udev
  8.  
  9. NV_URI="https://us.download.nvidia.com/XFree86/"
  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. SRC_URI="
  16.     amd64-fbsd? ( ${NV_URI}FreeBSD-x86_64/${PV}/${AMD64_FBSD_NV_PACKAGE}.tar.gz )
  17.     amd64? ( ${NV_URI}Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}.run )
  18.     x86-fbsd? ( ${NV_URI}FreeBSD-x86/${PV}/${X86_FBSD_NV_PACKAGE}.tar.gz )
  19.     x86? ( ${NV_URI}Linux-x86/${PV}/${X86_NV_PACKAGE}.run )
  20.     tools? (
  21.         https://download.nvidia.com/XFree86/nvidia-settings/nvidia-settings-${PV}.tar.bz2
  22.     )
  23. "
  24.  
  25. EMULTILIB_PKG="true"
  26. IUSE="driver multilib kernel_FreeBSD kernel_linux +libglvnd static-libs +tools +X"
  27. KEYWORDS="-* amd64 x86"
  28. LICENSE="GPL-2 NVIDIA-r2"
  29. SLOT="0/${PV%.*}"
  30.  
  31. COMMON="
  32.     driver? ( kernel_linux? ( acct-group/video ) )
  33.     kernel_linux? ( >=sys-libs/glibc-2.6.1 )
  34.     app-eselect/eselect-opencl
  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.         !libglvnd? ( >=app-eselect/eselect-opengl-1.0.9 )
  48.         libglvnd? (
  49.         media-libs/libglvnd[${MULTILIB_USEDEP}]
  50.         !app-eselect/eselect-opengl
  51.         )
  52.         app-misc/pax-utils
  53.     )
  54. "
  55. DEPEND="
  56.     ${COMMON}
  57.     app-arch/xz-utils
  58.     kernel_linux? ( virtual/linux-sources )
  59. "
  60. RDEPEND="
  61.     ${COMMON}
  62.     tools? ( !media-video/nvidia-settings )
  63.     X? (
  64.         <x11-base/xorg-server-1.20.99:=
  65.         >=x11-libs/libvdpau-0.3-r1
  66.         sys-libs/zlib[${MULTILIB_USEDEP}]
  67.         multilib? (
  68.             >=x11-libs/libX11-1.6.2[${MULTILIB_USEDEP}]
  69.             >=x11-libs/libXext-1.3.2[${MULTILIB_USEDEP}]
  70.         )
  71.     )
  72. "
  73. REQUIRED_USE="tools? ( X )"
  74. QA_PREBUILT="opt/* usr/lib*"
  75. S=${WORKDIR}/
  76. NV_KV_MAX_PLUS="5.5"
  77. CONFIG_CHECK="
  78.     !DEBUG_MUTEXES
  79.     ~!LOCKDEP
  80.     ~DRM
  81.     ~DRM_KMS_HELPER
  82.     ~SYSVIPC
  83. "
  84.  
  85. pkg_pretend() {
  86.     use x86 && CONFIG_CHECK+=" ~HIGHMEM"
  87.     nvidia-driver_check
  88. }
  89.  
  90. pkg_setup() {
  91.     use x86 && CONFIG_CHECK+=" ~HIGHMEM"
  92.     nvidia-driver_check
  93.  
  94.     # try to turn off distcc and ccache for people that have a problem with it
  95.     export DISTCC_DISABLE=1
  96.     export CCACHE_DISABLE=1
  97.  
  98.     if use driver && use kernel_linux; then
  99.         MODULE_NAMES="nvidia(video:${S}/kernel)"
  100.  
  101.         # This needs to run after MODULE_NAMES (so that the eclass checks
  102.         # whether the kernel supports loadable modules) but before BUILD_PARAMS
  103.         # is set (so that KV_DIR is populated).
  104.         linux-mod_pkg_setup
  105.  
  106.         BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
  107.         SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC)"
  108.  
  109.         # linux-mod_src_compile calls set_arch_to_kernel, which
  110.         # sets the ARCH to x86 but NVIDIA's wrapping Makefile
  111.         # expects x86_64 or i386 and then converts it to x86
  112.         # later on in the build process
  113.         BUILD_FIXES="ARCH=$(uname -m | sed -e 's/i.86/i386/')"
  114.     fi
  115.  
  116.     # set variables to where files are in the package structure
  117.     if use kernel_FreeBSD; then
  118.         use x86-fbsd   && S="${WORKDIR}/${X86_FBSD_NV_PACKAGE}"
  119.         use amd64-fbsd && S="${WORKDIR}/${AMD64_FBSD_NV_PACKAGE}"
  120.         NV_DOC="${S}/doc"
  121.         NV_OBJ="${S}/obj"
  122.         NV_SRC="${S}/src"
  123.         NV_MAN="${S}/x11/man"
  124.         NV_X11="${S}/obj"
  125.         NV_SOVER=1
  126.     elif use kernel_linux; then
  127.         NV_DOC="${S}"
  128.         NV_OBJ="${S}"
  129.         NV_SRC="${S}/kernel"
  130.         NV_MAN="${S}"
  131.         NV_X11="${S}"
  132.         NV_SOVER=${PV}
  133.     else
  134.         die "Could not determine proper NVIDIA package"
  135.     fi
  136. }
  137.  
  138. src_prepare() {
  139.     # Please add a brief description for every added patch
  140.  
  141.     if use driver && use kernel_linux; then
  142.         if kernel_is lt 2 6 9 ; then
  143.             eerror "You must build this against 2.6.9 or higher kernels."
  144.         fi
  145.  
  146.         # If greater than 2.6.5 use M= instead of SUBDIR=
  147. #       convert_to_m "${NV_SRC}"/Makefile.kbuild
  148.     fi
  149.  
  150.     local man_file
  151.     for man_file in "${NV_MAN}"/*1.gz; do
  152.         gunzip $man_file || die
  153.     done
  154.  
  155.     if use tools; then
  156.         cp "${FILESDIR}"/nvidia-settings-fno-common.patch "${WORKDIR}" || die
  157.         sed -i \
  158.             -e "s:@PV@:${PV}:g" \
  159.             "${WORKDIR}"/nvidia-settings-fno-common.patch \
  160.             || die
  161.         eapply "${WORKDIR}"/nvidia-settings-fno-common.patch
  162.     fi
  163.  
  164.     # Allow user patches so they can support RC kernels and whatever else
  165.     eapply_user
  166. }
  167.  
  168. src_compile() {
  169.     # This is already the default on Linux, as there's no toplevel Makefile, but
  170.     # on FreeBSD there's one and triggers the kernel module build, as we install
  171.     # it by itself, pass this.
  172.  
  173.     cd "${NV_SRC}"
  174.     if use kernel_FreeBSD; then
  175.         MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
  176.             LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
  177.     elif use driver && use kernel_linux; then
  178.         BUILD_TARGETS=module linux-mod_src_compile
  179.     fi
  180.  
  181.     if use tools; then
  182.         emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl clean
  183.         emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl \
  184.             AR="$(tc-getAR)" \
  185.             CC="$(tc-getCC)" \
  186.             RANLIB="$(tc-getRANLIB)" \
  187.             libXNVCtrl.a
  188.         emake -C "${S}"/nvidia-settings-${PV}/src \
  189.             AR="$(tc-getAR)" \
  190.             CC="$(tc-getCC)" \
  191.             LD="$(tc-getCC)" \
  192.             LIBDIR="$(get_libdir)" \
  193.             NVML_ENABLED=0 \
  194.             NV_USE_BUNDLED_LIBJANSSON=0 \
  195.             NV_VERBOSE=1 \
  196.             RANLIB="$(tc-getRANLIB)" \
  197.             STRIP_CMD=true
  198.     fi
  199. }
  200.  
  201. # Install nvidia library:
  202. # the first parameter is the library to install
  203. # the second parameter is the provided soversion
  204. # the third parameter is the target directory if its not /usr/lib
  205. donvidia() {
  206.     # Full path to library minus SOVER
  207.     MY_LIB="$1"
  208.  
  209.     # SOVER to use
  210.     MY_SOVER="$2"
  211.  
  212.     # Where to install
  213.     MY_DEST="$3"
  214.  
  215.     if [[ -z "${MY_DEST}" ]]; then
  216.         MY_DEST="/usr/$(get_libdir)"
  217.         action="dolib.so"
  218.     else
  219.         exeinto ${MY_DEST}
  220.         action="doexe"
  221.     fi
  222.  
  223.     # Get just the library name
  224.     libname=$(basename $1)
  225.  
  226.     # Install the library with the correct SOVER
  227.     ${action} ${MY_LIB}.${MY_SOVER} || \
  228.         die "failed to install ${libname}"
  229.  
  230.     # If SOVER wasn't 1, then we need to create a .1 symlink
  231.     if [[ "${MY_SOVER}" != "1" ]]; then
  232.         dosym ${libname}.${MY_SOVER} \
  233.             ${MY_DEST}/${libname}.1 || \
  234.             die "failed to create ${libname} symlink"
  235.     fi
  236.  
  237.     # Always create the symlink from the raw lib to the .1
  238.     dosym ${libname}.1 \
  239.         ${MY_DEST}/${libname} || \
  240.         die "failed to create ${libname} symlink"
  241. }
  242.  
  243. src_install() {
  244.     if use driver && use kernel_linux; then
  245.         linux-mod_src_install
  246.  
  247.         # Add the aliases
  248.         # This file is tweaked with the appropriate video group in
  249.         # pkg_preinst, see bug #491414
  250.         insinto /etc/modprobe.d
  251.         newins "${FILESDIR}"/nvidia-169.07 nvidia.conf
  252.  
  253.         # Ensures that our device nodes are created when not using X
  254.         exeinto "$(get_udevdir)"
  255.         newexe "${FILESDIR}"/nvidia-udev.sh-r1 nvidia-udev.sh
  256.         udev_newrules "${FILESDIR}"/nvidia.udev-rule 99-nvidia.rules
  257.     elif use kernel_FreeBSD; then
  258.         if use x86-fbsd; then
  259.             insinto /boot/modules
  260.             doins "${S}/src/nvidia.kld"
  261.         fi
  262.  
  263.         exeinto /boot/modules
  264.         doexe "${S}/src/nvidia.ko"
  265.     fi
  266.  
  267.     # NVIDIA kernel <-> userspace driver config lib
  268.     donvidia "${NV_OBJ}"/libnvidia-cfg.so ${NV_SOVER}
  269.  
  270.     # NVIDIA framebuffer capture library
  271.     donvidia "${NV_OBJ}"/libnvidia-fbc.so ${NV_SOVER}
  272.  
  273.     # NVIDIA video encode/decode <-> CUDA
  274.     if use kernel_linux; then
  275.         donvidia "${NV_OBJ}"/libnvcuvid.so ${NV_SOVER}
  276.         donvidia "${NV_OBJ}"/libnvidia-encode.so ${NV_SOVER}
  277.     fi
  278.  
  279.     if use X; then
  280.         # Xorg DDX driver
  281.         insinto /usr/$(get_libdir)/xorg/modules/drivers
  282.         doins "${NV_X11}"/nvidia_drv.so
  283.  
  284.         # Xorg GLX driver
  285.         donvidia "${NV_X11}"/libglx.so ${NV_SOVER} \
  286.             /usr/$(get_libdir)/opengl/nvidia/extensions
  287.     fi
  288.  
  289.     # OpenCL ICD for NVIDIA
  290.     if use kernel_linux; then
  291.         insinto /etc/OpenCL/vendors
  292.         doins "${NV_OBJ}"/nvidia.icd
  293.     fi
  294.  
  295.     # Helper Apps
  296.     exeinto /opt/bin/
  297.  
  298.     if use X; then
  299.         doexe "${NV_OBJ}"/nvidia-xconfig
  300.     fi
  301.  
  302.     if use kernel_linux ; then
  303.         doexe "${NV_OBJ}"/nvidia-cuda-mps-control
  304.         doexe "${NV_OBJ}"/nvidia-cuda-mps-server
  305.         doexe "${NV_OBJ}"/nvidia-debugdump
  306.         doexe "${NV_OBJ}"/nvidia-persistenced
  307.         doexe "${NV_OBJ}"/nvidia-smi
  308.  
  309.         # install nvidia-modprobe setuid and symlink in /usr/bin (bug #505092)
  310.         doexe "${NV_OBJ}"/nvidia-modprobe
  311.         fowners root:video /opt/bin/nvidia-modprobe
  312.         fperms 4710 /opt/bin/nvidia-modprobe
  313.         dosym /{opt,usr}/bin/nvidia-modprobe
  314.  
  315.         doman nvidia-cuda-mps-control.1
  316.         doman nvidia-modprobe.1
  317.         doman nvidia-persistenced.1
  318.         newinitd "${FILESDIR}/nvidia-smi.init" nvidia-smi
  319.         newconfd "${FILESDIR}/nvidia-persistenced.conf" nvidia-persistenced
  320.         newinitd "${FILESDIR}/nvidia-persistenced.init" nvidia-persistenced
  321.     fi
  322.  
  323.     if use tools; then
  324.         emake -C "${S}"/nvidia-settings-${PV}/src/ \
  325.             DESTDIR="${D}" \
  326.             LIBDIR="${D}/usr/$(get_libdir)" \
  327.             PREFIX=/usr \
  328.             NV_USE_BUNDLED_LIBJANSSON=0 \
  329.             install
  330.  
  331.         if use static-libs; then
  332.             dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
  333.  
  334.             insinto /usr/include/NVCtrl
  335.             doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
  336.         fi
  337.  
  338.         insinto /usr/share/nvidia/
  339.         doins nvidia-application-profiles-${PV}-key-documentation
  340.  
  341.         insinto /etc/nvidia
  342.         newins \
  343.             nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
  344.  
  345.         # There is no icon in the FreeBSD tarball.
  346.         use kernel_FreeBSD || \
  347.             doicon "${NV_OBJ}"/nvidia-settings.png
  348.  
  349.         domenu "${FILESDIR}"/nvidia-settings.desktop
  350.  
  351.         exeinto /etc/X11/xinit/xinitrc.d
  352.         newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
  353.  
  354.     fi
  355.  
  356.     dobin "${NV_OBJ}"/nvidia-bug-report.sh
  357.  
  358.     #doenvd "${FILESDIR}"/50nvidia-prelink-blacklist
  359.  
  360.     if has_multilib_profile && use multilib ; then
  361.         local OABI=${ABI}
  362.         for ABI in $(multilib_get_enabled_abis) ; do
  363.             src_install-libs
  364.         done
  365.         ABI=${OABI}
  366.         unset OABI
  367.     else
  368.         src_install-libs
  369.     fi
  370.  
  371.     is_final_abi || die "failed to iterate through all ABIs"
  372.  
  373.     # Documentation
  374.     if use kernel_FreeBSD; then
  375.         dodoc "${NV_DOC}"/README
  376.         use X && doman "${NV_MAN}"/nvidia-xconfig.1
  377.         use tools && doman "${NV_MAN}"/nvidia-settings.1
  378.     else
  379.         # Docs
  380.         newdoc "${NV_DOC}"/README.txt README
  381.         dodoc "${NV_DOC}"/NVIDIA_Changelog
  382.         doman "${NV_MAN}"/nvidia-smi.1
  383.         use X && doman "${NV_MAN}"/nvidia-xconfig.1
  384.         use tools && doman "${NV_MAN}"/nvidia-settings.1
  385.         doman "${NV_MAN}"/nvidia-cuda-mps-control.1
  386.     fi
  387.  
  388.     readme.gentoo_create_doc
  389.  
  390.     docinto html
  391.     dodoc -r "${NV_DOC}"/html/*
  392. }
  393.  
  394. src_install-libs() {
  395.     local inslibdir=$(get_libdir)
  396.     if use libglvnd; then
  397.         local GL_ROOT="/usr/$(get_libdir)"
  398.     else
  399.         local GL_ROOT="/usr/$(get_libdir)/opengl/nvidia/lib"
  400.     fi
  401.     local CL_ROOT="/usr/$(get_libdir)/OpenCL/vendors/nvidia"
  402.     local nv_libdir="${NV_OBJ}"
  403.  
  404.     if use kernel_linux && has_multilib_profile && [[ ${ABI} == "x86" ]]; then
  405.         nv_libdir="${NV_OBJ}"/32
  406.     fi
  407.  
  408.     if use X; then
  409.         # The GLX libraries
  410.         donvidia "${nv_libdir}"/libEGL.so ${NV_SOVER} ${GL_ROOT}
  411.         donvidia "${nv_libdir}"/libGL.so ${NV_SOVER} ${GL_ROOT}
  412.         donvidia "${nv_libdir}"/libGLESv1_CM.so ${NV_SOVER} ${GL_ROOT}
  413.         donvidia "${nv_libdir}"/libnvidia-eglcore.so ${NV_SOVER}
  414.         donvidia "${nv_libdir}"/libnvidia-glcore.so ${NV_SOVER}
  415.         donvidia "${nv_libdir}"/libnvidia-glsi.so ${NV_SOVER}
  416.         donvidia "${nv_libdir}"/libnvidia-ifr.so ${NV_SOVER}
  417.         if use kernel_FreeBSD; then
  418.             donvidia "${nv_libdir}"/libnvidia-tls.so ${NV_SOVER}
  419.         else
  420.             donvidia "${nv_libdir}"/tls/libnvidia-tls.so ${NV_SOVER}
  421.         fi
  422.  
  423.         # VDPAU
  424.         donvidia "${nv_libdir}"/libvdpau_nvidia.so ${NV_SOVER}
  425.  
  426.         # GLES v2 libraries
  427.         insinto ${GL_ROOT}
  428.         doexe "${nv_libdir}"/libGLESv2.so.${PV}
  429.         dosym libGLESv2.so.${PV} ${GL_ROOT}/libGLESv2.so.2
  430.         dosym libGLESv2.so.2 ${GL_ROOT}/libGLESv2.so
  431.     fi
  432.  
  433.     # NVIDIA monitoring library
  434.     if use kernel_linux ; then
  435.         donvidia "${nv_libdir}"/libnvidia-ml.so ${NV_SOVER}
  436.     fi
  437.  
  438.     # CUDA & OpenCL
  439.     if use kernel_linux; then
  440.         donvidia "${nv_libdir}"/libcuda.so ${NV_SOVER}
  441.         donvidia "${nv_libdir}"/libnvidia-compiler.so ${NV_SOVER}
  442.         donvidia "${nv_libdir}"/libOpenCL.so 1.0.0 ${CL_ROOT}
  443.         donvidia "${nv_libdir}"/libnvidia-opencl.so ${NV_SOVER}
  444.     fi
  445. }
  446.  
  447. pkg_preinst() {
  448.     if use driver && use kernel_linux; then
  449.         linux-mod_pkg_preinst
  450.         local videogroup="$(getent group video | cut -d ':' -f 3)"
  451.         if [ -z "${videogroup}" ]; then
  452.             eerror "Failed to determine the video group gid"
  453.             die "Failed to determine the video group gid"
  454.         else
  455.             sed -i \
  456.                 -e "s:PACKAGE:${PF}:g" \
  457.                 -e "s:VIDEOGID:${videogroup}:" \
  458.                 "${D}"/etc/modprobe.d/nvidia.conf || die
  459.         fi
  460.     fi
  461.  
  462.     # Clean the dynamic libGL stuff's home to ensure
  463.     # we dont have stale libs floating around
  464.     if [ -d "${ROOT}"/usr/lib/opengl/nvidia ] ; then
  465.         rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
  466.     fi
  467.     # Make sure we nuke the old nvidia-glx's env.d file
  468.     if [ -e "${ROOT}"/etc/env.d/09nvidia ] ; then
  469.         rm -f "${ROOT}"/etc/env.d/09nvidia
  470.     fi
  471. }
  472.  
  473. pkg_postinst() {
  474.     use driver && use kernel_linux && linux-mod_pkg_postinst
  475.  
  476.     # Switch to the nvidia implementation
  477.     if ! use libglvnd; then
  478.         use X && "${ROOT}"/usr/bin/eselect opengl set --use-old nvidia
  479.     fi
  480.     readme.gentoo_print_elog
  481.  
  482.     if ! use X; then
  483.         elog "You have elected to not install the X.org driver. Along with"
  484.         elog "this the OpenGL libraries and VDPAU libraries were not"
  485.         elog "installed. Additionally, once the driver is loaded your card"
  486.         elog "and fan will run at max speed which may not be desirable."
  487.         elog "Use the 'nvidia-smi' init script to have your card and fan"
  488.         elog "speed scale appropriately."
  489.         elog
  490.     fi
  491.     if ! use tools; then
  492.         elog "USE=tools controls whether the nvidia-settings application"
  493.         elog "is installed. If you would like to use it, enable that"
  494.         elog "flag and re-emerge this ebuild. Optionally you can install"
  495.         elog "media-video/nvidia-settings"
  496.         elog
  497.     fi
  498. }
  499.  
  500. pkg_prerm() {
  501.     if ! use libglvnd; then
  502.     use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
  503.     fi
  504. }
  505.  
  506. pkg_postrm() {
  507.     use driver && use kernel_linux && linux-mod_pkg_postrm
  508.     if ! use libglvnd; then
  509.     use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
  510.     fi
  511. }
Add Comment
Please, Sign In to add comment