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