Makefile.inc1 revision 166131
143902Sbrian#
243902Sbrian# $FreeBSD: head/Makefile.inc1 166131 2007-01-20 07:48:10Z rafan $
343948Sbrian#
443902Sbrian# Make command line options:
543948Sbrian#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
643902Sbrian#	-DNO_CLEAN do not clean at all
750476Speter#	-DNO_SHARE do not go into share subdir
843902Sbrian#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
943902Sbrian#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
1043902Sbrian#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
1143902Sbrian#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
1243902Sbrian#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
1376363Sbrian#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
1476363Sbrian#	TARGET="machine" to crossbuild world for a different machine type
1576363Sbrian
1676363Sbrian#
1776363Sbrian# The intended user-driven targets are:
1843902Sbrian# buildworld  - rebuild *everything*, including glue to help do upgrades
1943902Sbrian# installworld- install everything built by "buildworld"
2043902Sbrian# doxygen     - build API documentation of the kernel
2143902Sbrian# update      - convenient way to update your source tree (eg: cvsup/cvs)
2243902Sbrian#
2343902Sbrian# Standard targets (not defined here) are documented in the makefiles in
2443948Sbrian# /usr/share/mk.  These include:
2543902Sbrian#		obj depend all install clean cleandepend cleanobj
2679086Sbrian
2743948Sbrian.include <bsd.own.mk>
2843948Sbrian
2943902Sbrian# We must do share/info early so that installation of info `dir'
3043902Sbrian# entries works correctly.  Do it first since it is less likely to
3143902Sbrian# grow dependencies on include and lib than vice versa.
3243902Sbrian#
3343902Sbrian# We must do lib/ and libexec/ before bin/, because if installworld
3443948Sbrian# installs a new /bin/sh, the 'make' command will *immediately*
3543948Sbrian# use that new version.  And the new (dynamically-linked) /bin/sh
3643902Sbrian# will expect to find appropriate libraries in /lib and /libexec.
3743902Sbrian#
3843902SbrianSUBDIR=	share/info lib libexec
3943902SbrianSUBDIR+=bin
4043948Sbrian.if ${MK_GAMES} != "no"
4143948SbrianSUBDIR+=games
4247634Sbillf.endif
4343902SbrianSUBDIR+=gnu include
4443902Sbrian.if ${MK_KERBEROS} != "no"
4543902SbrianSUBDIR+=kerberos5
4643948Sbrian.endif
4743948Sbrian.if ${MK_RESCUE} != "no"
4843948SbrianSUBDIR+=rescue
4943902Sbrian.endif
5043902SbrianSUBDIR+=sbin
5143948Sbrian.if ${MK_CRYPT} != "no"
5243948SbrianSUBDIR+=secure
5343902Sbrian.endif
5443902Sbrian.if !defined(NO_SHARE)
5543902SbrianSUBDIR+=share
5643948Sbrian.endif
5743902SbrianSUBDIR+=sys usr.bin usr.sbin
5879086Sbrian#
5943948Sbrian# We must do etc/ last for install/distribute to work.
6043948Sbrian#
6143902SbrianSUBDIR+=etc
6243902Sbrian
6343902Sbrian# These are last, since it is nice to at least get the base system
6443902Sbrian# rebuilt before you do them.
6569470Sbrian.for _DIR in ${LOCAL_DIRS}
6669470Sbrian.if exists(${.CURDIR}/${_DIR}/Makefile)
6743902SbrianSUBDIR+= ${_DIR}
6843948Sbrian.endif
6943902Sbrian.endfor
7043948Sbrian
7143948Sbrian.if defined(SUBDIR_OVERRIDE)
7243902SbrianSUBDIR=		${SUBDIR_OVERRIDE}
7343948Sbrian.endif
7443948Sbrian
7543948Sbrian.if defined(NOCLEAN)
7643948SbrianNO_CLEAN=	${NOCLEAN}
7743948Sbrian.endif
7843948Sbrian.if defined(NO_CLEANDIR)
7943902SbrianCLEANDIR=	clean cleandepend
8043902Sbrian.else
8143902SbrianCLEANDIR=	cleandir
8243902Sbrian.endif
8343902Sbrian
8443902SbrianCVS?=		cvs
8543902SbrianCVSFLAGS?=	-A -P -d -I!
8643902SbrianSUP?=		/usr/bin/csup
8743948SbrianSUPFLAGS?=	-g -L 2
8847634Sbillf.if defined(SUPHOST)
8943902SbrianSUPFLAGS+=	-h ${SUPHOST}
9043902Sbrian.endif
9143948Sbrian
9243948SbrianMAKEOBJDIRPREFIX?=	/usr/obj
9343902Sbrian.if !defined(OSRELDATE)
9443902Sbrian.if exists(/usr/include/osreldate.h)
9543902SbrianOSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
9643902Sbrian		/usr/include/osreldate.h
9743902Sbrian.else
9843902SbrianOSRELDATE=	0
9943902Sbrian.endif
10043902Sbrian.endif
10143902Sbrian
10243902Sbrian# Guess machine architecture from machine type, and vice versa.
10343902Sbrian.if !defined(TARGET_ARCH) && defined(TARGET)
10443902SbrianTARGET_ARCH=	${TARGET:S/pc98/i386/:S/sun4v/sparc64/}
10543902Sbrian.elif !defined(TARGET) && defined(TARGET_ARCH) && \
10643902Sbrian    ${TARGET_ARCH} != ${MACHINE_ARCH}
10743902SbrianTARGET=		${TARGET_ARCH}
10843902Sbrian.endif
10943902Sbrian# Otherwise, default to current machine type and architecture.
11043902SbrianTARGET?=	${MACHINE}
11143902SbrianTARGET_ARCH?=	${MACHINE_ARCH}
11243902Sbrian
11343902SbrianKNOWN_ARCHES?=	amd64 arm i386 i386/pc98 ia64 powerpc sparc64 sparc64/sun4v
11443902Sbrian.if ${TARGET} == ${TARGET_ARCH}
11543902Sbrian_t=		${TARGET}
11643902Sbrian.else
11743902Sbrian_t=		${TARGET_ARCH}/${TARGET}
11843902Sbrian.endif
11943902Sbrian.for _t in ${_t}
12043902Sbrian.if empty(KNOWN_ARCHES:M${_t})
12177171Sbrian.error Unknown target ${TARGET_ARCH}:${TARGET}.
12277171Sbrian.endif
12377171Sbrian.endfor
12477171Sbrian
12577171Sbrian.if ${TARGET} == ${MACHINE}
12677171SbrianTARGET_CPUTYPE?=${CPUTYPE}
12777171Sbrian.else
12877171SbrianTARGET_CPUTYPE?=
12977171Sbrian.endif
13077171Sbrian
13177171Sbrian.if !empty(TARGET_CPUTYPE)
13277171Sbrian_TARGET_CPUTYPE=${TARGET_CPUTYPE}
13377171Sbrian.else
13477171Sbrian_TARGET_CPUTYPE=dummy
13577171Sbrian.endif
13677171Sbrian_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
13777171Sbrian		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
13877171Sbrian.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
13977171Sbrian.error CPUTYPE global should be set with ?=.
14077171Sbrian.endif
14177171Sbrian.if make(buildworld)
14277171SbrianBUILD_ARCH!=	uname -p
14377171Sbrian.if ${MACHINE_ARCH} != ${BUILD_ARCH}
14477171Sbrian.error To cross-build, set TARGET_ARCH.
14577171Sbrian.endif
14677171Sbrian.endif
14777171Sbrian.if ${MACHINE} == ${TARGET} && !defined(CROSS_BUILD_TESTING)
14877171SbrianOBJTREE=	${MAKEOBJDIRPREFIX}
14977171Sbrian.else
15077171SbrianOBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}
15177171Sbrian.endif
15277171SbrianWORLDTMP=	${OBJTREE}${.CURDIR}/tmp
15377171Sbrian# /usr/games added for fortune which depend on strfile
15477171SbrianBPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
15577171SbrianXPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
15677171SbrianSTRICTTMPPATH=	${BPATH}:${XPATH}
15777171SbrianTMPPATH=	${STRICTTMPPATH}:${PATH}
15877171Sbrian
15977171SbrianINSTALLTMP!=	/usr/bin/mktemp -d -u -t install
16077171Sbrian
16177171Sbrian#
16243902Sbrian# Building a world goes through the following stages
16343902Sbrian#
16443902Sbrian# 1. legacy stage [BMAKE]
16543902Sbrian#	This stage is responsible for creating compatibility
16643902Sbrian#	shims that are needed by the bootstrap-tools,
16743902Sbrian#	build-tools and cross-tools stages.
16843902Sbrian# 1. bootstrap-tools stage [BMAKE]
16943902Sbrian#	This stage is responsible for creating programs that
17043902Sbrian#	are needed for backward compatibility reasons. They
17143902Sbrian#	are not built as cross-tools.
17243902Sbrian# 2. build-tools stage [TMAKE]
17343902Sbrian#	This stage is responsible for creating the object
17443902Sbrian#	tree and building any tools that are needed during
17543902Sbrian#	the build process.
17676363Sbrian# 3. cross-tools stage [XMAKE]
17776363Sbrian#	This stage is responsible for creating any tools that
17876363Sbrian#	are needed for cross-builds. A cross-compiler is one
17976363Sbrian#	of them.
18076363Sbrian# 4. world stage [WMAKE]
18143902Sbrian#	This stage actually builds the world.
18243902Sbrian# 5. install stage (optional) [IMAKE]
18343902Sbrian#	This stage installs a previously built world.
18443902Sbrian#
18543902Sbrian
18643902SbrianBOOTSTRAPPING?=	0
18743902Sbrian
18843902Sbrian# Common environment for world related stages
18943902SbrianCROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
19043902Sbrian		MACHINE_ARCH=${TARGET_ARCH} \
19143902Sbrian		MACHINE=${TARGET} \
19243902Sbrian		CPUTYPE=${TARGET_CPUTYPE} \
19343902Sbrian		GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
19455247Sbrian		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
19543902Sbrian		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
19643902Sbrian
19743902Sbrian# bootstrap-tools stage
19843902SbrianBMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
19943902Sbrian		PATH=${BPATH}:${PATH} \
20043902Sbrian		WORLDTMP=${WORLDTMP} \
20169470Sbrian		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
20243902SbrianBMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
20343902Sbrian		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
20443902Sbrian		DESTDIR= \
20543902Sbrian		BOOTSTRAPPING=${OSRELDATE} \
20643902Sbrian		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
20743902Sbrian		-DWITHOUT_NLS -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \
20843902Sbrian		-DNO_CPU_CFLAGS -DNO_WARNS
20943902Sbrian
21043902Sbrian# build-tools stage
21143902SbrianTMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
21243902Sbrian		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
21343902Sbrian		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
21443902Sbrian		DESTDIR= \
21543902Sbrian		BOOTSTRAPPING=${OSRELDATE} -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS
21643902Sbrian
21743902Sbrian# cross-tools stage
21843902SbrianXMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
21943902Sbrian		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
22043902Sbrian		-DWITHOUT_FORTRAN -DWITHOUT_GDB
22143902Sbrian
22243902Sbrian# world stage
22343902SbrianWMAKEENV=	${CROSSENV} \
22443902Sbrian		_SHLIBDIRPREFIX=${WORLDTMP} \
22543902Sbrian		INSTALL="sh ${.CURDIR}/tools/install.sh" \
22643902Sbrian		PATH=${TMPPATH}
22743902SbrianWMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
22858636Sbrian
22943902Sbrian.if ${TARGET_ARCH} == "amd64"
23043902Sbrian# 32 bit world
23143902SbrianLIB32TMP=	${OBJTREE}${.CURDIR}/lib32
23243902Sbrian
23351050Sbrian.if empty(TARGET_CPUTYPE)
23451050SbrianLIB32CPUTYPE=	k8
23551050Sbrian.else
23651050SbrianLIB32CPUTYPE=	${TARGET_CPUTYPE}
23751049Sbrian.endif
23843902SbrianLIB32PREFLAGS=	-m32 -march=${LIB32CPUTYPE} -mfancy-math-387 -DCOMPAT_32BIT
23943902SbrianLIB32POSTFLAGS=	-I${LIB32TMP}/usr/include \
24055427Sbrian		-L${LIB32TMP}/usr/lib32 \
24155427Sbrian		-B${LIB32TMP}/usr/lib32
24243902SbrianLIB32CC=	${LIB32PREFLAGS} \
24343902Sbrian		${LIB32POSTFLAGS}
24443902SbrianLIB32CXX=	${LIB32PREFLAGS} -I${LIB32TMP}/usr/include/c++/3.4 \
24551049Sbrian		${LIB32POSTFLAGS}
24643902SbrianLIB32OBJC=	${LIB32PREFLAGS} -I${LIB32TMP}/usr/include/objc \
24743902Sbrian		${LIB32POSTFLAGS}
24843902Sbrian
24943902Sbrian# Yes, the flags are redundant.
25043902SbrianLIB32MAKEENV=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
25143902Sbrian		_SHLIBDIRPREFIX=${LIB32TMP} \
25243902Sbrian		MACHINE=i386 \
25343902Sbrian		MACHINE_ARCH=i386 \
25443902Sbrian		INSTALL="sh ${.CURDIR}/tools/install.sh" \
25543902Sbrian		PATH=${TMPPATH} \
25643902Sbrian		CC="${CC} ${LIB32CC}" \
25743902Sbrian		CXX="${CXX} ${LIB32CXX}" \
25843902Sbrian		OBJC="${OBJC} ${LIB32OBJC}" \
25943902Sbrian		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
26043902Sbrian		AS="${AS} --32" \
26143902Sbrian		LIBDIR=/usr/lib32 \
26243902Sbrian		SHLIBDIR=/usr/lib32
26343902Sbrian
26443902SbrianLIB32MAKE=	${LIB32MAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
26556704Sbrian		-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_INFO \
26643902Sbrian		-DWITHOUT_HTML
26756704SbrianLIB32IMAKE=	${LIB32MAKE:NINSTALL=*} -DNO_INCS
26856704Sbrian.endif
26956704Sbrian
27056704Sbrian# install stage
27159152Sbrian.if empty(.MAKEFLAGS:M-n)
27259152SbrianIMAKEENV=	${CROSSENV} \
27384999Sbrian		PATH=${STRICTTMPPATH}:${INSTALLTMP}
27459152Sbrian.else
27559152SbrianIMAKEENV=	${CROSSENV} \
27684999Sbrian		PATH=${TMPPATH}:${INSTALLTMP}
27759152Sbrian.endif
27859152SbrianIMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1
27943902Sbrian
28056704Sbrian# kernel stage
28143902SbrianKMAKEENV=	${WMAKEENV}
28256704SbrianKMAKE=		${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME}
28356704Sbrian
28456704Sbrian#
28556704Sbrian# buildworld
28684999Sbrian#
28756704Sbrian# Attempt to rebuild the entire system, with reasonable chance of
28856704Sbrian# success, regardless of how old your existing system is.
28984999Sbrian#
29056704Sbrian_worldtmp:
29156704Sbrian.if ${.CURDIR:C/[^,]//g} != ""
29243902Sbrian#	The m4 build of sendmail files doesn't like it if ',' is used
29356704Sbrian#	anywhere in the path of it's files.
29443902Sbrian	@echo
29556704Sbrian	@echo "*** Error: path to source tree contains a comma ','"
29656704Sbrian	@echo
29756704Sbrian	false
29856704Sbrian.endif
29956704Sbrian	@echo
30056704Sbrian	@echo "--------------------------------------------------------------"
30156704Sbrian	@echo ">>> Rebuilding the temporary build tree"
30256704Sbrian	@echo "--------------------------------------------------------------"
30356704Sbrian.if !defined(NO_CLEAN)
30456704Sbrian	rm -rf ${WORLDTMP}
30556704Sbrian.if ${TARGET_ARCH} == "amd64"
30656704Sbrian	rm -rf ${LIB32TMP}
30756704Sbrian.endif
30856704Sbrian.else
30956704Sbrian	rm -rf ${WORLDTMP}/legacy/usr/include
31056704Sbrian#	XXX - These two can depend on any header file.
31143902Sbrian	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
31249141Sbrian	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
31349141Sbrian.endif
31449141Sbrian.for _dir in \
31549141Sbrian    usr/bin usr/games usr/include/c++/3.4 usr/include/sys usr/lib \
31669470Sbrian    usr/libexec usr/sbin usr/share/dict \
31769470Sbrian    usr/share/groff_font/devX100 \
31869470Sbrian    usr/share/groff_font/devX100-12 \
31949141Sbrian    usr/share/groff_font/devX75 \
32069470Sbrian    usr/share/groff_font/devX75-12 \
32169470Sbrian    usr/share/groff_font/devascii \
32269470Sbrian    usr/share/groff_font/devcp1047 \
32369470Sbrian    usr/share/groff_font/devdvi \
32469470Sbrian    usr/share/groff_font/devhtml \
32569470Sbrian    usr/share/groff_font/devkoi8-r \
32669470Sbrian    usr/share/groff_font/devlatin1 \
32769470Sbrian    usr/share/groff_font/devlbp \
32869470Sbrian    usr/share/groff_font/devlj4 \
32969470Sbrian    usr/share/groff_font/devps \
33069470Sbrian    usr/share/groff_font/devutf8 \
33149141Sbrian    usr/share/tmac/mdoc usr/share/tmac/mm
33249141Sbrian	mkdir -p ${WORLDTMP}/legacy/${_dir}
33349141Sbrian.endfor
33469470Sbrian.for _dir in \
33549141Sbrian    lib usr/bin usr/include usr/lib/compat/aout usr/libdata/ldscripts \
33669470Sbrian    usr/libexec usr/sbin usr/share/misc \
33749141Sbrian    usr/share/snmp/defs usr/share/snmp/mibs
33849141Sbrian	mkdir -p ${WORLDTMP}/${_dir}
33943902Sbrian.endfor
34049141Sbrian	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
34149141Sbrian	    -p ${WORLDTMP}/usr/include >/dev/null
34249141Sbrian	ln -sf ${.CURDIR}/sys ${WORLDTMP}
34349141Sbrian.if ${MK_BIND_LIBS} != "no"
34449141Sbrian	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
34549141Sbrian	    -p ${WORLDTMP}/usr/include >/dev/null
34649141Sbrian.endif
34749141Sbrian_legacy:
34849141Sbrian	@echo
34949141Sbrian	@echo "--------------------------------------------------------------"
35049141Sbrian	@echo ">>> stage 1.1: legacy release compatibility shims"
35149141Sbrian	@echo "--------------------------------------------------------------"
35269470Sbrian	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
35349141Sbrian_bootstrap-tools:
35449141Sbrian	@echo
35549141Sbrian	@echo "--------------------------------------------------------------"
35649141Sbrian	@echo ">>> stage 1.2: bootstrap tools"
35749141Sbrian	@echo "--------------------------------------------------------------"
35849141Sbrian	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
35949141Sbrian_cleanobj:
36049141Sbrian.if !defined(NO_CLEAN)
36149141Sbrian	@echo
36249141Sbrian	@echo "--------------------------------------------------------------"
36349141Sbrian	@echo ">>> stage 2.1: cleaning up the object tree"
36449141Sbrian	@echo "--------------------------------------------------------------"
36549141Sbrian	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
36649141Sbrian.if ${TARGET_ARCH} == "amd64"
36769470Sbrian	rm -rf ${OBJTREE}/lib32
36849141Sbrian.endif
36949141Sbrian.endif
37069470Sbrian_obj:
37149141Sbrian	@echo
37249141Sbrian	@echo "--------------------------------------------------------------"
37349141Sbrian	@echo ">>> stage 2.2: rebuilding the object tree"
37449141Sbrian	@echo "--------------------------------------------------------------"
37549141Sbrian	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
37649141Sbrian_build-tools:
37749141Sbrian	@echo
37849141Sbrian	@echo "--------------------------------------------------------------"
37949141Sbrian	@echo ">>> stage 2.3: build tools"
38069470Sbrian	@echo "--------------------------------------------------------------"
38149141Sbrian	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
38249141Sbrian_cross-tools:
38349141Sbrian	@echo
38449141Sbrian	@echo "--------------------------------------------------------------"
38549141Sbrian	@echo ">>> stage 3: cross tools"
38649141Sbrian	@echo "--------------------------------------------------------------"
38749141Sbrian	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
38849141Sbrian_includes:
38969470Sbrian	@echo
39049141Sbrian	@echo "--------------------------------------------------------------"
39149141Sbrian	@echo ">>> stage 4.1: building includes"
39249141Sbrian	@echo "--------------------------------------------------------------"
39369470Sbrian	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
39449141Sbrian_libraries:
39549141Sbrian	@echo
39649141Sbrian	@echo "--------------------------------------------------------------"
39749141Sbrian	@echo ">>> stage 4.2: building libraries"
39849141Sbrian	@echo "--------------------------------------------------------------"
39969470Sbrian	${_+_}cd ${.CURDIR}; \
40049141Sbrian	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
40149141Sbrian	    -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE libraries
40269470Sbrian_depend:
40349141Sbrian	@echo
40449141Sbrian	@echo "--------------------------------------------------------------"
40549141Sbrian	@echo ">>> stage 4.3: make dependencies"
40649141Sbrian	@echo "--------------------------------------------------------------"
40743902Sbrian	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
40843902Sbrianeverything:
40943948Sbrian	@echo
41043948Sbrian	@echo "--------------------------------------------------------------"
41143948Sbrian	@echo ">>> stage 4.4: building everything"
41243948Sbrian	@echo "--------------------------------------------------------------"
41343948Sbrian	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
41443948Sbrian.if ${TARGET_ARCH} == "amd64"
41543948Sbrianbuild32:
41643948Sbrian	@echo
41743948Sbrian	@echo "--------------------------------------------------------------"
41843948Sbrian	@echo ">>> stage 5.1: building 32 bit shim libraries"
41969470Sbrian	@echo "--------------------------------------------------------------"
42069470Sbrian.for _dir in \
42143948Sbrian    lib lib32 usr/bin usr/include usr/lib32 usr/libdata/ldscripts \
42269470Sbrian    usr/libexec usr/sbin usr/share/misc \
42343948Sbrian    usr/share/snmp/defs usr/share/snmp/mibs
42443948Sbrian	mkdir -p ${LIB32TMP}/${_dir}
42543948Sbrian.endfor
42643948Sbrian	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
42743948Sbrian	    -p ${LIB32TMP}/usr/include >/dev/null
42879086Sbrian	mkdir -p ${WORLDTMP}
42943948Sbrian	ln -sf ${.CURDIR}/sys ${WORLDTMP}
43043948Sbrian.if ${MK_KERBEROS} != "no"
43143948Sbrian.for _t in obj depend all
43243948Sbrian	cd ${.CURDIR}/kerberos5/tools; \
43343948Sbrian	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= ${_t}
43443948Sbrian.endfor
43543948Sbrian.endif
43643948Sbrian.for _t in obj includes
43743948Sbrian	cd ${.CURDIR}/include; \
43843948Sbrian	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
43943948Sbrian	cd ${.CURDIR}/lib; \
44043902Sbrian	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
44143948Sbrian	cd ${.CURDIR}/gnu/lib; \
44243902Sbrian	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
44343948Sbrian.if ${MK_CRYPT} != "no"
44469470Sbrian	cd ${.CURDIR}/secure/lib; \
44543902Sbrian	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
44643948Sbrian.endif
44743902Sbrian.if ${MK_KERBEROS} != "no"
44843902Sbrian	cd ${.CURDIR}/kerberos5/lib; \
44943948Sbrian	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
45043948Sbrian.endif
45143948Sbrian.endfor
45243948Sbrian.for _dir in usr.bin/lex/lib
45343948Sbrian	cd ${.CURDIR}/${_dir}; \
45443948Sbrian	    ${LIB32MAKE} DESTDIR=${LIB32TMP} obj
45543948Sbrian.endfor
45643902Sbrian.for _dir in lib/ncurses/ncurses lib/libmagic
45743948Sbrian	cd ${.CURDIR}/${_dir}; \
45869470Sbrian	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= build-tools
45943948Sbrian.endfor
46043948Sbrian	cd ${.CURDIR}; \
46143948Sbrian	    ${LIB32MAKE} -f Makefile.inc1 DESTDIR=${LIB32TMP} libraries 
46243902Sbrian.for _t in obj depend all
46343902Sbrian	cd ${.CURDIR}/libexec/rtld-elf; \
46443902Sbrian	    PROG=ld-elf32.so.1 ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
46543902Sbrian.endfor
46643902Sbrian
46743902Sbriandistribute32 install32:
46843902Sbrian.if make(distribute32)
46943902Sbrian	mkdir -p ${DISTDIR}/${DISTRIBUTION}/usr/lib32	# XXX add to mtree
47043902Sbrian.else
47143902Sbrian	mkdir -p ${DESTDIR}/usr/lib32			# XXX add to mtree
47243902Sbrian.endif
47343902Sbrian	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
47469470Sbrian	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
47546103Sbrian.if ${MK_CRYPT} != "no"
47643902Sbrian	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
47743902Sbrian.endif
47843902Sbrian	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
47943902Sbrian.endif
48043902Sbrian
48143902Sbrian
48243902SbrianWMAKE_TGTS=
48343902Sbrian.if !defined(SUBDIR_OVERRIDE)
48443902SbrianWMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
48543902Sbrian.endif
48643902SbrianWMAKE_TGTS+=	_cleanobj _obj _build-tools
48743902Sbrian.if !defined(SUBDIR_OVERRIDE)
48843902SbrianWMAKE_TGTS+=	_cross-tools
48943902Sbrian.endif
49043902SbrianWMAKE_TGTS+=	_includes _libraries _depend everything
49143902Sbrian.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
49243902SbrianWMAKE_TGTS+=	build32
49343902Sbrian.endif
49443948Sbrian
49543948Sbrianbuildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
49643948Sbrian.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
49743902Sbrian
49843902Sbrianbuildworld_prologue:
49943902Sbrian	@echo "--------------------------------------------------------------"
50043902Sbrian	@echo ">>> World build started on `LC_ALL=C date`"
50145070Sbrian	@echo "--------------------------------------------------------------"
50245070Sbrian
50343902Sbrianbuildworld_epilogue:
50443902Sbrian	@echo
50543902Sbrian	@echo "--------------------------------------------------------------"
50643902Sbrian	@echo ">>> World build completed on `LC_ALL=C date`"
50743902Sbrian	@echo "--------------------------------------------------------------"
50843902Sbrian
50943902Sbrian#
51043902Sbrian# We need to have this as a target because the indirection between Makefile
51143902Sbrian# and Makefile.inc1 causes the correct PATH to be used, rather than a
51269470Sbrian# modification of the current environment's PATH.  In addition, we need
51343902Sbrian# to quote multiword values.
51469470Sbrian# 
51569470Sbrianbuildenvvars:
51669470Sbrian	@echo ${WMAKEENV:Q}
51769470Sbrian
51869470Sbrianbuildenv:
51969470Sbrian	@echo Entering world for ${TARGET_ARCH}:${TARGET}
52069470Sbrian	@cd ${.CURDIR} && env ${WMAKEENV} sh || true
52169470Sbrian
52243902SbrianTOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
52343902Sbriantoolchain: ${TOOLCHAIN_TGTS}
52443902Sbriankernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
52543902Sbrian
52643902Sbrian#
52743902Sbrian# installcheck
52843902Sbrian#
52943902Sbrian# Checks to be sure system is ready for installworld/installkernel.
53043902Sbrian#
53143902Sbrianinstallcheck:
53243902Sbrian
53343902Sbrian#
53469470Sbrian# Require DESTDIR to be set if installing for a different architecture.
53569470Sbrian#
53669470Sbrian.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE}
53769470Sbrian.if !make(distributeworld)
53869470Sbrianinstallcheck: installcheck_DESTDIR
53969470Sbrianinstallcheck_DESTDIR:
54069470Sbrian.if !defined(DESTDIR) || empty(DESTDIR)
54169470Sbrian	@echo "ERROR: Please set DESTDIR!"; \
54269470Sbrian	false
54369470Sbrian.endif
54469470Sbrian.endif
54569470Sbrian.endif
54669470Sbrian
54769470Sbrian#
54869470Sbrian# Check for missing UIDs/GIDs.
54969470Sbrian#
55069470SbrianCHECK_UIDS=
55169470SbrianCHECK_GIDS=	audit
55269470Sbrian.if ${MK_SENDMAIL} != "no"
55343948SbrianCHECK_UIDS+=	smmsp
55443948SbrianCHECK_GIDS+=	smmsp
55543902Sbrian.endif
55643948Sbrian.if ${MK_PF} != "no"
55743948SbrianCHECK_UIDS+=	proxy
55843902SbrianCHECK_GIDS+=	proxy authpf
55943948Sbrian.endif
56043948Sbrianinstallcheck: installcheck_UGID
56143902Sbrianinstallcheck_UGID:
56243902Sbrian.for uid in ${CHECK_UIDS}
56343902Sbrian	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
56443902Sbrian		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
56543902Sbrian		false; \
56643902Sbrian	fi
56743902Sbrian.endfor
56843902Sbrian.for gid in ${CHECK_GIDS}
56943902Sbrian	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
57043902Sbrian		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
57143902Sbrian		false; \
57243902Sbrian	fi
57343902Sbrian.endfor
57443902Sbrian
57543902Sbrian#
57643948Sbrian# distributeworld
57743948Sbrian#
57843948Sbrian# Distributes everything compiled by a `buildworld'.
57943902Sbrian#
58043948Sbrian# installworld
58143948Sbrian#
58243902Sbrian# Installs everything compiled by a 'buildworld'.
58343902Sbrian#
58449977Sbriandistributeworld installworld: installcheck
58549977Sbrian	mkdir -p ${INSTALLTMP}
58646103Sbrian	for prog in [ awk cap_mkdb cat chflags chmod chown \
58743902Sbrian	    date echo egrep find grep install-info \
58869470Sbrian	    ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
58969470Sbrian	    test true uname wc zic; do \
59069470Sbrian		cp `which $$prog` ${INSTALLTMP}; \
59169470Sbrian	done
59269470Sbrian	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
59369470Sbrian	rm -rf ${INSTALLTMP}
59469470Sbrian
59569470Sbrian#
59669470Sbrian# reinstall
59769470Sbrian#
59869470Sbrian# If you have a build server, you can NFS mount the source and obj directories
59969470Sbrian# and do a 'make reinstall' on the *client* to install new binaries from the
60069470Sbrian# most recent server build.
60169470Sbrian#
60269470Sbrianreinstall:
60369470Sbrian	@echo "--------------------------------------------------------------"
60469470Sbrian	@echo ">>> Making hierarchy"
60569470Sbrian	@echo "--------------------------------------------------------------"
60669470Sbrian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
60769470Sbrian	@echo
60869470Sbrian	@echo "--------------------------------------------------------------"
60969470Sbrian	@echo ">>> Installing everything"
61043948Sbrian	@echo "--------------------------------------------------------------"
61143948Sbrian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
61243948Sbrian.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
61343948Sbrian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
61443902Sbrian.endif
61543948Sbrian
61643948Sbrianredistribute:
61743948Sbrian	@echo "--------------------------------------------------------------"
61843902Sbrian	@echo ">>> Distributing everything"
61951700Sbrian	@echo "--------------------------------------------------------------"
62051700Sbrian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
62151700Sbrian.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
62243902Sbrian	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 DISTRIBUTION=lib32
62343902Sbrian.endif
62443902Sbrian
62551700Sbriandistrib-dirs distribution:
62643902Sbrian	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET}
62743902Sbrian
62843902Sbrian#
62943948Sbrian# buildkernel and installkernel
63043948Sbrian#
63143948Sbrian# Which kernels to build and/or install is specified by setting
63243948Sbrian# KERNCONF. If not defined a GENERIC kernel is built/installed.
63343948Sbrian# Only the existing (depending TARGET) config files are used
63443948Sbrian# for building kernels and only the first of these is designated
63543948Sbrian# as the one being installed.
63643948Sbrian#
63743948Sbrian# Note that we have to use TARGET instead of TARGET_ARCH when
63843948Sbrian# we're in kernel-land. Since only TARGET_ARCH is (expected) to
63943902Sbrian# be set to cross-build, we have to make sure TARGET is set
64043948Sbrian# properly.
64169470Sbrian
64243902Sbrian.if !defined(KERNCONF) && defined(KERNEL)
64343902SbrianKERNCONF=	${KERNEL}
64443902SbrianKERNWARN=
64543902Sbrian.else
64643902SbrianKERNCONF?=	GENERIC
64743902Sbrian.endif
64843948SbrianINSTKERNNAME?=	kernel
64943948Sbrian
65043902SbrianKERNSRCDIR?=	${.CURDIR}/sys
65143902SbrianKRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
65243902SbrianKRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
65343902SbrianKERNCONFDIR?=	${KRNLCONFDIR}
65443902Sbrian
65543902SbrianBUILDKERNELS=
65643902SbrianINSTALLKERNEL=
65743902Sbrian.for _kernel in ${KERNCONF}
65843902Sbrian.if exists(${KERNCONFDIR}/${_kernel})
65943948SbrianBUILDKERNELS+=	${_kernel}
66043902Sbrian.if empty(INSTALLKERNEL)
66143948SbrianINSTALLKERNEL= ${_kernel}
66243948Sbrian.endif
66343902Sbrian.endif
66443902Sbrian.endfor
66543902Sbrian
66669470Sbrian#
66769470Sbrian# buildkernel
66869470Sbrian#
66969470Sbrian# Builds all kernels defined by BUILDKERNELS.
67069470Sbrian#
67143902Sbrianbuildkernel:
67269470Sbrian.if empty(BUILDKERNELS)
67369470Sbrian	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
67443902Sbrian	false
67569470Sbrian.endif
67669470Sbrian.if defined(KERNWARN)
67769470Sbrian	@echo "--------------------------------------------------------------"
67869470Sbrian	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
67969470Sbrian	@echo "--------------------------------------------------------------"
68069470Sbrian	@sleep 3
68143902Sbrian.endif
68243902Sbrian	@echo
68369470Sbrian.for _kernel in ${BUILDKERNELS}
68443902Sbrian	@echo "--------------------------------------------------------------"
68543902Sbrian	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
68669470Sbrian	@echo "--------------------------------------------------------------"
68743902Sbrian	@echo "===> ${_kernel}"
68843902Sbrian	mkdir -p ${KRNLOBJDIR}
68943902Sbrian.if !defined(NO_KERNELCONFIG)
69043902Sbrian	@echo
69143902Sbrian	@echo "--------------------------------------------------------------"
69243902Sbrian	@echo ">>> stage 1: configuring the kernel"
69343902Sbrian	@echo "--------------------------------------------------------------"
69469470Sbrian	cd ${KRNLCONFDIR}; \
69543902Sbrian		PATH=${TMPPATH} \
69643902Sbrian		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
69743902Sbrian			${KERNCONFDIR}/${_kernel}
69869470Sbrian.endif
69943948Sbrian.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
70043948Sbrian	@echo
70143948Sbrian	@echo "--------------------------------------------------------------"
70243948Sbrian	@echo ">>> stage 2.1: cleaning up the object tree"
70343948Sbrian	@echo "--------------------------------------------------------------"
70443948Sbrian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
70543948Sbrian.endif
70643948Sbrian	@echo
70743948Sbrian	@echo "--------------------------------------------------------------"
70843948Sbrian	@echo ">>> stage 2.2: rebuilding the object tree"
70943948Sbrian	@echo "--------------------------------------------------------------"
71043948Sbrian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
71143948Sbrian	@echo
71243948Sbrian	@echo "--------------------------------------------------------------"
71343948Sbrian	@echo ">>> stage 2.3: build tools"
71443948Sbrian	@echo "--------------------------------------------------------------"
71543948Sbrian	cd ${KRNLOBJDIR}/${_kernel}; \
71643948Sbrian	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
71743948Sbrian	    ${MAKE} -DNO_CPU_CFLAGS -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
71843948Sbrian# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
71943948Sbrian.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
72043948Sbrian.for target in obj depend all
72143948Sbrian	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
72243948Sbrian	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
72343948Sbrian	    ${MAKE} -DNO_CPU_CFLAGS ${target}
72453540Sbrian.endfor
72561097Sbrian.endif
72661097Sbrian.if !defined(NO_KERNELDEPEND)
72761097Sbrian	@echo
72853540Sbrian	@echo "--------------------------------------------------------------"
72969470Sbrian	@echo ">>> stage 3.1: making dependencies"
73069470Sbrian	@echo "--------------------------------------------------------------"
73153540Sbrian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
73269470Sbrian.endif
73369470Sbrian	@echo
73453540Sbrian	@echo "--------------------------------------------------------------"
73553540Sbrian	@echo ">>> stage 3.2: building everything"
73653540Sbrian	@echo "--------------------------------------------------------------"
73753540Sbrian	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
73853540Sbrian	@echo "--------------------------------------------------------------"
73953540Sbrian	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
74053540Sbrian	@echo "--------------------------------------------------------------"
74153540Sbrian.endfor
74253540Sbrian
74353540Sbrian#
74453540Sbrian# installkernel, etc.
74553540Sbrian#
74664679Sbrian# Install the kernel defined by INSTALLKERNEL
74764679Sbrian#
74853540Sbrianinstallkernel installkernel.debug \
74964679Sbrianreinstallkernel reinstallkernel.debug: installcheck
75064679Sbrian.if empty(INSTALLKERNEL)
75164679Sbrian	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
75264679Sbrian	false
75364679Sbrian.endif
754	@echo "--------------------------------------------------------------"
755	@echo ">>> Installing kernel"
756	@echo "--------------------------------------------------------------"
757	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
758	    ${CROSSENV} PATH=${TMPPATH} \
759	    ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
760
761#
762# doxygen
763#
764# Build the API documentation with doxygen
765#
766doxygen:
767	@if [ ! -x `/usr/bin/which doxygen` ]; then \
768		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
769		exit 1; \
770	fi
771	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
772
773#
774# update
775#
776# Update the source tree, by running cvsup and/or running cvs to update to the
777# latest copy.
778#
779update:
780.if defined(SUP_UPDATE)
781	@echo "--------------------------------------------------------------"
782	@echo ">>> Running ${SUP}"
783	@echo "--------------------------------------------------------------"
784.if defined(SUPFILE)
785	@${SUP} ${SUPFLAGS} ${SUPFILE}
786.endif
787.if defined(SUPFILE1)
788	@${SUP} ${SUPFLAGS} ${SUPFILE1}
789.endif
790.if defined(SUPFILE2)
791	@${SUP} ${SUPFLAGS} ${SUPFILE2}
792.endif
793.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
794	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
795.endif
796.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
797	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
798.endif
799.endif
800.if defined(CVS_UPDATE)
801	@echo "--------------------------------------------------------------"
802	@echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT}
803	@echo "--------------------------------------------------------------"
804	cd ${.CURDIR}; ${CVS} -R -q update ${CVSFLAGS}
805.endif
806
807#
808# ------------------------------------------------------------------------
809#
810# From here onwards are utility targets used by the 'make world' and
811# related targets.  If your 'world' breaks, you may like to try to fix
812# the problem and manually run the following targets to attempt to
813# complete the build.  Beware, this is *not* guaranteed to work, you
814# need to have a pretty good grip on the current state of the system
815# to attempt to manually finish it.  If in doubt, 'make world' again.
816#
817
818#
819# legacy: Build compatibility shims for the next three targets
820#
821legacy:
822.if ${BOOTSTRAPPING} < 503000
823	@echo "ERROR: Source upgrades from versions prior to 5.3 not supported."; \
824	false
825.endif
826.for _tool in tools/build
827	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
828	    cd ${.CURDIR}/${_tool}; \
829	    ${MAKE} DIRPRFX=${_tool}/ obj; \
830	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
831	    ${MAKE} DIRPRFX=${_tool}/ depend; \
832	    ${MAKE} DIRPRFX=${_tool}/ all; \
833	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
834.endfor
835
836#
837# bootstrap-tools: Build tools needed for compatibility
838#
839.if ${MK_GAMES} != "no"
840_strfile=	games/fortune/strfile
841.endif
842
843.if ${MK_CXX} != "no"
844_gperf=		gnu/usr.bin/gperf
845.if ${BOOTSTRAPPING} < 700004
846_groff=		gnu/usr.bin/groff
847.else
848_groff=		gnu/usr.bin/groff/tmac
849.endif
850.endif
851
852.if ${BOOTSTRAPPING} < 600029
853_texinfo=	gnu/usr.bin/texinfo
854.endif
855
856.if ${BOOTSTRAPPING} < 600015
857_cap_mkdb=	usr.bin/cap_mkdb
858.endif
859
860.if ${BOOTSTRAPPING} < 600018
861_colldef=	usr.bin/colldef
862.endif
863
864.if ${BOOTSTRAPPING} < 600017
865_gencat=	usr.bin/gencat
866.endif
867
868.if ${BOOTSTRAPPING} < 600016
869_mklocale=	usr.bin/mklocale
870.endif
871
872.if ${BOOTSTRAPPING} < 700015
873_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
874.endif
875
876.if ${MK_RESCUE} != "no" && \
877    ${BOOTSTRAPPING} < 700026
878_crunchgen=	usr.sbin/crunch/crunchgen
879.endif
880
881.if ${BOOTSTRAPPING} < 600020
882_pwd_mkdb=	usr.sbin/pwd_mkdb
883.endif
884
885bootstrap-tools:
886.for _tool in \
887    ${_strfile} \
888    ${_gperf} \
889    ${_groff} \
890    ${_texinfo} \
891    ${_cap_mkdb} \
892    ${_colldef} \
893    ${_gencat} \
894    usr.bin/lorder \
895    usr.bin/makewhatis \
896    ${_mklocale} \
897    usr.bin/rpcgen \
898    usr.bin/xinstall \
899    ${_gensnmptree} \
900    usr.sbin/config \
901    ${_crunchgen} \
902    ${_pwd_mkdb}
903	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
904		cd ${.CURDIR}/${_tool}; \
905		${MAKE} DIRPRFX=${_tool}/ obj; \
906		${MAKE} DIRPRFX=${_tool}/ depend; \
907		${MAKE} DIRPRFX=${_tool}/ all; \
908		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
909.endfor
910
911#
912# build-tools: Build special purpose build tools
913#
914.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
915_aicasm= sys/modules/aic7xxx/aicasm
916.endif
917
918.if !defined(NO_SHARE)
919_share=	share/syscons/scrnmaps
920.endif
921
922.if ${MK_KERBEROS} != "no"
923_kerberos5_tools= kerberos5/tools
924.endif
925
926.if ${MK_RESCUE} != "no"
927_rescue= rescue/rescue
928.endif
929
930build-tools:
931.for _tool in \
932    bin/csh \
933    bin/sh \
934    ${_rescue} \
935    lib/ncurses/ncurses \
936    ${_share} \
937    ${_aicasm} \
938    usr.bin/awk \
939    lib/libmagic \
940    usr.sbin/sysinstall
941	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
942		cd ${.CURDIR}/${_tool}; \
943		${MAKE} DIRPRFX=${_tool}/ obj; \
944		${MAKE} DIRPRFX=${_tool}/ build-tools
945.endfor
946.for _tool in \
947    gnu/usr.bin/cc/cc_tools \
948    ${_kerberos5_tools}
949	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
950		cd ${.CURDIR}/${_tool}; \
951		${MAKE} DIRPRFX=${_tool}/ obj; \
952		${MAKE} DIRPRFX=${_tool}/ depend; \
953		${MAKE} DIRPRFX=${_tool}/ all
954.endfor
955
956#
957# cross-tools: Build cross-building tools
958#
959.if ${TARGET_ARCH} != ${MACHINE_ARCH}
960.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
961_btxld=		usr.sbin/btxld
962.endif
963.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
964_crunchide=	usr.sbin/crunch/crunchide
965.endif
966.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
967_kgzip=		usr.sbin/kgzip
968.endif
969.endif
970
971cross-tools:
972.for _tool in \
973    gnu/usr.bin/binutils \
974    gnu/usr.bin/cc \
975    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
976    ${_btxld} \
977    ${_crunchide} \
978    ${_kgzip}
979	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
980		cd ${.CURDIR}/${_tool}; \
981		${MAKE} DIRPRFX=${_tool}/ obj; \
982		${MAKE} DIRPRFX=${_tool}/ depend; \
983		${MAKE} DIRPRFX=${_tool}/ all; \
984		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
985.endfor
986
987#
988# hierarchy - ensure that all the needed directories are present
989#
990hierarchy:
991	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
992
993#
994# libraries - build all libraries, and install them under ${DESTDIR}.
995#
996# The list of libraries with dependents (${_prebuild_libs}) and their
997# interdependencies (__L) are built automatically by the
998# ${.CURDIR}/tools/make_libdeps.sh script.
999#
1000libraries:
1001	cd ${.CURDIR}; \
1002	    ${MAKE} -f Makefile.inc1 _startup_libs; \
1003	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1004	    ${MAKE} -f Makefile.inc1 _generic_libs;
1005
1006# These dependencies are not automatically generated:
1007#
1008# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
1009# shared libraries for ELF.
1010#
1011_startup_libs=	gnu/lib/csu gnu/lib/libgcc
1012.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1013_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1014.else
1015_startup_libs+=	lib/csu/${MACHINE_ARCH}
1016.endif
1017
1018_prebuild_libs=	${_kerberos5_lib_libasn1} ${_kerberos5_lib_libkrb5} \
1019		${_kerberos5_lib_libroken} \
1020		lib/libbz2 lib/libcom_err lib/libcrypt lib/libexpat \
1021		${_lib_libgssapi} ${_lib_libipx} \
1022		lib/libkiconv lib/libkvm lib/libmd \
1023		lib/ncurses/ncurses lib/libopie lib/libpam \
1024		lib/libradius lib/libsbuf lib/libtacplus lib/libutil \
1025		${_lib_libypclnt} lib/libz lib/msun \
1026		${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1027		${_secure_lib_libssl}
1028
1029_generic_libs=	gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib
1030
1031lib/libopie__L lib/libtacplus__L: lib/libmd__L
1032
1033.if ${MK_CRYPT} != "no"
1034.if ${MK_OPENSSL} != "no"
1035_secure_lib_libcrypto= secure/lib/libcrypto
1036_secure_lib_libssl= secure/lib/libssl
1037lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1038.if ${MK_OPENSSH} != "no"
1039_secure_lib_libssh= secure/lib/libssh
1040secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1041.if ${MK_KERBEROS} != "no"
1042secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1043    kerberos5/lib/libasn1__L lib/libcom_err__L lib/libmd__L \
1044    kerberos5/lib/libroken__L
1045.endif
1046.endif
1047.endif
1048_secure_lib=	secure/lib
1049.endif
1050
1051.if ${MK_IPX} != "no"
1052_lib_libipx=	lib/libipx
1053.endif
1054
1055.if ${MK_KERBEROS} != "no"
1056_kerberos5_lib=	kerberos5/lib
1057_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1058_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1059_kerberos5_lib_libroken= kerberos5/lib/libroken
1060_lib_libgssapi=	lib/libgssapi
1061.endif
1062
1063.if ${MK_NIS} != "no"
1064_lib_libypclnt=	lib/libypclnt
1065.endif
1066
1067.if ${MK_OPENSSL} == "no"
1068lib/libradius__L: lib/libmd__L
1069.endif
1070
1071.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1072${_lib}__L: .PHONY
1073.if exists(${.CURDIR}/${_lib})
1074	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1075		cd ${.CURDIR}/${_lib}; \
1076		${MAKE} DIRPRFX=${_lib}/ obj; \
1077		${MAKE} DIRPRFX=${_lib}/ depend; \
1078		${MAKE} DIRPRFX=${_lib}/ all; \
1079		${MAKE} DIRPRFX=${_lib}/ install
1080.endif
1081.endfor
1082
1083# libpam is special: we need to build static PAM modules before
1084# static PAM library, and dynamic PAM library before dynamic PAM
1085# modules.
1086lib/libpam__L: .PHONY
1087	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1088		cd ${.CURDIR}/lib/libpam; \
1089		${MAKE} DIRPRFX=lib/libpam/ obj; \
1090		${MAKE} DIRPRFX=lib/libpam/ depend; \
1091		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1092		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1093
1094_startup_libs: ${_startup_libs:S/$/__L/}
1095_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1096_generic_libs: ${_generic_libs:S/$/__L/}
1097
1098.for __target in all clean cleandepend cleandir depend includes obj
1099.for entry in ${SUBDIR}
1100${entry}.${__target}__D: .PHONY
1101	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1102		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1103		edir=${entry}.${MACHINE_ARCH}; \
1104		cd ${.CURDIR}/$${edir}; \
1105	else \
1106		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1107		edir=${entry}; \
1108		cd ${.CURDIR}/$${edir}; \
1109	fi; \
1110	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1111.endfor
1112par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1113.endfor
1114
1115.include <bsd.subdir.mk>
1116
1117.if make(delete-old) || make(delete-old-libs) || make(check-old)
1118
1119#
1120# check for / delete old files section
1121#
1122
1123.include "ObsoleteFiles.inc"
1124
1125OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1126else you can not start such an application. Consult UPDATING for more \
1127information regarding how to cope with the removal/revision bump of a \
1128specific library."
1129
1130.if !defined(BATCH_DELETE_OLD_FILES)
1131RM_I=-i
1132.else
1133RM_I=-v
1134.endif
1135
1136delete-old-files:
1137	@echo ">>> Removing old files (only deletes safe to delete libs)"
1138.for file in ${OLD_FILES}
1139# Ask for every old file if the user really wants to remove it.
1140# It's annoying, but better safe than sorry.
1141	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1142		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1143		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1144			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1145			chflags noschg "${DESTDIR}/${file}"; \
1146			rm ${RM_I} "${DESTDIR}/${file}"; \
1147		fi; \
1148	fi
1149.endfor
1150# Remove catpages without corresponding manpages.
1151	@3<&0; \
1152	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1153	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1154	while read catpage; do \
1155		read manpage; \
1156		if [ ! -e "$${manpage}" ]; then \
1157			rm ${RM_I} $${catpage} <&3 ; \
1158	        fi; \
1159	done
1160	@echo ">>> Old files removed"
1161
1162check-old-files:
1163	@echo ">>> Checking for old files"
1164.for file in ${OLD_FILES}
1165	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1166		 echo "${DESTDIR}/${file}"; \
1167	fi
1168.endfor
1169# Check for catpages without corresponding manpages.
1170	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1171	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1172	while read catpage; do \
1173		read manpage; \
1174		if [ ! -e "$${manpage}" ]; then \
1175			echo $${catpage} ; \
1176	        fi; \
1177	done
1178
1179delete-old-libs:
1180	@echo ">>> Removing old libraries"
1181	@echo "${OLD_LIBS_MESSAGE}" | fmt
1182.for file in ${OLD_LIBS}
1183	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1184		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1185		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1186			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1187			chflags noschg "${DESTDIR}/${file}"; \
1188			rm ${RM_I} "${DESTDIR}/${file}"; \
1189		fi; \
1190	fi
1191.endfor
1192	@echo ">>> Old libraries removed"
1193
1194check-old-libs:
1195	@echo ">>> Checking for old libraries"
1196.for file in ${OLD_LIBS}
1197	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1198		echo "${DESTDIR}/${file}"; \
1199	fi
1200.endfor
1201
1202delete-old-dirs:
1203	@echo ">>> Removing old directories"
1204.for dir in ${OLD_DIRS}
1205# Don't fail if an old directory isn't empty.
1206	@if [ -d "${DESTDIR}/${dir}" ]; then \
1207		rmdir -v "${DESTDIR}/${dir}" || true; \
1208	else \
1209		if [ -L "${DESTDIR}/${dir}" ]; then \
1210			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1211		fi; \
1212	fi
1213.endfor
1214	@echo ">>> Old directories removed"
1215
1216check-old-dirs:
1217	@echo ">>> Checking for old directories"
1218.for dir in ${OLD_DIRS}
1219	@if [ -d "${DESTDIR}/${dir}" ]; then \
1220		echo "${DESTDIR}/${dir}"; \
1221	else \
1222		if [ -L "${DESTDIR}/${dir}" ]; then \
1223			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1224		fi; \
1225	fi
1226.endfor
1227
1228delete-old: delete-old-files delete-old-dirs
1229	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1230
1231check-old: check-old-files check-old-libs check-old-dirs
1232	@echo "To remove old files and directories run '${MAKE} delete-old'."
1233	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1234
1235.endif
1236
1237#
1238# showconfig - show build configuration.
1239#
1240showconfig:
1241	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1242