# Template file for 'glycin'
pkgname=glycin
version=2.1.5
revision=2
build_style=meson
build_helper="rust gir"
configure_args="-Dtest_skip_install=true"
hostmakedepends="cargo clang19 gettext pkg-config vala"
makedepends="gtk4-devel libheif-devel libjxl-devel librsvg-devel
 libseccomp-devel rust-std"
depends="glycin-loaders>=${version}_${revision}"
short_desc="Sandboxed and extendable image decoding"
maintainer="chrysos349 <chrysostom349@gmail.com>"
license="MPL-2.0"
homepage="https://gitlab.gnome.org/GNOME/glycin"
changelog="https://gitlab.gnome.org/GNOME/glycin/-/raw/2.1/NEWS"
#changelog="https://gitlab.gnome.org/GNOME/glycin/-/raw/main/NEWS"
distfiles="${GNOME_SITE}/glycin/${version%.*}/glycin-${version}.tar.xz"
checksum=6c09757ee906330a60b6705753aa56bca007ad219b95e6e3537510d41bc341c8
make_check=no # needs to be installed to run tests

if [ "$CROSS_BUILD" ]; then
	XBPS_CROSS_RUSTFLAGS+=" -L$XBPS_BUILDDIR/${pkgname}-${version}/build/libglycin"
fi

post_patch() {
	if [ "$CROSS_BUILD" ]; then
		vsed -i meson.build \
			-e "s|rust_target =|rust_target = '${RUST_TARGET}' / |"
	fi

	# Fix CARGO_HOME path so it is shared across masterdirs
	vsed -i meson.build \
		-e "s|cargo_home =.*|cargo_home = '${CARGO_HOME}'|g"

	# loaders/meson.build tries to call git to get hash for debug builds.
	# Disable as it is useless for tarball builds.
	ln -sf /bin/false ${XBPS_WRAPPERDIR}/git
}

do_install() {
	meson install -C build --destdir $DESTDIR --no-rebuild
}

glycin-devel_package() {
	depends="glycin>=${version}_${revision} fontconfig-devel lcms2-devel
	 libglib-devel libseccomp-devel"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include/glycin-2
		vmove usr/lib/pkgconfig/glycin-2.pc
		vmove usr/lib/libglycin-2.so
		vmove usr/share/gir-1.0/Gly-2.gir
		vmove usr/share/vala/vapi/glycin-2.*
	}
}

glycin-gtk4_package() {
	depends="glycin>=${version}_${revision}"
	short_desc+=" - GTK4 integration"
	pkg_install() {
		vmove "usr/lib/libglycin-gtk4-2.so.*"
		vmove usr/lib/girepository-1.0/GlyGtk4-2.typelib
	}
}

glycin-gtk4-devel_package() {
	depends="glycin-gtk4>=${version}_${revision} glycin-devel gtk4-devel"
	short_desc+=" - GTK4 development files"
	pkg_install() {
		vmove usr/include/glycin-gtk4-2
		vmove usr/lib/pkgconfig/glycin-gtk4-2.pc
		vmove usr/lib/libglycin-gtk4-2.so
		vmove usr/share/gir-1.0/GlyGtk4-2.gir
		vmove usr/share/vala/vapi/glycin-gtk4-2.*
	}
}

glycin-loaders_package() {
	# according to README.md, the image loader binary is spawned via `bwrap`.
	depends="bubblewrap"
	short_desc+=" - image loading backends"
	pkg_install() {
		vmove usr/libexec/glycin-loaders
		vmove usr/share/glycin-loaders
	}
}
