# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=pax-utils
pkgver=1.3.9
pkgrel=1
pkgdesc="ELF related utils for ELF 32/64 binaries"
url="https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities"
arch="all"
license="GPL-2.0-only"
depends="scanelf"
makedepends_build="meson"
makedepends_host="linux-headers libcap-dev"
checkdepends="bash python3 py3-elftools"
subpackages="$pkgname-doc scanelf:_scanelf lddtreepax:_lddtreepax:noarch"
[ -n "$BOOTSTRAP" ] && options="$options !check" # prevent python dependency
source="https://dev.gentoo.org/~sam/distfiles/app-misc/pax-utils/pax-utils-$pkgver.tar.xz
	"

build() {
	abuild-meson \
		-Db_lto=true \
		-Dlddtree_implementation=python \
		-Duse_seccomp=false \
		-Duse_libcap=enabled \
		-Dtests="$(want_check && echo true || echo false)" \
		. output
	meson compile -C output
}

check() {
	meson test --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# Don't conflict with main/lddtree
	mv "$pkgdir"/usr/bin/lddtree "$pkgdir"/usr/bin/lddtreepax
}

_scanelf() {
	depends=""
	pkgdesc="Scan ELF binaries for stuff"
	replaces="pax-utils"

	amove usr/bin/scanelf
}

_lddtreepax() {
	depends="python3 py3-elftools"
	pkgdesc="Read and package ELF dependency trees"

	amove usr/bin/lddtreepax
}

sha512sums="
96caf7f2087bedc7949db828d966835f7d691e29ef8177dee00605c10d433d4c5b5770a3d7f2e25e3c0218f5b9a6c6967669a3dea18cf138d6f0111d2bb5288b  pax-utils-1.3.9.tar.xz
"
