pkgname=fzf
pkgver=0.67.0
pkgdesc='Command-line fuzzy finder'
arch=('x86_64')
homepage='https://github.com/junegunn/fzf'
license=('MIT')
depends=('bash')
makedepends=('go')
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://github.com/junegunn/fzf/archive/v${pkgver}.tar.gz")
md5sums=("502f470af95a7dec0dec2d21a1c42427")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  sed -i 's/-w /-w -linkmode external /' Makefile
}

src_build() {
  export CGO_LDFLAGS="${LDFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  export FZF_VERSION=${pkgver}
  export FZF_REVISION=tarball
	make
  make bin/fzf
}

src_check() {
  export CGO_LDFLAGS="${LDFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
	go test ./...
}

src_install() {
  ## Man page
	install -Dm644 man/man1/fzf.1 "$pkgdir"/usr/share/man/man1/fzf.1
	install -Dm644 man/man1/fzf-tmux.1 "$pkgdir"/usr/share/man/man1/fzf-tmux.1

	## License
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/fzf/LICENSE

	## Binaries
	install -dm755 "$pkgdir"/usr/bin
	install -m755 bin/fzf-tmux "$pkgdir"/usr/bin/
	install -m755 bin/fzf "$pkgdir"/usr/bin/

	## Completion and keybindings
	install -dm755 "$pkgdir"/usr/share/fzf
	install -m644 shell/key-bindings.bash shell/key-bindings.zsh shell/key-bindings.fish "$pkgdir"/usr/share/fzf
	install -m755 bin/fzf-preview.sh "$pkgdir"/usr/share/fzf/fzf-preview.sh
  install -Dm644 shell/completion.bash "${pkgdir}"/usr/share/bash-completion/completions/fzf
  install -Dm644 shell/completion.zsh "${pkgdir}"/usr/share/zsh/site-functions/_fzf

	## Vim plugin
	install -Dm644 doc/fzf.txt "$pkgdir"/usr/share/vim/vimfiles/doc/fzf.txt
	install -Dm644 plugin/fzf.vim "$pkgdir"/usr/share/vim/vimfiles/plugin/fzf.vim
}


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