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