# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Chris Lane <aur at chrislane dot com>
# Contributor: phiresky <phireskyde+aur@gmail.com>
# Contributor: Julien Nicoulaud <julien DOT nicoulaud AT gmail DOT com>

pkgname=ripgrep-all
pkgver=0.10.6
pkgrel=3
pkgdesc="rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc."
arch=('x86_64' 'aarch64')
url='https://github.com/phiresky/ripgrep-all'
license=('AGPL3')
depends=('ripgrep' 'xz')
makedepends=('cargo')
checkdepends=('pandoc' 'poppler')
optdepends=(
  'ffmpeg: for the ffmpeg adapter'
  'graphicsmagick: for the pdfpages adapter'
  'pandoc: for the pandoc adapter'
  'poppler: for the poppler adapter'
  'tesseract: for the tesseract adapter'
)
options=(!lto)
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/phiresky/ripgrep-all/archive/refs/tags/v${pkgver}.tar.gz"
)
b2sums=('fc2618369c349fda5a78d3604b17b78788be73ce5925a5b6aa234627ccaa4b70dba8deddfc7cf5ef38dfe3c94d60a84956d9779110af2ff7ca44812774ffa28b')

prepare() {
  cd ripgrep-all-${pkgver}
  export CARGO_HOME="$srcdir/cargo"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd ripgrep-all-${pkgver}
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  export CARGO_HOME="$srcdir/cargo"
  cargo build --frozen --release --all-features
}

check() {
  cd ripgrep-all-${pkgver}
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_HOME="$srcdir/cargo"
  cargo test --frozen --all-features
}

package() {
  cd ripgrep-all-${pkgver}
  install -Dm 755 target/release/rga "${pkgdir}"/usr/bin/rga
  install -Dm 755 target/release/rga-preproc "${pkgdir}"/usr/bin/rga-preproc
  install -Dm 755 target/release/rga-fzf "${pkgdir}"/usr/bin/rga-fzf
  install -Dm 755 target/release/rga-fzf-open "${pkgdir}"/usr/bin/rga-fzf-open
}
