SUMMARY="Free music composition and notation software"
DESCRIPTION="This application is used to create, play, and print beautiful sheet music"
HOMEPAGE="https://musescore.org/"
COPYRIGHT="2002-2021 Werner Schweer and others"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/musescore/MuseScore/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="c37acc6d7a316f04925265d2d22a35d715888580e16eff846e9b621954133c45"
SOURCE_DIR="MuseScore-$portVersion"
PATCHES="musescore-$portVersion.patchset"
ADDITIONAL_FILES="musescore.rdef.in"

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

PROVIDES="
 	musescore$secondaryArchSuffix = $portVersion
 	cmd:mscore
 	app:musescore
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libmp3lame$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libQt5$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Designer$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Quick$secondaryArchSuffix
	lib:libQt5Test$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libmp3lame$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libQt5$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Designer$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Quick$secondaryArchSuffix
	devel:libQt5Test$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	devel:libsndfile$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:getconf
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	export DISABLE_ASLR=1
	mkdir -p $appsDir
	make PREFIX=$appsDir/MuseScore \
		UPDATE_CACHE=FALSE \
		BUILD_PULSEAUDIO=OFF \
		BUILD_JACK=OFF \
		BUILD_PORTMIDI=OFF \
		BUILD_PORTAUDIO=OFF \
		BUILD_WEBENGINE=OFF \
		USE_SYSTEM_FREETYPE=ON \
		DOWNLOAD_SOUNDFONT=OFF \
		BUILD_ALSA=OFF \
		NO_RPATH=TRUE \
		MUSESCORE_BUILD_CONFIG=release revision release
}

INSTALL()
{
	make UPDATE_CACHE=FALSE -C build.release install

	local APP_SIGNATURE="application/x-vnd.musescore"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="0" # "`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/musescore.rdef.in > musescore.rdef

	addResourcesToBinaries musescore.rdef "$appsDir"/MuseScore/bin/musescore
	addAppDeskbarSymlink "$appsDir"/MuseScore/bin/musescore MuseScore
}
