150477Speter# $FreeBSD$
238465Smsmith
3156813Sru.include <bsd.own.mk>
4188895SruMK_SSP=		no
5156813Sru
6199714SrnolandLOADER?=	loader
7199714SrnolandPROG=		${LOADER}.sym
8125621SruINTERNALPROG=
9212066SdelphijNEWVERSWHAT?=	"bootstrap loader" x86
1038465Smsmith
1139441Smsmith# architecture-specific loader code
12125537SruSRCS=		main.c conf.c vers.c
1339441Smsmith
14170101Ssimokawa# Put LOADER_FIREWIRE_SUPPORT=yes in /etc/make.conf for FireWire/dcons support
15170101Ssimokawa.if defined(LOADER_FIREWIRE_SUPPORT)
16170101SsimokawaCFLAGS+=	-DLOADER_FIREWIRE_SUPPORT
17170101SsimokawaLIBFIREWIRE=	${.OBJDIR}/../libfirewire/libfirewire.a
18170101Ssimokawa.endif
19170101Ssimokawa
20199714Srnoland# Set by zfsloader Makefile
21185029Spjd.if defined(LOADER_ZFS_SUPPORT)
22185029SpjdCFLAGS+=	-DLOADER_ZFS_SUPPORT
23237760SavgLIBZFSBOOT=	${.OBJDIR}/../../zfs/libzfsboot.a
24185029Spjd.endif
25185029Spjd
2659087Sps# Enable PXE TFTP or NFS support, not both.
2768310Sps.if defined(LOADER_TFTP_SUPPORT)
2868310SpsCFLAGS+=	-DLOADER_TFTP_SUPPORT
2968310Sps.else
3059087SpsCFLAGS+=	-DLOADER_NFS_SUPPORT
3168310Sps.endif
3259087Sps
33163893Smarcel# Include bcache code.
34163893SmarcelHAVE_BCACHE=	yes
35163893Smarcel
3639178Smsmith# Enable PnP and ISA-PnP code.
3740555SmsmithHAVE_PNP=	yes
3840555SmsmithHAVE_ISABUS=	yes
3939178Smsmith
40156813Sru.if ${MK_FORTH} != "no"
4140877Smsmith# Enable BootForth
4256903SjhbBOOT_FORTH=	yes
4356903SjhbCFLAGS+=	-DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/i386
4441107SjkhLIBFICL=	${.OBJDIR}/../../ficl/libficl.a
4541107Sjkh.endif
4640877Smsmith
47146874Sobrien.if defined(LOADER_BZIP2_SUPPORT)
4883616SsobomaxCFLAGS+=	-DLOADER_BZIP2_SUPPORT
4983616Ssobomax.endif
5083616Ssobomax.if !defined(LOADER_NO_GZIP_SUPPORT)
5183616SsobomaxCFLAGS+=	-DLOADER_GZIP_SUPPORT
5283616Ssobomax.endif
5383616Ssobomax
5438465Smsmith# Always add MI sources 
5538465Smsmith.PATH:		${.CURDIR}/../../common
56125516Sru.include	"${.CURDIR}/../../common/Makefile.inc"
5740338SpeterCFLAGS+=	-I${.CURDIR}/../../common
58125537SruCFLAGS+=	-I.
5938465Smsmith
60199714SrnolandCLEANFILES=	vers.c ${LOADER} ${LOADER}.bin loader.help
6138465Smsmith
6238465SmsmithCFLAGS+=	-Wall
63125621SruLDFLAGS=	-static -Ttext 0x0
6438465Smsmith
6538465Smsmith# i386 standalone support library
6638465SmsmithLIBI386=	${.OBJDIR}/../libi386/libi386.a
6738465SmsmithCFLAGS+=	-I${.CURDIR}/..
6838465Smsmith
6939441Smsmith# BTX components
7039646SpeterCFLAGS+=	-I${.CURDIR}/../btx/lib
7139441Smsmith
7239664Smsmith# Debug me!
7340884Smsmith#CFLAGS+=	-g
7440884Smsmith#LDFLAGS+=	-g
7539664Smsmith
76125537Sru# Pick up ../Makefile.inc early.
77125537Sru.include <bsd.init.mk>
78125537Sru
79199714Srnolandvers.c:	${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version
80199714Srnoland	sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version \
81199714Srnoland		${NEWVERSWHAT}
8238465Smsmith
83199714Srnoland${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
84102623Sjhb	btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
85199714Srnoland		-b ${BTXKERN} ${LOADER}.bin
8638465Smsmith
87199714Srnoland${LOADER}.bin: ${LOADER}.sym
8840555Smsmith	cp ${.ALLSRC} ${.TARGET}
8969985Srnordier	strip -R .comment -R .note ${.TARGET}
9040555Smsmith
91125537Sruloader.help: help.common help.i386
9242807Smsmith	cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET}
9341821Smsmith
94199714SrnolandFILES=	${LOADER}
95199714Srnoland# XXX INSTALLFLAGS_loader= -b
96199714SrnolandFILESMODE_${LOADER}= ${BINMODE} -b
97199714Srnoland
98199714Srnoland.if !defined(LOADER_ONLY)
9994956Sru.PATH: ${.CURDIR}/../../forth 
100199714SrnolandFILES+=	loader.help loader.4th support.4th loader.conf
101151874SscottlFILES+= screen.4th frames.4th beastie.4th
102222417SjulianFILES+= brand.4th check-password.4th color.4th delay.4th
103254146SdteskeFILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th
10494956SruFILESDIR_loader.conf=	/boot/defaults
10594956Sru
10645759Sdcs.if !exists(${DESTDIR}/boot/loader.rc)
107138186SruFILES+=	loader.rc
10845759Sdcs.endif
109222417Sjulian.if !exists(${DESTDIR}/boot/menu.rc)
110222417SjulianFILES+= menu.rc
111199714Srnoland.endif
112222417Sjulian.endif
11341821Smsmith
114126312Sru# XXX crt0.o needs to be first for pxeboot(8) to work
115126312SruOBJS=	${BTXCRT} 
11640555Smsmith
117237760SavgDPADD=	${LIBFICL} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
118237760SavgLDADD=	${LIBFICL} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
119126312Sru
120125621Sru.include <bsd.prog.mk>
12139441Smsmith
122211677Simp.if ${MACHINE_CPUARCH} == "amd64"
123125581Srubeforedepend ${OBJS}: machine
124125537SruCLEANFILES+=	machine
125243243SaeCFLAGS+=	-DLOADER_PREFER_AMD64
12640338Spetermachine:
12740338Speter	ln -sf ${.CURDIR}/../../../i386/include machine
12840555Smsmith.endif
129