]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - Makefile.inc1
[POWERPC64LE,POWEPCSPE] set default kernel config for powerpc64le and powerpcspe...
[FreeBSD/FreeBSD.git] / Makefile.inc1
1 #
2 # $FreeBSD$
3 #
4 # Make command line options:
5 #       -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6 #       -DNO_CLEAN do not clean at all
7 #       -DDB_FROM_SRC use the user/group databases in src/etc instead of
8 #           the system database when installing.
9 #       -DNO_SHARE do not go into share subdir
10 #       -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,OBJ}
11 #       -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12 #       -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13 #       -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
14 #       -DNO_PORTSUPDATE do not update ports in ${MAKE} update
15 #       -DNO_ROOT install without using root privilege
16 #       -DNO_DOCUPDATE do not update doc in ${MAKE} update
17 #       -DWITHOUT_CTF do not run the DTrace CTF conversion tools on built objects
18 #       LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
19 #       LOCAL_ITOOLS="list of tools" to add additional tools to the ITOOLS list
20 #       LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
21 #       LOCAL_MTREE="list of mtree files" to process to allow local directories
22 #           to be created before files are installed
23 #       LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
24 #           list
25 #       LOCAL_XTOOL_DIRS="list of dirs" to add additional dirs to the
26 #           cross-tools target
27 #       METALOG="path to metadata log" to write permission and ownership
28 #           when NO_ROOT is set.  (default: ${DESTDIR}/${DISTDIR}/METALOG,
29 #           check /etc/make.conf for DISTDIR)
30 #       TARGET="machine" to crossbuild world for a different machine type
31 #       TARGET_ARCH= may be required when a TARGET supports multiple endians
32 #       BUILDENV_SHELL= shell to launch for the buildenv target (def:${SHELL})
33 #       WORLD_FLAGS= additional flags to pass to make(1) during buildworld
34 #       KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
35 #       SUBDIR_OVERRIDE="list of dirs" to build rather than everything.
36 #           All libraries and includes, and some build tools will still build.
37
38 #
39 # The intended user-driven targets are:
40 # buildworld  - rebuild *everything*, including glue to help do upgrades
41 # installworld- install everything built by "buildworld"
42 # checkworld  - run test suite on installed world
43 # doxygen     - build API documentation of the kernel
44 # update      - convenient way to update your source tree (eg: svn/svnup)
45 #
46 # Standard targets (not defined here) are documented in the makefiles in
47 # /usr/share/mk.  These include:
48 #               obj depend all install clean cleandepend cleanobj
49
50 .if !defined(TARGET) || !defined(TARGET_ARCH)
51 .error "Both TARGET and TARGET_ARCH must be defined."
52 .endif
53
54 .if make(showconfig) || make(test-system-*)
55 _MKSHOWCONFIG=  t
56 .endif
57
58 SRCDIR?=        ${.CURDIR}
59 LOCALBASE?=     /usr/local
60
61 .include "share/mk/src.tools.mk"
62
63 # Cross toolchain changes must be in effect before bsd.compiler.mk
64 # so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
65 .if defined(CROSS_TOOLCHAIN)
66 .if exists(${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk)
67 .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
68 .elif exists(/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk)
69 .include "/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk"
70 .elif exists(${CROSS_TOOLCHAIN})
71 .include "${CROSS_TOOLCHAIN}"
72 .else
73 .error CROSS_TOOLCHAIN ${CROSS_TOOLCHAIN} not found
74 .endif
75 CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
76 .endif
77 .if defined(CROSS_TOOLCHAIN_PREFIX)
78 CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
79 .endif
80
81 XCOMPILERS=     CC CXX CPP
82 .for COMPILER in ${XCOMPILERS}
83 .if defined(CROSS_COMPILER_PREFIX)
84 X${COMPILER}?=  ${CROSS_COMPILER_PREFIX}${${COMPILER}}
85 .else
86 X${COMPILER}?=  ${${COMPILER}}
87 .endif
88 .endfor
89 # If a full path to an external cross compiler is given, don't build
90 # a cross compiler.
91 .if ${XCC:N${CCACHE_BIN}:M/*}
92 MK_CLANG_BOOTSTRAP=     no
93 .endif
94
95 # Pull in compiler metadata from buildworld/toolchain if possible to avoid
96 # running CC from bsd.compiler.mk.
97 .if make(installworld) || make(install) || make(distributeworld) || \
98     make(stageworld)
99 .-include "${OBJTOP}/toolchain-metadata.mk"
100 .if !defined(_LOADED_TOOLCHAIN_METADATA)
101 .error A build is required first.  You may have the wrong MAKEOBJDIRPREFIX set.
102 .endif
103 .endif
104
105 # Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early. Pull it from the
106 # tree to be friendlier to foreign OS builds. It's safe to do so unconditionally
107 # here since we will always have the right make, unlike in src/Makefile
108 # Don't include bsd.linker.mk yet until XBINUTILS is handled (after src.opts.mk)
109 _NO_INCLUDE_LINKERMK=   t
110 # We also want the X_COMPILER* variables if we are using an external toolchain.
111 _WANT_TOOLCHAIN_CROSS_VARS=     t
112 .include "share/mk/bsd.compiler.mk"
113 .undef _NO_INCLUDE_LINKERMK
114 .undef _WANT_TOOLCHAIN_CROSS_VARS
115 # src.opts.mk depends on COMPILER_FEATURES
116 .include "share/mk/src.opts.mk"
117
118 .if ${TARGET} == ${MACHINE}
119 TARGET_CPUTYPE?=${CPUTYPE}
120 .else
121 TARGET_CPUTYPE?=
122 .endif
123 .if !empty(TARGET_CPUTYPE)
124 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
125 .else
126 _TARGET_CPUTYPE=dummy
127 .endif
128 .if ${TARGET} == "arm"
129 .if ${TARGET_ARCH:Marmv[67]*} != "" && ${TARGET_CPUTYPE:M*soft*} == ""
130 TARGET_ABI=     gnueabihf
131 .else
132 TARGET_ABI=     gnueabi
133 .endif
134 .endif
135 MACHINE_ABI?=   unknown
136 MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd13.0
137 TARGET_ABI?=    unknown
138 TARGET_TRIPLE?= ${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd13.0
139 KNOWN_ARCHES?=  aarch64/arm64 \
140                 amd64 \
141                 armv6/arm \
142                 armv7/arm \
143                 i386 \
144                 mips \
145                 mipsel/mips \
146                 mips64el/mips \
147                 mipsn32el/mips \
148                 mips64/mips \
149                 mipsn32/mips \
150                 mipshf/mips \
151                 mipselhf/mips \
152                 mips64elhf/mips \
153                 mips64hf/mips \
154                 powerpc \
155                 powerpc64/powerpc \
156                 powerpc64le/powerpc \
157                 powerpcspe/powerpc \
158                 riscv64/riscv \
159                 riscv64sf/riscv
160
161 .if ${TARGET} == ${TARGET_ARCH}
162 _t=             ${TARGET}
163 .else
164 _t=             ${TARGET_ARCH}/${TARGET}
165 .endif
166 .for _t in ${_t}
167 .if empty(KNOWN_ARCHES:M${_t})
168 .error Unknown target ${TARGET_ARCH}:${TARGET}.
169 .endif
170 .endfor
171
172 .if ${.MAKE.OS} != "FreeBSD"
173 CROSSBUILD_HOST=${.MAKE.OS}
174 .if ${.MAKE.OS} != "Linux" && ${.MAKE.OS} != "Darwin"
175 .warning "Unsupported crossbuild system: ${.MAKE.OS}. Build will probably fail!"
176 .endif
177 # We need to force NO_ROOT/DB_FROM_SRC builds when building on other operating
178 # systems since the BSD.foo.dist specs contain users and groups that do not
179 # exist by default on a Linux/MacOS system.
180 NO_ROOT:=       1
181 DB_FROM_SRC:=   1
182 .export NO_ROOT
183 .endif
184
185 # If all targets are disabled for system llvm then don't expect it to work
186 # for cross-builds.
187 .if !defined(TOOLS_PREFIX) && ${MK_LLVM_TARGET_ALL} == "no" && \
188     ${MACHINE} != ${TARGET} && ${MACHINE_ARCH} != ${TARGET_ARCH} && \
189     !make(showconfig)
190 MK_SYSTEM_COMPILER=     no
191 MK_SYSTEM_LINKER=       no
192 .endif
193
194 # Handle external binutils.
195 .if defined(CROSS_TOOLCHAIN_PREFIX)
196 CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
197 .endif
198 XBINUTILS=      AS AR LD NM OBJCOPY RANLIB SIZE STRINGS STRIPBIN
199 .for BINUTIL in ${XBINUTILS}
200 .if defined(CROSS_BINUTILS_PREFIX) && \
201     exists(${CROSS_BINUTILS_PREFIX}/${${BINUTIL}})
202 X${BINUTIL}?=   ${CROSS_BINUTILS_PREFIX:C,/*$,,}/${${BINUTIL}}
203 .else
204 X${BINUTIL}?=   ${${BINUTIL}}
205 .endif
206 .endfor
207
208 # If a full path to an external linker is given, don't build lld.
209 .if ${XLD:M/*}
210 MK_LLD_BOOTSTRAP=       no
211 .endif
212
213 # We also want the X_LINKER* variables if we are using an external toolchain.
214 _WANT_TOOLCHAIN_CROSS_VARS=     t
215 .include "share/mk/bsd.linker.mk"
216 .undef _WANT_TOOLCHAIN_CROSS_VARS
217
218 # Begin WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
219
220 # WITH_SYSTEM_COMPILER - Pull in needed values and make a decision.
221
222 # Check if there is a local compiler that can satisfy as an external compiler.
223 # Which compiler is expected to be used?
224 .if ${MK_CLANG_BOOTSTRAP} == "yes"
225 WANT_COMPILER_TYPE=     clang
226 .else
227 WANT_COMPILER_TYPE=
228 .endif
229
230 .if !defined(WANT_COMPILER_FREEBSD_VERSION) && !make(showconfig) && \
231     !make(test-system-linker)
232 .if ${WANT_COMPILER_TYPE} == "clang"
233 WANT_COMPILER_FREEBSD_VERSION_FILE= lib/clang/freebsd_cc_version.h
234 WANT_COMPILER_FREEBSD_VERSION!= \
235         awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \
236         ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown
237 WANT_COMPILER_VERSION_FILE= lib/clang/include/clang/Basic/Version.inc
238 WANT_COMPILER_VERSION!= \
239         awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
240         ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown
241 .endif
242 .export WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_VERSION
243 .endif  # !defined(WANT_COMPILER_FREEBSD_VERSION)
244
245 # It needs to be the same revision as we would build for the bootstrap.
246 # If the expected vs CC is different then we can't skip.
247 # GCC cannot be used for cross-arch yet.  For clang we pass -target later if
248 # TARGET_ARCH!=MACHINE_ARCH.
249 .if ${MK_SYSTEM_COMPILER} == "yes" && \
250     defined(WANT_COMPILER_FREEBSD_VERSION) && \
251     ${MK_CLANG_BOOTSTRAP} == "yes" && \
252     !make(xdev*) && \
253     ${X_COMPILER_TYPE} == ${WANT_COMPILER_TYPE} && \
254     (${X_COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH}) && \
255     ${X_COMPILER_VERSION} == ${WANT_COMPILER_VERSION} && \
256     ${X_COMPILER_FREEBSD_VERSION} == ${WANT_COMPILER_FREEBSD_VERSION}
257 # Everything matches, disable the bootstrap compiler.
258 MK_CLANG_BOOTSTRAP=     no
259 USING_SYSTEM_COMPILER=  yes
260 .endif  # ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE}
261
262 # WITH_SYSTEM_LD - Pull in needed values and make a decision.
263
264 # Check if there is a local linker that can satisfy as an external linker.
265 # Which linker is expected to be used?
266 .if ${MK_LLD_BOOTSTRAP} == "yes"
267 WANT_LINKER_TYPE=               lld
268 .else
269 WANT_LINKER_TYPE=
270 .endif
271
272 .if !defined(WANT_LINKER_FREEBSD_VERSION) && !make(showconfig) && \
273     !make(test-system-compiler)
274 .if ${WANT_LINKER_TYPE} == "lld"
275 WANT_LINKER_FREEBSD_VERSION_FILE= lib/clang/include/VCSVersion.inc
276 _WANT_LINKER_FREEBSD_VERSION!= \
277         awk '$$2 == "LLD_REVISION" {gsub(/"/, "", $$3); print $$3}' \
278         ${SRCDIR}/${WANT_LINKER_FREEBSD_VERSION_FILE} || echo unknown
279 WANT_LINKER_FREEBSD_VERSION=${_WANT_LINKER_FREEBSD_VERSION:C/.*-(.*)/\1/}
280 WANT_LINKER_VERSION_FILE= lib/clang/include/lld/Common/Version.inc
281 WANT_LINKER_VERSION!= \
282         awk '$$2 == "LLD_VERSION_STRING" { gsub("\"", "", $$3); split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
283         ${SRCDIR}/${WANT_LINKER_VERSION_FILE} || echo unknown
284 .else
285 WANT_LINKER_FREEBSD_VERSION_FILE=
286 WANT_LINKER_FREEBSD_VERSION=
287 .endif
288 .export WANT_LINKER_FREEBSD_VERSION WANT_LINKER_VERSION
289 .endif  # !defined(WANT_LINKER_FREEBSD_VERSION)
290
291 .if ${MK_SYSTEM_LINKER} == "yes" && \
292     defined(WANT_LINKER_FREEBSD_VERSION) && \
293     (${MK_LLD_BOOTSTRAP} == "yes") && \
294     !make(xdev*) && \
295     ${X_LINKER_TYPE} == ${WANT_LINKER_TYPE} && \
296     ${X_LINKER_VERSION} == ${WANT_LINKER_VERSION} && \
297     ${X_LINKER_FREEBSD_VERSION} == ${WANT_LINKER_FREEBSD_VERSION}
298 # Everything matches, disable the bootstrap linker.
299 MK_LLD_BOOTSTRAP=       no
300 USING_SYSTEM_LINKER=    yes
301 .endif  # ${WANT_LINKER_TYPE} == ${LINKER_TYPE}
302
303 # WITH_SYSTEM_COMPILER / WITH_SYSTEM_LINKER - Handle defaults and debug.
304 USING_SYSTEM_COMPILER?= no
305 USING_SYSTEM_LINKER?=   no
306
307 TEST_SYSTEM_COMPILER_VARS= \
308         USING_SYSTEM_COMPILER MK_SYSTEM_COMPILER \
309         MK_CROSS_COMPILER MK_CLANG_BOOTSTRAP \
310         WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \
311         WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \
312         CC COMPILER_TYPE COMPILER_FEATURES COMPILER_VERSION \
313         COMPILER_FREEBSD_VERSION \
314         XCC X_COMPILER_TYPE X_COMPILER_FEATURES X_COMPILER_VERSION \
315         X_COMPILER_FREEBSD_VERSION
316 TEST_SYSTEM_LINKER_VARS= \
317         USING_SYSTEM_LINKER MK_SYSTEM_LINKER \
318         MK_LLD_BOOTSTRAP \
319         WANT_LINKER_TYPE WANT_LINKER_VERSION WANT_LINKER_VERSION_FILE \
320         WANT_LINKER_FREEBSD_VERSION WANT_LINKER_FREEBSD_VERSION_FILE \
321         LD LINKER_TYPE LINKER_FEATURES LINKER_VERSION \
322         LINKER_FREEBSD_VERSION \
323         XLD X_LINKER_TYPE X_LINKER_FEATURES X_LINKER_VERSION \
324         X_LINKER_FREEBSD_VERSION
325
326 .for _t in compiler linker
327 test-system-${_t}: .PHONY
328 .for v in ${TEST_SYSTEM_${_t:tu}_VARS}
329         ${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}"
330 .endfor
331 .endfor
332 .if (make(buildworld) || make(buildkernel) || make(kernel-toolchain) || \
333     make(toolchain) || make(_cross-tools))
334 .if ${USING_SYSTEM_COMPILER} == "yes"
335 .info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree.  Not bootstrapping a cross-compiler.
336 .elif ${MK_CLANG_BOOTSTRAP} == "yes"
337 .info SYSTEM_COMPILER: libclang will be built for bootstrapping a cross-compiler.
338 .endif
339 .if ${USING_SYSTEM_LINKER} == "yes"
340 .info SYSTEM_LINKER: Determined that LD=${LD} matches the source tree.  Not bootstrapping a cross-linker.
341 .elif ${MK_LLD_BOOTSTRAP} == "yes"
342 .info SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.
343 .endif
344 .endif
345
346 # End WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
347
348 # Store some compiler metadata for use in installworld where we don't
349 # want to invoke CC at all.
350 _TOOLCHAIN_METADATA_VARS=       COMPILER_VERSION \
351                                 COMPILER_TYPE \
352                                 COMPILER_FEATURES \
353                                 COMPILER_FREEBSD_VERSION \
354                                 COMPILER_RESOURCE_DIR \
355                                 LINKER_VERSION \
356                                 LINKER_FEATURES \
357                                 LINKER_TYPE \
358                                 LINKER_FREEBSD_VERSION
359 toolchain-metadata.mk: .PHONY .META
360         @: > ${.TARGET}
361         @echo ".info Using cached toolchain metadata from build at $$(hostname) on $$(date)" \
362             > ${.TARGET}
363         @echo "_LOADED_TOOLCHAIN_METADATA=t" >> ${.TARGET}
364 .for v in ${_TOOLCHAIN_METADATA_VARS}
365         @echo "${v}=${${v}}" >> ${.TARGET}
366         @echo "X_${v}=${X_${v}}" >> ${.TARGET}
367 .endfor
368         @echo ".export ${_TOOLCHAIN_METADATA_VARS}" >> ${.TARGET}
369         @echo ".export ${_TOOLCHAIN_METADATA_VARS:C,^,X_,}" >> ${.TARGET}
370
371
372 # We must do lib/ and libexec/ before bin/ in case of a mid-install error to
373 # keep the users system reasonably usable.  For static->dynamic root upgrades,
374 # we don't want to install a dynamic binary without rtld and the needed
375 # libraries.  More commonly, for dynamic root, we don't want to install a
376 # binary that requires a newer library version that hasn't been installed yet.
377 # This ordering is not a guarantee though.  The only guarantee of a working
378 # system here would require fine-grained ordering of all components based
379 # on their dependencies.
380 .if !empty(SUBDIR_OVERRIDE)
381 SUBDIR= ${SUBDIR_OVERRIDE}
382 .else
383 SUBDIR= lib libexec
384 # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
385 # of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
386 # LOCAL_LIB_DIRS=foo/lib to behave as expected.
387 .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
388 _REDUNDANT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
389 .endfor
390 .for _DIR in ${LOCAL_LIB_DIRS}
391 .if ${_DIR} == ".WAIT" || (empty(_REDUNDANT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
392 SUBDIR+=        ${_DIR}
393 .endif
394 .endfor
395 .if !defined(NO_ROOT) && (make(installworld) || make(install))
396 # Ensure libraries are installed before progressing.
397 SUBDIR+=.WAIT
398 .endif
399 SUBDIR+=bin
400 .if ${MK_CDDL} != "no"
401 SUBDIR+=cddl
402 .endif
403 SUBDIR+=gnu include
404 .if ${MK_KERBEROS} != "no"
405 SUBDIR+=kerberos5
406 .endif
407 .if ${MK_RESCUE} != "no"
408 SUBDIR+=rescue
409 .endif
410 SUBDIR+=sbin
411 .if ${MK_CRYPT} != "no"
412 SUBDIR+=secure
413 .endif
414 .if !defined(NO_SHARE)
415 SUBDIR+=share
416 .endif
417 .if ${MK_BOOT} != "no"
418 SUBDIR+=stand
419 .endif
420 SUBDIR+=sys usr.bin usr.sbin
421 .if ${MK_TESTS} != "no"
422 SUBDIR+=        tests
423 .endif
424
425 # Local directories are built in parallel with the base system directories.
426 # Users may insert a .WAIT directive at the beginning or elsewhere within
427 # the LOCAL_DIRS and LOCAL_LIB_DIRS lists as needed.
428 .for _DIR in ${LOCAL_DIRS}
429 .if ${_DIR} == ".WAIT" || exists(${.CURDIR}/${_DIR}/Makefile)
430 SUBDIR+=        ${_DIR}
431 .endif
432 .endfor
433
434 # We must do etc/ last as it hooks into building the man whatis file
435 # by calling 'makedb' in share/man.  This is only relevant for
436 # install/distribute so they build the whatis file after every manpage is
437 # installed.
438 .if make(installworld) || make(install)
439 SUBDIR+=.WAIT
440 .endif
441 SUBDIR+=etc
442
443 .endif  # !empty(SUBDIR_OVERRIDE)
444
445 .if defined(NOCLEAN)
446 .warning The src.conf WITHOUT_CLEAN option can now be used instead of NOCLEAN.
447 MK_CLEAN:=      no
448 .endif
449 .if defined(NO_CLEAN)
450 .info The src.conf WITHOUT_CLEAN option can now be used instead of NO_CLEAN.
451 MK_CLEAN:=      no
452 .endif
453 .if defined(NO_CLEANDIR)
454 CLEANDIR=       clean cleandepend
455 .else
456 CLEANDIR=       cleandir
457 .endif
458
459 .if defined(WORLDFAST)
460 MK_CLEAN:=      no
461 NO_OBJWALK=     t
462 .endif
463
464 .if ${MK_META_MODE} == "yes"
465 # If filemon is used then we can rely on the build being incremental-safe.
466 # The .meta files will also track the build command and rebuild should
467 # it change.
468 .if empty(.MAKE.MODE:Mnofilemon)
469 MK_CLEAN:=      no
470 .endif
471 .endif
472 .if defined(NO_OBJWALK) || ${MK_AUTO_OBJ} == "yes"
473 NO_OBJWALK=     t
474 NO_KERNELOBJ=   t
475 .endif
476 .if !defined(NO_OBJWALK)
477 _obj=           obj
478 .endif
479
480 LOCAL_TOOL_DIRS?=
481 PACKAGEDIR?=    ${DESTDIR}/${DISTDIR}
482
483 .if empty(SHELL:M*csh*)
484 BUILDENV_SHELL?=${SHELL}
485 .else
486 BUILDENV_SHELL?=/bin/sh
487 .endif
488
489 .if !defined(_MKSHOWCONFIG)
490 .if !defined(SVN_CMD) || empty(SVN_CMD)
491 . for _P in /usr/bin /usr/local/bin
492 .  for _S in svn svnlite
493 .   if exists(${_P}/${_S})
494 SVN_CMD=   ${_P}/${_S}
495 .   endif
496 .  endfor
497 . endfor
498 .export SVN_CMD
499 .endif
500 SVNFLAGS?=      -r HEAD
501 .if !defined(VCS_REVISION) || empty(VCS_REVISION)
502 .if !defined(SVNVERSION_CMD) || empty(SVNVERSION_CMD)
503 . for _D in ${PATH:S,:, ,g}
504 .  if exists(${_D}/svnversion)
505 SVNVERSION_CMD?=${_D}/svnversion
506 .  endif
507 .  if exists(${_D}/svnliteversion)
508 SVNVERSION_CMD?=${_D}/svnliteversion
509 .  endif
510 . endfor
511 .endif
512 _VCS_REVISION?= $$(eval ${SVNVERSION_CMD} ${SRCDIR})
513 . if !empty(_VCS_REVISION)
514 VCS_REVISION=   $$(echo r${_VCS_REVISION})
515 . endif
516 .export VCS_REVISION
517 .endif
518
519 .if !defined(GIT_CMD) || empty(GIT_CMD)
520 . for _P in /usr/bin /usr/local/bin
521 .  if exists(${_P}/git)
522 GIT_CMD=   ${_P}/git
523 .  endif
524 . endfor
525 .export GIT_CMD
526 .endif
527
528 .if !defined(OSRELDATE)
529 .if exists(/usr/include/osreldate.h)
530 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
531                 /usr/include/osreldate.h
532 .else
533 OSRELDATE=      0
534 .endif
535 .export OSRELDATE
536 .endif
537
538 # Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
539 .if !defined(_REVISION)
540 _REVISION!=     ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V REVISION
541 .export _REVISION
542 .endif
543 .if !defined(_BRANCH)
544 _BRANCH!=       ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V BRANCH
545 .export _BRANCH
546 .endif
547 .if !defined(SRCRELDATE)
548 SRCRELDATE!=    awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
549                 ${SRCDIR}/sys/sys/param.h
550 .export SRCRELDATE
551 .endif
552 .if !defined(VERSION)
553 VERSION=        FreeBSD ${_REVISION}-${_BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
554 .export VERSION
555 .endif
556
557 .if !defined(PKG_VERSION)
558 .if ${_BRANCH:MSTABLE*} || ${_BRANCH:MCURRENT*}
559 TIMENOW=        %Y%m%d%H%M%S
560 EXTRA_REVISION= .s${TIMENOW:gmtime}
561 .elif ${_BRANCH:MALPHA*}
562 EXTRA_REVISION= _${_BRANCH:C/-ALPHA/.a/}
563 .elif ${_BRANCH:MBETA*}
564 EXTRA_REVISION= _${_BRANCH:C/-BETA/.b/}
565 .elif ${_BRANCH:MRC*}
566 EXTRA_REVISION= _${_BRANCH:C/-RC/.r/}
567 .elif ${_BRANCH:MPRERELEASE*}
568 EXTRA_REVISION= _${_BRANCH:C/-PRERELEASE/.p/}
569 .elif ${_BRANCH:M*-p*}
570 EXTRA_REVISION= _${_BRANCH:C/.*-p([0-9]+$)/\1/}
571 .endif
572 PKG_VERSION:=   ${_REVISION}${EXTRA_REVISION}
573 .endif
574 .endif  # !defined(PKG_VERSION)
575
576 .if !defined(PKG_TIMESTAMP)
577 TIMEEPOCHNOW=           %s
578 SOURCE_DATE_EPOCH=      ${TIMEEPOCHNOW:gmtime}
579 .else
580 SOURCE_DATE_EPOCH=      ${PKG_TIMESTAMP}
581 .endif
582
583 PKG_NAME_PREFIX?=       FreeBSD
584 PKG_MAINTAINER?=        re@FreeBSD.org
585 PKG_WWW?=               https://www.FreeBSD.org
586 .export PKG_NAME_PREFIX
587 .export PKG_MAINTAINER
588 .export PKG_WWW
589
590 .if !defined(_MKSHOWCONFIG)
591 _CPUTYPE!=      MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} -f /dev/null \
592                 -m ${.CURDIR}/share/mk MK_AUTO_OBJ=no -V CPUTYPE
593 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
594 .error CPUTYPE global should be set with ?=.
595 .endif
596 .endif
597 .if make(buildworld)
598 BUILD_ARCH!=    uname -p
599 # On some Linux systems uname -p returns "unknown" so skip this check there.
600 # This check only exists to tell people to use TARGET_ARCH instead of
601 # MACHINE_ARCH so skipping it when crossbuilding on non-FreeBSD should be fine.
602 .if ${MACHINE_ARCH} != ${BUILD_ARCH} && ${.MAKE.OS} == "FreeBSD"
603 .error To cross-build, set TARGET_ARCH.
604 .endif
605 .endif
606 WORLDTMP?=      ${OBJTOP}/tmp
607 BPATH=          ${CCACHE_WRAPPER_PATH_PFX}${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin:${WORLDTMP}/legacy/usr/libexec
608 XPATH=          ${WORLDTMP}/bin:${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
609
610 # When building we want to find the cross tools before the host tools in ${BPATH}.
611 # We also need to add UNIVERSE_TOOLCHAIN_PATH so that we can find the shared
612 # toolchain files (clang, lld, etc.) during make universe/tinderbox
613 STRICTTMPPATH=  ${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
614 # We should not be using tools from /usr/bin accidentally since this could cause
615 # the build to break on other systems that don't have that tool. For now we
616 # still allow using the old behaviour (inheriting $PATH) if
617 # BUILD_WITH_STRICT_TMPPATH is set to 0 but this will eventually be removed.
618
619 # Currently strict $PATH can cause build failures and does not work yet with
620 # USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
621 # resolved it will be turned on by default.
622 BUILD_WITH_STRICT_TMPPATH?=0
623 .if defined(CROSSBUILD_HOST)
624 # When building on non-FreeBSD we can't rely on the tools in /usr/bin being compatible
625 # with what FreeBSD expects. Therefore we only use tools from STRICTTMPPATH
626 # during the world build stage. We build most tools during the bootstrap-tools
627 # phase but symlink host tools that are known to work instead of building them
628 BUILD_WITH_STRICT_TMPPATH:=1
629 .endif
630 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
631 TMPPATH=        ${STRICTTMPPATH}
632 .else
633 TMPPATH=        ${STRICTTMPPATH}:${PATH}
634 .endif
635
636 #
637 # Avoid running mktemp(1) unless actually needed.
638 # It may not be functional, e.g., due to new ABI
639 # when in the middle of installing over this system.
640 #
641 .if make(distributeworld) || make(installworld) || make(stageworld)
642 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
643 MKTEMP=${WORLDTMP}/legacy/usr/bin/mktemp
644 .if !exists(${MKTEMP})
645 .error "mktemp binary doesn't exist in expected location: ${MKTEMP}"
646 .endif
647 .else
648 MKTEMP=mktemp
649 .endif
650 INSTALLTMP!=    ${MKTEMP} -d -u -t install
651 .endif
652
653 .if make(stagekernel) || make(distributekernel)
654 TAGS+=          kernel
655 PACKAGE=        kernel
656 .endif
657
658 #
659 # Building a world goes through the following stages
660 #
661 # 1. legacy stage [BMAKE]
662 #       This stage is responsible for creating compatibility
663 #       shims that are needed by the bootstrap-tools,
664 #       build-tools and cross-tools stages. These are generally
665 #       APIs that tools from one of those three stages need to
666 #       build that aren't present on the host.
667 # 1. bootstrap-tools stage [BMAKE]
668 #       This stage is responsible for creating programs that
669 #       are needed for backward compatibility reasons. They
670 #       are not built as cross-tools.
671 # 2. build-tools stage [TMAKE]
672 #       This stage is responsible for creating the object
673 #       tree and building any tools that are needed during
674 #       the build process. Some programs are listed during
675 #       this phase because they build binaries to generate
676 #       files needed to build these programs. This stage also
677 #       builds the 'build-tools' target rather than 'all'.
678 # 3. cross-tools stage [XMAKE]
679 #       This stage is responsible for creating any tools that
680 #       are needed for building the system. A cross-compiler is one
681 #       of them. This differs from build tools in two ways:
682 #       1. the 'all' target is built rather than 'build-tools'
683 #       2. these tools are installed into TMPPATH for stage 4.
684 # 4. world stage [WMAKE]
685 #       This stage actually builds the world.
686 # 5. install stage (optional) [IMAKE]
687 #       This stage installs a previously built world.
688 #
689
690 BOOTSTRAPPING?= 0
691 # Keep these in sync
692 MINIMUM_SUPPORTED_OSREL?= 1002501
693 MINIMUM_SUPPORTED_REL?= 10.3
694
695 # Common environment for world related stages
696 CROSSENV+=      \
697                 MACHINE_ARCH=${TARGET_ARCH} \
698                 MACHINE=${TARGET} \
699                 CPUTYPE=${TARGET_CPUTYPE}
700 .if ${MK_META_MODE} != "no"
701 # Don't rebuild build-tools targets during normal build.
702 CROSSENV+=      BUILD_TOOLS_META=.NOMETA
703 .endif
704 .if defined(TARGET_CFLAGS)
705 CROSSENV+=      ${TARGET_CFLAGS}
706 .endif
707 .if (${TARGET} != ${MACHINE} && !defined(WITH_LOCAL_MODULES)) || \
708     defined(WITHOUT_LOCAL_MODULES)
709 CROSSENV+=      LOCAL_MODULES=
710 .endif
711
712 BOOTSTRAPPING_OSRELDATE?=${OSRELDATE}
713
714 # bootstrap-tools stage
715 BMAKEENV=       INSTALL="sh ${.CURDIR}/tools/install.sh" \
716                 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
717                 PATH=${BPATH}:${PATH} \
718                 WORLDTMP=${WORLDTMP} \
719                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
720 # need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
721 BSARGS=         DESTDIR= \
722                 OBJTOP='${WORLDTMP}/obj-tools' \
723                 OBJROOT='$${OBJTOP}/' \
724                 MAKEOBJDIRPREFIX= \
725                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
726                 BWPHASE=${.TARGET:C,^_,,} \
727                 SSP_CFLAGS= \
728                 MK_HTML=no NO_LINT=yes MK_MAN=no MK_MAN_UTILS=yes \
729                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
730                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
731                 MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
732                 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \
733                 MK_INCLUDES=yes
734
735 BMAKE=          \
736                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
737                 ${BSARGS}
738 .if empty(.MAKEOVERRIDES:MMK_LLVM_TARGET_ALL)
739 BMAKE+=         MK_LLVM_TARGET_ALL=no
740 .endif
741
742 # build-tools stage
743 TMAKE=          \
744                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
745                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
746                 DESTDIR= \
747                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
748                 BWPHASE=${.TARGET:C,^_,,} \
749                 SSP_CFLAGS= \
750                 -DNO_LINT \
751                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
752                 MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
753                 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no
754
755 # cross-tools stage
756 # TOOLS_PREFIX set in BMAKE
757 XMAKE=          ${BMAKE} \
758                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
759                 MK_CLANG_IS_CC=${MK_CLANG_BOOTSTRAP} \
760                 MK_GDB=no MK_TESTS=no
761
762 # kernel-tools stage
763 KTMAKEENV=      INSTALL="sh ${.CURDIR}/tools/install.sh" \
764                 PATH=${BPATH}:${PATH} \
765                 WORLDTMP=${WORLDTMP} \
766                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
767
768 KTMAKE=         \
769                 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
770                 ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
771                 DESTDIR= \
772                 OBJTOP='${WORLDTMP}/obj-kernel-tools' \
773                 OBJROOT='$${OBJTOP}/' \
774                 MAKEOBJDIRPREFIX= \
775                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
776                 SSP_CFLAGS= \
777                 MK_HTML=no -DNO_LINT MK_MAN=no \
778                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
779                 -DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WARNS=no MK_CTF=no
780
781 # world stage
782 WMAKEENV=       ${CROSSENV} \
783                 INSTALL="${INSTALL_CMD} -U" \
784                 PATH=${TMPPATH} \
785                 SYSROOT=${WORLDTMP}
786
787 # make hierarchy
788 HMAKE=          PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
789 .if defined(NO_ROOT)
790 HMAKE+=         PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
791 .endif
792
793 CROSSENV+=      CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \
794                 CPP="${XCPP} ${XCFLAGS}" \
795                 AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \
796                 NM=${XNM} OBJCOPY="${XOBJCOPY}" \
797                 RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
798                 SIZE="${XSIZE}" STRIPBIN="${XSTRIPBIN}"
799
800 .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
801 # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
802 # directory, but the compiler will look in the right place for its
803 # tools so we don't need to tell it where to look.
804 BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
805 .endif
806
807
808 # The internal bootstrap compiler has a default sysroot set by TOOLS_PREFIX
809 # and target set by TARGET/TARGET_ARCH.  However, there are several needs to
810 # always pass an explicit --sysroot and -target.
811 # - External compiler needs sysroot and target flags.
812 # - External ld needs sysroot.
813 # - To be clear about the use of a sysroot when using the internal compiler.
814 # - Easier debugging.
815 # - Allowing WITH_SYSTEM_COMPILER+WITH_META_MODE to work together due to
816 #   the flip-flopping build command when sometimes using external and
817 #   sometimes using internal.
818 # - Allow using lld which has no support for default paths.
819 .if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
820 BFLAGS+=        -B${WORLDTMP}/usr/bin
821 .endif
822 .if ${WANT_COMPILER_TYPE} == gcc || \
823     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
824 .elif ${WANT_COMPILER_TYPE} == clang || \
825     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == clang)
826 XCFLAGS+=       -target ${TARGET_TRIPLE}
827 .endif
828 XCFLAGS+=       --sysroot=${WORLDTMP}
829
830 .if !empty(BFLAGS)
831 XCFLAGS+=       ${BFLAGS}
832 .endif
833
834 .if ${MK_LIB32} == "yes"
835 _LIBCOMPAT= 32
836 .include "Makefile.libcompat"
837 .elif ${MK_LIBSOFT} == "yes"
838 _LIBCOMPAT= SOFT
839 .include "Makefile.libcompat"
840 .endif
841
842 # META_MODE normally ignores host file changes since every build updates
843 # timestamps (see NO_META_IGNORE_HOST in sys.mk).  There are known times
844 # when the ABI breaks though that we want to force rebuilding WORLDTMP
845 # to get updated host tools.
846 .if ${MK_META_MODE} == "yes" && ${MK_CLEAN} == "no" && \
847     !defined(NO_META_IGNORE_HOST) && !defined(NO_META_IGNORE_HOST_HEADERS) && \
848     !defined(_MKSHOWCONFIG)
849 # r318736 - ino64 major ABI breakage
850 META_MODE_BAD_ABI_VERS+=        1200031
851
852 .if !defined(OBJDIR_HOST_OSRELDATE)
853 .if exists(${OBJTOP}/host-osreldate.h)
854 OBJDIR_HOST_OSRELDATE!= \
855     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
856     ${OBJTOP}/host-osreldate.h
857 .elif exists(${WORLDTMP}/usr/include/osreldate.h)
858 OBJDIR_HOST_OSRELDATE=  0
859 .endif
860 .export OBJDIR_HOST_OSRELDATE
861 .endif
862
863 # Note that this logic is the opposite of normal BOOTSTRAP handling.  We want
864 # to compare the WORLDTMP's OSRELDATE to the host's OSRELDATE.  If the WORLDTMP
865 # is older than the ABI-breakage OSRELDATE of the HOST then we rebuild.
866 .if defined(OBJDIR_HOST_OSRELDATE)
867 .for _ver in ${META_MODE_BAD_ABI_VERS}
868 .if ${OSRELDATE} >= ${_ver} && ${OBJDIR_HOST_OSRELDATE} < ${_ver}
869 _meta_mode_need_rebuild=        ${_ver}
870 .endif
871 .endfor
872 .if defined(_meta_mode_need_rebuild)
873 .info META_MODE: Rebuilding host tools due to ABI breakage in __FreeBSD_version ${_meta_mode_need_rebuild}.
874 NO_META_IGNORE_HOST_HEADERS=    1
875 .export NO_META_IGNORE_HOST_HEADERS
876 .endif  # defined(_meta_mode_need_rebuild)
877 .endif  # defined(OBJDIR_HOST_OSRELDATE)
878 .endif  # ${MK_META_MODE} == "yes" && ${MK_CLEAN} == "no" ...
879 # This is only used for META_MODE+filemon to track what the oldest
880 # __FreeBSD_version is in WORLDTMP.  This purposely does NOT have
881 # a make dependency on /usr/include/osreldate.h as the file should
882 # only be copied when it is missing or meta mode determines it has changed.
883 # Since host files are normally ignored without NO_META_IGNORE_HOST
884 # the file will never be updated unless that flag is specified.  This
885 # allows tracking the oldest osreldate to force rebuilds via
886 # META_MODE_BADABI_REVS above.
887 host-osreldate.h: # DO NOT ADD /usr/include/osreldate.h here
888 .if !defined(CROSSBUILD_HOST)
889         @cp -f /usr/include/osreldate.h ${.TARGET}
890 .else
891         @echo "#ifndef __FreeBSD_version" > ${.TARGET}
892         @echo "#define __FreeBSD_version ${OSRELDATE}" >> ${.TARGET}
893         @echo "#endif" >> ${.TARGET}
894 .endif
895
896 WMAKE=          ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
897                 BWPHASE=${.TARGET:C,^_,,} \
898                 DESTDIR=${WORLDTMP}
899
900 IMAKEENV=       ${CROSSENV}
901 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1 \
902                 ${IMAKE_INSTALL} ${IMAKE_MTREE}
903 .if empty(.MAKEFLAGS:M-n)
904 IMAKEENV+=      PATH=${STRICTTMPPATH}:${INSTALLTMP} \
905                 LD_LIBRARY_PATH=${INSTALLTMP} \
906                 PATH_LOCALE=${INSTALLTMP}/locale
907 IMAKE+=         __MAKE_SHELL=${INSTALLTMP}/sh
908 .else
909 IMAKEENV+=      PATH=${TMPPATH}:${INSTALLTMP}
910 .endif
911
912 # When generating install media, do not allow user and group information from
913 # the build host to affect the contents of the distribution.
914 .if make(distributeworld) || make(distrib-dirs) || make(distribution) || \
915     make(stageworld)
916 DB_FROM_SRC=    yes
917 .endif
918
919 .if defined(DB_FROM_SRC)
920 INSTALLFLAGS+=  -N ${.CURDIR}/etc
921 MTREEFLAGS+=    -N ${.CURDIR}/etc
922 .endif
923 _INSTALL_DDIR=  ${DESTDIR}/${DISTDIR}
924 INSTALL_DDIR=   ${_INSTALL_DDIR:S://:/:g:C:/$::}
925 .if defined(NO_ROOT)
926 METALOG?=       ${DESTDIR}/${DISTDIR}/METALOG
927 METALOG:=       ${METALOG:C,//+,/,g}
928 IMAKE+=         -DNO_ROOT METALOG=${METALOG}
929 METALOG_INSTALLFLAGS=   -U -M ${METALOG} -D ${INSTALL_DDIR}
930 INSTALLFLAGS+=  ${METALOG_INSTALLFLAGS}
931 CERTCTLFLAGS=   ${METALOG_INSTALLFLAGS}
932 MTREEFLAGS+=    -W
933 .endif
934 .if defined(BUILD_PKGS)
935 INSTALLFLAGS+=  -h sha256
936 .endif
937 .if defined(DB_FROM_SRC) || defined(NO_ROOT)
938 IMAKE_INSTALL=  INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}"
939 IMAKE_MTREE=    MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}"
940 .endif
941 .if make(distributeworld)
942 CERTCTLDESTDIR= ${DESTDIR}/${DISTDIR}/base
943 .else
944 CERTCTLDESTDIR= ${DESTDIR}
945 .endif
946
947 DESTDIR_MTREEFLAGS=     -deU
948 # When creating worldtmp we don't need to set the directories as owned by root
949 # so we also pass -W
950 WORLDTMP_MTREEFLAGS=    -deUW
951 .if defined(NO_ROOT)
952 # When building with -DNO_ROOT we shouldn't be changing the directories
953 # that are created by mtree to be owned by root/wheel.
954 DESTDIR_MTREEFLAGS+=    -W
955 .endif
956 DISTR_MTREE=    ${MTREE_CMD}
957 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
958 DISTR_MTREE=    ${WORLDTMP}/legacy/usr/sbin/mtree
959 .endif
960 WORLDTMP_MTREE= ${DISTR_MTREE} ${WORLDTMP_MTREEFLAGS}
961 DESTDIR_MTREE=  ${DISTR_MTREE} ${DESTDIR_MTREEFLAGS}
962
963 # kernel stage
964 KMAKEENV=       ${WMAKEENV:NSYSROOT=*}
965 KMAKE=          ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
966
967 #
968 # buildworld
969 #
970 # Attempt to rebuild the entire system, with reasonable chance of
971 # success, regardless of how old your existing system is.
972 #
973 _sanity_check: .PHONY .MAKE
974 .if ${.CURDIR:C/[^,]//g} != ""
975 #       The m4 build of sendmail files doesn't like it if ',' is used
976 #       anywhere in the path of it's files.
977         @echo
978         @echo "*** Error: path to source tree contains a comma ','"
979         @echo
980         @false
981 .elif ${.CURDIR:M*\:*} != ""
982 #       Using ':' leaks into PATH and breaks finding cross-tools.
983         @echo
984         @echo "*** Error: path to source tree contains a colon ':'"
985         @echo
986         @false
987 .endif
988
989 # Our current approach to dependency tracking cannot cope with certain source
990 # tree changes, particularly with respect to removing source files and
991 # replacing generated files.  Handle these cases here in an ad-hoc fashion.
992 _cleanobj_fast_depend_hack: .PHONY
993         @echo ">>> Deleting stale dependencies...";
994         sh ${.CURDIR}/tools/build/depend-cleanup.sh ${OBJTOP}
995
996 _worldtmp: .PHONY
997         @echo
998         @echo "--------------------------------------------------------------"
999         @echo ">>> Rebuilding the temporary build tree"
1000         @echo "--------------------------------------------------------------"
1001 .if ${MK_CLEAN} == "yes"
1002         rm -rf ${WORLDTMP}
1003 .else
1004 # Note: for delete-old we need to set $PATH to also include the host $PATH
1005 # since otherwise a partial build with missing symlinks in ${WORLDTMP}/legacy/
1006 # will fail to run due to missing binaries. $WMAKE sets PATH to only ${TMPPATH}
1007 # so we remove that assingnment from $WMAKE and prepend the new $PATH
1008         ${_+_}@if [ -e "${WORLDTMP}" ]; then \
1009                 echo ">>> Deleting stale files in build tree..."; \
1010                 cd ${.CURDIR}; env PATH=${TMPPATH}:${PATH} ${WMAKE:NPATH=*} \
1011                     _NO_INCLUDE_COMPILERMK=t -DBATCH_DELETE_OLD_FILES delete-old \
1012                     delete-old-libs >/dev/null; \
1013         fi
1014         rm -rf ${WORLDTMP}/legacy/usr/include
1015 .if ${USING_SYSTEM_COMPILER} == "yes"
1016 .for cc in cc c++
1017         if [ -x ${WORLDTMP}/usr/bin/${cc} ]; then \
1018                 inum=$$(stat -f %i ${WORLDTMP}/usr/bin/${cc}); \
1019                 find ${WORLDTMP}/usr/bin -inum $${inum} -delete; \
1020         fi
1021 .endfor
1022 .endif  # ${USING_SYSTEM_COMPILER} == "yes"
1023 .if ${USING_SYSTEM_LINKER} == "yes"
1024         @rm -f ${WORLDTMP}/usr/bin/ld ${WORLDTMP}/usr/bin/ld.lld
1025 .endif  # ${USING_SYSTEM_LINKER} == "yes"
1026 .endif  # ${MK_CLEAN} == "yes"
1027         @mkdir -p ${WORLDTMP}
1028         @touch ${WORLDTMP}/${.TARGET}
1029 # We can't use mtree to create the worldtmp directories since it may not be
1030 # available on the target system (this happens e.g. when building on non-FreeBSD)
1031         cd ${.CURDIR}/tools/build; \
1032             ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy installdirs
1033 # In order to build without inheriting $PATH we need to add symlinks to the host
1034 # tools in $WORLDTMP for the tools that we don't build during bootstrap-tools
1035         cd ${.CURDIR}/tools/build; \
1036             ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy host-symlinks
1037
1038 _legacy:
1039         @echo
1040         @echo "--------------------------------------------------------------"
1041         @echo ">>> stage 1.1: legacy release compatibility shims"
1042         @echo "--------------------------------------------------------------"
1043         ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
1044 _bootstrap-tools:
1045         @echo
1046         @echo "--------------------------------------------------------------"
1047         @echo ">>> stage 1.2: bootstrap tools"
1048         @echo "--------------------------------------------------------------"
1049         ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
1050         mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom \
1051             ${WORLDTMP}/bin
1052         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1053             -p ${WORLDTMP}/usr >/dev/null
1054         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1055             -p ${WORLDTMP}/usr/include >/dev/null
1056         ln -sf ${.CURDIR}/sys ${WORLDTMP}
1057 .if ${MK_DEBUG_FILES} != "no"
1058         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1059             -p ${WORLDTMP}/usr/lib >/dev/null
1060 .endif
1061 .for _mtree in ${LOCAL_MTREE}
1062         ${WORLDTMP_MTREE} -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
1063 .endfor
1064 _cleanobj:
1065 .if ${MK_CLEAN} == "yes"
1066         @echo
1067         @echo "--------------------------------------------------------------"
1068         @echo ">>> stage 2.1: cleaning up the object tree"
1069         @echo "--------------------------------------------------------------"
1070         # Avoid including bsd.compiler.mk in clean and obj with _NO_INCLUDE_COMPILERMK
1071         # since the restricted $PATH might not contain a valid cc binary
1072         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t ${CLEANDIR}
1073 .if defined(_LIBCOMPAT)
1074         ${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} _NO_INCLUDE_COMPILERMK=t -f Makefile.inc1 ${CLEANDIR}
1075 .endif
1076 .else
1077         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t _cleanobj_fast_depend_hack
1078 .endif  # ${MK_CLEAN} == "yes"
1079 _obj:
1080         @echo
1081         @echo "--------------------------------------------------------------"
1082         @echo ">>> stage 2.2: rebuilding the object tree"
1083         @echo "--------------------------------------------------------------"
1084         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t obj
1085 _build-tools:
1086         @echo
1087         @echo "--------------------------------------------------------------"
1088         @echo ">>> stage 2.3: build tools"
1089         @echo "--------------------------------------------------------------"
1090         ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
1091 _cross-tools:
1092         @echo
1093         @echo "--------------------------------------------------------------"
1094         @echo ">>> stage 3: cross tools"
1095         @echo "--------------------------------------------------------------"
1096         @rm -f ${OBJTOP}/toolchain-metadata.mk
1097         ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
1098         ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
1099 _build-metadata:
1100         @echo
1101         @echo "--------------------------------------------------------------"
1102         @echo ">>> stage 3.1: recording build metadata"
1103         @echo "--------------------------------------------------------------"
1104         ${_+_}cd ${.CURDIR}; ${WMAKE} toolchain-metadata.mk
1105         ${_+_}cd ${.CURDIR}; ${WMAKE} host-osreldate.h
1106 _includes:
1107         @echo
1108         @echo "--------------------------------------------------------------"
1109         @echo ">>> stage 4.1: building includes"
1110         @echo "--------------------------------------------------------------"
1111 # Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
1112 # headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
1113         ${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
1114             MK_INCLUDES=yes includes
1115 .if !empty(SUBDIR_OVERRIDE) && make(buildworld)
1116         ${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
1117 .endif
1118 _libraries:
1119         @echo
1120         @echo "--------------------------------------------------------------"
1121         @echo ">>> stage 4.2: building libraries"
1122         @echo "--------------------------------------------------------------"
1123         ${_+_}cd ${.CURDIR}; \
1124             ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
1125             MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} \
1126             libraries
1127 everything: .PHONY
1128         @echo
1129         @echo "--------------------------------------------------------------"
1130         @echo ">>> stage 4.4: building everything"
1131         @echo "--------------------------------------------------------------"
1132         ${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
1133
1134 WMAKE_TGTS=
1135 .if !defined(WORLDFAST)
1136 WMAKE_TGTS+=    _sanity_check _worldtmp _legacy
1137 .if empty(SUBDIR_OVERRIDE)
1138 WMAKE_TGTS+=    _bootstrap-tools
1139 .endif
1140 WMAKE_TGTS+=    _cleanobj
1141 .if !defined(NO_OBJWALK)
1142 WMAKE_TGTS+=    _obj
1143 .endif
1144 WMAKE_TGTS+=    _build-tools _cross-tools
1145 WMAKE_TGTS+=    _build-metadata
1146 WMAKE_TGTS+=    _includes
1147 .endif
1148 .if !defined(NO_LIBS)
1149 WMAKE_TGTS+=    _libraries
1150 .endif
1151 .if defined(_LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
1152 WMAKE_TGTS+=    build${libcompat}
1153 .endif
1154 WMAKE_TGTS+=    everything
1155
1156 # record buildworld time in seconds
1157 .if make(buildworld)
1158 _BUILDWORLD_START!= date '+%s'
1159 .export _BUILDWORLD_START
1160 .endif
1161
1162 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY
1163 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
1164
1165 _ncpu_cmd=sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo unknown
1166
1167 buildworld_prologue: .PHONY
1168         @echo "--------------------------------------------------------------"
1169         @echo ">>> World build started on `LC_ALL=C date`"
1170         @echo "--------------------------------------------------------------"
1171
1172 buildworld_epilogue: .PHONY
1173         @echo
1174         @echo "--------------------------------------------------------------"
1175         @echo ">>> World build completed on `LC_ALL=C date`"
1176         @seconds=$$(($$(date '+%s') - ${_BUILDWORLD_START})); \
1177           echo -n ">>> World built in $$seconds seconds, "; \
1178           echo "ncpu: $$(${_ncpu_cmd})${.MAKE.JOBS:S/^/, make -j/}"
1179         @echo "--------------------------------------------------------------"
1180
1181 #
1182 # We need to have this as a target because the indirection between Makefile
1183 # and Makefile.inc1 causes the correct PATH to be used, rather than a
1184 # modification of the current environment's PATH.  In addition, we need
1185 # to quote multiword values.
1186 #
1187 buildenvvars: .PHONY
1188         @echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
1189
1190 .if ${.TARGETS:Mbuildenv}
1191 .if ${.MAKEFLAGS:M-j}
1192 .error The buildenv target is incompatible with -j
1193 .endif
1194 .endif
1195 BUILDENV_DIR?=  ${.CURDIR}
1196 #
1197 # Note: make will report any errors the shell reports. This can
1198 # be odd if the last command in an interactive shell generates an
1199 # error or is terminated by SIGINT. These reported errors look bad,
1200 # but are harmless. Allowing them also allows BUIDLENV_SHELL to
1201 # be a complex command whose status will be returned to the caller.
1202 # Some scripts in tools rely on this behavior to report build errors.
1203 #
1204 buildenv: .PHONY
1205         @echo Entering world for ${TARGET_ARCH}:${TARGET}
1206 .if ${BUILDENV_SHELL:M*zsh*}
1207         @echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
1208 .endif
1209         @cd ${BUILDENV_DIR} && env ${WMAKEENV} \
1210         INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}" \
1211         MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}" BUILDENV=1 ${BUILDENV_SHELL}
1212
1213 TOOLCHAIN_TGTS= ${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
1214 toolchain: ${TOOLCHAIN_TGTS} .PHONY
1215 KERNEL_TOOLCHAIN_TGTS=  ${TOOLCHAIN_TGTS:N_obj:N_cleanobj:N_includes:N_libraries}
1216 .if make(kernel-toolchain)
1217 .ORDER: ${KERNEL_TOOLCHAIN_TGTS}
1218 .endif
1219 kernel-toolchain: ${KERNEL_TOOLCHAIN_TGTS} .PHONY
1220
1221 #
1222 # installcheck
1223 #
1224 # Checks to be sure system is ready for installworld/installkernel.
1225 #
1226 installcheck: _installcheck_world _installcheck_kernel .PHONY
1227 _installcheck_world: .PHONY
1228         @echo "--------------------------------------------------------------"
1229         @echo ">>> Install check world"
1230         @echo "--------------------------------------------------------------"
1231 _installcheck_kernel: .PHONY
1232         @echo "--------------------------------------------------------------"
1233         @echo ">>> Install check kernel"
1234         @echo "--------------------------------------------------------------"
1235
1236 #
1237 # Require DESTDIR to be set if installing for a different architecture or
1238 # using the user/group database in the source tree.
1239 #
1240 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
1241     defined(DB_FROM_SRC)
1242 .if !make(distributeworld)
1243 _installcheck_world: __installcheck_DESTDIR
1244 _installcheck_kernel: __installcheck_DESTDIR
1245 __installcheck_DESTDIR: .PHONY
1246 .if !defined(DESTDIR) || empty(DESTDIR)
1247         @echo "ERROR: Please set DESTDIR!"; \
1248         false
1249 .endif
1250 .endif
1251 .endif
1252
1253 .if !defined(DB_FROM_SRC)
1254 #
1255 # Check for missing UIDs/GIDs.
1256 #
1257 CHECK_UIDS=     auditdistd
1258 CHECK_GIDS=     audit
1259 CHECK_UIDS+=    ntpd
1260 CHECK_GIDS+=    ntpd
1261 CHECK_UIDS+=    proxy
1262 CHECK_GIDS+=    proxy authpf
1263 CHECK_UIDS+=    smmsp
1264 CHECK_GIDS+=    smmsp
1265 CHECK_UIDS+=    unbound
1266 CHECK_GIDS+=    unbound
1267 _installcheck_world: __installcheck_UGID
1268 __installcheck_UGID: .PHONY
1269 .for uid in ${CHECK_UIDS}
1270         @if ! `id -u ${uid} >/dev/null 2>&1`; then \
1271                 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
1272                 false; \
1273         fi
1274 .endfor
1275 .for gid in ${CHECK_GIDS}
1276         @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
1277                 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
1278                 false; \
1279         fi
1280 .endfor
1281 .endif
1282 #
1283 # If installing over the running system (DESTDIR is / or unset) and the install
1284 # includes rescue, try running rescue from the objdir as a sanity check.  If
1285 # rescue is not functional (e.g., because it depends on a system call not
1286 # supported by the currently running kernel), abort the installation.
1287 #
1288 .if !make(distributeworld) && ${MK_RESCUE} != "no" && \
1289     (empty(DESTDIR) || ${DESTDIR} == "/") && empty(BYPASS_INSTALLCHECK_SH)
1290 _installcheck_world: __installcheck_sh_check
1291 __installcheck_sh_check: .PHONY
1292         @if [ "`${OBJTOP}/rescue/rescue/rescue sh -c 'echo OK'`" != \
1293             OK ]; then \
1294                 echo "rescue/sh check failed, installation aborted" >&2; \
1295                 false; \
1296         fi
1297 .endif
1298
1299 #
1300 # Required install tools to be saved in a scratch dir for safety.
1301 #
1302 .if ${MK_ZONEINFO} != "no"
1303 _zoneinfo=      zic tzsetup
1304 .endif
1305
1306 .if !defined(CROSSBUILD_HOST)
1307 _sysctl=sysctl
1308 .endif
1309
1310 ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \
1311         date echo egrep find grep id install ${_install-info} \
1312         ln make mkdir mtree mv pwd_mkdb \
1313         rm sed services_mkdb sh sort strip ${_sysctl} test true uname wc \
1314         ${_zoneinfo} ${LOCAL_ITOOLS}
1315
1316 # Needed for share/man
1317 .if ${MK_MAN_UTILS} != "no"
1318 ITOOLS+=makewhatis
1319 .endif
1320
1321 #
1322 # distributeworld
1323 #
1324 # Distributes everything compiled by a `buildworld'.
1325 #
1326 # installworld
1327 #
1328 # Installs everything compiled by a 'buildworld'.
1329 #
1330
1331 # Non-base distributions produced by the base system
1332 EXTRA_DISTRIBUTIONS=
1333 .if defined(_LIBCOMPAT)
1334 EXTRA_DISTRIBUTIONS+=   lib${libcompat}
1335 .endif
1336 .if ${MK_TESTS} != "no"
1337 EXTRA_DISTRIBUTIONS+=   tests
1338 .endif
1339
1340 DEBUG_DISTRIBUTIONS=
1341 .if ${MK_DEBUG_FILES} != "no"
1342 DEBUG_DISTRIBUTIONS+=   base ${EXTRA_DISTRIBUTIONS:S,tests,,}
1343 .endif
1344
1345 MTREE_MAGIC?=   mtree 2.0
1346
1347 distributeworld installworld stageworld: _installcheck_world .PHONY
1348         mkdir -p ${INSTALLTMP}
1349         progs=$$(for prog in ${ITOOLS}; do \
1350                 if progpath=`env PATH=${TMPPATH} which $$prog`; then \
1351                         echo $$progpath; \
1352                 else \
1353                         echo "Required tool $$prog not found in PATH ($$PATH)." >&2; \
1354                         exit 1; \
1355                 fi; \
1356             done); \
1357         if [ -z "${CROSSBUILD_HOST}" ] ; then \
1358                 libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
1359                     while read line; do \
1360                         set -- $$line; \
1361                         if [ "$$2 $$3" != "not found" ]; then \
1362                                 echo $$2; \
1363                         else \
1364                                 echo "Required library $$1 not found." >&2; \
1365                                 exit 1; \
1366                         fi; \
1367                     done); \
1368         fi; \
1369         cp $$libs $$progs ${INSTALLTMP}
1370         cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
1371 .if defined(NO_ROOT)
1372         -mkdir -p ${METALOG:H}
1373         echo "#${MTREE_MAGIC}" > ${METALOG}
1374 .endif
1375 .if make(distributeworld)
1376 .for dist in ${EXTRA_DISTRIBUTIONS}
1377         -mkdir ${DESTDIR}/${DISTDIR}/${dist}
1378         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1379             -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
1380         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1381             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1382         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1383             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
1384 .if ${MK_DEBUG_FILES} != "no"
1385         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1386             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
1387 .endif
1388 .if defined(_LIBCOMPAT)
1389         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1390             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1391 .if ${MK_DEBUG_FILES} != "no"
1392         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1393             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
1394 .endif
1395 .endif
1396 .if ${MK_TESTS} != "no" && ${dist} == "tests"
1397         -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
1398         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1399             -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
1400 .if ${MK_DEBUG_FILES} != "no"
1401         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1402             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
1403 .endif
1404 .endif
1405 .if defined(NO_ROOT)
1406         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
1407             sed -e 's#^\./#./${dist}/#' >> ${METALOG}
1408         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
1409             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1410         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
1411             sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
1412 .if defined(_LIBCOMPAT)
1413         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
1414             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1415 .endif
1416 .endif
1417 .endfor
1418         -mkdir ${DESTDIR}/${DISTDIR}/base
1419         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1420             METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
1421             DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
1422             LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
1423         ${INSTALL_SYMLINK} ${INSTALLFLAGS} usr/src/sys ${INSTALL_DDIR}/base/sys
1424 .endif # make(distributeworld)
1425         ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
1426             ${IMAKEENV} rm -rf ${INSTALLTMP}
1427 .if make(distributeworld)
1428 .for dist in ${EXTRA_DISTRIBUTIONS}
1429         find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete
1430 .endfor
1431 .if defined(NO_ROOT)
1432 .for dist in base ${EXTRA_DISTRIBUTIONS}
1433         @# For each file that exists in this dist, print the corresponding
1434         @# line from the METALOG.  This relies on the fact that
1435         @# a line containing only the filename will sort immediately before
1436         @# the relevant mtree line.
1437         cd ${DESTDIR}/${DISTDIR}; \
1438         find ./${dist} | sort -u ${METALOG} - | \
1439         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1440         ${DESTDIR}/${DISTDIR}/${dist}.meta
1441 .endfor
1442 .for dist in ${DEBUG_DISTRIBUTIONS}
1443         @# For each file that exists in this dist, print the corresponding
1444         @# line from the METALOG.  This relies on the fact that
1445         @# a line containing only the filename will sort immediately before
1446         @# the relevant mtree line.
1447         cd ${DESTDIR}/${DISTDIR}; \
1448         find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
1449         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1450         ${DESTDIR}/${DISTDIR}/${dist}.debug.meta
1451 .endfor
1452 .endif
1453 .endif # make(distributeworld)
1454 .if !make(packageworld) && ${MK_CAROOT} != "no"
1455         @if which openssl>/dev/null; then \
1456                 DESTDIR=${CERTCTLDESTDIR} PATH=${TMPPATH}:${PATH} \
1457                     sh ${SRCTOP}/usr.sbin/certctl/certctl.sh ${CERTCTLFLAGS} rehash \
1458         else \
1459                 echo "No openssl on the host, not rehashing certificates target -- /etc/ssl may not be populated."; \
1460         fi
1461 .endif
1462
1463 packageworld: .PHONY
1464 .for dist in base ${EXTRA_DISTRIBUTIONS}
1465 .if defined(NO_ROOT)
1466         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1467             tar cvf - --exclude usr/lib/debug \
1468             @${DESTDIR}/${DISTDIR}/${dist}.meta | \
1469             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1470 .else
1471         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1472             tar cvf - --exclude usr/lib/debug . | \
1473             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1474 .endif
1475 .endfor
1476
1477 .for dist in ${DEBUG_DISTRIBUTIONS}
1478 . if defined(NO_ROOT)
1479         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1480             tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
1481             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1482 . else
1483         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1484             tar cvLf - usr/lib/debug | \
1485             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1486 . endif
1487 .endfor
1488
1489 makeman: .PHONY
1490         ${_+_}cd ${.CURDIR}/tools/build/options; sh makeman > \
1491             ${.CURDIR}/share/man/man5/src.conf.5
1492
1493 # We can't assume here that ${TMPPATH} will include ${PATH} or /usr/libexec
1494 # because we may be building with a STRICTTMPPATH, so we explicitly include
1495 # /usr/libexec here for flua.  ${TMPPATH} still usefully includes anything else
1496 # we may need to function.
1497 _sysent_PATH=   ${TMPPATH}:/usr/libexec
1498 _sysent_dirs=   sys/kern
1499 _sysent_dirs+=  sys/compat/freebsd32
1500 _sysent_dirs+=  sys/compat/cloudabi32   \
1501                 sys/compat/cloudabi64
1502 _sysent_dirs+=  sys/amd64/linux         \
1503                 sys/amd64/linux32       \
1504                 sys/arm/linux           \
1505                 sys/arm64/linux         \
1506                 sys/i386/linux
1507
1508 sysent: .PHONY
1509 .for _dir in ${_sysent_dirs}
1510 sysent-${_dir}: .PHONY
1511         @echo "${MAKE} -C ${.CURDIR}/${_dir} sysent"
1512         ${_+_}@env PATH=${_sysent_PATH} ${MAKE} -C ${.CURDIR}/${_dir} sysent
1513
1514 sysent: sysent-${_dir}
1515 .endfor
1516
1517 #
1518 # reinstall
1519 #
1520 # If you have a build server, you can NFS mount the source and obj directories
1521 # and do a 'make reinstall' on the *client* to install new binaries from the
1522 # most recent server build.
1523 #
1524 restage reinstall: .MAKE .PHONY
1525         @echo "--------------------------------------------------------------"
1526         @echo ">>> Making hierarchy"
1527         @echo "--------------------------------------------------------------"
1528         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1529             LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
1530 .if make(restage)
1531         @echo "--------------------------------------------------------------"
1532         @echo ">>> Making distribution"
1533         @echo "--------------------------------------------------------------"
1534         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1535             LOCAL_MTREE=${LOCAL_MTREE:Q} distribution
1536 .endif
1537         @echo
1538         @echo "--------------------------------------------------------------"
1539         @echo ">>> Installing everything started on `LC_ALL=C date`"
1540         @echo "--------------------------------------------------------------"
1541         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
1542 .if defined(_LIBCOMPAT)
1543         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
1544 .endif
1545         @echo "--------------------------------------------------------------"
1546         @echo ">>> Installing everything completed on `LC_ALL=C date`"
1547         @echo "--------------------------------------------------------------"
1548
1549 redistribute: .MAKE .PHONY
1550         @echo "--------------------------------------------------------------"
1551         @echo ">>> Distributing everything"
1552         @echo "--------------------------------------------------------------"
1553         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1554 .if defined(_LIBCOMPAT)
1555         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1556             DISTRIBUTION=lib${libcompat}
1557 .endif
1558
1559 distrib-dirs distribution: .MAKE .PHONY
1560         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1561             ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1562 .if make(distribution)
1563         ${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1564                 ${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1565                 METALOG=${METALOG} MK_TESTS=no \
1566                 MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} installconfig
1567 .endif
1568
1569 #
1570 # buildkernel and installkernel
1571 #
1572 # Which kernels to build and/or install is specified by setting
1573 # KERNCONF. If not defined a GENERIC kernel is built/installed.
1574 # Only the existing (depending TARGET) config files are used
1575 # for building kernels and only the first of these is designated
1576 # as the one being installed.
1577 #
1578 # Note that we have to use TARGET instead of TARGET_ARCH when
1579 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
1580 # be set to cross-build, we have to make sure TARGET is set
1581 # properly.
1582
1583 .if defined(KERNFAST)
1584 NO_KERNELCLEAN= t
1585 NO_KERNELCONFIG=        t
1586 NO_KERNELOBJ=           t
1587 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1588 .if !defined(KERNCONF) && ${KERNFAST} != "1"
1589 KERNCONF=${KERNFAST}
1590 .endif
1591 .endif
1592 .if ${TARGET_ARCH} == "powerpc64"
1593 KERNCONF?=      GENERIC64
1594 .elif ${TARGET_ARCH} == "powerpc64le"
1595 KERNCONF?=      GENERIC64LE
1596 .elif ${TARGET_ARCH} == "powerpcspe"
1597 KERNCONF?=      MPC85XXSPE
1598 .else
1599 KERNCONF?=      GENERIC
1600 .endif
1601 INSTKERNNAME?=  kernel
1602
1603 KERNSRCDIR?=    ${.CURDIR}/sys
1604 KRNLCONFDIR=    ${KERNSRCDIR}/${TARGET}/conf
1605 KRNLOBJDIR=     ${OBJTOP}${KERNSRCDIR:C,^${.CURDIR},,}
1606 KERNCONFDIR?=   ${KRNLCONFDIR}
1607
1608 BUILDKERNELS=
1609 INSTALLKERNEL=
1610 .if defined(NO_INSTALLKERNEL)
1611 # All of the BUILDKERNELS loops start at index 1.
1612 BUILDKERNELS+= dummy
1613 .endif
1614 .for _kernel in ${KERNCONF}
1615 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${_kernel})
1616 BUILDKERNELS+=  ${_kernel}
1617 .if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1618 INSTALLKERNEL= ${_kernel}
1619 .endif
1620 .else
1621 .if make(buildkernel)
1622 .error Missing KERNCONF ${KERNCONFDIR}/${_kernel}
1623 .endif
1624 .endif
1625 .endfor
1626
1627 _cleankernobj_fast_depend_hack: .PHONY
1628 # 20191009  r353340  removal of opensolaris_atomic.S (also r353381)
1629 .if ${MACHINE} != i386
1630 .for f in opensolaris_atomic
1631 .for m in opensolaris zfs
1632         @if [ -e "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o" ] && \
1633             grep -q ${f}.S "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o"; then \
1634                 echo "Removing stale dependencies for opensolaris_atomic"; \
1635                 rm -f ${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.*; \
1636         fi
1637 .endfor
1638 .endfor
1639 .endif
1640
1641 ${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1642
1643 # record kernel(s) build time in seconds
1644 .if make(buildkernel)
1645 _BUILDKERNEL_START!= date '+%s'
1646 .endif
1647
1648 #
1649 # buildkernel
1650 #
1651 # Builds all kernels defined by BUILDKERNELS.
1652 #
1653 buildkernel: .MAKE .PHONY
1654 .if empty(BUILDKERNELS:Ndummy)
1655         @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1656         false
1657 .endif
1658         @echo
1659 .for _kernel in ${BUILDKERNELS:Ndummy}
1660         @echo "--------------------------------------------------------------"
1661         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1662         @echo "--------------------------------------------------------------"
1663         @echo "===> ${_kernel}"
1664         mkdir -p ${KRNLOBJDIR}
1665 .if !defined(NO_KERNELCONFIG)
1666         @echo
1667         @echo "--------------------------------------------------------------"
1668         @echo ">>> stage 1: configuring the kernel"
1669         @echo "--------------------------------------------------------------"
1670         cd ${KRNLCONFDIR}; \
1671                 PATH=${TMPPATH} \
1672                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1673                         -I '${KERNCONFDIR}' -I '${KRNLCONFDIR}' \
1674                         '${KERNCONFDIR}/${_kernel}'
1675 .endif
1676 .if ${MK_CLEAN} == "yes" && !defined(NO_KERNELCLEAN)
1677         @echo
1678         @echo "--------------------------------------------------------------"
1679         @echo ">>> stage 2.1: cleaning up the object tree"
1680         @echo "--------------------------------------------------------------"
1681         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1682 .else
1683         ${_+_}cd ${.CURDIR}; ${WMAKE} _cleankernobj_fast_depend_hack
1684 .endif
1685 .if !defined(NO_KERNELOBJ)
1686         @echo
1687         @echo "--------------------------------------------------------------"
1688         @echo ">>> stage 2.2: rebuilding the object tree"
1689         @echo "--------------------------------------------------------------"
1690         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1691 .endif
1692         @echo
1693         @echo "--------------------------------------------------------------"
1694         @echo ">>> stage 2.3: build tools"
1695         @echo "--------------------------------------------------------------"
1696         ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1697         @echo
1698         @echo "--------------------------------------------------------------"
1699         @echo ">>> stage 3.1: building everything"
1700         @echo "--------------------------------------------------------------"
1701         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1702         @echo "--------------------------------------------------------------"
1703         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1704         @echo "--------------------------------------------------------------"
1705
1706 .endfor
1707         @seconds=$$(($$(date '+%s') - ${_BUILDKERNEL_START})); \
1708           echo -n ">>> Kernel(s) ${BUILDKERNELS} built in $$seconds seconds, "; \
1709           echo "ncpu: $$(${_ncpu_cmd})${.MAKE.JOBS:S/^/, make -j/}"
1710         @echo "--------------------------------------------------------------"
1711
1712 NO_INSTALLEXTRAKERNELS?=        yes
1713
1714 #
1715 # installkernel, etc.
1716 #
1717 # Install the kernel defined by INSTALLKERNEL
1718 #
1719 installkernel installkernel.debug \
1720 reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1721 .if !defined(NO_INSTALLKERNEL)
1722 .if empty(INSTALLKERNEL)
1723         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1724         false
1725 .endif
1726         @echo "--------------------------------------------------------------"
1727         @echo ">>> Installing kernel ${INSTALLKERNEL} on $$(LC_ALL=C date)"
1728         @echo "--------------------------------------------------------------"
1729         ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1730             ${CROSSENV} PATH=${TMPPATH} \
1731             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1732         @echo "--------------------------------------------------------------"
1733         @echo ">>> Installing kernel ${INSTALLKERNEL} completed on $$(LC_ALL=C date)"
1734         @echo "--------------------------------------------------------------"
1735 .endif
1736 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1737 .for _kernel in ${BUILDKERNELS:[2..-1]}
1738         @echo "--------------------------------------------------------------"
1739         @echo ">>> Installing kernel ${_kernel} $$(LC_ALL=C date)"
1740         @echo "--------------------------------------------------------------"
1741         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1742             ${CROSSENV} PATH=${TMPPATH} \
1743             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1744         @echo "--------------------------------------------------------------"
1745         @echo ">>> Installing kernel ${_kernel} completed on $$(LC_ALL=C date)"
1746         @echo "--------------------------------------------------------------"
1747 .endfor
1748 .endif
1749
1750 distributekernel distributekernel.debug: .PHONY
1751 .if !defined(NO_INSTALLKERNEL)
1752 .if empty(INSTALLKERNEL)
1753         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1754         false
1755 .endif
1756         mkdir -p ${DESTDIR}/${DISTDIR}
1757 .if defined(NO_ROOT)
1758         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1759 .endif
1760         ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1761             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1762             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1763             DESTDIR=${INSTALL_DDIR}/kernel \
1764             ${.TARGET:S/distributekernel/install/}
1765 .if defined(NO_ROOT)
1766         @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1767             ${DESTDIR}/${DISTDIR}/kernel.meta
1768 .endif
1769 .endif
1770 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1771 .for _kernel in ${BUILDKERNELS:[2..-1]}
1772 .if defined(NO_ROOT)
1773         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1774 .endif
1775         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1776             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1777             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1778             KERNEL=${INSTKERNNAME}.${_kernel} \
1779             DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1780             ${.TARGET:S/distributekernel/install/}
1781 .if defined(NO_ROOT)
1782         @sed -e "s|^./kernel.${_kernel}|.|" \
1783             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1784             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1785 .endif
1786 .endfor
1787 .endif
1788
1789 packagekernel: .PHONY
1790 .if defined(NO_ROOT)
1791 .if !defined(NO_INSTALLKERNEL)
1792         cd ${DESTDIR}/${DISTDIR}/kernel; \
1793             tar cvf - --exclude '*.debug' \
1794             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1795             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1796 .endif
1797 .if ${MK_DEBUG_FILES} != "no"
1798         cd ${DESTDIR}/${DISTDIR}/kernel; \
1799             tar cvf - --include '*/*/*.debug' \
1800             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1801             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1802 .endif
1803 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1804 .for _kernel in ${BUILDKERNELS:[2..-1]}
1805         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1806             tar cvf - --exclude '*.debug' \
1807             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1808             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1809 .if ${MK_DEBUG_FILES} != "no"
1810         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1811             tar cvf - --include '*/*/*.debug' \
1812             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1813             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1814 .endif
1815 .endfor
1816 .endif
1817 .else
1818 .if !defined(NO_INSTALLKERNEL)
1819         cd ${DESTDIR}/${DISTDIR}/kernel; \
1820             tar cvf - --exclude '*.debug' . | \
1821             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1822 .endif
1823 .if ${MK_DEBUG_FILES} != "no"
1824         cd ${DESTDIR}/${DISTDIR}/kernel; \
1825             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1826             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1827 .endif
1828 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1829 .for _kernel in ${BUILDKERNELS:[2..-1]}
1830         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1831             tar cvf - --exclude '*.debug' . | \
1832             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1833 .if ${MK_DEBUG_FILES} != "no"
1834         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1835             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1836             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1837 .endif
1838 .endfor
1839 .endif
1840 .endif
1841
1842 stagekernel: .PHONY
1843         ${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1844
1845 PORTSDIR?=      /usr/ports
1846 WSTAGEDIR?=     ${OBJTOP}/worldstage
1847 KSTAGEDIR?=     ${OBJTOP}/kernelstage
1848 REPODIR?=       ${OBJROOT}repo
1849 PKG_FORMAT?=    txz
1850 PKGSIGNKEY?=    # empty
1851 PKG_OUTPUT_DIR?=        ${PKG_VERSION}
1852
1853 .ORDER:         stage-packages create-packages
1854 .ORDER:         create-packages create-world-packages
1855 .ORDER:         create-packages create-kernel-packages
1856 .ORDER:         create-packages sign-packages
1857
1858 _pkgbootstrap: .PHONY
1859 .if make(*package*) && !exists(${LOCALBASE}/sbin/pkg)
1860         @env ASSUME_ALWAYS_YES=YES pkg bootstrap
1861 .endif
1862
1863 .if make(create-world-packages-jobs) || make(create-kernel-packages*) || make(real-update-packages)
1864 PKG_ABI!=${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI
1865 .endif
1866
1867 .if !defined(PKG_VERSION_FROM)
1868 .if defined(PKG_ABI)
1869 PKG_VERSION_FROM!=/usr/bin/readlink ${REPODIR}/${PKG_ABI}/latest
1870 .endif
1871 .endif
1872
1873 packages: .PHONY
1874         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1875
1876 update-packages: .PHONY
1877         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-update-packages
1878
1879 package-pkg: .PHONY
1880         rm -rf /tmp/ports.${TARGET} || :
1881         env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \
1882                 PKG_CMD=${PKG_CMD} PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} \
1883                 WSTAGEDIR=${WSTAGEDIR} \
1884                 sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1885
1886 real-packages:  stage-packages create-packages sign-packages .PHONY
1887
1888 real-update-packages: stage-packages .PHONY
1889         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} create-packages
1890         @echo "==> Checking for new packages (comparing ${PKG_VERSION} to ${PKG_VERSION_FROM})"
1891         @for pkg in ${REPODIR}/${PKG_ABI}/${PKG_VERSION_FROM}/${PKG_NAME_PREFIX}-*; do \
1892           pkgname=$$(pkg query -F $${pkg} '%n' | sed 's/${PKG_NAME_PREFIX}-\(.*\)/\1/') ; \
1893           newpkgname=${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION}.${PKG_FORMAT} ; \
1894           oldsum=$$(pkg query -F $${pkg} '%X') ; \
1895           if [ ! -f ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} ]; then \
1896             continue; \
1897           fi ; \
1898           newsum=$$(pkg query -F ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} '%X') ; \
1899           if [ "$${oldsum}" == "$${newsum}" ]; then \
1900            echo "==> Keeping old ${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION_FROM}.${PKG_FORMAT}" ; \
1901            rm ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} ; \
1902            cp $${pkg} ${REPODIR}/${PKG_ABI}/${PKG_VERSION} ; \
1903           else \
1904             echo "==> New package $${newpkgname}" ; \
1905           fi ; \
1906         done
1907         ${_+_}@cd ${.CURDIR}; \
1908                 ${MAKE} -f Makefile.inc1 PKG_VERSION=${PKG_VERSION} sign-packages
1909
1910 stage-packages-world: .PHONY
1911         @mkdir -p ${WSTAGEDIR}
1912         ${_+_}@cd ${.CURDIR}; \
1913                 ${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT stageworld
1914
1915 stage-packages-kernel: .PHONY
1916         @mkdir -p ${KSTAGEDIR}
1917         ${_+_}@cd ${.CURDIR}; \
1918                 ${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT stagekernel
1919
1920 stage-packages: .PHONY stage-packages-world stage-packages-kernel
1921
1922 _repodir: .PHONY
1923         @mkdir -p ${REPODIR}
1924
1925 create-packages-world:  _pkgbootstrap _repodir .PHONY
1926         ${_+_}@cd ${.CURDIR}; \
1927                 ${MAKE} -f Makefile.inc1 \
1928                         DESTDIR=${WSTAGEDIR} \
1929                         PKG_VERSION=${PKG_VERSION} create-world-packages
1930
1931 create-packages-kernel: _pkgbootstrap _repodir .PHONY
1932         ${_+_}@cd ${.CURDIR}; \
1933                 ${MAKE} -f Makefile.inc1 \
1934                         DESTDIR=${KSTAGEDIR} \
1935                         PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1936                         SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1937                         create-kernel-packages
1938
1939 create-packages: .PHONY create-packages-world create-packages-kernel
1940
1941 create-world-packages:  _pkgbootstrap .PHONY
1942         @rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1943         @cd ${WSTAGEDIR} ; \
1944                 env -i LC_COLLATE=C sort ${WSTAGEDIR}/${DISTDIR}/METALOG | \
1945                 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk
1946         @for plist in ${WSTAGEDIR}/*.plist; do \
1947           plist=$${plist##*/} ; \
1948           pkgname=$${plist%.plist} ; \
1949           echo "_PKGS+= $${pkgname}" ; \
1950         done > ${WSTAGEDIR}/packages.mk
1951         ${_+_}@cd ${.CURDIR}; \
1952                 ${MAKE} -f Makefile.inc1 create-world-packages-jobs \
1953                 SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1954                 .MAKE.JOB.PREFIX=
1955
1956 .if make(create-world-packages-jobs)
1957 .include "${WSTAGEDIR}/packages.mk"
1958 .endif
1959
1960 create-world-packages-jobs: .PHONY
1961 .for pkgname in ${_PKGS}
1962 create-world-packages-jobs: create-world-package-${pkgname}
1963 create-world-package-${pkgname}: .PHONY
1964         @sh ${SRCDIR}/release/packages/generate-ucl.sh -o ${pkgname} \
1965                 -s ${SRCDIR} -u ${WSTAGEDIR}/${pkgname}.ucl
1966         @awk -F\" ' \
1967                 /^name/ { printf("===> Creating %s-", $$2); next } \
1968                 /^version/ { print $$2; next } \
1969                 ' ${WSTAGEDIR}/${pkgname}.ucl
1970         @if [ "${pkgname}" == "runtime" ]; then \
1971                 sed -i '' -e "s/%VCS_REVISION%/${VCS_REVISION}/" ${WSTAGEDIR}/${pkgname}.ucl ; \
1972         fi
1973         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1974                 create -f ${PKG_FORMAT} -M ${WSTAGEDIR}/${pkgname}.ucl \
1975                 -p ${WSTAGEDIR}/${pkgname}.plist \
1976                 -r ${WSTAGEDIR} \
1977                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1978 .endfor
1979
1980 _default_flavor=        -default
1981 .if make(*package*) && exists(${KSTAGEDIR}/kernel.meta)
1982 . if ${MK_DEBUG_FILES} != "no"
1983 _debug=-dbg
1984 . endif
1985 create-kernel-packages: .PHONY
1986 . for flavor in "" ${_debug}
1987 create-kernel-packages: create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}
1988 create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}: _pkgbootstrap .PHONY
1989         @cd ${KSTAGEDIR}/${DISTDIR} ; \
1990         env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.meta | \
1991         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1992                 -v kernel=yes -v _kernconf=${INSTALLKERNEL} ; \
1993         sed -e "s/%VERSION%/${PKG_VERSION}/" \
1994                 -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1995                 -e "s/%KERNELDIR%/kernel/" \
1996                 -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1997                 -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1998                 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
1999                 -e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
2000                 -e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
2001                 -e "s|%PKG_WWW%|${PKG_WWW}|" \
2002                 ${SRCDIR}/release/packages/kernel.ucl \
2003                 > ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
2004         awk -F\" ' \
2005                 /name/ { printf("===> Creating %s-", $$2); next } \
2006                 /version/ {print $$2; next } ' \
2007                 ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
2008         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
2009                 create -f ${PKG_FORMAT} \
2010                 -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
2011                 -p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
2012                 -r ${KSTAGEDIR}/${DISTDIR} \
2013                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
2014 . endfor
2015 .endif
2016 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
2017 . for _kernel in ${BUILDKERNELS:[2..-1]}
2018 .  if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
2019 .   if ${MK_DEBUG_FILES} != "no"
2020 _debug=-dbg
2021 .   endif
2022 .   for flavor in "" ${_debug}
2023 create-kernel-packages: create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}
2024 create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}: _pkgbootstrap .PHONY
2025         @cd ${KSTAGEDIR}/kernel.${_kernel} ; \
2026         env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.${_kernel}.meta | \
2027         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
2028                 -v kernel=yes -v _kernconf=${_kernel} ; \
2029         sed -e "s/%VERSION%/${PKG_VERSION}/" \
2030                 -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
2031                 -e "s/%KERNELDIR%/kernel.${_kernel}/" \
2032                 -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
2033                 -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
2034                 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
2035                 -e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
2036                 -e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
2037                 -e "s|%PKG_WWW%|${PKG_WWW}|" \
2038                 ${SRCDIR}/release/packages/kernel.ucl \
2039                 > ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2040         awk -F\" ' \
2041                 /name/ { printf("===> Creating %s-", $$2); next } \
2042                 /version/ {print $$2; next } ' \
2043                 ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2044         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
2045                 create -f ${PKG_FORMAT} \
2046                 -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
2047                 -p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
2048                 -r ${KSTAGEDIR}/kernel.${_kernel} \
2049                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
2050 .   endfor
2051 .  endif
2052 . endfor
2053 .endif
2054
2055 sign-packages:  _pkgbootstrap .PHONY
2056         printf "version = 2;\npacking_format = \"${PKG_FORMAT}\";\n" > ${WSTAGEDIR}/meta
2057         @[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest" ] && \
2058                 unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest ; \
2059         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname repo \
2060                 -m ${WSTAGEDIR}/meta \
2061                 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2062                 ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2063                 ${PKGSIGNKEY} ; \
2064         cd ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI); \
2065         ln -s ${PKG_OUTPUT_DIR} latest
2066
2067 #
2068 #
2069 # checkworld
2070 #
2071 # Run test suite on installed world.
2072 #
2073 checkworld: .PHONY
2074         @if [ ! -x "${LOCALBASE}/bin/kyua" ] && [ ! -x "/usr/bin/kyua" ]; then \
2075                 echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
2076                 exit 1; \
2077         fi
2078         ${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile
2079
2080 #
2081 #
2082 # doxygen
2083 #
2084 # Build the API documentation with doxygen
2085 #
2086 doxygen: .PHONY
2087         @if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \
2088                 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
2089                 exit 1; \
2090         fi
2091         ${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
2092
2093 #
2094 # update
2095 #
2096 # Update the source tree(s), by running svn/svnup to update to the
2097 # latest copy.
2098 #
2099 update: .PHONY
2100 .if defined(SVN_UPDATE)
2101         @echo "--------------------------------------------------------------"
2102         @echo ">>> Updating ${.CURDIR} using Subversion"
2103         @echo "--------------------------------------------------------------"
2104         @(cd ${.CURDIR}; ${SVN_CMD} update ${SVNFLAGS})
2105 .endif
2106
2107 #
2108 # ------------------------------------------------------------------------
2109 #
2110 # From here onwards are utility targets used by the 'make world' and
2111 # related targets.  If your 'world' breaks, you may like to try to fix
2112 # the problem and manually run the following targets to attempt to
2113 # complete the build.  Beware, this is *not* guaranteed to work, you
2114 # need to have a pretty good grip on the current state of the system
2115 # to attempt to manually finish it.  If in doubt, 'make world' again.
2116 #
2117
2118 #
2119 # legacy: Build compatibility shims for the next three targets. This is a
2120 # minimal set of tools and shims necessary to compensate for older systems
2121 # which don't have the APIs required by the targets built in bootstrap-tools,
2122 # build-tools or cross-tools.
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