# Template file for 'ppsspp'
pkgname=ppsspp
version=0.9.9
revision=1
build_wrksrc="${pkgname}-${version}"
build_style=cmake
configure_args="-DHEADLESS=1"
hostmakedepends="cmake pkg-config"
makedepends="zlib-devel libpng-devel SDL-devel"
depends="desktop-file-utils"
short_desc="A fast and portable PSP emulator"
maintainer="Juan RP <xtraeme@gmail.com>"
license="GPL-2"
homepage="http://www.ppsspp.org/"
create_wrksrc=yes
distfiles="
 https://github.com/hrydgard/ppsspp/archive/v${version}.tar.gz
 https://github.com/hrydgard/ppsspp-ffmpeg/archive/bc6302be.tar.gz
 https://github.com/hrydgard/ppsspp-lang/archive/7876a52f.tar.gz
 https://github.com/hrydgard/native/archive/78941b08.tar.gz"
checksum="
 a465159a66d9514dfb037570ee080b6946b571b72cbcdd0b4b3cbc9b05843161
 beedce003bbfa915d7ebbec91adb649bef1f84fb865ae3b72381957bc3bddac2
 25f6b9497640690f07dc9a1171f3ee9d6ae7dbe9f6008aa95727a0d1b0da0c5f
 e3fe30296832b8fe107d6c901110a37959985777a92c6c5ce811e2b811a94e61"
nocross=yes

pre_configure() {
	# copy submodules to right location
	cp -rup ${wrksrc}/native-*/* ${wrksrc}/${pkgname}-${version}/native
	cp -rup ${wrksrc}/ppsspp-lang-*/* ${wrksrc}/${pkgname}-${version}/lang
	cp -rup ${wrksrc}/ppsspp-ffmpeg-*/linux ${wrksrc}/${pkgname}-${version}/ffmpeg
	# disable git versioning
	sed 's|find_package(Git)|# &|' -i ${wrksrc}/${pkgname}-${version}/git-version.cmake
	rm -rf ${pkgname}-${version}/build
}

do_install() {
	cd build
	install -Dm644 ../LICENSE.TXT "$DESTDIR/usr/share/licenses/ppsspp/LICENSE.TXT"
	install -Dm644 ../assets/icon.svg "$DESTDIR/usr/share/icons/ppsspp.svg"
	install -Dm644 ../Qt/PPSSPP.desktop "$DESTDIR/usr/share/applications/PPSSPP.desktop"
	install -Dm755 ${FILESDIR}/ppsspp-sdl.sh "$DESTDIR/usr/bin/ppsspp-sdl"
	install -Dm755 ${FILESDIR}/ppsspp-headless.sh "$DESTDIR/usr/bin/ppsspp-headless"
	install -Dm755 PPSSPPSDL "$DESTDIR/usr/share/ppsspp/PPSSPPSDL"
	install -Dm755 PPSSPPHeadless "$DESTDIR/usr/share/ppsspp/"
	cd assets
	find . -type f -exec install -Dm644 {} "$DESTDIR/usr/share/ppsspp/assets/"{} \;

	sed -e 's,^Exec=.*,Exec=/usr/bin/ppsspp-sdl,' -i $DESTDIR/usr/share/applications/PPSSPP.desktop
	sed -e 's,^Icon=.*,Icon=/usr/share/icons/ppsspp.svg,' -i $DESTDIR/usr/share/applications/PPSSPP.desktop
}
