# Template file for 'ppsspp'
# !! any change to ffmpeg should be tested with apropiate games,
# major ffmpeg updates have a high likelyhood of breaking video playback
pkgname=ppsspp
version=1.20.4
revision=1
build_style=cmake
configure_args="-DHEADLESS=1 -DUSE_SYSTEM_FFMPEG=1 -DUNITTEST=ON
 -DUSING_QT_UI=OFF -DUSE_SYSTEM_ZSTD=ON
 -DARMIPS_USE_STD_FILESYSTEM=ON -DUSE_SYSTEM_RAPIDJSON=ON
 -DUSE_SYSTEM_FREETYPE=ON -DUSE_SYSTEM_SNAPPY=ON -DUSE_SYSTEM_LIBZIP=ON"
hostmakedepends="pkg-config python3"
makedepends="zlib-devel glew-devel ffmpeg-devel libzip-devel
 snappy-devel rapidjson libpng-devel libzstd-devel
 SDL2_ttf-devel SDL2-devel wayland-devel"
depends="desktop-file-utils"
short_desc="Fast and portable PSP emulator"
maintainer="John <me@johnnynator.dev>"
license="GPL-2.0-or-later"
homepage="https://www.ppsspp.org/"
distfiles="https://github.com/hrydgard/ppsspp/releases/download/v${version}/ppsspp-${version}.tar.xz"
checksum=4de21db3105d9d81a465a8a7e78c68ee3c0e0bf6597d1c1d530f7555f3ad8b31

# ppsspp always tries to compile x86 unittest
# https://gist.github.com/Johnnynator/e18d59274451cff890b7235009d2e93d
case $XBPS_TARGET_MACHINE in
	x86_64* | i686*) configure_args+=" -DUNITTEST=ON";;
	armv[67]*) broken="SDL2 is not build against x11";;
	ppc*) broken="No JIT support";;
	*) configure_args+=" -DUNITTEST=OFF";;
esac

post_patch() {
	# disable git versioning
	vsed -e 's|find_package(Git)|# &|' -i git-version.cmake
}

post_configure() {
	cat > "${wrksrc}/build/git-version.cpp" <<-EOF
		const char *PPSSPP_GIT_VERSION = "${version}_${revision}-void";
		#define PPSSPP_GIT_VERSION_NO_UPDATE 1
	EOF
}

post_install() {
	vbin build/PPSSPPHeadless ppsspp-headless
}
