# 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=3
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
make_build_args="PREFIX=/usr LIBDIR=/usr/lib"
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*) make_build_args+=" HOSTARCH=x86_64" ;;
	i686*) make_build_args+=" HOSTARCH=ia32" ;;
	arm*) make_build_args+=" HOSTARCH=arm" ;;
	aarch64*) make_build_args+=" HOSTARCH=aarch64" ;;
	riscv64*) make_build_args+=" HOSTARCH=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*) make_build_args+=" ARCH=x86_64" ;;
	i686*) make_build_args+=" ARCH=ia32" ;;
	arm*) make_build_args+=" ARCH=arm" ;;
	aarch64*) make_build_args+=" ARCH=aarch64" ;;
	riscv64*) make_build_args+=" 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 ${make_build_args}
}

do_install() {
	make ${make_build_args} INSTALLROOT=${DESTDIR} install
}
