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