# $Id: PKGBUILD 186203 2016-08-09 13:55:48Z lcarlier $
# Maintainer (arch): Jan de Groot <jgc@archlinux.org>
# Maintainer (arch): Andreas Radke <andyrtr@archlinux.org>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

_pkgbasename=mesa-demos
pkgname=lib32-$_pkgbasename
pkgver=8.3.0
pkgrel=3.parabola1
arch=(x86_64)
pkgdesc="Mesa demos and tools (32-bit), without nonfree demos"
url="http://mesa3d.sourceforge.net"
license=('custom')
replaces=('lib32-mesa-demos-libre')
conflicts=('lib32-mesa-demos-libre')
depends=('lib32-libgl' 'lib32-glew' 'mesa-demos')
makedepends=(gcc-multilib 'lib32-mesa')
source=(https://repo.parabola.nu/other/mesa-demos-libre/mesa-demos-libre-${pkgver}.tar.bz2
        libre.patch)
md5sums=('b7708b773178fa0d661a28c580e60aee'
         '3e5ea3684ce3a1d285df1cdfb2c61dae')

prepare() {
  cd "${srcdir}/mesa-demos-${pkgver}"
  # remove nonfree demos references (pointblast and spriteblast)
  patch -Np1 -i ../libre.patch
}

build() {
  export CC="gcc -m32"
  export CXX="g++ -m32"
  export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"

  cd "${srcdir}/mesa-demos-${pkgver}"
  ./configure --prefix=/usr \
    --without-glut

  make
}

package() {
  depends=('lib32-glew' mesa-demos)

  cd "${srcdir}/mesa-demos-${pkgver}"
  make DESTDIR="${pkgdir}" install

  for i in "$pkgdir/usr/bin/"*; do
    mv "$i" "$i"32
  done

  rm -r "$pkgdir/usr/share/mesa-demos"

  mkdir -p "$pkgdir/usr/share/licenses"
  ln -s $_pkgbasename "$pkgdir/usr/share/licenses/$pkgname"
}
