SUMMARY="Great Qt GUI front-end for MPlayer/mpv"
DESCRIPTION="SMPlayer is a graphical user interface (GUI) for the \
award-winning MPlayer, which is capable of playing almost all known video and \
audio formats. But apart from providing access for the most common and useful \
options of MPlayer, SMPlayer adds other interesting features like the \
possibility to play Youtube videos or download subtitles."
HOMEPAGE="https://www.smplayer.info/"
COPYRIGHT="2006-2021 Ricardo Villalba"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://downloads.sf.net/smplayer/smplayer-$portVersion.tar.bz2"
CHECKSUM_SHA256="2c0bf10add4bea2582104281553cda9792b74d41273a98bceaa147c70065db8a"
PATCHES="smplayer-$portVersion.patchset"
ADDITIONAL_FILES="smplayer.rdef"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi


PROVIDES="
	smplayer$secondaryArchSuffix = $portVersion
	app:SMPlayer = $portVersion
	cmd:smplayer = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Script$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	cmd:mpv$secondaryArchSuffix
	cmd:smtube$commandSuffix
	"

BUILD_REQUIRES="
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5DBus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Script$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:gcc$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix
	cmd:make
	"

GLOBAL_WRITABLE_FILES="settings/smplayer/input.conf keep-old"

BUILD()
{
	make $jobArgs
}

INSTALL()
{
	smplayerDir=$appsDir/SMPlayer
	mkdir -p $smplayerDir/translations $settingsDir/smplayer
	cp src/translations/*.qm $smplayerDir/translations
	cp src/input.conf $settingsDir/smplayer
	cp src/smplayer $smplayerDir/SMPlayer$commandSuffix

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/smplayer.rdef > smplayer.rdef

	addResourcesToBinaries smplayer.rdef $smplayerDir/SMPlayer$commandSuffix

	mkdir -p $commandBinDir
	if [ -n "$commandSuffix" ]; then
	  mkdir -p $prefix/bin
	  symlinkRelative -s $smplayerDir/SMPlayer$commandSuffix $prefix/bin
	fi
	symlinkRelative -s $smplayerDir/SMPlayer$commandSuffix \
		$commandBinDir/smplayer
	addAppDeskbarSymlink $smplayerDir/SMPlayer
}
