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