xref: /freebsd/stand/defs.mk (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1
2.if !defined(__BOOT_DEFS_MK__)
3__BOOT_DEFS_MK__=${MFILE}
4
5FORTIFY_SOURCE=	0
6
7# We need to define all the MK_ options before including src.opts.mk
8# because it includes bsd.own.mk which needs the right MK_ values,
9# espeically MK_CTF.
10
11MK_CTF=		no
12MK_SSP=		no
13MK_PROFILE=	no
14MK_PIE=		no
15MAN=
16.if !defined(PIC)
17NO_PIC=
18INTERNALLIB=
19.endif
20# Should be NO_CPU_FLAGS, but bsd.cpu.mk is included too early in bsd.init.mk
21# via the early include of bsd.opts.mk. Moving Makefile.inc include earlier in
22# that file causes weirdness, so this is the next best thing. We need to do this
23# because the loader needs very specific flags to work right, and things like
24# CPUTYPE?=native prevent that, and introduce an endless game of whack-a-mole
25# to disable more and more features. Boot loader performance is never improved
26# enough to make that hassle worth chasing.
27_CPUCFLAGS=
28
29.if ${LDFLAGS:M-nostdlib}
30# Sanitizers won't work unless we link against libc (e.g. in userboot/test).
31MK_ASAN:=	no
32MK_UBSAN:=	no
33.endif
34
35.include <src.opts.mk>
36.include <bsd.linker.mk>
37
38WARNS?=		1
39
40BOOTSRC=	${SRCTOP}/stand
41EFISRC=		${BOOTSRC}/efi
42EFIINC=		${EFISRC}/include
43EFIINCMD=	${EFIINC}/${MACHINE}
44FDTSRC=		${BOOTSRC}/fdt
45FICLSRC=	${BOOTSRC}/ficl
46LDRSRC=		${BOOTSRC}/common
47LIBLUASRC=	${BOOTSRC}/liblua
48LIBOFWSRC=	${BOOTSRC}/libofw
49LUASRC=		${SRCTOP}/contrib/lua/src
50SASRC=		${BOOTSRC}/libsa
51SYSDIR=		${SRCTOP}/sys
52UBOOTSRC=	${BOOTSRC}/uboot
53ZFSSRC=		${SASRC}/zfs
54OZFS=		${SRCTOP}/sys/contrib/openzfs
55ZFSOSSRC=	${OZFS}/module/os/freebsd/
56ZFSOSINC=	${OZFS}/include/os/freebsd
57LIBCSRC=	${SRCTOP}/lib/libc
58
59BOOTOBJ=	${OBJTOP}/stand
60
61# BINDIR is where we install
62BINDIR?=	/boot
63
64# LUAPATH is where we search for and install lua scripts.
65LUAPATH?=	/boot/lua
66FLUASRC?=	${SRCTOP}/libexec/flua
67FLUALIB?=	${SRCTOP}/libexec/flua
68
69LIBSA=		${BOOTOBJ}/libsa/libsa.a
70.if ${MACHINE} == "i386"
71LIBSA32=	${LIBSA}
72.else
73LIBSA32=	${BOOTOBJ}/libsa32/libsa32.a
74.endif
75
76# Standard options:
77CFLAGS+=	-nostdinc
78# Allow CFLAGS_EARLY.file/target so that code that needs specific stack
79# of include paths can set them up before our include paths. Normally
80# the only thing that should be there are -I directives, and as few of
81# those as possible.
82CFLAGS+=	${CFLAGS_EARLY} ${CFLAGS_EARLY.${.IMPSRC:T}} ${CFLAGS_EARLY.${.TARGET:T}}
83.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
84CFLAGS+=	-I${BOOTOBJ}/libsa32
85.else
86CFLAGS+=	-I${BOOTOBJ}/libsa
87.endif
88CFLAGS+=	-I${SASRC} -D_STANDALONE
89CFLAGS+=	-I${SYSDIR}
90# Spike the floating point interfaces
91CFLAGS+=	-Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface
92.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
93# Slim down the image. This saves about 15% in size with clang 6 on x86
94# Our most constrained /boot/loader env is BIOS booting on x86, where
95# our text + data + BTX have to fit into 640k below the ISA hole.
96# Experience has shown that problems arise between ~520k to ~530k.
97CFLAGS.clang+=	-Oz
98CFLAGS.gcc+=	-Os
99CFLAGS+=	-ffunction-sections -fdata-sections
100.endif
101
102# GELI Support, with backward compat hooks (mostly)
103.if defined(LOADER_NO_GELI_SUPPORT)
104MK_LOADER_GELI=no
105.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI"
106.endif
107.if defined(LOADER_GELI_SUPPORT)
108MK_LOADER_GELI=yes
109.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI"
110.endif
111.if ${MK_LOADER_GELI} == "yes"
112CFLAGS+=	-DLOADER_GELI_SUPPORT
113CFLAGS+=	-I${SASRC}/geli
114.endif # MK_LOADER_GELI
115
116# These should be confined to loader.mk, but can't because uboot/lib
117# also uses it. It's part of loader, but isn't a loader so we can't
118# just include loader.mk
119.if ${LOADER_DISK_SUPPORT:Uyes} == "yes"
120CFLAGS+= -DLOADER_DISK_SUPPORT
121.endif
122
123# Machine specific flags for all builds here
124
125# Ensure PowerPC64 and PowerPC64LE boot loaders are compiled as 32 bit.
126# PowerPC64LE boot loaders are 32-bit little-endian.
127.if ${MACHINE_ARCH} == "powerpc64"
128CFLAGS+=	-m32 -mcpu=powerpc -mbig-endian
129.elif ${MACHINE_ARCH} == "powerpc64le"
130CFLAGS+=	-m32 -mcpu=powerpc -mlittle-endian
131.endif
132
133# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is
134# build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here
135# and activate it when DO32 is explicitly defined to be 1.
136.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
137CFLAGS+=	-m32
138# LD_FLAGS is passed directly to ${LD}, not via ${CC}:
139LD_FLAGS+=	-m elf_i386_fbsd
140AFLAGS+=	--32
141.endif
142
143# Add in the no float / no SIMD stuff and announce we're freestanding
144# aarch64 and riscv don't have -msoft-float, but all others do.
145CFLAGS+=	-ffreestanding ${CFLAGS_NO_SIMD}
146.if ${MACHINE_CPUARCH} == "aarch64"
147CFLAGS+=	-mgeneral-regs-only -ffixed-x18 -fPIC
148.elif ${MACHINE_CPUARCH} == "riscv"
149CFLAGS+=	-march=rv64imac -mabi=lp64 -fPIC
150CFLAGS.clang+=	-mcmodel=medium
151CFLAGS.gcc+=	-mcmodel=medany
152.else
153CFLAGS+=	-msoft-float
154.endif
155
156# -msoft-float seems to be insufficient for powerpcspe
157.if ${MACHINE_ARCH} == "powerpcspe"
158CFLAGS+=	-mno-spe
159.endif
160
161.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1)
162CFLAGS+=	-march=i386
163CFLAGS.gcc+=	-mpreferred-stack-boundary=2
164.endif
165.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0
166CFLAGS+=	-fPIC -mno-red-zone
167.endif
168
169.if ${MACHINE_CPUARCH} == "arm"
170# Do not generate movt/movw, because the relocation fixup for them does not
171# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8).
172# Also, the fpu is not available in a standalone environment.
173CFLAGS.clang+=	-mno-movt
174CFLAGS.clang+=  -mfpu=none
175CFLAGS+=	-fPIC
176.endif
177
178# Some RISC-V linkers have support for relaxations, while some (lld) do not
179# yet. If this is the case we inhibit the compiler from emitting relaxations.
180.if ${LINKER_FEATURES:Mriscv-relaxations} == ""
181CFLAGS+=	-mno-relax
182.endif
183
184# The boot loader build uses dd status=none, where possible, for reproducible
185# build output (since performance varies from run to run). Trouble is that
186# option was recently (10.3) added to FreeBSD and is non-standard. Only use it
187# when this test succeeds rather than require dd to be a bootstrap tool.
188DD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true
189DD=dd ${DD_NOSTATUS}
190
191#
192# Have a sensible default
193#
194.if ${MK_LOADER_LUA} == "yes"
195LOADER_DEFAULT_INTERP?=lua
196.elif ${MK_FORTH} == "yes"
197LOADER_DEFAULT_INTERP?=4th
198.else
199LOADER_DEFAULT_INTERP?=simp
200.endif
201LOADER_INTERP?=${LOADER_DEFAULT_INTERP}
202
203# Make sure we use the machine link we're about to create
204CFLAGS+=-I.
205
206all: ${PROG}
207
208CLEANFILES+= teken_state.h
209teken.c: teken_state.h
210
211teken_state.h: ${SYSDIR}/teken/sequences
212	awk -f ${SYSDIR}/teken/gensequences \
213		${SYSDIR}/teken/sequences > teken_state.h
214
215.if !defined(NO_OBJ)
216_ILINKS=include/machine
217.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
218_ILINKS+=include/${MACHINE_CPUARCH}
219.endif
220.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
221_ILINKS+=include/x86
222.endif
223CFLAGS+= -Iinclude
224CLEANDIRS+= include
225
226beforedepend: ${_ILINKS}
227beforebuild: ${_ILINKS}
228
229# Ensure that the links exist without depending on it when it exists which
230# causes all the modules to be rebuilt when the directory pointed to changes.
231.for _link in ${_ILINKS}
232.if !exists(${.OBJDIR}/${_link})
233${OBJS}:       ${_link}
234.endif # _link exists
235.endfor
236
237.NOPATH: ${_ILINKS}
238
239${_ILINKS}: .NOMETA
240	@case ${.TARGET:T} in \
241	machine) \
242		if [ ${DO32:U0} -eq 0 ]; then \
243			path=${SYSDIR}/${MACHINE}/include ; \
244		else \
245			path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \
246		fi ;; \
247	*) \
248		path=${SYSDIR}/${.TARGET:T}/include ;; \
249	esac ; \
250	case ${.TARGET} in \
251	*/*) mkdir -p ${.TARGET:H};; \
252	esac ; \
253	path=`(cd $$path && /bin/pwd)` ; \
254	${ECHO} ${.TARGET} "->" $$path ; \
255	ln -fns $$path ${.TARGET}
256.endif # !NO_OBJ
257.endif # __BOOT_DEFS_MK__
258