#!/usr/bin/env bash
name='mesa'
release='12'
version='26.0.1'
url='https://gitlab.freedesktop.org/mesa/mesa'
description='An open-source implementation of the OpenGL specification'
email='aliriza.keskin@pardus.org.tr'
maintainer='aliriza'
license=('GPLv3')
source=("https://gitlab.freedesktop.org/mesa/mesa/-/archive/mesa-$version/mesa-mesa-$version.tar.gz")
depends=(libva libvdpau libdrm llvm glslang elfutils libclc py3-mako libglvnd eudev)
makedepends=(git directx-headers py3-ply py3-yaml clang lld spirv-llvm-translator)
sha256sums=('4582190fe895126890b5b84457e885555f194f5387c2ed4a6f4a3021ace9e5f8')
group=(media.libs)
uses=(wayland x11)
wayland_depends=(wayland wayland-protocols)
x11_depends=(libxshmfence libXxf86vm libXrandr)
arch=('x86_64')

cd $name-$name-$version

export CFLAGS="-O3 -s"
export CXXFLAGS="-O3 -s"

export PATH=$PATH:/usr/lib64/rust/toolchains/stable-$(uname -m)-unknown-linux-gnu/bin:$HOME/.cargo/bin

prepare(){
# install rust stuff
    cargo install bindgen-cli cbindgen
}

options=(
    -D android-libbacktrace=disabled
    -D b_ndebug=true
    -D b_lto=false
    -D gallium-drivers=asahi,crocus,d3d12,freedreno,i915,iris,llvmpipe,nouveau,r300,r600,radeonsi,softpipe,svga,virgl,zink
    -D gallium-extra-hud=true
    -D gallium-mediafoundation=disabled
    -D gallium-rusticl-enable-drivers=asahi,freedreno,radeonsi
    -D gallium-rusticl=true
    -D gles1=disabled
    -D html-docs=disabled
    -D intel-rt=enabled
    -D libunwind=disabled
    -D microsoft-clc=disabled
    -D sysprof=false
    -D valgrind=false
    -D video-codecs=all
    -D vulkan-drivers=amd,freedreno,intel,intel_hasvk,swrast,virtio,microsoft-experimental,nouveau,asahi,gfxstream
    -D vulkan-layers=device-select,intel-nullhw,overlay,screenshot,vram-report-limit
)

unset meson

setup(){
    meson setup build --prefix=/usr \
        -D platforms=$(use_opt x11 x11 ""),$(use_opt wayland wayland "") \
        ${options[@]}

}

build(){
    ninja -C build ${jobs}
}

package(){
    ninja -C build install
}

