# Maintainer (Arch): Jan de Groot <jgc@archlinux.org>
# Maintainer (Arch): Andreas Radke <andyrtr@archlinux.org>
# Maintainer (Hyperbola): André Silva <emulatorman@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

pkgname='mesa-demos'
pkgver=8.4.0
pkgrel=2
pkgrel+=.parabola1
arch=('x86_64')
arch+=('i686' 'armv7h')
pkgdesc="Mesa demos and tools incl. glxinfo + glxgears"
pkgdesc+=", without nonfree demos"
url="https://www.mesa3d.org/"
license=('custom')
replaces=('mesa-demos-libre')
conflicts=('mesa-demos-libre')
depends=('libgl' 'glew' 'freeglut')
makedepends=('mesa' 'freetype2' 'git')
mksource=(https://mesa.freedesktop.org/archive/demos/mesa-demos-$pkgver.tar.bz2{,.sig})
source=("https://repo.parabola.nu/other/mesa-demos-libre/mesa-demos-libre-${pkgver}.tar.bz2"
        'LICENSE'
        'libre.patch')
mksha512sums=('b72d03cad36e0535ff18dcfb222ec4200064b9264f6da51a6e5f03b0dd912abe188bc1d600b6698de3ce6f63b28d2ce01565886ca8e7079edc4967fbf2fb0957'
              'SKIP')
sha512sums=('0f8c5463ea564c21df34cba64e911d435012bcc36f13eeba6d89c02ef514e19330d10f36348fec63add011b60b75e0ad6ad277e72d55c029ae1999906d71d607'
            '25da77914dded10c1f432ebcbf29941124138824ceecaf1367b3deedafaecabc082d463abcfa3d15abff59f177491472b505bcb5ba0c4a51bb6b93b4721a23c2'
            'f4fe1f087554af180962a32df4d8ba4616db292ff82bccf4930115616290e59c15364bac75fb4b9fd82b642be2c9e760dc9bcb27c58a4ea6239382105b4383de')
validpgpkeys=('E390B9700582FAEA959ACAD41EEF53D38A3A9C67') # "Andreas Boll <andreas.boll.dev@gmail.com>"

mksource() {
  cd mesa-demos-$pkgver

  # remove nonfree demos (pointblast and spriteblast)
  rm -v src/demos/{pointblast,spriteblast}.c
}

prepare() {
  cd mesa-demos-$pkgver

  # remove nonfree demos references (pointblast and spriteblast)
  patch -Np1 -i ../libre.patch
}

build() {
  cd mesa-demos-$pkgver
  ./configure --prefix=/usr \
    --disable-gles1 \
    --with-system-data-files=/usr/share/mesa-demos
  make
}

package() {
  cd mesa-demos-$pkgver
  make DESTDIR="${pkgdir}" install

  # add missing egl files
  install -m 0755 src/egl/opengl/{eglgears_x11,eglinfo,eglkms,egltri_x11,peglgears,xeglgears,xeglthreads} "${pkgdir}/usr/bin"

  install -m755 -d "${pkgdir}/usr/share/licenses/mesa-demos"
  install -m755 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/mesa-demos/"
}
