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