1264391Snwhitehorn# $FreeBSD$
2264391Snwhitehorn
3264391SnwhitehornNO_MAN=
4264391Snwhitehorn
5264391Snwhitehorn.include <bsd.own.mk>
6264391Snwhitehorn
7264391Snwhitehorn# In-tree GCC does not support __attribute__((ms_abi)).
8264391Snwhitehorn.if ${COMPILER_TYPE} != "gcc"
9264391Snwhitehorn
10264391SnwhitehornMK_SSP=		no
11264391Snwhitehorn
12264391SnwhitehornPROG=		loader.sym
13264391SnwhitehornINTERNALPROG=
14264391Snwhitehorn
15264391Snwhitehorn# architecture-specific loader code
16264391SnwhitehornSRCS=	boot1.c reloc.c start.S
17264391Snwhitehorn
18264391SnwhitehornCFLAGS+=	-fPIC
19264391SnwhitehornCFLAGS+=	-I.
20264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../efi/include
21264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
22264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../../contrib/dev/acpica/include
23264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../..
24264391Snwhitehorn
25271136Semaste# Always add MI sources and REGULAR efi loader bits
26271136Semaste.PATH:		${.CURDIR}/../efi ${.CURDIR}/../../common
27264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../common
28264391Snwhitehorn
29271136SemasteFILES=	boot1.efi boot1.efifat
30264391SnwhitehornFILESMODE_boot1.efi=	${BINMODE}
31264391Snwhitehorn
32264391SnwhitehornLDSCRIPT=	${.CURDIR}/../efi/ldscript.${MACHINE_CPUARCH}
33264391SnwhitehornLDFLAGS=	-Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared -Wl,-znocombreloc
34264391Snwhitehorn
35264391Snwhitehorn${PROG}:	${LDSCRIPT}
36264391Snwhitehorn
37264391SnwhitehornOBJCOPY?=	objcopy
38264391SnwhitehornOBJDUMP?=	objdump
39264391Snwhitehorn
40264391Snwhitehorn.if ${MACHINE_CPUARCH} == "amd64"
41264391SnwhitehornEFI_TARGET=	efi-app-x86_64
42264391Snwhitehorn.else
43264391SnwhitehornEFI_TARGET=	efi-app-ia32
44264391Snwhitehorn.endif
45264391Snwhitehorn
46264391Snwhitehornboot1.efi: loader.sym
47264391Snwhitehorn	if [ `${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*' | wc -l` != 0 ]; then \
48264391Snwhitehorn		${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*'; \
49264391Snwhitehorn		exit 1; \
50264391Snwhitehorn	fi
51264391Snwhitehorn	${OBJCOPY} -j .text -j .sdata -j .data \
52264391Snwhitehorn		-j .dynamic -j .dynsym -j .rel.dyn \
53264391Snwhitehorn		-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
54264391Snwhitehorn		--target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
55264391Snwhitehorn
56264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../common
57264391Snwhitehorn
58271136Semasteboot1.o: ${.CURDIR}/../../common/ufsread.c
59271136Semaste
60271136Semaste# The following inserts out objects into a template FAT file system
61271136Semaste# created by generate-fat.sh
62271136Semaste
63271136Semaste.include "${.CURDIR}/Makefile.fat"
64271136Semaste
65271136Semasteboot1.efifat: boot1.efi
66271136Semaste	echo ${.OBJDIR}
67271136Semaste	uudecode ${.CURDIR}/fat.tmpl.bz2.uu
68271136Semaste	mv fat.tmpl.bz2 ${.TARGET}.bz2
69271136Semaste	bzip2 -f -d ${.TARGET}.bz2
70271136Semaste	dd if=boot1.efi of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
71271136Semaste
72271136SemasteCLEANFILES= boot1.efifat
73271136Semaste
74264391Snwhitehorn.endif # ${COMPILER_TYPE} != "gcc"
75264391Snwhitehorn
76264391Snwhitehorn.include <bsd.prog.mk>
77264391Snwhitehorn
78264391Snwhitehornbeforedepend ${OBJS}: machine x86
79264391Snwhitehorn
80271136SemasteCLEANFILES+=   machine x86 boot1.efi
81264391Snwhitehorn
82264391Snwhitehornmachine:
83264391Snwhitehorn	ln -sf ${.CURDIR}/../../../amd64/include machine
84264391Snwhitehorn
85264391Snwhitehornx86:
86264391Snwhitehorn	ln -sf ${.CURDIR}/../../../x86/include x86
87