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