Makefile.inc1 revision 297279
1#
2# $FreeBSD: head/Makefile.inc1 297279 2016-03-25 22:36:26Z bdrewery $
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:${SHELL})
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#	SUBDIR_OVERRIDE="list of dirs" to build rather than everything.
34#	    All libraries and includes, and some build tools will still build.
35
36#
37# The intended user-driven targets are:
38# buildworld  - rebuild *everything*, including glue to help do upgrades
39# installworld- install everything built by "buildworld"
40# checkworld  - run test suite on installed world
41# doxygen     - build API documentation of the kernel
42# update      - convenient way to update your source tree (eg: svn/svnup)
43#
44# Standard targets (not defined here) are documented in the makefiles in
45# /usr/share/mk.  These include:
46#		obj depend all install clean cleandepend cleanobj
47
48.if !defined(TARGET) || !defined(TARGET_ARCH)
49.error "Both TARGET and TARGET_ARCH must be defined."
50.endif
51
52LOCALBASE?=	/usr/local
53
54# Cross toolchain changes must be in effect before bsd.compiler.mk
55# so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
56.if defined(CROSS_TOOLCHAIN)
57.include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
58CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
59.endif
60.include <bsd.compiler.mk>		# don't depend on src.opts.mk doing it
61.include "share/mk/src.opts.mk"	
62
63# We must do lib/ and libexec/ before bin/ in case of a mid-install error to
64# keep the users system reasonably usable.  For static->dynamic root upgrades,
65# we don't want to install a dynamic binary without rtld and the needed
66# libraries.  More commonly, for dynamic root, we don't want to install a
67# binary that requires a newer library version that hasn't been installed yet.
68# This ordering is not a guarantee though.  The only guarantee of a working
69# system here would require fine-grained ordering of all components based
70# on their dependencies.
71SRCDIR?=	${.CURDIR}
72.if !empty(SUBDIR_OVERRIDE)
73SUBDIR=	${SUBDIR_OVERRIDE}
74.else
75SUBDIR=	lib libexec
76.if !defined(NO_ROOT) && (make(installworld) || make(install))
77# Ensure libraries are installed before progressing.
78SUBDIR+=.WAIT
79.endif
80SUBDIR+=bin
81.if ${MK_CDDL} != "no"
82SUBDIR+=cddl
83.endif
84SUBDIR+=gnu include
85.if ${MK_KERBEROS} != "no"
86SUBDIR+=kerberos5
87.endif
88.if ${MK_RESCUE} != "no"
89SUBDIR+=rescue
90.endif
91SUBDIR+=sbin
92.if ${MK_CRYPT} != "no"
93SUBDIR+=secure
94.endif
95.if !defined(NO_SHARE)
96SUBDIR+=share
97.endif
98SUBDIR+=sys usr.bin usr.sbin
99.if ${MK_TESTS} != "no"
100SUBDIR+=	tests
101.endif
102.if ${MK_OFED} != "no"
103SUBDIR+=contrib/ofed
104.endif
105
106# Local directories are last, since it is nice to at least get the base
107# system rebuilt before you do them.
108.for _DIR in ${LOCAL_DIRS}
109.if exists(${.CURDIR}/${_DIR}/Makefile)
110SUBDIR+=	${_DIR}
111.endif
112.endfor
113# Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
114# of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
115# LOCAL_LIB_DIRS=foo/lib to behave as expected.
116.for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
117_REDUNDENT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
118.endfor
119.for _DIR in ${LOCAL_LIB_DIRS}
120.if empty(_REDUNDENT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile)
121SUBDIR+=	${_DIR}
122.else
123.warning ${_DIR} not added to SUBDIR list.  See UPDATING 20141121.
124.endif
125.endfor
126
127# We must do etc/ last as it hooks into building the man whatis file
128# by calling 'makedb' in share/man.  This is only relevant for
129# install/distribute so they build the whatis file after every manpage is
130# installed.
131.if make(installworld) || make(install)
132SUBDIR+=.WAIT
133.endif
134SUBDIR+=etc
135
136.endif	# !empty(SUBDIR_OVERRIDE)
137
138.if defined(NOCLEAN)
139.warning NOCLEAN option is deprecated. Use NO_CLEAN instead.
140NO_CLEAN=	${NOCLEAN}
141.endif
142.if defined(NO_CLEANDIR)
143CLEANDIR=	clean cleandepend
144.else
145CLEANDIR=	cleandir
146.endif
147
148# FAST_DEPEND can skip depend tree-walks.
149.if ${MK_FAST_DEPEND} == "yes"
150NO_DEPEND=	t
151NO_KERNELDEPEND=t
152.endif
153# Ensure shell checks later have a value.
154.if defined(NO_DEPEND)
155NO_DEPEND=	t
156.endif
157
158LOCAL_TOOL_DIRS?=
159PACKAGEDIR?=	${DESTDIR}/${DISTDIR}
160
161.if empty(SHELL:M*csh*)
162BUILDENV_SHELL?=${SHELL}
163.else
164BUILDENV_SHELL?=/bin/sh
165.endif
166
167SVN?=		/usr/local/bin/svn
168SVNFLAGS?=	-r HEAD
169
170MAKEOBJDIRPREFIX?=	/usr/obj
171.if !defined(OSRELDATE)
172.if exists(/usr/include/osreldate.h)
173OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
174		/usr/include/osreldate.h
175.else
176OSRELDATE=	0
177.endif
178.export OSRELDATE
179.endif
180
181# Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
182.if !defined(VERSION)
183REVISION!=	MK_AUTO_OBJ=no ${MAKE} -C ${SRCDIR}/release -V REVISION
184BRANCH!=	MK_AUTO_OBJ=no ${MAKE} -C ${SRCDIR}/release -V BRANCH
185SRCRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
186		${SRCDIR}/sys/sys/param.h
187VERSION=	FreeBSD ${REVISION}-${BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
188.export VERSION
189.endif
190
191KNOWN_ARCHES?=	aarch64/arm64 \
192		amd64 \
193		arm \
194		armeb/arm \
195		armv6/arm \
196		armv6hf/arm \
197		i386 \
198		i386/pc98 \
199		mips \
200		mipsel/mips \
201		mips64el/mips \
202		mips64/mips \
203		mipsn32el/mips \
204		mipsn32/mips \
205		powerpc \
206		powerpc64/powerpc \
207		riscv64/riscv \
208		sparc64
209
210.if ${TARGET} == ${TARGET_ARCH}
211_t=		${TARGET}
212.else
213_t=		${TARGET_ARCH}/${TARGET}
214.endif
215.for _t in ${_t}
216.if empty(KNOWN_ARCHES:M${_t})
217.error Unknown target ${TARGET_ARCH}:${TARGET}.
218.endif
219.endfor
220
221.if ${TARGET} == ${MACHINE}
222TARGET_CPUTYPE?=${CPUTYPE}
223.else
224TARGET_CPUTYPE?=
225.endif
226
227.if !empty(TARGET_CPUTYPE)
228_TARGET_CPUTYPE=${TARGET_CPUTYPE}
229.else
230_TARGET_CPUTYPE=dummy
231.endif
232_CPUTYPE!=	MK_AUTO_OBJ=no MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
233		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
234.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
235.error CPUTYPE global should be set with ?=.
236.endif
237.if make(buildworld)
238BUILD_ARCH!=	uname -p
239.if ${MACHINE_ARCH} != ${BUILD_ARCH}
240.error To cross-build, set TARGET_ARCH.
241.endif
242.endif
243.if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
244OBJTREE=	${MAKEOBJDIRPREFIX}
245.else
246OBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
247.endif
248WORLDTMP=	${OBJTREE}${.CURDIR}/tmp
249BPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin
250XPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
251STRICTTMPPATH=	${BPATH}:${XPATH}
252TMPPATH=	${STRICTTMPPATH}:${PATH}
253
254#
255# Avoid running mktemp(1) unless actually needed.
256# It may not be functional, e.g., due to new ABI
257# when in the middle of installing over this system.
258#
259.if make(distributeworld) || make(installworld)
260INSTALLTMP!=	/usr/bin/mktemp -d -u -t install
261.endif
262
263#
264# Building a world goes through the following stages
265#
266# 1. legacy stage [BMAKE]
267#	This stage is responsible for creating compatibility
268#	shims that are needed by the bootstrap-tools,
269#	build-tools and cross-tools stages. These are generally
270#	APIs that tools from one of those three stages need to
271#	build that aren't present on the host.
272# 1. bootstrap-tools stage [BMAKE]
273#	This stage is responsible for creating programs that
274#	are needed for backward compatibility reasons. They
275#	are not built as cross-tools.
276# 2. build-tools stage [TMAKE]
277#	This stage is responsible for creating the object
278#	tree and building any tools that are needed during
279#	the build process. Some programs are listed during
280#	this phase because they build binaries to generate
281#	files needed to build these programs. This stage also
282#	builds the 'build-tools' target rather than 'all'.
283# 3. cross-tools stage [XMAKE]
284#	This stage is responsible for creating any tools that
285#	are needed for building the system. A cross-compiler is one
286#	of them. This differs from build tools in two ways:
287#	1. the 'all' target is built rather than 'build-tools'
288#	2. these tools are installed into TMPPATH for stage 4.
289# 4. world stage [WMAKE]
290#	This stage actually builds the world.
291# 5. install stage (optional) [IMAKE]
292#	This stage installs a previously built world.
293#
294
295BOOTSTRAPPING?=	0
296
297# Common environment for world related stages
298CROSSENV+=	MAKEOBJDIRPREFIX=${OBJTREE} \
299		MACHINE_ARCH=${TARGET_ARCH} \
300		MACHINE=${TARGET} \
301		CPUTYPE=${TARGET_CPUTYPE}
302.if ${MK_GROFF} != "no"
303CROSSENV+=	GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
304		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
305		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
306.endif
307.if defined(TARGET_CFLAGS)
308CROSSENV+=	${TARGET_CFLAGS}
309.endif
310
311# bootstrap-tools stage
312BMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
313		PATH=${BPATH}:${PATH} \
314		WORLDTMP=${WORLDTMP} \
315		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
316# need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
317BSARGS= 	DESTDIR= \
318		BOOTSTRAPPING=${OSRELDATE} \
319		SSP_CFLAGS= \
320		MK_HTML=no NO_LINT=yes MK_MAN=no \
321		-DNO_PIC MK_PROFILE=no -DNO_SHARED \
322		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
323		MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
324		MK_LLDB=no MK_TESTS=no \
325		MK_INCLUDES=yes
326
327BMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
328		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
329		${BSARGS}
330
331# build-tools stage
332TMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
333		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
334		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
335		DESTDIR= \
336		BOOTSTRAPPING=${OSRELDATE} \
337		SSP_CFLAGS= \
338		-DNO_LINT \
339		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
340		MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
341		MK_LLDB=no MK_TESTS=no
342
343# cross-tools stage
344XMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
345		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
346		MK_GDB=no MK_TESTS=no
347
348# kernel-tools stage
349KTMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
350		PATH=${BPATH}:${PATH} \
351		WORLDTMP=${WORLDTMP}
352KTMAKE=		TOOLS_PREFIX=${WORLDTMP} MAKEOBJDIRPREFIX=${WORLDTMP} \
353		${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
354		DESTDIR= \
355		BOOTSTRAPPING=${OSRELDATE} \
356		SSP_CFLAGS= \
357		MK_HTML=no -DNO_LINT MK_MAN=no \
358		-DNO_PIC MK_PROFILE=no -DNO_SHARED \
359		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no
360
361# world stage
362WMAKEENV=	${CROSSENV} \
363		INSTALL="sh ${.CURDIR}/tools/install.sh" \
364		PATH=${TMPPATH}
365
366# make hierarchy
367HMAKE=		PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
368.if defined(NO_ROOT)
369HMAKE+=		PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
370.endif
371
372.if defined(CROSS_TOOLCHAIN_PREFIX)
373CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
374CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
375.endif
376
377# If we do not have a bootstrap binutils (because the in-tree one does not
378# support the target architecture), provide a default cross-binutils prefix.
379# This allows aarch64 builds, for example, to automatically use the
380# aarch64-binutils port or package.
381.if !make(showconfig)
382.if !empty(BROKEN_OPTIONS:MBINUTILS_BOOTSTRAP) && \
383    !defined(CROSS_BINUTILS_PREFIX)
384CROSS_BINUTILS_PREFIX=/usr/local/${TARGET_ARCH}-freebsd/bin/
385.if !exists(${CROSS_BINUTILS_PREFIX})
386.error In-tree binutils does not support the ${TARGET_ARCH} architecture. Install the ${TARGET_ARCH}-binutils port or package or set CROSS_BINUTILS_PREFIX.
387.endif
388.endif
389.endif
390
391XCOMPILERS=	CC CXX CPP
392.for COMPILER in ${XCOMPILERS}
393.if defined(CROSS_COMPILER_PREFIX)
394X${COMPILER}?=	${CROSS_COMPILER_PREFIX}${${COMPILER}}
395.else
396X${COMPILER}?=	${${COMPILER}}
397.endif
398.endfor
399XBINUTILS=	AS AR LD NM OBJCOPY OBJDUMP RANLIB SIZE STRINGS
400.for BINUTIL in ${XBINUTILS}
401.if defined(CROSS_BINUTILS_PREFIX) && \
402    exists(${CROSS_BINUTILS_PREFIX}${${BINUTIL}})
403X${BINUTIL}?=	${CROSS_BINUTILS_PREFIX}${${BINUTIL}}
404.else
405X${BINUTIL}?=	${${BINUTIL}}
406.endif
407.endfor
408CROSSENV+=	CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCFLAGS} ${XCXXFLAGS}" \
409		DEPFLAGS="${DEPFLAGS}" \
410		CPP="${XCPP} ${XCFLAGS}" \
411		AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
412		OBJDUMP=${XOBJDUMP} OBJCOPY="${XOBJCOPY}" \
413		RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
414		SIZE="${XSIZE}"
415
416.if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
417# In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
418# directory, but the compiler will look in the right place for its
419# tools so we don't need to tell it where to look.
420BFLAGS+=	-B${CROSS_BINUTILS_PREFIX}
421.endif
422
423# External compiler needs sysroot and target flags.
424.if ${XCC:N${CCACHE_BIN}:M/*} || ${MK_CROSS_COMPILER} == "no"
425.if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
426BFLAGS+=	-B${WORLDTMP}/usr/bin
427.endif
428.if ${TARGET} == "arm"
429.if ${TARGET_ARCH:M*hf*} != ""
430TARGET_ABI=	gnueabihf
431.else
432TARGET_ABI=	gnueabi
433.endif
434.endif
435.if defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc
436# GCC requires -isystem when using a cross-compiler.
437XCFLAGS+=	-isystem ${WORLDTMP}/usr/include
438# Force using libc++ for external GCC.
439XCXXFLAGS+=	-isystem ${WORLDTMP}/usr/include/c++/v1 -std=c++11 \
440		-nostdinc++ -L${WORLDTMP}/../lib/libc++
441# XXX: DEPFLAGS is a workaround for not properly passing CXXFLAGS to sub-makes
442# due to CXX="${XCXX} ${XCXXFLAGS}".  bsd.dep.mk does use CXXFLAGS when
443# building C++ files so this can come out if passing CXXFLAGS down is fixed.
444DEPFLAGS+=	-I${WORLDTMP}/usr/include/c++/v1
445.else
446TARGET_ABI?=	unknown
447TARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd11.0
448XCFLAGS+=	-target ${TARGET_TRIPLE}
449.endif
450XCFLAGS+=	--sysroot=${WORLDTMP}
451.else
452.endif # ${XCC:M/*} || ${MK_CROSS_COMPILER} == "no"
453
454.if !empty(BFLAGS)
455XCFLAGS+=	${BFLAGS}
456.endif
457
458.if ${MK_LIB32} != "no" && (${TARGET_ARCH} == "amd64" || \
459    ${TARGET_ARCH} == "powerpc64")
460LIBCOMPAT= 32
461.include "Makefile.libcompat"
462.elif ${MK_LIBSOFT} != "no" && ${TARGET_ARCH} == "armv6"
463LIBCOMPAT= SOFT
464.include "Makefile.libcompat"
465.endif
466
467WMAKE=		${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP}
468
469IMAKEENV=	${CROSSENV:N_LDSCRIPTROOT=*}
470IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1 \
471		${IMAKE_INSTALL} ${IMAKE_MTREE}
472.if empty(.MAKEFLAGS:M-n)
473IMAKEENV+=	PATH=${STRICTTMPPATH}:${INSTALLTMP} \
474		LD_LIBRARY_PATH=${INSTALLTMP} \
475		PATH_LOCALE=${INSTALLTMP}/locale
476IMAKE+=		__MAKE_SHELL=${INSTALLTMP}/sh
477.else
478IMAKEENV+=	PATH=${TMPPATH}:${INSTALLTMP}
479.endif
480.if defined(DB_FROM_SRC)
481INSTALLFLAGS+=	-N ${.CURDIR}/etc
482MTREEFLAGS+=	-N ${.CURDIR}/etc
483.endif
484_INSTALL_DDIR=	${DESTDIR}/${DISTDIR}
485INSTALL_DDIR=	${_INSTALL_DDIR:S://:/:g:C:/$::}
486.if defined(NO_ROOT)
487METALOG?=	${DESTDIR}/${DISTDIR}/METALOG
488IMAKE+=		-DNO_ROOT METALOG=${METALOG}
489INSTALLFLAGS+=	-U -M ${METALOG} -D ${INSTALL_DDIR}
490MTREEFLAGS+=	-W
491.endif
492.if defined(DB_FROM_SRC) || defined(NO_ROOT)
493IMAKE_INSTALL=	INSTALL="install ${INSTALLFLAGS}"
494IMAKE_MTREE=	MTREE_CMD="mtree ${MTREEFLAGS}"
495.endif
496
497# kernel stage
498KMAKEENV=	${WMAKEENV}
499KMAKE=		${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
500
501#
502# buildworld
503#
504# Attempt to rebuild the entire system, with reasonable chance of
505# success, regardless of how old your existing system is.
506#
507_worldtmp: .PHONY
508.if ${.CURDIR:C/[^,]//g} != ""
509#	The m4 build of sendmail files doesn't like it if ',' is used
510#	anywhere in the path of it's files.
511	@echo
512	@echo "*** Error: path to source tree contains a comma ','"
513	@echo
514	false
515.endif
516	@echo
517	@echo "--------------------------------------------------------------"
518	@echo ">>> Rebuilding the temporary build tree"
519	@echo "--------------------------------------------------------------"
520.if !defined(NO_CLEAN)
521	rm -rf ${WORLDTMP}
522.if defined(LIBCOMPAT)
523	rm -rf ${LIBCOMPATTMP}
524.endif
525.else
526	rm -rf ${WORLDTMP}/legacy/usr/include
527#	XXX - These can depend on any header file.
528	rm -f ${OBJTREE}${.CURDIR}/lib/libsysdecode/ioctl.c
529	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
530.endif
531.for _dir in \
532    lib lib/casper usr legacy/bin legacy/usr
533	mkdir -p ${WORLDTMP}/${_dir}
534.endfor
535	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
536	    -p ${WORLDTMP}/legacy/usr >/dev/null
537.if ${MK_GROFF} != "no"
538	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
539	    -p ${WORLDTMP}/legacy/usr >/dev/null
540.endif
541	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
542	    -p ${WORLDTMP}/usr >/dev/null
543	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
544	    -p ${WORLDTMP}/usr/include >/dev/null
545	ln -sf ${.CURDIR}/sys ${WORLDTMP}
546.if ${MK_DEBUG_FILES} != "no"
547	# We could instead disable debug files for these build stages
548	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
549	    -p ${WORLDTMP}/legacy/usr/lib >/dev/null
550	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
551	    -p ${WORLDTMP}/usr/lib >/dev/null
552.endif
553.if defined(LIBCOMPAT)
554	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
555	    -p ${WORLDTMP}/usr >/dev/null
556.if ${MK_DEBUG_FILES} != "no"
557	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
558	    -p ${WORLDTMP}/legacy/usr/lib/debug/usr >/dev/null
559	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
560	    -p ${WORLDTMP}/usr/lib/debug/usr >/dev/null
561.endif
562.endif
563.if ${MK_TESTS} != "no"
564	mkdir -p ${WORLDTMP}${TESTSBASE}
565	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
566	    -p ${WORLDTMP}${TESTSBASE} >/dev/null
567.if ${MK_DEBUG_FILES} != "no"
568	mkdir -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE}
569	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
570	    -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE} >/dev/null
571.endif
572.endif
573.for _mtree in ${LOCAL_MTREE}
574	mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
575.endfor
576_legacy:
577	@echo
578	@echo "--------------------------------------------------------------"
579	@echo ">>> stage 1.1: legacy release compatibility shims"
580	@echo "--------------------------------------------------------------"
581	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
582_bootstrap-tools:
583	@echo
584	@echo "--------------------------------------------------------------"
585	@echo ">>> stage 1.2: bootstrap tools"
586	@echo "--------------------------------------------------------------"
587	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
588_cleanobj:
589.if !defined(NO_CLEAN)
590	@echo
591	@echo "--------------------------------------------------------------"
592	@echo ">>> stage 2.1: cleaning up the object tree"
593	@echo "--------------------------------------------------------------"
594	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR}
595.if defined(LIBCOMPAT)
596	${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} -f Makefile.inc1 ${CLEANDIR}
597.endif
598.endif
599_obj:
600	@echo
601	@echo "--------------------------------------------------------------"
602	@echo ">>> stage 2.2: rebuilding the object tree"
603	@echo "--------------------------------------------------------------"
604	${_+_}cd ${.CURDIR}; ${WMAKE} obj
605_build-tools:
606	@echo
607	@echo "--------------------------------------------------------------"
608	@echo ">>> stage 2.3: build tools"
609	@echo "--------------------------------------------------------------"
610	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
611_cross-tools:
612	@echo
613	@echo "--------------------------------------------------------------"
614	@echo ">>> stage 3: cross tools"
615	@echo "--------------------------------------------------------------"
616	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
617	${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
618_includes:
619	@echo
620	@echo "--------------------------------------------------------------"
621	@echo ">>> stage 4.1: building includes"
622	@echo "--------------------------------------------------------------"
623# Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
624# headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
625	${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
626	    includes
627.if !empty(SUBDIR_OVERRIDE) && make(buildworld)
628	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks includes
629.endif
630_libraries:
631	@echo
632	@echo "--------------------------------------------------------------"
633	@echo ">>> stage 4.2: building libraries"
634	@echo "--------------------------------------------------------------"
635	${_+_}cd ${.CURDIR}; \
636	    ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
637	    MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
638_depend:
639	@echo
640	@echo "--------------------------------------------------------------"
641	@echo ">>> stage 4.3: make dependencies"
642	@echo "--------------------------------------------------------------"
643	${_+_}cd ${.CURDIR}; ${WMAKE} depend
644everything:
645	@echo
646	@echo "--------------------------------------------------------------"
647	@echo ">>> stage 4.4: building everything"
648	@echo "--------------------------------------------------------------"
649	${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
650
651WMAKE_TGTS=
652WMAKE_TGTS+=	_worldtmp _legacy
653.if empty(SUBDIR_OVERRIDE)
654WMAKE_TGTS+=	_bootstrap-tools
655.endif
656WMAKE_TGTS+=	_cleanobj _obj _build-tools _cross-tools
657WMAKE_TGTS+=	_includes _libraries
658.if !defined(NO_DEPEND)
659WMAKE_TGTS+=	_depend
660.endif
661WMAKE_TGTS+=	everything
662.if defined(LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
663WMAKE_TGTS+=	build${libcompat}
664.endif
665
666buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
667.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
668
669buildworld_prologue:
670	@echo "--------------------------------------------------------------"
671	@echo ">>> World build started on `LC_ALL=C date`"
672	@echo "--------------------------------------------------------------"
673
674buildworld_epilogue:
675	@echo
676	@echo "--------------------------------------------------------------"
677	@echo ">>> World build completed on `LC_ALL=C date`"
678	@echo "--------------------------------------------------------------"
679
680#
681# We need to have this as a target because the indirection between Makefile
682# and Makefile.inc1 causes the correct PATH to be used, rather than a
683# modification of the current environment's PATH.  In addition, we need
684# to quote multiword values.
685#
686buildenvvars: .PHONY
687	@echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
688
689.if ${.TARGETS:Mbuildenv}
690.if ${.MAKEFLAGS:M-j}
691.error The buildenv target is incompatible with -j
692.endif
693.endif
694BUILDENV_DIR?=	${.CURDIR}
695buildenv: .PHONY
696	@echo Entering world for ${TARGET_ARCH}:${TARGET}
697.if ${BUILDENV_SHELL:M*zsh*}
698	@echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
699.endif
700	@cd ${BUILDENV_DIR} && env ${WMAKEENV} BUILDENV=1 ${BUILDENV_SHELL} \
701	    || true
702
703TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild${libcompat}}
704toolchain: ${TOOLCHAIN_TGTS}
705kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
706
707#
708# installcheck
709#
710# Checks to be sure system is ready for installworld/installkernel.
711#
712installcheck: _installcheck_world _installcheck_kernel
713_installcheck_world:
714_installcheck_kernel:
715
716#
717# Require DESTDIR to be set if installing for a different architecture or
718# using the user/group database in the source tree.
719#
720.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
721    defined(DB_FROM_SRC)
722.if !make(distributeworld)
723_installcheck_world: __installcheck_DESTDIR
724_installcheck_kernel: __installcheck_DESTDIR
725__installcheck_DESTDIR:
726.if !defined(DESTDIR) || empty(DESTDIR)
727	@echo "ERROR: Please set DESTDIR!"; \
728	false
729.endif
730.endif
731.endif
732
733.if !defined(DB_FROM_SRC)
734#
735# Check for missing UIDs/GIDs.
736#
737CHECK_UIDS=	auditdistd
738CHECK_GIDS=	audit
739.if ${MK_SENDMAIL} != "no"
740CHECK_UIDS+=	smmsp
741CHECK_GIDS+=	smmsp
742.endif
743.if ${MK_PF} != "no"
744CHECK_UIDS+=	proxy
745CHECK_GIDS+=	proxy authpf
746.endif
747.if ${MK_UNBOUND} != "no"
748CHECK_UIDS+=	unbound
749CHECK_GIDS+=	unbound
750.endif
751_installcheck_world: __installcheck_UGID
752__installcheck_UGID:
753.for uid in ${CHECK_UIDS}
754	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
755		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
756		false; \
757	fi
758.endfor
759.for gid in ${CHECK_GIDS}
760	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
761		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
762		false; \
763	fi
764.endfor
765.endif
766
767#
768# Required install tools to be saved in a scratch dir for safety.
769#
770.if ${MK_ZONEINFO} != "no"
771_zoneinfo=	zic tzsetup
772.endif
773
774ITOOLS=	[ awk cap_mkdb cat chflags chmod chown cmp cp \
775	date echo egrep find grep id install ${_install-info} \
776	ln make mkdir mtree mv pwd_mkdb \
777	rm sed services_mkdb sh strip sysctl test true uname wc ${_zoneinfo} \
778	${LOCAL_ITOOLS}
779
780# Needed for share/man
781.if ${MK_MAN} != "no"
782ITOOLS+=makewhatis
783.endif
784
785#
786# distributeworld
787#
788# Distributes everything compiled by a `buildworld'.
789#
790# installworld
791#
792# Installs everything compiled by a 'buildworld'.
793#
794
795# Non-base distributions produced by the base system
796EXTRA_DISTRIBUTIONS=	doc
797.if defined(LIBCOMPAT)
798EXTRA_DISTRIBUTIONS+=	lib${libcompat}
799.endif
800.if ${MK_TESTS} != "no"
801EXTRA_DISTRIBUTIONS+=	tests
802.endif
803
804DEBUG_DISTRIBUTIONS=
805.if ${MK_DEBUG_FILES} != "no"
806DEBUG_DISTRIBUTIONS+=	base ${EXTRA_DISTRIBUTIONS:S,doc,,:S,tests,,}
807.endif
808
809MTREE_MAGIC?=	mtree 2.0
810
811distributeworld installworld: _installcheck_world
812	mkdir -p ${INSTALLTMP}
813	progs=$$(for prog in ${ITOOLS}; do \
814		if progpath=`which $$prog`; then \
815			echo $$progpath; \
816		else \
817			echo "Required tool $$prog not found in PATH." >&2; \
818			exit 1; \
819		fi; \
820	    done); \
821	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
822	    while read line; do \
823		set -- $$line; \
824		if [ "$$2 $$3" != "not found" ]; then \
825			echo $$2; \
826		else \
827			echo "Required library $$1 not found." >&2; \
828			exit 1; \
829		fi; \
830	    done); \
831	cp $$libs $$progs ${INSTALLTMP}
832	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
833.if defined(NO_ROOT)
834	-mkdir -p ${METALOG:H}
835	echo "#${MTREE_MAGIC}" > ${METALOG}
836.endif
837.if make(distributeworld)
838.for dist in ${EXTRA_DISTRIBUTIONS}
839	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
840	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
841	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
842	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
843	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
844	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
845	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
846.if ${MK_DEBUG_FILES} != "no"
847	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
848	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
849.endif
850.if defined(LIBCOMPAT)
851	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
852	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
853.if ${MK_DEBUG_FILES} != "no"
854	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
855	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
856.endif
857.endif
858.if ${MK_TESTS} != "no" && ${dist} == "tests"
859	-mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
860	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
861	    -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
862.if ${MK_DEBUG_FILES} != "no"
863	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
864	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
865.endif
866.endif
867.if defined(NO_ROOT)
868	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
869	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
870	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
871	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
872	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
873	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
874.if defined(LIBCOMPAT)
875	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
876	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
877.endif
878.endif
879.endfor
880	-mkdir ${DESTDIR}/${DISTDIR}/base
881	${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
882	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
883	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
884	    LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
885.endif
886	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
887	    ${IMAKEENV} rm -rf ${INSTALLTMP}
888.if make(distributeworld)
889.for dist in ${EXTRA_DISTRIBUTIONS}
890	find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -empty -delete
891.endfor
892.if defined(NO_ROOT)
893.for dist in base ${EXTRA_DISTRIBUTIONS}
894	@# For each file that exists in this dist, print the corresponding
895	@# line from the METALOG.  This relies on the fact that
896	@# a line containing only the filename will sort immediatly before
897	@# the relevant mtree line.
898	cd ${DESTDIR}/${DISTDIR}; \
899	find ./${dist} | sort -u ${METALOG} - | \
900	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
901	${DESTDIR}/${DISTDIR}/${dist}.meta
902.endfor
903.for dist in ${DEBUG_DISTRIBUTIONS}
904	@# For each file that exists in this dist, print the corresponding
905	@# line from the METALOG.  This relies on the fact that
906	@# a line containing only the filename will sort immediatly before
907	@# the relevant mtree line.
908	cd ${DESTDIR}/${DISTDIR}; \
909	find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
910	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
911	${DESTDIR}/${DISTDIR}/${dist}.debug.meta
912.endfor
913.endif
914.endif
915
916packageworld:
917.for dist in base ${EXTRA_DISTRIBUTIONS}
918.if defined(NO_ROOT)
919	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
920	    tar cvf - --exclude usr/lib/debug \
921	    @${DESTDIR}/${DISTDIR}/${dist}.meta | \
922	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
923.else
924	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
925	    tar cvf - --exclude usr/lib/debug . | \
926	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
927.endif
928.endfor
929
930.for dist in ${DEBUG_DISTRIBUTIONS}
931. if defined(NO_ROOT)
932	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
933	    tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
934	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
935. else
936	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
937	    tar cvLf - usr/lib/debug | \
938	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
939. endif
940.endfor
941
942#
943# reinstall
944#
945# If you have a build server, you can NFS mount the source and obj directories
946# and do a 'make reinstall' on the *client* to install new binaries from the
947# most recent server build.
948#
949reinstall: .MAKE .PHONY
950	@echo "--------------------------------------------------------------"
951	@echo ">>> Making hierarchy"
952	@echo "--------------------------------------------------------------"
953	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
954	    LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
955	@echo
956	@echo "--------------------------------------------------------------"
957	@echo ">>> Installing everything"
958	@echo "--------------------------------------------------------------"
959	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
960.if defined(LIBCOMPAT)
961	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
962.endif
963
964redistribute: .MAKE .PHONY
965	@echo "--------------------------------------------------------------"
966	@echo ">>> Distributing everything"
967	@echo "--------------------------------------------------------------"
968	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
969.if defined(LIBCOMPAT)
970	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
971	    DISTRIBUTION=lib${libcompat}
972.endif
973
974distrib-dirs distribution: .MAKE .PHONY
975	${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
976	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
977.if make(distribution)
978	${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
979		${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
980		METALOG=${METALOG} MK_TESTS=no installconfig
981.endif
982
983#
984# buildkernel and installkernel
985#
986# Which kernels to build and/or install is specified by setting
987# KERNCONF. If not defined a GENERIC kernel is built/installed.
988# Only the existing (depending TARGET) config files are used
989# for building kernels and only the first of these is designated
990# as the one being installed.
991#
992# Note that we have to use TARGET instead of TARGET_ARCH when
993# we're in kernel-land. Since only TARGET_ARCH is (expected) to
994# be set to cross-build, we have to make sure TARGET is set
995# properly.
996
997.if defined(KERNFAST)
998NO_KERNELCLEAN=	t
999NO_KERNELCONFIG=	t
1000NO_KERNELDEPEND=	t
1001NO_KERNELOBJ=		t
1002# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1003.if !defined(KERNCONF) && ${KERNFAST} != "1"
1004KERNCONF=${KERNFAST}
1005.endif
1006.endif
1007.if ${TARGET_ARCH} == "powerpc64"
1008KERNCONF?=	GENERIC64
1009.else
1010KERNCONF?=	GENERIC
1011.endif
1012INSTKERNNAME?=	kernel
1013
1014KERNSRCDIR?=	${.CURDIR}/sys
1015KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
1016KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
1017KERNCONFDIR?=	${KRNLCONFDIR}
1018
1019BUILDKERNELS=
1020INSTALLKERNEL=
1021.if defined(NO_INSTALLKERNEL)
1022# All of the BUILDKERNELS loops start at index 1.
1023BUILDKERNELS+= dummy
1024.endif
1025.for _kernel in ${KERNCONF}
1026.if exists(${KERNCONFDIR}/${_kernel})
1027BUILDKERNELS+=	${_kernel}
1028.if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1029INSTALLKERNEL= ${_kernel}
1030.endif
1031.endif
1032.endfor
1033
1034${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1035
1036#
1037# buildkernel
1038#
1039# Builds all kernels defined by BUILDKERNELS.
1040#
1041buildkernel: .MAKE .PHONY
1042.if empty(BUILDKERNELS:Ndummy)
1043	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1044	false
1045.endif
1046	@echo
1047.for _kernel in ${BUILDKERNELS:Ndummy}
1048	@echo "--------------------------------------------------------------"
1049	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1050	@echo "--------------------------------------------------------------"
1051	@echo "===> ${_kernel}"
1052	mkdir -p ${KRNLOBJDIR}
1053.if !defined(NO_KERNELCONFIG)
1054	@echo
1055	@echo "--------------------------------------------------------------"
1056	@echo ">>> stage 1: configuring the kernel"
1057	@echo "--------------------------------------------------------------"
1058	cd ${KRNLCONFDIR}; \
1059		PATH=${TMPPATH} \
1060		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1061			-I '${KERNCONFDIR}' '${KERNCONFDIR}/${_kernel}'
1062.endif
1063.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1064	@echo
1065	@echo "--------------------------------------------------------------"
1066	@echo ">>> stage 2.1: cleaning up the object tree"
1067	@echo "--------------------------------------------------------------"
1068	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1069.endif
1070.if !defined(NO_KERNELOBJ)
1071	@echo
1072	@echo "--------------------------------------------------------------"
1073	@echo ">>> stage 2.2: rebuilding the object tree"
1074	@echo "--------------------------------------------------------------"
1075	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1076.endif
1077	@echo
1078	@echo "--------------------------------------------------------------"
1079	@echo ">>> stage 2.3: build tools"
1080	@echo "--------------------------------------------------------------"
1081	${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1082.if !defined(NO_KERNELDEPEND)
1083	@echo
1084	@echo "--------------------------------------------------------------"
1085	@echo ">>> stage 3.1: making dependencies"
1086	@echo "--------------------------------------------------------------"
1087	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
1088.endif
1089	@echo
1090	@echo "--------------------------------------------------------------"
1091	@echo ">>> stage 3.2: building everything"
1092	@echo "--------------------------------------------------------------"
1093	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1094	@echo "--------------------------------------------------------------"
1095	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1096	@echo "--------------------------------------------------------------"
1097.endfor
1098
1099#
1100# installkernel, etc.
1101#
1102# Install the kernel defined by INSTALLKERNEL
1103#
1104installkernel installkernel.debug \
1105reinstallkernel reinstallkernel.debug: _installcheck_kernel
1106.if !defined(NO_INSTALLKERNEL)
1107.if empty(INSTALLKERNEL)
1108	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1109	false
1110.endif
1111	@echo "--------------------------------------------------------------"
1112	@echo ">>> Installing kernel ${INSTALLKERNEL}"
1113	@echo "--------------------------------------------------------------"
1114	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1115	    ${CROSSENV} PATH=${TMPPATH} \
1116	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1117.endif
1118.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1119.for _kernel in ${BUILDKERNELS:[2..-1]}
1120	@echo "--------------------------------------------------------------"
1121	@echo ">>> Installing kernel ${_kernel}"
1122	@echo "--------------------------------------------------------------"
1123	cd ${KRNLOBJDIR}/${_kernel}; \
1124	    ${CROSSENV} PATH=${TMPPATH} \
1125	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1126.endfor
1127.endif
1128
1129distributekernel distributekernel.debug:
1130.if !defined(NO_INSTALLKERNEL)
1131.if empty(INSTALLKERNEL)
1132	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1133	false
1134.endif
1135	mkdir -p ${DESTDIR}/${DISTDIR}
1136.if defined(NO_ROOT)
1137	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1138.endif
1139	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1140	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1141	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1142	    DESTDIR=${INSTALL_DDIR}/kernel \
1143	    ${.TARGET:S/distributekernel/install/}
1144.if defined(NO_ROOT)
1145	sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1146	    ${DESTDIR}/${DISTDIR}/kernel.meta
1147.endif
1148.endif
1149.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1150.for _kernel in ${BUILDKERNELS:[2..-1]}
1151.if defined(NO_ROOT)
1152	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1153.endif
1154	cd ${KRNLOBJDIR}/${_kernel}; \
1155	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1156	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1157	    KERNEL=${INSTKERNNAME}.${_kernel} \
1158	    DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1159	    ${.TARGET:S/distributekernel/install/}
1160.if defined(NO_ROOT)
1161	sed -e 's|^./kernel|.|' \
1162	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1163	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1164.endif
1165.endfor
1166.endif
1167
1168packagekernel:
1169.if defined(NO_ROOT)
1170.if !defined(NO_INSTALLKERNEL)
1171	cd ${DESTDIR}/${DISTDIR}/kernel; \
1172	    tar cvf - --exclude '*.debug' \
1173	    @${DESTDIR}/${DISTDIR}/kernel.meta | \
1174	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1175.endif
1176	cd ${DESTDIR}/${DISTDIR}/kernel; \
1177	    tar cvf - --include '*/*/*.debug' \
1178	    @${DESTDIR}/${DISTDIR}/kernel.meta | \
1179	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1180.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1181.for _kernel in ${BUILDKERNELS:[2..-1]}
1182	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1183	    tar cvf - --exclude '*.debug' \
1184	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1185	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1186	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1187	    tar cvf - --include '*/*/*.debug' \
1188	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1189	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1190.endfor
1191.endif
1192.else
1193.if !defined(NO_INSTALLKERNEL)
1194	cd ${DESTDIR}/${DISTDIR}/kernel; \
1195	    tar cvf - --exclude '*.debug' . | \
1196	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1197.endif
1198	cd ${DESTDIR}/${DISTDIR}/kernel; \
1199	    tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1200	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1201.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1202.for _kernel in ${BUILDKERNELS:[2..-1]}
1203	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1204	    tar cvf - --exclude '*.debug' . | \
1205	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1206	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1207	    tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1208	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1209.endfor
1210.endif
1211.endif
1212
1213#
1214#
1215# checkworld
1216#
1217# Run test suite on installed world.
1218#
1219checkworld: .PHONY
1220	@if [ ! -x ${LOCALBASE}/bin/kyua ]; then \
1221		echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
1222		exit 1; \
1223	fi
1224	${_+_}${LOCALBASE}/bin/kyua test -k ${TESTSBASE}/Kyuafile
1225
1226#
1227#
1228# doxygen
1229#
1230# Build the API documentation with doxygen
1231#
1232doxygen: .PHONY
1233	@if [ ! -x ${LOCALBASE}/bin/doxygen ]; then \
1234		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1235		exit 1; \
1236	fi
1237	${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
1238
1239#
1240# update
1241#
1242# Update the source tree(s), by running svn/svnup to update to the
1243# latest copy.
1244#
1245update:
1246.if (defined(CVS_UPDATE) || defined(SUP_UPDATE)) && !defined(SVN_UPDATE)
1247	@echo "--------------------------------------------------------------"
1248	@echo "CVS_UPDATE and SUP_UPDATE are no longer supported."
1249	@echo "Please see: https://wiki.freebsd.org/CvsIsDeprecated"
1250	@echo "--------------------------------------------------------------"
1251	@exit 1
1252.endif
1253.if defined(SVN_UPDATE)
1254	@echo "--------------------------------------------------------------"
1255	@echo ">>> Updating ${.CURDIR} using Subversion"
1256	@echo "--------------------------------------------------------------"
1257	@(cd ${.CURDIR}; ${SVN} update ${SVNFLAGS})
1258.endif
1259
1260#
1261# ------------------------------------------------------------------------
1262#
1263# From here onwards are utility targets used by the 'make world' and
1264# related targets.  If your 'world' breaks, you may like to try to fix
1265# the problem and manually run the following targets to attempt to
1266# complete the build.  Beware, this is *not* guaranteed to work, you
1267# need to have a pretty good grip on the current state of the system
1268# to attempt to manually finish it.  If in doubt, 'make world' again.
1269#
1270
1271#
1272# legacy: Build compatibility shims for the next three targets. This is a
1273# minimal set of tools and shims necessary to compensate for older systems
1274# which don't have the APIs required by the targets built in bootstrap-tools,
1275# build-tools or cross-tools.
1276#
1277
1278# ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
1279# r296685 fix cross-endian objcopy
1280.if ${BOOTSTRAPPING} < 1100102
1281_elftoolchain_libs= lib/libelf lib/libdwarf
1282.endif
1283
1284legacy:
1285.if ${BOOTSTRAPPING} < 800107 && ${BOOTSTRAPPING} != 0
1286	@echo "ERROR: Source upgrades from versions prior to 8.0 are not supported."; \
1287	false
1288.endif
1289.for _tool in tools/build ${_elftoolchain_libs}
1290	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
1291	    cd ${.CURDIR}/${_tool}; \
1292	    ${MAKE} DIRPRFX=${_tool}/ obj; \
1293	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
1294	    if [ -z "${NO_DEPEND}" ]; then ${MAKE} DIRPRFX=${_tool}/ depend; fi; \
1295	    ${MAKE} DIRPRFX=${_tool}/ all; \
1296	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1297.endfor
1298
1299#
1300# bootstrap-tools: Build tools needed for compatibility. These are binaries that
1301# are built to build other binaries in the system. However, the focus of these
1302# binaries is usually quite narrow. Bootstrap tools use the host's compiler and
1303# libraries, augmented by -legacy.
1304#
1305_bt=		_bootstrap-tools
1306
1307.if ${MK_GAMES} != "no"
1308_strfile=	usr.bin/fortune/strfile
1309.endif
1310
1311.if ${MK_GCC} != "no" && ${MK_CXX} != "no"
1312_gperf=		gnu/usr.bin/gperf
1313.endif
1314
1315.if ${MK_GROFF} != "no"
1316_groff=		gnu/usr.bin/groff \
1317		usr.bin/soelim
1318.endif
1319
1320.if ${MK_VT} != "no"
1321_vtfontcvt=	usr.bin/vtfontcvt
1322.endif
1323
1324.if ${BOOTSTRAPPING} < 900002
1325_sed=		usr.bin/sed
1326.endif
1327
1328.if ${BOOTSTRAPPING} < 1000033
1329_libopenbsd=	lib/libopenbsd
1330_m4=		usr.bin/m4
1331_lex=		usr.bin/lex
1332
1333${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd
1334${_bt}-usr.bin/lex: ${_bt}-usr.bin/m4
1335.endif
1336
1337.if ${BOOTSTRAPPING} < 1000026
1338_nmtree=	lib/libnetbsd \
1339		usr.sbin/nmtree
1340
1341${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
1342.endif
1343
1344.if ${BOOTSTRAPPING} < 1000027
1345_cat=		bin/cat
1346.endif
1347
1348# r264059 support for status=
1349.if ${BOOTSTRAPPING} < 1100017
1350_dd=		bin/dd
1351.endif
1352
1353# r277259 crunchide: Correct 64-bit section header offset
1354# r281674 crunchide: always include both 32- and 64-bit ELF support
1355# r285986 crunchen: use STRIPBIN rather than STRIP
1356.if ${BOOTSTRAPPING} < 1100078
1357_crunch=	usr.sbin/crunch
1358.endif
1359
1360.if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1361_awk=		usr.bin/awk
1362.endif
1363
1364_yacc=		lib/liby \
1365		usr.bin/yacc
1366
1367${_bt}-usr.bin/yacc: ${_bt}-lib/liby
1368
1369.if ${MK_BSNMP} != "no"
1370_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
1371.endif
1372
1373# We need to build tblgen when we're building clang either as
1374# the bootstrap compiler, or as the part of the normal build.
1375.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no"
1376_clang_tblgen= \
1377	lib/clang/libllvmsupport \
1378	lib/clang/libllvmtablegen \
1379	usr.bin/clang/llvm-tblgen \
1380	usr.bin/clang/clang-tblgen
1381
1382${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1383${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1384.endif
1385
1386# Default to building the GPL DTC, but build the BSDL one if users explicitly
1387# request it.
1388_dtc= usr.bin/dtc
1389.if ${MK_GPL_DTC} != "no"
1390_dtc= gnu/usr.bin/dtc
1391.endif
1392
1393.if ${MK_KERBEROS} != "no"
1394_kerberos5_bootstrap_tools= \
1395	kerberos5/tools/make-roken \
1396	kerberos5/lib/libroken \
1397	kerberos5/lib/libvers \
1398	kerberos5/tools/asn1_compile \
1399	kerberos5/tools/slc \
1400	usr.bin/compile_et
1401
1402.ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
1403.endif
1404
1405# r283777 makewhatis(1) replaced with mandoc version which builds a database.
1406.if ${MK_MANDOCDB} != "no" && ${BOOTSTRAPPING} < 1100075
1407_libopenbsd?=	lib/libopenbsd
1408_makewhatis=	lib/libsqlite3 \
1409		usr.bin/mandoc
1410${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd ${_bt}-lib/libsqlite3
1411.endif
1412
1413bootstrap-tools: .PHONY
1414
1415#	Please document (add comment) why something is in 'bootstrap-tools'.
1416#	Try to bound the building of the bootstrap-tool to just the
1417#	FreeBSD versions that need the tool built at this stage of the build.
1418.for _tool in \
1419    ${_clang_tblgen} \
1420    ${_kerberos5_bootstrap_tools} \
1421    ${_strfile} \
1422    ${_gperf} \
1423    ${_groff} \
1424    ${_dtc} \
1425    ${_awk} \
1426    ${_cat} \
1427    ${_dd} \
1428    usr.bin/lorder \
1429    ${_libopenbsd} \
1430    ${_makewhatis} \
1431    usr.bin/rpcgen \
1432    ${_sed} \
1433    ${_yacc} \
1434    ${_m4} \
1435    ${_lex} \
1436    usr.bin/xinstall \
1437    ${_gensnmptree} \
1438    usr.sbin/config \
1439    ${_crunch} \
1440    ${_nmtree} \
1441    ${_vtfontcvt} \
1442    usr.bin/localedef
1443${_bt}-${_tool}: .PHONY .MAKE
1444	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1445		cd ${.CURDIR}/${_tool}; \
1446		${MAKE} DIRPRFX=${_tool}/ obj; \
1447		if [ -z "${NO_DEPEND}" ]; then ${MAKE} DIRPRFX=${_tool}/ depend; fi; \
1448		${MAKE} DIRPRFX=${_tool}/ all; \
1449		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1450
1451bootstrap-tools: ${_bt}-${_tool}
1452.endfor
1453
1454#
1455# build-tools: Build special purpose build tools
1456#
1457.if !defined(NO_SHARE)
1458_share=	share/syscons/scrnmaps
1459.endif
1460
1461.if ${MK_GCC} != "no"
1462_gcc_tools= gnu/usr.bin/cc/cc_tools
1463.endif
1464
1465.if ${MK_RESCUE} != "no"
1466# rescue includes programs that have build-tools targets
1467_rescue=rescue/rescue
1468.endif
1469
1470.for _tool in \
1471    bin/csh \
1472    bin/sh \
1473    ${LOCAL_TOOL_DIRS} \
1474    lib/ncurses/ncurses \
1475    lib/ncurses/ncursesw \
1476    ${_rescue} \
1477    ${_share} \
1478    usr.bin/awk \
1479    lib/libmagic \
1480    usr.bin/mkesdb_static \
1481    usr.bin/mkcsmapper_static \
1482    usr.bin/vi/catalog
1483build-tools_${_tool}: .PHONY
1484	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1485		cd ${.CURDIR}/${_tool}; \
1486		${MAKE} DIRPRFX=${_tool}/ obj; \
1487		${MAKE} DIRPRFX=${_tool}/ build-tools
1488build-tools: build-tools_${_tool}
1489.endfor
1490.for _tool in \
1491    ${_gcc_tools}
1492build-tools_${_tool}: .PHONY
1493	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1494		cd ${.CURDIR}/${_tool}; \
1495		${MAKE} DIRPRFX=${_tool}/ obj; \
1496		if [ -z "${NO_DEPEND}" ]; then ${MAKE} DIRPRFX=${_tool}/ depend; fi; \
1497		${MAKE} DIRPRFX=${_tool}/ all
1498build-tools: build-tools_${_tool}
1499.endfor
1500
1501#
1502# kernel-tools: Build kernel-building tools
1503#
1504kernel-tools:
1505	mkdir -p ${MAKEOBJDIRPREFIX}/usr
1506	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1507	    -p ${MAKEOBJDIRPREFIX}/usr >/dev/null
1508
1509#
1510# cross-tools: All the tools needed to build the rest of the system after
1511# we get done with the earlier stages. It is the last set of tools needed
1512# to begin building the target binaries.
1513#
1514.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1515.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1516_btxld=		usr.sbin/btxld
1517.endif
1518.endif
1519
1520# Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
1521# resulting from missing bug fixes or ELF Toolchain updates.
1522.if ${MK_CDDL} != "no"
1523_dtrace_tools= cddl/lib/libctf cddl/usr.bin/ctfconvert \
1524    cddl/usr.bin/ctfmerge
1525.endif
1526
1527# If we're given an XAS, don't build binutils.
1528.if ${XAS:M/*} == ""
1529.if ${MK_BINUTILS_BOOTSTRAP} != "no"
1530_binutils=	gnu/usr.bin/binutils
1531.endif
1532.if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
1533_elftctools=	lib/libelftc \
1534		lib/libpe \
1535		usr.bin/elfcopy \
1536		usr.bin/nm \
1537		usr.bin/size \
1538		usr.bin/strings
1539# These are not required by the build, but can be useful for developers who
1540# cross-build on a FreeBSD 10 host:
1541_elftctools+=	usr.bin/addr2line
1542.endif
1543.elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
1544# If cross-building with an external binutils we still need to build strip for
1545# the target (for at least crunchide).
1546_elftctools=	lib/libelftc \
1547		lib/libpe \
1548		usr.bin/elfcopy
1549.endif
1550
1551# If an full path to an external cross compiler is given, don't build
1552# a cross compiler.
1553.if ${XCC:N${CCACHE_BIN}:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1554.if ${MK_CLANG_BOOTSTRAP} != "no"
1555_clang=		usr.bin/clang
1556_clang_libs=	lib/clang
1557.endif
1558.if ${MK_GCC_BOOTSTRAP} != "no"
1559_cc=		gnu/usr.bin/cc
1560.endif
1561.endif
1562.if ${MK_USB} != "no"
1563_usb_tools=	sys/boot/usb/tools
1564.endif
1565
1566cross-tools: .MAKE .PHONY
1567.for _tool in \
1568    ${_clang_libs} \
1569    ${_clang} \
1570    ${_binutils} \
1571    ${_elftctools} \
1572    ${_dtrace_tools} \
1573    ${_cc} \
1574    ${_btxld} \
1575    ${_crunchide} \
1576    ${_usb_tools}
1577	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1578		cd ${.CURDIR}/${_tool}; \
1579		${MAKE} DIRPRFX=${_tool}/ obj; \
1580		if [ -z "${NO_DEPEND}" ]; then ${MAKE} DIRPRFX=${_tool}/ depend; fi; \
1581		${MAKE} DIRPRFX=${_tool}/ all; \
1582		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1583.endfor
1584
1585NXBDESTDIR=	${OBJTREE}/nxb-bin
1586NXBENV=		MAKEOBJDIRPREFIX=${OBJTREE}/nxb \
1587		INSTALL="sh ${.CURDIR}/tools/install.sh" \
1588		PATH=${PATH}:${OBJTREE}/gperf_for_gcc/usr/bin
1589NXBMAKE=	${NXBENV} ${MAKE} \
1590		LLVM_TBLGEN=${NXBDESTDIR}/usr/bin/llvm-tblgen \
1591		CLANG_TBLGEN=${NXBDESTDIR}/usr/bin/clang-tblgen \
1592		MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
1593		MK_GDB=no MK_TESTS=no \
1594		SSP_CFLAGS= \
1595		MK_HTML=no NO_LINT=yes MK_MAN=no \
1596		-DNO_PIC MK_PROFILE=no -DNO_SHARED \
1597		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
1598		MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
1599		MK_LLDB=no MK_DEBUG_FILES=no
1600
1601# native-xtools is the current target for qemu-user cross builds of ports
1602# via poudriere and the imgact_binmisc kernel module.
1603# For non-clang enabled targets that are still using the in tree gcc
1604# we must build a gperf binary for one instance of its Makefiles.  On
1605# clang-enabled systems, the gperf binary is obsolete.
1606native-xtools: .PHONY
1607.if ${MK_GCC_BOOTSTRAP} != "no"
1608	mkdir -p ${OBJTREE}/gperf_for_gcc/usr/bin
1609	${_+_}@${ECHODIR} "===> ${_gperf} (obj,depend,all,install)"; \
1610	cd ${.CURDIR}/${_gperf}; \
1611	${NXBMAKE} DIRPRFX=${_gperf}/ obj; \
1612	if [ -z "${NO_DEPEND}" ]; then ${NXBMAKE} DIRPRFX=${_gperf}/ depend; fi; \
1613	${NXBMAKE} DIRPRFX=${_gperf}/ all; \
1614	${NXBMAKE} DIRPRFX=${_gperf}/ DESTDIR=${OBJTREE}/gperf_for_gcc install
1615.endif
1616	mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
1617	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1618	    -p ${NXBDESTDIR}/usr >/dev/null
1619	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1620	    -p ${NXBDESTDIR}/usr/include >/dev/null
1621.if ${MK_DEBUG_FILES} != "no"
1622	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1623	    -p ${NXBDESTDIR}/usr/lib >/dev/null
1624.endif
1625.for _tool in \
1626    bin/cat \
1627    bin/chmod \
1628    bin/cp \
1629    bin/csh \
1630    bin/echo \
1631    bin/expr \
1632    bin/hostname \
1633    bin/ln \
1634    bin/ls \
1635    bin/mkdir \
1636    bin/mv \
1637    bin/ps \
1638    bin/realpath \
1639    bin/rm \
1640    bin/rmdir \
1641    bin/sh \
1642    bin/sleep \
1643    ${_clang_tblgen} \
1644    usr.bin/ar \
1645    ${_binutils} \
1646    ${_elftctools} \
1647    ${_cc} \
1648    ${_gcc_tools} \
1649    ${_clang_libs} \
1650    ${_clang} \
1651    sbin/md5 \
1652    sbin/sysctl \
1653    gnu/usr.bin/diff \
1654    usr.bin/awk \
1655    usr.bin/basename \
1656    usr.bin/bmake \
1657    usr.bin/bzip2 \
1658    usr.bin/cmp \
1659    usr.bin/dirname \
1660    usr.bin/env \
1661    usr.bin/fetch \
1662    usr.bin/find \
1663    usr.bin/grep \
1664    usr.bin/gzip \
1665    usr.bin/id \
1666    usr.bin/lex \
1667    usr.bin/lorder \
1668    usr.bin/mktemp \
1669    usr.bin/mt \
1670    usr.bin/patch \
1671    usr.bin/sed \
1672    usr.bin/sort \
1673    usr.bin/tar \
1674    usr.bin/touch \
1675    usr.bin/tr \
1676    usr.bin/true \
1677    usr.bin/uniq \
1678    usr.bin/unzip \
1679    usr.bin/xargs \
1680    usr.bin/xinstall \
1681    usr.bin/xz \
1682    usr.bin/yacc \
1683    usr.sbin/chown
1684	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1685		cd ${.CURDIR}/${_tool}; \
1686		${NXBMAKE} DIRPRFX=${_tool}/ obj; \
1687		if [ -z "${NO_DEPEND}" ]; then ${NXBMAKE} DIRPRFX=${_tool}/ depend; fi; \
1688		${NXBMAKE} DIRPRFX=${_tool}/ all; \
1689		${NXBMAKE} DIRPRFX=${_tool}/ DESTDIR=${NXBDESTDIR} install
1690.endfor
1691
1692#
1693# hierarchy - ensure that all the needed directories are present
1694#
1695hierarchy hier: .MAKE .PHONY
1696	${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
1697
1698#
1699# libraries - build all libraries, and install them under ${DESTDIR}.
1700#
1701# The list of libraries with dependents (${_prebuild_libs}) and their
1702# interdependencies (__L) are built automatically by the
1703# ${.CURDIR}/tools/make_libdeps.sh script.
1704#
1705libraries: .MAKE .PHONY
1706	${_+_}cd ${.CURDIR}; \
1707	    ${MAKE} -f Makefile.inc1 _prereq_libs; \
1708	    ${MAKE} -f Makefile.inc1 _startup_libs; \
1709	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1710	    ${MAKE} -f Makefile.inc1 _generic_libs
1711
1712#
1713# static libgcc.a prerequisite for shared libc
1714#
1715_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1716
1717# These dependencies are not automatically generated:
1718#
1719# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1720# all shared libraries for ELF.
1721#
1722_startup_libs=	gnu/lib/csu
1723_startup_libs+=	lib/csu
1724_startup_libs+=	gnu/lib/libgcc
1725_startup_libs+=	lib/libcompiler_rt
1726_startup_libs+=	lib/libc
1727_startup_libs+=	lib/libc_nonshared
1728.if ${MK_LIBCPLUSPLUS} != "no"
1729_startup_libs+=	lib/libcxxrt
1730.endif
1731
1732gnu/lib/libgcc__L: lib/libc__L
1733gnu/lib/libgcc__L: lib/libc_nonshared__L
1734.if ${MK_LIBCPLUSPLUS} != "no"
1735lib/libcxxrt__L: gnu/lib/libgcc__L
1736.endif
1737
1738_prebuild_libs=	${_kerberos5_lib_libasn1} \
1739		${_kerberos5_lib_libhdb} \
1740		${_kerberos5_lib_libheimbase} \
1741		${_kerberos5_lib_libheimntlm} \
1742		${_libsqlite3} \
1743		${_kerberos5_lib_libheimipcc} \
1744		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1745		${_kerberos5_lib_libroken} \
1746		${_kerberos5_lib_libwind} \
1747		lib/libbz2 ${_libcom_err} lib/libcrypt \
1748		lib/libelf lib/libexpat \
1749		lib/libfigpar \
1750		${_lib_libgssapi} \
1751		lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
1752		${_lib_casper} \
1753		lib/ncurses/ncurses lib/ncurses/ncursesw \
1754		lib/libopie lib/libpam ${_lib_libthr} \
1755		${_lib_libradius} lib/libsbuf lib/libtacplus \
1756		lib/libgeom \
1757		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1758		${_cddl_lib_libuutil} \
1759		${_cddl_lib_libavl} \
1760		${_cddl_lib_libzfs_core} \
1761		${_cddl_lib_libctf} \
1762		lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
1763		${_secure_lib_libcrypto} ${_lib_libldns} \
1764		${_secure_lib_libssh} ${_secure_lib_libssl} \
1765		gnu/lib/libdialog
1766.if ${MK_GNUCXX} != "no"
1767_prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
1768gnu/lib/libstdc++__L: lib/msun__L
1769gnu/lib/libsupc++__L: gnu/lib/libstdc++__L
1770.endif
1771
1772.if ${MK_LIBCPLUSPLUS} != "no"
1773_prebuild_libs+= lib/libc++
1774.endif
1775
1776lib/libgeom__L: lib/libexpat__L
1777lib/libkvm__L: lib/libelf__L
1778
1779.if ${MK_LIBTHR} != "no"
1780_lib_libthr=	lib/libthr
1781.endif
1782
1783.if ${MK_RADIUS_SUPPORT} != "no"
1784_lib_libradius=	lib/libradius
1785.endif
1786
1787.if ${MK_OFED} != "no"
1788_ofed_lib=		contrib/ofed/usr.lib
1789_prebuild_libs+=	contrib/ofed/usr.lib/libosmcomp
1790_prebuild_libs+=	contrib/ofed/usr.lib/libopensm
1791_prebuild_libs+=	contrib/ofed/usr.lib/libibcommon
1792_prebuild_libs+=	contrib/ofed/usr.lib/libibverbs
1793_prebuild_libs+=	contrib/ofed/usr.lib/libibumad
1794
1795contrib/ofed/usr.lib/libopensm__L: lib/libthr__L
1796contrib/ofed/usr.lib/libosmcomp__L: lib/libthr__L
1797contrib/ofed/usr.lib/libibumad__L: contrib/ofed/usr.lib/libibcommon__L
1798.endif
1799
1800.if ${MK_CASPER} != "no"
1801_lib_casper=	lib/libcasper
1802.endif
1803
1804lib/libpjdlog__L: lib/libutil__L
1805lib/libcasper__L: lib/libnv__L
1806lib/liblzma__L: lib/libthr__L
1807
1808_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1809.for _DIR in ${LOCAL_LIB_DIRS}
1810.if exists(${.CURDIR}/${_DIR}/Makefile) && empty(_generic_libs:M${_DIR})
1811_generic_libs+= ${_DIR}
1812.endif
1813.endfor
1814
1815lib/libopie__L lib/libtacplus__L: lib/libmd__L
1816
1817.if ${MK_CDDL} != "no"
1818_cddl_lib_libumem= cddl/lib/libumem
1819_cddl_lib_libnvpair= cddl/lib/libnvpair
1820_cddl_lib_libavl= cddl/lib/libavl
1821_cddl_lib_libuutil= cddl/lib/libuutil
1822_cddl_lib_libzfs_core= cddl/lib/libzfs_core
1823_cddl_lib_libctf= cddl/lib/libctf
1824_cddl_lib= cddl/lib
1825cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1826cddl/lib/libzfs__L: lib/libgeom__L
1827cddl/lib/libctf__L: lib/libz__L
1828.endif
1829# cddl/lib/libdtrace requires lib/libproc and lib/librtld_db; it's only built
1830# on select architectures though (see cddl/lib/Makefile)
1831.if ${MACHINE_CPUARCH} != "sparc64"
1832_prebuild_libs+=	lib/libproc lib/librtld_db
1833.endif
1834
1835.if ${MK_CRYPT} != "no"
1836.if ${MK_OPENSSL} != "no"
1837_secure_lib_libcrypto= secure/lib/libcrypto
1838_secure_lib_libssl= secure/lib/libssl
1839lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1840.if ${MK_LDNS} != "no"
1841_lib_libldns= lib/libldns
1842lib/libldns__L: secure/lib/libcrypto__L
1843.endif
1844.if ${MK_OPENSSH} != "no"
1845_secure_lib_libssh= secure/lib/libssh
1846secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1847.if ${MK_LDNS} != "no"
1848secure/lib/libssh__L: lib/libldns__L
1849.endif
1850.if ${MK_KERBEROS_SUPPORT} != "no"
1851secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1852    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1853    lib/libmd__L kerberos5/lib/libroken__L
1854.endif
1855.endif
1856.endif
1857_secure_lib=	secure/lib
1858.endif
1859
1860.if ${MK_KERBEROS} != "no"
1861kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1862kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1863    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1864    kerberos5/lib/libwind__L lib/libsqlite3__L
1865kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1866    kerberos5/lib/libroken__L lib/libcom_err__L
1867kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1868    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1869kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1870    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1871    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1872    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1873kerberos5/lib/libroken__L: lib/libcrypt__L
1874kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1875kerberos5/lib/libheimbase__L: lib/libthr__L
1876kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1877.endif
1878
1879lib/libsqlite3__L: lib/libthr__L
1880
1881.if ${MK_GSSAPI} != "no"
1882_lib_libgssapi=	lib/libgssapi
1883.endif
1884
1885.if ${MK_KERBEROS} != "no"
1886_kerberos5_lib=	kerberos5/lib
1887_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1888_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1889_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1890_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1891_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1892_kerberos5_lib_libroken= kerberos5/lib/libroken
1893_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1894_libsqlite3= lib/libsqlite3
1895_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1896_kerberos5_lib_libwind= kerberos5/lib/libwind
1897_libcom_err= lib/libcom_err
1898.endif
1899
1900.if ${MK_NIS} != "no"
1901_lib_libypclnt=	lib/libypclnt
1902.endif
1903
1904.if ${MK_OPENSSL} == "no"
1905lib/libradius__L: lib/libmd__L
1906.endif
1907
1908lib/libproc__L: \
1909    ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
1910.if ${MK_CXX} != "no"
1911.if ${MK_LIBCPLUSPLUS} != "no"
1912lib/libproc__L: lib/libcxxrt__L
1913.else # This implies MK_GNUCXX != "no"; see lib/libproc
1914lib/libproc__L: gnu/lib/libsupc++__L
1915.endif
1916.endif
1917
1918gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
1919
1920.for _lib in ${_prereq_libs}
1921${_lib}__PL: .PHONY .MAKE
1922.if exists(${.CURDIR}/${_lib})
1923	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1924		cd ${.CURDIR}/${_lib}; \
1925		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \
1926		if [ -z "${NO_DEPEND}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ depend; fi; \
1927		${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
1928		    DIRPRFX=${_lib}/ all; \
1929		${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
1930		    DIRPRFX=${_lib}/ install
1931.endif
1932.endfor
1933
1934.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1935${_lib}__L: .PHONY .MAKE
1936.if exists(${.CURDIR}/${_lib})
1937	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1938		cd ${.CURDIR}/${_lib}; \
1939		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \
1940		if [ -z "${NO_DEPEND}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ depend; fi; \
1941		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
1942		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
1943.endif
1944.endfor
1945
1946# libpam is special: we need to build static PAM modules before
1947# static PAM library, and dynamic PAM library before dynamic PAM
1948# modules.
1949lib/libpam__L: .PHONY .MAKE
1950	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1951		cd ${.CURDIR}/lib/libpam; \
1952		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ obj; \
1953		if [ -z "${NO_DEPEND}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ depend; fi; \
1954		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ \
1955		    -D_NO_LIBPAM_SO_YET all; \
1956		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ \
1957		    -D_NO_LIBPAM_SO_YET install
1958
1959_prereq_libs: ${_prereq_libs:S/$/__PL/}
1960_startup_libs: ${_startup_libs:S/$/__L/}
1961_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1962_generic_libs: ${_generic_libs:S/$/__L/}
1963
1964# Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
1965# 'everything' with _PARALLEL_SUBDIR_OK set.  This is because it is unlikely
1966# that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
1967# or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
1968# parallel.  This is safe for the world stage of buildworld though since it has
1969# already built libraries in a proper order and installed includes into
1970# WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
1971# avoid trashing a system if it crashes mid-install.
1972.if !make(all) || defined(_PARALLEL_SUBDIR_OK)
1973SUBDIR_PARALLEL=
1974.endif
1975
1976.include <bsd.subdir.mk>
1977
1978.if make(check-old) || make(check-old-dirs) || \
1979    make(check-old-files) || make(check-old-libs) || \
1980    make(delete-old) || make(delete-old-dirs) || \
1981    make(delete-old-files) || make(delete-old-libs)
1982
1983#
1984# check for / delete old files section
1985#
1986
1987.include "ObsoleteFiles.inc"
1988
1989OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1990else you can not start such an application. Consult UPDATING for more \
1991information regarding how to cope with the removal/revision bump of a \
1992specific library."
1993
1994.if !defined(BATCH_DELETE_OLD_FILES)
1995RM_I=-i
1996.else
1997RM_I=-v
1998.endif
1999
2000delete-old-files:
2001	@echo ">>> Removing old files (only deletes safe to delete libs)"
2002# Ask for every old file if the user really wants to remove it.
2003# It's annoying, but better safe than sorry.
2004# NB: We cannot pass the list of OLD_FILES as a parameter because the
2005# argument list will get too long. Using .for/.endfor make "loops" will make
2006# the Makefile parser segfault.
2007	@exec 3<&0; \
2008	cd ${.CURDIR}; \
2009	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2010	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
2011	while read file; do \
2012		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2013			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
2014			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
2015		fi; \
2016		for ext in debug symbols; do \
2017		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
2018		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2019			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
2020			      <&3; \
2021		  fi; \
2022		done; \
2023	done
2024# Remove catpages without corresponding manpages.
2025	@exec 3<&0; \
2026	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
2027	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
2028	while read catpage; do \
2029		read manpage; \
2030		if [ ! -e "$${manpage}" ]; then \
2031			rm ${RM_I} $${catpage} <&3; \
2032	        fi; \
2033	done
2034	@echo ">>> Old files removed"
2035
2036check-old-files:
2037	@echo ">>> Checking for old files"
2038	@cd ${.CURDIR}; \
2039	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2040	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
2041	while read file; do \
2042		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2043		 	echo "${DESTDIR}/$${file}"; \
2044		fi; \
2045		for ext in debug symbols; do \
2046		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2047			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
2048		  fi; \
2049		done; \
2050	done
2051# Check for catpages without corresponding manpages.
2052	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
2053	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
2054	while read catpage; do \
2055		read manpage; \
2056		if [ ! -e "$${manpage}" ]; then \
2057			echo $${catpage}; \
2058	        fi; \
2059	done
2060
2061delete-old-libs:
2062	@echo ">>> Removing old libraries"
2063	@echo "${OLD_LIBS_MESSAGE}" | fmt
2064	@exec 3<&0; \
2065	cd ${.CURDIR}; \
2066	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2067	    -V OLD_LIBS | xargs -n1 | \
2068	while read file; do \
2069		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2070			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
2071			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
2072		fi; \
2073		for ext in debug symbols; do \
2074		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
2075		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2076			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
2077			      <&3; \
2078		  fi; \
2079		done; \
2080	done
2081	@echo ">>> Old libraries removed"
2082
2083check-old-libs:
2084	@echo ">>> Checking for old libraries"
2085	@cd ${.CURDIR}; \
2086	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2087	    -V OLD_LIBS | xargs -n1 | \
2088	while read file; do \
2089		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2090			echo "${DESTDIR}/$${file}"; \
2091		fi; \
2092		for ext in debug symbols; do \
2093		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2094			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
2095		  fi; \
2096		done; \
2097	done
2098
2099delete-old-dirs:
2100	@echo ">>> Removing old directories"
2101	@cd ${.CURDIR}; \
2102	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2103	    -V OLD_DIRS | xargs -n1 | sort -r | \
2104	while read dir; do \
2105		if [ -d "${DESTDIR}/$${dir}" ]; then \
2106			rmdir -v "${DESTDIR}/$${dir}" || true; \
2107		elif [ -L "${DESTDIR}/$${dir}" ]; then \
2108			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2109		fi; \
2110	done
2111	@echo ">>> Old directories removed"
2112
2113check-old-dirs:
2114	@echo ">>> Checking for old directories"
2115	@cd ${.CURDIR}; \
2116	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2117	    -V OLD_DIRS | xargs -n1 | \
2118	while read dir; do \
2119		if [ -d "${DESTDIR}/$${dir}" ]; then \
2120			echo "${DESTDIR}/$${dir}"; \
2121		elif [ -L "${DESTDIR}/$${dir}" ]; then \
2122			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2123		fi; \
2124	done
2125
2126delete-old: delete-old-files delete-old-dirs
2127	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
2128
2129check-old: check-old-files check-old-libs check-old-dirs
2130	@echo "To remove old files and directories run '${MAKE} delete-old'."
2131	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
2132
2133.endif
2134
2135#
2136# showconfig - show build configuration.
2137#
2138showconfig:
2139	@(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1; \
2140	  ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1) 2>&1 | grep ^MK_ | sort -u
2141
2142.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
2143DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
2144
2145.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
2146.if exists(${KERNCONFDIR}/${KERNCONF})
2147FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
2148	'${KERNCONFDIR}/${KERNCONF}' ; echo
2149.endif
2150.endif
2151
2152.endif
2153
2154.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
2155DTBOUTPUTPATH= ${.CURDIR}
2156.endif
2157
2158#
2159# Build 'standalone' Device Tree Blob
2160#
2161builddtb:
2162	@PATH=${TMPPATH} MACHINE=${TARGET} \
2163	${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
2164	    "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
2165
2166###############
2167
2168# cleanworld
2169# In the following, the first 'rm' in a series will usually remove all
2170# files and directories.  If it does not, then there are probably some
2171# files with file flags set, so this unsets them and tries the 'rm' a
2172# second time.  There are situations where this target will be cleaning
2173# some directories via more than one method, but that duplication is
2174# needed to correctly handle all the possible situations.  Removing all
2175# files without file flags set in the first 'rm' instance saves time,
2176# because 'chflags' will need to operate on fewer files afterwards.
2177#
2178# It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
2179# created by bsd.obj.mk, except that we don't want to .include that file
2180# in this makefile.
2181#
2182BW_CANONICALOBJDIR:=${OBJTREE}${.CURDIR}
2183cleanworld: .PHONY
2184.if exists(${BW_CANONICALOBJDIR}/)
2185	-rm -rf ${BW_CANONICALOBJDIR}/*
2186	-chflags -R 0 ${BW_CANONICALOBJDIR}
2187	rm -rf ${BW_CANONICALOBJDIR}/*
2188.endif
2189.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2190	#   To be safe in this case, fall back to a 'make cleandir'
2191	${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
2192.endif
2193
2194.if defined(TARGET) && defined(TARGET_ARCH)
2195
2196.if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
2197XDEV_CPUTYPE?=${CPUTYPE}
2198.else
2199XDEV_CPUTYPE?=${TARGET_CPUTYPE}
2200.endif
2201
2202NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
2203	MK_MAN=no MK_NLS=no MK_PROFILE=no \
2204	MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
2205	TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
2206	CPUTYPE=${XDEV_CPUTYPE}
2207
2208XDDIR=${TARGET_ARCH}-freebsd
2209XDTP?=/usr/${XDDIR}
2210.if ${XDTP:N/*}
2211.error XDTP variable should be an absolute path
2212.endif
2213
2214CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
2215	INSTALL="sh ${.CURDIR}/tools/install.sh"
2216CDENV= ${CDBENV} \
2217	TOOLS_PREFIX=${XDTP}
2218CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
2219	--sysroot=${XDDESTDIR}/ -B${XDDESTDIR}/usr/libexec \
2220	-B${XDDESTDIR}/usr/bin -B${XDDESTDIR}/usr/lib
2221CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CFLAGS}" \
2222	CPP="${CPP} ${CD2CFLAGS}" \
2223	MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
2224
2225CDTMP=	${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
2226CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2227CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2228XDDESTDIR=${DESTDIR}/${XDTP}
2229.if !defined(OSREL)
2230OSREL!= uname -r | sed -e 's/[-(].*//'
2231.endif
2232
2233.ORDER: xdev-build xdev-install xdev-links
2234xdev: xdev-build xdev-install
2235
2236.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2237xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2238
2239_xb-worldtmp: .PHONY
2240	mkdir -p ${CDTMP}/usr
2241	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2242	    -p ${CDTMP}/usr >/dev/null
2243
2244_xb-bootstrap-tools: .PHONY
2245.for _tool in \
2246    ${_clang_tblgen} \
2247    ${_gperf}
2248	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
2249	cd ${.CURDIR}/${_tool}; \
2250	${CDMAKE} DIRPRFX=${_tool}/ obj; \
2251	if [ -z "${NO_DEPEND}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ depend; fi; \
2252	${CDMAKE} DIRPRFX=${_tool}/ all; \
2253	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
2254.endfor
2255
2256_xb-build-tools: .PHONY
2257	${_+_}@cd ${.CURDIR}; \
2258	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
2259
2260_xb-cross-tools: .PHONY
2261.for _tool in \
2262    ${_binutils} \
2263    ${_elftctools} \
2264    usr.bin/ar \
2265    ${_clang_libs} \
2266    ${_clang} \
2267    ${_cc}
2268	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
2269	cd ${.CURDIR}/${_tool}; \
2270	${CDMAKE} DIRPRFX=${_tool}/ obj; \
2271	if [ -z "${NO_DEPEND}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ depend; fi; \
2272	${CDMAKE} DIRPRFX=${_tool}/ all
2273.endfor
2274
2275_xi-mtree: .PHONY
2276	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
2277	mkdir -p ${XDDESTDIR}
2278	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
2279	    -p ${XDDESTDIR} >/dev/null
2280	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2281	    -p ${XDDESTDIR}/usr >/dev/null
2282	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2283	    -p ${XDDESTDIR}/usr/include >/dev/null
2284.if defined(LIBCOMPAT)
2285	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
2286	    -p ${XDDESTDIR}/usr >/dev/null
2287.endif
2288.if ${MK_TESTS} != "no"
2289	mkdir -p ${XDDESTDIR}${TESTSBASE}
2290	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
2291	    -p ${XDDESTDIR}${TESTSBASE} >/dev/null
2292.endif
2293
2294.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
2295xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
2296
2297_xi-cross-tools: .PHONY
2298	@echo "_xi-cross-tools"
2299.for _tool in \
2300    ${_binutils} \
2301    ${_elftctools} \
2302    usr.bin/ar \
2303    ${_clang_libs} \
2304    ${_clang} \
2305    ${_cc}
2306	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
2307	cd ${.CURDIR}/${_tool}; \
2308	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
2309.endfor
2310
2311_xi-includes: .PHONY
2312	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
2313		DESTDIR=${XDDESTDIR}
2314
2315_xi-libraries: .PHONY
2316	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
2317		DESTDIR=${XDDESTDIR}
2318
2319xdev-links: .PHONY
2320	${_+_}cd ${XDDESTDIR}/usr/bin; \
2321	mkdir -p ../../../../usr/bin; \
2322		for i in *; do \
2323			ln -sf ../../${XDTP}/usr/bin/$$i \
2324			    ../../../../usr/bin/${XDDIR}-$$i; \
2325			ln -sf ../../${XDTP}/usr/bin/$$i \
2326			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
2327		done
2328.else
2329xdev xdev-build xdev-install xdev-links:
2330	@echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${.TARGET}\" target"
2331.endif
2332