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