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