# Template file for 'hub'
pkgname=hub
version=2.14.2
revision=5
build_style=go
go_import_path=github.com/github/hub
hostmakedepends="git groff"
short_desc="Command line tool for Github"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="MIT"
homepage="https://hub.github.com/"
changelog="https://github.com/github/hub/releases"
distfiles="https://github.com/github/hub/archive/v${version}.tar.gz"
checksum=e19e0fdfd1c69c401e1c24dd2d4ecf3fd9044aa4bd3f8d6fd942ed1b2b2ad21a

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" hub"
fi

post_install() {
	# needs col(1), which is only built on glibc
	if [ "$XBPS_TARGET_LIBC" = glibc ]; then
		if [ "$CROSS_BUILD" ]; then
			vsed -e 's|bin/hub|hub|g' -i Makefile

			(
				# Build md2roff ourselves since it needs to be executed on
				# the host, also use a subshell so we don't modify the
				# environment of the main program
				unset GOARCH GOARM GOOS
				export CC="$CC_FOR_BUILD"
				export CFLAGS="$CFLAGS_FOR_BUILD"
				go build -o bin/md2roff github.com/github/hub/md2roff-bin
			)
		fi

		make man-pages

		for m in share/man/man1/*.1; do
			vman $m
		done

		for d in share/doc/hub-doc/*.html; do
			vdoc $d
		done
	fi

	vlicense LICENSE

	vinstall etc/hub.zsh_completion 644 usr/share/zsh/site-functions _hub
	vinstall etc/hub.bash_completion.sh 644 usr/share/bash-completion/completions hub
	vinstall etc/hub.fish_completion 644 usr/share/fish/vendor_completions.d hub.fish
	for i in share/vim/vimfiles/*/pullrequest.vim; do
		dir="${i%/*}"
		vinstall "$i" 644 "usr/$dir"
		vmkdir "usr/${dir/vim/nvim}"
		ln -sr "$DESTDIR/usr/${i}" "$DESTDIR/usr/${i/vim/nvim}"
	done
}
