Makefile.inc1 revision 167359
1139804Simp#
243819Sken# $FreeBSD: head/Makefile.inc1 167359 2007-03-09 12:11:58Z rafan $
339229Sgibbs#
439229Sgibbs# Make command line options:
539229Sgibbs#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
639229Sgibbs#	-DNO_CLEAN do not clean at all
739229Sgibbs#	-DNO_SHARE do not go into share subdir
839229Sgibbs#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
939229Sgibbs#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
1039229Sgibbs#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
1139229Sgibbs#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
1239229Sgibbs#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
1339229Sgibbs#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
1439229Sgibbs#	TARGET="machine" to crossbuild world for a different machine type
1539229Sgibbs
1639229Sgibbs#
1739229Sgibbs# The intended user-driven targets are:
1839229Sgibbs# buildworld  - rebuild *everything*, including glue to help do upgrades
1939229Sgibbs# installworld- install everything built by "buildworld"
2039229Sgibbs# doxygen     - build API documentation of the kernel
2139229Sgibbs# update      - convenient way to update your source tree (eg: cvsup/cvs)
2239229Sgibbs#
2339229Sgibbs# Standard targets (not defined here) are documented in the makefiles in
2439229Sgibbs# /usr/share/mk.  These include:
2539229Sgibbs#		obj depend all install clean cleandepend cleanobj
2639229Sgibbs
2739229Sgibbs.include <bsd.own.mk>
2839229Sgibbs
29116182Sobrien# We must do share/info early so that installation of info `dir'
30116182Sobrien# entries works correctly.  Do it first since it is less likely to
31116182Sobrien# grow dependencies on include and lib than vice versa.
32243989Sgnn#
33243989Sgnn# We must do lib/ and libexec/ before bin/, because if installworld
3439229Sgibbs# installs a new /bin/sh, the 'make' command will *immediately*
3539229Sgibbs# use that new version.  And the new (dynamically-linked) /bin/sh
3639229Sgibbs# will expect to find appropriate libraries in /lib and /libexec.
3760041Sphk#
38112368SphkSUBDIR=	share/info lib libexec
39260816SavgSUBDIR+=bin
4039229Sgibbs.if ${MK_GAMES} != "no"
41112001SphkSUBDIR+=games
42112368Sphk.endif
43112368SphkSUBDIR+=gnu include
44112001Sphk.if ${MK_KERBEROS} != "no"
45112001SphkSUBDIR+=kerberos5
46112001Sphk.endif
4739229Sgibbs.if ${MK_RESCUE} != "no"
48112368SphkSUBDIR+=rescue
4939229Sgibbs.endif
50260816SavgSUBDIR+=sbin
51243989Sgnn.if ${MK_CRYPT} != "no"
52262057SavgSUBDIR+=secure
53262057Savg.endif
54262057Savg.if !defined(NO_SHARE)
55260816SavgSUBDIR+=share
56262057Savg.endif
57260816SavgSUBDIR+=sys usr.bin usr.sbin
58243989Sgnn#
59260816Savg# We must do etc/ last for install/distribute to work.
60260816Savg#
61260816SavgSUBDIR+=etc
62260816Savg
63262057Savg# These are last, since it is nice to at least get the base system
64262057Savg# rebuilt before you do them.
65243989Sgnn.for _DIR in ${LOCAL_DIRS}
6639229Sgibbs.if exists(${.CURDIR}/${_DIR}/Makefile)
67119028SphkSUBDIR+= ${_DIR}
6839229Sgibbs.endif
6939229Sgibbs.endfor
70112368Sphk
71223061Sgibbs.if defined(SUBDIR_OVERRIDE)
7239229SgibbsSUBDIR=		${SUBDIR_OVERRIDE}
73223061Sgibbs.endif
74112001Sphk
75112001Sphk.if defined(NOCLEAN)
76112365SphkNO_CLEAN=	${NOCLEAN}
77209390Sed.endif
78112007Sphk.if defined(NO_CLEANDIR)
79112007SphkCLEANDIR=	clean cleandepend
80112007Sphk.else
8139229SgibbsCLEANDIR=	cleandir
8239229Sgibbs.endif
83112001Sphk
84112001SphkCVS?=		cvs
85112001SphkCVSFLAGS?=	-A -P -d -I!
86112365SphkSUP?=		/usr/bin/csup
87209390SedSUPFLAGS?=	-g -L 2
88112001Sphk.if defined(SUPHOST)
89112001SphkSUPFLAGS+=	-h ${SUPHOST}
90112001Sphk.endif
91112001Sphk
92112001SphkMAKEOBJDIRPREFIX?=	/usr/obj
93112001Sphk.if !defined(OSRELDATE)
94112368Sphk.if exists(/usr/include/osreldate.h)
95112368SphkOSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
96112001Sphk		/usr/include/osreldate.h
97112368Sphk.else
98112369SphkOSRELDATE=	0
99112369Sphk.endif
100112369Sphk.endif
101112369Sphk
102112369Sphk# Guess machine architecture from machine type, and vice versa.
103112369Sphk.if !defined(TARGET_ARCH) && defined(TARGET)
104112369SphkTARGET_ARCH=	${TARGET:S/pc98/i386/:S/sun4v/sparc64/}
105112369Sphk.elif !defined(TARGET) && defined(TARGET_ARCH) && \
106112368Sphk    ${TARGET_ARCH} != ${MACHINE_ARCH}
107112001SphkTARGET=		${TARGET_ARCH}
108112001Sphk.endif
109112001Sphk# Otherwise, default to current machine type and architecture.
110112001SphkTARGET?=	${MACHINE}
11139229SgibbsTARGET_ARCH?=	${MACHINE_ARCH}
11239229Sgibbs
11339229SgibbsKNOWN_ARCHES?=	amd64 arm i386 i386/pc98 ia64 powerpc sparc64 sparc64/sun4v
114112007Sphk.if ${TARGET} == ${TARGET_ARCH}
115112365Sphk_t=		${TARGET}
116209390Sed.else
11739229Sgibbs_t=		${TARGET_ARCH}/${TARGET}
11843819Sken.endif
11943819Sken.for _t in ${_t}
12039229Sgibbs.if empty(KNOWN_ARCHES:M${_t})
12139229Sgibbs.error Unknown target ${TARGET_ARCH}:${TARGET}.
12243819Sken.endif
12339229Sgibbs.endfor
124112368Sphk
12539229Sgibbs.if ${TARGET} == ${MACHINE}
12639229SgibbsTARGET_CPUTYPE?=${CPUTYPE}
12739229Sgibbs.else
12839229SgibbsTARGET_CPUTYPE?=
12943819Sken.endif
13043819Sken
13143819Sken.if !empty(TARGET_CPUTYPE)
13243819Sken_TARGET_CPUTYPE=${TARGET_CPUTYPE}
13343819Sken.else
13443819Sken_TARGET_CPUTYPE=dummy
13543819Sken.endif
13643819Sken_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
13743819Sken		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
13843819Sken.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
13943819Sken.error CPUTYPE global should be set with ?=.
14043819Sken.endif
14172012Sphk.if make(buildworld)
14243819SkenBUILD_ARCH!=	uname -p
14339229Sgibbs.if ${MACHINE_ARCH} != ${BUILD_ARCH}
14443819Sken.error To cross-build, set TARGET_ARCH.
14543819Sken.endif
14643819Sken.endif
14743819Sken.if ${MACHINE} == ${TARGET} && !defined(CROSS_BUILD_TESTING)
14843819SkenOBJTREE=	${MAKEOBJDIRPREFIX}
14943819Sken.else
15043819SkenOBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}
15143819Sken.endif
15243819SkenWORLDTMP=	${OBJTREE}${.CURDIR}/tmp
15343819Sken# /usr/games added for fortune which depend on strfile
15443819SkenBPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
15543819SkenXPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
15643819SkenSTRICTTMPPATH=	${BPATH}:${XPATH}
15743819SkenTMPPATH=	${STRICTTMPPATH}:${PATH}
15843819Sken
15943819SkenINSTALLTMP!=	/usr/bin/mktemp -d -u -t install
16043819Sken
16143819Sken#
16243819Sken# Building a world goes through the following stages
16343819Sken#
16443819Sken# 1. legacy stage [BMAKE]
16543819Sken#	This stage is responsible for creating compatibility
16643819Sken#	shims that are needed by the bootstrap-tools,
16743819Sken#	build-tools and cross-tools stages.
16843819Sken# 1. bootstrap-tools stage [BMAKE]
16943819Sken#	This stage is responsible for creating programs that
17043819Sken#	are needed for backward compatibility reasons. They
17143819Sken#	are not built as cross-tools.
17243819Sken# 2. build-tools stage [TMAKE]
173112365Sphk#	This stage is responsible for creating the object
174112365Sphk#	tree and building any tools that are needed during
17543819Sken#	the build process.
17643819Sken# 3. cross-tools stage [XMAKE]
17743819Sken#	This stage is responsible for creating any tools that
17843819Sken#	are needed for cross-builds. A cross-compiler is one
17943819Sken#	of them.
18043819Sken# 4. world stage [WMAKE]
18139229Sgibbs#	This stage actually builds the world.
18239229Sgibbs# 5. install stage (optional) [IMAKE]
183105354Srobert#	This stage installs a previously built world.
18439229Sgibbs#
18539229Sgibbs
18639229SgibbsBOOTSTRAPPING?=	0
18743819Sken
188112288Sphk# Common environment for world related stages
189112368SphkCROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
19039229Sgibbs		MACHINE_ARCH=${TARGET_ARCH} \
19139229Sgibbs		MACHINE=${TARGET} \
19239229Sgibbs		CPUTYPE=${TARGET_CPUTYPE} \
19339229Sgibbs		GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
19439229Sgibbs		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
19539229Sgibbs		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
19639229Sgibbs
19739229Sgibbs# bootstrap-tools stage
19839229SgibbsBMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
19939229Sgibbs		PATH=${BPATH}:${PATH} \
200112368Sphk		WORLDTMP=${WORLDTMP} \
20139229Sgibbs		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
20239229SgibbsBMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
20339229Sgibbs		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
204112368Sphk		DESTDIR= \
20539229Sgibbs		BOOTSTRAPPING=${OSRELDATE} \
20639229Sgibbs		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
20739229Sgibbs		-DWITHOUT_NLS -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \
20839229Sgibbs		-DNO_CPU_CFLAGS -DNO_WARNS
209112368Sphk
210112369Sphk# build-tools stage
211112369SphkTMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
212112369Sphk		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
213112369Sphk		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
214112368Sphk		DESTDIR= \
215112368Sphk		BOOTSTRAPPING=${OSRELDATE} -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS
216112368Sphk
21739229Sgibbs# cross-tools stage
21839229SgibbsXMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
21939229Sgibbs		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
22039229Sgibbs		-DWITHOUT_FORTRAN -DWITHOUT_GDB
221112288Sphk
222112288Sphk# world stage
223112288SphkWMAKEENV=	${CROSSENV} \
22439229Sgibbs		_SHLIBDIRPREFIX=${WORLDTMP} \
22539229Sgibbs		INSTALL="sh ${.CURDIR}/tools/install.sh" \
226112288Sphk		PATH=${TMPPATH}
22739229SgibbsWMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
228112368Sphk
229112368Sphk.if ${TARGET_ARCH} == "amd64"
230112368Sphk# 32 bit world
23139229SgibbsLIB32TMP=	${OBJTREE}${.CURDIR}/lib32
23239229Sgibbs
23339229Sgibbs.if empty(TARGET_CPUTYPE)
23439229SgibbsLIB32CPUTYPE=	k8
235112368Sphk.else
23639229SgibbsLIB32CPUTYPE=	${TARGET_CPUTYPE}
23739229Sgibbs.endif
23839229SgibbsLIB32FLAGS=	-m32 -march=${LIB32CPUTYPE} -mfancy-math-387 -DCOMPAT_32BIT \
23939229Sgibbs		-iprefix ${LIB32TMP}/usr/ \
24039229Sgibbs		-L${LIB32TMP}/usr/lib32 \
241112288Sphk		-B${LIB32TMP}/usr/lib32
242112288Sphk
243112288Sphk# Yes, the flags are redundant.
244112288SphkLIB32WMAKEENV=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
245112288Sphk		_SHLIBDIRPREFIX=${LIB32TMP} \
246112288Sphk		MACHINE=i386 \
247112288Sphk		MACHINE_ARCH=i386 \
248112368Sphk		INSTALL="sh ${.CURDIR}/tools/install.sh" \
249243989Sgnn		PATH=${TMPPATH} \
25039229Sgibbs		CC="${CC} ${LIB32FLAGS}" \
25139229Sgibbs		CXX="${CXX} ${LIB32FLAGS}" \
252112258Sphk		OBJC="${OBJC} ${LIB32FLAGS}" \
253112258Sphk		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
254112258Sphk		AS="${AS} --32" \
255112258Sphk		LIBDIR=/usr/lib32 \
256112368Sphk		SHLIBDIR=/usr/lib32
257112368Sphk
258112368SphkLIB32WMAKE=	${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
259112368Sphk		-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_INFO \
260112368Sphk		-DWITHOUT_HTML DESTDIR=${LIB32TMP}
261112368SphkLIB32IMAKE=	${LIB32WMAKE:NINSTALL=*:NDESTDIR=*} -DNO_INCS
262112288Sphk.endif
263112288Sphk
264243989Sgnn# install stage
265112288Sphk.if empty(.MAKEFLAGS:M-n)
266112288SphkIMAKEENV=	${CROSSENV} \
26739229Sgibbs		PATH=${STRICTTMPPATH}:${INSTALLTMP}
26839229Sgibbs.else
269112288SphkIMAKEENV=	${CROSSENV} \
270112288Sphk		PATH=${TMPPATH}:${INSTALLTMP}
271112288Sphk.endif
272112288SphkIMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1
273112288Sphk
274112288Sphk# kernel stage
275112288SphkKMAKEENV=	${WMAKEENV}
276112288SphkKMAKE=		${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME}
277112288Sphk
278112368Sphk#
279112368Sphk# buildworld
280112368Sphk#
281112368Sphk# Attempt to rebuild the entire system, with reasonable chance of
282112368Sphk# success, regardless of how old your existing system is.
283112368Sphk#
284112368Sphk_worldtmp:
285112368Sphk.if ${.CURDIR:C/[^,]//g} != ""
286112368Sphk#	The m4 build of sendmail files doesn't like it if ',' is used
287112368Sphk#	anywhere in the path of it's files.
288112368Sphk	@echo
289112368Sphk	@echo "*** Error: path to source tree contains a comma ','"
290112368Sphk	@echo
291112368Sphk	false
29239229Sgibbs.endif
29339229Sgibbs	@echo
294209390Sed	@echo "--------------------------------------------------------------"
295112288Sphk	@echo ">>> Rebuilding the temporary build tree"
296112288Sphk	@echo "--------------------------------------------------------------"
29739229Sgibbs.if !defined(NO_CLEAN)
298112288Sphk	rm -rf ${WORLDTMP}
29939229Sgibbs.if ${TARGET_ARCH} == "amd64"
30039229Sgibbs	rm -rf ${LIB32TMP}
30139229Sgibbs.endif
30239229Sgibbs.else
30339229Sgibbs	rm -rf ${WORLDTMP}/legacy/usr/include
304112288Sphk#	XXX - These two can depend on any header file.
305112288Sphk	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
306112288Sphk	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
307112288Sphk.endif
30839229Sgibbs.for _dir in \
309112368Sphk    usr/bin usr/games usr/include/c++/3.4 usr/include/sys usr/lib \
310112288Sphk    usr/libexec usr/sbin usr/share/dict \
311112288Sphk    usr/share/groff_font/devX100 \
312112288Sphk    usr/share/groff_font/devX100-12 \
31339229Sgibbs    usr/share/groff_font/devX75 \
31439229Sgibbs    usr/share/groff_font/devX75-12 \
31539229Sgibbs    usr/share/groff_font/devascii \
31639229Sgibbs    usr/share/groff_font/devcp1047 \
31751397Sphk    usr/share/groff_font/devdvi \
31851375Sphk    usr/share/groff_font/devhtml \
31939229Sgibbs    usr/share/groff_font/devkoi8-r \
32039229Sgibbs    usr/share/groff_font/devlatin1 \
321112288Sphk    usr/share/groff_font/devlbp \
322112288Sphk    usr/share/groff_font/devlj4 \
323112288Sphk    usr/share/groff_font/devps \
324112288Sphk    usr/share/groff_font/devutf8 \
325112288Sphk    usr/share/tmac/mdoc usr/share/tmac/mm
326112288Sphk	mkdir -p ${WORLDTMP}/legacy/${_dir}
32739229Sgibbs.endfor
328112288Sphk.for _dir in \
329112288Sphk    lib usr/bin usr/include usr/lib/compat/aout usr/libdata/ldscripts \
330112288Sphk    usr/libexec usr/sbin usr/share/misc \
331112288Sphk    usr/share/snmp/defs usr/share/snmp/mibs
332112288Sphk	mkdir -p ${WORLDTMP}/${_dir}
333112288Sphk.endfor
334112288Sphk	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
335112368Sphk	    -p ${WORLDTMP}/usr/include >/dev/null
336243989Sgnn	ln -sf ${.CURDIR}/sys ${WORLDTMP}
33739229Sgibbs.if ${MK_BIND_LIBS} != "no"
33839229Sgibbs	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
33951375Sphk	    -p ${WORLDTMP}/usr/include >/dev/null
34058942Sphk.endif
34158942Sphk_legacy:
342265671Smav	@echo
343265671Smav	@echo "--------------------------------------------------------------"
344265671Smav	@echo ">>> stage 1.1: legacy release compatibility shims"
345265671Smav	@echo "--------------------------------------------------------------"
346265671Smav	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
347265671Smav_bootstrap-tools:
348265671Smav	@echo
349265671Smav	@echo "--------------------------------------------------------------"
35058942Sphk	@echo ">>> stage 1.2: bootstrap tools"
35158942Sphk	@echo "--------------------------------------------------------------"
352112368Sphk	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
353112368Sphk_cleanobj:
354112368Sphk.if !defined(NO_CLEAN)
355112368Sphk	@echo
35658942Sphk	@echo "--------------------------------------------------------------"
35758942Sphk	@echo ">>> stage 2.1: cleaning up the object tree"
35858942Sphk	@echo "--------------------------------------------------------------"
35958942Sphk	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
360112368Sphk.if ${TARGET_ARCH} == "amd64"
36158942Sphk	${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
362112368Sphk.endif
363112368Sphk.endif
36458942Sphk_obj:
36558942Sphk	@echo
366265671Smav	@echo "--------------------------------------------------------------"
367243989Sgnn	@echo ">>> stage 2.2: rebuilding the object tree"
36858942Sphk	@echo "--------------------------------------------------------------"
36958942Sphk	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
37039229Sgibbs_build-tools:
37139229Sgibbs	@echo
37239229Sgibbs	@echo "--------------------------------------------------------------"
37339229Sgibbs	@echo ">>> stage 2.3: build tools"
37439229Sgibbs	@echo "--------------------------------------------------------------"
37539229Sgibbs	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
376112368Sphk_cross-tools:
377112368Sphk	@echo
378112368Sphk	@echo "--------------------------------------------------------------"
37939229Sgibbs	@echo ">>> stage 3: cross tools"
38039229Sgibbs	@echo "--------------------------------------------------------------"
38162573Sphk	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
38239229Sgibbs_includes:
383112368Sphk	@echo
384113599Sharti	@echo "--------------------------------------------------------------"
38539229Sgibbs	@echo ">>> stage 4.1: building includes"
38639229Sgibbs	@echo "--------------------------------------------------------------"
387112368Sphk	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
388112368Sphk_libraries:
38939229Sgibbs	@echo
390112368Sphk	@echo "--------------------------------------------------------------"
391112368Sphk	@echo ">>> stage 4.2: building libraries"
392112368Sphk	@echo "--------------------------------------------------------------"
393112368Sphk	${_+_}cd ${.CURDIR}; \
394112368Sphk	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
395112368Sphk	    -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE libraries
39639229Sgibbs_depend:
397112368Sphk	@echo
39839229Sgibbs	@echo "--------------------------------------------------------------"
399112368Sphk	@echo ">>> stage 4.3: make dependencies"
400112368Sphk	@echo "--------------------------------------------------------------"
401119028Sphk	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
402119028Sphkeverything:
403119028Sphk	@echo
404112368Sphk	@echo "--------------------------------------------------------------"
405112368Sphk	@echo ">>> stage 4.4: building everything"
406112368Sphk	@echo "--------------------------------------------------------------"
407112368Sphk	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
408112368Sphk.if ${TARGET_ARCH} == "amd64"
409112368Sphkbuild32:
410112368Sphk	@echo
411112368Sphk	@echo "--------------------------------------------------------------"
412112368Sphk	@echo ">>> stage 5.1: building 32 bit shim libraries"
413112368Sphk	@echo "--------------------------------------------------------------"
414112368Sphk.for _dir in \
415112368Sphk    lib lib32 usr/bin usr/include usr/lib32 usr/libdata/ldscripts \
416112368Sphk    usr/libexec usr/sbin usr/share/misc \
41739229Sgibbs    usr/share/snmp/defs usr/share/snmp/mibs
418112368Sphk	mkdir -p ${LIB32TMP}/${_dir}
419112368Sphk.endfor
420112368Sphk	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
421112368Sphk	    -p ${LIB32TMP}/usr/include >/dev/null
422112368Sphk	mkdir -p ${WORLDTMP}
423112368Sphk	ln -sf ${.CURDIR}/sys ${WORLDTMP}
424112368Sphk.if ${MK_KERBEROS} != "no"
425112368Sphk.for _t in obj depend all
426112368Sphk	cd ${.CURDIR}/kerberos5/tools; \
427112368Sphk	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= ${_t}
428112368Sphk.endfor
42939229Sgibbs.endif
43039229Sgibbs.for _t in obj includes
43139229Sgibbs	cd ${.CURDIR}/include; ${LIB32WMAKE} ${_t}
43239229Sgibbs	cd ${.CURDIR}/lib; ${LIB32WMAKE} ${_t}
43339229Sgibbs	cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} ${_t}
43439229Sgibbs.if ${MK_CRYPT} != "no"
43539229Sgibbs	cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} ${_t}
436248085Smarius.endif
437248085Smarius.if ${MK_KERBEROS} != "no"
43839229Sgibbs	cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} ${_t}
43939229Sgibbs.endif
440188063Simp.endfor
44139229Sgibbs.for _dir in usr.bin/lex/lib
44239229Sgibbs	cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} obj
44339229Sgibbs.endfor
44439229Sgibbs.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
44546381Sbillf	cd ${.CURDIR}/${_dir}; \
44646381Sbillf	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= build-tools
447113599Sharti.endfor
44862622Sjhb	cd ${.CURDIR}; \
44946381Sbillf	    ${LIB32WMAKE} -f Makefile.inc1 libraries
45046381Sbillf.for _t in obj depend all
451112001Sphk	cd ${.CURDIR}/libexec/rtld-elf; \
452112368Sphk	    PROG=ld-elf32.so.1 ${LIB32WMAKE} ${_t}
453112368Sphk.endfor
454112368Sphk
455112368Sphkdistribute32 install32:
456112368Sphk.if make(distribute32)
457112368Sphk	mkdir -p ${DISTDIR}/${DISTRIBUTION}/usr/lib32	# XXX add to mtree
458112001Sphk.else
459112001Sphk	mkdir -p ${DESTDIR}/usr/lib32			# XXX add to mtree
460112001Sphk.endif
461112001Sphk	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
462112001Sphk	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
463126080Sphk.if ${MK_CRYPT} != "no"
464126080Sphk	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
465112001Sphk.endif
466112001Sphk	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
467112001Sphk.endif
468112001Sphk
469112001Sphk
470112001SphkWMAKE_TGTS=
471112001Sphk.if !defined(SUBDIR_OVERRIDE)
472112001SphkWMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
473112001Sphk.endif
474112001SphkWMAKE_TGTS+=	_cleanobj _obj _build-tools
475112001Sphk.if !defined(SUBDIR_OVERRIDE)
476112001SphkWMAKE_TGTS+=	_cross-tools
477112001Sphk.endif
478112001SphkWMAKE_TGTS+=	_includes _libraries _depend everything
479201223Srnoland.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
480201223SrnolandWMAKE_TGTS+=	build32
481112001Sphk.endif
482112001Sphk
483112001Sphkbuildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
484112001Sphk.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
485112001Sphk
486112001Sphkbuildworld_prologue:
487112001Sphk	@echo "--------------------------------------------------------------"
488112001Sphk	@echo ">>> World build started on `LC_ALL=C date`"
489112001Sphk	@echo "--------------------------------------------------------------"
490112001Sphk
491112001Sphkbuildworld_epilogue:
492112001Sphk	@echo
493112001Sphk	@echo "--------------------------------------------------------------"
494112001Sphk	@echo ">>> World build completed on `LC_ALL=C date`"
495112001Sphk	@echo "--------------------------------------------------------------"
496112001Sphk
497112001Sphk#
498112001Sphk# We need to have this as a target because the indirection between Makefile
499112001Sphk# and Makefile.inc1 causes the correct PATH to be used, rather than a
500197309Sattilio# modification of the current environment's PATH.  In addition, we need
501112001Sphk# to quote multiword values.
502112001Sphk# 
503112001Sphkbuildenvvars:
504112368Sphk	@echo ${WMAKEENV:Q}
505223062Sken
506223062Skenbuildenv:
507223062Sken	@echo Entering world for ${TARGET_ARCH}:${TARGET}
508223062Sken	@cd ${.CURDIR} && env ${WMAKEENV} sh || true
509223062Sken
510112001SphkTOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
511197309Sattiliotoolchain: ${TOOLCHAIN_TGTS}
512112368Sphkkernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
513112368Sphk
514112368Sphk#
515112368Sphk# installcheck
516112368Sphk#
517112368Sphk# Checks to be sure system is ready for installworld/installkernel.
518112368Sphk#
519112001Sphkinstallcheck:
520197309Sattilio
521197309Sattilio#
522197309Sattilio# Require DESTDIR to be set if installing for a different architecture.
523197309Sattilio#
524197309Sattilio.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE}
525112368Sphk.if !make(distributeworld)
526197309Sattilioinstallcheck: installcheck_DESTDIR
527197309Sattilioinstallcheck_DESTDIR:
528112368Sphk.if !defined(DESTDIR) || empty(DESTDIR)
529112368Sphk	@echo "ERROR: Please set DESTDIR!"; \
530197309Sattilio	false
531197309Sattilio.endif
532197309Sattilio.endif
533197309Sattilio.endif
534197309Sattilio
535197309Sattilio#
536197309Sattilio# Check for missing UIDs/GIDs.
537197309Sattilio#
538197309SattilioCHECK_UIDS=
539197309SattilioCHECK_GIDS=	audit
540197309Sattilio.if ${MK_SENDMAIL} != "no"
541197309SattilioCHECK_UIDS+=	smmsp
542197309SattilioCHECK_GIDS+=	smmsp
543197309Sattilio.endif
544112001Sphk.if ${MK_PF} != "no"
545112001SphkCHECK_UIDS+=	proxy
546112001SphkCHECK_GIDS+=	proxy authpf
547112001Sphk.endif
548112001Sphkinstallcheck: installcheck_UGID
549112001Sphkinstallcheck_UGID:
550112001Sphk.for uid in ${CHECK_UIDS}
551112001Sphk	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
552112001Sphk		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
553112368Sphk		false; \
554197309Sattilio	fi
555197309Sattilio.endfor
556197309Sattilio.for gid in ${CHECK_GIDS}
557197309Sattilio	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
558112001Sphk		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
559112001Sphk		false; \
560112001Sphk	fi
561112001Sphk.endfor
562112001Sphk
563112001Sphk#
564112001Sphk# distributeworld
565112001Sphk#
566112368Sphk# Distributes everything compiled by a `buildworld'.
567112001Sphk#
568112001Sphk# installworld
569112001Sphk#
570112001Sphk# Installs everything compiled by a 'buildworld'.
571112001Sphk#
572112001Sphkdistributeworld installworld: installcheck
573112001Sphk	mkdir -p ${INSTALLTMP}
574112001Sphk	for prog in [ awk cap_mkdb cat chflags chmod chown \
575112288Sphk	    date echo egrep find grep install-info \
576112288Sphk	    ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
577188063Simp	    test true uname wc zic; do \
578		cp `which $$prog` ${INSTALLTMP}; \
579	done
580	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
581	rm -rf ${INSTALLTMP}
582
583#
584# reinstall
585#
586# If you have a build server, you can NFS mount the source and obj directories
587# and do a 'make reinstall' on the *client* to install new binaries from the
588# most recent server build.
589#
590reinstall:
591	@echo "--------------------------------------------------------------"
592	@echo ">>> Making hierarchy"
593	@echo "--------------------------------------------------------------"
594	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
595	@echo
596	@echo "--------------------------------------------------------------"
597	@echo ">>> Installing everything"
598	@echo "--------------------------------------------------------------"
599	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
600.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
601	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
602.endif
603
604redistribute:
605	@echo "--------------------------------------------------------------"
606	@echo ">>> Distributing everything"
607	@echo "--------------------------------------------------------------"
608	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
609.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
610	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 DISTRIBUTION=lib32
611.endif
612
613distrib-dirs distribution:
614	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET}
615
616#
617# buildkernel and installkernel
618#
619# Which kernels to build and/or install is specified by setting
620# KERNCONF. If not defined a GENERIC kernel is built/installed.
621# Only the existing (depending TARGET) config files are used
622# for building kernels and only the first of these is designated
623# as the one being installed.
624#
625# Note that we have to use TARGET instead of TARGET_ARCH when
626# we're in kernel-land. Since only TARGET_ARCH is (expected) to
627# be set to cross-build, we have to make sure TARGET is set
628# properly.
629
630.if !defined(KERNCONF) && defined(KERNEL)
631KERNCONF=	${KERNEL}
632KERNWARN=
633.else
634KERNCONF?=	GENERIC
635.endif
636INSTKERNNAME?=	kernel
637
638KERNSRCDIR?=	${.CURDIR}/sys
639KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
640KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
641KERNCONFDIR?=	${KRNLCONFDIR}
642
643BUILDKERNELS=
644INSTALLKERNEL=
645.for _kernel in ${KERNCONF}
646.if exists(${KERNCONFDIR}/${_kernel})
647BUILDKERNELS+=	${_kernel}
648.if empty(INSTALLKERNEL)
649INSTALLKERNEL= ${_kernel}
650.endif
651.endif
652.endfor
653
654#
655# buildkernel
656#
657# Builds all kernels defined by BUILDKERNELS.
658#
659buildkernel:
660.if empty(BUILDKERNELS)
661	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
662	false
663.endif
664.if defined(KERNWARN)
665	@echo "--------------------------------------------------------------"
666	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
667	@echo "--------------------------------------------------------------"
668	@sleep 3
669.endif
670	@echo
671.for _kernel in ${BUILDKERNELS}
672	@echo "--------------------------------------------------------------"
673	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
674	@echo "--------------------------------------------------------------"
675	@echo "===> ${_kernel}"
676	mkdir -p ${KRNLOBJDIR}
677.if !defined(NO_KERNELCONFIG)
678	@echo
679	@echo "--------------------------------------------------------------"
680	@echo ">>> stage 1: configuring the kernel"
681	@echo "--------------------------------------------------------------"
682	cd ${KRNLCONFDIR}; \
683		PATH=${TMPPATH} \
684		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
685			${KERNCONFDIR}/${_kernel}
686.endif
687.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
688	@echo
689	@echo "--------------------------------------------------------------"
690	@echo ">>> stage 2.1: cleaning up the object tree"
691	@echo "--------------------------------------------------------------"
692	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
693.endif
694	@echo
695	@echo "--------------------------------------------------------------"
696	@echo ">>> stage 2.2: rebuilding the object tree"
697	@echo "--------------------------------------------------------------"
698	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
699	@echo
700	@echo "--------------------------------------------------------------"
701	@echo ">>> stage 2.3: build tools"
702	@echo "--------------------------------------------------------------"
703	cd ${KRNLOBJDIR}/${_kernel}; \
704	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
705	    ${MAKE} -DNO_CPU_CFLAGS -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
706# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
707.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
708.for target in obj depend all
709	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
710	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
711	    ${MAKE} -DNO_CPU_CFLAGS ${target}
712.endfor
713.endif
714.if !defined(NO_KERNELDEPEND)
715	@echo
716	@echo "--------------------------------------------------------------"
717	@echo ">>> stage 3.1: making dependencies"
718	@echo "--------------------------------------------------------------"
719	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
720.endif
721	@echo
722	@echo "--------------------------------------------------------------"
723	@echo ">>> stage 3.2: building everything"
724	@echo "--------------------------------------------------------------"
725	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
726	@echo "--------------------------------------------------------------"
727	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
728	@echo "--------------------------------------------------------------"
729.endfor
730
731#
732# installkernel, etc.
733#
734# Install the kernel defined by INSTALLKERNEL
735#
736installkernel installkernel.debug \
737reinstallkernel reinstallkernel.debug: installcheck
738.if empty(INSTALLKERNEL)
739	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
740	false
741.endif
742	@echo "--------------------------------------------------------------"
743	@echo ">>> Installing kernel"
744	@echo "--------------------------------------------------------------"
745	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
746	    ${CROSSENV} PATH=${TMPPATH} \
747	    ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
748
749#
750# doxygen
751#
752# Build the API documentation with doxygen
753#
754doxygen:
755	@if [ ! -x `/usr/bin/which doxygen` ]; then \
756		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
757		exit 1; \
758	fi
759	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
760
761#
762# update
763#
764# Update the source tree, by running cvsup and/or running cvs to update to the
765# latest copy.
766#
767update:
768.if defined(SUP_UPDATE)
769	@echo "--------------------------------------------------------------"
770	@echo ">>> Running ${SUP}"
771	@echo "--------------------------------------------------------------"
772.if defined(SUPFILE)
773	@${SUP} ${SUPFLAGS} ${SUPFILE}
774.endif
775.if defined(SUPFILE1)
776	@${SUP} ${SUPFLAGS} ${SUPFILE1}
777.endif
778.if defined(SUPFILE2)
779	@${SUP} ${SUPFLAGS} ${SUPFILE2}
780.endif
781.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
782	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
783.endif
784.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
785	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
786.endif
787.endif
788.if defined(CVS_UPDATE)
789	@echo "--------------------------------------------------------------"
790	@echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT}
791	@echo "--------------------------------------------------------------"
792	cd ${.CURDIR}; ${CVS} -R -q update ${CVSFLAGS}
793.endif
794
795#
796# ------------------------------------------------------------------------
797#
798# From here onwards are utility targets used by the 'make world' and
799# related targets.  If your 'world' breaks, you may like to try to fix
800# the problem and manually run the following targets to attempt to
801# complete the build.  Beware, this is *not* guaranteed to work, you
802# need to have a pretty good grip on the current state of the system
803# to attempt to manually finish it.  If in doubt, 'make world' again.
804#
805
806#
807# legacy: Build compatibility shims for the next three targets
808#
809legacy:
810.if ${BOOTSTRAPPING} < 503000
811	@echo "ERROR: Source upgrades from versions prior to 5.3 not supported."; \
812	false
813.endif
814.for _tool in tools/build
815	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
816	    cd ${.CURDIR}/${_tool}; \
817	    ${MAKE} DIRPRFX=${_tool}/ obj; \
818	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
819	    ${MAKE} DIRPRFX=${_tool}/ depend; \
820	    ${MAKE} DIRPRFX=${_tool}/ all; \
821	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
822.endfor
823
824#
825# bootstrap-tools: Build tools needed for compatibility
826#
827.if ${MK_GAMES} != "no"
828_strfile=	games/fortune/strfile
829.endif
830
831.if ${MK_CXX} != "no"
832_gperf=		gnu/usr.bin/gperf
833.if ${BOOTSTRAPPING} < 700004
834_groff=		gnu/usr.bin/groff
835.else
836_groff=		gnu/usr.bin/groff/tmac
837.endif
838.endif
839
840.if ${BOOTSTRAPPING} < 600029
841_texinfo=	gnu/usr.bin/texinfo
842.endif
843
844.if ${BOOTSTRAPPING} < 600015
845_cap_mkdb=	usr.bin/cap_mkdb
846.endif
847
848.if ${BOOTSTRAPPING} < 600018
849_colldef=	usr.bin/colldef
850.endif
851
852.if ${BOOTSTRAPPING} < 600017
853_gencat=	usr.bin/gencat
854.endif
855
856.if ${BOOTSTRAPPING} < 600016
857_mklocale=	usr.bin/mklocale
858.endif
859
860.if ${BOOTSTRAPPING} < 700018
861_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
862.endif
863
864.if ${MK_RESCUE} != "no" && \
865    ${BOOTSTRAPPING} < 700026
866_crunchgen=	usr.sbin/crunch/crunchgen
867.endif
868
869.if ${BOOTSTRAPPING} < 600020
870_pwd_mkdb=	usr.sbin/pwd_mkdb
871.endif
872
873bootstrap-tools:
874.for _tool in \
875    ${_strfile} \
876    ${_gperf} \
877    ${_groff} \
878    ${_texinfo} \
879    ${_cap_mkdb} \
880    ${_colldef} \
881    ${_gencat} \
882    usr.bin/lorder \
883    usr.bin/makewhatis \
884    ${_mklocale} \
885    usr.bin/rpcgen \
886    usr.bin/xinstall \
887    ${_gensnmptree} \
888    usr.sbin/config \
889    ${_crunchgen} \
890    ${_pwd_mkdb}
891	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
892		cd ${.CURDIR}/${_tool}; \
893		${MAKE} DIRPRFX=${_tool}/ obj; \
894		${MAKE} DIRPRFX=${_tool}/ depend; \
895		${MAKE} DIRPRFX=${_tool}/ all; \
896		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
897.endfor
898
899#
900# build-tools: Build special purpose build tools
901#
902.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
903_aicasm= sys/modules/aic7xxx/aicasm
904.endif
905
906.if !defined(NO_SHARE)
907_share=	share/syscons/scrnmaps
908.endif
909
910.if ${MK_KERBEROS} != "no"
911_kerberos5_tools= kerberos5/tools
912.endif
913
914.if ${MK_RESCUE} != "no"
915_rescue= rescue/rescue
916.endif
917
918build-tools:
919.for _tool in \
920    bin/csh \
921    bin/sh \
922    ${_rescue} \
923    lib/ncurses/ncurses \
924    lib/ncurses/ncursesw \
925    ${_share} \
926    ${_aicasm} \
927    usr.bin/awk \
928    lib/libmagic \
929    usr.sbin/sysinstall
930	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
931		cd ${.CURDIR}/${_tool}; \
932		${MAKE} DIRPRFX=${_tool}/ obj; \
933		${MAKE} DIRPRFX=${_tool}/ build-tools
934.endfor
935.for _tool in \
936    gnu/usr.bin/cc/cc_tools \
937    ${_kerberos5_tools}
938	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
939		cd ${.CURDIR}/${_tool}; \
940		${MAKE} DIRPRFX=${_tool}/ obj; \
941		${MAKE} DIRPRFX=${_tool}/ depend; \
942		${MAKE} DIRPRFX=${_tool}/ all
943.endfor
944
945#
946# cross-tools: Build cross-building tools
947#
948.if ${TARGET_ARCH} != ${MACHINE_ARCH}
949.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
950_btxld=		usr.sbin/btxld
951.endif
952.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
953_crunchide=	usr.sbin/crunch/crunchide
954.endif
955.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
956_kgzip=		usr.sbin/kgzip
957.endif
958.endif
959
960cross-tools:
961.for _tool in \
962    gnu/usr.bin/binutils \
963    gnu/usr.bin/cc \
964    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
965    ${_btxld} \
966    ${_crunchide} \
967    ${_kgzip}
968	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
969		cd ${.CURDIR}/${_tool}; \
970		${MAKE} DIRPRFX=${_tool}/ obj; \
971		${MAKE} DIRPRFX=${_tool}/ depend; \
972		${MAKE} DIRPRFX=${_tool}/ all; \
973		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
974.endfor
975
976#
977# hierarchy - ensure that all the needed directories are present
978#
979hierarchy:
980	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
981
982#
983# libraries - build all libraries, and install them under ${DESTDIR}.
984#
985# The list of libraries with dependents (${_prebuild_libs}) and their
986# interdependencies (__L) are built automatically by the
987# ${.CURDIR}/tools/make_libdeps.sh script.
988#
989libraries:
990	cd ${.CURDIR}; \
991	    ${MAKE} -f Makefile.inc1 _startup_libs; \
992	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
993	    ${MAKE} -f Makefile.inc1 _generic_libs;
994
995# These dependencies are not automatically generated:
996#
997# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
998# shared libraries for ELF.
999#
1000_startup_libs=	gnu/lib/csu gnu/lib/libgcc
1001.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1002_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1003.else
1004_startup_libs+=	lib/csu/${MACHINE_ARCH}
1005.endif
1006
1007_prebuild_libs=	${_kerberos5_lib_libasn1} ${_kerberos5_lib_libkrb5} \
1008		${_kerberos5_lib_libroken} \
1009		lib/libbz2 lib/libcom_err lib/libcrypt lib/libexpat \
1010		${_lib_libgssapi} ${_lib_libipx} \
1011		lib/libkiconv lib/libkvm lib/libmd \
1012		lib/ncurses/ncurses lib/ncurses/ncursesw \
1013		lib/libopie lib/libpam \
1014		lib/libradius lib/libsbuf lib/libtacplus lib/libutil \
1015		${_lib_libypclnt} lib/libz lib/msun \
1016		${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1017		${_secure_lib_libssl}
1018
1019_generic_libs=	gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib
1020
1021lib/libopie__L lib/libtacplus__L: lib/libmd__L
1022
1023.if ${MK_CRYPT} != "no"
1024.if ${MK_OPENSSL} != "no"
1025_secure_lib_libcrypto= secure/lib/libcrypto
1026_secure_lib_libssl= secure/lib/libssl
1027lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1028.if ${MK_OPENSSH} != "no"
1029_secure_lib_libssh= secure/lib/libssh
1030secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1031.if ${MK_KERBEROS} != "no"
1032secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1033    kerberos5/lib/libasn1__L lib/libcom_err__L lib/libmd__L \
1034    kerberos5/lib/libroken__L
1035.endif
1036.endif
1037.endif
1038_secure_lib=	secure/lib
1039.endif
1040
1041.if ${MK_IPX} != "no"
1042_lib_libipx=	lib/libipx
1043.endif
1044
1045.if ${MK_KERBEROS} != "no"
1046_kerberos5_lib=	kerberos5/lib
1047_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1048_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1049_kerberos5_lib_libroken= kerberos5/lib/libroken
1050_lib_libgssapi=	lib/libgssapi
1051.endif
1052
1053.if ${MK_NIS} != "no"
1054_lib_libypclnt=	lib/libypclnt
1055.endif
1056
1057.if ${MK_OPENSSL} == "no"
1058lib/libradius__L: lib/libmd__L
1059.endif
1060
1061.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1062${_lib}__L: .PHONY
1063.if exists(${.CURDIR}/${_lib})
1064	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1065		cd ${.CURDIR}/${_lib}; \
1066		${MAKE} DIRPRFX=${_lib}/ obj; \
1067		${MAKE} DIRPRFX=${_lib}/ depend; \
1068		${MAKE} DIRPRFX=${_lib}/ all; \
1069		${MAKE} DIRPRFX=${_lib}/ install
1070.endif
1071.endfor
1072
1073# libpam is special: we need to build static PAM modules before
1074# static PAM library, and dynamic PAM library before dynamic PAM
1075# modules.
1076lib/libpam__L: .PHONY
1077	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1078		cd ${.CURDIR}/lib/libpam; \
1079		${MAKE} DIRPRFX=lib/libpam/ obj; \
1080		${MAKE} DIRPRFX=lib/libpam/ depend; \
1081		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1082		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1083
1084_startup_libs: ${_startup_libs:S/$/__L/}
1085_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1086_generic_libs: ${_generic_libs:S/$/__L/}
1087
1088.for __target in all clean cleandepend cleandir depend includes obj
1089.for entry in ${SUBDIR}
1090${entry}.${__target}__D: .PHONY
1091	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1092		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1093		edir=${entry}.${MACHINE_ARCH}; \
1094		cd ${.CURDIR}/$${edir}; \
1095	else \
1096		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1097		edir=${entry}; \
1098		cd ${.CURDIR}/$${edir}; \
1099	fi; \
1100	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1101.endfor
1102par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1103.endfor
1104
1105.include <bsd.subdir.mk>
1106
1107.if make(delete-old) || make(delete-old-libs) || make(check-old)
1108
1109#
1110# check for / delete old files section
1111#
1112
1113.include "ObsoleteFiles.inc"
1114
1115OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1116else you can not start such an application. Consult UPDATING for more \
1117information regarding how to cope with the removal/revision bump of a \
1118specific library."
1119
1120.if !defined(BATCH_DELETE_OLD_FILES)
1121RM_I=-i
1122.else
1123RM_I=-v
1124.endif
1125
1126delete-old-files:
1127	@echo ">>> Removing old files (only deletes safe to delete libs)"
1128.for file in ${OLD_FILES}
1129# Ask for every old file if the user really wants to remove it.
1130# It's annoying, but better safe than sorry.
1131	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1132		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1133		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1134			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1135			chflags noschg "${DESTDIR}/${file}"; \
1136			rm ${RM_I} "${DESTDIR}/${file}"; \
1137		fi; \
1138	fi
1139.endfor
1140# Remove catpages without corresponding manpages.
1141	@3<&0; \
1142	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1143	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1144	while read catpage; do \
1145		read manpage; \
1146		if [ ! -e "$${manpage}" ]; then \
1147			rm ${RM_I} $${catpage} <&3 ; \
1148	        fi; \
1149	done
1150	@echo ">>> Old files removed"
1151
1152check-old-files:
1153	@echo ">>> Checking for old files"
1154.for file in ${OLD_FILES}
1155	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1156		 echo "${DESTDIR}/${file}"; \
1157	fi
1158.endfor
1159# Check for catpages without corresponding manpages.
1160	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1161	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1162	while read catpage; do \
1163		read manpage; \
1164		if [ ! -e "$${manpage}" ]; then \
1165			echo $${catpage} ; \
1166	        fi; \
1167	done
1168
1169delete-old-libs:
1170	@echo ">>> Removing old libraries"
1171	@echo "${OLD_LIBS_MESSAGE}" | fmt
1172.for file in ${OLD_LIBS}
1173	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1174		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1175		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1176			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1177			chflags noschg "${DESTDIR}/${file}"; \
1178			rm ${RM_I} "${DESTDIR}/${file}"; \
1179		fi; \
1180	fi
1181.endfor
1182	@echo ">>> Old libraries removed"
1183
1184check-old-libs:
1185	@echo ">>> Checking for old libraries"
1186.for file in ${OLD_LIBS}
1187	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1188		echo "${DESTDIR}/${file}"; \
1189	fi
1190.endfor
1191
1192delete-old-dirs:
1193	@echo ">>> Removing old directories"
1194.for dir in ${OLD_DIRS}
1195# Don't fail if an old directory isn't empty.
1196	@if [ -d "${DESTDIR}/${dir}" ]; then \
1197		rmdir -v "${DESTDIR}/${dir}" || true; \
1198	else \
1199		if [ -L "${DESTDIR}/${dir}" ]; then \
1200			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1201		fi; \
1202	fi
1203.endfor
1204	@echo ">>> Old directories removed"
1205
1206check-old-dirs:
1207	@echo ">>> Checking for old directories"
1208.for dir in ${OLD_DIRS}
1209	@if [ -d "${DESTDIR}/${dir}" ]; then \
1210		echo "${DESTDIR}/${dir}"; \
1211	else \
1212		if [ -L "${DESTDIR}/${dir}" ]; then \
1213			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1214		fi; \
1215	fi
1216.endfor
1217
1218delete-old: delete-old-files delete-old-dirs
1219	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1220
1221check-old: check-old-files check-old-libs check-old-dirs
1222	@echo "To remove old files and directories run '${MAKE} delete-old'."
1223	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1224
1225.endif
1226
1227#
1228# showconfig - show build configuration.
1229#
1230showconfig:
1231	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1232