*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / media-libs / mesa / mesa-9999.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_6 python3_7 )
7
8 inherit llvm meson multilib-minimal pax-utils python-any-r1
9
10 OPENGL_DIR="xorg-x11"
11
12 MY_P="${P/_/-}"
13
14 DESCRIPTION="OpenGL-like graphic library for Linux"
15 HOMEPAGE="https://www.mesa3d.org/ https://mesa.freedesktop.org/"
16
17 if [[ ${PV} == 9999 ]]; then
18         EGIT_REPO_URI="https://gitlab.freedesktop.org/mesa/mesa.git"
19         inherit git-r3
20 else
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"
23 fi
24
25 LICENSE="MIT"
26 SLOT="0"
27 RESTRICT="
28         !test? ( test )
29 "
30
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}"
35 done
36
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"
41
42 REQUIRED_USE="
43         d3d9?   ( dri3 || ( video_cards_iris video_cards_r300 video_cards_r600 video_cards_radeonsi video_cards_nouveau video_cards_vmware ) )
44         gles1?  ( egl )
45         gles2?  ( egl )
46         vulkan? ( dri3
47                           || ( video_cards_i965 video_cards_iris video_cards_radeonsi )
48                           video_cards_radeonsi? ( llvm ) )
49         vulkan-overlay? ( vulkan )
50         wayland? ( egl gbm )
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 )
70         xa? ( X )
71         xvmc? ( X )
72 "
73
74 LIBDRM_DEPSTRING=">=x11-libs/libdrm-2.4.100"
75 RDEPEND="
76         !app-eselect/eselect-mesa
77         >=dev-libs/expat-2.1.0-r3:=[${MULTILIB_USEDEP}]
78         >=sys-libs/zlib-1.2.8[${MULTILIB_USEDEP}]
79         libglvnd? (
80                 >=media-libs/libglvnd-1.2.0-r1[${MULTILIB_USEDEP}]
81                 !app-eselect/eselect-opengl
82         )
83         !libglvnd? (
84                 >=app-eselect/eselect-opengl-1.3.0
85         )
86         gallium? (
87                 unwind? ( sys-libs/libunwind[${MULTILIB_USEDEP}] )
88                 llvm? (
89                         video_cards_radeonsi? (
90                                 virtual/libelf:0=[${MULTILIB_USEDEP}]
91                         )
92                         video_cards_r600? (
93                                 virtual/libelf:0=[${MULTILIB_USEDEP}]
94                         )
95                         video_cards_radeon? (
96                                 virtual/libelf:0=[${MULTILIB_USEDEP}]
97                         )
98                 )
99                 lm-sensors? ( sys-apps/lm-sensors:=[${MULTILIB_USEDEP}] )
100                 opencl? (
101                                         dev-libs/ocl-icd[khronos-headers,${MULTILIB_USEDEP}]
102                                         dev-libs/libclc
103                                         virtual/libelf:0=[${MULTILIB_USEDEP}]
104                                 )
105                 vaapi? (
106                         >=x11-libs/libva-1.7.3:=[${MULTILIB_USEDEP}]
107                 )
108                 vdpau? ( >=x11-libs/libvdpau-1.1:=[${MULTILIB_USEDEP}] )
109                 xvmc? ( >=x11-libs/libXvMC-1.0.8:=[${MULTILIB_USEDEP}] )
110         )
111         selinux? ( sys-libs/libselinux[${MULTILIB_USEDEP}] )
112         wayland? (
113                 >=dev-libs/wayland-1.15.0:=[${MULTILIB_USEDEP}]
114                 >=dev-libs/wayland-protocols-1.8
115         )
116         ${LIBDRM_DEPSTRING}[video_cards_freedreno?,video_cards_nouveau?,video_cards_vc4?,video_cards_vivante?,video_cards_vmware?,${MULTILIB_USEDEP}]
117         video_cards_intel? (
118                 !video_cards_i965? ( ${LIBDRM_DEPSTRING}[video_cards_intel] )
119         )
120         video_cards_i915? ( ${LIBDRM_DEPSTRING}[video_cards_intel] )
121         vulkan-overlay? ( dev-util/glslang:0=[${MULTILIB_USEDEP}] )
122         X? (
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}]
130         )
131 "
132 for card in ${RADEON_CARDS}; do
133         RDEPEND="${RDEPEND}
134                 video_cards_${card}? ( ${LIBDRM_DEPSTRING}[video_cards_radeon] )
135         "
136 done
137 RDEPEND="${RDEPEND}
138         video_cards_radeonsi? ( ${LIBDRM_DEPSTRING}[video_cards_amdgpu] )
139 "
140
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
143 # simultaneously.
144 #
145 # How to use it:
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.
149 LLVM_MAX_SLOT="10"
150 LLVM_DEPSTR="
151         || (
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}]
156         )
157         sys-devel/llvm:=[${MULTILIB_USEDEP}]
158 "
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(-)]}
162 RDEPEND="${RDEPEND}
163         gallium? (
164                 llvm? (
165                         opencl? (
166                                 video_cards_r600? (
167                                         ${CLANG_DEPSTR_AMDGPU}
168                                 )
169                                 !video_cards_r600? (
170                                         video_cards_radeonsi? (
171                                                 ${CLANG_DEPSTR_AMDGPU}
172                                         )
173                                 )
174                                 !video_cards_r600? (
175                                         !video_cards_radeonsi? (
176                                                 video_cards_radeon? (
177                                                         ${CLANG_DEPSTR_AMDGPU}
178                                                 )
179                                         )
180                                 )
181                                 !video_cards_r600? (
182                                         !video_cards_radeon? (
183                                                 !video_cards_radeonsi? (
184                                                         ${CLANG_DEPSTR}
185                                                 )
186                                         )
187                                 )
188                         )
189                         !opencl? (
190                                 video_cards_r600? (
191                                         ${LLVM_DEPSTR_AMDGPU}
192                                 )
193                                 !video_cards_r600? (
194                                         video_cards_radeonsi? (
195                                                 ${LLVM_DEPSTR_AMDGPU}
196                                         )
197                                 )
198                                 !video_cards_r600? (
199                                         !video_cards_radeonsi? (
200                                                 video_cards_radeon? (
201                                                         ${LLVM_DEPSTR_AMDGPU}
202                                                 )
203                                         )
204                                 )
205                                 !video_cards_r600? (
206                                         !video_cards_radeon? (
207                                                 !video_cards_radeonsi? (
208                                                         ${LLVM_DEPSTR}
209                                                 )
210                                         )
211                                 )
212                         )
213                 )
214         )
215 "
216 unset {LLVM,CLANG}_DEPSTR{,_AMDGPU}
217
218 DEPEND="${RDEPEND}
219         valgrind? ( dev-util/valgrind )
220         X? (
221                 x11-libs/libXrandr[${MULTILIB_USEDEP}]
222                 x11-base/xorg-proto
223         )
224 "
225 BDEPEND="
226         ${PYTHON_DEPS}
227         opencl? (
228                 >=sys-devel/gcc-4.6
229         )
230         sys-devel/bison
231         sys-devel/flex
232         sys-devel/gettext
233         virtual/pkgconfig
234         $(python_gen_any_dep ">=dev-python/mako-0.8.0[\${PYTHON_USEDEP}]")
235 "
236
237 S="${WORKDIR}/${MY_P}"
238 EGIT_CHECKOUT_DIR=${S}
239
240 QA_WX_LOAD="
241 x86? (
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 )
248 )"
249
250 llvm_check_deps() {
251         local flags=${MULTILIB_USEDEP}
252         if use video_cards_r600 || use video_cards_radeon || use video_cards_radeonsi
253         then
254                 flags+=",llvm_targets_AMDGPU(-)"
255         fi
256
257         if use opencl; then
258                 has_version "sys-devel/clang:${LLVM_SLOT}[${flags}]" || return 1
259         fi
260         has_version "sys-devel/llvm:${LLVM_SLOT}[${flags}]"
261 }
262
263 pkg_pretend() {
264         if use opencl; then
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"
268                 fi
269         fi
270
271         if use vaapi; then
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"
276                 fi
277         fi
278
279         if use vdpau; then
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"
285                 fi
286         fi
287
288         if use xa; then
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"
293                 fi
294         fi
295
296         if use xvmc; then
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"
300                 fi
301         fi
302
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"
312         fi
313
314         if ! use llvm; then
315                 use opencl     && ewarn "Ignoring USE=opencl     since USE does not contain llvm"
316         fi
317 }
318
319 python_check_deps() {
320         has_version -b ">=dev-python/mako-0.8.0[${PYTHON_USEDEP}]"
321 }
322
323 pkg_setup() {
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."
328         fi
329
330         if use llvm; then
331                 llvm_pkg_setup
332         fi
333         python-any-r1_pkg_setup
334 }
335
336 multilib_src_configure() {
337         local emesonargs=()
338
339         if use classic; then
340                 # Intel code
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
346                 fi
347
348                 # Nouveau code
349                 dri_driver_enable video_cards_nouveau nouveau
350
351                 # ATI code
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
357                 fi
358         fi
359
360         emesonargs+=( -Dplatforms=surfaceless$(use X && echo ",x11")$(use wayland && echo ",wayland")$(use gbm && echo ",drm") )
361
362         if use gallium; then
363                 emesonargs+=(
364                         $(meson_use llvm)
365                         $(meson_use lm-sensors lmsensors)
366                         $(meson_use unwind libunwind)
367                 )
368
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))
376                 else
377                         emesonargs+=(-Dgallium-nine=false)
378                 fi
379
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 )
385                 else
386                         emesonargs+=(-Dgallium-va=false)
387                 fi
388
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))
394                 else
395                         emesonargs+=(-Dgallium-vdpau=false)
396                 fi
397
398                 if use video_cards_freedreno ||
399                    use video_cards_nouveau ||
400                    use video_cards_vmware; then
401                         emesonargs+=($(meson_use xa gallium-xa))
402                 else
403                         emesonargs+=(-Dgallium-xa=false)
404                 fi
405
406                 if use video_cards_r600 ||
407                    use video_cards_nouveau; then
408                         emesonargs+=($(meson_use xvmc gallium-xvmc))
409                 else
410                         emesonargs+=(-Dgallium-xvmc=false)
411                 fi
412
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
419                 fi
420
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
427
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
434                         fi
435                 fi
436
437                 gallium_enable video_cards_iris iris
438
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
445                 fi
446
447                 gallium_enable video_cards_freedreno freedreno
448                 gallium_enable video_cards_virgl virgl
449
450                 # opencl stuff
451                 emesonargs+=(
452                         -Dgallium-opencl="$(usex opencl icd disabled)"
453                 )
454         fi
455
456         if use vulkan; then
457                 vulkan_enable video_cards_i965 intel
458                 vulkan_enable video_cards_iris intel
459                 vulkan_enable video_cards_radeonsi amd
460         fi
461
462         if use gallium; then
463                 gallium_enable -- swrast
464                 emesonargs+=( -Dosmesa=$(usex osmesa gallium none) )
465         else
466                 dri_driver_enable -- swrast
467                 emesonargs+=( -Dosmesa=$(usex osmesa classic none) )
468         fi
469
470         driver_list() {
471                 local drivers="$(sort -u <<< "${1// /$'\n'}")"
472                 echo "${drivers//$'\n'/,}"
473         }
474
475         emesonargs+=(
476                 $(meson_use test build-tests)
477                 -Dglx=$(usex X dri disabled)
478                 -Dshared-glapi=true
479                 $(meson_use dri3)
480                 $(meson_use egl)
481                 $(meson_use gbm)
482                 $(meson_use gles1)
483                 $(meson_use gles2)
484                 $(meson_use libglvnd glvnd)
485                 $(meson_use selinux)
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)
493         )
494         meson_src_configure
495 }
496
497 multilib_src_compile() {
498         meson_src_compile
499 }
500
501 multilib_src_install() {
502         meson_src_install
503
504         use libglvnd && rm -f "${D}"/usr/$(get_libdir)/pkgconfig/{egl,gl}.pc
505 }
506
507 multilib_src_install_all() {
508         einstalldocs
509 }
510
511 multilib_src_test() {
512         meson test -v -C "${BUILD_DIR}" -t 100
513 }
514
515 pkg_postinst() {
516         if ! use libglvnd; then
517                 # Switch to the xorg implementation.
518                 echo
519                 eselect opengl set --use-old ${OPENGL_DIR}
520         fi
521 }
522
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
527                 shift
528                 DRI_DRIVERS+=("$@")
529         fi
530 }
531
532 gallium_enable() {
533         if [[ $1 == -- ]] || use $1; then
534                 shift
535                 GALLIUM_DRIVERS+=("$@")
536         fi
537 }
538
539 vulkan_enable() {
540         if [[ $1 == -- ]] || use $1; then
541                 shift
542                 VULKAN_DRIVERS+=("$@")
543         fi
544 }