SUMMARY="Extracts audio tracks from an audio CD image to separate tracks"
DESCRIPTION="Flacon extracts individual tracks from one big audio file \
containing the entire album of music and saves them as separate audio files. \
To do this, it uses information from the appropriate CUE file.
Besides, Flacon makes it possible to conveniently revise or specify tags both \
for all tracks at once or for each tag separately."
HOMEPAGE="https://flacon.github.io/"
COPYRIGHT="2012-2019 Alexander Sokoloff"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://github.com/flacon/flacon/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="f63b959099e7b97b02a7f9ccf2c922a99de6c0d1ec83e74c436fd10e41630b6e"
SOURCE_FILENAME="flacon-$portVersion.tar.gz"
PATCHES="flacon-$portVersion.patchset"
ADDITIONAL_FILES="flacon.rdef.in"

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

PROVIDES="
	flacon$secondaryArchSuffix = $portVersion
	app:flacon$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:faac
	cmd:flac
	cmd:lame
#	cmd:mac
	cmd:metaflac
	cmd:mp3gain
	cmd:oggenc
	cmd:opusenc
#	cmd:ttaenc
#	cmd:vorbisgain
	cmd:wavpack
	cmd:wvgain
	cmd:wvunpack
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libuchardet$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libuchardet$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	rm -rf build
	cmake -B build -S . \
		-DBIN_DIR=$appsDir \
		-DDATA_DIR=$dataDir \
		-DMAN_DIR=$manDir \
		-DTRANSLATIONS_DIR=$dataDir/Flacon/translations

	make $jobArgs -C build
}

INSTALL()
{
	make -C build install

	mv $appsDir/flacon $appsDir/Flacon

	# Add Haiku resources
	local APP_SIGNATURE="application/x-vnd.qt5-flacon"
	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/flacon.rdef.in > flacon.rdef

	addResourcesToBinaries flacon.rdef $appsDir/Flacon
	addAppDeskbarSymlink $appsDir/Flacon

}
