SUMMARY="A collaborative drawing program"
DESCRIPTION="Drawpile is a drawing program that lets you share \
the canvas with other users in real time."
HOMEPAGE="https://drawpile.net/"
COPYRIGHT="2006-2020 Calle Laakkonen"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/drawpile/Drawpile/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="67e569856ca5031dadd349f17e5185e93d42020f560016540fc32b5b52653a2f"
SOURCE_FILENAME="Drawpile-$portVersion.tar.gz"
SOURCE_DIR="Drawpile-$portVersion"
PATCHES="drawpile-$portVersion.patchset"
ADDITIONAL_FILES="Drawpile.rdef.in"

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

PROVIDES="
	drawpile$secondaryArchSuffix = $portVersion
	app:Drawpile = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgif$secondaryArchSuffix
	lib:libKF5Archive$secondaryArchSuffix
	lib:libminiupnpc$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Sql$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libsodium$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	extra_cmake_modules$secondaryArchSuffix >= 5.65
	devel:libarchive$secondaryArchSuffix
	devel:libgif$secondaryArchSuffix
	devel:libKF5Archive$secondaryArchSuffix
	devel:libminiupnpc$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5WebKit$secondaryArchSuffix
	devel:libsodium$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build && cd build
	cmake .. -DCMAKE_EXE_LINKER_FLAGS=-lnetwork -DTESTS=on \
			-DECM_DIR=/system/data/cmake/Modules/ECM/cmake \
			-DECM_MKSPECS_INSTALL_DIR=$dataDir/Qt5/mkspecs
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/Drawpile
	cp ./build/bin/drawpile $appsDir/Drawpile/Drawpile
	cp ./build/bin/drawpile-srv $appsDir/Drawpile/drawpile-srv

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

	addResourcesToBinaries Drawpile.rdef $appsDir/Drawpile/Drawpile

	addAppDeskbarSymlink $appsDir/Drawpile/Drawpile
}

TEST()
{
	make -C build test
}
