# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=minisign
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.12
pkgrel=1
pkgdesc="A dead simple tool to sign files and verify digital signatures (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/jedisct1/minisign"
license=('spdx:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-libsodium")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/jedisct1/minisign/archive/${pkgver}/${_realname}-$pkgver.tar.gz")
sha512sums=('fc95020fef3ae63ab974a20c39b9bf05df957c40838fceb73cb10d6cec9880d882727b6a0240b81b4a7593ff2603d4eef4b32b0857dcf5f85de5e0b7573086ed')

build() {
  mkdir -p "${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}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -Dm644 "${srcdir}"/minisign-${pkgver}/LICENSE "$pkgdir"/${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
