# Maintainer: Sylvain Rouquette <srouquette@gmail.com>

_realname=mdcat
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.7.1
pkgrel=1
pkgdesc="Fancy cat for Markdown (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64' 'mingw64')
url='https://github.com/swsnr/mdcat'
msys2_references=(
  'purl: pkg:cargo/mdcat'
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-curl")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
options=('!strip')
source=("${url}/archive/${_realname}-${pkgver}.tar.gz")
sha256sums=('460024d9795eb578be09ec2284af243627721151aa001aae6ffb5589380b2ba1')
prepare() {
  cd "${_realname}-${_realname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  cd "${_realname}-${_realname}-${pkgver}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo build --release --frozen
}

check() {
  cd "${_realname}-${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

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