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