# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=drawterm
pkgver=20170119
pkgrel=2
pkgdesc="Connect to Plan 9 CPU servers from other operating systems"
url="http://drawterm.9front.org/"
arch="all !armhf !aarch64 !s390x"
license="custom"
depends=""
options="!check"
makedepends="linux-headers libx11-dev libxt-dev"
install=""
subpackages="$pkgname-dbg"
source="http://dev.alpinelinux.org/archive/$pkgname/$pkgname-$pkgver.tar.gz
	fix-off-by-one.patch
	respect-env.patch"

_srcurl="https://code.9front.org/hg/$pkgname"
_srcrev="169f32a871c9"

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

prepare() {
	cd "$builddir"

	if [ "$CARCH" = "ppc64le" ]; then
		ln -s posix-power posix-ppc64le
	fi
	default_prepare
}

snapshot() {
	mkdir -p "$srcdir" && cd "$srcdir"

	hg clone "$_srcurl" $pkgname-$pkgver \
		-r "$_srcrev"
	hg --cwd "$pkgname-$pkgver" archive \
		-t tgz \
		-X ".hg*" \
		-p $pkgname-$pkgver/ \
		"$srcdir"/$pkgname-$pkgver.tar.gz

	scp "$srcdir"/$pkgname-$pkgver.tar.gz \
		dev.alpinelinux.org:/archive/$pkgname/
}

build() {
	CONF=unix make X11INC=/usr/include/X11 \
		X11LIB=/usr/lib/X11 \
		-C "$builddir"
}

package() {
	cd "$builddir"
	install -Dm755 $pkgname \
		"$pkgdir"/usr/bin/$pkgname
	install -Dm644 LICENSE \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="fec2895bd01940cd91ed6c4b73fd13ec6a55c5a5b2241f48430a73af44e6e4c649819a2ee9feee1880d4bf27ab007a229c6b5170039b73f1f19f8b0e6d04c510  drawterm-20170119.tar.gz
dc57264470e2ab583c7dfbb6451b9fcea47e37a24bdeb7e512ab50a0321f086b471dbe08b2d13514c7842e084f5fdf078f917a19e62bd6aaceb2e199e8169374  fix-off-by-one.patch
be42c27a550b49f13fa26cdd698fb4d8387d989141cae1a3671deceb82b9286c9f73772ec9731698c7ecef69949381f9eda8af1dc1d9957fa373752e52f809bb  respect-env.patch"
