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