SUMMARY="A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input"
DESCRIPTION="GLFW is an Open Source, multi-platform library for OpenGL, \
OpenGL ES and Vulkan development on the desktop. It provides a simple API \
for creating windows, contexts and surfaces, receiving input and events."
HOMEPAGE="https://www.glfw.org/"
COPYRIGHT="2002-2006 Marcus Geelnard
	2006-2021 Camilla Löwy
	"
LICENSE="Zlib"
REVISION="3"
SOURCE_URI="https://github.com/glfw/glfw/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="ed07b90e334dcd39903e6288d90fa1ae0cf2d2119fec516cf743a0a404527c02"
PATCHES="glfw-$portVersion.patchset"
ADDITIONAL_FILES="glfw.rdef.in"

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

PROVIDES="
	glfw$secondaryArchSuffix = $portVersion
	lib:libglfw$secondaryArchSuffix = 3.3 compat >= 3
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libglu$secondaryArchSuffix
	"

PROVIDES_devel="
	glfw${secondaryArchSuffix}_devel = $portVersion
	devel:libglfw$secondaryArchSuffix = 3.3 compat >= 3
	"
REQUIRES_devel="
	glfw$secondaryArchSuffix == $portVersion base
	devel:libgl$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	"

PROVIDES_demos="
	glfw${secondaryArchSuffix}_demos = $portVersion
	app:boing = $portVersion
	app:gears = $portVersion
	app:particles = $portVersion
	app:sharing = $portVersion
	app:simple = $portVersion
	app:splitview = $portVersion
	app:wave = $portVersion
	"
REQUIRES_demos="
	haiku$secondaryArchSuffix
	lib:libglfw$secondaryArchSuffix
	"

BUILD_REQUIRES="
	devel:libgl$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	cmake -B build -S . \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_SHARED_LIBS=ON \
		-DGLFW_BUILD_EXAMPLES=ON \
		-DGLFW_BUILD_TESTS=ON \
		-DGLFW_BUILD_DOCS=OFF \
		$cmakeDirArgs

	make $jobArgs -C build
}

INSTALL()
{
	make -C build install

	mkdir -p $appsDir/GLFW3

	GLFW_DEMO_DESKBAR="${dataDir}/deskbar/menu/Demos/GLFW"
	demoApps="boing gears particles sharing simple splitview wave"
	for demo in $demoApps; do
		cp build/examples/$demo $appsDir/GLFW3/${demo^}

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

		addResourcesToBinaries glfw.rdef $appsDir/GLFW3/${demo^}
		mimeset -f $appsDir/GLFW3/${demo^}
		
		mkdir -p ${GLFW_DEMO_DESKBAR}
		ln -s -t ${GLFW_DEMO_DESKBAR} $appsDir/GLFW3/${demo^}
	done

	prepareInstalledDevelLib libglfw
	fixPkgconfig

	# demos package
	packageEntries demos \
		$appsDir \
		$dataDir

	# devel package
	packageEntries devel \
		$libDir/cmake \
		$developDir
}

TEST()
{
	make -C build test
}
