SUMMARY="Library for playback of Blu-ray movies"
DESCRIPTION="This library is simply a tool for playback of Blu-ray movies."
HOMEPAGE="https://www.videolan.org/developers/libbluray.html"
COPYRIGHT="2010-2021 VideoLAN"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://download.videolan.org/pub/videolan/libbluray/$portVersion/libbluray-$portVersion.tar.bz2"
CHECKSUM_SHA256="e2dbaf99e84e0a9725f4985bcb85d41e52c2261cc651d8884b1b790b5ef016f9"
PATCHES="libbluray-$portVersion.patchset"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

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

PROVIDES="
	libbluray$secondaryArchSuffix = $portVersionCompat
	lib:libbluray$secondaryArchSuffix = $libVersionCompat
	cmd:bd_info$commandSuffix
	cmd:bd_list_titles$commandSuffix
	cmd:bd_splice$commandSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	# required by freetype
	lib:libbz2$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	libbluray${secondaryArchSuffix}_devel = $portVersionCompat
	devel:libbluray$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libbluray$secondaryArchSuffix == $portVersion base
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	# required by freetype
	devel:libbz2$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autom4te
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libbluray$secondaryArchSuffix \
	"$commandBinDir"/bd_info \
	"$libDir"/libbluray.so.$libVersion

BUILD()
{
	./bootstrap
	runConfigure --omit-dirs binDir ./configure --bindir="$commandBinDir" \
		--disable-bdjava-jar
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libbluray.la

	prepareInstalledDevelLibs libbluray
	fixPkgconfig

	local develPackageName="${portName}_devel-$portFullVersion"
	local packageLinksDir="`dirname "$portPackageLinksDir"`"
	local develPkgLinksDir="$packageLinksDir/$develPackageName"
	local libfontconfig="$develPkgLinksDir/devel~libfontconfig$secondaryArchSuffix/$relativeDevelopLibDir"
	local libfreetype="$develPkgLinksDir/devel~libfreetype$secondaryArchSuffix/$relativeDevelopLibDir"
	local libxml2="$develPkgLinksDir/devel~libxml2$secondaryArchSuffix/$relativeDevelopLibDir"
	sed -i \
		-e "/^Libs\.private:/ s,-L/packages/fontconfig$secondaryArchSuffix-[^\ /]*/\.self/develop/$relativeLibDir,-L$libfontconfig,g" \
		-e "/^Libs\.private:/ s,-L/packages/freetype$secondaryArchSuffix-[^\ /]*/\.self/develop/$relativeLibDir,-L$libfreetype,g" \
		-e "/^Libs\.private:/ s,-L/packages/libxml2$secondaryArchSuffix-[^\ /]*/\.self/develop/$relativeLibDir,-L$libxml2,g" \
		$developLibDir/pkgconfig/libbluray.pc

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
