]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - Makefile.inc1
Update to bmake-20201101
[FreeBSD/FreeBSD.git] / Makefile.inc1
1 #
2 # $FreeBSD$
3 #
4 # Make command line options:
5 #       -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6 #       -DNO_CLEAN do not clean at all
7 #       -DDB_FROM_SRC use the user/group databases in src/etc instead of
8 #           the system database when installing.
9 #       -DNO_SHARE do not go into share subdir
10 #       -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,OBJ}
11 #       -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12 #       -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13 #       -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
14 #       -DNO_PORTSUPDATE do not update ports in ${MAKE} update
15 #       -DNO_ROOT install without using root privilege
16 #       -DNO_DOCUPDATE do not update doc in ${MAKE} update
17 #       -DWITHOUT_CTF do not run the DTrace CTF conversion tools on built objects
18 #       LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
19 #       LOCAL_ITOOLS="list of tools" to add additional tools to the ITOOLS list
20 #       LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
21 #       LOCAL_MTREE="list of mtree files" to process to allow local directories
22 #           to be created before files are installed
23 #       LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
24 #           list
25 #       LOCAL_XTOOL_DIRS="list of dirs" to add additional dirs to the
26 #           cross-tools target
27 #       METALOG="path to metadata log" to write permission and ownership
28 #           when NO_ROOT is set.  (default: ${DESTDIR}/${DISTDIR}/METALOG,
29 #           check /etc/make.conf for DISTDIR)
30 #       TARGET="machine" to crossbuild world for a different machine type
31 #       TARGET_ARCH= may be required when a TARGET supports multiple endians
32 #       BUILDENV_SHELL= shell to launch for the buildenv target (def:${SHELL})
33 #       WORLD_FLAGS= additional flags to pass to make(1) during buildworld
34 #       KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
35 #       SUBDIR_OVERRIDE="list of dirs" to build rather than everything.
36 #           All libraries and includes, and some build tools will still build.
37
38 #
39 # The intended user-driven targets are:
40 # buildworld  - rebuild *everything*, including glue to help do upgrades
41 # installworld- install everything built by "buildworld"
42 # checkworld  - run test suite on installed world
43 # doxygen     - build API documentation of the kernel
44 # update      - convenient way to update your source tree (eg: svn/svnup)
45 #
46 # Standard targets (not defined here) are documented in the makefiles in
47 # /usr/share/mk.  These include:
48 #               obj depend all install clean cleandepend cleanobj
49
50 .if !defined(TARGET) || !defined(TARGET_ARCH)
51 .error "Both TARGET and TARGET_ARCH must be defined."
52 .endif
53
54 .if make(showconfig) || make(test-system-*)
55 _MKSHOWCONFIG=  t
56 .endif
57
58 SRCDIR?=        ${.CURDIR}
59 LOCALBASE?=     /usr/local
60
61 .include "share/mk/src.tools.mk"
62
63 # Cross toolchain changes must be in effect before bsd.compiler.mk
64 # so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
65 .if defined(CROSS_TOOLCHAIN)
66 .if exists(${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk)
67 .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
68 .elif exists(/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk)
69 .include "/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk"
70 .elif exists(${CROSS_TOOLCHAIN})
71 .include "${CROSS_TOOLCHAIN}"
72 .else
73 .error CROSS_TOOLCHAIN ${CROSS_TOOLCHAIN} not found
74 .endif
75 CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
76 .endif
77 .if defined(CROSS_TOOLCHAIN_PREFIX)
78 CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
79 .endif
80
81 XCOMPILERS=     CC CXX CPP
82 .for COMPILER in ${XCOMPILERS}
83 .if defined(CROSS_COMPILER_PREFIX)
84 X${COMPILER}?=  ${CROSS_COMPILER_PREFIX}${${COMPILER}}
85 .else
86 X${COMPILER}?=  ${${COMPILER}}
87 .endif
88 .endfor
89 # If a full path to an external cross compiler is given, don't build
90 # a cross compiler.
91 .if ${XCC:N${CCACHE_BIN}:M/*}
92 MK_CLANG_BOOTSTRAP=     no
93 .endif
94
95 # Pull in compiler metadata from buildworld/toolchain if possible to avoid
96 # running CC from bsd.compiler.mk.
97 .if make(installworld) || make(install) || make(distributeworld) || \
98     make(stageworld)
99 .-include "${OBJTOP}/toolchain-metadata.mk"
100 .if !defined(_LOADED_TOOLCHAIN_METADATA)
101 .error A build is required first.  You may have the wrong MAKEOBJDIRPREFIX set.
102 .endif
103 .endif
104
105 # Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early. Pull it from the
106 # tree to be friendlier to foreign OS builds. It's safe to do so unconditionally
107 # here since we will always have the right make, unlike in src/Makefile
108 # Don't include bsd.linker.mk yet until XBINUTILS is handled (after src.opts.mk)
109 _NO_INCLUDE_LINKERMK=   t
110 # We also want the X_COMPILER* variables if we are using an external toolchain.
111 _WANT_TOOLCHAIN_CROSS_VARS=     t
112 .include "share/mk/bsd.compiler.mk"
113 .undef _NO_INCLUDE_LINKERMK
114 .undef _WANT_TOOLCHAIN_CROSS_VARS
115 # src.opts.mk depends on COMPILER_FEATURES
116 .include "share/mk/src.opts.mk"
117
118 .if ${TARGET} == ${MACHINE}
119 TARGET_CPUTYPE?=${CPUTYPE}
120 .else
121 TARGET_CPUTYPE?=
122 .endif
123 .if !empty(TARGET_CPUTYPE)
124 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
125 .else
126 _TARGET_CPUTYPE=dummy
127 .endif
128 .if ${TARGET} == "arm"
129 .if ${TARGET_ARCH:Marmv[67]*} != "" && ${TARGET_CPUTYPE:M*soft*} == ""
130 TARGET_ABI=     gnueabihf
131 .else
132 TARGET_ABI=     gnueabi
133 .endif
134 .endif
135 MACHINE_ABI?=   unknown
136 MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd13.0
137 TARGET_ABI?=    unknown
138 TARGET_TRIPLE?= ${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd13.0
139 KNOWN_ARCHES?=  aarch64/arm64 \
140                 amd64 \
141                 armv6/arm \
142                 armv7/arm \
143                 i386 \
144                 mips \
145                 mipsel/mips \
146                 mips64el/mips \
147                 mipsn32el/mips \
148                 mips64/mips \
149                 mipsn32/mips \
150                 mipshf/mips \
151                 mipselhf/mips \
152                 mips64elhf/mips \
153                 mips64hf/mips \
154                 powerpc \
155                 powerpc64/powerpc \
156                 powerpc64le/powerpc \
157                 powerpcspe/powerpc \
158                 riscv64/riscv \
159                 riscv64sf/riscv
160
161 .if ${TARGET} == ${TARGET_ARCH}
162 _t=             ${TARGET}
163 .else
164 _t=             ${TARGET_ARCH}/${TARGET}
165 .endif
166 .for _t in ${_t}
167 .if empty(KNOWN_ARCHES:M${_t})
168 .error Unknown target ${TARGET_ARCH}:${TARGET}.
169 .endif
170 .endfor
171
172 .if ${.MAKE.OS} != "FreeBSD"
173 CROSSBUILD_HOST=${.MAKE.OS}
174 .if ${.MAKE.OS} != "Linux" && ${.MAKE.OS} != "Darwin"
175 .warning "Unsupported crossbuild system: ${.MAKE.OS}. Build will probably fail!"
176 .endif
177 # We need to force NO_ROOT/DB_FROM_SRC builds when building on other operating
178 # systems since the BSD.foo.dist specs contain users and groups that do not
179 # exist by default on a Linux/MacOS system.
180 NO_ROOT:=       1
181 DB_FROM_SRC:=   1
182 .export NO_ROOT
183 .endif
184
185 # If all targets are disabled for system llvm then don't expect it to work
186 # for cross-builds.
187 .if !defined(TOOLS_PREFIX) && ${MK_LLVM_TARGET_ALL} == "no" && \
188     ${MACHINE} != ${TARGET} && ${MACHINE_ARCH} != ${TARGET_ARCH} && \
189     !make(showconfig)
190 MK_SYSTEM_COMPILER=     no
191 MK_SYSTEM_LINKER=       no
192 .endif
193
194 # Handle external binutils.
195 .if defined(CROSS_TOOLCHAIN_PREFIX)
196 CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
197 .endif
198 XBINUTILS=      AS AR LD NM OBJCOPY RANLIB SIZE STRINGS STRIPBIN
199 .for BINUTIL in ${XBINUTILS}
200 .if defined(CROSS_BINUTILS_PREFIX) && \
201     exists(${CROSS_BINUTILS_PREFIX}/${${BINUTIL}})
202 X${BINUTIL}?=   ${CROSS_BINUTILS_PREFIX:C,/*$,,}/${${BINUTIL}}
203 .else
204 X${BINUTIL}?=   ${${BINUTIL}}
205 .endif
206 .endfor
207
208 # If a full path to an external linker is given, don't build lld.
209 .if ${XLD:M/*}
210 MK_LLD_BOOTSTRAP=       no
211 .endif
212
213 # We also want the X_LINKER* variables if we are using an external toolchain.
214 _WANT_TOOLCHAIN_CROSS_VARS=     t
215 .include "share/mk/bsd.linker.mk"
216 .undef _WANT_TOOLCHAIN_CROSS_VARS
217
218 # Begin WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
219
220 # WITH_SYSTEM_COMPILER - Pull in needed values and make a decision.
221
222 # Check if there is a local compiler that can satisfy as an external compiler.
223 # Which compiler is expected to be used?
224 .if ${MK_CLANG_BOOTSTRAP} == "yes"
225 WANT_COMPILER_TYPE=     clang
226 .else
227 WANT_COMPILER_TYPE=
228 .endif
229
230 .if !defined(WANT_COMPILER_FREEBSD_VERSION) && !make(showconfig) && \
231     !make(test-system-linker)
232 .if ${WANT_COMPILER_TYPE} == "clang"
233 WANT_COMPILER_FREEBSD_VERSION_FILE= lib/clang/freebsd_cc_version.h
234 WANT_COMPILER_FREEBSD_VERSION!= \
235         awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \
236         ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown
237 WANT_COMPILER_VERSION_FILE= lib/clang/include/clang/Basic/Version.inc
238 WANT_COMPILER_VERSION!= \
239         awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
240         ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown
241 .endif
242 .export WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_VERSION
243 .endif  # !defined(WANT_COMPILER_FREEBSD_VERSION)
244
245 # It needs to be the same revision as we would build for the bootstrap.
246 # If the expected vs CC is different then we can't skip.
247 # GCC cannot be used for cross-arch yet.  For clang we pass -target later if
248 # TARGET_ARCH!=MACHINE_ARCH.
249 .if ${MK_SYSTEM_COMPILER} == "yes" && \
250     defined(WANT_COMPILER_FREEBSD_VERSION) && \
251     ${MK_CLANG_BOOTSTRAP} == "yes" && \
252     !make(xdev*) && \
253     ${X_COMPILER_TYPE} == ${WANT_COMPILER_TYPE} && \
254     (${X_COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH}) && \
255     ${X_COMPILER_VERSION} == ${WANT_COMPILER_VERSION} && \
256     ${X_COMPILER_FREEBSD_VERSION} == ${WANT_COMPILER_FREEBSD_VERSION}
257 # Everything matches, disable the bootstrap compiler.
258 MK_CLANG_BOOTSTRAP=     no
259 USING_SYSTEM_COMPILER=  yes
260 .endif  # ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE}
261
262 # WITH_SYSTEM_LD - Pull in needed values and make a decision.
263
264 # Check if there is a local linker that can satisfy as an external linker.
265 # Which linker is expected to be used?
266 .if ${MK_LLD_BOOTSTRAP} == "yes"
267 WANT_LINKER_TYPE=               lld
268 .else
269 WANT_LINKER_TYPE=
270 .endif
271
272 .if !defined(WANT_LINKER_FREEBSD_VERSION) && !make(showconfig) && \
273     !make(test-system-compiler)
274 .if ${WANT_LINKER_TYPE} == "lld"
275 WANT_LINKER_FREEBSD_VERSION_FILE= lib/clang/include/VCSVersion.inc
276 _WANT_LINKER_FREEBSD_VERSION!= \
277         awk '$$2 == "LLD_REVISION" {gsub(/"/, "", $$3); print $$3}' \
278         ${SRCDIR}/${WANT_LINKER_FREEBSD_VERSION_FILE} || echo unknown
279 WANT_LINKER_FREEBSD_VERSION=${_WANT_LINKER_FREEBSD_VERSION:C/.*-(.*)/\1/}
280 WANT_LINKER_VERSION_FILE= lib/clang/include/lld/Common/Version.inc
281 WANT_LINKER_VERSION!= \
282         awk '$$2 == "LLD_VERSION_STRING" { gsub("\"", "", $$3); split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
283         ${SRCDIR}/${WANT_LINKER_VERSION_FILE} || echo unknown
284 .else
285 WANT_LINKER_FREEBSD_VERSION_FILE=
286 WANT_LINKER_FREEBSD_VERSION=
287 .endif
288 .export WANT_LINKER_FREEBSD_VERSION WANT_LINKER_VERSION
289 .endif  # !defined(WANT_LINKER_FREEBSD_VERSION)
290
291 .if ${MK_SYSTEM_LINKER} == "yes" && \
292     defined(WANT_LINKER_FREEBSD_VERSION) && \
293     (${MK_LLD_BOOTSTRAP} == "yes") && \
294     !make(xdev*) && \
295     ${X_LINKER_TYPE} == ${WANT_LINKER_TYPE} && \
296     ${X_LINKER_VERSION} == ${WANT_LINKER_VERSION} && \
297     ${X_LINKER_FREEBSD_VERSION} == ${WANT_LINKER_FREEBSD_VERSION}
298 # Everything matches, disable the bootstrap linker.
299 MK_LLD_BOOTSTRAP=       no
300 USING_SYSTEM_LINKER=    yes
301 .endif  # ${WANT_LINKER_TYPE} == ${LINKER_TYPE}
302
303 # WITH_SYSTEM_COMPILER / WITH_SYSTEM_LINKER - Handle defaults and debug.
304 USING_SYSTEM_COMPILER?= no
305 USING_SYSTEM_LINKER?=   no
306
307 TEST_SYSTEM_COMPILER_VARS= \
308         USING_SYSTEM_COMPILER MK_SYSTEM_COMPILER \
309         MK_CROSS_COMPILER MK_CLANG_BOOTSTRAP \
310         WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \
311         WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \
312         CC COMPILER_TYPE COMPILER_FEATURES COMPILER_VERSION \
313         COMPILER_FREEBSD_VERSION \
314         XCC X_COMPILER_TYPE X_COMPILER_FEATURES X_COMPILER_VERSION \
315         X_COMPILER_FREEBSD_VERSION
316 TEST_SYSTEM_LINKER_VARS= \
317         USING_SYSTEM_LINKER MK_SYSTEM_LINKER \
318         MK_LLD_BOOTSTRAP \
319         WANT_LINKER_TYPE WANT_LINKER_VERSION WANT_LINKER_VERSION_FILE \
320         WANT_LINKER_FREEBSD_VERSION WANT_LINKER_FREEBSD_VERSION_FILE \
321         LD LINKER_TYPE LINKER_FEATURES LINKER_VERSION \
322         LINKER_FREEBSD_VERSION \
323         XLD X_LINKER_TYPE X_LINKER_FEATURES X_LINKER_VERSION \
324         X_LINKER_FREEBSD_VERSION
325
326 .for _t in compiler linker
327 test-system-${_t}: .PHONY
328 .for v in ${TEST_SYSTEM_${_t:tu}_VARS}
329         ${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}"
330 .endfor
331 .endfor
332 .if (make(buildworld) || make(buildkernel) || make(kernel-toolchain) || \
333     make(toolchain) || make(_cross-tools))
334 .if ${USING_SYSTEM_COMPILER} == "yes"
335 .info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree.  Not bootstrapping a cross-compiler.
336 .elif ${MK_CLANG_BOOTSTRAP} == "yes"
337 .info SYSTEM_COMPILER: libclang will be built for bootstrapping a cross-compiler.
338 .endif
339 .if ${USING_SYSTEM_LINKER} == "yes"
340 .info SYSTEM_LINKER: Determined that LD=${LD} matches the source tree.  Not bootstrapping a cross-linker.
341 .elif ${MK_LLD_BOOTSTRAP} == "yes"
342 .info SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.
343 .endif
344 .endif
345
346 # End WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
347
348 # Store some compiler metadata for use in installworld where we don't
349 # want to invoke CC at all.
350 _TOOLCHAIN_METADATA_VARS=       COMPILER_VERSION \
351                                 COMPILER_TYPE \
352                                 COMPILER_FEATURES \
353                                 COMPILER_FREEBSD_VERSION \
354                                 COMPILER_RESOURCE_DIR \
355                                 LINKER_VERSION \
356                                 LINKER_FEATURES \
357                                 LINKER_TYPE \
358                                 LINKER_FREEBSD_VERSION
359 toolchain-metadata.mk: .PHONY .META
360         @: > ${.TARGET}
361         @echo ".info Using cached toolchain metadata from build at $$(hostname) on $$(date)" \
362             > ${.TARGET}
363         @echo "_LOADED_TOOLCHAIN_METADATA=t" >> ${.TARGET}
364 .for v in ${_TOOLCHAIN_METADATA_VARS}
365         @echo "${v}=${${v}}" >> ${.TARGET}
366         @echo "X_${v}=${X_${v}}" >> ${.TARGET}
367 .endfor
368         @echo ".export ${_TOOLCHAIN_METADATA_VARS}" >> ${.TARGET}
369         @echo ".export ${_TOOLCHAIN_METADATA_VARS:C,^,X_,}" >> ${.TARGET}
370
371
372 # We must do lib/ and libexec/ before bin/ in case of a mid-install error to
373 # keep the users system reasonably usable.  For static->dynamic root upgrades,
374 # we don't want to install a dynamic binary without rtld and the needed
375 # libraries.  More commonly, for dynamic root, we don't want to install a
376 # binary that requires a newer library version that hasn't been installed yet.
377 # This ordering is not a guarantee though.  The only guarantee of a working
378 # system here would require fine-grained ordering of all components based
379 # on their dependencies.
380 .if !empty(SUBDIR_OVERRIDE)
381 SUBDIR= ${SUBDIR_OVERRIDE}
382 .else
383 SUBDIR= lib libexec
384 # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
385 # of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
386 # LOCAL_LIB_DIRS=foo/lib to behave as expected.
387 .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
388 _REDUNDANT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
389 .endfor
390 .for _DIR in ${LOCAL_LIB_DIRS}
391 .if ${_DIR} == ".WAIT" || (empty(_REDUNDANT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
392 SUBDIR+=        ${_DIR}
393 .endif
394 .endfor
395 .if !defined(NO_ROOT) && (make(installworld) || make(install))
396 # Ensure libraries are installed before progressing.
397 SUBDIR+=.WAIT
398 .endif
399 SUBDIR+=bin
400 .if ${MK_CDDL} != "no"
401 SUBDIR+=cddl
402 .endif
403 SUBDIR+=gnu include
404 .if ${MK_KERBEROS} != "no"
405 SUBDIR+=kerberos5
406 .endif
407 .if ${MK_RESCUE} != "no"
408 SUBDIR+=rescue
409 .endif
410 SUBDIR+=sbin
411 .if ${MK_CRYPT} != "no"
412 SUBDIR+=secure
413 .endif
414 .if !defined(NO_SHARE)
415 SUBDIR+=share
416 .endif
417 .if ${MK_BOOT} != "no"
418 SUBDIR+=stand
419 .endif
420 SUBDIR+=sys usr.bin usr.sbin
421 .if ${MK_TESTS} != "no"
422 SUBDIR+=        tests
423 .endif
424
425 # Local directories are built in parallel with the base system directories.
426 # Users may insert a .WAIT directive at the beginning or elsewhere within
427 # the LOCAL_DIRS and LOCAL_LIB_DIRS lists as needed.
428 .for _DIR in ${LOCAL_DIRS}
429 .if ${_DIR} == ".WAIT" || exists(${.CURDIR}/${_DIR}/Makefile)
430 SUBDIR+=        ${_DIR}
431 .endif
432 .endfor
433
434 # We must do etc/ last as it hooks into building the man whatis file
435 # by calling 'makedb' in share/man.  This is only relevant for
436 # install/distribute so they build the whatis file after every manpage is
437 # installed.
438 .if make(installworld) || make(install)
439 SUBDIR+=.WAIT
440 .endif
441 SUBDIR+=etc
442
443 .endif  # !empty(SUBDIR_OVERRIDE)
444
445 .if defined(NOCLEAN)
446 .warning The src.conf WITHOUT_CLEAN option can now be used instead of NOCLEAN.
447 MK_CLEAN:=      no
448 .endif
449 .if defined(NO_CLEAN)
450 .info The src.conf WITHOUT_CLEAN option can now be used instead of NO_CLEAN.
451 MK_CLEAN:=      no
452 .endif
453 .if defined(NO_CLEANDIR)
454 CLEANDIR=       clean cleandepend
455 .else
456 CLEANDIR=       cleandir
457 .endif
458
459 .if defined(WORLDFAST)
460 MK_CLEAN:=      no
461 NO_OBJWALK=     t
462 .endif
463
464 .if ${MK_META_MODE} == "yes"
465 # If filemon is used then we can rely on the build being incremental-safe.
466 # The .meta files will also track the build command and rebuild should
467 # it change.
468 .if empty(.MAKE.MODE:Mnofilemon)
469 MK_CLEAN:=      no
470 .endif
471 .endif
472 .if defined(NO_OBJWALK) || ${MK_AUTO_OBJ} == "yes"
473 NO_OBJWALK=     t
474 NO_KERNELOBJ=   t
475 .endif
476 .if !defined(NO_OBJWALK)
477 _obj=           obj
478 .endif
479
480 LOCAL_TOOL_DIRS?=
481 PACKAGEDIR?=    ${DESTDIR}/${DISTDIR}
482
483 .if empty(SHELL:M*csh*)
484 BUILDENV_SHELL?=${SHELL}
485 .else
486 BUILDENV_SHELL?=/bin/sh
487 .endif
488
489 .if !defined(_MKSHOWCONFIG)
490 .if !defined(SVN_CMD) || empty(SVN_CMD)
491 . for _P in /usr/bin /usr/local/bin
492 .  for _S in svn svnlite
493 .   if exists(${_P}/${_S})
494 SVN_CMD=   ${_P}/${_S}
495 .   endif
496 .  endfor
497 . endfor
498 .export SVN_CMD
499 .endif
500 SVNFLAGS?=      -r HEAD
501 .if !defined(VCS_REVISION) || empty(VCS_REVISION)
502 .if !defined(SVNVERSION_CMD) || empty(SVNVERSION_CMD)
503 . for _D in ${PATH:S,:, ,g}
504 .  if exists(${_D}/svnversion)
505 SVNVERSION_CMD?=${_D}/svnversion
506 .  endif
507 .  if exists(${_D}/svnliteversion)
508 SVNVERSION_CMD?=${_D}/svnliteversion
509 .  endif
510 . endfor
511 .endif
512 _VCS_REVISION?= $$(eval ${SVNVERSION_CMD} ${SRCDIR})
513 . if !empty(_VCS_REVISION)
514 VCS_REVISION=   $$(echo r${_VCS_REVISION})
515 . endif
516 .export VCS_REVISION
517 .endif
518
519 .if !defined(GIT_CMD) || empty(GIT_CMD)
520 . for _P in /usr/bin /usr/local/bin
521 .  if exists(${_P}/git)
522 GIT_CMD=   ${_P}/git
523 .  endif
524 . endfor
525 .export GIT_CMD
526 .endif
527
528 .if !defined(OSRELDATE)
529 .if exists(/usr/include/osreldate.h)
530 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
531                 /usr/include/osreldate.h
532 .else
533 OSRELDATE=      0
534 .endif
535 .export OSRELDATE
536 .endif
537
538 # Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
539 .if !defined(_REVISION)
540 _REVISION!=     ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V REVISION
541 .export _REVISION
542 .endif
543 .if !defined(_BRANCH)
544 _BRANCH!=       ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V BRANCH
545 .export _BRANCH
546 .endif
547 .if !defined(SRCRELDATE)
548 SRCRELDATE!=    awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
549                 ${SRCDIR}/sys/sys/param.h
550 .export SRCRELDATE
551 .endif
552 .if !defined(VERSION)
553 VERSION=        FreeBSD ${_REVISION}-${_BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
554 .export VERSION
555 .endif
556
557 .if !defined(PKG_VERSION)
558 .if ${_BRANCH:MSTABLE*} || ${_BRANCH:MCURRENT*}
559 TIMENOW=        %Y%m%d%H%M%S
560 EXTRA_REVISION= .s${TIMENOW:gmtime}
561 .elif ${_BRANCH:MALPHA*}
562 EXTRA_REVISION= _${_BRANCH:C/-ALPHA/.a/}
563 .elif ${_BRANCH:MBETA*}
564 EXTRA_REVISION= _${_BRANCH:C/-BETA/.b/}
565 .elif ${_BRANCH:MRC*}
566 EXTRA_REVISION= _${_BRANCH:C/-RC/.r/}
567 .elif ${_BRANCH:MPRERELEASE*}
568 EXTRA_REVISION= _${_BRANCH:C/-PRERELEASE/.p/}
569 .elif ${_BRANCH:M*-p*}
570 EXTRA_REVISION= _${_BRANCH:C/.*-p([0-9]+$)/\1/}
571 .endif
572 PKG_VERSION:=   ${_REVISION}${EXTRA_REVISION}
573 .endif
574 .endif  # !defined(PKG_VERSION)
575
576 .if !defined(PKG_TIMESTAMP)
577 TIMEEPOCHNOW=           %s
578 SOURCE_DATE_EPOCH=      ${TIMEEPOCHNOW:gmtime}
579 .else
580 SOURCE_DATE_EPOCH=      ${PKG_TIMESTAMP}
581 .endif
582
583 PKG_NAME_PREFIX?=       FreeBSD
584 PKG_MAINTAINER?=        re@FreeBSD.org
585 PKG_WWW?=               https://www.FreeBSD.org
586 .export PKG_NAME_PREFIX
587 .export PKG_MAINTAINER
588 .export PKG_WWW
589
590 .if !defined(_MKSHOWCONFIG)
591 _CPUTYPE!=      MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} -f /dev/null \
592                 -m ${.CURDIR}/share/mk MK_AUTO_OBJ=no -V CPUTYPE
593 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
594 .error CPUTYPE global should be set with ?=.
595 .endif
596 .endif
597 .if make(buildworld)
598 BUILD_ARCH!=    uname -p
599 # On some Linux systems uname -p returns "unknown" so skip this check there.
600 # This check only exists to tell people to use TARGET_ARCH instead of
601 # MACHINE_ARCH so skipping it when crossbuilding on non-FreeBSD should be fine.
602 .if ${MACHINE_ARCH} != ${BUILD_ARCH} && ${.MAKE.OS} == "FreeBSD"
603 .error To cross-build, set TARGET_ARCH.
604 .endif
605 .endif
606 WORLDTMP?=      ${OBJTOP}/tmp
607 BPATH=          ${CCACHE_WRAPPER_PATH_PFX}${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin:${WORLDTMP}/legacy/usr/libexec
608 XPATH=          ${WORLDTMP}/bin:${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
609
610 # When building we want to find the cross tools before the host tools in ${BPATH}.
611 # We also need to add UNIVERSE_TOOLCHAIN_PATH so that we can find the shared
612 # toolchain files (clang, lld, etc.) during make universe/tinderbox
613 STRICTTMPPATH=  ${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
614 # We should not be using tools from /usr/bin accidentally since this could cause
615 # the build to break on other systems that don't have that tool. For now we
616 # still allow using the old behaviour (inheriting $PATH) if
617 # BUILD_WITH_STRICT_TMPPATH is set to 0 but this will eventually be removed.
618
619 # Currently strict $PATH can cause build failures and does not work yet with
620 # USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
621 # resolved it will be turned on by default.
622 BUILD_WITH_STRICT_TMPPATH?=0
623 .if defined(CROSSBUILD_HOST)
624 # When building on non-FreeBSD we can't rely on the tools in /usr/bin being compatible
625 # with what FreeBSD expects. Therefore we only use tools from STRICTTMPPATH
626 # during the world build stage. We build most tools during the bootstrap-tools
627 # phase but symlink host tools that are known to work instead of building them
628 BUILD_WITH_STRICT_TMPPATH:=1
629 .endif
630 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
631 TMPPATH=        ${STRICTTMPPATH}
632 .else
633 TMPPATH=        ${STRICTTMPPATH}:${PATH}
634 .endif
635
636 #
637 # Avoid running mktemp(1) unless actually needed.
638 # It may not be functional, e.g., due to new ABI
639 # when in the middle of installing over this system.
640 #
641 .if make(distributeworld) || make(installworld) || make(stageworld)
642 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
643 MKTEMP=${WORLDTMP}/legacy/usr/bin/mktemp
644 .if !exists(${MKTEMP})
645 .error "mktemp binary doesn't exist in expected location: ${MKTEMP}"
646 .endif
647 .else
648 MKTEMP=mktemp
649 .endif
650 INSTALLTMP!=    ${MKTEMP} -d -u -t install
651 .endif
652
653 .if make(stagekernel) || make(distributekernel)
654 TAGS+=          kernel
655 PACKAGE=        kernel
656 .endif
657
658 #
659 # Building a world goes through the following stages
660 #
661 # 1. legacy stage [BMAKE]
662 #       This stage is responsible for creating compatibility
663 #       shims that are needed by the bootstrap-tools,
664 #       build-tools and cross-tools stages. These are generally
665 #       APIs that tools from one of those three stages need to
666 #       build that aren't present on the host.
667 # 1. bootstrap-tools stage [BMAKE]
668 #       This stage is responsible for creating programs that
669 #       are needed for backward compatibility reasons. They
670 #       are not built as cross-tools.
671 # 2. build-tools stage [TMAKE]
672 #       This stage is responsible for creating the object
673 #       tree and building any tools that are needed during
674 #       the build process. Some programs are listed during
675 #       this phase because they build binaries to generate
676 #       files needed to build these programs. This stage also
677 #       builds the 'build-tools' target rather than 'all'.
678 # 3. cross-tools stage [XMAKE]
679 #       This stage is responsible for creating any tools that
680 #       are needed for building the system. A cross-compiler is one
681 #       of them. This differs from build tools in two ways:
682 #       1. the 'all' target is built rather than 'build-tools'
683 #       2. these tools are installed into TMPPATH for stage 4.
684 # 4. world stage [WMAKE]
685 #       This stage actually builds the world.
686 # 5. install stage (optional) [IMAKE]
687 #       This stage installs a previously built world.
688 #
689
690 BOOTSTRAPPING?= 0
691 # Keep these in sync
692 MINIMUM_SUPPORTED_OSREL?= 1002501
693 MINIMUM_SUPPORTED_REL?= 10.3
694
695 # Common environment for world related stages
696 CROSSENV+=      \
697                 MACHINE_ARCH=${TARGET_ARCH} \
698                 MACHINE=${TARGET} \
699                 CPUTYPE=${TARGET_CPUTYPE}
700 .if ${MK_META_MODE} != "no"
701 # Don't rebuild build-tools targets during normal build.
702 CROSSENV+=      BUILD_TOOLS_META=.NOMETA
703 .endif
704 .if defined(TARGET_CFLAGS)
705 CROSSENV+=      ${TARGET_CFLAGS}
706 .endif
707 .if (${TARGET} != ${MACHINE} && !defined(WITH_LOCAL_MODULES)) || \
708     defined(WITHOUT_LOCAL_MODULES)
709 CROSSENV+=      LOCAL_MODULES=
710 .endif
711
712 BOOTSTRAPPING_OSRELDATE?=${OSRELDATE}
713
714 # bootstrap-tools stage
715 BMAKEENV=       INSTALL="sh ${.CURDIR}/tools/install.sh" \
716                 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
717                 PATH=${BPATH}:${PATH} \
718                 WORLDTMP=${WORLDTMP} \
719                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
720 # need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
721 BSARGS=         DESTDIR= \
722                 OBJTOP='${WORLDTMP}/obj-tools' \
723                 OBJROOT='$${OBJTOP}/' \
724                 MAKEOBJDIRPREFIX= \
725                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
726                 BWPHASE=${.TARGET:C,^_,,} \
727                 SSP_CFLAGS= \
728                 MK_HTML=no NO_LINT=yes MK_MAN=no MK_MAN_UTILS=yes \
729                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
730                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
731                 MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
732                 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \
733                 MK_INCLUDES=yes
734
735 BMAKE=          \
736                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
737                 ${BSARGS}
738 .if empty(.MAKEOVERRIDES:MMK_LLVM_TARGET_ALL)
739 BMAKE+=         MK_LLVM_TARGET_ALL=no
740 .endif
741
742 # build-tools stage
743 TMAKE=          \
744                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
745                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
746                 DESTDIR= \
747                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
748                 BWPHASE=${.TARGET:C,^_,,} \
749                 SSP_CFLAGS= \
750                 -DNO_LINT \
751                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
752                 MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
753                 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no
754
755 # cross-tools stage
756 # TOOLS_PREFIX set in BMAKE
757 XMAKE=          ${BMAKE} \
758                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
759                 MK_CLANG_IS_CC=${MK_CLANG_BOOTSTRAP} \
760                 MK_GDB=no MK_TESTS=no
761
762 # kernel-tools stage
763 KTMAKEENV=      INSTALL="sh ${.CURDIR}/tools/install.sh" \
764                 PATH=${BPATH}:${PATH} \
765                 WORLDTMP=${WORLDTMP} \
766                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
767
768 KTMAKE=         \
769                 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
770                 ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
771                 DESTDIR= \
772                 OBJTOP='${WORLDTMP}/obj-kernel-tools' \
773                 OBJROOT='$${OBJTOP}/' \
774                 MAKEOBJDIRPREFIX= \
775                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
776                 SSP_CFLAGS= \
777                 MK_HTML=no -DNO_LINT MK_MAN=no \
778                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
779                 -DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WARNS=no MK_CTF=no
780
781 # world stage
782 WMAKEENV=       ${CROSSENV} \
783                 INSTALL="${INSTALL_CMD} -U" \
784                 PATH=${TMPPATH} \
785                 SYSROOT=${WORLDTMP}
786
787 # make hierarchy
788 HMAKE=          PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
789 .if defined(NO_ROOT)
790 HMAKE+=         PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
791 .endif
792
793 CROSSENV+=      CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \
794                 CPP="${XCPP} ${XCFLAGS}" \
795                 AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \
796                 NM=${XNM} OBJCOPY="${XOBJCOPY}" \
797                 RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
798                 SIZE="${XSIZE}" STRIPBIN="${XSTRIPBIN}"
799
800 .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
801 # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
802 # directory, but the compiler will look in the right place for its
803 # tools so we don't need to tell it where to look.
804 BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
805 .endif
806
807
808 # The internal bootstrap compiler has a default sysroot set by TOOLS_PREFIX
809 # and target set by TARGET/TARGET_ARCH.  However, there are several needs to
810 # always pass an explicit --sysroot and -target.
811 # - External compiler needs sysroot and target flags.
812 # - External ld needs sysroot.
813 # - To be clear about the use of a sysroot when using the internal compiler.
814 # - Easier debugging.
815 # - Allowing WITH_SYSTEM_COMPILER+WITH_META_MODE to work together due to
816 #   the flip-flopping build command when sometimes using external and
817 #   sometimes using internal.
818 # - Allow using lld which has no support for default paths.
819 .if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
820 BFLAGS+=        -B${WORLDTMP}/usr/bin
821 .endif
822 .if ${WANT_COMPILER_TYPE} == gcc || \
823     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
824 .elif ${WANT_COMPILER_TYPE} == clang || \
825     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == clang)
826 XCFLAGS+=       -target ${TARGET_TRIPLE}
827 .endif
828 XCFLAGS+=       --sysroot=${WORLDTMP}
829
830 .if !empty(BFLAGS)
831 XCFLAGS+=       ${BFLAGS}
832 .endif
833
834 .if ${MK_LIB32} == "yes"
835 _LIBCOMPAT= 32
836 .include "Makefile.libcompat"
837 .elif ${MK_LIBSOFT} == "yes"
838 _LIBCOMPAT= SOFT
839 .include "Makefile.libcompat"
840 .endif
841
842 # META_MODE normally ignores host file changes since every build updates
843 # timestamps (see NO_META_IGNORE_HOST in sys.mk).  There are known times
844 # when the ABI breaks though that we want to force rebuilding WORLDTMP
845 # to get updated host tools.
846 .if ${MK_META_MODE} == "yes" && ${MK_CLEAN} == "no" && \
847     !defined(NO_META_IGNORE_HOST) && !defined(NO_META_IGNORE_HOST_HEADERS) && \
848     !defined(_MKSHOWCONFIG)
849 # r318736 - ino64 major ABI breakage
850 META_MODE_BAD_ABI_VERS+=        1200031
851
852 .if !defined(OBJDIR_HOST_OSRELDATE)
853 .if exists(${OBJTOP}/host-osreldate.h)
854 OBJDIR_HOST_OSRELDATE!= \
855     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
856     ${OBJTOP}/host-osreldate.h
857 .elif exists(${WORLDTMP}/usr/include/osreldate.h)
858 OBJDIR_HOST_OSRELDATE=  0
859 .endif
860 .export OBJDIR_HOST_OSRELDATE
861 .endif
862
863 # Note that this logic is the opposite of normal BOOTSTRAP handling.  We want
864 # to compare the WORLDTMP's OSRELDATE to the host's OSRELDATE.  If the WORLDTMP
865 # is older than the ABI-breakage OSRELDATE of the HOST then we rebuild.
866 .if defined(OBJDIR_HOST_OSRELDATE)
867 .for _ver in ${META_MODE_BAD_ABI_VERS}
868 .if ${OSRELDATE} >= ${_ver} && ${OBJDIR_HOST_OSRELDATE} < ${_ver}
869 _meta_mode_need_rebuild=        ${_ver}
870 .endif
871 .endfor
872 .if defined(_meta_mode_need_rebuild)
873 .info META_MODE: Rebuilding host tools due to ABI breakage in __FreeBSD_version ${_meta_mode_need_rebuild}.
874 NO_META_IGNORE_HOST_HEADERS=    1
875 .export NO_META_IGNORE_HOST_HEADERS
876 .endif  # defined(_meta_mode_need_rebuild)
877 .endif  # defined(OBJDIR_HOST_OSRELDATE)
878 .endif  # ${MK_META_MODE} == "yes" && ${MK_CLEAN} == "no" ...
879 # This is only used for META_MODE+filemon to track what the oldest
880 # __FreeBSD_version is in WORLDTMP.  This purposely does NOT have
881 # a make dependency on /usr/include/osreldate.h as the file should
882 # only be copied when it is missing or meta mode determines it has changed.
883 # Since host files are normally ignored without NO_META_IGNORE_HOST
884 # the file will never be updated unless that flag is specified.  This
885 # allows tracking the oldest osreldate to force rebuilds via
886 # META_MODE_BADABI_REVS above.
887 host-osreldate.h: # DO NOT ADD /usr/include/osreldate.h here
888 .if !defined(CROSSBUILD_HOST)
889         @cp -f /usr/include/osreldate.h ${.TARGET}
890 .else
891         @echo "#ifndef __FreeBSD_version" > ${.TARGET}
892         @echo "#define __FreeBSD_version ${OSRELDATE}" >> ${.TARGET}
893         @echo "#endif" >> ${.TARGET}
894 .endif
895
896 WMAKE=          ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
897                 BWPHASE=${.TARGET:C,^_,,} \
898                 DESTDIR=${WORLDTMP}
899
900 IMAKEENV=       ${CROSSENV}
901 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1 \
902                 ${IMAKE_INSTALL} ${IMAKE_MTREE}
903 .if empty(.MAKEFLAGS:M-n)
904 IMAKEENV+=      PATH=${STRICTTMPPATH}:${INSTALLTMP} \
905                 LD_LIBRARY_PATH=${INSTALLTMP} \
906                 PATH_LOCALE=${INSTALLTMP}/locale
907 IMAKE+=         __MAKE_SHELL=${INSTALLTMP}/sh
908 .else
909 IMAKEENV+=      PATH=${TMPPATH}:${INSTALLTMP}
910 .endif
911
912 # When generating install media, do not allow user and group information from
913 # the build host to affect the contents of the distribution.
914 .if make(distributeworld) || make(distrib-dirs) || make(distribution) || \
915     make(stageworld)
916 DB_FROM_SRC=    yes
917 .endif
918
919 .if defined(DB_FROM_SRC)
920 INSTALLFLAGS+=  -N ${.CURDIR}/etc
921 MTREEFLAGS+=    -N ${.CURDIR}/etc
922 .endif
923 _INSTALL_DDIR=  ${DESTDIR}/${DISTDIR}
924 INSTALL_DDIR=   ${_INSTALL_DDIR:S://:/:g:C:/$::}
925 .if defined(NO_ROOT)
926 METALOG?=       ${DESTDIR}/${DISTDIR}/METALOG
927 METALOG:=       ${METALOG:C,//+,/,g}
928 IMAKE+=         -DNO_ROOT METALOG=${METALOG}
929 METALOG_INSTALLFLAGS=   -U -M ${METALOG} -D ${INSTALL_DDIR}
930 INSTALLFLAGS+=  ${METALOG_INSTALLFLAGS}
931 CERTCTLFLAGS=   ${METALOG_INSTALLFLAGS}
932 MTREEFLAGS+=    -W
933 .endif
934 .if defined(BUILD_PKGS)
935 INSTALLFLAGS+=  -h sha256
936 .endif
937 .if defined(DB_FROM_SRC) || defined(NO_ROOT)
938 IMAKE_INSTALL=  INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}"
939 IMAKE_MTREE=    MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}"
940 .endif
941 .if make(distributeworld)
942 CERTCTLDESTDIR= ${DESTDIR}/${DISTDIR}/base
943 .else
944 CERTCTLDESTDIR= ${DESTDIR}
945 .endif
946
947 DESTDIR_MTREEFLAGS=     -deU
948 # When creating worldtmp we don't need to set the directories as owned by root
949 # so we also pass -W
950 WORLDTMP_MTREEFLAGS=    -deUW
951 .if defined(NO_ROOT)
952 # When building with -DNO_ROOT we shouldn't be changing the directories
953 # that are created by mtree to be owned by root/wheel.
954 DESTDIR_MTREEFLAGS+=    -W
955 .endif
956 DISTR_MTREE=    ${MTREE_CMD}
957 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
958 DISTR_MTREE=    ${WORLDTMP}/legacy/usr/sbin/mtree
959 .endif
960 WORLDTMP_MTREE= ${DISTR_MTREE} ${WORLDTMP_MTREEFLAGS}
961 DESTDIR_MTREE=  ${DISTR_MTREE} ${DESTDIR_MTREEFLAGS}
962
963 # kernel stage
964 KMAKEENV=       ${WMAKEENV:NSYSROOT=*}
965 KMAKE=          ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
966
967 #
968 # buildworld
969 #
970 # Attempt to rebuild the entire system, with reasonable chance of
971 # success, regardless of how old your existing system is.
972 #
973 _sanity_check: .PHONY .MAKE
974 .if ${.CURDIR:C/[^,]//g} != ""
975 #       The m4 build of sendmail files doesn't like it if ',' is used
976 #       anywhere in the path of it's files.
977         @echo
978         @echo "*** Error: path to source tree contains a comma ','"
979         @echo
980         @false
981 .elif ${.CURDIR:M*\:*} != ""
982 #       Using ':' leaks into PATH and breaks finding cross-tools.
983         @echo
984         @echo "*** Error: path to source tree contains a colon ':'"
985         @echo
986         @false
987 .endif
988
989 # Our current approach to dependency tracking cannot cope with certain source
990 # tree changes, particularly with respect to removing source files and
991 # replacing generated files.  Handle these cases here in an ad-hoc fashion.
992 _cleanobj_fast_depend_hack: .PHONY
993         @echo ">>> Deleting stale dependencies...";
994         sh ${.CURDIR}/tools/build/depend-cleanup.sh ${OBJTOP}
995
996 _worldtmp: .PHONY
997         @echo
998         @echo "--------------------------------------------------------------"
999         @echo ">>> Rebuilding the temporary build tree"
1000         @echo "--------------------------------------------------------------"
1001 .if ${MK_CLEAN} == "yes"
1002         rm -rf ${WORLDTMP}
1003 .else
1004 # Note: for delete-old we need to set $PATH to also include the host $PATH
1005 # since otherwise a partial build with missing symlinks in ${WORLDTMP}/legacy/
1006 # will fail to run due to missing binaries. $WMAKE sets PATH to only ${TMPPATH}
1007 # so we remove that assingnment from $WMAKE and prepend the new $PATH
1008         ${_+_}@if [ -e "${WORLDTMP}" ]; then \
1009                 echo ">>> Deleting stale files in build tree..."; \
1010                 cd ${.CURDIR}; env PATH=${TMPPATH}:${PATH} ${WMAKE:NPATH=*} \
1011                     _NO_INCLUDE_COMPILERMK=t -DBATCH_DELETE_OLD_FILES delete-old \
1012                     delete-old-libs >/dev/null; \
1013         fi
1014         rm -rf ${WORLDTMP}/legacy/usr/include
1015 .if ${USING_SYSTEM_COMPILER} == "yes"
1016 .for cc in cc c++
1017         if [ -x ${WORLDTMP}/usr/bin/${cc} ]; then \
1018                 inum=$$(stat -f %i ${WORLDTMP}/usr/bin/${cc}); \
1019                 find ${WORLDTMP}/usr/bin -inum $${inum} -delete; \
1020         fi
1021 .endfor
1022 .endif  # ${USING_SYSTEM_COMPILER} == "yes"
1023 .if ${USING_SYSTEM_LINKER} == "yes"
1024         @rm -f ${WORLDTMP}/usr/bin/ld ${WORLDTMP}/usr/bin/ld.lld
1025 .endif  # ${USING_SYSTEM_LINKER} == "yes"
1026 .endif  # ${MK_CLEAN} == "yes"
1027         @mkdir -p ${WORLDTMP}
1028         @touch ${WORLDTMP}/${.TARGET}
1029 # We can't use mtree to create the worldtmp directories since it may not be
1030 # available on the target system (this happens e.g. when building on non-FreeBSD)
1031         cd ${.CURDIR}/tools/build; \
1032             ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy installdirs
1033 # In order to build without inheriting $PATH we need to add symlinks to the host
1034 # tools in $WORLDTMP for the tools that we don't build during bootstrap-tools
1035         cd ${.CURDIR}/tools/build; \
1036             ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy host-symlinks
1037
1038 _legacy:
1039         @echo
1040         @echo "--------------------------------------------------------------"
1041         @echo ">>> stage 1.1: legacy release compatibility shims"
1042         @echo "--------------------------------------------------------------"
1043         ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
1044 _bootstrap-tools:
1045         @echo
1046         @echo "--------------------------------------------------------------"
1047         @echo ">>> stage 1.2: bootstrap tools"
1048         @echo "--------------------------------------------------------------"
1049         ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
1050         mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom \
1051             ${WORLDTMP}/bin
1052         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1053             -p ${WORLDTMP}/usr >/dev/null
1054         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1055             -p ${WORLDTMP}/usr/include >/dev/null
1056         ln -sf ${.CURDIR}/sys ${WORLDTMP}
1057 .if ${MK_DEBUG_FILES} != "no"
1058         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1059             -p ${WORLDTMP}/usr/lib >/dev/null
1060 .endif
1061 .for _mtree in ${LOCAL_MTREE}
1062         ${WORLDTMP_MTREE} -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
1063 .endfor
1064 _cleanobj:
1065 .if ${MK_CLEAN} == "yes"
1066         @echo
1067         @echo "--------------------------------------------------------------"
1068         @echo ">>> stage 2.1: cleaning up the object tree"
1069         @echo "--------------------------------------------------------------"
1070         # Avoid including bsd.compiler.mk in clean and obj with _NO_INCLUDE_COMPILERMK
1071         # since the restricted $PATH might not contain a valid cc binary
1072         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t ${CLEANDIR}
1073 .if defined(_LIBCOMPAT)
1074         ${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} _NO_INCLUDE_COMPILERMK=t -f Makefile.inc1 ${CLEANDIR}
1075 .endif
1076 .else
1077         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t _cleanobj_fast_depend_hack
1078 .endif  # ${MK_CLEAN} == "yes"
1079 _obj:
1080         @echo
1081         @echo "--------------------------------------------------------------"
1082         @echo ">>> stage 2.2: rebuilding the object tree"
1083         @echo "--------------------------------------------------------------"
1084         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t obj
1085 _build-tools:
1086         @echo
1087         @echo "--------------------------------------------------------------"
1088         @echo ">>> stage 2.3: build tools"
1089         @echo "--------------------------------------------------------------"
1090         ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
1091 _cross-tools:
1092         @echo
1093         @echo "--------------------------------------------------------------"
1094         @echo ">>> stage 3: cross tools"
1095         @echo "--------------------------------------------------------------"
1096         @rm -f ${OBJTOP}/toolchain-metadata.mk
1097         ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
1098         ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
1099 _build-metadata:
1100         @echo
1101         @echo "--------------------------------------------------------------"
1102         @echo ">>> stage 3.1: recording build metadata"
1103         @echo "--------------------------------------------------------------"
1104         ${_+_}cd ${.CURDIR}; ${WMAKE} toolchain-metadata.mk
1105         ${_+_}cd ${.CURDIR}; ${WMAKE} host-osreldate.h
1106 _includes:
1107         @echo
1108         @echo "--------------------------------------------------------------"
1109         @echo ">>> stage 4.1: building includes"
1110         @echo "--------------------------------------------------------------"
1111 # Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
1112 # headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
1113         ${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
1114             MK_INCLUDES=yes includes
1115 .if !empty(SUBDIR_OVERRIDE) && make(buildworld)
1116         ${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
1117 .endif
1118 _libraries:
1119         @echo
1120         @echo "--------------------------------------------------------------"
1121         @echo ">>> stage 4.2: building libraries"
1122         @echo "--------------------------------------------------------------"
1123         ${_+_}cd ${.CURDIR}; \
1124             ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
1125             MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} \
1126             libraries
1127 everything: .PHONY
1128         @echo
1129         @echo "--------------------------------------------------------------"
1130         @echo ">>> stage 4.4: building everything"
1131         @echo "--------------------------------------------------------------"
1132         ${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
1133
1134 WMAKE_TGTS=
1135 .if !defined(WORLDFAST)
1136 WMAKE_TGTS+=    _sanity_check _worldtmp _legacy
1137 .if empty(SUBDIR_OVERRIDE)
1138 WMAKE_TGTS+=    _bootstrap-tools
1139 .endif
1140 WMAKE_TGTS+=    _cleanobj
1141 .if !defined(NO_OBJWALK)
1142 WMAKE_TGTS+=    _obj
1143 .endif
1144 WMAKE_TGTS+=    _build-tools _cross-tools
1145 WMAKE_TGTS+=    _build-metadata
1146 WMAKE_TGTS+=    _includes
1147 .endif
1148 .if !defined(NO_LIBS)
1149 WMAKE_TGTS+=    _libraries
1150 .endif
1151 .if defined(_LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
1152 WMAKE_TGTS+=    build${libcompat}
1153 .endif
1154 WMAKE_TGTS+=    everything
1155
1156 # record buildworld time in seconds
1157 .if make(buildworld)
1158 _BUILDWORLD_START!= date '+%s'
1159 .export _BUILDWORLD_START
1160 .endif
1161
1162 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY
1163 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
1164
1165 _ncpu_cmd=sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo unknown
1166
1167 buildworld_prologue: .PHONY
1168         @echo "--------------------------------------------------------------"
1169         @echo ">>> World build started on `LC_ALL=C date`"
1170         @echo "--------------------------------------------------------------"
1171
1172 buildworld_epilogue: .PHONY
1173         @echo
1174         @echo "--------------------------------------------------------------"
1175         @echo ">>> World build completed on `LC_ALL=C date`"
1176         @seconds=$$(($$(date '+%s') - ${_BUILDWORLD_START})); \
1177           echo -n ">>> World built in $$seconds seconds, "; \
1178           echo "ncpu: $$(${_ncpu_cmd})${.MAKE.JOBS:S/^/, make -j/}"
1179         @echo "--------------------------------------------------------------"
1180
1181 #
1182 # We need to have this as a target because the indirection between Makefile
1183 # and Makefile.inc1 causes the correct PATH to be used, rather than a
1184 # modification of the current environment's PATH.  In addition, we need
1185 # to quote multiword values.
1186 #
1187 buildenvvars: .PHONY
1188         @echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
1189
1190 .if ${.TARGETS:Mbuildenv}
1191 .if ${.MAKEFLAGS:M-j}
1192 .error The buildenv target is incompatible with -j
1193 .endif
1194 .endif
1195 BUILDENV_DIR?=  ${.CURDIR}
1196 #
1197 # Note: make will report any errors the shell reports. This can
1198 # be odd if the last command in an interactive shell generates an
1199 # error or is terminated by SIGINT. These reported errors look bad,
1200 # but are harmless. Allowing them also allows BUIDLENV_SHELL to
1201 # be a complex command whose status will be returned to the caller.
1202 # Some scripts in tools rely on this behavior to report build errors.
1203 #
1204 buildenv: .PHONY
1205         @echo Entering world for ${TARGET_ARCH}:${TARGET}
1206 .if ${BUILDENV_SHELL:M*zsh*}
1207         @echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
1208 .endif
1209         @cd ${BUILDENV_DIR} && env ${WMAKEENV} \
1210         INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}" \
1211         MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}" BUILDENV=1 ${BUILDENV_SHELL}
1212
1213 TOOLCHAIN_TGTS= ${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
1214 toolchain: ${TOOLCHAIN_TGTS} .PHONY
1215 KERNEL_TOOLCHAIN_TGTS=  ${TOOLCHAIN_TGTS:N_obj:N_cleanobj:N_includes:N_libraries}
1216 .if make(kernel-toolchain)
1217 .ORDER: ${KERNEL_TOOLCHAIN_TGTS}
1218 .endif
1219 kernel-toolchain: ${KERNEL_TOOLCHAIN_TGTS} .PHONY
1220
1221 #
1222 # installcheck
1223 #
1224 # Checks to be sure system is ready for installworld/installkernel.
1225 #
1226 installcheck: _installcheck_world _installcheck_kernel .PHONY
1227 _installcheck_world: .PHONY
1228         @echo "--------------------------------------------------------------"
1229         @echo ">>> Install check world"
1230         @echo "--------------------------------------------------------------"
1231 _installcheck_kernel: .PHONY
1232         @echo "--------------------------------------------------------------"
1233         @echo ">>> Install check kernel"
1234         @echo "--------------------------------------------------------------"
1235
1236 #
1237 # Require DESTDIR to be set if installing for a different architecture or
1238 # using the user/group database in the source tree.
1239 #
1240 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
1241     defined(DB_FROM_SRC)
1242 .if !make(distributeworld)
1243 _installcheck_world: __installcheck_DESTDIR
1244 _installcheck_kernel: __installcheck_DESTDIR
1245 __installcheck_DESTDIR: .PHONY
1246 .if !defined(DESTDIR) || empty(DESTDIR)
1247         @echo "ERROR: Please set DESTDIR!"; \
1248         false
1249 .endif
1250 .endif
1251 .endif
1252
1253 .if !defined(DB_FROM_SRC)
1254 #
1255 # Check for missing UIDs/GIDs.
1256 #
1257 CHECK_UIDS=     auditdistd
1258 CHECK_GIDS=     audit
1259 CHECK_UIDS+=    ntpd
1260 CHECK_GIDS+=    ntpd
1261 CHECK_UIDS+=    proxy
1262 CHECK_GIDS+=    proxy authpf
1263 CHECK_UIDS+=    smmsp
1264 CHECK_GIDS+=    smmsp
1265 CHECK_UIDS+=    unbound
1266 CHECK_GIDS+=    unbound
1267 _installcheck_world: __installcheck_UGID
1268 __installcheck_UGID: .PHONY
1269 .for uid in ${CHECK_UIDS}
1270         @if ! `id -u ${uid} >/dev/null 2>&1`; then \
1271                 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
1272                 false; \
1273         fi
1274 .endfor
1275 .for gid in ${CHECK_GIDS}
1276         @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
1277                 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
1278                 false; \
1279         fi
1280 .endfor
1281 .endif
1282 #
1283 # If installing over the running system (DESTDIR is / or unset) and the install
1284 # includes rescue, try running rescue from the objdir as a sanity check.  If
1285 # rescue is not functional (e.g., because it depends on a system call not
1286 # supported by the currently running kernel), abort the installation.
1287 #
1288 .if !make(distributeworld) && ${MK_RESCUE} != "no" && \
1289     (empty(DESTDIR) || ${DESTDIR} == "/") && empty(BYPASS_INSTALLCHECK_SH)
1290 _installcheck_world: __installcheck_sh_check
1291 __installcheck_sh_check: .PHONY
1292         @if [ "`${OBJTOP}/rescue/rescue/rescue sh -c 'echo OK'`" != \
1293             OK ]; then \
1294                 echo "rescue/sh check failed, installation aborted" >&2; \
1295                 false; \
1296         fi
1297 .endif
1298
1299 #
1300 # Required install tools to be saved in a scratch dir for safety.
1301 #
1302 .if ${MK_ZONEINFO} != "no"
1303 _zoneinfo=      zic tzsetup
1304 .endif
1305
1306 .if !defined(CROSSBUILD_HOST)
1307 _sysctl=sysctl
1308 .endif
1309
1310 ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \
1311         date echo egrep find grep id install ${_install-info} \
1312         ln make mkdir mtree mv pwd_mkdb \
1313         rm sed services_mkdb sh sort strip ${_sysctl} test true uname wc \
1314         ${_zoneinfo} ${LOCAL_ITOOLS}
1315
1316 # Needed for share/man
1317 .if ${MK_MAN_UTILS} != "no"
1318 ITOOLS+=makewhatis
1319 .endif
1320
1321 #
1322 # distributeworld
1323 #
1324 # Distributes everything compiled by a `buildworld'.
1325 #
1326 # installworld
1327 #
1328 # Installs everything compiled by a 'buildworld'.
1329 #
1330
1331 # Non-base distributions produced by the base system
1332 EXTRA_DISTRIBUTIONS=
1333 .if defined(_LIBCOMPAT)
1334 EXTRA_DISTRIBUTIONS+=   lib${libcompat}
1335 .endif
1336 .if ${MK_TESTS} != "no"
1337 EXTRA_DISTRIBUTIONS+=   tests
1338 .endif
1339
1340 DEBUG_DISTRIBUTIONS=
1341 .if ${MK_DEBUG_FILES} != "no"
1342 DEBUG_DISTRIBUTIONS+=   base ${EXTRA_DISTRIBUTIONS:S,tests,,}
1343 .endif
1344
1345 MTREE_MAGIC?=   mtree 2.0
1346
1347 distributeworld installworld stageworld: _installcheck_world .PHONY
1348         mkdir -p ${INSTALLTMP}
1349         progs=$$(for prog in ${ITOOLS}; do \
1350                 if progpath=`env PATH=${TMPPATH} which $$prog`; then \
1351                         echo $$progpath; \
1352                 else \
1353                         echo "Required tool $$prog not found in PATH ($$PATH)." >&2; \
1354                         exit 1; \
1355                 fi; \
1356             done); \
1357         if [ -z "${CROSSBUILD_HOST}" ] ; then \
1358                 libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
1359                     while read line; do \
1360                         set -- $$line; \
1361                         if [ "$$2 $$3" != "not found" ]; then \
1362                                 echo $$2; \
1363                         else \
1364                                 echo "Required library $$1 not found." >&2; \
1365                                 exit 1; \
1366                         fi; \
1367                     done); \
1368         fi; \
1369         cp $$libs $$progs ${INSTALLTMP}
1370         cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
1371 .if defined(NO_ROOT)
1372         -mkdir -p ${METALOG:H}
1373         echo "#${MTREE_MAGIC}" > ${METALOG}
1374 .endif
1375 .if make(distributeworld)
1376 .for dist in ${EXTRA_DISTRIBUTIONS}
1377         -mkdir ${DESTDIR}/${DISTDIR}/${dist}
1378         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1379             -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
1380         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1381             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1382         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1383             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
1384 .if ${MK_DEBUG_FILES} != "no"
1385         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1386             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
1387 .endif
1388 .if defined(_LIBCOMPAT)
1389         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1390             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1391 .if ${MK_DEBUG_FILES} != "no"
1392         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1393             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
1394 .endif
1395 .endif
1396 .if ${MK_TESTS} != "no" && ${dist} == "tests"
1397         -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
1398         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1399             -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
1400 .if ${MK_DEBUG_FILES} != "no"
1401         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1402             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
1403 .endif
1404 .endif
1405 .if defined(NO_ROOT)
1406         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
1407             sed -e 's#^\./#./${dist}/#' >> ${METALOG}
1408         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
1409             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1410         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
1411             sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
1412 .if defined(_LIBCOMPAT)
1413         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
1414             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1415 .endif
1416 .endif
1417 .endfor
1418         -mkdir ${DESTDIR}/${DISTDIR}/base
1419         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1420             METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
1421             DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
1422             LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
1423         ${INSTALL_SYMLINK} ${INSTALLFLAGS} usr/src/sys ${INSTALL_DDIR}/base/sys
1424 .endif # make(distributeworld)
1425         ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
1426             ${IMAKEENV} rm -rf ${INSTALLTMP}
1427 .if make(distributeworld)
1428 .for dist in ${EXTRA_DISTRIBUTIONS}
1429         find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete
1430 .endfor
1431 .if defined(NO_ROOT)
1432 .for dist in base ${EXTRA_DISTRIBUTIONS}
1433         @# For each file that exists in this dist, print the corresponding
1434         @# line from the METALOG.  This relies on the fact that
1435         @# a line containing only the filename will sort immediately before
1436         @# the relevant mtree line.
1437         cd ${DESTDIR}/${DISTDIR}; \
1438         find ./${dist} | sort -u ${METALOG} - | \
1439         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1440         ${DESTDIR}/${DISTDIR}/${dist}.meta
1441 .endfor
1442 .for dist in ${DEBUG_DISTRIBUTIONS}
1443         @# For each file that exists in this dist, print the corresponding
1444         @# line from the METALOG.  This relies on the fact that
1445         @# a line containing only the filename will sort immediately before
1446         @# the relevant mtree line.
1447         cd ${DESTDIR}/${DISTDIR}; \
1448         find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
1449         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1450         ${DESTDIR}/${DISTDIR}/${dist}.debug.meta
1451 .endfor
1452 .endif
1453 .endif # make(distributeworld)
1454 .if !make(packageworld) && ${MK_CAROOT} != "no"
1455         @if which openssl>/dev/null; then \
1456                 DESTDIR=${CERTCTLDESTDIR} PATH=${TMPPATH}:${PATH} \
1457                     sh ${SRCTOP}/usr.sbin/certctl/certctl.sh ${CERTCTLFLAGS} rehash \
1458         else \
1459                 echo "No openssl on the host, not rehashing certificates target -- /etc/ssl may not be populated."; \
1460         fi
1461 .endif
1462
1463 packageworld: .PHONY
1464 .for dist in base ${EXTRA_DISTRIBUTIONS}
1465 .if defined(NO_ROOT)
1466         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1467             tar cvf - --exclude usr/lib/debug \
1468             @${DESTDIR}/${DISTDIR}/${dist}.meta | \
1469             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1470 .else
1471         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1472             tar cvf - --exclude usr/lib/debug . | \
1473             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1474 .endif
1475 .endfor
1476
1477 .for dist in ${DEBUG_DISTRIBUTIONS}
1478 . if defined(NO_ROOT)
1479         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1480             tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
1481             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1482 . else
1483         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1484             tar cvLf - usr/lib/debug | \
1485             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1486 . endif
1487 .endfor
1488
1489 makeman: .PHONY
1490         ${_+_}cd ${.CURDIR}/tools/build/options; sh makeman > \
1491             ${.CURDIR}/share/man/man5/src.conf.5
1492
1493 # We can't assume here that ${TMPPATH} will include ${PATH} or /usr/libexec
1494 # because we may be building with a STRICTTMPPATH, so we explicitly include
1495 # /usr/libexec here for flua.  ${TMPPATH} still usefully includes anything else
1496 # we may need to function.
1497 _sysent_PATH=   ${TMPPATH}:/usr/libexec
1498 _sysent_dirs=   sys/kern
1499 _sysent_dirs+=  sys/compat/freebsd32
1500 _sysent_dirs+=  sys/compat/cloudabi32   \
1501                 sys/compat/cloudabi64
1502 _sysent_dirs+=  sys/amd64/linux         \
1503                 sys/amd64/linux32       \
1504                 sys/arm/linux           \
1505                 sys/arm64/linux         \
1506                 sys/i386/linux
1507
1508 sysent: .PHONY
1509 .for _dir in ${_sysent_dirs}
1510 sysent-${_dir}: .PHONY
1511         @echo "${MAKE} -C ${.CURDIR}/${_dir} sysent"
1512         ${_+_}@env PATH=${_sysent_PATH} ${MAKE} -C ${.CURDIR}/${_dir} sysent
1513
1514 sysent: sysent-${_dir}
1515 .endfor
1516
1517 #
1518 # reinstall
1519 #
1520 # If you have a build server, you can NFS mount the source and obj directories
1521 # and do a 'make reinstall' on the *client* to install new binaries from the
1522 # most recent server build.
1523 #
1524 restage reinstall: .MAKE .PHONY
1525         @echo "--------------------------------------------------------------"
1526         @echo ">>> Making hierarchy"
1527         @echo "--------------------------------------------------------------"
1528         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1529             LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
1530 .if make(restage)
1531         @echo "--------------------------------------------------------------"
1532         @echo ">>> Making distribution"
1533         @echo "--------------------------------------------------------------"
1534         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1535             LOCAL_MTREE=${LOCAL_MTREE:Q} distribution
1536 .endif
1537         @echo
1538         @echo "--------------------------------------------------------------"
1539         @echo ">>> Installing everything started on `LC_ALL=C date`"
1540         @echo "--------------------------------------------------------------"
1541         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
1542 .if defined(_LIBCOMPAT)
1543         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
1544 .endif
1545         @echo "--------------------------------------------------------------"
1546         @echo ">>> Installing everything completed on `LC_ALL=C date`"
1547         @echo "--------------------------------------------------------------"
1548
1549 redistribute: .MAKE .PHONY
1550         @echo "--------------------------------------------------------------"
1551         @echo ">>> Distributing everything"
1552         @echo "--------------------------------------------------------------"
1553         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1554 .if defined(_LIBCOMPAT)
1555         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1556             DISTRIBUTION=lib${libcompat}
1557 .endif
1558
1559 distrib-dirs distribution: .MAKE .PHONY
1560         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1561             ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1562 .if make(distribution)
1563         ${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1564                 ${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1565                 METALOG=${METALOG} MK_TESTS=no \
1566                 MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} installconfig
1567 .endif
1568
1569 #
1570 # buildkernel and installkernel
1571 #
1572 # Which kernels to build and/or install is specified by setting
1573 # KERNCONF. If not defined a GENERIC kernel is built/installed.
1574 # Only the existing (depending TARGET) config files are used
1575 # for building kernels and only the first of these is designated
1576 # as the one being installed.
1577 #
1578 # Note that we have to use TARGET instead of TARGET_ARCH when
1579 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
1580 # be set to cross-build, we have to make sure TARGET is set
1581 # properly.
1582
1583 .if defined(KERNFAST)
1584 NO_KERNELCLEAN= t
1585 NO_KERNELCONFIG=        t
1586 NO_KERNELOBJ=           t
1587 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1588 .if !defined(KERNCONF) && ${KERNFAST} != "1"
1589 KERNCONF=${KERNFAST}
1590 .endif
1591 .endif
1592 .if ${TARGET_ARCH} == "powerpc64"
1593 KERNCONF?=      GENERIC64
1594 .else
1595 KERNCONF?=      GENERIC
1596 .endif
1597 INSTKERNNAME?=  kernel
1598
1599 KERNSRCDIR?=    ${.CURDIR}/sys
1600 KRNLCONFDIR=    ${KERNSRCDIR}/${TARGET}/conf
1601 KRNLOBJDIR=     ${OBJTOP}${KERNSRCDIR:C,^${.CURDIR},,}
1602 KERNCONFDIR?=   ${KRNLCONFDIR}
1603
1604 BUILDKERNELS=
1605 INSTALLKERNEL=
1606 .if defined(NO_INSTALLKERNEL)
1607 # All of the BUILDKERNELS loops start at index 1.
1608 BUILDKERNELS+= dummy
1609 .endif
1610 .for _kernel in ${KERNCONF}
1611 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${_kernel})
1612 BUILDKERNELS+=  ${_kernel}
1613 .if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1614 INSTALLKERNEL= ${_kernel}
1615 .endif
1616 .else
1617 .if make(buildkernel)
1618 .error Missing KERNCONF ${KERNCONFDIR}/${_kernel}
1619 .endif
1620 .endif
1621 .endfor
1622
1623 _cleankernobj_fast_depend_hack: .PHONY
1624 # 20191009  r353340  removal of opensolaris_atomic.S (also r353381)
1625 .if ${MACHINE} != i386
1626 .for f in opensolaris_atomic
1627 .for m in opensolaris zfs
1628         @if [ -e "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o" ] && \
1629             grep -q ${f}.S "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o"; then \
1630                 echo "Removing stale dependencies for opensolaris_atomic"; \
1631                 rm -f ${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.*; \
1632         fi
1633 .endfor
1634 .endfor
1635 .endif
1636
1637 ${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1638
1639 # record kernel(s) build time in seconds
1640 .if make(buildkernel)
1641 _BUILDKERNEL_START!= date '+%s'
1642 .endif
1643
1644 #
1645 # buildkernel
1646 #
1647 # Builds all kernels defined by BUILDKERNELS.
1648 #
1649 buildkernel: .MAKE .PHONY
1650 .if empty(BUILDKERNELS:Ndummy)
1651         @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1652         false
1653 .endif
1654         @echo
1655 .for _kernel in ${BUILDKERNELS:Ndummy}
1656         @echo "--------------------------------------------------------------"
1657         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1658         @echo "--------------------------------------------------------------"
1659         @echo "===> ${_kernel}"
1660         mkdir -p ${KRNLOBJDIR}
1661 .if !defined(NO_KERNELCONFIG)
1662         @echo
1663         @echo "--------------------------------------------------------------"
1664         @echo ">>> stage 1: configuring the kernel"
1665         @echo "--------------------------------------------------------------"
1666         cd ${KRNLCONFDIR}; \
1667                 PATH=${TMPPATH} \
1668                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1669                         -I '${KERNCONFDIR}' -I '${KRNLCONFDIR}' \
1670                         '${KERNCONFDIR}/${_kernel}'
1671 .endif
1672 .if ${MK_CLEAN} == "yes" && !defined(NO_KERNELCLEAN)
1673         @echo
1674         @echo "--------------------------------------------------------------"
1675         @echo ">>> stage 2.1: cleaning up the object tree"
1676         @echo "--------------------------------------------------------------"
1677         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1678 .else
1679         ${_+_}cd ${.CURDIR}; ${WMAKE} _cleankernobj_fast_depend_hack
1680 .endif
1681 .if !defined(NO_KERNELOBJ)
1682         @echo
1683         @echo "--------------------------------------------------------------"
1684         @echo ">>> stage 2.2: rebuilding the object tree"
1685         @echo "--------------------------------------------------------------"
1686         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1687 .endif
1688         @echo
1689         @echo "--------------------------------------------------------------"
1690         @echo ">>> stage 2.3: build tools"
1691         @echo "--------------------------------------------------------------"
1692         ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1693         @echo
1694         @echo "--------------------------------------------------------------"
1695         @echo ">>> stage 3.1: building everything"
1696         @echo "--------------------------------------------------------------"
1697         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1698         @echo "--------------------------------------------------------------"
1699         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1700         @echo "--------------------------------------------------------------"
1701
1702 .endfor
1703         @seconds=$$(($$(date '+%s') - ${_BUILDKERNEL_START})); \
1704           echo -n ">>> Kernel(s) ${BUILDKERNELS} built in $$seconds seconds, "; \
1705           echo "ncpu: $$(${_ncpu_cmd})${.MAKE.JOBS:S/^/, make -j/}"
1706         @echo "--------------------------------------------------------------"
1707
1708 NO_INSTALLEXTRAKERNELS?=        yes
1709
1710 #
1711 # installkernel, etc.
1712 #
1713 # Install the kernel defined by INSTALLKERNEL
1714 #
1715 installkernel installkernel.debug \
1716 reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1717 .if !defined(NO_INSTALLKERNEL)
1718 .if empty(INSTALLKERNEL)
1719         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1720         false
1721 .endif
1722         @echo "--------------------------------------------------------------"
1723         @echo ">>> Installing kernel ${INSTALLKERNEL} on $$(LC_ALL=C date)"
1724         @echo "--------------------------------------------------------------"
1725         ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1726             ${CROSSENV} PATH=${TMPPATH} \
1727             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1728         @echo "--------------------------------------------------------------"
1729         @echo ">>> Installing kernel ${INSTALLKERNEL} completed on $$(LC_ALL=C date)"
1730         @echo "--------------------------------------------------------------"
1731 .endif
1732 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1733 .for _kernel in ${BUILDKERNELS:[2..-1]}
1734         @echo "--------------------------------------------------------------"
1735         @echo ">>> Installing kernel ${_kernel} $$(LC_ALL=C date)"
1736         @echo "--------------------------------------------------------------"
1737         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1738             ${CROSSENV} PATH=${TMPPATH} \
1739             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1740         @echo "--------------------------------------------------------------"
1741         @echo ">>> Installing kernel ${_kernel} completed on $$(LC_ALL=C date)"
1742         @echo "--------------------------------------------------------------"
1743 .endfor
1744 .endif
1745
1746 distributekernel distributekernel.debug: .PHONY
1747 .if !defined(NO_INSTALLKERNEL)
1748 .if empty(INSTALLKERNEL)
1749         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1750         false
1751 .endif
1752         mkdir -p ${DESTDIR}/${DISTDIR}
1753 .if defined(NO_ROOT)
1754         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1755 .endif
1756         ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1757             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1758             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1759             DESTDIR=${INSTALL_DDIR}/kernel \
1760             ${.TARGET:S/distributekernel/install/}
1761 .if defined(NO_ROOT)
1762         @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1763             ${DESTDIR}/${DISTDIR}/kernel.meta
1764 .endif
1765 .endif
1766 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1767 .for _kernel in ${BUILDKERNELS:[2..-1]}
1768 .if defined(NO_ROOT)
1769         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1770 .endif
1771         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1772             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1773             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1774             KERNEL=${INSTKERNNAME}.${_kernel} \
1775             DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1776             ${.TARGET:S/distributekernel/install/}
1777 .if defined(NO_ROOT)
1778         @sed -e "s|^./kernel.${_kernel}|.|" \
1779             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1780             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1781 .endif
1782 .endfor
1783 .endif
1784
1785 packagekernel: .PHONY
1786 .if defined(NO_ROOT)
1787 .if !defined(NO_INSTALLKERNEL)
1788         cd ${DESTDIR}/${DISTDIR}/kernel; \
1789             tar cvf - --exclude '*.debug' \
1790             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1791             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1792 .endif
1793 .if ${MK_DEBUG_FILES} != "no"
1794         cd ${DESTDIR}/${DISTDIR}/kernel; \
1795             tar cvf - --include '*/*/*.debug' \
1796             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1797             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1798 .endif
1799 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1800 .for _kernel in ${BUILDKERNELS:[2..-1]}
1801         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1802             tar cvf - --exclude '*.debug' \
1803             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1804             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1805 .if ${MK_DEBUG_FILES} != "no"
1806         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1807             tar cvf - --include '*/*/*.debug' \
1808             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1809             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1810 .endif
1811 .endfor
1812 .endif
1813 .else
1814 .if !defined(NO_INSTALLKERNEL)
1815         cd ${DESTDIR}/${DISTDIR}/kernel; \
1816             tar cvf - --exclude '*.debug' . | \
1817             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1818 .endif
1819 .if ${MK_DEBUG_FILES} != "no"
1820         cd ${DESTDIR}/${DISTDIR}/kernel; \
1821             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1822             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1823 .endif
1824 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1825 .for _kernel in ${BUILDKERNELS:[2..-1]}
1826         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1827             tar cvf - --exclude '*.debug' . | \
1828             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1829 .if ${MK_DEBUG_FILES} != "no"
1830         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1831             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1832             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1833 .endif
1834 .endfor
1835 .endif
1836 .endif
1837
1838 stagekernel: .PHONY
1839         ${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1840
1841 PORTSDIR?=      /usr/ports
1842 WSTAGEDIR?=     ${OBJTOP}/worldstage
1843 KSTAGEDIR?=     ${OBJTOP}/kernelstage
1844 REPODIR?=       ${OBJROOT}repo
1845 PKG_FORMAT?=    txz
1846 PKGSIGNKEY?=    # empty
1847 PKG_OUTPUT_DIR?=        ${PKG_VERSION}
1848
1849 .ORDER:         stage-packages create-packages
1850 .ORDER:         create-packages create-world-packages
1851 .ORDER:         create-packages create-kernel-packages
1852 .ORDER:         create-packages sign-packages
1853
1854 _pkgbootstrap: .PHONY
1855 .if make(*package*) && !exists(${LOCALBASE}/sbin/pkg)
1856         @env ASSUME_ALWAYS_YES=YES pkg bootstrap
1857 .endif
1858
1859 .if make(create-world-packages-jobs) || make(create-kernel-packages*) || make(real-update-packages)
1860 PKG_ABI!=${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI
1861 .endif
1862
1863 .if !defined(PKG_VERSION_FROM)
1864 .if defined(PKG_ABI)
1865 PKG_VERSION_FROM!=/usr/bin/readlink ${REPODIR}/${PKG_ABI}/latest
1866 .endif
1867 .endif
1868
1869 packages: .PHONY
1870         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1871
1872 update-packages: .PHONY
1873         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-update-packages
1874
1875 package-pkg: .PHONY
1876         rm -rf /tmp/ports.${TARGET} || :
1877         env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \
1878                 PKG_CMD=${PKG_CMD} PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} \
1879                 WSTAGEDIR=${WSTAGEDIR} \
1880                 sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1881
1882 real-packages:  stage-packages create-packages sign-packages .PHONY
1883
1884 real-update-packages: stage-packages .PHONY
1885         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} create-packages
1886         @echo "==> Checking for new packages (comparing ${PKG_VERSION} to ${PKG_VERSION_FROM})"
1887         @for pkg in ${REPODIR}/${PKG_ABI}/${PKG_VERSION_FROM}/${PKG_NAME_PREFIX}-*; do \
1888           pkgname=$$(pkg query -F $${pkg} '%n' | sed 's/${PKG_NAME_PREFIX}-\(.*\)/\1/') ; \
1889           newpkgname=${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION}.${PKG_FORMAT} ; \
1890           oldsum=$$(pkg query -F $${pkg} '%X') ; \
1891           if [ ! -f ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} ]; then \
1892             continue; \
1893           fi ; \
1894           newsum=$$(pkg query -F ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} '%X') ; \
1895           if [ "$${oldsum}" == "$${newsum}" ]; then \
1896            echo "==> Keeping old ${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION_FROM}.${PKG_FORMAT}" ; \
1897            rm ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} ; \
1898            cp $${pkg} ${REPODIR}/${PKG_ABI}/${PKG_VERSION} ; \
1899           else \
1900             echo "==> New package $${newpkgname}" ; \
1901           fi ; \
1902         done
1903         ${_+_}@cd ${.CURDIR}; \
1904                 ${MAKE} -f Makefile.inc1 PKG_VERSION=${PKG_VERSION} sign-packages
1905
1906 stage-packages-world: .PHONY
1907         @mkdir -p ${WSTAGEDIR}
1908         ${_+_}@cd ${.CURDIR}; \
1909                 ${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT stageworld
1910
1911 stage-packages-kernel: .PHONY
1912         @mkdir -p ${KSTAGEDIR}
1913         ${_+_}@cd ${.CURDIR}; \
1914                 ${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT stagekernel
1915
1916 stage-packages: .PHONY stage-packages-world stage-packages-kernel
1917
1918 _repodir: .PHONY
1919         @mkdir -p ${REPODIR}
1920
1921 create-packages-world:  _pkgbootstrap _repodir .PHONY
1922         ${_+_}@cd ${.CURDIR}; \
1923                 ${MAKE} -f Makefile.inc1 \
1924                         DESTDIR=${WSTAGEDIR} \
1925                         PKG_VERSION=${PKG_VERSION} create-world-packages
1926
1927 create-packages-kernel: _pkgbootstrap _repodir .PHONY
1928         ${_+_}@cd ${.CURDIR}; \
1929                 ${MAKE} -f Makefile.inc1 \
1930                         DESTDIR=${KSTAGEDIR} \
1931                         PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1932                         SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1933                         create-kernel-packages
1934
1935 create-packages: .PHONY create-packages-world create-packages-kernel
1936
1937 create-world-packages:  _pkgbootstrap .PHONY
1938         @rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1939         @cd ${WSTAGEDIR} ; \
1940                 env -i LC_COLLATE=C sort ${WSTAGEDIR}/${DISTDIR}/METALOG | \
1941                 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk
1942         @for plist in ${WSTAGEDIR}/*.plist; do \
1943           plist=$${plist##*/} ; \
1944           pkgname=$${plist%.plist} ; \
1945           echo "_PKGS+= $${pkgname}" ; \
1946         done > ${WSTAGEDIR}/packages.mk
1947         ${_+_}@cd ${.CURDIR}; \
1948                 ${MAKE} -f Makefile.inc1 create-world-packages-jobs \
1949                 SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1950                 .MAKE.JOB.PREFIX=
1951
1952 .if make(create-world-packages-jobs)
1953 .include "${WSTAGEDIR}/packages.mk"
1954 .endif
1955
1956 create-world-packages-jobs: .PHONY
1957 .for pkgname in ${_PKGS}
1958 create-world-packages-jobs: create-world-package-${pkgname}
1959 create-world-package-${pkgname}: .PHONY
1960         @sh ${SRCDIR}/release/packages/generate-ucl.sh -o ${pkgname} \
1961                 -s ${SRCDIR} -u ${WSTAGEDIR}/${pkgname}.ucl
1962         @awk -F\" ' \
1963                 /^name/ { printf("===> Creating %s-", $$2); next } \
1964                 /^version/ { print $$2; next } \
1965                 ' ${WSTAGEDIR}/${pkgname}.ucl
1966         @if [ "${pkgname}" == "runtime" ]; then \
1967                 sed -i '' -e "s/%VCS_REVISION%/${VCS_REVISION}/" ${WSTAGEDIR}/${pkgname}.ucl ; \
1968         fi
1969         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1970                 create -f ${PKG_FORMAT} -M ${WSTAGEDIR}/${pkgname}.ucl \
1971                 -p ${WSTAGEDIR}/${pkgname}.plist \
1972                 -r ${WSTAGEDIR} \
1973                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1974 .endfor
1975
1976 _default_flavor=        -default
1977 .if make(*package*) && exists(${KSTAGEDIR}/kernel.meta)
1978 . if ${MK_DEBUG_FILES} != "no"
1979 _debug=-dbg
1980 . endif
1981 create-kernel-packages: .PHONY
1982 . for flavor in "" ${_debug}
1983 create-kernel-packages: create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}
1984 create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}: _pkgbootstrap .PHONY
1985         @cd ${KSTAGEDIR}/${DISTDIR} ; \
1986         env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.meta | \
1987         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1988                 -v kernel=yes -v _kernconf=${INSTALLKERNEL} ; \
1989         sed -e "s/%VERSION%/${PKG_VERSION}/" \
1990                 -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1991                 -e "s/%KERNELDIR%/kernel/" \
1992                 -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1993                 -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1994                 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
1995                 -e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
1996                 -e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
1997                 -e "s|%PKG_WWW%|${PKG_WWW}|" \
1998                 ${SRCDIR}/release/packages/kernel.ucl \
1999                 > ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
2000         awk -F\" ' \
2001                 /name/ { printf("===> Creating %s-", $$2); next } \
2002                 /version/ {print $$2; next } ' \
2003                 ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
2004         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
2005                 create -f ${PKG_FORMAT} \
2006                 -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
2007                 -p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
2008                 -r ${KSTAGEDIR}/${DISTDIR} \
2009                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
2010 . endfor
2011 .endif
2012 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
2013 . for _kernel in ${BUILDKERNELS:[2..-1]}
2014 .  if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
2015 .   if ${MK_DEBUG_FILES} != "no"
2016 _debug=-dbg
2017 .   endif
2018 .   for flavor in "" ${_debug}
2019 create-kernel-packages: create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}
2020 create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}: _pkgbootstrap .PHONY
2021         @cd ${KSTAGEDIR}/kernel.${_kernel} ; \
2022         env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.${_kernel}.meta | \
2023         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
2024                 -v kernel=yes -v _kernconf=${_kernel} ; \
2025         sed -e "s/%VERSION%/${PKG_VERSION}/" \
2026                 -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
2027                 -e "s/%KERNELDIR%/kernel.${_kernel}/" \
2028                 -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
2029                 -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
2030                 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
2031                 -e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
2032                 -e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
2033                 -e "s|%PKG_WWW%|${PKG_WWW}|" \
2034                 ${SRCDIR}/release/packages/kernel.ucl \
2035                 > ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2036         awk -F\" ' \
2037                 /name/ { printf("===> Creating %s-", $$2); next } \
2038                 /version/ {print $$2; next } ' \
2039                 ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2040         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
2041                 create -f ${PKG_FORMAT} \
2042                 -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
2043                 -p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
2044                 -r ${KSTAGEDIR}/kernel.${_kernel} \
2045                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
2046 .   endfor
2047 .  endif
2048 . endfor
2049 .endif
2050
2051 sign-packages:  _pkgbootstrap .PHONY
2052         printf "version = 2;\npacking_format = \"${PKG_FORMAT}\";\n" > ${WSTAGEDIR}/meta
2053         @[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest" ] && \
2054                 unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest ; \
2055         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname repo \
2056                 -m ${WSTAGEDIR}/meta \
2057                 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2058                 ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2059                 ${PKGSIGNKEY} ; \
2060         cd ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI); \
2061         ln -s ${PKG_OUTPUT_DIR} latest
2062
2063 #
2064 #
2065 # checkworld
2066 #
2067 # Run test suite on installed world.
2068 #
2069 checkworld: .PHONY
2070         @if [ ! -x "${LOCALBASE}/bin/kyua" ] && [ ! -x "/usr/bin/kyua" ]; then \
2071                 echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
2072                 exit 1; \
2073         fi
2074         ${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile
2075
2076 #
2077 #
2078 # doxygen
2079 #
2080 # Build the API documentation with doxygen
2081 #
2082 doxygen: .PHONY
2083         @if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \
2084                 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
2085                 exit 1; \
2086         fi
2087         ${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
2088
2089 #
2090 # update
2091 #
2092 # Update the source tree(s), by running svn/svnup to update to the
2093 # latest copy.
2094 #
2095 update: .PHONY
2096 .if defined(SVN_UPDATE)
2097         @echo "--------------------------------------------------------------"
2098         @echo ">>> Updating ${.CURDIR} using Subversion"
2099         @echo "--------------------------------------------------------------"
2100         @(cd ${.CURDIR}; ${SVN_CMD} update ${SVNFLAGS})
2101 .endif
2102
2103 #
2104 # ------------------------------------------------------------------------
2105 #
2106 # From here onwards are utility targets used by the 'make world' and
2107 # related targets.  If your 'world' breaks, you may like to try to fix
2108 # the problem and manually run the following targets to attempt to
2109 # complete the build.  Beware, this is *not* guaranteed to work, you
2110 # need to have a pretty good grip on the current state of the system
2111 # to attempt to manually finish it.  If in doubt, 'make world' again.
2112 #
2113
2114 #
2115 # legacy: Build compatibility shims for the next three targets. This is a
2116 # minimal set of tools and shims necessary to compensate for older systems
2117 # which don't have the APIs required by the targets built in bootstrap-tools,
2118 # build-tools or cross-tools.
2119 #
2120
2121 # libnv and libsbuf are requirements for config(8), which is an unconditional
2122 # bootstrap-tool.
2123 _config_deps= lib/libnv lib/libsbuf
2124
2125 legacy: .PHONY
2126 .if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0
2127         @echo "ERROR: Source upgrades from versions prior to ${MINIMUM_SUPPORTED_REL} are not supported."; \
2128         false
2129 .endif
2130
2131 .for _tool in tools/build
2132         ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
2133             cd ${.CURDIR}/${_tool}; \
2134             if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2135             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy includes; \
2136             ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no all; \
2137             ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no \
2138                 DESTDIR=${WORLDTMP}/legacy install
2139 .endfor
2140
2141 #
2142 # bootstrap-tools: Build tools needed for compatibility. These are binaries that
2143 # are built to build other binaries in the system. However, the focus of these
2144 # binaries is usually quite narrow. Bootstrap tools use the host's compiler and
2145 # libraries, augmented by -legacy, in addition to the libraries built during
2146 # bootstrap-tools.
2147 #
2148 _bt=            _bootstrap-tools
2149
2150 # We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
2151 # accidentally run tools that are incompatible but happen to be in $PATH.
2152 # This is especially important when building on Linux/MacOS where many of the
2153 # programs used during the build accept different flags or generate different
2154 # output. On those platforms we only symlink the tools known to be compatible
2155 # (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
2156 # from the FreeBSD sources during the bootstrap-tools stage.
2157 # We want to build without the user's $PATH starting in the bootstrap-tools
2158 # phase so the tools used in that phase (ln, cp, etc) must have already been
2159 # linked to $WORLDTMP. The tools are listed in the _host_tools_to_symlink
2160 # variable in tools/build/Makefile and are linked during the legacy phase.
2161 # Since they could be Linux or MacOS binaries, too we must only use flags that
2162 # are portable across operating systems.
2163
2164 # If BOOTSTRAP_ALL_TOOLS is set we will build all the required tools from the
2165 # current source tree. Otherwise we create a symlink to the version found in
2166 # $PATH during the bootstrap-tools stage.
2167 # When building on non-FreeBSD systems we can't assume that the host binaries
2168 # accept compatible flags or produce compatible output. Therefore we force
2169 # BOOTSTRAP_ALL_TOOLS and just build the FreeBSD version of the binary.
2170 .if defined(CROSSBUILD_HOST)
2171 BOOTSTRAP_ALL_TOOLS:=   1
2172 .endif
2173 .if defined(BOOTSTRAP_ALL_TOOLS)
2174 # BOOTSTRAPPING will be set on the command line so we can't override it here.
2175 # Instead set BOOTSTRAPPING_OSRELDATE so that the value 0 is set ${BSARGS}
2176 BOOTSTRAPPING_OSRELDATE:=       0
2177 .endif
2178
2179 # libnv and libsbuf are requirements for config(8), which is an unconditional
2180 # bootstrap-tool.
2181 _config=usr.sbin/config lib/libnv lib/libsbuf
2182 ${_bt}-usr.sbin/config: ${_bt}-lib/libnv ${_bt}-lib/libsbuf
2183
2184 .if ${MK_GAMES} != "no"
2185 _strfile=       usr.bin/fortune/strfile
2186 .endif
2187
2188 .if ${MK_VT} != "no"
2189 _vtfontcvt=     usr.bin/vtfontcvt
2190 .endif
2191
2192 # If we are not building the bootstrap because BOOTSTRAPPING is sufficient
2193 # we symlink the host version to $WORLDTMP instead. By doing this we can also
2194 # detect when a bootstrap tool is being used without the required MK_FOO.
2195 # If you add a new bootstrap tool where we could also use the host version,
2196 # please ensure that you also add a .else case where you add the tool to the
2197 # _bootstrap_tools_links variable.
2198 .if ${BOOTSTRAPPING} < 1000033
2199 # Note: lex needs m4 to build but m4 also depends on lex (which needs m4 to
2200 # generate any files). To fix this cyclic dependency we can build a bootstrap
2201 # version of m4 (with pre-generated files) then use that to build the real m4.
2202 # We can't simply use the host m4 since e.g. the macOS version does not accept
2203 # the flags that are passed by lex.
2204 # For lex we also use the pre-gerated files since we would otherwise need to
2205 # build awk and sed first (which need lex to build)
2206 # TODO: add a _bootstrap_lex and then build the real lex afterwards
2207 _lex=           usr.bin/lex
2208 _m4=            tools/build/bootstrap-m4 usr.bin/m4
2209 ${_bt}-tools/build/bootstrap-m4: ${_bt}-usr.bin/lex ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc
2210 ${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc ${_bt}-usr.bin/lex ${_bt}-tools/build/bootstrap-m4
2211 _bt_m4_depend=${_bt}-usr.bin/m4
2212 _bt_lex_depend=${_bt}-usr.bin/lex ${_bt_m4_depend}
2213 .else
2214 _bootstrap_tools_links+=m4 lex
2215 .endif
2216
2217 # ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
2218 # r296685 fix cross-endian objcopy
2219 # r310724 fixed PR 215350, a crash in libdwarf with objects built by GCC 6.2.
2220 # r334881 added libdwarf constants used by ctfconvert.
2221 # r338478 fixed a crash in objcopy for mips64el objects
2222 # r339083 libelf: correct mips64el test to use ELF header
2223 # r348347 Add missing powerpc64 relocation support to libdwarf
2224 .if ${BOOTSTRAPPING} < 1300030
2225 _elftoolchain_libs= lib/libelf lib/libdwarf lib/libzstd
2226 ${_bt}-lib/libelf: ${_bt_m4_depend}
2227 ${_bt}-lib/libdwarf: ${_bt_m4_depend}
2228 .endif
2229
2230 # flua is required to regenerate syscall files.  It first appeared during the
2231 # 13.0-CURRENT cycle, thus needs to be built on -older releases and stable
2232 # branches.
2233 .if ${BOOTSTRAPPING} < 1300059
2234 ${_bt}-libexec/flua: ${_bt}-lib/liblua ${_bt}-lib/libucl
2235 _flua= lib/liblua lib/libucl libexec/flua
2236 .endif
2237
2238 # r245440 mtree -N support added
2239 # r313404 requires sha384.h for libnetbsd, added to libmd in r292782
2240 .if ${BOOTSTRAPPING} < 1100093
2241 _nmtree=        lib/libmd \
2242                 lib/libnetbsd \
2243                 usr.sbin/nmtree
2244
2245 ${_bt}-lib/libnetbsd: ${_bt}-lib/libmd
2246 ${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
2247 .else
2248 _bootstrap_tools_links+=mtree
2249 .endif
2250
2251 # r246097: log addition login.conf.db, passwd, pwd.db, and spwd.db with cat -l
2252 .if ${BOOTSTRAPPING} < 1000027
2253 _cat=           bin/cat
2254 .else
2255 _bootstrap_tools_links+=cat
2256 .endif
2257
2258 # r277259 crunchide: Correct 64-bit section header offset
2259 # r281674 crunchide: always include both 32- and 64-bit ELF support
2260 .if ${BOOTSTRAPPING} < 1100078
2261 _crunchide=     usr.sbin/crunch/crunchide
2262 .else
2263 _bootstrap_tools_links+=crunchide
2264 .endif
2265
2266 # 1300115: Higher WARNS fixes
2267 .if ${BOOTSTRAPPING} < 1202502 || \
2268         (${BOOTSTRAPPING} > 1300000 && ${BOOTSTRAPPING} < 1300115)
2269 _crunchgen=     usr.sbin/crunch/crunchgen
2270 .else
2271 _bootstrap_tools_links+=crunchgen
2272 .endif
2273
2274 # r296926 -P keymap search path, MFC to stable/10 in r298297
2275 # Note: kbdcontrol can not be bootstrapped on non-FreeBSD systems
2276 .if !defined(CROSSBUILD_HOST)
2277 .if (${BOOTSTRAPPING} < 1003501 || \
2278         (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103))
2279 _kbdcontrol=    usr.sbin/kbdcontrol
2280 .else
2281 _bootstrap_tools_links+=kbdcontrol
2282 .endif
2283 .endif
2284
2285 _yacc=          usr.bin/yacc
2286
2287 .if ${MK_BSNMP} != "no"
2288 _gensnmptree=   usr.sbin/bsnmpd/gensnmptree
2289 .endif
2290
2291
2292 # We need to build tblgen when we're building clang or lld, either as
2293 # bootstrap tools, or as the part of the normal build.
2294 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" || \
2295     ${MK_LLD_BOOTSTRAP} != "no" || ${MK_LLD} != "no"
2296 _clang_tblgen= \
2297         lib/clang/libllvmminimal \
2298         usr.bin/clang/llvm-tblgen \
2299         usr.bin/clang/clang-tblgen \
2300         usr.bin/clang/lldb-tblgen
2301 # XXX: lldb-tblgen is not needed, if top-level MK_LLDB=no
2302
2303 ${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmminimal
2304 ${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmminimal
2305 ${_bt}-usr.bin/clang/lldb-tblgen: ${_bt}-lib/clang/libllvmminimal
2306 .endif
2307
2308 .if ${MK_LOCALES} != "no"
2309 _localedef=     usr.bin/localedef
2310 ${_bt}-usr.bin/localedef: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
2311 .endif
2312
2313 .if ${MK_KERBEROS} != "no"
2314 _kerberos5_bootstrap_tools= \
2315         kerberos5/tools/make-roken \
2316         kerberos5/lib/libroken \
2317         kerberos5/lib/libvers \
2318         kerberos5/tools/asn1_compile \
2319         kerberos5/tools/slc \
2320         usr.bin/compile_et
2321
2322 .ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
2323 .for _tool in ${_kerberos5_bootstrap_tools}
2324 ${_bt}-${_tool}: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
2325 .endfor
2326 .endif
2327
2328 ${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd
2329
2330 # The tools listed in _basic_bootstrap_tools will generally not be
2331 # bootstrapped unless BOOTSTRAP_ALL_TOOL is set. However, when building on a
2332 # Linux or MacOS host the host versions are incompatible so we need to build
2333 # them from the source tree. Usually the link name will be the same as the subdir,
2334 # but some directories such as grep or test install multiple binaries. In that
2335 # case we use the _basic_bootstrap_tools_multilink variable which is a list of
2336 # subdirectory and comma-separated list of files.
2337 _basic_bootstrap_tools_multilink=usr.bin/grep grep,egrep,fgrep
2338 _basic_bootstrap_tools_multilink+=bin/test test,[
2339 # bootstrap tools needed by buildworld:
2340 _basic_bootstrap_tools+=usr.bin/cut bin/expr usr.bin/gencat usr.bin/join \
2341     usr.bin/mktemp bin/realpath bin/rmdir usr.bin/sed usr.bin/sort \
2342     usr.bin/truncate usr.bin/tsort
2343 # Some build scripts use nawk instead of awk (this happens at least in
2344 # cddl/contrib/opensolaris/lib/libdtrace/common/mknames.sh) so we need both awk
2345 # and nawk in ${WORLDTMP}/legacy/bin.
2346 _basic_bootstrap_tools_multilink+=usr.bin/awk awk,nawk
2347 # file2c is required for building usr.sbin/config:
2348 _basic_bootstrap_tools+=usr.bin/file2c
2349 # uuencode/uudecode required for share/tabset
2350 _basic_bootstrap_tools+=usr.bin/uuencode usr.bin/uudecode
2351 # xargs is required by mkioctls
2352 _basic_bootstrap_tools+=usr.bin/xargs
2353 # cap_mkdb is required for share/termcap:
2354 _basic_bootstrap_tools+=usr.bin/cap_mkdb
2355 # services_mkdb/pwd_mkdb are required for installworld:
2356 _basic_bootstrap_tools+=usr.sbin/services_mkdb usr.sbin/pwd_mkdb
2357 # ldd is required for installcheck (TODO: just always use /usr/bin/ldd instead?)
2358 .if !defined(CROSSBUILD_HOST)
2359 # ldd is only needed for updating the running system so we don't need to
2360 # bootstrap ldd on non-FreeBSD systems
2361 _basic_bootstrap_tools+=usr.bin/ldd
2362 .endif
2363 # sysctl/chflags are required for installkernel:
2364 .if !defined(CROSSBUILD_HOST)
2365 _basic_bootstrap_tools+=bin/chflags
2366 # Note: sysctl does not bootstrap on FreeBSD < 13 anymore, but that doesn't
2367 # matter since we don't need any of the new features for the build.
2368 _bootstrap_tools_links+=sysctl
2369 .else
2370 # When building on non-FreeBSD, install a fake chflags instead since the
2371 # version from the source tree cannot work. We also don't need sysctl since we
2372 # are install with -DNO_ROOT.
2373 _other_bootstrap_tools+=tools/build/cross-build/fake_chflags
2374 .endif
2375 # mkfifo is used by sys/conf/newvers.sh
2376 _basic_bootstrap_tools+=usr.bin/mkfifo
2377 # jot is needed for the mkimg tests
2378 _basic_bootstrap_tools+=usr.bin/jot
2379
2380 .if ${MK_BOOT} != "no"
2381 # md5 is used by boot/beri (and possibly others)
2382 _basic_bootstrap_tools+=sbin/md5
2383 .endif
2384
2385 .if ${MK_ZONEINFO} != "no"
2386 _basic_bootstrap_tools+=usr.sbin/zic usr.sbin/tzsetup
2387 .endif
2388
2389 .if defined(BOOTSTRAP_ALL_TOOLS)
2390 _other_bootstrap_tools+=${_basic_bootstrap_tools}
2391 .for _subdir _links in ${_basic_bootstrap_tools_multilink}
2392 _other_bootstrap_tools+=${_subdir}
2393 .endfor
2394 ${_bt}-usr.bin/awk: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2395 ${_bt}-bin/expr: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2396 # If we are bootstrapping file2c, we have to build it before config:
2397 ${_bt}-usr.sbin/config: ${_bt}-usr.bin/file2c ${_bt_lex_depend}
2398 # Note: no symlink to make/bmake in the !BOOTSTRAP_ALL_TOOLS case here since
2399 # the links to make/bmake make links will have already have been created in the
2400 # `make legacy` step. Not adding a link to make is important on non-FreeBSD
2401 # since "make" will usually point to GNU make there.
2402 _other_bootstrap_tools+=usr.bin/bmake
2403
2404 # Avoid dependency on host bz2 headers:
2405 _other_bootstrap_tools+=lib/libbz2
2406 ${_bt}-usr.bin/grep: ${_bt}-lib/libbz2
2407 .else
2408 # All tools in _basic_bootstrap_tools have the same name as the subdirectory
2409 # so we can use :T to get the name of the symlinks that we need to create.
2410 _bootstrap_tools_links+=${_basic_bootstrap_tools:T}
2411 .for _subdir _links in ${_basic_bootstrap_tools_multilink}
2412 _bootstrap_tools_links+=${_links:S/,/ /g}
2413 .endfor
2414 .endif  # defined(BOOTSTRAP_ALL_TOOLS)
2415
2416 # Link the tools that we need for building but don't need to bootstrap because
2417 # the host version is known to be compatible into ${WORLDTMP}/legacy
2418 # We do this before building any of the bootstrap tools in case they depend on
2419 # the presence of any of the links (e.g. as m4/lex/awk)
2420 ${_bt}-links: .PHONY
2421
2422 .for _tool in ${_bootstrap_tools_links}
2423 ${_bt}-link-${_tool}: .PHONY .MAKE
2424         @rm -f "${WORLDTMP}/legacy/bin/${_tool}"; \
2425         source_path=`which ${_tool}`; \
2426         if [ ! -e "$${source_path}" ] ; then \
2427                 echo "Cannot find host tool '${_tool}'"; false; \
2428         fi; \
2429         cp -pf "$${source_path}" "${WORLDTMP}/legacy/bin/${_tool}"
2430 ${_bt}-links: ${_bt}-link-${_tool}
2431 .endfor
2432
2433 bootstrap-tools: ${_bt}-links .PHONY
2434
2435 #       Please document (add comment) why something is in 'bootstrap-tools'.
2436 #       Try to bound the building of the bootstrap-tool to just the
2437 #       FreeBSD versions that need the tool built at this stage of the build.
2438 .for _tool in \
2439     ${_clang_tblgen} \
2440     ${_kerberos5_bootstrap_tools} \
2441     ${_strfile} \
2442     usr.bin/dtc \
2443     ${_cat} \
2444     ${_kbdcontrol} \
2445     ${_elftoolchain_libs} \
2446     usr.bin/lorder \
2447     lib/libopenbsd \
2448     usr.bin/mandoc \
2449     usr.bin/rpcgen \
2450     ${_yacc} \
2451     ${_m4} \
2452     ${_lex} \
2453     ${_other_bootstrap_tools} \
2454     usr.bin/xinstall \
2455     ${_gensnmptree} \
2456     ${_config} \
2457     ${_flua} \
2458     ${_crunchide} \
2459     ${_crunchgen} \
2460     ${_nmtree} \
2461     ${_vtfontcvt} \
2462     ${_localedef}
2463 ${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
2464         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2465                 cd ${.CURDIR}/${_tool}; \
2466                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2467                 if [ "${_tool}" = "usr.bin/lex" ]; then \
2468                         ${MAKE} DIRPRFX=${_tool}/ bootstrap; \
2469                 fi; \
2470                 ${MAKE} DIRPRFX=${_tool}/ all; \
2471                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy install
2472
2473 bootstrap-tools: ${_bt}-${_tool}
2474 .endfor
2475 .if target(${_bt}-lib/libmd)
2476 # If we are bootstrapping libmd (e.g. when building on macOS/Linux) add the
2477 # necessary dependencies:
2478 ${_bt}-usr.bin/sort: ${_bt}-lib/libmd
2479 ${_bt}-usr.bin/xinstall: ${_bt}-lib/libmd
2480 ${_bt}-sbin/md5: ${_bt}-lib/libmd
2481 .endif
2482
2483
2484 #
2485 # build-tools: Build special purpose build tools
2486 #
2487 .if !defined(NO_SHARE) && ${MK_SYSCONS} != "no"
2488 _share= share/syscons/scrnmaps
2489 .endif
2490
2491 .if ${MK_RESCUE} != "no"
2492 # rescue includes programs that have build-tools targets
2493 _rescue=rescue/rescue
2494 .endif
2495
2496 .if ${MK_TCSH} != "no"
2497 _tcsh=bin/csh
2498 .endif
2499 .if ${MK_FILE} != "no"
2500 _libmagic=lib/libmagic
2501 .endif
2502
2503 .if ${MK_PMC} != "no" && \
2504     (${TARGET_ARCH} == "aarch64" || ${TARGET_ARCH} == "amd64" || \
2505     ${TARGET_ARCH} == "i386")
2506 _jevents=lib/libpmc/pmu-events
2507 .endif
2508
2509 # kernel-toolchain skips _cleanobj, so handle cleaning up previous
2510 # build-tools directories if needed.
2511 .if ${MK_CLEAN} == "yes" && make(kernel-toolchain)
2512 _bt_clean=      ${CLEANDIR}
2513 .endif
2514
2515 .for _tool in \
2516     ${_tcsh} \
2517     bin/sh \
2518     ${LOCAL_TOOL_DIRS} \
2519     ${_jevents} \
2520     lib/ncurses/ncurses \
2521     lib/ncurses/ncursesw \
2522     ${_rescue} \
2523     ${_share} \
2524     usr.bin/awk \
2525     ${_libmagic} \
2526     usr.bin/mkesdb_static \
2527     usr.bin/mkcsmapper_static \
2528     usr.bin/vi/catalog
2529 build-tools_${_tool}: .PHONY
2530         ${_+_}@${ECHODIR} "===> ${_tool} (${_bt_clean:D${_bt_clean},}obj,build-tools)"; \
2531                 cd ${.CURDIR}/${_tool}; \
2532                 if [ -n "${_bt_clean}" ]; then ${MAKE} DIRPRFX=${_tool}/ ${_bt_clean}; fi; \
2533                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2534                 ${MAKE} DIRPRFX=${_tool}/ build-tools
2535 build-tools: build-tools_${_tool}
2536 .endfor
2537
2538 #
2539 # kernel-tools: Build kernel-building tools
2540 #
2541 kernel-tools: .PHONY
2542         mkdir -p ${WORLDTMP}/usr
2543         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2544             -p ${WORLDTMP}/usr >/dev/null
2545
2546 #
2547 # cross-tools: All the tools needed to build the rest of the system after
2548 # we get done with the earlier stages. It is the last set of tools needed
2549 # to begin building the target binaries.
2550 #
2551 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BUILD_WITH_STRICT_TMPPATH} != 0
2552 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
2553 _btxld=         usr.sbin/btxld
2554 .endif
2555 .endif
2556
2557 # Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
2558 # resulting from missing bug fixes or ELF Toolchain updates.
2559 .if ${MK_CDDL} != "no"
2560 _dtrace_tools= cddl/lib/libctf cddl/lib/libspl cddl/usr.bin/ctfconvert \
2561     cddl/usr.bin/ctfmerge
2562 .endif
2563
2564 # If we're given an XAS, don't build binutils.
2565 .if ${XAS:M/*} == ""
2566 .if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2567 _elftctools=    lib/libelftc \
2568                 lib/libpe \
2569                 usr.bin/objcopy \
2570                 usr.bin/nm \
2571                 usr.bin/size \
2572                 usr.bin/strings
2573 # These are not required by the build, but can be useful for developers who
2574 # cross-build on a FreeBSD 10 host:
2575 _elftctools+=   usr.bin/addr2line
2576 .endif
2577 .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2578 # If cross-building with an external binutils we still need to build strip for
2579 # the target (for at least crunchide).
2580 _elftctools=    lib/libelftc \
2581                 lib/libpe \
2582                 usr.bin/objcopy
2583 .endif
2584
2585 .if ${MK_CLANG_BOOTSTRAP} != "no"
2586 _clang=         usr.bin/clang
2587 .endif
2588 .if ${MK_LLD_BOOTSTRAP} != "no"
2589 _lld=           usr.bin/clang/lld
2590 .endif
2591 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
2592 _clang_libs=    lib/clang
2593 .endif
2594 .if ${MK_USB} != "no"
2595 _usb_tools=     stand/usb/tools
2596 .endif
2597
2598 .if ${BUILD_WITH_STRICT_TMPPATH} != 0 || defined(BOOTSTRAP_ALL_TOOLS)
2599 _ar=usr.bin/ar
2600 .endif
2601
2602 cross-tools: .MAKE .PHONY
2603 .for _tool in \
2604     ${LOCAL_XTOOL_DIRS} \
2605     ${_ar} \
2606     ${_clang_libs} \
2607     ${_clang} \
2608     ${_lld} \
2609     ${_elftctools} \
2610     ${_dtrace_tools} \
2611     ${_btxld} \
2612     ${_usb_tools}
2613         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2614                 cd ${.CURDIR}/${_tool}; \
2615                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2616                 ${MAKE} DIRPRFX=${_tool}/ all; \
2617                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP} install
2618 .endfor
2619
2620 #
2621 # native-xtools is the current target for qemu-user cross builds of ports
2622 # via poudriere and the imgact_binmisc kernel module.
2623 # This target merely builds a toolchan/sysroot, then builds the tools it wants
2624 # with the options it wants in a special MAKEOBJDIRPREFIX, using the toolchain
2625 # already built.  It then installs the static tools to NXBDESTDIR for Poudriere
2626 # to pickup.
2627 #
2628 NXBOBJROOT=     ${OBJROOT}${MACHINE}.${MACHINE_ARCH}/nxb/
2629 NXBOBJTOP=      ${NXBOBJROOT}${NXB_TARGET}.${NXB_TARGET_ARCH}
2630 NXTP?=          /nxb-bin
2631 .if ${NXTP:N/*}
2632 .error NXTP variable should be an absolute path
2633 .endif
2634 NXBDESTDIR?=    ${DESTDIR}${NXTP}
2635
2636 # This is the list of tools to be built/installed as static and where
2637 # appropriate to build for the given TARGET.TARGET_ARCH.
2638 NXBDIRS+= \
2639     bin/cat \
2640     bin/chmod \
2641     bin/cp \
2642     ${_tcsh} \
2643     bin/echo \
2644     bin/expr \
2645     bin/hostname \
2646     bin/ln \
2647     bin/ls \
2648     bin/mkdir \
2649     bin/mv \
2650     bin/ps \
2651     bin/realpath \
2652     bin/rm \
2653     bin/rmdir \
2654     bin/sh \
2655     bin/sleep \
2656     sbin/md5 \
2657     sbin/sysctl \
2658     usr.bin/addr2line \
2659     usr.bin/ar \
2660     usr.bin/awk \
2661     usr.bin/basename \
2662     usr.bin/bmake \
2663     usr.bin/bzip2 \
2664     usr.bin/cmp \
2665     usr.bin/diff \
2666     usr.bin/dirname \
2667     usr.bin/objcopy \
2668     usr.bin/env \
2669     usr.bin/fetch \
2670     usr.bin/find \
2671     usr.bin/grep \
2672     usr.bin/gzip \
2673     usr.bin/head \
2674     usr.bin/id \
2675     usr.bin/lex \
2676     usr.bin/limits \
2677     usr.bin/lorder \
2678     usr.bin/mandoc \
2679     usr.bin/mktemp \
2680     usr.bin/mt \
2681     usr.bin/nm \
2682     usr.bin/patch \
2683     usr.bin/readelf \
2684     usr.bin/sed \
2685     usr.bin/size \
2686     usr.bin/sort \
2687     usr.bin/strings \
2688     usr.bin/tar \
2689     usr.bin/touch \
2690     usr.bin/tr \
2691     usr.bin/true \
2692     usr.bin/uniq \
2693     usr.bin/unzip \
2694     usr.bin/wc \
2695     usr.bin/xargs \
2696     usr.bin/xinstall \
2697     usr.bin/xz \
2698     usr.bin/yacc \
2699     usr.sbin/chown
2700
2701 SUBDIR_DEPEND_usr.bin/clang=    lib/clang
2702 .if ${MK_CLANG} != "no"
2703 NXBDIRS+=       lib/clang
2704 NXBDIRS+=       usr.bin/clang
2705 .endif
2706 # XXX: native-xtools passes along ${NXBDIRS} in SUBDIR_OVERRIDE that needs
2707 # to be evaluated after NXBDIRS is set.
2708 .if make(install) && !empty(SUBDIR_OVERRIDE)
2709 SUBDIR= ${SUBDIR_OVERRIDE}
2710 .endif
2711
2712 NXBMAKEARGS+= \
2713         OBJTOP=${NXBOBJTOP:Q} \
2714         OBJROOT=${NXBOBJROOT:Q} \
2715         MAKEOBJDIRPREFIX= \
2716         -DNO_SHARED \
2717         -DNO_CPU_CFLAGS \
2718         -DNO_PIC \
2719         SSP_CFLAGS= \
2720         MK_CASPER=no \
2721         MK_CLANG_EXTRAS=no \
2722         MK_CLANG_FORMAT=no \
2723         MK_CLANG_FULL=no \
2724         MK_CTF=no \
2725         MK_DEBUG_FILES=no \
2726         MK_GDB=no \
2727         MK_HTML=no \
2728         MK_LLDB=no \
2729         MK_MAN=no \
2730         MK_MAN_UTILS=yes \
2731         MK_OFED=no \
2732         MK_OPENSSH=no \
2733         MK_PROFILE=no \
2734         MK_RETPOLINE=no \
2735         MK_SENDMAIL=no \
2736         MK_SVNLITE=no \
2737         MK_TESTS=no \
2738         MK_WARNS=no \
2739         MK_ZFS=no
2740
2741 .if make(native-xtools*) && \
2742     (!defined(NXB_TARGET) || !defined(NXB_TARGET_ARCH))
2743 .error Missing NXB_TARGET / NXB_TARGET_ARCH
2744 .endif
2745 # For 'toolchain' we want to produce native binaries that themselves generate
2746 # native binaries.
2747 NXBTMAKE=       ${NXBMAKEENV} ${MAKE} ${NXBMAKEARGS:N-DNO_PIC:N-DNO_SHARED} \
2748                 TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH}
2749 # For 'everything' we want to produce native binaries (hence -target to
2750 # be MACHINE) that themselves generate TARGET.TARGET_ARCH binaries.
2751 # TARGET/TARGET_ARCH are still passed along from user.
2752 #
2753 # Use the toolchain we create as an external toolchain.
2754 .if ${USING_SYSTEM_COMPILER} == "yes" || ${XCC:N${CCACHE_BIN}:M/*}
2755 NXBMAKE+=       XCC="${XCC}" \
2756                 XCXX="${XCXX}" \
2757                 XCPP="${XCPP}"
2758 .else
2759 NXBMAKE+=       XCC="${NXBOBJTOP}/tmp/usr/bin/cc" \
2760                 XCXX="${NXBOBJTOP}/tmp/usr/bin/c++" \
2761                 XCPP="${NXBOBJTOP}/tmp/usr/bin/cpp"
2762 .endif
2763 NXBMAKE+=       ${NXBMAKEENV} ${MAKE} -f Makefile.inc1 ${NXBMAKEARGS} \
2764                 MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
2765                 TARGET=${NXB_TARGET} TARGET_ARCH=${NXB_TARGET_ARCH} \
2766                 TARGET_TRIPLE=${MACHINE_TRIPLE:Q}
2767 # NXBDIRS is improperly based on MACHINE rather than NXB_TARGET.  Need to
2768 # invoke a sub-make to reevaluate MK_CLANG, etc, for NXBDIRS.
2769 NXBMAKE+=       SUBDIR_OVERRIDE='$${NXBDIRS:M*}'
2770 # Need to avoid the -isystem logic when using clang as an external toolchain
2771 # even if the TARGET being built for wants GCC.
2772 NXBMAKE+=       WANT_COMPILER_TYPE='$${X_COMPILER_TYPE}'
2773 native-xtools: .PHONY
2774         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _cleanobj
2775         # Build the bootstrap/host/cross tools that produce native binaries
2776         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} kernel-toolchain
2777         # Populate includes/libraries sysroot that produce native binaries.
2778         # This is split out from 'toolchain' above mostly so that target LLVM
2779         # libraries have a proper LLVM_DEFAULT_TARGET_TRIPLE without
2780         # polluting the cross-compiler build.  The LLVM/GCC libs are skipped
2781         # here to avoid the problem but are kept in 'toolchain' so that
2782         # needed build tools are built.
2783         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _includes MK_CLANG=no
2784         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _libraries MK_CLANG=no
2785 .if !defined(NO_OBJWALK)
2786         ${_+_}cd ${.CURDIR}; ${NXBMAKE} _obj
2787 .endif
2788         ${_+_}cd ${.CURDIR}; ${NXBMAKE} everything
2789         @echo ">> native-xtools done.  Use 'make native-xtools-install' to install to a given DESTDIR"
2790
2791 native-xtools-install: .PHONY
2792         mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
2793         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2794             -p ${NXBDESTDIR}/usr >/dev/null
2795         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2796             -p ${NXBDESTDIR}/usr/include >/dev/null
2797         ${_+_}cd ${.CURDIR}; ${NXBMAKE} \
2798             DESTDIR=${NXBDESTDIR} \
2799             -DNO_ROOT \
2800             install
2801
2802 #
2803 # hierarchy - ensure that all the needed directories are present
2804 #
2805 hierarchy hier: .MAKE .PHONY
2806         ${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
2807
2808 #
2809 # libraries - build all libraries, and install them under ${DESTDIR}.
2810 #
2811 # The list of libraries with dependents (${_prebuild_libs}) and their
2812 # interdependencies (__L) are built automatically by the
2813 # ${.CURDIR}/tools/make_libdeps.sh script.
2814 #
2815 libraries: .MAKE .PHONY
2816         ${_+_}cd ${.CURDIR}; \
2817             ${MAKE} -f Makefile.inc1 _prereq_libs; \
2818             ${MAKE} -f Makefile.inc1 _startup_libs; \
2819             ${MAKE} -f Makefile.inc1 _prebuild_libs; \
2820             ${MAKE} -f Makefile.inc1 _generic_libs
2821
2822 #
2823 # static libgcc.a prerequisite for shared libc
2824 #
2825 _prereq_libs= lib/libcompiler_rt
2826 .if ${MK_SSP} != "no"
2827 _prereq_libs+= lib/libssp_nonshared
2828 .endif
2829
2830 # These dependencies are not automatically generated:
2831 #
2832 # lib/csu and lib/libc must be built before
2833 # all shared libraries for ELF.
2834 #
2835 _startup_libs=  lib/csu
2836 _startup_libs+= lib/libc
2837 _startup_libs+= lib/libc_nonshared
2838 .if ${MK_LIBCPLUSPLUS} != "no"
2839 _startup_libs+= lib/libcxxrt
2840 .endif
2841
2842 _prereq_libs+=  lib/libgcc_eh lib/libgcc_s
2843 _startup_libs+= lib/libgcc_eh lib/libgcc_s
2844
2845 lib/libgcc_s__L: lib/libc__L
2846 lib/libgcc_s__L: lib/libc_nonshared__L
2847 .if ${MK_LIBCPLUSPLUS} != "no"
2848 lib/libcxxrt__L: lib/libgcc_s__L
2849 .endif
2850
2851 _prebuild_libs= ${_kerberos5_lib_libasn1} \
2852                 ${_kerberos5_lib_libhdb} \
2853                 ${_kerberos5_lib_libheimbase} \
2854                 ${_kerberos5_lib_libheimntlm} \
2855                 ${_libsqlite3} \
2856                 ${_kerberos5_lib_libheimipcc} \
2857                 ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
2858                 ${_kerberos5_lib_libroken} \
2859                 ${_kerberos5_lib_libwind} \
2860                 lib/libbz2 ${_libcom_err} lib/libcrypt \
2861                 lib/libelf lib/libexpat \
2862                 lib/libfigpar \
2863                 ${_lib_libgssapi} \
2864                 lib/libjail \
2865                 lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
2866                 lib/libzstd \
2867                 ${_lib_casper} \
2868                 lib/ncurses/ncurses lib/ncurses/ncursesw \
2869                 lib/libopie lib/libpam/libpam ${_lib_libthr} \
2870                 ${_lib_libradius} lib/libsbuf lib/libtacplus \
2871                 lib/libgeom \
2872                 ${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
2873                 ${_cddl_lib_libuutil} \
2874                 ${_cddl_lib_libavl} \
2875                 ${_cddl_lib_libicp} \
2876                 ${_cddl_lib_libicp_rescue} \
2877                 ${_cddl_lib_libspl} \
2878                 ${_cddl_lib_libtpool} \
2879                 ${_cddl_lib_libzfs_core} ${_cddl_lib_libzfs} \
2880                 ${_cddl_lib_libzutil} \
2881                 ${_cddl_lib_libctf} ${_cddl_lib_libzfsbootenv} \
2882                 lib/libufs \
2883                 lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
2884                 ${_secure_lib_libcrypto} ${_secure_lib_libssl} \
2885                 ${_lib_libldns} ${_secure_lib_libssh}
2886
2887 .if ${MK_DIALOG} != "no"
2888 _prebuild_libs+= gnu/lib/libdialog
2889 gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
2890 .endif
2891
2892 .if ${MK_GOOGLETEST} != "no"
2893 _prebuild_libs+= lib/libregex
2894 .endif
2895
2896 .if ${MK_LIBCPLUSPLUS} != "no"
2897 _prebuild_libs+= lib/libc++
2898 .endif
2899
2900 lib/libgeom__L: lib/libexpat__L lib/libsbuf__L
2901 lib/libkvm__L: lib/libelf__L
2902
2903 .if ${MK_LIBTHR} != "no"
2904 _lib_libthr=    lib/libthr
2905 .endif
2906
2907 .if ${MK_RADIUS_SUPPORT} != "no"
2908 _lib_libradius= lib/libradius
2909 .endif
2910
2911 .if ${MK_OFED} != "no"
2912 _prebuild_libs+= \
2913         lib/ofed/libibverbs \
2914         lib/ofed/libibmad \
2915         lib/ofed/libibumad \
2916         lib/ofed/complib \
2917         lib/ofed/libmlx5
2918
2919 lib/ofed/libibmad__L:   lib/ofed/libibumad__L
2920 lib/ofed/complib__L:    lib/libthr__L
2921 lib/ofed/libmlx5__L:    lib/ofed/libibverbs__L lib/libthr__L
2922 .endif
2923
2924 .if ${MK_CASPER} != "no"
2925 _lib_casper=    lib/libcasper
2926 .endif
2927
2928 lib/libpjdlog__L: lib/libutil__L
2929 lib/libcasper__L: lib/libnv__L
2930 lib/liblzma__L: lib/libmd__L lib/libthr__L
2931 lib/libzstd__L: lib/libthr__L
2932
2933 _generic_libs=  ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib}
2934 .if ${MK_IPFILTER} != "no"
2935 _generic_libs+= sbin/ipf/libipf
2936 .endif
2937 .for _DIR in ${LOCAL_LIB_DIRS}
2938 .if ${_DIR} == ".WAIT"  || (empty(_generic_libs:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
2939 _generic_libs+= ${_DIR}
2940 .endif
2941 .endfor
2942
2943 lib/libopie__L lib/libtacplus__L: lib/libmd__L
2944
2945 .if ${MK_CDDL} != "no"
2946 _cddl_lib_libumem= cddl/lib/libumem
2947 _cddl_lib_libnvpair= cddl/lib/libnvpair
2948 _cddl_lib_libavl= cddl/lib/libavl
2949 _cddl_lib_libuutil= cddl/lib/libuutil
2950 _cddl_lib_libspl= cddl/lib/libspl
2951
2952 cddl/lib/libuutil__L: cddl/lib/libavl__L cddl/lib/libspl__L
2953
2954 .if ${MK_ZFS} != "no"
2955 _cddl_lib_libicp= cddl/lib/libicp
2956 _cddl_lib_libicp_rescue= cddl/lib/libicp_rescue
2957 _cddl_lib_libtpool= cddl/lib/libtpool
2958 _cddl_lib_libzutil= cddl/lib/libzutil
2959 _cddl_lib_libzfs_core= cddl/lib/libzfs_core
2960 _cddl_lib_libzfs= cddl/lib/libzfs
2961 _cddl_lib_libzfsbootenv= cddl/lib/libzfsbootenv
2962
2963 cddl/lib/libtpool__L: cddl/lib/libspl__L
2964
2965 cddl/lib/libzutil__L: cddl/lib/libavl__L cddl/lib/libtpool__L
2966
2967 cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
2968
2969 cddl/lib/libzfs__L: cddl/lib/libzfs_core__L lib/msun__L lib/libutil__L
2970 cddl/lib/libzfs__L: lib/libthr__L lib/libmd__L lib/libz__L cddl/lib/libumem__L
2971 cddl/lib/libzfs__L: cddl/lib/libuutil__L cddl/lib/libavl__L lib/libgeom__L
2972 cddl/lib/libzfs__L: cddl/lib/libnvpair__L cddl/lib/libzutil__L
2973 cddl/lib/libzfs__L: secure/lib/libcrypto__L
2974
2975 cddl/lib/libzfsbootenv__L: cddl/lib/libzfs__L
2976 lib/libbe__L: cddl/lib/libzfs__L cddl/lib/libzfsbootenv__L
2977 .endif
2978 _cddl_lib_libctf= cddl/lib/libctf
2979 _cddl_lib= cddl/lib
2980 cddl/lib/libctf__L: lib/libz__L cddl/lib/libspl__L
2981 .endif
2982 # cddl/lib/libdtrace requires lib/libproc and lib/librtld_db
2983 _prebuild_libs+=        lib/libprocstat lib/libproc lib/librtld_db
2984 lib/libprocstat__L: lib/libelf__L lib/libkvm__L lib/libutil__L
2985 lib/libproc__L: lib/libprocstat__L
2986 lib/librtld_db__L: lib/libprocstat__L
2987
2988 .if ${MK_CRYPT} != "no"
2989 .if ${MK_OPENSSL} != "no"
2990 _secure_lib_libcrypto= secure/lib/libcrypto
2991 _secure_lib_libssl= secure/lib/libssl
2992 lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
2993 secure/lib/libcrypto__L: lib/libthr__L
2994 .if ${MK_LDNS} != "no"
2995 _lib_libldns= lib/libldns
2996 lib/libldns__L: secure/lib/libssl__L
2997 .endif
2998 .if ${MK_OPENSSH} != "no"
2999 _secure_lib_libssh= secure/lib/libssh
3000 secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
3001 .if ${MK_LDNS} != "no"
3002 secure/lib/libssh__L: lib/libldns__L
3003 .endif
3004 .if ${MK_GSSAPI} != "no" && ${MK_KERBEROS_SUPPORT} != "no"
3005 secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
3006     kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
3007     lib/libmd__L kerberos5/lib/libroken__L
3008 .endif
3009 .endif
3010 .endif
3011 _secure_lib=    secure/lib
3012 .endif
3013
3014 .if ${MK_KERBEROS} != "no"
3015 kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
3016 kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
3017     kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
3018     kerberos5/lib/libwind__L lib/libsqlite3__L
3019 kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
3020     kerberos5/lib/libroken__L lib/libcom_err__L
3021 kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
3022     secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
3023 kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
3024     lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
3025     kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
3026     kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
3027 kerberos5/lib/libroken__L: lib/libcrypt__L
3028 kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
3029 kerberos5/lib/libheimbase__L: lib/libthr__L
3030 kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
3031 .endif
3032
3033 lib/libsqlite3__L: lib/libthr__L
3034
3035 .if ${MK_GSSAPI} != "no"
3036 _lib_libgssapi= lib/libgssapi
3037 .endif
3038
3039 .if ${MK_KERBEROS} != "no"
3040 _kerberos5_lib= kerberos5/lib
3041 _kerberos5_lib_libasn1= kerberos5/lib/libasn1
3042 _kerberos5_lib_libhdb= kerberos5/lib/libhdb
3043 _kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
3044 _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
3045 _kerberos5_lib_libhx509= kerberos5/lib/libhx509
3046 _kerberos5_lib_libroken= kerberos5/lib/libroken
3047 _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
3048 _libsqlite3= lib/libsqlite3
3049 _kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
3050 _kerberos5_lib_libwind= kerberos5/lib/libwind
3051 _libcom_err= lib/libcom_err
3052 .endif
3053
3054 .if ${MK_NIS} != "no"
3055 _lib_libypclnt= lib/libypclnt
3056 .endif
3057
3058 .if ${MK_OPENSSL} == "no"
3059 lib/libradius__L: lib/libmd__L
3060 .endif
3061
3062 lib/libproc__L: \
3063     ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
3064 .if ${MK_CXX} != "no" && ${MK_LIBCPLUSPLUS} != "no"
3065 lib/libproc__L: lib/libcxxrt__L
3066 .endif
3067
3068 .for _lib in ${_prereq_libs}
3069 ${_lib}__PL: .PHONY .MAKE
3070 .if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
3071         ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
3072                 cd ${.CURDIR}/${_lib}; \
3073                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
3074                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
3075                     DIRPRFX=${_lib}/ all; \
3076                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
3077                     DIRPRFX=${_lib}/ install
3078 .endif
3079 .endfor
3080
3081 .for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
3082 ${_lib}__L: .PHONY .MAKE
3083 .if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
3084         ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
3085                 cd ${.CURDIR}/${_lib}; \
3086                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
3087                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
3088                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
3089 .endif
3090 .endfor
3091
3092 _prereq_libs: ${_prereq_libs:S/$/__PL/}
3093 _startup_libs: ${_startup_libs:S/$/__L/}
3094 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
3095 _generic_libs: ${_generic_libs:S/$/__L/}
3096
3097 # Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
3098 # 'everything' with _PARALLEL_SUBDIR_OK set.  This is because it is unlikely
3099 # that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
3100 # or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
3101 # parallel.  This is safe for the world stage of buildworld though since it has
3102 # already built libraries in a proper order and installed includes into
3103 # WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
3104 # avoid trashing a system if it crashes mid-install.
3105 .if !make(all) || defined(_PARALLEL_SUBDIR_OK)
3106 SUBDIR_PARALLEL=
3107 .endif
3108
3109 .include <bsd.subdir.mk>
3110
3111 .if make(check-old) || make(check-old-dirs) || \
3112     make(check-old-files) || make(check-old-libs) || \
3113     make(delete-old) || make(delete-old-dirs) || \
3114     make(delete-old-files) || make(delete-old-libs)
3115
3116 #
3117 # check for / delete old files section
3118 #
3119
3120 .include "ObsoleteFiles.inc"
3121
3122 OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
3123 else you can not start such an application. Consult UPDATING for more \
3124 information regarding how to cope with the removal/revision bump of a \
3125 specific library."
3126
3127 .if !defined(BATCH_DELETE_OLD_FILES)
3128 RM_I=-i
3129 .else
3130 RM_I=-v
3131 .endif
3132
3133 delete-old-files: .PHONY
3134         @echo ">>> Removing old files (only deletes safe to delete libs)"
3135 # Ask for every old file if the user really wants to remove it.
3136 # It's annoying, but better safe than sorry.
3137 # NB: We cannot pass the list of OLD_FILES as a parameter because the
3138 # argument list will get too long. Using .for/.endfor make "loops" will make
3139 # the Makefile parser segfault.
3140         @exec 3<&0; \
3141         cd ${.CURDIR}; \
3142         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3143             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | sort | \
3144         while read file; do \
3145                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3146                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3147                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3148                 fi; \
3149                 for ext in debug symbols; do \
3150                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3151                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3152                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3153                               <&3; \
3154                   fi; \
3155                 done; \
3156         done
3157 # Remove catpages without corresponding manpages.
3158         @exec 3<&0; \
3159         find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | sort | \
3160         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3161         while read catpage; do \
3162                 read manpage; \
3163                 if [ ! -e "$${manpage}" ]; then \
3164                         rm ${RM_I} $${catpage} <&3; \
3165                 fi; \
3166         done
3167         @echo ">>> Old files removed"
3168
3169 check-old-files: .PHONY
3170         @echo ">>> Checking for old files"
3171         @cd ${.CURDIR}; \
3172         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3173             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
3174         while read file; do \
3175                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3176                         echo "${DESTDIR}/$${file}"; \
3177                 fi; \
3178                 for ext in debug symbols; do \
3179                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3180                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3181                   fi; \
3182                 done; \
3183         done | sort
3184 # Check for catpages without corresponding manpages.
3185         @find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | \
3186         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3187         while read catpage; do \
3188                 read manpage; \
3189                 if [ ! -e "$${manpage}" ]; then \
3190                         echo $${catpage}; \
3191                 fi; \
3192         done | sort
3193
3194 delete-old-libs: .PHONY
3195         @echo ">>> Removing old libraries"
3196         @echo "${OLD_LIBS_MESSAGE}" | fmt
3197         @exec 3<&0; \
3198         cd ${.CURDIR}; \
3199         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3200             -V OLD_LIBS | xargs -n1 | sort | \
3201         while read file; do \
3202                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3203                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3204                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3205                 fi; \
3206                 for ext in debug symbols; do \
3207                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3208                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3209                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3210                               <&3; \
3211                   fi; \
3212                 done; \
3213         done
3214         @echo ">>> Old libraries removed"
3215
3216 check-old-libs: .PHONY
3217         @echo ">>> Checking for old libraries"
3218         @cd ${.CURDIR}; \
3219         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3220             -V OLD_LIBS | xargs -n1 | \
3221         while read file; do \
3222                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3223                         echo "${DESTDIR}/$${file}"; \
3224                 fi; \
3225                 for ext in debug symbols; do \
3226                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3227                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3228                   fi; \
3229                 done; \
3230         done | sort
3231
3232 delete-old-dirs: .PHONY
3233         @echo ">>> Removing old directories"
3234         @cd ${.CURDIR}; \
3235         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3236             -V OLD_DIRS | xargs -n1 | sort -r | \
3237         while read dir; do \
3238                 if [ -d "${DESTDIR}/$${dir}" ]; then \
3239                         rmdir -v "${DESTDIR}/$${dir}" || true; \
3240                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
3241                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3242                 fi; \
3243                 if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3244                         rmdir -v "${DESTDIR}${DEBUGDIR}/$${dir}" || true; \
3245                 elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3246                         echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3247                 fi; \
3248         done
3249         @echo ">>> Old directories removed"
3250
3251 check-old-dirs: .PHONY
3252         @echo ">>> Checking for old directories"
3253         @cd ${.CURDIR}; \
3254         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3255             -V OLD_DIRS | xargs -n1 | sort -r | \
3256         while read dir; do \
3257                 if [ -d "${DESTDIR}/$${dir}" ]; then \
3258                         echo "${DESTDIR}/$${dir}"; \
3259                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
3260                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3261                 fi; \
3262                 if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3263                         echo "${DESTDIR}${DEBUGDIR}/$${dir}"; \
3264                 elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3265                         echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3266                 fi; \
3267         done
3268
3269 delete-old: delete-old-files delete-old-dirs .PHONY
3270         @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3271
3272 check-old: check-old-files check-old-libs check-old-dirs .PHONY
3273         @echo "To remove old files and directories run '${MAKE_CMD} delete-old'."
3274         @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3275
3276 .endif
3277
3278 #
3279 # showconfig - show build configuration.
3280 #
3281 showconfig: .PHONY
3282         @(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes; \
3283           ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes) 2>&1 | grep ^MK_ | sort -u
3284
3285 .if !empty(KRNLOBJDIR) && !empty(KERNCONF)
3286 DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
3287
3288 .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
3289 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${KERNCONF})
3290 FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
3291         '${KERNCONFDIR}/${KERNCONF}' ; echo
3292 .endif
3293 .endif
3294
3295 .endif
3296
3297 .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
3298 DTBOUTPUTPATH= ${.CURDIR}
3299 .endif
3300
3301 #
3302 # Build 'standalone' Device Tree Blob
3303 #
3304 builddtb: .PHONY
3305         @PATH=${TMPPATH} MACHINE=${TARGET} \
3306         sh ${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
3307             "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
3308
3309 ###############
3310
3311 # cleanworld
3312 # In the following, the first 'rm' in a series will usually remove all
3313 # files and directories.  If it does not, then there are probably some
3314 # files with file flags set, so this unsets them and tries the 'rm' a
3315 # second time.  There are situations where this target will be cleaning
3316 # some directories via more than one method, but that duplication is
3317 # needed to correctly handle all the possible situations.  Removing all
3318 # files without file flags set in the first 'rm' instance saves time,
3319 # because 'chflags' will need to operate on fewer files afterwards.
3320 #
3321 # It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
3322 # created by bsd.obj.mk, except that we don't want to .include that file
3323 # in this makefile.  We don't do a cleandir walk if MK_AUTO_OBJ is yes
3324 # since it is not possible for files to land in the wrong place.
3325 #
3326 .if make(cleanworld)
3327 BW_CANONICALOBJDIR:=${OBJTOP}/
3328 .elif make(cleanuniverse)
3329 BW_CANONICALOBJDIR:=${OBJROOT}
3330 .if ${MK_UNIFIED_OBJDIR} == "no"
3331 .error ${.TARGETS} only supported with WITH_UNIFIED_OBJDIR enabled.
3332 .endif
3333 .endif
3334 cleanworld cleanuniverse: .PHONY
3335 .if !empty(BW_CANONICALOBJDIR) && exists(${BW_CANONICALOBJDIR}) && \
3336     ${.CURDIR:tA} != ${BW_CANONICALOBJDIR:tA}
3337         -rm -rf ${BW_CANONICALOBJDIR}*
3338         -chflags -R 0 ${BW_CANONICALOBJDIR}
3339         rm -rf ${BW_CANONICALOBJDIR}*
3340 .endif
3341 .if make(cleanworld) && ${MK_AUTO_OBJ} == "no" && \
3342     (empty(BW_CANONICALOBJDIR) || ${.CURDIR:tA} == ${BW_CANONICALOBJDIR:tA})
3343 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
3344         #   To be safe in this case, fall back to a 'make cleandir'
3345         ${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
3346 .endif
3347 .endif
3348
3349 .if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
3350 XDEV_CPUTYPE?=${CPUTYPE}
3351 .else
3352 XDEV_CPUTYPE?=${TARGET_CPUTYPE}
3353 .endif
3354
3355 NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
3356         MK_MAN=no MK_NLS=no MK_PROFILE=no \
3357         MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
3358         TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
3359         CPUTYPE=${XDEV_CPUTYPE}
3360
3361 XDDIR=${TARGET_ARCH}-freebsd
3362 XDTP?=/usr/${XDDIR}
3363 .if ${XDTP:N/*}
3364 .error XDTP variable should be an absolute path
3365 .endif
3366
3367 CDBOBJROOT=     ${OBJROOT}${MACHINE}.${MACHINE_ARCH}/xdev/
3368 CDBOBJTOP=      ${CDBOBJROOT}${XDDIR}
3369 CDBENV= \
3370         INSTALL="sh ${.CURDIR}/tools/install.sh"
3371 CDENV= ${CDBENV} \
3372         TOOLS_PREFIX=${XDTP}
3373 CDMAKEARGS= \
3374         OBJTOP=${CDBOBJTOP:Q} \
3375         OBJROOT=${CDBOBJROOT:Q}
3376 CD2MAKEARGS= ${CDMAKEARGS}
3377
3378 .if ${WANT_COMPILER_TYPE} == gcc || \
3379     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
3380 # GCC requires -isystem and -L when using a cross-compiler.  --sysroot
3381 # won't set header path and -L is used to ensure the base library path
3382 # is added before the port PREFIX library path.
3383 CD2CFLAGS+=     -isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib
3384 # GCC requires -B to find /usr/lib/crti.o when using a cross-compiler
3385 # combined with --sysroot.
3386 CD2CFLAGS+=     -B${XDDESTDIR}/usr/lib
3387 # Force using libc++ for external GCC.
3388 .if defined(X_COMPILER_TYPE) && \
3389     ${X_COMPILER_TYPE} == gcc && ${X_COMPILER_VERSION} >= 40800
3390 CD2CXXFLAGS+=   -isystem ${XDDESTDIR}/usr/include/c++/v1 -std=c++11 \
3391                 -nostdinc++
3392 .endif
3393 .endif
3394 CD2CFLAGS+=     --sysroot=${XDDESTDIR}/
3395 CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CXXFLAGS} ${CD2CFLAGS}" \
3396         CPP="${CPP} ${CD2CFLAGS}" \
3397         MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
3398
3399 CDTMP=  ${OBJTOP}/${XDDIR}/tmp
3400 CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${CDMAKEARGS} ${NOFUN}
3401 CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} \
3402         ${MAKE} ${CD2MAKEARGS} ${NOFUN}
3403 .if ${MK_META_MODE} != "no"
3404 # Don't rebuild build-tools targets during normal build.
3405 CD2MAKE+=       BUILD_TOOLS_META=.NOMETA
3406 .endif
3407 XDDESTDIR=${DESTDIR}${XDTP}
3408
3409 .ORDER: xdev-build xdev-install xdev-links
3410 xdev: xdev-build xdev-install .PHONY
3411
3412 .ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
3413 xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY
3414
3415 _xb-worldtmp: .PHONY
3416         mkdir -p ${CDTMP}/usr
3417         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3418             -p ${CDTMP}/usr >/dev/null
3419
3420 _xb-bootstrap-tools: .PHONY
3421 .for _tool in \
3422     ${_clang_tblgen} \
3423     ${_yacc}
3424         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
3425         cd ${.CURDIR}/${_tool}; \
3426         if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3427         ${CDMAKE} DIRPRFX=${_tool}/ all; \
3428         ${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
3429 .endfor
3430
3431 _xb-build-tools: .PHONY
3432         ${_+_}@cd ${.CURDIR}; \
3433         ${CDBENV} ${MAKE} ${CDMAKEARGS} -f Makefile.inc1 ${NOFUN} build-tools
3434
3435 XDEVDIRS= \
3436     ${_clang_libs} \
3437     ${_lld} \
3438     ${_elftctools} \
3439     usr.bin/ar \
3440     ${_clang}
3441
3442 _xb-cross-tools: .PHONY
3443 .for _tool in ${XDEVDIRS}
3444         ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \
3445         cd ${.CURDIR}/${_tool}; \
3446         if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3447         ${CDMAKE} DIRPRFX=${_tool}/ all
3448 .endfor
3449
3450 _xi-mtree: .PHONY
3451         ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
3452         mkdir -p ${XDDESTDIR}
3453         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
3454             -p ${XDDESTDIR} >/dev/null
3455         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3456             -p ${XDDESTDIR}/usr >/dev/null
3457         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
3458             -p ${XDDESTDIR}/usr/include >/dev/null
3459 .if defined(_LIBCOMPAT)
3460         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
3461             -p ${XDDESTDIR}/usr >/dev/null
3462 .endif
3463 .if ${MK_TESTS} != "no"
3464         mkdir -p ${XDDESTDIR}${TESTSBASE}
3465         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
3466             -p ${XDDESTDIR}${TESTSBASE} >/dev/null
3467 .endif
3468
3469 .ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
3470 xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY
3471
3472 _xi-cross-tools: .PHONY
3473         @echo "_xi-cross-tools"
3474 .for _tool in ${XDEVDIRS}
3475         ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
3476         cd ${.CURDIR}/${_tool}; \
3477         ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
3478 .endfor
3479
3480 _xi-includes: .PHONY
3481 .if !defined(NO_OBJWALK)
3482         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 _obj \
3483                 DESTDIR=${XDDESTDIR}
3484 .endif
3485         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
3486                 DESTDIR=${XDDESTDIR}
3487
3488 _xi-libraries: .PHONY
3489         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
3490                 DESTDIR=${XDDESTDIR}
3491
3492 xdev-links: .PHONY
3493         ${_+_}cd ${XDDESTDIR}/usr/bin; \
3494         mkdir -p ../../../../usr/bin; \
3495                 for i in *; do \
3496                         ln -sf ../../${XDTP}/usr/bin/$$i \
3497                             ../../../../usr/bin/${XDDIR}-$$i; \
3498                         ln -sf ../../${XDTP}/usr/bin/$$i \
3499                             ../../../../usr/bin/${XDDIR}${_REVISION}-$$i; \
3500                 done