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