Makefile.inc1 revision 169596
125184Sjkh#
225184Sjkh# $FreeBSD: head/Makefile.inc1 169596 2007-05-16 08:39:46Z des $
344992Sbrian#
425184Sjkh# Make command line options:
525184Sjkh#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
625184Sjkh#	-DNO_CLEAN do not clean at all
725184Sjkh#	-DNO_SHARE do not go into share subdir
825184Sjkh#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
925184Sjkh#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
1025184Sjkh#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
1125184Sjkh#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
1225184Sjkh#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
1325184Sjkh#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
1425184Sjkh#	TARGET="machine" to crossbuild world for a different machine type
1525184Sjkh
1625184Sjkh#
1725184Sjkh# The intended user-driven targets are:
1825184Sjkh# buildworld  - rebuild *everything*, including glue to help do upgrades
1925184Sjkh# installworld- install everything built by "buildworld"
2025184Sjkh# doxygen     - build API documentation of the kernel
2125184Sjkh# update      - convenient way to update your source tree (eg: cvsup/cvs)
2225184Sjkh#
2325184Sjkh# Standard targets (not defined here) are documented in the makefiles in
2425184Sjkh# /usr/share/mk.  These include:
2525184Sjkh#		obj depend all install clean cleandepend cleanobj
2625184Sjkh
2725184Sjkh.include <bsd.own.mk>
2840006Sphk
2940006Sphk# We must do share/info early so that installation of info `dir'
3040006Sphk# entries works correctly.  Do it first since it is less likely to
3140006Sphk# grow dependencies on include and lib than vice versa.
3240006Sphk#
3340006Sphk# We must do lib/ and libexec/ before bin/, because if installworld
3442621Shm# installs a new /bin/sh, the 'make' command will *immediately*
3542621Shm# use that new version.  And the new (dynamically-linked) /bin/sh
3642621Shm# will expect to find appropriate libraries in /lib and /libexec.
3742621Shm#
3842621ShmSUBDIR=	share/info lib libexec
3942627SjoergSUBDIR+=bin
4042627Sjoerg.if ${MK_GAMES} != "no"
4142627SjoergSUBDIR+=games
4242627Sjoerg.endif
4342627Sjoerg.if ${MK_CDDL} != "no"
4442627SjoergSUBDIR+=cddl
4542627Sjoerg.endif
4642627SjoergSUBDIR+=gnu include
4742627Sjoerg.if ${MK_KERBEROS} != "no"
4842627SjoergSUBDIR+=kerberos5
4942627Sjoerg.endif
5042627Sjoerg.if ${MK_RESCUE} != "no"
5142627SjoergSUBDIR+=rescue
5242627Sjoerg.endif
5325184SjkhSUBDIR+=sbin
5425184Sjkh.if ${MK_CRYPT} != "no"
5525184SjkhSUBDIR+=secure
5633682Sbrian.endif
5725184Sjkh.if !defined(NO_SHARE)
5825184SjkhSUBDIR+=share
5925184Sjkh.endif
6025184SjkhSUBDIR+=sys usr.bin usr.sbin
6125184Sjkh#
6225184Sjkh# We must do etc/ last for install/distribute to work.
6325184Sjkh#
6425184SjkhSUBDIR+=etc
6525184Sjkh
6625184Sjkh# These are last, since it is nice to at least get the base system
6725184Sjkh# rebuilt before you do them.
6825184Sjkh.for _DIR in ${LOCAL_DIRS}
6925184Sjkh.if exists(${.CURDIR}/${_DIR}/Makefile)
7025184SjkhSUBDIR+= ${_DIR}
7125184Sjkh.endif
7225184Sjkh.endfor
7325184Sjkh
7425184Sjkh.if defined(SUBDIR_OVERRIDE)
7525184SjkhSUBDIR=		${SUBDIR_OVERRIDE}
7625184Sjkh.endif
7725184Sjkh
7825184Sjkh.if defined(NOCLEAN)
7925184SjkhNO_CLEAN=	${NOCLEAN}
8025184Sjkh.endif
8125184Sjkh.if defined(NO_CLEANDIR)
8229300SdannyCLEANDIR=	clean cleandepend
8329300Sdanny.else
8429300SdannyCLEANDIR=	cleandir
8529300Sdanny.endif
8632382Salex
8732382SalexCVS?=		cvs
8832382SalexCVSFLAGS?=	-A -P -d -I!
8929300SdannySUP?=		/usr/bin/csup
9029300SdannySUPFLAGS?=	-g -L 2
9129300Sdanny.if defined(SUPHOST)
9229300SdannySUPFLAGS+=	-h ${SUPHOST}
9341077Speter.endif
9429300Sdanny
9529300SdannyMAKEOBJDIRPREFIX?=	/usr/obj
9629300Sdanny.if !defined(OSRELDATE)
9729300Sdanny.if exists(/usr/include/osreldate.h)
9829300SdannyOSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
9929300Sdanny		/usr/include/osreldate.h
10029300Sdanny.else
10129300SdannyOSRELDATE=	0
10229300Sdanny.endif
10344992Sbrian.endif
10425364Sjkh
10544992Sbrian# Guess machine architecture from machine type, and vice versa.
10644992Sbrian.if !defined(TARGET_ARCH) && defined(TARGET)
10744992SbrianTARGET_ARCH=	${TARGET:S/pc98/i386/:S/sun4v/sparc64/}
10844992Sbrian.elif !defined(TARGET) && defined(TARGET_ARCH) && \
10944992Sbrian    ${TARGET_ARCH} != ${MACHINE_ARCH}
11044992SbrianTARGET=		${TARGET_ARCH}
11144992Sbrian.endif
11244992Sbrian# Otherwise, default to current machine type and architecture.
11344992SbrianTARGET?=	${MACHINE}
11444992SbrianTARGET_ARCH?=	${MACHINE_ARCH}
11544992Sbrian
11644992SbrianKNOWN_ARCHES?=	amd64 arm i386 i386/pc98 ia64 powerpc sparc64 sparc64/sun4v
11744992Sbrian.if ${TARGET} == ${TARGET_ARCH}
11829300Sdanny_t=		${TARGET}
11933337Salex.else
12033337Salex_t=		${TARGET_ARCH}/${TARGET}
12133149Salex.endif
12233149Salex.for _t in ${_t}
12333149Salex.if empty(KNOWN_ARCHES:M${_t})
12433149Salex.error Unknown target ${TARGET_ARCH}:${TARGET}.
12529300Sdanny.endif
12625184Sjkh.endfor
12725184Sjkh
12840006Sphk.if ${TARGET} == ${MACHINE}
12940006SphkTARGET_CPUTYPE?=${CPUTYPE}
13040006Sphk.else
13140006SphkTARGET_CPUTYPE?=
13240006Sphk.endif
13329300Sdanny
13429300Sdanny.if !empty(TARGET_CPUTYPE)
13525184Sjkh_TARGET_CPUTYPE=${TARGET_CPUTYPE}
13625184Sjkh.else
13725184Sjkh_TARGET_CPUTYPE=dummy
13825184Sjkh.endif
13925184Sjkh_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
14025184Sjkh		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
14125184Sjkh.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
14225184Sjkh.error CPUTYPE global should be set with ?=.
14325184Sjkh.endif
14425184Sjkh.if make(buildworld)
14525184SjkhBUILD_ARCH!=	uname -p
14625184Sjkh.if ${MACHINE_ARCH} != ${BUILD_ARCH}
14725184Sjkh.error To cross-build, set TARGET_ARCH.
14825184Sjkh.endif
14927218Spst.endif
15027218Spst.if ${MACHINE} == ${TARGET} && !defined(CROSS_BUILD_TESTING)
15127218SpstOBJTREE=	${MAKEOBJDIRPREFIX}
15227218Spst.else
15327218SpstOBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}
15439267Sjkoshy.endif
15539267SjkoshyWORLDTMP=	${OBJTREE}${.CURDIR}/tmp
15639267Sjkoshy# /usr/games added for fortune which depend on strfile
15739267SjkoshyBPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
15839267SjkoshyXPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
15925184SjkhSTRICTTMPPATH=	${BPATH}:${XPATH}
16025365SjkhTMPPATH=	${STRICTTMPPATH}:${PATH}
16125184Sjkh
16225184SjkhINSTALLTMP!=	/usr/bin/mktemp -d -u -t install
16325184Sjkh
16433439Sguido#
16533439Sguido# Building a world goes through the following stages
16633439Sguido#
16733439Sguido# 1. legacy stage [BMAKE]
16833439Sguido#	This stage is responsible for creating compatibility
16933439Sguido#	shims that are needed by the bootstrap-tools,
17033439Sguido#	build-tools and cross-tools stages.
17133439Sguido# 1. bootstrap-tools stage [BMAKE]
17233439Sguido#	This stage is responsible for creating programs that
17333439Sguido#	are needed for backward compatibility reasons. They
17425184Sjkh#	are not built as cross-tools.
17525365Sjkh# 2. build-tools stage [TMAKE]
17625184Sjkh#	This stage is responsible for creating the object
17725184Sjkh#	tree and building any tools that are needed during
17825184Sjkh#	the build process.
17936174Sjkh# 3. cross-tools stage [XMAKE]
18036174Sjkh#	This stage is responsible for creating any tools that
18136174Sjkh#	are needed for cross-builds. A cross-compiler is one
18236174Sjkh#	of them.
18336174Sjkh# 4. world stage [WMAKE]
18436174Sjkh#	This stage actually builds the world.
18536174Sjkh# 5. install stage (optional) [IMAKE]
18636174Sjkh#	This stage installs a previously built world.
18736174Sjkh#
18836174Sjkh
18936174SjkhBOOTSTRAPPING?=	0
19025184Sjkh
19136174Sjkh# Common environment for world related stages
19225184SjkhCROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
19325184Sjkh		MACHINE_ARCH=${TARGET_ARCH} \
19425765Sjkh		MACHINE=${TARGET} \
19536174Sjkh		CPUTYPE=${TARGET_CPUTYPE} \
19636174Sjkh		GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
19725765Sjkh		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
19836174Sjkh		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
19934395Sjkh
20034395Sjkh# bootstrap-tools stage
20134395SjkhBMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
20225184Sjkh		PATH=${BPATH}:${PATH} \
20325184Sjkh		WORLDTMP=${WORLDTMP} \
20425184Sjkh		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
20525184SjkhBMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
20625184Sjkh		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
20725184Sjkh		DESTDIR= \
20825184Sjkh		BOOTSTRAPPING=${OSRELDATE} \
20932949Swollman		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
21025184Sjkh		-DWITHOUT_NLS -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \
21125184Sjkh		-DNO_CPU_CFLAGS -DNO_WARNS
21231472Sobrien
21335787Sandreas# build-tools stage
21431472SobrienTMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
21525184Sjkh		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
21631472Sobrien		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
21735787Sandreas		DESTDIR= \
21825184Sjkh		BOOTSTRAPPING=${OSRELDATE} -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS
21925184Sjkh
22025184Sjkh# cross-tools stage
22125184SjkhXMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
22225184Sjkh		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
22325184Sjkh		-DWITHOUT_FORTRAN -DWITHOUT_GDB
22425184Sjkh
22544668Sjfitz# world stage
22625184SjkhWMAKEENV=	${CROSSENV} \
22725184Sjkh		_SHLIBDIRPREFIX=${WORLDTMP} \
22825184Sjkh		INSTALL="sh ${.CURDIR}/tools/install.sh" \
22925184Sjkh		PATH=${TMPPATH}
23025184SjkhWMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
23125184Sjkh
23225184Sjkh.if ${TARGET_ARCH} == "amd64"
23325184Sjkh# 32 bit world
23425184SjkhLIB32TMP=	${OBJTREE}${.CURDIR}/lib32
23525184Sjkh
23625184Sjkh.if empty(TARGET_CPUTYPE)
23725184SjkhLIB32CPUTYPE=	k8
23825184Sjkh.else
23925184SjkhLIB32CPUTYPE=	${TARGET_CPUTYPE}
24025184Sjkh.endif
24125184SjkhLIB32FLAGS=	-m32 -march=${LIB32CPUTYPE} -mfancy-math-387 -DCOMPAT_32BIT \
24225184Sjkh		-iprefix ${LIB32TMP}/usr/ \
24325184Sjkh		-L${LIB32TMP}/usr/lib32 \
24425184Sjkh		-B${LIB32TMP}/usr/lib32
24525184Sjkh
24625184Sjkh# Yes, the flags are redundant.
24725184SjkhLIB32WMAKEENV=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
24825184Sjkh		_SHLIBDIRPREFIX=${LIB32TMP} \
24925184Sjkh		MACHINE=i386 \
25035149Smarkm		MACHINE_ARCH=i386 \
25135149Smarkm		INSTALL="sh ${.CURDIR}/tools/install.sh" \
25235149Smarkm		PATH=${TMPPATH} \
25335149Smarkm		CC="${CC} ${LIB32FLAGS}" \
25435149Smarkm		CXX="${CXX} ${LIB32FLAGS}" \
25535149Smarkm		OBJC="${OBJC} ${LIB32FLAGS}" \
25635149Smarkm		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
25735149Smarkm		AS="${AS} --32" \
25835149Smarkm		LIBDIR=/usr/lib32 \
25940006Sphk		SHLIBDIR=/usr/lib32
26040006Sphk
26140006SphkLIB32WMAKE=	${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
26240006Sphk		-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_INFO \
26340006Sphk		-DWITHOUT_HTML DESTDIR=${LIB32TMP}
26425184SjkhLIB32IMAKE=	${LIB32WMAKE:NINSTALL=*:NDESTDIR=*} -DNO_INCS
26525184Sjkh.endif
26625184Sjkh
26725184Sjkh# install stage
26825184Sjkh.if empty(.MAKEFLAGS:M-n)
26925184SjkhIMAKEENV=	${CROSSENV} \
27025184Sjkh		PATH=${STRICTTMPPATH}:${INSTALLTMP}
27125184Sjkh.else
27225184SjkhIMAKEENV=	${CROSSENV} \
27325184Sjkh		PATH=${TMPPATH}:${INSTALLTMP}
27425184Sjkh.endif
27525184SjkhIMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1
27625184Sjkh
27725184Sjkh# kernel stage
27825184SjkhKMAKEENV=	${WMAKEENV}
27925184SjkhKMAKE=		${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME}
28025916Sjkh
28125184Sjkh#
28225184Sjkh# buildworld
28325184Sjkh#
28425184Sjkh# Attempt to rebuild the entire system, with reasonable chance of
28525184Sjkh# success, regardless of how old your existing system is.
28625184Sjkh#
28725184Sjkh_worldtmp:
28825184Sjkh.if ${.CURDIR:C/[^,]//g} != ""
28925184Sjkh#	The m4 build of sendmail files doesn't like it if ',' is used
29025916Sjkh#	anywhere in the path of it's files.
29141371Sjkoshy	@echo
29241371Sjkoshy	@echo "*** Error: path to source tree contains a comma ','"
29341371Sjkoshy	@echo
29441185Smsmith	false
29525184Sjkh.endif
29625184Sjkh	@echo
29725184Sjkh	@echo "--------------------------------------------------------------"
29825184Sjkh	@echo ">>> Rebuilding the temporary build tree"
29935459Sphk	@echo "--------------------------------------------------------------"
30039380Scracauer.if !defined(NO_CLEAN)
30135459Sphk	rm -rf ${WORLDTMP}
30225184Sjkh.if ${TARGET_ARCH} == "amd64"
30325184Sjkh	rm -rf ${LIB32TMP}
30425184Sjkh.endif
30525184Sjkh.else
30642270Sjkh	rm -rf ${WORLDTMP}/legacy/usr/include
30725184Sjkh#	XXX - These two can depend on any header file.
30825184Sjkh	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
30925184Sjkh	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
31025184Sjkh.endif
31131033Ssef.for _dir in \
31231033Ssef    usr/bin usr/games usr/include/c++/3.4 usr/include/sys usr/lib \
31331033Ssef    usr/libexec usr/sbin usr/share/dict \
31431033Ssef    usr/share/groff_font/devX100 \
31531033Ssef    usr/share/groff_font/devX100-12 \
31631033Ssef    usr/share/groff_font/devX75 \
31738316Sphk    usr/share/groff_font/devX75-12 \
31831033Ssef    usr/share/groff_font/devascii \
31931033Ssef    usr/share/groff_font/devcp1047 \
32038316Sphk    usr/share/groff_font/devdvi \
32131033Ssef    usr/share/groff_font/devhtml \
32231033Ssef    usr/share/groff_font/devkoi8-r \
32325184Sjkh    usr/share/groff_font/devlatin1 \
32425184Sjkh    usr/share/groff_font/devlbp \
32525184Sjkh    usr/share/groff_font/devlj4 \
32625184Sjkh    usr/share/groff_font/devps \
32725184Sjkh    usr/share/groff_font/devutf8 \
328    usr/share/tmac/mdoc usr/share/tmac/mm
329	mkdir -p ${WORLDTMP}/legacy/${_dir}
330.endfor
331.for _dir in \
332    lib usr/bin usr/include usr/lib/compat/aout usr/libdata/ldscripts \
333    usr/libexec usr/sbin usr/share/misc \
334    usr/share/snmp/defs usr/share/snmp/mibs
335	mkdir -p ${WORLDTMP}/${_dir}
336.endfor
337	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
338	    -p ${WORLDTMP}/usr/include >/dev/null
339	ln -sf ${.CURDIR}/sys ${WORLDTMP}
340.if ${MK_BIND_LIBS} != "no"
341	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
342	    -p ${WORLDTMP}/usr/include >/dev/null
343.endif
344_legacy:
345	@echo
346	@echo "--------------------------------------------------------------"
347	@echo ">>> stage 1.1: legacy release compatibility shims"
348	@echo "--------------------------------------------------------------"
349	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
350_bootstrap-tools:
351	@echo
352	@echo "--------------------------------------------------------------"
353	@echo ">>> stage 1.2: bootstrap tools"
354	@echo "--------------------------------------------------------------"
355	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
356_cleanobj:
357.if !defined(NO_CLEAN)
358	@echo
359	@echo "--------------------------------------------------------------"
360	@echo ">>> stage 2.1: cleaning up the object tree"
361	@echo "--------------------------------------------------------------"
362	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
363.if ${TARGET_ARCH} == "amd64"
364	${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
365.endif
366.endif
367_obj:
368	@echo
369	@echo "--------------------------------------------------------------"
370	@echo ">>> stage 2.2: rebuilding the object tree"
371	@echo "--------------------------------------------------------------"
372	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
373_build-tools:
374	@echo
375	@echo "--------------------------------------------------------------"
376	@echo ">>> stage 2.3: build tools"
377	@echo "--------------------------------------------------------------"
378	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
379_cross-tools:
380	@echo
381	@echo "--------------------------------------------------------------"
382	@echo ">>> stage 3: cross tools"
383	@echo "--------------------------------------------------------------"
384	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
385_includes:
386	@echo
387	@echo "--------------------------------------------------------------"
388	@echo ">>> stage 4.1: building includes"
389	@echo "--------------------------------------------------------------"
390	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
391_libraries:
392	@echo
393	@echo "--------------------------------------------------------------"
394	@echo ">>> stage 4.2: building libraries"
395	@echo "--------------------------------------------------------------"
396	${_+_}cd ${.CURDIR}; \
397	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
398	    -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE libraries
399_depend:
400	@echo
401	@echo "--------------------------------------------------------------"
402	@echo ">>> stage 4.3: make dependencies"
403	@echo "--------------------------------------------------------------"
404	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
405everything:
406	@echo
407	@echo "--------------------------------------------------------------"
408	@echo ">>> stage 4.4: building everything"
409	@echo "--------------------------------------------------------------"
410	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
411.if ${TARGET_ARCH} == "amd64"
412build32:
413	@echo
414	@echo "--------------------------------------------------------------"
415	@echo ">>> stage 5.1: building 32 bit shim libraries"
416	@echo "--------------------------------------------------------------"
417.for _dir in \
418    lib lib32 usr/bin usr/include usr/lib32 usr/libdata/ldscripts \
419    usr/libexec usr/sbin usr/share/misc \
420    usr/share/snmp/defs usr/share/snmp/mibs
421	mkdir -p ${LIB32TMP}/${_dir}
422.endfor
423	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
424	    -p ${LIB32TMP}/usr/include >/dev/null
425	mkdir -p ${WORLDTMP}
426	ln -sf ${.CURDIR}/sys ${WORLDTMP}
427.if ${MK_KERBEROS} != "no"
428.for _t in obj depend all
429	cd ${.CURDIR}/kerberos5/tools; \
430	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= ${_t}
431.endfor
432.endif
433.for _t in obj includes
434	cd ${.CURDIR}/include; ${LIB32WMAKE} ${_t}
435	cd ${.CURDIR}/lib; ${LIB32WMAKE} ${_t}
436.if ${MK_CDDL} != "no"
437	cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} ${_t}
438.endif
439	cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} ${_t}
440.if ${MK_CRYPT} != "no"
441	cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} ${_t}
442.endif
443.if ${MK_KERBEROS} != "no"
444	cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} ${_t}
445.endif
446.endfor
447.for _dir in usr.bin/lex/lib
448	cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} obj
449.endfor
450.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
451	cd ${.CURDIR}/${_dir}; \
452	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= build-tools
453.endfor
454	cd ${.CURDIR}; \
455	    ${LIB32WMAKE} -f Makefile.inc1 libraries
456.for _t in obj depend all
457	cd ${.CURDIR}/libexec/rtld-elf; \
458	    PROG=ld-elf32.so.1 ${LIB32WMAKE} ${_t}
459.endfor
460
461distribute32 install32:
462.if make(distribute32)
463	mkdir -p ${DISTDIR}/${DISTRIBUTION}/usr/lib32	# XXX add to mtree
464.else
465	mkdir -p ${DESTDIR}/usr/lib32			# XXX add to mtree
466.endif
467	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
468	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
469.if ${MK_CRYPT} != "no"
470	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
471.endif
472	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
473.endif
474
475
476WMAKE_TGTS=
477.if !defined(SUBDIR_OVERRIDE)
478WMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
479.endif
480WMAKE_TGTS+=	_cleanobj _obj _build-tools
481.if !defined(SUBDIR_OVERRIDE)
482WMAKE_TGTS+=	_cross-tools
483.endif
484WMAKE_TGTS+=	_includes _libraries _depend everything
485.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
486WMAKE_TGTS+=	build32
487.endif
488
489buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
490.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
491
492buildworld_prologue:
493	@echo "--------------------------------------------------------------"
494	@echo ">>> World build started on `LC_ALL=C date`"
495	@echo "--------------------------------------------------------------"
496
497buildworld_epilogue:
498	@echo
499	@echo "--------------------------------------------------------------"
500	@echo ">>> World build completed on `LC_ALL=C date`"
501	@echo "--------------------------------------------------------------"
502
503#
504# We need to have this as a target because the indirection between Makefile
505# and Makefile.inc1 causes the correct PATH to be used, rather than a
506# modification of the current environment's PATH.  In addition, we need
507# to quote multiword values.
508# 
509buildenvvars:
510	@echo ${WMAKEENV:Q}
511
512buildenv:
513	@echo Entering world for ${TARGET_ARCH}:${TARGET}
514	@cd ${.CURDIR} && env ${WMAKEENV} sh || true
515
516TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
517toolchain: ${TOOLCHAIN_TGTS}
518kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
519
520#
521# installcheck
522#
523# Checks to be sure system is ready for installworld/installkernel.
524#
525installcheck:
526
527#
528# Require DESTDIR to be set if installing for a different architecture.
529#
530.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE}
531.if !make(distributeworld)
532installcheck: installcheck_DESTDIR
533installcheck_DESTDIR:
534.if !defined(DESTDIR) || empty(DESTDIR)
535	@echo "ERROR: Please set DESTDIR!"; \
536	false
537.endif
538.endif
539.endif
540
541#
542# Check for missing UIDs/GIDs.
543#
544CHECK_UIDS=
545CHECK_GIDS=	audit
546.if ${MK_SENDMAIL} != "no"
547CHECK_UIDS+=	smmsp
548CHECK_GIDS+=	smmsp
549.endif
550.if ${MK_PF} != "no"
551CHECK_UIDS+=	proxy
552CHECK_GIDS+=	proxy authpf
553.endif
554installcheck: installcheck_UGID
555installcheck_UGID:
556.for uid in ${CHECK_UIDS}
557	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
558		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
559		false; \
560	fi
561.endfor
562.for gid in ${CHECK_GIDS}
563	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
564		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
565		false; \
566	fi
567.endfor
568
569#
570# distributeworld
571#
572# Distributes everything compiled by a `buildworld'.
573#
574# installworld
575#
576# Installs everything compiled by a 'buildworld'.
577#
578distributeworld installworld: installcheck
579	mkdir -p ${INSTALLTMP}
580	for prog in [ awk cap_mkdb cat chflags chmod chown \
581	    date echo egrep find grep install-info \
582	    ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
583	    test true uname wc zic; do \
584		cp `which $$prog` ${INSTALLTMP}; \
585	done
586	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
587	rm -rf ${INSTALLTMP}
588
589#
590# reinstall
591#
592# If you have a build server, you can NFS mount the source and obj directories
593# and do a 'make reinstall' on the *client* to install new binaries from the
594# most recent server build.
595#
596reinstall:
597	@echo "--------------------------------------------------------------"
598	@echo ">>> Making hierarchy"
599	@echo "--------------------------------------------------------------"
600	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
601	@echo
602	@echo "--------------------------------------------------------------"
603	@echo ">>> Installing everything"
604	@echo "--------------------------------------------------------------"
605	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
606.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
607	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
608.endif
609
610redistribute:
611	@echo "--------------------------------------------------------------"
612	@echo ">>> Distributing everything"
613	@echo "--------------------------------------------------------------"
614	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
615.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
616	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 DISTRIBUTION=lib32
617.endif
618
619distrib-dirs distribution:
620	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET}
621
622#
623# buildkernel and installkernel
624#
625# Which kernels to build and/or install is specified by setting
626# KERNCONF. If not defined a GENERIC kernel is built/installed.
627# Only the existing (depending TARGET) config files are used
628# for building kernels and only the first of these is designated
629# as the one being installed.
630#
631# Note that we have to use TARGET instead of TARGET_ARCH when
632# we're in kernel-land. Since only TARGET_ARCH is (expected) to
633# be set to cross-build, we have to make sure TARGET is set
634# properly.
635
636.if !defined(KERNCONF) && defined(KERNEL)
637KERNCONF=	${KERNEL}
638KERNWARN=
639.else
640KERNCONF?=	GENERIC
641.endif
642INSTKERNNAME?=	kernel
643
644KERNSRCDIR?=	${.CURDIR}/sys
645KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
646KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
647KERNCONFDIR?=	${KRNLCONFDIR}
648
649BUILDKERNELS=
650INSTALLKERNEL=
651.for _kernel in ${KERNCONF}
652.if exists(${KERNCONFDIR}/${_kernel})
653BUILDKERNELS+=	${_kernel}
654.if empty(INSTALLKERNEL)
655INSTALLKERNEL= ${_kernel}
656.endif
657.endif
658.endfor
659
660#
661# buildkernel
662#
663# Builds all kernels defined by BUILDKERNELS.
664#
665buildkernel:
666.if empty(BUILDKERNELS)
667	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
668	false
669.endif
670.if defined(KERNWARN)
671	@echo "--------------------------------------------------------------"
672	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
673	@echo "--------------------------------------------------------------"
674	@sleep 3
675.endif
676	@echo
677.for _kernel in ${BUILDKERNELS}
678	@echo "--------------------------------------------------------------"
679	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
680	@echo "--------------------------------------------------------------"
681	@echo "===> ${_kernel}"
682	mkdir -p ${KRNLOBJDIR}
683.if !defined(NO_KERNELCONFIG)
684	@echo
685	@echo "--------------------------------------------------------------"
686	@echo ">>> stage 1: configuring the kernel"
687	@echo "--------------------------------------------------------------"
688	cd ${KRNLCONFDIR}; \
689		PATH=${TMPPATH} \
690		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
691			${KERNCONFDIR}/${_kernel}
692.endif
693.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
694	@echo
695	@echo "--------------------------------------------------------------"
696	@echo ">>> stage 2.1: cleaning up the object tree"
697	@echo "--------------------------------------------------------------"
698	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
699.endif
700	@echo
701	@echo "--------------------------------------------------------------"
702	@echo ">>> stage 2.2: rebuilding the object tree"
703	@echo "--------------------------------------------------------------"
704	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
705	@echo
706	@echo "--------------------------------------------------------------"
707	@echo ">>> stage 2.3: build tools"
708	@echo "--------------------------------------------------------------"
709	cd ${KRNLOBJDIR}/${_kernel}; \
710	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
711	    ${MAKE} -DNO_CPU_CFLAGS -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
712# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
713.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
714.for target in obj depend all
715	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
716	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
717	    ${MAKE} -DNO_CPU_CFLAGS ${target}
718.endfor
719.endif
720.if !defined(NO_KERNELDEPEND)
721	@echo
722	@echo "--------------------------------------------------------------"
723	@echo ">>> stage 3.1: making dependencies"
724	@echo "--------------------------------------------------------------"
725	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
726.endif
727	@echo
728	@echo "--------------------------------------------------------------"
729	@echo ">>> stage 3.2: building everything"
730	@echo "--------------------------------------------------------------"
731	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
732	@echo "--------------------------------------------------------------"
733	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
734	@echo "--------------------------------------------------------------"
735.endfor
736
737#
738# installkernel, etc.
739#
740# Install the kernel defined by INSTALLKERNEL
741#
742installkernel installkernel.debug \
743reinstallkernel reinstallkernel.debug: installcheck
744.if empty(INSTALLKERNEL)
745	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
746	false
747.endif
748	@echo "--------------------------------------------------------------"
749	@echo ">>> Installing kernel"
750	@echo "--------------------------------------------------------------"
751	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
752	    ${CROSSENV} PATH=${TMPPATH} \
753	    ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
754
755#
756# doxygen
757#
758# Build the API documentation with doxygen
759#
760doxygen:
761	@if [ ! -x `/usr/bin/which doxygen` ]; then \
762		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
763		exit 1; \
764	fi
765	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
766
767#
768# update
769#
770# Update the source tree, by running cvsup and/or running cvs to update to the
771# latest copy.
772#
773update:
774.if defined(SUP_UPDATE)
775	@echo "--------------------------------------------------------------"
776	@echo ">>> Running ${SUP}"
777	@echo "--------------------------------------------------------------"
778.if defined(SUPFILE)
779	@${SUP} ${SUPFLAGS} ${SUPFILE}
780.endif
781.if defined(SUPFILE1)
782	@${SUP} ${SUPFLAGS} ${SUPFILE1}
783.endif
784.if defined(SUPFILE2)
785	@${SUP} ${SUPFLAGS} ${SUPFILE2}
786.endif
787.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
788	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
789.endif
790.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
791	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
792.endif
793.endif
794.if defined(CVS_UPDATE)
795	@echo "--------------------------------------------------------------"
796	@echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT}
797	@echo "--------------------------------------------------------------"
798	cd ${.CURDIR}; ${CVS} -R -q update ${CVSFLAGS}
799.endif
800
801#
802# ------------------------------------------------------------------------
803#
804# From here onwards are utility targets used by the 'make world' and
805# related targets.  If your 'world' breaks, you may like to try to fix
806# the problem and manually run the following targets to attempt to
807# complete the build.  Beware, this is *not* guaranteed to work, you
808# need to have a pretty good grip on the current state of the system
809# to attempt to manually finish it.  If in doubt, 'make world' again.
810#
811
812#
813# legacy: Build compatibility shims for the next three targets
814#
815legacy:
816.if ${BOOTSTRAPPING} < 503000
817	@echo "ERROR: Source upgrades from versions prior to 5.3 not supported."; \
818	false
819.endif
820.for _tool in tools/build
821	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
822	    cd ${.CURDIR}/${_tool}; \
823	    ${MAKE} DIRPRFX=${_tool}/ obj; \
824	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
825	    ${MAKE} DIRPRFX=${_tool}/ depend; \
826	    ${MAKE} DIRPRFX=${_tool}/ all; \
827	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
828.endfor
829
830#
831# bootstrap-tools: Build tools needed for compatibility
832#
833.if ${MK_GAMES} != "no"
834_strfile=	games/fortune/strfile
835.endif
836
837.if ${MK_CXX} != "no"
838_gperf=		gnu/usr.bin/gperf
839.if ${BOOTSTRAPPING} < 700004
840_groff=		gnu/usr.bin/groff
841.else
842_groff=		gnu/usr.bin/groff/tmac
843.endif
844.endif
845
846.if ${BOOTSTRAPPING} < 600029
847_texinfo=	gnu/usr.bin/texinfo
848.endif
849
850.if ${BOOTSTRAPPING} < 600015
851_cap_mkdb=	usr.bin/cap_mkdb
852.endif
853
854.if ${BOOTSTRAPPING} < 600018
855_colldef=	usr.bin/colldef
856.endif
857
858.if ${BOOTSTRAPPING} < 600017
859_gencat=	usr.bin/gencat
860.endif
861
862.if ${BOOTSTRAPPING} < 600016
863_mklocale=	usr.bin/mklocale
864.endif
865
866.if ${BOOTSTRAPPING} < 700018
867_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
868.endif
869
870.if ${MK_RESCUE} != "no" && \
871    ${BOOTSTRAPPING} < 700026
872_crunchgen=	usr.sbin/crunch/crunchgen
873.endif
874
875.if ${BOOTSTRAPPING} < 600020
876_pwd_mkdb=	usr.sbin/pwd_mkdb
877.endif
878
879bootstrap-tools:
880.for _tool in \
881    ${_strfile} \
882    ${_gperf} \
883    ${_groff} \
884    ${_texinfo} \
885    ${_cap_mkdb} \
886    ${_colldef} \
887    ${_gencat} \
888    usr.bin/lorder \
889    usr.bin/makewhatis \
890    ${_mklocale} \
891    usr.bin/rpcgen \
892    usr.bin/xinstall \
893    ${_gensnmptree} \
894    usr.sbin/config \
895    ${_crunchgen} \
896    ${_pwd_mkdb}
897	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
898		cd ${.CURDIR}/${_tool}; \
899		${MAKE} DIRPRFX=${_tool}/ obj; \
900		${MAKE} DIRPRFX=${_tool}/ depend; \
901		${MAKE} DIRPRFX=${_tool}/ all; \
902		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
903.endfor
904
905#
906# build-tools: Build special purpose build tools
907#
908.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
909_aicasm= sys/modules/aic7xxx/aicasm
910.endif
911
912.if !defined(NO_SHARE)
913_share=	share/syscons/scrnmaps
914.endif
915
916.if ${MK_KERBEROS} != "no"
917_kerberos5_tools= kerberos5/tools
918.endif
919
920.if ${MK_RESCUE} != "no"
921_rescue= rescue/rescue
922.endif
923
924build-tools:
925.for _tool in \
926    bin/csh \
927    bin/sh \
928    ${_rescue} \
929    lib/ncurses/ncurses \
930    lib/ncurses/ncursesw \
931    ${_share} \
932    ${_aicasm} \
933    usr.bin/awk \
934    lib/libmagic \
935    usr.sbin/sysinstall
936	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
937		cd ${.CURDIR}/${_tool}; \
938		${MAKE} DIRPRFX=${_tool}/ obj; \
939		${MAKE} DIRPRFX=${_tool}/ build-tools
940.endfor
941.for _tool in \
942    gnu/usr.bin/cc/cc_tools \
943    ${_kerberos5_tools}
944	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
945		cd ${.CURDIR}/${_tool}; \
946		${MAKE} DIRPRFX=${_tool}/ obj; \
947		${MAKE} DIRPRFX=${_tool}/ depend; \
948		${MAKE} DIRPRFX=${_tool}/ all
949.endfor
950
951#
952# cross-tools: Build cross-building tools
953#
954.if ${TARGET_ARCH} != ${MACHINE_ARCH}
955.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
956_btxld=		usr.sbin/btxld
957.endif
958.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
959_crunchide=	usr.sbin/crunch/crunchide
960.endif
961.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
962_kgzip=		usr.sbin/kgzip
963.endif
964.endif
965
966cross-tools:
967.for _tool in \
968    gnu/usr.bin/binutils \
969    gnu/usr.bin/cc \
970    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
971    ${_btxld} \
972    ${_crunchide} \
973    ${_kgzip}
974	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
975		cd ${.CURDIR}/${_tool}; \
976		${MAKE} DIRPRFX=${_tool}/ obj; \
977		${MAKE} DIRPRFX=${_tool}/ depend; \
978		${MAKE} DIRPRFX=${_tool}/ all; \
979		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
980.endfor
981
982#
983# hierarchy - ensure that all the needed directories are present
984#
985hierarchy:
986	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
987
988#
989# libraries - build all libraries, and install them under ${DESTDIR}.
990#
991# The list of libraries with dependents (${_prebuild_libs}) and their
992# interdependencies (__L) are built automatically by the
993# ${.CURDIR}/tools/make_libdeps.sh script.
994#
995libraries:
996	cd ${.CURDIR}; \
997	    ${MAKE} -f Makefile.inc1 _startup_libs; \
998	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
999	    ${MAKE} -f Makefile.inc1 _generic_libs;
1000
1001# These dependencies are not automatically generated:
1002#
1003# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
1004# shared libraries for ELF.
1005#
1006_startup_libs=	gnu/lib/csu gnu/lib/libgcc
1007.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1008_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1009.else
1010_startup_libs+=	lib/csu/${MACHINE_ARCH}
1011.endif
1012
1013_prebuild_libs=	${_kerberos5_lib_libasn1} ${_kerberos5_lib_libkrb5} \
1014		${_kerberos5_lib_libroken} \
1015		lib/libbz2 lib/libcom_err lib/libcrypt lib/libexpat \
1016		${_lib_libgssapi} ${_lib_libipx} \
1017		lib/libkiconv lib/libkvm lib/libmd \
1018		lib/ncurses/ncurses lib/ncurses/ncursesw \
1019		lib/libopie lib/libpam lib/${DEFAULT_THREAD_LIB} \
1020		lib/libradius lib/libsbuf lib/libtacplus lib/libutil \
1021		${_lib_libypclnt} lib/libz lib/msun \
1022		${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1023		${_secure_lib_libssl}
1024
1025_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib
1026
1027lib/libopie__L lib/libtacplus__L: lib/libmd__L
1028
1029.if ${MK_CDDL} != "no"
1030_cddl_lib= cddl/lib
1031.endif
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# Ask for every old file if the user really wants to remove it.
1139# It's annoying, but better safe than sorry.
1140	@(for file in ${OLD_FILES}; do \
1141		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1142			rm ${RM_I} "${DESTDIR}/$${file}"; \
1143		fi; \
1144	done)
1145# Remove catpages without corresponding manpages.
1146	@3<&0; \
1147	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1148	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1149	while read catpage; do \
1150		read manpage; \
1151		if [ ! -e "$${manpage}" ]; then \
1152			rm ${RM_I} $${catpage} <&3 ; \
1153	        fi; \
1154	done
1155	@echo ">>> Old files removed"
1156
1157check-old-files:
1158	@echo ">>> Checking for old files"
1159	@(for file in ${OLD_FILES}; do \
1160		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1161		 	echo "${DESTDIR}/$${file}"; \
1162		fi; \
1163	done)
1164# Check for catpages without corresponding manpages.
1165	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1166	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1167	while read catpage; do \
1168		read manpage; \
1169		if [ ! -e "$${manpage}" ]; then \
1170			echo $${catpage} ; \
1171	        fi; \
1172	done
1173
1174delete-old-libs:
1175	@echo ">>> Removing old libraries"
1176	@echo "${OLD_LIBS_MESSAGE}" | fmt
1177	@(for file in ${OLD_LIBS}; do \
1178		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1179			rm ${RM_I} "${DESTDIR}/$${file}"; \
1180		fi; \
1181	done)
1182	@echo ">>> Old libraries removed"
1183
1184check-old-libs:
1185	@echo ">>> Checking for old libraries"
1186	@(for file in ${OLD_LIBS}; do \
1187		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1188			echo "${DESTDIR}/$${file}"; \
1189		fi; \
1190	done)
1191
1192delete-old-dirs:
1193	@echo ">>> Removing old directories"
1194	@(for dir in ${OLD_DIRS}; do \
1195		if [ -d "${DESTDIR}/$${dir}" ]; then \
1196			rmdir -v "${DESTDIR}/$${dir}" || true; \
1197		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1198			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1199		fi; \
1200	done)
1201	@echo ">>> Old directories removed"
1202
1203check-old-dirs:
1204	@echo ">>> Checking for old directories"
1205	@(for dir in ${OLD_DIRS}; do \
1206		if [ -d "${DESTDIR}/$${dir}" ]; then \
1207			echo "${DESTDIR}/$${dir}"; \
1208		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1209			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1210		fi; \
1211	done)
1212
1213delete-old: delete-old-files delete-old-dirs
1214	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1215
1216check-old: check-old-files check-old-libs check-old-dirs
1217	@echo "To remove old files and directories run '${MAKE} delete-old'."
1218	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1219
1220.endif
1221
1222#
1223# showconfig - show build configuration.
1224#
1225showconfig:
1226	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1227