# Maintainer: Gavin Luo <lunt.luo#gmail.com>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: GONG Chen <chen dot sst at gmail dot com>
# Contributor: 網軍總司令

pkgname=librime-luajit
pkgver=1.17.0
pkgrel=4
epoch=1
pkgdesc="Rime input method engine"
arch=('x86_64')
url="https://github.com/rime/librime"
license=('BSD-3-Clause')
depends=('boost-libs' 'capnproto' 'glibc' 'opencc' 'yaml-cpp' 'leveldb' 'librime-data' 'luajit' 'google-glog' 'marisa' 'libstdc++' 'libgcc')
makedepends=('git' 'cmake' 'boost' 'gtest' 'ninja')
source=("git+https://github.com/rime/librime.git#tag=$pkgver"
        "git+https://github.com/lotem/librime-octagram.git"
        "git+https://github.com/hchunhui/librime-lua.git"
        "git+https://github.com/rime/librime-charcode.git"
        "git+https://github.com/lotem/librime-proto.git"
        "git+https://github.com/rime/librime-predict.git")
sha512sums=('411f3555e307910cc71304de796a5b55834226f840fd664ca92fe91ce9012c0cfa1870dc29b5e24afae859f5c2177960ea553774512affd9bef0f46e00b46cc0'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP')
provides=("librime=${pkgver}")
conflicts=(librime)

prepare() {
  cd ${srcdir}/librime
  # Fix simplifier crashes with OpenCC converters without conversion chains:
  # https://github.com/rime/librime/pull/1184
  git cherry-pick -n 96a55478ba6ae3f8e78a3c824809905745440d57

  cd ${srcdir}/librime/plugins
  ln -sf "$srcdir"/librime-octagram .
  ln -sf "$srcdir"/librime-lua .
  ln -sf "$srcdir"/librime-charcode .
  ln -sf "$srcdir"/librime-proto .
  ln -sf "$srcdir"/librime-predict .
}

build() {
  cd librime
  export CXXFLAGS="$CXXFLAGS -DNDEBUG -DGLOG_USE_GLOG_EXPORT -DGLOG_USE_GFLAGS"
  cmake . -GNinja -Bbuild -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_MERGED_PLUGINS=Off -DENABLE_EXTERNAL_PLUGINS=On -Wno-dev -DLUA_VERSION=luajit
  cmake --build build
}

check() {
  cd librime/build
  ninja test
}

package() {
  cd librime/build
  DESTDIR="$pkgdir" ninja install
  install -vDm 644 ../LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
