]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/build/Makefile
zfs: merge OpenZFS master-bf156c966
[FreeBSD/FreeBSD.git] / tools / build / Makefile
1 # $FreeBSD$
2
3 .PATH: ${.CURDIR}/../../include
4
5 LIB=            egacy
6 SRC=
7 INCSGROUPS=     INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS
8 INCSGROUPS+=    MACHINESYSINCS RPCINCS
9 INCS=
10
11 SYSINCSDIR=     ${INCLUDEDIR}/sys
12 CASPERINCDIR=   ${INCLUDEDIR}/casper
13 # Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool
14 UFSINCSDIR=     ${INCLUDEDIR}/ufs/ufs
15 FFSINCSDIR=     ${INCLUDEDIR}/ufs/ffs
16 MSDOSFSINCSDIR= ${INCLUDEDIR}/fs/msdosfs
17 DISKINCSDIR=    ${INCLUDEDIR}/sys/disk
18 MACHINESYSINCSDIR=      ${INCLUDEDIR}/machine
19 RPCINCSDIR=     ${INCLUDEDIR}/rpc
20
21 BOOTSTRAPPING?= 0
22
23
24 .if ${.MAKE.OS} == "Darwin"
25 _XCODE_ROOT!=xcode-select -p
26 # since macOS 10.14 C headers are no longer installed in /usr but only
27 # provided via the SDK
28 .if ${_XCODE_ROOT} == "/Library/Developer/CommandLineTools"
29 # Only command line tools installed -> host headers are in the SDKs directory
30 _MACOS_SDK_DIR=${_XCODE_ROOT}/SDKs/MacOSX.sdk/
31 .else
32 # Full XCode installed -> host headers are below Platforms/MacOSX.platform
33 _MACOS_SDK_DIR=${_XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
34 .endif
35 HOST_INCLUDE_ROOT=${_MACOS_SDK_DIR}/usr/include
36 .if !exists(${HOST_INCLUDE_ROOT}/stdio.h)
37 .error "You must install the macOS SDK (try xcode-select --install)"
38 .endif
39 .else
40 HOST_INCLUDE_ROOT=/usr/include
41 .endif
42
43 # Allow building libc-internal files (also on non-FreeBSD hosts)
44 CFLAGS+=        -I${.CURDIR}/libc-bootstrap
45 # Symbol versioning is not required for -legacy (and macOS bootstrap)
46 MK_SYMVER=      no
47
48 _WITH_PWCACHEDB!= grep -c pwcache_groupdb ${HOST_INCLUDE_ROOT}/grp.h || true
49 .if ${_WITH_PWCACHEDB} == 0
50 .PATH: ${.CURDIR}/../../contrib/libc-pwcache
51 CFLAGS.pwcache.c+=      -I${.CURDIR}/../../contrib/libc-pwcache
52 SRCS+=          pwcache.c
53 .endif
54
55 _WITH_STRSVIS!= grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true
56 .if ${_WITH_STRSVIS} == 0
57 .PATH: ${.CURDIR}/../../contrib/libc-vis
58 INCS+=          vis.h
59 SRCS+=          vis.c unvis.c
60 CFLAGS.vis.c+=  -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0
61 CFLAGS.unvis.c+=        -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0
62 .endif
63
64 _WITH_REALLOCARRAY!= grep -c reallocarray ${HOST_INCLUDE_ROOT}/stdlib.h || true
65 .if ${_WITH_REALLOCARRAY} == 0
66 .PATH: ${.CURDIR}/../../lib/libc/stdlib
67 INCS+=          stdlib.h
68 SRCS+=          reallocarray.c
69 .endif
70
71 _WITH_UTIMENS!= grep -c utimensat ${HOST_INCLUDE_ROOT}/sys/stat.h || true
72 .if ${_WITH_UTIMENS} == 0
73 SYSINCS+=       stat.h
74 SRCS+=          futimens.c utimensat.c
75 .endif
76
77 _WITH_EXPLICIT_BZERO!= grep -c explicit_bzero ${HOST_INCLUDE_ROOT}/strings.h || true
78 .if ${_WITH_EXPLICIT_BZERO} == 0
79 # .PATH: ${SRCTOP}/sys/libkern
80 # Adding sys/libkern to .PATH breaks building the cross-build compat library
81 # since that attempts to build strlcpy.c from libc and adding libkern here will
82 # cause it to pick the file from libkern instead (which won't compile).
83 # Avoid modifying .PATH by creating a copy in the build directory instead.
84 explicit_bzero.c: ${SRCTOP}/sys/libkern/explicit_bzero.c
85         cp ${.ALLSRC} ${.TARGET}
86 CLEANFILES+=    explicit_bzero.c
87 INCS+=          strings.h
88 SRCS+=          explicit_bzero.c
89 .endif
90
91
92 .if exists(${HOST_INCLUDE_ROOT}/capsicum_helpers.h)
93 _WITH_CAPH_ENTER!= grep -c caph_enter ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true
94 _WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true
95 .endif
96 .if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0
97 .PATH: ${SRCTOP}/lib/libcapsicum
98 INCS+=          capsicum_helpers.h
99 .PATH: ${SRCTOP}/lib/libcasper/libcasper
100 INCS+=          libcasper.h
101 .endif
102
103 # rpcgen should build against the source tree rpc/types.h and not the host.
104 # This is especially important on non-FreeBSD systems where the types may
105 # not match.
106 RPCINCS+=       ${SRCTOP}/sys/rpc/types.h
107
108 INCS+=  ${SRCTOP}/include/mpool.h
109 INCS+=  ${SRCTOP}/include/ndbm.h
110 INCS+=  ${SRCTOP}/include/err.h
111 INCS+=  ${SRCTOP}/include/stringlist.h
112
113 # Needed to build arc4random.c
114 INCSGROUPS+=    CHACHA20INCS
115 CHACHA20INCSDIR=        ${INCLUDEDIR}/crypto/chacha20
116 CHACHA20INCS+=  ${SRCTOP}/sys/crypto/chacha20/_chacha.h \
117         ${SRCTOP}/sys/crypto/chacha20/chacha.h
118
119 _host_arch=${MACHINE}
120 .if ${_host_arch} == "x86_64"
121 # bmake on Linux/mac often prints that instead of amd64
122 _host_arch=amd64
123 .endif
124 .if ${_host_arch} == "unknown"
125 # HACK: If MACHINE is unknown, assume we are building on x86
126 _host_arch=amd64
127 .endif
128 MACHINESYSINCS+=        ${SRCTOP}/sys/${_host_arch}/include/elf.h
129 .if ${_host_arch} == "amd64" || ${_host_arch} == "i386"
130 INCSGROUPS+=    X86INCS
131 X86INCSDIR=     ${INCLUDEDIR}/x86
132 X86INCS+=       ${SRCTOP}/sys/x86/include/elf.h
133 .endif
134
135 # needed for btxld:
136 MACHINESYSINCS+=        ${SRCTOP}/sys/${_host_arch}/include/exec.h
137 MACHINESYSINCS+=        ${SRCTOP}/sys/${_host_arch}/include/reloc.h
138 INCS+=  ${SRCTOP}/include/a.out.h
139 INCS+=  ${SRCTOP}/include/nlist.h
140 SYSINCS+=       ${SRCTOP}/sys/sys/imgact_aout.h
141 SYSINCS+=       ${SRCTOP}/sys/sys/nlist_aout.h
142
143
144 .if ${.MAKE.OS} != "FreeBSD"
145 .PATH: ${.CURDIR}/cross-build
146 # dbopen() behaves differently on Linux and FreeBSD so we ensure that we
147 # bootstrap the FreeBSD db code. The cross-build headers #define dbopen() to
148 # __freebsd_dbopen() so that we don't ever use the host version
149 INCS+=  ${SRCTOP}/include/db.h
150 LIBC_SRCTOP=    ${SRCTOP}/lib/libc/
151 .include "${LIBC_SRCTOP}/db/Makefile.inc"
152 # Do the same as we did for dbopen() for getopt() on since it's not compatible
153 # on Linux (and to avoid surprises also compile the FreeBSD code on macOS)
154 .PATH: ${LIBC_SRCTOP}/stdlib
155 SRCS+=  getopt.c getopt_long.c
156 INCS+=   ${SRCTOP}/include/getopt.h
157
158 # getcap.c is needed for cap_mkdb:
159 .PATH: ${LIBC_SRCTOP}/gen
160 SRCS+=  getcap.c
161 # Glibc does not provide all err*/warn* functions, and for macOS we need the
162 # alias with the extra underscore.
163 SRCS+=  err.c
164 # Add various libbc functions that are not available in glibc:
165 SRCS+=  stringlist.c setmode.c
166 SRCS+=  strtonum.c merge.c heapsort.c reallocf.c
167 .PATH: ${LIBC_SRCTOP}/locale
168 SRCS+=  rpmatch.c
169
170 .if ${.MAKE.OS} == "Linux"
171 # On Linux, glibc does not provide strlcpy,strlcat or strmode.
172 .PATH: ${LIBC_SRCTOP}/string
173 SRCS+=  strlcpy.c strlcat.c strmode.c
174 # Compile the fgetln/fgetwln/closefrom fallback code from libbsd:
175 SRCS+=  fgetln_fallback.c fgetwln_fallback.c closefrom.c
176 CFLAGS.closefrom.c+=    -DSTDC_HEADERS -DHAVE_SYS_DIR_H -DHAVE_DIRENT_H \
177         -DHAVE_DIRFD -DHAVE_SYSCONF
178 # Provide getprogname/setprograme
179 SRCS+=  progname.c
180 # Stub implementations of fflagstostr/strtofflags
181 SRCS+=  fflags.c
182 .endif
183 # Provide the same arc4random implementation on Linux/macOS
184 CFLAGS.arc4random.c+=   -I${SRCTOP}/sys/crypto/chacha20 -D__isthreaded=1
185 SRCS+=  arc4random.c arc4random_uniform.c
186
187 # expand_number() is not provided by either Linux or MacOS libutil
188 .PATH: ${SRCTOP}/lib/libutil
189 SRCS+=  expand_number.c
190 # Linux libutil also doesn't have fparseln
191 SRCS+=  fparseln.c
192 # A dummy sysctl for tzsetup:
193 SRCS+=  fake_sysctl.c
194
195 # capsicum support
196 SYSINCS+=       ${SRCTOP}/sys/sys/capsicum.h
197 SYSINCS+=       ${SRCTOP}/sys/sys/caprights.h
198 SRCS+=  capsicum_stubs.c
199 # XXX: we can't add ${SRCTOP}/sys/kern to .PATH since that will causes
200 # conflicts with other files. Instead copy subr_capability to the build dir.
201 subr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c
202         cp ${.ALLSRC} ${.TARGET}
203 SRCS+=  subr_capability.c
204 CLEANFILES+=    subr_capability.c
205 .endif
206
207 CASPERINC+=     ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h
208 CASPERINC+=     ${SRCTOP}/lib/libcasper/services/cap_net/cap_net.h
209
210 .if empty(SRCS)
211 SRCS=           dummy.c
212 .endif
213
214 .if defined(CROSS_BUILD_TESTING)
215 SUBDIR=         cross-build
216 .endif
217
218 # To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems:
219 UFSINCS+=       ${SRCTOP}/sys/ufs/ufs/dinode.h
220 UFSINCS+=       ${SRCTOP}/sys/ufs/ufs/dir.h
221 FFSINCS+=       ${SRCTOP}/sys/ufs/ffs/fs.h
222
223 MSDOSFSINCS+=   ${SRCTOP}/sys/fs/msdosfs/bootsect.h
224 MSDOSFSINCS+=   ${SRCTOP}/sys/fs/msdosfs/bpb.h
225 MSDOSFSINCS+=   ${SRCTOP}/sys/fs/msdosfs/denode.h
226 MSDOSFSINCS+=   ${SRCTOP}/sys/fs/msdosfs/direntry.h
227 MSDOSFSINCS+=   ${SRCTOP}/sys/fs/msdosfs/fat.h
228 MSDOSFSINCS+=   ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h
229 DISKINCS+=      ${SRCTOP}/sys/sys/disk/bsd.h
230
231 # Needed to build config (since it uses libnv)
232 SYSINCS+=       ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \
233                 ${SRCTOP}/sys/sys/dnv.h
234
235 # Needed when bootstrapping ldd (since it uses DF_1_PIE)
236 SYSINCS+=       ${SRCTOP}/sys/sys/elf32.h
237 SYSINCS+=       ${SRCTOP}/sys/sys/elf64.h
238 SYSINCS+=       ${SRCTOP}/sys/sys/elf_common.h
239 SYSINCS+=       ${SRCTOP}/sys/sys/elf_generic.h
240 SYSINCS+=       ${SRCTOP}/sys/sys/queue.h
241 SYSINCS+=       ${SRCTOP}/sys/sys/md5.h
242 SYSINCS+=       ${SRCTOP}/sys/sys/sbuf.h
243 SYSINCS+=       ${SRCTOP}/sys/sys/tree.h
244
245 # vtfontcvt is using sys/font.h
246 SYSINCS+=       ${SRCTOP}/sys/sys/font.h
247 # For mkscrfil.c:
248 SYSINCS+=       ${SRCTOP}/sys/sys/consio.h
249 # for gencat:
250 INCS+=  ${SRCTOP}/include/nl_types.h
251 # for vtfontcvt:
252 SYSINCS+=       ${SRCTOP}/sys/sys/fnv_hash.h
253 # opensolaris compatibility
254 INCS+=  ${SRCTOP}/include/elf.h
255 SYSINCS+=       ${SRCTOP}/sys/sys/elf.h
256
257 # We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
258 # accidentally run tools that are incompatible but happen to be in $PATH.
259 # This is especially important when building on Linux/MacOS where many of the
260 # programs used during the build accept different flags or generate different
261 # output. On those platforms we only symlink the tools known to be compatible
262 # (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
263 # from the FreeBSD sources during the bootstrap-tools stage.
264
265 # basic commands: It is fine to use the host version for all of these even on
266 # Linux/MacOS since we only use flags that are supported by all of them.
267 _host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \
268         dirname echo env false find fmt gzip gunzip head hostname id ln ls \
269         mkdir mv nice patch rm sh sleep stat tee touch tr true uname uniq unxz \
270         wc which xz
271
272 # We also need a symlink to the absolute path to the make binary used for
273 # the toplevel makefile. This is not necessarily the same as `which make`
274 # since e.g. on Linux and MacOS that will be GNU make.
275 _make_abs!=     which "${MAKE}"
276 _host_abs_tools_to_symlink=     ${_make_abs}:make ${_make_abs}:bmake
277
278 .if ${.MAKE.OS} == "FreeBSD"
279 # When building on FreeBSD we always copy the host tools instead of linking
280 # into WORLDTMP to avoid issues with incompatible libraries (see r364030).
281 # Note: we could create links if we don't intend to update the current machine.
282 _COPY_HOST_TOOL=cp -pf
283 .else
284 # However, this is not necessary on Linux/macOS. Additionally, copying the host
285 # tools to another directory with cp -p results in freezes on macOS Big Sur for
286 # some unknown reason. It can also break building inside docker containers if
287 # there are ACLs on shared volumes.
288 _COPY_HOST_TOOL=ln -sfn
289 _make_abs!=     which "${MAKE}"
290 _host_abs_tools_to_symlink+=    ${_make_abs}:make ${_make_abs}:bmake
291 .if ${.MAKE.OS} == "Darwin"
292 # /usr/bin/cpp may invoke xcrun:
293 _host_tools_to_symlink+=xcrun
294 .endif  # ${.MAKE.OS} == "Darwin"
295 # On Ubuntu /bin/sh is dash which is totally useless. Let's just link bash
296 # as the build sh since that will work fine.
297 _host_abs_tools_to_symlink+=    /bin/bash:sh
298 _host_tools_to_symlink:=${_host_tools_to_symlink:Nsh}
299 .endif
300
301 host-symlinks:
302         @echo "Linking host tools into ${DESTDIR}/bin"
303 .for _tool in ${_host_tools_to_symlink}
304         @export PATH=$${PATH}:/usr/local/bin; source_path=`which ${_tool}`; \
305         if [ ! -e "$${source_path}" ] ; then \
306                 echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \
307         fi; \
308         rm -f "${DESTDIR}/bin/${_tool}"; \
309         ${_COPY_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}"
310 .endfor
311 .for _tool in ${_host_abs_tools_to_symlink}
312         @source_path="${_tool:S/:/ /:[1]}"; \
313         target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \
314         if [ ! -e "$${source_path}" ] ; then \
315                 echo "Host tool '${src_path}' is missing"; false; \
316         fi; \
317         rm -f "$${target_path}"; \
318         ${_COPY_HOST_TOOL} "$${source_path}" "$${target_path}"
319 .endfor
320 .if exists(/usr/libexec/flua)
321         rm -f ${DESTDIR}/usr/libexec/flua
322         ${_COPY_HOST_TOOL} /usr/libexec/flua ${DESTDIR}/usr/libexec/flua
323 .endif
324
325 # Create all the directories that are needed during the legacy, bootstrap-tools
326 # and cross-tools stages. We do this here using mkdir since mtree may not exist
327 # yet (this happens if we are crossbuilding from Linux/Mac).
328 INSTALLDIR_LIST= \
329         bin \
330         lib/casper \
331         lib/geom \
332         usr/include/casper \
333         usr/include/private/ucl \
334         usr/include/private/zstd \
335         usr/lib \
336         usr/libexec
337
338 installdirs:
339         mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,}
340
341 # Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a
342 # bootstrap tool was added to WORLTMP with a symlink or by building it in the
343 # bootstrap-tools phase. We could also overrride BINDIR when building bootstrap
344 # tools but adding the symlinks is easier and means all tools are also
345 # in the directory that they are installed to normally.
346
347 .for _dir in sbin usr/sbin usr/bin
348 # delete existing directories from before r340157
349         @if [ -e ${DESTDIR}/${_dir} ] && [ ! -L ${DESTDIR}/${_dir} ]; then \
350             echo "removing old non-symlink ${DESTDIR}/${_dir}"; \
351             rm -rf "${DESTDIR}/${_dir}"; \
352         fi
353 .endfor
354         ln -sfn bin ${DESTDIR}/sbin
355         ln -sfn ../bin ${DESTDIR}/usr/bin
356         ln -sfn ../bin ${DESTDIR}/usr/sbin
357 .for _group in ${INCSGROUPS:NINCS}
358         mkdir -p "${DESTDIR}/${${_group}DIR}"
359 .endfor
360
361 .include <bsd.lib.mk>