xref: /freebsd/stand/efi/loader/Makefile (revision 87b759f0fa1f7554d50ce640c40138512bbded44)
1LOADER_NET_SUPPORT?=	yes
2LOADER_MSDOS_SUPPORT?=	yes
3LOADER_UFS_SUPPORT?=	yes
4LOADER_CD9660_SUPPORT?=	no
5LOADER_EXT2FS_SUPPORT?=	no
6
7.include <bsd.init.mk>
8
9.if ${MACHINE} == "amd64" && ${DO32:U0} == 1
10__arch=	i386
11LOADER?=	loader_ia32
12.else
13__arch=	${MACHINE}
14LOADER?=	loader_${LOADER_INTERP}
15.endif
16PROG=		${LOADER}.sym
17INTERNALPROG=
18WARNS?=		3
19
20# architecture-specific loader code
21SRCS=	autoload.c \
22	bootinfo.c \
23	conf.c \
24	copy.c \
25	efi_main.c \
26	framebuffer.c \
27	main.c \
28	self_reloc.c \
29	vers.c \
30	gfx_fb.c \
31	8x16.c
32
33CFLAGS+=	-I${.CURDIR}/../loader
34.if ${MK_LOADER_ZFS} != "no"
35CFLAGS+=	-I${ZFSSRC}
36CFLAGS+=        -I${SYSDIR}/contrib/openzfs/include
37CFLAGS+=        -I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs
38CFLAGS+=	-DEFI_ZFS_BOOT
39HAVE_ZFS=	yes
40.endif
41
42CFLAGS.bootinfo.c += -I$(SRCTOP)/sys/teken
43CFLAGS.bootinfo.c += -I${SRCTOP}/contrib/pnglite
44CFLAGS.framebuffer.c += -I$(SRCTOP)/sys/teken
45CFLAGS.framebuffer.c += -I${SRCTOP}/contrib/pnglite
46CFLAGS.main.c += -I$(SRCTOP)/sys/teken
47CFLAGS.main.c += -I${SRCTOP}/contrib/pnglite
48CFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken
49CFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
50CFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite
51CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib
52
53# We implement a slightly non-standard %S in that it always takes a
54# CHAR16 that's common in UEFI-land instead of a wchar_t. This only
55# seems to matter on arm64 where wchar_t defaults to an int instead
56# of a short. There's no good cast to use here so just ignore the
57# warnings for now.
58CWARNFLAGS.main.c+=	-Wno-format
59
60.PATH: ${.CURDIR}/../loader
61.PATH: ${.CURDIR}/../loader/arch/${__arch}
62.include "${.CURDIR}/../loader/arch/${__arch}/Makefile.inc"
63
64CFLAGS+=	-I${.CURDIR}
65CFLAGS+=	-I${.CURDIR}/arch/${__arch}
66CFLAGS+=	-I${EFISRC}/include
67CFLAGS+=	-I${EFISRC}/include/${__arch}
68CFLAGS+=	-I${SYSDIR}/contrib/dev/acpica/include
69CFLAGS+=	-I${BOOTSRC}/i386/libi386
70CFLAGS+=	-DEFI
71
72.if defined(HAVE_FDT) && ${MK_FDT} != "no"
73.include	"${BOOTSRC}/fdt.mk"
74LIBEFI_FDT=	${BOOTOBJ}/efi/fdt/libefi_fdt.a
75HELP_FILES+=	${FDTSRC}/help.fdt
76.endif
77
78# Include bcache code.
79HAVE_BCACHE=    yes
80
81.if defined(EFI_STAGING_SIZE)
82CFLAGS+=	-DEFI_STAGING_SIZE=${EFI_STAGING_SIZE}
83.endif
84
85.if ${MK_LOADER_EFI_SECUREBOOT} != "no"
86CFLAGS+= -DEFI_SECUREBOOT
87.endif
88
89NEWVERSWHAT?=	"EFI loader" ${MACHINE}
90VERSION_FILE=	${.CURDIR}/../loader/version
91HELP_FILENAME=	loader.help.efi
92
93# Always add MI sources
94.include	"${BOOTSRC}/loader.mk"
95
96CLEANFILES+=	8x16.c
97
988x16.c:		${SRCTOP}/contrib/terminus/ter-u16b.bdf
99	vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC}
100
101FILES+=	${LOADER}.efi
102FILESMODE_${LOADER}.efi=	${BINMODE}
103
104.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} && ${__arch} != "i386"
105LINKS+=		${BINDIR}/${LOADER}.efi ${BINDIR}/loader.efi
106.endif
107
108LDSCRIPT=	${.CURDIR}/../loader/arch/${__arch}/${__arch}.ldscript
109LDFLAGS+=	-Wl,-T${LDSCRIPT},-Bsymbolic,-znotext -pie
110.if ${LINKER_TYPE} == "bfd" && ${LINKER_VERSION} >= 23400
111LDFLAGS+=	-Wl,--no-dynamic-linker
112.endif
113
114.include <bsd.linker.mk>
115
116.if ${LINKER_TYPE} == "lld" && ${LINKER_FREEBSD_VERSION} < 1500001
117# When lld is using multiple threads, which it does by default, it can
118# result in non-reproducible output with the custom linker script. Work
119# around this by disabling threading.
120LDFLAGS+=	-Wl,--threads=1
121.endif
122
123CLEANFILES+=	${LOADER}.efi
124
125${LOADER}.efi: ${PROG}
126	@if ${NM} ${.ALLSRC} | grep ' U '; then \
127		echo "Undefined symbols in ${.ALLSRC}"; \
128		exit 1; \
129	fi
130	SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
131	${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \
132		-j .dynamic -j .dynsym -j .rel.dyn \
133		-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
134		-j set_X${LOADER_INTERP}_compile_set \
135		--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
136
137LIBEFI=		${BOOTOBJ}/efi/libefi/libefi.a
138LIBEFI32=	${BOOTOBJ}/efi/libefi32/libefi.a
139
140.if ${__arch} == "i386"
141DPADD=		${LDR_INTERP32} ${LIBEFI32} ${LIBSA32} ${LDSCRIPT}
142LDADD=		${LDR_INTERP32} ${LIBEFI32} ${LIBSA32}
143.else
144DPADD=		${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA} ${LDSCRIPT}
145LDADD=		${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA}
146.endif
147
148.include <bsd.prog.mk>
149