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