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