Makefile revision 293425
1135549Sdes# $FreeBSD: head/sys/boot/efi/boot1/Makefile 293425 2016-01-08 16:37:22Z emaste $
2135549Sdes
3135549SdesMAN=
4135549Sdes
5135549Sdes.include <bsd.own.mk>
6135549Sdes
7135549Sdes# In-tree GCC does not support __attribute__((ms_abi)).
8135549Sdes.if ${COMPILER_TYPE} != "gcc"
9135549Sdes
10135549SdesMK_SSP=		no
11135549Sdes
12135549SdesPROG=		boot1.sym
13135549SdesINTERNALPROG=
14135549Sdes
15135549Sdes# architecture-specific loader code
16135549SdesSRCS=	boot1.c self_reloc.c start.S
17135549Sdes
18135549SdesCFLAGS+=	-I.
19135549SdesCFLAGS+=	-I${.CURDIR}/../include
20135549SdesCFLAGS+=	-I${.CURDIR}/../include/${MACHINE}
21135549SdesCFLAGS+=	-I${.CURDIR}/../../../contrib/dev/acpica/include
22135549SdesCFLAGS+=	-I${.CURDIR}/../../..
23135549Sdes
24135549Sdes# Always add MI sources and REGULAR efi loader bits
25135549Sdes.PATH:		${.CURDIR}/../loader/arch/${MACHINE}
26135549Sdes.PATH:		${.CURDIR}/../loader
27135549Sdes.PATH:		${.CURDIR}/../../common
28135549SdesCFLAGS+=	-I${.CURDIR}/../../common
29135549Sdes
30135549SdesFILES=	boot1.efi boot1.efifat
31135549SdesFILESMODE_boot1.efi=	${BINMODE}
32135549Sdes
33135549SdesLDSCRIPT=	${.CURDIR}/../loader/arch/${MACHINE}/ldscript.${MACHINE}
34135549SdesLDFLAGS=	-Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared
35135549Sdes
36135549Sdes.if ${MACHINE_CPUARCH} == "aarch64"
37135549SdesCFLAGS+=	-msoft-float -mgeneral-regs-only
38135549Sdes.endif
39135549Sdes.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
40135549SdesCFLAGS+=	-fPIC
41135549SdesLDFLAGS+=	-Wl,-znocombreloc
42135549Sdes.endif
43135549Sdes
44135549Sdes.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "i386"
45135549Sdes#
46135549Sdes# Add libstand for the runtime functions used by the compiler - for example
47135549Sdes# __aeabi_* (arm) or __divdi3 (i386).
48135549Sdes#
49135549SdesDPADD+=		${LIBSTAND}
50135549SdesLDADD+=		-lstand
51135549Sdes.endif
52135549Sdes
53135549SdesDPADD+=		${LDSCRIPT}
54135549Sdes
55135549SdesOBJCOPY?=	objcopy
56135549SdesOBJDUMP?=	objdump
57135549Sdes
58135549Sdes.if ${MACHINE_CPUARCH} == "amd64"
59135549SdesEFI_TARGET=	efi-app-x86_64
60135549Sdes.elif ${MACHINE_CPUARCH} == "i386"
61135549SdesEFI_TARGET=	efi-app-ia32
62135549Sdes.else
63135549SdesEFI_TARGET=	binary
64135549Sdes.endif
65135549Sdes
66135549Sdesboot1.efi: ${PROG}
67135549Sdes	if [ `${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*' | wc -l` != 0 ]; then \
68135549Sdes		${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*'; \
69135549Sdes		exit 1; \
70135549Sdes	fi
71135549Sdes	${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \
72135549Sdes		-j .dynamic -j .dynsym -j .rel.dyn \
73135549Sdes		-j .rela.dyn -j .reloc -j .eh_frame \
74135549Sdes		--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
75135549Sdes
76135549Sdesboot1.o: ${.CURDIR}/../../common/ufsread.c
77135549Sdes
78135549Sdes# The following inserts our objects into a template FAT file system
79135549Sdes# created by generate-fat.sh
80135549Sdes
81135549Sdes.include "${.CURDIR}/Makefile.fat"
82135549SdesBOOT1_MAXSIZE?=	131072
83135549Sdes
84135549Sdesboot1.efifat: boot1.efi
85135549Sdes	@set -- `ls -l boot1.efi`; \
86135549Sdes	x=$$(($$5-${BOOT1_MAXSIZE})); \
87135549Sdes	if [ $$x -ge 0 ]; then \
88135549Sdes	    echo "boot1 $$x bytes too large; regenerate FAT templates?" >&2 ;\
89135549Sdes	    exit 1; \
90135549Sdes	fi
91135549Sdes	echo ${.OBJDIR}
92135549Sdes	uudecode ${.CURDIR}/fat-${MACHINE}.tmpl.bz2.uu
93135549Sdes	mv fat-${MACHINE}.tmpl.bz2 ${.TARGET}.bz2
94135549Sdes	bzip2 -f -d ${.TARGET}.bz2
95135549Sdes	dd if=boot1.efi of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
96135549Sdes
97135549SdesCLEANFILES= boot1.efi boot1.efifat
98135549Sdes
99135549Sdes.endif # ${COMPILER_TYPE} != "gcc"
100135549Sdes
101135549Sdes.include <bsd.prog.mk>
102135549Sdes
103135549Sdesbeforedepend ${OBJS}: machine
104135549Sdes
105135549SdesCLEANFILES+=   machine
106135549Sdes
107135549Sdesmachine:
108135549Sdes	ln -sf ${.CURDIR}/../../../${MACHINE}/include machine
109135549Sdes
110135549Sdes.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
111135549Sdesbeforedepend ${OBJS}: x86
112135549SdesCLEANFILES+=   x86
113135549Sdes
114135549Sdesx86:
115135549Sdes	ln -sf ${.CURDIR}/../../../x86/include x86
116135549Sdes.endif
117135549Sdes