1ca987d46SWarner Losh# $FreeBSD$ 2ca987d46SWarner Losh 3ca987d46SWarner Losh.if !defined(__BOOT_DEFS_MK__) 4ca987d46SWarner Losh__BOOT_DEFS_MK__=${MFILE} 5ca987d46SWarner Losh 6991699dbSWarner Losh# We need to define all the MK_ options before including src.opts.mk 7991699dbSWarner Losh# because it includes bsd.own.mk which needs the right MK_ values, 8991699dbSWarner Losh# espeically MK_CTF. 9991699dbSWarner Losh 108299b37fSWarner LoshMK_CTF= no 118299b37fSWarner LoshMK_SSP= no 128299b37fSWarner LoshMK_PROFILE= no 138299b37fSWarner LoshMAN= 1411421c37SWarner Losh.if !defined(PIC) 1511421c37SWarner LoshNO_PIC= 168299b37fSWarner LoshINTERNALLIB= 1711421c37SWarner Losh.endif 188299b37fSWarner Losh 19991699dbSWarner Losh.include <src.opts.mk> 20*5e697f5fSMitchell Horne.include <bsd.linker.mk> 21991699dbSWarner Losh 22991699dbSWarner LoshWARNS?= 1 23991699dbSWarner Losh 24ca987d46SWarner LoshBOOTSRC= ${SRCTOP}/stand 25ca987d46SWarner LoshEFISRC= ${BOOTSRC}/efi 26ca987d46SWarner LoshEFIINC= ${EFISRC}/include 27ca987d46SWarner LoshEFIINCMD= ${EFIINC}/${MACHINE} 28ca987d46SWarner LoshFDTSRC= ${BOOTSRC}/fdt 29ca987d46SWarner LoshFICLSRC= ${BOOTSRC}/ficl 30ca987d46SWarner LoshLDRSRC= ${BOOTSRC}/common 317cafeaa1SWarner LoshLIBLUASRC= ${BOOTSRC}/liblua 32475008d6SBrandon BergrenLIBOFWSRC= ${BOOTSRC}/libofw 337cafeaa1SWarner LoshLUASRC= ${SRCTOP}/contrib/lua/src 34ca987d46SWarner LoshSASRC= ${BOOTSRC}/libsa 35ca987d46SWarner LoshSYSDIR= ${SRCTOP}/sys 36ca987d46SWarner LoshUBOOTSRC= ${BOOTSRC}/uboot 37b8902de1SWarner LoshZFSSRC= ${SASRC}/zfs 3880335781SKyle EvansLIBCSRC= ${SRCTOP}/lib/libc 39ca987d46SWarner Losh 40ca987d46SWarner LoshBOOTOBJ= ${OBJTOP}/stand 41ca987d46SWarner Losh 42ca987d46SWarner Losh# BINDIR is where we install 43ca987d46SWarner LoshBINDIR?= /boot 44ca987d46SWarner Losh 45ee74c236SKyle Evans# LUAPATH is where we search for and install lua scripts. 46ee74c236SKyle EvansLUAPATH?= /boot/lua 47506f3640SKyle EvansFLUASRC?= ${SRCTOP}/libexec/flua 48ee74c236SKyle Evans 49ca987d46SWarner LoshLIBSA= ${BOOTOBJ}/libsa/libsa.a 50ca987d46SWarner Losh.if ${MACHINE} == "i386" 51ca987d46SWarner LoshLIBSA32= ${LIBSA} 52ca987d46SWarner Losh.else 53ca987d46SWarner LoshLIBSA32= ${BOOTOBJ}/libsa32/libsa32.a 54ca987d46SWarner Losh.endif 55ca987d46SWarner Losh 56ca987d46SWarner Losh# Standard options: 5705f37f4dSWarner LoshCFLAGS+= -nostdinc 5805f37f4dSWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 5905f37f4dSWarner LoshCFLAGS+= -I${BOOTOBJ}/libsa32 6005f37f4dSWarner Losh.else 6105f37f4dSWarner LoshCFLAGS+= -I${BOOTOBJ}/libsa 6205f37f4dSWarner Losh.endif 63b65d7763SWarner LoshCFLAGS+= -I${SASRC} -D_STANDALONE 644f6b2874SWarner LoshCFLAGS+= -I${SYSDIR} 65ef1fcaf0SWarner Losh# Spike the floating point interfaces 66e52cfb3eSWarner LoshCFLAGS+= -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface 670125fb63SWarner Losh.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64" 68f835d609SWarner Losh# Slim down the image. This saves about 15% in size with clang 6 on x86 69f835d609SWarner Losh# Our most constrained /boot/loader env is BIOS booting on x86, where 70f835d609SWarner Losh# our text + data + BTX have to fit into 640k below the ISA hole. 71f835d609SWarner Losh# Experience has shown that problems arise between ~520k to ~530k. 72f835d609SWarner LoshCFLAGS.clang+= -Oz 73f835d609SWarner LoshCFLAGS.gcc+= -Os 74094b4065SToomas SoomeCFLAGS+= -ffunction-sections -fdata-sections 750125fb63SWarner Losh.endif 76ca987d46SWarner Losh 775ba722feSWarner Losh# GELI Support, with backward compat hooks (mostly) 78ca987d46SWarner Losh.if defined(LOADER_NO_GELI_SUPPORT) 79ca987d46SWarner LoshMK_LOADER_GELI=no 80ca987d46SWarner Losh.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI" 81ca987d46SWarner Losh.endif 82ca987d46SWarner Losh.if defined(LOADER_GELI_SUPPORT) 83ca987d46SWarner LoshMK_LOADER_GELI=yes 84ca987d46SWarner Losh.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI" 85ca987d46SWarner Losh.endif 86ca987d46SWarner Losh.if ${MK_LOADER_GELI} == "yes" 87ca987d46SWarner LoshCFLAGS+= -DLOADER_GELI_SUPPORT 8862bd02ceSWarner LoshCFLAGS+= -I${SASRC}/geli 894927bbceSWarner Losh.endif # MK_LOADER_GELI 90ca987d46SWarner Losh 918701bb8fSWarner Losh# These should be confined to loader.mk, but can't because uboot/lib 928701bb8fSWarner Losh# also uses it. It's part of loader, but isn't a loader so we can't 938701bb8fSWarner Losh# just include loader.mk 948701bb8fSWarner Losh.if ${LOADER_DISK_SUPPORT:Uyes} == "yes" 958701bb8fSWarner LoshCFLAGS+= -DLOADER_DISK_SUPPORT 968701bb8fSWarner Losh.endif 978701bb8fSWarner Losh 984f6b2874SWarner Losh# Machine specific flags for all builds here 99ca987d46SWarner Losh 100ca987d46SWarner Losh# All PowerPC builds are 32 bit. We have no 64-bit loaders on powerpc 101ca987d46SWarner Losh# or powerpc64. 102ca987d46SWarner Losh.if ${MACHINE_ARCH} == "powerpc64" 103ca987d46SWarner LoshCFLAGS+= -m32 -mcpu=powerpc 104ca987d46SWarner Losh.endif 105ca987d46SWarner Losh 106ca987d46SWarner Losh# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is 107ca987d46SWarner Losh# build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here 108ca987d46SWarner Losh# and activate it when DO32 is explicitly defined to be 1. 109ca987d46SWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 110073193edSDimitry AndricCFLAGS+= -m32 111ca987d46SWarner Losh# LD_FLAGS is passed directly to ${LD}, not via ${CC}: 112ca987d46SWarner LoshLD_FLAGS+= -m elf_i386_fbsd 113ca987d46SWarner LoshAFLAGS+= --32 114ca987d46SWarner Losh.endif 115ca987d46SWarner Losh 1164f6b2874SWarner LoshSSP_CFLAGS= 1174f6b2874SWarner Losh 1184f6b2874SWarner Losh# Add in the no float / no SIMD stuff and announce we're freestanding 1192192efc0SMitchell Horne# aarch64 and riscv don't have -msoft-float, but all others do. 1204f6b2874SWarner LoshCFLAGS+= -ffreestanding ${CFLAGS_NO_SIMD} 1214f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "aarch64" 122a2e2311aSAndrew TurnerCFLAGS+= -mgeneral-regs-only -ffixed-x18 -fPIC 123fcdb1f03SWarner Losh.elif ${MACHINE_CPUARCH} == "riscv" 1242192efc0SMitchell HorneCFLAGS+= -march=rv64imac -mabi=lp64 -fPIC 1252192efc0SMitchell HorneCFLAGS.clang+= -mcmodel=medium 1262192efc0SMitchell HorneCFLAGS.gcc+= -mcmodel=medany 127fcdb1f03SWarner Losh.else 1284f6b2874SWarner LoshCFLAGS+= -msoft-float 1294f6b2874SWarner Losh.endif 1304f6b2874SWarner Losh 13189797c88SJustin Hibbits# -msoft-float seems to be insufficient for powerpcspe 13289797c88SJustin Hibbits.if ${MACHINE_ARCH} == "powerpcspe" 13389797c88SJustin HibbitsCFLAGS+= -mno-spe 13489797c88SJustin Hibbits.endif 13589797c88SJustin Hibbits 1364f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1) 1374f6b2874SWarner LoshCFLAGS+= -march=i386 1384f6b2874SWarner LoshCFLAGS.gcc+= -mpreferred-stack-boundary=2 1394f6b2874SWarner Losh.endif 140fcdb1f03SWarner Losh.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 141fcdb1f03SWarner LoshCFLAGS+= -fPIC -mno-red-zone 142fcdb1f03SWarner Losh.endif 1434f6b2874SWarner Losh 1444f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "arm" 1454f6b2874SWarner Losh# Do not generate movt/movw, because the relocation fixup for them does not 1464f6b2874SWarner Losh# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8). 1474f6b2874SWarner Losh# Also, the fpu is not available in a standalone environment. 1484f6b2874SWarner LoshCFLAGS.clang+= -mno-movt 1494f6b2874SWarner LoshCFLAGS.clang+= -mfpu=none 150fcdb1f03SWarner LoshCFLAGS+= -fPIC 1514f6b2874SWarner Losh.endif 1524f6b2874SWarner Losh 1532192efc0SMitchell Horne# Some RISC-V linkers have support for relaxations, while some (lld) do not 1542192efc0SMitchell Horne# yet. If this is the case we inhibit the compiler from emitting relaxations. 155*5e697f5fSMitchell Horne.if ${LINKER_FEATURES:Mriscv-relaxations} == "" 1562192efc0SMitchell HorneCFLAGS+= -mno-relax 1572192efc0SMitchell Horne.endif 1582192efc0SMitchell Horne 1594f6b2874SWarner Losh# The boot loader build uses dd status=none, where possible, for reproducible 1604f6b2874SWarner Losh# build output (since performance varies from run to run). Trouble is that 1614f6b2874SWarner Losh# option was recently (10.3) added to FreeBSD and is non-standard. Only use it 1624f6b2874SWarner Losh# when this test succeeds rather than require dd to be a bootstrap tool. 1634f6b2874SWarner LoshDD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true 1644f6b2874SWarner LoshDD=dd ${DD_NOSTATUS} 1654f6b2874SWarner Losh 166fcdb1f03SWarner Losh.if ${MACHINE_CPUARCH} == "mips" 167fcdb1f03SWarner LoshCFLAGS+= -G0 -fno-pic -mno-abicalls 168fcdb1f03SWarner Losh.endif 169fcdb1f03SWarner Losh 1704f6b2874SWarner Losh.if ${MK_LOADER_FORCE_LE} != "no" 1714f6b2874SWarner Losh.if ${MACHINE_ARCH} == "powerpc64" 1724f6b2874SWarner LoshCFLAGS+= -mlittle-endian 1734f6b2874SWarner Losh.endif 1744f6b2874SWarner Losh.endif 1754f6b2874SWarner Losh 1769d45c24cSWarner Losh# 1779d45c24cSWarner Losh# Have a sensible default 1789d45c24cSWarner Losh# 179f9f8ac94SKyle Evans.if ${MK_LOADER_LUA} == "yes" 1809d45c24cSWarner LoshLOADER_DEFAULT_INTERP?=lua 181f9f8ac94SKyle Evans.elif ${MK_FORTH} == "yes" 182f9f8ac94SKyle EvansLOADER_DEFAULT_INTERP?=4th 1839d45c24cSWarner Losh.else 1849d45c24cSWarner LoshLOADER_DEFAULT_INTERP?=simp 1859d45c24cSWarner Losh.endif 1869d45c24cSWarner LoshLOADER_INTERP?=${LOADER_DEFAULT_INTERP} 1879d45c24cSWarner Losh 188ca987d46SWarner Losh# Make sure we use the machine link we're about to create 189ca987d46SWarner LoshCFLAGS+=-I. 190ca987d46SWarner Losh 191a0139c46SWarner Loshall: ${PROG} 192a0139c46SWarner Losh 19356758831SToomas SoomeCLEANFILES+= teken_state.h 19456758831SToomas Soometeken.c: teken_state.h 19556758831SToomas Soome 19656758831SToomas Soometeken_state.h: ${SYSDIR}/teken/sequences 19756758831SToomas Soome awk -f ${SYSDIR}/teken/gensequences \ 19856758831SToomas Soome ${SYSDIR}/teken/sequences > teken_state.h 19956758831SToomas Soome 200a0139c46SWarner Losh.if !defined(NO_OBJ) 201e9b148a3SSimon J. Gerraty_ILINKS=include/machine 202ca987d46SWarner Losh.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" 203e9b148a3SSimon J. Gerraty_ILINKS+=include/${MACHINE_CPUARCH} 204ca987d46SWarner Losh.endif 205ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 206e9b148a3SSimon J. Gerraty_ILINKS+=include/x86 207ca987d46SWarner Losh.endif 208e9b148a3SSimon J. GerratyCFLAGS+= -Iinclude 209e9b148a3SSimon J. GerratyCLEANDIRS+= include 210ca987d46SWarner Losh 211ca987d46SWarner Loshbeforedepend: ${_ILINKS} 212ca987d46SWarner Loshbeforebuild: ${_ILINKS} 213ca987d46SWarner Losh 214ca987d46SWarner Losh# Ensure that the links exist without depending on it when it exists which 215ca987d46SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 216ca987d46SWarner Losh.for _link in ${_ILINKS} 217ca987d46SWarner Losh.if !exists(${.OBJDIR}/${_link}) 218ca987d46SWarner Losh${OBJS}: ${_link} 219a0139c46SWarner Losh.endif # _link exists 220ca987d46SWarner Losh.endfor 221ca987d46SWarner Losh 222ca987d46SWarner Losh.NOPATH: ${_ILINKS} 223ca987d46SWarner Losh 224e9b148a3SSimon J. Gerraty${_ILINKS}: .NOMETA 225e9b148a3SSimon J. Gerraty @case ${.TARGET:T} in \ 226ca987d46SWarner Losh machine) \ 227ca987d46SWarner Losh if [ ${DO32:U0} -eq 0 ]; then \ 228ca987d46SWarner Losh path=${SYSDIR}/${MACHINE}/include ; \ 229ca987d46SWarner Losh else \ 230ca987d46SWarner Losh path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \ 231ca987d46SWarner Losh fi ;; \ 232ca987d46SWarner Losh *) \ 233ca987d46SWarner Losh path=${SYSDIR}/${.TARGET:T}/include ;; \ 234ca987d46SWarner Losh esac ; \ 235e9b148a3SSimon J. Gerraty case ${.TARGET} in \ 236e9b148a3SSimon J. Gerraty */*) mkdir -p ${.TARGET:H};; \ 237e9b148a3SSimon J. Gerraty esac ; \ 238ca987d46SWarner Losh path=`(cd $$path && /bin/pwd)` ; \ 239e9b148a3SSimon J. Gerraty ${ECHO} ${.TARGET} "->" $$path ; \ 240e9b148a3SSimon J. Gerraty ln -fhs $$path ${.TARGET} 241a0139c46SWarner Losh.endif # !NO_OBJ 242ca987d46SWarner Losh.endif # __BOOT_DEFS_MK__ 243