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