SUMMARY="Installable Client Driver (ICD) Loader for Vulkan"
DESCRIPTION="Vulkan is an explicit API, enabling direct control over how GPUs \
actually work. As such, Vulkan supports systems that have multiple GPUs, each \
running with a different driver, or ICD (Installable Client Driver). Vulkan \
also supports multiple global contexts (instances, in Vulkan terminology). The \
ICD loader is a library that is placed between a Vulkan application and any \
number of Vulkan drivers, in order to support multiple drivers and the \
instance-level functionality that works across these drivers. Additionally, \
the loader manages inserting Vulkan layer libraries, such as validation \
layers, between an application and the drivers."
HOMEPAGE="https://www.vulkan.org/"
COPYRIGHT="2014-2022 The Khronos Group Inc."
LICENSE="Apache v2"
REVISION="1"
SOURCE_URI="https://github.com/KhronosGroup/Vulkan-Loader/archive/refs/tags/v$portVersion.tar.gz"
SOURCE_FILENAME="Vulkan-Loader-$portVersion.tar.gz"
CHECKSUM_SHA256="a431c627f36f90ce8d1aa752e7a37838db569760a54bb97edaee35dae4743118"
SOURCE_DIR="Vulkan-Loader-$portVersion"
SOURCE_URI_2="https://github.com/KhronosGroup/Vulkan-Headers/archive/refs/tags/v$portVersion.tar.gz"
SOURCE_FILENAME_2="Vulkan-Headers-$portVersion.tar.gz"
CHECKSUM_SHA256_2="7239108c372f1fbe365bd8d1610ca2bb4e72b73b2151f2551bf9df54dd539639"
SOURCE_DIR_2="Vulkan-Headers-$portVersion"
PATCHES="vulkan-$portVersion.patchset"

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

libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	vulkan$secondaryArchSuffix = $portVersion
	lib:libvulkan$secondaryArchSuffix = libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	vulkan${secondaryArchSuffix}_devel = $portVersion
	devel:libvulkan$secondaryArchSuffix = libVersionCompat
	"
REQUIRES_devel="
	vulkan$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage vulkan$secondaryArchSuffix \
	"$libDir"/libvulkan.so.$libVersion

BUILD()
{
	cmake -S . -B build $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX:PATH=$prefix \
		-DVULKAN_HEADERS_INSTALL_DIR=$sourceDir2 \
		-DVulkanRegistry_DIR=$sourceDir2/registry \
		-DFALLBACK_CONFIG_DIRS="/boot/home/config/non-packaged/add-ons:/boot/home/config/add-ons:/boot/system/non-packaged/add-ons:/boot/system/add-ons" \
		-G Ninja

	ninja -C build
}

INSTALL()
{
	ninja -C build install

	mkdir -p $dataDir/vulkan/registry
	cp $sourceDir2/registry/vk.xml $dataDir/vulkan/registry/vk.xml

	mkdir -p $includeDir
	cp -r $sourceDir2/include/* $includeDir

	prepareInstalledDevelLib libvulkan
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}
