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