# Contributor: Alex Yam <alex@alexyam.com>
# Contributor: Lindsay Zhou <i@lin.moe>
# Maintainer: Lindsay Zhou <i@lin.moe>
pkgname=fcitx5-gtk
pkgver=5.1.3
pkgrel=0
pkgdesc="Fcitx5 GTK module"
url="https://github.com/fcitx/fcitx5-gtk/"
arch="all"
license="LGPL-2.1-or-later"
depends="fcitx5"
makedepends="
	cmake
	extra-cmake-modules
	gobject-introspection-dev
	gtk+3.0-dev
	gtk4.0-dev
	samurai
	"
subpackages="
	$pkgname-dev
	${pkgname}3:_gtk3
	${pkgname}4:_gtk4
	"
options="!check" # no test suites
source="$pkgname-$pkgver.tar.gz::https://github.com/fcitx/fcitx5-gtk/archive/$pkgver.tar.gz"

build() {
	_build 3
	_build 4
	_build libs
}

_build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B $pkgname-$1 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_SKIP_BUILD_RPATH=true \
		-DENABLE_GTK2_IM_MODULE=OFF \
		-DENABLE_GTK3_IM_MODULE=OFF \
		-DENABLE_GTK4_IM_MODULE=OFF \
		-DENABLE_GTK"$1"_IM_MODULE=ON \
		-DENABLE_SNOOPER=ON \
		-DENABLE_GIR=ON
	cmake --build $pkgname-$1
}

package() {
	DESTDIR="$pkgdir" cmake --install $pkgname-3
	DESTDIR="$pkgdir" cmake --install $pkgname-4
	DESTDIR="$pkgdir" cmake --install $pkgname-libs
}

_gtk3() {
	pkgdesc="${pkgdesc/GTK/GTK3}"
	install_if="$pkgname=$pkgver-r$pkgrel gtk+3.0"
	amove usr/lib/gtk-3.0
}

_gtk4() {
	pkgdesc="${pkgdesc/GTK/GTK4}"
	install_if="$pkgname=$pkgver-r$pkgrel gtk4.0"

	amove usr/lib/gtk-4.0
}

sha512sums="
1b3a944c947fface27b6d590ecc02e0a427d658da4d8e57a2788b5d0a7c7da6e725156b120da683d0fa566452c9a9a17594ce61934d57dd9da01f49358c27304  fcitx5-gtk-5.1.3.tar.gz
"
