pkgname=busybox
pkgver=1.38.0
pkgrel=1
pkgdesc="tiny swiss army knife for linux (owencore base)"
url="https://www.busybox.net/"
arch=x86_64
license=GPL-2.0
source="https://busybox.net/downloads/busybox-${pkgver}.tar.bz2"
makedepends=

build_dir=busybox-${pkgver}

build()
{
  make defconfig
  # defconfig picks applets that break on newer glibc headers (tc.c struct
  # drift); drop them here, not in bldpkg. defconfig ignores CONFIG_* on the
  # make command line, so CONFIG_STATIC is flipped in the file below too.
  for f in TC TCPSVD SSD; do
    sed -i "s|^CONFIG_$f=y|# CONFIG_$f is not set|" .config
  done
  sed -i "s|^# CONFIG_STATIC is not set|CONFIG_STATIC=y|" .config
  make oldconfig >/dev/null 2>&1
  # compiles stay in tcc; lib.a handling and the busybox link run in gcc
  # (see build/cc); that bridge carries libtcc1.a at link itself.
  mkgcc=${CC:-gcc}
  case "$mkgcc" in *tcc*) mkgcc=$TCC_BRIDGE;; esac
  if [ "$mkgcc" = "$TCC_BRIDGE" ]; then
    sed -i '/struct BUG {/,/^};/d' archival/unzip.c
    sed -i 's|BUILD_BUG_ON(sizeof(header) != 8);|;|' archival/libarchive/decompress_gunzip.c
    sed -i '/char ERR_svstatus_must_be_20_bytes/d;/^struct ERR_svstatus_must_be_20_bytes {$/,/^};/d' runit/runit_lib.h
    sed -i '/char bug\[/d;/char BUG[1-9]\[/d;/char BUG_off_t/d;/char c\[/d;/char ERR_width_bytes_has_bad_size/d' util-linux/mkfs_vfat.c include/bb_e2fs_defs.h archival/rpm.h include/bb_archive.h include/libbb.h networking/udhcp/common.h coreutils/od_bloaty.c
    # tcc folds no dead branches; calls it keeps, gcc prunes its static
    # callee, so these units go through the gcc path instead (see build/cc).
    TCCGCC_SKIP="networking/nameif.c util-linux/fdisk.c shell/ash.c shell/hush.c"
    export TCCGCC_SKIP
  fi
  make -j1 CONFIG_STATIC=y CC="$mkgcc"
}

package()
{
  make CONFIG_PREFIX="$pkgdir" install
}
