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