pkgname=mesa
pkgver=25.2.7
_pkgver=${pkgver/[a-z]/-&}
pkgdesc="Open-source OpenGL drivers"
homepage="https://www.mesa3d.org/"
arch=(x86_64)
license=("MIT AND BSD-3-Clause AND SGI-B-2.0")
makedepends=(
  clang
  expat
  gcc-libs
  glibc
  libdrm
  libelf
  llvm
  llvm-libs
  spirv-tools
  wayland
  wayland-scanner
  wayland-protocols
  zlib
  zstd
  cmake
  glslang
  meson
  python
  mako
  pyyaml
)
sources=("${pkgname}-${pkgver}.tar.xz")
urls=("https://mesa.freedesktop.org/archive/${sources[0]}")
md5sums=("0de4be70ff09523b3f4e1270cb0a69ef")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1

  # From Arch:
  # Include package release in version string so Chromium invalidates
  # its GPU cache; otherwise it can cause pages to render incorrectly.
  # https://bugs.launchpad.net/ubuntu/+source/chromium-browser/+bug/2020604
  echo "$_pkgver-LFS.1" >VERSION
}

src_build() {
  local meson_options=(
    --prefix=/usr
    --buildtype=plain
    --wrap-mode=nodownload
    -D legacy-x11=dri2
    -D platforms=wayland
    -D b_ndebug=true
    -D gallium-drivers=radeonsi
    -D gallium-va=enabled
    -D va-libs-path="/usr/lib/va/drivers"
    -D gallium-extra-hud=false
    -D gallium-mediafoundation=disabled
    -D opengl=true
    -D gles1=enabled
    -D gles2=enabled
    -D glvnd=enabled
    -D gbm=enabled
    -D glx=disabled
    -D libunwind=disabled
    -D sysprof=false
    -D video-codecs=all
    -D vulkan-drivers=amd
    -D vulkan-layers=device-select,overlay
    -D build-tests=false
    -D expat=enabled
    -D egl=enabled
    -D valgrind=disabled
    -D llvm=enabled
    -D amd-use-llvm=true
    -D zstd=enabled
    -D sse2=true
  )

  # Build only minimal debug info to reduce size
  CFLAGS=${CFLAGS/-g /-g1 }
  CXXFLAGS=${CXXFLAGS/-g /-g1 }

  meson setup build "${meson_options[@]}"

  meson configure build --no-pager

  meson compile -C build
}

src_install() {
  meson install -C build --destdir "$pkgdir" --no-rebuild
  install -Dm644 docs/license.rst -t "$pkgdir/usr/share/licenses/$pkgname"
}

# vim:ft=sh syn=sh et sw=2:
