xref: /freebsd/stand/defs.mk (revision 25c2f4cb95686fa3dc2144872abe6df2a983c608)
1# $FreeBSD$
2
3.include <src.opts.mk>
4
5WARNS?=1
6
7.if !defined(__BOOT_DEFS_MK__)
8__BOOT_DEFS_MK__=${MFILE}
9
10BOOTSRC=	${SRCTOP}/stand
11EFISRC=		${BOOTSRC}/efi
12EFIINC=		${EFISRC}/include
13EFIINCMD=	${EFIINC}/${MACHINE}
14FDTSRC=		${BOOTSRC}/fdt
15FICLSRC=	${BOOTSRC}/ficl
16LDRSRC=		${BOOTSRC}/common
17SASRC=		${BOOTSRC}/libsa
18SYSDIR=		${SRCTOP}/sys
19UBOOTSRC=	${BOOTSRC}/uboot
20ZFSSRC=		${BOOTSRC}/zfs
21
22BOOTOBJ=	${OBJTOP}/stand
23
24# BINDIR is where we install
25BINDIR?=	/boot
26
27# NB: The makefiles depend on these being empty when we don't build forth.
28.if ${MK_FORTH} != "no"
29LIBFICL=	${BOOTOBJ}/ficl/libficl.a
30.if ${MACHINE} == "i386"
31LIBFICL32=	${LIBFICL}
32.else
33LIBFICL32=	${BOOTOBJ}/ficl32/libficl.a
34.endif
35.endif
36LIBSA=		${BOOTOBJ}/libsa/libsa.a
37.if ${MACHINE} == "i386"
38LIBSA32=	${LIBSA}
39.else
40LIBSA32=	${BOOTOBJ}/libsa32/libsa32.a
41.endif
42
43# Standard options:
44CFLAGS+=	-nostdinc
45.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
46CFLAGS+=	-I${BOOTOBJ}/libsa32
47.else
48CFLAGS+=	-I${BOOTOBJ}/libsa
49.endif
50CFLAGS+=	-I${SASRC} -D_STANDALONE
51CFLAGS+=	-I${SYSDIR}
52
53# GELI Support, with backward compat hooks (mostly)
54.if defined(HAVE_GELI)
55.if defined(LOADER_NO_GELI_SUPPORT)
56MK_LOADER_GELI=no
57.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI"
58.endif
59.if defined(LOADER_GELI_SUPPORT)
60MK_LOADER_GELI=yes
61.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI"
62.endif
63.if ${MK_LOADER_GELI} == "yes"
64CFLAGS+=	-DLOADER_GELI_SUPPORT
65CFLAGS+=	-I${BOOTSRC}/geli
66LIBGELIBOOT=	${BOOTOBJ}/geli/libgeliboot.a
67.endif # MK_LOADER_GELI
68.endif # HAVE_GELI
69
70# Machine specific flags for all builds here
71
72# All PowerPC builds are 32 bit. We have no 64-bit loaders on powerpc
73# or powerpc64.
74.if ${MACHINE_ARCH} == "powerpc64"
75CFLAGS+=	-m32 -mcpu=powerpc
76.endif
77
78# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is
79# build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here
80# and activate it when DO32 is explicitly defined to be 1.
81.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
82CFLAGS+=	-m32 -mcpu=i386
83# LD_FLAGS is passed directly to ${LD}, not via ${CC}:
84LD_FLAGS+=	-m elf_i386_fbsd
85AFLAGS+=	--32
86.endif
87
88SSP_CFLAGS=
89
90# Add in the no float / no SIMD stuff and announce we're freestanding
91# aarch64 and riscv don't have -msoft-float, but all others do. riscv
92# currently has no /boot/loader, but may soon.
93CFLAGS+=	-ffreestanding ${CFLAGS_NO_SIMD}
94.if ${MACHINE_CPUARCH} == "aarch64"
95CFLAGS+=	-mgeneral-regs-only
96.elif ${MACHINE_CPUARCH} != "riscv"
97CFLAGS+=	-msoft-float
98.endif
99
100.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1)
101CFLAGS+=	-march=i386
102CFLAGS.gcc+=	-mpreferred-stack-boundary=2
103.endif
104
105
106.if ${MACHINE_CPUARCH} == "arm"
107# Do not generate movt/movw, because the relocation fixup for them does not
108# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8).
109# Also, the fpu is not available in a standalone environment.
110.if ${COMPILER_VERSION} < 30800
111CFLAGS.clang+=	-mllvm -arm-use-movt=0
112.else
113CFLAGS.clang+=	-mno-movt
114.endif
115CFLAGS.clang+=  -mfpu=none
116.endif
117
118# The boot loader build uses dd status=none, where possible, for reproducible
119# build output (since performance varies from run to run). Trouble is that
120# option was recently (10.3) added to FreeBSD and is non-standard. Only use it
121# when this test succeeds rather than require dd to be a bootstrap tool.
122DD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true
123DD=dd ${DD_NOSTATUS}
124
125.if ${MK_LOADER_FORCE_LE} != "no"
126.if ${MACHINE_ARCH} == "powerpc64"
127CFLAGS+=	-mlittle-endian
128.endif
129.endif
130
131# Make sure we use the machine link we're about to create
132CFLAGS+=-I.
133
134_ILINKS=machine
135.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
136_ILINKS+=${MACHINE_CPUARCH}
137.endif
138.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
139_ILINKS+=x86
140.endif
141CLEANFILES+=${_ILINKS}
142
143all: ${PROG}
144
145beforedepend: ${_ILINKS}
146beforebuild: ${_ILINKS}
147
148# Ensure that the links exist without depending on it when it exists which
149# causes all the modules to be rebuilt when the directory pointed to changes.
150.for _link in ${_ILINKS}
151.if !exists(${.OBJDIR}/${_link})
152${OBJS}:       ${_link}
153.endif
154.endfor
155
156.NOPATH: ${_ILINKS}
157
158${_ILINKS}:
159	@case ${.TARGET} in \
160	machine) \
161		if [ ${DO32:U0} -eq 0 ]; then \
162			path=${SYSDIR}/${MACHINE}/include ; \
163		else \
164			path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \
165		fi ;; \
166	*) \
167		path=${SYSDIR}/${.TARGET:T}/include ;; \
168	esac ; \
169	path=`(cd $$path && /bin/pwd)` ; \
170	${ECHO} ${.TARGET:T} "->" $$path ; \
171	ln -fhs $$path ${.TARGET:T}
172
173.endif # __BOOT_DEFS_MK__
174