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