# Template file for 'toybox'
pkgname=toybox
version=0.8.13
revision=1
create_wrksrc=yes
short_desc="BSD-licensed alternative to busybox"
maintainer="Orphaned <orphan@voidlinux.org>"
license="0BSD"
homepage="http://www.landley.net/toybox"
changelog="https://www.landley.net/toybox/news.html"
distfiles="http://www.landley.net/toybox/downloads/toybox-${version}.tar.gz"
checksum=9d4c124d7d731a2db399f6278baa2b42c2e3511f610c6ad30cc3f1a52581334b

if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
	makedepends+=" libxcrypt-devel"
fi

post_extract() {
	mv toybox-${version} toybox
	cp -r toybox toybox-static
}

do_build() {
	export NOSTRIP=1

	# toybox
	make -C toybox defconfig
	make -C toybox ${makejobs} toybox

	# toybox-static
	make -C toybox-static defconfig
	make -C toybox-static ${makejobs} LDFLAGS="-static" toybox
}

pre_check() {
	# XXX: Some tests for du, ls and tar fail, depending on filesystem and the environment
	rm -f toybox{,-static}/tests/du.test
	rm -f toybox{,-static}/tests/ls.test
	rm -f toybox{,-static}/tests/tar.test
	rm -f toybox{,-static}/tests/sed.test # musl: FAIL: sed s after NUL
	rm -f toybox{,-static}/tests/devmem.test # musl: FAIL: devmem read 8
	[ "$XBPS_BUILD_ENVIRONMENT" != void-packages-ci ] && return 0
	# XXX: chattr, hostname,losetup, rmdir tests fail on CI
	rm toybox{,-static}/tests/chattr.test
	rm toybox{,-static}/tests/hostname.test
	rm toybox{,-static}/tests/losetup.test
	rm toybox{,-static}/tests/rmdir.test
	rm toybox{,-static}/tests/rm.test
}

do_check() {
	export USER=$(id -un)
	msg_normal "Running tests for toybox...\n"
	make -C toybox tests
	msg_normal "Running tests for toybox-static...\n"
	make -C toybox-static tests
}

do_install() {
	vbin toybox/toybox
	vlicense toybox/LICENSE
}

toybox-static_package() {
	short_desc+=" - statically linked"
	pkg_install() {
		vbin toybox-static/toybox toybox.static
		vlicense toybox-static/LICENSE
	}
}
