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
23235156SavgLIBZFSBOOT=	${.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
44271135Semaste.if ${MACHINE_CPUARCH} == "amd64"
45271135SemasteLIBFICL=	${.OBJDIR}/../../ficl32/libficl.a
46271135Semaste.else
4741107SjkhLIBFICL=	${.OBJDIR}/../../ficl/libficl.a
4841107Sjkh.endif
49271135Semaste.endif
5040877Smsmith
51146874Sobrien.if defined(LOADER_BZIP2_SUPPORT)
5283616SsobomaxCFLAGS+=	-DLOADER_BZIP2_SUPPORT
5383616Ssobomax.endif
5483616Ssobomax.if !defined(LOADER_NO_GZIP_SUPPORT)
5583616SsobomaxCFLAGS+=	-DLOADER_GZIP_SUPPORT
5683616Ssobomax.endif
57235537Sgber.if defined(LOADER_NANDFS_SUPPORT)
58235537SgberCFLAGS+=	-DLOADER_NANDFS_SUPPORT
59235537Sgber.endif
6083616Ssobomax
61227726Smiwi# Always add MI sources
6238465Smsmith.PATH:		${.CURDIR}/../../common
63125516Sru.include	"${.CURDIR}/../../common/Makefile.inc"
6440338SpeterCFLAGS+=	-I${.CURDIR}/../../common
65125537SruCFLAGS+=	-I.
6638465Smsmith
67199714SrnolandCLEANFILES=	vers.c ${LOADER} ${LOADER}.bin loader.help
6838465Smsmith
6938465SmsmithCFLAGS+=	-Wall
70125621SruLDFLAGS=	-static -Ttext 0x0
7138465Smsmith
7238465Smsmith# i386 standalone support library
7338465SmsmithLIBI386=	${.OBJDIR}/../libi386/libi386.a
7438465SmsmithCFLAGS+=	-I${.CURDIR}/..
7538465Smsmith
76271130SemasteLIBSTAND=	${.OBJDIR}/../../libstand32/libstand.a
77271130Semaste
7839441Smsmith# BTX components
7939646SpeterCFLAGS+=	-I${.CURDIR}/../btx/lib
8039441Smsmith
8139664Smsmith# Debug me!
8240884Smsmith#CFLAGS+=	-g
8340884Smsmith#LDFLAGS+=	-g
8439664Smsmith
85125537Sru# Pick up ../Makefile.inc early.
86125537Sru.include <bsd.init.mk>
87125537Sru
88199714Srnolandvers.c:	${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version
89199714Srnoland	sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version \
90199714Srnoland		${NEWVERSWHAT}
9138465Smsmith
92199714Srnoland${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
93102623Sjhb	btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
94199714Srnoland		-b ${BTXKERN} ${LOADER}.bin
9538465Smsmith
96199714Srnoland${LOADER}.bin: ${LOADER}.sym
9740555Smsmith	cp ${.ALLSRC} ${.TARGET}
9869985Srnordier	strip -R .comment -R .note ${.TARGET}
9940555Smsmith
100125537Sruloader.help: help.common help.i386
10142807Smsmith	cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET}
10241821Smsmith
103199714SrnolandFILES=	${LOADER}
104199714Srnoland# XXX INSTALLFLAGS_loader= -b
105199714SrnolandFILESMODE_${LOADER}= ${BINMODE} -b
106199714Srnoland
107199714Srnoland.if !defined(LOADER_ONLY)
108227726Smiwi.PATH: ${.CURDIR}/../../forth
109199714SrnolandFILES+=	loader.help loader.4th support.4th loader.conf
110151874SscottlFILES+= screen.4th frames.4th beastie.4th
111222417SjulianFILES+= brand.4th check-password.4th color.4th delay.4th
112242688SdteskeFILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th
11394956SruFILESDIR_loader.conf=	/boot/defaults
11494956Sru
11545759Sdcs.if !exists(${DESTDIR}/boot/loader.rc)
116138186SruFILES+=	loader.rc
11745759Sdcs.endif
118222417Sjulian.if !exists(${DESTDIR}/boot/menu.rc)
119222417SjulianFILES+= menu.rc
120199714Srnoland.endif
121222417Sjulian.endif
12241821Smsmith
123126312Sru# XXX crt0.o needs to be first for pxeboot(8) to work
124227726SmiwiOBJS=	${BTXCRT}
12540555Smsmith
126235156SavgDPADD=	${LIBFICL} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
127235156SavgLDADD=	${LIBFICL} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND}
128126312Sru
129125621Sru.include <bsd.prog.mk>
13039441Smsmith
131211677Simp.if ${MACHINE_CPUARCH} == "amd64"
132125581Srubeforedepend ${OBJS}: machine
133125537SruCLEANFILES+=	machine
134241068SaeCFLAGS+=	-DLOADER_PREFER_AMD64
13540338Spetermachine:
13640338Speter	ln -sf ${.CURDIR}/../../../i386/include machine
13740555Smsmith.endif
138