app=mesa
version=20.1.4
build=2sml
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"

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

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

  applypatch $srcdir/add-use-elf-tls.patch
  applypatch $srcdir/adjust-cache-deflate-buffer.patch
  applypatch $srcdir/disable-rgb10-by-default.patch
  applypatch $srcdir/musl-fix-includes.patch

  export CFLAGS="$CFLAGS -D_XOPEN_SOURCE=700"

  if [ "$arch" = "aarch64" ]; then
    dridrivers=""
    galliumdrivers="v3d,vc4,kmsro"

  elif [ "$arch" = "x86_64" ]; then
    dridrivers="i915,i965,nouveau,r100,r200,swrast"
    galliumdrivers="nouveau,radeonsi,r300,r600"
  fi

  mkdir -p smbuild && cd smbuild
  meson .. \
    --prefix="/" \
    --sysconfdir=/etc \
    --localstatedir=/var \
    -Dbuildtype=release \
    -Ddri-drivers="$dridrivers" \
    -Dgallium-drivers="$galliumdrivers" \
    -Dplatforms="x11,wayland" \
    -Dgallium-nine=false \
    -Degl=true \
    -Dgles1=false \
    -Dgles2=true \
    -Dglx=dri \
    -Dopengl=true \
    -Dvalgrind=false \
    -Dlibunwind=false 

  ninja
  DESTDIR="$pkg" ninja install

  cp $srcdir/LICENSE $pkgdocs/

  mkfinalpkg
}

sha512sums="
f4d79694cda8531e7560147caf5d18bce5c685cd6c61264dced5adaa9043be9c83d3a2bd623ebffedc8d4258b9b1f97d84d9aeea307aa77cf99d0bc47c987155  mesa-20.1.4.tar.xz
cd3961319079882e692176f654feb21ddfeccafcc7f4ce4f8d21160f36deda768eb3ee7f49dae2e18f0587d321473adc7f127a2d75ae143ec29168bcc0fe12c0  add-use-elf-tls.patch
cdf22d2da3328e116c379264886bd01fd3ad5cc45fe03dc6fd97bdc4794502598ee195c0b9d975fa264d6ac31c6fa108c0535c91800ecf4fcabfd308e53074cc  adjust-cache-deflate-buffer.patch
ede642ae9be64c3fc5fee46e8bf1b2f982191febcfadb235b0261868213c7cca11d38bb53b972f3184a887430f37b9f470a9b12fd03cf54b98315ec75c4d8ed4  disable-rgb10-by-default.patch
cf849044d6cc7d2af4ff015208fb09d70bf9660538699797da21bda2ecb7c1892d312af83d05116afd826708d9caafb1d05a13f09139c558aea6fee931e3eee7  musl-fix-includes.patch
"
