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