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