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