description="Combines tiny versions of many common UNIX utilities."
url="https://busybox.net/about.html"

packager="tnut <tnut@nutyx.org>"

makedepends=(git musl)

name=busybox
version=1.34.1
release=2

source=(busybox-1.33.0_modprobe.patch
        $name.config
	https://busybox.net/downloads/busybox-$version.tar.bz2)

prepare() {
git clone https://github.com/slashbeast/mdev-like-a-boss.git
sed -i "s@/opt/mdev@/etc/mdev.d@g" mdev-like-a-boss/mdev.conf
sed -i "s@uucp@dialout@g" mdev-like-a-boss/mdev.conf
cd $name-$version
# Anti-future-proofing patch: when kernel will learn how to finit_module(fd)
# a gzipped module in addition to uncompressed ones, this patch needs to be
# removed
patch -Np1 -i ../busybox-1.33.0_modprobe.patch
}
build() {
cd $name-$version
cp ../$name.config .config
make CC=musl-gcc

# mdev
mkdir -p $PKG/{etc/mdev.d,bin,sbin}
cd ..
install -m0755  mdev-like-a-boss/mdev.conf $PKG/etc/mdev.conf
cp -a mdev-like-a-boss/helpers $PKG/etc/mdev.d
}
package() {
install -m0755 $name-$version/$name $PKG/sbin/$name
for link in $($PKG/sbin/$name --list)
do
  found=no
  for i in $name bash sh ifup ifdown init halt reboot \
  shutdown poweroff chpst runit runsv sv runsvdir svlogd
  do
   [ "$link" == "$i" ] && found=yes
  done
  [ "$found" == "yes" ] && continue
  if [ "$link" == "ash" ]; then
    ln -s ../sbin/$name $PKG/bin/$link
  else
    ln -s ../sbin/$name $PKG/sbin/$link
  fi
done

}
