_pkgname=desmume
pkgname=${_pkgname}-git
pkgdesc='Nintendo DS emulator'
url='http://desmume.org/'
arch=('i686' 'x86_64')
license=('GPL')
_relver=0.9.11
pkgver=${_relver}.r800.e29e825d
pkgrel=2
depends=('agg'
         'gtkglext'
         'lua51'
         'libgl'
         'openal'
         'sdl'
         'soundtouch')
makedepends=('autoconf'
             'automake'
             'pkg-config'
             'git'
             'lua')
provides=('desmume')
replaces=('desmume-sourceforge'
          'desmume-svn'
          'desmume-jit-svn')
conflicts=("${provides[@]}" "${replaces[@]}")
source=('git+https://github.com/TASVideos/desmume.git')
sha512sums=('SKIP')
_builddir="${_pkgname}/src/frontend/posix"

pkgver() {
	cd "${srcdir}/${_pkgname}"
	echo ${_relver}.r$(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare(){
	cd "${srcdir}/${_pkgname}/${_builddir}"
	
	# lua5.1 package is named lua51 on Arch
	# we could probably just make it compile against the current lua
	sed -i 's/lua5.1/lua51/' configure.ac
}

build() {
	cd "${srcdir}/${_pkgname}/${_builddir}"

	./autogen.sh

	# Hud causes segfault in gtk version. Wifi doesn't really work.
	./configure \
		--prefix=/usr \
		--enable-osmesa \
		--enable-glx \
		--enable-hud \
		--enable-openal

	make
}

package() {
	cd "${srcdir}/${_pkgname}/${_builddir}"

	make DESTDIR="${pkgdir}" install
}