SUMMARY="Open source Linux SDL/ImGui edition software for viewing .brd files"
DESCRIPTION="Linux SDL/ImGui edition software for viewing .brd files, intended \
as a drop-in replacement for the \"Test_Link\" software and \"Landrex\".

Features:
* Annotations (per board database file)
* Part and pin sizes better represented
* Better outlining of irregular objects (such as connectors)
* Drag and drop
* Recently used file history
* Non-orthagonally orientated caps/resistors/diodes now drawn more realistically
* Adjustable DPI (for working on 2K/4K screens)
* Works with multiple concurrent instances"
HOMEPAGE="https://openboardview.org/"
COPYRIGHT="2016 Chloridite and OpenBoardView contributors"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://github.com/OpenBoardView/OpenBoardView/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="e1e2cfe12375b8725c714d9760241f3a15646fba6cda5173db9a9caaa9868aa7"
SOURCE_DIR="OpenBoardView-$portVersion"
srcGitRev_2="a5ca31c88a4cc5847ea012629aff3690f261c7c4"
SOURCE_URI_2="https://github.com/Dav1dde/glad/archive/$srcGitRev_2.zip"
CHECKSUM_SHA256_2="9aa8158dda4d3af8de3d61427bf99e75090f9178824550ebaf69ec26964656a5"
SOURCE_DIR_2="glad-$srcGitRev_2"
srcGitRev_3="738606a2943a8a11316fa15b319193a2baa84bc0"
SOURCE_URI_3="https://github.com/ocornut/imgui/archive/$srcGitRev_3.zip"
CHECKSUM_SHA256_3="0d52d2ffed6006edd2a77c8bfa083bce5982c06ab2620272403623fb42257f78"
SOURCE_DIR_3="imgui-$srcGitRev_3"
srcGitRev_4="80c8f6af0304588b9d780a41015472013b705194"
SOURCE_URI_4="https://github.com/nothings/stb/archive/$srcGitRev_4.zip"
CHECKSUM_SHA256_4="9783c3a6f29fe5c9672bd66d969d3dc2be76c70694be33d9734a075380e49ec1"
SOURCE_DIR_4="stb-$srcGitRev_4"
srcGitRev_5="3e9e3ec15c7bf129664ab2a113eb03b54ee0b584"
SOURCE_URI_5="https://github.com/sheredom/utf8.h/archive/$srcGitRev_5.zip"
CHECKSUM_SHA256_5="fe19ed41de2418722b7ccb94a36a3f81fff3720b089f2a52065ea5e10801a5e3"
SOURCE_DIR_5="utf8.h-$srcGitRev_5"
PATCHES="openboardview-$portVersion.patchset"
PATCHES_3="imgui-$portVersion.patchset"
ADDITIONAL_FILES="openboardview.rdef.in"

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

PROVIDES="
	openboardview$secondaryArchSuffix = $portVersion
	app:OpenBoardView$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	"

BUILD()
{
	# link submodules
	rm -rf $sourceDir/src/{glad,imgui,stb,utf8}
	ln -s $sourceDir2 $sourceDir/src/glad
	ln -s $sourceDir3 $sourceDir/src/imgui
	ln -s $sourceDir4 $sourceDir/src/stb
	ln -s $sourceDir5 $sourceDir/src/utf8

	mkdir -p build
	cd build
	cmake .. -DCMAKE_BUILD_TYPE=Release \
		-DSDL2_INCLUDE_DIR=/system/$relativeIncludeDir/SDL2
	make $jobArgs
}

INSTALL()
{
	mkdir $appsDir
	cp build/src/openboardview/openboardview $appsDir/OpenBoardView

	local APP_SIGNATURE="application/x-vnd.openboardview"
	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/openboardview.rdef.in > $sourceDir/openboardview.rdef

	addResourcesToBinaries  $sourceDir/openboardview.rdef $appsDir/OpenBoardView

	addAppDeskbarSymlink $appsDir/OpenBoardView
}
