SUMMARY="Introspection system for GObject-based libraries"
DESCRIPTION="GObject introspection is a middleware layer between C libraries \
(using GObject) and language bindings. The C library can be scanned at \
compile time and generate a metadata file, in addition to the actual native \
C library. Then at runtime, language bindings can read this metadata and \
automatically provide bindings to call into the C library."
HOMEPAGE="https://wiki.gnome.org/Projects/GObjectIntrospection"
COPYRIGHT="Colin Walters
	Johan Dahlin
	Matthias Clasen (girepository)
	Jürg Billeter (scanner)"
LICENSE="GNU LGPL v2
	GNU GPL v2
	MIT"
REVISION="1"
SOURCE_URI="http://ftp.gnome.org/pub/GNOME/sources/gobject-introspection/${portVersion%.*}/gobject-introspection-$portVersion.tar.xz"
CHECKSUM_SHA256="d229242481a201b84a0c66716de1752bca41db4133672cfcfb37c93eb6e54a27"
SOURCE_DIR="gobject-introspection-$portVersion"
PATCHES="gobject_introspection-$portVersion.patchset"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
    commandSuffix=
    commandBinDir=$prefix/bin
fi

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

PROVIDES="
	gobject_introspection$secondaryArchSuffix = $portVersion
	cmd:g_ir_annotation_tool$commandSuffix
	cmd:g_ir_compiler$commandSuffix
	cmd:g_ir_generate$commandSuffix
	cmd:g_ir_inspect$commandSuffix
	cmd:g_ir_scanner$commandSuffix
	lib:libgirepository_1.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$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:libintl$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	"

PROVIDES_devel="
	gobject_introspection${secondaryArchSuffix}_devel = $portVersion
	devel:libgirepository_1.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	gobject_introspection$secondaryArchSuffix == $portVersion base
	devel:libffi$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libffi$secondaryArchSuffix
	devel:libgio_2.0$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgmodule_2.0$secondaryArchSuffix
	devel:libgobject_2.0$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:bison
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:meson
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3 >= 3.7
	cmd:which
	"

defineDebugInfoPackage gobject_introspection$secondaryArchSuffix \
	"$libDir"/libgirepository-1.0.so.$libVersion

BUILD()
{
	meson build --buildtype=release \
		--prefix=$prefix \
		--includedir=$includeDir \
		--datadir=$dataDir \
		--libdir=$libDir \
		--mandir=$manDir

	ninja -C build $jobArgs
}

INSTALL()
{
	ninja -C build install

	prepareInstalledDevelLib libgirepository-1.0
	fixPkgconfig

	# devel package
	packageEntries devel \
		"$developDir"
}

TEST()
{
	# tests fails on Regress-1.0.gir, but as it looks
	# it is known to fail there (doesn't break the tests)
	ninja -C build test
}
