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