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