# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: whisky <archlinux.cle(at)gmail.com>
# Contributor: damir <damir@archlinux.org>

pkgname=libchewing
pkgver=0.7.0
pkgrel=1
pkgdesc='Intelligent Chinese phonetic input method'
url='https://chewing.im/'
arch=('x86_64' 'aarch64')
# See discussions at https://github.com/chewing/libchewing/issues/433
license=('LGPL-2.1-or-later')
depends=('sqlite')
makedepends=('cmake' 'minisign')
optdepends=(
  'chewing-editor: view and modify libchewing user phrases database'
)
source=("https://github.com/chewing/${pkgname}/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.zst"{,.minisig})
sha256sums=('87289bc759d04bfebad92d395d4f63e54f584f3e805731588edaa0c9a8bb6cce'
            '16ed098e7a63da7631d27d2df3a72e095bed057aebe5a98335c766b5bf7b82db')
# The key is mentioned on https://github.com/chewing/libchewing
_validminisignkey='RWRzJFnXiLZleAyCIv1talBjyRewelcy9gzYQq9pd3SKSFBPoy57sf5s'

# XXX: move to verify() when pacman 7.0 is out
# https://gitlab.archlinux.org/pacman/pacman/-/merge_requests/37
prepare() {
  minisign -Vm $pkgname-$pkgver.tar.zst -P $_validminisignkey
}

build() {
  # Specify the existence of ncurses.h manually as FindCurses.cmake cannot identify it
  cmake -B build -S $pkgname-$pkgver \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_INFO=ON \
    -DCURSES_HAVE_NCURSES_H=ON
  make -C build
}

check() {
  # parallel testing is broken (https://github.com/chewing/libchewing/issues/293)
  make -C build -j1 check
}

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