Makefile revision 281300
1264391Snwhitehorn# $FreeBSD: head/sys/boot/efi/boot1/Makefile 281300 2015-04-09 10:08:10Z andrew $
2264391Snwhitehorn
3264925SimpMAN=
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+=	-I.
19280950SandrewCFLAGS+=	-I${.CURDIR}/../include
20280950SandrewCFLAGS+=	-I${.CURDIR}/../include/${MACHINE_CPUARCH}
21264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../../contrib/dev/acpica/include
22264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../..
23264391Snwhitehorn
24264403Snwhitehorn# Always add MI sources and REGULAR efi loader bits
25281237Semaste.PATH:		${.CURDIR}/../loader/arch/${MACHINE_CPUARCH}
26281237Semaste.PATH:		${.CURDIR}/../loader
27281237Semaste.PATH:		${.CURDIR}/../../common
28264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../common
29264391Snwhitehorn
30264975SnwhitehornFILES=	boot1.efi boot1.efifat
31264391SnwhitehornFILESMODE_boot1.efi=	${BINMODE}
32264391Snwhitehorn
33280950SandrewLDSCRIPT=	${.CURDIR}/../loader/arch/${MACHINE_CPUARCH}/ldscript.${MACHINE_CPUARCH}
34281027SandrewLDFLAGS=	-Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared
35264391Snwhitehorn
36281027Sandrew.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
37281300SandrewCFLAGS+=	-fPIC
38281027SandrewLDFLAGS+=	-Wl,-znocombreloc
39281027Sandrew.endif
40281027Sandrew
41281238Semaste.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "i386"
42281156Sandrew#
43281238Semaste# Add libstand for the runtime functions used by the compiler - for example
44281238Semaste# __aeabi_* (arm) or __divdi3 (i386).
45281156Sandrew#
46281156SandrewDPADD+=		${LIBSTAND}
47281156SandrewLDADD+=		-lstand
48281156Sandrew.endif
49281156Sandrew
50264391Snwhitehorn${PROG}:	${LDSCRIPT}
51264391Snwhitehorn
52264391SnwhitehornOBJCOPY?=	objcopy
53264391SnwhitehornOBJDUMP?=	objdump
54264391Snwhitehorn
55264391Snwhitehorn.if ${MACHINE_CPUARCH} == "amd64"
56264391SnwhitehornEFI_TARGET=	efi-app-x86_64
57280950Sandrew.elif ${MACHINE_CPUARCH} == "i386"
58264391SnwhitehornEFI_TARGET=	efi-app-ia32
59281156Sandrew.else
60281156SandrewEFI_TARGET=	binary
61264391Snwhitehorn.endif
62264391Snwhitehorn
63264391Snwhitehornboot1.efi: loader.sym
64264391Snwhitehorn	if [ `${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*' | wc -l` != 0 ]; then \
65264391Snwhitehorn		${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*'; \
66264391Snwhitehorn		exit 1; \
67264391Snwhitehorn	fi
68281156Sandrew	${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \
69264391Snwhitehorn		-j .dynamic -j .dynsym -j .rel.dyn \
70264391Snwhitehorn		-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
71276146Semaste		--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
72264391Snwhitehorn
73264414Snwhitehornboot1.o: ${.CURDIR}/../../common/ufsread.c
74264414Snwhitehorn
75264975Snwhitehorn# The following inserts out objects into a template FAT file system
76264975Snwhitehorn# created by generate-fat.sh
77264975Snwhitehorn
78264975Snwhitehorn.include "${.CURDIR}/Makefile.fat"
79264975Snwhitehorn
80264975Snwhitehornboot1.efifat: boot1.efi
81264975Snwhitehorn	echo ${.OBJDIR}
82281156Sandrew	uudecode ${.CURDIR}/fat-${MACHINE_CPUARCH}.tmpl.bz2.uu
83281156Sandrew	mv fat-${MACHINE_CPUARCH}.tmpl.bz2 ${.TARGET}.bz2
84264975Snwhitehorn	bzip2 -f -d ${.TARGET}.bz2
85264975Snwhitehorn	dd if=boot1.efi of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
86264975Snwhitehorn
87281117SandrewCLEANFILES= boot1.efi boot1.efifat
88264975Snwhitehorn
89264391Snwhitehorn.endif # ${COMPILER_TYPE} != "gcc"
90264391Snwhitehorn
91264391Snwhitehorn.include <bsd.prog.mk>
92264391Snwhitehorn
93281027Sandrew.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
94264391Snwhitehornbeforedepend ${OBJS}: machine x86
95264391Snwhitehorn
96281117SandrewCLEANFILES+=   machine x86
97264391Snwhitehorn
98264391Snwhitehornmachine:
99264391Snwhitehorn	ln -sf ${.CURDIR}/../../../amd64/include machine
100264391Snwhitehorn
101264391Snwhitehornx86:
102264391Snwhitehorn	ln -sf ${.CURDIR}/../../../x86/include x86
103281027Sandrew.endif
104