# Template file for 'libretro-mupen64plus'
pkgname=libretro-mupen64plus
version=20190611
revision=1
_gitrev=e64ef9d9f214e32341fb7cd9633260fbb44b2326
hostmakedepends="pkg-config unzip"
makedepends="MesaLib-devel zlib-devel"
short_desc="Libretro port of Mupen64 Plus"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-3.0-or-later"
homepage="http://www.libretro.com/"
distfiles="https://github.com/libretro/mupen64plus-libretro/archive/${_gitrev}.tar.gz"
checksum=947abfb1d5ff34d6b22fecfb2df02bd3759fde3f4a0e5d238f65ec7e97d964d4
conflicts="ĺibretro-mupen64plus-rpi>=0"

case "$XBPS_TARGET_MACHINE" in
	i686*) hostmakedepends+=" nasm";;
esac

build_options="gles gles3"

case "$XBPS_TARGET_MACHINE" in
	armv*|aarch64*) build_options_default="gles";;
esac

CFLAGS="-fcommon"

do_build() {
	local _args

	# setting ARCH makes sure proper dynarec is selected
	case "$XBPS_TARGET_MACHINE" in
		i686*) _args="ARCH=i686";;
		arm*) _args="ARCH=arm";;
		aarch64*) _args="ARCH=aarch64";;
		x86_64*) _args="ARCH=x86_64";;
		*) _args="ARCH=${XBPS_TARGET_MACHINE%-musl}";;
	esac

	if [ "$build_option_gles3" ]; then
		_args+=" FORCE_GLES3=1"
	elif [ "$builld_option_gles" ]; then
		_args+=" FORCE_GLES=1"
	fi

	make CC=$CC ${_args} ${makejobs}
}

do_install() {
	vinstall mupen64plus_libretro.so 755 usr/lib/libretro
}
