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