xref: /freebsd/Makefile.inc1 (revision 4ec234c813eed05c166859bba82c882e40826eb9)
1#
2# $FreeBSD$
3#
4# Make command line options:
5#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6#	-DNO_CLEAN do not clean at all
7#	-DDB_FROM_SRC use the user/group databases in src/etc instead of
8#	    the system database when installing.
9#	-DNO_SHARE do not go into share subdir
10#	-DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ}
11#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
14#	-DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
15#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
16#	-DNO_ROOT install without using root privilege
17#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
18#	-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
1373#
1374# cross-tools: Build cross-building tools
1375#
1376.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1377.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1378_btxld=		usr.sbin/btxld
1379.endif
1380.endif
1381.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1382.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1383_crunchide=	usr.sbin/crunch/crunchide
1384.endif
1385.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1386_kgzip=		usr.sbin/kgzip
1387.endif
1388.endif
1389
1390.if ${XAS:M/*} == "" && ${MK_BINUTILS} != "no"
1391_binutils=	gnu/usr.bin/binutils
1392.endif
1393
1394# If an full path to an external cross compiler is given, don't build
1395# a cross compiler.
1396.if ${XCC:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1397.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
1398_clang=		usr.bin/clang
1399_clang_libs=	lib/clang
1400.else
1401_cc=		gnu/usr.bin/cc
1402.endif
1403
1404# The boot2 for pc98 requires gcc.
1405.if ${TARGET} == "pc98"
1406_cc=		gnu/usr.bin/cc
1407.endif
1408.endif
1409
1410cross-tools: .MAKE
1411.for _tool in \
1412    ${_clang_libs} \
1413    ${_clang} \
1414    ${_binutils} \
1415    ${_cc} \
1416    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1417    ${_btxld} \
1418    ${_crunchide} \
1419    ${_kgzip}
1420	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1421		cd ${.CURDIR}/${_tool} && \
1422		${MAKE} DIRPRFX=${_tool}/ obj && \
1423		${MAKE} DIRPRFX=${_tool}/ depend && \
1424		${MAKE} DIRPRFX=${_tool}/ all && \
1425		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1426.endfor
1427
1428#
1429# hierarchy - ensure that all the needed directories are present
1430#
1431hierarchy hier:
1432	cd ${.CURDIR}/etc && ${HMAKE} distrib-dirs
1433
1434#
1435# libraries - build all libraries, and install them under ${DESTDIR}.
1436#
1437# The list of libraries with dependents (${_prebuild_libs}) and their
1438# interdependencies (__L) are built automatically by the
1439# ${.CURDIR}/tools/make_libdeps.sh script.
1440#
1441libraries: .MAKE
1442	cd ${.CURDIR} && \
1443	    ${MAKE} -f Makefile.inc1 _prereq_libs && \
1444	    ${MAKE} -f Makefile.inc1 _startup_libs && \
1445	    ${MAKE} -f Makefile.inc1 _prebuild_libs && \
1446	    ${MAKE} -f Makefile.inc1 _generic_libs
1447
1448#
1449# static libgcc.a prerequisite for shared libc
1450#
1451_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1452
1453# These dependencies are not automatically generated:
1454#
1455# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1456# all shared libraries for ELF.
1457#
1458_startup_libs=	gnu/lib/csu
1459.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1460_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1461.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1462_startup_libs+=	lib/csu/${MACHINE_ARCH}
1463.else
1464_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1465.endif
1466_startup_libs+=	gnu/lib/libgcc
1467_startup_libs+=	lib/libcompiler_rt
1468_startup_libs+=	lib/libc
1469_startup_libs+=	lib/libc_nonshared
1470.if ${MK_LIBCPLUSPLUS} != "no"
1471_startup_libs+=	lib/libcxxrt
1472.endif
1473
1474gnu/lib/libgcc__L: lib/libc__L
1475gnu/lib/libgcc__L: lib/libc_nonshared__L
1476.if ${MK_LIBCPLUSPLUS} != "no"
1477lib/libcxxrt__L: gnu/lib/libgcc__L
1478.endif
1479
1480_prebuild_libs=	${_kerberos5_lib_libasn1} \
1481		${_kerberos5_lib_libhdb} \
1482		${_kerberos5_lib_libheimbase} \
1483		${_kerberos5_lib_libheimntlm} \
1484		${_kerberos5_lib_libheimsqlite} \
1485		${_kerberos5_lib_libheimipcc} \
1486		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1487		${_kerberos5_lib_libroken} \
1488		${_kerberos5_lib_libwind} \
1489		${_lib_atf} \
1490		lib/libbz2 ${_libcom_err} lib/libcrypt \
1491		lib/libelf lib/libexpat \
1492		${_lib_libgssapi} ${_lib_libipx} \
1493		lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
1494		${_lib_libcapsicum} \
1495		lib/ncurses/ncurses lib/ncurses/ncursesw \
1496		lib/libopie lib/libpam ${_lib_libthr} \
1497		lib/libradius lib/libsbuf lib/libtacplus \
1498		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1499		${_cddl_lib_libzfs_core} \
1500		lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
1501		${_secure_lib_libcrypto} ${_lib_libldns} \
1502		${_secure_lib_libssh} ${_secure_lib_libssl}
1503
1504.if ${MK_TESTS} != "no"
1505_lib_atf=	lib/atf
1506.endif
1507
1508.if ${MK_LIBTHR} != "no"
1509_lib_libthr=	lib/libthr
1510.endif
1511
1512.if ${MK_OFED} != "no"
1513_ofed_lib=	contrib/ofed/usr.lib/
1514.endif
1515
1516.if ${MK_CASPER} != "no"
1517_lib_libcapsicum=lib/libcapsicum
1518.endif
1519
1520lib/libcapsicum__L: lib/libnv__L
1521lib/libpjdlog__L: lib/libutil__L
1522
1523_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1524.for _DIR in ${LOCAL_LIB_DIRS}
1525.if exists(${.CURDIR}/${_DIR}/Makefile)
1526_generic_libs+= ${_DIR}
1527.endif
1528.endfor
1529
1530lib/libopie__L lib/libtacplus__L: lib/libmd__L
1531
1532.if ${MK_CDDL} != "no"
1533_cddl_lib_libumem= cddl/lib/libumem
1534_cddl_lib_libnvpair= cddl/lib/libnvpair
1535_cddl_lib_libzfs_core= cddl/lib/libzfs_core
1536_cddl_lib= cddl/lib
1537cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1538.endif
1539
1540.if ${MK_CRYPT} != "no"
1541.if ${MK_OPENSSL} != "no"
1542_secure_lib_libcrypto= secure/lib/libcrypto
1543_secure_lib_libssl= secure/lib/libssl
1544lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1545.if ${MK_LDNS} != "no"
1546_lib_libldns= lib/libldns
1547lib/libldns__L: secure/lib/libcrypto__L
1548.endif
1549.if ${MK_OPENSSH} != "no"
1550_secure_lib_libssh= secure/lib/libssh
1551secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1552.if ${MK_LDNS} != "no"
1553secure/lib/libssh__L: lib/libldns__L
1554.endif
1555.if ${MK_KERBEROS_SUPPORT} != "no"
1556secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1557    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1558    lib/libmd__L kerberos5/lib/libroken__L
1559.endif
1560.endif
1561.endif
1562_secure_lib=	secure/lib
1563.endif
1564
1565.if ${MK_KERBEROS} != "no"
1566kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1567kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1568    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1569    kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L
1570kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1571    kerberos5/lib/libroken__L lib/libcom_err__L
1572kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1573    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1574kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1575    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1576    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1577    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1578kerberos5/lib/libroken__L: lib/libcrypt__L
1579kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1580kerberos5/lib/libheimbase__L: lib/libthr__L
1581kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1582kerberos5/lib/libheimsqlite__L: lib/libthr__L
1583.endif
1584
1585.if ${MK_GSSAPI} != "no"
1586_lib_libgssapi=	lib/libgssapi
1587.endif
1588
1589.if ${MK_IPX} != "no"
1590_lib_libipx=	lib/libipx
1591.endif
1592
1593.if ${MK_KERBEROS} != "no"
1594_kerberos5_lib=	kerberos5/lib
1595_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1596_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1597_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1598_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1599_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1600_kerberos5_lib_libroken= kerberos5/lib/libroken
1601_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1602_kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1603_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1604_kerberos5_lib_libwind= kerberos5/lib/libwind
1605_libcom_err= lib/libcom_err
1606.endif
1607
1608.if ${MK_NIS} != "no"
1609_lib_libypclnt=	lib/libypclnt
1610.endif
1611
1612.if ${MK_OPENSSL} == "no"
1613lib/libradius__L: lib/libmd__L
1614.endif
1615
1616.for _lib in ${_prereq_libs}
1617${_lib}__PL: .PHONY .MAKE
1618.if exists(${.CURDIR}/${_lib})
1619	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1620		cd ${.CURDIR}/${_lib} && \
1621		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ obj && \
1622		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ depend && \
1623		${MAKE} -DNO_TESTS -DNO_PROFILE -DNO_PIC \
1624		    DIRPRFX=${_lib}/ all && \
1625		${MAKE} -DNO_TESTS -DNO_PROFILE -DNO_PIC \
1626		    DIRPRFX=${_lib}/ install
1627.endif
1628.endfor
1629
1630.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1631${_lib}__L: .PHONY .MAKE
1632.if exists(${.CURDIR}/${_lib})
1633	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1634		cd ${.CURDIR}/${_lib} && \
1635		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ obj && \
1636		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ depend && \
1637		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ all && \
1638		${MAKE} -DNO_TESTS DIRPRFX=${_lib}/ install
1639.endif
1640.endfor
1641
1642# libpam is special: we need to build static PAM modules before
1643# static PAM library, and dynamic PAM library before dynamic PAM
1644# modules.
1645lib/libpam__L: .PHONY .MAKE
1646	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1647		cd ${.CURDIR}/lib/libpam && \
1648		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ obj && \
1649		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ depend && \
1650		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ \
1651		    -D_NO_LIBPAM_SO_YET all && \
1652		${MAKE} -DNO_TESTS DIRPRFX=lib/libpam/ \
1653		    -D_NO_LIBPAM_SO_YET install
1654
1655_prereq_libs: ${_prereq_libs:S/$/__PL/}
1656_startup_libs: ${_startup_libs:S/$/__L/}
1657_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1658_generic_libs: ${_generic_libs:S/$/__L/}
1659
1660.for __target in all clean cleandepend cleandir depend includes obj
1661.for entry in ${SUBDIR}
1662${entry}.${__target}__D: .PHONY .MAKE
1663	${_+_}@set -e; if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1664		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1665		edir=${entry}.${MACHINE_ARCH}; \
1666		cd ${.CURDIR}/$${edir}; \
1667	else \
1668		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1669		edir=${entry}; \
1670		cd ${.CURDIR}/$${edir}; \
1671	fi; \
1672	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1673.endfor
1674par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1675.endfor
1676
1677.include <bsd.subdir.mk>
1678
1679.if make(check-old) || make(check-old-dirs) || \
1680    make(check-old-files) || make(check-old-libs) || \
1681    make(delete-old) || make(delete-old-dirs) || \
1682    make(delete-old-files) || make(delete-old-libs)
1683
1684#
1685# check for / delete old files section
1686#
1687
1688.include "ObsoleteFiles.inc"
1689
1690OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1691else you can not start such an application. Consult UPDATING for more \
1692information regarding how to cope with the removal/revision bump of a \
1693specific library."
1694
1695.if !defined(BATCH_DELETE_OLD_FILES)
1696RM_I=-i
1697.else
1698RM_I=-v
1699.endif
1700
1701delete-old-files:
1702	@echo ">>> Removing old files (only deletes safe to delete libs)"
1703# Ask for every old file if the user really wants to remove it.
1704# It's annoying, but better safe than sorry.
1705# NB: We cannot pass the list of OLD_FILES as a parameter because the
1706# argument list will get too long. Using .for/.endfor make "loops" will make
1707# the Makefile parser segfault.
1708	@exec 3<&0; \
1709	cd ${.CURDIR}; \
1710	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1711	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1712	while read file; do \
1713		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1714			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1715			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1716		fi; \
1717	done
1718# Remove catpages without corresponding manpages.
1719	@exec 3<&0; \
1720	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1721	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1722	while read catpage; do \
1723		read manpage; \
1724		if [ ! -e "$${manpage}" ]; then \
1725			rm ${RM_I} $${catpage} <&3; \
1726	        fi; \
1727	done
1728	@echo ">>> Old files removed"
1729
1730check-old-files:
1731	@echo ">>> Checking for old files"
1732	@cd ${.CURDIR}; \
1733	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1734	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1735	while read file; do \
1736		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1737		 	echo "${DESTDIR}/$${file}"; \
1738		fi; \
1739	done
1740# Check for catpages without corresponding manpages.
1741	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1742	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1743	while read catpage; do \
1744		read manpage; \
1745		if [ ! -e "$${manpage}" ]; then \
1746			echo $${catpage}; \
1747	        fi; \
1748	done
1749
1750delete-old-libs:
1751	@echo ">>> Removing old libraries"
1752	@echo "${OLD_LIBS_MESSAGE}" | fmt
1753	@exec 3<&0; \
1754	cd ${.CURDIR}; \
1755	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1756	    -V OLD_LIBS | xargs -n1 | \
1757	while read file; do \
1758		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1759			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1760			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1761		fi; \
1762		for ext in debug symbols; do \
1763		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
1764		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1765			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
1766			      <&3; \
1767		  fi; \
1768		done; \
1769	done
1770	@echo ">>> Old libraries removed"
1771
1772check-old-libs:
1773	@echo ">>> Checking for old libraries"
1774	@cd ${.CURDIR}; \
1775	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1776	    -V OLD_LIBS | xargs -n1 | \
1777	while read file; do \
1778		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1779			echo "${DESTDIR}/$${file}"; \
1780		fi; \
1781		for ext in debug symbols; do \
1782		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1783			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
1784		  fi; \
1785		done; \
1786	done
1787
1788delete-old-dirs:
1789	@echo ">>> Removing old directories"
1790	@cd ${.CURDIR}; \
1791	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1792	    -V OLD_DIRS | xargs -n1 | sort -r | \
1793	while read dir; do \
1794		if [ -d "${DESTDIR}/$${dir}" ]; then \
1795			rmdir -v "${DESTDIR}/$${dir}" || true; \
1796		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1797			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1798		fi; \
1799	done
1800	@echo ">>> Old directories removed"
1801
1802check-old-dirs:
1803	@echo ">>> Checking for old directories"
1804	@cd ${.CURDIR}; \
1805	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1806	    -V OLD_DIRS | xargs -n1 | \
1807	while read dir; do \
1808		if [ -d "${DESTDIR}/$${dir}" ]; then \
1809			echo "${DESTDIR}/$${dir}"; \
1810		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1811			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1812		fi; \
1813	done
1814
1815delete-old: delete-old-files delete-old-dirs
1816	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1817
1818check-old: check-old-files check-old-libs check-old-dirs
1819	@echo "To remove old files and directories run '${MAKE} delete-old'."
1820	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1821
1822.endif
1823
1824#
1825# showconfig - show build configuration.
1826#
1827showconfig:
1828	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 2>&1 | grep ^MK_ | sort
1829
1830.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
1831DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
1832
1833.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
1834.if exists(${KERNCONFDIR}/${KERNCONF})
1835FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
1836	${KERNCONFDIR}/${KERNCONF} ; echo
1837.endif
1838.endif
1839
1840.endif
1841
1842.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
1843DTBOUTPUTPATH= ${.CURDIR}
1844.endif
1845
1846#
1847# Build 'standalone' Device Tree Blob
1848#
1849builddtb:
1850	@if [ "${FDT_DTS_FILE}" = "" ]; then \
1851		echo "ERROR: FDT_DTS_FILE must be specified!"; \
1852		exit 1; \
1853	fi;	\
1854	if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ]; then \
1855		echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \
1856			exist!"; \
1857		exit 1;	\
1858	fi;	\
1859	if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then	\
1860		echo "WARNING: DTB will be placed in the current working \
1861			directory"; \
1862	fi
1863	@PATH=${TMPPATH} \
1864	dtc -O dtb -o \
1865	    ${DTBOUTPUTPATH}/`echo ${FDT_DTS_FILE} | cut -d. -f1`.dtb -b 0 \
1866	    -p 1024 ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE}
1867
1868###############
1869
1870.if defined(XDEV) && defined(XDEV_ARCH)
1871
1872.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
1873XDEV_CPUTYPE?=${CPUTYPE}
1874.else
1875XDEV_CPUTYPE?=${TARGET_CPUTYPE}
1876.endif
1877
1878NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
1879	-DWITHOUT_MAN -DWITHOUT_NLS -DNO_PROFILE \
1880	-DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \
1881	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
1882	CPUTYPE=${XDEV_CPUTYPE}
1883
1884XDDIR=${XDEV_ARCH}-freebsd
1885XDTP=usr/${XDDIR}
1886CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
1887	INSTALL="sh ${.CURDIR}/tools/install.sh"
1888CDENV= ${CDBENV} \
1889	_SHLIBDIRPREFIX=${XDDESTDIR} \
1890	TOOLS_PREFIX=${XDDESTDIR}
1891CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
1892	-B${XDDESTDIR}/usr/lib
1893CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" \
1894	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1895
1896CDTMP=	${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
1897CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1898CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1899XDDESTDIR=${DESTDIR}/${XDTP}
1900.if !defined(OSREL)
1901OSREL!= uname -r | sed -e 's/[-(].*//'
1902.endif
1903
1904.ORDER: xdev-build xdev-install
1905xdev: xdev-build xdev-install
1906
1907.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
1908xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
1909
1910_xb-worldtmp:
1911	mkdir -p ${CDTMP}/usr
1912	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1913	    -p ${CDTMP}/usr >/dev/null
1914
1915_xb-bootstrap-tools:
1916.for _tool in \
1917    ${_clang_tblgen}
1918	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1919	cd ${.CURDIR}/${_tool} && \
1920	${CDMAKE} DIRPRFX=${_tool}/ obj && \
1921	${CDMAKE} DIRPRFX=${_tool}/ depend && \
1922	${CDMAKE} DIRPRFX=${_tool}/ all && \
1923	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
1924.endfor
1925
1926_xb-build-tools:
1927	${_+_}@cd ${.CURDIR}; \
1928	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1929
1930_xb-cross-tools:
1931.for _tool in \
1932    gnu/usr.bin/binutils \
1933    gnu/usr.bin/cc \
1934    usr.bin/ar \
1935    ${_clang_libs} \
1936    ${_clang}
1937	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1938	cd ${.CURDIR}/${_tool} && \
1939	${CDMAKE} DIRPRFX=${_tool}/ obj && \
1940	${CDMAKE} DIRPRFX=${_tool}/ depend && \
1941	${CDMAKE} DIRPRFX=${_tool}/ all
1942.endfor
1943
1944_xi-mtree:
1945	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1946	mkdir -p ${XDDESTDIR}
1947	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1948	    -p ${XDDESTDIR} >/dev/null
1949	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1950	    -p ${XDDESTDIR}/usr >/dev/null
1951	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1952	    -p ${XDDESTDIR}/usr/include >/dev/null
1953
1954.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1955xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1956
1957_xi-cross-tools:
1958	@echo "_xi-cross-tools"
1959.for _tool in \
1960    gnu/usr.bin/binutils \
1961    gnu/usr.bin/cc \
1962    usr.bin/ar \
1963    ${_clang}
1964	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1965	cd ${.CURDIR}/${_tool}; \
1966	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1967.endfor
1968
1969_xi-includes:
1970	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1971		DESTDIR=${XDDESTDIR}
1972
1973_xi-libraries:
1974	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1975		DESTDIR=${XDDESTDIR}
1976
1977_xi-links:
1978	${_+_}cd ${XDDESTDIR}/usr/bin; \
1979       mkdir -p ../../../../usr/bin; \
1980		for i in *; do \
1981			ln -sf ../../${XDTP}/usr/bin/$$i \
1982			    ../../../../usr/bin/${XDDIR}-$$i; \
1983			ln -sf ../../${XDTP}/usr/bin/$$i \
1984			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1985		done
1986.else
1987xdev xdev-build xdev-install:
1988	@echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target"
1989.endif
1990
1991buildkernel ${WMAKE_TGTS} ${.ALLTARGETS:M_*}: .MAKE
1992