# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: csslayer <wengxt AT gmail com>

pkgname=fcitx5-chinese-addons
pkgver=5.1.11
_py_stroke_ver=20250329
_py_table_ver=20121124
pkgrel=1
pkgdesc="Addons related to Chinese, including IME previous bundled inside fcitx4"
arch=('x86_64')
url="https://github.com/fcitx/fcitx5-chinese-addons"
license=('GPL')
conflicts=('fcitx')
depends=('curl' 'fcitx5-qt' 'libime' 'opencc' 'qt6-webengine')
makedepends=('git' 'boost' 'extra-cmake-modules' 'fcitx5-lua' 'ninja')
optdepends=('fcitx5-lua: Lua and imeapi support from pinyin')
source=("git+https://github.com/fcitx/fcitx5-chinese-addons.git#tag=$pkgver?signed"
        "https://download.fcitx-im.org/data/py_stroke-$_py_stroke_ver.tar.gz"
        "https://download.fcitx-im.org/data/py_table-$_py_table_ver.tar.gz")
sha512sums=('9e4dc35a153d69951f45cb0a0a4ee61f0bee45fc4fb149cad3634de027e542ed7638486ce8f274bb2bd2daa961c943a4556e7468a5a4e80df74a37fd093cd328'
            '0b69b008e00a246dd8ff56d6c1e2a3402a2f26e957623e2927b919ac8a90e99861c3f525e3ccf166ba27ac2e44cdbd68fb0dac234f7e4e8e26d7e23ab6ff9144'
            '0fa72ce6820a316e9729bc0d7a08af5ca3468134de9ff1bf0c559a398846a7bcf7313a3609d943e6bab637d930cf45ad9acfe25a8d3df078a774b071a7296486')
validpgpkeys=('2CC8A0609AD2A479C65B6D5C8E8B898CBF2412F9') # Weng Xuetian <wengxt@gmail.com>
noextract=("py_stroke-$_py_stroke_ver.tar.gz"
           "py_table-$_py_table_ver.tar.gz")

prepare() {
  cd $pkgname
  # fix tests: https://github.com/fcitx/fcitx5-chinese-addons/pull/238
  git cherry-pick -n 666f8d04548af7e47958de63fe7aa9da3f0e76c1

  mv ../py_stroke-$_py_stroke_ver.tar.gz modules/pinyinhelper/
  mv ../py_table-$_py_table_ver.tar.gz modules/pinyinhelper/
  # grep to make sure the version is correct
  grep "PY_STROKE_VER $_py_stroke_ver" modules/pinyinhelper/CMakeLists.txt
  grep "PY_TABLE_VER $_py_table_ver" modules/pinyinhelper/CMakeLists.txt
}

build() {
  cd $pkgname
  cmake -GNinja -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=/usr/lib -DUSE_WEBKIT=Off .
  ninja
}

check() {
  cd $pkgname
  ninja test
}

package() {
  cd $pkgname
  DESTDIR="$pkgdir" ninja install
}
