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