Makefile.inc1 revision 289145
1#
2# $FreeBSD: stable/10/Makefile.inc1 289145 2015-10-11 17:59:20Z ian $
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#	-DNO_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:/bin/sh)
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
34#
35# The intended user-driven targets are:
36# buildworld  - rebuild *everything*, including glue to help do upgrades
37# installworld- install everything built by "buildworld"
38# doxygen     - build API documentation of the kernel
39# update      - convenient way to update your source tree (eg: svn/svnup)
40#
41# Standard targets (not defined here) are documented in the makefiles in
42# /usr/share/mk.  These include:
43#		obj depend all install clean cleandepend cleanobj
44
45.if !defined(TARGET) || !defined(TARGET_ARCH)
46.error "Both TARGET and TARGET_ARCH must be defined."
47.endif
48
49.include <bsd.own.mk>
50.include <bsd.arch.inc.mk>
51.include <bsd.compiler.mk>
52
53# We must do share/info early so that installation of info `dir'
54# entries works correctly.  Do it first since it is less likely to
55# grow dependencies on include and lib than vice versa.
56#
57# We must do lib/ and libexec/ before bin/, because if installworld
58# installs a new /bin/sh, the 'make' command will *immediately*
59# use that new version.  And the new (dynamically-linked) /bin/sh
60# will expect to find appropriate libraries in /lib and /libexec.
61#
62SRCDIR?=	${.CURDIR}
63.if defined(SUBDIR_OVERRIDE)
64SUBDIR=	${SUBDIR_OVERRIDE}
65.else
66SUBDIR=	share/info lib libexec
67SUBDIR+=bin
68.if ${MK_GAMES} != "no"
69SUBDIR+=games
70.endif
71.if ${MK_CDDL} != "no"
72SUBDIR+=cddl
73.endif
74SUBDIR+=gnu include
75.if ${MK_KERBEROS} != "no"
76SUBDIR+=kerberos5
77.endif
78.if ${MK_RESCUE} != "no"
79SUBDIR+=rescue
80.endif
81SUBDIR+=sbin
82.if ${MK_CRYPT} != "no"
83SUBDIR+=secure
84.endif
85.if !defined(NO_SHARE)
86SUBDIR+=share
87.endif
88SUBDIR+=sys usr.bin usr.sbin
89.if ${MK_TESTS} != "no"
90SUBDIR+=	tests
91.endif
92.if ${MK_OFED} != "no"
93SUBDIR+=contrib/ofed
94.endif
95#
96# We must do etc/ last for install/distribute to work.
97#
98SUBDIR+=etc
99
100# These are last, since it is nice to at least get the base system
101# rebuilt before you do them.
102.for _DIR in ${LOCAL_LIB_DIRS} ${LOCAL_DIRS}
103.if exists(${.CURDIR}/${_DIR}/Makefile)
104SUBDIR+= ${_DIR}
105.endif
106.endfor
107.endif
108
109.if defined(NOCLEAN)
110NO_CLEAN=	${NOCLEAN}
111.endif
112.if defined(NO_CLEANDIR)
113CLEANDIR=	clean cleandepend
114.else
115CLEANDIR=	cleandir
116.endif
117
118LOCAL_TOOL_DIRS?=
119
120BUILDENV_SHELL?=/bin/sh
121
122SVN?=		/usr/local/bin/svn
123SVNFLAGS?=	-r HEAD
124
125MAKEOBJDIRPREFIX?=	/usr/obj
126.if !defined(OSRELDATE)
127.if exists(/usr/include/osreldate.h)
128OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
129		/usr/include/osreldate.h
130.else
131OSRELDATE=	0
132.endif
133.endif
134
135.if !defined(VERSION)
136REVISION!=	${MAKE} -C ${SRCDIR}/release -V REVISION
137BRANCH!=	${MAKE} -C ${SRCDIR}/release -V BRANCH
138SRCRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
139		${SRCDIR}/sys/sys/param.h
140VERSION=	FreeBSD ${REVISION}-${BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
141.endif
142
143KNOWN_ARCHES?=	amd64 arm armeb/arm armv6/arm i386 i386/pc98 ia64 mips mipsel/mips mips64el/mips mips64/mips mipsn32el/mips mipsn32/mips powerpc powerpc64/powerpc sparc64
144.if ${TARGET} == ${TARGET_ARCH}
145_t=		${TARGET}
146.else
147_t=		${TARGET_ARCH}/${TARGET}
148.endif
149.for _t in ${_t}
150.if empty(KNOWN_ARCHES:M${_t})
151.error Unknown target ${TARGET_ARCH}:${TARGET}.
152.endif
153.endfor
154
155.if ${TARGET} == ${MACHINE}
156TARGET_CPUTYPE?=${CPUTYPE}
157.else
158TARGET_CPUTYPE?=
159.endif
160
161.if !empty(TARGET_CPUTYPE)
162_TARGET_CPUTYPE=${TARGET_CPUTYPE}
163.else
164_TARGET_CPUTYPE=dummy
165.endif
166_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
167		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
168.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
169.error CPUTYPE global should be set with ?=.
170.endif
171.if make(buildworld)
172BUILD_ARCH!=	uname -p
173.if ${MACHINE_ARCH} != ${BUILD_ARCH}
174.error To cross-build, set TARGET_ARCH.
175.endif
176.endif
177.if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
178OBJTREE=	${MAKEOBJDIRPREFIX}
179.else
180OBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
181.endif
182WORLDTMP=	${OBJTREE}${.CURDIR}/tmp
183# /usr/games added for fortune which depend on strfile
184BPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
185XPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
186STRICTTMPPATH=	${BPATH}:${XPATH}
187TMPPATH=	${STRICTTMPPATH}:${PATH}
188
189#
190# Avoid running mktemp(1) unless actually needed.
191# It may not be functional, e.g., due to new ABI
192# when in the middle of installing over this system.
193#
194.if make(distributeworld) || make(installworld)
195INSTALLTMP!=	/usr/bin/mktemp -d -u -t install
196.endif
197
198#
199# Building a world goes through the following stages
200#
201# 1. legacy stage [BMAKE]
202#	This stage is responsible for creating compatibility
203#	shims that are needed by the bootstrap-tools,
204#	build-tools and cross-tools stages.
205# 1. bootstrap-tools stage [BMAKE]
206#	This stage is responsible for creating programs that
207#	are needed for backward compatibility reasons. They
208#	are not built as cross-tools.
209# 2. build-tools stage [TMAKE]
210#	This stage is responsible for creating the object
211#	tree and building any tools that are needed during
212#	the build process.
213# 3. cross-tools stage [XMAKE]
214#	This stage is responsible for creating any tools that
215#	are needed for cross-builds. A cross-compiler is one
216#	of them.
217# 4. world stage [WMAKE]
218#	This stage actually builds the world.
219# 5. install stage (optional) [IMAKE]
220#	This stage installs a previously built world.
221#
222
223BOOTSTRAPPING?=	0
224
225# Common environment for world related stages
226CROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
227		MACHINE_ARCH=${TARGET_ARCH} \
228		MACHINE=${TARGET} \
229		CPUTYPE=${TARGET_CPUTYPE}
230.if ${MK_GROFF} != "no"
231CROSSENV+=	GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
232		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
233		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
234.endif
235
236_BOOTSTRAP_MAKEINFO?=	${MK_INFO}
237# bootstrap-tools stage
238BMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
239		PATH=${BPATH}:${PATH} \
240		WORLDTMP=${WORLDTMP} \
241		VERSION="${VERSION}" \
242		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
243		COMPILER_TYPE=${COMPILER_TYPE}
244BMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
245		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
246		DESTDIR= \
247		BOOTSTRAPPING=${OSRELDATE} \
248		SSP_CFLAGS= \
249		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
250		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
251		_BOOTSTRAP_MAKEINFO=${_BOOTSTRAP_MAKEINFO} \
252		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD -DNO_TESTS
253
254# build-tools stage
255TMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
256		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
257		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
258		DESTDIR= \
259		BOOTSTRAPPING=${OSRELDATE} \
260		SSP_CFLAGS= \
261		-DNO_LINT \
262		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD -DNO_TESTS
263
264# cross-tools stage
265XMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
266		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
267		-DWITHOUT_GDB -DNO_TESTS
268
269# kernel-tools stage
270KTMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
271		PATH=${BPATH}:${PATH} \
272		WORLDTMP=${WORLDTMP} \
273		VERSION="${VERSION}" \
274		COMPILER_TYPE=${COMPILER_TYPE}
275KTMAKE=		TOOLS_PREFIX=${WORLDTMP} MAKEOBJDIRPREFIX=${WORLDTMP} \
276		${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
277		DESTDIR= \
278		BOOTSTRAPPING=${OSRELDATE} \
279		SSP_CFLAGS= \
280		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
281		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
282		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD
283
284# world stage
285WMAKEENV=	${CROSSENV} \
286		_SHLIBDIRPREFIX=${WORLDTMP} \
287		_LDSCRIPTROOT= \
288		VERSION="${VERSION}" \
289		INSTALL="sh ${.CURDIR}/tools/install.sh" \
290		PATH=${TMPPATH}
291
292# make hierarchy
293HMAKE=		PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
294.if defined(NO_ROOT)
295HMAKE+=		PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
296.endif
297
298.if ${MK_CDDL} == "no"
299WMAKEENV+=	NO_CTF=1
300.endif
301
302.if defined(CROSS_TOOLCHAIN_PREFIX)
303CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
304CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
305.endif
306XCOMPILERS=	CC CXX CPP
307.for COMPILER in ${XCOMPILERS}
308.if defined(CROSS_COMPILER_PREFIX)
309X${COMPILER}?=	${CROSS_COMPILER_PREFIX}${${COMPILER}}
310.else
311X${COMPILER}?=	${${COMPILER}}
312.endif
313.endfor
314XBINUTILS=	AS AR LD NM OBJCOPY OBJDUMP RANLIB STRINGS
315.for BINUTIL in ${XBINUTILS}
316.if defined(CROSS_BINUTILS_PREFIX)
317X${BINUTIL}?=	${CROSS_BINUTILS_PREFIX}${${BINUTIL}}
318.else
319X${BINUTIL}?=	${${BINUTIL}}
320.endif
321.endfor
322WMAKEENV+=	CC="${XCC} ${XFLAGS}" CXX="${XCXX} ${XFLAGS}" \
323		CPP="${XCPP} ${XFLAGS}" \
324		AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
325		OBJDUMP=${XOBJDUMP} OBJCOPY="${XOBJCOPY}" \
326		RANLIB=${XRANLIB} STRINGS=${XSTRINGS}
327
328.if ${XCC:T:Mgcc} == "gcc"
329WMAKE_COMPILER_TYPE=	gcc
330.elif ${XCC:T:Mclang} == "clang"
331WMAKE_COMPILER_TYPE=	clang
332.elif ${MK_CLANG_IS_CC} == "no"
333WMAKE_COMPILER_TYPE=	gcc
334.else
335WMAKE_COMPILER_TYPE=	clang
336.endif
337IMAKE_COMPILER_TYPE=	COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
338
339.if ${XCC:M/*}
340XFLAGS=		--sysroot=${WORLDTMP}
341.if defined(CROSS_BINUTILS_PREFIX)
342# In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
343# directory, but the compiler will look in the right place for it's
344# tools so we don't need to tell it where to look.
345.if exists(${CROSS_BINUTILS_PREFIX})
346XFLAGS+=	-B${CROSS_BINUTILS_PREFIX}
347.endif
348.else
349XFLAGS+=	-B${WORLDTMP}/usr/bin
350.endif
351.if ${TARGET_ARCH} != ${MACHINE_ARCH} && ${WMAKE_COMPILER_TYPE} == "clang"
352.if (${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "armv6") && \
353${MK_ARM_EABI} != "no"
354TARGET_ABI=	gnueabi
355.else
356TARGET_ABI=	unknown
357.endif
358TARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd10.0
359XFLAGS+=	-target ${TARGET_TRIPLE}
360.endif
361.endif
362
363WMAKEENV+=	COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
364WMAKE=		${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP}
365
366.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64"
367# 32 bit world
368LIB32TMP=	${OBJTREE}${.CURDIR}/lib32
369
370.if ${TARGET_ARCH} == "amd64"
371.if empty(TARGET_CPUTYPE)
372LIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
373.else
374LIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
375.endif
376LIB32WMAKEENV=	MACHINE=i386 MACHINE_ARCH=i386 \
377		MACHINE_CPU="i686 mmx sse sse2"
378LIB32WMAKEFLAGS=	\
379		AS="${XAS} --32" \
380		LD="${XLD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
381		OBJCOPY="${XOBJCOPY}"
382
383.elif ${TARGET_ARCH} == "powerpc64"
384.if empty(TARGET_CPUTYPE)
385LIB32CPUFLAGS=	-mcpu=powerpc
386.else
387LIB32CPUFLAGS=	-mcpu=${TARGET_CPUTYPE}
388.endif
389LIB32WMAKEENV=	MACHINE=powerpc MACHINE_ARCH=powerpc
390LIB32WMAKEFLAGS=	\
391		LD="${XLD} -m elf32ppc_fbsd" \
392		OBJCOPY="${XOBJCOPY}"
393.endif
394
395
396LIB32FLAGS=	-m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \
397		-isystem ${LIB32TMP}/usr/include/ \
398		-L${LIB32TMP}/usr/lib32 \
399		-B${LIB32TMP}/usr/lib32
400.if ${XCC:M/*}
401LIB32FLAGS+=		--sysroot=${WORLDTMP}
402.endif
403
404# Yes, the flags are redundant.
405LIB32WMAKEENV+=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
406		_SHLIBDIRPREFIX=${LIB32TMP} \
407		_LDSCRIPTROOT=${LIB32TMP} \
408		VERSION="${VERSION}" \
409		INSTALL="sh ${.CURDIR}/tools/install.sh" \
410		PATH=${TMPPATH} \
411		LIBDIR=/usr/lib32 \
412		SHLIBDIR=/usr/lib32 \
413		LIBPRIVATEDIR=/usr/lib32/private \
414		COMPILER_TYPE=${WMAKE_COMPILER_TYPE} \
415		DTRACE="${DTRACE} -32"
416LIB32WMAKEFLAGS+=	\
417		CC="${XCC} ${LIB32FLAGS}" \
418		CXX="${XCXX} ${LIB32FLAGS}" \
419		DESTDIR=${LIB32TMP} \
420		-DCOMPAT_32BIT \
421		-DLIBRARIES_ONLY \
422		-DNO_CPU_CFLAGS \
423		-DNO_CTF \
424		-DNO_LINT \
425		-DNO_TESTS
426
427LIB32WMAKE=	${LIB32WMAKEENV} ${MAKE} ${LIB32WMAKEFLAGS} \
428		-DWITHOUT_MAN -DWITHOUT_INFO -DWITHOUT_HTML
429LIB32IMAKE=	${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} -DNO_INCS \
430		${IMAKE_INSTALL}
431.endif
432
433IMAKEENV=	${CROSSENV:N_LDSCRIPTROOT=*}
434IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1 \
435		${IMAKE_INSTALL} ${IMAKE_MTREE} ${IMAKE_COMPILER_TYPE}
436.if empty(.MAKEFLAGS:M-n)
437IMAKEENV+=	PATH=${STRICTTMPPATH}:${INSTALLTMP} \
438		LD_LIBRARY_PATH=${INSTALLTMP} \
439		PATH_LOCALE=${INSTALLTMP}/locale
440IMAKE+=		__MAKE_SHELL=${INSTALLTMP}/sh
441.else
442IMAKEENV+=	PATH=${TMPPATH}:${INSTALLTMP}
443.endif
444.if defined(DB_FROM_SRC)
445INSTALLFLAGS+=	-N ${.CURDIR}/etc
446MTREEFLAGS+=	-N ${.CURDIR}/etc
447.endif
448_INSTALL_DDIR=	${DESTDIR}/${DISTDIR}
449INSTALL_DDIR=	${_INSTALL_DDIR:S://:/:g:C:/$::}
450.if defined(NO_ROOT)
451METALOG?=	${DESTDIR}/${DISTDIR}/METALOG
452IMAKE+=		-DNO_ROOT METALOG=${METALOG}
453INSTALLFLAGS+=	-U -M ${METALOG} -D ${INSTALL_DDIR}
454MTREEFLAGS+=	-W
455.endif
456.if defined(DB_FROM_SRC) || defined(NO_ROOT)
457IMAKE_INSTALL=	INSTALL="install ${INSTALLFLAGS}"
458IMAKE_MTREE=	MTREE_CMD="nmtree ${MTREEFLAGS}"
459.endif
460
461# kernel stage
462KMAKEENV=	${WMAKEENV}
463KMAKE=		${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
464
465#
466# buildworld
467#
468# Attempt to rebuild the entire system, with reasonable chance of
469# success, regardless of how old your existing system is.
470#
471_worldtmp:
472.if ${.CURDIR:C/[^,]//g} != ""
473#	The m4 build of sendmail files doesn't like it if ',' is used
474#	anywhere in the path of it's files.
475	@echo
476	@echo "*** Error: path to source tree contains a comma ','"
477	@echo
478	false
479.endif
480	@echo
481	@echo "--------------------------------------------------------------"
482	@echo ">>> Rebuilding the temporary build tree"
483	@echo "--------------------------------------------------------------"
484.if !defined(NO_CLEAN)
485	rm -rf ${WORLDTMP}
486.if defined(LIB32TMP)
487	rm -rf ${LIB32TMP}
488.endif
489.else
490	rm -rf ${WORLDTMP}/legacy/usr/include
491#	XXX - These three can depend on any header file.
492	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
493	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
494	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
495.endif
496.for _dir in \
497    lib usr legacy/bin legacy/usr
498	mkdir -p ${WORLDTMP}/${_dir}
499.endfor
500	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
501	    -p ${WORLDTMP}/legacy/usr >/dev/null
502.if ${MK_GROFF} != "no"
503	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
504	    -p ${WORLDTMP}/legacy/usr >/dev/null
505.endif
506	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
507	    -p ${WORLDTMP}/usr >/dev/null
508	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
509	    -p ${WORLDTMP}/usr/include >/dev/null
510	ln -sf ${.CURDIR}/sys ${WORLDTMP}
511.if ${MK_DEBUG_FILES} != "no"
512	# We could instead disable debug files for these build stages
513	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
514	    -p ${WORLDTMP}/legacy/usr/lib >/dev/null
515	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
516	    -p ${WORLDTMP}/usr/lib >/dev/null
517.endif
518.if ${MK_TESTS} != "no"
519	mkdir -p ${WORLDTMP}${TESTSBASE}
520	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
521	    -p ${WORLDTMP}${TESTSBASE} >/dev/null
522.endif
523.for _mtree in ${LOCAL_MTREE}
524	mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
525.endfor
526_legacy:
527	@echo
528	@echo "--------------------------------------------------------------"
529	@echo ">>> stage 1.1: legacy release compatibility shims"
530	@echo "--------------------------------------------------------------"
531	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
532_bootstrap-tools:
533	@echo
534	@echo "--------------------------------------------------------------"
535	@echo ">>> stage 1.2: bootstrap tools"
536	@echo "--------------------------------------------------------------"
537	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
538_cleanobj:
539.if !defined(NO_CLEAN)
540	@echo
541	@echo "--------------------------------------------------------------"
542	@echo ">>> stage 2.1: cleaning up the object tree"
543	@echo "--------------------------------------------------------------"
544	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
545.if defined(LIB32TMP)
546	${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
547.endif
548.endif
549_obj:
550	@echo
551	@echo "--------------------------------------------------------------"
552	@echo ">>> stage 2.2: rebuilding the object tree"
553	@echo "--------------------------------------------------------------"
554	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
555_build-tools:
556	@echo
557	@echo "--------------------------------------------------------------"
558	@echo ">>> stage 2.3: build tools"
559	@echo "--------------------------------------------------------------"
560	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
561_cross-tools:
562	@echo
563	@echo "--------------------------------------------------------------"
564	@echo ">>> stage 3: cross tools"
565	@echo "--------------------------------------------------------------"
566	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
567	${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
568_includes:
569	@echo
570	@echo "--------------------------------------------------------------"
571	@echo ">>> stage 4.1: building includes"
572	@echo "--------------------------------------------------------------"
573	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
574_libraries:
575	@echo
576	@echo "--------------------------------------------------------------"
577	@echo ">>> stage 4.2: building libraries"
578	@echo "--------------------------------------------------------------"
579	${_+_}cd ${.CURDIR}; \
580	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
581	    -DWITHOUT_MAN -DNO_PROFILE -DNO_TESTS libraries
582_depend:
583	@echo
584	@echo "--------------------------------------------------------------"
585	@echo ">>> stage 4.3: make dependencies"
586	@echo "--------------------------------------------------------------"
587	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
588everything:
589	@echo
590	@echo "--------------------------------------------------------------"
591	@echo ">>> stage 4.4: building everything"
592	@echo "--------------------------------------------------------------"
593	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
594.if defined(LIB32TMP)
595build32:
596	@echo
597	@echo "--------------------------------------------------------------"
598	@echo ">>> stage 5.1: building 32 bit shim libraries"
599	@echo "--------------------------------------------------------------"
600	mkdir -p ${LIB32TMP}/usr/include
601	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
602	    -p ${LIB32TMP}/usr >/dev/null
603	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
604	    -p ${LIB32TMP}/usr/include >/dev/null
605.if ${MK_DEBUG_FILES} != "no"
606	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
607	    -p ${LIB32TMP}/usr/lib >/dev/null
608.endif
609	mkdir -p ${WORLDTMP}
610	ln -sf ${.CURDIR}/sys ${WORLDTMP}
611.for _t in obj includes
612	cd ${.CURDIR}/include; ${LIB32WMAKE} DIRPRFX=include/ ${_t}
613	cd ${.CURDIR}/lib; ${LIB32WMAKE} DIRPRFX=lib/ ${_t}
614.if ${MK_CDDL} != "no"
615	cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} DIRPRFX=cddl/lib/ ${_t}
616.endif
617	cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} DIRPRFX=gnu/lib/ ${_t}
618.if ${MK_CRYPT} != "no"
619	cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} DIRPRFX=secure/lib/ ${_t}
620.endif
621.if ${MK_KERBEROS} != "no"
622	cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} DIRPRFX=kerberos5/lib ${_t}
623.endif
624.endfor
625.for _dir in usr.bin/lex/lib
626	cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} DIRPRFX=${_dir}/ obj
627.endfor
628.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
629	cd ${.CURDIR}/${_dir}; \
630	    WORLDTMP=${WORLDTMP} \
631	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
632	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \
633	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF \
634	    -DEARLY_BUILD build-tools
635.endfor
636	cd ${.CURDIR}; \
637	    ${LIB32WMAKE} -f Makefile.inc1 libraries
638.for _t in obj depend all
639	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} \
640	    DIRPRFX=libexec/rtld-elf/ ${_t}
641	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} \
642	    DIRPRFX=usr.bin/ldd ${_t}
643.endfor
644
645distribute32 install32:
646	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
647.if ${MK_CDDL} != "no"
648	cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
649.endif
650	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
651.if ${MK_CRYPT} != "no"
652	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
653.endif
654.if ${MK_KERBEROS} != "no"
655	cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
656.endif
657	cd ${.CURDIR}/libexec/rtld-elf; \
658	    PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
659	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//}
660.endif
661
662WMAKE_TGTS=
663.if !defined(SUBDIR_OVERRIDE)
664WMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
665.endif
666WMAKE_TGTS+=	_cleanobj _obj _build-tools
667.if !defined(SUBDIR_OVERRIDE)
668WMAKE_TGTS+=	_cross-tools
669.endif
670WMAKE_TGTS+=	_includes _libraries _depend everything
671.if defined(LIB32TMP) && ${MK_LIB32} != "no"
672WMAKE_TGTS+=	build32
673.endif
674
675buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
676.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
677
678buildworld_prologue:
679	@echo "--------------------------------------------------------------"
680	@echo ">>> World build started on `LC_ALL=C date`"
681	@echo "--------------------------------------------------------------"
682
683buildworld_epilogue:
684	@echo
685	@echo "--------------------------------------------------------------"
686	@echo ">>> World build completed on `LC_ALL=C date`"
687	@echo "--------------------------------------------------------------"
688
689#
690# We need to have this as a target because the indirection between Makefile
691# and Makefile.inc1 causes the correct PATH to be used, rather than a
692# modification of the current environment's PATH.  In addition, we need
693# to quote multiword values.
694#
695buildenvvars:
696	@echo ${WMAKEENV:Q}
697
698.if ${.TARGETS:Mbuildenv}
699.if ${.MAKEFLAGS:M-j}
700.error The buildenv target is incompatible with -j
701.endif
702.endif
703buildenv:
704	@echo Entering world for ${TARGET_ARCH}:${TARGET}
705	@cd ${.CURDIR} && env ${WMAKEENV} ${BUILDENV_SHELL} || true
706
707TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
708toolchain: ${TOOLCHAIN_TGTS}
709kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
710
711#
712# installcheck
713#
714# Checks to be sure system is ready for installworld/installkernel.
715#
716installcheck: _installcheck_world _installcheck_kernel
717_installcheck_world:
718_installcheck_kernel:
719
720#
721# Require DESTDIR to be set if installing for a different architecture or
722# using the user/group database in the source tree.
723#
724.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
725    defined(DB_FROM_SRC)
726.if !make(distributeworld)
727_installcheck_world: __installcheck_DESTDIR
728_installcheck_kernel: __installcheck_DESTDIR
729__installcheck_DESTDIR:
730.if !defined(DESTDIR) || empty(DESTDIR)
731	@echo "ERROR: Please set DESTDIR!"; \
732	false
733.endif
734.endif
735.endif
736
737.if !defined(DB_FROM_SRC)
738#
739# Check for missing UIDs/GIDs.
740#
741CHECK_UIDS=	auditdistd
742CHECK_GIDS=	audit
743.if ${MK_SENDMAIL} != "no"
744CHECK_UIDS+=	smmsp
745CHECK_GIDS+=	smmsp
746.endif
747.if ${MK_PF} != "no"
748CHECK_UIDS+=	proxy
749CHECK_GIDS+=	proxy authpf
750.endif
751.if ${MK_UNBOUND} != "no"
752CHECK_UIDS+=	unbound
753CHECK_GIDS+=	unbound
754.endif
755_installcheck_world: __installcheck_UGID
756__installcheck_UGID:
757.for uid in ${CHECK_UIDS}
758	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
759		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
760		false; \
761	fi
762.endfor
763.for gid in ${CHECK_GIDS}
764	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
765		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
766		false; \
767	fi
768.endfor
769.endif
770
771#
772# Required install tools to be saved in a scratch dir for safety.
773#
774.if ${MK_INFO} != "no"
775_install-info=	install-info
776.endif
777.if ${MK_ZONEINFO} != "no"
778_zoneinfo=	zic tzsetup
779.endif
780
781.if exists(/usr/sbin/nmtree)
782_nmtree_itools=	nmtree
783.endif
784
785ITOOLS=	[ awk cap_mkdb cat chflags chmod chown \
786	date echo egrep find grep id install ${_install-info} \
787	ln lockf make mkdir mtree ${_nmtree_itools} mv pwd_mkdb \
788	rm sed sh strip sysctl test true uname wc ${_zoneinfo} \
789	${LOCAL_ITOOLS}
790
791# Needed for share/man
792.if ${MK_MAN} != "no"
793ITOOLS+=makewhatis
794.endif
795
796#
797# distributeworld
798#
799# Distributes everything compiled by a `buildworld'.
800#
801# installworld
802#
803# Installs everything compiled by a 'buildworld'.
804#
805
806# Non-base distributions produced by the base system
807EXTRA_DISTRIBUTIONS=	doc
808.if ${MK_GAMES} != "no"
809EXTRA_DISTRIBUTIONS+=	games
810.endif
811.if defined(LIB32TMP) && ${MK_LIB32} != "no"
812EXTRA_DISTRIBUTIONS+=	lib32
813.endif
814.if ${MK_TESTS} != "no"
815EXTRA_DISTRIBUTIONS+=	tests
816.endif
817
818MTREE_MAGIC?=	mtree 2.0
819
820distributeworld installworld: _installcheck_world
821	mkdir -p ${INSTALLTMP}
822	export PATH=${BPATH}:${PATH} ; \
823	progs=$$(for prog in ${ITOOLS}; do \
824		if progpath=`which $$prog`; then \
825			echo $$progpath; \
826		else \
827			echo "Required tool $$prog not found in PATH." >&2; \
828			exit 1; \
829		fi; \
830	    done); \
831	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
832	    while read line; do \
833		set -- $$line; \
834		if [ "$$2 $$3" != "not found" ]; then \
835			echo $$2; \
836		else \
837			echo "Required library $$1 not found." >&2; \
838			exit 1; \
839		fi; \
840	    done); \
841	cp $$libs $$progs ${INSTALLTMP}
842	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
843.if defined(NO_ROOT)
844	echo "#${MTREE_MAGIC}" > ${METALOG}
845.endif
846.if make(distributeworld)
847.for dist in ${EXTRA_DISTRIBUTIONS}
848	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
849	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
850	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
851	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
852	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
853	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
854	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
855.if ${MK_DEBUG_FILES} != "no"
856	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
857	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
858.endif
859.if ${MK_TESTS} != "no" && ${dist} == "tests"
860	-mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
861	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
862	    -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
863.endif
864.if defined(NO_ROOT)
865	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
866	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
867	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
868	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
869	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
870	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
871.endif
872.endfor
873	-mkdir ${DESTDIR}/${DISTDIR}/base
874	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
875	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
876	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
877	    LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
878.endif
879	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
880	    ${IMAKEENV} rm -rf ${INSTALLTMP}
881.if make(distributeworld)
882.for dist in ${EXTRA_DISTRIBUTIONS}
883	find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -empty -delete
884.endfor
885.if defined(NO_ROOT)
886.for dist in base ${EXTRA_DISTRIBUTIONS}
887	@# For each file that exists in this dist, print the corresponding
888	@# line from the METALOG.  This relies on the fact that
889	@# a line containing only the filename will sort immediatly before
890	@# the relevant mtree line.
891	cd ${DESTDIR}/${DISTDIR}; \
892	find ./${dist} | sort -u ${METALOG} - | \
893	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
894	${DESTDIR}/${DISTDIR}/${dist}.meta
895.endfor
896.if ${MK_DEBUG_FILES} != "no"
897. for dist in base ${EXTRA_DISTRIBUTIONS}
898	@# For each file that exists in this dist, print the corresponding
899	@# line from the METALOG.  This relies on the fact that
900	@# a line containing only the filename will sort immediatly before
901	@# the relevant mtree line.
902	cd ${DESTDIR}/${DISTDIR}; \
903	find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
904	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
905	${DESTDIR}/${DISTDIR}/${dist}.debug.meta
906. endfor
907.endif
908.endif
909.endif
910
911packageworld:
912.for dist in base ${EXTRA_DISTRIBUTIONS}
913.if defined(NO_ROOT)
914	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
915	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
916	    --exclude usr/lib/debug \
917	    @${DESTDIR}/${DISTDIR}/${dist}.meta
918.else
919	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
920	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
921	    --exclude usr/lib/debug .
922.endif
923.endfor
924
925.if ${MK_DEBUG_FILES} != "no"
926. for dist in base ${EXTRA_DISTRIBUTIONS}
927.  if defined(NO_ROOT)
928	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
929	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.debug.txz \
930	    @${DESTDIR}/${DISTDIR}/${dist}.debug.meta
931.  else
932	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
933	    tar cvJfL ${DESTDIR}/${DISTDIR}/${dist}.debug.txz \
934	    usr/lib/debug
935.  endif
936. endfor
937.endif
938
939#
940# reinstall
941#
942# If you have a build server, you can NFS mount the source and obj directories
943# and do a 'make reinstall' on the *client* to install new binaries from the
944# most recent server build.
945#
946reinstall: .MAKE
947	@echo "--------------------------------------------------------------"
948	@echo ">>> Making hierarchy"
949	@echo "--------------------------------------------------------------"
950	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
951	    LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
952	@echo
953	@echo "--------------------------------------------------------------"
954	@echo ">>> Installing everything"
955	@echo "--------------------------------------------------------------"
956	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
957.if defined(LIB32TMP) && ${MK_LIB32} != "no"
958	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
959.endif
960
961redistribute: .MAKE
962	@echo "--------------------------------------------------------------"
963	@echo ">>> Distributing everything"
964	@echo "--------------------------------------------------------------"
965	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
966.if defined(LIB32TMP) && ${MK_LIB32} != "no"
967	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
968	    DISTRIBUTION=lib32
969.endif
970
971distrib-dirs distribution: .MAKE
972	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
973	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
974
975#
976# buildkernel and installkernel
977#
978# Which kernels to build and/or install is specified by setting
979# KERNCONF. If not defined a GENERIC kernel is built/installed.
980# Only the existing (depending TARGET) config files are used
981# for building kernels and only the first of these is designated
982# as the one being installed.
983#
984# Note that we have to use TARGET instead of TARGET_ARCH when
985# we're in kernel-land. Since only TARGET_ARCH is (expected) to
986# be set to cross-build, we have to make sure TARGET is set
987# properly.
988
989.if defined(KERNFAST)
990NO_KERNELCLEAN=	t
991NO_KERNELCONFIG=	t
992NO_KERNELDEPEND=	t
993NO_KERNELOBJ=		t
994# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
995.if !defined(KERNCONF) && ${KERNFAST} != "1"
996KERNCONF=${KERNFAST}
997.endif
998.endif
999.if ${TARGET_ARCH} == "powerpc64"
1000KERNCONF?=	GENERIC64
1001.else
1002KERNCONF?=	GENERIC
1003.endif
1004INSTKERNNAME?=	kernel
1005
1006KERNSRCDIR?=	${.CURDIR}/sys
1007KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
1008KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
1009KERNCONFDIR?=	${KRNLCONFDIR}
1010
1011BUILDKERNELS=
1012INSTALLKERNEL=
1013.for _kernel in ${KERNCONF}
1014.if exists(${KERNCONFDIR}/${_kernel})
1015BUILDKERNELS+=	${_kernel}
1016.if empty(INSTALLKERNEL)
1017INSTALLKERNEL= ${_kernel}
1018.endif
1019.endif
1020.endfor
1021
1022buildkernel ${WMAKE_TGTS} ${.ALLTARGETS:M_*}: .MAKE
1023
1024#
1025# buildkernel
1026#
1027# Builds all kernels defined by BUILDKERNELS.
1028#
1029buildkernel:
1030.if empty(BUILDKERNELS)
1031	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1032	false
1033.endif
1034	@echo
1035.for _kernel in ${BUILDKERNELS}
1036	@echo "--------------------------------------------------------------"
1037	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1038	@echo "--------------------------------------------------------------"
1039	@echo "===> ${_kernel}"
1040	mkdir -p ${KRNLOBJDIR}
1041.if !defined(NO_KERNELCONFIG)
1042	@echo
1043	@echo "--------------------------------------------------------------"
1044	@echo ">>> stage 1: configuring the kernel"
1045	@echo "--------------------------------------------------------------"
1046	cd ${KRNLCONFDIR}; \
1047		PATH=${TMPPATH} \
1048		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1049			-I '${KERNCONFDIR}' '${KERNCONFDIR}/${_kernel}'
1050.endif
1051.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1052	@echo
1053	@echo "--------------------------------------------------------------"
1054	@echo ">>> stage 2.1: cleaning up the object tree"
1055	@echo "--------------------------------------------------------------"
1056	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1057.endif
1058.if !defined(NO_KERNELOBJ)
1059	@echo
1060	@echo "--------------------------------------------------------------"
1061	@echo ">>> stage 2.2: rebuilding the object tree"
1062	@echo "--------------------------------------------------------------"
1063	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1064.endif
1065	@echo
1066	@echo "--------------------------------------------------------------"
1067	@echo ">>> stage 2.3: build tools"
1068	@echo "--------------------------------------------------------------"
1069	${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1070.if !defined(NO_KERNELDEPEND)
1071	@echo
1072	@echo "--------------------------------------------------------------"
1073	@echo ">>> stage 3.1: making dependencies"
1074	@echo "--------------------------------------------------------------"
1075	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
1076.endif
1077	@echo
1078	@echo "--------------------------------------------------------------"
1079	@echo ">>> stage 3.2: building everything"
1080	@echo "--------------------------------------------------------------"
1081	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1082	@echo "--------------------------------------------------------------"
1083	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1084	@echo "--------------------------------------------------------------"
1085.endfor
1086
1087#
1088# installkernel, etc.
1089#
1090# Install the kernel defined by INSTALLKERNEL
1091#
1092installkernel installkernel.debug \
1093reinstallkernel reinstallkernel.debug: _installcheck_kernel
1094.if empty(INSTALLKERNEL)
1095	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1096	false
1097.endif
1098	@echo "--------------------------------------------------------------"
1099	@echo ">>> Installing kernel ${INSTALLKERNEL}"
1100	@echo "--------------------------------------------------------------"
1101	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1102	    ${CROSSENV} PATH=${TMPPATH} \
1103	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1104
1105distributekernel distributekernel.debug:
1106.if empty(INSTALLKERNEL)
1107	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1108	false
1109.endif
1110	mkdir -p ${DESTDIR}/${DISTDIR}
1111.if defined(NO_ROOT)
1112	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1113.endif
1114	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1115	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1116	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1117	    DESTDIR=${INSTALL_DDIR}/kernel \
1118	    ${.TARGET:S/distributekernel/install/}
1119.if defined(NO_ROOT)
1120	sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1121	    ${DESTDIR}/${DISTDIR}/kernel.meta
1122.endif
1123.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1124.if defined(NO_ROOT)
1125	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1126.endif
1127	cd ${KRNLOBJDIR}/${_kernel}; \
1128	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1129	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1130	    KERNEL=${INSTKERNNAME}.${_kernel} \
1131	    DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1132	    ${.TARGET:S/distributekernel/install/}
1133.if defined(NO_ROOT)
1134	sed -e 's|^./kernel|.|' \
1135	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1136	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1137.endif
1138.endfor
1139
1140packagekernel:
1141.if defined(NO_ROOT)
1142	cd ${DESTDIR}/${DISTDIR}/kernel; \
1143	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz \
1144	    @${DESTDIR}/${DISTDIR}/kernel.meta
1145.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1146	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1147	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz \
1148	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1149.endfor
1150.else
1151	cd ${DESTDIR}/${DISTDIR}/kernel; \
1152	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz .
1153.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1154	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1155	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz .
1156.endfor
1157.endif
1158
1159#
1160# doxygen
1161#
1162# Build the API documentation with doxygen
1163#
1164doxygen:
1165	@if [ ! -x `/usr/bin/which doxygen` ]; then \
1166		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1167		exit 1; \
1168	fi
1169	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
1170
1171#
1172# update
1173#
1174# Update the source tree(s), by running svn/svnup to update to the
1175# latest copy.
1176#
1177update:
1178.if (defined(CVS_UPDATE) || defined(SUP_UPDATE)) && !defined(SVN_UPDATE)
1179	@echo "--------------------------------------------------------------"
1180	@echo "CVS_UPDATE and SUP_UPDATE are no longer supported."
1181	@echo "Please see: https://wiki.freebsd.org/CvsIsDeprecated"
1182	@echo "--------------------------------------------------------------"
1183	@exit 1
1184.endif
1185.if defined(SVN_UPDATE)
1186	@echo "--------------------------------------------------------------"
1187	@echo ">>> Updating ${.CURDIR} using Subversion"
1188	@echo "--------------------------------------------------------------"
1189	@(cd ${.CURDIR} && ${SVN} update ${SVNFLAGS})
1190.endif
1191
1192#
1193# ------------------------------------------------------------------------
1194#
1195# From here onwards are utility targets used by the 'make world' and
1196# related targets.  If your 'world' breaks, you may like to try to fix
1197# the problem and manually run the following targets to attempt to
1198# complete the build.  Beware, this is *not* guaranteed to work, you
1199# need to have a pretty good grip on the current state of the system
1200# to attempt to manually finish it.  If in doubt, 'make world' again.
1201#
1202
1203#
1204# legacy: Build compatibility shims for the next three targets
1205#
1206legacy:
1207.if ${BOOTSTRAPPING} < 700055 && ${BOOTSTRAPPING} != 0
1208	@echo "ERROR: Source upgrades from versions prior to 7.0 not supported."; \
1209	false
1210.endif
1211.for _tool in tools/build
1212	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
1213	    cd ${.CURDIR}/${_tool} && \
1214	    ${MAKE} DIRPRFX=${_tool}/ obj && \
1215	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes && \
1216	    ${MAKE} DIRPRFX=${_tool}/ depend && \
1217	    ${MAKE} DIRPRFX=${_tool}/ all && \
1218	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1219.endfor
1220
1221#
1222# bootstrap-tools: Build tools needed for compatibility
1223#
1224_bt=		_bootstrap-tools	
1225
1226.if ${MK_GAMES} != "no"
1227_strfile=	games/fortune/strfile
1228.endif
1229
1230.if ${MK_CXX} != "no"
1231_gperf=		gnu/usr.bin/gperf
1232.endif
1233
1234.if ${MK_GROFF} != "no"
1235_groff=		gnu/usr.bin/groff
1236.endif
1237
1238.if ${MK_VT} != "no"
1239_vtfontcvt=	usr.bin/vtfontcvt
1240.endif
1241
1242.if ${BOOTSTRAPPING} < 800022
1243_ar=		usr.bin/ar
1244.endif
1245
1246.if ${BOOTSTRAPPING} < 800013
1247_mklocale=	usr.bin/mklocale
1248.endif
1249
1250.if ${BOOTSTRAPPING} < 900002
1251_sed=		usr.bin/sed
1252.endif
1253
1254.if ${BOOTSTRAPPING} < 1000002
1255_m4=		usr.bin/m4
1256.endif
1257
1258.if ${BOOTSTRAPPING} < 1001506
1259_yacc=		lib/liby \
1260		usr.bin/yacc
1261
1262${_bt}-usr.bin/yacc: ${_bt}-lib/liby
1263.endif
1264
1265# crunchgen broken on head with STRIP= for a while, even
1266# when building stable binaries, so bootstrap there too.
1267# r284356 to r285986 is the broken range.
1268.if ${BOOTSTRAPPING} < 1000014 || \
1269	(${BOOTSTRAPPING} > 1100076 && ${BOOTSTRAPPING} < 1100078)
1270_crunch=	usr.sbin/crunch
1271.endif
1272
1273.if ${BOOTSTRAPPING} < 1000026
1274_nmtree=	lib/libnetbsd \
1275		usr.sbin/nmtree
1276
1277${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
1278.endif
1279
1280.if ${BOOTSTRAPPING} < 1000027
1281_cat=		bin/cat
1282.endif
1283
1284.if ${BOOTSTRAPPING} < 1000033
1285_lex=		usr.bin/lex
1286
1287${_bt}-usr.bin/lex: ${_bt}-usr.bin/m4
1288.endif
1289
1290.if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1291_awk=		usr.bin/awk
1292.endif
1293
1294.if ${MK_BSNMP} != "no"
1295_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
1296.endif
1297
1298.if ${MK_CLANG} != "no"
1299_clang_tblgen= \
1300	lib/clang/libllvmsupport \
1301	lib/clang/libllvmtablegen \
1302	usr.bin/clang/tblgen \
1303	usr.bin/clang/clang-tblgen
1304
1305${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1306${_bt}-usr.bin/clang/tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1307.endif
1308
1309# dtrace tools are required for older bootstrap env and cross-build
1310.if ${MK_CDDL} != "no" && \
1311    ((${BOOTSTRAPPING} < 1000034 && \
1312          !(${BOOTSTRAPPING} >= 901505 && ${BOOTSTRAPPING} < 999999)) \
1313      || (${MACHINE} != ${TARGET} || ${MACHINE_ARCH} != ${TARGET_ARCH}))
1314_dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
1315    lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
1316
1317${_bt}-cddl/usr.bin/ctfconvert: ${_bt}-lib/libelf ${_bt}-lib/libdwarf ${_bt}-cddl/lib/libctf
1318${_bt}-cddl/usr.bin/ctfmerge: ${_bt}-lib/libelf ${_bt}-lib/libdwarf ${_bt}-cddl/lib/libctf
1319.endif
1320
1321# Default to building the GPL DTC, but build the BSDL one if users explicitly
1322# request it.
1323_dtc= usr.bin/dtc
1324.if ${MK_GPL_DTC} != "no"
1325_dtc= gnu/usr.bin/dtc
1326.endif
1327
1328.if ${MK_KERBEROS} != "no"
1329_kerberos5_bootstrap_tools= \
1330	kerberos5/tools/make-roken \
1331	kerberos5/lib/libroken \
1332	kerberos5/lib/libvers \
1333	kerberos5/tools/asn1_compile \
1334	kerberos5/tools/slc \
1335	usr.bin/compile_et
1336
1337.ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
1338.endif
1339
1340.if ${_BOOTSTRAP_MAKEINFO} != "no"
1341_texinfo=	gnu/usr.bin/texinfo/libtxi \
1342		gnu/usr.bin/texinfo/makeinfo \
1343		gnu/usr.bin/texinfo/install-info
1344
1345${_bt}-gnu/usr.bin/texinfo/install-info: ${_bt}-gnu/usr.bin/texinfo/libtxi
1346${_bt}-gnu/usr.bin/texinfo/makeinfo: ${_bt}-gnu/usr.bin/texinfo/libtxi
1347.endif
1348bootstrap-tools: .PHONY
1349
1350#	Please document (add comment) why something is in 'bootstrap-tools'.
1351#	Try to bound the building of the bootstrap-tool to just the
1352#	FreeBSD versions that need the tool built at this stage of the build.
1353.for _tool in \
1354    ${_clang_tblgen} \
1355    ${_kerberos5_bootstrap_tools} \
1356    ${_dtrace_tools} \
1357    ${_strfile} \
1358    ${_gperf} \
1359    ${_groff} \
1360    ${_ar} \
1361    ${_dtc} \
1362    ${_awk} \
1363    ${_cat} \
1364    usr.bin/lorder \
1365    usr.bin/makewhatis \
1366    ${_mklocale} \
1367    usr.bin/rpcgen \
1368    ${_sed} \
1369    ${_yacc} \
1370    ${_m4} \
1371    ${_lex} \
1372    lib/libmd \
1373    usr.bin/xinstall \
1374    ${_gensnmptree} \
1375    usr.sbin/config \
1376    ${_crunch} \
1377    ${_nmtree} \
1378    ${_texinfo} \
1379    ${_vtfontcvt}
1380${_bt}-${_tool}: .PHONY .MAKE
1381	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1382		cd ${.CURDIR}/${_tool} && \
1383		${MAKE} DIRPRFX=${_tool}/ obj && \
1384		${MAKE} DIRPRFX=${_tool}/ depend && \
1385		${MAKE} DIRPRFX=${_tool}/ all && \
1386		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1387
1388bootstrap-tools: ${_bt}-${_tool}
1389.endfor
1390
1391#
1392# build-tools: Build special purpose build tools
1393#
1394.if !defined(NO_SHARE)
1395_share=	share/syscons/scrnmaps
1396.endif
1397
1398.if ${MK_GCC} != "no"
1399_gcc_tools= gnu/usr.bin/cc/cc_tools
1400.endif
1401
1402.if ${MK_RESCUE} != "no"
1403_rescue= rescue/rescue
1404.endif
1405
1406build-tools: .MAKE
1407.for _tool in \
1408    bin/csh \
1409    bin/sh \
1410    ${_rescue} \
1411    ${LOCAL_TOOL_DIRS} \
1412    lib/ncurses/ncurses \
1413    lib/ncurses/ncursesw \
1414    ${_share} \
1415    usr.bin/awk \
1416    lib/libmagic \
1417    usr.bin/mkesdb_static \
1418    usr.bin/mkcsmapper_static \
1419    usr.bin/vi/catalog
1420	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1421		cd ${.CURDIR}/${_tool} && \
1422		${MAKE} DIRPRFX=${_tool}/ obj && \
1423		${MAKE} DIRPRFX=${_tool}/ build-tools
1424.endfor
1425.for _tool in \
1426    ${_gcc_tools}
1427	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1428		cd ${.CURDIR}/${_tool} && \
1429		${MAKE} DIRPRFX=${_tool}/ obj && \
1430		${MAKE} DIRPRFX=${_tool}/ depend && \
1431		${MAKE} DIRPRFX=${_tool}/ all
1432.endfor
1433
1434
1435#
1436# kernel-tools: Build kernel-building tools
1437#
1438kernel-tools: .MAKE
1439	mkdir -p ${MAKEOBJDIRPREFIX}/usr
1440	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1441	    -p ${MAKEOBJDIRPREFIX}/usr >/dev/null
1442
1443#
1444# cross-tools: Build cross-building tools
1445#
1446.if !defined(TARGET_ARCH) && defined(XDEV_ARCH)
1447TARGET_ARCH=	${XDEV_ARCH}
1448.endif
1449.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1450.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1451_btxld=		usr.sbin/btxld
1452.endif
1453.endif
1454.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1455.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1456_crunchide=	usr.sbin/crunch/crunchide
1457.endif
1458.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1459_kgzip=		usr.sbin/kgzip
1460.endif
1461.endif
1462
1463.if ${XAS:M/*} == "" && ${MK_BINUTILS} != "no"
1464_binutils=	gnu/usr.bin/binutils
1465.endif
1466
1467# If an full path to an external cross compiler is given, don't build
1468# a cross compiler.
1469.if ${XCC:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1470.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
1471_clang=		usr.bin/clang
1472_clang_libs=	lib/clang
1473.else
1474_cc=		gnu/usr.bin/cc
1475.endif
1476
1477# The boot2 for pc98 requires gcc.
1478.if ${TARGET} == "pc98"
1479_cc=		gnu/usr.bin/cc
1480.endif
1481.endif
1482
1483cross-tools: .MAKE
1484.for _tool in \
1485    ${_clang_libs} \
1486    ${_clang} \
1487    ${_binutils} \
1488    ${_cc} \
1489    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1490    ${_btxld} \
1491    ${_crunchide} \
1492    ${_kgzip}
1493	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1494		cd ${.CURDIR}/${_tool} && \
1495		${MAKE} DIRPRFX=${_tool}/ obj && \
1496		${MAKE} DIRPRFX=${_tool}/ depend && \
1497		${MAKE} DIRPRFX=${_tool}/ all && \
1498		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1499.endfor
1500
1501NXBENV=		MAKEOBJDIRPREFIX=${OBJTREE}/nxb \
1502		INSTALL="sh ${.CURDIR}/tools/install.sh" \
1503		VERSION="${VERSION}"
1504NXBMAKE=	${NXBENV} ${MAKE} \
1505		TBLGEN=${OBJTREE}/nxb-bin/usr/bin/tblgen \
1506		CLANG_TBLGEN=${OBJTREE}/nxb-bin/usr/bin/clang-tblgen \
1507		MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
1508		-DWITHOUT_GDB -DNO_TESTS \
1509		SSP_CFLAGS= \
1510		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
1511		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
1512		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF \
1513		-DWITHOUT_CLANG_FULL -DWITHOUT_LLDB
1514
1515native-xtools: .MAKE
1516	mkdir -p ${OBJTREE}/nxb-bin/bin
1517	mkdir -p ${OBJTREE}/nxb-bin/sbin
1518	mkdir -p ${OBJTREE}/nxb-bin/usr
1519	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1520	    -p ${OBJTREE}/nxb-bin/usr >/dev/null
1521	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1522	    -p ${OBJTREE}/nxb-bin/usr/include >/dev/null
1523.for _tool in \
1524    bin/cat \
1525    bin/chmod \
1526    bin/cp \
1527    bin/csh \
1528    bin/echo \
1529    bin/expr \
1530    bin/hostname \
1531    bin/ln \
1532    bin/ls \
1533    bin/mkdir \
1534    bin/mv \
1535    bin/ps \
1536    bin/realpath \
1537    bin/rm \
1538    bin/rmdir \
1539    bin/sh \
1540    bin/sleep \
1541    ${_clang_tblgen} \
1542    usr.bin/ar \
1543    ${_binutils} \
1544    ${_cc} \
1545    ${_gcc_tools} \
1546    ${_clang_libs} \
1547    ${_clang} \
1548    sbin/md5 \
1549    sbin/sysctl \
1550    gnu/usr.bin/diff \
1551    usr.bin/awk \
1552    usr.bin/basename \
1553    usr.bin/bmake \
1554    usr.bin/bzip2 \
1555    usr.bin/cmp \
1556    usr.bin/dirname \
1557    usr.bin/env \
1558    usr.bin/fetch \
1559    usr.bin/find \
1560    usr.bin/grep \
1561    usr.bin/gzip \
1562    usr.bin/id \
1563    usr.bin/lex \
1564    usr.bin/lorder \
1565    usr.bin/mktemp \
1566    usr.bin/mt \
1567    usr.bin/patch \
1568    usr.bin/sed \
1569    usr.bin/sort \
1570    usr.bin/tar \
1571    usr.bin/touch \
1572    usr.bin/tr \
1573    usr.bin/true \
1574    usr.bin/uniq \
1575    usr.bin/unzip \
1576    usr.bin/xargs \
1577    usr.bin/xinstall \
1578    usr.bin/xz \
1579    usr.bin/yacc \
1580    usr.sbin/chown
1581	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1582		cd ${.CURDIR}/${_tool} && \
1583		${NXBMAKE} DIRPRFX=${_tool}/ obj && \
1584		${NXBMAKE} DIRPRFX=${_tool}/ depend && \
1585		${NXBMAKE} DIRPRFX=${_tool}/ all && \
1586		${NXBMAKE} DIRPRFX=${_tool}/ DESTDIR=${OBJTREE}/nxb-bin install
1587.endfor
1588
1589#
1590# hierarchy - ensure that all the needed directories are present
1591#
1592hierarchy hier: .MAKE
1593	cd ${.CURDIR}/etc && ${HMAKE} distrib-dirs
1594
1595#
1596# libraries - build all libraries, and install them under ${DESTDIR}.
1597#
1598# The list of libraries with dependents (${_prebuild_libs}) and their
1599# interdependencies (__L) are built automatically by the
1600# ${.CURDIR}/tools/make_libdeps.sh script.
1601#
1602libraries: .MAKE
1603	cd ${.CURDIR} && \
1604	    ${MAKE} -f Makefile.inc1 _prereq_libs && \
1605	    ${MAKE} -f Makefile.inc1 _startup_libs && \
1606	    ${MAKE} -f Makefile.inc1 _prebuild_libs && \
1607	    ${MAKE} -f Makefile.inc1 _generic_libs
1608
1609#
1610# static libgcc.a prerequisite for shared libc
1611#
1612_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1613
1614# These dependencies are not automatically generated:
1615#
1616# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1617# all shared libraries for ELF.
1618#
1619_startup_libs=	gnu/lib/csu
1620.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1621_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1622.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1623_startup_libs+=	lib/csu/${MACHINE_ARCH}
1624.else
1625_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1626.endif
1627_startup_libs+=	gnu/lib/libgcc
1628_startup_libs+=	lib/libcompiler_rt
1629_startup_libs+=	lib/libc
1630_startup_libs+=	lib/libc_nonshared
1631.if ${MK_LIBCPLUSPLUS} != "no"
1632_startup_libs+=	lib/libcxxrt
1633.endif
1634
1635gnu/lib/libgcc__L: lib/libc__L
1636gnu/lib/libgcc__L: lib/libc_nonshared__L
1637.if ${MK_LIBCPLUSPLUS} != "no"
1638lib/libcxxrt__L: gnu/lib/libgcc__L
1639.endif
1640
1641_prebuild_libs=	${_kerberos5_lib_libasn1} \
1642		${_kerberos5_lib_libhdb} \
1643		${_kerberos5_lib_libheimbase} \
1644		${_kerberos5_lib_libheimntlm} \
1645		${_kerberos5_lib_libheimsqlite} \
1646		${_kerberos5_lib_libheimipcc} \
1647		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1648		${_kerberos5_lib_libroken} \
1649		${_kerberos5_lib_libwind} \
1650		${_lib_atf} \
1651		lib/libbz2 ${_libcom_err} lib/libcrypt \
1652		lib/libelf lib/libexpat \
1653		lib/libfigpar \
1654		${_lib_libgssapi} ${_lib_libipx} \
1655		lib/libkiconv lib/libkvm lib/liblzma lib/libmd \
1656		lib/ncurses/ncurses lib/ncurses/ncursesw \
1657		lib/libopie lib/libpam ${_lib_libthr} \
1658		${_lib_libradius} lib/libsbuf lib/libtacplus \
1659		lib/libgeom \
1660		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1661		${_cddl_lib_libuutil} \
1662		${_cddl_lib_libavl} \
1663		${_cddl_lib_libzfs_core} \
1664		lib/libutil ${_lib_libypclnt} lib/libz lib/msun \
1665		${_secure_lib_libcrypto} ${_lib_libldns} \
1666		${_secure_lib_libssh} ${_secure_lib_libssl} \
1667		gnu/lib/libdialog
1668.if ${MK_GNUCXX} != no
1669_prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
1670gnu/lib/libstdc++__L: lib/msun__L
1671.endif
1672
1673.if ${MK_LIBCPLUSPLUS} != "no"
1674_prebuild_libs+= lib/libc++
1675.endif
1676
1677lib/libgeom__L: lib/libexpat__L
1678
1679.if defined(WITH_ATF) || ${MK_TESTS} != "no"
1680.if !defined(WITH_ATF)
1681# Ensure that the ATF libraries will be built during make libraries, even
1682# though they will have -DNO_TESTS
1683MAKE+=		-DWITH_ATF
1684.endif
1685_lib_atf=	lib/atf
1686.if ${MK_GNUCXX} != no
1687lib/atf__L: gnu/lib/libstdc++__L
1688.endif
1689.if ${MK_LIBCPLUSPLUS} != "no"
1690lib/atf__L: lib/libc++__L lib/msun__L
1691.endif
1692.endif
1693
1694.if ${MK_LIBTHR} != "no"
1695_lib_libthr=	lib/libthr
1696.endif
1697
1698.if ${MK_RADIUS_SUPPORT} != "no"
1699_lib_libradius=	lib/libradius
1700.endif
1701
1702.if ${MK_OFED} != "no"
1703_ofed_lib=	contrib/ofed/usr.lib/
1704.endif
1705
1706_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1707.for _DIR in ${LOCAL_LIB_DIRS}
1708.if exists(${.CURDIR}/${_DIR}/Makefile)
1709_generic_libs+= ${_DIR}
1710.endif
1711.endfor
1712
1713lib/libopie__L lib/libtacplus__L: lib/libmd__L
1714
1715.if ${MK_CDDL} != "no"
1716_cddl_lib_libumem= cddl/lib/libumem
1717_cddl_lib_libnvpair= cddl/lib/libnvpair
1718_cddl_lib_libavl= cddl/lib/libavl
1719_cddl_lib_libuutil= cddl/lib/libuutil
1720_cddl_lib_libzfs_core= cddl/lib/libzfs_core
1721_cddl_lib= cddl/lib
1722cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1723cddl/lib/libzfs__L: lib/libgeom__L
1724.endif
1725
1726.if ${MK_CRYPT} != "no"
1727.if ${MK_OPENSSL} != "no"
1728_secure_lib_libcrypto= secure/lib/libcrypto
1729_secure_lib_libssl= secure/lib/libssl
1730lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1731.if ${MK_LDNS} != "no"
1732_lib_libldns= lib/libldns
1733lib/libldns__L: secure/lib/libcrypto__L
1734.endif
1735.if ${MK_OPENSSH} != "no"
1736_secure_lib_libssh= secure/lib/libssh
1737secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1738.if ${MK_LDNS} != "no"
1739secure/lib/libssh__L: lib/libldns__L
1740.endif
1741.if ${MK_KERBEROS_SUPPORT} != "no"
1742secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1743    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1744    lib/libmd__L kerberos5/lib/libroken__L
1745.endif
1746.endif
1747.endif
1748_secure_lib=	secure/lib
1749.endif
1750
1751.if ${MK_KERBEROS} != "no"
1752kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1753kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1754    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1755    kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L 
1756kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1757    kerberos5/lib/libroken__L lib/libcom_err__L
1758kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1759    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1760kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1761    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1762    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1763    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1764kerberos5/lib/libroken__L: lib/libcrypt__L
1765kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1766kerberos5/lib/libheimbase__L: lib/libthr__L
1767kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1768kerberos5/lib/libheimsqlite__L: lib/libthr__L
1769.endif
1770
1771.if ${MK_GSSAPI} != "no"
1772_lib_libgssapi=	lib/libgssapi
1773.endif
1774
1775.if ${MK_IPX} != "no"
1776_lib_libipx=	lib/libipx
1777.endif
1778
1779.if ${MK_KERBEROS} != "no"
1780_kerberos5_lib=	kerberos5/lib
1781_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1782_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1783_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1784_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1785_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1786_kerberos5_lib_libroken= kerberos5/lib/libroken
1787_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1788_kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1789_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1790_kerberos5_lib_libwind= kerberos5/lib/libwind
1791_libcom_err= lib/libcom_err
1792.endif
1793
1794.if ${MK_NIS} != "no"
1795_lib_libypclnt=	lib/libypclnt
1796.endif
1797
1798.if ${MK_OPENSSL} == "no"
1799lib/libradius__L: lib/libmd__L
1800.endif
1801
1802gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
1803
1804.for _lib in ${_prereq_libs}
1805${_lib}__PL: .PHONY .MAKE
1806.if exists(${.CURDIR}/${_lib})
1807	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1808		cd ${.CURDIR}/${_lib} && \
1809		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ obj && \
1810		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ depend && \
1811		${MAKE} -DNO_TESTS -DNO_PROFILE -DNO_PIC \
1812		    DIRPRFX=${_lib}/ all && \
1813		${MAKE} -DNO_TESTS -DNO_PROFILE -DNO_PIC \
1814		    DIRPRFX=${_lib}/ install
1815.endif
1816.endfor
1817
1818.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1819${_lib}__L: .PHONY .MAKE
1820.if exists(${.CURDIR}/${_lib})
1821	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1822		cd ${.CURDIR}/${_lib} && \
1823		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ obj && \
1824		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ depend && \
1825		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ all && \
1826		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ install
1827.endif
1828.endfor
1829
1830# libpam is special: we need to build static PAM modules before
1831# static PAM library, and dynamic PAM library before dynamic PAM
1832# modules.
1833lib/libpam__L: .PHONY .MAKE
1834	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1835		cd ${.CURDIR}/lib/libpam && \
1836		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ obj && \
1837		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ depend && \
1838		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ \
1839		    -D_NO_LIBPAM_SO_YET all && \
1840		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ \
1841		    -D_NO_LIBPAM_SO_YET install
1842
1843_prereq_libs: ${_prereq_libs:S/$/__PL/}
1844_startup_libs: ${_startup_libs:S/$/__L/}
1845_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1846_generic_libs: ${_generic_libs:S/$/__L/}
1847
1848.for __target in all clean cleandepend cleandir depend includes obj
1849.for entry in ${SUBDIR}
1850${entry}.${__target}__D: .PHONY .MAKE
1851	${_+_}@set -e; if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1852		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1853		edir=${entry}.${MACHINE_ARCH}; \
1854		cd ${.CURDIR}/$${edir}; \
1855	else \
1856		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1857		edir=${entry}; \
1858		cd ${.CURDIR}/$${edir}; \
1859	fi; \
1860	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1861.endfor
1862par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1863.endfor
1864
1865.include <bsd.subdir.mk>
1866
1867.if make(check-old) || make(check-old-dirs) || \
1868    make(check-old-files) || make(check-old-libs) || \
1869    make(delete-old) || make(delete-old-dirs) || \
1870    make(delete-old-files) || make(delete-old-libs)
1871
1872#
1873# check for / delete old files section
1874#
1875
1876.include "ObsoleteFiles.inc"
1877
1878OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1879else you can not start such an application. Consult UPDATING for more \
1880information regarding how to cope with the removal/revision bump of a \
1881specific library."
1882
1883.if !defined(BATCH_DELETE_OLD_FILES)
1884RM_I=-i
1885.else
1886RM_I=-v
1887.endif
1888
1889delete-old-files:
1890	@echo ">>> Removing old files (only deletes safe to delete libs)"
1891# Ask for every old file if the user really wants to remove it.
1892# It's annoying, but better safe than sorry.
1893# NB: We cannot pass the list of OLD_FILES as a parameter because the
1894# argument list will get too long. Using .for/.endfor make "loops" will make
1895# the Makefile parser segfault.
1896	@exec 3<&0; \
1897	cd ${.CURDIR}; \
1898	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1899	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1900	while read file; do \
1901		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1902			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1903			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1904		fi; \
1905	done
1906# Remove catpages without corresponding manpages.
1907	@exec 3<&0; \
1908	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1909	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1910	while read catpage; do \
1911		read manpage; \
1912		if [ ! -e "$${manpage}" ]; then \
1913			rm ${RM_I} $${catpage} <&3; \
1914	        fi; \
1915	done
1916	@echo ">>> Old files removed"
1917
1918check-old-files:
1919	@echo ">>> Checking for old files"
1920	@cd ${.CURDIR}; \
1921	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1922	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1923	while read file; do \
1924		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1925		 	echo "${DESTDIR}/$${file}"; \
1926		fi; \
1927	done
1928# Check for catpages without corresponding manpages.
1929	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1930	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1931	while read catpage; do \
1932		read manpage; \
1933		if [ ! -e "$${manpage}" ]; then \
1934			echo $${catpage}; \
1935	        fi; \
1936	done
1937
1938delete-old-libs:
1939	@echo ">>> Removing old libraries"
1940	@echo "${OLD_LIBS_MESSAGE}" | fmt
1941	@exec 3<&0; \
1942	cd ${.CURDIR}; \
1943	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1944	    -V OLD_LIBS | xargs -n1 | \
1945	while read file; do \
1946		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1947			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1948			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1949		fi; \
1950		for ext in debug symbols; do \
1951		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
1952		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1953			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
1954			      <&3; \
1955		  fi; \
1956		done; \
1957	done
1958	@echo ">>> Old libraries removed"
1959
1960check-old-libs:
1961	@echo ">>> Checking for old libraries"
1962	@cd ${.CURDIR}; \
1963	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1964	    -V OLD_LIBS | xargs -n1 | \
1965	while read file; do \
1966		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1967			echo "${DESTDIR}/$${file}"; \
1968		fi; \
1969		for ext in debug symbols; do \
1970		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1971			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
1972		  fi; \
1973		done; \
1974	done
1975
1976delete-old-dirs:
1977	@echo ">>> Removing old directories"
1978	@cd ${.CURDIR}; \
1979	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1980	    -V OLD_DIRS | xargs -n1 | sort -r | \
1981	while read dir; do \
1982		if [ -d "${DESTDIR}/$${dir}" ]; then \
1983			rmdir -v "${DESTDIR}/$${dir}" || true; \
1984		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1985			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1986		fi; \
1987	done
1988	@echo ">>> Old directories removed"
1989
1990check-old-dirs:
1991	@echo ">>> Checking for old directories"
1992	@cd ${.CURDIR}; \
1993	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1994	    -V OLD_DIRS | xargs -n1 | \
1995	while read dir; do \
1996		if [ -d "${DESTDIR}/$${dir}" ]; then \
1997			echo "${DESTDIR}/$${dir}"; \
1998		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1999			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2000		fi; \
2001	done
2002
2003delete-old: delete-old-files delete-old-dirs
2004	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
2005
2006check-old: check-old-files check-old-libs check-old-dirs
2007	@echo "To remove old files and directories run '${MAKE} delete-old'."
2008	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
2009
2010.endif
2011
2012#
2013# showconfig - show build configuration.
2014#
2015showconfig:
2016	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 2>&1 | grep ^MK_ | sort
2017
2018.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
2019DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
2020
2021.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
2022.if exists(${KERNCONFDIR}/${KERNCONF})
2023FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
2024	'${KERNCONFDIR}/${KERNCONF}' ; echo
2025.endif
2026.endif
2027
2028.endif
2029
2030.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
2031DTBOUTPUTPATH= ${.CURDIR}
2032.endif
2033
2034#
2035# Build 'standalone' Device Tree Blob
2036#
2037builddtb:
2038	@PATH=${TMPPATH} MACHINE=${TARGET} \
2039	${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
2040	    "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
2041
2042###############
2043
2044.if defined(XDEV) && defined(XDEV_ARCH)
2045
2046.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
2047XDEV_CPUTYPE?=${CPUTYPE}
2048.else
2049XDEV_CPUTYPE?=${TARGET_CPUTYPE}
2050.endif
2051
2052NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
2053	-DWITHOUT_MAN -DWITHOUT_NLS -DNO_PROFILE \
2054	-DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_TESTS -DNO_WARNS \
2055	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
2056	CPUTYPE=${XDEV_CPUTYPE}
2057
2058XDDIR=${XDEV_ARCH}-freebsd
2059XDTP?=/usr/${XDDIR}
2060.if ${XDTP:N/*}
2061.error XDTP variable should be an absolute path
2062.endif
2063
2064CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
2065	INSTALL="sh ${.CURDIR}/tools/install.sh"
2066CDENV= ${CDBENV} \
2067	_SHLIBDIRPREFIX=${XDDESTDIR} \
2068	TOOLS_PREFIX=${XDTP}
2069CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
2070	--sysroot=${XDDESTDIR}/ -B${XDDESTDIR}/usr/libexec \
2071	-B${XDDESTDIR}/usr/bin -B${XDDESTDIR}/usr/lib
2072CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CFLAGS}" \
2073	CPP="${CPP} ${CD2CFLAGS}" \
2074	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
2075
2076CDTMP=	${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
2077CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2078CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2079XDDESTDIR=${DESTDIR}/${XDTP}
2080.if !defined(OSREL)
2081OSREL!= uname -r | sed -e 's/[-(].*//'
2082.endif
2083
2084.ORDER: xdev-build xdev-install
2085xdev: xdev-build xdev-install
2086
2087.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2088xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2089
2090_xb-worldtmp:
2091	mkdir -p ${CDTMP}/usr
2092	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2093	    -p ${CDTMP}/usr >/dev/null
2094
2095_xb-bootstrap-tools:
2096.for _tool in \
2097    ${_clang_tblgen}
2098	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
2099	cd ${.CURDIR}/${_tool} && \
2100	${CDMAKE} DIRPRFX=${_tool}/ obj && \
2101	${CDMAKE} DIRPRFX=${_tool}/ depend && \
2102	${CDMAKE} DIRPRFX=${_tool}/ all && \
2103	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
2104.endfor
2105
2106_xb-build-tools:
2107	${_+_}@cd ${.CURDIR}; \
2108	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
2109
2110_xb-cross-tools:
2111.for _tool in \
2112    ${_binutils} \
2113    usr.bin/ar \
2114    ${_clang_libs} \
2115    ${_clang} \
2116    ${_cc}
2117	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
2118	cd ${.CURDIR}/${_tool} && \
2119	${CDMAKE} DIRPRFX=${_tool}/ obj && \
2120	${CDMAKE} DIRPRFX=${_tool}/ depend && \
2121	${CDMAKE} DIRPRFX=${_tool}/ all
2122.endfor
2123
2124_xi-mtree:
2125	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
2126	mkdir -p ${XDDESTDIR}
2127	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
2128	    -p ${XDDESTDIR} >/dev/null
2129	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2130	    -p ${XDDESTDIR}/usr >/dev/null
2131	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2132	    -p ${XDDESTDIR}/usr/include >/dev/null
2133.if ${MK_TESTS} != "no"
2134	mkdir -p ${XDDESTDIR}${TESTSBASE}
2135	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
2136	    -p ${XDDESTDIR}${TESTSBASE} >/dev/null
2137.endif
2138
2139.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
2140xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
2141
2142_xi-cross-tools:
2143	@echo "_xi-cross-tools"
2144.for _tool in \
2145    ${_binutils} \
2146    usr.bin/ar \
2147    ${_clang_libs} \
2148    ${_clang} \
2149    ${_cc}
2150	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
2151	cd ${.CURDIR}/${_tool}; \
2152	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
2153.endfor
2154
2155_xi-includes:
2156	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
2157		DESTDIR=${XDDESTDIR}
2158
2159_xi-libraries:
2160	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
2161		DESTDIR=${XDDESTDIR}
2162
2163_xi-links:
2164	${_+_}cd ${XDDESTDIR}/usr/bin; \
2165       mkdir -p ../../../../usr/bin; \
2166		for i in *; do \
2167			ln -sf ../../${XDTP}/usr/bin/$$i \
2168			    ../../../../usr/bin/${XDDIR}-$$i; \
2169			ln -sf ../../${XDTP}/usr/bin/$$i \
2170			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
2171		done
2172.else
2173xdev xdev-build xdev-install:
2174	@echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target"
2175.endif
2176