Makefile.inc1 revision 255981
153246Sarchie#
253246Sarchie# $FreeBSD: head/Makefile.inc1 255981 2013-10-01 22:53:27Z delphij $
3139823Simp#
4139823Simp# Make command line options:
5139823Simp#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
653246Sarchie#	-DNO_CLEAN do not clean at all
753246Sarchie#	-DDB_FROM_SRC use the user/group databases in src/etc instead of
853246Sarchie#	    the system database when installing.
953246Sarchie#	-DNO_SHARE do not go into share subdir
1053246Sarchie#	-DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ}
1153246Sarchie#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
1253246Sarchie#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
1353246Sarchie#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
1453246Sarchie#	-DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
1553246Sarchie#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
1653246Sarchie#	-DNO_ROOT install without using root privilege
1753246Sarchie#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
1853246Sarchie#	-DNO_CTF do not run the DTrace CTF conversion tools on built objects
1953246Sarchie#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
2053246Sarchie#	LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
2153246Sarchie#	LOCAL_MTREE="list of mtree files" to process to allow local directories
2253246Sarchie#	    to be created before files are installed
2353246Sarchie#	LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
2453246Sarchie#	    list
2553246Sarchie#	METALOG="path to metadata log" to write permission and ownership
2653246Sarchie#	    when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
2753246Sarchie#	TARGET="machine" to crossbuild world for a different machine type
2853246Sarchie#	TARGET_ARCH= may be required when a TARGET supports multiple endians
2953246Sarchie#	BUILDENV_SHELL= shell to launch for the buildenv target (def:/bin/sh)
3053246Sarchie#	WORLD_FLAGS= additional flags to pass to make(1) during buildworld
3153246Sarchie#	KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
3253246Sarchie
3353246Sarchie#
3453246Sarchie# The intended user-driven targets are:
3553246Sarchie# buildworld  - rebuild *everything*, including glue to help do upgrades
3653246Sarchie# installworld- install everything built by "buildworld"
3753246Sarchie# doxygen     - build API documentation of the kernel
3867506Sjulian# update      - convenient way to update your source tree (eg: svn/svnup)
3953246Sarchie#
4053246Sarchie# Standard targets (not defined here) are documented in the makefiles in
4153246Sarchie# /usr/share/mk.  These include:
4253246Sarchie#		obj depend all install clean cleandepend cleanobj
4353246Sarchie
4453246Sarchie.if !defined(TARGET) || !defined(TARGET_ARCH)
4553246Sarchie.error "Both TARGET and TARGET_ARCH must be defined."
4653246Sarchie.endif
4753246Sarchie
4853246Sarchie.include <bsd.own.mk>
4953246Sarchie.include <bsd.arch.inc.mk>
5053246Sarchie.include <bsd.compiler.mk>
5153246Sarchie
5253246Sarchie# We must do share/info early so that installation of info `dir'
5353246Sarchie# entries works correctly.  Do it first since it is less likely to
5453246Sarchie# grow dependencies on include and lib than vice versa.
5553913Sarchie#
5653246Sarchie# We must do lib/ and libexec/ before bin/, because if installworld
5753246Sarchie# installs a new /bin/sh, the 'make' command will *immediately*
5853246Sarchie# use that new version.  And the new (dynamically-linked) /bin/sh
5953246Sarchie# will expect to find appropriate libraries in /lib and /libexec.
6053246Sarchie#
6153913Sarchie.if defined(SUBDIR_OVERRIDE)
6253246SarchieSUBDIR=	${SUBDIR_OVERRIDE}
6353246Sarchie.else
6453246SarchieSUBDIR=	share/info lib libexec
6553913SarchieSUBDIR+=bin
6653246Sarchie.if ${MK_GAMES} != "no"
6753246SarchieSUBDIR+=games
6853246Sarchie.endif
6953246Sarchie.if ${MK_CDDL} != "no"
7053246SarchieSUBDIR+=cddl
7170870Sjulian.endif
72249132SmavSUBDIR+=gnu include
73249132Smav.if ${MK_KERBEROS} != "no"
7470870SjulianSUBDIR+=kerberos5
7570870Sjulian.endif
7670870Sjulian.if ${MK_RESCUE} != "no"
7770870SjulianSUBDIR+=rescue
7853913Sarchie.endif
7953913SarchieSUBDIR+=sbin
8053913Sarchie.if ${MK_CRYPT} != "no"
8153246SarchieSUBDIR+=secure
8253404Sarchie.endif
8383186Sjulian.if !defined(NO_SHARE)
8453246SarchieSUBDIR+=share
8553246Sarchie.endif
86176917SmavSUBDIR+=sys usr.bin usr.sbin
8783186Sjulian.if ${MK_OFED} != "no"
8883186SjulianSUBDIR+=contrib/ofed
8983186Sjulian.endif
9083186Sjulian#
9183186Sjulian# We must do etc/ last for install/distribute to work.
9253246Sarchie#
9353404SarchieSUBDIR+=etc
9453246Sarchie
9583186Sjulian# These are last, since it is nice to at least get the base system
9683186Sjulian# rebuilt before you do them.
9783186Sjulian.for _DIR in ${LOCAL_LIB_DIRS} ${LOCAL_DIRS}
9883186Sjulian.if exists(${.CURDIR}/${_DIR}/Makefile)
9983186SjulianSUBDIR+= ${_DIR}
10083186Sjulian.endif
10183186Sjulian.endfor
10253246Sarchie.endif
10353246Sarchie
10453246Sarchie.if defined(NOCLEAN)
10570700SjulianNO_CLEAN=	${NOCLEAN}
10653246Sarchie.endif
10753246Sarchie.if defined(NO_CLEANDIR)
10883186SjulianCLEANDIR=	clean cleandepend
10953246Sarchie.else
11053246SarchieCLEANDIR=	cleandir
11153246Sarchie.endif
11253246Sarchie
11353246SarchieLOCAL_TOOL_DIRS?=
11453246Sarchie
11553246SarchieBUILDENV_SHELL?=/bin/sh
11653246Sarchie
11753246SarchieSVN?=		/usr/local/bin/svn
11853246SarchieSVNFLAGS?=	-r HEAD
11953246Sarchie
12053246SarchieMAKEOBJDIRPREFIX?=	/usr/obj
12153246Sarchie.if !defined(OSRELDATE)
12253246Sarchie.if exists(/usr/include/osreldate.h)
12353246SarchieOSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
12453246Sarchie		/usr/include/osreldate.h
12553246Sarchie.else
12653246SarchieOSRELDATE=	0
12753246Sarchie.endif
12853246Sarchie.endif
12953246Sarchie
13053246Sarchie.if !defined(VERSION)
13153246SarchieVERSION!=	uname -srp
13253246SarchieVERSION+=	${OSRELDATE}
13353246Sarchie.endif
13453246Sarchie
13553246SarchieKNOWN_ARCHES?=	amd64 arm armeb/arm armv6/arm i386 i386/pc98 ia64 mips mipsel/mips mips64el/mips mips64/mips mipsn32el/mips mipsn32/mips powerpc powerpc64/powerpc sparc64
13653246Sarchie.if ${TARGET} == ${TARGET_ARCH}
13753246Sarchie_t=		${TARGET}
13853246Sarchie.else
13953246Sarchie_t=		${TARGET_ARCH}/${TARGET}
14053246Sarchie.endif
14153246Sarchie.for _t in ${_t}
14284776Sarchie.if empty(KNOWN_ARCHES:M${_t})
14353246Sarchie.error Unknown target ${TARGET_ARCH}:${TARGET}.
14453246Sarchie.endif
14553246Sarchie.endfor
14653246Sarchie
14753246Sarchie.if ${TARGET} == ${MACHINE}
14853246SarchieTARGET_CPUTYPE?=${CPUTYPE}
14953246Sarchie.else
15053246SarchieTARGET_CPUTYPE?=
15153246Sarchie.endif
15253246Sarchie
153119187Shsu.if !empty(TARGET_CPUTYPE)
15453246Sarchie_TARGET_CPUTYPE=${TARGET_CPUTYPE}
15553246Sarchie.else
15653246Sarchie_TARGET_CPUTYPE=dummy
15753246Sarchie.endif
15853246Sarchie_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
15953913Sarchie		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
16083186Sjulian.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
16183186Sjulian.error CPUTYPE global should be set with ?=.
162193272Sjhb.endif
16353913Sarchie.if make(buildworld)
16453913SarchieBUILD_ARCH!=	uname -p
16583186Sjulian.if ${MACHINE_ARCH} != ${BUILD_ARCH}
166176917Smav.error To cross-build, set TARGET_ARCH.
16753913Sarchie.endif
16853913Sarchie.endif
16953913Sarchie.if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
17053913SarchieOBJTREE=	${MAKEOBJDIRPREFIX}
17153913Sarchie.else
17253913SarchieOBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
17353913Sarchie.endif
17453913SarchieWORLDTMP=	${OBJTREE}${.CURDIR}/tmp
17553913Sarchie# /usr/games added for fortune which depend on strfile
17653913SarchieBPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin
17753913SarchieXPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
17853913SarchieSTRICTTMPPATH=	${BPATH}:${XPATH}
17953913SarchieTMPPATH=	${STRICTTMPPATH}:${PATH}
18064470Sarchie
18153913Sarchie#
18253913Sarchie# Avoid running mktemp(1) unless actually needed.
18353913Sarchie# It may not be functional, e.g., due to new ABI
18453913Sarchie# when in the middle of installing over this system.
18553913Sarchie#
18653913Sarchie.if make(distributeworld) || make(installworld)
18753913SarchieINSTALLTMP!=	/usr/bin/mktemp -d -u -t install
18853913Sarchie.endif
18953913Sarchie
19097685Sarchie#
19197685Sarchie# Building a world goes through the following stages
19264508Sarchie#
19364508Sarchie# 1. legacy stage [BMAKE]
19453913Sarchie#	This stage is responsible for creating compatibility
19553913Sarchie#	shims that are needed by the bootstrap-tools,
19653913Sarchie#	build-tools and cross-tools stages.
19753913Sarchie# 1. bootstrap-tools stage [BMAKE]
19853913Sarchie#	This stage is responsible for creating programs that
19997685Sarchie#	are needed for backward compatibility reasons. They
20053913Sarchie#	are not built as cross-tools.
20153913Sarchie# 2. build-tools stage [TMAKE]
20253913Sarchie#	This stage is responsible for creating the object
20353913Sarchie#	tree and building any tools that are needed during
20453913Sarchie#	the build process.
20553913Sarchie# 3. cross-tools stage [XMAKE]
20653913Sarchie#	This stage is responsible for creating any tools that
20753913Sarchie#	are needed for cross-builds. A cross-compiler is one
20853913Sarchie#	of them.
20953913Sarchie# 4. world stage [WMAKE]
21053913Sarchie#	This stage actually builds the world.
21153913Sarchie# 5. install stage (optional) [IMAKE]
21253913Sarchie#	This stage installs a previously built world.
21353913Sarchie#
21453913Sarchie
21553913SarchieBOOTSTRAPPING?=	0
21653913Sarchie
21753913Sarchie# Common environment for world related stages
21853913SarchieCROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
21953913Sarchie		MACHINE_ARCH=${TARGET_ARCH} \
22053913Sarchie		MACHINE=${TARGET} \
22153913Sarchie		CPUTYPE=${TARGET_CPUTYPE}
22253913Sarchie.if ${MK_GROFF} != "no"
22353913SarchieCROSSENV+=	GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
22453913Sarchie		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
22553913Sarchie		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
22653913Sarchie.endif
22753913Sarchie
22853913Sarchie# bootstrap-tools stage
22953913SarchieBMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
23053913Sarchie		PATH=${BPATH}:${PATH} \
23153913Sarchie		WORLDTMP=${WORLDTMP} \
23253913Sarchie		VERSION="${VERSION}" \
23353913Sarchie		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
23453913Sarchie		COMPILER_TYPE=${COMPILER_TYPE}
23553913SarchieBMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
23653913Sarchie		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
23753913Sarchie		DESTDIR= \
23853913Sarchie		BOOTSTRAPPING=${OSRELDATE} \
23953913Sarchie		SSP_CFLAGS= \
24053913Sarchie		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
24153913Sarchie		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
24253913Sarchie		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD
24353913Sarchie
24453913Sarchie# build-tools stage
24553913SarchieTMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
24653913Sarchie		${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
24753913Sarchie		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
24853913Sarchie		DESTDIR= \
24953913Sarchie		BOOTSTRAPPING=${OSRELDATE} \
25068845Sbrian		SSP_CFLAGS= \
25153913Sarchie		-DNO_LINT \
25253913Sarchie		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD
25353913Sarchie
254184205Sdes# cross-tools stage
25553913SarchieXMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
25653913Sarchie		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
25753913Sarchie		-DWITHOUT_GDB
258184205Sdes
25953913Sarchie# world stage
26053913SarchieWMAKEENV=	${CROSSENV} \
26153913Sarchie		_SHLIBDIRPREFIX=${WORLDTMP} \
26253913Sarchie		_LDSCRIPTROOT= \
26353913Sarchie		VERSION="${VERSION}" \
264184205Sdes		INSTALL="sh ${.CURDIR}/tools/install.sh" \
26553913Sarchie		PATH=${TMPPATH}
26653913Sarchie
26753913Sarchie# make hierarchy
26853913SarchieHMAKE=		PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
26953913Sarchie.if defined(NO_ROOT)
27053913SarchieHMAKE+=		PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
27153913Sarchie.endif
27253913Sarchie
27353913Sarchie.if ${MK_CDDL} == "no"
27453913SarchieWMAKEENV+=	NO_CTF=1
27553913Sarchie.endif
27653913Sarchie
27753913Sarchie.if defined(CROSS_TOOLCHAIN_PREFIX)
27853913SarchieCROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
27953913SarchieCROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
28053913Sarchie.endif
28153913SarchieXCOMPILERS=	CC CXX CPP
28253913Sarchie.for COMPILER in ${XCOMPILERS}
28353913Sarchie.if defined(CROSS_COMPILER_PREFIX)
28453913SarchieX${COMPILER}?=	${CROSS_COMPILER_PREFIX}${${COMPILER}}
28553913Sarchie.else
28653913SarchieX${COMPILER}?=	${${COMPILER}}
28753913Sarchie.endif
28853913Sarchie.endfor
28953913SarchieXBINUTILS=	AS AR LD NM OBJDUMP RANLIB STRINGS
29053913Sarchie.for BINUTIL in ${XBINUTILS}
29153913Sarchie.if defined(CROSS_BINUTILS_PREFIX)
29253913SarchieX${BINUTIL}?=	${CROSS_BINUTILS_PREFIX}${${BINUTIL}}
29353913Sarchie.else
29453913SarchieX${BINUTIL}?=	${${BINUTIL}}
29553913Sarchie.endif
29653913Sarchie.endfor
29753913SarchieWMAKEENV+=	CC="${XCC} ${XFLAGS}" CXX="${XCXX} ${XFLAGS}" \
29853913Sarchie		CPP="${XCPP} ${XFLAGS}" \
29953913Sarchie		AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
30053913Sarchie		OBJDUMP=${XOBJDUMP} RANLIB=${XRANLIB} STRINGS=${XSTRINGS}
30153913Sarchie
30253913Sarchie.if ${XCC:T:Mgcc} == "gcc"
30353913SarchieWMAKE_COMPILER_TYPE=	gcc
30453913Sarchie.elif ${XCC:T:Mclang} == "clang"
30553913SarchieWMAKE_COMPILER_TYPE=	clang
30653913Sarchie.elif ${MK_CLANG_IS_CC} == "no"
30753913SarchieWMAKE_COMPILER_TYPE=	gcc
30853913Sarchie.else
30953913SarchieWMAKE_COMPILER_TYPE=	clang
31053913Sarchie.endif
31153913SarchieIMAKE_COMPILER_TYPE=	COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
31253913Sarchie
31353913Sarchie.if ${XCC:M/*}
31453913SarchieXFLAGS=		--sysroot=${WORLDTMP}
31553913Sarchie.if defined(CROSS_BINUTILS_PREFIX)
31653913Sarchie# In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
31753913Sarchie# directory, but the compiler will look in the right place for it's
31853913Sarchie# tools so we don't need to tell it where to look.
31953913Sarchie.if exists(${CROSS_BINUTILS_PREFIX})
32053913SarchieXFLAGS+=	-B${CROSS_BINUTILS_PREFIX}
32153913Sarchie.endif
32253913Sarchie.else
32353913SarchieXFLAGS+=	-B${WORLDTMP}/usr/bin
32453913Sarchie.endif
32553913Sarchie.if ${TARGET_ARCH} != ${MACHINE_ARCH} && ${WMAKE_COMPILER_TYPE} == "clang"
32653913Sarchie.if (${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "armv6") && \
32753913Sarchie${MK_ARM_EABI} != "no"
32853913SarchieTARGET_ABI=	gnueabi
32953913Sarchie.else
33053913SarchieTARGET_ABI=	unknown
33153913Sarchie.endif
33253913SarchieTARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd10.0
33353913SarchieXFLAGS+=	-target ${TARGET_TRIPLE}
33453913Sarchie.endif
33553913Sarchie.endif
33668845Sbrian
33753913SarchieWMAKEENV+=	COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
33853913SarchieWMAKE=		${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP}
339184205Sdes
34053913Sarchie.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64"
34153913Sarchie# 32 bit world
34253913SarchieLIB32TMP=	${OBJTREE}${.CURDIR}/lib32
34353913Sarchie
34453913Sarchie.if ${TARGET_ARCH} == "amd64"
34553913Sarchie.if empty(TARGET_CPUTYPE)
34653913SarchieLIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
34753913Sarchie.else
34853913SarchieLIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
34953913Sarchie.endif
35053913SarchieLIB32WMAKEENV=	MACHINE=i386 MACHINE_ARCH=i386 \
35153913Sarchie		MACHINE_CPU="i686 mmx sse sse2"
35253913SarchieLIB32WMAKEFLAGS=	\
35353913Sarchie		AS="${AS} --32" \
35453913Sarchie		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32"
35553913Sarchie
35653913Sarchie.elif ${TARGET_ARCH} == "powerpc64"
35753913Sarchie.if empty(TARGET_CPUTYPE)
35853913SarchieLIB32CPUFLAGS=	-mcpu=powerpc
35953913Sarchie.else
36053913SarchieLIB32CPUFLAGS=	-mcpu=${TARGET_CPUTYPE}
36153913Sarchie.endif
36253913SarchieLIB32WMAKEENV=	MACHINE=powerpc MACHINE_ARCH=powerpc
36353913SarchieLIB32WMAKEFLAGS=	\
36453913Sarchie		LD="${LD} -m elf32ppc_fbsd"
36553913Sarchie.endif
36653913Sarchie
36753913Sarchie
36853913SarchieLIB32FLAGS=	-m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \
36953913Sarchie		-isystem ${LIB32TMP}/usr/include/ \
37053913Sarchie		-L${LIB32TMP}/usr/lib32 \
37153913Sarchie		-B${LIB32TMP}/usr/lib32
37253913Sarchie.if ${XCC:M/*}
37353913SarchieLIB32FLAGS+=		--sysroot=${WORLDTMP}
37453913Sarchie.endif
37553913Sarchie
37653913Sarchie# Yes, the flags are redundant.
37753913SarchieLIB32WMAKEENV+=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
37853913Sarchie		_SHLIBDIRPREFIX=${LIB32TMP} \
37953913Sarchie		_LDSCRIPTROOT=${LIB32TMP} \
38053913Sarchie		VERSION="${VERSION}" \
38153913Sarchie		INSTALL="sh ${.CURDIR}/tools/install.sh" \
38253913Sarchie		PATH=${TMPPATH} \
38353913Sarchie		LIBDIR=/usr/lib32 \
38453913Sarchie		SHLIBDIR=/usr/lib32 \
38553913Sarchie		LIBPRIVATEDIR=/usr/lib32/private \
38653913Sarchie		COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
38753913SarchieLIB32WMAKEFLAGS+=	\
38853913Sarchie		CC="${XCC} ${LIB32FLAGS}" \
38953913Sarchie		CXX="${XCXX} ${LIB32FLAGS}" \
39053913Sarchie		DESTDIR=${LIB32TMP} \
39153913Sarchie		-DCOMPAT_32BIT \
39253913Sarchie		-DLIBRARIES_ONLY \
39353913Sarchie		-DNO_CPU_CFLAGS \
39453913Sarchie		-DNO_CTF \
39553913Sarchie		-DNO_LINT
39653913Sarchie
39753913SarchieLIB32WMAKE=	${LIB32WMAKEENV} ${MAKE} ${LIB32WMAKEFLAGS} \
39853913Sarchie		-DWITHOUT_MAN -DWITHOUT_INFO -DWITHOUT_HTML
39953913SarchieLIB32IMAKE=	${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} -DNO_INCS \
40053913Sarchie		${IMAKE_INSTALL}
40153913Sarchie.endif
40253913Sarchie
40353913SarchieIMAKEENV=	${CROSSENV:N_LDSCRIPTROOT=*}
40453913SarchieIMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1 \
40553913Sarchie		${IMAKE_INSTALL} ${IMAKE_MTREE} ${IMAKE_COMPILER_TYPE}
40653913Sarchie.if empty(.MAKEFLAGS:M-n)
40753913SarchieIMAKEENV+=	PATH=${STRICTTMPPATH}:${INSTALLTMP} \
40853913Sarchie		LD_LIBRARY_PATH=${INSTALLTMP} \
40953913Sarchie		PATH_LOCALE=${INSTALLTMP}/locale
41053913SarchieIMAKE+=		__MAKE_SHELL=${INSTALLTMP}/sh
41153913Sarchie.else
41253913SarchieIMAKEENV+=	PATH=${TMPPATH}:${INSTALLTMP}
41353913Sarchie.endif
41453913Sarchie.if defined(DB_FROM_SRC)
41553913SarchieINSTALLFLAGS+=	-N ${.CURDIR}/etc
41653913SarchieMTREEFLAGS+=	-N ${.CURDIR}/etc
41753913Sarchie.endif
41853913Sarchie_INSTALL_DDIR=	${DESTDIR}/${DISTDIR}
41997685SarchieINSTALL_DDIR=	${_INSTALL_DDIR:S://:/:g:C:/$::}
42053913Sarchie.if defined(NO_ROOT)
42153913SarchieMETALOG?=	${DESTDIR}/${DISTDIR}/METALOG
42253913SarchieIMAKE+=		-DNO_ROOT METALOG=${METALOG}
42397685SarchieINSTALLFLAGS+=	-U -M ${METALOG} -D ${INSTALL_DDIR}
42453913SarchieMTREEFLAGS+=	-W
42553913Sarchie.endif
42683186Sjulian.if defined(DB_FROM_SRC) || defined(NO_ROOT)
42797685SarchieIMAKE_INSTALL=	INSTALL="install ${INSTALLFLAGS}"
42883186SjulianIMAKE_MTREE=	MTREE_CMD="nmtree ${MTREEFLAGS}"
42983186Sjulian.endif
43083186Sjulian
43197685Sarchie# kernel stage
43283186SjulianKMAKEENV=	${WMAKEENV}
43383186SjulianKMAKE=		${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
43453913Sarchie
43553913Sarchie#
43653913Sarchie# buildworld
43753913Sarchie#
43853913Sarchie# Attempt to rebuild the entire system, with reasonable chance of
43953913Sarchie# success, regardless of how old your existing system is.
44053913Sarchie#
44153913Sarchie_worldtmp:
44253913Sarchie.if ${.CURDIR:C/[^,]//g} != ""
44353913Sarchie#	The m4 build of sendmail files doesn't like it if ',' is used
44453913Sarchie#	anywhere in the path of it's files.
44553913Sarchie	@echo
44653913Sarchie	@echo "*** Error: path to source tree contains a comma ','"
44753913Sarchie	@echo
44853913Sarchie	false
44953913Sarchie.endif
45053913Sarchie	@echo
45153913Sarchie	@echo "--------------------------------------------------------------"
45253913Sarchie	@echo ">>> Rebuilding the temporary build tree"
45353913Sarchie	@echo "--------------------------------------------------------------"
45453913Sarchie.if !defined(NO_CLEAN)
45583186Sjulian	rm -rf ${WORLDTMP}
45653913Sarchie.if defined(LIB32TMP)
45753913Sarchie	rm -rf ${LIB32TMP}
45853913Sarchie.endif
45953913Sarchie.else
46053913Sarchie	rm -rf ${WORLDTMP}/legacy/usr/include
46153913Sarchie#	XXX - These three can depend on any header file.
46283186Sjulian	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
46353913Sarchie	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
46453913Sarchie	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
46553913Sarchie.endif
46653913Sarchie.for _dir in \
46753913Sarchie    lib usr legacy/bin legacy/usr
46853913Sarchie	mkdir -p ${WORLDTMP}/${_dir}
46953913Sarchie.endfor
47053913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
47153913Sarchie	    -p ${WORLDTMP}/legacy/usr >/dev/null
47253913Sarchie.if ${MK_GROFF} != "no"
47353913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
47453913Sarchie	    -p ${WORLDTMP}/legacy/usr >/dev/null
47553913Sarchie.endif
47653913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
47753913Sarchie	    -p ${WORLDTMP}/usr >/dev/null
47853913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
47953913Sarchie	    -p ${WORLDTMP}/usr/include >/dev/null
48053913Sarchie	ln -sf ${.CURDIR}/sys ${WORLDTMP}
48153913Sarchie.if ${MK_DEBUG_FILES} != "no"
48253913Sarchie	# We could instead disable debug files for these build stages
48353913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
48453913Sarchie	    -p ${WORLDTMP}/legacy/usr/lib >/dev/null
48553913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
48653913Sarchie	    -p ${WORLDTMP}/usr/lib >/dev/null
48753913Sarchie.endif
48853913Sarchie.for _mtree in ${LOCAL_MTREE}
48953913Sarchie	mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
49053913Sarchie.endfor
49153913Sarchie_legacy:
49253913Sarchie	@echo
49353913Sarchie	@echo "--------------------------------------------------------------"
49453913Sarchie	@echo ">>> stage 1.1: legacy release compatibility shims"
49553913Sarchie	@echo "--------------------------------------------------------------"
49653913Sarchie	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
497129823Sjulian_bootstrap-tools:
498129823Sjulian	@echo
499129823Sjulian	@echo "--------------------------------------------------------------"
500129823Sjulian	@echo ">>> stage 1.2: bootstrap tools"
501129823Sjulian	@echo "--------------------------------------------------------------"
502129823Sjulian	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
503129823Sjulian_cleanobj:
504129823Sjulian.if !defined(NO_CLEAN)
505129823Sjulian	@echo
506129823Sjulian	@echo "--------------------------------------------------------------"
50753913Sarchie	@echo ">>> stage 2.1: cleaning up the object tree"
50853913Sarchie	@echo "--------------------------------------------------------------"
50953913Sarchie	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
51097658Stanimura.if defined(LIB32TMP)
51153246Sarchie	${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
51253246Sarchie.endif
51353246Sarchie.endif
51453246Sarchie_obj:
51553246Sarchie	@echo
51653246Sarchie	@echo "--------------------------------------------------------------"
51753246Sarchie	@echo ">>> stage 2.2: rebuilding the object tree"
51883186Sjulian	@echo "--------------------------------------------------------------"
51983186Sjulian	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
52053246Sarchie_build-tools:
52153246Sarchie	@echo
52270700Sjulian	@echo "--------------------------------------------------------------"
52353246Sarchie	@echo ">>> stage 2.3: build tools"
52453246Sarchie	@echo "--------------------------------------------------------------"
52553246Sarchie	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
52653246Sarchie_cross-tools:
527220768Sglebius	@echo
52853246Sarchie	@echo "--------------------------------------------------------------"
52983186Sjulian	@echo ">>> stage 3: cross tools"
53083186Sjulian	@echo "--------------------------------------------------------------"
53183186Sjulian	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
53270784Sjulian_includes:
53353246Sarchie	@echo
53453246Sarchie	@echo "--------------------------------------------------------------"
53553246Sarchie	@echo ">>> stage 4.1: building includes"
53653246Sarchie	@echo "--------------------------------------------------------------"
53753246Sarchie	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
53853246Sarchie_libraries:
53953246Sarchie	@echo
54072545Sarchie	@echo "--------------------------------------------------------------"
54153246Sarchie	@echo ">>> stage 4.2: building libraries"
54253246Sarchie	@echo "--------------------------------------------------------------"
54353246Sarchie	${_+_}cd ${.CURDIR}; \
54453246Sarchie	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
54553246Sarchie	    -DWITHOUT_MAN -DNO_PROFILE libraries
54653246Sarchie_depend:
54753246Sarchie	@echo
54853246Sarchie	@echo "--------------------------------------------------------------"
549134651Srwatson	@echo ">>> stage 4.3: make dependencies"
55070784Sjulian	@echo "--------------------------------------------------------------"
551125028Sharti	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
55253246Sarchieeverything:
55353246Sarchie	@echo
55453246Sarchie	@echo "--------------------------------------------------------------"
55553246Sarchie	@echo ">>> stage 4.4: building everything"
55653246Sarchie	@echo "--------------------------------------------------------------"
55753246Sarchie	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
55883186Sjulian.if defined(LIB32TMP)
55983186Sjulianbuild32:
56083186Sjulian	@echo
56183186Sjulian	@echo "--------------------------------------------------------------"
56283186Sjulian	@echo ">>> stage 5.1: building 32 bit shim libraries"
56383186Sjulian	@echo "--------------------------------------------------------------"
56483186Sjulian	mkdir -p ${LIB32TMP}/usr/include
56583186Sjulian	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
56683186Sjulian	    -p ${LIB32TMP}/usr >/dev/null
56783186Sjulian	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
56883186Sjulian	    -p ${LIB32TMP}/usr/include >/dev/null
56983186Sjulian.if ${MK_DEBUG_FILES} != "no"
57083186Sjulian	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
57183186Sjulian	    -p ${LIB32TMP}/usr/lib >/dev/null
57283186Sjulian.endif
57383186Sjulian	mkdir -p ${WORLDTMP}
57483186Sjulian	ln -sf ${.CURDIR}/sys ${WORLDTMP}
57583186Sjulian.for _t in obj includes
57683186Sjulian	cd ${.CURDIR}/include; ${LIB32WMAKE} DIRPRFX=include/ ${_t}
57783186Sjulian	cd ${.CURDIR}/lib; ${LIB32WMAKE} DIRPRFX=lib/ ${_t}
57883186Sjulian.if ${MK_CDDL} != "no"
57983186Sjulian	cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} DIRPRFX=cddl/lib/ ${_t}
58083186Sjulian.endif
58183186Sjulian	cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} DIRPRFX=gnu/lib/ ${_t}
58283186Sjulian.if ${MK_CRYPT} != "no"
58383186Sjulian	cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} DIRPRFX=secure/lib/ ${_t}
58483186Sjulian.endif
58553246Sarchie.if ${MK_KERBEROS} != "no"
58683186Sjulian	cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} DIRPRFX=kerberos5/lib ${_t}
58788739Srwatson.endif
58891406Sjhb.endfor
58983186Sjulian.for _dir in usr.bin/lex/lib
59083186Sjulian	cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} DIRPRFX=${_dir}/ obj
59153246Sarchie.endfor
59283186Sjulian.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
59353246Sarchie	cd ${.CURDIR}/${_dir}; \
59483186Sjulian	    WORLDTMP=${WORLDTMP} \
59583186Sjulian	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
59683186Sjulian	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \
59783186Sjulian	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF \
598145229Sglebius	    -DEARLY_BUILD build-tools
599145229Sglebius.endfor
600145229Sglebius	cd ${.CURDIR}; \
601145229Sglebius	    ${LIB32WMAKE} -f Makefile.inc1 libraries
602145229Sglebius.for _t in obj depend all
603145229Sglebius	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} \
604145229Sglebius	    DIRPRFX=libexec/rtld-elf/ ${_t}
605145229Sglebius	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} \
60683186Sjulian	    DIRPRFX=usr.bin/ldd ${_t}
60783186Sjulian.endfor
60883186Sjulian
60983186Sjuliandistribute32 install32:
61083186Sjulian	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
61183186Sjulian.if ${MK_CDDL} != "no"
61283186Sjulian	cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
61383186Sjulian.endif
61483186Sjulian	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
61583186Sjulian.if ${MK_CRYPT} != "no"
61683186Sjulian	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
617130653Srwatson.endif
618193272Sjhb.if ${MK_KERBEROS} != "no"
619130653Srwatson	cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
620130653Srwatson.endif
621193272Sjhb	cd ${.CURDIR}/libexec/rtld-elf; \
622130653Srwatson	    PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
623130653Srwatson	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//}
62483186Sjulian.endif
625130653Srwatson
62683186SjulianWMAKE_TGTS=
62783186Sjulian.if !defined(SUBDIR_OVERRIDE)
62883186SjulianWMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
62983186Sjulian.endif
63083186SjulianWMAKE_TGTS+=	_cleanobj _obj _build-tools
63183186Sjulian.if !defined(SUBDIR_OVERRIDE)
63283186SjulianWMAKE_TGTS+=	_cross-tools
63383186Sjulian.endif
63483186SjulianWMAKE_TGTS+=	_includes _libraries _depend everything
63583186Sjulian.if defined(LIB32TMP) && ${MK_LIB32} != "no"
63683186SjulianWMAKE_TGTS+=	build32
63783186Sjulian.endif
63883186Sjulian
63983186Sjulianbuildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
64083186Sjulian.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
64183186Sjulian
64283186Sjulianbuildworld_prologue:
64383186Sjulian	@echo "--------------------------------------------------------------"
64483186Sjulian	@echo ">>> World build started on `LC_ALL=C date`"
64583186Sjulian	@echo "--------------------------------------------------------------"
64683186Sjulian
64783186Sjulianbuildworld_epilogue:
64883186Sjulian	@echo
64983186Sjulian	@echo "--------------------------------------------------------------"
65083186Sjulian	@echo ">>> World build completed on `LC_ALL=C date`"
65183186Sjulian	@echo "--------------------------------------------------------------"
65283186Sjulian
65383186Sjulian#
65483186Sjulian# We need to have this as a target because the indirection between Makefile
65583186Sjulian# and Makefile.inc1 causes the correct PATH to be used, rather than a
65683186Sjulian# modification of the current environment's PATH.  In addition, we need
65783186Sjulian# to quote multiword values.
65883186Sjulian#
65983186Sjulianbuildenvvars:
66053246Sarchie	@echo ${WMAKEENV:Q}
66153246Sarchie
66253246Sarchiebuildenv:
66353246Sarchie	@echo Entering world for ${TARGET_ARCH}:${TARGET}
66453246Sarchie	@cd ${.CURDIR} && env ${WMAKEENV} ${BUILDENV_SHELL} || true
66553246Sarchie
66653246SarchieTOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
66753246Sarchietoolchain: ${TOOLCHAIN_TGTS}
66870700Sjuliankernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
66953246Sarchie
670134651Srwatson#
67170784Sjulian# installcheck
67253913Sarchie#
67353246Sarchie# Checks to be sure system is ready for installworld/installkernel.
67453246Sarchie#
67570700Sjulianinstallcheck: _installcheck_world _installcheck_kernel
67683186Sjulian_installcheck_world:
67753246Sarchie_installcheck_kernel:
67870700Sjulian
67953246Sarchie#
68053246Sarchie# Require DESTDIR to be set if installing for a different architecture or
68153246Sarchie# using the user/group database in the source tree.
68253246Sarchie#
68353246Sarchie.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
68453913Sarchie    defined(DB_FROM_SRC)
68553913Sarchie.if !make(distributeworld)
68653246Sarchie_installcheck_world: __installcheck_DESTDIR
68753913Sarchie_installcheck_kernel: __installcheck_DESTDIR
68853913Sarchie__installcheck_DESTDIR:
68953913Sarchie.if !defined(DESTDIR) || empty(DESTDIR)
69053913Sarchie	@echo "ERROR: Please set DESTDIR!"; \
69153913Sarchie	false
69253913Sarchie.endif
69353246Sarchie.endif
69453913Sarchie.endif
69583366Sjulian
69653246Sarchie.if !defined(DB_FROM_SRC)
69753246Sarchie#
69853246Sarchie# Check for missing UIDs/GIDs.
69953246Sarchie#
70053913SarchieCHECK_UIDS=	auditdistd
70183186SjulianCHECK_GIDS=	audit
70253246Sarchie.if ${MK_SENDMAIL} != "no"
70353913SarchieCHECK_UIDS+=	smmsp
70453913SarchieCHECK_GIDS+=	smmsp
70553246Sarchie.endif
70653913Sarchie.if ${MK_PF} != "no"
70783366SjulianCHECK_UIDS+=	proxy
70853246SarchieCHECK_GIDS+=	proxy authpf
70953246Sarchie.endif
71053246Sarchie.if ${MK_UNBOUND} != "no"
71153246SarchieCHECK_UIDS+=	unbound
71253246SarchieCHECK_GIDS+=	unbound
71353913Sarchie.endif
71453913Sarchie_installcheck_world: __installcheck_UGID
71553913Sarchie__installcheck_UGID:
71653913Sarchie.for uid in ${CHECK_UIDS}
71753913Sarchie	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
71853913Sarchie		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
71983186Sjulian		false; \
72083186Sjulian	fi
72197658Stanimura.endfor
72283186Sjulian.for gid in ${CHECK_GIDS}
72383186Sjulian	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
72453913Sarchie		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
72583186Sjulian		false; \
72683186Sjulian	fi
72783186Sjulian.endfor
72883186Sjulian.endif
72983186Sjulian
73083186Sjulian#
73183186Sjulian# Required install tools to be saved in a scratch dir for safety.
73283186Sjulian#
73383186Sjulian.if ${MK_INFO} != "no"
73483186Sjulian_install-info=	install-info
735103205Sbenno.endif
73683186Sjulian.if ${MK_ZONEINFO} != "no"
73783186Sjulian_zoneinfo=	zic tzsetup
73883186Sjulian.endif
73983186Sjulian
74053246Sarchie.if exists(/usr/sbin/nmtree)
74153246Sarchie_nmtree_itools=	nmtree
74253246Sarchie.endif
74353246Sarchie
74453246SarchieITOOLS=	[ awk cap_mkdb cat chflags chmod chown \
74553913Sarchie	date echo egrep find grep id install ${_install-info} \
74653913Sarchie	ln lockf make mkdir mtree ${_nmtree_itools} mv pwd_mkdb \
74753246Sarchie	rm sed sh sysctl test true uname wc ${_zoneinfo}
74853913Sarchie
74953913Sarchie#
75053913Sarchie# distributeworld
75153913Sarchie#
75253913Sarchie# Distributes everything compiled by a `buildworld'.
75353913Sarchie#
75453246Sarchie# installworld
75553246Sarchie#
75653246Sarchie# Installs everything compiled by a 'buildworld'.
75797658Stanimura#
75883366Sjulian
75953246Sarchie# Non-base distributions produced by the base system
76097658StanimuraEXTRA_DISTRIBUTIONS=	doc
76153246Sarchie.if ${MK_GAMES} != "no"
762114178SarchieEXTRA_DISTRIBUTIONS+=	games
76383186Sjulian.endif
76483186Sjulian.if defined(LIB32TMP) && ${MK_LIB32} != "no"
765103205SbennoEXTRA_DISTRIBUTIONS+=	lib32
76683186Sjulian.endif
76797658Stanimura
768114178SarchieMTREE_MAGIC?=	mtree 2.0
76953246Sarchie
77053246Sarchiedistributeworld installworld: _installcheck_world
77153246Sarchie	mkdir -p ${INSTALLTMP}
77253246Sarchie	progs=$$(for prog in ${ITOOLS}; do \
77353913Sarchie		if progpath=`which $$prog`; then \
77453246Sarchie			echo $$progpath; \
77553913Sarchie		else \
77653913Sarchie			echo "Required tool $$prog not found in PATH." >&2; \
77753913Sarchie			exit 1; \
77853246Sarchie		fi; \
77953913Sarchie	    done); \
78053913Sarchie	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
78153913Sarchie	    while read line; do \
78253913Sarchie		set -- $$line; \
78353913Sarchie		if [ "$$2 $$3" != "not found" ]; then \
78453913Sarchie			echo $$2; \
78553913Sarchie		else \
78653913Sarchie			echo "Required library $$1 not found." >&2; \
78753913Sarchie			exit 1; \
78853913Sarchie		fi; \
78997658Stanimura	    done); \
79053913Sarchie	cp $$libs $$progs ${INSTALLTMP}
79153913Sarchie	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
79253913Sarchie.if defined(NO_ROOT)
79353913Sarchie	echo "#${MTREE_MAGIC}" > ${METALOG}
79453913Sarchie.endif
79553913Sarchie.if make(distributeworld)
79653913Sarchie.for dist in ${EXTRA_DISTRIBUTIONS}
79753913Sarchie	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
79853913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
79953913Sarchie	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
80053913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
80153913Sarchie	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
80253913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
80353913Sarchie	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
80453913Sarchie.if ${MK_DEBUG_FILES} != "no"
80553913Sarchie	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
80653913Sarchie	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
80753913Sarchie.endif
80853913Sarchie.if defined(NO_ROOT)
80953913Sarchie	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
810184205Sdes	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
81153246Sarchie	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
81253246Sarchie	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
81353246Sarchie	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
81453246Sarchie	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
81553246Sarchie.endif
81653913Sarchie.endfor
81753913Sarchie	-mkdir ${DESTDIR}/${DISTDIR}/base
81853913Sarchie	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
81953913Sarchie	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
82053913Sarchie	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
82153913Sarchie	    LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
82253913Sarchie.endif
82353913Sarchie	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
82453913Sarchie	    ${IMAKEENV} rm -rf ${INSTALLTMP}
82553913Sarchie.if make(distributeworld)
82653913Sarchie.for dist in ${EXTRA_DISTRIBUTIONS}
82753913Sarchie	find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -empty -delete
82853913Sarchie.endfor
82953913Sarchie.if defined(NO_ROOT)
83053913Sarchie.for dist in base ${EXTRA_DISTRIBUTIONS}
83153913Sarchie	@# For each file that exists in this dist, print the corresponding
83253913Sarchie	@# line from the METALOG.  This relies on the fact that
83353913Sarchie	@# a line containing only the filename will sort immediatly before
83453913Sarchie	@# the relevant mtree line.
83553913Sarchie	cd ${DESTDIR}/${DISTDIR}; \
83683366Sjulian	find ./${dist} | sort -u ${METALOG} - | \
83753913Sarchie	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
83853913Sarchie	${DESTDIR}/${DISTDIR}/${dist}.meta
83953913Sarchie.endfor
84053913Sarchie.if ${MK_DEBUG_FILES} != "no"
84170700Sjulian. for dist in base ${EXTRA_DISTRIBUTIONS}
84253913Sarchie	@# For each file that exists in this dist, print the corresponding
84353913Sarchie	@# line from the METALOG.  This relies on the fact that
84453913Sarchie	@# a line containing only the filename will sort immediatly before
84553913Sarchie	@# the relevant mtree line.
84653913Sarchie	cd ${DESTDIR}/${DISTDIR}; \
84753913Sarchie	find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
84853246Sarchie	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
84953246Sarchie	${DESTDIR}/${DISTDIR}/${dist}.debug.meta
85053246Sarchie. endfor
85153246Sarchie.endif
85253246Sarchie.endif
85353913Sarchie.endif
85453913Sarchie
85553913Sarchiepackageworld:
85653913Sarchie.for dist in base ${EXTRA_DISTRIBUTIONS}
85753913Sarchie.if defined(NO_ROOT)
85853913Sarchie	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
85953913Sarchie	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
86053913Sarchie	    --exclude usr/lib/debug \
86153913Sarchie	    @${DESTDIR}/${DISTDIR}/${dist}.meta
86253913Sarchie.else
86353913Sarchie	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
86453913Sarchie	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
86553913Sarchie	    --exclude usr/lib/debug .
86653913Sarchie.endif
86753913Sarchie.endfor
86853913Sarchie
86953913Sarchie.if ${MK_DEBUG_FILES} != "no"
87083366Sjulian. for dist in base ${EXTRA_DISTRIBUTIONS}
87153913Sarchie.  if defined(NO_ROOT)
87253246Sarchie	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
87353246Sarchie	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.debug.txz \
87453246Sarchie	    @${DESTDIR}/${DISTDIR}/${dist}.debug.meta
87553246Sarchie.  else
87653246Sarchie	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
87753246Sarchie	    tar cvJfL ${DESTDIR}/${DISTDIR}/${dist}.debug.txz \
87853246Sarchie	    usr/lib/debug
87953246Sarchie.  endif
88053246Sarchie. endfor
88153246Sarchie.endif
88253246Sarchie
88353246Sarchie#
88453246Sarchie# reinstall
88570700Sjulian#
88670700Sjulian# If you have a build server, you can NFS mount the source and obj directories
88753246Sarchie# and do a 'make reinstall' on the *client* to install new binaries from the
88853246Sarchie# most recent server build.
88953246Sarchie#
89053246Sarchiereinstall:
89153246Sarchie	@echo "--------------------------------------------------------------"
89253246Sarchie	@echo ">>> Making hierarchy"
89353246Sarchie	@echo "--------------------------------------------------------------"
89470700Sjulian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
89553246Sarchie	    LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
896134651Srwatson	@echo
89770784Sjulian	@echo "--------------------------------------------------------------"
89870784Sjulian	@echo ">>> Installing everything"
89953246Sarchie	@echo "--------------------------------------------------------------"
90087070Sarchie	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
90153246Sarchie.if defined(LIB32TMP) && ${MK_LIB32} != "no"
90270700Sjulian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
903206017Smav.endif
904206017Smav
905206017Smavredistribute:
906131108Sjulian	@echo "--------------------------------------------------------------"
90753246Sarchie	@echo ">>> Distributing everything"
908131108Sjulian	@echo "--------------------------------------------------------------"
90970700Sjulian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
91070700Sjulian.if defined(LIB32TMP) && ${MK_LIB32} != "no"
911206017Smav	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
912206017Smav	    DISTRIBUTION=lib32
913206017Smav.endif
914206017Smav
915206017Smavdistrib-dirs distribution:
916206017Smav	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
917206017Smav	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
918206017Smav
919206017Smav#
920206017Smav# buildkernel and installkernel
921141728Sglebius#
922141728Sglebius# Which kernels to build and/or install is specified by setting
923141728Sglebius# KERNCONF. If not defined a GENERIC kernel is built/installed.
924141728Sglebius# Only the existing (depending TARGET) config files are used
925141728Sglebius# for building kernels and only the first of these is designated
926141728Sglebius# as the one being installed.
927141728Sglebius#
928141728Sglebius# Note that we have to use TARGET instead of TARGET_ARCH when
929131108Sjulian# we're in kernel-land. Since only TARGET_ARCH is (expected) to
93087070Sarchie# be set to cross-build, we have to make sure TARGET is set
931166585Sbms# properly.
932166585Sbms
933166585Sbms.if defined(KERNFAST)
93487070SarchieNO_KERNELCLEAN=	t
935160619SrwatsonNO_KERNELCONFIG=	t
93687070SarchieNO_KERNELDEPEND=	t
93753246SarchieNO_KERNELOBJ=		t
93853246Sarchie# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
93953246Sarchie.if !defined(KERNCONF) && ${KERNFAST} != "1"
94053246SarchieKERNCONF=${KERNFAST}
94153246Sarchie.endif
94253246Sarchie.endif
94353246Sarchie.if ${TARGET_ARCH} == "powerpc64"
94470700SjulianKERNCONF?=	GENERIC64
94553246Sarchie.else
94670784SjulianKERNCONF?=	GENERIC
94783186Sjulian.endif
94853246SarchieINSTKERNNAME?=	kernel
94953404Sarchie
95053404SarchieKERNSRCDIR?=	${.CURDIR}/sys
951130653SrwatsonKRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
952193272SjhbKRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
953130653SrwatsonKERNCONFDIR?=	${KRNLCONFDIR}
954130653Srwatson
955193272SjhbBUILDKERNELS=
956130653SrwatsonINSTALLKERNEL=
95753404Sarchie.for _kernel in ${KERNCONF}
95853404Sarchie.if exists(${KERNCONFDIR}/${_kernel})
95953404SarchieBUILDKERNELS+=	${_kernel}
96053404Sarchie.if empty(INSTALLKERNEL)
96183186SjulianINSTALLKERNEL= ${_kernel}
96283186Sjulian.endif
96383186Sjulian.endif
96483186Sjulian.endfor
96583186Sjulian
96683186Sjulian#
96783186Sjulian# buildkernel
96883186Sjulian#
96983186Sjulian# Builds all kernels defined by BUILDKERNELS.
97083186Sjulian#
97183186Sjulianbuildkernel:
97283186Sjulian.if empty(BUILDKERNELS)
97353246Sarchie	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
97453246Sarchie	false
975184205Sdes.endif
97670784Sjulian	@echo
97770784Sjulian.for _kernel in ${BUILDKERNELS}
97853246Sarchie	@echo "--------------------------------------------------------------"
97953246Sarchie	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
98053246Sarchie	@echo "--------------------------------------------------------------"
98153246Sarchie	@echo "===> ${_kernel}"
98253246Sarchie	mkdir -p ${KRNLOBJDIR}
98353246Sarchie.if !defined(NO_KERNELCONFIG)
98453246Sarchie	@echo
98553246Sarchie	@echo "--------------------------------------------------------------"
98653246Sarchie	@echo ">>> stage 1: configuring the kernel"
98770784Sjulian	@echo "--------------------------------------------------------------"
98887599Sobrien	cd ${KRNLCONFDIR}; \
98972545Sarchie		PATH=${TMPPATH} \
99070784Sjulian		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
99170784Sjulian			${KERNCONFDIR}/${_kernel}
99253246Sarchie.endif
99353246Sarchie.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
99453246Sarchie	@echo
99553246Sarchie	@echo "--------------------------------------------------------------"
99653246Sarchie	@echo ">>> stage 2.1: cleaning up the object tree"
99753246Sarchie	@echo "--------------------------------------------------------------"
99883186Sjulian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
999176917Smav.endif
1000176917Smav.if !defined(NO_KERNELOBJ)
1001176917Smav	@echo
1002176917Smav	@echo "--------------------------------------------------------------"
100383186Sjulian	@echo ">>> stage 2.2: rebuilding the object tree"
100483186Sjulian	@echo "--------------------------------------------------------------"
100583186Sjulian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1006149820Sglebius.endif
1007149820Sglebius	@echo
100883186Sjulian	@echo "--------------------------------------------------------------"
100953246Sarchie	@echo ">>> stage 2.3: build tools"
1010193272Sjhb	@echo "--------------------------------------------------------------"
101183186Sjulian	cd ${KRNLOBJDIR}/${_kernel}; \
101283186Sjulian	    PATH=${BPATH}:${PATH} \
101383186Sjulian	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
1014176917Smav	    ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF -DEARLY_BUILD \
1015176917Smav	    -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
101683186Sjulian# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
1017176917Smav.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
1018176917Smav.for target in obj depend all
1019176917Smav	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
1020176917Smav	    PATH=${BPATH}:${PATH} \
1021176917Smav	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
1022176917Smav	    ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF -DEARLY_BUILD ${target}
1023176917Smav.endfor
1024176917Smav.endif
1025176917Smav.if !defined(NO_KERNELDEPEND)
1026176917Smav	@echo
1027193272Sjhb	@echo "--------------------------------------------------------------"
102883186Sjulian	@echo ">>> stage 3.1: making dependencies"
102983186Sjulian	@echo "--------------------------------------------------------------"
103083186Sjulian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
103153246Sarchie.endif
103253246Sarchie	@echo
103383186Sjulian	@echo "--------------------------------------------------------------"
103483186Sjulian	@echo ">>> stage 3.2: building everything"
103583186Sjulian	@echo "--------------------------------------------------------------"
1036176917Smav	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
103753246Sarchie	@echo "--------------------------------------------------------------"
103853246Sarchie	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1039176917Smav	@echo "--------------------------------------------------------------"
104053246Sarchie.endfor
104183186Sjulian
104270784Sjulian#
104353246Sarchie# installkernel, etc.
104483186Sjulian#
104553246Sarchie# Install the kernel defined by INSTALLKERNEL
104653404Sarchie#
104753246Sarchieinstallkernel installkernel.debug \
104853404Sarchiereinstallkernel reinstallkernel.debug: _installcheck_kernel
104953404Sarchie.if empty(INSTALLKERNEL)
105083186Sjulian	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
105187599Sobrien	false
1052176917Smav.endif
1053176917Smav	@echo "--------------------------------------------------------------"
1054176917Smav	@echo ">>> Installing kernel ${INSTALLKERNEL}"
105553246Sarchie	@echo "--------------------------------------------------------------"
105683186Sjulian	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
105783186Sjulian	    ${CROSSENV} PATH=${TMPPATH} \
105883186Sjulian	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
105983186Sjulian
106083186Sjuliandistributekernel distributekernel.debug:
106183186Sjulian.if empty(INSTALLKERNEL)
106283186Sjulian	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
106383186Sjulian	false
1064176917Smav.endif
106583186Sjulian	mkdir -p ${DESTDIR}/${DISTDIR}
106683186Sjulian.if defined(NO_ROOT)
106783186Sjulian	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
106883186Sjulian.endif
106983186Sjulian	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
107083186Sjulian	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
107183186Sjulian	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
107283186Sjulian	    DESTDIR=${INSTALL_DDIR}/kernel \
107383186Sjulian	    ${.TARGET:S/distributekernel/install/}
1074102244Sarchie.if defined(NO_ROOT)
1075102244Sarchie	sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
107683186Sjulian	    ${DESTDIR}/${DISTDIR}/kernel.meta
107783186Sjulian.endif
107897658Stanimura.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
107983186Sjulian.if defined(NO_ROOT)
108083186Sjulian	echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
108183186Sjulian.endif
108283186Sjulian	cd ${KRNLOBJDIR}/${_kernel}; \
108383186Sjulian	    ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
108483186Sjulian	    ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
108583186Sjulian	    KERNEL=${INSTKERNNAME}.${_kernel} \
108683186Sjulian	    DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
108783186Sjulian	    ${.TARGET:S/distributekernel/install/}
108883186Sjulian.if defined(NO_ROOT)
108983186Sjulian	sed -e 's|^./kernel|.|' \
109083186Sjulian	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
109183186Sjulian	    ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
109283186Sjulian.endif
109383186Sjulian.endfor
109483186Sjulian
109583186Sjulianpackagekernel:
109683186Sjulian.if defined(NO_ROOT)
109783186Sjulian	cd ${DESTDIR}/${DISTDIR}/kernel; \
109883186Sjulian	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz \
109983186Sjulian	    @${DESTDIR}/${DISTDIR}/kernel.meta
110053246Sarchie.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
110183366Sjulian	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
110253246Sarchie	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz \
110353246Sarchie	    @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
110487070Sarchie.endfor
110587070Sarchie.else
110687070Sarchie	cd ${DESTDIR}/${DISTDIR}/kernel; \
110787070Sarchie	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz .
110887070Sarchie.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1109160619Srwatson	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1110160619Srwatson	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz .
111187070Sarchie.endfor
111253913Sarchie.endif
111387070Sarchie
111487070Sarchie#
111587070Sarchie# doxygen
1116184205Sdes#
111787070Sarchie# Build the API documentation with doxygen
111853913Sarchie#
111983186Sjuliandoxygen:
1120149820Sglebius	@if [ ! -x `/usr/bin/which doxygen` ]; then \
1121149820Sglebius		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1122149820Sglebius		exit 1; \
1123149820Sglebius	fi
1124149820Sglebius	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
1125149820Sglebius
1126149820Sglebius#
1127155877Sru# update
1128149820Sglebius#
112987070Sarchie# Update the source tree(s), by running svn/svnup to update to the
1130149820Sglebius# latest copy.
1131149820Sglebius#
113287070Sarchieupdate:
1133131108Sjulian.if (defined(CVS_UPDATE) || defined(SUP_UPDATE)) && !defined(SVN_UPDATE)
113487070Sarchie	@echo "--------------------------------------------------------------"
1135131108Sjulian	@echo "CVS_UPDATE and SUP_UPDATE are no longer supported."
113687070Sarchie	@echo "Please see: https://wiki.freebsd.org/CvsIsDeprecated"
1137131108Sjulian	@echo "--------------------------------------------------------------"
1138141743Sglebius	@exit 1
1139141743Sglebius.endif
1140131108Sjulian.if defined(SVN_UPDATE)
1141184205Sdes	@echo "--------------------------------------------------------------"
114287070Sarchie	@echo ">>> Updating ${.CURDIR} using Subversion"
114387070Sarchie	@echo "--------------------------------------------------------------"
1144131108Sjulian	@(cd ${.CURDIR} && ${SVN} update ${SVNFLAGS})
1145184205Sdes.endif
1146141728Sglebius
1147131108Sjulian#
114887070Sarchie# ------------------------------------------------------------------------
114987070Sarchie#
1150131108Sjulian# From here onwards are utility targets used by the 'make world' and
1151131108Sjulian# related targets.  If your 'world' breaks, you may like to try to fix
115287070Sarchie# the problem and manually run the following targets to attempt to
115387070Sarchie# complete the build.  Beware, this is *not* guaranteed to work, you
115483186Sjulian# need to have a pretty good grip on the current state of the system
115583186Sjulian# to attempt to manually finish it.  If in doubt, 'make world' again.
115683186Sjulian#
115783186Sjulian
1158130480Srwatson#
1159176917Smav# legacy: Build compatibility shims for the next three targets
116083186Sjulian#
116183186Sjulianlegacy:
116283186Sjulian.if ${BOOTSTRAPPING} < 700055 && ${BOOTSTRAPPING} != 0
116383186Sjulian	@echo "ERROR: Source upgrades from versions prior to 7.0 not supported."; \
116483186Sjulian	false
116597658Stanimura.endif
116653404Sarchie.for _tool in tools/build
116753246Sarchie	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
116853246Sarchie	    cd ${.CURDIR}/${_tool} && \
116953246Sarchie	    ${MAKE} DIRPRFX=${_tool}/ obj && \
117083186Sjulian	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes && \
117183186Sjulian	    ${MAKE} DIRPRFX=${_tool}/ depend && \
117283186Sjulian	    ${MAKE} DIRPRFX=${_tool}/ all && \
117383186Sjulian	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
117483186Sjulian.endfor
117583186Sjulian
117683186Sjulian#
117783186Sjulian# bootstrap-tools: Build tools needed for compatibility
117883186Sjulian#
117983186Sjulian.if ${MK_GAMES} != "no"
118083186Sjulian_strfile=	games/fortune/strfile
118183186Sjulian.endif
118283186Sjulian
1183129979Srwatson.if ${MK_CXX} != "no"
118483186Sjulian_gperf=		gnu/usr.bin/gperf
1185130480Srwatson.endif
118683186Sjulian
118783186Sjulian.if ${MK_GROFF} != "no"
118883186Sjulian_groff=		gnu/usr.bin/groff
118983186Sjulian.endif
119083186Sjulian
119183186Sjulian.if ${BOOTSTRAPPING} < 800022
119283186Sjulian_ar=		usr.bin/ar
119383186Sjulian.endif
119483186Sjulian
119583186Sjulian.if ${BOOTSTRAPPING} < 800013
119683186Sjulian_mklocale=	usr.bin/mklocale
119783186Sjulian.endif
119883186Sjulian
119983186Sjulian.if ${BOOTSTRAPPING} < 900002
120083186Sjulian_sed=		usr.bin/sed
120183186Sjulian.endif
120283186Sjulian
120383186Sjulian.if ${BOOTSTRAPPING} < 900006
120483186Sjulian_lex=		usr.bin/lex
120583186Sjulian.endif
120683186Sjulian
120783186Sjulian.if ${BOOTSTRAPPING} < 1000002
120883186Sjulian_m4=		usr.bin/m4
1209129979Srwatson.endif
121083186Sjulian
1211129979Srwatson.if ${BOOTSTRAPPING} < 1000013
1212129979Srwatson_yacc=		lib/liby \
121383186Sjulian		usr.bin/yacc
1214129979Srwatson.endif
121583186Sjulian
121683186Sjulian.if ${BOOTSTRAPPING} < 1000014
1217129979Srwatson_crunch=	usr.sbin/crunch
1218129979Srwatson.endif
1219130387Srwatson
1220129979Srwatson.if ${BOOTSTRAPPING} < 1000026
1221129979Srwatson_nmtree=	lib/libnetbsd \
1222130387Srwatson		usr.sbin/nmtree
1223129979Srwatson.endif
122483186Sjulian
1225195148Sstas.if ${BOOTSTRAPPING} < 1000027
122683186Sjulian_cat=		bin/cat
122783186Sjulian.endif
122883186Sjulian
122983186Sjulian.if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
123083186Sjulian_awk=		usr.bin/awk
123183186Sjulian.endif
123283186Sjulian
123383186Sjulian.if ${MK_BSNMP} != "no" && !exists(/usr/sbin/gensnmptree)
123483186Sjulian_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
123583186Sjulian.endif
123683186Sjulian
123783186Sjulian.if ${MK_CLANG} != "no"
123883186Sjulian_clang_tblgen= \
123983186Sjulian	lib/clang/libllvmsupport \
124083186Sjulian	lib/clang/libllvmtablegen \
124183186Sjulian	usr.bin/clang/tblgen \
124283186Sjulian	usr.bin/clang/clang-tblgen
124383186Sjulian.endif
124483186Sjulian
1245184205Sdes# dtrace tools are required for older bootstrap env and cross-build
124683186Sjulian.if ${MK_CDDL} != "no" && \
124783186Sjulian    ((${BOOTSTRAPPING} < 1000034 && \
124883186Sjulian          !(${BOOTSTRAPPING} >= 901505 && ${BOOTSTRAPPING} < 999999)) \
124983186Sjulian      || (${MACHINE} != ${TARGET} || ${MACHINE_ARCH} != ${TARGET_ARCH}))
125083186Sjulian_dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
125183186Sjulian    lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
1252184205Sdes.endif
125383186Sjulian
125483186Sjulian# Default to building the BSDL DTC, but build the GPL one if users explicitly
125583186Sjulian# request it.
125683186Sjulian_dtc= usr.bin/dtc
125783186Sjulian.if ${MK_GPL_DTC} != "no"
125883186Sjulian_dtc= gnu/usr.bin/dtc
125983186Sjulian.endif
126083186Sjulian
126183186Sjulian.if ${MK_KERBEROS} != "no"
126283186Sjulian_kerberos5_bootstrap_tools= \
126383186Sjulian	kerberos5/tools/make-roken \
126483186Sjulian	kerberos5/lib/libroken \
126583186Sjulian	kerberos5/lib/libvers \
126683186Sjulian	kerberos5/tools/asn1_compile \
126783186Sjulian	kerberos5/tools/slc \
126883186Sjulian	usr.bin/compile_et
1269130653Srwatson.endif
1270193272Sjhb
1271130653Srwatson#	Please document (add comment) why something is in 'bootstrap-tools'.
1272130653Srwatson#	Try to bound the building of the bootstrap-tool to just the
1273207732Sfabient#	FreeBSD versions that need the tool built at this stage of the build.
1274130653Srwatsonbootstrap-tools: .MAKE
127583186Sjulian.for _tool in \
127683186Sjulian    ${_clang_tblgen} \
127783186Sjulian    ${_kerberos5_bootstrap_tools} \
127883186Sjulian    ${_dtrace_tools} \
127983186Sjulian    ${_strfile} \
128083186Sjulian    ${_gperf} \
1281102244Sarchie    ${_groff} \
128283186Sjulian    ${_ar} \
128383186Sjulian    ${_dtc} \
128483186Sjulian    ${_awk} \
1285184205Sdes    ${_cat} \
128683186Sjulian    usr.bin/lorder \
128783186Sjulian    usr.bin/makewhatis \
128883186Sjulian    ${_mklocale} \
128953246Sarchie    usr.bin/rpcgen \
129053246Sarchie    ${_sed} \
129153246Sarchie    ${_yacc} \
129253246Sarchie    ${_m4} \
129353246Sarchie    ${_lex} \
129453246Sarchie    lib/libmd \
129553246Sarchie    usr.bin/xinstall \
129653648Sarchie    ${_gensnmptree} \
129753246Sarchie    usr.sbin/config \
129853246Sarchie    ${_crunch} \
129953246Sarchie    ${_nmtree}
130053246Sarchie	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
130153246Sarchie		cd ${.CURDIR}/${_tool} && \
130253246Sarchie		${MAKE} DIRPRFX=${_tool}/ obj && \
130353246Sarchie		${MAKE} DIRPRFX=${_tool}/ depend && \
130453246Sarchie		${MAKE} DIRPRFX=${_tool}/ all && \
130553246Sarchie		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
130653246Sarchie.endfor
130753913Sarchie
130853246Sarchie#
130953246Sarchie# build-tools: Build special purpose build tools
131053246Sarchie#
131153246Sarchie.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
1312_aicasm= sys/modules/aic7xxx/aicasm
1313.endif
1314
1315.if !defined(NO_SHARE)
1316_share=	share/syscons/scrnmaps
1317.endif
1318
1319.if ${MK_GCC} != "no"
1320_gcc_tools= gnu/usr.bin/cc/cc_tools
1321.endif
1322
1323.if ${MK_RESCUE} != "no"
1324_rescue= rescue/rescue
1325.endif
1326
1327build-tools: .MAKE
1328.for _tool in \
1329    bin/csh \
1330    bin/sh \
1331    ${_rescue} \
1332    ${LOCAL_TOOL_DIRS} \
1333    lib/ncurses/ncurses \
1334    lib/ncurses/ncursesw \
1335    ${_share} \
1336    ${_aicasm} \
1337    usr.bin/awk \
1338    lib/libmagic \
1339    usr.bin/mkesdb_static \
1340    usr.bin/mkcsmapper_static \
1341    usr.bin/vi/catalog
1342	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1343		cd ${.CURDIR}/${_tool} && \
1344		${MAKE} DIRPRFX=${_tool}/ obj && \
1345		${MAKE} DIRPRFX=${_tool}/ build-tools
1346.endfor
1347.for _tool in \
1348    ${_gcc_tools}
1349	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1350		cd ${.CURDIR}/${_tool} && \
1351		${MAKE} DIRPRFX=${_tool}/ obj && \
1352		${MAKE} DIRPRFX=${_tool}/ depend && \
1353		${MAKE} DIRPRFX=${_tool}/ all
1354.endfor
1355
1356#
1357# cross-tools: Build cross-building tools
1358#
1359.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1360.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1361_btxld=		usr.sbin/btxld
1362.endif
1363.endif
1364.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1365.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1366_crunchide=	usr.sbin/crunch/crunchide
1367.endif
1368.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1369_kgzip=		usr.sbin/kgzip
1370.endif
1371.endif
1372
1373.if ${XAS:M/*} == "" && ${MK_BINUTILS} != "no"
1374_binutils=	gnu/usr.bin/binutils
1375.endif
1376
1377# If an full path to an external cross compiler is given, don't build
1378# a cross compiler.
1379.if ${XCC:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1380.if ${MK_CLANG} != "no" && (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang")
1381_clang=		usr.bin/clang
1382_clang_libs=	lib/clang
1383.endif
1384
1385.if ${MK_GCC} != "no" && (${MK_CLANG_IS_CC} == "no" || ${TARGET} == "pc98")
1386_cc=		gnu/usr.bin/cc
1387.endif
1388.endif
1389
1390cross-tools: .MAKE
1391.for _tool in \
1392    ${_clang_libs} \
1393    ${_clang} \
1394    ${_binutils} \
1395    ${_cc} \
1396    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1397    ${_btxld} \
1398    ${_crunchide} \
1399    ${_kgzip}
1400	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1401		cd ${.CURDIR}/${_tool} && \
1402		${MAKE} DIRPRFX=${_tool}/ obj && \
1403		${MAKE} DIRPRFX=${_tool}/ depend && \
1404		${MAKE} DIRPRFX=${_tool}/ all && \
1405		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1406.endfor
1407
1408#
1409# hierarchy - ensure that all the needed directories are present
1410#
1411hierarchy hier:
1412	cd ${.CURDIR}/etc && ${HMAKE} distrib-dirs
1413
1414#
1415# libraries - build all libraries, and install them under ${DESTDIR}.
1416#
1417# The list of libraries with dependents (${_prebuild_libs}) and their
1418# interdependencies (__L) are built automatically by the
1419# ${.CURDIR}/tools/make_libdeps.sh script.
1420#
1421libraries: .MAKE
1422	cd ${.CURDIR} && \
1423	    ${MAKE} -f Makefile.inc1 _prereq_libs && \
1424	    ${MAKE} -f Makefile.inc1 _startup_libs && \
1425	    ${MAKE} -f Makefile.inc1 _prebuild_libs && \
1426	    ${MAKE} -f Makefile.inc1 _generic_libs
1427
1428#
1429# static libgcc.a prerequisite for shared libc
1430#
1431_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1432
1433# These dependencies are not automatically generated:
1434#
1435# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1436# all shared libraries for ELF.
1437#
1438_startup_libs=	gnu/lib/csu
1439.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1440_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1441.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1442_startup_libs+=	lib/csu/${MACHINE_ARCH}
1443.else
1444_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1445.endif
1446_startup_libs+=	gnu/lib/libgcc
1447_startup_libs+=	lib/libcompiler_rt
1448_startup_libs+=	lib/libc
1449.if ${MK_LIBCPLUSPLUS} != "no"
1450_startup_libs+=	lib/libcxxrt
1451.endif
1452
1453gnu/lib/libgcc__L: lib/libc__L
1454.if ${MK_LIBCPLUSPLUS} != "no"
1455lib/libcxxrt__L: gnu/lib/libgcc__L
1456.endif
1457
1458_prebuild_libs=	${_kerberos5_lib_libasn1} \
1459		${_kerberos5_lib_libhdb} \
1460		${_kerberos5_lib_libheimbase} \
1461		${_kerberos5_lib_libheimntlm} \
1462		${_kerberos5_lib_libheimsqlite} \
1463		${_kerberos5_lib_libheimipcc} \
1464		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1465		${_kerberos5_lib_libroken} \
1466		${_kerberos5_lib_libwind} \
1467		${_lib_atf_libatf_c} \
1468		lib/libbz2 ${_libcom_err} lib/libcrypt \
1469		lib/libelf lib/libexpat \
1470		${_lib_libgssapi} ${_lib_libipx} \
1471		lib/libkiconv lib/libkvm lib/liblzma lib/libmd \
1472		lib/ncurses/ncurses lib/ncurses/ncursesw \
1473		lib/libopie lib/libpam ${_lib_libthr} \
1474		lib/libradius lib/libsbuf lib/libtacplus \
1475		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1476		${_cddl_lib_libzfs_core} \
1477		lib/libutil ${_lib_libypclnt} lib/libz lib/msun \
1478		${_secure_lib_libcrypto} ${_lib_libldns} \
1479		${_secure_lib_libssh} ${_secure_lib_libssl}
1480
1481.if ${MK_ATF} != "no"
1482_lib_atf_libatf_c=	lib/atf/libatf-c
1483.endif
1484
1485.if ${MK_LIBTHR} != "no"
1486_lib_libthr=	lib/libthr
1487.endif
1488
1489.if ${MK_OFED} != "no"
1490_ofed_lib=	contrib/ofed/usr.lib/
1491.endif
1492
1493_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1494.for _DIR in ${LOCAL_LIB_DIRS}
1495.if exists(${.CURDIR}/${_DIR}/Makefile)
1496_generic_libs+= ${_DIR}
1497.endif
1498.endfor
1499
1500lib/libopie__L lib/libtacplus__L: lib/libmd__L
1501
1502.if ${MK_CDDL} != "no"
1503_cddl_lib_libumem= cddl/lib/libumem
1504_cddl_lib_libnvpair= cddl/lib/libnvpair
1505_cddl_lib_libzfs_core= cddl/lib/libzfs_core
1506_cddl_lib= cddl/lib
1507cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1508.endif
1509
1510.if ${MK_CRYPT} != "no"
1511.if ${MK_OPENSSL} != "no"
1512_secure_lib_libcrypto= secure/lib/libcrypto
1513_secure_lib_libssl= secure/lib/libssl
1514lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1515.if ${MK_LDNS} != "no"
1516_lib_libldns= lib/libldns
1517lib/libldns__L: secure/lib/libcrypto__L
1518.endif
1519.if ${MK_OPENSSH} != "no"
1520_secure_lib_libssh= secure/lib/libssh
1521secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1522.if ${MK_LDNS} != "no"
1523secure/lib/libssh__L: lib/libldns__L
1524.endif
1525.if ${MK_KERBEROS_SUPPORT} != "no"
1526secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1527    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1528    lib/libmd__L kerberos5/lib/libroken__L
1529.endif
1530.endif
1531.endif
1532_secure_lib=	secure/lib
1533.endif
1534
1535.if ${MK_KERBEROS} != "no"
1536kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1537kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1538    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1539    kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L 
1540kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1541    kerberos5/lib/libroken__L lib/libcom_err__L
1542kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1543    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1544kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1545    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1546    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1547    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1548kerberos5/lib/libroken__L: lib/libcrypt__L
1549kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1550kerberos5/lib/libheimbase__L: lib/libthr__L
1551kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1552kerberos5/lib/libheimsqlite__L: lib/libthr__L
1553.endif
1554
1555.if ${MK_GSSAPI} != "no"
1556_lib_libgssapi=	lib/libgssapi
1557.endif
1558
1559.if ${MK_IPX} != "no"
1560_lib_libipx=	lib/libipx
1561.endif
1562
1563.if ${MK_KERBEROS} != "no"
1564_kerberos5_lib=	kerberos5/lib
1565_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1566_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1567_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1568_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1569_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1570_kerberos5_lib_libroken= kerberos5/lib/libroken
1571_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1572_kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1573_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1574_kerberos5_lib_libwind= kerberos5/lib/libwind
1575_libcom_err= lib/libcom_err
1576.endif
1577
1578.if ${MK_NIS} != "no"
1579_lib_libypclnt=	lib/libypclnt
1580.endif
1581
1582.if ${MK_OPENSSL} == "no"
1583lib/libradius__L: lib/libmd__L
1584.endif
1585
1586.for _lib in ${_prereq_libs}
1587${_lib}__PL: .PHONY .MAKE
1588.if exists(${.CURDIR}/${_lib})
1589	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1590		cd ${.CURDIR}/${_lib} && \
1591		${MAKE} DIRPRFX=${_lib}/ obj && \
1592		${MAKE} DIRPRFX=${_lib}/ depend && \
1593		${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all && \
1594		${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install
1595.endif
1596.endfor
1597
1598.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1599${_lib}__L: .PHONY .MAKE
1600.if exists(${.CURDIR}/${_lib})
1601	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1602		cd ${.CURDIR}/${_lib} && \
1603		${MAKE} DIRPRFX=${_lib}/ obj && \
1604		${MAKE} DIRPRFX=${_lib}/ depend && \
1605		${MAKE} DIRPRFX=${_lib}/ all && \
1606		${MAKE} DIRPRFX=${_lib}/ install
1607.endif
1608.endfor
1609
1610# libpam is special: we need to build static PAM modules before
1611# static PAM library, and dynamic PAM library before dynamic PAM
1612# modules.
1613lib/libpam__L: .PHONY .MAKE
1614	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1615		cd ${.CURDIR}/lib/libpam && \
1616		${MAKE} DIRPRFX=lib/libpam/ obj && \
1617		${MAKE} DIRPRFX=lib/libpam/ depend && \
1618		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all && \
1619		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1620
1621_prereq_libs: ${_prereq_libs:S/$/__PL/}
1622_startup_libs: ${_startup_libs:S/$/__L/}
1623_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1624_generic_libs: ${_generic_libs:S/$/__L/}
1625
1626.for __target in all clean cleandepend cleandir depend includes obj
1627.for entry in ${SUBDIR}
1628${entry}.${__target}__D: .PHONY .MAKE
1629	${_+_}@set -e; if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1630		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1631		edir=${entry}.${MACHINE_ARCH}; \
1632		cd ${.CURDIR}/$${edir}; \
1633	else \
1634		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1635		edir=${entry}; \
1636		cd ${.CURDIR}/$${edir}; \
1637	fi; \
1638	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1639.endfor
1640par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1641.endfor
1642
1643.include <bsd.subdir.mk>
1644
1645.if make(check-old) || make(check-old-dirs) || \
1646    make(check-old-files) || make(check-old-libs) || \
1647    make(delete-old) || make(delete-old-dirs) || \
1648    make(delete-old-files) || make(delete-old-libs)
1649
1650#
1651# check for / delete old files section
1652#
1653
1654.include "ObsoleteFiles.inc"
1655
1656OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1657else you can not start such an application. Consult UPDATING for more \
1658information regarding how to cope with the removal/revision bump of a \
1659specific library."
1660
1661.if !defined(BATCH_DELETE_OLD_FILES)
1662RM_I=-i
1663.else
1664RM_I=-v
1665.endif
1666
1667delete-old-files:
1668	@echo ">>> Removing old files (only deletes safe to delete libs)"
1669# Ask for every old file if the user really wants to remove it.
1670# It's annoying, but better safe than sorry.
1671# NB: We cannot pass the list of OLD_FILES as a parameter because the
1672# argument list will get too long. Using .for/.endfor make "loops" will make
1673# the Makefile parser segfault.
1674	@exec 3<&0; \
1675	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1676	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1677	while read file; do \
1678		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1679			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1680			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1681		fi; \
1682	done
1683# Remove catpages without corresponding manpages.
1684	@exec 3<&0; \
1685	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1686	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1687	while read catpage; do \
1688		read manpage; \
1689		if [ ! -e "$${manpage}" ]; then \
1690			rm ${RM_I} $${catpage} <&3; \
1691	        fi; \
1692	done
1693	@echo ">>> Old files removed"
1694
1695check-old-files:
1696	@echo ">>> Checking for old files"
1697	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1698	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1699	while read file; do \
1700		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1701		 	echo "${DESTDIR}/$${file}"; \
1702		fi; \
1703	done
1704# Check for catpages without corresponding manpages.
1705	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1706	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1707	while read catpage; do \
1708		read manpage; \
1709		if [ ! -e "$${manpage}" ]; then \
1710			echo $${catpage}; \
1711	        fi; \
1712	done
1713
1714delete-old-libs:
1715	@echo ">>> Removing old libraries"
1716	@echo "${OLD_LIBS_MESSAGE}" | fmt
1717	@exec 3<&0; \
1718	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1719	    -V OLD_LIBS | xargs -n1 | \
1720	while read file; do \
1721		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1722			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1723			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1724		fi; \
1725	done
1726	@echo ">>> Old libraries removed"
1727
1728check-old-libs:
1729	@echo ">>> Checking for old libraries"
1730	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1731	    -V OLD_LIBS | xargs -n1 | \
1732	while read file; do \
1733		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1734			echo "${DESTDIR}/$${file}"; \
1735		fi; \
1736	done
1737
1738delete-old-dirs:
1739	@echo ">>> Removing old directories"
1740	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1741	    -V OLD_DIRS | xargs -n1 | sort -r | \
1742	while read dir; do \
1743		if [ -d "${DESTDIR}/$${dir}" ]; then \
1744			rmdir -v "${DESTDIR}/$${dir}" || true; \
1745		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1746			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1747		fi; \
1748	done
1749	@echo ">>> Old directories removed"
1750
1751check-old-dirs:
1752	@echo ">>> Checking for old directories"
1753	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1754	    -V OLD_DIRS | xargs -n1 | \
1755	while read dir; do \
1756		if [ -d "${DESTDIR}/$${dir}" ]; then \
1757			echo "${DESTDIR}/$${dir}"; \
1758		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1759			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1760		fi; \
1761	done
1762
1763delete-old: delete-old-files delete-old-dirs
1764	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1765
1766check-old: check-old-files check-old-libs check-old-dirs
1767	@echo "To remove old files and directories run '${MAKE} delete-old'."
1768	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1769
1770.endif
1771
1772#
1773# showconfig - show build configuration.
1774#
1775showconfig:
1776	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 2>&1 | grep ^MK_ | sort
1777
1778.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
1779DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
1780
1781.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
1782.if exists(${KERNCONFDIR}/${KERNCONF})
1783FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
1784	${KERNCONFDIR}/${KERNCONF} ; echo
1785.endif
1786.endif
1787
1788.endif
1789
1790.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
1791DTBOUTPUTPATH= ${.CURDIR}
1792.endif
1793
1794#
1795# Build 'standalone' Device Tree Blob
1796#
1797builddtb:
1798	@if [ "${FDT_DTS_FILE}" = "" ]; then \
1799		echo "ERROR: FDT_DTS_FILE must be specified!"; \
1800		exit 1; \
1801	fi;	\
1802	if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ]; then \
1803		echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \
1804			exist!"; \
1805		exit 1;	\
1806	fi;	\
1807	if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then	\
1808		echo "WARNING: DTB will be placed in the current working \
1809			directory"; \
1810	fi
1811	@PATH=${TMPPATH} \
1812	dtc -O dtb -o \
1813	    ${DTBOUTPUTPATH}/`echo ${FDT_DTS_FILE} | cut -d. -f1`.dtb -b 0 \
1814	    -p 1024 ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE}
1815
1816###############
1817
1818.if defined(XDEV) && defined(XDEV_ARCH)
1819
1820.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
1821XDEV_CPUTYPE?=${CPUTYPE}
1822.else
1823XDEV_CPUTYPE?=${TARGET_CPUTYPE}
1824.endif
1825
1826NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
1827	-DWITHOUT_MAN -DWITHOUT_NLS -DNO_PROFILE \
1828	-DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \
1829	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
1830	CPUTYPE=${XDEV_CPUTYPE}
1831
1832XDDIR=${XDEV_ARCH}-freebsd
1833XDTP=/usr/${XDDIR}
1834CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
1835	INSTALL="sh ${.CURDIR}/tools/install.sh"
1836CDENV= ${CDBENV} \
1837	_SHLIBDIRPREFIX=${XDDESTDIR} \
1838	TOOLS_PREFIX=${XDDESTDIR}
1839CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
1840	-B${XDDESTDIR}/usr/lib
1841CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" \
1842	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1843
1844CDTMP=	${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
1845CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1846CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1847XDDESTDIR=${DESTDIR}${XDTP}
1848.if !defined(OSREL)
1849OSREL!= uname -r | sed -e 's/[-(].*//'
1850.endif
1851
1852.ORDER: xdev-build xdev-install
1853xdev: xdev-build xdev-install
1854
1855.ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
1856xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
1857
1858_xb-worldtmp:
1859	mkdir -p ${CDTMP}/usr
1860	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1861	    -p ${CDTMP}/usr >/dev/null
1862
1863_xb-bootstrap-tools:
1864.for _tool in \
1865    ${_clang_tblgen}
1866	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1867	cd ${.CURDIR}/${_tool} && \
1868	${CDMAKE} DIRPRFX=${_tool}/ obj && \
1869	${CDMAKE} DIRPRFX=${_tool}/ depend && \
1870	${CDMAKE} DIRPRFX=${_tool}/ all && \
1871	${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
1872.endfor
1873
1874_xb-build-tools:
1875	${_+_}@cd ${.CURDIR}; \
1876	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1877
1878_xb-cross-tools:
1879.for _tool in \
1880    gnu/usr.bin/binutils \
1881    gnu/usr.bin/cc \
1882    usr.bin/ar \
1883    ${_clang_libs} \
1884    ${_clang}
1885	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1886	cd ${.CURDIR}/${_tool} && \
1887	${CDMAKE} DIRPRFX=${_tool}/ obj && \
1888	${CDMAKE} DIRPRFX=${_tool}/ depend && \
1889	${CDMAKE} DIRPRFX=${_tool}/ all
1890.endfor
1891
1892_xi-mtree:
1893	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1894	mkdir -p ${XDDESTDIR}
1895	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1896	    -p ${XDDESTDIR} >/dev/null
1897	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1898	    -p ${XDDESTDIR}/usr >/dev/null
1899	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1900	    -p ${XDDESTDIR}/usr/include >/dev/null
1901
1902.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1903xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1904
1905_xi-cross-tools:
1906	@echo "_xi-cross-tools"
1907.for _tool in \
1908    gnu/usr.bin/binutils \
1909    gnu/usr.bin/cc \
1910    usr.bin/ar \
1911    ${_clang}
1912	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1913	cd ${.CURDIR}/${_tool}; \
1914	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1915.endfor
1916
1917_xi-includes:
1918	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1919		DESTDIR=${XDDESTDIR}
1920
1921_xi-libraries:
1922	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1923		DESTDIR=${XDDESTDIR}
1924
1925_xi-links:
1926	${_+_}cd ${XDDESTDIR}/usr/bin; \
1927		for i in *; do \
1928			ln -sf ../../${XDTP}/usr/bin/$$i \
1929			    ../../../../usr/bin/${XDDIR}-$$i; \
1930			ln -sf ../../${XDTP}/usr/bin/$$i \
1931			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1932		done
1933.else
1934xdev xdev-build xdev-install:
1935	@echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target"
1936.endif
1937
1938buildkernel ${WMAKE_TGTS} ${.ALLTARGETS:M_*}: .MAKE
1939