Makefile revision 293425
1264391Snwhitehorn# $FreeBSD: head/sys/boot/efi/boot1/Makefile 293425 2016-01-08 16:37:22Z emaste $
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
12287930SjhbPROG=		boot1.sym
13264391SnwhitehornINTERNALPROG=
14264391Snwhitehorn
15264391Snwhitehorn# architecture-specific loader code
16282727SianSRCS=	boot1.c self_reloc.c start.S
17264391Snwhitehorn
18264391SnwhitehornCFLAGS+=	-I.
19280950SandrewCFLAGS+=	-I${.CURDIR}/../include
20281524SandrewCFLAGS+=	-I${.CURDIR}/../include/${MACHINE}
21264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../../contrib/dev/acpica/include
22264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../..
23264391Snwhitehorn
24264403Snwhitehorn# Always add MI sources and REGULAR efi loader bits
25281524Sandrew.PATH:		${.CURDIR}/../loader/arch/${MACHINE}
26281237Semaste.PATH:		${.CURDIR}/../loader
27281237Semaste.PATH:		${.CURDIR}/../../common
28264391SnwhitehornCFLAGS+=	-I${.CURDIR}/../../common
29264391Snwhitehorn
30264975SnwhitehornFILES=	boot1.efi boot1.efifat
31264391SnwhitehornFILESMODE_boot1.efi=	${BINMODE}
32264391Snwhitehorn
33281524SandrewLDSCRIPT=	${.CURDIR}/../loader/arch/${MACHINE}/ldscript.${MACHINE}
34281027SandrewLDFLAGS=	-Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared
35264391Snwhitehorn
36282474Sandrew.if ${MACHINE_CPUARCH} == "aarch64"
37282474SandrewCFLAGS+=	-msoft-float -mgeneral-regs-only
38282474Sandrew.endif
39281027Sandrew.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
40281300SandrewCFLAGS+=	-fPIC
41281027SandrewLDFLAGS+=	-Wl,-znocombreloc
42281027Sandrew.endif
43281027Sandrew
44281238Semaste.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "i386"
45281156Sandrew#
46281238Semaste# Add libstand for the runtime functions used by the compiler - for example
47281238Semaste# __aeabi_* (arm) or __divdi3 (i386).
48281156Sandrew#
49281156SandrewDPADD+=		${LIBSTAND}
50281156SandrewLDADD+=		-lstand
51281156Sandrew.endif
52281156Sandrew
53287930SjhbDPADD+=		${LDSCRIPT}
54264391Snwhitehorn
55264391SnwhitehornOBJCOPY?=	objcopy
56264391SnwhitehornOBJDUMP?=	objdump
57264391Snwhitehorn
58264391Snwhitehorn.if ${MACHINE_CPUARCH} == "amd64"
59264391SnwhitehornEFI_TARGET=	efi-app-x86_64
60280950Sandrew.elif ${MACHINE_CPUARCH} == "i386"
61264391SnwhitehornEFI_TARGET=	efi-app-ia32
62281156Sandrew.else
63281156SandrewEFI_TARGET=	binary
64264391Snwhitehorn.endif
65264391Snwhitehorn
66287930Sjhbboot1.efi: ${PROG}
67264391Snwhitehorn	if [ `${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*' | wc -l` != 0 ]; then \
68264391Snwhitehorn		${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*'; \
69264391Snwhitehorn		exit 1; \
70264391Snwhitehorn	fi
71281156Sandrew	${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \
72264391Snwhitehorn		-j .dynamic -j .dynsym -j .rel.dyn \
73287930Sjhb		-j .rela.dyn -j .reloc -j .eh_frame \
74276146Semaste		--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
75264391Snwhitehorn
76264414Snwhitehornboot1.o: ${.CURDIR}/../../common/ufsread.c
77264414Snwhitehorn
78287930Sjhb# The following inserts our objects into a template FAT file system
79264975Snwhitehorn# created by generate-fat.sh
80264975Snwhitehorn
81264975Snwhitehorn.include "${.CURDIR}/Makefile.fat"
82293425SemasteBOOT1_MAXSIZE?=	131072
83264975Snwhitehorn
84264975Snwhitehornboot1.efifat: boot1.efi
85293425Semaste	@set -- `ls -l boot1.efi`; \
86293425Semaste	x=$$(($$5-${BOOT1_MAXSIZE})); \
87293425Semaste	if [ $$x -ge 0 ]; then \
88293425Semaste	    echo "boot1 $$x bytes too large; regenerate FAT templates?" >&2 ;\
89293425Semaste	    exit 1; \
90293425Semaste	fi
91264975Snwhitehorn	echo ${.OBJDIR}
92281524Sandrew	uudecode ${.CURDIR}/fat-${MACHINE}.tmpl.bz2.uu
93281524Sandrew	mv fat-${MACHINE}.tmpl.bz2 ${.TARGET}.bz2
94264975Snwhitehorn	bzip2 -f -d ${.TARGET}.bz2
95264975Snwhitehorn	dd if=boot1.efi of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
96264975Snwhitehorn
97281117SandrewCLEANFILES= boot1.efi boot1.efifat
98264975Snwhitehorn
99264391Snwhitehorn.endif # ${COMPILER_TYPE} != "gcc"
100264391Snwhitehorn
101264391Snwhitehorn.include <bsd.prog.mk>
102264391Snwhitehorn
103281496Sandrewbeforedepend ${OBJS}: machine
104264391Snwhitehorn
105281496SandrewCLEANFILES+=   machine
106264391Snwhitehorn
107264391Snwhitehornmachine:
108281496Sandrew	ln -sf ${.CURDIR}/../../../${MACHINE}/include machine
109264391Snwhitehorn
110281496Sandrew.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
111281496Sandrewbeforedepend ${OBJS}: x86
112281496SandrewCLEANFILES+=   x86
113281496Sandrew
114264391Snwhitehornx86:
115264391Snwhitehorn	ln -sf ${.CURDIR}/../../../x86/include x86
116281027Sandrew.endif
117