# Maintainer: Bin Meng <bmeng.cn@gmail.com>

pkgname=u-boot-tools
pkgver=2025.07
pkgrel=3
pkgdesc="U-Boot Tools"
arch=('i686' 'x86_64')
url="https://github.com/u-boot/u-boot"
msys2_references=(
  "anitya: 5022"
  "cpe: cpe:/a:denx:u-boot"
  "archlinux: uboot-tools"
)
license=('GPL2')
depends=('dtc' 'openssl')
makedepends=('make' 'gcc' 'openssl-devel' 'libgnutls-devel' 'libuuid-devel')
source=(https://ftp.denx.de/pub/u-boot/u-boot-${pkgver}.tar.bz2{,.sig})
noextract=("u-boot-${pkgver}.tar.bz2")
sha256sums=('0f933f6c5a426895bf306e93e6ac53c60870e4b54cda56d95211bec99e63bec7'
            'SKIP')
validpgpkeys=('1A3C7F70E08FAB1707809BBF147C39FF9634B72C') # Thomas Rini <trini@konsulko.com>

prepare() {
  # workaround an issue of bsdtar for extracting symbolic links in the tarball
  bsdtar -xzf ${srcdir}/u-boot-${pkgver}.tar.bz2 -C $srcdir || true
  bsdtar -xzf ${srcdir}/u-boot-${pkgver}.tar.bz2 -C $srcdir || true
}

build() {
  cd ${srcdir}/u-boot-${pkgver}
  make tools-only_defconfig tools-only NO_SDL=1
}

package() {
  mkdir -p ${pkgdir}/usr/bin
  cd ${srcdir}/u-boot-${pkgver}
  cp -f tools/dumpimage.exe ${pkgdir}/usr/bin/
  cp -f tools/fdt_add_pubkey.exe ${pkgdir}/usr/bin/
  cp -f tools/fdtgrep.exe ${pkgdir}/usr/bin/
  cp -f tools/fit_info.exe ${pkgdir}/usr/bin/
  cp -f tools/fit_check_sign.exe ${pkgdir}/usr/bin/
  cp -f tools/ifwitool.exe ${pkgdir}/usr/bin/
  cp -f tools/mkeficapsule.exe ${pkgdir}/usr/bin/
  cp -f tools/mkimage.exe ${pkgdir}/usr/bin/
  cp -f tools/mkenvimage.exe ${pkgdir}/usr/bin/
  cp -f tools/proftool.exe ${pkgdir}/usr/bin/
}
