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