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