1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_6 python3_7 )
8 inherit llvm meson multilib-minimal pax-utils python-any-r1
14 DESCRIPTION="OpenGL-like graphic library for Linux"
15 HOMEPAGE="https://www.mesa3d.org/ https://mesa.freedesktop.org/"
17 if [[ ${PV} == 9999 ]]; then
18 EGIT_REPO_URI="https://gitlab.freedesktop.org/mesa/mesa.git"
21 SRC_URI="https://mesa.freedesktop.org/archive/${MY_P}.tar.xz"
22 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-linux ~x86-linux ~sparc-solaris ~x64-solaris ~x86-solaris"
31 RADEON_CARDS="r100 r200 r300 r600 radeon radeonsi"
32 VIDEO_CARDS="${RADEON_CARDS} freedreno i915 i965 intel iris lima nouveau panfrost vc4 virgl vivante vmware"
33 for card in ${VIDEO_CARDS}; do
34 IUSE_VIDEO_CARDS+=" video_cards_${card}"
37 IUSE="${IUSE_VIDEO_CARDS}
38 +classic d3d9 debug +dri3 +egl +gallium +gbm gles1 +gles2 libglvnd +llvm
39 lm-sensors opencl osmesa selinux test unwind vaapi valgrind vdpau vulkan
40 vulkan-overlay wayland +X xa xvmc"
43 d3d9? ( dri3 || ( video_cards_iris video_cards_r300 video_cards_r600 video_cards_radeonsi video_cards_nouveau video_cards_vmware ) )
47 || ( video_cards_i965 video_cards_iris video_cards_radeonsi )
48 video_cards_radeonsi? ( llvm ) )
49 vulkan-overlay? ( vulkan )
51 video_cards_freedreno? ( gallium )
52 video_cards_intel? ( classic )
53 video_cards_i915? ( || ( classic gallium ) )
54 video_cards_i965? ( classic )
55 video_cards_iris? ( gallium )
56 video_cards_lima? ( gallium )
57 video_cards_nouveau? ( || ( classic gallium ) )
58 video_cards_panfrost? ( gallium )
59 video_cards_radeon? ( || ( classic gallium )
60 gallium? ( x86? ( llvm ) amd64? ( llvm ) ) )
61 video_cards_r100? ( classic )
62 video_cards_r200? ( classic )
63 video_cards_r300? ( gallium x86? ( llvm ) amd64? ( llvm ) )
64 video_cards_r600? ( gallium )
65 video_cards_radeonsi? ( gallium llvm )
66 video_cards_vc4? ( gallium )
67 video_cards_virgl? ( gallium )
68 video_cards_vivante? ( gallium gbm )
69 video_cards_vmware? ( gallium )
74 LIBDRM_DEPSTRING=">=x11-libs/libdrm-2.4.100"
76 !app-eselect/eselect-mesa
77 >=dev-libs/expat-2.1.0-r3:=[${MULTILIB_USEDEP}]
78 >=sys-libs/zlib-1.2.8[${MULTILIB_USEDEP}]
80 >=media-libs/libglvnd-1.2.0-r1[${MULTILIB_USEDEP}]
81 !app-eselect/eselect-opengl
84 >=app-eselect/eselect-opengl-1.3.0
87 unwind? ( sys-libs/libunwind[${MULTILIB_USEDEP}] )
89 video_cards_radeonsi? (
90 virtual/libelf:0=[${MULTILIB_USEDEP}]
93 virtual/libelf:0=[${MULTILIB_USEDEP}]
96 virtual/libelf:0=[${MULTILIB_USEDEP}]
99 lm-sensors? ( sys-apps/lm-sensors:=[${MULTILIB_USEDEP}] )
101 dev-libs/ocl-icd[khronos-headers,${MULTILIB_USEDEP}]
103 virtual/libelf:0=[${MULTILIB_USEDEP}]
106 >=x11-libs/libva-1.7.3:=[${MULTILIB_USEDEP}]
108 vdpau? ( >=x11-libs/libvdpau-1.1:=[${MULTILIB_USEDEP}] )
109 xvmc? ( >=x11-libs/libXvMC-1.0.8:=[${MULTILIB_USEDEP}] )
111 selinux? ( sys-libs/libselinux[${MULTILIB_USEDEP}] )
113 >=dev-libs/wayland-1.15.0:=[${MULTILIB_USEDEP}]
114 >=dev-libs/wayland-protocols-1.8
116 ${LIBDRM_DEPSTRING}[video_cards_freedreno?,video_cards_nouveau?,video_cards_vc4?,video_cards_vivante?,video_cards_vmware?,${MULTILIB_USEDEP}]
118 !video_cards_i965? ( ${LIBDRM_DEPSTRING}[video_cards_intel] )
120 video_cards_i915? ( ${LIBDRM_DEPSTRING}[video_cards_intel] )
121 vulkan-overlay? ( dev-util/glslang:0=[${MULTILIB_USEDEP}] )
123 >=x11-libs/libX11-1.6.2:=[${MULTILIB_USEDEP}]
124 >=x11-libs/libxshmfence-1.1:=[${MULTILIB_USEDEP}]
125 >=x11-libs/libXdamage-1.1.4-r1:=[${MULTILIB_USEDEP}]
126 >=x11-libs/libXext-1.3.2:=[${MULTILIB_USEDEP}]
127 >=x11-libs/libXxf86vm-1.1.3:=[${MULTILIB_USEDEP}]
128 >=x11-libs/libxcb-1.13:=[${MULTILIB_USEDEP}]
129 x11-libs/libXfixes:=[${MULTILIB_USEDEP}]
132 for card in ${RADEON_CARDS}; do
134 video_cards_${card}? ( ${LIBDRM_DEPSTRING}[video_cards_radeon] )
138 video_cards_radeonsi? ( ${LIBDRM_DEPSTRING}[video_cards_amdgpu] )
141 # Please keep the LLVM dependency block separate. Since LLVM is slotted,
142 # we need to *really* make sure we're not pulling one than more slot
146 # 1. List all the working slots (with min versions) in ||, newest first.
147 # 2. Update the := to specify *max* version, e.g. < 10.
148 # 3. Specify LLVM_MAX_SLOT, e.g. 9.
152 sys-devel/llvm:10[${MULTILIB_USEDEP}]
153 sys-devel/llvm:9[${MULTILIB_USEDEP}]
154 sys-devel/llvm:8[${MULTILIB_USEDEP}]
155 sys-devel/llvm:7[${MULTILIB_USEDEP}]
157 sys-devel/llvm:=[${MULTILIB_USEDEP}]
159 LLVM_DEPSTR_AMDGPU=${LLVM_DEPSTR//]/,llvm_targets_AMDGPU(-)]}
160 CLANG_DEPSTR=${LLVM_DEPSTR//llvm/clang}
161 CLANG_DEPSTR_AMDGPU=${CLANG_DEPSTR//]/,llvm_targets_AMDGPU(-)]}
167 ${CLANG_DEPSTR_AMDGPU}
170 video_cards_radeonsi? (
171 ${CLANG_DEPSTR_AMDGPU}
175 !video_cards_radeonsi? (
176 video_cards_radeon? (
177 ${CLANG_DEPSTR_AMDGPU}
182 !video_cards_radeon? (
183 !video_cards_radeonsi? (
191 ${LLVM_DEPSTR_AMDGPU}
194 video_cards_radeonsi? (
195 ${LLVM_DEPSTR_AMDGPU}
199 !video_cards_radeonsi? (
200 video_cards_radeon? (
201 ${LLVM_DEPSTR_AMDGPU}
206 !video_cards_radeon? (
207 !video_cards_radeonsi? (
216 unset {LLVM,CLANG}_DEPSTR{,_AMDGPU}
219 valgrind? ( dev-util/valgrind )
221 x11-libs/libXrandr[${MULTILIB_USEDEP}]
234 $(python_gen_any_dep ">=dev-python/mako-0.8.0[\${PYTHON_USEDEP}]")
237 S="${WORKDIR}/${MY_P}"
238 EGIT_CHECKOUT_DIR=${S}
242 usr/lib*/libglapi.so.0.0.0
243 usr/lib*/libGLESv1_CM.so.1.1.0
244 usr/lib*/libGLESv2.so.2.0.0
245 usr/lib*/libGL.so.1.2.0
246 usr/lib*/libOSMesa.so.8.0.0
247 libglvnd? ( usr/lib/libGLX_mesa.so.0.0.0 )
251 local flags=${MULTILIB_USEDEP}
252 if use video_cards_r600 || use video_cards_radeon || use video_cards_radeonsi
254 flags+=",llvm_targets_AMDGPU(-)"
258 has_version "sys-devel/clang:${LLVM_SLOT}[${flags}]" || return 1
260 has_version "sys-devel/llvm:${LLVM_SLOT}[${flags}]"
265 if ! use video_cards_r600 &&
266 ! use video_cards_radeonsi; then
267 ewarn "Ignoring USE=opencl since VIDEO_CARDS does not contain r600 or radeonsi"
272 if ! use video_cards_r600 &&
273 ! use video_cards_radeonsi &&
274 ! use video_cards_nouveau; then
275 ewarn "Ignoring USE=vaapi since VIDEO_CARDS does not contain r600, radeonsi, or nouveau"
280 if ! use video_cards_r300 &&
281 ! use video_cards_r600 &&
282 ! use video_cards_radeonsi &&
283 ! use video_cards_nouveau; then
284 ewarn "Ignoring USE=vdpau since VIDEO_CARDS does not contain r300, r600, radeonsi, or nouveau"
289 if ! use video_cards_freedreno &&
290 ! use video_cards_nouveau &&
291 ! use video_cards_vmware; then
292 ewarn "Ignoring USE=xa since VIDEO_CARDS does not contain freedreno, nouveau, or vmware"
297 if ! use video_cards_r600 &&
298 ! use video_cards_nouveau; then
299 ewarn "Ignoring USE=xvmc since VIDEO_CARDS does not contain r600 or nouveau"
303 if ! use gallium; then
304 use lm-sensors && ewarn "Ignoring USE=lm-sensors since USE does not contain gallium"
305 use llvm && ewarn "Ignoring USE=llvm since USE does not contain gallium"
306 use opencl && ewarn "Ignoring USE=opencl since USE does not contain gallium"
307 use vaapi && ewarn "Ignoring USE=vaapi since USE does not contain gallium"
308 use vdpau && ewarn "Ignoring USE=vdpau since USE does not contain gallium"
309 use unwind && ewarn "Ignoring USE=unwind since USE does not contain gallium"
310 use xa && ewarn "Ignoring USE=xa since USE does not contain gallium"
311 use xvmc && ewarn "Ignoring USE=xvmc since USE does not contain gallium"
315 use opencl && ewarn "Ignoring USE=opencl since USE does not contain llvm"
319 python_check_deps() {
320 has_version -b ">=dev-python/mako-0.8.0[${PYTHON_USEDEP}]"
324 # warning message for bug 459306
325 if use llvm && has_version sys-devel/llvm[!debug=]; then
326 ewarn "Mismatch between debug USE flags in media-libs/mesa and sys-devel/llvm"
327 ewarn "detected! This can cause problems. For details, see bug 459306."
333 python-any-r1_pkg_setup
336 multilib_src_configure() {
341 dri_driver_enable video_cards_i915 i915
342 dri_driver_enable video_cards_i965 i965
343 if ! use video_cards_i915 && \
344 ! use video_cards_i965; then
345 dri_driver_enable video_cards_intel i915 i965
349 dri_driver_enable video_cards_nouveau nouveau
352 dri_driver_enable video_cards_r100 r100
353 dri_driver_enable video_cards_r200 r200
354 if ! use video_cards_r100 && \
355 ! use video_cards_r200; then
356 dri_driver_enable video_cards_radeon r100 r200
360 emesonargs+=( -Dplatforms=surfaceless$(use X && echo ",x11")$(use wayland && echo ",wayland")$(use gbm && echo ",drm") )
365 $(meson_use lm-sensors lmsensors)
366 $(meson_use unwind libunwind)
369 if use video_cards_iris ||
370 use video_cards_r300 ||
371 use video_cards_r600 ||
372 use video_cards_radeonsi ||
373 use video_cards_nouveau ||
374 use video_cards_vmware; then
375 emesonargs+=($(meson_use d3d9 gallium-nine))
377 emesonargs+=(-Dgallium-nine=false)
380 if use video_cards_r600 ||
381 use video_cards_radeonsi ||
382 use video_cards_nouveau; then
383 emesonargs+=($(meson_use vaapi gallium-va))
384 use vaapi && emesonargs+=( -Dva-libs-path="${EPREFIX}"/usr/$(get_libdir)/va/drivers )
386 emesonargs+=(-Dgallium-va=false)
389 if use video_cards_r300 ||
390 use video_cards_r600 ||
391 use video_cards_radeonsi ||
392 use video_cards_nouveau; then
393 emesonargs+=($(meson_use vdpau gallium-vdpau))
395 emesonargs+=(-Dgallium-vdpau=false)
398 if use video_cards_freedreno ||
399 use video_cards_nouveau ||
400 use video_cards_vmware; then
401 emesonargs+=($(meson_use xa gallium-xa))
403 emesonargs+=(-Dgallium-xa=false)
406 if use video_cards_r600 ||
407 use video_cards_nouveau; then
408 emesonargs+=($(meson_use xvmc gallium-xvmc))
410 emesonargs+=(-Dgallium-xvmc=false)
413 if use video_cards_freedreno ||
414 use video_cards_lima ||
415 use video_cards_panfrost ||
416 use video_cards_vc4 ||
417 use video_cards_vivante; then
418 gallium_enable -- kmsro
421 gallium_enable video_cards_lima lima
422 gallium_enable video_cards_panfrost panfrost
423 gallium_enable video_cards_vc4 vc4
424 gallium_enable video_cards_vivante etnaviv
425 gallium_enable video_cards_vmware svga
426 gallium_enable video_cards_nouveau nouveau
428 # Only one i915 driver (classic vs gallium). Default to classic.
429 if ! use classic; then
430 gallium_enable video_cards_i915 i915
431 if ! use video_cards_i915 && \
432 ! use video_cards_i965; then
433 gallium_enable video_cards_intel i915
437 gallium_enable video_cards_iris iris
439 gallium_enable video_cards_r300 r300
440 gallium_enable video_cards_r600 r600
441 gallium_enable video_cards_radeonsi radeonsi
442 if ! use video_cards_r300 && \
443 ! use video_cards_r600; then
444 gallium_enable video_cards_radeon r300 r600
447 gallium_enable video_cards_freedreno freedreno
448 gallium_enable video_cards_virgl virgl
452 -Dgallium-opencl="$(usex opencl icd disabled)"
457 vulkan_enable video_cards_i965 intel
458 vulkan_enable video_cards_iris intel
459 vulkan_enable video_cards_radeonsi amd
463 gallium_enable -- swrast
464 emesonargs+=( -Dosmesa=$(usex osmesa gallium none) )
466 dri_driver_enable -- swrast
467 emesonargs+=( -Dosmesa=$(usex osmesa classic none) )
471 local drivers="$(sort -u <<< "${1// /$'\n'}")"
472 echo "${drivers//$'\n'/,}"
476 $(meson_use test build-tests)
477 -Dglx=$(usex X dri disabled)
484 $(meson_use libglvnd glvnd)
486 -Dvalgrind=$(usex valgrind auto false)
487 -Ddri-drivers=$(driver_list "${DRI_DRIVERS[*]}")
488 -Dgallium-drivers=$(driver_list "${GALLIUM_DRIVERS[*]}")
489 -Dvulkan-drivers=$(driver_list "${VULKAN_DRIVERS[*]}")
490 $(meson_use vulkan-overlay vulkan-overlay-layer)
491 --buildtype $(usex debug debug plain)
492 -Db_ndebug=$(usex debug false true)
497 multilib_src_compile() {
501 multilib_src_install() {
504 use libglvnd && rm -f "${D}"/usr/$(get_libdir)/pkgconfig/{egl,gl}.pc
507 multilib_src_install_all() {
511 multilib_src_test() {
512 meson test -v -C "${BUILD_DIR}" -t 100
516 if ! use libglvnd; then
517 # Switch to the xorg implementation.
519 eselect opengl set --use-old ${OPENGL_DIR}
523 # $1 - VIDEO_CARDS flag (check skipped for "--")
524 # other args - names of DRI drivers to enable
525 dri_driver_enable() {
526 if [[ $1 == -- ]] || use $1; then
533 if [[ $1 == -- ]] || use $1; then
535 GALLIUM_DRIVERS+=("$@")
540 if [[ $1 == -- ]] || use $1; then
542 VULKAN_DRIVERS+=("$@")