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