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