xref: /freebsd/stand/efi/boot1/Makefile (revision ca987d4641cdcd7f27e153db17c5bf064934faf5)
1# $FreeBSD$
2
3MAN=
4
5.include <bsd.init.mk>
6
7MK_SSP=		no
8MK_FORTH=	no
9
10PROG=		boot1.sym
11INTERNALPROG=
12WARNS?=		6
13
14# We implement a slightly non-standard %S in that it always takes a
15# CHAR16 that's common in UEFI-land instead of a wchar_t. This only
16# seems to matter on arm64 where wchar_t defaults to an int instead
17# of a short. There's no good cast to use here so just ignore the
18# warnings for now.
19CWARNFLAGS.boot1.c+=	-Wno-format
20
21# Disable warnings that are currently incompatible with the zfs boot code
22CWARNFLAGS.zfs_module.c += -Wno-array-bounds
23CWARNFLAGS.zfs_module.c += -Wno-cast-align
24CWARNFLAGS.zfs_module.c += -Wno-cast-qual
25CWARNFLAGS.zfs_module.c += -Wno-missing-prototypes
26CWARNFLAGS.zfs_module.c += -Wno-sign-compare
27CWARNFLAGS.zfs_module.c += -Wno-unused-parameter
28CWARNFLAGS.zfs_module.c += -Wno-unused-function
29
30# architecture-specific loader code
31SRCS=	boot1.c self_reloc.c start.S ufs_module.c
32.if ${MK_ZFS} != "no"
33SRCS+=		zfs_module.c
34CFLAGS+=	-I${ZFSSRC}
35CFLAGS+=	-I${SYSDIR}/cddl/boot/zfs
36CFLAGS+=	-DEFI_ZFS_BOOT
37LIBZFSBOOT=	${BOOTOBJ}/zfs/libzfsboot.a
38.endif
39
40.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201
41CWARNFLAGS.self_reloc.c+=	-Wno-error=maybe-uninitialized
42.endif
43
44CFLAGS+=	-I${EFIINC}
45CFLAGS+=	-I${EFIINCMD}
46CFLAGS+=	-I${SYSDIR}/contrib/dev/acpica/include
47CFLAGS+=	-DEFI_UFS_BOOT
48.ifdef(EFI_DEBUG)
49CFLAGS+=	-DEFI_DEBUG
50.endif
51
52# Always add MI sources and REGULAR efi loader bits
53.PATH:		${EFISRC}/loader/arch/${MACHINE}
54.PATH:		${EFISRC}/loader
55.PATH:		${LDRSRC}
56CFLAGS+=	-I${LDRSRC}
57
58FILES=	boot1.efi boot1.efifat
59FILESMODE_boot1.efi=	${BINMODE}
60
61LDSCRIPT=	${EFISRC}/loader/arch/${MACHINE}/ldscript.${MACHINE}
62LDFLAGS+=	-Wl,-T${LDSCRIPT},-Bsymbolic,-znotext -shared
63
64.if ${MACHINE_CPUARCH} == "aarch64"
65CFLAGS+=	-mgeneral-regs-only
66.endif
67.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
68CFLAGS+=	-fPIC
69LDFLAGS+=	-Wl,-znocombreloc
70.endif
71
72LIBEFI=		${BOOTOBJ}/efi/libefi/libefi.a
73
74#
75# Add libstand for the runtime functions used by the compiler - for example
76# __aeabi_* (arm) or __divdi3 (i386).
77# as well as required string and memory functions for all platforms.
78#
79DPADD+=		${LIBEFI} ${LIBZFSBOOT} ${LIBSA}
80LDADD+=		${LIBEFI} ${LIBZFSBOOT} ${LIBSA}
81
82DPADD+=		${LDSCRIPT}
83
84NM?=		nm
85OBJCOPY?=	objcopy
86
87.if ${MACHINE_CPUARCH} == "amd64"
88EFI_TARGET=	efi-app-x86_64
89.elif ${MACHINE_CPUARCH} == "i386"
90EFI_TARGET=	efi-app-ia32
91.else
92EFI_TARGET=	binary
93.endif
94
95# Arbitrarily set the PE/COFF header timestamps to 1 Jan 2016 00:00:00
96# for build reproducibility.
97SOURCE_DATE_EPOCH?=1451606400
98boot1.efi: ${PROG}
99	if ${NM} ${.ALLSRC} | grep ' U '; then \
100		echo "Undefined symbols in ${.ALLSRC}"; \
101		exit 1; \
102	fi
103	SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
104	${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \
105		-j .dynamic -j .dynsym -j .rel.dyn \
106		-j .rela.dyn -j .reloc -j .eh_frame \
107		--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
108
109boot1.o: ${SASRC}/ufsread.c
110
111# The following inserts our objects into a template FAT file system
112# created by generate-fat.sh
113
114.include "${.CURDIR}/Makefile.fat"
115
116boot1.efifat: boot1.efi
117	@set -- `ls -l ${.ALLSRC}`; \
118	x=$$(($$5-${BOOT1_MAXSIZE})); \
119	if [ $$x -ge 0 ]; then \
120	    echo "boot1 $$x bytes too large; regenerate FAT templates?" >&2 ;\
121	    exit 1; \
122	fi
123	echo ${.OBJDIR}
124	xz -d -c ${.CURDIR}/fat-${MACHINE}.tmpl.xz > ${.TARGET}
125	${DD} if=${.ALLSRC} of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
126
127CLEANFILES+= boot1.efi boot1.efifat
128
129.include <bsd.prog.mk>
130