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