# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Keshav Amburay <(the ddoott ridikulus ddoott rat) (aatt) (gemmaeiil) (ddoott) (ccoomm)>

pkgname=efivar
pkgdesc="Tools and libraries to work with EFI variables"
pkgver=37
pkgrel=4
arch=('x86_64')
url="https://github.com/rhboot/efivar"
license=('LGPL2.1')
makedepends=('git')
depends=('glibc')
provides=('libefiboot.so' 'libefivar.so')
source=("git+https://github.com/rhinstaller/efivar.git#tag=${pkgver}?signed")
sha512sums=('SKIP')
validpgpkeys=('B00B48BC731AA8840FED9FB0EED266B70F4FEF10') # Peter Jones <pjones@redhat.com>

prepare() {
  mv -v "${pkgname}" "${pkgname}-${pkgver}"
  cd "${pkgname}-${pkgver}"
  # -Werror, not even once
  sed -e 's/-Werror//g' -i gcc.specs
  # remove insecure rpath in efivar-tester
  sed 's|-rpath,$(TOPDIR)/src|-rpath,$(libdir)|g' -i src/test/Makefile
}

build() {
  cd "${pkgname}-${pkgver}"
  make libdir="/usr/lib/" \
       bindir="/usr/bin/" \
       mandir="/usr/share/man/" \
       includedir="/usr/include/"
  # build efivar-tester
  make libdir="/usr/lib/" \
       bindir="/usr/bin/" \
       mandir="/usr/share/man/" \
       includedir="/usr/include/" \
       -C src/test
}

package() {
  cd "${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}/" \
       libdir="/usr/lib/" \
       bindir="/usr/bin/" \
       mandir="/usr/share/man/" \
       includedir="/usr/include/" install -j1 V=1
  install -vDm 755 "src/test/tester" "${pkgdir}/usr/bin/efivar-tester"
  install -vDm 644 {README.md,TODO} -t "${pkgdir}/usr/share/doc/${pkgname}"
}
