xref: /freebsd/stand/defs.mk (revision b65d7763288e39229a722a764ddd5b3f3302794e)
1ca987d46SWarner Losh# $FreeBSD$
2ca987d46SWarner Losh
3ca987d46SWarner Losh.include <src.opts.mk>
4ca987d46SWarner Losh
5ca987d46SWarner Losh.if !defined(__BOOT_DEFS_MK__)
6ca987d46SWarner Losh__BOOT_DEFS_MK__=${MFILE}
7ca987d46SWarner Losh
8ca987d46SWarner LoshBOOTSRC=	${SRCTOP}/stand
9ca987d46SWarner LoshEFISRC=		${BOOTSRC}/efi
10ca987d46SWarner LoshEFIINC=		${EFISRC}/include
11ca987d46SWarner LoshEFIINCMD=	${EFIINC}/${MACHINE}
12ca987d46SWarner LoshFDTSRC=		${BOOTSRC}/fdt
13ca987d46SWarner LoshFICLSRC=	${BOOTSRC}/ficl
14ca987d46SWarner LoshLDRSRC=		${BOOTSRC}/common
15ca987d46SWarner LoshSASRC=		${BOOTSRC}/libsa
16ca987d46SWarner LoshSYSDIR=		${SRCTOP}/sys
17ca987d46SWarner LoshUBOOTSRC=	${BOOTSRC}/uboot
18ca987d46SWarner LoshZFSSRC=		${BOOTSRC}/zfs
19ca987d46SWarner Losh
20ca987d46SWarner LoshBOOTOBJ=	${OBJTOP}/stand
21ca987d46SWarner Losh
22ca987d46SWarner Losh# BINDIR is where we install
23ca987d46SWarner LoshBINDIR?=	/boot
24ca987d46SWarner Losh
25ca987d46SWarner Losh# NB: The makefiles depend on these being empty when we don't build forth.
26ca987d46SWarner Losh.if ${MK_FORTH} != "no"
27ca987d46SWarner LoshLIBFICL=	${BOOTOBJ}/ficl/libficl.a
28ca987d46SWarner Losh.if ${MACHINE} == "i386"
29ca987d46SWarner LoshLIBFICL32=	${LIBFICL}
30ca987d46SWarner Losh.else
31ca987d46SWarner LoshLIBFICL32=	${BOOTOBJ}/ficl32/libficl.a
32ca987d46SWarner Losh.endif
33ca987d46SWarner Losh.endif
34ca987d46SWarner LoshLIBSA=		${BOOTOBJ}/libsa/libsa.a
35ca987d46SWarner Losh.if ${MACHINE} == "i386"
36ca987d46SWarner LoshLIBSA32=	${LIBSA}
37ca987d46SWarner Losh.else
38ca987d46SWarner LoshLIBSA32=	${BOOTOBJ}/libsa32/libsa32.a
39ca987d46SWarner Losh.endif
40ca987d46SWarner Losh
41ca987d46SWarner Losh# Standard options:
42*b65d7763SWarner LoshCFLAGS+=	-I${SASRC} -D_STANDALONE
434f6b2874SWarner LoshCFLAGS+=	-I${SYSDIR}
44ca987d46SWarner Losh
45ca987d46SWarner Losh# Filesystem support
46ca987d46SWarner Losh.if ${LOADER_CD9660_SUPPORT:Uno} == "yes"
47ca987d46SWarner LoshCFLAGS+=	-DLOADER_CD9660_SUPPORT
48ca987d46SWarner Losh.endif
49ca987d46SWarner Losh.if ${LOADER_EXT2FS_SUPPORT:Uno} == "yes"
50ca987d46SWarner LoshCFLAGS+=	-DLOADER_EXT2FS_SUPPORT
51ca987d46SWarner Losh.endif
52ca987d46SWarner Losh.if ${LOADER_MSDOS_SUPPORT:Uno} == "yes"
53ca987d46SWarner LoshCFLAGS+=	-DLOADER_MSDOS_SUPPORT
54ca987d46SWarner Losh.endif
55ca987d46SWarner Losh.if ${LOADER_NANDFS_SUPPORT:U${MK_NAND}} == "yes"
56ca987d46SWarner LoshCFLAGS+=	-DLOADER_NANDFS_SUPPORT
57ca987d46SWarner Losh.endif
58ca987d46SWarner Losh.if ${LOADER_UFS_SUPPORT:Uyes} == "yes"
59ca987d46SWarner LoshCFLAGS+=	-DLOADER_UFS_SUPPORT
60ca987d46SWarner Losh.endif
61ca987d46SWarner Losh
62ca987d46SWarner Losh# Compression
63ca987d46SWarner Losh.if ${LOADER_GZIP_SUPPORT:Uno} == "yes"
64ca987d46SWarner LoshCFLAGS+=	-DLOADER_GZIP_SUPPORT
65ca987d46SWarner Losh.endif
66ca987d46SWarner Losh.if ${LOADER_BZIP2_SUPPORT:Uno} == "yes"
67ca987d46SWarner LoshCFLAGS+=	-DLOADER_BZIP2_SUPPORT
68ca987d46SWarner Losh.endif
69ca987d46SWarner Losh
70ca987d46SWarner Losh# Network related things
71ca987d46SWarner Losh.if ${LOADER_NET_SUPPORT:Uno} == "yes"
72ca987d46SWarner LoshCFLAGS+=	-DLOADER_NET_SUPPORT
73ca987d46SWarner Losh.endif
74ca987d46SWarner Losh.if ${LOADER_NFS_SUPPORT:Uno} == "yes"
75ca987d46SWarner LoshCFLAGS+=	-DLOADER_NFS_SUPPORT
76ca987d46SWarner Losh.endif
77ca987d46SWarner Losh.if ${LOADER_TFTP_SUPPORT:Uno} == "yes"
78ca987d46SWarner LoshCFLAGS+=	-DLOADER_TFTP_SUPPORT
79ca987d46SWarner Losh.endif
80ca987d46SWarner Losh
81ca987d46SWarner Losh# Disk and partition support
82ca987d46SWarner Losh.if ${LOADER_DISK_SUPPORT:Uyes} == "yes"
83ca987d46SWarner LoshCFLAGS+= -DLOADER_DISK_SUPPORT
84ca987d46SWarner Losh.if ${LOADER_GPT_SUPPORT:Uyes} == "yes"
85ca987d46SWarner LoshCFLAGS+= -DLOADER_GPT_SUPPORT
86ca987d46SWarner Losh.endif
87ca987d46SWarner Losh.if ${LOADER_MBR_SUPPORT:Uyes} == "yes"
88ca987d46SWarner LoshCFLAGS+= -DLOADER_MBR_SUPPORT
89ca987d46SWarner Losh.endif
90ca987d46SWarner Losh
91ca987d46SWarner Losh# GELI Support, with backward compat hooks
92ca987d46SWarner Losh.if defined(HAVE_GELI)
93ca987d46SWarner Losh.if defined(LOADER_NO_GELI_SUPPORT)
94ca987d46SWarner LoshMK_LOADER_GELI=no
95ca987d46SWarner Losh.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI"
96ca987d46SWarner Losh.endif
97ca987d46SWarner Losh.if defined(LOADER_GELI_SUPPORT)
98ca987d46SWarner LoshMK_LOADER_GELI=yes
99ca987d46SWarner Losh.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI"
100ca987d46SWarner Losh.endif
101ca987d46SWarner Losh.if ${MK_LOADER_GELI} == "yes"
102ca987d46SWarner LoshCFLAGS+=	-DLOADER_GELI_SUPPORT
103ca987d46SWarner LoshCFLAGS+=	-I${BOOTSRC}/geli
104ca987d46SWarner LoshLIBGELIBOOT=	${BOOTOBJ}/geli/libgeliboot.a
105ca987d46SWarner Losh.endif
106ca987d46SWarner Losh.endif
107ca987d46SWarner Losh.endif
108ca987d46SWarner Losh
1094f6b2874SWarner Losh# Machine specific flags for all builds here
110ca987d46SWarner Losh
111ca987d46SWarner Losh# All PowerPC builds are 32 bit. We have no 64-bit loaders on powerpc
112ca987d46SWarner Losh# or powerpc64.
113ca987d46SWarner Losh.if ${MACHINE_ARCH} == "powerpc64"
114ca987d46SWarner LoshCFLAGS+=	-m32 -mcpu=powerpc
115ca987d46SWarner Losh.endif
116ca987d46SWarner Losh
117ca987d46SWarner Losh# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is
118ca987d46SWarner Losh# build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here
119ca987d46SWarner Losh# and activate it when DO32 is explicitly defined to be 1.
120ca987d46SWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
121ca987d46SWarner LoshCFLAGS+=	-m32 -mcpu=i386
122ca987d46SWarner Losh# LD_FLAGS is passed directly to ${LD}, not via ${CC}:
123ca987d46SWarner LoshLD_FLAGS+=	-m elf_i386_fbsd
124ca987d46SWarner LoshAFLAGS+=	--32
125ca987d46SWarner Losh.endif
126ca987d46SWarner Losh
1274f6b2874SWarner LoshSSP_CFLAGS=
1284f6b2874SWarner Losh
1294f6b2874SWarner Losh# Add in the no float / no SIMD stuff and announce we're freestanding
1304f6b2874SWarner Losh# aarch64 and riscv don't have -msoft-float, but all others do. riscv
1314f6b2874SWarner Losh# currently has no /boot/loader, but may soon.
1324f6b2874SWarner LoshCFLAGS+=	-ffreestanding ${CFLAGS_NO_SIMD}
1334f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "aarch64"
1344f6b2874SWarner LoshCFLAGS+=	-mgeneral-regs-only
1354f6b2874SWarner Losh.elif ${MACHINE_CPUARCH} != "riscv"
1364f6b2874SWarner LoshCFLAGS+=	-msoft-float
1374f6b2874SWarner Losh.endif
1384f6b2874SWarner Losh
1394f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1)
1404f6b2874SWarner LoshCFLAGS+=	-march=i386
1414f6b2874SWarner LoshCFLAGS.gcc+=	-mpreferred-stack-boundary=2
1424f6b2874SWarner Losh.endif
1434f6b2874SWarner Losh
1444f6b2874SWarner Losh
1454f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "arm"
1464f6b2874SWarner Losh# Do not generate movt/movw, because the relocation fixup for them does not
1474f6b2874SWarner Losh# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8).
1484f6b2874SWarner Losh# Also, the fpu is not available in a standalone environment.
1494f6b2874SWarner Losh.if ${COMPILER_VERSION} < 30800
1504f6b2874SWarner LoshCFLAGS.clang+=	-mllvm -arm-use-movt=0
1514f6b2874SWarner Losh.else
1524f6b2874SWarner LoshCFLAGS.clang+=	-mno-movt
1534f6b2874SWarner Losh.endif
1544f6b2874SWarner LoshCFLAGS.clang+=  -mfpu=none
1554f6b2874SWarner Losh.endif
1564f6b2874SWarner Losh
1574f6b2874SWarner Losh# The boot loader build uses dd status=none, where possible, for reproducible
1584f6b2874SWarner Losh# build output (since performance varies from run to run). Trouble is that
1594f6b2874SWarner Losh# option was recently (10.3) added to FreeBSD and is non-standard. Only use it
1604f6b2874SWarner Losh# when this test succeeds rather than require dd to be a bootstrap tool.
1614f6b2874SWarner LoshDD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true
1624f6b2874SWarner LoshDD=dd ${DD_NOSTATUS}
1634f6b2874SWarner Losh
1644f6b2874SWarner Losh.if ${MK_LOADER_FORCE_LE} != "no"
1654f6b2874SWarner Losh.if ${MACHINE_ARCH} == "powerpc64"
1664f6b2874SWarner LoshCFLAGS+=	-mlittle-endian
1674f6b2874SWarner Losh.endif
1684f6b2874SWarner Losh.endif
1694f6b2874SWarner Losh
170ca987d46SWarner Losh# Make sure we use the machine link we're about to create
171ca987d46SWarner LoshCFLAGS+=-I.
172ca987d46SWarner Losh
173ca987d46SWarner Losh_ILINKS=machine
174ca987d46SWarner Losh.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
175ca987d46SWarner Losh_ILINKS+=${MACHINE_CPUARCH}
176ca987d46SWarner Losh.endif
177ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
178ca987d46SWarner Losh_ILINKS+=x86
179ca987d46SWarner Losh.endif
180ca987d46SWarner LoshCLEANFILES+=${_ILINKS}
181ca987d46SWarner Losh
182ca987d46SWarner Loshall: ${PROG}
183ca987d46SWarner Losh
184ca987d46SWarner Loshbeforedepend: ${_ILINKS}
185ca987d46SWarner Loshbeforebuild: ${_ILINKS}
186ca987d46SWarner Losh
187ca987d46SWarner Losh# Ensure that the links exist without depending on it when it exists which
188ca987d46SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes.
189ca987d46SWarner Losh.for _link in ${_ILINKS}
190ca987d46SWarner Losh.if !exists(${.OBJDIR}/${_link})
191ca987d46SWarner Losh${OBJS}:       ${_link}
192ca987d46SWarner Losh.endif
193ca987d46SWarner Losh.endfor
194ca987d46SWarner Losh
195ca987d46SWarner Losh.NOPATH: ${_ILINKS}
196ca987d46SWarner Losh
197ca987d46SWarner Losh${_ILINKS}:
198ca987d46SWarner Losh	@case ${.TARGET} in \
199ca987d46SWarner Losh	machine) \
200ca987d46SWarner Losh		if [ ${DO32:U0} -eq 0 ]; then \
201ca987d46SWarner Losh			path=${SYSDIR}/${MACHINE}/include ; \
202ca987d46SWarner Losh		else \
203ca987d46SWarner Losh			path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \
204ca987d46SWarner Losh		fi ;; \
205ca987d46SWarner Losh	*) \
206ca987d46SWarner Losh		path=${SYSDIR}/${.TARGET:T}/include ;; \
207ca987d46SWarner Losh	esac ; \
208ca987d46SWarner Losh	path=`(cd $$path && /bin/pwd)` ; \
209ca987d46SWarner Losh	${ECHO} ${.TARGET:T} "->" $$path ; \
210ca987d46SWarner Losh	ln -fhs $$path ${.TARGET:T}
211ca987d46SWarner Losh
212ca987d46SWarner Losh# For loader implementations, we generate a loader.help file. This can be suppressed by
213ca987d46SWarner Losh# setting HELP_FILES to nothing.
214ca987d46SWarner LoshHELP_FILES=	${LDRSRC}/help.common
215ca987d46SWarner Losh
216ca987d46SWarner Losh.endif # __BOOT_DEFS_MK__
217