# Contributor: Díaz Urbaneja Diego <sodomon2@gmail.com>
# Maintainer: Díaz Urbaneja Diego <sodomon2@gmail.com>
pkgname=ppsspp
pkgver=1.17.1
pkgrel=4
pkgdesc="PPSSPP - a fast and portable PSP emulator"
url="https://www.ppsspp.org/"
arch="aarch64 x86 x86_64 ppc64le" # other arches fail to build
license="GPL-2.0-only"
makedepends="
	cmake
	ffmpeg4-dev
	glew-dev
	libzip-dev
	mesa-dev
	miniupnpc-dev
	python3
	qt5-qtbase-dev
	qt5-qtmultimedia-dev
	samurai
	sdl2-dev
	sdl2_ttf-dev
	snappy-dev
	zlib-dev
	zstd-dev
	"
source="https://github.com/hrydgard/ppsspp/releases/download/v$pkgver/ppsspp-$pkgver.tar.xz
	miniupnpc.patch
	"
options="!check" # make check not implemented

# This should avoid the segfault caused by switching between tabs on x86/x86_64 architectures.
case "$CARCH" in
	x86|x86_64) _use_egl_and_gles2=OFF;;
	*) _use_egl_and_gles2=ON ;;
esac


build() {
	cmake -B build-qt -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DUSE_DISCORD=OFF \
		-DUSE_SYSTEM_FFMPEG=ON \
		-DUSE_SYSTEM_LIBPNG=ON \
		-DUSE_SYSTEM_LIBSDL2=ON \
		-DUSE_SYSTEM_LIBZIP=ON \
		-DUSE_SYSTEM_MINIUPNPC=ON \
		-DUSE_SYSTEM_SNAPPY=ON \
		-DUSE_SYSTEM_ZSTD=ON \
		-DUSING_QT_UI=ON \
		-DUSING_GLES2=$_use_egl_and_gles2 \
		-DUSING_EGL=$_use_egl_and_gles2 \
		-Wno-dev
	cmake --build build-qt
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt
}

sha512sums="
eaa0046f5d8e529efd8238690fa242638aa88630172abe59c4b7ffb16b1e18eeb38fcaf8e70ef76dbd2304b226d1f33e10cde709abe00fa2a5baff16c1883c31  ppsspp-1.17.1.tar.xz
a48c2b87f9e56e47efe6e0059d62e433811ccf163f3c72c2268d54821c84cf0d61e3e3a5d0c74d62d5b895a126cac11ade3170d7837f1d1ea1ea312fdcbc236f  miniupnpc.patch
"
