# Build template for 'base-system-busybox'.
pkgname=base-system-busybox
version=1.23.2
revision=7
wrksrc="busybox-${version}"
homepage="http://www.busybox.net"
hostmakedepends="perl"
short_desc="The Swiss Army Knife of Embedded Linux - base-system replacements"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="GPL-2"
distfiles="${homepage}/downloads/busybox-$version.tar.bz2"
checksum=05a6f9e21aad8c098e388ae77de7b2361941afa7157ef74216703395b14e319a

register_shell="/bin/sh"
conflicts="base-system>=0"

# Applets provided by this busybox version.
# Keep this list updated with ${FILESDIR}/dotconfig.
#
# XXX bzip2 provides libbz2, split it into libbz2 pkg.
# XXX pgrep/pkill do not support -s0,1 required by runit-void.
#
_FEATURES="acpid coreutils cpio dash diffutils dosfstools findutils awk
	grep gzip hdparm ifenslave iproute2 iputils less lsof netcat nvi
	patch powertop psmisc rfkill run-parts sed tar
	traceroute util-linux which whois xz ncurses"
for f in ${_FEATURES}; do
	provides+=" ${f}-${version}_${revision}"
	conflicts+=" ${f}>=0"
done

depends="base-files runit-void xbps kbd eudev shadow kmod ncurses-base procps-ng tzdata ethtool"

case "$XBPS_TARGET_MACHINE" in
	*-musl) depends+=" musl";;
	*) depends+=" glibc-locales";;
esac

pre_build() {
	cp -f ${FILESDIR}/dotconfig .config
	if [ "$CROSS_BUILD" ]; then
		sed -e "s,\(CONFIG_CROSS_COMPILER_PREFIX\).*,\1=\"${XBPS_CROSS_TRIPLET}-\",g" -i .config
	fi
}
do_build() {
	rm -f ${XBPS_WRAPPERDIR}/strip
	make ${makejobs}
}
do_install() {
	# Install everything to /usr/bin.
	vmkdir usr/bin
	for f in bin sbin; do
		ln -sfr ${DESTDIR}/usr/bin ${DESTDIR}/${f}
	done
	make CONFIG_PREFIX=${DESTDIR} install
	vinstall ${FILESDIR}/udhcpc-default.script \
		755 usr/share/udhcpc default.script
	mv ${DESTDIR}/usr/sbin/* ${DESTDIR}/usr/bin
	rm -f ${DESTDIR}/{,s}bin
	# Provide /sbin/init symlink to runit.
	ln -s runit-init ${DESTDIR}/usr/bin/init
}
