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