Makefile.inc1 revision 263991
10SN/A#
29330SN/A# $FreeBSD: head/Makefile.inc1 263991 2014-04-01 14:23:58Z imp $
30SN/A#
40SN/A# Make command line options:
50SN/A#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
60SN/A#	-DNO_CLEAN do not clean at all
72362SN/A#	-DDB_FROM_SRC use the user/group databases in src/etc instead of
80SN/A#	    the system database when installing.
92362SN/A#	-DNO_SHARE do not go into share subdir
100SN/A#	-DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ}
110SN/A#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
120SN/A#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
130SN/A#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
140SN/A#	-DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
150SN/A#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
160SN/A#	-DNO_ROOT install without using root privilege
170SN/A#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
180SN/A#	-DNO_CTF do not run the DTrace CTF conversion tools on built objects
190SN/A#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
200SN/A#	LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
212362SN/A#	LOCAL_MTREE="list of mtree files" to process to allow local directories
222362SN/A#	    to be created before files are installed
232362SN/A#	LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
240SN/A#	    list
250SN/A#	METALOG="path to metadata log" to write permission and ownership
260SN/A#	    when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
270SN/A#	TARGET="machine" to crossbuild world for a different machine type
280SN/A#	TARGET_ARCH= may be required when a TARGET supports multiple endians
295116SN/A#	BUILDENV_SHELL= shell to launch for the buildenv target (def:/bin/sh)
300SN/A#	WORLD_FLAGS= additional flags to pass to make(1) during buildworld
310SN/A#	KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
320SN/A
330SN/A#
340SN/A# The intended user-driven targets are:
350SN/A# buildworld  - rebuild *everything*, including glue to help do upgrades
360SN/A# installworld- install everything built by "buildworld"
370SN/A# doxygen     - build API documentation of the kernel
380SN/A# update      - convenient way to update your source tree (eg: svn/svnup)
390SN/A#
400SN/A# Standard targets (not defined here) are documented in the makefiles in
410SN/A# /usr/share/mk.  These include:
420SN/A#		obj depend all install clean cleandepend cleanobj
430SN/A
440SN/A.if !defined(TARGET) || !defined(TARGET_ARCH)
450SN/A.error "Both TARGET and TARGET_ARCH must be defined."
460SN/A.endif
470SN/A
480SN/A.include <bsd.own.mk>
490SN/A.include <bsd.arch.inc.mk>
500SN/A.include <bsd.compiler.mk>
510SN/A
520SN/A# We must do share/info early so that installation of info `dir'
530SN/A# entries works correctly.  Do it first since it is less likely to
540SN/A# grow dependencies on include and lib than vice versa.
5510329SN/A#
5610329SN/A# We must do lib/ and libexec/ before bin/, because if installworld
570SN/A# installs a new /bin/sh, the 'make' command will *immediately*
580SN/A# use that new version.  And the new (dynamically-linked) /bin/sh
590SN/A# will expect to find appropriate libraries in /lib and /libexec.
600SN/A#
610SN/ASRCDIR?=	${.CURDIR}
620SN/A.if defined(SUBDIR_OVERRIDE)
630SN/ASUBDIR=	${SUBDIR_OVERRIDE}
640SN/A.else
650SN/ASUBDIR=	share/info lib libexec
660SN/ASUBDIR+=bin
670SN/A.if ${MK_GAMES} != "no"
680SN/ASUBDIR+=games
690SN/A.endif
700SN/A.if ${MK_CDDL} != "no"
710SN/ASUBDIR+=cddl
720SN/A.endif
730SN/ASUBDIR+=gnu include
740SN/A.if ${MK_KERBEROS} != "no"
7510329SN/ASUBDIR+=kerberos5
7610329SN/A.endif
7710329SN/A.if ${MK_RESCUE} != "no"
780SN/ASUBDIR+=rescue
790SN/A.endif
800SN/ASUBDIR+=sbin
810SN/A.if ${MK_CRYPT} != "no"
820SN/ASUBDIR+=secure
830SN/A.endif
840SN/A.if !defined(NO_SHARE)
850SN/ASUBDIR+=share
860SN/A.endif
870SN/ASUBDIR+=sys usr.bin usr.sbin
880SN/A.if ${MK_TESTS} != "no"
890SN/ASUBDIR+=	tests
900SN/A.endif
910SN/A.if ${MK_OFED} != "no"
920SN/ASUBDIR+=contrib/ofed
930SN/A.endif
940SN/A#
950SN/A# We must do etc/ last for install/distribute to work.
960SN/A#
970SN/ASUBDIR+=etc
980SN/A
990SN/A# These are last, since it is nice to at least get the base system
1000SN/A# rebuilt before you do them.
1010SN/A.for _DIR in ${LOCAL_LIB_DIRS} ${LOCAL_DIRS}
1020SN/A.if exists(${.CURDIR}/${_DIR}/Makefile)
1030SN/ASUBDIR+= ${_DIR}
1040SN/A.endif
1050SN/A.endfor
1060SN/A.endif
1070SN/A
1080SN/A.if defined(NOCLEAN)
1090SN/ANO_CLEAN=	${NOCLEAN}
1100SN/A.endif
1110SN/A.if defined(NO_CLEANDIR)
1120SN/ACLEANDIR=	clean cleandepend
1130SN/A.else
1140SN/ACLEANDIR=	cleandir
1150SN/A.endif
1160SN/A
1170SN/ALOCAL_TOOL_DIRS?=
1180SN/A
1190SN/ABUILDENV_SHELL?=/bin/sh
1200SN/A
1210SN/ASVN?=		/usr/local/bin/svn
1220SN/ASVNFLAGS?=	-r HEAD
1230SN/A
1240SN/AMAKEOBJDIRPREFIX?=	/usr/obj
1250SN/A.if !defined(OSRELDATE)
1260SN/A.if exists(/usr/include/osreldate.h)
1270SN/AOSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
1280SN/A		/usr/include/osreldate.h
1290SN/A.else
1300SN/AOSRELDATE=	0
1310SN/A.endif
1320SN/A.endif
1330SN/A
1340SN/A.if !defined(VERSION)
1350SN/AREVISION!=	${MAKE} -C ${SRCDIR}/release -V REVISION
1360SN/ABRANCH!=	${MAKE} -C ${SRCDIR}/release -V BRANCH
1370SN/ASRCRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
1380SN/A		${SRCDIR}/sys/sys/param.h
1390SN/AVERSION=	FreeBSD ${REVISION}-${BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
1400SN/A.endif
1410SN/A
1420SN/AKNOWN_ARCHES?=	amd64 arm armeb/arm armv6/arm armv6hf/arm i386 i386/pc98 ia64 mips mipsel/mips mips64el/mips mips64/mips mipsn32el/mips mipsn32/mips powerpc powerpc64/powerpc sparc64
1430SN/A.if ${TARGET} == ${TARGET_ARCH}
1440SN/A_t=		${TARGET}
1450SN/A.else
1460SN/A_t=		${TARGET_ARCH}/${TARGET}
1470SN/A.endif
1480SN/A.for _t in ${_t}
1490SN/A.if empty(KNOWN_ARCHES:M${_t})
1500SN/A.error Unknown target ${TARGET_ARCH}:${TARGET}.
1510SN/A.endif
1520SN/A.endfor
1530SN/A
1540SN/A.if ${TARGET} == ${MACHINE}
1550SN/ATARGET_CPUTYPE?=${CPUTYPE}
1560SN/A.else
1570SN/ATARGET_CPUTYPE?=
1580SN/A.endif
1590SN/A
1600SN/A.if !empty(TARGET_CPUTYPE)
1610SN/A_TARGET_CPUTYPE=${TARGET_CPUTYPE}
1620SN/A.else
1630SN/A_TARGET_CPUTYPE=dummy
1640SN/A.endif
1650SN/A_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
1660SN/A		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
1670SN/A.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
1680SN/A.error CPUTYPE global should be set with ?=.
1690SN/A.endif
1700SN/A.if make(buildworld)
1710SN/ABUILD_ARCH!=	uname -p
1720SN/A.if ${MACHINE_ARCH} != ${BUILD_ARCH}
1730SN/A.error To cross-build, set TARGET_ARCH.
1740SN/A.endif
1750SN/A.endif
1760SN/A.if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
1770SN/AOBJTREE=	${MAKEOBJDIRPREFIX}
1780SN/A.else
1790SN/AOBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
1800SN/A.endif
1810SN/AWORLDTMP=	${OBJTREE}${.CURDIR}/tmp
1820SN/A# /usr/games added for fortune which depend on strfile
1830SN/ABPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
1840SN/AXPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
1850SN/ASTRICTTMPPATH=	${BPATH}:${XPATH}
1860SN/ATMPPATH=	${STRICTTMPPATH}:${PATH}
1870SN/A
1880SN/A#
1890SN/A# Avoid running mktemp(1) unless actually needed.
1900SN/A# It may not be functional, e.g., due to new ABI
1910SN/A# when in the middle of installing over this system.
1920SN/A#
1930SN/A.if make(distributeworld) || make(installworld)
1940SN/AINSTALLTMP!=	/usr/bin/mktemp -d -u -t install
1950SN/A.endif
1960SN/A
1970SN/A#
1980SN/A# Building a world goes through the following stages
1990SN/A#
2000SN/A# 1. legacy stage [BMAKE]
2010SN/A#	This stage is responsible for creating compatibility
2020SN/A#	shims that are needed by the bootstrap-tools,
2030SN/A#	build-tools and cross-tools stages.
2040SN/A# 1. bootstrap-tools stage [BMAKE]
2050SN/A#	This stage is responsible for creating programs that
2060SN/A#	are needed for backward compatibility reasons. They
2070SN/A#	are not built as cross-tools.
2080SN/A# 2. build-tools stage [TMAKE]
2090SN/A#	This stage is responsible for creating the object
2100SN/A#	tree and building any tools that are needed during
2110SN/A#	the build process.
2120SN/A# 3. cross-tools stage [XMAKE]
2130SN/A#	This stage is responsible for creating any tools that
2140SN/A#	are needed for cross-builds. A cross-compiler is one
2150SN/A#	of them.
2160SN/A# 4. world stage [WMAKE]
2170SN/A#	This stage actually builds the world.
2180SN/A# 5. install stage (optional) [IMAKE]
2190SN/A#	This stage installs a previously built world.
2200SN/A#
2210SN/A
2220SN/ABOOTSTRAPPING?=	0
2230SN/A
2240SN/A# Common environment for world related stages
2250SN/ACROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
2260SN/A		MACHINE_ARCH=${TARGET_ARCH} \
2270SN/A		MACHINE=${TARGET} \
2280SN/A		CPUTYPE=${TARGET_CPUTYPE}
2290SN/A.if ${MK_GROFF} != "no"
2300SN/ACROSSENV+=	GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
2310SN/A		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
2320SN/A		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
2330SN/A.endif
2340SN/A.if defined(TARGET_CFLAGS)
2350SN/ACROSSENV+=	${TARGET_CFLAGS}
2360SN/A.endif
2370SN/A
2380SN/A# bootstrap-tools stage
2390SN/ABMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
2400SN/A		PATH=${BPATH}:${PATH} \
2410SN/A		WORLDTMP=${WORLDTMP} \
2420SN/A		VERSION="${VERSION}" \
2430SN/A		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
2440SN/ABMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
2450SN/A		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
2460SN/A		DESTDIR= \
2470SN/A		BOOTSTRAPPING=${OSRELDATE} \
2480SN/A		SSP_CFLAGS= \
2490SN/A		MK_HTML=no MK_INFO=no NO_LINT=yes MK_MAN=no \
2500SN/A		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
2510SN/A		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD MK_TESTS=no
2520SN/A
2530SN/A# build-tools stage
2540SN/ATMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
2550SN/A		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
2560SN/A		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
2570SN/A		DESTDIR= \
2580SN/A		BOOTSTRAPPING=${OSRELDATE} \
2590SN/A		SSP_CFLAGS= \
2600SN/A		-DNO_LINT \
2610SN/A		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD MK_TESTS=no
2620SN/A
2630SN/A# cross-tools stage
2640SN/AXMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
2650SN/A		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
2660SN/A		MK_GDB=no MK_TESTS=no
2670SN/A
2680SN/A# kernel-tools stage
2690SN/AKTMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
2700SN/A		PATH=${BPATH}:${PATH} \
2710SN/A		WORLDTMP=${WORLDTMP} \
2720SN/A		VERSION="${VERSION}"
2730SN/AKTMAKE=		TOOLS_PREFIX=${WORLDTMP} MAKEOBJDIRPREFIX=${WORLDTMP} \
2740SN/A		${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
2750SN/A		DESTDIR= \
2760SN/A		BOOTSTRAPPING=${OSRELDATE} \
2770SN/A		SSP_CFLAGS= \
2780SN/A		MK_HTML=no MK_INFO=no -DNO_LINT MK_MAN=no \
2790SN/A		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
2800SN/A		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD
2810SN/A
2820SN/A# world stage
2830SN/AWMAKEENV=	${CROSSENV} \
2840SN/A		_SHLIBDIRPREFIX=${WORLDTMP} \
2850SN/A		_LDSCRIPTROOT= \
2860SN/A		VERSION="${VERSION}" \
2870SN/A		INSTALL="sh ${.CURDIR}/tools/install.sh" \
2880SN/A		PATH=${TMPPATH}
2890SN/A
2900SN/A# make hierarchy
2910SN/AHMAKE=		PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
2920SN/A.if defined(NO_ROOT)
2930SN/AHMAKE+=		PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
2940SN/A.endif
2950SN/A
2960SN/A.if ${MK_CDDL} == "no"
2970SN/AWMAKEENV+=	NO_CTF=1
2980SN/A.endif
2990SN/A
3000SN/A.if defined(CROSS_TOOLCHAIN_PREFIX)
3010SN/ACROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
3020SN/ACROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
3030SN/A.endif
3040SN/AXCOMPILERS=	CC CXX CPP
3050SN/A.for COMPILER in ${XCOMPILERS}
3060SN/A.if defined(CROSS_COMPILER_PREFIX)
3070SN/AX${COMPILER}?=	${CROSS_COMPILER_PREFIX}${${COMPILER}}
3080SN/A.else
3090SN/AX${COMPILER}?=	${${COMPILER}}
3100SN/A.endif
3110SN/A.endfor
3120SN/AXBINUTILS=	AS AR LD NM OBJDUMP RANLIB STRINGS
3130SN/A.for BINUTIL in ${XBINUTILS}
3140SN/A.if defined(CROSS_BINUTILS_PREFIX)
3150SN/AX${BINUTIL}?=	${CROSS_BINUTILS_PREFIX}${${BINUTIL}}
3160SN/A.else
3170SN/AX${BINUTIL}?=	${${BINUTIL}}
3180SN/A.endif
3190SN/A.endfor
3200SN/AWMAKEENV+=	CC="${XCC} ${XFLAGS}" CXX="${XCXX} ${XFLAGS}" \
3210SN/A		CPP="${XCPP} ${XFLAGS}" \
3220SN/A		AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
3230SN/A		OBJDUMP=${XOBJDUMP} RANLIB=${XRANLIB} STRINGS=${XSTRINGS}
3240SN/A
3250SN/A.if ${XCC:M/*}
3260SN/AXFLAGS=		--sysroot=${WORLDTMP}
3270SN/A.if defined(CROSS_BINUTILS_PREFIX)
3280SN/A# In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
3290SN/A# directory, but the compiler will look in the right place for it's
3300SN/A# tools so we don't need to tell it where to look.
3310SN/A.if exists(${CROSS_BINUTILS_PREFIX})
3320SN/AXFLAGS+=	-B${CROSS_BINUTILS_PREFIX}
3330SN/A.endif
3340SN/A.else
3350SN/AXFLAGS+=	-B${WORLDTMP}/usr/bin
3360SN/A.endif
3370SN/A.if ${TARGET} == "arm" && ${MK_ARM_EABI} != "no"
3380SN/A.if ${TARGET_ARCH:M*eb*} == ""
3390SN/ATARGET_ABI=	gnueabi
3400SN/A.elif ${TARGET_ARCH} == "armv6hf"
3410SN/ATARGET_ABI=	gnueabihf
3420SN/A.endif
3430SN/A.endif
3440SN/ATARGET_ABI?=	unknown
3450SN/ATARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd11.0
3460SN/AXFLAGS+=	-target ${TARGET_TRIPLE}
3470SN/A.endif
3480SN/A
3490SN/AWMAKE=		${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP}
3500SN/A
3510SN/A.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64"
3520SN/A# 32 bit world
3530SN/ALIB32TMP=	${OBJTREE}${.CURDIR}/lib32
3540SN/A
3550SN/A.if ${TARGET_ARCH} == "amd64"
3560SN/A.if empty(TARGET_CPUTYPE)
3570SN/ALIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
3580SN/A.else
3590SN/ALIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
3600SN/A.endif
3610SN/ALIB32WMAKEENV=	MACHINE=i386 MACHINE_ARCH=i386 \
3620SN/A		MACHINE_CPU="i686 mmx sse sse2"
3630SN/ALIB32WMAKEFLAGS=	\
3640SN/A		AS="${AS} --32" \
3650SN/A		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32"
3660SN/A
3670SN/A.elif ${TARGET_ARCH} == "powerpc64"
3680SN/A.if empty(TARGET_CPUTYPE)
3690SN/ALIB32CPUFLAGS=	-mcpu=powerpc
3700SN/A.else
3710SN/ALIB32CPUFLAGS=	-mcpu=${TARGET_CPUTYPE}
3720SN/A.endif
3730SN/ALIB32WMAKEENV=	MACHINE=powerpc MACHINE_ARCH=powerpc
3740SN/ALIB32WMAKEFLAGS=	\
3750SN/A		LD="${LD} -m elf32ppc_fbsd"
3760SN/A.endif
3770SN/A
3780SN/A
3790SN/ALIB32FLAGS=	-m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \
3800SN/A		-isystem ${LIB32TMP}/usr/include/ \
3810SN/A		-L${LIB32TMP}/usr/lib32 \
3820SN/A		-B${LIB32TMP}/usr/lib32
3830SN/A.if ${XCC:M/*}
3840SN/ALIB32FLAGS+=		--sysroot=${WORLDTMP}
3850SN/A.endif
3860SN/A
3870SN/A# Yes, the flags are redundant.
3880SN/ALIB32WMAKEENV+=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
3890SN/A		_SHLIBDIRPREFIX=${LIB32TMP} \
3900SN/A		_LDSCRIPTROOT=${LIB32TMP} \
3910SN/A		VERSION="${VERSION}" \
3920SN/A		INSTALL="sh ${.CURDIR}/tools/install.sh" \
3930SN/A		PATH=${TMPPATH} \
3940SN/A		LIBDIR=/usr/lib32 \
3950SN/A		SHLIBDIR=/usr/lib32 \
3960SN/A		LIBPRIVATEDIR=/usr/lib32/private
3970SN/ALIB32WMAKEFLAGS+= CC="${XCC} ${LIB32FLAGS}" \
3980SN/A		CXX="${XCXX} ${LIB32FLAGS}" \
3990SN/A		DESTDIR=${LIB32TMP} \
4000SN/A		-DCOMPAT_32BIT \
4010SN/A		-DLIBRARIES_ONLY \
4020SN/A		-DNO_CPU_CFLAGS \
4030SN/A		-DNO_CTF \
4040SN/A		-DNO_LINT \
4050SN/A		MK_TESTS=no
4060SN/A
4070SN/ALIB32WMAKE=	${LIB32WMAKEENV} ${MAKE} ${LIB32WMAKEFLAGS} \
4080SN/A		MK_MAN=no MK_INFO=no MK_HTML=no
4090SN/ALIB32IMAKE=	${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} -DNO_INCS \
4100SN/A		${IMAKE_INSTALL}
4110SN/A.endif
4120SN/A
4130SN/AIMAKEENV=	${CROSSENV:N_LDSCRIPTROOT=*}
4140SN/AIMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1 \
4150SN/A		${IMAKE_INSTALL} ${IMAKE_MTREE}
4160SN/A.if empty(.MAKEFLAGS:M-n)
4170SN/AIMAKEENV+=	PATH=${STRICTTMPPATH}:${INSTALLTMP} \
4180SN/A		LD_LIBRARY_PATH=${INSTALLTMP} \
4190SN/A		PATH_LOCALE=${INSTALLTMP}/locale
4200SN/AIMAKE+=		__MAKE_SHELL=${INSTALLTMP}/sh
4210SN/A.else
4220SN/AIMAKEENV+=	PATH=${TMPPATH}:${INSTALLTMP}
4230SN/A.endif
4240SN/A.if defined(DB_FROM_SRC)
4250SN/AINSTALLFLAGS+=	-N ${.CURDIR}/etc
4260SN/AMTREEFLAGS+=	-N ${.CURDIR}/etc
4270SN/A.endif
4280SN/A_INSTALL_DDIR=	${DESTDIR}/${DISTDIR}
4290SN/AINSTALL_DDIR=	${_INSTALL_DDIR:S://:/:g:C:/$::}
4300SN/A.if defined(NO_ROOT)
4310SN/AMETALOG?=	${DESTDIR}/${DISTDIR}/METALOG
4320SN/AIMAKE+=		-DNO_ROOT METALOG=${METALOG}
4330SN/AINSTALLFLAGS+=	-U -M ${METALOG} -D ${INSTALL_DDIR}
4340SN/AMTREEFLAGS+=	-W
4350SN/A.endif
4360SN/A.if defined(DB_FROM_SRC) || defined(NO_ROOT)
4370SN/AIMAKE_INSTALL=	INSTALL="install ${INSTALLFLAGS}"
4380SN/AIMAKE_MTREE=	MTREE_CMD="mtree ${MTREEFLAGS}"
4390SN/A.endif
4400SN/A
4410SN/A# kernel stage
4420SN/AKMAKEENV=	${WMAKEENV}
4430SN/AKMAKE=		${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
4440SN/A
4450SN/A#
4460SN/A# buildworld
4470SN/A#
4480SN/A# Attempt to rebuild the entire system, with reasonable chance of
4490SN/A# success, regardless of how old your existing system is.
4500SN/A#
4510SN/A_worldtmp:
4520SN/A.if ${.CURDIR:C/[^,]//g} != ""
4530SN/A#	The m4 build of sendmail files doesn't like it if ',' is used
4540SN/A#	anywhere in the path of it's files.
4550SN/A	@echo
4560SN/A	@echo "*** Error: path to source tree contains a comma ','"
4570SN/A	@echo
4580SN/A	false
4590SN/A.endif
4600SN/A	@echo
4610SN/A	@echo "--------------------------------------------------------------"
4620SN/A	@echo ">>> Rebuilding the temporary build tree"
4630SN/A	@echo "--------------------------------------------------------------"
4640SN/A.if !defined(NO_CLEAN)
4650SN/A	rm -rf ${WORLDTMP}
4660SN/A.if defined(LIB32TMP)
4670SN/A	rm -rf ${LIB32TMP}
4680SN/A.endif
4690SN/A.else
4700SN/A	rm -rf ${WORLDTMP}/legacy/usr/include
4710SN/A#	XXX - These three can depend on any header file.
4720SN/A	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
4730SN/A	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
4740SN/A	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
4750SN/A.endif
4760SN/A.for _dir in \
4770SN/A    lib usr legacy/bin legacy/usr
4780SN/A	mkdir -p ${WORLDTMP}/${_dir}
4790SN/A.endfor
4800SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
4810SN/A	    -p ${WORLDTMP}/legacy/usr >/dev/null
4820SN/A.if ${MK_GROFF} != "no"
4830SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
4840SN/A	    -p ${WORLDTMP}/legacy/usr >/dev/null
4850SN/A.endif
48610329SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
48710329SN/A	    -p ${WORLDTMP}/usr >/dev/null
4880SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
4890SN/A	    -p ${WORLDTMP}/usr/include >/dev/null
4900SN/A	ln -sf ${.CURDIR}/sys ${WORLDTMP}
4910SN/A.if ${MK_DEBUG_FILES} != "no"
4920SN/A	# We could instead disable debug files for these build stages
4930SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
4940SN/A	    -p ${WORLDTMP}/legacy/usr/lib >/dev/null
4950SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
4960SN/A	    -p ${WORLDTMP}/usr/lib >/dev/null
4970SN/A.endif
4980SN/A.if ${MK_TESTS} != "no"
4990SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
5000SN/A	    -p ${WORLDTMP}/usr >/dev/null
5010SN/A.endif
5020SN/A.for _mtree in ${LOCAL_MTREE}
5030SN/A	mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
5040SN/A.endfor
5050SN/A_legacy:
5060SN/A	@echo
5070SN/A	@echo "--------------------------------------------------------------"
50810329SN/A	@echo ">>> stage 1.1: legacy release compatibility shims"
50910329SN/A	@echo "--------------------------------------------------------------"
51010329SN/A	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
5110SN/A_bootstrap-tools:
5120SN/A	@echo
5130SN/A	@echo "--------------------------------------------------------------"
5140SN/A	@echo ">>> stage 1.2: bootstrap tools"
5150SN/A	@echo "--------------------------------------------------------------"
5160SN/A	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
5170SN/A_cleanobj:
5180SN/A.if !defined(NO_CLEAN)
5190SN/A	@echo
5200SN/A	@echo "--------------------------------------------------------------"
5210SN/A	@echo ">>> stage 2.1: cleaning up the object tree"
5220SN/A	@echo "--------------------------------------------------------------"
5230SN/A	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
5240SN/A.if defined(LIB32TMP)
5250SN/A	${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
5260SN/A.endif
5270SN/A.endif
5280SN/A_obj:
5290SN/A	@echo
5300SN/A	@echo "--------------------------------------------------------------"
5310SN/A	@echo ">>> stage 2.2: rebuilding the object tree"
5320SN/A	@echo "--------------------------------------------------------------"
5330SN/A	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
5340SN/A_build-tools:
5350SN/A	@echo
5360SN/A	@echo "--------------------------------------------------------------"
5370SN/A	@echo ">>> stage 2.3: build tools"
5380SN/A	@echo "--------------------------------------------------------------"
5390SN/A	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
5400SN/A_cross-tools:
5410SN/A	@echo
5420SN/A	@echo "--------------------------------------------------------------"
5430SN/A	@echo ">>> stage 3: cross tools"
5440SN/A	@echo "--------------------------------------------------------------"
5450SN/A	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
5460SN/A	${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
5470SN/A_includes:
5480SN/A	@echo
5490SN/A	@echo "--------------------------------------------------------------"
5500SN/A	@echo ">>> stage 4.1: building includes"
5510SN/A	@echo "--------------------------------------------------------------"
5520SN/A	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
5530SN/A_libraries:
5540SN/A	@echo
5550SN/A	@echo "--------------------------------------------------------------"
5560SN/A	@echo ">>> stage 4.2: building libraries"
5570SN/A	@echo "--------------------------------------------------------------"
5580SN/A	${_+_}cd ${.CURDIR}; \
5590SN/A	    ${WMAKE} -DNO_FSCHG MK_HTML=no MK_INFO=no -DNO_LINT MK_MAN=no \
5600SN/A	    -DNO_PROFILE MK_TESTS=no libraries
5610SN/A_depend:
5620SN/A	@echo
5630SN/A	@echo "--------------------------------------------------------------"
5640SN/A	@echo ">>> stage 4.3: make dependencies"
5650SN/A	@echo "--------------------------------------------------------------"
5660SN/A	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
5670SN/Aeverything:
5680SN/A	@echo
5690SN/A	@echo "--------------------------------------------------------------"
5700SN/A	@echo ">>> stage 4.4: building everything"
5710SN/A	@echo "--------------------------------------------------------------"
5720SN/A	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
5730SN/A.if defined(LIB32TMP)
5740SN/Abuild32:
5750SN/A	@echo
5760SN/A	@echo "--------------------------------------------------------------"
5770SN/A	@echo ">>> stage 5.1: building 32 bit shim libraries"
5780SN/A	@echo "--------------------------------------------------------------"
5790SN/A	mkdir -p ${LIB32TMP}/usr/include
5800SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
5810SN/A	    -p ${LIB32TMP}/usr >/dev/null
5820SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
5830SN/A	    -p ${LIB32TMP}/usr/include >/dev/null
5840SN/A.if ${MK_DEBUG_FILES} != "no"
5850SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
5860SN/A	    -p ${LIB32TMP}/usr/lib >/dev/null
5870SN/A.endif
5880SN/A	mkdir -p ${WORLDTMP}
5890SN/A	ln -sf ${.CURDIR}/sys ${WORLDTMP}
5900SN/A.for _t in obj includes
5910SN/A	cd ${.CURDIR}/include; ${LIB32WMAKE} DIRPRFX=include/ ${_t}
5920SN/A	cd ${.CURDIR}/lib; ${LIB32WMAKE} DIRPRFX=lib/ ${_t}
5930SN/A.if ${MK_CDDL} != "no"
5940SN/A	cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} DIRPRFX=cddl/lib/ ${_t}
5950SN/A.endif
5960SN/A	cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} DIRPRFX=gnu/lib/ ${_t}
5970SN/A.if ${MK_CRYPT} != "no"
5980SN/A	cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} DIRPRFX=secure/lib/ ${_t}
5990SN/A.endif
6000SN/A.if ${MK_KERBEROS} != "no"
6010SN/A	cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} DIRPRFX=kerberos5/lib ${_t}
6020SN/A.endif
6030SN/A.endfor
6040SN/A.for _dir in usr.bin/lex/lib
6050SN/A	cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} DIRPRFX=${_dir}/ obj
6060SN/A.endfor
6070SN/A.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
6080SN/A	cd ${.CURDIR}/${_dir}; \
6090SN/A	    WORLDTMP=${WORLDTMP} \
6100SN/A	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
6110SN/A	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \
6120SN/A	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF \
6130SN/A	    -DEARLY_BUILD build-tools
6140SN/A.endfor
6150SN/A	cd ${.CURDIR}; \
6160SN/A	    ${LIB32WMAKE} -f Makefile.inc1 libraries
6170SN/A.for _t in obj depend all
6180SN/A	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} \
6190SN/A	    DIRPRFX=libexec/rtld-elf/ ${_t}
6200SN/A	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} \
6210SN/A	    DIRPRFX=usr.bin/ldd ${_t}
6220SN/A.endfor
6230SN/A
6240SN/Adistribute32 install32:
6250SN/A	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
6260SN/A.if ${MK_CDDL} != "no"
6270SN/A	cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
6280SN/A.endif
6290SN/A	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
6300SN/A.if ${MK_CRYPT} != "no"
6310SN/A	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
6320SN/A.endif
6330SN/A.if ${MK_KERBEROS} != "no"
6340SN/A	cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
6350SN/A.endif
6360SN/A	cd ${.CURDIR}/libexec/rtld-elf; \
6370SN/A	    PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
6380SN/A	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//}
6390SN/A.endif
6400SN/A
6410SN/AWMAKE_TGTS=
6420SN/A.if !defined(SUBDIR_OVERRIDE)
6430SN/AWMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
6440SN/A.endif
6450SN/AWMAKE_TGTS+=	_cleanobj _obj _build-tools
6460SN/A.if !defined(SUBDIR_OVERRIDE)
6470SN/AWMAKE_TGTS+=	_cross-tools
6480SN/A.endif
6490SN/AWMAKE_TGTS+=	_includes _libraries _depend everything
6500SN/A.if defined(LIB32TMP) && ${MK_LIB32} != "no"
6510SN/AWMAKE_TGTS+=	build32
6520SN/A.endif
6530SN/A
6540SN/Abuildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
6550SN/A.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
6560SN/A
6570SN/Abuildworld_prologue:
6580SN/A	@echo "--------------------------------------------------------------"
6590SN/A	@echo ">>> World build started on `LC_ALL=C date`"
6600SN/A	@echo "--------------------------------------------------------------"
6610SN/A
6620SN/Abuildworld_epilogue:
6630SN/A	@echo
6640SN/A	@echo "--------------------------------------------------------------"
6650SN/A	@echo ">>> World build completed on `LC_ALL=C date`"
6660SN/A	@echo "--------------------------------------------------------------"
6670SN/A
6680SN/A#
6690SN/A# We need to have this as a target because the indirection between Makefile
6700SN/A# and Makefile.inc1 causes the correct PATH to be used, rather than a
6710SN/A# modification of the current environment's PATH.  In addition, we need
6720SN/A# to quote multiword values.
6730SN/A#
6740SN/Abuildenvvars:
6750SN/A	@echo ${WMAKEENV:Q}
6760SN/A
6770SN/Abuildenv:
6780SN/A	@echo Entering world for ${TARGET_ARCH}:${TARGET}
6790SN/A	@cd ${.CURDIR} && env ${WMAKEENV} ${BUILDENV_SHELL} || true
6800SN/A
6810SN/ATOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
6820SN/Atoolchain: ${TOOLCHAIN_TGTS}
6830SN/Akernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
6840SN/A
6850SN/A#
6860SN/A# installcheck
6870SN/A#
6880SN/A# Checks to be sure system is ready for installworld/installkernel.
6890SN/A#
6900SN/Ainstallcheck: _installcheck_world _installcheck_kernel
6910SN/A_installcheck_world:
6920SN/A_installcheck_kernel:
6930SN/A
6940SN/A#
6950SN/A# Require DESTDIR to be set if installing for a different architecture or
6960SN/A# using the user/group database in the source tree.
6970SN/A#
6980SN/A.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
6990SN/A    defined(DB_FROM_SRC)
7000SN/A.if !make(distributeworld)
7010SN/A_installcheck_world: __installcheck_DESTDIR
7020SN/A_installcheck_kernel: __installcheck_DESTDIR
7030SN/A__installcheck_DESTDIR:
7040SN/A.if !defined(DESTDIR) || empty(DESTDIR)
7050SN/A	@echo "ERROR: Please set DESTDIR!"; \
7060SN/A	false
7070SN/A.endif
7080SN/A.endif
7090SN/A.endif
7100SN/A
7110SN/A.if !defined(DB_FROM_SRC)
7120SN/A#
7130SN/A# Check for missing UIDs/GIDs.
7140SN/A#
7150SN/ACHECK_UIDS=	auditdistd
7160SN/ACHECK_GIDS=	audit
7170SN/A.if ${MK_SENDMAIL} != "no"
7180SN/ACHECK_UIDS+=	smmsp
7190SN/ACHECK_GIDS+=	smmsp
7200SN/A.endif
7210SN/A.if ${MK_PF} != "no"
7220SN/ACHECK_UIDS+=	proxy
7230SN/ACHECK_GIDS+=	proxy authpf
7240SN/A.endif
7250SN/A.if ${MK_UNBOUND} != "no"
7260SN/ACHECK_UIDS+=	unbound
7270SN/ACHECK_GIDS+=	unbound
7280SN/A.endif
7290SN/A_installcheck_world: __installcheck_UGID
7300SN/A__installcheck_UGID:
7310SN/A.for uid in ${CHECK_UIDS}
7320SN/A	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
7330SN/A		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
7340SN/A		false; \
7350SN/A	fi
7360SN/A.endfor
7370SN/A.for gid in ${CHECK_GIDS}
7380SN/A	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
7390SN/A		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
7400SN/A		false; \
7410SN/A	fi
7420SN/A.endfor
7430SN/A.endif
7440SN/A
7450SN/A#
7460SN/A# Required install tools to be saved in a scratch dir for safety.
7470SN/A#
7480SN/A.if ${MK_INFO} != "no"
7490SN/A_install-info=	install-info
7500SN/A.endif
7510SN/A.if ${MK_ZONEINFO} != "no"
7520SN/A_zoneinfo=	zic tzsetup
7530SN/A.endif
7540SN/A
7550SN/AITOOLS=	[ awk cap_mkdb cat chflags chmod chown \
7560SN/A	date echo egrep find grep id install ${_install-info} \
7570SN/A	ln lockf make mkdir mtree mv pwd_mkdb \
7580SN/A	rm sed services_mkdb sh sysctl test true uname wc ${_zoneinfo}
7590SN/A
7600SN/A#
7610SN/A# distributeworld
7620SN/A#
7630SN/A# Distributes everything compiled by a `buildworld'.
7640SN/A#
7650SN/A# installworld
7660SN/A#
7670SN/A# Installs everything compiled by a 'buildworld'.
7680SN/A#
7690SN/A
7700SN/A# Non-base distributions produced by the base system
7710SN/AEXTRA_DISTRIBUTIONS=	doc
7720SN/A.if ${MK_GAMES} != "no"
7730SN/AEXTRA_DISTRIBUTIONS+=	games
7740SN/A.endif
7750SN/A.if defined(LIB32TMP) && ${MK_LIB32} != "no"
7760SN/AEXTRA_DISTRIBUTIONS+=	lib32
7770SN/A.endif
7780SN/A
7790SN/AMTREE_MAGIC?=	mtree 2.0
7800SN/A
7810SN/Adistributeworld installworld: _installcheck_world
7820SN/A	mkdir -p ${INSTALLTMP}
7830SN/A	progs=$$(for prog in ${ITOOLS}; do \
7840SN/A		if progpath=`which $$prog`; then \
7850SN/A			echo $$progpath; \
7860SN/A		else \
7870SN/A			echo "Required tool $$prog not found in PATH." >&2; \
7880SN/A			exit 1; \
7890SN/A		fi; \
7900SN/A	    done); \
7910SN/A	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
7920SN/A	    while read line; do \
7930SN/A		set -- $$line; \
7940SN/A		if [ "$$2 $$3" != "not found" ]; then \
7950SN/A			echo $$2; \
7960SN/A		else \
7970SN/A			echo "Required library $$1 not found." >&2; \
7980SN/A			exit 1; \
7990SN/A		fi; \
8000SN/A	    done); \
8010SN/A	cp $$libs $$progs ${INSTALLTMP}
8020SN/A	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
8030SN/A.if defined(NO_ROOT)
8040SN/A	echo "#${MTREE_MAGIC}" > ${METALOG}
8050SN/A.endif
8060SN/A.if make(distributeworld)
8070SN/A.for dist in ${EXTRA_DISTRIBUTIONS}
8080SN/A	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
8090SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
8100SN/A	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
8110SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
8120SN/A	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
8130SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
8140SN/A	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
8150SN/A.if ${MK_DEBUG_FILES} != "no"
8160SN/A	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
8170SN/A	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
8180SN/A.endif
8190SN/A.if defined(NO_ROOT)
8200SN/A	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
8210SN/A	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
8220SN/A	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
8230SN/A	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
8240SN/A	${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
8250SN/A	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
8260SN/A.endif
8270SN/A.endfor
8280SN/A	-mkdir ${DESTDIR}/${DISTDIR}/base
8290SN/A	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
8300SN/A	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
8310SN/A	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
8320SN/A	    LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
8330SN/A.endif
8340SN/A	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
8350SN/A	    ${IMAKEENV} rm -rf ${INSTALLTMP}
8360SN/A.if make(distributeworld)
8370SN/A.for dist in ${EXTRA_DISTRIBUTIONS}
8380SN/A	find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -empty -delete
8390SN/A.endfor
8400SN/A.if defined(NO_ROOT)
8410SN/A.for dist in base ${EXTRA_DISTRIBUTIONS}
8420SN/A	@# For each file that exists in this dist, print the corresponding
8430SN/A	@# line from the METALOG.  This relies on the fact that
8440SN/A	@# a line containing only the filename will sort immediatly before
8450SN/A	@# the relevant mtree line.
8460SN/A	cd ${DESTDIR}/${DISTDIR}; \
8470SN/A	find ./${dist} | sort -u ${METALOG} - | \
8480SN/A	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
8490SN/A	${DESTDIR}/${DISTDIR}/${dist}.meta
8500SN/A.endfor
8510SN/A.if ${MK_DEBUG_FILES} != "no"
8520SN/A. for dist in base ${EXTRA_DISTRIBUTIONS}
8530SN/A	@# For each file that exists in this dist, print the corresponding
8540SN/A	@# line from the METALOG.  This relies on the fact that
8550SN/A	@# a line containing only the filename will sort immediatly before
8560SN/A	@# the relevant mtree line.
8570SN/A	cd ${DESTDIR}/${DISTDIR}; \
8580SN/A	find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
8590SN/A	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
8600SN/A	${DESTDIR}/${DISTDIR}/${dist}.debug.meta
8610SN/A. endfor
8620SN/A.endif
8630SN/A.endif
8640SN/A.endif
8650SN/A
8660SN/Apackageworld:
8670SN/A.for dist in base ${EXTRA_DISTRIBUTIONS}
8680SN/A.if defined(NO_ROOT)
8690SN/A	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
8700SN/A	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
871	    --exclude usr/lib/debug \
872	    @${DESTDIR}/${DISTDIR}/${dist}.meta
873.else
874	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
875	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
876	    --exclude usr/lib/debug .
877.endif
878.endfor
879
880.if ${MK_DEBUG_FILES} != "no"
881. for dist in base ${EXTRA_DISTRIBUTIONS}
882.  if defined(NO_ROOT)
883	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
884	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.debug.txz \
885	    @${DESTDIR}/${DISTDIR}/${dist}.debug.meta
886.  else
887	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
888	    tar cvJfL ${DESTDIR}/${DISTDIR}/${dist}.debug.txz \
889	    usr/lib/debug
890.  endif
891. endfor
892.endif
893
894#
895# reinstall
896#
897# If you have a build server, you can NFS mount the source and obj directories
898# and do a 'make reinstall' on the *client* to install new binaries from the
899# most recent server build.
900#
901reinstall:
902	@echo "--------------------------------------------------------------"
903	@echo ">>> Making hierarchy"
904	@echo "--------------------------------------------------------------"
905	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
906	    LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
907	@echo
908	@echo "--------------------------------------------------------------"
909	@echo ">>> Installing everything"
910	@echo "--------------------------------------------------------------"
911	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
912.if defined(LIB32TMP) && ${MK_LIB32} != "no"
913	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
914.endif
915
916redistribute:
917	@echo "--------------------------------------------------------------"
918	@echo ">>> Distributing everything"
919	@echo "--------------------------------------------------------------"
920	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
921.if defined(LIB32TMP) && ${MK_LIB32} != "no"
922	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
923	    DISTRIBUTION=lib32
924.endif
925
926distrib-dirs distribution:
927	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
928	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
929
930#
931# buildkernel and installkernel
932#
933# Which kernels to build and/or install is specified by setting
934# KERNCONF. If not defined a GENERIC kernel is built/installed.
935# Only the existing (depending TARGET) config files are used
936# for building kernels and only the first of these is designated
937# as the one being installed.
938#
939# Note that we have to use TARGET instead of TARGET_ARCH when
940# we're in kernel-land. Since only TARGET_ARCH is (expected) to
941# be set to cross-build, we have to make sure TARGET is set
942# properly.
943
944.if defined(KERNFAST)
945NO_KERNELCLEAN=	t
946NO_KERNELCONFIG=	t
947NO_KERNELDEPEND=	t
948NO_KERNELOBJ=		t
949# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
950.if !defined(KERNCONF) && ${KERNFAST} != "1"
951KERNCONF=${KERNFAST}
952.endif
953.endif
954.if ${TARGET_ARCH} == "powerpc64"
955KERNCONF?=	GENERIC64
956.else
957KERNCONF?=	GENERIC
958.endif
959INSTKERNNAME?=	kernel
960
961KERNSRCDIR?=	${.CURDIR}/sys
962KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
963KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
964KERNCONFDIR?=	${KRNLCONFDIR}
965
966BUILDKERNELS=
967INSTALLKERNEL=
968.for _kernel in ${KERNCONF}
969.if exists(${KERNCONFDIR}/${_kernel})
970BUILDKERNELS+=	${_kernel}
971.if empty(INSTALLKERNEL)
972INSTALLKERNEL= ${_kernel}
973.endif
974.endif
975.endfor
976
977buildkernel ${WMAKE_TGTS} ${.ALLTARGETS:M_*}: .MAKE
978
979#
980# buildkernel
981#
982# Builds all kernels defined by BUILDKERNELS.
983#
984buildkernel:
985.if empty(BUILDKERNELS)
986	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
987	false
988.endif
989	@echo
990.for _kernel in ${BUILDKERNELS}
991	@echo "--------------------------------------------------------------"
992	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
993	@echo "--------------------------------------------------------------"
994	@echo "===> ${_kernel}"
995	mkdir -p ${KRNLOBJDIR}
996.if !defined(NO_KERNELCONFIG)
997	@echo
998	@echo "--------------------------------------------------------------"
999	@echo ">>> stage 1: configuring the kernel"
1000	@echo "--------------------------------------------------------------"
1001	cd ${KRNLCONFDIR}; \
1002		PATH=${TMPPATH} \
1003		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1004			-I ${KERNCONFDIR} ${KERNCONFDIR}/${_kernel}
1005.endif
1006.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1007	@echo
1008	@echo "--------------------------------------------------------------"
1009	@echo ">>> stage 2.1: cleaning up the object tree"
1010	@echo "--------------------------------------------------------------"
1011	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1012.endif
1013.if !defined(NO_KERNELOBJ)
1014	@echo
1015	@echo "--------------------------------------------------------------"
1016	@echo ">>> stage 2.2: rebuilding the object tree"
1017	@echo "--------------------------------------------------------------"
1018	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1019.endif
1020	@echo
1021	@echo "--------------------------------------------------------------"
1022	@echo ">>> stage 2.3: build tools"
1023	@echo "--------------------------------------------------------------"
1024	${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1025.if !defined(NO_KERNELDEPEND)
1026	@echo
1027	@echo "--------------------------------------------------------------"
1028	@echo ">>> stage 3.1: making dependencies"
1029	@echo "--------------------------------------------------------------"
1030	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
1031.endif
1032	@echo
1033	@echo "--------------------------------------------------------------"
1034	@echo ">>> stage 3.2: building everything"
1035	@echo "--------------------------------------------------------------"
1036	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1037	@echo "--------------------------------------------------------------"
1038	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1039	@echo "--------------------------------------------------------------"
1040.endfor
1041
1042#
1043# installkernel, etc.
1044#
1045# Install the kernel defined by INSTALLKERNEL
1046#
1047installkernel installkernel.debug \
1048reinstallkernel reinstallkernel.debug: _installcheck_kernel
1049.if empty(INSTALLKERNEL)
1050	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1051	false
1052.endif
1053	@echo "--------------------------------------------------------------"
1054	@echo ">>> Installing kernel ${INSTALLKERNEL}"
1055	@echo "--------------------------------------------------------------"
1056	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1057	    ${CROSSENV} PATH=${TMPPATH} \
1058	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1059
1060distributekernel distributekernel.debug:
1061.if empty(INSTALLKERNEL)
1062	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1063	false
1064.endif
1065	mkdir -p ${DESTDIR}/${DISTDIR}
1066.if defined(NO_ROOT)
1067	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1068.endif
1069	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1070	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1071	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1072	    DESTDIR=${INSTALL_DDIR}/kernel \
1073	    ${.TARGET:S/distributekernel/install/}
1074.if defined(NO_ROOT)
1075	sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1076	    ${DESTDIR}/${DISTDIR}/kernel.meta
1077.endif
1078.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1079.if defined(NO_ROOT)
1080	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1081.endif
1082	cd ${KRNLOBJDIR}/${_kernel}; \
1083	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1084	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1085	    KERNEL=${INSTKERNNAME}.${_kernel} \
1086	    DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1087	    ${.TARGET:S/distributekernel/install/}
1088.if defined(NO_ROOT)
1089	sed -e 's|^./kernel|.|' \
1090	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1091	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1092.endif
1093.endfor
1094
1095packagekernel:
1096.if defined(NO_ROOT)
1097	cd ${DESTDIR}/${DISTDIR}/kernel; \
1098	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz \
1099	    @${DESTDIR}/${DISTDIR}/kernel.meta
1100.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1101	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1102	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz \
1103	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1104.endfor
1105.else
1106	cd ${DESTDIR}/${DISTDIR}/kernel; \
1107	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz .
1108.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1109	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1110	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz .
1111.endfor
1112.endif
1113
1114#
1115# doxygen
1116#
1117# Build the API documentation with doxygen
1118#
1119doxygen:
1120	@if [ ! -x `/usr/bin/which doxygen` ]; then \
1121		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1122		exit 1; \
1123	fi
1124	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
1125
1126#
1127# update
1128#
1129# Update the source tree(s), by running svn/svnup to update to the
1130# latest copy.
1131#
1132update:
1133.if (defined(CVS_UPDATE) || defined(SUP_UPDATE)) && !defined(SVN_UPDATE)
1134	@echo "--------------------------------------------------------------"
1135	@echo "CVS_UPDATE and SUP_UPDATE are no longer supported."
1136	@echo "Please see: https://wiki.freebsd.org/CvsIsDeprecated"
1137	@echo "--------------------------------------------------------------"
1138	@exit 1
1139.endif
1140.if defined(SVN_UPDATE)
1141	@echo "--------------------------------------------------------------"
1142	@echo ">>> Updating ${.CURDIR} using Subversion"
1143	@echo "--------------------------------------------------------------"
1144	@(cd ${.CURDIR} && ${SVN} update ${SVNFLAGS})
1145.endif
1146
1147#
1148# ------------------------------------------------------------------------
1149#
1150# From here onwards are utility targets used by the 'make world' and
1151# related targets.  If your 'world' breaks, you may like to try to fix
1152# the problem and manually run the following targets to attempt to
1153# complete the build.  Beware, this is *not* guaranteed to work, you
1154# need to have a pretty good grip on the current state of the system
1155# to attempt to manually finish it.  If in doubt, 'make world' again.
1156#
1157
1158#
1159# legacy: Build compatibility shims for the next three targets
1160#
1161legacy:
1162.if ${BOOTSTRAPPING} < 700055 && ${BOOTSTRAPPING} != 0
1163	@echo "ERROR: Source upgrades from versions prior to 7.0 not supported."; \
1164	false
1165.endif
1166.for _tool in tools/build
1167	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
1168	    cd ${.CURDIR}/${_tool} && \
1169	    ${MAKE} DIRPRFX=${_tool}/ obj && \
1170	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes && \
1171	    ${MAKE} DIRPRFX=${_tool}/ depend && \
1172	    ${MAKE} DIRPRFX=${_tool}/ all && \
1173	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1174.endfor
1175
1176#
1177# bootstrap-tools: Build tools needed for compatibility
1178#
1179.if ${MK_GAMES} != "no"
1180_strfile=	games/fortune/strfile
1181.endif
1182
1183.if ${MK_CXX} != "no"
1184_gperf=		gnu/usr.bin/gperf
1185.endif
1186
1187.if ${MK_GROFF} != "no"
1188_groff=		gnu/usr.bin/groff
1189.endif
1190
1191.if ${BOOTSTRAPPING} < 800022
1192_ar=		usr.bin/ar
1193.endif
1194
1195.if ${BOOTSTRAPPING} < 800013
1196_mklocale=	usr.bin/mklocale
1197.endif
1198
1199.if ${BOOTSTRAPPING} < 900002
1200_sed=		usr.bin/sed
1201.endif
1202
1203.if ${BOOTSTRAPPING} < 900006
1204_lex=		usr.bin/lex
1205.endif
1206
1207.if ${BOOTSTRAPPING} < 1000002
1208_m4=		usr.bin/m4
1209.endif
1210
1211.if ${BOOTSTRAPPING} < 1000013
1212_yacc=		lib/liby \
1213		usr.bin/yacc
1214.endif
1215
1216.if ${BOOTSTRAPPING} < 1000014
1217_crunch=	usr.sbin/crunch
1218.endif
1219
1220.if ${BOOTSTRAPPING} < 1000026
1221_nmtree=	lib/libnetbsd \
1222		usr.sbin/nmtree
1223.endif
1224
1225.if ${BOOTSTRAPPING} < 1000027
1226_cat=		bin/cat
1227.endif
1228
1229.if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1230_awk=		usr.bin/awk
1231.endif
1232
1233.if ${MK_BSNMP} != "no" && !exists(/usr/sbin/gensnmptree)
1234_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
1235.endif
1236
1237.if ${MK_CLANG} != "no"
1238_clang_tblgen= \
1239	lib/clang/libllvmsupport \
1240	lib/clang/libllvmtablegen \
1241	usr.bin/clang/tblgen \
1242	usr.bin/clang/clang-tblgen
1243.endif
1244
1245# dtrace tools are required for older bootstrap env and cross-build
1246.if ${MK_CDDL} != "no" && \
1247    ((${BOOTSTRAPPING} < 1000034 && \
1248          !(${BOOTSTRAPPING} >= 901505 && ${BOOTSTRAPPING} < 999999)) \
1249      || (${MACHINE} != ${TARGET} || ${MACHINE_ARCH} != ${TARGET_ARCH}))
1250_dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
1251    lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
1252.endif
1253
1254# Default to building the GPL DTC, but build the BSDL one if users explicitly
1255# request it.
1256_dtc= usr.bin/dtc
1257.if ${MK_GPL_DTC} != "no"
1258_dtc= gnu/usr.bin/dtc
1259.endif
1260
1261.if ${MK_KERBEROS} != "no"
1262_kerberos5_bootstrap_tools= \
1263	kerberos5/tools/make-roken \
1264	kerberos5/lib/libroken \
1265	kerberos5/lib/libvers \
1266	kerberos5/tools/asn1_compile \
1267	kerberos5/tools/slc \
1268	usr.bin/compile_et
1269.endif
1270
1271#	Please document (add comment) why something is in 'bootstrap-tools'.
1272#	Try to bound the building of the bootstrap-tool to just the
1273#	FreeBSD versions that need the tool built at this stage of the build.
1274bootstrap-tools: .MAKE
1275.for _tool in \
1276    ${_clang_tblgen} \
1277    ${_kerberos5_bootstrap_tools} \
1278    ${_dtrace_tools} \
1279    ${_strfile} \
1280    ${_gperf} \
1281    ${_groff} \
1282    ${_ar} \
1283    ${_dtc} \
1284    ${_awk} \
1285    ${_cat} \
1286    usr.bin/lorder \
1287    usr.bin/makewhatis \
1288    ${_mklocale} \
1289    usr.bin/rpcgen \
1290    ${_sed} \
1291    ${_yacc} \
1292    ${_m4} \
1293    ${_lex} \
1294    lib/libmd \
1295    usr.bin/xinstall \
1296    ${_gensnmptree} \
1297    usr.sbin/config \
1298    ${_crunch} \
1299    ${_nmtree}
1300	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1301		cd ${.CURDIR}/${_tool} && \
1302		${MAKE} DIRPRFX=${_tool}/ obj && \
1303		${MAKE} DIRPRFX=${_tool}/ depend && \
1304		${MAKE} DIRPRFX=${_tool}/ all && \
1305		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1306.endfor
1307
1308#
1309# build-tools: Build special purpose build tools
1310#
1311.if !defined(NO_SHARE)
1312_share=	share/syscons/scrnmaps
1313.endif
1314
1315.if ${MK_GCC} != "no"
1316_gcc_tools= gnu/usr.bin/cc/cc_tools
1317.endif
1318
1319.if ${MK_RESCUE} != "no"
1320_rescue= rescue/rescue
1321.endif
1322
1323build-tools: .MAKE
1324.for _tool in \
1325    bin/csh \
1326    bin/sh \
1327    ${_rescue} \
1328    ${LOCAL_TOOL_DIRS} \
1329    lib/ncurses/ncurses \
1330    lib/ncurses/ncursesw \
1331    ${_share} \
1332    usr.bin/awk \
1333    lib/libmagic \
1334    usr.bin/mkesdb_static \
1335    usr.bin/mkcsmapper_static \
1336    usr.bin/vi/catalog
1337	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1338		cd ${.CURDIR}/${_tool} && \
1339		${MAKE} DIRPRFX=${_tool}/ obj && \
1340		${MAKE} DIRPRFX=${_tool}/ build-tools
1341.endfor
1342.for _tool in \
1343    ${_gcc_tools}
1344	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1345		cd ${.CURDIR}/${_tool} && \
1346		${MAKE} DIRPRFX=${_tool}/ obj && \
1347		${MAKE} DIRPRFX=${_tool}/ depend && \
1348		${MAKE} DIRPRFX=${_tool}/ all
1349.endfor
1350
1351#
1352# kernel-tools: Build kernel-building tools
1353#
1354kernel-tools: .MAKE
1355	mkdir -p ${MAKEOBJDIRPREFIX}/usr
1356	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1357	    -p ${MAKEOBJDIRPREFIX}/usr >/dev/null
1358
1359#
1360# cross-tools: Build cross-building tools
1361#
1362.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1363.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1364_btxld=		usr.sbin/btxld
1365.endif
1366.endif
1367.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1368.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1369_crunchide=	usr.sbin/crunch/crunchide
1370.endif
1371.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1372_kgzip=		usr.sbin/kgzip
1373.endif
1374.endif
1375
1376.if ${XAS:M/*} == "" && ${MK_BINUTILS} != "no"
1377_binutils=	gnu/usr.bin/binutils
1378.endif
1379
1380# If an full path to an external cross compiler is given, don't build
1381# a cross compiler.
1382.if ${XCC:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1383.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
1384_clang=		usr.bin/clang
1385_clang_libs=	lib/clang
1386.else
1387_cc=		gnu/usr.bin/cc
1388.endif
1389
1390# The boot2 for pc98 requires gcc.
1391.if ${TARGET} == "pc98"
1392_cc=		gnu/usr.bin/cc
1393.endif
1394.endif
1395
1396cross-tools: .MAKE
1397.for _tool in \
1398    ${_clang_libs} \
1399    ${_clang} \
1400    ${_binutils} \
1401    ${_cc} \
1402    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1403    ${_btxld} \
1404    ${_crunchide} \
1405    ${_kgzip}
1406	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1407		cd ${.CURDIR}/${_tool} && \
1408		${MAKE} DIRPRFX=${_tool}/ obj && \
1409		${MAKE} DIRPRFX=${_tool}/ depend && \
1410		${MAKE} DIRPRFX=${_tool}/ all && \
1411		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1412.endfor
1413
1414#
1415# hierarchy - ensure that all the needed directories are present
1416#
1417hierarchy hier:
1418	cd ${.CURDIR}/etc && ${HMAKE} distrib-dirs
1419
1420#
1421# libraries - build all libraries, and install them under ${DESTDIR}.
1422#
1423# The list of libraries with dependents (${_prebuild_libs}) and their
1424# interdependencies (__L) are built automatically by the
1425# ${.CURDIR}/tools/make_libdeps.sh script.
1426#
1427libraries: .MAKE
1428	cd ${.CURDIR} && \
1429	    ${MAKE} -f Makefile.inc1 _prereq_libs && \
1430	    ${MAKE} -f Makefile.inc1 _startup_libs && \
1431	    ${MAKE} -f Makefile.inc1 _prebuild_libs && \
1432	    ${MAKE} -f Makefile.inc1 _generic_libs
1433
1434#
1435# static libgcc.a prerequisite for shared libc
1436#
1437_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1438
1439# These dependencies are not automatically generated:
1440#
1441# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1442# all shared libraries for ELF.
1443#
1444_startup_libs=	gnu/lib/csu
1445.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1446_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1447.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1448_startup_libs+=	lib/csu/${MACHINE_ARCH}
1449.else
1450_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1451.endif
1452_startup_libs+=	gnu/lib/libgcc
1453_startup_libs+=	lib/libcompiler_rt
1454_startup_libs+=	lib/libc
1455_startup_libs+=	lib/libc_nonshared
1456.if ${MK_LIBCPLUSPLUS} != "no"
1457_startup_libs+=	lib/libcxxrt
1458.endif
1459
1460gnu/lib/libgcc__L: lib/libc__L
1461gnu/lib/libgcc__L: lib/libc_nonshared__L
1462.if ${MK_LIBCPLUSPLUS} != "no"
1463lib/libcxxrt__L: gnu/lib/libgcc__L
1464.endif
1465
1466_prebuild_libs=	${_kerberos5_lib_libasn1} \
1467		${_kerberos5_lib_libhdb} \
1468		${_kerberos5_lib_libheimbase} \
1469		${_kerberos5_lib_libheimntlm} \
1470		${_kerberos5_lib_libheimsqlite} \
1471		${_kerberos5_lib_libheimipcc} \
1472		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1473		${_kerberos5_lib_libroken} \
1474		${_kerberos5_lib_libwind} \
1475		${_lib_atf} \
1476		lib/libbz2 ${_libcom_err} lib/libcrypt \
1477		lib/libelf lib/libexpat \
1478		${_lib_libgssapi} \
1479		lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
1480		${_lib_libcapsicum} \
1481		lib/ncurses/ncurses lib/ncurses/ncursesw \
1482		lib/libopie lib/libpam ${_lib_libthr} \
1483		lib/libradius lib/libsbuf lib/libtacplus \
1484		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1485		${_cddl_lib_libzfs_core} \
1486		lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
1487		${_secure_lib_libcrypto} ${_lib_libldns} \
1488		${_secure_lib_libssh} ${_secure_lib_libssl}
1489.if ${MK_GNUCXX} != "no" && ${MK_CXX} != "no"
1490_prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
1491.endif
1492
1493.if defined(WITH_ATF) || ${MK_TESTS} != "no"
1494.if !defined(WITH_ATF)
1495# Ensure that the ATF libraries will be built during make libraries, even
1496# though they will have WITHOUT_TESTS
1497MAKE+=		-DWITH_ATF
1498.endif
1499_lib_atf=	lib/atf
1500.endif
1501
1502.if ${MK_LIBTHR} != "no"
1503_lib_libthr=	lib/libthr
1504.endif
1505
1506.if ${MK_OFED} != "no"
1507_ofed_lib=	contrib/ofed/usr.lib/
1508.endif
1509
1510.if ${MK_CASPER} != "no"
1511_lib_libcapsicum=lib/libcapsicum
1512.endif
1513
1514lib/libcapsicum__L: lib/libnv__L
1515lib/libpjdlog__L: lib/libutil__L
1516
1517_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1518.for _DIR in ${LOCAL_LIB_DIRS}
1519.if exists(${.CURDIR}/${_DIR}/Makefile)
1520_generic_libs+= ${_DIR}
1521.endif
1522.endfor
1523
1524lib/libopie__L lib/libtacplus__L: lib/libmd__L
1525
1526.if ${MK_CDDL} != "no"
1527_cddl_lib_libumem= cddl/lib/libumem
1528_cddl_lib_libnvpair= cddl/lib/libnvpair
1529_cddl_lib_libzfs_core= cddl/lib/libzfs_core
1530_cddl_lib= cddl/lib
1531cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1532.endif
1533
1534.if ${MK_CRYPT} != "no"
1535.if ${MK_OPENSSL} != "no"
1536_secure_lib_libcrypto= secure/lib/libcrypto
1537_secure_lib_libssl= secure/lib/libssl
1538lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1539.if ${MK_LDNS} != "no"
1540_lib_libldns= lib/libldns
1541lib/libldns__L: secure/lib/libcrypto__L
1542.endif
1543.if ${MK_OPENSSH} != "no"
1544_secure_lib_libssh= secure/lib/libssh
1545secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1546.if ${MK_LDNS} != "no"
1547secure/lib/libssh__L: lib/libldns__L
1548.endif
1549.if ${MK_KERBEROS_SUPPORT} != "no"
1550secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1551    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1552    lib/libmd__L kerberos5/lib/libroken__L
1553.endif
1554.endif
1555.endif
1556_secure_lib=	secure/lib
1557.endif
1558
1559.if ${MK_KERBEROS} != "no"
1560kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1561kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1562    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1563    kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L 
1564kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1565    kerberos5/lib/libroken__L lib/libcom_err__L
1566kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1567    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1568kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1569    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1570    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1571    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1572kerberos5/lib/libroken__L: lib/libcrypt__L
1573kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1574kerberos5/lib/libheimbase__L: lib/libthr__L
1575kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1576kerberos5/lib/libheimsqlite__L: lib/libthr__L
1577.endif
1578
1579.if ${MK_GSSAPI} != "no"
1580_lib_libgssapi=	lib/libgssapi
1581.endif
1582
1583.if ${MK_KERBEROS} != "no"
1584_kerberos5_lib=	kerberos5/lib
1585_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1586_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1587_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1588_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1589_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1590_kerberos5_lib_libroken= kerberos5/lib/libroken
1591_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1592_kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1593_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1594_kerberos5_lib_libwind= kerberos5/lib/libwind
1595_libcom_err= lib/libcom_err
1596.endif
1597
1598.if ${MK_NIS} != "no"
1599_lib_libypclnt=	lib/libypclnt
1600.endif
1601
1602.if ${MK_OPENSSL} == "no"
1603lib/libradius__L: lib/libmd__L
1604.endif
1605
1606.for _lib in ${_prereq_libs}
1607${_lib}__PL: .PHONY .MAKE
1608.if exists(${.CURDIR}/${_lib})
1609	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1610		cd ${.CURDIR}/${_lib} && \
1611		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj && \
1612		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ depend && \
1613		${MAKE} MK_TESTS=no -DNO_PROFILE -DNO_PIC \
1614		    DIRPRFX=${_lib}/ all && \
1615		${MAKE} MK_TESTS=no -DNO_PROFILE -DNO_PIC \
1616		    DIRPRFX=${_lib}/ install
1617.endif
1618.endfor
1619
1620.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1621${_lib}__L: .PHONY .MAKE
1622.if exists(${.CURDIR}/${_lib})
1623	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1624		cd ${.CURDIR}/${_lib} && \
1625		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj && \
1626		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ depend && \
1627		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all && \
1628		${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
1629.endif
1630.endfor
1631
1632# libpam is special: we need to build static PAM modules before
1633# static PAM library, and dynamic PAM library before dynamic PAM
1634# modules.
1635lib/libpam__L: .PHONY .MAKE
1636	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1637		cd ${.CURDIR}/lib/libpam && \
1638		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ obj && \
1639		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ depend && \
1640		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ \
1641		    -D_NO_LIBPAM_SO_YET all && \
1642		${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ \
1643		    -D_NO_LIBPAM_SO_YET install
1644
1645_prereq_libs: ${_prereq_libs:S/$/__PL/}
1646_startup_libs: ${_startup_libs:S/$/__L/}
1647_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1648_generic_libs: ${_generic_libs:S/$/__L/}
1649
1650.for __target in all clean cleandepend cleandir depend includes obj
1651.for entry in ${SUBDIR}
1652${entry}.${__target}__D: .PHONY .MAKE
1653	${_+_}@set -e; if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1654		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1655		edir=${entry}.${MACHINE_ARCH}; \
1656		cd ${.CURDIR}/$${edir}; \
1657	else \
1658		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1659		edir=${entry}; \
1660		cd ${.CURDIR}/$${edir}; \
1661	fi; \
1662	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1663.endfor
1664par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1665.endfor
1666
1667.include <bsd.subdir.mk>
1668
1669.if make(check-old) || make(check-old-dirs) || \
1670    make(check-old-files) || make(check-old-libs) || \
1671    make(delete-old) || make(delete-old-dirs) || \
1672    make(delete-old-files) || make(delete-old-libs)
1673
1674#
1675# check for / delete old files section
1676#
1677
1678.include "ObsoleteFiles.inc"
1679
1680OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1681else you can not start such an application. Consult UPDATING for more \
1682information regarding how to cope with the removal/revision bump of a \
1683specific library."
1684
1685.if !defined(BATCH_DELETE_OLD_FILES)
1686RM_I=-i
1687.else
1688RM_I=-v
1689.endif
1690
1691delete-old-files:
1692	@echo ">>> Removing old files (only deletes safe to delete libs)"
1693# Ask for every old file if the user really wants to remove it.
1694# It's annoying, but better safe than sorry.
1695# NB: We cannot pass the list of OLD_FILES as a parameter because the
1696# argument list will get too long. Using .for/.endfor make "loops" will make
1697# the Makefile parser segfault.
1698	@exec 3<&0; \
1699	cd ${.CURDIR}; \
1700	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1701	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1702	while read file; do \
1703		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1704			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1705			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1706		fi; \
1707	done
1708# Remove catpages without corresponding manpages.
1709	@exec 3<&0; \
1710	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1711	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1712	while read catpage; do \
1713		read manpage; \
1714		if [ ! -e "$${manpage}" ]; then \
1715			rm ${RM_I} $${catpage} <&3; \
1716	        fi; \
1717	done
1718	@echo ">>> Old files removed"
1719
1720check-old-files:
1721	@echo ">>> Checking for old files"
1722	@cd ${.CURDIR}; \
1723	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1724	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1725	while read file; do \
1726		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1727		 	echo "${DESTDIR}/$${file}"; \
1728		fi; \
1729	done
1730# Check for catpages without corresponding manpages.
1731	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1732	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1733	while read catpage; do \
1734		read manpage; \
1735		if [ ! -e "$${manpage}" ]; then \
1736			echo $${catpage}; \
1737	        fi; \
1738	done
1739
1740delete-old-libs:
1741	@echo ">>> Removing old libraries"
1742	@echo "${OLD_LIBS_MESSAGE}" | fmt
1743	@exec 3<&0; \
1744	cd ${.CURDIR}; \
1745	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1746	    -V OLD_LIBS | xargs -n1 | \
1747	while read file; do \
1748		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1749			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1750			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1751		fi; \
1752		for ext in debug symbols; do \
1753		  if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
1754		      "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1755			  rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
1756			      <&3; \
1757		  fi; \
1758		done; \
1759	done
1760	@echo ">>> Old libraries removed"
1761
1762check-old-libs:
1763	@echo ">>> Checking for old libraries"
1764	@cd ${.CURDIR}; \
1765	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1766	    -V OLD_LIBS | xargs -n1 | \
1767	while read file; do \
1768		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1769			echo "${DESTDIR}/$${file}"; \
1770		fi; \
1771		for ext in debug symbols; do \
1772		  if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1773			  echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
1774		  fi; \
1775		done; \
1776	done
1777
1778delete-old-dirs:
1779	@echo ">>> Removing old directories"
1780	@cd ${.CURDIR}; \
1781	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1782	    -V OLD_DIRS | xargs -n1 | sort -r | \
1783	while read dir; do \
1784		if [ -d "${DESTDIR}/$${dir}" ]; then \
1785			rmdir -v "${DESTDIR}/$${dir}" || true; \
1786		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1787			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1788		fi; \
1789	done
1790	@echo ">>> Old directories removed"
1791
1792check-old-dirs:
1793	@echo ">>> Checking for old directories"
1794	@cd ${.CURDIR}; \
1795	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1796	    -V OLD_DIRS | xargs -n1 | \
1797	while read dir; do \
1798		if [ -d "${DESTDIR}/$${dir}" ]; then \
1799			echo "${DESTDIR}/$${dir}"; \
1800		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1801			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1802		fi; \
1803	done
1804
1805delete-old: delete-old-files delete-old-dirs
1806	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1807
1808check-old: check-old-files check-old-libs check-old-dirs
1809	@echo "To remove old files and directories run '${MAKE} delete-old'."
1810	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1811
1812.endif
1813
1814#
1815# showconfig - show build configuration.
1816#
1817showconfig:
1818	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 2>&1 | grep ^MK_ | sort
1819
1820.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
1821DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
1822
1823.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
1824.if exists(${KERNCONFDIR}/${KERNCONF})
1825FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
1826	${KERNCONFDIR}/${KERNCONF} ; echo
1827.endif
1828.endif
1829
1830.endif
1831
1832.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
1833DTBOUTPUTPATH= ${.CURDIR}
1834.endif
1835
1836#
1837# Build 'standalone' Device Tree Blob
1838#
1839builddtb:
1840	@if [ "${FDT_DTS_FILE}" = "" ]; then \
1841		echo "ERROR: FDT_DTS_FILE must be specified!"; \
1842		exit 1; \
1843	fi;	\
1844	if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${MACHINE}/${FDT_DTS_FILE} ]; then \
1845		echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \
1846			exist!"; \
1847		exit 1;	\
1848	fi;	\
1849	if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then	\
1850		echo "WARNING: DTB will be placed in the current working \
1851			directory"; \
1852	fi
1853	@PATH=${TMPPATH} \
1854	${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
1855	    ${FDT_DTS_FILE} \
1856	    ${DTBOUTPUTPATH}/`basename ${FDT_DTS_FILE} .dts`
1857
1858###############
1859
1860.if defined(XDEV) && defined(XDEV_ARCH)
1861
1862.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
1863XDEV_CPUTYPE?=${CPUTYPE}
1864.else
1865XDEV_CPUTYPE?=${TARGET_CPUTYPE}
1866.endif
1867
1868NOFUN=-DNO_FSCHG MK_HTML=no MK_INFO=no -DNO_LINT \
1869	MK_MAN=no MK_NLS=no -DNO_PROFILE \
1870	MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no -DNO_WARNS \
1871	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
1872	CPUTYPE=${XDEV_CPUTYPE}
1873
1874XDDIR=${XDEV_ARCH}-freebsd
1875XDTP=usr/${XDDIR}
1876CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
1877	INSTALL="sh ${.CURDIR}/tools/install.sh"
1878CDENV= ${CDBENV} \
1879	_SHLIBDIRPREFIX=${XDDESTDIR} \
1880	TOOLS_PREFIX=${XDDESTDIR}
1881CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
1882	-B${XDDESTDIR}/usr/lib
1883CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" \
1884	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1885
1886CDTMP=	${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
1887CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1888CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1889XDDESTDIR?=${DESTDIR}/${XDTP}
1890.if !defined(OSREL)
1891OSREL!= uname -r | sed -e 's/[-(].*//'
1892.endif
1893
1894.ORDER: xdev-build xdev-install
1895xdev: xdev-build xdev-install
1896
1897.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
1898xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
1899
1900_xb-worldtmp:
1901	mkdir -p ${CDTMP}/usr
1902	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1903	    -p ${CDTMP}/usr >/dev/null
1904
1905_xb-bootstrap-tools:
1906.for _tool in \
1907    ${_clang_tblgen}
1908	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1909	cd ${.CURDIR}/${_tool} && \
1910	${CDMAKE} DIRPRFX=${_tool}/ obj && \
1911	${CDMAKE} DIRPRFX=${_tool}/ depend && \
1912	${CDMAKE} DIRPRFX=${_tool}/ all && \
1913	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
1914.endfor
1915
1916_xb-build-tools:
1917	${_+_}@cd ${.CURDIR}; \
1918	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1919
1920_xb-cross-tools:
1921.for _tool in \
1922    ${_binutils} \
1923    usr.bin/ar \
1924    ${_clang_libs} \
1925    ${_clang} \
1926    ${_cc}
1927	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1928	cd ${.CURDIR}/${_tool} && \
1929	${CDMAKE} DIRPRFX=${_tool}/ obj && \
1930	${CDMAKE} DIRPRFX=${_tool}/ depend && \
1931	${CDMAKE} DIRPRFX=${_tool}/ all
1932.endfor
1933
1934_xi-mtree:
1935	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1936	mkdir -p ${XDDESTDIR}
1937	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1938	    -p ${XDDESTDIR} >/dev/null
1939	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1940	    -p ${XDDESTDIR}/usr >/dev/null
1941	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1942	    -p ${XDDESTDIR}/usr/include >/dev/null
1943
1944.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1945xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1946
1947_xi-cross-tools:
1948	@echo "_xi-cross-tools"
1949.for _tool in \
1950    ${_binutils} \
1951    usr.bin/ar \
1952    ${_clang_libs} \
1953    ${_clang} \
1954    ${_cc}
1955	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1956	cd ${.CURDIR}/${_tool}; \
1957	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1958.endfor
1959
1960_xi-includes:
1961	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1962		DESTDIR=${XDDESTDIR}
1963
1964_xi-libraries:
1965	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1966		DESTDIR=${XDDESTDIR}
1967
1968_xi-links:
1969	${_+_}cd ${XDDESTDIR}/usr/bin; \
1970       mkdir -p ../../../../usr/bin; \
1971		for i in *; do \
1972			ln -sf ../../${XDTP}/usr/bin/$$i \
1973			    ../../../../usr/bin/${XDDIR}-$$i; \
1974			ln -sf ../../${XDTP}/usr/bin/$$i \
1975			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1976		done
1977.else
1978xdev xdev-build xdev-install:
1979	@echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target"
1980.endif
1981