# Template file for 'syslinux'
pkgname=syslinux
version=6.03
revision=3
hostmakedepends="perl python nasm"
makedepends="gnu-efi-libs libuuid-devel"
short_desc="A boot loader for the Linux operating system"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="http://syslinux.zytor.com/wiki/index.php/The_Syslinux_Project"
license="GPL-2"
distfiles="${KERNEL_SITE}/utils/boot/$pkgname/$pkgname-$version.tar.xz"
checksum=26d3986d2bea109d5dc0e4f8c4822a459276cf021125e8c9f23c3cca5d8c850e
only_for_archs="i686 i686-musl x86_64 x86_64-musl"

pre_build() {
	# Do not try to build the Windows or DOS installers and DIAG files
	sed 's|diag libinstaller dos win32 win64 dosutil txt|libinstaller txt|g' -i Makefile
	sed 's|win32/syslinux.exe win64/syslinux64.exe||g' -i Makefile
	sed 's|dosutil/*.com dosutil/*.sys||g' -i Makefile
	sed 's|dos/syslinux.com||g' -i Makefile
	sed 's|INSTALLSUBDIRS = com32 utils dosutil|INSTALLSUBDIRS = com32 utils|g' -i Makefile
	sed 's|install -m 644 -c $(INSTALL_DIAG) $(INSTALLROOT)$(DIAGDIR)|# install -m 644 -c $(INSTALL_DIAG) $(INSTALLROOT)$(DIAGDIR)|g' -i Makefile
	# Fix FHS manpage path
	sed 's|/usr/man|/usr/share/man|g' -i mk/syslinux.mk
}
do_build() {
	unset CFLAGS LDFLAGS
	case "$XBPS_TARGET_MACHINE" in
		i686*) sed -e 's,^firmware =.*,firmware = bios efi32,g' -i Makefile;;
		x86_64*) sed -e 's,^firmware =.*,firmware = bios efi64,g' -i Makefile;;
	esac
	make installer
}
do_install() {
	make INSTALLROOT=${DESTDIR} install
	mv ${DESTDIR}/sbin/* ${DESTDIR}/usr/bin
	# Remove completely development stuff.
	rm -r ${DESTDIR}/usr/share/syslinux/com32/include
	rm ${DESTDIR}/usr/share/syslinux/com32/*.a
	# Remove keytab-lilo to prevent conflict with LILO
	rm ${DESTDIR}/usr/bin/keytab-lilo
}
