spacepaste

  1.  
  2. # Copyright 1999-2018 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. EAPI=6
  5. EGIT_REPO_URI="https://gitlab.freedesktop.org/mesa/mesa.git"
  6. if [[ ${PV} = 9999 ]]; then
  7. GIT_ECLASS="git-r3"
  8. EXPERIMENTAL="true"
  9. fi
  10. PYTHON_COMPAT=( python2_7 )
  11. inherit autotools llvm multilib-minimal python-any-r1 pax-utils ${GIT_ECLASS}
  12. OPENGL_DIR="xorg-x11"
  13. MY_P="${P/_/-}"
  14. DESCRIPTION="OpenGL-like graphic library for Linux"
  15. HOMEPAGE="https://www.mesa3d.org/ https://mesa.freedesktop.org/"
  16. if [[ $PV == 9999 ]]; then
  17. SRC_URI=""
  18. else
  19. SRC_URI="https://mesa.freedesktop.org/archive/${MY_P}.tar.xz"
  20. KEYWORDS="amd64 ~arm ~arm64 ~ppc x86"
  21. fi
  22. LICENSE="MIT"
  23. SLOT="0"
  24. RESTRICT="!bindist? ( bindist )"
  25. RADEON_CARDS="r100 r200 r300 r600 radeon radeonsi"
  26. VIDEO_CARDS="${RADEON_CARDS} freedreno i915 i965 imx intel nouveau vc4 virgl vivante vmware"
  27. for card in ${VIDEO_CARDS}; do
  28. IUSE_VIDEO_CARDS+=" video_cards_${card}"
  29. done
  30. IUSE="${IUSE_VIDEO_CARDS}
  31. bindist +classic d3d9 debug +dri3 +egl +gallium +gbm gles1 gles2 unwind
  32. +llvm +nptl opencl osmesa pax_kernel openmax pic selinux vaapi valgrind
  33. vdpau vulkan wayland xvmc xa"
  34. REQUIRED_USE="
  35. d3d9? ( dri3 gallium )
  36. llvm? ( gallium )
  37. opencl? ( gallium llvm || ( video_cards_r600 video_cards_radeonsi ) )
  38. openmax? ( gallium )
  39. gles1? ( egl )
  40. gles2? ( egl )
  41. vaapi? ( gallium )
  42. vdpau? ( gallium )
  43. vulkan? ( || ( video_cards_i965 video_cards_radeonsi )
  44. video_cards_radeonsi? ( llvm ) )
  45. wayland? ( egl gbm )
  46. xa? ( gallium )
  47. video_cards_freedreno? ( gallium )
  48. video_cards_intel? ( classic )
  49. video_cards_i915? ( || ( classic gallium ) )
  50. video_cards_i965? ( classic )
  51. video_cards_imx? ( gallium video_cards_vivante )
  52. video_cards_nouveau? ( || ( classic gallium ) )
  53. video_cards_radeon? ( || ( classic gallium )
  54. gallium? ( x86? ( llvm ) amd64? ( llvm ) ) )
  55. video_cards_r100? ( classic )
  56. video_cards_r200? ( classic )
  57. video_cards_r300? ( gallium x86? ( llvm ) amd64? ( llvm ) )
  58. video_cards_r600? ( gallium )
  59. video_cards_radeonsi? ( gallium llvm )
  60. video_cards_vc4? ( gallium )
  61. video_cards_virgl? ( gallium )
  62. video_cards_vivante? ( gallium gbm )
  63. video_cards_vmware? ( gallium )
  64. "
  65. LIBDRM_DEPSTRING=">=x11-libs/libdrm-2.4.91"
  66. RDEPEND="
  67. !app-eselect/eselect-mesa
  68. >=app-eselect/eselect-opengl-1.3.0
  69. >=dev-libs/expat-2.1.0-r3:=[${MULTILIB_USEDEP}]
  70. >=sys-libs/zlib-1.2.8[${MULTILIB_USEDEP}]
  71. >=x11-libs/libX11-1.6.2:=[${MULTILIB_USEDEP}]
  72. >=x11-libs/libxshmfence-1.1:=[${MULTILIB_USEDEP}]
  73. >=x11-libs/libXdamage-1.1.4-r1:=[${MULTILIB_USEDEP}]
  74. >=x11-libs/libXext-1.3.2:=[${MULTILIB_USEDEP}]
  75. >=x11-libs/libXxf86vm-1.1.3:=[${MULTILIB_USEDEP}]
  76. >=x11-libs/libxcb-1.13:=[${MULTILIB_USEDEP}]
  77. x11-libs/libXfixes:=[${MULTILIB_USEDEP}]
  78. unwind? ( sys-libs/libunwind[${MULTILIB_USEDEP}] )
  79. llvm? (
  80. video_cards_radeonsi? (
  81. virtual/libelf:0=[${MULTILIB_USEDEP}]
  82. )
  83. video_cards_r600? (
  84. virtual/libelf:0=[${MULTILIB_USEDEP}]
  85. )
  86. video_cards_radeon? (
  87. virtual/libelf:0=[${MULTILIB_USEDEP}]
  88. )
  89. )
  90. opencl? (
  91. app-eselect/eselect-opencl
  92. dev-libs/libclc
  93. virtual/libelf:0=[${MULTILIB_USEDEP}]
  94. )
  95. openmax? (
  96. >=media-libs/libomxil-bellagio-0.9.3:=[${MULTILIB_USEDEP}]
  97. x11-misc/xdg-utils
  98. )
  99. vaapi? (
  100. >=x11-libs/libva-1.7.3:=[${MULTILIB_USEDEP}]
  101. video_cards_nouveau? ( !<=x11-libs/libva-vdpau-driver-0.7.4-r3 )
  102. )
  103. vdpau? ( >=x11-libs/libvdpau-1.1:=[${MULTILIB_USEDEP}] )
  104. wayland? (
  105. >=dev-libs/wayland-1.15.0:=[${MULTILIB_USEDEP}]
  106. >=dev-libs/wayland-protocols-1.8
  107. )
  108. xvmc? ( >=x11-libs/libXvMC-1.0.8:=[${MULTILIB_USEDEP}] )
  109. ${LIBDRM_DEPSTRING}[video_cards_freedreno?,video_cards_nouveau?,video_cards_vc4?,video_cards_vivante?,video_cards_vmware?,${MULTILIB_USEDEP}]
  110. video_cards_intel? (
  111. !video_cards_i965? ( ${LIBDRM_DEPSTRING}[video_cards_intel] )
  112. )
  113. video_cards_i915? ( ${LIBDRM_DEPSTRING}[video_cards_intel] )
  114. "
  115. for card in ${RADEON_CARDS}; do
  116. RDEPEND="${RDEPEND}
  117. video_cards_${card}? ( ${LIBDRM_DEPSTRING}[video_cards_radeon] )
  118. "
  119. done
  120. RDEPEND="${RDEPEND}
  121. video_cards_radeonsi? ( ${LIBDRM_DEPSTRING}[video_cards_amdgpu] )
  122. "
  123. # Please keep the LLVM dependency block separate. Since LLVM is slotted,
  124. # we need to *really* make sure we're not pulling one than more slot
  125. # simultaneously.
  126. #
  127. # How to use it:
  128. # 1. List all the working slots (with min versions) in ||, newest first.
  129. # 2. Update the := to specify *max* version, e.g. < 7.
  130. # 3. Specify LLVM_MAX_SLOT, e.g. 6.
  131. LLVM_MAX_SLOT="6"
  132. LLVM_DEPSTR="
  133. || (
  134. sys-devel/llvm:7[${MULTILIB_USEDEP}]
  135. sys-devel/llvm:6[${MULTILIB_USEDEP}]
  136. sys-devel/llvm:5[${MULTILIB_USEDEP}]
  137. sys-devel/llvm:4[${MULTILIB_USEDEP}]
  138. >=sys-devel/llvm-3.9.0:0[${MULTILIB_USEDEP}]
  139. )
  140. sys-devel/llvm:=[${MULTILIB_USEDEP}]
  141. "
  142. LLVM_DEPSTR_AMDGPU=${LLVM_DEPSTR//]/,llvm_targets_AMDGPU(-)]}
  143. CLANG_DEPSTR=${LLVM_DEPSTR//llvm/clang}
  144. CLANG_DEPSTR_AMDGPU=${CLANG_DEPSTR//]/,llvm_targets_AMDGPU(-)]}
  145. RDEPEND="${RDEPEND}
  146. llvm? (
  147. opencl? (
  148. video_cards_r600? (
  149. ${CLANG_DEPSTR_AMDGPU}
  150. )
  151. !video_cards_r600? (
  152. video_cards_radeonsi? (
  153. ${CLANG_DEPSTR_AMDGPU}
  154. )
  155. )
  156. !video_cards_r600? (
  157. !video_cards_radeonsi? (
  158. video_cards_radeon? (
  159. ${CLANG_DEPSTR_AMDGPU}
  160. )
  161. )
  162. )
  163. !video_cards_r600? (
  164. !video_cards_radeon? (
  165. !video_cards_radeonsi? (
  166. ${CLANG_DEPSTR}
  167. )
  168. )
  169. )
  170. )
  171. !opencl? (
  172. video_cards_r600? (
  173. ${LLVM_DEPSTR_AMDGPU}
  174. )
  175. !video_cards_r600? (
  176. video_cards_radeonsi? (
  177. ${LLVM_DEPSTR_AMDGPU}
  178. )
  179. )
  180. !video_cards_r600? (
  181. !video_cards_radeonsi? (
  182. video_cards_radeon? (
  183. ${LLVM_DEPSTR_AMDGPU}
  184. )
  185. )
  186. )
  187. !video_cards_r600? (
  188. !video_cards_radeon? (
  189. !video_cards_radeonsi? (
  190. ${LLVM_DEPSTR}
  191. )
  192. )
  193. )
  194. )
  195. )
  196. "
  197. unset {LLVM,CLANG}_DEPSTR{,_AMDGPU}
  198. DEPEND="${RDEPEND}
  199. ${PYTHON_DEPS}
  200. opencl? (
  201. >=sys-devel/gcc-4.6
  202. )
  203. sys-devel/gettext
  204. virtual/pkgconfig
  205. valgrind? ( dev-util/valgrind )
  206. x11-base/xorg-proto
  207. vulkan? (
  208. $(python_gen_any_dep ">=dev-python/mako-0.7.3[\${PYTHON_USEDEP}]")
  209. )
  210. "
  211. [[ ${PV} == 9999 ]] && DEPEND+="
  212. sys-devel/bison
  213. sys-devel/flex
  214. $(python_gen_any_dep ">=dev-python/mako-0.7.3[\${PYTHON_USEDEP}]")
  215. "
  216. S="${WORKDIR}/${MY_P}"
  217. EGIT_CHECKOUT_DIR=${S}
  218. QA_WX_LOAD="
  219. x86? (
  220. !pic? (
  221. usr/lib*/libglapi.so.0.0.0
  222. usr/lib*/libGLESv1_CM.so.1.1.0
  223. usr/lib*/libGLESv2.so.2.0.0
  224. usr/lib*/libGL.so.1.2.0
  225. usr/lib*/libOSMesa.so.8.0.0
  226. )
  227. )"
  228. llvm_check_deps() {
  229. local flags=${MULTILIB_USEDEP}
  230. if use video_cards_r600 || use video_cards_radeon || use video_cards_radeonsi
  231. then
  232. flags+=",llvm_targets_AMDGPU(-)"
  233. fi
  234. if use opencl; then
  235. has_version "sys-devel/clang[${flags}]" || return 1
  236. fi
  237. has_version "sys-devel/llvm[${flags}]"
  238. }
  239. pkg_setup() {
  240. # warning message for bug 459306
  241. if use llvm && has_version sys-devel/llvm[!debug=]; then
  242. ewarn "Mismatch between debug USE flags in media-libs/mesa and sys-devel/llvm"
  243. ewarn "detected! This can cause problems. For details, see bug 459306."
  244. fi
  245. if use llvm; then
  246. llvm_pkg_setup
  247. fi
  248. python-any-r1_pkg_setup
  249. }
  250. src_prepare() {
  251. eapply "${FILESDIR}"/${PN}-17-execinfo.patch
  252. eapply "${FILESDIR}"/${PN}-17-musl-string_h.patch
  253. eapply "${FILESDIR}"/${PN}-17-musl-invocation_name.patch
  254. eapply "${FILESDIR}"/${PN}-18-musl-pthread.patch
  255. eapply "${FILESDIR}"/${PN}-18-intel-missing-time_t.patch
  256. eapply "${FILESDIR}"/${PN}-18-musl-amdgpu-include-pthread.patch
  257. eapply_user
  258. eautoreconf
  259. }
  260. multilib_src_configure() {
  261. local myconf
  262. if use classic; then
  263. # Configurable DRI drivers
  264. driver_enable swrast
  265. # Intel code
  266. driver_enable video_cards_i915 i915
  267. driver_enable video_cards_i965 i965
  268. if ! use video_cards_i915 && \
  269. ! use video_cards_i965; then
  270. driver_enable video_cards_intel i915 i965
  271. fi
  272. # Nouveau code
  273. driver_enable video_cards_nouveau nouveau
  274. # ATI code
  275. driver_enable video_cards_r100 radeon
  276. driver_enable video_cards_r200 r200
  277. if ! use video_cards_r100 && \
  278. ! use video_cards_r200; then
  279. driver_enable video_cards_radeon radeon r200
  280. fi
  281. fi
  282. if use egl; then
  283. myconf+=" --with-platforms=x11,surfaceless$(use wayland && echo ",wayland")$(use gbm && echo ",drm")"
  284. fi
  285. if use gallium; then
  286. myconf+="
  287. $(use_enable d3d9 nine)
  288. $(use_enable llvm)
  289. $(use_enable openmax omx-bellagio)
  290. $(use_enable vaapi va)
  291. $(use_enable vdpau)
  292. $(use_enable xa)
  293. $(use_enable xvmc)
  294. "
  295. use vaapi && myconf+=" --with-va-libdir=/usr/$(get_libdir)/va/drivers"
  296. gallium_enable swrast
  297. gallium_enable video_cards_vc4 vc4
  298. gallium_enable video_cards_vivante etnaviv
  299. gallium_enable video_cards_vmware svga
  300. gallium_enable video_cards_nouveau nouveau
  301. gallium_enable video_cards_i915 i915
  302. gallium_enable video_cards_imx imx
  303. if ! use video_cards_i915 && \
  304. ! use video_cards_i965; then
  305. gallium_enable video_cards_intel i915
  306. fi
  307. gallium_enable video_cards_r300 r300
  308. gallium_enable video_cards_r600 r600
  309. gallium_enable video_cards_radeonsi radeonsi
  310. if ! use video_cards_r300 && \
  311. ! use video_cards_r600; then
  312. gallium_enable video_cards_radeon r300 r600
  313. fi
  314. gallium_enable video_cards_freedreno freedreno
  315. # opencl stuff
  316. if use opencl; then
  317. myconf+="
  318. $(use_enable opencl)
  319. --with-clang-libdir="${EPREFIX}/usr/lib"
  320. "
  321. fi
  322. gallium_enable video_cards_virgl virgl
  323. fi
  324. if use vulkan; then
  325. vulkan_enable video_cards_i965 intel
  326. vulkan_enable video_cards_radeonsi radeon
  327. fi
  328. # x86 hardened pax_kernel needs glx-rts, bug 240956
  329. if [[ ${ABI} == x86 ]]; then
  330. myconf+=" $(use_enable pax_kernel glx-read-only-text)"
  331. fi
  332. # on abi_x86_32 hardened we need to have asm disable
  333. if [[ ${ABI} == x86* ]] && use pic; then
  334. myconf+=" --disable-asm"
  335. fi
  336. if use gallium; then
  337. myconf+=" $(use_enable osmesa gallium-osmesa)"
  338. else
  339. myconf+=" $(use_enable osmesa)"
  340. fi
  341. # build fails with BSD indent, bug #428112
  342. use userland_GNU || export INDENT=cat
  343. ECONF_SOURCE="${S}" \
  344. econf \
  345. --enable-dri \
  346. --enable-glx \
  347. --enable-shared-glapi \
  348. $(use_enable !bindist texture-float) \
  349. $(use_enable d3d9 nine) \
  350. $(use_enable debug) \
  351. $(use_enable dri3) \
  352. $(use_enable egl) \
  353. $(use_enable gbm) \
  354. $(use_enable gles1) \
  355. $(use_enable gles2) \
  356. $(use_enable nptl glx-tls) \
  357. $(use_enable unwind libunwind) \
  358. --enable-valgrind=$(usex valgrind auto no) \
  359. --enable-llvm-shared-libs \
  360. --disable-opencl-icd \
  361. --with-dri-drivers=${DRI_DRIVERS} \
  362. --with-gallium-drivers=${GALLIUM_DRIVERS} \
  363. --with-vulkan-drivers=${VULKAN_DRIVERS} \
  364. PYTHON2="${PYTHON}" \
  365. ${myconf}
  366. }
  367. multilib_src_install() {
  368. emake install DESTDIR="${D}"
  369. if use wayland; then
  370. # These files are now provided by >=dev-libs/wayland-1.15.0
  371. rm "${ED}/usr/$(get_libdir)/libwayland-egl.so" || die
  372. rm "${ED}/usr/$(get_libdir)/libwayland-egl.so.1" || die
  373. rm "${ED}/usr/$(get_libdir)/libwayland-egl.so.1.0.0" || die
  374. rm "${ED}/usr/$(get_libdir)/pkgconfig/wayland-egl.pc" || die
  375. fi
  376. if use opencl; then
  377. ebegin "Moving Gallium/Clover OpenCL implementation for dynamic switching"
  378. local cl_dir="/usr/$(get_libdir)/OpenCL/vendors/mesa"
  379. dodir ${cl_dir}/{lib,include}
  380. if [ -f "${ED}/usr/$(get_libdir)/libOpenCL.so" ]; then
  381. mv -f "${ED}"/usr/$(get_libdir)/libOpenCL.so* \
  382. "${ED}"${cl_dir}
  383. fi
  384. if [ -f "${ED}/usr/include/CL/opencl.h" ]; then
  385. mv -f "${ED}"/usr/include/CL \
  386. "${ED}"${cl_dir}/include
  387. fi
  388. eend $?
  389. fi
  390. if use openmax; then
  391. echo "XDG_DATA_DIRS=\"${EPREFIX}/usr/share/mesa/xdg\"" > "${T}/99mesaxdgomx"
  392. doenvd "${T}"/99mesaxdgomx
  393. keepdir /usr/share/mesa/xdg
  394. fi
  395. }
  396. multilib_src_install_all() {
  397. find "${ED}" -name '*.la' -delete
  398. einstalldocs
  399. if use !bindist; then
  400. dodoc docs/patents.txt
  401. fi
  402. }
  403. multilib_src_test() {
  404. if use llvm; then
  405. local llvm_tests='lp_test_arit lp_test_arit lp_test_blend lp_test_blend lp_test_conv lp_test_conv lp_test_format lp_test_format lp_test_printf lp_test_printf'
  406. pushd src/gallium/drivers/llvmpipe >/dev/null || die
  407. emake ${llvm_tests}
  408. pax-mark m ${llvm_tests}
  409. popd >/dev/null || die
  410. fi
  411. emake check
  412. }
  413. pkg_postinst() {
  414. # Switch to the xorg implementation.
  415. echo
  416. eselect opengl set --use-old ${OPENGL_DIR}
  417. # Switch to mesa opencl
  418. if use opencl; then
  419. eselect opencl set --use-old ${PN}
  420. fi
  421. # run omxregister-bellagio to make the OpenMAX drivers known system-wide
  422. if use openmax; then
  423. ebegin "Registering OpenMAX drivers"
  424. BELLAGIO_SEARCH_PATH="${EPREFIX}/usr/$(get_libdir)/libomxil-bellagio0" \
  425. OMX_BELLAGIO_REGISTRY=${EPREFIX}/usr/share/mesa/xdg/.omxregister \
  426. omxregister-bellagio
  427. eend $?
  428. fi
  429. # warn about patent encumbered texture-float
  430. if use !bindist; then
  431. elog "USE=\"bindist\" was not set. Potentially patent encumbered code was"
  432. elog "enabled. Please see /usr/share/doc/${P}/patents.txt.bz2 for an"
  433. elog "explanation."
  434. fi
  435. }
  436. pkg_prerm() {
  437. if use openmax; then
  438. rm "${EPREFIX}"/usr/share/mesa/xdg/.omxregister
  439. fi
  440. }
  441. # $1 - VIDEO_CARDS flag
  442. # other args - names of DRI drivers to enable
  443. # TODO: avoid code duplication for a more elegant implementation
  444. driver_enable() {
  445. case $# in
  446. # for enabling unconditionally
  447. 1)
  448. DRI_DRIVERS+=",$1"
  449. ;;
  450. *)
  451. if use $1; then
  452. shift
  453. for i in $@; do
  454. DRI_DRIVERS+=",${i}"
  455. done
  456. fi
  457. ;;
  458. esac
  459. }
  460. gallium_enable() {
  461. case $# in
  462. # for enabling unconditionally
  463. 1)
  464. GALLIUM_DRIVERS+=",$1"
  465. ;;
  466. *)
  467. if use $1; then
  468. shift
  469. for i in $@; do
  470. GALLIUM_DRIVERS+=",${i}"
  471. done
  472. fi
  473. ;;
  474. esac
  475. }
  476. vulkan_enable() {
  477. case $# in
  478. # for enabling unconditionally
  479. 1)
  480. VULKAN_DRIVERS+=",$1"
  481. ;;
  482. *)
  483. if use $1; then
  484. shift
  485. for i in $@; do
  486. VULKAN_DRIVERS+=",${i}"
  487. done
  488. fi
  489. ;;
  490. esac
  491. }
  492.