SUMMARY="Qt-based audio player with winamp/xmms skins support"
DESCRIPTION="This program is an audio-player, written with the help of the Qt library. \
The user interface is similar to winamp or xmms."
HOMEPAGE="http://qmmp.ylsoftware.com/"
COPYRIGHT="2006-2022 Qmmp Development Team"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://qmmp.ylsoftware.com/files/qmmp/2.0/qmmp-$portVersion.tar.bz2"
CHECKSUM_SHA256="a0c22071bedfcc44deb37428faeeecafb095b7a0ce28ade8907adb300453542e"
PATCHES="qmmp-$portVersion.patchset"
ADDITIONAL_FILES="
	qmmp.rdef.in
	BenuAmp.wsz
	Rugged.wsz
	icons.zip
	"

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

PROVIDES="
	qmmp$secondaryArchSuffix = $portVersion
	app:Qmmp$secondaryArchSuffix = $portVersion
	lib:libqmmp$secondaryArchSuffix = $portVersion
	lib:libqmmpui$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libarchive$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libbs2b$secondaryArchSuffix
	lib:libcddb$secondaryArchSuffix
	lib:libcdio$secondaryArchSuffix
	lib:libcdio_cdda$secondaryArchSuffix
	lib:libcdio_paranoia$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libenca$secondaryArchSuffix
	lib:libfaad$secondaryArchSuffix
	lib:libflac$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgme$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libmad$secondaryArchSuffix
	lib:libmms$secondaryArchSuffix
	lib:libmodplug$secondaryArchSuffix
	lib:libmpcdec$secondaryArchSuffix
	lib:libmpg123$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libopusfile$secondaryArchSuffix
	lib:libQt6Core$secondaryArchSuffix
	lib:libQt6Gui$secondaryArchSuffix
	lib:libQt6Widgets$secondaryArchSuffix
	lib:libsidplayfp$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix
	lib:libsoxr$secondaryArchSuffix
	lib:libtag$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libwavpack$secondaryArchSuffix
	lib:libwildmidi$secondaryArchSuffix
	"

PROVIDES_devel="
	qmmp${secondaryArchSuffix}_devel = $portVersion
	devel:libqmmp$secondaryArchSuffix = 0.0.0 compat >= 0
	devel:libqmmpui$secondaryArchSuffix = 0.0.0 compat >= 0
	"
REQUIRES_devel="
	qmmp$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	qt6_tools${secondaryArchSuffix}_devel
	devel:libarchive$secondaryArchSuffix
	devel:libavcodec$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libbs2b$secondaryArchSuffix
	devel:libcddb$secondaryArchSuffix
	devel:libcdio$secondaryArchSuffix >= 19
	devel:libcdio_cdda$secondaryArchSuffix
	devel:libcdio_paranoia$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libenca$secondaryArchSuffix
	devel:libfaad$secondaryArchSuffix
	devel:libflac$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgme$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libmad$secondaryArchSuffix
	devel:libmms$secondaryArchSuffix
	devel:libmodplug$secondaryArchSuffix
	devel:libmpcdec$secondaryArchSuffix
	devel:libmpg123$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libopusfile$secondaryArchSuffix
	devel:libQt6Core$secondaryArchSuffix
	devel:libQt6Gui$secondaryArchSuffix
	devel:libQt6Widgets$secondaryArchSuffix
	devel:libsidplayfp$secondaryArchSuffix
	devel:libsndfile$secondaryArchSuffix
	devel:libsoxr$secondaryArchSuffix
	devel:libtag$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libwavpack$secondaryArchSuffix
	devel:libwildmidi$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:find
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake6$secondaryArchSuffix
	cmd:unzip
	cmd:xargs
	cmd:yacc
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/icons.zip -d $sourceDir
}

BUILD()
{
	mkdir -p build
	cd build
	cmake .. $cmakeDirArgs \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Qmmp \
		-DCMAKE_INSTALL_BINDIR=$appsDir/Qmmp \
		-DPLUGIN_DIR=$appsDir/Qmmp/plugins \
		-DCMAKE_BUILD_TYPE=RELEASE \
		-DUSE_GNOMEHOTKEY=OFF \
		-DUSE_HAL=OFF \
		-DUSE_HOTKEY=OFF \
		-DUSE_KDENOTIFY=OFF \
		-DUSE_LADSPA=OFF \
		-DUSE_MEDIAKIT=ON \
		-DUSE_MPRIS=OFF \
		-DUSE_QTMULTIMEDIA=OFF \
		-DUSE_SKINNED=ON \
		-DUSE_UDISKS2=OFF

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mkdir -p $appsDir/Qmmp/skins
	cp -f $portDir/additional-files/*.wsz $appsDir/Qmmp/skins
	mv $appsDir/Qmmp/qmmp $appsDir/Qmmp/Qmmp
	rm -rf $dataDir

	fixPkgconfig
	prepareInstalledDevelLibs libqmmp libqmmpui
	packageEntries devel $developDir

	local APP_SIGNATURE="application/x-vnd.qt5-qmmp"
	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/qmmp.rdef.in > qmmp.rdef

	addResourcesToBinaries qmmp.rdef $appsDir/Qmmp/Qmmp
	addAppDeskbarSymlink $appsDir/Qmmp/Qmmp
}
