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