# busybox - init, getty, mdev and the network stack.
# Arctic runs busybox as PID 1. The classic Unix commands come from toybox
# instead, so this build keeps the applets busybox is actually best at.
name=busybox
version=1.38.0
release=1
desc="Init, getty, device manager and network tools in one binary"
url="https://busybox.net/"
license="GPL-2.0-only"
depend="glibc"
source="https://busybox.net/downloads/busybox-$version.tar.bz2
	arctic.config"
sha256="SKIP
	SKIP"

build() {
	cd "busybox-$version"
	cp ../arctic.config .config
	make oldconfig </dev/null >/dev/null
	make -j"$JOBS" CFLAGS_EXTRA="-Wno-error"
	# A static copy for the initramfs, where no libraries exist yet.
	cp .config .config.dyn
	sed -i 's/^# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config
	make oldconfig </dev/null >/dev/null
	make -j"$JOBS" CFLAGS_EXTRA="-Wno-error" busybox
	cp busybox busybox.static
	cp .config.dyn .config
	make oldconfig </dev/null >/dev/null
	make -j"$JOBS" CFLAGS_EXTRA="-Wno-error"
}

package() {
	cd "busybox-$version"
	install -Dm755 busybox "$pkgdir/usr/bin/busybox"
	install -Dm755 busybox.static "$pkgdir/usr/lib/arctic/busybox.static"
	install -Dm644 .config "$pkgdir/usr/share/busybox/config"
	# Only claim the applets Arctic wants from busybox; toybox takes the rest.
	for a in init getty mdev sh ash login su passwd chpasswd adduser addgroup \
		deluser delgroup mount umount swapon swapoff mkswap fsck blkid findfs \
		mountpoint losetup switch_root pivot_root udhcpc ip ifconfig route \
		ping wget modprobe insmod rmmod lsmod depmod sysctl hwclock killall5 \
		start-stop-daemon syslogd klogd crond reboot halt poweroff setfont \
		loadkmap vi less
	do
		ln -sf busybox "$pkgdir/usr/bin/$a"
	done
}
