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