# Maintainer: Feng Shu <tumashu@163.com>

_realname=liberime
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.6
pkgrel=2
pkgdesc="An emacs dynamic module provide librime bindings for emacs (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/merrickluo/liberime"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-librime")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/merrickluo/liberime/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('52dd3e000402c3a5476755de053c097cd7b7a2bd4a2134d6019559629b508ebb')

build() {
  mkdir - "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  install -Dm644 liberime-core.dll "${pkgdir}"${MINGW_PREFIX}/bin/liberime-core.dll
  install -Dm644 liberime-core.dll.a "${pkgdir}"${MINGW_PREFIX}/lib/liberime-core.dll.a
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/README.org "${pkgdir}"${MINGW_PREFIX}/share/liberime/README.org
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/liberime.el "${pkgdir}"${MINGW_PREFIX}/share/emacs/site-lisp/liberime.el
}
