# Forked from Alpine to apply Purism's mobile patches
pkgname=gnome-software
pkgver=9999_git20191031
_commit="b915095540fa7ada6778aded0d51a93572762d89"
pkgrel=1
pkgdesc="Software lets you install and update applications and system extensions"
url="https://wiki.gnome.org/Apps/Software"
arch="all !s390x !mips !mips64"
license="GPL-2.0-or-later"
makedepends="meson appstream-glib-dev gdk-pixbuf-dev libxmlb-dev glib-dev gtk+3.0-dev
	json-glib-dev libsoup-dev gnome-desktop-dev gspell-dev polkit-dev gtk-doc
	ostree-dev flatpak-dev libgudev-dev gnome-online-accounts-dev libhandy-dev"
options="!check" # lots of failing tests
subpackages="$pkgname-lang $pkgname-doc $pkgname-dbg $pkgname-static
	$pkgname-dev $pkgname-plugin-flatpak:flatpak_plugin"
source="https://source.puri.sm/Librem5/gnome-software/-/archive/$_commit/gnome-software-$_commit.tar.gz
	445.patch
	install-more-headers.patch
	org.gnome.software.gschema.override
	"
builddir="$srcdir/$pkgname-$_commit"

case "$CARCH" in
	x86*) makedepends="$makedepends fwupd-dev" ;;
esac

# gnome-software-plugin-apk is only a runtime dependency and unfortunately
# not available on other arches yet due to LDC.
case "$CARCH" in
	x86_64|aarch64) depends="$depends gnome-software-plugin-apk" ;;
esac

build() {
	case "$CARCH" in
		x86*) conf="-Dfwupd=true" ;;
		*) conf="-Dfwupd=false" ;;
	esac


	meson \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--buildtype=plain \
		-Dvalgrind=false \
		-Dmalcontent=false \
		-Dpackagekit=false \
		-Dexternal_appstream=true \
		$conf \
		. output
	ninja -C output
}

check() {
	ninja -C output test
}

package() {
	DESTDIR="$pkgdir" ninja -C output install
	mkdir -p "$pkgdir"/usr/share/glib-2.0/schemas/
	sed "s|@CARCH@|$CARCH|g" "$srcdir"/org.gnome.software.gschema.override > \
		"$pkgdir"/usr/share/glib-2.0/schemas/org.gnome.software.gschema.override
}

flatpak_plugin() {
	pkgdesc="$pkgdesc (flatpak plugin)"
	install_if="$pkgname=$pkgver-r$pkgrel flatpak"
	depends=""

	amove usr/lib/gs-plugins-13/libgs_plugin_flatpak.so
	amove usr/share/metainfo/org.gnome.Software.Plugin.Flatpak.metainfo.xml
}

sha512sums="12d276f0a30c744c8ff1ee162b75340181a58516389a4ccb1013017c03c5d75eb193f7f79975c02c5de9506c2585a70eb4f67a93410877dcf24e8fb4cbcd006e  gnome-software-b915095540fa7ada6778aded0d51a93572762d89.tar.gz
2a8746ac0f948022b10fd29bcaf159d428954061d5ae19db86a09733f69901eda61e109ed4b3d3d484d91c182b2967e4b3bc11ce78774885bb9105a752c55c35  445.patch
e7de617dbdecaa46fad25d8fe7d7ea5db324aaed73555bbe6814357b4ac3b787269653863679cff4318250dcc7729299b549f41220f441d9033a448af28da9dd  install-more-headers.patch
711dfa147c587a665c18ff15539984fd38d56580c41ce81ea52a35f875770e6dad1ded6d2cb18af70e6e697ad11f9c94c06916f6bbcfe65900df89a8bf8bd723  org.gnome.software.gschema.override"
