#	$NetBSD: Makefile,v 1.1 2007/01/01 22:11:09 dsl Exp $

S=		${.CURDIR}/../../../../

PROG=		fatboot
NOMAN=		# defined

LIBCRT0=	# nothing
LIBCRTBEGIN=	# nothing
LIBCRTEND=	# nothing
LIBC=		# nothing

.include <bsd.own.mk>

STRIPFLAG=	# override

SRCS=		fatboot.S

BINDIR=		/usr/mdec
BINMODE=	444

.PATH:		${.CURDIR}/..

LDFLAGS+=	-nostdlib -Wl,-e,start
CPPFLAGS+=	-I. -I${.CURDIR}/../lib -I${S}

.if ${MACHINE} == "amd64"
LDFLAGS+=	-Wl,-m,elf_i386
AFLAGS+=	-m32
.endif

BUILDSYMLINKS+=	$S/arch/i386/include	machine \
		$S/arch/x86/include	x86

DPSRCS+=	machine x86

CLEANFILES+=	${PROG}.tmp

${PROG}: ${OBJS}
	${_MKTARGET_LINK}
	${CC} -o ${PROG}.tmp ${LDFLAGS} -Wl,-Ttext,0x7c00 ${OBJS}
	@ set -- $$( ${NM} -t d ${PROG}.tmp | grep '\<pbr_space\>' \
		    | sed 's/^0*//'  ); \
		echo "#### There are $$1 free bytes in ${PROG}"
	${OBJCOPY} -O binary ${PROG}.tmp ${PROG}
	rm -f ${PROG}.tmp

.include <bsd.prog.mk>
