# Template file for 'libretro-mupen64plus'
pkgname=libretro-mupen64plus
version=20190611
revision=2
_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

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

build_options="gles gles3 rpi"

case "$XBPS_TARGET_MACHINE" in
	armv*) build_options_default="rpi";;
	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
		armv*) _args=(ARCH=arm);;
		*) _args=(ARCH="${XBPS_TARGET_MACHINE%-musl}");;
	esac

	if [ "$build_option_rpi" ]; then
		case "$XBPS_TARGET_MACHINE" in
			armv6*) _args+=(platform="rpi mesa");;
			armv7*) _args+=(platform="rpi2 mesa");;
		esac
	fi

	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
}

libretro-mupen64plus-rpi_package() {
	metapackage=yes
	short_desc+=" (transitional dummy package)"
	depends="${sourcepkg}>=${version}_${revision}"
}
