pkgname=abuild
pkgver=3.18.0_rc5_git20260823
pkgrel=0
pkgdesc="Upstream Alpine packaging tools with a minimal Debian shell portability patch"
url="https://gitlab.alpinelinux.org/alpine/abuild"
arch="all"
license="GPL-2.0-only"
depends="apk-tools busybox fakeroot pax-utils libcap-utils openssl pkgconf bc binutils make
	git patch curl tar gzip bzip2 xz zstd"
makedepends="pkgconf openssl-dev zlib-dev scdoc"
_commit=2770c8ec05ca2a5bbdaf74e340b9dba0257c1fd5
source="https://github.com/alpinelinux/abuild/archive/$_commit.tar.gz
	abuild-debian-shell.patch"
sha256sums="
dde9e38cd4d7074640cc362cd8fe5eeca72f4d4b9b6b657fb70d6f2cdb7d79c4  $_commit.tar.gz
a0e3627d8b8075240446900325a4f7ec0056fbdd3b6a1070a8c7d0757bfe2be7  abuild-debian-shell.patch
"
builddir="$srcdir/$pkgname-$_commit"

build() {
	make
	# The current foundationpkgs builder does not invoke check() itself.
	if ! cross_compiling; then
		check
	fi
}

check() {
	grep -q '^#!/bin/busybox ash$' abuild
	ABUILD_SHAREDIR="$builddir" ABUILD_CONF=/dev/null ABUILD_USERCONF=/dev/null ./abuild -V
}

package() {
	make DESTDIR="$pkgdir" install
	# Bootstrap packaging must not introduce a setuid helper on Debian.
	chmod 0755 "$pkgdir/usr/bin/abuild-sudo"
	# Match upstream man-page policy without relying on builder-specific splits.
	find "$pkgdir/usr/share/man" -type f -exec gzip -n -9 {} \;
	# Debian keeps getcap outside a regular user's default PATH.
	printf '\nexport PATH="$PATH:/usr/sbin:/sbin"\n' >>"$pkgdir/etc/abuild.conf"
	mkdir -p "$pkgdir/usr/share/licenses/$pkgname"
	install -m644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}
