# Maintainer: Martell Malone <martellmalone@gmail.com>

pkgname=busybox
pkgver=1.31.1
pkgrel=1
pkgdesc="BusyBox: The Swiss Army Knife of Embedded Linux"
arch=('i686' 'x86_64')
url="https://busybox.net/"
license=('GPL2')
install=busybox.install
source=("https://busybox.net/downloads/${pkgname}-${pkgver}.tar.bz2"
        "busybox-1.31.1-msys2.patch"
        "msys2_defconfig")
sha256sums=('d0f940a72f648943c1f2211e0e3117387c31d765137d92bd8284a3fb9752a998'
            '824e74f153ea1cb389d0cf35ab7df2e51fbe9ffbbd4dd718855ba0da6c1a8027'
            '3a08ea8d5f2dbdf4f9f47b80f5f4e64d55e0ea3346b9e27949cc3e882ad04606')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/busybox-1.31.1-msys2.patch

  cp ${srcdir}/msys2_defconfig ${srcdir}/${pkgname}-${pkgver}/.config
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  #make oldconfig
  #CFLAGS='-O2 -static-libgcc'
  #make cygwin_defconfig
  make
  mv -v busybox_unstripped.exe busybox.exe
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  #install busybox
  mkdir -p ${pkgdir}/usr/bin
  cp ${srcdir}/${pkgname}-${pkgver}/busybox.exe ${pkgdir}/usr/bin

  # license
  install -m644 -D LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}
