SUMMARY="A video and audio player which can play most formats and codecs"
DESCRIPTION="QMPlay2 is a video and audio player. It can play all formats \
supported by FFmpeg, libmodplug (including J2B and SFX). It also supports \
Audio CD, raw files, Rayman 2 music and chiptunes. It contains YouTube and \
MyFreeMP3 browser."
HOMEPAGE="http://zaps166.sourceforge.net"
COPYRIGHT="2010-2021 Błażej Szczygieł"
LICENSE="GNU GPL v3"
REVISION="3"
SOURCE_URI="https://github.com/zaps166/QMPlay2/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="6fd7ff7eda4173f5467cc3dffbff26ce0b8a05b325db4531fd6000c9c05df958"
SOURCE_DIR="QMPlay2-$portVersion"
PATCHES="qmplay2-$portVersion.patchset"
ADDITIONAL_FILES="
	qmplay2.rdef.in
	MediaKit.png
	"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	qmplay2$secondaryArchSuffix = $portVersion
	app:QMPlay2$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku${secondaryArchSuffix}
	cmd:yt_dlp
	lib:libass$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libcddb$secondaryArchSuffix
	lib:libcdio$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libgme$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libsidplayfp$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	lib:libswresample$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libtag$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libass$secondaryArchSuffix
	devel:libavcodec$secondaryArchSuffix >= 59
	devel:libavformat$secondaryArchSuffix >= 59
	devel:libavutil$secondaryArchSuffix >= 57
	devel:libcddb$secondaryArchSuffix
	devel:libcdio$secondaryArchSuffix >= 19
	devel:libgme$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5DBus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libsidplayfp$secondaryArchSuffix
	devel:libswresample$secondaryArchSuffix  >= 4
	devel:libswscale$secondaryArchSuffix >= 6
	devel:libtag$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	"

BUILD()
{
	cp $portDir/additional-files/MediaKit.png src/modules/MediaKit
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir/QMPlay2 \
		-DUSE_OPENGL=OFF
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	local APP_SIGNATURE="application/x-vnd.QMPlay2"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/qmplay2.rdef.in > qmplay2.rdef

	mv $appsDir/QMPlay2/share/qmplay2/lang $appsDir/QMPlay2
	mv $appsDir/QMPlay2/bin/QMPlay2 $appsDir/QMPlay2/QMPlay2
	rm -rf $appsDir/QMPlay2/{share,bin,include}

	addResourcesToBinaries qmplay2.rdef $appsDir/QMPlay2/QMPlay2

	addAppDeskbarSymlink $appsDir/QMPlay2/QMPlay2
}
