xref: /freebsd/Makefile.inc1 (revision 1a18ab420b6098b92f3a16db68e482682a506688)
1#
2# $FreeBSD$
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#	LOCAL_XTOOL_DIRS="list of dirs" to add additional dirs to the
26#	    cross-tools target
27#	METALOG="path to metadata log" to write permission and ownership
28#	    when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
29#	TARGET="machine" to crossbuild world for a different machine type
30#	TARGET_ARCH= may be required when a TARGET supports multiple endians
31#	BUILDENV_SHELL= shell to launch for the buildenv target (def:${SHELL})
32#	WORLD_FLAGS= additional flags to pass to make(1) during buildworld
33#	KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
34#	SUBDIR_OVERRIDE="list of dirs" to build rather than everything.
35#	    All libraries and includes, and some build tools will still build.
36
37#
38# The intended user-driven targets are:
39# buildworld  - rebuild *everything*, including glue to help do upgrades
40# installworld- install everything built by "buildworld"
41# checkworld  - run test suite on installed world
42# doxygen     - build API documentation of the kernel
43# update      - convenient way to update your source tree (eg: svn/svnup)
44#
45# Standard targets (not defined here) are documented in the makefiles in
46# /usr/share/mk.  These include:
47#		obj depend all install clean cleandepend cleanobj
48
49.if !defined(TARGET) || !defined(TARGET_ARCH)
50.error "Both TARGET and TARGET_ARCH must be defined."
51.endif
52
53.if make(showconfig) || make(test-system-*)
54_MKSHOWCONFIG=	t
55.endif
56
57SRCDIR?=	${.CURDIR}
58LOCALBASE?=	/usr/local
59
60.include "share/mk/src.tools.mk"
61
62# Cross toolchain changes must be in effect before bsd.compiler.mk
63# so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
64.if defined(CROSS_TOOLCHAIN)
65.if exists(${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk)
66.include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
67.elif exists(/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk)
68.include "/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk"
69.elif exists(${CROSS_TOOLCHAIN})
70.include "${CROSS_TOOLCHAIN}"
71.else
72.error CROSS_TOOLCHAIN ${CROSS_TOOLCHAIN} not found
73.endif
74CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
75.endif
76.if defined(CROSS_TOOLCHAIN_PREFIX)
77CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
78.endif
79
80XCOMPILERS=	CC CXX CPP
81.for COMPILER in ${XCOMPILERS}
82.if defined(CROSS_COMPILER_PREFIX)
83X${COMPILER}?=	${CROSS_COMPILER_PREFIX}${${COMPILER}}
84.else
85X${COMPILER}?=	${${COMPILER}}
86.endif
87.endfor
88# If a full path to an external cross compiler is given, don't build
89# a cross compiler.
90.if ${XCC:N${CCACHE_BIN}:M/*}
91MK_CLANG_BOOTSTRAP=	no
92.endif
93
94# Pull in compiler metadata from buildworld/toolchain if possible to avoid
95# running CC from bsd.compiler.mk.
96.if make(installworld) || make(install) || make(distributeworld) || \
97    make(stageworld)
98.-include "${OBJTOP}/toolchain-metadata.mk"
99.if !defined(_LOADED_TOOLCHAIN_METADATA)
100.error A build is required first.  You may have the wrong MAKEOBJDIRPREFIX set.
101.endif
102.endif
103
104# Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early. Pull it from the
105# tree to be friendlier to foreign OS builds. It's safe to do so unconditionally
106# here since we will always have the right make, unlike in src/Makefile
107# Don't include bsd.linker.mk yet until XBINUTILS is handled (after src.opts.mk)
108_NO_INCLUDE_LINKERMK=	t
109# We also want the X_COMPILER* variables if we are using an external toolchain.
110_WANT_TOOLCHAIN_CROSS_VARS=	t
111.include "share/mk/bsd.compiler.mk"
112.undef _NO_INCLUDE_LINKERMK
113.undef _WANT_TOOLCHAIN_CROSS_VARS
114# src.opts.mk depends on COMPILER_FEATURES
115.include "share/mk/src.opts.mk"
116
117.if ${TARGET} == ${MACHINE}
118TARGET_CPUTYPE?=${CPUTYPE}
119.else
120TARGET_CPUTYPE?=
121.endif
122.if !empty(TARGET_CPUTYPE)
123_TARGET_CPUTYPE=${TARGET_CPUTYPE}
124.else
125_TARGET_CPUTYPE=dummy
126.endif
127.if ${TARGET} == "arm"
128.if ${TARGET_ARCH:Marmv[67]*} != "" && ${TARGET_CPUTYPE:M*soft*} == ""
129TARGET_ABI=	gnueabihf
130.else
131TARGET_ABI=	gnueabi
132.endif
133.endif
134MACHINE_ABI?=	unknown
135MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd13.0
136TARGET_ABI?=	unknown
137TARGET_TRIPLE?=	${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd13.0
138KNOWN_ARCHES?=	aarch64/arm64 \
139		amd64 \
140		armv6/arm \
141		armv7/arm \
142		i386 \
143		mips \
144		mipsel/mips \
145		mips64el/mips \
146		mipsn32el/mips \
147		mips64/mips \
148		mipsn32/mips \
149		mipshf/mips \
150		mipselhf/mips \
151		mips64elhf/mips \
152		mips64hf/mips \
153		powerpc \
154		powerpc64/powerpc \
155		powerpcspe/powerpc \
156		riscv64/riscv \
157		riscv64sf/riscv
158
159.if ${TARGET} == ${TARGET_ARCH}
160_t=		${TARGET}
161.else
162_t=		${TARGET_ARCH}/${TARGET}
163.endif
164.for _t in ${_t}
165.if empty(KNOWN_ARCHES:M${_t})
166.error Unknown target ${TARGET_ARCH}:${TARGET}.
167.endif
168.endfor
169
170# If all targets are disabled for system llvm then don't expect it to work
171# for cross-builds.
172.if !defined(TOOLS_PREFIX) && ${MK_LLVM_TARGET_ALL} == "no" && \
173    ${MACHINE} != ${TARGET} && ${MACHINE_ARCH} != ${TARGET_ARCH} && \
174    !make(showconfig)
175MK_SYSTEM_COMPILER=	no
176MK_SYSTEM_LINKER=	no
177.endif
178
179# Handle external binutils.
180.if defined(CROSS_TOOLCHAIN_PREFIX)
181CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
182.endif
183XBINUTILS=	AS AR LD NM OBJCOPY RANLIB SIZE STRINGS STRIPBIN
184.for BINUTIL in ${XBINUTILS}
185.if defined(CROSS_BINUTILS_PREFIX) && \
186    exists(${CROSS_BINUTILS_PREFIX}/${${BINUTIL}})
187X${BINUTIL}?=	${CROSS_BINUTILS_PREFIX:C,/*$,,}/${${BINUTIL}}
188.else
189X${BINUTIL}?=	${${BINUTIL}}
190.endif
191.endfor
192
193# If a full path to an external linker is given, don't build lld.
194.if ${XLD:M/*}
195MK_LLD_BOOTSTRAP=	no
196.endif
197
198# We also want the X_LINKER* variables if we are using an external toolchain.
199_WANT_TOOLCHAIN_CROSS_VARS=	t
200.include "share/mk/bsd.linker.mk"
201.undef _WANT_TOOLCHAIN_CROSS_VARS
202
203# Begin WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
204
205# WITH_SYSTEM_COMPILER - Pull in needed values and make a decision.
206
207# Check if there is a local compiler that can satisfy as an external compiler.
208# Which compiler is expected to be used?
209.if ${MK_CLANG_BOOTSTRAP} == "yes"
210WANT_COMPILER_TYPE=	clang
211.else
212WANT_COMPILER_TYPE=
213.endif
214
215.if !defined(WANT_COMPILER_FREEBSD_VERSION) && !make(showconfig) && \
216    !make(test-system-linker)
217.if ${WANT_COMPILER_TYPE} == "clang"
218WANT_COMPILER_FREEBSD_VERSION_FILE= lib/clang/freebsd_cc_version.h
219WANT_COMPILER_FREEBSD_VERSION!= \
220	awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \
221	${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown
222WANT_COMPILER_VERSION_FILE= lib/clang/include/clang/Basic/Version.inc
223WANT_COMPILER_VERSION!= \
224	awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
225	${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown
226.endif
227.export WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_VERSION
228.endif	# !defined(WANT_COMPILER_FREEBSD_VERSION)
229
230# It needs to be the same revision as we would build for the bootstrap.
231# If the expected vs CC is different then we can't skip.
232# GCC cannot be used for cross-arch yet.  For clang we pass -target later if
233# TARGET_ARCH!=MACHINE_ARCH.
234.if ${MK_SYSTEM_COMPILER} == "yes" && \
235    defined(WANT_COMPILER_FREEBSD_VERSION) && \
236    ${MK_CLANG_BOOTSTRAP} == "yes" && \
237    !make(xdev*) && \
238    ${X_COMPILER_TYPE} == ${WANT_COMPILER_TYPE} && \
239    (${X_COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH}) && \
240    ${X_COMPILER_VERSION} == ${WANT_COMPILER_VERSION} && \
241    ${X_COMPILER_FREEBSD_VERSION} == ${WANT_COMPILER_FREEBSD_VERSION}
242# Everything matches, disable the bootstrap compiler.
243MK_CLANG_BOOTSTRAP=	no
244USING_SYSTEM_COMPILER=	yes
245.endif	# ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE}
246
247# WITH_SYSTEM_LD - Pull in needed values and make a decision.
248
249# Check if there is a local linker that can satisfy as an external linker.
250# Which linker is expected to be used?
251.if ${MK_LLD_BOOTSTRAP} == "yes"
252WANT_LINKER_TYPE=		lld
253.else
254WANT_LINKER_TYPE=
255.endif
256
257.if !defined(WANT_LINKER_FREEBSD_VERSION) && !make(showconfig) && \
258    !make(test-system-compiler)
259.if ${WANT_LINKER_TYPE} == "lld"
260WANT_LINKER_FREEBSD_VERSION_FILE= lib/clang/include/VCSVersion.inc
261_WANT_LINKER_FREEBSD_VERSION!= \
262	awk '$$2 == "LLD_REVISION" {gsub(/"/, "", $$3); print $$3}' \
263	${SRCDIR}/${WANT_LINKER_FREEBSD_VERSION_FILE} || echo unknown
264WANT_LINKER_FREEBSD_VERSION=${_WANT_LINKER_FREEBSD_VERSION:C/.*-(.*)/\1/}
265WANT_LINKER_VERSION_FILE= lib/clang/include/lld/Common/Version.inc
266WANT_LINKER_VERSION!= \
267	awk '$$2 == "LLD_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
268	${SRCDIR}/${WANT_LINKER_VERSION_FILE} || echo unknown
269.else
270WANT_LINKER_FREEBSD_VERSION_FILE=
271WANT_LINKER_FREEBSD_VERSION=
272.endif
273.export WANT_LINKER_FREEBSD_VERSION WANT_LINKER_VERSION
274.endif	# !defined(WANT_LINKER_FREEBSD_VERSION)
275
276.if ${MK_SYSTEM_LINKER} == "yes" && \
277    defined(WANT_LINKER_FREEBSD_VERSION) && \
278    (${MK_LLD_BOOTSTRAP} == "yes") && \
279    !make(xdev*) && \
280    ${X_LINKER_TYPE} == ${WANT_LINKER_TYPE} && \
281    ${X_LINKER_VERSION} == ${WANT_LINKER_VERSION} && \
282    ${X_LINKER_FREEBSD_VERSION} == ${WANT_LINKER_FREEBSD_VERSION}
283# Everything matches, disable the bootstrap linker.
284MK_LLD_BOOTSTRAP=	no
285USING_SYSTEM_LINKER=	yes
286.endif	# ${WANT_LINKER_TYPE} == ${LINKER_TYPE}
287
288# WITH_SYSTEM_COMPILER / WITH_SYSTEM_LINKER - Handle defaults and debug.
289USING_SYSTEM_COMPILER?=	no
290USING_SYSTEM_LINKER?=	no
291
292TEST_SYSTEM_COMPILER_VARS= \
293	USING_SYSTEM_COMPILER MK_SYSTEM_COMPILER \
294	MK_CROSS_COMPILER MK_CLANG_BOOTSTRAP \
295	WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \
296	WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \
297	CC COMPILER_TYPE COMPILER_FEATURES COMPILER_VERSION \
298	COMPILER_FREEBSD_VERSION \
299	XCC X_COMPILER_TYPE X_COMPILER_FEATURES X_COMPILER_VERSION \
300	X_COMPILER_FREEBSD_VERSION
301TEST_SYSTEM_LINKER_VARS= \
302	USING_SYSTEM_LINKER MK_SYSTEM_LINKER \
303	MK_LLD_BOOTSTRAP \
304	WANT_LINKER_TYPE WANT_LINKER_VERSION WANT_LINKER_VERSION_FILE \
305	WANT_LINKER_FREEBSD_VERSION WANT_LINKER_FREEBSD_VERSION_FILE \
306	LD LINKER_TYPE LINKER_FEATURES LINKER_VERSION \
307	LINKER_FREEBSD_VERSION \
308	XLD X_LINKER_TYPE X_LINKER_FEATURES X_LINKER_VERSION \
309	X_LINKER_FREEBSD_VERSION
310
311.for _t in compiler linker
312test-system-${_t}: .PHONY
313.for v in ${TEST_SYSTEM_${_t:tu}_VARS}
314	${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}"
315.endfor
316.endfor
317.if (make(buildworld) || make(buildkernel) || make(kernel-toolchain) || \
318    make(toolchain) || make(_cross-tools))
319.if ${USING_SYSTEM_COMPILER} == "yes"
320.info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree.  Not bootstrapping a cross-compiler.
321.elif ${MK_CLANG_BOOTSTRAP} == "yes"
322.info SYSTEM_COMPILER: libclang will be built for bootstrapping a cross-compiler.
323.endif
324.if ${USING_SYSTEM_LINKER} == "yes"
325.info SYSTEM_LINKER: Determined that LD=${LD} matches the source tree.  Not bootstrapping a cross-linker.
326.elif ${MK_LLD_BOOTSTRAP} == "yes"
327.info SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.
328.endif
329.endif
330
331# End WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
332
333# Store some compiler metadata for use in installworld where we don't
334# want to invoke CC at all.
335_TOOLCHAIN_METADATA_VARS=	COMPILER_VERSION \
336				COMPILER_TYPE \
337				COMPILER_FEATURES \
338				COMPILER_FREEBSD_VERSION \
339				COMPILER_RESOURCE_DIR \
340				LINKER_VERSION \
341				LINKER_FEATURES \
342				LINKER_TYPE \
343				LINKER_FREEBSD_VERSION
344toolchain-metadata.mk: .PHONY .META
345	@: > ${.TARGET}
346	@echo ".info Using cached toolchain metadata from build at $$(hostname) on $$(date)" \
347	    > ${.TARGET}
348	@echo "_LOADED_TOOLCHAIN_METADATA=t" >> ${.TARGET}
349.for v in ${_TOOLCHAIN_METADATA_VARS}
350	@echo "${v}=${${v}}" >> ${.TARGET}
351	@echo "X_${v}=${X_${v}}" >> ${.TARGET}
352.endfor
353	@echo ".export ${_TOOLCHAIN_METADATA_VARS}" >> ${.TARGET}
354	@echo ".export ${_TOOLCHAIN_METADATA_VARS:C,^,X_,}" >> ${.TARGET}
355
356
357# We must do lib/ and libexec/ before bin/ in case of a mid-install error to
358# keep the users system reasonably usable.  For static->dynamic root upgrades,
359# we don't want to install a dynamic binary without rtld and the needed
360# libraries.  More commonly, for dynamic root, we don't want to install a
361# binary that requires a newer library version that hasn't been installed yet.
362# This ordering is not a guarantee though.  The only guarantee of a working
363# system here would require fine-grained ordering of all components based
364# on their dependencies.
365.if !empty(SUBDIR_OVERRIDE)
366SUBDIR=	${SUBDIR_OVERRIDE}
367.else
368SUBDIR=	lib libexec
369# Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
370# of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
371# LOCAL_LIB_DIRS=foo/lib to behave as expected.
372.for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
373_REDUNDANT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
374.endfor
375.for _DIR in ${LOCAL_LIB_DIRS}
376.if ${_DIR} == ".WAIT" || (empty(_REDUNDANT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
377SUBDIR+=	${_DIR}
378.endif
379.endfor
380.if !defined(NO_ROOT) && (make(installworld) || make(install))
381# Ensure libraries are installed before progressing.
382SUBDIR+=.WAIT
383.endif
384SUBDIR+=bin
385.if ${MK_CDDL} != "no"
386SUBDIR+=cddl
387.endif
388SUBDIR+=gnu include
389.if ${MK_KERBEROS} != "no"
390SUBDIR+=kerberos5
391.endif
392.if ${MK_RESCUE} != "no"
393SUBDIR+=rescue
394.endif
395SUBDIR+=sbin
396.if ${MK_CRYPT} != "no"
397SUBDIR+=secure
398.endif
399.if !defined(NO_SHARE)
400SUBDIR+=share
401.endif
402.if ${MK_BOOT} != "no"
403SUBDIR+=stand
404.endif
405SUBDIR+=sys usr.bin usr.sbin
406.if ${MK_TESTS} != "no"
407SUBDIR+=	tests
408.endif
409
410# Local directories are built in parallel with the base system directories.
411# Users may insert a .WAIT directive at the beginning or elsewhere within
412# the LOCAL_DIRS and LOCAL_LIB_DIRS lists as needed.
413.for _DIR in ${LOCAL_DIRS}
414.if ${_DIR} == ".WAIT" || exists(${.CURDIR}/${_DIR}/Makefile)
415SUBDIR+=	${_DIR}
416.endif
417.endfor
418
419# We must do etc/ last as it hooks into building the man whatis file
420# by calling 'makedb' in share/man.  This is only relevant for
421# install/distribute so they build the whatis file after every manpage is
422# installed.
423.if make(installworld) || make(install)
424SUBDIR+=.WAIT
425.endif
426SUBDIR+=etc
427
428.endif	# !empty(SUBDIR_OVERRIDE)
429
430.if defined(NOCLEAN)
431.warning NOCLEAN option is deprecated. Use NO_CLEAN instead.
432NO_CLEAN=	${NOCLEAN}
433.endif
434.if defined(NO_CLEANDIR)
435CLEANDIR=	clean cleandepend
436.else
437CLEANDIR=	cleandir
438.endif
439
440.if defined(WORLDFAST)
441NO_CLEAN=	t
442NO_OBJWALK=	t
443.endif
444
445.if ${MK_META_MODE} == "yes"
446# If filemon is used then we can rely on the build being incremental-safe.
447# The .meta files will also track the build command and rebuild should
448# it change.
449.if empty(.MAKE.MODE:Mnofilemon)
450NO_CLEAN=	t
451.endif
452.endif
453.if defined(NO_OBJWALK) || ${MK_AUTO_OBJ} == "yes"
454NO_OBJWALK=	t
455NO_KERNELOBJ=	t
456.endif
457.if !defined(NO_OBJWALK)
458_obj=		obj
459.endif
460
461LOCAL_TOOL_DIRS?=
462PACKAGEDIR?=	${DESTDIR}/${DISTDIR}
463
464.if empty(SHELL:M*csh*)
465BUILDENV_SHELL?=${SHELL}
466.else
467BUILDENV_SHELL?=/bin/sh
468.endif
469
470.if !defined(_MKSHOWCONFIG)
471.if !defined(SVN_CMD) || empty(SVN_CMD)
472. for _P in /usr/bin /usr/local/bin
473.  for _S in svn svnlite
474.   if exists(${_P}/${_S})
475SVN_CMD=   ${_P}/${_S}
476.   endif
477.  endfor
478. endfor
479.export SVN_CMD
480.endif
481SVNFLAGS?=	-r HEAD
482.if !defined(VCS_REVISION) || empty(VCS_REVISION)
483.if !defined(SVNVERSION_CMD) || empty(SVNVERSION_CMD)
484. for _D in ${PATH:S,:, ,g}
485.  if exists(${_D}/svnversion)
486SVNVERSION_CMD?=${_D}/svnversion
487.  endif
488.  if exists(${_D}/svnliteversion)
489SVNVERSION_CMD?=${_D}/svnliteversion
490.  endif
491. endfor
492.endif
493_VCS_REVISION?=	$$(eval ${SVNVERSION_CMD} ${SRCDIR})
494. if !empty(_VCS_REVISION)
495VCS_REVISION=	$$(echo r${_VCS_REVISION})
496. endif
497.export VCS_REVISION
498.endif
499
500.if !defined(OSRELDATE)
501.if exists(/usr/include/osreldate.h)
502OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
503		/usr/include/osreldate.h
504.else
505OSRELDATE=	0
506.endif
507.export OSRELDATE
508.endif
509
510# Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
511.if !defined(_REVISION)
512_REVISION!=	${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V REVISION
513.export _REVISION
514.endif
515.if !defined(_BRANCH)
516_BRANCH!=	${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V BRANCH
517.export _BRANCH
518.endif
519.if !defined(SRCRELDATE)
520SRCRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
521		${SRCDIR}/sys/sys/param.h
522.export SRCRELDATE
523.endif
524.if !defined(VERSION)
525VERSION=	FreeBSD ${_REVISION}-${_BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
526.export VERSION
527.endif
528
529.if !defined(PKG_VERSION)
530.if ${_BRANCH:MSTABLE*} || ${_BRANCH:MCURRENT*}
531TIMENOW=	%Y%m%d%H%M%S
532EXTRA_REVISION=	.s${TIMENOW:gmtime}
533.elif ${_BRANCH:MALPHA*}
534EXTRA_REVISION= _${_BRANCH:C/-ALPHA/.a/}
535.elif ${_BRANCH:MBETA*}
536EXTRA_REVISION= _${_BRANCH:C/-BETA/.b/}
537.elif ${_BRANCH:MRC*}
538EXTRA_REVISION= _${_BRANCH:C/-RC/.r/}
539.elif ${_BRANCH:MPRERELEASE*}
540EXTRA_REVISION= _${_BRANCH:C/-PRERELEASE/.p/}
541.elif ${_BRANCH:M*-p*}
542EXTRA_REVISION=	_${_BRANCH:C/.*-p([0-9]+$)/\1/}
543.endif
544PKG_VERSION=	${_REVISION}${EXTRA_REVISION}
545.endif
546.endif	# !defined(PKG_VERSION)
547
548.if !defined(PKG_TIMESTAMP)
549TIMEEPOCHNOW=	%s
550SOURCE_DATE_EPOCH=	${TIMEEPOCHNOW:gmtime}
551.else
552SOURCE_DATE_EPOCH=	${PKG_TIMESTAMP}
553.endif
554
555PKG_NAME_PREFIX?=	FreeBSD
556PKG_MAINTAINER?=	re@FreeBSD.org
557PKG_WWW?=		https://www.FreeBSD.org
558.export PKG_NAME_PREFIX
559.export PKG_MAINTAINER
560.export PKG_WWW
561
562.if !defined(_MKSHOWCONFIG)
563_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} -f /dev/null \
564		-m ${.CURDIR}/share/mk MK_AUTO_OBJ=no -V CPUTYPE
565.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
566.error CPUTYPE global should be set with ?=.
567.endif
568.endif
569.if make(buildworld)
570BUILD_ARCH!=	uname -p
571.if ${MACHINE_ARCH} != ${BUILD_ARCH}
572.error To cross-build, set TARGET_ARCH.
573.endif
574.endif
575WORLDTMP?=	${OBJTOP}/tmp
576BPATH=		${CCACHE_WRAPPER_PATH_PFX}${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin:${WORLDTMP}/legacy/usr/libexec
577XPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
578
579# When building we want to find the cross tools before the host tools in ${BPATH}.
580# We also need to add UNIVERSE_TOOLCHAIN_PATH so that we can find the shared
581# toolchain files (clang, lld, etc.) during make universe/tinderbox
582STRICTTMPPATH=	${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
583# We should not be using tools from /usr/bin accidentally since this could cause
584# the build to break on other systems that don't have that tool. For now we
585# still allow using the old behaviour (inheriting $PATH) if
586# BUILD_WITH_STRICT_TMPPATH is set to 0 but this will eventually be removed.
587
588# Currently strict $PATH can cause build failures and does not work yet with
589# USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
590# resolved it will be turned on by default.
591BUILD_WITH_STRICT_TMPPATH?=0
592.if ${BUILD_WITH_STRICT_TMPPATH} != 0
593TMPPATH=	${STRICTTMPPATH}
594.else
595TMPPATH=	${STRICTTMPPATH}:${PATH}
596.endif
597
598#
599# Avoid running mktemp(1) unless actually needed.
600# It may not be functional, e.g., due to new ABI
601# when in the middle of installing over this system.
602#
603.if make(distributeworld) || make(installworld) || make(stageworld)
604.if ${BUILD_WITH_STRICT_TMPPATH} != 0
605MKTEMP=${WORLDTMP}/legacy/usr/bin/mktemp
606.if !exists(${MKTEMP})
607.error "mktemp binary doesn't exist in expected location: ${MKTEMP}"
608.endif
609.else
610MKTEMP=mktemp
611.endif
612INSTALLTMP!=	${MKTEMP} -d -u -t install
613.endif
614
615.if make(stagekernel) || make(distributekernel)
616TAGS+=		kernel
617PACKAGE=	kernel
618.endif
619
620#
621# Building a world goes through the following stages
622#
623# 1. legacy stage [BMAKE]
624#	This stage is responsible for creating compatibility
625#	shims that are needed by the bootstrap-tools,
626#	build-tools and cross-tools stages. These are generally
627#	APIs that tools from one of those three stages need to
628#	build that aren't present on the host.
629# 1. bootstrap-tools stage [BMAKE]
630#	This stage is responsible for creating programs that
631#	are needed for backward compatibility reasons. They
632#	are not built as cross-tools.
633# 2. build-tools stage [TMAKE]
634#	This stage is responsible for creating the object
635#	tree and building any tools that are needed during
636#	the build process. Some programs are listed during
637#	this phase because they build binaries to generate
638#	files needed to build these programs. This stage also
639#	builds the 'build-tools' target rather than 'all'.
640# 3. cross-tools stage [XMAKE]
641#	This stage is responsible for creating any tools that
642#	are needed for building the system. A cross-compiler is one
643#	of them. This differs from build tools in two ways:
644#	1. the 'all' target is built rather than 'build-tools'
645#	2. these tools are installed into TMPPATH for stage 4.
646# 4. world stage [WMAKE]
647#	This stage actually builds the world.
648# 5. install stage (optional) [IMAKE]
649#	This stage installs a previously built world.
650#
651
652BOOTSTRAPPING?=	0
653# Keep these in sync
654MINIMUM_SUPPORTED_OSREL?= 1002501
655MINIMUM_SUPPORTED_REL?= 10.3
656
657# Common environment for world related stages
658CROSSENV+=	\
659		MACHINE_ARCH=${TARGET_ARCH} \
660		MACHINE=${TARGET} \
661		CPUTYPE=${TARGET_CPUTYPE}
662.if ${MK_META_MODE} != "no"
663# Don't rebuild build-tools targets during normal build.
664CROSSENV+=	BUILD_TOOLS_META=.NOMETA
665.endif
666.if defined(TARGET_CFLAGS)
667CROSSENV+=	${TARGET_CFLAGS}
668.endif
669.if (${TARGET} != ${MACHINE} && !defined(WITH_LOCAL_MODULES)) || \
670    defined(WITHOUT_LOCAL_MODULES)
671CROSSENV+=	LOCAL_MODULES=
672.endif
673
674BOOTSTRAPPING_OSRELDATE?=${OSRELDATE}
675
676# bootstrap-tools stage
677BMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
678		TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
679		PATH=${BPATH}:${PATH} \
680		WORLDTMP=${WORLDTMP} \
681		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
682# need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
683BSARGS= 	DESTDIR= \
684		OBJTOP='${WORLDTMP}/obj-tools' \
685		OBJROOT='$${OBJTOP}/' \
686		MAKEOBJDIRPREFIX= \
687		BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
688		BWPHASE=${.TARGET:C,^_,,} \
689		SSP_CFLAGS= \
690		MK_HTML=no NO_LINT=yes MK_MAN=no \
691		-DNO_PIC MK_PROFILE=no -DNO_SHARED \
692		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
693		MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
694		MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \
695		MK_INCLUDES=yes
696
697BMAKE=		\
698		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
699		${BSARGS}
700.if empty(.MAKEOVERRIDES:MMK_LLVM_TARGET_ALL)
701BMAKE+=		MK_LLVM_TARGET_ALL=no
702.endif
703
704# build-tools stage
705TMAKE=		\
706		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
707		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
708		DESTDIR= \
709		BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
710		BWPHASE=${.TARGET:C,^_,,} \
711		SSP_CFLAGS= \
712		-DNO_LINT \
713		-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
714		MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
715		MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no
716
717# cross-tools stage
718# TOOLS_PREFIX set in BMAKE
719XMAKE=		${BMAKE} \
720		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
721		MK_CLANG_IS_CC=${MK_CLANG_BOOTSTRAP} \
722		MK_GDB=no MK_TESTS=no
723
724# kernel-tools stage
725KTMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
726		PATH=${BPATH}:${PATH} \
727		WORLDTMP=${WORLDTMP}
728KTMAKE=		\
729		TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
730		${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
731		DESTDIR= \
732		OBJTOP='${WORLDTMP}/obj-kernel-tools' \
733		OBJROOT='$${OBJTOP}/' \
734		MAKEOBJDIRPREFIX= \
735		BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
736		SSP_CFLAGS= \
737		MK_HTML=no -DNO_LINT MK_MAN=no \
738		-DNO_PIC MK_PROFILE=no -DNO_SHARED \
739		-DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WARNS=no MK_CTF=no
740
741# world stage
742WMAKEENV=	${CROSSENV} \
743		INSTALL="sh ${.CURDIR}/tools/install.sh" \
744		PATH=${TMPPATH} \
745		SYSROOT=${WORLDTMP}
746
747# make hierarchy
748HMAKE=		PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
749.if defined(NO_ROOT)
750HMAKE+=		PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
751.endif
752
753CROSSENV+=	CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \
754		CPP="${XCPP} ${XCFLAGS}" \
755		AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \
756		NM=${XNM} OBJCOPY="${XOBJCOPY}" \
757		RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
758		SIZE="${XSIZE}" STRIPBIN="${XSTRIPBIN}"
759
760.if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
761# In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
762# directory, but the compiler will look in the right place for its
763# tools so we don't need to tell it where to look.
764BFLAGS+=	-B${CROSS_BINUTILS_PREFIX}
765.endif
766
767
768# The internal bootstrap compiler has a default sysroot set by TOOLS_PREFIX
769# and target set by TARGET/TARGET_ARCH.  However, there are several needs to
770# always pass an explicit --sysroot and -target.
771# - External compiler needs sysroot and target flags.
772# - External ld needs sysroot.
773# - To be clear about the use of a sysroot when using the internal compiler.
774# - Easier debugging.
775# - Allowing WITH_SYSTEM_COMPILER+WITH_META_MODE to work together due to
776#   the flip-flopping build command when sometimes using external and
777#   sometimes using internal.
778# - Allow using lld which has no support for default paths.
779.if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
780BFLAGS+=	-B${WORLDTMP}/usr/bin
781.endif
782.if ${WANT_COMPILER_TYPE} == gcc || \
783    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
784.elif ${WANT_COMPILER_TYPE} == clang || \
785    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == clang)
786XCFLAGS+=	-target ${TARGET_TRIPLE}
787.endif
788XCFLAGS+=	--sysroot=${WORLDTMP}
789
790.if !empty(BFLAGS)
791XCFLAGS+=	${BFLAGS}
792.endif
793
794.if ${MK_LIB32} == "yes"
795_LIBCOMPAT= 32
796.include "Makefile.libcompat"
797.elif ${MK_LIBSOFT} == "yes"
798_LIBCOMPAT= SOFT
799.include "Makefile.libcompat"
800.endif
801
802# META_MODE normally ignores host file changes since every build updates
803# timestamps (see NO_META_IGNORE_HOST in sys.mk).  There are known times
804# when the ABI breaks though that we want to force rebuilding WORLDTMP
805# to get updated host tools.
806.if ${MK_META_MODE} == "yes" && defined(NO_CLEAN) && \
807    !defined(NO_META_IGNORE_HOST) && !defined(NO_META_IGNORE_HOST_HEADERS) && \
808    !defined(_MKSHOWCONFIG)
809# r318736 - ino64 major ABI breakage
810META_MODE_BAD_ABI_VERS+=	1200031
811
812.if !defined(OBJDIR_HOST_OSRELDATE)
813.if exists(${OBJTOP}/host-osreldate.h)
814OBJDIR_HOST_OSRELDATE!=	\
815    awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
816    ${OBJTOP}/host-osreldate.h
817.elif exists(${WORLDTMP}/usr/include/osreldate.h)
818OBJDIR_HOST_OSRELDATE=	0
819.endif
820.export OBJDIR_HOST_OSRELDATE
821.endif
822
823# Note that this logic is the opposite of normal BOOTSTRAP handling.  We want
824# to compare the WORLDTMP's OSRELDATE to the host's OSRELDATE.  If the WORLDTMP
825# is older than the ABI-breakage OSRELDATE of the HOST then we rebuild.
826.if defined(OBJDIR_HOST_OSRELDATE)
827.for _ver in ${META_MODE_BAD_ABI_VERS}
828.if ${OSRELDATE} >= ${_ver} && ${OBJDIR_HOST_OSRELDATE} < ${_ver}
829_meta_mode_need_rebuild=	${_ver}
830.endif
831.endfor
832.if defined(_meta_mode_need_rebuild)
833.info META_MODE: Rebuilding host tools due to ABI breakage in __FreeBSD_version ${_meta_mode_need_rebuild}.
834NO_META_IGNORE_HOST_HEADERS=	1
835.export NO_META_IGNORE_HOST_HEADERS
836.endif	# defined(_meta_mode_need_rebuild)
837.endif	# defined(OBJDIR_HOST_OSRELDATE)
838.endif	# ${MK_META_MODE} == "yes" && defined(NO_CLEAN) ...
839# This is only used for META_MODE+filemon to track what the oldest
840# __FreeBSD_version is in WORLDTMP.  This purposely does NOT have
841# a make dependency on /usr/include/osreldate.h as the file should
842# only be copied when it is missing or meta mode determines it has changed.
843# Since host files are normally ignored without NO_META_IGNORE_HOST
844# the file will never be updated unless that flag is specified.  This
845# allows tracking the oldest osreldate to force rebuilds via
846# META_MODE_BADABI_REVS above.
847host-osreldate.h: # DO NOT ADD /usr/include/osreldate.h here
848	@cp -f /usr/include/osreldate.h ${.TARGET}
849
850WMAKE=		${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
851		BWPHASE=${.TARGET:C,^_,,} \
852		DESTDIR=${WORLDTMP}
853
854IMAKEENV=	${CROSSENV}
855IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1 \
856		${IMAKE_INSTALL} ${IMAKE_MTREE}
857.if empty(.MAKEFLAGS:M-n)
858IMAKEENV+=	PATH=${STRICTTMPPATH}:${INSTALLTMP} \
859		LD_LIBRARY_PATH=${INSTALLTMP} \
860		PATH_LOCALE=${INSTALLTMP}/locale
861IMAKE+=		__MAKE_SHELL=${INSTALLTMP}/sh
862.else
863IMAKEENV+=	PATH=${TMPPATH}:${INSTALLTMP}
864.endif
865
866# When generating install media, do not allow user and group information from
867# the build host to affect the contents of the distribution.
868.if make(distributeworld) || make(distrib-dirs) || make(distribution) || \
869    make(stageworld)
870DB_FROM_SRC=	yes
871.endif
872
873.if defined(DB_FROM_SRC)
874INSTALLFLAGS+=	-N ${.CURDIR}/etc
875MTREEFLAGS+=	-N ${.CURDIR}/etc
876.endif
877_INSTALL_DDIR=	${DESTDIR}/${DISTDIR}
878INSTALL_DDIR=	${_INSTALL_DDIR:S://:/:g:C:/$::}
879.if defined(NO_ROOT)
880METALOG?=	${DESTDIR}/${DISTDIR}/METALOG
881METALOG:=	${METALOG:C,//+,/,g}
882IMAKE+=		-DNO_ROOT METALOG=${METALOG}
883INSTALLFLAGS+=	-U -M ${METALOG} -D ${INSTALL_DDIR}
884MTREEFLAGS+=	-W
885.endif
886.if defined(BUILD_PKGS)
887INSTALLFLAGS+=	-h sha256
888.endif
889.if defined(DB_FROM_SRC) || defined(NO_ROOT)
890IMAKE_INSTALL=	INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}"
891IMAKE_MTREE=	MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}"
892.endif
893
894DESTDIR_MTREEFLAGS=	-deU
895# When creating worldtmp we don't need to set the directories as owned by root
896# so we also pass -W
897WORLDTMP_MTREEFLAGS=	-deUW
898.if defined(NO_ROOT)
899# When building with -DNO_ROOT we shouldn't be changing the directories
900# that are created by mtree to be owned by root/wheel.
901DESTDIR_MTREEFLAGS+=	-W
902.endif
903DISTR_MTREE=	${MTREE_CMD}
904.if ${BUILD_WITH_STRICT_TMPPATH} != 0
905DISTR_MTREE=	${WORLDTMP}/legacy/usr/sbin/mtree
906.endif
907WORLDTMP_MTREE=	${DISTR_MTREE} ${WORLDTMP_MTREEFLAGS}
908DESTDIR_MTREE=	${DISTR_MTREE} ${DESTDIR_MTREEFLAGS}
909
910# kernel stage
911KMAKEENV=	${WMAKEENV:NSYSROOT=*}
912KMAKE=		${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
913
914#
915# buildworld
916#
917# Attempt to rebuild the entire system, with reasonable chance of
918# success, regardless of how old your existing system is.
919#
920_sanity_check: .PHONY .MAKE
921.if ${.CURDIR:C/[^,]//g} != ""
922#	The m4 build of sendmail files doesn't like it if ',' is used
923#	anywhere in the path of it's files.
924	@echo
925	@echo "*** Error: path to source tree contains a comma ','"
926	@echo
927	@false
928.elif ${.CURDIR:M*\:*} != ""
929#	Using ':' leaks into PATH and breaks finding cross-tools.
930	@echo
931	@echo "*** Error: path to source tree contains a colon ':'"
932	@echo
933	@false
934.endif
935
936# Our current approach to dependency tracking cannot cope with certain source
937# tree changes, particularly with respect to removing source files and
938# replacing generated files.  Handle these cases here in an ad-hoc fashion.
939_cleanobj_fast_depend_hack: .PHONY
940	@echo ">>> Deleting stale dependencies...";
941	sh ${.CURDIR}/tools/build/depend-cleanup.sh ${OBJTOP}
942# Date      SVN Rev  Syscalls/Changes
943# Syscall stubs rewritten in C and obsolete MD assembly implementations
944# 20191009  r353340  removal of opensolaris_atomic.S (also r353381)
945.if ${MACHINE} != i386
946.for f in opensolaris_atomic
947	@if [ -e "${OBJTOP}/cddl/lib/libzpool/.depend.${f}.o" ] && \
948	    egrep -qw 'opensolaris_atomic\.S' ${OBJTOP}/cddl/lib/libzpool/.depend.${f}.o; then \
949		echo "Removing stale dependencies for opensolaris_atomic"; \
950		rm -f ${OBJTOP}/cddl/lib/libzpool/.depend.${f}.* \
951		   ${LIBCOMPAT:D${LIBCOMPAT_OBJTOP}/cddl/lib/libzpool/.depend.${f}.*}; \
952	fi
953.endfor
954.endif
955# 20190925  r352689  removal of obsolete i386 memchr.S
956.for f in memchr
957	@if [ -e "${OBJTOP}/lib/libc/.depend.${f}.o" ] && \
958	    egrep -qw 'i386/string/memchr\.S' ${OBJTOP}/lib/libc/.depend.${f}.o; then \
959		echo "Removing stale dependencies for memchr"; \
960		rm -f ${OBJTOP}/lib/libc/.depend.${f}.*; \
961	fi
962.if defined(_LIBCOMPAT)
963	@if [ -e "${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.o" ] && \
964	    egrep -qw 'i386/string/memchr\.S' ${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.o; then \
965		echo "Removing stale dependencies for memchr"; \
966		rm -f ${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.*; \
967	fi
968.endif
969.endfor
970
971_worldtmp: .PHONY
972	@echo
973	@echo "--------------------------------------------------------------"
974	@echo ">>> Rebuilding the temporary build tree"
975	@echo "--------------------------------------------------------------"
976.if !defined(NO_CLEAN)
977	rm -rf ${WORLDTMP}
978.else
979# Note: for delete-old we need to set $PATH to also include the host $PATH
980# since otherwise a partial build with missing symlinks in ${WORLDTMP}/legacy/
981# will fail to run due to missing binaries. $WMAKE sets PATH to only ${TMPPATH}
982# so we remove that assingnment from $WMAKE and prepend the new $PATH
983	${_+_}@if [ -e "${WORLDTMP}" ]; then \
984		echo ">>> Deleting stale files in build tree..."; \
985		cd ${.CURDIR}; env PATH=${TMPPATH}:${PATH} ${WMAKE:NPATH=*} \
986		    _NO_INCLUDE_COMPILERMK=t -DBATCH_DELETE_OLD_FILES delete-old \
987		    delete-old-libs >/dev/null; \
988	fi
989	rm -rf ${WORLDTMP}/legacy/usr/include
990.if ${USING_SYSTEM_COMPILER} == "yes"
991.for cc in cc c++
992	if [ -x ${WORLDTMP}/usr/bin/${cc} ]; then \
993		inum=$$(stat -f %i ${WORLDTMP}/usr/bin/${cc}); \
994		find ${WORLDTMP}/usr/bin -inum $${inum} -delete; \
995	fi
996.endfor
997.endif	# ${USING_SYSTEM_COMPILER} == "yes"
998.if ${USING_SYSTEM_LINKER} == "yes"
999	@rm -f ${WORLDTMP}/usr/bin/ld ${WORLDTMP}/usr/bin/ld.lld
1000.endif	# ${USING_SYSTEM_LINKER} == "yes"
1001.endif	# !defined(NO_CLEAN)
1002	@mkdir -p ${WORLDTMP}
1003	@touch ${WORLDTMP}/${.TARGET}
1004# We can't use mtree to create the worldtmp directories since it may not be
1005# available on the target system (this happens e.g. when building on non-FreeBSD)
1006	cd ${.CURDIR}/tools/build; \
1007	    ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy installdirs
1008# In order to build without inheriting $PATH we need to add symlinks to the host
1009# tools in $WORLDTMP for the tools that we don't build during bootstrap-tools
1010	cd ${.CURDIR}/tools/build; \
1011	    ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy host-symlinks
1012
1013_legacy:
1014	@echo
1015	@echo "--------------------------------------------------------------"
1016	@echo ">>> stage 1.1: legacy release compatibility shims"
1017	@echo "--------------------------------------------------------------"
1018	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
1019_bootstrap-tools:
1020	@echo
1021	@echo "--------------------------------------------------------------"
1022	@echo ">>> stage 1.2: bootstrap tools"
1023	@echo "--------------------------------------------------------------"
1024	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
1025	mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom
1026	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1027	    -p ${WORLDTMP}/usr >/dev/null
1028	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1029	    -p ${WORLDTMP}/usr/include >/dev/null
1030	ln -sf ${.CURDIR}/sys ${WORLDTMP}
1031.if ${MK_DEBUG_FILES} != "no"
1032	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1033	    -p ${WORLDTMP}/usr/lib >/dev/null
1034.endif
1035.for _mtree in ${LOCAL_MTREE}
1036	${WORLDTMP_MTREE} -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
1037.endfor
1038_cleanobj:
1039.if !defined(NO_CLEAN)
1040	@echo
1041	@echo "--------------------------------------------------------------"
1042	@echo ">>> stage 2.1: cleaning up the object tree"
1043	@echo "--------------------------------------------------------------"
1044	# Avoid including bsd.compiler.mk in clean and obj with _NO_INCLUDE_COMPILERMK
1045	# since the restricted $PATH might not contain a valid cc binary
1046	${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t ${CLEANDIR}
1047.if defined(_LIBCOMPAT)
1048	${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} _NO_INCLUDE_COMPILERMK=t -f Makefile.inc1 ${CLEANDIR}
1049.endif
1050.else
1051	${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t _cleanobj_fast_depend_hack
1052.endif	# !defined(NO_CLEAN)
1053_obj:
1054	@echo
1055	@echo "--------------------------------------------------------------"
1056	@echo ">>> stage 2.2: rebuilding the object tree"
1057	@echo "--------------------------------------------------------------"
1058	${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t obj
1059_build-tools:
1060	@echo
1061	@echo "--------------------------------------------------------------"
1062	@echo ">>> stage 2.3: build tools"
1063	@echo "--------------------------------------------------------------"
1064	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
1065_cross-tools:
1066	@echo
1067	@echo "--------------------------------------------------------------"
1068	@echo ">>> stage 3: cross tools"
1069	@echo "--------------------------------------------------------------"
1070	@rm -f ${OBJTOP}/toolchain-metadata.mk
1071	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
1072	${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
1073_build-metadata:
1074	@echo
1075	@echo "--------------------------------------------------------------"
1076	@echo ">>> stage 3.1: recording build metadata"
1077	@echo "--------------------------------------------------------------"
1078	${_+_}cd ${.CURDIR}; ${WMAKE} toolchain-metadata.mk
1079	${_+_}cd ${.CURDIR}; ${WMAKE} host-osreldate.h
1080_includes:
1081	@echo
1082	@echo "--------------------------------------------------------------"
1083	@echo ">>> stage 4.1: building includes"
1084	@echo "--------------------------------------------------------------"
1085# Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
1086# headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
1087	${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
1088	    MK_INCLUDES=yes includes
1089.if !empty(SUBDIR_OVERRIDE) && make(buildworld)
1090	${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
1091.endif
1092_libraries:
1093	@echo
1094	@echo "--------------------------------------------------------------"
1095	@echo ">>> stage 4.2: building libraries"
1096	@echo "--------------------------------------------------------------"
1097	${_+_}cd ${.CURDIR}; \
1098	    ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
1099	    MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} \
1100	    libraries
1101everything: .PHONY
1102	@echo
1103	@echo "--------------------------------------------------------------"
1104	@echo ">>> stage 4.4: building everything"
1105	@echo "--------------------------------------------------------------"
1106	${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
1107
1108WMAKE_TGTS=
1109.if !defined(WORLDFAST)
1110WMAKE_TGTS+=	_sanity_check _worldtmp _legacy
1111.if empty(SUBDIR_OVERRIDE)
1112WMAKE_TGTS+=	_bootstrap-tools
1113.endif
1114WMAKE_TGTS+=	_cleanobj
1115.if !defined(NO_OBJWALK)
1116WMAKE_TGTS+=	_obj
1117.endif
1118WMAKE_TGTS+=	_build-tools _cross-tools
1119WMAKE_TGTS+=	_build-metadata
1120WMAKE_TGTS+=	_includes
1121.endif
1122.if !defined(NO_LIBS)
1123WMAKE_TGTS+=	_libraries
1124.endif
1125.if defined(_LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
1126WMAKE_TGTS+=	build${libcompat}
1127.endif
1128WMAKE_TGTS+=	everything
1129
1130# record buildworld time in seconds
1131.if make(buildworld)
1132_BUILDWORLD_START!= date '+%s'
1133.export _BUILDWORLD_START
1134.endif
1135
1136buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY
1137.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
1138
1139buildworld_prologue: .PHONY
1140	@echo "--------------------------------------------------------------"
1141	@echo ">>> World build started on `LC_ALL=C date`"
1142	@echo "--------------------------------------------------------------"
1143
1144buildworld_epilogue: .PHONY
1145	@echo
1146	@echo "--------------------------------------------------------------"
1147	@echo ">>> World build completed on `LC_ALL=C date`"
1148	@seconds=$$(($$(date '+%s') - ${_BUILDWORLD_START})); \
1149	  echo -n ">>> World built in $$seconds seconds, "; \
1150	  echo "ncpu: $$(sysctl -n hw.ncpu)${.MAKE.JOBS:S/^/, make -j/}"
1151	@echo "--------------------------------------------------------------"
1152
1153#
1154# We need to have this as a target because the indirection between Makefile
1155# and Makefile.inc1 causes the correct PATH to be used, rather than a
1156# modification of the current environment's PATH.  In addition, we need
1157# to quote multiword values.
1158#
1159buildenvvars: .PHONY
1160	@echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
1161
1162.if ${.TARGETS:Mbuildenv}
1163.if ${.MAKEFLAGS:M-j}
1164.error The buildenv target is incompatible with -j
1165.endif
1166.endif
1167BUILDENV_DIR?=	${.CURDIR}
1168#
1169# Note: make will report any errors the shell reports. This can
1170# be odd if the last command in an interactive shell generates an
1171# error or is terminated by SIGINT. These reported errors look bad,
1172# but are harmless. Allowing them also allows BUIDLENV_SHELL to
1173# be a complex command whose status will be returned to the caller.
1174# Some scripts in tools rely on this behavior to report build errors.
1175#
1176buildenv: .PHONY
1177	@echo Entering world for ${TARGET_ARCH}:${TARGET}
1178.if ${BUILDENV_SHELL:M*zsh*}
1179	@echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
1180.endif
1181	@cd ${BUILDENV_DIR} && env ${WMAKEENV} BUILDENV=1 ${BUILDENV_SHELL}
1182
1183TOOLCHAIN_TGTS=	${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
1184toolchain: ${TOOLCHAIN_TGTS} .PHONY
1185KERNEL_TOOLCHAIN_TGTS=	${TOOLCHAIN_TGTS:N_obj:N_cleanobj:N_includes:N_libraries}
1186.if make(kernel-toolchain)
1187.ORDER: ${KERNEL_TOOLCHAIN_TGTS}
1188.endif
1189kernel-toolchain: ${KERNEL_TOOLCHAIN_TGTS} .PHONY
1190
1191#
1192# installcheck
1193#
1194# Checks to be sure system is ready for installworld/installkernel.
1195#
1196installcheck: _installcheck_world _installcheck_kernel .PHONY
1197_installcheck_world: .PHONY
1198	@echo "--------------------------------------------------------------"
1199	@echo ">>> Install check world"
1200	@echo "--------------------------------------------------------------"
1201_installcheck_kernel: .PHONY
1202	@echo "--------------------------------------------------------------"
1203	@echo ">>> Install check kernel"
1204	@echo "--------------------------------------------------------------"
1205
1206#
1207# Require DESTDIR to be set if installing for a different architecture or
1208# using the user/group database in the source tree.
1209#
1210.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
1211    defined(DB_FROM_SRC)
1212.if !make(distributeworld)
1213_installcheck_world: __installcheck_DESTDIR
1214_installcheck_kernel: __installcheck_DESTDIR
1215__installcheck_DESTDIR: .PHONY
1216.if !defined(DESTDIR) || empty(DESTDIR)
1217	@echo "ERROR: Please set DESTDIR!"; \
1218	false
1219.endif
1220.endif
1221.endif
1222
1223.if !defined(DB_FROM_SRC)
1224#
1225# Check for missing UIDs/GIDs.
1226#
1227CHECK_UIDS=	auditdistd
1228CHECK_GIDS=	audit
1229CHECK_UIDS+=	ntpd
1230CHECK_GIDS+=	ntpd
1231CHECK_UIDS+=	proxy
1232CHECK_GIDS+=	proxy authpf
1233CHECK_UIDS+=	smmsp
1234CHECK_GIDS+=	smmsp
1235CHECK_UIDS+=	unbound
1236CHECK_GIDS+=	unbound
1237_installcheck_world: __installcheck_UGID
1238__installcheck_UGID: .PHONY
1239.for uid in ${CHECK_UIDS}
1240	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
1241		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
1242		false; \
1243	fi
1244.endfor
1245.for gid in ${CHECK_GIDS}
1246	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
1247		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
1248		false; \
1249	fi
1250.endfor
1251.endif
1252#
1253# If installing over the running system (DESTDIR is / or unset) and the install
1254# includes rescue, try running rescue from the objdir as a sanity check.  If
1255# rescue is not functional (e.g., because it depends on a system call not
1256# supported by the currently running kernel), abort the installation.
1257#
1258.if !make(distributeworld) && ${MK_RESCUE} != "no" && \
1259    (empty(DESTDIR) || ${DESTDIR} == "/") && empty(BYPASS_INSTALLCHECK_SH)
1260_installcheck_world: __installcheck_sh_check
1261__installcheck_sh_check: .PHONY
1262	@if [ "`${OBJTOP}/rescue/rescue/rescue sh -c 'echo OK'`" != \
1263	    OK ]; then \
1264		echo "rescue/sh check failed, installation aborted" >&2; \
1265		false; \
1266	fi
1267.endif
1268
1269#
1270# Required install tools to be saved in a scratch dir for safety.
1271#
1272.if ${MK_ZONEINFO} != "no"
1273_zoneinfo=	zic tzsetup
1274.endif
1275
1276ITOOLS=	[ awk cap_mkdb cat chflags chmod chown cmp cp \
1277	date echo egrep find grep id install ${_install-info} \
1278	ln make mkdir mtree mv pwd_mkdb \
1279	rm sed services_mkdb sh sort strip sysctl test true uname wc ${_zoneinfo} \
1280	${LOCAL_ITOOLS}
1281
1282# Needed for share/man
1283.if ${MK_MAN_UTILS} != "no"
1284ITOOLS+=makewhatis
1285.endif
1286
1287#
1288# distributeworld
1289#
1290# Distributes everything compiled by a `buildworld'.
1291#
1292# installworld
1293#
1294# Installs everything compiled by a 'buildworld'.
1295#
1296
1297# Non-base distributions produced by the base system
1298EXTRA_DISTRIBUTIONS=
1299.if defined(_LIBCOMPAT)
1300EXTRA_DISTRIBUTIONS+=	lib${libcompat}
1301.endif
1302.if ${MK_TESTS} != "no"
1303EXTRA_DISTRIBUTIONS+=	tests
1304.endif
1305
1306DEBUG_DISTRIBUTIONS=
1307.if ${MK_DEBUG_FILES} != "no"
1308DEBUG_DISTRIBUTIONS+=	base ${EXTRA_DISTRIBUTIONS:S,tests,,}
1309.endif
1310
1311MTREE_MAGIC?=	mtree 2.0
1312
1313distributeworld installworld stageworld: _installcheck_world .PHONY
1314	mkdir -p ${INSTALLTMP}
1315	progs=$$(for prog in ${ITOOLS}; do \
1316		if progpath=`which $$prog`; then \
1317			echo $$progpath; \
1318		else \
1319			echo "Required tool $$prog not found in PATH." >&2; \
1320			exit 1; \
1321		fi; \
1322	    done); \
1323	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
1324	    while read line; do \
1325		set -- $$line; \
1326		if [ "$$2 $$3" != "not found" ]; then \
1327			echo $$2; \
1328		else \
1329			echo "Required library $$1 not found." >&2; \
1330			exit 1; \
1331		fi; \
1332	    done); \
1333	cp $$libs $$progs ${INSTALLTMP}
1334	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
1335.if defined(NO_ROOT)
1336	-mkdir -p ${METALOG:H}
1337	echo "#${MTREE_MAGIC}" > ${METALOG}
1338.endif
1339.if make(distributeworld)
1340.for dist in ${EXTRA_DISTRIBUTIONS}
1341	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
1342	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1343	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
1344	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1345	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1346	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1347	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
1348.if ${MK_DEBUG_FILES} != "no"
1349	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1350	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
1351.endif
1352.if defined(_LIBCOMPAT)
1353	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1354	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1355.if ${MK_DEBUG_FILES} != "no"
1356	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1357	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
1358.endif
1359.endif
1360.if ${MK_TESTS} != "no" && ${dist} == "tests"
1361	-mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
1362	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1363	    -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
1364.if ${MK_DEBUG_FILES} != "no"
1365	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1366	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
1367.endif
1368.endif
1369.if defined(NO_ROOT)
1370	${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
1371	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
1372	${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
1373	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1374	${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
1375	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
1376.if defined(_LIBCOMPAT)
1377	${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
1378	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1379.endif
1380.endif
1381.endfor
1382	-mkdir ${DESTDIR}/${DISTDIR}/base
1383	${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1384	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
1385	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
1386	    LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
1387	${INSTALL_SYMLINK} ${INSTALLFLAGS} usr/src/sys ${INSTALL_DDIR}/base/sys
1388.endif
1389	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
1390	    ${IMAKEENV} rm -rf ${INSTALLTMP}
1391.if make(distributeworld)
1392.for dist in ${EXTRA_DISTRIBUTIONS}
1393	find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete
1394.endfor
1395.if defined(NO_ROOT)
1396.for dist in base ${EXTRA_DISTRIBUTIONS}
1397	@# For each file that exists in this dist, print the corresponding
1398	@# line from the METALOG.  This relies on the fact that
1399	@# a line containing only the filename will sort immediately before
1400	@# the relevant mtree line.
1401	cd ${DESTDIR}/${DISTDIR}; \
1402	find ./${dist} | sort -u ${METALOG} - | \
1403	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1404	${DESTDIR}/${DISTDIR}/${dist}.meta
1405.endfor
1406.for dist in ${DEBUG_DISTRIBUTIONS}
1407	@# For each file that exists in this dist, print the corresponding
1408	@# line from the METALOG.  This relies on the fact that
1409	@# a line containing only the filename will sort immediately before
1410	@# the relevant mtree line.
1411	cd ${DESTDIR}/${DISTDIR}; \
1412	find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
1413	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1414	${DESTDIR}/${DISTDIR}/${dist}.debug.meta
1415.endfor
1416.endif
1417.endif
1418
1419packageworld: .PHONY
1420.for dist in base ${EXTRA_DISTRIBUTIONS}
1421.if defined(NO_ROOT)
1422	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1423	    tar cvf - --exclude usr/lib/debug \
1424	    @${DESTDIR}/${DISTDIR}/${dist}.meta | \
1425	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1426.else
1427	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1428	    tar cvf - --exclude usr/lib/debug . | \
1429	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1430.endif
1431.endfor
1432
1433.for dist in ${DEBUG_DISTRIBUTIONS}
1434. if defined(NO_ROOT)
1435	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1436	    tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
1437	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1438. else
1439	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1440	    tar cvLf - usr/lib/debug | \
1441	    ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1442. endif
1443.endfor
1444
1445makeman: .PHONY
1446	${_+_}cd ${.CURDIR}/tools/build/options; sh makeman > \
1447	    ${.CURDIR}/share/man/man5/src.conf.5
1448
1449# We can't assume here that ${TMPPATH} will include ${PATH} or /usr/libexec
1450# because we may be building with a STRICTTMPPATH, so we explicitly include
1451# /usr/libexec here for flua.  ${TMPPATH} still usefully includes anything else
1452# we may need to function.
1453_sysent_PATH=	${TMPPATH}:/usr/libexec
1454_sysent_dirs=	sys/kern
1455_sysent_dirs+=	sys/compat/freebsd32
1456_sysent_dirs+=	sys/compat/cloudabi32	\
1457		sys/compat/cloudabi64
1458_sysent_dirs+=	sys/amd64/linux		\
1459		sys/amd64/linux32	\
1460		sys/arm/linux		\
1461		sys/arm64/linux		\
1462		sys/i386/linux
1463sysent: .PHONY
1464.for _dir in ${_sysent_dirs}
1465	@echo "${MAKE} -C ${.CURDIR}/${_dir} sysent"
1466	${_+_}@env PATH=${_sysent_PATH} ${MAKE} -C ${.CURDIR}/${_dir} sysent
1467.endfor
1468
1469#
1470# reinstall
1471#
1472# If you have a build server, you can NFS mount the source and obj directories
1473# and do a 'make reinstall' on the *client* to install new binaries from the
1474# most recent server build.
1475#
1476restage reinstall: .MAKE .PHONY
1477	@echo "--------------------------------------------------------------"
1478	@echo ">>> Making hierarchy"
1479	@echo "--------------------------------------------------------------"
1480	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1481	    LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
1482.if make(restage)
1483	@echo "--------------------------------------------------------------"
1484	@echo ">>> Making distribution"
1485	@echo "--------------------------------------------------------------"
1486	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1487	    LOCAL_MTREE=${LOCAL_MTREE:Q} distribution
1488.endif
1489	@echo
1490	@echo "--------------------------------------------------------------"
1491	@echo ">>> Installing everything started on `LC_ALL=C date`"
1492	@echo "--------------------------------------------------------------"
1493	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
1494.if defined(_LIBCOMPAT)
1495	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
1496.endif
1497	@echo "--------------------------------------------------------------"
1498	@echo ">>> Installing everything completed on `LC_ALL=C date`"
1499	@echo "--------------------------------------------------------------"
1500
1501redistribute: .MAKE .PHONY
1502	@echo "--------------------------------------------------------------"
1503	@echo ">>> Distributing everything"
1504	@echo "--------------------------------------------------------------"
1505	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1506.if defined(_LIBCOMPAT)
1507	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1508	    DISTRIBUTION=lib${libcompat}
1509.endif
1510
1511distrib-dirs distribution: .MAKE .PHONY
1512	${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1513	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1514.if make(distribution)
1515	${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1516		${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1517		METALOG=${METALOG} MK_TESTS=no \
1518		MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} installconfig
1519.endif
1520
1521#
1522# buildkernel and installkernel
1523#
1524# Which kernels to build and/or install is specified by setting
1525# KERNCONF. If not defined a GENERIC kernel is built/installed.
1526# Only the existing (depending TARGET) config files are used
1527# for building kernels and only the first of these is designated
1528# as the one being installed.
1529#
1530# Note that we have to use TARGET instead of TARGET_ARCH when
1531# we're in kernel-land. Since only TARGET_ARCH is (expected) to
1532# be set to cross-build, we have to make sure TARGET is set
1533# properly.
1534
1535.if defined(KERNFAST)
1536NO_KERNELCLEAN=	t
1537NO_KERNELCONFIG=	t
1538NO_KERNELOBJ=		t
1539# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1540.if !defined(KERNCONF) && ${KERNFAST} != "1"
1541KERNCONF=${KERNFAST}
1542.endif
1543.endif
1544.if ${TARGET_ARCH} == "powerpc64"
1545KERNCONF?=	GENERIC64
1546.else
1547KERNCONF?=	GENERIC
1548.endif
1549INSTKERNNAME?=	kernel
1550
1551KERNSRCDIR?=	${.CURDIR}/sys
1552KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
1553KRNLOBJDIR=	${OBJTOP}${KERNSRCDIR:C,^${.CURDIR},,}
1554KERNCONFDIR?=	${KRNLCONFDIR}
1555
1556BUILDKERNELS=
1557INSTALLKERNEL=
1558.if defined(NO_INSTALLKERNEL)
1559# All of the BUILDKERNELS loops start at index 1.
1560BUILDKERNELS+= dummy
1561.endif
1562.for _kernel in ${KERNCONF}
1563.if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${_kernel})
1564BUILDKERNELS+=	${_kernel}
1565.if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1566INSTALLKERNEL= ${_kernel}
1567.endif
1568.else
1569.if make(buildkernel)
1570.error Missing KERNCONF ${KERNCONFDIR}/${_kernel}
1571.endif
1572.endif
1573.endfor
1574
1575_cleankernobj_fast_depend_hack: .PHONY
1576# 20191009  r353340  removal of opensolaris_atomic.S (also r353381)
1577.if ${MACHINE} != i386
1578.for f in opensolaris_atomic
1579.for m in opensolaris zfs
1580	@if [ -e "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o" ] && \
1581	    grep -q ${f}.S "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o"; then \
1582		echo "Removing stale dependencies for opensolaris_atomic"; \
1583		rm -f ${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.*; \
1584	fi
1585.endfor
1586.endfor
1587.endif
1588
1589${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1590
1591# record kernel(s) build time in seconds
1592.if make(buildkernel)
1593_BUILDKERNEL_START!= date '+%s'
1594.endif
1595
1596#
1597# buildkernel
1598#
1599# Builds all kernels defined by BUILDKERNELS.
1600#
1601buildkernel: .MAKE .PHONY
1602.if empty(BUILDKERNELS:Ndummy)
1603	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1604	false
1605.endif
1606	@echo
1607.for _kernel in ${BUILDKERNELS:Ndummy}
1608	@echo "--------------------------------------------------------------"
1609	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1610	@echo "--------------------------------------------------------------"
1611	@echo "===> ${_kernel}"
1612	mkdir -p ${KRNLOBJDIR}
1613.if !defined(NO_KERNELCONFIG)
1614	@echo
1615	@echo "--------------------------------------------------------------"
1616	@echo ">>> stage 1: configuring the kernel"
1617	@echo "--------------------------------------------------------------"
1618	cd ${KRNLCONFDIR}; \
1619		PATH=${TMPPATH} \
1620		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1621			-I '${KERNCONFDIR}' -I '${KRNLCONFDIR}' \
1622			'${KERNCONFDIR}/${_kernel}'
1623.endif
1624.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1625	@echo
1626	@echo "--------------------------------------------------------------"
1627	@echo ">>> stage 2.1: cleaning up the object tree"
1628	@echo "--------------------------------------------------------------"
1629	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1630.else
1631	${_+_}cd ${.CURDIR}; ${WMAKE} _cleankernobj_fast_depend_hack
1632.endif
1633.if !defined(NO_KERNELOBJ)
1634	@echo
1635	@echo "--------------------------------------------------------------"
1636	@echo ">>> stage 2.2: rebuilding the object tree"
1637	@echo "--------------------------------------------------------------"
1638	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1639.endif
1640	@echo
1641	@echo "--------------------------------------------------------------"
1642	@echo ">>> stage 2.3: build tools"
1643	@echo "--------------------------------------------------------------"
1644	${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1645	@echo
1646	@echo "--------------------------------------------------------------"
1647	@echo ">>> stage 3.1: building everything"
1648	@echo "--------------------------------------------------------------"
1649	${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1650	@echo "--------------------------------------------------------------"
1651	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1652	@echo "--------------------------------------------------------------"
1653
1654.endfor
1655	@seconds=$$(($$(date '+%s') - ${_BUILDKERNEL_START})); \
1656	  echo -n ">>> Kernel(s) ${BUILDKERNELS} built in $$seconds seconds, "; \
1657	  echo "ncpu: $$(sysctl -n hw.ncpu)${.MAKE.JOBS:S/^/, make -j/}"
1658	@echo "--------------------------------------------------------------"
1659
1660NO_INSTALLEXTRAKERNELS?=	yes
1661
1662#
1663# installkernel, etc.
1664#
1665# Install the kernel defined by INSTALLKERNEL
1666#
1667installkernel installkernel.debug \
1668reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1669.if !defined(NO_INSTALLKERNEL)
1670.if empty(INSTALLKERNEL)
1671	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1672	false
1673.endif
1674	@echo "--------------------------------------------------------------"
1675	@echo ">>> Installing kernel ${INSTALLKERNEL} on $$(LC_ALL=C date)"
1676	@echo "--------------------------------------------------------------"
1677	${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1678	    ${CROSSENV} PATH=${TMPPATH} \
1679	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1680	@echo "--------------------------------------------------------------"
1681	@echo ">>> Installing kernel ${INSTALLKERNEL} completed on $$(LC_ALL=C date)"
1682	@echo "--------------------------------------------------------------"
1683.endif
1684.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1685.for _kernel in ${BUILDKERNELS:[2..-1]}
1686	@echo "--------------------------------------------------------------"
1687	@echo ">>> Installing kernel ${_kernel} $$(LC_ALL=C date)"
1688	@echo "--------------------------------------------------------------"
1689	${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1690	    ${CROSSENV} PATH=${TMPPATH} \
1691	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1692	@echo "--------------------------------------------------------------"
1693	@echo ">>> Installing kernel ${_kernel} completed on $$(LC_ALL=C date)"
1694	@echo "--------------------------------------------------------------"
1695.endfor
1696.endif
1697
1698distributekernel distributekernel.debug: .PHONY
1699.if !defined(NO_INSTALLKERNEL)
1700.if empty(INSTALLKERNEL)
1701	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1702	false
1703.endif
1704	mkdir -p ${DESTDIR}/${DISTDIR}
1705.if defined(NO_ROOT)
1706	@echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1707.endif
1708	${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1709	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1710	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1711	    DESTDIR=${INSTALL_DDIR}/kernel \
1712	    ${.TARGET:S/distributekernel/install/}
1713.if defined(NO_ROOT)
1714	@sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1715	    ${DESTDIR}/${DISTDIR}/kernel.meta
1716.endif
1717.endif
1718.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1719.for _kernel in ${BUILDKERNELS:[2..-1]}
1720.if defined(NO_ROOT)
1721	@echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1722.endif
1723	${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1724	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1725	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1726	    KERNEL=${INSTKERNNAME}.${_kernel} \
1727	    DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1728	    ${.TARGET:S/distributekernel/install/}
1729.if defined(NO_ROOT)
1730	@sed -e "s|^./kernel.${_kernel}|.|" \
1731	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1732	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1733.endif
1734.endfor
1735.endif
1736
1737packagekernel: .PHONY
1738.if defined(NO_ROOT)
1739.if !defined(NO_INSTALLKERNEL)
1740	cd ${DESTDIR}/${DISTDIR}/kernel; \
1741	    tar cvf - --exclude '*.debug' \
1742	    @${DESTDIR}/${DISTDIR}/kernel.meta | \
1743	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1744.endif
1745.if ${MK_DEBUG_FILES} != "no"
1746	cd ${DESTDIR}/${DISTDIR}/kernel; \
1747	    tar cvf - --include '*/*/*.debug' \
1748	    @${DESTDIR}/${DISTDIR}/kernel.meta | \
1749	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1750.endif
1751.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1752.for _kernel in ${BUILDKERNELS:[2..-1]}
1753	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1754	    tar cvf - --exclude '*.debug' \
1755	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1756	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1757.if ${MK_DEBUG_FILES} != "no"
1758	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1759	    tar cvf - --include '*/*/*.debug' \
1760	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1761	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1762.endif
1763.endfor
1764.endif
1765.else
1766.if !defined(NO_INSTALLKERNEL)
1767	cd ${DESTDIR}/${DISTDIR}/kernel; \
1768	    tar cvf - --exclude '*.debug' . | \
1769	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1770.endif
1771.if ${MK_DEBUG_FILES} != "no"
1772	cd ${DESTDIR}/${DISTDIR}/kernel; \
1773	    tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1774	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1775.endif
1776.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1777.for _kernel in ${BUILDKERNELS:[2..-1]}
1778	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1779	    tar cvf - --exclude '*.debug' . | \
1780	    ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1781.if ${MK_DEBUG_FILES} != "no"
1782	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1783	    tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1784	    ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1785.endif
1786.endfor
1787.endif
1788.endif
1789
1790stagekernel: .PHONY
1791	${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1792
1793PORTSDIR?=	/usr/ports
1794WSTAGEDIR?=	${OBJTOP}/worldstage
1795KSTAGEDIR?=	${OBJTOP}/kernelstage
1796REPODIR?=	${OBJROOT}repo
1797PKG_FORMAT?=	txz
1798PKGSIGNKEY?=	# empty
1799PKG_OUTPUT_DIR?=	${PKG_VERSION}
1800
1801.ORDER:		stage-packages create-packages
1802.ORDER:		create-packages create-world-packages
1803.ORDER:		create-packages create-kernel-packages
1804.ORDER:		create-packages sign-packages
1805
1806_pkgbootstrap: .PHONY
1807.if make(*package*) && !exists(${LOCALBASE}/sbin/pkg)
1808	@env ASSUME_ALWAYS_YES=YES pkg bootstrap
1809.endif
1810
1811packages: .PHONY
1812	${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1813
1814package-pkg: .PHONY
1815	rm -rf /tmp/ports.${TARGET} || :
1816	env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \
1817		PKG_CMD=${PKG_CMD} PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} \
1818		WSTAGEDIR=${WSTAGEDIR} \
1819		sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1820
1821real-packages:	stage-packages create-packages sign-packages .PHONY
1822
1823stage-packages-world: .PHONY
1824	@mkdir -p ${WSTAGEDIR}
1825	${_+_}@cd ${.CURDIR}; \
1826		${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT stageworld
1827
1828stage-packages-kernel: .PHONY
1829	@mkdir -p ${KSTAGEDIR}
1830	${_+_}@cd ${.CURDIR}; \
1831		${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT stagekernel
1832
1833stage-packages: .PHONY stage-packages-world stage-packages-kernel
1834
1835_repodir: .PHONY
1836	@mkdir -p ${REPODIR}
1837
1838create-packages-world:	_pkgbootstrap _repodir .PHONY
1839	${_+_}@cd ${.CURDIR}; \
1840		${MAKE} -f Makefile.inc1 \
1841			DESTDIR=${WSTAGEDIR} \
1842			PKG_VERSION=${PKG_VERSION} create-world-packages
1843
1844create-packages-kernel:	_pkgbootstrap _repodir .PHONY
1845	${_+_}@cd ${.CURDIR}; \
1846		${MAKE} -f Makefile.inc1 \
1847			DESTDIR=${KSTAGEDIR} \
1848			PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1849			SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1850			create-kernel-packages
1851
1852create-packages: .PHONY create-packages-world create-packages-kernel
1853
1854create-world-packages:	_pkgbootstrap .PHONY
1855	@rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1856	@cd ${WSTAGEDIR} ; \
1857		env -i LC_COLLATE=C sort ${WSTAGEDIR}/${DISTDIR}/METALOG | \
1858		awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk
1859	@for plist in ${WSTAGEDIR}/*.plist; do \
1860	  plist=$${plist##*/} ; \
1861	  pkgname=$${plist%.plist} ; \
1862	  echo "_PKGS+= $${pkgname}" ; \
1863	done > ${WSTAGEDIR}/packages.mk
1864	${_+_}@cd ${.CURDIR}; \
1865		${MAKE} -f Makefile.inc1 create-world-packages-jobs \
1866		SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1867		.MAKE.JOB.PREFIX=
1868
1869.if make(create-world-packages-jobs)
1870.include "${WSTAGEDIR}/packages.mk"
1871.endif
1872
1873.if make(create-world-packages-jobs) || make(create-kernel-packages*)
1874PKG_ABI!=${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI
1875.endif
1876
1877create-world-packages-jobs: .PHONY
1878.for pkgname in ${_PKGS}
1879create-world-packages-jobs: create-world-package-${pkgname}
1880create-world-package-${pkgname}: .PHONY
1881	@sh ${SRCDIR}/release/packages/generate-ucl.sh -o ${pkgname} \
1882		-s ${SRCDIR} -u ${WSTAGEDIR}/${pkgname}.ucl
1883	@awk -F\" ' \
1884		/^name/ { printf("===> Creating %s-", $$2); next } \
1885		/^version/ { print $$2; next } \
1886		' ${WSTAGEDIR}/${pkgname}.ucl
1887	@if [ "${pkgname}" == "runtime" ]; then \
1888		sed -i '' -e "s/%VCS_REVISION%/${VCS_REVISION}/" ${WSTAGEDIR}/${pkgname}.ucl ; \
1889	fi
1890	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1891		create -f ${PKG_FORMAT} -M ${WSTAGEDIR}/${pkgname}.ucl \
1892		-p ${WSTAGEDIR}/${pkgname}.plist \
1893		-r ${WSTAGEDIR} \
1894		-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1895.endfor
1896
1897_default_flavor=	-default
1898.if make(*package*) && exists(${KSTAGEDIR}/kernel.meta)
1899. if ${MK_DEBUG_FILES} != "no"
1900_debug=-dbg
1901. endif
1902create-kernel-packages:	.PHONY
1903. for flavor in "" ${_debug}
1904create-kernel-packages: create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}
1905create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}: _pkgbootstrap .PHONY
1906	@cd ${KSTAGEDIR}/${DISTDIR} ; \
1907	env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.meta | \
1908	awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1909		-v kernel=yes -v _kernconf=${INSTALLKERNEL} ; \
1910	sed -e "s/%VERSION%/${PKG_VERSION}/" \
1911		-e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1912		-e "s/%KERNELDIR%/kernel/" \
1913		-e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1914		-e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1915		-e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
1916		-e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
1917		-e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
1918		-e "s|%PKG_WWW%|${PKG_WWW}|" \
1919		${SRCDIR}/release/packages/kernel.ucl \
1920		> ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1921	awk -F\" ' \
1922		/name/ { printf("===> Creating %s-", $$2); next } \
1923		/version/ {print $$2; next } ' \
1924		${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1925	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1926		create -f ${PKG_FORMAT} \
1927		-M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
1928		-p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
1929		-r ${KSTAGEDIR}/${DISTDIR} \
1930		-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1931. endfor
1932.endif
1933.if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1934. for _kernel in ${BUILDKERNELS:[2..-1]}
1935.  if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
1936.   if ${MK_DEBUG_FILES} != "no"
1937_debug=-dbg
1938.   endif
1939.   for flavor in "" ${_debug}
1940create-kernel-packages: create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}
1941create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}: _pkgbootstrap .PHONY
1942	@cd ${KSTAGEDIR}/kernel.${_kernel} ; \
1943	env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.${_kernel}.meta | \
1944	awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1945		-v kernel=yes -v _kernconf=${_kernel} ; \
1946	sed -e "s/%VERSION%/${PKG_VERSION}/" \
1947		-e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
1948		-e "s/%KERNELDIR%/kernel.${_kernel}/" \
1949		-e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
1950		-e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
1951		-e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
1952		-e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
1953		-e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
1954		-e "s|%PKG_WWW%|${PKG_WWW}|" \
1955		${SRCDIR}/release/packages/kernel.ucl \
1956		> ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
1957	awk -F\" ' \
1958		/name/ { printf("===> Creating %s-", $$2); next } \
1959		/version/ {print $$2; next } ' \
1960		${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
1961	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1962		create -f ${PKG_FORMAT} \
1963		-M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
1964		-p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
1965		-r ${KSTAGEDIR}/kernel.${_kernel} \
1966		-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1967.   endfor
1968.  endif
1969. endfor
1970.endif
1971
1972sign-packages:	_pkgbootstrap .PHONY
1973	printf "version = 2;\npacking_format = \"${PKG_FORMAT}\";\n" > ${WSTAGEDIR}/meta
1974	@[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest" ] && \
1975		unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest ; \
1976	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname repo \
1977		-m ${WSTAGEDIR}/meta \
1978		-o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
1979		${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
1980		${PKGSIGNKEY} ; \
1981	cd ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI); \
1982	ln -s ${PKG_OUTPUT_DIR} latest
1983
1984#
1985#
1986# checkworld
1987#
1988# Run test suite on installed world.
1989#
1990checkworld: .PHONY
1991	@if [ ! -x "${LOCALBASE}/bin/kyua" ] && [ ! -x "/usr/bin/kyua" ]; then \
1992		echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
1993		exit 1; \
1994	fi
1995	${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile
1996
1997#
1998#
1999# doxygen
2000#
2001# Build the API documentation with doxygen
2002#
2003doxygen: .PHONY
2004	@if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \
2005		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
2006		exit 1; \
2007	fi
2008	${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
2009
2010#
2011# update
2012#
2013# Update the source tree(s), by running svn/svnup to update to the
2014# latest copy.
2015#
2016update: .PHONY
2017.if defined(SVN_UPDATE)
2018	@echo "--------------------------------------------------------------"
2019	@echo ">>> Updating ${.CURDIR} using Subversion"
2020	@echo "--------------------------------------------------------------"
2021	@(cd ${.CURDIR}; ${SVN_CMD} update ${SVNFLAGS})
2022.endif
2023
2024#
2025# ------------------------------------------------------------------------
2026#
2027# From here onwards are utility targets used by the 'make world' and
2028# related targets.  If your 'world' breaks, you may like to try to fix
2029# the problem and manually run the following targets to attempt to
2030# complete the build.  Beware, this is *not* guaranteed to work, you
2031# need to have a pretty good grip on the current state of the system
2032# to attempt to manually finish it.  If in doubt, 'make world' again.
2033#
2034
2035#
2036# legacy: Build compatibility shims for the next three targets. This is a
2037# minimal set of tools and shims necessary to compensate for older systems
2038# which don't have the APIs required by the targets built in bootstrap-tools,
2039# build-tools or cross-tools.
2040#
2041
2042
2043# libnv is a requirement for config(8), which is an unconditional
2044# bootstrap-tool.
2045_config_deps= lib/libnv
2046
2047legacy: .PHONY
2048.if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0
2049	@echo "ERROR: Source upgrades from versions prior to ${MINIMUM_SUPPORTED_REL} are not supported."; \
2050	false
2051.endif
2052
2053.for _tool in tools/build ${_config_deps}
2054	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
2055	    cd ${.CURDIR}/${_tool}; \
2056	    if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2057	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy includes; \
2058	    ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no all; \
2059	    ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no \
2060	        DESTDIR=${WORLDTMP}/legacy install
2061.endfor
2062
2063#
2064# bootstrap-tools: Build tools needed for compatibility. These are binaries that
2065# are built to build other binaries in the system. However, the focus of these
2066# binaries is usually quite narrow. Bootstrap tools use the host's compiler and
2067# libraries, augmented by -legacy, in addition to the libraries built during
2068# bootstrap-tools.
2069#
2070_bt=		_bootstrap-tools
2071
2072# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
2073# accidentally run tools that are incompatible but happen to be in $PATH.
2074# This is especially important when building on Linux/MacOS where many of the
2075# programs used during the build accept different flags or generate different
2076# output. On those platforms we only symlink the tools known to be compatible
2077# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
2078# from the FreeBSD sources during the bootstrap-tools stage.
2079# We want to build without the user's $PATH starting in the bootstrap-tools
2080# phase so the tools used in that phase (ln, cp, etc) must have already been
2081# linked to $WORLDTMP. The tools are listed in the _host_tools_to_symlink
2082# variable in tools/build/Makefile and are linked during the legacy phase.
2083# Since they could be Linux or MacOS binaries, too we must only use flags that
2084# are portable across operating systems.
2085
2086# If BOOTSTRAP_ALL_TOOLS is set we will build all the required tools from the
2087# current source tree. Otherwise we create a symlink to the version found in
2088# $PATH during the bootstrap-tools stage.
2089.if defined(BOOTSTRAP_ALL_TOOLS)
2090# BOOTSTRAPPING will be set on the command line so we can't override it here.
2091# Instead set BOOTSTRAPPING_OSRELDATE so that the value 0 is set ${BSARGS}
2092BOOTSTRAPPING_OSRELDATE:=	0
2093.endif
2094
2095.if ${MK_GAMES} != "no"
2096_strfile=	usr.bin/fortune/strfile
2097.endif
2098
2099.if ${MK_VT} != "no"
2100_vtfontcvt=	usr.bin/vtfontcvt
2101.endif
2102
2103# If we are not building the bootstrap because BOOTSTRAPPING is sufficient
2104# we symlink the host version to $WORLDTMP instead. By doing this we can also
2105# detect when a bootstrap tool is being used without the required MK_FOO.
2106# If you add a new bootstrap tool where we could also use the host version,
2107# please ensure that you also add a .else case where you add the tool to the
2108# _bootstrap_tools_links variable.
2109.if ${BOOTSTRAPPING} < 1000033
2110_m4=		usr.bin/m4
2111_lex=		usr.bin/lex
2112# Note: lex needs m4 to build but m4 also depends on lex. However, lex can be
2113# bootstrapped so we build lex first.
2114${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc ${_bt}-${_lex}
2115_bt_m4_depend=${_bt}-${_m4}
2116_bt_lex_depend=${_bt}-${_lex} ${_bt_m4_depend}
2117.else
2118_bootstrap_tools_links+=m4 lex
2119.endif
2120
2121# ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
2122# r296685 fix cross-endian objcopy
2123# r310724 fixed PR 215350, a crash in libdwarf with objects built by GCC 6.2.
2124# r334881 added libdwarf constants used by ctfconvert.
2125# r338478 fixed a crash in objcopy for mips64el objects
2126# r339083 libelf: correct mips64el test to use ELF header
2127# r348347 Add missing powerpc64 relocation support to libdwarf
2128.if ${BOOTSTRAPPING} < 1300030
2129_elftoolchain_libs= lib/libelf lib/libdwarf lib/libzstd
2130${_bt}-lib/libelf: ${_bt_m4_depend}
2131${_bt}-lib/libdwarf: ${_bt_m4_depend}
2132.endif
2133
2134# flua is required to regenerate syscall files.  It first appeared during the
2135# 13.0-CURRENT cycle, thus needs to be built on -older releases and stable
2136# branches.
2137.if ${BOOTSTRAPPING} < 1300059
2138${_bt}-libexec/flua: ${_bt}-lib/liblua ${_bt}-lib/libucl
2139_flua= lib/liblua lib/libucl libexec/flua
2140.endif
2141
2142# r245440 mtree -N support added
2143# r313404 requires sha384.h for libnetbsd, added to libmd in r292782
2144.if ${BOOTSTRAPPING} < 1100093
2145_nmtree=	lib/libmd \
2146		lib/libnetbsd \
2147		usr.sbin/nmtree
2148
2149${_bt}-lib/libnetbsd: ${_bt}-lib/libmd
2150${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
2151.else
2152_bootstrap_tools_links+=mtree
2153.endif
2154
2155# r246097: log addition login.conf.db, passwd, pwd.db, and spwd.db with cat -l
2156.if ${BOOTSTRAPPING} < 1000027
2157_cat=		bin/cat
2158.else
2159_bootstrap_tools_links+=cat
2160.endif
2161
2162# r277259 crunchide: Correct 64-bit section header offset
2163# r281674 crunchide: always include both 32- and 64-bit ELF support
2164.if ${BOOTSTRAPPING} < 1100078
2165_crunchide=	usr.sbin/crunch/crunchide
2166.else
2167_bootstrap_tools_links+=crunchide
2168.endif
2169
2170# r285986 crunchen: use STRIPBIN rather than STRIP
2171# 1100113: Support MK_AUTO_OBJ
2172# 1200006: META_MODE fixes
2173.if ${BOOTSTRAPPING} < 1100078 || \
2174    (${MK_AUTO_OBJ} == "yes" && ${BOOTSTRAPPING} < 1100114) || \
2175    (${MK_META_MODE} == "yes" && ${BOOTSTRAPPING} < 1200006)
2176_crunchgen=	usr.sbin/crunch/crunchgen
2177.else
2178_bootstrap_tools_links+=crunchgen
2179.endif
2180
2181# r296926 -P keymap search path, MFC to stable/10 in r298297
2182.if ${BOOTSTRAPPING} < 1003501 || \
2183	(${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103)
2184_kbdcontrol=	usr.sbin/kbdcontrol
2185.else
2186_bootstrap_tools_links+=kbdcontrol
2187.endif
2188
2189_yacc=		usr.bin/yacc
2190
2191.if ${MK_BSNMP} != "no"
2192_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
2193.endif
2194
2195
2196# We need to build tblgen when we're building clang or lld, either as
2197# bootstrap tools, or as the part of the normal build.
2198.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" || \
2199    ${MK_LLD_BOOTSTRAP} != "no" || ${MK_LLD} != "no"
2200_clang_tblgen= \
2201	lib/clang/libllvmminimal \
2202	usr.bin/clang/llvm-tblgen \
2203	usr.bin/clang/clang-tblgen \
2204	usr.bin/clang/lldb-tblgen
2205# XXX: lldb-tblgen is not needed, if top-level MK_LLDB=no
2206
2207${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmminimal
2208${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmminimal
2209${_bt}-usr.bin/clang/lldb-tblgen: ${_bt}-lib/clang/libllvmminimal
2210.endif
2211
2212.if ${MK_LOCALES} != "no"
2213_localedef=	usr.bin/localedef
2214.endif
2215
2216.if ${MK_KERBEROS} != "no"
2217_kerberos5_bootstrap_tools= \
2218	kerberos5/tools/make-roken \
2219	kerberos5/lib/libroken \
2220	kerberos5/lib/libvers \
2221	kerberos5/tools/asn1_compile \
2222	kerberos5/tools/slc \
2223	usr.bin/compile_et
2224
2225.ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
2226.for _tool in ${_kerberos5_bootstrap_tools}
2227${_bt}-${_tool}: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
2228.endfor
2229.endif
2230
2231${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd
2232
2233# The tools listed in _basic_bootstrap_tools will generally not be
2234# bootstrapped unless BOOTSTRAP_ALL_TOOL is set. However, when building on a
2235# Linux or MacOS host the host versions are incompatible so we need to build
2236# them from the source tree. Usually the link name will be the same as the subdir,
2237# but some directories such as grep or test install multiple binaries. In that
2238# case we use the _basic_bootstrap_tools_multilink variable which is a list of
2239# subdirectory and comma-separated list of files.
2240_basic_bootstrap_tools_multilink=usr.bin/grep grep,egrep,fgrep
2241_basic_bootstrap_tools_multilink+=bin/test test,[
2242# bootstrap tools needed by buildworld:
2243_basic_bootstrap_tools=usr.bin/awk usr.bin/cut bin/expr usr.bin/gencat \
2244    usr.bin/join usr.bin/mktemp bin/rmdir usr.bin/sed usr.bin/sort \
2245    usr.bin/truncate usr.bin/tsort
2246# file2c is required for building usr.sbin/config:
2247_basic_bootstrap_tools+=usr.bin/file2c
2248# uuencode/uudecode required for share/tabset
2249_basic_bootstrap_tools+=usr.bin/uuencode usr.bin/uudecode
2250# xargs is required by mkioctls
2251_basic_bootstrap_tools+=usr.bin/xargs
2252# cap_mkdb is required for share/termcap:
2253_basic_bootstrap_tools+=usr.bin/cap_mkdb
2254# ldd is required for installcheck (TODO: just always use /usr/bin/ldd instead?)
2255_basic_bootstrap_tools+=usr.bin/ldd
2256# services_mkdb/pwd_mkdb are required for installworld:
2257_basic_bootstrap_tools+=usr.sbin/services_mkdb usr.sbin/pwd_mkdb
2258# sysctl/chflags are required for installkernel:
2259_basic_bootstrap_tools+=sbin/sysctl bin/chflags
2260# mkfifo is used by sys/conf/newvers.sh
2261_basic_bootstrap_tools+=usr.bin/mkfifo
2262
2263.if ${MK_BOOT} != "no"
2264_basic_bootstrap_tools+=bin/dd
2265# xz/unxz is used by EFI
2266_basic_bootstrap_tools_multilink+=usr.bin/xz xz,unxz
2267# md5 is used by boot/beri (and possibly others)
2268_basic_bootstrap_tools+=sbin/md5
2269.if defined(BOOTSTRAP_ALL_TOOLS)
2270${_bt}-sbin/md5: ${_bt}-lib/libmd
2271.endif
2272.endif
2273
2274.if ${MK_ZONEINFO} != "no"
2275_basic_bootstrap_tools+=usr.sbin/zic usr.sbin/tzsetup
2276.endif
2277
2278.if defined(BOOTSTRAP_ALL_TOOLS)
2279_other_bootstrap_tools+=${_basic_bootstrap_tools}
2280.for _subdir _links in ${_basic_bootstrap_tools_multilink}
2281_other_bootstrap_tools+=${_subdir}
2282.endfor
2283${_bt}-usr.bin/awk: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2284${_bt}-bin/expr: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2285# If we are bootstrapping file2c, we have to build it before config:
2286${_bt}-usr.sbin/config: ${_bt}-usr.bin/file2c ${_bt_lex_depend}
2287# Note: no symlink to make/bmake in the !BOOTSTRAP_ALL_TOOLS case here since
2288# the links to make/bmake make links will have already have been created in the
2289# `make legacy` step. Not adding a link to make is important on non-FreeBSD
2290# since "make" will usually point to GNU make there.
2291_other_bootstrap_tools+=usr.bin/bmake
2292.else
2293# All tools in _basic_bootstrap_tools have the same name as the subdirectory
2294# so we can use :T to get the name of the symlinks that we need to create.
2295_bootstrap_tools_links+=${_basic_bootstrap_tools:T}
2296.for _subdir _links in ${_basic_bootstrap_tools_multilink}
2297_bootstrap_tools_links+=${_links:S/,/ /g}
2298.endfor
2299.endif	# defined(BOOTSTRAP_ALL_TOOLS)
2300
2301# Link the tools that we need for building but don't need to bootstrap because
2302# the host version is known to be compatible into ${WORLDTMP}/legacy
2303# We do this before building any of the bootstrap tools in case they depend on
2304# the presence of any of the links (e.g. as m4/lex/awk)
2305${_bt}-links: .PHONY
2306
2307.for _tool in ${_bootstrap_tools_links}
2308${_bt}-link-${_tool}: .PHONY .MAKE
2309	@rm -f "${WORLDTMP}/legacy/bin/${_tool}"; \
2310	source_path=`which ${_tool}`; \
2311	if [ ! -e "$${source_path}" ] ; then \
2312		echo "Cannot find host tool '${_tool}'"; false; \
2313	fi; \
2314	cp -f "$${source_path}" "${WORLDTMP}/legacy/bin/${_tool}"
2315${_bt}-links: ${_bt}-link-${_tool}
2316.endfor
2317
2318bootstrap-tools: ${_bt}-links .PHONY
2319
2320#	Please document (add comment) why something is in 'bootstrap-tools'.
2321#	Try to bound the building of the bootstrap-tool to just the
2322#	FreeBSD versions that need the tool built at this stage of the build.
2323.for _tool in \
2324    ${_clang_tblgen} \
2325    ${_kerberos5_bootstrap_tools} \
2326    ${_strfile} \
2327    usr.bin/dtc \
2328    ${_cat} \
2329    ${_kbdcontrol} \
2330    ${_elftoolchain_libs} \
2331    usr.bin/lorder \
2332    lib/libopenbsd \
2333    usr.bin/mandoc \
2334    usr.bin/rpcgen \
2335    ${_yacc} \
2336    ${_m4} \
2337    ${_lex} \
2338    ${_other_bootstrap_tools} \
2339    usr.bin/xinstall \
2340    ${_gensnmptree} \
2341    usr.sbin/config \
2342    ${_flua} \
2343    ${_crunchide} \
2344    ${_crunchgen} \
2345    ${_nmtree} \
2346    ${_vtfontcvt} \
2347    ${_localedef}
2348${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
2349	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2350		cd ${.CURDIR}/${_tool}; \
2351		if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2352		if [ "${_tool}" = "usr.bin/lex" ]; then \
2353			${MAKE} DIRPRFX=${_tool}/ bootstrap; \
2354		fi; \
2355		${MAKE} DIRPRFX=${_tool}/ all; \
2356		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy install
2357
2358bootstrap-tools: ${_bt}-${_tool}
2359.endfor
2360
2361#
2362# build-tools: Build special purpose build tools
2363#
2364.if !defined(NO_SHARE) && ${MK_SYSCONS} != "no"
2365_share=	share/syscons/scrnmaps
2366.endif
2367
2368.if ${MK_RESCUE} != "no"
2369# rescue includes programs that have build-tools targets
2370_rescue=rescue/rescue
2371.endif
2372
2373.if ${MK_TCSH} != "no"
2374_tcsh=bin/csh
2375.endif
2376.if ${MK_FILE} != "no"
2377_libmagic=lib/libmagic
2378.endif
2379
2380.if ${MK_PMC} != "no" && \
2381    (${TARGET_ARCH} == "aarch64" || ${TARGET_ARCH} == "amd64" || \
2382    ${TARGET_ARCH} == "i386")
2383_jevents=lib/libpmc/pmu-events
2384.endif
2385
2386# kernel-toolchain skips _cleanobj, so handle cleaning up previous
2387# build-tools directories if needed.
2388.if !defined(NO_CLEAN) && make(kernel-toolchain)
2389_bt_clean=	${CLEANDIR}
2390.endif
2391
2392.for _tool in \
2393    ${_tcsh} \
2394    bin/sh \
2395    ${LOCAL_TOOL_DIRS} \
2396    ${_jevents} \
2397    lib/ncurses/ncurses \
2398    lib/ncurses/ncursesw \
2399    ${_rescue} \
2400    ${_share} \
2401    usr.bin/awk \
2402    ${_libmagic} \
2403    usr.bin/mkesdb_static \
2404    usr.bin/mkcsmapper_static \
2405    usr.bin/vi/catalog
2406build-tools_${_tool}: .PHONY
2407	${_+_}@${ECHODIR} "===> ${_tool} (${_bt_clean:D${_bt_clean},}obj,build-tools)"; \
2408		cd ${.CURDIR}/${_tool}; \
2409		if [ -n "${_bt_clean}" ]; then ${MAKE} DIRPRFX=${_tool}/ ${_bt_clean}; fi; \
2410		if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2411		${MAKE} DIRPRFX=${_tool}/ build-tools
2412build-tools: build-tools_${_tool}
2413.endfor
2414
2415#
2416# kernel-tools: Build kernel-building tools
2417#
2418kernel-tools: .PHONY
2419	mkdir -p ${WORLDTMP}/usr
2420	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2421	    -p ${WORLDTMP}/usr >/dev/null
2422
2423#
2424# cross-tools: All the tools needed to build the rest of the system after
2425# we get done with the earlier stages. It is the last set of tools needed
2426# to begin building the target binaries.
2427#
2428.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BUILD_WITH_STRICT_TMPPATH} != 0
2429.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
2430_btxld=		usr.sbin/btxld
2431.endif
2432.endif
2433
2434# Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
2435# resulting from missing bug fixes or ELF Toolchain updates.
2436.if ${MK_CDDL} != "no"
2437_dtrace_tools= cddl/lib/libctf cddl/usr.bin/ctfconvert \
2438    cddl/usr.bin/ctfmerge
2439.endif
2440
2441# If we're given an XAS, don't build binutils.
2442.if ${XAS:M/*} == ""
2443.if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2444_elftctools=	lib/libelftc \
2445		lib/libpe \
2446		usr.bin/objcopy \
2447		usr.bin/nm \
2448		usr.bin/size \
2449		usr.bin/strings
2450# These are not required by the build, but can be useful for developers who
2451# cross-build on a FreeBSD 10 host:
2452_elftctools+=	usr.bin/addr2line
2453.endif
2454.elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2455# If cross-building with an external binutils we still need to build strip for
2456# the target (for at least crunchide).
2457_elftctools=	lib/libelftc \
2458		lib/libpe \
2459		usr.bin/objcopy
2460.endif
2461
2462.if ${MK_CLANG_BOOTSTRAP} != "no"
2463_clang=		usr.bin/clang
2464.endif
2465.if ${MK_LLD_BOOTSTRAP} != "no"
2466_lld=		usr.bin/clang/lld
2467.endif
2468.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
2469_clang_libs=	lib/clang
2470.endif
2471.if ${MK_USB} != "no"
2472_usb_tools=	stand/usb/tools
2473.endif
2474
2475.if ${BUILD_WITH_STRICT_TMPPATH} != 0 || defined(BOOTSTRAP_ALL_TOOLS)
2476_ar=usr.bin/ar
2477.endif
2478
2479cross-tools: .MAKE .PHONY
2480.for _tool in \
2481    ${LOCAL_XTOOL_DIRS} \
2482    ${_ar} \
2483    ${_clang_libs} \
2484    ${_clang} \
2485    ${_lld} \
2486    ${_elftctools} \
2487    ${_dtrace_tools} \
2488    ${_btxld} \
2489    ${_usb_tools}
2490	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2491		cd ${.CURDIR}/${_tool}; \
2492		if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2493		${MAKE} DIRPRFX=${_tool}/ all; \
2494		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP} install
2495.endfor
2496
2497#
2498# native-xtools is the current target for qemu-user cross builds of ports
2499# via poudriere and the imgact_binmisc kernel module.
2500# This target merely builds a toolchan/sysroot, then builds the tools it wants
2501# with the options it wants in a special MAKEOBJDIRPREFIX, using the toolchain
2502# already built.  It then installs the static tools to NXBDESTDIR for Poudriere
2503# to pickup.
2504#
2505NXBOBJROOT=	${OBJROOT}${MACHINE}.${MACHINE_ARCH}/nxb/
2506NXBOBJTOP=	${NXBOBJROOT}${NXB_TARGET}.${NXB_TARGET_ARCH}
2507NXTP?=		/nxb-bin
2508.if ${NXTP:N/*}
2509.error NXTP variable should be an absolute path
2510.endif
2511NXBDESTDIR?=	${DESTDIR}${NXTP}
2512
2513# This is the list of tools to be built/installed as static and where
2514# appropriate to build for the given TARGET.TARGET_ARCH.
2515NXBDIRS+= \
2516    bin/cat \
2517    bin/chmod \
2518    bin/cp \
2519    ${_tcsh} \
2520    bin/echo \
2521    bin/expr \
2522    bin/hostname \
2523    bin/ln \
2524    bin/ls \
2525    bin/mkdir \
2526    bin/mv \
2527    bin/ps \
2528    bin/realpath \
2529    bin/rm \
2530    bin/rmdir \
2531    bin/sh \
2532    bin/sleep \
2533    sbin/md5 \
2534    sbin/sysctl \
2535    usr.bin/addr2line \
2536    usr.bin/ar \
2537    usr.bin/awk \
2538    usr.bin/basename \
2539    usr.bin/bmake \
2540    usr.bin/bzip2 \
2541    usr.bin/cmp \
2542    usr.bin/diff \
2543    usr.bin/dirname \
2544    usr.bin/objcopy \
2545    usr.bin/env \
2546    usr.bin/fetch \
2547    usr.bin/find \
2548    usr.bin/grep \
2549    usr.bin/gzip \
2550    usr.bin/head \
2551    usr.bin/id \
2552    usr.bin/lex \
2553    usr.bin/limits \
2554    usr.bin/lorder \
2555    usr.bin/mandoc \
2556    usr.bin/mktemp \
2557    usr.bin/mt \
2558    usr.bin/nm \
2559    usr.bin/patch \
2560    usr.bin/readelf \
2561    usr.bin/sed \
2562    usr.bin/size \
2563    usr.bin/sort \
2564    usr.bin/strings \
2565    usr.bin/tar \
2566    usr.bin/touch \
2567    usr.bin/tr \
2568    usr.bin/true \
2569    usr.bin/uniq \
2570    usr.bin/unzip \
2571    usr.bin/wc \
2572    usr.bin/xargs \
2573    usr.bin/xinstall \
2574    usr.bin/xz \
2575    usr.bin/yacc \
2576    usr.sbin/chown
2577
2578SUBDIR_DEPEND_usr.bin/clang=	lib/clang
2579.if ${MK_CLANG} != "no"
2580NXBDIRS+=	lib/clang
2581NXBDIRS+=	usr.bin/clang
2582.endif
2583# XXX: native-xtools passes along ${NXBDIRS} in SUBDIR_OVERRIDE that needs
2584# to be evaluated after NXBDIRS is set.
2585.if make(install) && !empty(SUBDIR_OVERRIDE)
2586SUBDIR=	${SUBDIR_OVERRIDE}
2587.endif
2588
2589NXBMAKEARGS+= \
2590	OBJTOP=${NXBOBJTOP:Q} \
2591	OBJROOT=${NXBOBJROOT:Q} \
2592	MAKEOBJDIRPREFIX= \
2593	-DNO_SHARED \
2594	-DNO_CPU_CFLAGS \
2595	-DNO_PIC \
2596	SSP_CFLAGS= \
2597	MK_CASPER=no \
2598	MK_CLANG_EXTRAS=no \
2599	MK_CLANG_FORMAT=no \
2600	MK_CLANG_FULL=no \
2601	MK_CTF=no \
2602	MK_DEBUG_FILES=no \
2603	MK_GDB=no \
2604	MK_HTML=no \
2605	MK_LLDB=no \
2606	MK_MAN=no \
2607	MK_MAN_UTILS=yes \
2608	MK_OFED=no \
2609	MK_OPENSSH=no \
2610	MK_PROFILE=no \
2611	MK_RETPOLINE=no \
2612	MK_SENDMAIL=no \
2613	MK_SVNLITE=no \
2614	MK_TESTS=no \
2615	MK_WARNS=no \
2616	MK_ZFS=no
2617
2618.if make(native-xtools*) && \
2619    (!defined(NXB_TARGET) || !defined(NXB_TARGET_ARCH))
2620.error Missing NXB_TARGET / NXB_TARGET_ARCH
2621.endif
2622# For 'toolchain' we want to produce native binaries that themselves generate
2623# native binaries.
2624NXBTMAKE=	${NXBMAKEENV} ${MAKE} ${NXBMAKEARGS:N-DNO_PIC:N-DNO_SHARED} \
2625		TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH}
2626# For 'everything' we want to produce native binaries (hence -target to
2627# be MACHINE) that themselves generate TARGET.TARGET_ARCH binaries.
2628# TARGET/TARGET_ARCH are still passed along from user.
2629#
2630# Use the toolchain we create as an external toolchain.
2631.if ${USING_SYSTEM_COMPILER} == "yes" || ${XCC:N${CCACHE_BIN}:M/*}
2632NXBMAKE+=	XCC="${XCC}" \
2633		XCXX="${XCXX}" \
2634		XCPP="${XCPP}"
2635.else
2636NXBMAKE+=	XCC="${NXBOBJTOP}/tmp/usr/bin/cc" \
2637		XCXX="${NXBOBJTOP}/tmp/usr/bin/c++" \
2638		XCPP="${NXBOBJTOP}/tmp/usr/bin/cpp"
2639.endif
2640NXBMAKE+=	${NXBMAKEENV} ${MAKE} -f Makefile.inc1 ${NXBMAKEARGS} \
2641		MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
2642		TARGET=${NXB_TARGET} TARGET_ARCH=${NXB_TARGET_ARCH} \
2643		TARGET_TRIPLE=${MACHINE_TRIPLE:Q}
2644# NXBDIRS is improperly based on MACHINE rather than NXB_TARGET.  Need to
2645# invoke a sub-make to reevaluate MK_CLANG, etc, for NXBDIRS.
2646NXBMAKE+=	SUBDIR_OVERRIDE='$${NXBDIRS:M*}'
2647# Need to avoid the -isystem logic when using clang as an external toolchain
2648# even if the TARGET being built for wants GCC.
2649NXBMAKE+=	WANT_COMPILER_TYPE='$${X_COMPILER_TYPE}'
2650native-xtools: .PHONY
2651	${_+_}cd ${.CURDIR}; ${NXBTMAKE} _cleanobj
2652	# Build the bootstrap/host/cross tools that produce native binaries
2653	${_+_}cd ${.CURDIR}; ${NXBTMAKE} kernel-toolchain
2654	# Populate includes/libraries sysroot that produce native binaries.
2655	# This is split out from 'toolchain' above mostly so that target LLVM
2656	# libraries have a proper LLVM_DEFAULT_TARGET_TRIPLE without
2657	# polluting the cross-compiler build.  The LLVM/GCC libs are skipped
2658	# here to avoid the problem but are kept in 'toolchain' so that
2659	# needed build tools are built.
2660	${_+_}cd ${.CURDIR}; ${NXBTMAKE} _includes MK_CLANG=no
2661	${_+_}cd ${.CURDIR}; ${NXBTMAKE} _libraries MK_CLANG=no
2662.if !defined(NO_OBJWALK)
2663	${_+_}cd ${.CURDIR}; ${NXBMAKE} _obj
2664.endif
2665	${_+_}cd ${.CURDIR}; ${NXBMAKE} everything
2666	@echo ">> native-xtools done.  Use 'make native-xtools-install' to install to a given DESTDIR"
2667
2668native-xtools-install: .PHONY
2669	mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
2670	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2671	    -p ${NXBDESTDIR}/usr >/dev/null
2672	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2673	    -p ${NXBDESTDIR}/usr/include >/dev/null
2674	${_+_}cd ${.CURDIR}; ${NXBMAKE} \
2675	    DESTDIR=${NXBDESTDIR} \
2676	    -DNO_ROOT \
2677	    install
2678
2679#
2680# hierarchy - ensure that all the needed directories are present
2681#
2682hierarchy hier: .MAKE .PHONY
2683	${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
2684
2685#
2686# libraries - build all libraries, and install them under ${DESTDIR}.
2687#
2688# The list of libraries with dependents (${_prebuild_libs}) and their
2689# interdependencies (__L) are built automatically by the
2690# ${.CURDIR}/tools/make_libdeps.sh script.
2691#
2692libraries: .MAKE .PHONY
2693	${_+_}cd ${.CURDIR}; \
2694	    ${MAKE} -f Makefile.inc1 _prereq_libs; \
2695	    ${MAKE} -f Makefile.inc1 _startup_libs; \
2696	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
2697	    ${MAKE} -f Makefile.inc1 _generic_libs
2698
2699#
2700# static libgcc.a prerequisite for shared libc
2701#
2702_prereq_libs= lib/libcompiler_rt
2703.if ${MK_SSP} != "no"
2704_prereq_libs+= lib/libssp_nonshared
2705.endif
2706
2707# These dependencies are not automatically generated:
2708#
2709# lib/csu and lib/libc must be built before
2710# all shared libraries for ELF.
2711#
2712_startup_libs=	lib/csu
2713_startup_libs+=	lib/libc
2714_startup_libs+=	lib/libc_nonshared
2715.if ${MK_LIBCPLUSPLUS} != "no"
2716_startup_libs+=	lib/libcxxrt
2717.endif
2718
2719_prereq_libs+=	lib/libgcc_eh lib/libgcc_s
2720_startup_libs+=	lib/libgcc_eh lib/libgcc_s
2721
2722lib/libgcc_s__L: lib/libc__L
2723lib/libgcc_s__L: lib/libc_nonshared__L
2724.if ${MK_LIBCPLUSPLUS} != "no"
2725lib/libcxxrt__L: lib/libgcc_s__L
2726.endif
2727
2728_prebuild_libs=	${_kerberos5_lib_libasn1} \
2729		${_kerberos5_lib_libhdb} \
2730		${_kerberos5_lib_libheimbase} \
2731		${_kerberos5_lib_libheimntlm} \
2732		${_libsqlite3} \
2733		${_kerberos5_lib_libheimipcc} \
2734		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
2735		${_kerberos5_lib_libroken} \
2736		${_kerberos5_lib_libwind} \
2737		lib/libbz2 ${_libcom_err} lib/libcrypt \
2738		lib/libelf lib/libexpat \
2739		lib/libfigpar \
2740		${_lib_libgssapi} \
2741		lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
2742		lib/libzstd \
2743		${_lib_casper} \
2744		lib/ncurses/ncurses lib/ncurses/ncursesw \
2745		lib/libopie lib/libpam/libpam ${_lib_libthr} \
2746		${_lib_libradius} lib/libsbuf lib/libtacplus \
2747		lib/libgeom \
2748		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
2749		${_cddl_lib_libuutil} \
2750		${_cddl_lib_libavl} \
2751		${_cddl_lib_libzfs_core} ${_cddl_lib_libzfs} \
2752		${_cddl_lib_libctf} \
2753		lib/libufs \
2754		lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
2755		${_secure_lib_libcrypto} ${_secure_lib_libssl} \
2756		${_lib_libldns} ${_secure_lib_libssh}
2757
2758.if ${MK_DIALOG} != "no"
2759_prebuild_libs+= gnu/lib/libdialog
2760gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
2761.endif
2762
2763.if ${MK_GOOGLETEST} != "no"
2764_prebuild_libs+= lib/libregex
2765.endif
2766
2767.if ${MK_LIBCPLUSPLUS} != "no"
2768_prebuild_libs+= lib/libc++
2769.endif
2770
2771lib/libgeom__L: lib/libexpat__L lib/libsbuf__L
2772lib/libkvm__L: lib/libelf__L
2773
2774.if ${MK_LIBTHR} != "no"
2775_lib_libthr=	lib/libthr
2776.endif
2777
2778.if ${MK_RADIUS_SUPPORT} != "no"
2779_lib_libradius=	lib/libradius
2780.endif
2781
2782.if ${MK_OFED} != "no"
2783_prebuild_libs+= \
2784	lib/ofed/libibverbs \
2785	lib/ofed/libibmad \
2786	lib/ofed/libibumad \
2787	lib/ofed/complib \
2788	lib/ofed/libmlx5
2789
2790lib/ofed/libibmad__L:	lib/ofed/libibumad__L
2791lib/ofed/complib__L:	lib/libthr__L
2792lib/ofed/libmlx5__L:	lib/ofed/libibverbs__L lib/libthr__L
2793.endif
2794
2795.if ${MK_CASPER} != "no"
2796_lib_casper=	lib/libcasper
2797.endif
2798
2799lib/libpjdlog__L: lib/libutil__L
2800lib/libcasper__L: lib/libnv__L
2801lib/liblzma__L: lib/libmd__L lib/libthr__L
2802lib/libzstd__L: lib/libthr__L
2803
2804_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib}
2805.if ${MK_IPFILTER} != "no"
2806_generic_libs+=	sbin/ipf/libipf
2807.endif
2808.for _DIR in ${LOCAL_LIB_DIRS}
2809.if ${_DIR} == ".WAIT"  || (empty(_generic_libs:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
2810_generic_libs+= ${_DIR}
2811.endif
2812.endfor
2813
2814lib/libopie__L lib/libtacplus__L: lib/libmd__L
2815
2816.if ${MK_CDDL} != "no"
2817_cddl_lib_libumem= cddl/lib/libumem
2818_cddl_lib_libnvpair= cddl/lib/libnvpair
2819_cddl_lib_libavl= cddl/lib/libavl
2820_cddl_lib_libuutil= cddl/lib/libuutil
2821.if ${MK_ZFS} != "no"
2822_cddl_lib_libzfs_core= cddl/lib/libzfs_core
2823_cddl_lib_libzfs= cddl/lib/libzfs
2824
2825cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
2826
2827cddl/lib/libzfs__L: cddl/lib/libzfs_core__L lib/msun__L lib/libutil__L
2828cddl/lib/libzfs__L: lib/libthr__L lib/libmd__L lib/libz__L cddl/lib/libumem__L
2829cddl/lib/libzfs__L: cddl/lib/libuutil__L cddl/lib/libavl__L lib/libgeom__L
2830
2831lib/libbe__L: cddl/lib/libzfs__L
2832.endif
2833_cddl_lib_libctf= cddl/lib/libctf
2834_cddl_lib= cddl/lib
2835cddl/lib/libctf__L: lib/libz__L
2836.endif
2837# cddl/lib/libdtrace requires lib/libproc and lib/librtld_db
2838_prebuild_libs+=	lib/libprocstat lib/libproc lib/librtld_db
2839lib/libprocstat__L: lib/libelf__L lib/libkvm__L lib/libutil__L
2840lib/libproc__L: lib/libprocstat__L
2841lib/librtld_db__L: lib/libprocstat__L
2842
2843.if ${MK_CRYPT} != "no"
2844.if ${MK_OPENSSL} != "no"
2845_secure_lib_libcrypto= secure/lib/libcrypto
2846_secure_lib_libssl= secure/lib/libssl
2847lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
2848secure/lib/libcrypto__L: lib/libthr__L
2849.if ${MK_LDNS} != "no"
2850_lib_libldns= lib/libldns
2851lib/libldns__L: secure/lib/libssl__L
2852.endif
2853.if ${MK_OPENSSH} != "no"
2854_secure_lib_libssh= secure/lib/libssh
2855secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
2856.if ${MK_LDNS} != "no"
2857secure/lib/libssh__L: lib/libldns__L
2858.endif
2859.if ${MK_GSSAPI} != "no" && ${MK_KERBEROS_SUPPORT} != "no"
2860secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
2861    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
2862    lib/libmd__L kerberos5/lib/libroken__L
2863.endif
2864.endif
2865.endif
2866_secure_lib=	secure/lib
2867.endif
2868
2869.if ${MK_KERBEROS} != "no"
2870kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
2871kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2872    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
2873    kerberos5/lib/libwind__L lib/libsqlite3__L
2874kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
2875    kerberos5/lib/libroken__L lib/libcom_err__L
2876kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2877    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
2878kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2879    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
2880    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
2881    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
2882kerberos5/lib/libroken__L: lib/libcrypt__L
2883kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
2884kerberos5/lib/libheimbase__L: lib/libthr__L
2885kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
2886.endif
2887
2888lib/libsqlite3__L: lib/libthr__L
2889
2890.if ${MK_GSSAPI} != "no"
2891_lib_libgssapi=	lib/libgssapi
2892.endif
2893
2894.if ${MK_KERBEROS} != "no"
2895_kerberos5_lib=	kerberos5/lib
2896_kerberos5_lib_libasn1= kerberos5/lib/libasn1
2897_kerberos5_lib_libhdb= kerberos5/lib/libhdb
2898_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
2899_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
2900_kerberos5_lib_libhx509= kerberos5/lib/libhx509
2901_kerberos5_lib_libroken= kerberos5/lib/libroken
2902_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
2903_libsqlite3= lib/libsqlite3
2904_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
2905_kerberos5_lib_libwind= kerberos5/lib/libwind
2906_libcom_err= lib/libcom_err
2907.endif
2908
2909.if ${MK_NIS} != "no"
2910_lib_libypclnt=	lib/libypclnt
2911.endif
2912
2913.if ${MK_OPENSSL} == "no"
2914lib/libradius__L: lib/libmd__L
2915.endif
2916
2917lib/libproc__L: \
2918    ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
2919.if ${MK_CXX} != "no" && ${MK_LIBCPLUSPLUS} != "no"
2920lib/libproc__L: lib/libcxxrt__L
2921.endif
2922
2923.for _lib in ${_prereq_libs}
2924${_lib}__PL: .PHONY .MAKE
2925.if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
2926	${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
2927		cd ${.CURDIR}/${_lib}; \
2928		if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
2929		${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
2930		    DIRPRFX=${_lib}/ all; \
2931		${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
2932		    DIRPRFX=${_lib}/ install
2933.endif
2934.endfor
2935
2936.for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
2937${_lib}__L: .PHONY .MAKE
2938.if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
2939	${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
2940		cd ${.CURDIR}/${_lib}; \
2941		if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
2942		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
2943		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
2944.endif
2945.endfor
2946
2947_prereq_libs: ${_prereq_libs:S/$/__PL/}
2948_startup_libs: ${_startup_libs:S/$/__L/}
2949_prebuild_libs: ${_prebuild_libs:S/$/__L/}
2950_generic_libs: ${_generic_libs:S/$/__L/}
2951
2952# Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
2953# 'everything' with _PARALLEL_SUBDIR_OK set.  This is because it is unlikely
2954# that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
2955# or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
2956# parallel.  This is safe for the world stage of buildworld though since it has
2957# already built libraries in a proper order and installed includes into
2958# WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
2959# avoid trashing a system if it crashes mid-install.
2960.if !make(all) || defined(_PARALLEL_SUBDIR_OK)
2961SUBDIR_PARALLEL=
2962.endif
2963
2964.include <bsd.subdir.mk>
2965
2966.if make(check-old) || make(check-old-dirs) || \
2967    make(check-old-files) || make(check-old-libs) || \
2968    make(delete-old) || make(delete-old-dirs) || \
2969    make(delete-old-files) || make(delete-old-libs)
2970
2971#
2972# check for / delete old files section
2973#
2974
2975.include "ObsoleteFiles.inc"
2976
2977OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
2978else you can not start such an application. Consult UPDATING for more \
2979information regarding how to cope with the removal/revision bump of a \
2980specific library."
2981
2982.if !defined(BATCH_DELETE_OLD_FILES)
2983RM_I=-i
2984.else
2985RM_I=-v
2986.endif
2987
2988delete-old-files: .PHONY
2989	@echo ">>> Removing old files (only deletes safe to delete libs)"
2990# Ask for every old file if the user really wants to remove it.
2991# It's annoying, but better safe than sorry.
2992# NB: We cannot pass the list of OLD_FILES as a parameter because the
2993# argument list will get too long. Using .for/.endfor make "loops" will make
2994# the Makefile parser segfault.
2995	@exec 3<&0; \
2996	cd ${.CURDIR}; \
2997	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2998	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | sort | \
2999	while read file; do \
3000		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3001			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3002			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3003		fi; \
3004		for ext in debug symbols; do \
3005		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3006		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3007			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3008			      <&3; \
3009		  fi; \
3010		done; \
3011	done
3012# Remove catpages without corresponding manpages.
3013	@exec 3<&0; \
3014	find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | sort | \
3015	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3016	while read catpage; do \
3017		read manpage; \
3018		if [ ! -e "$${manpage}" ]; then \
3019			rm ${RM_I} $${catpage} <&3; \
3020	        fi; \
3021	done
3022	@echo ">>> Old files removed"
3023
3024check-old-files: .PHONY
3025	@echo ">>> Checking for old files"
3026	@cd ${.CURDIR}; \
3027	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3028	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
3029	while read file; do \
3030		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3031		 	echo "${DESTDIR}/$${file}"; \
3032		fi; \
3033		for ext in debug symbols; do \
3034		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3035			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3036		  fi; \
3037		done; \
3038	done | sort
3039# Check for catpages without corresponding manpages.
3040	@find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | \
3041	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3042	while read catpage; do \
3043		read manpage; \
3044		if [ ! -e "$${manpage}" ]; then \
3045			echo $${catpage}; \
3046	        fi; \
3047	done | sort
3048
3049delete-old-libs: .PHONY
3050	@echo ">>> Removing old libraries"
3051	@echo "${OLD_LIBS_MESSAGE}" | fmt
3052	@exec 3<&0; \
3053	cd ${.CURDIR}; \
3054	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3055	    -V OLD_LIBS | xargs -n1 | sort | \
3056	while read file; do \
3057		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3058			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3059			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3060		fi; \
3061		for ext in debug symbols; do \
3062		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3063		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3064			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3065			      <&3; \
3066		  fi; \
3067		done; \
3068	done
3069	@echo ">>> Old libraries removed"
3070
3071check-old-libs: .PHONY
3072	@echo ">>> Checking for old libraries"
3073	@cd ${.CURDIR}; \
3074	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3075	    -V OLD_LIBS | xargs -n1 | \
3076	while read file; do \
3077		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3078			echo "${DESTDIR}/$${file}"; \
3079		fi; \
3080		for ext in debug symbols; do \
3081		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3082			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3083		  fi; \
3084		done; \
3085	done | sort
3086
3087delete-old-dirs: .PHONY
3088	@echo ">>> Removing old directories"
3089	@cd ${.CURDIR}; \
3090	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3091	    -V OLD_DIRS | xargs -n1 | sort -r | \
3092	while read dir; do \
3093		if [ -d "${DESTDIR}/$${dir}" ]; then \
3094			rmdir -v "${DESTDIR}/$${dir}" || true; \
3095		elif [ -L "${DESTDIR}/$${dir}" ]; then \
3096			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3097		fi; \
3098		if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3099			rmdir -v "${DESTDIR}${DEBUGDIR}/$${dir}" || true; \
3100		elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3101			echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3102		fi; \
3103	done
3104	@echo ">>> Old directories removed"
3105
3106check-old-dirs: .PHONY
3107	@echo ">>> Checking for old directories"
3108	@cd ${.CURDIR}; \
3109	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3110	    -V OLD_DIRS | xargs -n1 | sort -r | \
3111	while read dir; do \
3112		if [ -d "${DESTDIR}/$${dir}" ]; then \
3113			echo "${DESTDIR}/$${dir}"; \
3114		elif [ -L "${DESTDIR}/$${dir}" ]; then \
3115			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3116		fi; \
3117		if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3118			echo "${DESTDIR}${DEBUGDIR}/$${dir}"; \
3119		elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3120			echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3121		fi; \
3122	done
3123
3124delete-old: delete-old-files delete-old-dirs .PHONY
3125	@echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3126
3127check-old: check-old-files check-old-libs check-old-dirs .PHONY
3128	@echo "To remove old files and directories run '${MAKE_CMD} delete-old'."
3129	@echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3130
3131.endif
3132
3133#
3134# showconfig - show build configuration.
3135#
3136showconfig: .PHONY
3137	@(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes; \
3138	  ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes) 2>&1 | grep ^MK_ | sort -u
3139
3140.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
3141DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
3142
3143.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
3144.if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${KERNCONF})
3145FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
3146	'${KERNCONFDIR}/${KERNCONF}' ; echo
3147.endif
3148.endif
3149
3150.endif
3151
3152.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
3153DTBOUTPUTPATH= ${.CURDIR}
3154.endif
3155
3156#
3157# Build 'standalone' Device Tree Blob
3158#
3159builddtb: .PHONY
3160	@PATH=${TMPPATH} MACHINE=${TARGET} \
3161	${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
3162	    "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
3163
3164###############
3165
3166# cleanworld
3167# In the following, the first 'rm' in a series will usually remove all
3168# files and directories.  If it does not, then there are probably some
3169# files with file flags set, so this unsets them and tries the 'rm' a
3170# second time.  There are situations where this target will be cleaning
3171# some directories via more than one method, but that duplication is
3172# needed to correctly handle all the possible situations.  Removing all
3173# files without file flags set in the first 'rm' instance saves time,
3174# because 'chflags' will need to operate on fewer files afterwards.
3175#
3176# It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
3177# created by bsd.obj.mk, except that we don't want to .include that file
3178# in this makefile.  We don't do a cleandir walk if MK_AUTO_OBJ is yes
3179# since it is not possible for files to land in the wrong place.
3180#
3181.if make(cleanworld)
3182BW_CANONICALOBJDIR:=${OBJTOP}/
3183.elif make(cleanuniverse)
3184BW_CANONICALOBJDIR:=${OBJROOT}
3185.if ${MK_UNIFIED_OBJDIR} == "no"
3186.error ${.TARGETS} only supported with WITH_UNIFIED_OBJDIR enabled.
3187.endif
3188.endif
3189cleanworld cleanuniverse: .PHONY
3190.if !empty(BW_CANONICALOBJDIR) && exists(${BW_CANONICALOBJDIR}) && \
3191    ${.CURDIR:tA} != ${BW_CANONICALOBJDIR:tA}
3192	-rm -rf ${BW_CANONICALOBJDIR}*
3193	-chflags -R 0 ${BW_CANONICALOBJDIR}
3194	rm -rf ${BW_CANONICALOBJDIR}*
3195.endif
3196.if make(cleanworld) && ${MK_AUTO_OBJ} == "no" && \
3197    (empty(BW_CANONICALOBJDIR) || ${.CURDIR:tA} == ${BW_CANONICALOBJDIR:tA})
3198.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
3199	#   To be safe in this case, fall back to a 'make cleandir'
3200	${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
3201.endif
3202.endif
3203
3204.if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
3205XDEV_CPUTYPE?=${CPUTYPE}
3206.else
3207XDEV_CPUTYPE?=${TARGET_CPUTYPE}
3208.endif
3209
3210NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
3211	MK_MAN=no MK_NLS=no MK_PROFILE=no \
3212	MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
3213	TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
3214	CPUTYPE=${XDEV_CPUTYPE}
3215
3216XDDIR=${TARGET_ARCH}-freebsd
3217XDTP?=/usr/${XDDIR}
3218.if ${XDTP:N/*}
3219.error XDTP variable should be an absolute path
3220.endif
3221
3222CDBOBJROOT=	${OBJROOT}${MACHINE}.${MACHINE_ARCH}/xdev/
3223CDBOBJTOP=	${CDBOBJROOT}${XDDIR}
3224CDBENV= \
3225	INSTALL="sh ${.CURDIR}/tools/install.sh"
3226CDENV= ${CDBENV} \
3227	TOOLS_PREFIX=${XDTP}
3228CDMAKEARGS= \
3229	OBJTOP=${CDBOBJTOP:Q} \
3230	OBJROOT=${CDBOBJROOT:Q}
3231CD2MAKEARGS= ${CDMAKEARGS}
3232
3233.if ${WANT_COMPILER_TYPE} == gcc || \
3234    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
3235# GCC requires -isystem and -L when using a cross-compiler.  --sysroot
3236# won't set header path and -L is used to ensure the base library path
3237# is added before the port PREFIX library path.
3238CD2CFLAGS+=	-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib
3239# GCC requires -B to find /usr/lib/crti.o when using a cross-compiler
3240# combined with --sysroot.
3241CD2CFLAGS+=	-B${XDDESTDIR}/usr/lib
3242# Force using libc++ for external GCC.
3243.if defined(X_COMPILER_TYPE) && \
3244    ${X_COMPILER_TYPE} == gcc && ${X_COMPILER_VERSION} >= 40800
3245CD2CXXFLAGS+=	-isystem ${XDDESTDIR}/usr/include/c++/v1 -std=c++11 \
3246		-nostdinc++
3247.endif
3248.endif
3249CD2CFLAGS+=	--sysroot=${XDDESTDIR}/
3250CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CXXFLAGS} ${CD2CFLAGS}" \
3251	CPP="${CPP} ${CD2CFLAGS}" \
3252	MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
3253
3254CDTMP=	${OBJTOP}/${XDDIR}/tmp
3255CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${CDMAKEARGS} ${NOFUN}
3256CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} \
3257	${MAKE} ${CD2MAKEARGS} ${NOFUN}
3258.if ${MK_META_MODE} != "no"
3259# Don't rebuild build-tools targets during normal build.
3260CD2MAKE+=	BUILD_TOOLS_META=.NOMETA
3261.endif
3262XDDESTDIR=${DESTDIR}${XDTP}
3263
3264.ORDER: xdev-build xdev-install xdev-links
3265xdev: xdev-build xdev-install .PHONY
3266
3267.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
3268xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY
3269
3270_xb-worldtmp: .PHONY
3271	mkdir -p ${CDTMP}/usr
3272	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3273	    -p ${CDTMP}/usr >/dev/null
3274
3275_xb-bootstrap-tools: .PHONY
3276.for _tool in \
3277    ${_clang_tblgen} \
3278    ${_yacc}
3279	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
3280	cd ${.CURDIR}/${_tool}; \
3281	if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3282	${CDMAKE} DIRPRFX=${_tool}/ all; \
3283	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
3284.endfor
3285
3286_xb-build-tools: .PHONY
3287	${_+_}@cd ${.CURDIR}; \
3288	${CDBENV} ${MAKE} ${CDMAKEARGS} -f Makefile.inc1 ${NOFUN} build-tools
3289
3290XDEVDIRS= \
3291    ${_clang_libs} \
3292    ${_lld} \
3293    ${_elftctools} \
3294    usr.bin/ar \
3295    ${_clang}
3296
3297_xb-cross-tools: .PHONY
3298.for _tool in ${XDEVDIRS}
3299	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \
3300	cd ${.CURDIR}/${_tool}; \
3301	if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3302	${CDMAKE} DIRPRFX=${_tool}/ all
3303.endfor
3304
3305_xi-mtree: .PHONY
3306	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
3307	mkdir -p ${XDDESTDIR}
3308	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
3309	    -p ${XDDESTDIR} >/dev/null
3310	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3311	    -p ${XDDESTDIR}/usr >/dev/null
3312	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
3313	    -p ${XDDESTDIR}/usr/include >/dev/null
3314.if defined(_LIBCOMPAT)
3315	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
3316	    -p ${XDDESTDIR}/usr >/dev/null
3317.endif
3318.if ${MK_TESTS} != "no"
3319	mkdir -p ${XDDESTDIR}${TESTSBASE}
3320	${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
3321	    -p ${XDDESTDIR}${TESTSBASE} >/dev/null
3322.endif
3323
3324.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
3325xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY
3326
3327_xi-cross-tools: .PHONY
3328	@echo "_xi-cross-tools"
3329.for _tool in ${XDEVDIRS}
3330	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
3331	cd ${.CURDIR}/${_tool}; \
3332	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
3333.endfor
3334
3335_xi-includes: .PHONY
3336.if !defined(NO_OBJWALK)
3337	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 _obj \
3338		DESTDIR=${XDDESTDIR}
3339.endif
3340	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
3341		DESTDIR=${XDDESTDIR}
3342
3343_xi-libraries: .PHONY
3344	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
3345		DESTDIR=${XDDESTDIR}
3346
3347xdev-links: .PHONY
3348	${_+_}cd ${XDDESTDIR}/usr/bin; \
3349	mkdir -p ../../../../usr/bin; \
3350		for i in *; do \
3351			ln -sf ../../${XDTP}/usr/bin/$$i \
3352			    ../../../../usr/bin/${XDDIR}-$$i; \
3353			ln -sf ../../${XDTP}/usr/bin/$$i \
3354			    ../../../../usr/bin/${XDDIR}${_REVISION}-$$i; \
3355		done
3356