# Template file for 'syslinux'
pkgname=syslinux
version=6.02
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@gmail.com>"
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=afa31b7cbf72e1c0c1752a0636ba724ce01c0e374366e46e61db6862b4685478
only_for_archs="i686 x86_64"

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
}
