# Maintainer: Naveen M K <naveen521kk@gmail.com>

_realname=bat
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.18.1
pkgrel=1
pkgdesc="Cat clone with syntax highlighting and git integration (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/sharkdp/bat'
license=(APACHE MIT)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/sharkdp/bat/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('ab5246c3bec8745c14ca9a0473971f00fbce2fdc1ce7842e0a96676ee5eac2af')

prepare() {
  cp -r ${_realname}-${pkgver} build-${CARCH}
  ${MINGW_PREFIX}/bin/cargo fetch \
  --locked \
  --manifest-path build-${CARCH}/Cargo.toml
}

build() {
  ${MINGW_PREFIX}/bin/cargo build \
  --release \
  --manifest-path build-${CARCH}/Cargo.toml
}

package() {
  ${MINGW_PREFIX}/bin/cargo install \
  --offline \
  --no-track \
  --path build-${CARCH} \
  --root ${pkgdir}${MINGW_PREFIX}

  # Package licenses
  install -Dm644 build-${CARCH}/LICENSE-APACHE \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/$pkgname/LICENSE-APACHE
  install -Dm644 build-${CARCH}/LICENSE-MIT \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/$pkgname/LICENSE-MIT

  cd build-${CARCH}/target/release/build

  # Package the man page
  find . -name bat.1 -type f -exec install -Dm644 {} \
    "${pkgdir}${MINGW_PREFIX}"/share/man/man1/bat.1 \;

  find . -name bat.zsh -type f -exec install -Dm644 {} \
    "${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_bat \;

  # Package the fish completion
  find . -name bat.fish -type f -exec install -Dm644 {} \
    "${pkgdir}${MINGW_PREFIX}"/share/fish/vendor_completions.d/bat.fish \;

}
