# Template file for 'gnu-efi-libs'
pkgname=gnu-efi-libs
reverts="3.0w_1" # Not an actual revert, xbps considers 3.0w higher than 3.0.8
version=3.0.18
revision=1
makedepends="pciutils-devel"
short_desc="Library for building UEFI Applications using GNU toolchain"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-or-later"
homepage="https://sourceforge.net/projects/gnu-efi/"
distfiles="${SOURCEFORGE_SITE}/gnu-efi/gnu-efi-${version}.tar.bz2"
checksum=7f212c96ee66547eeefb531267b641e5473d7d8529f0bd8ccdefd33cf7413f5c
nostrip=yes

# If we are cross-building we need to pass the cross-compilation triplet
# to the CROSS_COMPILE environment variable so the build system uses
# the cross tooling
if [ "$CROSS_BUILD" ]; then
	export CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-
fi

# Filter out arches for the host machine
# the makefile only accept specific names like ia32 for i686
# and arm for all armv*, we also get to remove the musl specifiers
case "$XBPS_MACHINE" in
	x86_64*) HOST_ARCH=x86_64 ;;
	i686*) HOST_ARCH=ia32 ;;
	arm*) HOST_ARCH=arm ;;
	aarch64*) HOST_ARCH=aarch64 ;;
	riscv64*) HOST_ARCH=riscv64 ;;
esac

# Filter our arches for the target machines
# the same rules as above apply, we also get a chance to declare
# broken= here for unsupported configurations
case "$XBPS_TARGET_MACHINE" in
	x86_64*) TARGET_ARCH=x86_64 ;;
	i686*) TARGET_ARCH=ia32 ;;
	arm*) TARGET_ARCH=arm ;;
	aarch64*) TARGET_ARCH=aarch64 ;;
	riscv64*) TARGET_ARCH=riscv64 ;;
	*) broken="${XBPS_TARGET_MACHINE} is untested, please add support if possible" ;;
esac

do_build() {
	# upstream provides LDFLAGS directly to ld: https://sourceforge.net/p/gnu-efi/bugs/33/
	LDFLAGS="${LDFLAGS//-Wl/}"
	LDFLAGS="${LDFLAGS//,/ }"
	make ARCH=${TARGET_ARCH} HOSTARCH=${HOST_ARCH}
}

do_install() {
	make ARCH=${TARGET_ARCH} INSTALLROOT=${DESTDIR} PREFIX=/usr LIBDIR=/usr/lib install
}
