SUMMARY="MusicBrainz music tagger"
DESCRIPTION="Tag your music with the next generation MusicBrainz tagger.

* Multiple formats - Picard supports all popular music formats, including MP3, \
FLAC, OGG, M4A, WMA, WAV, and more.
* AcoustID - Picard uses AcoustID audio fingerprints, allowing files to be \
identified by the actual music, even if they have no metadata.
* CD lookups - Picard can lookup entire music CDs with a click.
* Plugin support - If you need a particular feature, you can choose from a \
selection of available plugins or write your own."
HOMEPAGE="https://picard.musicbrainz.org/"
COPYRIGHT="2004-2021 Robert Kaye, Lukas Lalinsky, Laurent Monin, \
Sambhav Kothari, Philipp Wolfer and others"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="ftp://ftp.eu.metabrainz.org/pub/musicbrainz/picard/picard-$portVersion.tar.gz"
CHECKSUM_SHA256="73c70933f78de9a92ad8943d2e237d5f580d4f695c950d2070385f1067315e76"
SOURCE_DIR="picard-release-$portVersion"
SOURCE_FILENAME="picard-$portVersion"
PATCHES="picard-$portVersion.patchset"
ADDITIONAL_FILES="
	picard.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	picard$secondaryArchSuffix = $portVersion
	app:Picard = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:fpcalc
	cmd:python3.8
	dateutil_python38
	discid_python38
	fasteners_python38
	lib:libdiscid$secondaryArchSuffix
	markdown_python38
	mutagen_python38
	pyjwt_python38
	pyqt5_python38
	pyyaml_python38
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	pyqt5_python38
	setuptools_python38
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:msgfmt$secondaryArchSuffix
	cmd:python3.8
	"

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

BUILD()
{
	LC_ALL=en_US.UTF-8

	#Rebuild resources
	rm -f resources/picard.qrc
	rm -f picard/resources.py
	python3.8 resources/makeqrc.py
	python3.8 resources/compile.py

	python3.8 setup.py config
}

INSTALL()
{
	LC_ALL=en_US.UTF-8
	python3.8 setup.py install \
		--root=/ --prefix=$prefix \
		--install-data=$dataDir \
		--install-locales=$dataDir/locale \
		--disable-autoupdate

	mkdir -p $appsDir
	mv $prefix/bin/picard $appsDir/Picard
	rm -rf $binDir

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3 | cut -d~ -f1`"
	if [ -z "$MINOR" ]; then MINOR=0; fi

	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/picard.rdef.in > $sourceDir/build/picard.rdef

	settype -t application/x-vnd.Be-elfexecutable $appsDir/Picard

	rc $sourceDir/build/picard.rdef
	resattr -o $appsDir/Picard $sourceDir/build/picard.rsrc
	mimeset -f $appsDir/Picard
	addAppDeskbarSymlink $appsDir/Picard

	rm -rf $dataDir/share
}
