# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Camille Moncelier <pix@devlife.org>, simo <simo@archlinux.org>

pkgname=kexec-tools
pkgver=2.0.29
pkgrel=2
pkgdesc="Load another kernel from the currently executing Linux kernel"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://kernel.org/pub/linux/utils/kernel/kexec/"
source=("git+https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git?signed#tag=v${pkgver}"
        hotfix-error_msg.patch
        hotfix-ppc32-kexec-file-syscall.patch
        hotfix-ppc32.patch
        hotfix-ppc64-elfv2.patch
        hotfix-ppc64-mem-ranges.patch
        add-riscv64-support.patch
        riscv-hotplug.patch)
makedepends=('git')
validpgpkeys=('E27CD9A1F5ACC2FF4BFE7285D7CF64696A374FBE') # Simon Horman <horms@debian.org>
depends=('zlib' 'xz')
license=('GPL-2.0-or-later')
b2sums=('e49b21dadc06cd91ec71a7c48e6a731a29560dde91f53cea615ffcfc747f443b5db3bfc2fe56050a2a604e4eb5b4f50788b8887e73d2f5c7e8c485a14c467580'
        'ed06ef6e38249105e2f6a6751edbd3975aada1563a89a55a6aa1eb0c29cccd629532f28d90726f6ed90ef3662afaf1f169ce405f01f35b313880eebf239bfdcc'
        '79d6e7e1ed8e77fd0f551daa9d01cf78e264cd36eb853e2a85821491eede1e27642f8b14927021d0c86dc38887d66d7198bc2fb15a367a313db158021d44ada1'
        'b3f4c16a04b22e909e5d68ee4e7c698f659cc44ebf4961a4c377de0f6bd0f9163352466226143068a9fff4cf07f990df393dac669bdc72f67f5602862c0294da'
        '5eabd0ed708b2c67aa4df52fd40db57edf165b88ce51b8cc753ee90763e96ae6460294f94432c3218e89f9a2ec3f1b2c5888adc2b830445329fe223b43468795'
        '91817d8c8d446186bbbf45d4117307eb134a8a3e35bd78f90e2c031b1a5769f0e8ece18a9b7b506ee0d60bf6cf9602d180ff34db0830773ccf20bb4c048284cf'
        '60f71a3da5945af3099f0359f695c7e8cb6875b10b223df32bd729d25baa7474914c9aa49c37fbc2af173ce9804696b17d3681060cba599e150b42c9daa32bbd'
        '05600e0964fa35df04f5f25aee15745bce91f5b1ad9320880bc48bf56563e512b21ceb069bc3898069602b4629cbba89e3688887fb9d39c1438c031654c8016a')

prepare() {
  cd "${pkgname}"

  patch -Np1 -i ${srcdir}/hotfix-error_msg.patch
  patch -Np1 -i ${srcdir}/hotfix-ppc32-kexec-file-syscall.patch
  patch -Np1 -i ${srcdir}/hotfix-ppc32.patch
  patch -Np1 -i ${srcdir}/hotfix-ppc64-elfv2.patch
  patch -Np1 -i ${srcdir}/hotfix-ppc64-mem-ranges.patch

  patch -Np1 -i ${srcdir}/add-riscv64-support.patch
  patch -Np1 -i ${srcdir}/riscv-hotplug.patch

  ./bootstrap
}

build() {
  cd "${pkgname}"
  ./configure --prefix=/usr --sbindir=/usr/bin --without-lzma
  make
}

package() {
  cd "${pkgname}"
  make DESTDIR="${pkgdir}" install
  install -D -m644 kexec/kexec.8 "$pkgdir"/usr/share/man/man8/kexec.8
}

