SUMMARY="Bitmap rendering and loading support"
DESCRIPTION="The GdkPixBuf library provides a number of features:
* Reference counting for libart's ArtPixBuf structure.
* Image loading facilities.
* Rendering of a GdkPixBuf into various formats: drawables (windows, pixmaps), \
GdkRGB buffers.
* Fast scaling and compositing of pixbufs.
* Simple animation loading (ie. animated GIFs)"
HOMEPAGE="https://wiki.gnome.org/Projects/GdkPixbuf"
COPYRIGHT="1999-2020 Gnome Project"
LICENSE="GNU LGPL v2.1"
REVISION="8"
SOURCE_URI="https://download.gnome.org/sources/gdk-pixbuf/${portVersion%.*}/gdk-pixbuf-$portVersion.tar.xz"
CHECKSUM_SHA256="83c66a1cfd591d7680c144d2922c5955d38b4db336d7cd3ee109f7bcf9afef15"
SOURCE_DIR="gdk-pixbuf-$portVersion"
PATCHES="gdk_pixbuf-$portVersion.patchset"
ADDITIONAL_FILES="
	update_loaders_cache.sh
	"

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

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

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

GLOBAL_WRITABLE_FILES="
	settings/gdk-pixbuf-2.0/loaders.cache keep-old
	"
POST_INSTALL_SCRIPTS="
	$relativePostInstallDir/update_loaders_cache.sh
	"

PROVIDES="
	gdk_pixbuf$secondaryArchSuffix = $portVersion
	cmd:gdk_pixbuf_csource$secondaryArchSuffix = $portVersion
	cmd:gdk_pixbuf_pixdata$commandSuffix = $portVersion
	cmd:gdk_pixbuf_query_loaders$commandSuffix = $portVersion
	cmd:gdk_pixbuf_thumbnailer$commandSuffix = $portVersion
	lib:libgdk_pixbuf_2.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	shared_mime_info$secondaryArchSuffix
	lib:libffi$secondaryArchSuffix
	lib:libgio_2.0$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	gdk_pixbuf${secondaryArchSuffix}_devel = $portVersion
	devel:libgdk_pixbuf_2.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	gdk_pixbuf$secondaryArchSuffix == $portVersion base
	devel:libffi$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	shared_mime_info$secondaryArchSuffix
	devel:libffi$secondaryArchSuffix
	devel:libgio_2.0$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgmodule_2.0$secondaryArchSuffix
	devel:libgobject_2.0$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:meson
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	"

defineDebugInfoPackage gdk_pixbuf$secondaryArchSuffix  \
	"$binDir"/gdk-pixbuf-csource \
	"$binDir"/gdk-pixbuf-pixdata \
	"$binDir"/gdk-pixbuf-query-loaders \
	"$binDir"/gdk-pixbuf-thumbnailer \
	"$libDir"/libgdk_pixbuf-2.0.so.$libVersion

BUILD()
{
	meson build \
		--buildtype=release \
		--prefix=$prefix \
		--bindir=$commandBinDir \
		--datadir=$dataDir \
		--includedir=$includeDir \
		--libdir=$libDir \
		--libexecdir=$libDir \
		--localedir=$dataDir/locale \
		-D installed_tests=false
	ninja -C build $jobArgs
}

INSTALL()
{
	ninja -C build install

	# move loaders.cache to settings dir
	mkdir $settingsDir/gdk-pixbuf-2.0
	mv $libDir/gdk-pixbuf-2.0/*/loaders.cache $settingsDir/gdk-pixbuf-2.0
	# postinstall script for rebuild loaders.cache
	mkdir -p $postInstallDir
	cp $portDir/additional-files/update_loaders_cache.sh $postInstallDir
	chmod +x $postInstallDir/update_loaders_cache.sh

	prepareInstalledDevelLib \
		libgdk_pixbuf-2.0
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	:
	# tests fail/crash (also with previous version)
	# meson test -C build --print-errorlogs
}
