# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: rubicon <rubicon@mailo.com>
pkgname=hime
pkgver=0.9.12_git20231221
pkgrel=0
_gitrev=1c15f1f1482172c45f0172571f15fce1361a7c70
pkgdesc="HIME Input Method Editor"
url="https://hime-ime.github.io/"
arch="all"
license="LGPL-2.1-or-later AND GPL-2.0-or-later"
depends="bash cmd:whereis"
makedepends="
	libxtst-dev
	cmd:iconv
	anthy-dev
	autoconf
	automake
	libchewing-dev
	gtk+3.0-dev
	qt5-qtbase-dev
	qt6-qtbase-dev
	qt6-qtbase-private-dev
	"
options="!check"
subpackages="
	$pkgname-doc
	$pkgname-lang
	$pkgname-dev
	$pkgname-anthy
	$pkgname-chewing
	$pkgname-gtk3
	$pkgname-qt5
	$pkgname-qt6
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/hime-ime/hime/archive/$_gitrev.tar.gz
	fix-im-client-ldflags.patch
	implicit-declarations.patch
	incompatible-pointers.patch
	use-bash-not-sh.patch
	"
builddir="$srcdir/$pkgname-$_gitrev"

prepare() {
	default_prepare
	autoreconf -fvi
}

build() {
	./configure --prefix=/usr \
		--enable-anthy \
		--enable-chewing \
		--with-gtk=3.0 \
		--with-qt5-moc-path=/usr/lib/qt5/bin/moc \
		--with-qt6-moc-path=/usr/lib/qt6/libexec/moc
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

anthy() {
	pkgdesc="$pkgdesc (Anthy Hiragana support)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel anthy"
	amove usr/lib/hime/anthy-module.so
}

chewing() {
	pkgdesc="$pkgdesc (Chewing Bopomofo support)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel libchewing"
	amove usr/lib/hime/chewing-module.so
}

gtk3() {
	pkgdesc="$pkgdesc (Gtk+3 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel gtk+3.0"
	install="$subpkgname.post-install $subpkgname.post-upgrade"
	amove usr/lib/gtk-3.0/*/immodules/im-hime.so
}

qt5() {
	pkgdesc="$pkgdesc (Qt5 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel qt5-qtbase-x11"
	amove usr/lib/qt5/plugins/platforminputcontexts/im-hime.so
}

qt6() {
	pkgdesc="$pkgdesc (Qt6 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel qt6-qtbase-x11"
	amove usr/lib/qt6/plugins/platforminputcontexts/im-hime.so
}

sha512sums="
7e80fd7f53ea34f07cd2ca1b94dcda38dc7b239c2f0c73e2882f4659842e8939d170eb89e0ccdb931c001277bb41037adef886ab082e4d2589048e2e89ee426c  hime-0.9.12_git20231221.tar.gz
b6025a98d3a909aabb55baaa3f9711b176ef9b54d98951e4ba911981ae7e0fd371a7f4939a7803e4b2b913eeea46a99e776a7c5c0471f1525fc5124acc1eef79  fix-im-client-ldflags.patch
7da1cac9c5da3d87775f8c13d33be1c2b6ceb1cd34e5f9f28e97ef482097db087f58aaefedc5395e4f2caa5fe33fdc5779b0e5f7229988366048f9189b2138b0  implicit-declarations.patch
a15e918e802024af56ca8e52f3cfe1c67614ed89029bcd522f6650da6e4ac1f9021d9cacdb76bf687cbea5696eefa517fae134d472341ae635b28fe80ebe82c4  incompatible-pointers.patch
b5f704873a2aa6a6132b6ec9a368fd335b43ab830efd51b7b3b2308abdb7f17582b4144d25e6a42822600909b172f4c1385e70c358956498609cd68f074a0e9a  use-bash-not-sh.patch
"
