SUMMARY="A Qt based client for Music Player Daemon"
DESCRIPTION="Music Player Daemon (MPD) is a flexible, powerful, server-side \
application for playing music. Through plugins and libraries it can play a \
variety of sound files while being controlled by its network protocol.

Cantata is a full featured Qt based client for Music Player Daemon."
HOMEPAGE="https://github.com/CDrummond/cantata"
COPYRIGHT="2010-2020 Craig Drummond"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/CDrummond/cantata/releases/download/v$portVersion/cantata-$portVersion.tar.bz2"
CHECKSUM_SHA256="3ed25d0c838720af7ed08b89a30f3e05d6952d40a5f520f29b3558b2eacdec82"
SOURCE_FILENAME="cantata-$portVersion.tar.gz"
ADDITIONAL_FILES="cantata.rdef"

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

PROVIDES="
	cantata$secondaryArchSuffix = $portVersion
	app:cantata$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libebur128$secondaryArchSuffix
	lib:libmpg123$secondaryArchSuffix
	lib:libmtp$secondaryArchSuffix
#	lib:libmusicbrainz5$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Sql$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libtag$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libavcodec$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libebur128$secondaryArchSuffix
	devel:libmpg123$secondaryArchSuffix
	devel:libmtp$secondaryArchSuffix
#	devel:libmusicbrainz5$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5DBus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Multimedia$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Sql$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	devel:libtag$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage cantata$secondaryArchSuffix \
	"$appsDir"/Cantata

BUILD()
{
	mkdir -p build
	cd build

	cmake .. \
		-Wno-dev \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DSHARE_INSTALL_PREFIX=$dataDir \
		-DCMAKE_BUILD_TYPE=Release \
		-DENABLE_UDISKS2=OFF \
		-DENABLE_HTTP_STREAM_PLAYBACK=OFF \
		-DENABLE_DEVICES_SUPPORT=ON \
		-DENABLE_REMOTE_DEVICES=OFF \
		-DENABLE_LIBVLC=OFF \
		-DENABLE_TAGLIB=ON \
		-DENABLE_FFMPEG=ON \
		-DENABLE_MPG123=ON \
		-DENABLE_PROXY_CONFIG=ON \
		-DENABLE_HTTP_SERVER=ON \
		-DENABLE_SIMPLE_MPD_SUPPORT=ON \
		-DCMAKE_CXX_FLAGS="-I$(finddir B_SYSTEM_HEADERS_DIRECTORY)$secondaryArchSubDir/QtDBus" \
		-DCMAKE_EXE_LINKER_FLAGS="-lQt5DBus"

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mkdir -p $appsDir
	mv $prefix/cantata $appsDir/Cantata
	rm -r $dataDir/cantata/icons

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

	addResourcesToBinaries cantata.rdef \
		$appsDir/Cantata

	addAppDeskbarSymlink $appsDir/Cantata
}
