# Maintainer: Yonggang Luo <luoyonggang@gmail.com>

pkgname=('gnu-efi' 'gnu-efi-devel')
pkgver=4.0.4
pkgrel=1
pkgdesc="Building EFI Applications Using the GNU Toolchain"
arch=('i686' 'x86_64')
url="https://github.com/ncroxon/gnu-efi"
license=('BSD')
depends=()
makedepends=('gcc' 'make')

_patches=(
  '0001-Support-building-under-cygwin.patch'
)

source=(
  "gnu-efi-${pkgver}.tar.gz"::"https://github.com/ncroxon/gnu-efi/archive/refs/tags/${pkgver}.tar.gz"
  ${_patches[@]}
)

sha256sums=('40b61e842a4efcbf80f3e53b2f220c044e8cfe46eb4dd6396c83b751240b1c0d'
            '2fb86ca36149da9fe6d1c94ae0a6b311e122f5cc051c9b8b076f75e8abdd0f2a')

prepare() {
  cd "${srcdir}/gnu-efi-${pkgver}"
  for patch in ${_patches[@]}; do
    msg2 "Patching with ${patch}"
    patch -p1 < "${srcdir}/${patch}"
  done
}

build() {
  cd "${srcdir}/gnu-efi-${pkgver}"
  make
}

package_gnu-efi() {
  cd "${srcdir}/gnu-efi-${pkgver}"
  make DESTDIR="${pkgdir}" PREFIX=/usr install
  # Remove devel files
  rm -rf "${pkgdir}/usr/include"
  rm -rf "${pkgdir}/usr/lib"
}

package_gnu-efi-devel() {
  pkgdesc="GNU EFI development headers and libraries"
  cd "${srcdir}/gnu-efi-${pkgver}"
  make DESTDIR="${pkgdir}" PREFIX=/usr install
  # Remove non-devel files
  rm -rf "${pkgdir}/usr/bin"
  rm -rf "${pkgdir}/usr/share"
}
