SUMMARY="Xlib compatibility layer for Haiku"
DESCRIPTION="This package contains an Xlib implementation which does not \
interface with X11 servers, but instead with the Haiku API, making it possible \
to run X applications on Haiku without a real X server."
HOMEPAGE="https://github.com/waddlesplash/xlibe/"
COPYRIGHT="1984-2021 The Open Group
	2003 ja6hfa (Shibukawa Yoshiki), kazuyakt
	2021-2022 Haiku, Inc."
LICENSE="MIT
	MIT (no promotion)"
REVISION="2"
SOURCE_URI="https://github.com/waddlesplash/xlibe/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="e7150988aa74991e77d1cdd99b9ac6027d72cb46331d7c26b7a115dff607214a"
SOURCE_DIR="xlibe-$portVersion"

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

# Make sure the versions stay in line with the real libX11, libXext!
libX11Version=6.3.0
libXextVersion=6.4.0

PROVIDES="
	xlibe$secondaryArchSuffix = $portVersion
	lib:libX11$secondaryArchSuffix = $libX11Version compat >= 6
	lib:libXext$secondaryArchSuffix = $libXextVersion compat >= 6
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	"
CONFLICTS="
	libx11$secondaryArchSuffix
	libxext$secondaryArchSuffix
	"

PROVIDES_devel="
	xlibe${secondaryArchSuffix}_devel = $portVersion
	devel:libX11$secondaryArchSuffix = $libX11Version compat >= 6
	devel:libXext$secondaryArchSuffix = $libXextVersion compat >= 6
	"
REQUIRES_devel="
	xlibe$secondaryArchSuffix == $portVersion base
	devel:kbproto
	devel:xproto
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:kbproto
	devel:xproto
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage xlibe$secondaryArchSuffix \
	"$libDir"/libX11.so.$libX11Version \
	"$libDir"/libXext.so.$libXextVersion

BUILD()
{
	cmake . $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo
	make $jobArgs
}

INSTALL()
{
	make install

	# make compatibility symlinks
	mv $libDir/libX11.so.6 $libDir/libX11.so.$libX11Version
	ln -s libX11.so.$libX11Version $libDir/libX11.so.6

	mv $libDir/libXext.so.6 $libDir/libXext.so.$libXextVersion
	ln -s libXext.so.$libXextVersion $libDir/libXext.so.6

	prepareInstalledDevelLibs \
		libX11 \
		libXext

	fixPkgconfig

	packageEntries devel \
		$developDir
}
