# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=the_silver_searcher
pkgver=2.2.0
pkgrel=1
pkgdesc="A code searching tool similar to ack, with a focus on speed."
options="!check" # No testsuite
url="https://geoff.greer.fm/ag/"
arch="all"
license="Apache-2.0"
makedepends="pcre-dev xz-dev zlib-dev"
subpackages="$pkgname-doc
	$pkgname-zsh-completion:zshcomp:noarch
	$pkgname-bash-completion:bashcomp:noarch"
source="https://geoff.greer.fm/ag/releases/the_silver_searcher-$pkgver.tar.gz
	gcc-10.patch
	no-lfs64.patch
	"
prepare() {
	default_prepare
	update_config_sub
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	mkdir -p "$subpkgdir"/usr/share/bash-completion/completions/
	mv "$pkgdir"/usr/share/the_silver_searcher/completions/ag.bashcomp.sh \
		"$subpkgdir"/usr/share/bash-completion/completions/ag

	rmdir -p "$pkgdir"/usr/share/the_silver_searcher/completions/ 2>&1 || true
}

zshcomp() {
	depends=""
	pkgdesc="Zsh completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel zsh"

	mkdir -p "$subpkgdir"/usr/share/zsh/site-functions/
	mv "$pkgdir"/usr/share/zsh/site-functions/_the_silver_searcher \
		"$subpkgdir"/usr/share/zsh/site-functions/

	rmdir -p "$pkgdir"/usr/share/zsh/site-functions/ 2>&1 || true
}

sha512sums="
89d4e4f7f34c0d57aa880e7c3466f0373b961744a89ad30541e89e2d614322ab46c8044ec458406a117f74b0fea14cd3063fa4e0624a96526aa23eaccd6f1141  the_silver_searcher-2.2.0.tar.gz
efda96b0f6371827e0fd568cdb751c059a8985fd263415616c9bd19e991e54e03c8ceb29c187b87146f8dcf730bb06abb065e6e6aa6a6342b3a4507ba1ab6501  gcc-10.patch
551e9d50fc761b6bbd1ce54cfcc140016de7302d733e73146f842cc4c683854b7b7bb3b7c20b3a1e3cf114669c5e22459a3998e6ae54b2154e1319ce168105a4  no-lfs64.patch
"
