# Contributor: Daniel Santana <daniel@santana.tech>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=proot
pkgver=5.4.0
pkgrel=1
pkgdesc="User-space implementation of chroot, mount --bind, and binfmt_misc"
url="https://proot-me.github.io"
arch="aarch64 armhf armv7 x86 x86_64"
license="GPL-2.0-or-later"
makedepends="
	bsd-compat-headers
	libarchive-dev
	linux-headers
	py3-docutils
	talloc-dev
	talloc-static
	uthash-dev
	"
checkdepends="
	bash
	coreutils
	grep
	lzop
	mcookie
	python3
	strace
	"
subpackages="$pkgname-doc $pkgname-static"
source="https://github.com/proot-me/proot/archive/v$pkgver/proot-$pkgver.tar.gz
	fix-basename.patch
	tests-musl-compat.patch
	"
options="!check"  # FIXME: several tests are failing

prepare() {
	default_prepare
	cp -r src src-static
}

build() {
	make -C src proot VERSION=$pkgver
	make -C src-static proot VERSION=$pkgver \
		LDFLAGS="$LDFLAGS -static -ltalloc"
	make -C doc proot/man.1
}

check() {
	ln -sfv /usr/bin/python3 python
	PATH="$PATH:$PWD" make -C test
}

package() {
	install -Dvm755 ./src/proot \
		-t "$pkgdir"/usr/bin/
	install -Dvm755 ./src-static/proot \
		"$pkgdir"/usr/bin/proot.static
	install -Dvm644 ./doc/proot/man.1 \
		"$pkgdir"/usr/share/man/man1/proot.1
}

static() {
	pkgdesc="$pkgdesc (static binary)"

	amove usr/bin/proot.static
}

sha512sums="
c4d7b7428758c0d8f6a89ecaa01d1d7d5d9663a84b7e730e8160bc2a2385a7e278589f5dd86f5cd4f8e0736f09b3097b9efea7814096fd2d28e6032435b9ee63  proot-5.4.0.tar.gz
86dba073aacfb61a22115042956a4ee8e8d14d99617642976c90b7cd1ee26a72ee6fdee44c8fbac4b774d12ac5f0bded0e8dab38f6bb9c961c680f843636d169  fix-basename.patch
d09de6d776072e9991abd04e294e6d36bd1634b9e972294a112526ebf3f63e919d01755de1ecd7253d614b41b07fe6882df8787c638b8576bcf2555abcafa466  tests-musl-compat.patch
"
