Makefile.inc1 revision 321337
1#
2# $FreeBSD: stable/11/Makefile.inc1 321337 2017-07-21 17:55:40Z bdrewery $
3#
4# Make command line options:
5#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6#	-DNO_CLEAN do not clean at all
7#	-DDB_FROM_SRC use the user/group databases in src/etc instead of
8#	    the system database when installing.
9#	-DNO_SHARE do not go into share subdir
10#	-DKERNFAST define NO_KERNEL{CONFIG,CLEAN,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.if ${USING_SYSTEM_COMPILER} == "yes"
682.for cc in cc c++
683	if [ -x ${WORLDTMP}/usr/bin/${cc} ]; then \
684		inum=$$(stat -f %i ${WORLDTMP}/usr/bin/${cc}); \
685		find ${WORLDTMP}/usr/bin -inum $${inum} -delete; \
686	fi
687.endfor
688.endif	# ${USING_SYSTEM_COMPILER} == "yes"
689.endif	# !defined(NO_CLEAN)
690.for _dir in \
691    lib lib/casper usr legacy/bin legacy/usr
692	mkdir -p ${WORLDTMP}/${_dir}
693.endfor
694	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
695	    -p ${WORLDTMP}/legacy/usr >/dev/null
696.if ${MK_GROFF} != "no"
697	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
698	    -p ${WORLDTMP}/legacy/usr >/dev/null
699.endif
700	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
701	    -p ${WORLDTMP}/legacy/usr/include >/dev/null
702	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
703	    -p ${WORLDTMP}/usr >/dev/null
704	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
705	    -p ${WORLDTMP}/usr/include >/dev/null
706	ln -sf ${.CURDIR}/sys ${WORLDTMP}
707.if ${MK_DEBUG_FILES} != "no"
708	# We could instead disable debug files for these build stages
709	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
710	    -p ${WORLDTMP}/legacy/usr/lib >/dev/null
711	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
712	    -p ${WORLDTMP}/usr/lib >/dev/null
713.endif
714.if defined(LIBCOMPAT)
715	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
716	    -p ${WORLDTMP}/usr >/dev/null
717.if ${MK_DEBUG_FILES} != "no"
718	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
719	    -p ${WORLDTMP}/legacy/usr/lib/debug/usr >/dev/null
720	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
721	    -p ${WORLDTMP}/usr/lib/debug/usr >/dev/null
722.endif
723.endif
724.if ${MK_TESTS} != "no"
725	mkdir -p ${WORLDTMP}${TESTSBASE}
726	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
727	    -p ${WORLDTMP}${TESTSBASE} >/dev/null
728.if ${MK_DEBUG_FILES} != "no"
729	mkdir -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE}
730	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
731	    -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE} >/dev/null
732.endif
733.endif
734.for _mtree in ${LOCAL_MTREE}
735	mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
736.endfor
737_legacy:
738	@echo
739	@echo "--------------------------------------------------------------"
740	@echo ">>> stage 1.1: legacy release compatibility shims"
741	@echo "--------------------------------------------------------------"
742	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
743_bootstrap-tools:
744	@echo
745	@echo "--------------------------------------------------------------"
746	@echo ">>> stage 1.2: bootstrap tools"
747	@echo "--------------------------------------------------------------"
748	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
749_cleanobj:
750.if !defined(NO_CLEAN)
751	@echo
752	@echo "--------------------------------------------------------------"
753	@echo ">>> stage 2.1: cleaning up the object tree"
754	@echo "--------------------------------------------------------------"
755	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR}
756.if defined(LIBCOMPAT)
757	${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} -f Makefile.inc1 ${CLEANDIR}
758.endif
759.endif
760_obj:
761	@echo
762	@echo "--------------------------------------------------------------"
763	@echo ">>> stage 2.2: rebuilding the object tree"
764	@echo "--------------------------------------------------------------"
765	${_+_}cd ${.CURDIR}; ${WMAKE} obj
766_build-tools:
767	@echo
768	@echo "--------------------------------------------------------------"
769	@echo ">>> stage 2.3: build tools"
770	@echo "--------------------------------------------------------------"
771	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
772_cross-tools:
773	@echo
774	@echo "--------------------------------------------------------------"
775	@echo ">>> stage 3: cross tools"
776	@echo "--------------------------------------------------------------"
777	@rm -f ${.OBJDIR}/compiler-metadata.mk
778	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
779	${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
780_compiler-metadata:
781	@echo
782	@echo "--------------------------------------------------------------"
783	@echo ">>> stage 3.1: recording compiler metadata"
784	@echo "--------------------------------------------------------------"
785	${_+_}cd ${.CURDIR}; ${WMAKE} compiler-metadata.mk
786_includes:
787	@echo
788	@echo "--------------------------------------------------------------"
789	@echo ">>> stage 4.1: building includes"
790	@echo "--------------------------------------------------------------"
791# Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
792# headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
793	${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
794	    MK_INCLUDES=yes includes
795.if !empty(SUBDIR_OVERRIDE) && make(buildworld)
796	${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
797.endif
798_libraries:
799	@echo
800	@echo "--------------------------------------------------------------"
801	@echo ">>> stage 4.2: building libraries"
802	@echo "--------------------------------------------------------------"
803	${_+_}cd ${.CURDIR}; \
804	    ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
805	    MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
806everything: .PHONY
807	@echo
808	@echo "--------------------------------------------------------------"
809	@echo ">>> stage 4.3: building everything"
810	@echo "--------------------------------------------------------------"
811	${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
812
813WMAKE_TGTS=
814WMAKE_TGTS+=	_worldtmp _legacy
815.if empty(SUBDIR_OVERRIDE)
816WMAKE_TGTS+=	_bootstrap-tools
817.endif
818WMAKE_TGTS+=	_cleanobj _obj _build-tools _cross-tools
819WMAKE_TGTS+=	_compiler-metadata
820WMAKE_TGTS+=	_includes _libraries
821WMAKE_TGTS+=	everything
822.if defined(LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
823WMAKE_TGTS+=	build${libcompat}
824.endif
825
826buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY
827.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
828
829buildworld_prologue: .PHONY
830	@echo "--------------------------------------------------------------"
831	@echo ">>> World build started on `LC_ALL=C date`"
832	@echo "--------------------------------------------------------------"
833
834buildworld_epilogue: .PHONY
835	@echo
836	@echo "--------------------------------------------------------------"
837	@echo ">>> World build completed on `LC_ALL=C date`"
838	@echo "--------------------------------------------------------------"
839
840#
841# We need to have this as a target because the indirection between Makefile
842# and Makefile.inc1 causes the correct PATH to be used, rather than a
843# modification of the current environment's PATH.  In addition, we need
844# to quote multiword values.
845#
846buildenvvars: .PHONY
847	@echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
848
849.if ${.TARGETS:Mbuildenv}
850.if ${.MAKEFLAGS:M-j}
851.error The buildenv target is incompatible with -j
852.endif
853.endif
854BUILDENV_DIR?=	${.CURDIR}
855buildenv: .PHONY
856	@echo Entering world for ${TARGET_ARCH}:${TARGET}
857.if ${BUILDENV_SHELL:M*zsh*}
858	@echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
859.endif
860	@cd ${BUILDENV_DIR} && env ${WMAKEENV} BUILDENV=1 ${BUILDENV_SHELL} \
861	    || true
862
863TOOLCHAIN_TGTS=	${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
864toolchain: ${TOOLCHAIN_TGTS} .PHONY
865kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries} .PHONY
866
867#
868# installcheck
869#
870# Checks to be sure system is ready for installworld/installkernel.
871#
872installcheck: _installcheck_world _installcheck_kernel .PHONY
873_installcheck_world: .PHONY
874_installcheck_kernel: .PHONY
875
876#
877# Require DESTDIR to be set if installing for a different architecture or
878# using the user/group database in the source tree.
879#
880.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
881    defined(DB_FROM_SRC)
882.if !make(distributeworld)
883_installcheck_world: __installcheck_DESTDIR
884_installcheck_kernel: __installcheck_DESTDIR
885__installcheck_DESTDIR: .PHONY
886.if !defined(DESTDIR) || empty(DESTDIR)
887	@echo "ERROR: Please set DESTDIR!"; \
888	false
889.endif
890.endif
891.endif
892
893.if !defined(DB_FROM_SRC)
894#
895# Check for missing UIDs/GIDs.
896#
897CHECK_UIDS=	auditdistd
898CHECK_GIDS=	audit
899.if ${MK_SENDMAIL} != "no"
900CHECK_UIDS+=	smmsp
901CHECK_GIDS+=	smmsp
902.endif
903.if ${MK_PF} != "no"
904CHECK_UIDS+=	proxy
905CHECK_GIDS+=	proxy authpf
906.endif
907.if ${MK_UNBOUND} != "no"
908CHECK_UIDS+=	unbound
909CHECK_GIDS+=	unbound
910.endif
911_installcheck_world: __installcheck_UGID
912__installcheck_UGID: .PHONY
913.for uid in ${CHECK_UIDS}
914	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
915		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
916		false; \
917	fi
918.endfor
919.for gid in ${CHECK_GIDS}
920	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
921		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
922		false; \
923	fi
924.endfor
925.endif
926#
927# If installing over the running system (DESTDIR is / or unset) and the install
928# includes rescue, try running rescue from the objdir as a sanity check.  If
929# rescue is not functional (e.g., because it depends on a system call not
930# supported by the currently running kernel), abort the installation.
931#
932.if !make(distributeworld) && ${MK_RESCUE} != "no" && \
933    (empty(DESTDIR) || ${DESTDIR} == "/") && empty(BYPASS_INSTALLCHECK_SH)
934_installcheck_world: __installcheck_sh_check
935__installcheck_sh_check: .PHONY
936	@if [ "`${OBJTREE}${.CURDIR}/rescue/rescue/rescue sh -c 'echo OK'`" != \
937	    OK ]; then \
938		echo "rescue/sh check failed, installation aborted" >&2; \
939		false; \
940	fi
941.endif
942
943#
944# Required install tools to be saved in a scratch dir for safety.
945#
946.if ${MK_ZONEINFO} != "no"
947_zoneinfo=	zic tzsetup
948.endif
949
950ITOOLS=	[ awk cap_mkdb cat chflags chmod chown cmp cp \
951	date echo egrep find grep id install ${_install-info} \
952	ln make mkdir mtree mv pwd_mkdb \
953	rm sed services_mkdb sh strip sysctl test true uname wc ${_zoneinfo} \
954	${LOCAL_ITOOLS}
955
956# Needed for share/man
957.if ${MK_MAN_UTILS} != "no"
958ITOOLS+=makewhatis
959.endif
960
961#
962# distributeworld
963#
964# Distributes everything compiled by a `buildworld'.
965#
966# installworld
967#
968# Installs everything compiled by a 'buildworld'.
969#
970
971# Non-base distributions produced by the base system
972EXTRA_DISTRIBUTIONS=	doc
973.if defined(LIBCOMPAT)
974EXTRA_DISTRIBUTIONS+=	lib${libcompat}
975.endif
976.if ${MK_TESTS} != "no"
977EXTRA_DISTRIBUTIONS+=	tests
978.endif
979
980DEBUG_DISTRIBUTIONS=
981.if ${MK_DEBUG_FILES} != "no"
982DEBUG_DISTRIBUTIONS+=	base ${EXTRA_DISTRIBUTIONS:S,doc,,:S,tests,,}
983.endif
984
985MTREE_MAGIC?=	mtree 2.0
986
987distributeworld installworld stageworld: _installcheck_world .PHONY
988	mkdir -p ${INSTALLTMP}
989	progs=$$(for prog in ${ITOOLS}; do \
990		if progpath=`which $$prog`; then \
991			echo $$progpath; \
992		else \
993			echo "Required tool $$prog not found in PATH." >&2; \
994			exit 1; \
995		fi; \
996	    done); \
997	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
998	    while read line; do \
999		set -- $$line; \
1000		if [ "$$2 $$3" != "not found" ]; then \
1001			echo $$2; \
1002		else \
1003			echo "Required library $$1 not found." >&2; \
1004			exit 1; \
1005		fi; \
1006	    done); \
1007	cp $$libs $$progs ${INSTALLTMP}
1008	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
1009.if defined(NO_ROOT)
1010	-mkdir -p ${METALOG:H}
1011	echo "#${MTREE_MAGIC}" > ${METALOG}
1012.endif
1013.if make(distributeworld)
1014.for dist in ${EXTRA_DISTRIBUTIONS}
1015	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
1016	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1017	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
1018	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1019	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1020	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1021	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
1022.if ${MK_DEBUG_FILES} != "no"
1023	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1024	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
1025.endif
1026.if defined(LIBCOMPAT)
1027	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1028	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1029.if ${MK_DEBUG_FILES} != "no"
1030	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1031	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
1032.endif
1033.endif
1034.if ${MK_TESTS} != "no" && ${dist} == "tests"
1035	-mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
1036	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1037	    -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
1038.if ${MK_DEBUG_FILES} != "no"
1039	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1040	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
1041.endif
1042.endif
1043.if defined(NO_ROOT)
1044	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
1045	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
1046	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
1047	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1048	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
1049	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
1050.if defined(LIBCOMPAT)
1051	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
1052	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1053.endif
1054.endif
1055.endfor
1056	-mkdir ${DESTDIR}/${DISTDIR}/base
1057	${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1058	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
1059	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
1060	    LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
1061.endif
1062	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
1063	    ${IMAKEENV} rm -rf ${INSTALLTMP}
1064.if make(distributeworld)
1065.for dist in ${EXTRA_DISTRIBUTIONS}
1066	find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete
1067.endfor
1068.if defined(NO_ROOT)
1069.for dist in base ${EXTRA_DISTRIBUTIONS}
1070	@# For each file that exists in this dist, print the corresponding
1071	@# line from the METALOG.  This relies on the fact that
1072	@# a line containing only the filename will sort immediately before
1073	@# the relevant mtree line.
1074	cd ${DESTDIR}/${DISTDIR}; \
1075	find ./${dist} | sort -u ${METALOG} - | \
1076	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1077	${DESTDIR}/${DISTDIR}/${dist}.meta
1078.endfor
1079.for dist in ${DEBUG_DISTRIBUTIONS}
1080	@# For each file that exists in this dist, print the corresponding
1081	@# line from the METALOG.  This relies on the fact that
1082	@# a line containing only the filename will sort immediately before
1083	@# the relevant mtree line.
1084	cd ${DESTDIR}/${DISTDIR}; \
1085	find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
1086	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1087	${DESTDIR}/${DISTDIR}/${dist}.debug.meta
1088.endfor
1089.endif
1090.endif
1091
1092packageworld: .PHONY
1093.for dist in base ${EXTRA_DISTRIBUTIONS}
1094.if defined(NO_ROOT)
1095	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1096	    tar cvf - --exclude usr/lib/debug \
1097	    @${DESTDIR}/${DISTDIR}/${dist}.meta | \
1098	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1099.else
1100	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1101	    tar cvf - --exclude usr/lib/debug . | \
1102	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1103.endif
1104.endfor
1105
1106.for dist in ${DEBUG_DISTRIBUTIONS}
1107. if defined(NO_ROOT)
1108	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1109	    tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
1110	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1111. else
1112	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1113	    tar cvLf - usr/lib/debug | \
1114	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1115. endif
1116.endfor
1117
1118#
1119# reinstall
1120#
1121# If you have a build server, you can NFS mount the source and obj directories
1122# and do a 'make reinstall' on the *client* to install new binaries from the
1123# most recent server build.
1124#
1125restage reinstall: .MAKE .PHONY
1126	@echo "--------------------------------------------------------------"
1127	@echo ">>> Making hierarchy"
1128	@echo "--------------------------------------------------------------"
1129	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1130	    LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
1131.if make(restage)
1132	@echo "--------------------------------------------------------------"
1133	@echo ">>> Making distribution"
1134	@echo "--------------------------------------------------------------"
1135	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1136	    LOCAL_MTREE=${LOCAL_MTREE:Q} distribution
1137.endif
1138	@echo
1139	@echo "--------------------------------------------------------------"
1140	@echo ">>> Installing everything"
1141	@echo "--------------------------------------------------------------"
1142	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
1143.if defined(LIBCOMPAT)
1144	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
1145.endif
1146
1147redistribute: .MAKE .PHONY
1148	@echo "--------------------------------------------------------------"
1149	@echo ">>> Distributing everything"
1150	@echo "--------------------------------------------------------------"
1151	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1152.if defined(LIBCOMPAT)
1153	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1154	    DISTRIBUTION=lib${libcompat}
1155.endif
1156
1157distrib-dirs distribution: .MAKE .PHONY
1158	${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1159	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1160.if make(distribution)
1161	${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1162		${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1163		METALOG=${METALOG} MK_TESTS=no installconfig
1164.endif
1165
1166#
1167# buildkernel and installkernel
1168#
1169# Which kernels to build and/or install is specified by setting
1170# KERNCONF. If not defined a GENERIC kernel is built/installed.
1171# Only the existing (depending TARGET) config files are used
1172# for building kernels and only the first of these is designated
1173# as the one being installed.
1174#
1175# Note that we have to use TARGET instead of TARGET_ARCH when
1176# we're in kernel-land. Since only TARGET_ARCH is (expected) to
1177# be set to cross-build, we have to make sure TARGET is set
1178# properly.
1179
1180.if defined(KERNFAST)
1181NO_KERNELCLEAN=	t
1182NO_KERNELCONFIG=	t
1183NO_KERNELOBJ=		t
1184# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1185.if !defined(KERNCONF) && ${KERNFAST} != "1"
1186KERNCONF=${KERNFAST}
1187.endif
1188.endif
1189.if ${TARGET_ARCH} == "powerpc64"
1190KERNCONF?=	GENERIC64
1191.else
1192KERNCONF?=	GENERIC
1193.endif
1194INSTKERNNAME?=	kernel
1195
1196KERNSRCDIR?=	${.CURDIR}/sys
1197KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
1198KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
1199KERNCONFDIR?=	${KRNLCONFDIR}
1200
1201BUILDKERNELS=
1202INSTALLKERNEL=
1203.if defined(NO_INSTALLKERNEL)
1204# All of the BUILDKERNELS loops start at index 1.
1205BUILDKERNELS+= dummy
1206.endif
1207.for _kernel in ${KERNCONF}
1208.if exists(${KERNCONFDIR}/${_kernel})
1209BUILDKERNELS+=	${_kernel}
1210.if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1211INSTALLKERNEL= ${_kernel}
1212.endif
1213.endif
1214.endfor
1215
1216${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1217
1218#
1219# buildkernel
1220#
1221# Builds all kernels defined by BUILDKERNELS.
1222#
1223buildkernel: .MAKE .PHONY
1224.if empty(BUILDKERNELS:Ndummy)
1225	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1226	false
1227.endif
1228	@echo
1229.for _kernel in ${BUILDKERNELS:Ndummy}
1230	@echo "--------------------------------------------------------------"
1231	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1232	@echo "--------------------------------------------------------------"
1233	@echo "===> ${_kernel}"
1234	mkdir -p ${KRNLOBJDIR}
1235.if !defined(NO_KERNELCONFIG)
1236	@echo
1237	@echo "--------------------------------------------------------------"
1238	@echo ">>> stage 1: configuring the kernel"
1239	@echo "--------------------------------------------------------------"
1240	cd ${KRNLCONFDIR}; \
1241		PATH=${TMPPATH} \
1242		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1243			-I '${KERNCONFDIR}' '${KERNCONFDIR}/${_kernel}'
1244.endif
1245.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1246	@echo
1247	@echo "--------------------------------------------------------------"
1248	@echo ">>> stage 2.1: cleaning up the object tree"
1249	@echo "--------------------------------------------------------------"
1250	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1251.endif
1252.if !defined(NO_KERNELOBJ)
1253	@echo
1254	@echo "--------------------------------------------------------------"
1255	@echo ">>> stage 2.2: rebuilding the object tree"
1256	@echo "--------------------------------------------------------------"
1257	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1258.endif
1259	@echo
1260	@echo "--------------------------------------------------------------"
1261	@echo ">>> stage 2.3: build tools"
1262	@echo "--------------------------------------------------------------"
1263	${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1264	@echo
1265	@echo "--------------------------------------------------------------"
1266	@echo ">>> stage 3.1: building everything"
1267	@echo "--------------------------------------------------------------"
1268	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1269	@echo "--------------------------------------------------------------"
1270	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1271	@echo "--------------------------------------------------------------"
1272.endfor
1273
1274NO_INSTALLEXTRAKERNELS?=	yes
1275
1276#
1277# installkernel, etc.
1278#
1279# Install the kernel defined by INSTALLKERNEL
1280#
1281installkernel installkernel.debug \
1282reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1283.if !defined(NO_INSTALLKERNEL)
1284.if empty(INSTALLKERNEL)
1285	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1286	false
1287.endif
1288	@echo "--------------------------------------------------------------"
1289	@echo ">>> Installing kernel ${INSTALLKERNEL}"
1290	@echo "--------------------------------------------------------------"
1291	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1292	    ${CROSSENV} PATH=${TMPPATH} \
1293	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1294.endif
1295.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1296.for _kernel in ${BUILDKERNELS:[2..-1]}
1297	@echo "--------------------------------------------------------------"
1298	@echo ">>> Installing kernel ${_kernel}"
1299	@echo "--------------------------------------------------------------"
1300	cd ${KRNLOBJDIR}/${_kernel}; \
1301	    ${CROSSENV} PATH=${TMPPATH} \
1302	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1303.endfor
1304.endif
1305
1306distributekernel distributekernel.debug: .PHONY
1307.if !defined(NO_INSTALLKERNEL)
1308.if empty(INSTALLKERNEL)
1309	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1310	false
1311.endif
1312	mkdir -p ${DESTDIR}/${DISTDIR}
1313.if defined(NO_ROOT)
1314	@echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1315.endif
1316	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1317	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1318	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1319	    DESTDIR=${INSTALL_DDIR}/kernel \
1320	    ${.TARGET:S/distributekernel/install/}
1321.if defined(NO_ROOT)
1322	@sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1323	    ${DESTDIR}/${DISTDIR}/kernel.meta
1324.endif
1325.endif
1326.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1327.for _kernel in ${BUILDKERNELS:[2..-1]}
1328.if defined(NO_ROOT)
1329	@echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1330.endif
1331	cd ${KRNLOBJDIR}/${_kernel}; \
1332	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1333	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1334	    KERNEL=${INSTKERNNAME}.${_kernel} \
1335	    DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1336	    ${.TARGET:S/distributekernel/install/}
1337.if defined(NO_ROOT)
1338	@sed -e "s|^./kernel.${_kernel}|.|" \
1339	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1340	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1341.endif
1342.endfor
1343.endif
1344
1345packagekernel: .PHONY
1346.if defined(NO_ROOT)
1347.if !defined(NO_INSTALLKERNEL)
1348	cd ${DESTDIR}/${DISTDIR}/kernel; \
1349	    tar cvf - --exclude '*.debug' \
1350	    @${DESTDIR}/${DISTDIR}/kernel.meta | \
1351	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1352.endif
1353	cd ${DESTDIR}/${DISTDIR}/kernel; \
1354	    tar cvf - --include '*/*/*.debug' \
1355	    @${DESTDIR}/${DISTDIR}/kernel.meta | \
1356	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1357.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1358.for _kernel in ${BUILDKERNELS:[2..-1]}
1359	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1360	    tar cvf - --exclude '*.debug' \
1361	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1362	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1363	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1364	    tar cvf - --include '*/*/*.debug' \
1365	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1366	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1367.endfor
1368.endif
1369.else
1370.if !defined(NO_INSTALLKERNEL)
1371	cd ${DESTDIR}/${DISTDIR}/kernel; \
1372	    tar cvf - --exclude '*.debug' . | \
1373	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1374.endif
1375	cd ${DESTDIR}/${DISTDIR}/kernel; \
1376	    tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1377	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1378.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1379.for _kernel in ${BUILDKERNELS:[2..-1]}
1380	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1381	    tar cvf - --exclude '*.debug' . | \
1382	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1383	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1384	    tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1385	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1386.endfor
1387.endif
1388.endif
1389
1390stagekernel: .PHONY
1391	${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1392
1393PORTSDIR?=	/usr/ports
1394WSTAGEDIR?=	${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/worldstage
1395KSTAGEDIR?=	${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/kernelstage
1396REPODIR?=	${MAKEOBJDIRPREFIX}${.CURDIR}/repo
1397PKGSIGNKEY?=	# empty
1398
1399.ORDER:		stage-packages create-packages
1400.ORDER:		create-packages create-world-packages
1401.ORDER:		create-packages create-kernel-packages
1402.ORDER:		create-packages sign-packages
1403
1404_pkgbootstrap: .PHONY
1405.if !exists(${LOCALBASE}/sbin/pkg)
1406	@env ASSUME_ALWAYS_YES=YES pkg bootstrap
1407.endif
1408
1409packages: .PHONY
1410	${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1411
1412package-pkg: .PHONY
1413	rm -rf /tmp/ports.${TARGET} || :
1414	env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \
1415		PKG_CMD=${PKG_CMD} PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} \
1416		WSTAGEDIR=${WSTAGEDIR} \
1417		sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1418
1419real-packages:	stage-packages create-packages sign-packages .PHONY
1420
1421stage-packages: .PHONY
1422	@mkdir -p ${REPODIR} ${WSTAGEDIR} ${KSTAGEDIR}
1423	${_+_}@cd ${.CURDIR}; \
1424		${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT -B stageworld ; \
1425		${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT -B stagekernel
1426
1427create-packages:	_pkgbootstrap .PHONY
1428	@mkdir -p ${REPODIR}
1429	${_+_}@cd ${.CURDIR}; \
1430		${MAKE} DESTDIR=${WSTAGEDIR} \
1431			PKG_VERSION=${PKG_VERSION} create-world-packages ; \
1432		${MAKE} DESTDIR=${KSTAGEDIR} \
1433			PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1434			create-kernel-packages
1435
1436create-world-packages:	_pkgbootstrap .PHONY
1437	@rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1438	@cd ${WSTAGEDIR} ; \
1439		awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1440		${WSTAGEDIR}/METALOG
1441	@for plist in ${WSTAGEDIR}/*.plist; do \
1442		plist=$${plist##*/} ; \
1443		pkgname=$${plist%.plist} ; \
1444		sh ${SRCDIR}/release/packages/generate-ucl.sh -o $${pkgname} \
1445			-s ${SRCDIR} -u ${WSTAGEDIR}/$${pkgname}.ucl ; \
1446	done
1447	@for plist in ${WSTAGEDIR}/*.plist; do \
1448		plist=$${plist##*/} ; \
1449		pkgname=$${plist%.plist} ; \
1450		awk -F\" ' \
1451			/^name/ { printf("===> Creating %s-", $$2); next } \
1452			/^version/ { print $$2; next } \
1453			' ${WSTAGEDIR}/$${pkgname}.ucl ; \
1454		${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
1455			create -M ${WSTAGEDIR}/$${pkgname}.ucl \
1456			-p ${WSTAGEDIR}/$${pkgname}.plist \
1457			-r ${WSTAGEDIR} \
1458			-o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} ; \
1459	done
1460
1461create-kernel-packages:	_pkgbootstrap .PHONY
1462.if exists(${KSTAGEDIR}/kernel.meta)
1463.for flavor in "" -debug
1464	@cd ${KSTAGEDIR}/${DISTDIR} ; \
1465	awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1466		-v kernel=yes -v _kernconf=${INSTALLKERNEL} \
1467		${KSTAGEDIR}/kernel.meta ; \
1468	cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \
1469	pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \
1470	sed -e "s/%VERSION%/${PKG_VERSION}/" \
1471		-e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1472		-e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1473		-e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1474		-e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \
1475		-e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \
1476		${SRCDIR}/release/packages/kernel.ucl \
1477		> ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1478	awk -F\" ' \
1479		/name/ { printf("===> Creating %s-", $$2); next } \
1480		/version/ {print $$2; next } ' \
1481		${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1482	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
1483		create -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
1484		-p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
1485		-r ${KSTAGEDIR}/${DISTDIR} \
1486		-o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
1487.endfor
1488.endif
1489.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1490.for _kernel in ${BUILDKERNELS:[2..-1]}
1491.if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
1492.for flavor in "" -debug
1493	@cd ${KSTAGEDIR}/kernel.${_kernel} ; \
1494	awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1495		-v kernel=yes -v _kernconf=${_kernel} \
1496		${KSTAGEDIR}/kernel.${_kernel}.meta ; \
1497	cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \
1498	pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \
1499	sed -e "s/%VERSION%/${PKG_VERSION}/" \
1500		-e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
1501		-e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
1502		-e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
1503		-e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \
1504		-e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \
1505		${SRCDIR}/release/packages/kernel.ucl \
1506		> ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
1507	awk -F\" ' \
1508		/name/ { printf("===> Creating %s-", $$2); next } \
1509		/version/ {print $$2; next } ' \
1510		${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
1511	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
1512		create -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
1513		-p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
1514		-r ${KSTAGEDIR}/kernel.${_kernel} \
1515		-o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
1516.endfor
1517.endif
1518.endfor
1519.endif
1520
1521sign-packages:	_pkgbootstrap .PHONY
1522	@[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest" ] && \
1523		unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest ; \
1524	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh repo \
1525		-o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
1526		${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
1527		${PKGSIGNKEY} ; \
1528	cd ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI); \
1529	ln -s ${PKG_VERSION} latest
1530
1531#
1532#
1533# checkworld
1534#
1535# Run test suite on installed world.
1536#
1537checkworld: .PHONY
1538	@if [ ! -x "${LOCALBASE}/bin/kyua" ]; then \
1539		echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
1540		exit 1; \
1541	fi
1542	${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile
1543
1544#
1545#
1546# doxygen
1547#
1548# Build the API documentation with doxygen
1549#
1550doxygen: .PHONY
1551	@if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \
1552		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1553		exit 1; \
1554	fi
1555	${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
1556
1557#
1558# update
1559#
1560# Update the source tree(s), by running svn/svnup to update to the
1561# latest copy.
1562#
1563update: .PHONY
1564.if defined(SVN_UPDATE)
1565	@echo "--------------------------------------------------------------"
1566	@echo ">>> Updating ${.CURDIR} using Subversion"
1567	@echo "--------------------------------------------------------------"
1568	@(cd ${.CURDIR}; ${SVN} update ${SVNFLAGS})
1569.endif
1570
1571#
1572# ------------------------------------------------------------------------
1573#
1574# From here onwards are utility targets used by the 'make world' and
1575# related targets.  If your 'world' breaks, you may like to try to fix
1576# the problem and manually run the following targets to attempt to
1577# complete the build.  Beware, this is *not* guaranteed to work, you
1578# need to have a pretty good grip on the current state of the system
1579# to attempt to manually finish it.  If in doubt, 'make world' again.
1580#
1581
1582#
1583# legacy: Build compatibility shims for the next three targets. This is a
1584# minimal set of tools and shims necessary to compensate for older systems
1585# which don't have the APIs required by the targets built in bootstrap-tools,
1586# build-tools or cross-tools.
1587#
1588
1589# ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
1590# r296685 fix cross-endian objcopy
1591.if ${BOOTSTRAPPING} < 1100102
1592_elftoolchain_libs= lib/libelf lib/libdwarf
1593.endif
1594
1595legacy: .PHONY
1596.if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0
1597	@echo "ERROR: Source upgrades from versions prior to ${MINIMUM_SUPPORTED_REL} are not supported."; \
1598	false
1599.endif
1600.for _tool in tools/build ${_elftoolchain_libs}
1601	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
1602	    cd ${.CURDIR}/${_tool}; \
1603	    ${MAKE} DIRPRFX=${_tool}/ obj; \
1604	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
1605	    ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no all; \
1606	    ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no \
1607	        DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1608.endfor
1609
1610#
1611# bootstrap-tools: Build tools needed for compatibility. These are binaries that
1612# are built to build other binaries in the system. However, the focus of these
1613# binaries is usually quite narrow. Bootstrap tools use the host's compiler and
1614# libraries, augmented by -legacy.
1615#
1616_bt=		_bootstrap-tools
1617
1618.if ${MK_GAMES} != "no"
1619_strfile=	usr.bin/fortune/strfile
1620.endif
1621
1622.if ${MK_GCC} != "no" && ${MK_CXX} != "no"
1623_gperf=		gnu/usr.bin/gperf
1624.endif
1625
1626.if ${MK_SHAREDOCS} != "no" && ${MK_GROFF} != "no"
1627_groff=		gnu/usr.bin/groff \
1628		usr.bin/soelim
1629.endif
1630
1631.if ${MK_VT} != "no"
1632_vtfontcvt=	usr.bin/vtfontcvt
1633.endif
1634
1635.if ${BOOTSTRAPPING} < 1000033
1636_libopenbsd=	lib/libopenbsd
1637_m4=		usr.bin/m4
1638_lex=		usr.bin/lex
1639
1640${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd
1641${_bt}-usr.bin/lex: ${_bt}-usr.bin/m4
1642.endif
1643
1644# r245440 mtree -N support added
1645# r313404 requires sha384.h for libnetbsd, added to libmd in r292782
1646.if ${BOOTSTRAPPING} < 1100093
1647_nmtree=	lib/libmd \
1648		lib/libnetbsd \
1649		usr.sbin/nmtree
1650
1651${_bt}-lib/libnetbsd: ${_bt}-lib/libmd
1652${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
1653.endif
1654
1655.if ${BOOTSTRAPPING} < 1000027
1656_cat=		bin/cat
1657.endif
1658
1659# r277259 crunchide: Correct 64-bit section header offset
1660# r281674 crunchide: always include both 32- and 64-bit ELF support
1661.if ${BOOTSTRAPPING} < 1100078
1662_crunchide=	usr.sbin/crunch/crunchide
1663.endif
1664
1665# r285986 crunchen: use STRIPBIN rather than STRIP
1666# 1100113: Support MK_AUTO_OBJ
1667# 1100509: META_MODE fixes
1668.if ${BOOTSTRAPPING} < 1100078 || \
1669    (${MK_AUTO_OBJ} == "yes" && ${BOOTSTRAPPING} < 1100114) || \
1670    (${MK_META_MODE} == "yes" && ${BOOTSTRAPPING} < 1200006)
1671_crunchgen=	usr.sbin/crunch/crunchgen
1672.endif
1673
1674# r296926 -P keymap search path, MFC to stable/10 in r298297
1675.if ${BOOTSTRAPPING} < 1003501 || \
1676	(${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103)
1677_kbdcontrol=	usr.sbin/kbdcontrol
1678.endif
1679
1680_yacc=		lib/liby \
1681		usr.bin/yacc
1682
1683${_bt}-usr.bin/yacc: ${_bt}-lib/liby
1684
1685.if ${MK_BSNMP} != "no"
1686_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
1687.endif
1688
1689# We need to build tblgen when we're building clang or lld, either as
1690# bootstrap tools, or as the part of the normal build.
1691.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" || \
1692    ${MK_LLD_BOOTSTRAP} != "no" || ${MK_LLD} != "no"
1693_clang_tblgen= \
1694	lib/clang/libllvmminimal \
1695	usr.bin/clang/llvm-tblgen \
1696	usr.bin/clang/clang-tblgen
1697
1698${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmminimal
1699${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmminimal
1700.endif
1701
1702# Default to building the GPL DTC, but build the BSDL one if users explicitly
1703# request it.
1704_dtc= usr.bin/dtc
1705.if ${MK_GPL_DTC} != "no"
1706_dtc= gnu/usr.bin/dtc
1707.endif
1708
1709.if ${MK_KERBEROS} != "no"
1710_kerberos5_bootstrap_tools= \
1711	kerberos5/tools/make-roken \
1712	kerberos5/lib/libroken \
1713	kerberos5/lib/libvers \
1714	kerberos5/tools/asn1_compile \
1715	kerberos5/tools/slc \
1716	usr.bin/compile_et
1717
1718.ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
1719.endif
1720
1721# r283777 makewhatis(1) replaced with mandoc version which builds a database.
1722.if ${MK_MANDOCDB} != "no"
1723_libopenbsd?=	lib/libopenbsd
1724_makewhatis=	usr.bin/mandoc
1725${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd
1726.endif
1727
1728bootstrap-tools: .PHONY
1729
1730#	Please document (add comment) why something is in 'bootstrap-tools'.
1731#	Try to bound the building of the bootstrap-tool to just the
1732#	FreeBSD versions that need the tool built at this stage of the build.
1733.for _tool in \
1734    ${_clang_tblgen} \
1735    ${_kerberos5_bootstrap_tools} \
1736    ${_strfile} \
1737    ${_gperf} \
1738    ${_groff} \
1739    ${_dtc} \
1740    ${_cat} \
1741    ${_kbdcontrol} \
1742    usr.bin/lorder \
1743    ${_libopenbsd} \
1744    ${_makewhatis} \
1745    usr.bin/rpcgen \
1746    ${_yacc} \
1747    ${_m4} \
1748    ${_lex} \
1749    usr.bin/xinstall \
1750    ${_gensnmptree} \
1751    usr.sbin/config \
1752    ${_crunchide} \
1753    ${_crunchgen} \
1754    ${_nmtree} \
1755    ${_vtfontcvt} \
1756    usr.bin/localedef
1757${_bt}-${_tool}: .PHONY .MAKE
1758	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
1759		cd ${.CURDIR}/${_tool}; \
1760		${MAKE} DIRPRFX=${_tool}/ obj; \
1761		${MAKE} DIRPRFX=${_tool}/ all; \
1762		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1763
1764bootstrap-tools: ${_bt}-${_tool}
1765.endfor
1766
1767#
1768# build-tools: Build special purpose build tools
1769#
1770.if !defined(NO_SHARE)
1771_share=	share/syscons/scrnmaps
1772.endif
1773
1774.if ${MK_GCC} != "no"
1775_gcc_tools= gnu/usr.bin/cc/cc_tools
1776.endif
1777
1778.if ${MK_RESCUE} != "no"
1779# rescue includes programs that have build-tools targets
1780_rescue=rescue/rescue
1781.endif
1782
1783.for _tool in \
1784    bin/csh \
1785    bin/sh \
1786    ${LOCAL_TOOL_DIRS} \
1787    lib/ncurses/ncurses \
1788    lib/ncurses/ncursesw \
1789    ${_rescue} \
1790    ${_share} \
1791    usr.bin/awk \
1792    lib/libmagic \
1793    usr.bin/mkesdb_static \
1794    usr.bin/mkcsmapper_static \
1795    usr.bin/vi/catalog
1796build-tools_${_tool}: .PHONY
1797	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1798		cd ${.CURDIR}/${_tool}; \
1799		${MAKE} DIRPRFX=${_tool}/ obj; \
1800		${MAKE} DIRPRFX=${_tool}/ build-tools
1801build-tools: build-tools_${_tool}
1802.endfor
1803.for _tool in \
1804    ${_gcc_tools}
1805build-tools_${_tool}: .PHONY
1806	${_+_}@${ECHODIR} "===> ${_tool} (obj,all)"; \
1807		cd ${.CURDIR}/${_tool}; \
1808		${MAKE} DIRPRFX=${_tool}/ obj; \
1809		${MAKE} DIRPRFX=${_tool}/ all
1810build-tools: build-tools_${_tool}
1811.endfor
1812
1813#
1814# kernel-tools: Build kernel-building tools
1815#
1816kernel-tools: .PHONY
1817	mkdir -p ${MAKEOBJDIRPREFIX}/usr
1818	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1819	    -p ${MAKEOBJDIRPREFIX}/usr >/dev/null
1820
1821#
1822# cross-tools: All the tools needed to build the rest of the system after
1823# we get done with the earlier stages. It is the last set of tools needed
1824# to begin building the target binaries.
1825#
1826.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1827.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1828_btxld=		usr.sbin/btxld
1829.endif
1830.endif
1831
1832# Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
1833# resulting from missing bug fixes or ELF Toolchain updates.
1834.if ${MK_CDDL} != "no"
1835_dtrace_tools= cddl/lib/libctf cddl/usr.bin/ctfconvert \
1836    cddl/usr.bin/ctfmerge
1837.endif
1838
1839# If we're given an XAS, don't build binutils.
1840.if ${XAS:M/*} == ""
1841.if ${MK_BINUTILS_BOOTSTRAP} != "no"
1842_binutils=	gnu/usr.bin/binutils
1843.endif
1844.if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
1845_elftctools=	lib/libelftc \
1846		lib/libpe \
1847		usr.bin/elfcopy \
1848		usr.bin/nm \
1849		usr.bin/size \
1850		usr.bin/strings
1851# These are not required by the build, but can be useful for developers who
1852# cross-build on a FreeBSD 10 host:
1853_elftctools+=	usr.bin/addr2line
1854.endif
1855.elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
1856# If cross-building with an external binutils we still need to build strip for
1857# the target (for at least crunchide).
1858_elftctools=	lib/libelftc \
1859		lib/libpe \
1860		usr.bin/elfcopy
1861.endif
1862
1863.if ${MK_CLANG_BOOTSTRAP} != "no"
1864_clang=		usr.bin/clang
1865.endif
1866.if ${MK_LLD_BOOTSTRAP} != "no"
1867_lld=		usr.bin/clang/lld
1868.endif
1869.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
1870_clang_libs=	lib/clang
1871.endif
1872.if ${MK_GCC_BOOTSTRAP} != "no"
1873_gcc=		gnu/usr.bin/cc
1874.endif
1875.if ${MK_USB} != "no"
1876_usb_tools=	sys/boot/usb/tools
1877.endif
1878
1879cross-tools: .MAKE .PHONY
1880.for _tool in \
1881    ${_clang_libs} \
1882    ${_clang} \
1883    ${_lld} \
1884    ${_binutils} \
1885    ${_elftctools} \
1886    ${_dtrace_tools} \
1887    ${_gcc} \
1888    ${_btxld} \
1889    ${_usb_tools}
1890	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
1891		cd ${.CURDIR}/${_tool}; \
1892		${MAKE} DIRPRFX=${_tool}/ obj; \
1893		${MAKE} DIRPRFX=${_tool}/ all; \
1894		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1895.endfor
1896
1897NXBDESTDIR=	${OBJTREE}/nxb-bin
1898NXBENV=		MAKEOBJDIRPREFIX=${OBJTREE}/nxb \
1899		TOOLS_PREFIX= \
1900		INSTALL="sh ${.CURDIR}/tools/install.sh" \
1901		PATH=${PATH}:${OBJTREE}/gperf_for_gcc/usr/bin
1902NXBMAKE=	${NXBENV} ${MAKE} \
1903		LLVM_TBLGEN=${NXBDESTDIR}/usr/bin/llvm-tblgen \
1904		CLANG_TBLGEN=${NXBDESTDIR}/usr/bin/clang-tblgen \
1905		MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
1906		MK_GDB=no MK_TESTS=no \
1907		SSP_CFLAGS= \
1908		MK_HTML=no NO_LINT=yes MK_MAN=no \
1909		-DNO_PIC MK_PROFILE=no -DNO_SHARED \
1910		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
1911		MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
1912		MK_LLDB=no MK_DEBUG_FILES=no
1913
1914# native-xtools is the current target for qemu-user cross builds of ports
1915# via poudriere and the imgact_binmisc kernel module.
1916# For non-clang enabled targets that are still using the in tree gcc
1917# we must build a gperf binary for one instance of its Makefiles.  On
1918# clang-enabled systems, the gperf binary is obsolete.
1919native-xtools: .PHONY
1920.if ${MK_GCC_BOOTSTRAP} != "no"
1921	mkdir -p ${OBJTREE}/gperf_for_gcc/usr/bin
1922	${_+_}@${ECHODIR} "===> ${_gperf} (obj,all,install)"; \
1923	cd ${.CURDIR}/${_gperf}; \
1924	${NXBMAKE} DIRPRFX=${_gperf}/ obj; \
1925	${NXBMAKE} DIRPRFX=${_gperf}/ all; \
1926	${NXBMAKE} DIRPRFX=${_gperf}/ DESTDIR=${OBJTREE}/gperf_for_gcc install
1927.endif
1928	mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
1929	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1930	    -p ${NXBDESTDIR}/usr >/dev/null
1931	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1932	    -p ${NXBDESTDIR}/usr/include >/dev/null
1933.if ${MK_DEBUG_FILES} != "no"
1934	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1935	    -p ${NXBDESTDIR}/usr/lib >/dev/null
1936.endif
1937.for _tool in \
1938    bin/cat \
1939    bin/chmod \
1940    bin/cp \
1941    bin/csh \
1942    bin/echo \
1943    bin/expr \
1944    bin/hostname \
1945    bin/ln \
1946    bin/ls \
1947    bin/mkdir \
1948    bin/mv \
1949    bin/ps \
1950    bin/realpath \
1951    bin/rm \
1952    bin/rmdir \
1953    bin/sh \
1954    bin/sleep \
1955    ${_clang_tblgen} \
1956    usr.bin/ar \
1957    ${_binutils} \
1958    ${_elftctools} \
1959    ${_gcc} \
1960    ${_gcc_tools} \
1961    ${_clang_libs} \
1962    ${_clang} \
1963    sbin/md5 \
1964    sbin/sysctl \
1965    gnu/usr.bin/diff \
1966    usr.bin/awk \
1967    usr.bin/basename \
1968    usr.bin/bmake \
1969    usr.bin/bzip2 \
1970    usr.bin/cmp \
1971    usr.bin/dirname \
1972    usr.bin/env \
1973    usr.bin/fetch \
1974    usr.bin/find \
1975    usr.bin/grep \
1976    usr.bin/gzip \
1977    usr.bin/id \
1978    usr.bin/lex \
1979    usr.bin/lorder \
1980    usr.bin/mktemp \
1981    usr.bin/mt \
1982    usr.bin/patch \
1983    usr.bin/readelf \
1984    usr.bin/sed \
1985    usr.bin/sort \
1986    usr.bin/tar \
1987    usr.bin/touch \
1988    usr.bin/tr \
1989    usr.bin/true \
1990    usr.bin/uniq \
1991    usr.bin/unzip \
1992    usr.bin/xargs \
1993    usr.bin/xinstall \
1994    usr.bin/xz \
1995    usr.bin/yacc \
1996    usr.sbin/chown
1997	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
1998		cd ${.CURDIR}/${_tool}; \
1999		${NXBMAKE} DIRPRFX=${_tool}/ obj; \
2000		${NXBMAKE} DIRPRFX=${_tool}/ all; \
2001		${NXBMAKE} DIRPRFX=${_tool}/ DESTDIR=${NXBDESTDIR} install
2002.endfor
2003
2004#
2005# hierarchy - ensure that all the needed directories are present
2006#
2007hierarchy hier: .MAKE .PHONY
2008	${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
2009
2010#
2011# libraries - build all libraries, and install them under ${DESTDIR}.
2012#
2013# The list of libraries with dependents (${_prebuild_libs}) and their
2014# interdependencies (__L) are built automatically by the
2015# ${.CURDIR}/tools/make_libdeps.sh script.
2016#
2017libraries: .MAKE .PHONY
2018	${_+_}cd ${.CURDIR}; \
2019	    ${MAKE} -f Makefile.inc1 _prereq_libs; \
2020	    ${MAKE} -f Makefile.inc1 _startup_libs; \
2021	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
2022	    ${MAKE} -f Makefile.inc1 _generic_libs
2023
2024#
2025# static libgcc.a prerequisite for shared libc
2026#
2027_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
2028
2029# These dependencies are not automatically generated:
2030#
2031# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
2032# all shared libraries for ELF.
2033#
2034_startup_libs=	gnu/lib/csu
2035_startup_libs+=	lib/csu
2036_startup_libs+=	gnu/lib/libgcc
2037_startup_libs+=	lib/libcompiler_rt
2038_startup_libs+=	lib/libc
2039_startup_libs+=	lib/libc_nonshared
2040.if ${MK_LIBCPLUSPLUS} != "no"
2041_startup_libs+=	lib/libcxxrt
2042.endif
2043
2044gnu/lib/libgcc__L: lib/libc__L
2045gnu/lib/libgcc__L: lib/libc_nonshared__L
2046.if ${MK_LIBCPLUSPLUS} != "no"
2047lib/libcxxrt__L: gnu/lib/libgcc__L
2048.endif
2049
2050_prebuild_libs=	${_kerberos5_lib_libasn1} \
2051		${_kerberos5_lib_libhdb} \
2052		${_kerberos5_lib_libheimbase} \
2053		${_kerberos5_lib_libheimntlm} \
2054		${_libsqlite3} \
2055		${_kerberos5_lib_libheimipcc} \
2056		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
2057		${_kerberos5_lib_libroken} \
2058		${_kerberos5_lib_libwind} \
2059		lib/libbz2 ${_libcom_err} lib/libcrypt \
2060		lib/libelf lib/libexpat \
2061		lib/libfigpar \
2062		${_lib_libgssapi} \
2063		lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
2064		${_lib_casper} \
2065		lib/ncurses/ncurses lib/ncurses/ncursesw \
2066		lib/libopie lib/libpam/libpam ${_lib_libthr} \
2067		${_lib_libradius} lib/libsbuf lib/libtacplus \
2068		lib/libgeom \
2069		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
2070		${_cddl_lib_libuutil} \
2071		${_cddl_lib_libavl} \
2072		${_cddl_lib_libzfs_core} \
2073		${_cddl_lib_libctf} \
2074		lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
2075		${_secure_lib_libcrypto} ${_lib_libldns} \
2076		${_secure_lib_libssh} ${_secure_lib_libssl}
2077
2078.if ${MK_GNUCXX} != "no"
2079_prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
2080gnu/lib/libstdc++__L: lib/msun__L
2081gnu/lib/libsupc++__L: gnu/lib/libstdc++__L
2082.endif
2083
2084.if ${MK_DIALOG} != "no"
2085_prebuild_libs+= gnu/lib/libdialog
2086gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
2087.endif
2088
2089.if ${MK_LIBCPLUSPLUS} != "no"
2090_prebuild_libs+= lib/libc++
2091.endif
2092
2093lib/libgeom__L: lib/libexpat__L
2094lib/libkvm__L: lib/libelf__L
2095
2096.if ${MK_LIBTHR} != "no"
2097_lib_libthr=	lib/libthr
2098.endif
2099
2100.if ${MK_RADIUS_SUPPORT} != "no"
2101_lib_libradius=	lib/libradius
2102.endif
2103
2104.if ${MK_OFED} != "no"
2105_ofed_lib=		contrib/ofed/usr.lib
2106_prebuild_libs+=	contrib/ofed/usr.lib/libosmcomp
2107_prebuild_libs+=	contrib/ofed/usr.lib/libopensm
2108_prebuild_libs+=	contrib/ofed/usr.lib/libibcommon
2109_prebuild_libs+=	contrib/ofed/usr.lib/libibverbs
2110_prebuild_libs+=	contrib/ofed/usr.lib/libibumad
2111
2112contrib/ofed/usr.lib/libopensm__L: lib/libthr__L
2113contrib/ofed/usr.lib/libosmcomp__L: lib/libthr__L
2114contrib/ofed/usr.lib/libibumad__L: contrib/ofed/usr.lib/libibcommon__L
2115.endif
2116
2117.if ${MK_CASPER} != "no"
2118_lib_casper=	lib/libcasper
2119.endif
2120
2121lib/libpjdlog__L: lib/libutil__L
2122lib/libcasper__L: lib/libnv__L
2123lib/liblzma__L: lib/libthr__L
2124
2125_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
2126.for _DIR in ${LOCAL_LIB_DIRS}
2127.if exists(${.CURDIR}/${_DIR}/Makefile) && empty(_generic_libs:M${_DIR})
2128_generic_libs+= ${_DIR}
2129.endif
2130.endfor
2131
2132lib/libopie__L lib/libtacplus__L: lib/libmd__L
2133
2134.if ${MK_CDDL} != "no"
2135_cddl_lib_libumem= cddl/lib/libumem
2136_cddl_lib_libnvpair= cddl/lib/libnvpair
2137_cddl_lib_libavl= cddl/lib/libavl
2138_cddl_lib_libuutil= cddl/lib/libuutil
2139_cddl_lib_libzfs_core= cddl/lib/libzfs_core
2140_cddl_lib_libctf= cddl/lib/libctf
2141_cddl_lib= cddl/lib
2142cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
2143cddl/lib/libzfs__L: lib/libgeom__L
2144cddl/lib/libctf__L: lib/libz__L
2145.endif
2146# cddl/lib/libdtrace requires lib/libproc and lib/librtld_db; it's only built
2147# on select architectures though (see cddl/lib/Makefile)
2148.if ${MACHINE_CPUARCH} != "sparc64"
2149_prebuild_libs+=	lib/libproc lib/librtld_db
2150.endif
2151
2152.if ${MK_CRYPT} != "no"
2153.if ${MK_OPENSSL} != "no"
2154_secure_lib_libcrypto= secure/lib/libcrypto
2155_secure_lib_libssl= secure/lib/libssl
2156lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
2157.if ${MK_LDNS} != "no"
2158_lib_libldns= lib/libldns
2159lib/libldns__L: secure/lib/libcrypto__L
2160.endif
2161.if ${MK_OPENSSH} != "no"
2162_secure_lib_libssh= secure/lib/libssh
2163secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
2164.if ${MK_LDNS} != "no"
2165secure/lib/libssh__L: lib/libldns__L
2166.endif
2167.if ${MK_GSSAPI} != "no" && ${MK_KERBEROS_SUPPORT} != "no"
2168secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
2169    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
2170    lib/libmd__L kerberos5/lib/libroken__L
2171.endif
2172.endif
2173.endif
2174_secure_lib=	secure/lib
2175.endif
2176
2177.if ${MK_KERBEROS} != "no"
2178kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
2179kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2180    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
2181    kerberos5/lib/libwind__L lib/libsqlite3__L
2182kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
2183    kerberos5/lib/libroken__L lib/libcom_err__L
2184kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2185    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
2186kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2187    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
2188    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
2189    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
2190kerberos5/lib/libroken__L: lib/libcrypt__L
2191kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
2192kerberos5/lib/libheimbase__L: lib/libthr__L
2193kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
2194.endif
2195
2196lib/libsqlite3__L: lib/libthr__L
2197
2198.if ${MK_GSSAPI} != "no"
2199_lib_libgssapi=	lib/libgssapi
2200.endif
2201
2202.if ${MK_KERBEROS} != "no"
2203_kerberos5_lib=	kerberos5/lib
2204_kerberos5_lib_libasn1= kerberos5/lib/libasn1
2205_kerberos5_lib_libhdb= kerberos5/lib/libhdb
2206_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
2207_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
2208_kerberos5_lib_libhx509= kerberos5/lib/libhx509
2209_kerberos5_lib_libroken= kerberos5/lib/libroken
2210_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
2211_libsqlite3= lib/libsqlite3
2212_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
2213_kerberos5_lib_libwind= kerberos5/lib/libwind
2214_libcom_err= lib/libcom_err
2215.endif
2216
2217.if ${MK_NIS} != "no"
2218_lib_libypclnt=	lib/libypclnt
2219.endif
2220
2221.if ${MK_OPENSSL} == "no"
2222lib/libradius__L: lib/libmd__L
2223.endif
2224
2225lib/libproc__L: \
2226    ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
2227.if ${MK_CXX} != "no"
2228.if ${MK_LIBCPLUSPLUS} != "no"
2229lib/libproc__L: lib/libcxxrt__L
2230.else # This implies MK_GNUCXX != "no"; see lib/libproc
2231lib/libproc__L: gnu/lib/libsupc++__L
2232.endif
2233.endif
2234
2235.for _lib in ${_prereq_libs}
2236${_lib}__PL: .PHONY .MAKE
2237.if exists(${.CURDIR}/${_lib})
2238	${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
2239		cd ${.CURDIR}/${_lib}; \
2240		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \
2241		${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
2242		    DIRPRFX=${_lib}/ all; \
2243		${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
2244		    DIRPRFX=${_lib}/ install
2245.endif
2246.endfor
2247
2248.for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
2249${_lib}__L: .PHONY .MAKE
2250.if exists(${.CURDIR}/${_lib})
2251	${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
2252		cd ${.CURDIR}/${_lib}; \
2253		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \
2254		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
2255		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
2256.endif
2257.endfor
2258
2259_prereq_libs: ${_prereq_libs:S/$/__PL/}
2260_startup_libs: ${_startup_libs:S/$/__L/}
2261_prebuild_libs: ${_prebuild_libs:S/$/__L/}
2262_generic_libs: ${_generic_libs:S/$/__L/}
2263
2264# Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
2265# 'everything' with _PARALLEL_SUBDIR_OK set.  This is because it is unlikely
2266# that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
2267# or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
2268# parallel.  This is safe for the world stage of buildworld though since it has
2269# already built libraries in a proper order and installed includes into
2270# WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
2271# avoid trashing a system if it crashes mid-install.
2272.if !make(all) || defined(_PARALLEL_SUBDIR_OK)
2273SUBDIR_PARALLEL=
2274.endif
2275
2276.include <bsd.subdir.mk>
2277
2278.if make(check-old) || make(check-old-dirs) || \
2279    make(check-old-files) || make(check-old-libs) || \
2280    make(delete-old) || make(delete-old-dirs) || \
2281    make(delete-old-files) || make(delete-old-libs)
2282
2283#
2284# check for / delete old files section
2285#
2286
2287.include "ObsoleteFiles.inc"
2288
2289OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
2290else you can not start such an application. Consult UPDATING for more \
2291information regarding how to cope with the removal/revision bump of a \
2292specific library."
2293
2294.if !defined(BATCH_DELETE_OLD_FILES)
2295RM_I=-i
2296.else
2297RM_I=-v
2298.endif
2299
2300delete-old-files: .PHONY
2301	@echo ">>> Removing old files (only deletes safe to delete libs)"
2302# Ask for every old file if the user really wants to remove it.
2303# It's annoying, but better safe than sorry.
2304# NB: We cannot pass the list of OLD_FILES as a parameter because the
2305# argument list will get too long. Using .for/.endfor make "loops" will make
2306# the Makefile parser segfault.
2307	@exec 3<&0; \
2308	cd ${.CURDIR}; \
2309	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2310	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
2311	while read file; do \
2312		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2313			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
2314			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
2315		fi; \
2316		for ext in debug symbols; do \
2317		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
2318		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2319			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
2320			      <&3; \
2321		  fi; \
2322		done; \
2323	done
2324# Remove catpages without corresponding manpages.
2325	@exec 3<&0; \
2326	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
2327	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
2328	while read catpage; do \
2329		read manpage; \
2330		if [ ! -e "$${manpage}" ]; then \
2331			rm ${RM_I} $${catpage} <&3; \
2332	        fi; \
2333	done
2334	@echo ">>> Old files removed"
2335
2336check-old-files: .PHONY
2337	@echo ">>> Checking for old files"
2338	@cd ${.CURDIR}; \
2339	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2340	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
2341	while read file; do \
2342		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2343		 	echo "${DESTDIR}/$${file}"; \
2344		fi; \
2345		for ext in debug symbols; do \
2346		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2347			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
2348		  fi; \
2349		done; \
2350	done
2351# Check for catpages without corresponding manpages.
2352	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
2353	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
2354	while read catpage; do \
2355		read manpage; \
2356		if [ ! -e "$${manpage}" ]; then \
2357			echo $${catpage}; \
2358	        fi; \
2359	done
2360
2361delete-old-libs: .PHONY
2362	@echo ">>> Removing old libraries"
2363	@echo "${OLD_LIBS_MESSAGE}" | fmt
2364	@exec 3<&0; \
2365	cd ${.CURDIR}; \
2366	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2367	    -V OLD_LIBS | xargs -n1 | \
2368	while read file; do \
2369		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2370			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
2371			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
2372		fi; \
2373		for ext in debug symbols; do \
2374		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
2375		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2376			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
2377			      <&3; \
2378		  fi; \
2379		done; \
2380	done
2381	@echo ">>> Old libraries removed"
2382
2383check-old-libs: .PHONY
2384	@echo ">>> Checking for old libraries"
2385	@cd ${.CURDIR}; \
2386	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2387	    -V OLD_LIBS | xargs -n1 | \
2388	while read file; do \
2389		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2390			echo "${DESTDIR}/$${file}"; \
2391		fi; \
2392		for ext in debug symbols; do \
2393		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2394			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
2395		  fi; \
2396		done; \
2397	done
2398
2399delete-old-dirs: .PHONY
2400	@echo ">>> Removing old directories"
2401	@cd ${.CURDIR}; \
2402	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2403	    -V OLD_DIRS | xargs -n1 | sort -r | \
2404	while read dir; do \
2405		if [ -d "${DESTDIR}/$${dir}" ]; then \
2406			rmdir -v "${DESTDIR}/$${dir}" || true; \
2407		elif [ -L "${DESTDIR}/$${dir}" ]; then \
2408			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2409		fi; \
2410		if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
2411			rmdir -v "${DESTDIR}${DEBUGDIR}/$${dir}" || true; \
2412		elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
2413			echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
2414		fi; \
2415	done
2416	@echo ">>> Old directories removed"
2417
2418check-old-dirs: .PHONY
2419	@echo ">>> Checking for old directories"
2420	@cd ${.CURDIR}; \
2421	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2422	    -V OLD_DIRS | xargs -n1 | \
2423	while read dir; do \
2424		if [ -d "${DESTDIR}/$${dir}" ]; then \
2425			echo "${DESTDIR}/$${dir}"; \
2426		elif [ -L "${DESTDIR}/$${dir}" ]; then \
2427			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2428		fi; \
2429		if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
2430			echo "${DESTDIR}${DEBUGDIR}/$${dir}"; \
2431		elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
2432			echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
2433		fi; \
2434	done
2435
2436delete-old: delete-old-files delete-old-dirs .PHONY
2437	@echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
2438
2439check-old: check-old-files check-old-libs check-old-dirs .PHONY
2440	@echo "To remove old files and directories run '${MAKE_CMD} delete-old'."
2441	@echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
2442
2443.endif
2444
2445#
2446# showconfig - show build configuration.
2447#
2448showconfig: .PHONY
2449	@(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1; \
2450	  ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1) 2>&1 | grep ^MK_ | sort -u
2451
2452.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
2453DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
2454
2455.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
2456.if exists(${KERNCONFDIR}/${KERNCONF})
2457FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
2458	'${KERNCONFDIR}/${KERNCONF}' ; echo
2459.endif
2460.endif
2461
2462.endif
2463
2464.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
2465DTBOUTPUTPATH= ${.CURDIR}
2466.endif
2467
2468#
2469# Build 'standalone' Device Tree Blob
2470#
2471builddtb: .PHONY
2472	@PATH=${TMPPATH} MACHINE=${TARGET} \
2473	${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
2474	    "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
2475
2476###############
2477
2478# cleanworld
2479# In the following, the first 'rm' in a series will usually remove all
2480# files and directories.  If it does not, then there are probably some
2481# files with file flags set, so this unsets them and tries the 'rm' a
2482# second time.  There are situations where this target will be cleaning
2483# some directories via more than one method, but that duplication is
2484# needed to correctly handle all the possible situations.  Removing all
2485# files without file flags set in the first 'rm' instance saves time,
2486# because 'chflags' will need to operate on fewer files afterwards.
2487#
2488# It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
2489# created by bsd.obj.mk, except that we don't want to .include that file
2490# in this makefile.
2491#
2492BW_CANONICALOBJDIR:=${OBJTREE}${.CURDIR}
2493cleanworld: .PHONY
2494.if exists(${BW_CANONICALOBJDIR}/)
2495	-rm -rf ${BW_CANONICALOBJDIR}/*
2496	-chflags -R 0 ${BW_CANONICALOBJDIR}
2497	rm -rf ${BW_CANONICALOBJDIR}/*
2498.endif
2499.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2500	#   To be safe in this case, fall back to a 'make cleandir'
2501	${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
2502.endif
2503
2504.if defined(TARGET) && defined(TARGET_ARCH)
2505
2506.if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
2507XDEV_CPUTYPE?=${CPUTYPE}
2508.else
2509XDEV_CPUTYPE?=${TARGET_CPUTYPE}
2510.endif
2511
2512NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
2513	MK_MAN=no MK_NLS=no MK_PROFILE=no \
2514	MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
2515	TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
2516	CPUTYPE=${XDEV_CPUTYPE}
2517
2518XDDIR=${TARGET_ARCH}-freebsd
2519XDTP?=/usr/${XDDIR}
2520.if ${XDTP:N/*}
2521.error XDTP variable should be an absolute path
2522.endif
2523
2524CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
2525	INSTALL="sh ${.CURDIR}/tools/install.sh"
2526CDENV= ${CDBENV} \
2527	TOOLS_PREFIX=${XDTP}
2528
2529.if ${WANT_COMPILER_TYPE} == gcc || \
2530    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
2531# GCC requires -isystem and -L when using a cross-compiler.  --sysroot
2532# won't set header path and -L is used to ensure the base library path
2533# is added before the port PREFIX library path.
2534CD2CFLAGS+=	-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib
2535# GCC requires -B to find /usr/lib/crti.o when using a cross-compiler
2536# combined with --sysroot.
2537CD2CFLAGS+=	-B${XDDESTDIR}/usr/lib
2538# Force using libc++ for external GCC.
2539# XXX: This should be checking MK_GNUCXX == no
2540.if ${X_COMPILER_VERSION} >= 40800
2541CD2CXXFLAGS+=	-isystem ${XDDESTDIR}/usr/include/c++/v1 -std=c++11 \
2542		-nostdinc++
2543.endif
2544.endif
2545CD2CFLAGS+=	--sysroot=${XDDESTDIR}/
2546CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CXXFLAGS} ${CD2CFLAGS}" \
2547	CPP="${CPP} ${CD2CFLAGS}" \
2548	MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
2549
2550CDTMP=	${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
2551CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2552CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2553.if ${MK_META_MODE} != "no"
2554# Don't rebuild build-tools targets during normal build.
2555CD2MAKE+=	BUILD_TOOLS_META=.NOMETA
2556.endif
2557XDDESTDIR=${DESTDIR}/${XDTP}
2558.if !defined(OSREL)
2559OSREL!= uname -r | sed -e 's/[-(].*//'
2560.endif
2561
2562.ORDER: xdev-build xdev-install xdev-links
2563xdev: xdev-build xdev-install .PHONY
2564
2565.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2566xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY
2567
2568_xb-worldtmp: .PHONY
2569	mkdir -p ${CDTMP}/usr
2570	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2571	    -p ${CDTMP}/usr >/dev/null
2572
2573_xb-bootstrap-tools: .PHONY
2574.for _tool in \
2575    ${_clang_tblgen} \
2576    ${_gperf} \
2577    ${_yacc}
2578	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2579	cd ${.CURDIR}/${_tool}; \
2580	${CDMAKE} DIRPRFX=${_tool}/ obj; \
2581	${CDMAKE} DIRPRFX=${_tool}/ all; \
2582	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
2583.endfor
2584
2585_xb-build-tools: .PHONY
2586	${_+_}@cd ${.CURDIR}; \
2587	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
2588
2589_xb-cross-tools: .PHONY
2590.for _tool in \
2591    ${_binutils} \
2592    ${_elftctools} \
2593    usr.bin/ar \
2594    ${_clang_libs} \
2595    ${_clang} \
2596    ${_gcc}
2597	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \
2598	cd ${.CURDIR}/${_tool}; \
2599	${CDMAKE} DIRPRFX=${_tool}/ obj; \
2600	${CDMAKE} DIRPRFX=${_tool}/ all
2601.endfor
2602
2603_xi-mtree: .PHONY
2604	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
2605	mkdir -p ${XDDESTDIR}
2606	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
2607	    -p ${XDDESTDIR} >/dev/null
2608	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2609	    -p ${XDDESTDIR}/usr >/dev/null
2610	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2611	    -p ${XDDESTDIR}/usr/include >/dev/null
2612.if defined(LIBCOMPAT)
2613	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
2614	    -p ${XDDESTDIR}/usr >/dev/null
2615.endif
2616.if ${MK_TESTS} != "no"
2617	mkdir -p ${XDDESTDIR}${TESTSBASE}
2618	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
2619	    -p ${XDDESTDIR}${TESTSBASE} >/dev/null
2620.endif
2621
2622.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
2623xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY
2624
2625_xi-cross-tools: .PHONY
2626	@echo "_xi-cross-tools"
2627.for _tool in \
2628    ${_binutils} \
2629    ${_elftctools} \
2630    usr.bin/ar \
2631    ${_clang_libs} \
2632    ${_clang} \
2633    ${_gcc}
2634	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
2635	cd ${.CURDIR}/${_tool}; \
2636	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
2637.endfor
2638
2639_xi-includes: .PHONY
2640	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
2641		DESTDIR=${XDDESTDIR}
2642
2643_xi-libraries: .PHONY
2644	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
2645		DESTDIR=${XDDESTDIR}
2646
2647xdev-links: .PHONY
2648	${_+_}cd ${XDDESTDIR}/usr/bin; \
2649	mkdir -p ../../../../usr/bin; \
2650		for i in *; do \
2651			ln -sf ../../${XDTP}/usr/bin/$$i \
2652			    ../../../../usr/bin/${XDDIR}-$$i; \
2653			ln -sf ../../${XDTP}/usr/bin/$$i \
2654			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
2655		done
2656.else
2657xdev xdev-build xdev-install xdev-links: .PHONY
2658	@echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${.TARGET}\" target"
2659.endif
2660