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