3 .if !defined(__BOOT_DEFS_MK__)
4 __BOOT_DEFS_MK__=${MFILE}
6 # We need to define all the MK_ options before including src.opts.mk
7 # because it includes bsd.own.mk which needs the right MK_ values,
19 # Should be NO_CPU_FLAGS, but bsd.cpu.mk is included too early in bsd.init.mk
20 # via the early include of bsd.opts.mk. Moving Makefile.inc include earlier in
21 # that file causes weirdness, so this is the next best thing. We need to do this
22 # because the loader needs very specific flags to work right, and things like
23 # CPUTYPE?=native prevent that, and introduce an endless game of whack-a-mole
24 # to disable more and more features. Boot loader performance is never improved
25 # enough to make that hassle worth chasing.
28 .include <src.opts.mk>
29 .include <bsd.linker.mk>
33 BOOTSRC= ${SRCTOP}/stand
34 EFISRC= ${BOOTSRC}/efi
35 EFIINC= ${EFISRC}/include
36 EFIINCMD= ${EFIINC}/${MACHINE}
37 FDTSRC= ${BOOTSRC}/fdt
38 FICLSRC= ${BOOTSRC}/ficl
39 LDRSRC= ${BOOTSRC}/common
40 LIBLUASRC= ${BOOTSRC}/liblua
41 LIBOFWSRC= ${BOOTSRC}/libofw
42 LUASRC= ${SRCTOP}/contrib/lua/src
43 SASRC= ${BOOTSRC}/libsa
45 UBOOTSRC= ${BOOTSRC}/uboot
47 OZFS= ${SRCTOP}/sys/contrib/openzfs
48 ZFSOSSRC= ${OZFS}/module/os/freebsd/
49 ZFSOSINC= ${OZFS}/include/os/freebsd
50 LIBCSRC= ${SRCTOP}/lib/libc
52 BOOTOBJ= ${OBJTOP}/stand
54 # BINDIR is where we install
57 # LUAPATH is where we search for and install lua scripts.
59 FLUASRC?= ${SRCTOP}/libexec/flua
61 LIBSA= ${BOOTOBJ}/libsa/libsa.a
62 .if ${MACHINE} == "i386"
65 LIBSA32= ${BOOTOBJ}/libsa32/libsa32.a
70 # Allow CFLAGS_EARLY.file/target so that code that needs specific stack
71 # of include paths can set them up before our include paths. Normally
72 # the only thing that should be there are -I directives, and as few of
74 CFLAGS+= ${CFLAGS_EARLY} ${CFLAGS_EARLY.${.IMPSRC:T}} ${CFLAGS_EARLY.${.TARGET:T}}
75 .if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
76 CFLAGS+= -I${BOOTOBJ}/libsa32
78 CFLAGS+= -I${BOOTOBJ}/libsa
80 CFLAGS+= -I${SASRC} -D_STANDALONE
82 # Spike the floating point interfaces
83 CFLAGS+= -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface
84 .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
85 # Slim down the image. This saves about 15% in size with clang 6 on x86
86 # Our most constrained /boot/loader env is BIOS booting on x86, where
87 # our text + data + BTX have to fit into 640k below the ISA hole.
88 # Experience has shown that problems arise between ~520k to ~530k.
91 CFLAGS+= -ffunction-sections -fdata-sections
94 # GELI Support, with backward compat hooks (mostly)
95 .if defined(LOADER_NO_GELI_SUPPORT)
97 .warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI"
99 .if defined(LOADER_GELI_SUPPORT)
101 .warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI"
103 .if ${MK_LOADER_GELI} == "yes"
104 CFLAGS+= -DLOADER_GELI_SUPPORT
105 CFLAGS+= -I${SASRC}/geli
106 .endif # MK_LOADER_GELI
108 # These should be confined to loader.mk, but can't because uboot/lib
109 # also uses it. It's part of loader, but isn't a loader so we can't
110 # just include loader.mk
111 .if ${LOADER_DISK_SUPPORT:Uyes} == "yes"
112 CFLAGS+= -DLOADER_DISK_SUPPORT
115 # Machine specific flags for all builds here
117 # Ensure PowerPC64 and PowerPC64LE boot loaders are compiled as 32 bit.
118 # PowerPC64LE boot loaders are 32-bit little-endian.
119 .if ${MACHINE_ARCH} == "powerpc64"
120 CFLAGS+= -m32 -mcpu=powerpc -mbig-endian
121 .elif ${MACHINE_ARCH} == "powerpc64le"
122 CFLAGS+= -m32 -mcpu=powerpc -mlittle-endian
125 # For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is
126 # build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here
127 # and activate it when DO32 is explicitly defined to be 1.
128 .if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
130 # LD_FLAGS is passed directly to ${LD}, not via ${CC}:
131 LD_FLAGS+= -m elf_i386_fbsd
135 # Add in the no float / no SIMD stuff and announce we're freestanding
136 # aarch64 and riscv don't have -msoft-float, but all others do.
137 CFLAGS+= -ffreestanding ${CFLAGS_NO_SIMD}
138 .if ${MACHINE_CPUARCH} == "aarch64"
139 CFLAGS+= -mgeneral-regs-only -ffixed-x18 -fPIC
140 .elif ${MACHINE_CPUARCH} == "riscv"
141 CFLAGS+= -march=rv64imac -mabi=lp64 -fPIC
142 CFLAGS.clang+= -mcmodel=medium
143 CFLAGS.gcc+= -mcmodel=medany
145 CFLAGS+= -msoft-float
148 # -msoft-float seems to be insufficient for powerpcspe
149 .if ${MACHINE_ARCH} == "powerpcspe"
153 .if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1)
155 CFLAGS.gcc+= -mpreferred-stack-boundary=2
157 .if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0
158 CFLAGS+= -fPIC -mno-red-zone
161 .if ${MACHINE_CPUARCH} == "arm"
162 # Do not generate movt/movw, because the relocation fixup for them does not
163 # translate to the -Bsymbolic -pie format required by self_reloc() in loader(8).
164 # Also, the fpu is not available in a standalone environment.
165 CFLAGS.clang+= -mno-movt
166 CFLAGS.clang+= -mfpu=none
170 # Some RISC-V linkers have support for relaxations, while some (lld) do not
171 # yet. If this is the case we inhibit the compiler from emitting relaxations.
172 .if ${LINKER_FEATURES:Mriscv-relaxations} == ""
176 # The boot loader build uses dd status=none, where possible, for reproducible
177 # build output (since performance varies from run to run). Trouble is that
178 # option was recently (10.3) added to FreeBSD and is non-standard. Only use it
179 # when this test succeeds rather than require dd to be a bootstrap tool.
180 DD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true
183 .if ${MACHINE_CPUARCH} == "mips"
184 CFLAGS+= -G0 -fno-pic -mno-abicalls
188 # Have a sensible default
190 .if ${MK_LOADER_LUA} == "yes"
191 LOADER_DEFAULT_INTERP?=lua
192 .elif ${MK_FORTH} == "yes"
193 LOADER_DEFAULT_INTERP?=4th
195 LOADER_DEFAULT_INTERP?=simp
197 LOADER_INTERP?=${LOADER_DEFAULT_INTERP}
199 # Make sure we use the machine link we're about to create
204 CLEANFILES+= teken_state.h
205 teken.c: teken_state.h
207 teken_state.h: ${SYSDIR}/teken/sequences
208 awk -f ${SYSDIR}/teken/gensequences \
209 ${SYSDIR}/teken/sequences > teken_state.h
212 _ILINKS=include/machine
213 .if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
214 _ILINKS+=include/${MACHINE_CPUARCH}
216 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
222 beforedepend: ${_ILINKS}
223 beforebuild: ${_ILINKS}
225 # Ensure that the links exist without depending on it when it exists which
226 # causes all the modules to be rebuilt when the directory pointed to changes.
227 .for _link in ${_ILINKS}
228 .if !exists(${.OBJDIR}/${_link})
230 .endif # _link exists
236 @case ${.TARGET:T} in \
238 if [ ${DO32:U0} -eq 0 ]; then \
239 path=${SYSDIR}/${MACHINE}/include ; \
241 path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \
244 path=${SYSDIR}/${.TARGET:T}/include ;; \
247 */*) mkdir -p ${.TARGET:H};; \
249 path=`(cd $$path && /bin/pwd)` ; \
250 ${ECHO} ${.TARGET} "->" $$path ; \
251 ln -fns $$path ${.TARGET}
253 .endif # __BOOT_DEFS_MK__