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