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