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