# Template file for 'glib'
# keep in sync with glib-bootstrap
pkgname=glib
version=2.82.1
revision=2
build_style=meson
build_helper="qemu"
# static version is necessary for qemu-user
# also disable LTO, otherwise there are multiple failures when linking qemu
configure_args="-Dman=true -Dselinux=disabled -Dintrospection=enabled
 $(vopt_bool gtk_doc documentation) --default-library=both -Db_lto=false"
hostmakedepends="gettext pkg-config gobject-introspection-bootstrap
 libxslt docbook-xsl $(vopt_if gtk_doc gi-docgen) python3-packaging python3-docutils"
makedepends="zlib-devel pcre2-devel libffi-devel dbus-devel elfutils-devel libmount-devel"
checkdepends="glib-bootstrap desktop-file-utils shared-mime-info dbus python3-pytest"
short_desc="GNU library of C routines"
maintainer="Orphaned <orphan@voidlinux.org>"
license="LGPL-2.1-or-later"
homepage="https://wiki.gnome.org/Projects/GLib"
changelog="https://gitlab.gnome.org/GNOME/glib/raw/glib-2-82/NEWS"
#changelog="https://gitlab.gnome.org/GNOME/glib/raw/main/NEWS"
distfiles="${GNOME_SITE}/glib/${version%.*}/glib-${version}.tar.xz"
checksum=478634440bf52ee4ec4428d558787398c0be6b043c521beb308334b3db4489a6
conflicts="gir-freedesktop<1.80.0_1" # glib typelibs are now in glib
make_check_pre="dbus-run-session"

build_options="gtk_doc"
build_options_default="gtk_doc"
desc_option_gtk_doc="Build Glib API docs"

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" prelink-cross"
	makedepends+=" gobject-introspection-bootstrap"
fi

post_patch() {
	# Timer test is flaky on 32 bit (does float comparisons)
	if [ "${XBPS_TARGET_WORDSIZE}" = "32" ]; then
		vsed -e "s/'timer' : {},//" -i glib/tests/meson.build
	fi
	# Test fails in CI
	vsed -e '/test_cleanup_handles_errors)/d' -i glib/tests/utils-isolated.c
}

post_install() {
	# Install introspection wrappers for cross compiling
	vbin ${FILESDIR}/gi-xbps-qemuwrapper

	# Install emulator wrappers for tools that require it
	for tool in gi-compile-repository gi-decompile-typelib gi-inspect-typelib; do
		mv ${DESTDIR}/usr/bin/${tool}{,.wrapped}
		sed -e "s|@TOOL@|${tool}|" ${FILESDIR}/gi-tool-emulator-wrapper > gi-tool-emulator-wrapper
		vbin gi-tool-emulator-wrapper ${tool}
	done
}

pre_check() {
	# machine-id is a random, non-zero value
	echo 'dcb30309cd6c8b7cc20383d85a5c7012' > /etc/machine-id
}

post_check() {
	rm /etc/machine-id
}

libglib-devel_package() {
	depends="${makedepends/gobject-introspection-bootstrap/} ${sourcepkg}>=${version}_${revision}"
	conflicts="libgirepository-devel<1.80.0_1"
	short_desc+=" - development files"
	lib32files="/usr/lib/glib-2.0/include/glibconfig.h"
	pkg_install() {
		vmove usr/include
		vmove usr/share/gir-1.0
		vmove usr/lib/glib-2.0
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.a"
	}
}

glib-devel_package() {
	depends="python3-packaging libglib-devel>=${version}_${revision}"
	short_desc+=" - development files"
	python_version=3
	pycompile_dirs="usr/share/glib-2.0/codegen usr/share/glib-2.0/gdb"
	pkg_install() {
		vmove usr/bin/glib-compile-resources
		vmove usr/bin/glib-genmarshal
		vmove usr/bin/glib-mkenums
		vmove usr/bin/gtester-report
		vmove usr/bin/gdbus-codegen
		vmove usr/bin/gtester
		vmove usr/bin/glib-gettextize
		vmove "usr/bin/gi-*"
		vmove usr/share/man/man1/glib-compile-resources.1
		vmove usr/share/man/man1/glib-gettextize.1
		vmove usr/share/man/man1/gtester.1
		vmove usr/share/man/man1/glib-mkenums.1
		vmove usr/share/man/man1/gdbus-codegen.1
		vmove usr/share/man/man1/glib-genmarshal.1
		vmove usr/share/man/man1/gtester-report.1
		for f in aclocal glib-2.0 gdb; do
			vmove usr/share/${f}
		done
		if [ "$build_option_gtk_doc" ]; then
			vmove usr/share/doc
		fi
	}
}
