# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=miniserve
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.32.0
pkgrel=1
pkgdesc="Tool to serve files via HTTP (mingw-w64)"
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
arch=('any')
url="https://github.com/svenstaro/miniserve"
msys2_repository_url="https://github.com/svenstaro/miniserve"
msys2_references=(
  "archlinux: miniserve"
  "purl: pkg:cargo/miniserve"
)
license=("spdx:MIT")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/svenstaro/miniserve/archive/v${pkgver}.tar.gz")
sha256sums=('30cfabd398f0c17c2eff3fdab115b5681e21fb048f363955a064249d14cd5869')

build() {
  cd "${_realname}-${pkgver}"
  cargo build --release --locked
}

check() {
  cd "${_realname}-${pkgver}"
  cargo test --release --locked -- --test-threads=1
}

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

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share"/{bash-completion/completions,zsh/site-functions,fish/vendor_completions.d}
  "target/release/${_realname}.exe" --print-completions bash > "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/${_realname}"
  "target/release/${_realname}.exe" --print-completions zsh > "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_${_realname}"
  "target/release/${_realname}.exe" --print-completions fish > "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/${_realname}.fish"

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/man/man1"
  "target/release/${_realname}.exe" --print-manpage | gzip > "${pkgdir}${MINGW_PREFIX}/share/man/man1/${_realname}.1.gz"

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