pkgname=bat
pkgver=0.26.1
pkgdesc='Cat clone with syntax highlighting and git integration'
arch=(x86_64)
homepage='https://github.com/sharkdp/bat'
license=('Apache-2.0 OR MIT')
depends=(gcc glibc libgit2 oniguruma zlib)
makedepends=(clang cmake rust)
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://github.com/sharkdp/${pkgname}/archive/v${pkgver}.tar.gz")
sha512sums=("4b97c094922a750b61744fb9f54685554577d316074b52f5c9dd864fd3bfc91d9cf2fdc5fb7558aaf5c0277470fa40c551d3b284e989b46c3903442bc970b2f8")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  cargo fetch --locked --target "$(rustc --print host-tuple)"
}

src_build() {
  CFLAGS+=' -ffat-lto-objects -w'
  CFLAGS=${CFLAGS/-O2/-O3}
  export LIBGIT2_NO_VENDOR=1
  cargo build --frozen --release
}

src_check() {
  export LIBGIT2_NO_VENDOR=1
  cargo test --locked --release
}

src_install() {
  install -Dm755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"

  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE-APACHE LICENSE-MIT

  cd target/release/build

  # Find and package the man page (because cargo --out-dir is too new)
  find . -name bat.1 -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/man/man1/bat.1" \;

  # Find and package the bash completion file
  find . -name bat.bash -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/bash-completion/completions/bat" \;

  # Find and package the zsh completion file (not in zsh-completions yet)
  find . -name bat.zsh -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/zsh/site-functions/_bat" \;

  # Find and package the fish completion file
  find . -name bat.fish -type f -exec install -Dm644 {} \
    "$pkgdir/usr/share/fish/vendor_completions.d/bat.fish" \;
}

# vim:ft=sh syn=sh et sw=2:
