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
25 # LOCAL_XTOOL_DIRS="list of dirs" to add additional dirs to the
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.
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)
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
49 .if !defined(TARGET) || !defined(TARGET_ARCH)
50 .error "Both TARGET and TARGET_ARCH must be defined."
53 .if make(showconfig) || make(test-system-*)
58 LOCALBASE?= /usr/local
60 # Cross toolchain changes must be in effect before bsd.compiler.mk
61 # so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
62 .if defined(CROSS_TOOLCHAIN)
63 .if exists(${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk)
64 .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
65 .elif exists(/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk)
66 .include "/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk"
67 .elif exists(${CROSS_TOOLCHAIN})
68 .include "${CROSS_TOOLCHAIN}"
70 .error CROSS_TOOLCHAIN ${CROSS_TOOLCHAIN} not found
72 CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
74 .if defined(CROSS_TOOLCHAIN_PREFIX)
75 CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
78 XCOMPILERS= CC CXX CPP
79 .for COMPILER in ${XCOMPILERS}
80 .if defined(CROSS_COMPILER_PREFIX)
81 X${COMPILER}?= ${CROSS_COMPILER_PREFIX}${${COMPILER}}
83 X${COMPILER}?= ${${COMPILER}}
86 # If a full path to an external cross compiler is given, don't build
88 .if ${XCC:N${CCACHE_BIN}:M/*}
89 MK_CLANG_BOOTSTRAP= no
93 # Pull in compiler metadata from buildworld/toolchain if possible to avoid
94 # running CC from bsd.compiler.mk.
95 .if make(installworld) || make(install) || make(distributeworld) || \
97 .-include "${OBJTOP}/toolchain-metadata.mk"
98 .if !defined(_LOADED_TOOLCHAIN_METADATA)
99 .error A build is required first. You may have the wrong MAKEOBJDIRPREFIX set.
103 # Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early. Pull it from the
104 # tree to be friendlier to foreign OS builds. It's safe to do so unconditionally
105 # here since we will always have the right make, unlike in src/Makefile
106 # Don't include bsd.linker.mk yet until XBINUTILS is handled (after src.opts.mk)
107 _NO_INCLUDE_LINKERMK= t
108 # We also want the X_COMPILER* variables if we are using an external toolchain.
109 _WANT_TOOLCHAIN_CROSS_VARS= t
110 .include "share/mk/bsd.compiler.mk"
111 .undef _NO_INCLUDE_LINKERMK
112 .undef _WANT_TOOLCHAIN_CROSS_VARS
113 # src.opts.mk depends on COMPILER_FEATURES
114 .include "share/mk/src.opts.mk"
116 .if ${TARGET} == ${MACHINE}
117 TARGET_CPUTYPE?=${CPUTYPE}
121 .if !empty(TARGET_CPUTYPE)
122 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
124 _TARGET_CPUTYPE=dummy
126 .if ${TARGET} == "arm"
127 .if ${TARGET_ARCH:Marmv[67]*} != "" && ${TARGET_CPUTYPE:M*soft*} == ""
128 TARGET_ABI= gnueabihf
133 MACHINE_ABI?= unknown
134 MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd13.0
136 TARGET_TRIPLE?= ${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd13.0
137 KNOWN_ARCHES?= aarch64/arm64 \
159 .if ${TARGET} == ${TARGET_ARCH}
162 _t= ${TARGET_ARCH}/${TARGET}
165 .if empty(KNOWN_ARCHES:M${_t})
166 .error Unknown target ${TARGET_ARCH}:${TARGET}.
170 # If all targets are disabled for system llvm then don't expect it to work
172 .if !defined(TOOLS_PREFIX) && ${MK_LLVM_TARGET_ALL} == "no" && \
173 ${MACHINE} != ${TARGET} && ${MACHINE_ARCH} != ${TARGET_ARCH} && \
175 MK_SYSTEM_COMPILER= no
179 # Handle external binutils.
180 .if defined(CROSS_TOOLCHAIN_PREFIX)
181 CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
183 # If we do not have a bootstrap binutils (because the in-tree one does not
184 # support the target architecture), provide a default cross-binutils prefix.
185 # This allows riscv64 builds, for example, to automatically use the
186 # riscv64-binutils port or package.
187 .if !make(showconfig) && !defined(_NO_INCLUDE_COMPILERMK)
188 .if !empty(BROKEN_OPTIONS:MBINUTILS_BOOTSTRAP) && \
189 ${MK_LLD_BOOTSTRAP} == "no" && \
190 !defined(CROSS_BINUTILS_PREFIX)
191 CROSS_BINUTILS_PREFIX=/usr/local/${TARGET_TRIPLE}/bin/
192 .if !exists(${CROSS_BINUTILS_PREFIX})
193 .if !empty(BROKEN_OPTIONS:MGCC_BOOTSTRAP) && ${MK_CLANG_BOOTSTRAP} == "no"
194 .error In-tree toolchain does not support the ${TARGET_ARCH} architecture. Install the ${TARGET_ARCH}-xtoolchain-gcc port or package or set CROSS_TOOLCHAIN_PREFIX.
196 .error In-tree binutils does not support the ${TARGET_ARCH} architecture. Install the ${TARGET_ARCH}-binutils port or package or set CROSS_BINUTILS_PREFIX.
201 XBINUTILS= AS AR LD NM OBJCOPY RANLIB SIZE STRINGS
202 .for BINUTIL in ${XBINUTILS}
203 .if defined(CROSS_BINUTILS_PREFIX) && \
204 exists(${CROSS_BINUTILS_PREFIX}/${${BINUTIL}})
205 X${BINUTIL}?= ${CROSS_BINUTILS_PREFIX:C,/*$,,}/${${BINUTIL}}
207 X${BINUTIL}?= ${${BINUTIL}}
211 # If a full path to an external linker is given, don't build lld.
216 # We also want the X_LINKER* variables if we are using an external toolchain.
217 _WANT_TOOLCHAIN_CROSS_VARS= t
218 .include "share/mk/bsd.linker.mk"
219 .undef _WANT_TOOLCHAIN_CROSS_VARS
221 # Begin WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
223 # WITH_SYSTEM_COMPILER - Pull in needed values and make a decision.
225 # Check if there is a local compiler that can satisfy as an external compiler.
226 # Which compiler is expected to be used?
227 .if ${MK_CLANG_BOOTSTRAP} == "yes"
228 WANT_COMPILER_TYPE= clang
229 .elif ${MK_GCC_BOOTSTRAP} == "yes"
230 WANT_COMPILER_TYPE= gcc
235 .if !defined(WANT_COMPILER_FREEBSD_VERSION) && !make(showconfig) && \
236 !make(test-system-linker)
237 .if ${WANT_COMPILER_TYPE} == "clang"
238 WANT_COMPILER_FREEBSD_VERSION_FILE= lib/clang/freebsd_cc_version.h
239 WANT_COMPILER_FREEBSD_VERSION!= \
240 awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \
241 ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown
242 WANT_COMPILER_VERSION_FILE= lib/clang/include/clang/Basic/Version.inc
243 WANT_COMPILER_VERSION!= \
244 awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
245 ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown
246 .elif ${WANT_COMPILER_TYPE} == "gcc"
247 WANT_COMPILER_FREEBSD_VERSION_FILE= gnu/usr.bin/cc/cc_tools/freebsd-native.h
248 WANT_COMPILER_FREEBSD_VERSION!= \
249 awk '$$2 == "FBSD_CC_VER" {printf("%d\n", $$3)}' \
250 ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown
251 WANT_COMPILER_VERSION_FILE= contrib/gcc/BASE-VER
252 WANT_COMPILER_VERSION!= \
253 awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3}' \
254 ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown
256 .export WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_VERSION
257 .endif # !defined(WANT_COMPILER_FREEBSD_VERSION)
259 # It needs to be the same revision as we would build for the bootstrap.
260 # If the expected vs CC is different then we can't skip.
261 # GCC cannot be used for cross-arch yet. For clang we pass -target later if
262 # TARGET_ARCH!=MACHINE_ARCH.
263 .if ${MK_SYSTEM_COMPILER} == "yes" && \
264 defined(WANT_COMPILER_FREEBSD_VERSION) && \
265 (${MK_CLANG_BOOTSTRAP} == "yes" || ${MK_GCC_BOOTSTRAP} == "yes") && \
267 ${X_COMPILER_TYPE} == ${WANT_COMPILER_TYPE} && \
268 (${X_COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH}) && \
269 ${X_COMPILER_VERSION} == ${WANT_COMPILER_VERSION} && \
270 ${X_COMPILER_FREEBSD_VERSION} == ${WANT_COMPILER_FREEBSD_VERSION}
271 # Everything matches, disable the bootstrap compiler.
272 MK_CLANG_BOOTSTRAP= no
274 USING_SYSTEM_COMPILER= yes
275 .endif # ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE}
277 # WITH_SYSTEM_LD - Pull in needed values and make a decision.
279 # Check if there is a local linker that can satisfy as an external linker.
280 # Which linker is expected to be used?
281 .if ${MK_LLD_BOOTSTRAP} == "yes"
282 WANT_LINKER_TYPE= lld
283 .elif ${MK_BINUTILS_BOOTSTRAP} == "yes"
284 # Note that there's no support for bfd in WITH_SYSTEM_LINKER.
285 WANT_LINKER_TYPE= bfd
290 .if !defined(WANT_LINKER_FREEBSD_VERSION) && !make(showconfig) && \
291 !make(test-system-compiler)
292 .if ${WANT_LINKER_TYPE} == "lld"
293 WANT_LINKER_FREEBSD_VERSION_FILE= lib/clang/include/VCSVersion.inc
294 WANT_LINKER_FREEBSD_VERSION!= \
295 awk '$$2 == "LLD_REVISION" {gsub(/"/, "", $$3); print $$3}' \
296 ${SRCDIR}/${WANT_LINKER_FREEBSD_VERSION_FILE} || echo unknown
297 WANT_LINKER_VERSION_FILE= lib/clang/include/lld/Common/Version.inc
298 WANT_LINKER_VERSION!= \
299 awk '$$2 == "LLD_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
300 ${SRCDIR}/${WANT_LINKER_VERSION_FILE} || echo unknown
302 WANT_LINKER_FREEBSD_VERSION_FILE=
303 WANT_LINKER_FREEBSD_VERSION=
305 .export WANT_LINKER_FREEBSD_VERSION WANT_LINKER_VERSION
306 .endif # !defined(WANT_LINKER_FREEBSD_VERSION)
308 .if ${MK_SYSTEM_LINKER} == "yes" && \
309 defined(WANT_LINKER_FREEBSD_VERSION) && \
310 (${MK_LLD_BOOTSTRAP} == "yes") && \
312 ${X_LINKER_TYPE} == ${WANT_LINKER_TYPE} && \
313 ${X_LINKER_VERSION} == ${WANT_LINKER_VERSION} && \
314 ${X_LINKER_FREEBSD_VERSION} == ${WANT_LINKER_FREEBSD_VERSION}
315 # Everything matches, disable the bootstrap linker.
317 USING_SYSTEM_LINKER= yes
318 .endif # ${WANT_LINKER_TYPE} == ${LINKER_TYPE}
320 # WITH_SYSTEM_COMPILER / WITH_SYSTEM_LINKER - Handle defaults and debug.
321 USING_SYSTEM_COMPILER?= no
322 USING_SYSTEM_LINKER?= no
324 TEST_SYSTEM_COMPILER_VARS= \
325 USING_SYSTEM_COMPILER MK_SYSTEM_COMPILER \
326 MK_CROSS_COMPILER MK_CLANG_BOOTSTRAP MK_GCC_BOOTSTRAP \
327 WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \
328 WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \
329 CC COMPILER_TYPE COMPILER_FEATURES COMPILER_VERSION \
330 COMPILER_FREEBSD_VERSION \
331 XCC X_COMPILER_TYPE X_COMPILER_FEATURES X_COMPILER_VERSION \
332 X_COMPILER_FREEBSD_VERSION
333 TEST_SYSTEM_LINKER_VARS= \
334 USING_SYSTEM_LINKER MK_SYSTEM_LINKER \
335 MK_LLD_BOOTSTRAP MK_BINUTILS_BOOTSTRAP \
336 WANT_LINKER_TYPE WANT_LINKER_VERSION WANT_LINKER_VERSION_FILE \
337 WANT_LINKER_FREEBSD_VERSION WANT_LINKER_FREEBSD_VERSION_FILE \
338 LD LINKER_TYPE LINKER_FEATURES LINKER_VERSION \
339 LINKER_FREEBSD_VERSION \
340 XLD X_LINKER_TYPE X_LINKER_FEATURES X_LINKER_VERSION \
341 X_LINKER_FREEBSD_VERSION
343 .for _t in compiler linker
344 test-system-${_t}: .PHONY
345 .for v in ${TEST_SYSTEM_${_t:tu}_VARS}
346 ${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}"
349 .if (make(buildworld) || make(buildkernel) || make(kernel-toolchain) || \
350 make(toolchain) || make(_cross-tools))
351 .if ${USING_SYSTEM_COMPILER} == "yes"
352 .info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree. Not bootstrapping a cross-compiler.
353 .elif ${MK_CLANG_BOOTSTRAP} == "yes"
354 .info SYSTEM_COMPILER: libclang will be built for bootstrapping a cross-compiler.
356 .if ${USING_SYSTEM_LINKER} == "yes"
357 .info SYSTEM_LINKER: Determined that LD=${LD} matches the source tree. Not bootstrapping a cross-linker.
358 .elif ${MK_LLD_BOOTSTRAP} == "yes"
359 .info SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.
363 # End WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
365 # Store some compiler metadata for use in installworld where we don't
366 # want to invoke CC at all.
367 _TOOLCHAIN_METADATA_VARS= COMPILER_VERSION \
370 COMPILER_FREEBSD_VERSION \
374 LINKER_FREEBSD_VERSION
375 toolchain-metadata.mk: .PHONY .META
377 @echo ".info Using cached toolchain metadata from build at $$(hostname) on $$(date)" \
379 @echo "_LOADED_TOOLCHAIN_METADATA=t" >> ${.TARGET}
380 .for v in ${_TOOLCHAIN_METADATA_VARS}
381 @echo "${v}=${${v}}" >> ${.TARGET}
382 @echo "X_${v}=${X_${v}}" >> ${.TARGET}
384 @echo ".export ${_TOOLCHAIN_METADATA_VARS}" >> ${.TARGET}
385 @echo ".export ${_TOOLCHAIN_METADATA_VARS:C,^,X_,}" >> ${.TARGET}
388 # We must do lib/ and libexec/ before bin/ in case of a mid-install error to
389 # keep the users system reasonably usable. For static->dynamic root upgrades,
390 # we don't want to install a dynamic binary without rtld and the needed
391 # libraries. More commonly, for dynamic root, we don't want to install a
392 # binary that requires a newer library version that hasn't been installed yet.
393 # This ordering is not a guarantee though. The only guarantee of a working
394 # system here would require fine-grained ordering of all components based
395 # on their dependencies.
396 .if !empty(SUBDIR_OVERRIDE)
397 SUBDIR= ${SUBDIR_OVERRIDE}
400 # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
401 # of a LOCAL_DIRS directory. This allows LOCAL_DIRS=foo and
402 # LOCAL_LIB_DIRS=foo/lib to behave as expected.
403 .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
404 _REDUNDANT_LIB_DIRS+= ${LOCAL_LIB_DIRS:M${_DIR}*}
406 .for _DIR in ${LOCAL_LIB_DIRS}
407 .if ${_DIR} == ".WAIT" || (empty(_REDUNDANT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
411 .if !defined(NO_ROOT) && (make(installworld) || make(install))
412 # Ensure libraries are installed before progressing.
416 .if ${MK_CDDL} != "no"
420 .if ${MK_KERBEROS} != "no"
423 .if ${MK_RESCUE} != "no"
427 .if ${MK_CRYPT} != "no"
430 .if !defined(NO_SHARE)
433 .if ${MK_BOOT} != "no"
436 SUBDIR+=sys usr.bin usr.sbin
437 .if ${MK_TESTS} != "no"
441 # Local directories are built in parallel with the base system directories.
442 # Users may insert a .WAIT directive at the beginning or elsewhere within
443 # the LOCAL_DIRS and LOCAL_LIB_DIRS lists as needed.
444 .for _DIR in ${LOCAL_DIRS}
445 .if ${_DIR} == ".WAIT" || exists(${.CURDIR}/${_DIR}/Makefile)
450 # We must do etc/ last as it hooks into building the man whatis file
451 # by calling 'makedb' in share/man. This is only relevant for
452 # install/distribute so they build the whatis file after every manpage is
454 .if make(installworld) || make(install)
459 .endif # !empty(SUBDIR_OVERRIDE)
462 .warning NOCLEAN option is deprecated. Use NO_CLEAN instead.
465 .if defined(NO_CLEANDIR)
466 CLEANDIR= clean cleandepend
471 .if defined(WORLDFAST)
476 .if ${MK_META_MODE} == "yes"
477 # If filemon is used then we can rely on the build being incremental-safe.
478 # The .meta files will also track the build command and rebuild should
480 .if empty(.MAKE.MODE:Mnofilemon)
484 .if defined(NO_OBJWALK) || ${MK_AUTO_OBJ} == "yes"
488 .if !defined(NO_OBJWALK)
493 PACKAGEDIR?= ${DESTDIR}/${DISTDIR}
495 .if empty(SHELL:M*csh*)
496 BUILDENV_SHELL?=${SHELL}
498 BUILDENV_SHELL?=/bin/sh
501 .if !defined(_MKSHOWCONFIG)
502 .if !defined(SVN_CMD) || empty(SVN_CMD)
503 . for _P in /usr/bin /usr/local/bin
504 . for _S in svn svnlite
505 . if exists(${_P}/${_S})
513 .if !defined(VCS_REVISION) || empty(VCS_REVISION)
514 .if !defined(SVNVERSION_CMD) || empty(SVNVERSION_CMD)
515 . for _D in ${PATH:S,:, ,g}
516 . if exists(${_D}/svnversion)
517 SVNVERSION_CMD?=${_D}/svnversion
519 . if exists(${_D}/svnliteversion)
520 SVNVERSION_CMD?=${_D}/svnliteversion
524 _VCS_REVISION?= $$(eval ${SVNVERSION_CMD} ${SRCDIR})
525 . if !empty(_VCS_REVISION)
526 VCS_REVISION= $$(echo r${_VCS_REVISION})
531 .if !defined(OSRELDATE)
532 .if exists(/usr/include/osreldate.h)
533 OSRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
534 /usr/include/osreldate.h
541 # Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
542 .if !defined(_REVISION)
543 _REVISION!= ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V REVISION
546 .if !defined(_BRANCH)
547 _BRANCH!= ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V BRANCH
550 .if !defined(SRCRELDATE)
551 SRCRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
552 ${SRCDIR}/sys/sys/param.h
555 .if !defined(VERSION)
556 VERSION= FreeBSD ${_REVISION}-${_BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
560 .if !defined(PKG_VERSION)
561 .if ${_BRANCH:MSTABLE*} || ${_BRANCH:MCURRENT*}
562 TIMENOW= %Y%m%d%H%M%S
563 EXTRA_REVISION= .s${TIMENOW:gmtime}
564 .elif ${_BRANCH:MALPHA*}
565 EXTRA_REVISION= _${_BRANCH:C/-ALPHA/.a/}
566 .elif ${_BRANCH:MBETA*}
567 EXTRA_REVISION= _${_BRANCH:C/-BETA/.b/}
568 .elif ${_BRANCH:MRC*}
569 EXTRA_REVISION= _${_BRANCH:C/-RC/.r/}
570 .elif ${_BRANCH:MPRERELEASE*}
571 EXTRA_REVISION= _${_BRANCH:C/-PRERELEASE/.p/}
572 .elif ${_BRANCH:M*-p*}
573 EXTRA_REVISION= _${_BRANCH:C/.*-p([0-9]+$)/\1/}
575 PKG_VERSION= ${_REVISION}${EXTRA_REVISION}
577 .endif # !defined(PKG_VERSION)
579 .if !defined(_MKSHOWCONFIG)
580 _CPUTYPE!= MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} -f /dev/null \
581 -m ${.CURDIR}/share/mk MK_AUTO_OBJ=no -V CPUTYPE
582 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
583 .error CPUTYPE global should be set with ?=.
587 BUILD_ARCH!= uname -p
588 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
589 .error To cross-build, set TARGET_ARCH.
592 WORLDTMP?= ${OBJTOP}/tmp
593 BPATH= ${CCACHE_WRAPPER_PATH_PFX}${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin
594 XPATH= ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
596 # When building we want to find the cross tools before the host tools in ${BPATH}.
597 # We also need to add UNIVERSE_TOOLCHAIN_PATH so that we can find the shared
598 # toolchain files (clang, lld, etc.) during make universe/tinderbox
599 STRICTTMPPATH= ${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
600 # We should not be using tools from /usr/bin accidentally since this could cause
601 # the build to break on other systems that don't have that tool. For now we
602 # still allow using the old behaviour (inheriting $PATH) if
603 # BUILD_WITH_STRICT_TMPPATH is set to 0 but this will eventually be removed.
605 # Currently strict $PATH can cause build failures and does not work yet with
606 # USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
607 # resolved it will be turned on by default.
608 BUILD_WITH_STRICT_TMPPATH?=0
609 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
610 TMPPATH= ${STRICTTMPPATH}
612 TMPPATH= ${STRICTTMPPATH}:${PATH}
616 # Avoid running mktemp(1) unless actually needed.
617 # It may not be functional, e.g., due to new ABI
618 # when in the middle of installing over this system.
620 .if make(distributeworld) || make(installworld) || make(stageworld)
621 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
622 MKTEMP=${WORLDTMP}/legacy/usr/bin/mktemp
623 .if !exists(${MKTEMP})
624 .error "mktemp binary doesn't exist in expected location: ${MKTEMP}"
629 INSTALLTMP!= ${MKTEMP} -d -u -t install
632 .if make(stagekernel) || make(distributekernel)
638 # Building a world goes through the following stages
640 # 1. legacy stage [BMAKE]
641 # This stage is responsible for creating compatibility
642 # shims that are needed by the bootstrap-tools,
643 # build-tools and cross-tools stages. These are generally
644 # APIs that tools from one of those three stages need to
645 # build that aren't present on the host.
646 # 1. bootstrap-tools stage [BMAKE]
647 # This stage is responsible for creating programs that
648 # are needed for backward compatibility reasons. They
649 # are not built as cross-tools.
650 # 2. build-tools stage [TMAKE]
651 # This stage is responsible for creating the object
652 # tree and building any tools that are needed during
653 # the build process. Some programs are listed during
654 # this phase because they build binaries to generate
655 # files needed to build these programs. This stage also
656 # builds the 'build-tools' target rather than 'all'.
657 # 3. cross-tools stage [XMAKE]
658 # This stage is responsible for creating any tools that
659 # are needed for building the system. A cross-compiler is one
660 # of them. This differs from build tools in two ways:
661 # 1. the 'all' target is built rather than 'build-tools'
662 # 2. these tools are installed into TMPPATH for stage 4.
663 # 4. world stage [WMAKE]
664 # This stage actually builds the world.
665 # 5. install stage (optional) [IMAKE]
666 # This stage installs a previously built world.
671 MINIMUM_SUPPORTED_OSREL?= 1002501
672 MINIMUM_SUPPORTED_REL?= 10.3
674 # Common environment for world related stages
676 MACHINE_ARCH=${TARGET_ARCH} \
678 CPUTYPE=${TARGET_CPUTYPE}
679 .if ${MK_META_MODE} != "no"
680 # Don't rebuild build-tools targets during normal build.
681 CROSSENV+= BUILD_TOOLS_META=.NOMETA
683 .if defined(TARGET_CFLAGS)
684 CROSSENV+= ${TARGET_CFLAGS}
686 .if (${TARGET} != ${MACHINE} && !defined(WITH_LOCAL_MODULES)) || \
687 defined(WITHOUT_LOCAL_MODULES)
688 CROSSENV+= LOCAL_MODULES=
691 BOOTSTRAPPING_OSRELDATE?=${OSRELDATE}
693 # bootstrap-tools stage
694 BMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \
695 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
696 PATH=${BPATH}:${PATH} \
697 WORLDTMP=${WORLDTMP} \
698 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
699 # need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
701 OBJTOP='${WORLDTMP}/obj-tools' \
702 OBJROOT='$${OBJTOP}/' \
704 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
705 BWPHASE=${.TARGET:C,^_,,} \
707 MK_HTML=no NO_LINT=yes MK_MAN=no \
708 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
709 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
710 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
711 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \
715 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
717 .if empty(.MAKEOVERRIDES:MMK_LLVM_TARGET_ALL)
718 BMAKE+= MK_LLVM_TARGET_ALL=no
723 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
724 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
726 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
727 BWPHASE=${.TARGET:C,^_,,} \
730 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
731 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
732 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no
735 # TOOLS_PREFIX set in BMAKE
737 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
738 MK_CLANG_IS_CC=${MK_CLANG_BOOTSTRAP} \
739 MK_GDB=no MK_TESTS=no
742 KTMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \
743 PATH=${BPATH}:${PATH} \
746 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
747 ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
749 OBJTOP='${WORLDTMP}/obj-kernel-tools' \
750 OBJROOT='$${OBJTOP}/' \
752 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
754 MK_HTML=no -DNO_LINT MK_MAN=no \
755 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
756 -DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WARNS=no MK_CTF=no
759 WMAKEENV= ${CROSSENV} \
760 INSTALL="sh ${.CURDIR}/tools/install.sh" \
765 HMAKE= PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
767 HMAKE+= PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
770 CROSSENV+= CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \
771 CPP="${XCPP} ${XCFLAGS}" \
772 AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \
773 NM=${XNM} OBJCOPY="${XOBJCOPY}" \
774 RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
777 .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
778 # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
779 # directory, but the compiler will look in the right place for its
780 # tools so we don't need to tell it where to look.
781 BFLAGS+= -B${CROSS_BINUTILS_PREFIX}
785 # The internal bootstrap compiler has a default sysroot set by TOOLS_PREFIX
786 # and target set by TARGET/TARGET_ARCH. However, there are several needs to
787 # always pass an explicit --sysroot and -target.
788 # - External compiler needs sysroot and target flags.
789 # - External ld needs sysroot.
790 # - To be clear about the use of a sysroot when using the internal compiler.
791 # - Easier debugging.
792 # - Allowing WITH_SYSTEM_COMPILER+WITH_META_MODE to work together due to
793 # the flip-flopping build command when sometimes using external and
794 # sometimes using internal.
795 # - Allow using lld which has no support for default paths.
796 .if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
797 BFLAGS+= -B${WORLDTMP}/usr/bin
799 .if ${WANT_COMPILER_TYPE} == gcc || \
800 (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
801 .elif ${WANT_COMPILER_TYPE} == clang || \
802 (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == clang)
803 XCFLAGS+= -target ${TARGET_TRIPLE}
805 XCFLAGS+= --sysroot=${WORLDTMP}
811 .if ${MK_LIB32} == "yes"
813 .include "Makefile.libcompat"
814 .elif ${MK_LIBSOFT} == "yes"
816 .include "Makefile.libcompat"
819 # META_MODE normally ignores host file changes since every build updates
820 # timestamps (see NO_META_IGNORE_HOST in sys.mk). There are known times
821 # when the ABI breaks though that we want to force rebuilding WORLDTMP
822 # to get updated host tools.
823 .if ${MK_META_MODE} == "yes" && defined(NO_CLEAN) && \
824 !defined(NO_META_IGNORE_HOST) && !defined(NO_META_IGNORE_HOST_HEADERS) && \
825 !defined(_MKSHOWCONFIG)
826 # r318736 - ino64 major ABI breakage
827 META_MODE_BAD_ABI_VERS+= 1200031
829 .if !defined(OBJDIR_HOST_OSRELDATE)
830 .if exists(${OBJTOP}/host-osreldate.h)
831 OBJDIR_HOST_OSRELDATE!= \
832 awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
833 ${OBJTOP}/host-osreldate.h
834 .elif exists(${WORLDTMP}/usr/include/osreldate.h)
835 OBJDIR_HOST_OSRELDATE= 0
837 .export OBJDIR_HOST_OSRELDATE
840 # Note that this logic is the opposite of normal BOOTSTRAP handling. We want
841 # to compare the WORLDTMP's OSRELDATE to the host's OSRELDATE. If the WORLDTMP
842 # is older than the ABI-breakage OSRELDATE of the HOST then we rebuild.
843 .if defined(OBJDIR_HOST_OSRELDATE)
844 .for _ver in ${META_MODE_BAD_ABI_VERS}
845 .if ${OSRELDATE} >= ${_ver} && ${OBJDIR_HOST_OSRELDATE} < ${_ver}
846 _meta_mode_need_rebuild= ${_ver}
849 .if defined(_meta_mode_need_rebuild)
850 .info META_MODE: Rebuilding host tools due to ABI breakage in __FreeBSD_version ${_meta_mode_need_rebuild}.
851 NO_META_IGNORE_HOST_HEADERS= 1
852 .export NO_META_IGNORE_HOST_HEADERS
853 .endif # defined(_meta_mode_need_rebuild)
854 .endif # defined(OBJDIR_HOST_OSRELDATE)
855 .endif # ${MK_META_MODE} == "yes" && defined(NO_CLEAN) ...
856 # This is only used for META_MODE+filemon to track what the oldest
857 # __FreeBSD_version is in WORLDTMP. This purposely does NOT have
858 # a make dependency on /usr/include/osreldate.h as the file should
859 # only be copied when it is missing or meta mode determines it has changed.
860 # Since host files are normally ignored without NO_META_IGNORE_HOST
861 # the file will never be updated unless that flag is specified. This
862 # allows tracking the oldest osreldate to force rebuilds via
863 # META_MODE_BADABI_REVS above.
864 host-osreldate.h: # DO NOT ADD /usr/include/osreldate.h here
865 @cp -f /usr/include/osreldate.h ${.TARGET}
867 WMAKE= ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
868 BWPHASE=${.TARGET:C,^_,,} \
871 IMAKEENV= ${CROSSENV}
872 IMAKE= ${IMAKEENV} ${MAKE} -f Makefile.inc1 \
873 ${IMAKE_INSTALL} ${IMAKE_MTREE}
874 .if empty(.MAKEFLAGS:M-n)
875 IMAKEENV+= PATH=${STRICTTMPPATH}:${INSTALLTMP} \
876 LD_LIBRARY_PATH=${INSTALLTMP} \
877 PATH_LOCALE=${INSTALLTMP}/locale
878 IMAKE+= __MAKE_SHELL=${INSTALLTMP}/sh
880 IMAKEENV+= PATH=${TMPPATH}:${INSTALLTMP}
883 # When generating install media, do not allow user and group information from
884 # the build host to affect the contents of the distribution.
885 .if make(distributeworld) || make(distrib-dirs) || make(distribution)
889 .if defined(DB_FROM_SRC)
890 INSTALLFLAGS+= -N ${.CURDIR}/etc
891 MTREEFLAGS+= -N ${.CURDIR}/etc
893 _INSTALL_DDIR= ${DESTDIR}/${DISTDIR}
894 INSTALL_DDIR= ${_INSTALL_DDIR:S://:/:g:C:/$::}
896 METALOG?= ${DESTDIR}/${DISTDIR}/METALOG
897 METALOG:= ${METALOG:C,//+,/,g}
898 IMAKE+= -DNO_ROOT METALOG=${METALOG}
899 INSTALLFLAGS+= -U -M ${METALOG} -D ${INSTALL_DDIR}
902 .if defined(BUILD_PKGS)
903 INSTALLFLAGS+= -h sha256
905 .if defined(DB_FROM_SRC) || defined(NO_ROOT)
906 IMAKE_INSTALL= INSTALL="install ${INSTALLFLAGS}"
907 IMAKE_MTREE= MTREE_CMD="mtree ${MTREEFLAGS}"
910 DESTDIR_MTREEFLAGS= -deU
911 # When creating worldtmp we don't need to set the directories as owned by root
913 WORLDTMP_MTREEFLAGS= -deUW
915 # When building with -DNO_ROOT we shouldn't be changing the directories
916 # that are created by mtree to be owned by root/wheel.
917 DESTDIR_MTREEFLAGS+= -W
920 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
921 MTREE= ${WORLDTMP}/legacy/usr/sbin/mtree
923 WORLDTMP_MTREE= ${MTREE} ${WORLDTMP_MTREEFLAGS}
924 DESTDIR_MTREE= ${MTREE} ${DESTDIR_MTREEFLAGS}
927 KMAKEENV= ${WMAKEENV:NSYSROOT=*}
928 KMAKE= ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
933 # Attempt to rebuild the entire system, with reasonable chance of
934 # success, regardless of how old your existing system is.
936 _sanity_check: .PHONY .MAKE
937 .if ${.CURDIR:C/[^,]//g} != ""
938 # The m4 build of sendmail files doesn't like it if ',' is used
939 # anywhere in the path of it's files.
941 @echo "*** Error: path to source tree contains a comma ','"
944 .elif ${.CURDIR:M*\:*} != ""
945 # Using ':' leaks into PATH and breaks finding cross-tools.
947 @echo "*** Error: path to source tree contains a colon ':'"
952 # Our current approach to dependency tracking cannot cope with certain source
953 # tree changes, particularly with respect to removing source files and
954 # replacing generated files. Handle these cases here in an ad-hoc fashion.
955 _cleanobj_fast_depend_hack: .PHONY
956 # Syscall stubs rewritten in C and obsolete MD assembly implementations
957 # Date SVN Rev Syscalls/Changes
958 # 20191009 r353340 removal of opensolaris_atomic.S (also r353381)
959 .if ${MACHINE} != i386
960 .for f in opensolaris_atomic
961 @if [ -e "${OBJTOP}/cddl/lib/libzpool/.depend.${f}.o" ] && \
962 egrep -qw 'opensolaris_atomic\.S' ${OBJTOP}/cddl/lib/libzpool/.depend.${f}.o; then \
963 echo "Removing stale dependencies for opensolaris_atomic"; \
964 rm -f ${OBJTOP}/cddl/lib/libzpool/.depend.${f}.* \
965 ${LIBCOMPAT:D${LIBCOMPAT_OBJTOP}/cddl/lib/libzpool/.depend.${f}.*}; \
969 # 20190925 r352689 removal of obsolete i386 memchr.S
971 @if [ -e "${OBJTOP}/lib/libc/.depend.${f}.o" ] && \
972 egrep -qw 'i386/string/memchr\.S' ${OBJTOP}/lib/libc/.depend.${f}.o; then \
973 echo "Removing stale dependencies for memchr"; \
974 rm -f ${OBJTOP}/lib/libc/.depend.${f}.*; \
976 .if defined(_LIBCOMPAT)
977 @if [ -e "${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.o" ] && \
978 egrep -qw 'i386/string/memchr\.S' ${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.o; then \
979 echo "Removing stale dependencies for memchr"; \
980 rm -f ${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.*; \
984 # 20180604 r334626 brk sbrk
985 # 20190916 r352703 shm_open
986 .for f in brk sbrk shm_open
987 @if [ -e "${OBJTOP}/lib/libc/.depend.${f}.o" ] && \
988 egrep -qw '${f}\.[sS]' ${OBJTOP}/lib/libc/.depend.${f}.o; then \
989 echo "Removing stale dependencies for ${f} syscall wrappers"; \
990 rm -f ${OBJTOP}/lib/libc/.depend.${f}.* \
991 ${_LIBCOMPAT:D${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.*}; \
994 # 20181013 r339348 bcopy reimplemented as .c
995 .for f in bcopy memcpy memmove
996 @if [ -e "${OBJTOP}/lib/libc/.depend.${f}.o" ] && \
997 egrep -qw 'bcopy\.[sS]' ${OBJTOP}/lib/libc/.depend.${f}.o; then \
998 echo "Removing stale dependencies for bcopy"; \
999 rm -f ${OBJTOP}/lib/libc/.depend.${f}.* \
1000 ${_LIBCOMPAT:D${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.*}; \
1003 # 20181115 r340463 bzero reimplemented as .c
1004 @if [ -e "${OBJTOP}/lib/libc/.depend.bzero.o" ] && \
1005 egrep -qw 'bzero\.[sS]' ${OBJTOP}/lib/libc/.depend.bzero.o; then \
1006 echo "Removing stale dependencies for bzero"; \
1007 rm -f ${OBJTOP}/lib/libc/.depend.bzero.* \
1008 ${_LIBCOMPAT:D${LIBCOMPAT_OBJTOP}/lib/libc/.depend.bzero.*}; \
1010 # 20181009 track migration from ntp's embedded libevent to updated one
1011 @if [ -e "${OBJTOP}/usr.sbin/ntp/libntpevent/.depend.bufferevent_openssl.o" ] && \
1012 egrep -q 'contrib/ntp/sntp/libevent/bufferevent_openssl.c' \
1013 ${OBJTOP}/usr.sbin/ntp/libntpevent/.depend.bufferevent_openssl.o ; then \
1014 echo "Removing stale libevent dependencies"; \
1015 rm -f ${OBJTOP}/usr.sbin/ntp/libntpevent/.depend.*; \
1018 # 20181209 r341759 track migration across wpa update
1019 @if [ -e "${OBJTOP}/usr.sbin/wpa/wpa_supplicant/.depend.rrm.o" ] && \
1020 egrep -q 'src/ap/rrm.c' \
1021 ${OBJTOP}/usr.sbin/wpa/wpa_supplicant/.depend.rrm.o; then \
1022 echo "Removing stale wpa dependencies"; \
1023 rm -f ${OBJTOP}/usr.sbin/wpa/*/.depend*; \
1028 @echo "--------------------------------------------------------------"
1029 @echo ">>> Rebuilding the temporary build tree"
1030 @echo "--------------------------------------------------------------"
1031 .if !defined(NO_CLEAN)
1034 # Note: for delete-old we need to set $PATH to also include the host $PATH
1035 # since otherwise a partial build with missing symlinks in ${WORLDTMP}/legacy/
1036 # will fail to run due to missing binaries. $WMAKE sets PATH to only ${TMPPATH}
1037 # so we remove that assingnment from $WMAKE and prepend the new $PATH
1038 ${_+_}@if [ -e "${WORLDTMP}" ]; then \
1039 echo ">>> Deleting stale files in build tree..."; \
1040 cd ${.CURDIR}; env PATH=${TMPPATH}:${PATH} ${WMAKE:NPATH=*} \
1041 _NO_INCLUDE_COMPILERMK=t -DBATCH_DELETE_OLD_FILES delete-old \
1042 delete-old-libs >/dev/null; \
1044 rm -rf ${WORLDTMP}/legacy/usr/include
1045 .if ${USING_SYSTEM_COMPILER} == "yes"
1047 if [ -x ${WORLDTMP}/usr/bin/${cc} ]; then \
1048 inum=$$(stat -f %i ${WORLDTMP}/usr/bin/${cc}); \
1049 find ${WORLDTMP}/usr/bin -inum $${inum} -delete; \
1052 .endif # ${USING_SYSTEM_COMPILER} == "yes"
1053 .if ${USING_SYSTEM_LINKER} == "yes"
1054 @rm -f ${WORLDTMP}/usr/bin/ld ${WORLDTMP}/usr/bin/ld.lld
1055 .endif # ${USING_SYSTEM_LINKER} == "yes"
1056 .endif # !defined(NO_CLEAN)
1057 @mkdir -p ${WORLDTMP}
1058 @touch ${WORLDTMP}/${.TARGET}
1059 # We can't use mtree to create the worldtmp directories since it may not be
1060 # available on the target system (this happens e.g. when building on non-FreeBSD)
1061 cd ${.CURDIR}/tools/build; \
1062 ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy installdirs
1063 # In order to build without inheriting $PATH we need to add symlinks to the host
1064 # tools in $WORLDTMP for the tools that we don't build during bootstrap-tools
1065 cd ${.CURDIR}/tools/build; \
1066 ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy host-symlinks
1070 @echo "--------------------------------------------------------------"
1071 @echo ">>> stage 1.1: legacy release compatibility shims"
1072 @echo "--------------------------------------------------------------"
1073 ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
1076 @echo "--------------------------------------------------------------"
1077 @echo ">>> stage 1.2: bootstrap tools"
1078 @echo "--------------------------------------------------------------"
1079 ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
1080 mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom
1081 ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1082 -p ${WORLDTMP}/usr >/dev/null
1083 ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1084 -p ${WORLDTMP}/usr/include >/dev/null
1085 ln -sf ${.CURDIR}/sys ${WORLDTMP}
1086 .if ${MK_DEBUG_FILES} != "no"
1087 ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1088 -p ${WORLDTMP}/usr/lib >/dev/null
1090 .for _mtree in ${LOCAL_MTREE}
1091 ${WORLDTMP_MTREE} -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
1094 .if !defined(NO_CLEAN)
1096 @echo "--------------------------------------------------------------"
1097 @echo ">>> stage 2.1: cleaning up the object tree"
1098 @echo "--------------------------------------------------------------"
1099 # Avoid including bsd.compiler.mk in clean and obj with _NO_INCLUDE_COMPILERMK
1100 # since the restricted $PATH might not contain a valid cc binary
1101 ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t ${CLEANDIR}
1102 .if defined(_LIBCOMPAT)
1103 ${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} _NO_INCLUDE_COMPILERMK=t -f Makefile.inc1 ${CLEANDIR}
1106 ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t _cleanobj_fast_depend_hack
1107 .endif # !defined(NO_CLEAN)
1110 @echo "--------------------------------------------------------------"
1111 @echo ">>> stage 2.2: rebuilding the object tree"
1112 @echo "--------------------------------------------------------------"
1113 ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t obj
1116 @echo "--------------------------------------------------------------"
1117 @echo ">>> stage 2.3: build tools"
1118 @echo "--------------------------------------------------------------"
1119 ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
1122 @echo "--------------------------------------------------------------"
1123 @echo ">>> stage 3: cross tools"
1124 @echo "--------------------------------------------------------------"
1125 @rm -f ${OBJTOP}/toolchain-metadata.mk
1126 ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
1127 ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
1130 @echo "--------------------------------------------------------------"
1131 @echo ">>> stage 3.1: recording build metadata"
1132 @echo "--------------------------------------------------------------"
1133 ${_+_}cd ${.CURDIR}; ${WMAKE} toolchain-metadata.mk
1134 ${_+_}cd ${.CURDIR}; ${WMAKE} host-osreldate.h
1137 @echo "--------------------------------------------------------------"
1138 @echo ">>> stage 4.1: building includes"
1139 @echo "--------------------------------------------------------------"
1140 # Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
1141 # headers from default SUBDIR. Do SUBDIR_OVERRIDE includes last.
1142 ${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
1143 MK_INCLUDES=yes includes
1144 .if !empty(SUBDIR_OVERRIDE) && make(buildworld)
1145 ${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
1149 @echo "--------------------------------------------------------------"
1150 @echo ">>> stage 4.2: building libraries"
1151 @echo "--------------------------------------------------------------"
1152 ${_+_}cd ${.CURDIR}; \
1153 ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
1154 MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
1157 @echo "--------------------------------------------------------------"
1158 @echo ">>> stage 4.4: building everything"
1159 @echo "--------------------------------------------------------------"
1160 ${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
1163 .if !defined(WORLDFAST)
1164 WMAKE_TGTS+= _sanity_check _worldtmp _legacy
1165 .if empty(SUBDIR_OVERRIDE)
1166 WMAKE_TGTS+= _bootstrap-tools
1168 WMAKE_TGTS+= _cleanobj
1169 .if !defined(NO_OBJWALK)
1172 WMAKE_TGTS+= _build-tools _cross-tools
1173 WMAKE_TGTS+= _build-metadata
1174 WMAKE_TGTS+= _includes
1176 .if !defined(NO_LIBS)
1177 WMAKE_TGTS+= _libraries
1179 .if defined(_LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
1180 WMAKE_TGTS+= build${libcompat}
1182 WMAKE_TGTS+= everything
1184 # record buildworld time in seconds
1185 .if make(buildworld)
1186 _BUILDWORLD_START!= date '+%s'
1187 .export _BUILDWORLD_START
1190 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY
1191 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
1193 buildworld_prologue: .PHONY
1194 @echo "--------------------------------------------------------------"
1195 @echo ">>> World build started on `LC_ALL=C date`"
1196 @echo "--------------------------------------------------------------"
1198 buildworld_epilogue: .PHONY
1200 @echo "--------------------------------------------------------------"
1201 @echo ">>> World build completed on `LC_ALL=C date`"
1202 @seconds=$$(($$(date '+%s') - ${_BUILDWORLD_START})); \
1203 echo -n ">>> World built in $$seconds seconds, "; \
1204 echo "ncpu: $$(sysctl -n hw.ncpu)${.MAKE.JOBS:S/^/, make -j/}"
1205 @echo "--------------------------------------------------------------"
1208 # We need to have this as a target because the indirection between Makefile
1209 # and Makefile.inc1 causes the correct PATH to be used, rather than a
1210 # modification of the current environment's PATH. In addition, we need
1211 # to quote multiword values.
1213 buildenvvars: .PHONY
1214 @echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
1216 .if ${.TARGETS:Mbuildenv}
1217 .if ${.MAKEFLAGS:M-j}
1218 .error The buildenv target is incompatible with -j
1221 BUILDENV_DIR?= ${.CURDIR}
1223 # Note: make will report any errors the shell reports. This can
1224 # be odd if the last command in an interactive shell generates an
1225 # error or is terminated by SIGINT. These reported errors look bad,
1226 # but are harmless. Allowing them also allows BUIDLENV_SHELL to
1227 # be a complex command whose status will be returned to the caller.
1228 # Some scripts in tools rely on this behavior to report build errors.
1231 @echo Entering world for ${TARGET_ARCH}:${TARGET}
1232 .if ${BUILDENV_SHELL:M*zsh*}
1233 @echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
1235 @cd ${BUILDENV_DIR} && env ${WMAKEENV} BUILDENV=1 ${BUILDENV_SHELL}
1237 TOOLCHAIN_TGTS= ${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
1238 toolchain: ${TOOLCHAIN_TGTS} .PHONY
1239 KERNEL_TOOLCHAIN_TGTS= ${TOOLCHAIN_TGTS:N_obj:N_cleanobj:N_includes:N_libraries}
1240 .if make(kernel-toolchain)
1241 .ORDER: ${KERNEL_TOOLCHAIN_TGTS}
1243 kernel-toolchain: ${KERNEL_TOOLCHAIN_TGTS} .PHONY
1248 # Checks to be sure system is ready for installworld/installkernel.
1250 installcheck: _installcheck_world _installcheck_kernel .PHONY
1251 _installcheck_world: .PHONY
1252 @echo "--------------------------------------------------------------"
1253 @echo ">>> Install check world"
1254 @echo "--------------------------------------------------------------"
1255 _installcheck_kernel: .PHONY
1256 @echo "--------------------------------------------------------------"
1257 @echo ">>> Install check kernel"
1258 @echo "--------------------------------------------------------------"
1261 # Require DESTDIR to be set if installing for a different architecture or
1262 # using the user/group database in the source tree.
1264 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
1265 defined(DB_FROM_SRC)
1266 .if !make(distributeworld)
1267 _installcheck_world: __installcheck_DESTDIR
1268 _installcheck_kernel: __installcheck_DESTDIR
1269 __installcheck_DESTDIR: .PHONY
1270 .if !defined(DESTDIR) || empty(DESTDIR)
1271 @echo "ERROR: Please set DESTDIR!"; \
1277 .if !defined(DB_FROM_SRC)
1279 # Check for missing UIDs/GIDs.
1281 CHECK_UIDS= auditdistd
1286 CHECK_GIDS+= proxy authpf
1289 CHECK_UIDS+= unbound
1290 CHECK_GIDS+= unbound
1291 _installcheck_world: __installcheck_UGID
1292 __installcheck_UGID: .PHONY
1293 .for uid in ${CHECK_UIDS}
1294 @if ! `id -u ${uid} >/dev/null 2>&1`; then \
1295 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
1299 .for gid in ${CHECK_GIDS}
1300 @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
1301 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
1307 # If installing over the running system (DESTDIR is / or unset) and the install
1308 # includes rescue, try running rescue from the objdir as a sanity check. If
1309 # rescue is not functional (e.g., because it depends on a system call not
1310 # supported by the currently running kernel), abort the installation.
1312 .if !make(distributeworld) && ${MK_RESCUE} != "no" && \
1313 (empty(DESTDIR) || ${DESTDIR} == "/") && empty(BYPASS_INSTALLCHECK_SH)
1314 _installcheck_world: __installcheck_sh_check
1315 __installcheck_sh_check: .PHONY
1316 @if [ "`${OBJTOP}/rescue/rescue/rescue sh -c 'echo OK'`" != \
1318 echo "rescue/sh check failed, installation aborted" >&2; \
1324 # Required install tools to be saved in a scratch dir for safety.
1326 .if ${MK_ZONEINFO} != "no"
1327 _zoneinfo= zic tzsetup
1330 ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \
1331 date echo egrep find grep id install ${_install-info} \
1332 ln make mkdir mtree mv pwd_mkdb \
1333 rm sed services_mkdb sh sort strip sysctl test true uname wc ${_zoneinfo} \
1336 # Needed for share/man
1337 .if ${MK_MAN_UTILS} != "no"
1344 # Distributes everything compiled by a `buildworld'.
1348 # Installs everything compiled by a 'buildworld'.
1351 # Non-base distributions produced by the base system
1352 EXTRA_DISTRIBUTIONS=
1353 .if defined(_LIBCOMPAT)
1354 EXTRA_DISTRIBUTIONS+= lib${libcompat}
1356 .if ${MK_TESTS} != "no"
1357 EXTRA_DISTRIBUTIONS+= tests
1360 DEBUG_DISTRIBUTIONS=
1361 .if ${MK_DEBUG_FILES} != "no"
1362 DEBUG_DISTRIBUTIONS+= base ${EXTRA_DISTRIBUTIONS:S,tests,,}
1365 MTREE_MAGIC?= mtree 2.0
1367 distributeworld installworld stageworld: _installcheck_world .PHONY
1368 mkdir -p ${INSTALLTMP}
1369 progs=$$(for prog in ${ITOOLS}; do \
1370 if progpath=`which $$prog`; then \
1373 echo "Required tool $$prog not found in PATH." >&2; \
1377 libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
1378 while read line; do \
1380 if [ "$$2 $$3" != "not found" ]; then \
1383 echo "Required library $$1 not found." >&2; \
1387 cp $$libs $$progs ${INSTALLTMP}
1388 cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
1389 .if defined(NO_ROOT)
1390 -mkdir -p ${METALOG:H}
1391 echo "#${MTREE_MAGIC}" > ${METALOG}
1393 .if make(distributeworld)
1394 .for dist in ${EXTRA_DISTRIBUTIONS}
1395 -mkdir ${DESTDIR}/${DISTDIR}/${dist}
1396 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1397 -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
1398 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1399 -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1400 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1401 -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
1402 .if ${MK_DEBUG_FILES} != "no"
1403 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1404 -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
1406 .if defined(_LIBCOMPAT)
1407 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1408 -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1409 .if ${MK_DEBUG_FILES} != "no"
1410 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1411 -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
1414 .if ${MK_TESTS} != "no" && ${dist} == "tests"
1415 -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
1416 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1417 -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
1418 .if ${MK_DEBUG_FILES} != "no"
1419 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1420 -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
1423 .if defined(NO_ROOT)
1424 ${IMAKEENV} ${MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
1425 sed -e 's#^\./#./${dist}/#' >> ${METALOG}
1426 ${IMAKEENV} ${MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
1427 sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1428 ${IMAKEENV} ${MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
1429 sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
1430 .if defined(_LIBCOMPAT)
1431 ${IMAKEENV} ${MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
1432 sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1436 -mkdir ${DESTDIR}/${DISTDIR}/base
1437 ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1438 METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
1439 DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
1440 LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
1441 ${INSTALL_SYMLINK} ${INSTALLFLAGS} usr/src/sys ${INSTALL_DDIR}/base/sys
1443 ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
1444 ${IMAKEENV} rm -rf ${INSTALLTMP}
1445 .if make(distributeworld)
1446 .for dist in ${EXTRA_DISTRIBUTIONS}
1447 find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete
1449 .if defined(NO_ROOT)
1450 .for dist in base ${EXTRA_DISTRIBUTIONS}
1451 @# For each file that exists in this dist, print the corresponding
1452 @# line from the METALOG. This relies on the fact that
1453 @# a line containing only the filename will sort immediately before
1454 @# the relevant mtree line.
1455 cd ${DESTDIR}/${DISTDIR}; \
1456 find ./${dist} | sort -u ${METALOG} - | \
1457 awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1458 ${DESTDIR}/${DISTDIR}/${dist}.meta
1460 .for dist in ${DEBUG_DISTRIBUTIONS}
1461 @# For each file that exists in this dist, print the corresponding
1462 @# line from the METALOG. This relies on the fact that
1463 @# a line containing only the filename will sort immediately before
1464 @# the relevant mtree line.
1465 cd ${DESTDIR}/${DISTDIR}; \
1466 find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
1467 awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1468 ${DESTDIR}/${DISTDIR}/${dist}.debug.meta
1473 packageworld: .PHONY
1474 .for dist in base ${EXTRA_DISTRIBUTIONS}
1475 .if defined(NO_ROOT)
1476 ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1477 tar cvf - --exclude usr/lib/debug \
1478 @${DESTDIR}/${DISTDIR}/${dist}.meta | \
1479 ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1481 ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1482 tar cvf - --exclude usr/lib/debug . | \
1483 ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1487 .for dist in ${DEBUG_DISTRIBUTIONS}
1488 . if defined(NO_ROOT)
1489 ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1490 tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
1491 ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1493 ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1494 tar cvLf - usr/lib/debug | \
1495 ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1500 ${_+_}cd ${.CURDIR}/tools/build/options; sh makeman > \
1501 ${.CURDIR}/share/man/man5/src.conf.5
1504 .include <src.lua.mk>
1507 _sysent_PATH= ${WORLDTMP}/legacy/usr/libexec:/usr/libexec:${PATH}
1508 _sysent_dirs= sys/kern
1509 _sysent_dirs+= sys/compat/freebsd32
1510 _sysent_dirs+= sys/compat/cloudabi32 \
1511 sys/compat/cloudabi64
1512 _sysent_dirs+= sys/amd64/linux \
1518 .for _dir in ${_sysent_dirs}
1519 @echo "${MAKE} -C ${.CURDIR}/${_dir} sysent"
1520 ${_+_}@env PATH=${_sysent_PATH} LUA=${LUA_CMD} \
1521 ${MAKE} -C ${.CURDIR}/${_dir} sysent
1527 # If you have a build server, you can NFS mount the source and obj directories
1528 # and do a 'make reinstall' on the *client* to install new binaries from the
1529 # most recent server build.
1531 restage reinstall: .MAKE .PHONY
1532 @echo "--------------------------------------------------------------"
1533 @echo ">>> Making hierarchy"
1534 @echo "--------------------------------------------------------------"
1535 ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1536 LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
1538 @echo "--------------------------------------------------------------"
1539 @echo ">>> Making distribution"
1540 @echo "--------------------------------------------------------------"
1541 ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1542 LOCAL_MTREE=${LOCAL_MTREE:Q} distribution
1545 @echo "--------------------------------------------------------------"
1546 @echo ">>> Installing everything started on `LC_ALL=C date`"
1547 @echo "--------------------------------------------------------------"
1548 ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
1549 .if defined(_LIBCOMPAT)
1550 ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
1552 @echo "--------------------------------------------------------------"
1553 @echo ">>> Installing everything completed on `LC_ALL=C date`"
1554 @echo "--------------------------------------------------------------"
1556 redistribute: .MAKE .PHONY
1557 @echo "--------------------------------------------------------------"
1558 @echo ">>> Distributing everything"
1559 @echo "--------------------------------------------------------------"
1560 ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1561 .if defined(_LIBCOMPAT)
1562 ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1563 DISTRIBUTION=lib${libcompat}
1566 distrib-dirs distribution: .MAKE .PHONY
1567 ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1568 ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1569 .if make(distribution)
1570 ${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1571 ${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1572 METALOG=${METALOG} MK_TESTS=no installconfig
1576 # buildkernel and installkernel
1578 # Which kernels to build and/or install is specified by setting
1579 # KERNCONF. If not defined a GENERIC kernel is built/installed.
1580 # Only the existing (depending TARGET) config files are used
1581 # for building kernels and only the first of these is designated
1582 # as the one being installed.
1584 # Note that we have to use TARGET instead of TARGET_ARCH when
1585 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
1586 # be set to cross-build, we have to make sure TARGET is set
1589 .if defined(KERNFAST)
1593 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1594 .if !defined(KERNCONF) && ${KERNFAST} != "1"
1595 KERNCONF=${KERNFAST}
1598 .if ${TARGET_ARCH} == "powerpc64"
1599 KERNCONF?= GENERIC64
1603 INSTKERNNAME?= kernel
1605 KERNSRCDIR?= ${.CURDIR}/sys
1606 KRNLCONFDIR= ${KERNSRCDIR}/${TARGET}/conf
1607 KRNLOBJDIR= ${OBJTOP}${KERNSRCDIR:C,^${.CURDIR},,}
1608 KERNCONFDIR?= ${KRNLCONFDIR}
1612 .if defined(NO_INSTALLKERNEL)
1613 # All of the BUILDKERNELS loops start at index 1.
1614 BUILDKERNELS+= dummy
1616 .for _kernel in ${KERNCONF}
1617 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${_kernel})
1618 BUILDKERNELS+= ${_kernel}
1619 .if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1620 INSTALLKERNEL= ${_kernel}
1623 .if make(buildkernel)
1624 .error Missing KERNCONF ${KERNCONFDIR}/${_kernel}
1629 _cleankernobj_fast_depend_hack: .PHONY
1630 # 20180320 remove stale generated assym.s after renaming to .inc in r331254
1631 @if [ -e "${OBJTOP}/sys/${KERNCONF}/assym.s" ]; then \
1632 echo "Removing stale generated assym files"; \
1633 rm -f ${OBJTOP}/sys/${KERNCONF}/assym.* \
1634 ${OBJTOP}/sys/${KERNCONF}/.depend.assym.*; \
1636 # 20191009 r353340 removal of opensolaris_atomic.S (also r353381)
1637 .if ${MACHINE} != i386
1638 .for f in opensolaris_atomic
1639 .for m in opensolaris zfs
1640 @if [ -e "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o" ] && \
1641 grep -q ${f}.S "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o"; then \
1642 echo "Removing stale dependencies for opensolaris_atomic"; \
1643 rm -f ${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.*; \
1649 ${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1651 # record kernel(s) build time in seconds
1652 .if make(buildkernel)
1653 _BUILDKERNEL_START!= date '+%s'
1659 # Builds all kernels defined by BUILDKERNELS.
1661 buildkernel: .MAKE .PHONY
1662 .if empty(BUILDKERNELS:Ndummy)
1663 @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1667 .for _kernel in ${BUILDKERNELS:Ndummy}
1668 @echo "--------------------------------------------------------------"
1669 @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1670 @echo "--------------------------------------------------------------"
1671 @echo "===> ${_kernel}"
1672 mkdir -p ${KRNLOBJDIR}
1673 .if !defined(NO_KERNELCONFIG)
1675 @echo "--------------------------------------------------------------"
1676 @echo ">>> stage 1: configuring the kernel"
1677 @echo "--------------------------------------------------------------"
1678 cd ${KRNLCONFDIR}; \
1680 config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1681 -I '${KERNCONFDIR}' -I '${KRNLCONFDIR}' \
1682 '${KERNCONFDIR}/${_kernel}'
1684 .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1686 @echo "--------------------------------------------------------------"
1687 @echo ">>> stage 2.1: cleaning up the object tree"
1688 @echo "--------------------------------------------------------------"
1689 ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1691 ${_+_}cd ${.CURDIR}; ${WMAKE} _cleankernobj_fast_depend_hack
1693 .if !defined(NO_KERNELOBJ)
1695 @echo "--------------------------------------------------------------"
1696 @echo ">>> stage 2.2: rebuilding the object tree"
1697 @echo "--------------------------------------------------------------"
1698 ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1701 @echo "--------------------------------------------------------------"
1702 @echo ">>> stage 2.3: build tools"
1703 @echo "--------------------------------------------------------------"
1704 ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1706 @echo "--------------------------------------------------------------"
1707 @echo ">>> stage 3.1: building everything"
1708 @echo "--------------------------------------------------------------"
1709 ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1710 @echo "--------------------------------------------------------------"
1711 @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1712 @echo "--------------------------------------------------------------"
1715 @seconds=$$(($$(date '+%s') - ${_BUILDKERNEL_START})); \
1716 echo -n ">>> Kernel(s) ${BUILDKERNELS} built in $$seconds seconds, "; \
1717 echo "ncpu: $$(sysctl -n hw.ncpu)${.MAKE.JOBS:S/^/, make -j/}"
1718 @echo "--------------------------------------------------------------"
1720 NO_INSTALLEXTRAKERNELS?= yes
1723 # installkernel, etc.
1725 # Install the kernel defined by INSTALLKERNEL
1727 installkernel installkernel.debug \
1728 reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1729 .if !defined(NO_INSTALLKERNEL)
1730 .if empty(INSTALLKERNEL)
1731 @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1734 @echo "--------------------------------------------------------------"
1735 @echo ">>> Installing kernel ${INSTALLKERNEL} on $$(LC_ALL=C date)"
1736 @echo "--------------------------------------------------------------"
1737 ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1738 ${CROSSENV} PATH=${TMPPATH} \
1739 ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1740 @echo "--------------------------------------------------------------"
1741 @echo ">>> Installing kernel ${INSTALLKERNEL} completed on $$(LC_ALL=C date)"
1742 @echo "--------------------------------------------------------------"
1744 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1745 .for _kernel in ${BUILDKERNELS:[2..-1]}
1746 @echo "--------------------------------------------------------------"
1747 @echo ">>> Installing kernel ${_kernel} $$(LC_ALL=C date)"
1748 @echo "--------------------------------------------------------------"
1749 ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1750 ${CROSSENV} PATH=${TMPPATH} \
1751 ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1752 @echo "--------------------------------------------------------------"
1753 @echo ">>> Installing kernel ${_kernel} completed on $$(LC_ALL=C date)"
1754 @echo "--------------------------------------------------------------"
1758 distributekernel distributekernel.debug: .PHONY
1759 .if !defined(NO_INSTALLKERNEL)
1760 .if empty(INSTALLKERNEL)
1761 @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1764 mkdir -p ${DESTDIR}/${DISTDIR}
1765 .if defined(NO_ROOT)
1766 @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1768 ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1769 ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1770 ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1771 DESTDIR=${INSTALL_DDIR}/kernel \
1772 ${.TARGET:S/distributekernel/install/}
1773 .if defined(NO_ROOT)
1774 @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1775 ${DESTDIR}/${DISTDIR}/kernel.meta
1778 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1779 .for _kernel in ${BUILDKERNELS:[2..-1]}
1780 .if defined(NO_ROOT)
1781 @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1783 ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1784 ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1785 ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1786 KERNEL=${INSTKERNNAME}.${_kernel} \
1787 DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1788 ${.TARGET:S/distributekernel/install/}
1789 .if defined(NO_ROOT)
1790 @sed -e "s|^./kernel.${_kernel}|.|" \
1791 ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1792 ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1797 packagekernel: .PHONY
1798 .if defined(NO_ROOT)
1799 .if !defined(NO_INSTALLKERNEL)
1800 cd ${DESTDIR}/${DISTDIR}/kernel; \
1801 tar cvf - --exclude '*.debug' \
1802 @${DESTDIR}/${DISTDIR}/kernel.meta | \
1803 ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1805 .if ${MK_DEBUG_FILES} != "no"
1806 cd ${DESTDIR}/${DISTDIR}/kernel; \
1807 tar cvf - --include '*/*/*.debug' \
1808 @${DESTDIR}/${DISTDIR}/kernel.meta | \
1809 ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1811 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1812 .for _kernel in ${BUILDKERNELS:[2..-1]}
1813 cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1814 tar cvf - --exclude '*.debug' \
1815 @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1816 ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1817 .if ${MK_DEBUG_FILES} != "no"
1818 cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1819 tar cvf - --include '*/*/*.debug' \
1820 @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1821 ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1826 .if !defined(NO_INSTALLKERNEL)
1827 cd ${DESTDIR}/${DISTDIR}/kernel; \
1828 tar cvf - --exclude '*.debug' . | \
1829 ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1831 .if ${MK_DEBUG_FILES} != "no"
1832 cd ${DESTDIR}/${DISTDIR}/kernel; \
1833 tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1834 ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1836 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1837 .for _kernel in ${BUILDKERNELS:[2..-1]}
1838 cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1839 tar cvf - --exclude '*.debug' . | \
1840 ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1841 .if ${MK_DEBUG_FILES} != "no"
1842 cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1843 tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1844 ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1851 ${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1853 PORTSDIR?= /usr/ports
1854 WSTAGEDIR?= ${OBJTOP}/worldstage
1855 KSTAGEDIR?= ${OBJTOP}/kernelstage
1856 REPODIR?= ${OBJROOT}repo
1857 PKGSIGNKEY?= # empty
1859 .ORDER: stage-packages create-packages
1860 .ORDER: create-packages create-world-packages
1861 .ORDER: create-packages create-kernel-packages
1862 .ORDER: create-packages sign-packages
1864 _pkgbootstrap: .PHONY
1865 .if make(*package*) && !exists(${LOCALBASE}/sbin/pkg)
1866 @env ASSUME_ALWAYS_YES=YES pkg bootstrap
1870 ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1873 rm -rf /tmp/ports.${TARGET} || :
1874 env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \
1875 PKG_CMD=${PKG_CMD} PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} \
1876 WSTAGEDIR=${WSTAGEDIR} \
1877 sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1879 real-packages: stage-packages create-packages sign-packages .PHONY
1881 stage-packages-world: .PHONY
1882 @mkdir -p ${WSTAGEDIR}
1883 ${_+_}@cd ${.CURDIR}; \
1884 ${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT stageworld
1886 stage-packages-kernel: .PHONY
1887 @mkdir -p ${KSTAGEDIR}
1888 ${_+_}@cd ${.CURDIR}; \
1889 ${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT stagekernel
1891 stage-packages: .PHONY stage-packages-world stage-packages-kernel
1894 @mkdir -p ${REPODIR}
1896 create-packages-world: _pkgbootstrap _repodir .PHONY
1897 ${_+_}@cd ${.CURDIR}; \
1898 ${MAKE} -f Makefile.inc1 \
1899 DESTDIR=${WSTAGEDIR} \
1900 PKG_VERSION=${PKG_VERSION} create-world-packages
1902 create-packages-kernel: _pkgbootstrap _repodir .PHONY
1903 ${_+_}@cd ${.CURDIR}; \
1904 ${MAKE} -f Makefile.inc1 \
1905 DESTDIR=${KSTAGEDIR} \
1906 PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1907 create-kernel-packages
1909 create-packages: .PHONY create-packages-world create-packages-kernel
1911 create-world-packages: _pkgbootstrap .PHONY
1912 @rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1913 @cd ${WSTAGEDIR} ; \
1914 env -i LC_COLLATE=C sort ${WSTAGEDIR}/${DISTDIR}/METALOG | \
1915 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk
1916 @for plist in ${WSTAGEDIR}/*.plist; do \
1917 plist=$${plist##*/} ; \
1918 pkgname=$${plist%.plist} ; \
1919 echo "_PKGS+= $${pkgname}" ; \
1920 done > ${WSTAGEDIR}/packages.mk
1921 ${_+_}@cd ${.CURDIR}; \
1922 ${MAKE} -f Makefile.inc1 create-world-packages-jobs \
1925 .if make(create-world-packages-jobs)
1926 .include "${WSTAGEDIR}/packages.mk"
1929 create-world-packages-jobs: .PHONY
1930 .for pkgname in ${_PKGS}
1931 create-world-packages-jobs: create-world-package-${pkgname}
1932 create-world-package-${pkgname}: .PHONY
1933 @sh ${SRCDIR}/release/packages/generate-ucl.sh -o ${pkgname} \
1934 -s ${SRCDIR} -u ${WSTAGEDIR}/${pkgname}.ucl
1936 /^name/ { printf("===> Creating %s-", $$2); next } \
1937 /^version/ { print $$2; next } \
1938 ' ${WSTAGEDIR}/${pkgname}.ucl
1939 @if [ "${pkgname}" == "runtime" ]; then \
1940 sed -i '' -e "s/%VCS_REVISION%/${VCS_REVISION}/" ${WSTAGEDIR}/${pkgname}.ucl ; \
1942 ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1943 create -M ${WSTAGEDIR}/${pkgname}.ucl \
1944 -p ${WSTAGEDIR}/${pkgname}.plist \
1946 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION}
1949 _default_flavor= -default
1950 .if make(*package*) && exists(${KSTAGEDIR}/kernel.meta)
1951 . if ${MK_DEBUG_FILES} != "no"
1954 create-kernel-packages: .PHONY
1955 . for flavor in "" ${_debug}
1956 create-kernel-packages: create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}
1957 create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}: _pkgbootstrap .PHONY
1958 @cd ${KSTAGEDIR}/${DISTDIR} ; \
1959 env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.meta | \
1960 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1961 -v kernel=yes -v _kernconf=${INSTALLKERNEL} ; \
1962 sed -e "s/%VERSION%/${PKG_VERSION}/" \
1963 -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1964 -e "s/%KERNELDIR%/kernel/" \
1965 -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1966 -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1967 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
1968 ${SRCDIR}/release/packages/kernel.ucl \
1969 > ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1971 /name/ { printf("===> Creating %s-", $$2); next } \
1972 /version/ {print $$2; next } ' \
1973 ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1974 ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1975 create -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
1976 -p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
1977 -r ${KSTAGEDIR}/${DISTDIR} \
1978 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION}
1981 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1982 . for _kernel in ${BUILDKERNELS:[2..-1]}
1983 . if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
1984 . if ${MK_DEBUG_FILES} != "no"
1987 . for flavor in "" ${_debug}
1988 create-kernel-packages: create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}
1989 create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}: _pkgbootstrap .PHONY
1990 @cd ${KSTAGEDIR}/kernel.${_kernel} ; \
1991 env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.${_kernel}.meta | \
1992 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1993 -v kernel=yes -v _kernconf=${_kernel} ; \
1994 sed -e "s/%VERSION%/${PKG_VERSION}/" \
1995 -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
1996 -e "s/%KERNELDIR%/kernel.${_kernel}/" \
1997 -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
1998 -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
1999 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
2000 ${SRCDIR}/release/packages/kernel.ucl \
2001 > ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2003 /name/ { printf("===> Creating %s-", $$2); next } \
2004 /version/ {print $$2; next } ' \
2005 ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2006 ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
2007 create -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
2008 -p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
2009 -r ${KSTAGEDIR}/kernel.${_kernel} \
2010 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION}
2016 sign-packages: _pkgbootstrap .PHONY
2017 @[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest" ] && \
2018 unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest ; \
2019 ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname repo \
2020 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2021 ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2023 cd ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI); \
2024 ln -s ${PKG_VERSION} latest
2030 # Run test suite on installed world.
2033 @if [ ! -x "${LOCALBASE}/bin/kyua" ]; then \
2034 echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
2037 ${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile
2043 # Build the API documentation with doxygen
2046 @if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \
2047 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
2050 ${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
2055 # Update the source tree(s), by running svn/svnup to update to the
2059 .if defined(SVN_UPDATE)
2060 @echo "--------------------------------------------------------------"
2061 @echo ">>> Updating ${.CURDIR} using Subversion"
2062 @echo "--------------------------------------------------------------"
2063 @(cd ${.CURDIR}; ${SVN_CMD} update ${SVNFLAGS})
2067 # ------------------------------------------------------------------------
2069 # From here onwards are utility targets used by the 'make world' and
2070 # related targets. If your 'world' breaks, you may like to try to fix
2071 # the problem and manually run the following targets to attempt to
2072 # complete the build. Beware, this is *not* guaranteed to work, you
2073 # need to have a pretty good grip on the current state of the system
2074 # to attempt to manually finish it. If in doubt, 'make world' again.
2078 # legacy: Build compatibility shims for the next three targets. This is a
2079 # minimal set of tools and shims necessary to compensate for older systems
2080 # which don't have the APIs required by the targets built in bootstrap-tools,
2081 # build-tools or cross-tools.
2085 # libnv and libl are both requirements for config(8), which is an unconditional
2087 _config_deps= lib/libnv usr.bin/lex/lib
2090 .if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0
2091 @echo "ERROR: Source upgrades from versions prior to ${MINIMUM_SUPPORTED_REL} are not supported."; \
2095 .for _tool in tools/build ${_config_deps}
2096 ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
2097 cd ${.CURDIR}/${_tool}; \
2098 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2099 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy includes; \
2100 ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no all; \
2101 ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no \
2102 DESTDIR=${WORLDTMP}/legacy install
2106 # bootstrap-tools: Build tools needed for compatibility. These are binaries that
2107 # are built to build other binaries in the system. However, the focus of these
2108 # binaries is usually quite narrow. Bootstrap tools use the host's compiler and
2109 # libraries, augmented by -legacy, in addition to the libraries built during
2112 _bt= _bootstrap-tools
2114 # We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
2115 # accidentally run tools that are incompatible but happen to be in $PATH.
2116 # This is especially important when building on Linux/MacOS where many of the
2117 # programs used during the build accept different flags or generate different
2118 # output. On those platforms we only symlink the tools known to be compatible
2119 # (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
2120 # from the FreeBSD sources during the bootstrap-tools stage.
2121 # We want to build without the user's $PATH starting in the bootstrap-tools
2122 # phase so the tools used in that phase (ln, cp, etc) must have already been
2123 # linked to $WORLDTMP. The tools are listed in the _host_tools_to_symlink
2124 # variable in tools/build/Makefile and are linked during the legacy phase.
2125 # Since they could be Linux or MacOS binaries, too we must only use flags that
2126 # are portable across operating systems.
2128 # If BOOTSTRAP_ALL_TOOLS is set we will build all the required tools from the
2129 # current source tree. Otherwise we create a symlink to the version found in
2130 # $PATH during the bootstrap-tools stage.
2131 .if defined(BOOTSTRAP_ALL_TOOLS)
2132 # BOOTSTRAPPING will be set on the command line so we can't override it here.
2133 # Instead set BOOTSTRAPPING_OSRELDATE so that the value 0 is set ${BSARGS}
2134 BOOTSTRAPPING_OSRELDATE:= 0
2137 .if ${MK_GAMES} != "no"
2138 _strfile= usr.bin/fortune/strfile
2141 .if ${MK_GCC} != "no" && ${MK_CXX} != "no"
2142 _gperf= gnu/usr.bin/gperf
2145 .if ${MK_VT} != "no"
2146 _vtfontcvt= usr.bin/vtfontcvt
2149 # If we are not building the bootstrap because BOOTSTRAPPING is sufficient
2150 # we symlink the host version to $WORLDTMP instead. By doing this we can also
2151 # detect when a bootstrap tool is being used without the required MK_FOO.
2152 # If you add a new bootstrap tool where we could also use the host version,
2153 # please ensure that you also add a .else case where you add the tool to the
2154 # _bootstrap_tools_links variable.
2155 .if ${BOOTSTRAPPING} < 1000033
2158 # Note: lex needs m4 to build but m4 also depends on lex. However, lex can be
2159 # bootstrapped so we build lex first.
2160 ${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc ${_bt}-${_lex}
2161 _bt_m4_depend=${_bt}-${_m4}
2162 _bt_lex_depend=${_bt}-${_lex} ${_bt_m4_depend}
2164 _bootstrap_tools_links+=m4 lex
2167 # ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
2168 # r296685 fix cross-endian objcopy
2169 # r310724 fixed PR 215350, a crash in libdwarf with objects built by GCC 6.2.
2170 # r334881 added libdwarf constants used by ctfconvert.
2171 # r338478 fixed a crash in objcopy for mips64el objects
2172 # r339083 libelf: correct mips64el test to use ELF header
2173 # r348347 Add missing powerpc64 relocation support to libdwarf
2174 .if ${BOOTSTRAPPING} < 1300030
2175 _elftoolchain_libs= lib/libelf lib/libdwarf lib/libzstd
2176 ${_bt}-lib/libelf: ${_bt_m4_depend}
2177 ${_bt}-lib/libdwarf: ${_bt_m4_depend}
2180 # flua is required to regenerate syscall files. It first appeared during the
2181 # 13.0-CURRENT cycle, thus needs to be built on -older releases and stable
2183 .if ${BOOTSTRAPPING} < 1300059
2187 # r245440 mtree -N support added
2188 # r313404 requires sha384.h for libnetbsd, added to libmd in r292782
2189 .if ${BOOTSTRAPPING} < 1100093
2190 _nmtree= lib/libmd \
2194 ${_bt}-lib/libnetbsd: ${_bt}-lib/libmd
2195 ${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
2197 _bootstrap_tools_links+=mtree
2200 # r246097: log addition login.conf.db, passwd, pwd.db, and spwd.db with cat -l
2201 .if ${BOOTSTRAPPING} < 1000027
2204 _bootstrap_tools_links+=cat
2207 # r277259 crunchide: Correct 64-bit section header offset
2208 # r281674 crunchide: always include both 32- and 64-bit ELF support
2209 .if ${BOOTSTRAPPING} < 1100078
2210 _crunchide= usr.sbin/crunch/crunchide
2212 _bootstrap_tools_links+=crunchide
2215 # r285986 crunchen: use STRIPBIN rather than STRIP
2216 # 1100113: Support MK_AUTO_OBJ
2217 # 1200006: META_MODE fixes
2218 .if ${BOOTSTRAPPING} < 1100078 || \
2219 (${MK_AUTO_OBJ} == "yes" && ${BOOTSTRAPPING} < 1100114) || \
2220 (${MK_META_MODE} == "yes" && ${BOOTSTRAPPING} < 1200006)
2221 _crunchgen= usr.sbin/crunch/crunchgen
2223 _bootstrap_tools_links+=crunchgen
2226 # r296926 -P keymap search path, MFC to stable/10 in r298297
2227 .if ${BOOTSTRAPPING} < 1003501 || \
2228 (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103)
2229 _kbdcontrol= usr.sbin/kbdcontrol
2231 _bootstrap_tools_links+=kbdcontrol
2237 ${_bt}-usr.bin/yacc: ${_bt}-lib/liby
2239 .if ${MK_BSNMP} != "no"
2240 _gensnmptree= usr.sbin/bsnmpd/gensnmptree
2243 .if ${MK_LOCALES} != "no"
2244 _localedef= usr.bin/localedef
2247 # We need to build tblgen when we're building clang or lld, either as
2248 # bootstrap tools, or as the part of the normal build.
2249 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" || \
2250 ${MK_LLD_BOOTSTRAP} != "no" || ${MK_LLD} != "no"
2252 lib/clang/libllvmminimal \
2253 usr.bin/clang/llvm-tblgen \
2254 usr.bin/clang/clang-tblgen \
2255 usr.bin/clang/lldb-tblgen
2256 # XXX: lldb-tblgen is not needed, if top-level MK_LLDB=no
2258 ${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmminimal
2259 ${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmminimal
2260 ${_bt}-usr.bin/clang/lldb-tblgen: ${_bt}-lib/clang/libllvmminimal
2263 # Build BSDL or GPL DTC depending on GPL_DTC option.
2265 .if ${MK_GPL_DTC} != "no"
2266 _dtc= gnu/usr.bin/dtc
2269 .if ${MK_LOCALES} != "no"
2270 _localedef= usr.bin/localedef
2273 .if ${MK_KERBEROS} != "no"
2274 _kerberos5_bootstrap_tools= \
2275 kerberos5/tools/make-roken \
2276 kerberos5/lib/libroken \
2277 kerberos5/lib/libvers \
2278 kerberos5/tools/asn1_compile \
2279 kerberos5/tools/slc \
2282 .ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
2283 .for _tool in ${_kerberos5_bootstrap_tools}
2284 ${_bt}-${_tool}: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
2288 ${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd
2290 # The tools listed in _basic_bootstrap_tools will generally not be
2291 # bootstrapped unless BOOTSTRAP_ALL_TOOL is set. However, when building on a
2292 # Linux or MacOS host the host versions are incompatible so we need to build
2293 # them from the source tree. Usually the link name will be the same as the subdir,
2294 # but some directories such as grep or test install multiple binaries. In that
2295 # case we use the _basic_bootstrap_tools_multilink variable which is a list of
2296 # subdirectory and comma-separated list of files.
2297 _basic_bootstrap_tools_multilink=usr.bin/grep grep,egrep,fgrep
2298 _basic_bootstrap_tools_multilink+=bin/test test,[
2299 # bootstrap tools needed by buildworld:
2300 _basic_bootstrap_tools=usr.bin/awk usr.bin/cut bin/expr usr.bin/gencat \
2301 usr.bin/join usr.bin/mktemp bin/rmdir usr.bin/sed usr.bin/sort \
2302 usr.bin/truncate usr.bin/tsort
2303 # elf2aout is required for sparc64 build
2304 _basic_bootstrap_tools+=usr.bin/elf2aout
2305 # file2c is required for building usr.sbin/config:
2306 _basic_bootstrap_tools+=usr.bin/file2c
2307 # uuencode/uudecode required for share/tabset
2308 _basic_bootstrap_tools+=usr.bin/uuencode usr.bin/uudecode
2309 # xargs is required by mkioctls
2310 _basic_bootstrap_tools+=usr.bin/xargs
2311 # cap_mkdb is required for share/termcap:
2312 _basic_bootstrap_tools+=usr.bin/cap_mkdb
2313 # ldd is required for installcheck (TODO: just always use /usr/bin/ldd instead?)
2314 _basic_bootstrap_tools+=usr.bin/ldd
2315 # services_mkdb/pwd_mkdb are required for installworld:
2316 _basic_bootstrap_tools+=usr.sbin/services_mkdb usr.sbin/pwd_mkdb
2317 # sysctl/chflags are required for installkernel:
2318 _basic_bootstrap_tools+=sbin/sysctl bin/chflags
2319 # mkfifo is used by sys/conf/newvers.sh
2320 _basic_bootstrap_tools+=usr.bin/mkfifo
2322 .if ${MK_AMD} != "no"
2323 # unifdef is only used by usr.sbin/amd/libamu/Makefile
2324 _basic_bootstrap_tools+=usr.bin/unifdef
2327 .if ${MK_BOOT} != "no"
2328 _basic_bootstrap_tools+=bin/dd
2329 # xz/unxz is used by EFI
2330 _basic_bootstrap_tools_multilink+=usr.bin/xz xz,unxz
2331 # md5 is used by boot/beri (and possibly others)
2332 _basic_bootstrap_tools+=sbin/md5
2333 .if defined(BOOTSTRAP_ALL_TOOLS)
2334 ${_bt}-sbin/md5: ${_bt}-lib/libmd
2338 .if ${MK_ZONEINFO} != "no"
2339 _basic_bootstrap_tools+=usr.sbin/zic usr.sbin/tzsetup
2342 .if defined(BOOTSTRAP_ALL_TOOLS)
2343 _other_bootstrap_tools+=${_basic_bootstrap_tools}
2344 .for _subdir _links in ${_basic_bootstrap_tools_multilink}
2345 _other_bootstrap_tools+=${_subdir}
2347 ${_bt}-usr.bin/awk: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2348 ${_bt}-bin/expr: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2349 # If we are bootstrapping file2c, we have to build it before config:
2350 ${_bt}-usr.sbin/config: ${_bt}-usr.bin/file2c ${_bt_lex_depend}
2351 # Note: no symlink to make/bmake in the !BOOTSTRAP_ALL_TOOLS case here since
2352 # the links to make/bmake make links will have already have been created in the
2353 # `make legacy` step. Not adding a link to make is important on non-FreeBSD
2354 # since "make" will usually point to GNU make there.
2355 _other_bootstrap_tools+=usr.bin/bmake
2357 # All tools in _basic_bootstrap_tools have the same name as the subdirectory
2358 # so we can use :T to get the name of the symlinks that we need to create.
2359 _bootstrap_tools_links+=${_basic_bootstrap_tools:T}
2360 .for _subdir _links in ${_basic_bootstrap_tools_multilink}
2361 _bootstrap_tools_links+=${_links:S/,/ /g}
2363 .endif # defined(BOOTSTRAP_ALL_TOOLS)
2365 # Link the tools that we need for building but don't need to bootstrap because
2366 # the host version is known to be compatible into ${WORLDTMP}/legacy
2367 # We do this before building any of the bootstrap tools in case they depend on
2368 # the presence of any of the links (e.g. as m4/lex/awk)
2369 ${_bt}-links: .PHONY
2371 .for _tool in ${_bootstrap_tools_links}
2372 ${_bt}-link-${_tool}: .PHONY .MAKE
2373 @if [ ! -e "${WORLDTMP}/legacy/bin/${_tool}" ]; then \
2374 source_path=`which ${_tool}`; \
2375 if [ ! -e "$${source_path}" ] ; then \
2376 echo "Cannot find host tool '${_tool}'"; false; \
2378 ln -sfnv "$${source_path}" "${WORLDTMP}/legacy/bin/${_tool}"; \
2380 ${_bt}-links: ${_bt}-link-${_tool}
2383 bootstrap-tools: ${_bt}-links .PHONY
2385 # Please document (add comment) why something is in 'bootstrap-tools'.
2386 # Try to bound the building of the bootstrap-tool to just the
2387 # FreeBSD versions that need the tool built at this stage of the build.
2390 ${_kerberos5_bootstrap_tools} \
2396 ${_elftoolchain_libs} \
2404 ${_other_bootstrap_tools} \
2414 ${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
2415 ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2416 cd ${.CURDIR}/${_tool}; \
2417 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2418 if [ "${_tool}" = "usr.bin/lex" ]; then \
2419 ${MAKE} DIRPRFX=${_tool}/ bootstrap; \
2421 ${MAKE} DIRPRFX=${_tool}/ all; \
2422 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy install
2424 bootstrap-tools: ${_bt}-${_tool}
2428 # build-tools: Build special purpose build tools
2430 .if !defined(NO_SHARE) && ${MK_SYSCONS} != "no"
2431 _share= share/syscons/scrnmaps
2434 .if ${MK_GCC} != "no"
2435 _gcc_tools= gnu/usr.bin/cc/cc_tools
2438 .if ${MK_RESCUE} != "no"
2439 # rescue includes programs that have build-tools targets
2440 _rescue=rescue/rescue
2443 .if ${MK_TCSH} != "no"
2446 .if ${MK_FILE} != "no"
2447 _libmagic=lib/libmagic
2450 .if ${MK_PMC} != "no" && \
2451 (${TARGET_ARCH} == "aarch64" || ${TARGET_ARCH} == "amd64" || \
2452 ${TARGET_ARCH} == "i386")
2453 _jevents=lib/libpmc/pmu-events
2456 # kernel-toolchain skips _cleanobj, so handle cleaning up previous
2457 # build-tools directories if needed.
2458 .if !defined(NO_CLEAN) && make(kernel-toolchain)
2459 _bt_clean= ${CLEANDIR}
2465 ${LOCAL_TOOL_DIRS} \
2467 lib/ncurses/ncurses \
2468 lib/ncurses/ncursesw \
2473 usr.bin/mkesdb_static \
2474 usr.bin/mkcsmapper_static \
2475 usr.bin/vi/catalog \
2477 build-tools_${_tool}: .PHONY
2478 ${_+_}@${ECHODIR} "===> ${_tool} (${_bt_clean:D${_bt_clean},}obj,build-tools)"; \
2479 cd ${.CURDIR}/${_tool}; \
2480 if [ -n "${_bt_clean}" ]; then ${MAKE} DIRPRFX=${_tool}/ ${_bt_clean}; fi; \
2481 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2482 ${MAKE} DIRPRFX=${_tool}/ build-tools
2483 build-tools: build-tools_${_tool}
2487 # kernel-tools: Build kernel-building tools
2489 kernel-tools: .PHONY
2490 mkdir -p ${WORLDTMP}/usr
2491 ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2492 -p ${WORLDTMP}/usr >/dev/null
2495 # cross-tools: All the tools needed to build the rest of the system after
2496 # we get done with the earlier stages. It is the last set of tools needed
2497 # to begin building the target binaries.
2499 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BUILD_WITH_STRICT_TMPPATH} != 0
2500 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
2501 _btxld= usr.sbin/btxld
2505 # Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
2506 # resulting from missing bug fixes or ELF Toolchain updates.
2507 .if ${MK_CDDL} != "no"
2508 _dtrace_tools= cddl/lib/libctf cddl/usr.bin/ctfconvert \
2509 cddl/usr.bin/ctfmerge
2512 # If we're given an XAS, don't build binutils.
2513 .if ${XAS:M/*} == ""
2514 .if ${MK_BINUTILS_BOOTSTRAP} != "no"
2515 _binutils= gnu/usr.bin/binutils
2517 .if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2518 _elftctools= lib/libelftc \
2524 # These are not required by the build, but can be useful for developers who
2525 # cross-build on a FreeBSD 10 host:
2526 _elftctools+= usr.bin/addr2line
2528 .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2529 # If cross-building with an external binutils we still need to build strip for
2530 # the target (for at least crunchide).
2531 _elftctools= lib/libelftc \
2536 .if ${MK_CLANG_BOOTSTRAP} != "no"
2537 _clang= usr.bin/clang
2539 .if ${MK_LLD_BOOTSTRAP} != "no"
2540 _lld= usr.bin/clang/lld
2542 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
2543 _clang_libs= lib/clang
2545 .if ${MK_GCC_BOOTSTRAP} != "no"
2546 _gcc= gnu/usr.bin/cc
2548 .if ${MK_USB} != "no"
2549 _usb_tools= stand/usb/tools
2552 .if ${BUILD_WITH_STRICT_TMPPATH} != 0 || defined(BOOTSTRAP_ALL_TOOLS)
2556 cross-tools: .MAKE .PHONY
2558 ${LOCAL_XTOOL_DIRS} \
2569 ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2570 cd ${.CURDIR}/${_tool}; \
2571 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2572 ${MAKE} DIRPRFX=${_tool}/ all; \
2573 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP} install
2577 # native-xtools is the current target for qemu-user cross builds of ports
2578 # via poudriere and the imgact_binmisc kernel module.
2579 # This target merely builds a toolchan/sysroot, then builds the tools it wants
2580 # with the options it wants in a special MAKEOBJDIRPREFIX, using the toolchain
2581 # already built. It then installs the static tools to NXBDESTDIR for Poudriere
2584 NXBOBJROOT= ${OBJROOT}${MACHINE}.${MACHINE_ARCH}/nxb/
2585 NXBOBJTOP= ${NXBOBJROOT}${NXB_TARGET}.${NXB_TARGET_ARCH}
2588 .error NXTP variable should be an absolute path
2590 NXBDESTDIR?= ${DESTDIR}${NXTP}
2592 # This is the list of tools to be built/installed as static and where
2593 # appropriate to build for the given TARGET.TARGET_ARCH.
2657 SUBDIR_DEPEND_usr.bin/clang= lib/clang
2658 .if ${MK_CLANG} != "no"
2660 NXBDIRS+= usr.bin/clang
2662 .if ${MK_GCC} != "no"
2663 NXBDIRS+= gnu/usr.bin/cc
2665 .if ${MK_BINUTILS} != "no"
2666 NXBDIRS+= gnu/usr.bin/binutils
2668 # XXX: native-xtools passes along ${NXBDIRS} in SUBDIR_OVERRIDE that needs
2669 # to be evaluated after NXBDIRS is set.
2670 .if make(install) && !empty(SUBDIR_OVERRIDE)
2671 SUBDIR= ${SUBDIR_OVERRIDE}
2675 OBJTOP=${NXBOBJTOP:Q} \
2676 OBJROOT=${NXBOBJROOT:Q} \
2683 MK_CLANG_EXTRAS=no \
2702 .if make(native-xtools*) && \
2703 (!defined(NXB_TARGET) || !defined(NXB_TARGET_ARCH))
2704 .error Missing NXB_TARGET / NXB_TARGET_ARCH
2706 # For 'toolchain' we want to produce native binaries that themselves generate
2708 NXBTMAKE= ${NXBMAKEENV} ${MAKE} ${NXBMAKEARGS:N-DNO_PIC:N-DNO_SHARED} \
2709 TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH}
2710 # For 'everything' we want to produce native binaries (hence -target to
2711 # be MACHINE) that themselves generate TARGET.TARGET_ARCH binaries.
2712 # TARGET/TARGET_ARCH are still passed along from user.
2714 # Use the toolchain we create as an external toolchain.
2715 .if ${USING_SYSTEM_COMPILER} == "yes" || ${XCC:N${CCACHE_BIN}:M/*}
2716 NXBMAKE+= XCC="${XCC}" \
2720 NXBMAKE+= XCC="${NXBOBJTOP}/tmp/usr/bin/cc" \
2721 XCXX="${NXBOBJTOP}/tmp/usr/bin/c++" \
2722 XCPP="${NXBOBJTOP}/tmp/usr/bin/cpp"
2724 NXBMAKE+= ${NXBMAKEENV} ${MAKE} -f Makefile.inc1 ${NXBMAKEARGS} \
2725 TARGET=${NXB_TARGET} TARGET_ARCH=${NXB_TARGET_ARCH} \
2726 TARGET_TRIPLE=${MACHINE_TRIPLE:Q}
2727 # NXBDIRS is improperly based on MACHINE rather than NXB_TARGET. Need to
2728 # invoke a sub-make to reevaluate MK_GCC, etc, for NXBDIRS.
2729 NXBMAKE+= SUBDIR_OVERRIDE='$${NXBDIRS:M*}'
2730 # Need to avoid the -isystem logic when using clang as an external toolchain
2731 # even if the TARGET being built for wants GCC.
2732 NXBMAKE+= WANT_COMPILER_TYPE='$${X_COMPILER_TYPE}'
2733 native-xtools: .PHONY
2734 ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _cleanobj MK_GCC=yes
2735 # Build the bootstrap/host/cross tools that produce native binaries
2736 # Pass along MK_GCC=yes to ensure GCC-needed build tools are built.
2737 # We don't quite know what the NXB_TARGET wants so just build it.
2738 ${_+_}cd ${.CURDIR}; ${NXBTMAKE} kernel-toolchain MK_GCC=yes
2739 # Populate includes/libraries sysroot that produce native binaries.
2740 # This is split out from 'toolchain' above mostly so that target LLVM
2741 # libraries have a proper LLVM_DEFAULT_TARGET_TRIPLE without
2742 # polluting the cross-compiler build. The LLVM/GCC libs are skipped
2743 # here to avoid the problem but are kept in 'toolchain' so that
2744 # needed build tools are built.
2745 ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _includes MK_CLANG=no MK_GCC=no
2746 ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _libraries MK_CLANG=no MK_GCC=no
2747 # Clean out improper TARGET=MACHINE files
2748 ${_+_}cd ${.CURDIR}/gnu/usr.bin/cc/cc_tools; ${NXBTMAKE} cleandir
2749 .if !defined(NO_OBJWALK)
2750 ${_+_}cd ${.CURDIR}; ${NXBMAKE} _obj
2752 ${_+_}cd ${.CURDIR}; ${NXBMAKE} everything
2753 @echo ">> native-xtools done. Use 'make native-xtools-install' to install to a given DESTDIR"
2755 native-xtools-install: .PHONY
2756 mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
2757 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2758 -p ${NXBDESTDIR}/usr >/dev/null
2759 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2760 -p ${NXBDESTDIR}/usr/include >/dev/null
2761 ${_+_}cd ${.CURDIR}; ${NXBMAKE} \
2762 DESTDIR=${NXBDESTDIR} \
2767 # hierarchy - ensure that all the needed directories are present
2769 hierarchy hier: .MAKE .PHONY
2770 ${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
2773 # libraries - build all libraries, and install them under ${DESTDIR}.
2775 # The list of libraries with dependents (${_prebuild_libs}) and their
2776 # interdependencies (__L) are built automatically by the
2777 # ${.CURDIR}/tools/make_libdeps.sh script.
2779 libraries: .MAKE .PHONY
2780 ${_+_}cd ${.CURDIR}; \
2781 ${MAKE} -f Makefile.inc1 _prereq_libs; \
2782 ${MAKE} -f Makefile.inc1 _startup_libs; \
2783 ${MAKE} -f Makefile.inc1 _prebuild_libs; \
2784 ${MAKE} -f Makefile.inc1 _generic_libs
2787 # static libgcc.a prerequisite for shared libc
2789 _prereq_libs= lib/libcompiler_rt
2790 .if ${MK_SSP} != "no"
2791 _prereq_libs+= lib/libssp_nonshared
2794 # These dependencies are not automatically generated:
2796 # gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
2797 # all shared libraries for ELF.
2799 _startup_libs= lib/csu
2800 .if ${MK_BSD_CRTBEGIN} == "no"
2801 _startup_libs+= gnu/lib/csu
2803 _startup_libs+= lib/libc
2804 _startup_libs+= lib/libc_nonshared
2805 .if ${MK_LIBCPLUSPLUS} != "no"
2806 _startup_libs+= lib/libcxxrt
2809 .if ${MK_LLVM_LIBUNWIND} != "no"
2810 _prereq_libs+= lib/libgcc_eh lib/libgcc_s
2811 _startup_libs+= lib/libgcc_eh lib/libgcc_s
2813 lib/libgcc_s__L: lib/libc__L
2814 lib/libgcc_s__L: lib/libc_nonshared__L
2815 .if ${MK_LIBCPLUSPLUS} != "no"
2816 lib/libcxxrt__L: lib/libgcc_s__L
2820 _prebuild_libs= ${_kerberos5_lib_libasn1} \
2821 ${_kerberos5_lib_libhdb} \
2822 ${_kerberos5_lib_libheimbase} \
2823 ${_kerberos5_lib_libheimntlm} \
2825 ${_kerberos5_lib_libheimipcc} \
2826 ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
2827 ${_kerberos5_lib_libroken} \
2828 ${_kerberos5_lib_libwind} \
2829 lib/libbz2 ${_libcom_err} lib/libcrypt \
2830 lib/libelf lib/libexpat \
2833 lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
2836 lib/ncurses/ncurses lib/ncurses/ncursesw \
2837 lib/libopie lib/libpam/libpam ${_lib_libthr} \
2838 ${_lib_libradius} lib/libsbuf lib/libtacplus \
2840 ${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
2841 ${_cddl_lib_libuutil} \
2842 ${_cddl_lib_libavl} \
2843 ${_cddl_lib_libzfs_core} ${_cddl_lib_libzfs} \
2844 ${_cddl_lib_libctf} \
2846 lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
2847 ${_secure_lib_libcrypto} ${_secure_lib_libssl} \
2848 ${_lib_libldns} ${_secure_lib_libssh}
2850 .if ${MK_GNUCXX} != "no"
2851 _prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
2852 gnu/lib/libstdc++__L: lib/msun__L
2853 gnu/lib/libsupc++__L: gnu/lib/libstdc++__L
2856 .if ${MK_DIALOG} != "no"
2857 _prebuild_libs+= gnu/lib/libdialog
2858 gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
2861 .if ${MK_LIBCPLUSPLUS} != "no"
2862 _prebuild_libs+= lib/libc++
2865 lib/libgeom__L: lib/libexpat__L
2866 lib/libkvm__L: lib/libelf__L
2868 .if ${MK_LIBTHR} != "no"
2869 _lib_libthr= lib/libthr
2872 .if ${MK_RADIUS_SUPPORT} != "no"
2873 _lib_libradius= lib/libradius
2876 .if ${MK_OFED} != "no"
2878 lib/ofed/libibverbs \
2880 lib/ofed/libibumad \
2884 lib/ofed/libibmad__L: lib/ofed/libibumad__L
2885 lib/ofed/complib__L: lib/libthr__L
2886 lib/ofed/libmlx5__L: lib/ofed/libibverbs__L lib/libthr__L
2889 .if ${MK_CASPER} != "no"
2890 _lib_casper= lib/libcasper
2893 lib/libpjdlog__L: lib/libutil__L
2894 lib/libcasper__L: lib/libnv__L
2895 lib/liblzma__L: lib/libthr__L
2896 lib/libzstd__L: lib/libthr__L
2898 _generic_libs= ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib
2899 .if ${MK_IPFILTER} != "no"
2900 _generic_libs+= sbin/ipf/libipf
2902 .for _DIR in ${LOCAL_LIB_DIRS}
2903 .if ${_DIR} == ".WAIT" || (empty(_generic_libs:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
2904 _generic_libs+= ${_DIR}
2908 lib/libopie__L lib/libtacplus__L: lib/libmd__L
2910 .if ${MK_CDDL} != "no"
2911 _cddl_lib_libumem= cddl/lib/libumem
2912 _cddl_lib_libnvpair= cddl/lib/libnvpair
2913 _cddl_lib_libavl= cddl/lib/libavl
2914 _cddl_lib_libuutil= cddl/lib/libuutil
2915 .if ${MK_ZFS} != "no"
2916 _cddl_lib_libzfs_core= cddl/lib/libzfs_core
2917 _cddl_lib_libzfs= cddl/lib/libzfs
2919 cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
2921 cddl/lib/libzfs__L: cddl/lib/libzfs_core__L lib/msun__L lib/libutil__L
2922 cddl/lib/libzfs__L: lib/libthr__L lib/libmd__L lib/libz__L cddl/lib/libumem__L
2923 cddl/lib/libzfs__L: cddl/lib/libuutil__L cddl/lib/libavl__L lib/libgeom__L
2925 lib/libbe__L: cddl/lib/libzfs__L
2927 _cddl_lib_libctf= cddl/lib/libctf
2929 cddl/lib/libctf__L: lib/libz__L
2931 # cddl/lib/libdtrace requires lib/libproc and lib/librtld_db; it's only built
2932 # on select architectures though (see cddl/lib/Makefile)
2933 .if ${MACHINE_CPUARCH} != "sparc64"
2934 _prebuild_libs+= lib/libprocstat lib/libproc lib/librtld_db
2935 lib/libprocstat__L: lib/libelf__L lib/libkvm__L lib/libutil__L
2936 lib/libproc__L: lib/libprocstat__L
2937 lib/librtld_db__L: lib/libprocstat__L
2940 .if ${MK_CRYPT} != "no"
2941 .if ${MK_OPENSSL} != "no"
2942 _secure_lib_libcrypto= secure/lib/libcrypto
2943 _secure_lib_libssl= secure/lib/libssl
2944 lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
2945 secure/lib/libcrypto__L: lib/libthr__L
2946 .if ${MK_LDNS} != "no"
2947 _lib_libldns= lib/libldns
2948 lib/libldns__L: secure/lib/libssl__L
2950 .if ${MK_OPENSSH} != "no"
2951 _secure_lib_libssh= secure/lib/libssh
2952 secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
2953 .if ${MK_LDNS} != "no"
2954 secure/lib/libssh__L: lib/libldns__L
2956 .if ${MK_GSSAPI} != "no" && ${MK_KERBEROS_SUPPORT} != "no"
2957 secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
2958 kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
2959 lib/libmd__L kerberos5/lib/libroken__L
2963 _secure_lib= secure/lib
2966 .if ${MK_KERBEROS} != "no"
2967 kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
2968 kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2969 kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
2970 kerberos5/lib/libwind__L lib/libsqlite3__L
2971 kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
2972 kerberos5/lib/libroken__L lib/libcom_err__L
2973 kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2974 secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
2975 kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2976 lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
2977 kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
2978 kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
2979 kerberos5/lib/libroken__L: lib/libcrypt__L
2980 kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
2981 kerberos5/lib/libheimbase__L: lib/libthr__L
2982 kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
2985 lib/libsqlite3__L: lib/libthr__L
2987 .if ${MK_GSSAPI} != "no"
2988 _lib_libgssapi= lib/libgssapi
2991 .if ${MK_KERBEROS} != "no"
2992 _kerberos5_lib= kerberos5/lib
2993 _kerberos5_lib_libasn1= kerberos5/lib/libasn1
2994 _kerberos5_lib_libhdb= kerberos5/lib/libhdb
2995 _kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
2996 _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
2997 _kerberos5_lib_libhx509= kerberos5/lib/libhx509
2998 _kerberos5_lib_libroken= kerberos5/lib/libroken
2999 _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
3000 _libsqlite3= lib/libsqlite3
3001 _kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
3002 _kerberos5_lib_libwind= kerberos5/lib/libwind
3003 _libcom_err= lib/libcom_err
3006 .if ${MK_NIS} != "no"
3007 _lib_libypclnt= lib/libypclnt
3010 .if ${MK_OPENSSL} == "no"
3011 lib/libradius__L: lib/libmd__L
3015 ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
3016 .if ${MK_CXX} != "no"
3017 .if ${MK_LIBCPLUSPLUS} != "no"
3018 lib/libproc__L: lib/libcxxrt__L
3019 .else # This implies MK_GNUCXX != "no"; see lib/libproc
3020 lib/libproc__L: gnu/lib/libsupc++__L
3024 .for _lib in ${_prereq_libs}
3025 ${_lib}__PL: .PHONY .MAKE
3026 .if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
3027 ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
3028 cd ${.CURDIR}/${_lib}; \
3029 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
3030 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
3031 DIRPRFX=${_lib}/ all; \
3032 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
3033 DIRPRFX=${_lib}/ install
3037 .for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
3038 ${_lib}__L: .PHONY .MAKE
3039 .if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
3040 ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
3041 cd ${.CURDIR}/${_lib}; \
3042 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
3043 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
3044 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
3048 _prereq_libs: ${_prereq_libs:S/$/__PL/}
3049 _startup_libs: ${_startup_libs:S/$/__L/}
3050 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
3051 _generic_libs: ${_generic_libs:S/$/__L/}
3053 # Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
3054 # 'everything' with _PARALLEL_SUBDIR_OK set. This is because it is unlikely
3055 # that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
3056 # or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
3057 # parallel. This is safe for the world stage of buildworld though since it has
3058 # already built libraries in a proper order and installed includes into
3059 # WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
3060 # avoid trashing a system if it crashes mid-install.
3061 .if !make(all) || defined(_PARALLEL_SUBDIR_OK)
3065 .include <bsd.subdir.mk>
3067 .if make(check-old) || make(check-old-dirs) || \
3068 make(check-old-files) || make(check-old-libs) || \
3069 make(delete-old) || make(delete-old-dirs) || \
3070 make(delete-old-files) || make(delete-old-libs)
3073 # check for / delete old files section
3076 .include "ObsoleteFiles.inc"
3078 OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
3079 else you can not start such an application. Consult UPDATING for more \
3080 information regarding how to cope with the removal/revision bump of a \
3083 .if !defined(BATCH_DELETE_OLD_FILES)
3089 delete-old-files: .PHONY
3090 @echo ">>> Removing old files (only deletes safe to delete libs)"
3091 # Ask for every old file if the user really wants to remove it.
3092 # It's annoying, but better safe than sorry.
3093 # NB: We cannot pass the list of OLD_FILES as a parameter because the
3094 # argument list will get too long. Using .for/.endfor make "loops" will make
3095 # the Makefile parser segfault.
3098 ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3099 -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | sort | \
3100 while read file; do \
3101 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3102 chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3103 rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3105 for ext in debug symbols; do \
3106 if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3107 "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3108 rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3113 # Remove catpages without corresponding manpages.
3115 find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | sort | \
3116 sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3117 while read catpage; do \
3119 if [ ! -e "$${manpage}" ]; then \
3120 rm ${RM_I} $${catpage} <&3; \
3123 @echo ">>> Old files removed"
3125 check-old-files: .PHONY
3126 @echo ">>> Checking for old files"
3128 ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3129 -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
3130 while read file; do \
3131 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3132 echo "${DESTDIR}/$${file}"; \
3134 for ext in debug symbols; do \
3135 if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3136 echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3140 # Check for catpages without corresponding manpages.
3141 @find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | \
3142 sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3143 while read catpage; do \
3145 if [ ! -e "$${manpage}" ]; then \
3150 delete-old-libs: .PHONY
3151 @echo ">>> Removing old libraries"
3152 @echo "${OLD_LIBS_MESSAGE}" | fmt
3155 ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3156 -V OLD_LIBS | xargs -n1 | sort | \
3157 while read file; do \
3158 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3159 chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3160 rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3162 for ext in debug symbols; do \
3163 if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3164 "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3165 rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3170 @echo ">>> Old libraries removed"
3172 check-old-libs: .PHONY
3173 @echo ">>> Checking for old libraries"
3175 ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3176 -V OLD_LIBS | xargs -n1 | \
3177 while read file; do \
3178 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3179 echo "${DESTDIR}/$${file}"; \
3181 for ext in debug symbols; do \
3182 if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3183 echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3188 delete-old-dirs: .PHONY
3189 @echo ">>> Removing old directories"
3191 ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3192 -V OLD_DIRS | xargs -n1 | sort -r | \
3193 while read dir; do \
3194 if [ -d "${DESTDIR}/$${dir}" ]; then \
3195 rmdir -v "${DESTDIR}/$${dir}" || true; \
3196 elif [ -L "${DESTDIR}/$${dir}" ]; then \
3197 echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3199 if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3200 rmdir -v "${DESTDIR}${DEBUGDIR}/$${dir}" || true; \
3201 elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3202 echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3205 @echo ">>> Old directories removed"
3207 check-old-dirs: .PHONY
3208 @echo ">>> Checking for old directories"
3210 ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3211 -V OLD_DIRS | xargs -n1 | sort -r | \
3212 while read dir; do \
3213 if [ -d "${DESTDIR}/$${dir}" ]; then \
3214 echo "${DESTDIR}/$${dir}"; \
3215 elif [ -L "${DESTDIR}/$${dir}" ]; then \
3216 echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3218 if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3219 echo "${DESTDIR}${DEBUGDIR}/$${dir}"; \
3220 elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3221 echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3225 delete-old: delete-old-files delete-old-dirs .PHONY
3226 @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3228 check-old: check-old-files check-old-libs check-old-dirs .PHONY
3229 @echo "To remove old files and directories run '${MAKE_CMD} delete-old'."
3230 @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3235 # showconfig - show build configuration.
3238 @(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes; \
3239 ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes) 2>&1 | grep ^MK_ | sort -u
3241 .if !empty(KRNLOBJDIR) && !empty(KERNCONF)
3242 DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
3244 .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
3245 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${KERNCONF})
3246 FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
3247 '${KERNCONFDIR}/${KERNCONF}' ; echo
3253 .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
3254 DTBOUTPUTPATH= ${.CURDIR}
3258 # Build 'standalone' Device Tree Blob
3261 @PATH=${TMPPATH} MACHINE=${TARGET} \
3262 ${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
3263 "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
3268 # In the following, the first 'rm' in a series will usually remove all
3269 # files and directories. If it does not, then there are probably some
3270 # files with file flags set, so this unsets them and tries the 'rm' a
3271 # second time. There are situations where this target will be cleaning
3272 # some directories via more than one method, but that duplication is
3273 # needed to correctly handle all the possible situations. Removing all
3274 # files without file flags set in the first 'rm' instance saves time,
3275 # because 'chflags' will need to operate on fewer files afterwards.
3277 # It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
3278 # created by bsd.obj.mk, except that we don't want to .include that file
3279 # in this makefile. We don't do a cleandir walk if MK_AUTO_OBJ is yes
3280 # since it is not possible for files to land in the wrong place.
3282 .if make(cleanworld)
3283 BW_CANONICALOBJDIR:=${OBJTOP}/
3284 .elif make(cleanuniverse)
3285 BW_CANONICALOBJDIR:=${OBJROOT}
3286 .if ${MK_UNIFIED_OBJDIR} == "no"
3287 .error ${.TARGETS} only supported with WITH_UNIFIED_OBJDIR enabled.
3290 cleanworld cleanuniverse: .PHONY
3291 .if !empty(BW_CANONICALOBJDIR) && exists(${BW_CANONICALOBJDIR}) && \
3292 ${.CURDIR:tA} != ${BW_CANONICALOBJDIR:tA}
3293 -rm -rf ${BW_CANONICALOBJDIR}*
3294 -chflags -R 0 ${BW_CANONICALOBJDIR}
3295 rm -rf ${BW_CANONICALOBJDIR}*
3297 .if make(cleanworld) && ${MK_AUTO_OBJ} == "no" && \
3298 (empty(BW_CANONICALOBJDIR) || ${.CURDIR:tA} == ${BW_CANONICALOBJDIR:tA})
3299 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
3300 # To be safe in this case, fall back to a 'make cleandir'
3301 ${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
3305 .if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
3306 XDEV_CPUTYPE?=${CPUTYPE}
3308 XDEV_CPUTYPE?=${TARGET_CPUTYPE}
3311 NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
3312 MK_MAN=no MK_NLS=no MK_PROFILE=no \
3313 MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
3314 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
3315 CPUTYPE=${XDEV_CPUTYPE}
3317 XDDIR=${TARGET_ARCH}-freebsd
3320 .error XDTP variable should be an absolute path
3323 CDBOBJROOT= ${OBJROOT}${MACHINE}.${MACHINE_ARCH}/xdev/
3324 CDBOBJTOP= ${CDBOBJROOT}${XDDIR}
3326 INSTALL="sh ${.CURDIR}/tools/install.sh"
3328 TOOLS_PREFIX=${XDTP}
3330 OBJTOP=${CDBOBJTOP:Q} \
3331 OBJROOT=${CDBOBJROOT:Q}
3332 CD2MAKEARGS= ${CDMAKEARGS}
3334 .if ${WANT_COMPILER_TYPE} == gcc || \
3335 (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
3336 # GCC requires -isystem and -L when using a cross-compiler. --sysroot
3337 # won't set header path and -L is used to ensure the base library path
3338 # is added before the port PREFIX library path.
3339 CD2CFLAGS+= -isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib
3340 # GCC requires -B to find /usr/lib/crti.o when using a cross-compiler
3341 # combined with --sysroot.
3342 CD2CFLAGS+= -B${XDDESTDIR}/usr/lib
3343 # Force using libc++ for external GCC.
3344 .if defined(X_COMPILER_TYPE) && \
3345 ${X_COMPILER_TYPE} == gcc && ${X_COMPILER_VERSION} >= 40800
3346 CD2CXXFLAGS+= -isystem ${XDDESTDIR}/usr/include/c++/v1 -std=c++11 \
3350 CD2CFLAGS+= --sysroot=${XDDESTDIR}/
3351 CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CXXFLAGS} ${CD2CFLAGS}" \
3352 CPP="${CPP} ${CD2CFLAGS}" \
3353 MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
3355 CDTMP= ${OBJTOP}/${XDDIR}/tmp
3356 CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${CDMAKEARGS} ${NOFUN}
3357 CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} \
3358 ${MAKE} ${CD2MAKEARGS} ${NOFUN}
3359 .if ${MK_META_MODE} != "no"
3360 # Don't rebuild build-tools targets during normal build.
3361 CD2MAKE+= BUILD_TOOLS_META=.NOMETA
3363 XDDESTDIR=${DESTDIR}${XDTP}
3365 .ORDER: xdev-build xdev-install xdev-links
3366 xdev: xdev-build xdev-install .PHONY
3368 .ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
3369 xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY
3371 _xb-worldtmp: .PHONY
3372 mkdir -p ${CDTMP}/usr
3373 ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3374 -p ${CDTMP}/usr >/dev/null
3376 _xb-bootstrap-tools: .PHONY
3381 ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
3382 cd ${.CURDIR}/${_tool}; \
3383 if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3384 ${CDMAKE} DIRPRFX=${_tool}/ all; \
3385 ${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
3388 _xb-build-tools: .PHONY
3389 ${_+_}@cd ${.CURDIR}; \
3390 ${CDBENV} ${MAKE} ${CDMAKEARGS} -f Makefile.inc1 ${NOFUN} build-tools
3401 _xb-cross-tools: .PHONY
3402 .for _tool in ${XDEVDIRS}
3403 ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \
3404 cd ${.CURDIR}/${_tool}; \
3405 if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3406 ${CDMAKE} DIRPRFX=${_tool}/ all
3410 ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
3411 mkdir -p ${XDDESTDIR}
3412 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
3413 -p ${XDDESTDIR} >/dev/null
3414 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3415 -p ${XDDESTDIR}/usr >/dev/null
3416 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
3417 -p ${XDDESTDIR}/usr/include >/dev/null
3418 .if defined(_LIBCOMPAT)
3419 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
3420 -p ${XDDESTDIR}/usr >/dev/null
3422 .if ${MK_TESTS} != "no"
3423 mkdir -p ${XDDESTDIR}${TESTSBASE}
3424 ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
3425 -p ${XDDESTDIR}${TESTSBASE} >/dev/null
3428 .ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
3429 xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY
3431 _xi-cross-tools: .PHONY
3432 @echo "_xi-cross-tools"
3433 .for _tool in ${XDEVDIRS}
3434 ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
3435 cd ${.CURDIR}/${_tool}; \
3436 ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
3439 _xi-includes: .PHONY
3440 .if !defined(NO_OBJWALK)
3441 ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 _obj \
3442 DESTDIR=${XDDESTDIR}
3444 ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
3445 DESTDIR=${XDDESTDIR}
3447 _xi-libraries: .PHONY
3448 ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
3449 DESTDIR=${XDDESTDIR}
3452 ${_+_}cd ${XDDESTDIR}/usr/bin; \
3453 mkdir -p ../../../../usr/bin; \
3455 ln -sf ../../${XDTP}/usr/bin/$$i \
3456 ../../../../usr/bin/${XDDIR}-$$i; \
3457 ln -sf ../../${XDTP}/usr/bin/$$i \
3458 ../../../../usr/bin/${XDDIR}${_REVISION}-$$i; \