APP=mesa
VERSION=20.1.4
BUILD=1sml
HOMEPAGE="https://www.mesa3d.org/"
DOWNLOAD="https://archive.mesa3d.org/mesa-20.1.4.tar.xz"
DESC="An open-source implementation of the OpenGL specification"
REQUIRES="gcc-libs expat libxml2 libdrm libx11 libxrandr libxdamage libxshmfence libxxf86vm libvdpau "

build() {
  mkandenterbuilddir
  rm -rf $APP-$VERSION

  tar xf $SRCDIR/$APP-$VERSION.tar.?z*
  cd $APP-$VERSION
  fixbuilddirpermissions

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

  export CFLAGS="$CFLAGS -D_XOPEN_SOURCE=700"

  if [ "$ARCH" = "aarch64" ]; then
    dridrivers=""
    galliumdrivers="vc4,v3d,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,drm,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
"
