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