# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=alacritty
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.16.1
pkgrel=1
pkgdesc="A cross-platform, OpenGL terminal emulator (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://alacritty.org"
msys2_repository_url="https://github.com/alacritty/alacritty"
license=('spdx:Apache-2.0 OR MIT')
msys2_references=(
  'archlinux: alacritty'
  'purl: pkg:cargo/alacritty'
)
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-ncurses"
             "${MINGW_PACKAGE_PREFIX}-scdoc"
             'git')
checkdepends=("${MINGW_PACKAGE_PREFIX}-ttf-dejavu")
optdepends=("${MINGW_PACKAGE_PREFIX}-ncurses: for alacritty terminfo database")
source=("git+${msys2_repository_url}.git#tag=v${pkgver}")
validpgpkeys=('4DAA67A9EA8B91FCC15B699C85CDAE3C164BA7B4'  # Christian Dürr <contact@christianduerr.com>
              'A56EF308A9F1256C25ACA3807EA8F8B94622A6A9') # Kirill Chibisov <contact@kchibisov.com>
sha256sums=('e339261179f7edcaf9c28b1646d5a6761e76eae62078f07c308e8efa9ace18bb')

prepare() {
  cd "${_realname}"

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

build() {
  cd "${_realname}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo build --release --locked
}

check() {
  cd "${_realname}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo test --release --locked
}

package() {
  cd "${_realname}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -d "${pkgdir}${MINGW_PREFIX}"/share/man/man{1,5}
  scdoc < "extra/man/${_realname}.1.scd" | gzip > "${pkgdir}${MINGW_PREFIX}/share/man/man1/${_realname}.1.gz"
  scdoc < "extra/man/${_realname}-msg.1.scd" | gzip > "${pkgdir}${MINGW_PREFIX}/share/man/man1/${_realname}-msg.1.gz"
  scdoc < "extra/man/${_realname}.5.scd" | gzip > "${pkgdir}${MINGW_PREFIX}/share/man/man5/${_realname}.5.gz"
  scdoc < "extra/man/${_realname}-bindings.5.scd" | gzip > "${pkgdir}${MINGW_PREFIX}/share/man/man5/${_realname}-bindings.5.gz"
  install -Dm644 "extra/completions/alacritty.bash" "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/alacritty"
  install -Dm644 "extra/completions/_alacritty" "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_alacritty"
  install -Dm644 "extra/completions/alacritty.fish" "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/alacritty.fish"
  install -Dm644 "extra/logo/alacritty-term.svg" "${pkgdir}${MINGW_PREFIX}/share/pixmaps/Alacritty.svg"
}
