150477Speter# $FreeBSD$
240269Srnordier
3213136Spjd.PATH:		${.CURDIR}/../boot2 ${.CURDIR}/../common ${.CURDIR}/../../common
440326Srnordier
5172940SjhbFILES=		gptboot
6252492SwblockMAN=		gptboot.8
7172940Sjhb
880751SjhbNM?=		nm
980751Sjhb
1042480SrnordierBOOT_COMCONSOLE_PORT?= 0x3f8
1142480SrnordierBOOT_COMCONSOLE_SPEED?= 9600
1240541SrnordierB2SIOFMT?=	0x3
1340541Srnordier
14104673SgreenREL1=	0x700
1540269SrnordierORG1=	0x7c00
16172940SjhbORG2=	0x0
1740269Srnordier
18125537Sru# Decide level of UFS support.
19172940SjhbGPTBOOT_UFS?=	UFS1_AND_UFS2
20172940Sjhb#GPTBOOT_UFS?=	UFS2_ONLY
21172940Sjhb#GPTBOOT_UFS?=	UFS1_ONLY
22104635Sphk
23213136SpjdCFLAGS=	-DBOOTPROG=\"gptboot\" \
24225530Savg	-O1 \
25213136Spjd	-DGPT \
26172940Sjhb	-D${GPTBOOT_UFS} \
27125932Sru	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
28125932Sru	-DSIOFMT=${B2SIOFMT} \
29125932Sru	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
3097860Sphk	-I${.CURDIR}/../../common \
31213136Spjd	-I${.CURDIR}/../common \
32173026Sjhb	-I${.CURDIR}/../btx/lib -I. \
33172940Sjhb	-I${.CURDIR}/../boot2 \
34213568Spho	-I${.CURDIR}/../../.. \
3540269Srnordier	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
3640269Srnordier	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
37169732Skan	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
38260497Sdim	-Winline
3940269Srnordier
40260497SdimCFLAGS.gcc+=	--param max-inline-insns-single=100
41260497Sdim
42260291SdimLD_FLAGS=-static -N --gc-sections
4340269Srnordier
44271130SemasteLIBSTAND=	${.OBJDIR}/../../libstand32/libstand.a
45271130Semaste
46125537Sru# Pick up ../Makefile.inc early.
47125537Sru.include <bsd.init.mk>
4840269Srnordier
49172940SjhbCLEANFILES=	gptboot
50125537Sru
51172940Sjhbgptboot: gptldr.bin gptboot.bin ${BTXKERN}
52172940Sjhb	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l gptldr.bin \
53172940Sjhb	    -o ${.TARGET} gptboot.bin
54109886Sphk
55172940SjhbCLEANFILES+=	gptldr.bin gptldr.out gptldr.o
56125537Sru
57172940Sjhbgptldr.bin: gptldr.out
58172940Sjhb	objcopy -S -O binary gptldr.out ${.TARGET}
5940269Srnordier
60172940Sjhbgptldr.out: gptldr.o
61260291Sdim	${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} gptldr.o
6240269Srnordier
63219483SjhbCLEANFILES+=	gptboot.bin gptboot.out gptboot.o sio.o gpt.o crc32.o drv.o \
64219483Sjhb		cons.o util.o
6596424Speter
66172940Sjhbgptboot.bin: gptboot.out
67172940Sjhb	objcopy -S -O binary gptboot.out ${.TARGET}
6880751Sjhb
69213136Spjdgptboot.out: ${BTXCRT} gptboot.o sio.o gpt.o crc32.o drv.o cons.o util.o
70260291Sdim	${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSTAND}
7140269Srnordier
72172940Sjhbgptboot.o: ${.CURDIR}/../../common/ufsread.c
7380751Sjhb
74211677Simp.if ${MACHINE_CPUARCH} == "amd64"
75172940Sjhbbeforedepend gptboot.o: machine
76125556SruCLEANFILES+=	machine
77116864Spetermachine:
78116864Speter	ln -sf ${.CURDIR}/../../../i386/include machine
79116864Speter.endif
80116864Speter
81125537Sru.include <bsd.prog.mk>
82232263Sdim
83232263Sdim# XXX: clang integrated-as doesn't grok .codeNN directives yet
84232263SdimCFLAGS.gptldr.S=	${CLANG_NO_IAS}
85232263SdimCFLAGS+=		${CFLAGS.${.IMPSRC:T}}
86