nvidia-drivers-304.134-r1.ebuild 13 KB

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