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