TERMUX_PKG_HOMEPAGE=https://github.com/KhronosGroup/Vulkan-ValidationLayers
TERMUX_PKG_DESCRIPTION="Vulkan Validation Layers"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="1.4.351"
TERMUX_PKG_SRCURL=https://github.com/KhronosGroup/Vulkan-ValidationLayers/archive/refs/tags/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=40b5e0777d61c4b09acc9e99cdf5f67afe2ae27189bb0efd76a74e7c18f976c1
TERMUX_PKG_DEPENDS="libc++, vulkan-loader"
TERMUX_PKG_BUILD_DEPENDS="libwayland, libx11, libxcb, libxrandr"
TERMUX_PKG_ANTI_BUILD_DEPENDS="vulkan-loader"
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_UPDATE_VERSION_REGEXP="\d+\.\d+\.\d+"
# update_deps.py in pre_configure
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DUPDATE_DEPS=OFF
"

termux_step_pre_configure() {
	termux_setup_cmake
	termux_setup_ninja

	# use upstream known_good.json to fetch and build deps
	"${TERMUX_PKG_SRCDIR}/scripts/update_deps.py" --generator Ninja

	find "$PWD" -name helper.cmake | sort | xargs -i bash -c "echo '===== {} =====' && cat {}"

	# prioritises build deps from source instead of system prefix
	# avoiding pollution from old dependencies
	local GLSLANG_INSTALL_DIR="${TERMUX_PKG_SRCDIR}/glslang/build/install"
	local GOOGLETEST_INSTALL_DIR="${TERMUX_PKG_SRCDIR}/googletest/build/install"
	local SPIRV_HEADERS_INSTALL_DIR="${TERMUX_PKG_SRCDIR}/SPIRV-Headers/build/install"
	local SPIRV_TOOLS_INSTALL_DIR="${TERMUX_PKG_SRCDIR}/SPIRV-Tools/build/install"
	local VULKAN_HEADERS_INSTALL_DIR="${TERMUX_PKG_SRCDIR}/Vulkan-Headers/build/install"
	local VULKAN_UTILITY_LIBRARIES_INSTALL_DIR="${TERMUX_PKG_SRCDIR}/Vulkan-Utility-Libraries/build/install"

	TERMUX_PKG_EXTRA_CONFIGURE_ARGS+="
	-DGLSLANG_INSTALL_DIR=${GLSLANG_INSTALL_DIR}
	-DGOOGLETEST_INSTALL_DIR=${GOOGLETEST_INSTALL_DIR}
	-DSPIRV_HEADERS_INSTALL_DIR=${SPIRV_HEADERS_INSTALL_DIR}
	-DSPIRV_TOOLS_INSTALL_DIR=${SPIRV_TOOLS_INSTALL_DIR}
	-DVULKAN_HEADERS_INSTALL_DIR=${VULKAN_HEADERS_INSTALL_DIR}
	-DVULKAN_UTILITY_LIBRARIES_INSTALL_DIR=${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}
	"

	CFLAGS="-I${GLSLANG_INSTALL_DIR}/include ${CFLAGS}"
	CFLAGS="-I${GOOGLETEST_INSTALL_DIR}/include ${CFLAGS}"
	CFLAGS="-I${SPIRV_HEADERS_INSTALL_DIR}/include ${CFLAGS}"
	CFLAGS="-I${SPIRV_TOOLS_INSTALL_DIR}/include ${CFLAGS}"
	CFLAGS="-I${VULKAN_HEADERS_INSTALL_DIR}/include ${CFLAGS}"
	CFLAGS="-I${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}/include ${CFLAGS}"
	CXXFLAGS="-I${GLSLANG_INSTALL_DIR}/include ${CXXFLAGS}"
	CXXFLAGS="-I${GOOGLETEST_INSTALL_DIR}/include ${CXXFLAGS}"
	CXXFLAGS="-I${SPIRV_HEADERS_INSTALL_DIR}/include ${CXXFLAGS}"
	CXXFLAGS="-I${SPIRV_TOOLS_INSTALL_DIR}/include ${CXXFLAGS}"
	CXXFLAGS="-I${VULKAN_HEADERS_INSTALL_DIR}/include ${CXXFLAGS}"
	CXXFLAGS="-I${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}/include ${CXXFLAGS}"
	LDFLAGS="-L${GLSLANG_INSTALL_DIR}/lib ${LDFLAGS}"
	LDFLAGS="-L${GOOGLETEST_INSTALL_DIR}/lib ${LDFLAGS}"
	LDFLAGS="-L${SPIRV_HEADERS_INSTALL_DIR}/lib ${LDFLAGS}"
	LDFLAGS="-L${SPIRV_TOOLS_INSTALL_DIR}/lib ${LDFLAGS}"
	LDFLAGS="-L${VULKAN_HEADERS_INSTALL_DIR}/lib ${LDFLAGS}"
	LDFLAGS="-L${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}/lib ${LDFLAGS}"
}
