# Contributor: Lindsay Zhou <i@lin.moe>
# Maintainer: Lindsay Zhou <i@lin.moe>
pkgname=libime
pkgver=1.1.8
pkgrel=0
_kenlm=bcd4af619a2fa45f5876d8855f7876cc09f663af
pkgdesc="Fcitx input method engine library"
url="https://github.com/fcitx/libime"
arch="all"
license="LGPL-2.1-or-later"
depends_dev="boost-dev"
makedepends="
	$depends_dev
	cmake
	extra-cmake-modules
	fcitx5-dev
	samurai
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/fcitx/libime/archive/refs/tags/$pkgver.tar.gz
	kenlm-$_kenlm.tar.gz::https://github.com/kpu/kenlm/archive/$_kenlm.tar.gz
	"
options="net" # build fetches some checksummed language data itself, todo

prepare() {
	default_prepare

	rmdir src/libime/core/kenlm
	ln -sfv "$srcdir"/kenlm-$_kenlm src/libime/core/kenlm
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DENABLE_TEST="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

core() {
	pkgdesc="$pkgdesc (core module)"

	amove usr/lib/libIMECore.so.*
}

pinyin() {
	pkgdesc="$pkgdesc (pinyin module)"

	amove usr/lib/libIMEPinyin.so.*
}

table() {
	pkgdesc="$pkgdesc (table module)"

	amove usr/lib/libIMETable.so.*
}

sha512sums="
4625b510314b6863c909f12b94b246ef1817a0f8604f4dc2ad2591d45b71b6bc31e2be2435a85a806d44b8dea9d7e2b0d3bd4acf58a9c78c37ec0a2fc657705c  libime-1.1.8.tar.gz
0ed68ed3b927b8c8353ab3815d17d0706b3357dce8a446176bd48ef6b73989bcf142983008e2b2b5e44769428a684dc1abcf3973f9f99c76b9bfc5f80a3aa363  kenlm-bcd4af619a2fa45f5876d8855f7876cc09f663af.tar.gz
"
