# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=mosh
pkgver=master
pkgrel=17
pkgdesc="Mobile shell surviving disconnects with local echo and line editing"
options="!check" # emulation-cursor-motion.test fails
url="https://mosh.org"
arch="all !mips64"
license="GPL-3.0-or-later"
depends="$pkgname-client $pkgname-server"
checkdepends="tmux perl"
makedepends="ncurses-dev zlib-dev openssl-dev perl-dev perl-doc perl-io-tty
	protobuf-dev automake autoconf libtool gzip"
subpackages="$pkgname-doc $pkgname-client $pkgname-server
	$pkgname-bash-completion:bashcomp:noarch"
source="https://github.com/mobile-shell/mosh/archive/$pkgver.zip"

builddir="$srcdir"/$pkgname-$pkgver

prepare() {
	default_prepare
	# Test unicode-later-combining is failing. Ideally we want to fix it.
	sed -i '/unicode-later-combining.test/d' "$builddir"/src/tests/Makefile.am
	cd "$builddir"
	./autogen.sh
}

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-compile-warnings=error \
		--enable-examples
	make
}

check() {
	cd "$builddir"
	make distcheck VERBOSE=1 V=1
}

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

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

	install -Dm644 "$builddir"/conf/bash-completion/completions/mosh \
		"$subpkgdir"/usr/share/bash-completion/completions/$pkgname
}

server() {
	replaces="mosh"
	pkgdesc="Mosh server"
	depends=""
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/mosh-server \
		"$subpkgdir"/usr/bin/
}

client() {
	replaces="mosh"
	pkgdesc="Mosh client"
	depends="openssh-client perl-io-tty"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/mosh-client \
		"$subpkgdir"/usr/bin/
}

sha512sums="1aca55646667ce937da329d3dcc31c124f7a60b975c732cba4290fa7782ac75f17341d9690c811417420269393c415908177c0450dc7d3b6fbfbb9f6ac4cd744  master.zip"