# Maintainer: PktSurf <smlinux@pktsurf.in>
app=mesa
version=22.3.6
build=1sml
homepage="https://www.mesa3d.org/"
download="https://archive.mesa3d.org/mesa-$version.tar.xz"
desc="An open-source implementation of the OpenGL specification"
requires="gcc-libs  expat libxml2 llvm libdrm libx11 libxrandr libxdamage libxshmfence libxxf86vm libvdpau"

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions
}

build() {
  if [[ $arch = aarch64 ]]; then
    galliumdrivers="swrast,v3d,vc4,kmsro"

  elif [[ $arch = x86_64 ]]; then
    galliumdrivers="nouveau,radeonsi,swrast,r300,i915,iris,zink"
  fi

  mkdir -p smbuild && cd smbuild
  meson .. \
    --prefix=/ \
    --sysconfdir=/etc \
    --localstatedir=/var \
    -Dbuildtype=release \
    -Dgallium-va=enabled \
    -Dgallium-vdpau=enabled \
    -Dgallium-drivers="$galliumdrivers" \
    -Dvulkan-drivers=amd,intel,swrast \
    -Dplatforms="x11,wayland" \
    -Dgallium-nine=false \
    -Degl=enabled \
    -Dgles1=disabled \
    -Dgles2=enabled \
    -Dglx=dri \
    -Dopengl=true \
    -Dvalgrind=false \
    -Dlibunwind=false \
    -Db_lto=false \
    -Dllvm=enabled \
    -Dshared-llvm=enabled

  ninja
  DESTDIR="$pkg" ninja install

  cp $srcdir/LICENSE $pkgdocs/

  mkfinalpkg
}

sha512sums="
1346ff598ab783b726cc07fa4fee6f307a3ec610541a336411d95bfca9bd79f13040ec1f7d1e73a7b29c1a3e2e236e710344c79c867f44c5a2440df67841a6d3  mesa-22.3.6.tar.lz
"
