1ca987d46SWarner Losh# $FreeBSD$ 2ca987d46SWarner Losh 3ca987d46SWarner Losh.include <src.opts.mk> 4ca987d46SWarner Losh 5a9839149SWarner LoshWARNS?=1 61227a4f4SWarner Losh 7ca987d46SWarner Losh.if !defined(__BOOT_DEFS_MK__) 8ca987d46SWarner Losh__BOOT_DEFS_MK__=${MFILE} 9ca987d46SWarner 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 19ca987d46SWarner LoshBOOTSRC= ${SRCTOP}/stand 20ca987d46SWarner LoshEFISRC= ${BOOTSRC}/efi 21ca987d46SWarner LoshEFIINC= ${EFISRC}/include 22ca987d46SWarner LoshEFIINCMD= ${EFIINC}/${MACHINE} 23ca987d46SWarner LoshFDTSRC= ${BOOTSRC}/fdt 24ca987d46SWarner LoshFICLSRC= ${BOOTSRC}/ficl 25ca987d46SWarner LoshLDRSRC= ${BOOTSRC}/common 267cafeaa1SWarner LoshLIBLUASRC= ${BOOTSRC}/liblua 277cafeaa1SWarner LoshLUASRC= ${SRCTOP}/contrib/lua/src 28ca987d46SWarner LoshSASRC= ${BOOTSRC}/libsa 29ca987d46SWarner LoshSYSDIR= ${SRCTOP}/sys 30ca987d46SWarner LoshUBOOTSRC= ${BOOTSRC}/uboot 31b8902de1SWarner LoshZFSSRC= ${SASRC}/zfs 32ca987d46SWarner Losh 33ca987d46SWarner LoshBOOTOBJ= ${OBJTOP}/stand 34ca987d46SWarner Losh 35ca987d46SWarner Losh# BINDIR is where we install 36ca987d46SWarner LoshBINDIR?= /boot 37ca987d46SWarner Losh 38ca987d46SWarner LoshLIBSA= ${BOOTOBJ}/libsa/libsa.a 39ca987d46SWarner Losh.if ${MACHINE} == "i386" 40ca987d46SWarner LoshLIBSA32= ${LIBSA} 41ca987d46SWarner Losh.else 42ca987d46SWarner LoshLIBSA32= ${BOOTOBJ}/libsa32/libsa32.a 43ca987d46SWarner Losh.endif 44ca987d46SWarner Losh 45ca987d46SWarner Losh# Standard options: 4605f37f4dSWarner LoshCFLAGS+= -nostdinc 4705f37f4dSWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 4805f37f4dSWarner LoshCFLAGS+= -I${BOOTOBJ}/libsa32 4905f37f4dSWarner Losh.else 5005f37f4dSWarner LoshCFLAGS+= -I${BOOTOBJ}/libsa 5105f37f4dSWarner Losh.endif 52b65d7763SWarner LoshCFLAGS+= -I${SASRC} -D_STANDALONE 534f6b2874SWarner LoshCFLAGS+= -I${SYSDIR} 54ef1fcaf0SWarner Losh# Spike the floating point interfaces 55e52cfb3eSWarner LoshCFLAGS+= -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface 56f835d609SWarner Losh# Slim down the image. This saves about 15% in size with clang 6 on x86 57f835d609SWarner Losh# Our most constrained /boot/loader env is BIOS booting on x86, where 58f835d609SWarner Losh# our text + data + BTX have to fit into 640k below the ISA hole. 59f835d609SWarner Losh# Experience has shown that problems arise between ~520k to ~530k. 60f835d609SWarner LoshCFLAGS.clang+= -Oz 61f835d609SWarner LoshCFLAGS.gcc+= -Os 62ca987d46SWarner Losh 635ba722feSWarner Losh# GELI Support, with backward compat hooks (mostly) 64ca987d46SWarner Losh.if defined(LOADER_NO_GELI_SUPPORT) 65ca987d46SWarner LoshMK_LOADER_GELI=no 66ca987d46SWarner Losh.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI" 67ca987d46SWarner Losh.endif 68ca987d46SWarner Losh.if defined(LOADER_GELI_SUPPORT) 69ca987d46SWarner LoshMK_LOADER_GELI=yes 70ca987d46SWarner Losh.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI" 71ca987d46SWarner Losh.endif 72ca987d46SWarner Losh.if ${MK_LOADER_GELI} == "yes" 73ca987d46SWarner LoshCFLAGS+= -DLOADER_GELI_SUPPORT 7462bd02ceSWarner LoshCFLAGS+= -I${SASRC}/geli 754927bbceSWarner Losh.endif # MK_LOADER_GELI 76ca987d46SWarner Losh 778701bb8fSWarner Losh# These should be confined to loader.mk, but can't because uboot/lib 788701bb8fSWarner Losh# also uses it. It's part of loader, but isn't a loader so we can't 798701bb8fSWarner Losh# just include loader.mk 808701bb8fSWarner Losh.if ${LOADER_DISK_SUPPORT:Uyes} == "yes" 818701bb8fSWarner LoshCFLAGS+= -DLOADER_DISK_SUPPORT 828701bb8fSWarner Losh.endif 838701bb8fSWarner Losh 844f6b2874SWarner Losh# Machine specific flags for all builds here 85ca987d46SWarner Losh 86ca987d46SWarner Losh# All PowerPC builds are 32 bit. We have no 64-bit loaders on powerpc 87ca987d46SWarner Losh# or powerpc64. 88ca987d46SWarner Losh.if ${MACHINE_ARCH} == "powerpc64" 89ca987d46SWarner LoshCFLAGS+= -m32 -mcpu=powerpc 90ca987d46SWarner Losh.endif 91ca987d46SWarner Losh 92ca987d46SWarner Losh# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is 93ca987d46SWarner Losh# build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here 94ca987d46SWarner Losh# and activate it when DO32 is explicitly defined to be 1. 95ca987d46SWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 96073193edSDimitry AndricCFLAGS+= -m32 97ca987d46SWarner Losh# LD_FLAGS is passed directly to ${LD}, not via ${CC}: 98ca987d46SWarner LoshLD_FLAGS+= -m elf_i386_fbsd 99ca987d46SWarner LoshAFLAGS+= --32 100ca987d46SWarner Losh.endif 101ca987d46SWarner Losh 1024f6b2874SWarner LoshSSP_CFLAGS= 1034f6b2874SWarner Losh 1044f6b2874SWarner Losh# Add in the no float / no SIMD stuff and announce we're freestanding 1054f6b2874SWarner Losh# aarch64 and riscv don't have -msoft-float, but all others do. riscv 1064f6b2874SWarner Losh# currently has no /boot/loader, but may soon. 1074f6b2874SWarner LoshCFLAGS+= -ffreestanding ${CFLAGS_NO_SIMD} 1084f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "aarch64" 109fcdb1f03SWarner LoshCFLAGS+= -mgeneral-regs-only -fPIC 110fcdb1f03SWarner Losh.elif ${MACHINE_CPUARCH} == "riscv" 111*888c8381SRuslan BukinCFLAGS+= -march=rv64imac -mabi=lp64 112fcdb1f03SWarner Losh.else 1134f6b2874SWarner LoshCFLAGS+= -msoft-float 1144f6b2874SWarner Losh.endif 1154f6b2874SWarner Losh 1164f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1) 1174f6b2874SWarner LoshCFLAGS+= -march=i386 1184f6b2874SWarner LoshCFLAGS.gcc+= -mpreferred-stack-boundary=2 1194f6b2874SWarner Losh.endif 120fcdb1f03SWarner Losh.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 121fcdb1f03SWarner LoshCFLAGS+= -fPIC -mno-red-zone 122fcdb1f03SWarner Losh.endif 1234f6b2874SWarner Losh 1244f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "arm" 1254f6b2874SWarner Losh# Do not generate movt/movw, because the relocation fixup for them does not 1264f6b2874SWarner Losh# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8). 1274f6b2874SWarner Losh# Also, the fpu is not available in a standalone environment. 1284f6b2874SWarner Losh.if ${COMPILER_VERSION} < 30800 1294f6b2874SWarner LoshCFLAGS.clang+= -mllvm -arm-use-movt=0 1304f6b2874SWarner Losh.else 1314f6b2874SWarner LoshCFLAGS.clang+= -mno-movt 1324f6b2874SWarner Losh.endif 1334f6b2874SWarner LoshCFLAGS.clang+= -mfpu=none 134fcdb1f03SWarner LoshCFLAGS+= -fPIC 1354f6b2874SWarner Losh.endif 1364f6b2874SWarner Losh 1374f6b2874SWarner Losh# The boot loader build uses dd status=none, where possible, for reproducible 1384f6b2874SWarner Losh# build output (since performance varies from run to run). Trouble is that 1394f6b2874SWarner Losh# option was recently (10.3) added to FreeBSD and is non-standard. Only use it 1404f6b2874SWarner Losh# when this test succeeds rather than require dd to be a bootstrap tool. 1414f6b2874SWarner LoshDD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true 1424f6b2874SWarner LoshDD=dd ${DD_NOSTATUS} 1434f6b2874SWarner Losh 144fcdb1f03SWarner Losh.if ${MACHINE_CPUARCH} == "mips" 145fcdb1f03SWarner LoshCFLAGS+= -G0 -fno-pic -mno-abicalls 146fcdb1f03SWarner Losh.endif 147fcdb1f03SWarner Losh 1484f6b2874SWarner Losh.if ${MK_LOADER_FORCE_LE} != "no" 1494f6b2874SWarner Losh.if ${MACHINE_ARCH} == "powerpc64" 1504f6b2874SWarner LoshCFLAGS+= -mlittle-endian 1514f6b2874SWarner Losh.endif 1524f6b2874SWarner Losh.endif 1534f6b2874SWarner Losh 1549d45c24cSWarner Losh# 1559d45c24cSWarner Losh# Have a sensible default 1569d45c24cSWarner Losh# 157f9f8ac94SKyle Evans.if ${MK_LOADER_LUA} == "yes" 1589d45c24cSWarner LoshLOADER_DEFAULT_INTERP?=lua 159f9f8ac94SKyle Evans.elif ${MK_FORTH} == "yes" 160f9f8ac94SKyle EvansLOADER_DEFAULT_INTERP?=4th 1619d45c24cSWarner Losh.else 1629d45c24cSWarner LoshLOADER_DEFAULT_INTERP?=simp 1639d45c24cSWarner Losh.endif 1649d45c24cSWarner LoshLOADER_INTERP?=${LOADER_DEFAULT_INTERP} 1659d45c24cSWarner Losh 166ca987d46SWarner Losh# Make sure we use the machine link we're about to create 167ca987d46SWarner LoshCFLAGS+=-I. 168ca987d46SWarner Losh 169a0139c46SWarner Loshall: ${PROG} 170a0139c46SWarner Losh 171a0139c46SWarner Losh.if !defined(NO_OBJ) 172ca987d46SWarner Losh_ILINKS=machine 173ca987d46SWarner Losh.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" 174ca987d46SWarner Losh_ILINKS+=${MACHINE_CPUARCH} 175ca987d46SWarner Losh.endif 176ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 177ca987d46SWarner Losh_ILINKS+=x86 178ca987d46SWarner Losh.endif 179ca987d46SWarner LoshCLEANFILES+=${_ILINKS} 180ca987d46SWarner Losh 181ca987d46SWarner Loshbeforedepend: ${_ILINKS} 182ca987d46SWarner Loshbeforebuild: ${_ILINKS} 183ca987d46SWarner Losh 184ca987d46SWarner Losh# Ensure that the links exist without depending on it when it exists which 185ca987d46SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 186ca987d46SWarner Losh.for _link in ${_ILINKS} 187ca987d46SWarner Losh.if !exists(${.OBJDIR}/${_link}) 188ca987d46SWarner Losh${OBJS}: ${_link} 189a0139c46SWarner Losh.endif # _link exists 190ca987d46SWarner Losh.endfor 191ca987d46SWarner Losh 192ca987d46SWarner Losh.NOPATH: ${_ILINKS} 193ca987d46SWarner Losh 194ca987d46SWarner Losh${_ILINKS}: 195ca987d46SWarner Losh @case ${.TARGET} in \ 196ca987d46SWarner Losh machine) \ 197ca987d46SWarner Losh if [ ${DO32:U0} -eq 0 ]; then \ 198ca987d46SWarner Losh path=${SYSDIR}/${MACHINE}/include ; \ 199ca987d46SWarner Losh else \ 200ca987d46SWarner Losh path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \ 201ca987d46SWarner Losh fi ;; \ 202ca987d46SWarner Losh *) \ 203ca987d46SWarner Losh path=${SYSDIR}/${.TARGET:T}/include ;; \ 204ca987d46SWarner Losh esac ; \ 205ca987d46SWarner Losh path=`(cd $$path && /bin/pwd)` ; \ 206ca987d46SWarner Losh ${ECHO} ${.TARGET:T} "->" $$path ; \ 207ca987d46SWarner Losh ln -fhs $$path ${.TARGET:T} 208a0139c46SWarner Losh.endif # !NO_OBJ 209ca987d46SWarner Losh.endif # __BOOT_DEFS_MK__ 210