# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=gnu-efi
pkgver=4.0.4
pkgrel=1
pkgdesc="Develop EFI applications using the GNU toolchain and the EFI development environment"
arch=(x86_64 aarch64)
url="https://github.com/ncroxon/gnu-efi"
license=(
  BSD-2-Clause
  BSD-2-Clause-Patent
  BSD-3-Clause
  'BSD-2-Clause OR GPL-2.0-or-later'
  GPL-3.0-or-later
  LGPL-3.0-or-later
)
conflicts=(gnu-efi-libs)
provides=(gnu-efi-libs)
replaces=(gnu-efi-libs)
source=($pkgname-$pkgver.tar.gz::$url/archive/refs/tags/$pkgver.tar.gz)
options=(!lto !strip)
sha512sums=('4ed273ef8203f1b2fd90855821576523b070236911a26199eec220f1bad34f63759a32b06f11a681e532a2c793339d9e66bcb90e5cde5de02d8842a40c471a06')
b2sums=('a636ec81a830206b4d793689b6b4b85ab88b9061224691d47076b096e4502f4625fdc759c351d3e8b0a93fc26c33dd4862c2383d7620bb1704649c275da322f7')

prepare() {
  # -Werror, not even once
  sed -e 's/-Werror//g' -i $pkgname-$pkgver/Make.defaults
}

build() {
  cd $pkgname-$pkgver
  # NOTE: apply only minimal CFLAGS, as gnu-efi does not provide userspace
  # libs, but may be used in unitialized machine state and should therefore not
  # be architecture optmized
  CFLAGS="-O2"
  # upstream provides LDFLAGS directly to ld: https://sourceforge.net/p/gnu-efi/bugs/33/
  LDFLAGS="${LDFLAGS//-Wl/}"
  LDFLAGS="${LDFLAGS//,/ }"
  make PREFIX=/usr
}

package() {
  cd $pkgname-$pkgver
  make INSTALLROOT="$pkgdir" PREFIX=/usr install
  install -vDm 644 licenses/* -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {README,SECURITY}.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
