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