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

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
	cd toybox
	make defconfig
	make ${makejobs} toybox

	# toybox-static
	cd ../toybox-static
	make defconfig
	make ${makejobs} LDFLAGS="-static" toybox
}

_rm_failing_tests() {
	# XXX: Some tests for du, find, grep, sed and tar fail
	rm tests/du.test
	rm tests/find.test
	rm tests/grep.test
	rm tests/sed.test
	rm tests/tar.test
	[ "$XBPS_BUILD_ENVIRONMENT" != void-packages-ci ] && return 0
	# XXX: chattr, hostname,losetup, rmdir tests fail on CI
	rm tests/chattr.test
	rm tests/hostname.test
	rm tests/losetup.test
	rm tests/rmdir.test
	rm tests/rm.test
}

do_check() {
	msg_normal "Running tests for toybox...\n"
	cd toybox
	_rm_failing_tests
	make tests

	msg_normal "Running tests for toybox-static...\n"
	cd ../toybox-static
	_rm_failing_tests
	make 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
	}
}
