SUMMARY="Cloth patternmaking software"
DESCRIPTION="Valentina is an open source pattern drafting software tool, designed to be the \
foundation of a new stack of open source tools to remake the garment industry.
Small-batch and custom-sized clothing manufacturing is essential to create a sustainable \
future, preserve small- to medium-sized textile spinning and weaving manufacturers, enable \
independent and small designers and manufacturers to scale up to make a decent living, \
rebuild local garment districts, and reduce or eliminate slave labor."
HOMEPAGE="https://valentinaproject.bitbucket.io/"
COPYRIGHT="2013-2019 Valentina project"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/dismine/Valentina_git/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="714460dcecd9fb42371298a29181cc3c7e33ab2a18236aceeffc1732d7ddffd7"
SOURCE_DIR="Valentina_git-$portVersion"
PATCHES="valentina-$portVersion.patchset"
ADDITIONAL_FILES="
	valentina.rdef.in
	tape.rdef.in
	"

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

PROVIDES="
	valentina$secondaryArchSuffix = $portVersion
	app:Valentina$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:ccache
	cmd:find
	cmd:g++$secondaryArchSuffix
	cmd:git
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5
	cmd:which
	"

BUILD()
{
	mkdir -p build
	cd build
	qmake \
		PREFIX=$appsDir/Valentina \
		PREFIX_LIB=$appsDir/Valentina/lib \
		"CONFIG+=noTests noRunPath noDebugSymbols noWindowsInstaller" \
		../Valentina.pro -r
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/Valentina/{lib,translations}

	cp -rf build/src/libs/qmuparser/bin/* $appsDir/Valentina/lib
	cp -rf build/src/libs/vpropertyexplorer/bin/* $appsDir/Valentina/lib
	cp -rf build/src/app/tape/bin/tape $appsDir/Valentina/Tape
	cp -rf build/src/app/valentina/bin/valentina $appsDir/Valentina/Valentina

	cp -dpR src/app/share/{labels,tables,collection} $appsDir/Valentina
	cp -rf share/translations/*.qm $appsDir/Valentina/translations

	strip $appsDir/Valentina/{Tape,Valentina}
	strip $appsDir/Valentina/lib/*

	local APP_SIGNATURE="application/x-vnd.valentina"
	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/valentina.rdef.in > valentina.rdef
	addResourcesToBinaries valentina.rdef $appsDir/Valentina/Valentina

	local APP_SIGNATURE="application/x-vnd.valentina-tape"
	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/tape.rdef.in > tape.rdef
	addResourcesToBinaries tape.rdef $appsDir/Valentina/Tape

	addAppDeskbarSymlink $appsDir/Valentina/Valentina
}
