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