Makefile.inc1 revision 162113
1#
2# $FreeBSD: head/Makefile.inc1 162113 2006-09-07 16:41:30Z ru $
3#
4# Make command line options:
5#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6#	-DNO_CLEAN do not clean at all
7#	-DNO_SHARE do not go into share subdir
8#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
9#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
10#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
11#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
12#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
13#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
14#	TARGET="machine" to crossbuild world for a different machine type
15
16#
17# The intended user-driven targets are:
18# buildworld  - rebuild *everything*, including glue to help do upgrades
19# installworld- install everything built by "buildworld"
20# doxygen     - build API documentation of the kernel
21# update      - convenient way to update your source tree (eg: cvsup/cvs)
22#
23# Standard targets (not defined here) are documented in the makefiles in
24# /usr/share/mk.  These include:
25#		obj depend all install clean cleandepend cleanobj
26
27.include <bsd.own.mk>
28
29# We must do share/info early so that installation of info `dir'
30# entries works correctly.  Do it first since it is less likely to
31# grow dependencies on include and lib than vice versa.
32#
33# We must do lib and libexec before bin, because if installworld
34# installs a new /bin/sh, the 'make' command will *immediately*
35# use that new version.  And the new (dynamically-linked) /bin/sh
36# will expect to find appropriate libraries in /lib and /libexec.
37#
38# We must do etc last for install/distribute to work.
39#
40SUBDIR=	share/info include lib libexec bin
41.if ${MK_GAMES} != "no"
42SUBDIR+=games
43.endif
44SUBDIR+=gnu
45.if ${MK_KERBEROS} != "no"
46SUBDIR+=kerberos5
47.endif
48.if ${MK_RESCUE} != "no"
49SUBDIR+=rescue
50.endif
51SUBDIR+=sbin
52.if ${MK_CRYPT} != "no"
53SUBDIR+=secure
54.endif
55.if !defined(NO_SHARE)
56SUBDIR+=share
57.endif
58SUBDIR+=sys usr.bin usr.sbin etc
59
60# These are last, since it is nice to at least get the base system
61# rebuilt before you do them.
62.for _DIR in ${LOCAL_DIRS}
63.if exists(${.CURDIR}/${_DIR}/Makefile)
64SUBDIR+= ${_DIR}
65.endif
66.endfor
67
68.if defined(SUBDIR_OVERRIDE)
69SUBDIR=		${SUBDIR_OVERRIDE}
70.endif
71
72.if defined(NOCLEAN)
73NO_CLEAN=	${NOCLEAN}
74.endif
75.if defined(NO_CLEANDIR)
76CLEANDIR=	clean cleandepend
77.else
78CLEANDIR=	cleandir
79.endif
80
81CVS?=		cvs
82CVSFLAGS?=	-A -P -d -I!
83SUP?=		/usr/bin/csup
84SUPFLAGS?=	-g -L 2
85.if defined(SUPHOST)
86SUPFLAGS+=	-h ${SUPHOST}
87.endif
88
89MAKEOBJDIRPREFIX?=	/usr/obj
90.if !defined(OSRELDATE)
91.if exists(/usr/include/osreldate.h)
92OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
93		/usr/include/osreldate.h
94.else
95OSRELDATE=	0
96.endif
97.endif
98
99# Guess machine architecture from machine type, and vice versa.
100.if !defined(TARGET_ARCH) && defined(TARGET)
101TARGET_ARCH=	${TARGET:S/pc98/i386/}
102.elif !defined(TARGET) && defined(TARGET_ARCH) && \
103    ${TARGET_ARCH} != ${MACHINE_ARCH}
104TARGET=		${TARGET_ARCH}
105.endif
106# Otherwise, default to current machine type and architecture.
107TARGET?=	${MACHINE}
108TARGET_ARCH?=	${MACHINE_ARCH}
109
110KNOWN_ARCHES?=	amd64 arm i386 i386/pc98 ia64 powerpc sparc64
111.if ${TARGET} == ${TARGET_ARCH}
112_t=		${TARGET}
113.else
114_t=		${TARGET_ARCH}/${TARGET}
115.endif
116.for _t in ${_t}
117.if empty(KNOWN_ARCHES:M${_t})
118.error Unknown target ${TARGET_ARCH}:${TARGET}.
119.endif
120.endfor
121
122.if ${TARGET} == ${MACHINE}
123TARGET_CPUTYPE?=${CPUTYPE}
124.else
125TARGET_CPUTYPE?=
126.endif
127
128.if !empty(TARGET_CPUTYPE)
129_TARGET_CPUTYPE=${TARGET_CPUTYPE}
130.else
131_TARGET_CPUTYPE=dummy
132.endif
133_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
134		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
135.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
136.error CPUTYPE global should be set with ?=.
137.endif
138.if make(buildworld)
139BUILD_ARCH!=	uname -p
140.if ${MACHINE_ARCH} != ${BUILD_ARCH}
141.error To cross-build, set TARGET_ARCH.
142.endif
143.endif
144.if ${MACHINE} == ${TARGET} && !defined(CROSS_BUILD_TESTING)
145OBJTREE=	${MAKEOBJDIRPREFIX}
146.else
147OBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}
148.endif
149WORLDTMP=	${OBJTREE}${.CURDIR}/tmp
150# /usr/games added for fortune which depend on strfile
151BPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
152XPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
153STRICTTMPPATH=	${BPATH}:${XPATH}
154TMPPATH=	${STRICTTMPPATH}:${PATH}
155
156INSTALLTMP!=	/usr/bin/mktemp -d -u -t install
157
158#
159# Building a world goes through the following stages
160#
161# 1. legacy stage [BMAKE]
162#	This stage is responsible for creating compatibility
163#	shims that are needed by the bootstrap-tools,
164#	build-tools and cross-tools stages.
165# 1. bootstrap-tools stage [BMAKE]
166#	This stage is responsible for creating programs that
167#	are needed for backward compatibility reasons. They
168#	are not built as cross-tools.
169# 2. build-tools stage [TMAKE]
170#	This stage is responsible for creating the object
171#	tree and building any tools that are needed during
172#	the build process.
173# 3. cross-tools stage [XMAKE]
174#	This stage is responsible for creating any tools that
175#	are needed for cross-builds. A cross-compiler is one
176#	of them.
177# 4. world stage [WMAKE]
178#	This stage actually builds the world.
179# 5. install stage (optional) [IMAKE]
180#	This stage installs a previously built world.
181#
182
183BOOTSTRAPPING?=	0
184
185# Common environment for world related stages
186CROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
187		MACHINE_ARCH=${TARGET_ARCH} \
188		MACHINE=${TARGET} \
189		CPUTYPE=${TARGET_CPUTYPE} \
190		GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
191		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
192		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
193
194# bootstrap-tools stage
195BMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
196		PATH=${BPATH}:${PATH} \
197		WORLDTMP=${WORLDTMP} \
198		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
199BMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
200		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
201		DESTDIR= \
202		BOOTSTRAPPING=${OSRELDATE} \
203		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
204		-DWITHOUT_NLS -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \
205		-DNO_CPU_CFLAGS -DNO_WARNS
206
207# build-tools stage
208TMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
209		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
210		DESTDIR= \
211		BOOTSTRAPPING=${OSRELDATE} -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS
212
213# cross-tools stage
214XMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
215		-DWITHOUT_FORTRAN -DWITHOUT_GDB
216
217# world stage
218WMAKEENV=	${CROSSENV} \
219		_SHLIBDIRPREFIX=${WORLDTMP} \
220		INSTALL="sh ${.CURDIR}/tools/install.sh" \
221		PATH=${TMPPATH}
222WMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
223
224.if ${TARGET_ARCH} == "amd64"
225# 32 bit world
226LIB32TMP=	${OBJTREE}${.CURDIR}/lib32
227
228.if empty(TARGET_CPUTYPE)
229LIB32CPUTYPE=	k8
230.else
231LIB32CPUTYPE=	${TARGET_CPUTYPE}
232.endif
233LIB32PREFLAGS=	-m32 -march=${LIB32CPUTYPE} -mfancy-math-387 -DCOMPAT_32BIT
234LIB32POSTFLAGS=	-I${LIB32TMP}/usr/include \
235		-L${LIB32TMP}/usr/lib32 \
236		-B${LIB32TMP}/usr/lib32
237LIB32CC=	${LIB32PREFLAGS} \
238		${LIB32POSTFLAGS}
239LIB32CXX=	${LIB32PREFLAGS} -I${LIB32TMP}/usr/include/c++/3.4 \
240		${LIB32POSTFLAGS}
241LIB32OBJC=	${LIB32PREFLAGS} -I${LIB32TMP}/usr/include/objc \
242		${LIB32POSTFLAGS}
243
244# Yes, the flags are redundant.
245LIB32MAKEENV=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
246		_SHLIBDIRPREFIX=${LIB32TMP} \
247		MACHINE=i386 \
248		MACHINE_ARCH=i386 \
249		INSTALL="sh ${.CURDIR}/tools/install.sh" \
250		PATH=${TMPPATH} \
251		CC="${CC} ${LIB32CC}" \
252		CXX="${CXX} ${LIB32CXX}" \
253		OBJC="${OBJC} ${LIB32OBJC}" \
254		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
255		AS="${AS} --32" \
256		LIBDIR=/usr/lib32 \
257		SHLIBDIR=/usr/lib32
258
259LIB32MAKE=	${LIB32MAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
260		-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_INFO \
261		-DWITHOUT_HTML
262LIB32IMAKE=	${LIB32MAKE:NINSTALL=*} -DNO_INCS
263.endif
264
265# install stage
266.if empty(.MAKEFLAGS:M-n)
267IMAKEENV=	${CROSSENV} \
268		PATH=${STRICTTMPPATH}:${INSTALLTMP}
269.else
270IMAKEENV=	${CROSSENV} \
271		PATH=${TMPPATH}:${INSTALLTMP}
272.endif
273IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1
274
275# kernel stage
276KMAKEENV=	${WMAKEENV}
277KMAKE=		${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME}
278
279#
280# buildworld
281#
282# Attempt to rebuild the entire system, with reasonable chance of
283# success, regardless of how old your existing system is.
284#
285_worldtmp:
286.if ${.CURDIR:C/[^,]//g} != ""
287#	The m4 build of sendmail files doesn't like it if ',' is used
288#	anywhere in the path of it's files.
289	@echo
290	@echo "*** Error: path to source tree contains a comma ','"
291	@echo
292	false
293.endif
294	@echo
295	@echo "--------------------------------------------------------------"
296	@echo ">>> Rebuilding the temporary build tree"
297	@echo "--------------------------------------------------------------"
298.if !defined(NO_CLEAN)
299	rm -rf ${WORLDTMP}
300.if ${TARGET_ARCH} == "amd64"
301	rm -rf ${LIB32TMP}
302.endif
303.else
304	rm -rf ${WORLDTMP}/legacy/usr/include
305#	XXX - These two can depend on any header file.
306	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
307	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
308.endif
309.for _dir in \
310    usr/bin usr/games usr/include/c++/3.4 usr/include/sys usr/lib \
311    usr/libexec usr/sbin usr/share/dict \
312    usr/share/groff_font/devX100 \
313    usr/share/groff_font/devX100-12 \
314    usr/share/groff_font/devX75 \
315    usr/share/groff_font/devX75-12 \
316    usr/share/groff_font/devascii \
317    usr/share/groff_font/devcp1047 \
318    usr/share/groff_font/devdvi \
319    usr/share/groff_font/devhtml \
320    usr/share/groff_font/devkoi8-r \
321    usr/share/groff_font/devlatin1 \
322    usr/share/groff_font/devlbp \
323    usr/share/groff_font/devlj4 \
324    usr/share/groff_font/devps \
325    usr/share/groff_font/devutf8 \
326    usr/share/tmac/mdoc usr/share/tmac/mm
327	mkdir -p ${WORLDTMP}/legacy/${_dir}
328.endfor
329.for _dir in \
330    lib usr/bin usr/include usr/lib/compat/aout usr/libdata/ldscripts \
331    usr/libexec usr/sbin usr/share/misc \
332    usr/share/snmp/defs usr/share/snmp/mibs
333	mkdir -p ${WORLDTMP}/${_dir}
334.endfor
335	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
336	    -p ${WORLDTMP}/usr/include >/dev/null
337	ln -sf ${.CURDIR}/sys ${WORLDTMP}
338.if ${MK_BIND_LIBS} != "no"
339	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
340	    -p ${WORLDTMP}/usr/include >/dev/null
341.endif
342_legacy:
343	@echo
344	@echo "--------------------------------------------------------------"
345	@echo ">>> stage 1.1: legacy release compatibility shims"
346	@echo "--------------------------------------------------------------"
347	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
348_bootstrap-tools:
349	@echo
350	@echo "--------------------------------------------------------------"
351	@echo ">>> stage 1.2: bootstrap tools"
352	@echo "--------------------------------------------------------------"
353	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
354_cleanobj:
355.if !defined(NO_CLEAN)
356	@echo
357	@echo "--------------------------------------------------------------"
358	@echo ">>> stage 2.1: cleaning up the object tree"
359	@echo "--------------------------------------------------------------"
360	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
361.if ${TARGET_ARCH} == "amd64"
362	rm -rf ${OBJTREE}/lib32
363.endif
364.endif
365_obj:
366	@echo
367	@echo "--------------------------------------------------------------"
368	@echo ">>> stage 2.2: rebuilding the object tree"
369	@echo "--------------------------------------------------------------"
370	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
371_build-tools:
372	@echo
373	@echo "--------------------------------------------------------------"
374	@echo ">>> stage 2.3: build tools"
375	@echo "--------------------------------------------------------------"
376	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
377_cross-tools:
378	@echo
379	@echo "--------------------------------------------------------------"
380	@echo ">>> stage 3: cross tools"
381	@echo "--------------------------------------------------------------"
382	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
383_includes:
384	@echo
385	@echo "--------------------------------------------------------------"
386	@echo ">>> stage 4.1: building includes"
387	@echo "--------------------------------------------------------------"
388	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
389_libraries:
390	@echo
391	@echo "--------------------------------------------------------------"
392	@echo ">>> stage 4.2: building libraries"
393	@echo "--------------------------------------------------------------"
394	${_+_}cd ${.CURDIR}; \
395	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
396	    -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE libraries
397_depend:
398	@echo
399	@echo "--------------------------------------------------------------"
400	@echo ">>> stage 4.3: make dependencies"
401	@echo "--------------------------------------------------------------"
402	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
403everything:
404	@echo
405	@echo "--------------------------------------------------------------"
406	@echo ">>> stage 4.4: building everything"
407	@echo "--------------------------------------------------------------"
408	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
409.if ${TARGET_ARCH} == "amd64"
410build32:
411	@echo
412	@echo "--------------------------------------------------------------"
413	@echo ">>> stage 5.1: building 32 bit shim libraries"
414	@echo "--------------------------------------------------------------"
415.for _dir in \
416    lib lib32 usr/bin usr/include usr/lib32 usr/libdata/ldscripts \
417    usr/libexec usr/sbin usr/share/misc \
418    usr/share/snmp/defs usr/share/snmp/mibs
419	mkdir -p ${LIB32TMP}/${_dir}
420.endfor
421	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
422	    -p ${LIB32TMP}/usr/include >/dev/null
423	mkdir -p ${WORLDTMP}
424	ln -sf ${.CURDIR}/sys ${WORLDTMP}
425.if ${MK_KERBEROS} != "no"
426.for _t in obj depend all
427	cd ${.CURDIR}/kerberos5/tools; \
428	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= ${_t}
429.endfor
430.endif
431.for _t in obj includes
432	cd ${.CURDIR}/include; \
433	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
434	cd ${.CURDIR}/lib; \
435	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
436	cd ${.CURDIR}/gnu/lib; \
437	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
438.if ${MK_CRYPT} != "no"
439	cd ${.CURDIR}/secure/lib; \
440	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
441.endif
442.if ${MK_KERBEROS} != "no"
443	cd ${.CURDIR}/kerberos5/lib; \
444	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
445.endif
446.endfor
447.for _dir in usr.bin/lex/lib
448	cd ${.CURDIR}/${_dir}; \
449	    ${LIB32MAKE} DESTDIR=${LIB32TMP} obj
450.endfor
451.for _dir in lib/libncurses lib/libmagic
452	cd ${.CURDIR}/${_dir}; \
453	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= build-tools
454.endfor
455	cd ${.CURDIR}; \
456	    ${LIB32MAKE} -f Makefile.inc1 DESTDIR=${LIB32TMP} libraries 
457.for _t in obj depend all
458	cd ${.CURDIR}/libexec/rtld-elf; \
459	    PROG=ld-elf32.so.1 ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
460.endfor
461
462distribute32 install32:
463.if make(distribute32)
464	mkdir -p ${DISTDIR}/${DISTRIBUTION}/usr/lib32	# XXX add to mtree
465.else
466	mkdir -p ${DESTDIR}/usr/lib32			# XXX add to mtree
467.endif
468	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
469	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
470.if ${MK_CRYPT} != "no"
471	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
472.endif
473	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
474.endif
475
476
477WMAKE_TGTS=
478.if !defined(SUBDIR_OVERRIDE)
479WMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
480.endif
481WMAKE_TGTS+=	_cleanobj _obj _build-tools
482.if !defined(SUBDIR_OVERRIDE)
483WMAKE_TGTS+=	_cross-tools
484.endif
485WMAKE_TGTS+=	_includes _libraries _depend everything
486.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
487WMAKE_TGTS+=	build32
488.endif
489
490buildworld: ${WMAKE_TGTS}
491.ORDER: ${WMAKE_TGTS}
492
493
494#
495# We need to have this as a target because the indirection between Makefile
496# and Makefile.inc1 causes the correct PATH to be used, rather than a
497# modification of the current environment's PATH.  In addition, we need
498# to quote multiword values.
499# 
500buildenvvars:
501	@echo ${WMAKEENV:Q}
502
503buildenv:
504	@echo Entering world for ${TARGET_ARCH}:${TARGET}
505	@cd ${.CURDIR} && env ${WMAKEENV} sh || true
506
507TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
508toolchain: ${TOOLCHAIN_TGTS}
509kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
510
511#
512# installcheck
513#
514# Checks to be sure system is ready for installworld/installkernel.
515#
516installcheck:
517
518#
519# Require DESTDIR to be set if installing for a different architecture.
520#
521.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE}
522.if !make(distributeworld)
523installcheck: installcheck_DESTDIR
524installcheck_DESTDIR:
525.if !defined(DESTDIR) || empty(DESTDIR)
526	@echo "ERROR: Please set DESTDIR!"; \
527	false
528.endif
529.endif
530.endif
531
532#
533# Check for missing UIDs/GIDs.
534#
535CHECK_UIDS=
536CHECK_GIDS=	audit
537.if ${MK_SENDMAIL} != "no"
538CHECK_UIDS+=	smmsp
539CHECK_GIDS+=	smmsp
540.endif
541.if ${MK_PF} != "no"
542CHECK_UIDS+=	proxy
543CHECK_GIDS+=	proxy authpf
544.endif
545installcheck: installcheck_UGID
546installcheck_UGID:
547.for uid in ${CHECK_UIDS}
548	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
549		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
550		false; \
551	fi
552.endfor
553.for gid in ${CHECK_GIDS}
554	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
555		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
556		false; \
557	fi
558.endfor
559
560#
561# distributeworld
562#
563# Distributes everything compiled by a `buildworld'.
564#
565# installworld
566#
567# Installs everything compiled by a 'buildworld'.
568#
569distributeworld installworld: installcheck
570	mkdir -p ${INSTALLTMP}
571	for prog in [ awk cap_mkdb cat chflags chmod chown \
572	    date echo egrep find grep install-info \
573	    ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
574	    test true uname wc zic; do \
575		cp `which $$prog` ${INSTALLTMP}; \
576	done
577	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
578	rm -rf ${INSTALLTMP}
579
580#
581# reinstall
582#
583# If you have a build server, you can NFS mount the source and obj directories
584# and do a 'make reinstall' on the *client* to install new binaries from the
585# most recent server build.
586#
587reinstall:
588	@echo "--------------------------------------------------------------"
589	@echo ">>> Making hierarchy"
590	@echo "--------------------------------------------------------------"
591	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
592	@echo
593	@echo "--------------------------------------------------------------"
594	@echo ">>> Installing everything"
595	@echo "--------------------------------------------------------------"
596	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
597.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
598	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
599.endif
600
601redistribute:
602	@echo "--------------------------------------------------------------"
603	@echo ">>> Distributing everything"
604	@echo "--------------------------------------------------------------"
605	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
606.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
607	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 DISTRIBUTION=lib32
608.endif
609
610distrib-dirs distribution:
611	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET}
612
613#
614# buildkernel and installkernel
615#
616# Which kernels to build and/or install is specified by setting
617# KERNCONF. If not defined a GENERIC kernel is built/installed.
618# Only the existing (depending TARGET) config files are used
619# for building kernels and only the first of these is designated
620# as the one being installed.
621#
622# Note that we have to use TARGET instead of TARGET_ARCH when
623# we're in kernel-land. Since only TARGET_ARCH is (expected) to
624# be set to cross-build, we have to make sure TARGET is set
625# properly.
626
627.if !defined(KERNCONF) && defined(KERNEL)
628KERNCONF=	${KERNEL}
629KERNWARN=
630.else
631KERNCONF?=	GENERIC
632.endif
633INSTKERNNAME?=	kernel
634
635KERNSRCDIR?=	${.CURDIR}/sys
636KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
637KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
638KERNCONFDIR?=	${KRNLCONFDIR}
639
640BUILDKERNELS=
641INSTALLKERNEL=
642.for _kernel in ${KERNCONF}
643.if exists(${KERNCONFDIR}/${_kernel})
644BUILDKERNELS+=	${_kernel}
645.if empty(INSTALLKERNEL)
646INSTALLKERNEL= ${_kernel}
647.endif
648.endif
649.endfor
650
651#
652# buildkernel
653#
654# Builds all kernels defined by BUILDKERNELS.
655#
656buildkernel:
657.if empty(BUILDKERNELS)
658	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
659	false
660.endif
661.if defined(KERNWARN)
662	@echo "--------------------------------------------------------------"
663	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
664	@echo "--------------------------------------------------------------"
665	@sleep 3
666.endif
667	@echo
668.for _kernel in ${BUILDKERNELS}
669	@echo "--------------------------------------------------------------"
670	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
671	@echo "--------------------------------------------------------------"
672	@echo "===> ${_kernel}"
673	mkdir -p ${KRNLOBJDIR}
674.if !defined(NO_KERNELCONFIG)
675	@echo
676	@echo "--------------------------------------------------------------"
677	@echo ">>> stage 1: configuring the kernel"
678	@echo "--------------------------------------------------------------"
679	cd ${KRNLCONFDIR}; \
680		PATH=${TMPPATH} \
681		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
682			${KERNCONFDIR}/${_kernel}
683.endif
684.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
685	@echo
686	@echo "--------------------------------------------------------------"
687	@echo ">>> stage 2.1: cleaning up the object tree"
688	@echo "--------------------------------------------------------------"
689	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
690.endif
691	@echo
692	@echo "--------------------------------------------------------------"
693	@echo ">>> stage 2.2: rebuilding the object tree"
694	@echo "--------------------------------------------------------------"
695	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
696	@echo
697	@echo "--------------------------------------------------------------"
698	@echo ">>> stage 2.3: build tools"
699	@echo "--------------------------------------------------------------"
700	cd ${KRNLOBJDIR}/${_kernel}; \
701	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
702	    ${MAKE} -DNO_CPU_CFLAGS -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
703# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
704.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
705.for target in obj depend all
706	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
707	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
708	    ${MAKE} -DNO_CPU_CFLAGS ${target}
709.endfor
710.endif
711.if !defined(NO_KERNELDEPEND)
712	@echo
713	@echo "--------------------------------------------------------------"
714	@echo ">>> stage 3.1: making dependencies"
715	@echo "--------------------------------------------------------------"
716	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
717.endif
718	@echo
719	@echo "--------------------------------------------------------------"
720	@echo ">>> stage 3.2: building everything"
721	@echo "--------------------------------------------------------------"
722	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
723	@echo "--------------------------------------------------------------"
724	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
725	@echo "--------------------------------------------------------------"
726.endfor
727
728#
729# installkernel, etc.
730#
731# Install the kernel defined by INSTALLKERNEL
732#
733installkernel installkernel.debug \
734reinstallkernel reinstallkernel.debug: installcheck
735.if empty(INSTALLKERNEL)
736	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
737	false
738.endif
739	@echo "--------------------------------------------------------------"
740	@echo ">>> Installing kernel"
741	@echo "--------------------------------------------------------------"
742	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
743	    ${CROSSENV} PATH=${TMPPATH} \
744	    ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
745
746#
747# doxygen
748#
749# Build the API documentation with doxygen
750#
751doxygen:
752	@if [ ! -x `/usr/bin/which doxygen` ]; then \
753		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
754		exit 1; \
755	fi
756	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
757
758#
759# update
760#
761# Update the source tree, by running cvsup and/or running cvs to update to the
762# latest copy.
763#
764update:
765.if defined(SUP_UPDATE)
766	@echo "--------------------------------------------------------------"
767	@echo ">>> Running ${SUP}"
768	@echo "--------------------------------------------------------------"
769.if defined(SUPFILE)
770	@${SUP} ${SUPFLAGS} ${SUPFILE}
771.endif
772.if defined(SUPFILE1)
773	@${SUP} ${SUPFLAGS} ${SUPFILE1}
774.endif
775.if defined(SUPFILE2)
776	@${SUP} ${SUPFLAGS} ${SUPFILE2}
777.endif
778.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
779	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
780.endif
781.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
782	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
783.endif
784.endif
785.if defined(CVS_UPDATE)
786	@echo "--------------------------------------------------------------"
787	@echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT}
788	@echo "--------------------------------------------------------------"
789	cd ${.CURDIR}; ${CVS} -R -q update ${CVSFLAGS}
790.endif
791
792#
793# ------------------------------------------------------------------------
794#
795# From here onwards are utility targets used by the 'make world' and
796# related targets.  If your 'world' breaks, you may like to try to fix
797# the problem and manually run the following targets to attempt to
798# complete the build.  Beware, this is *not* guaranteed to work, you
799# need to have a pretty good grip on the current state of the system
800# to attempt to manually finish it.  If in doubt, 'make world' again.
801#
802
803#
804# legacy: Build compatibility shims for the next three targets
805#
806legacy:
807.if ${BOOTSTRAPPING} < 503000
808	@echo "ERROR: Source upgrades from versions prior to 5.3 not supported."; \
809	false
810.endif
811.for _tool in tools/build
812	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
813	    cd ${.CURDIR}/${_tool}; \
814	    ${MAKE} DIRPRFX=${_tool}/ obj; \
815	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
816	    ${MAKE} DIRPRFX=${_tool}/ depend; \
817	    ${MAKE} DIRPRFX=${_tool}/ all; \
818	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
819.endfor
820
821#
822# bootstrap-tools: Build tools needed for compatibility
823#
824.if ${MK_GAMES} != "no"
825_strfile=	games/fortune/strfile
826.endif
827
828.if ${MK_CXX} != "no"
829_gperf=		gnu/usr.bin/gperf
830.if ${BOOTSTRAPPING} < 700004
831_groff=		gnu/usr.bin/groff
832.else
833_groff=		gnu/usr.bin/groff/tmac
834.endif
835.endif
836
837.if ${BOOTSTRAPPING} < 600029
838_texinfo=	gnu/usr.bin/texinfo
839.endif
840
841.if ${BOOTSTRAPPING} < 600015
842_cap_mkdb=	usr.bin/cap_mkdb
843.endif
844
845.if ${BOOTSTRAPPING} < 600018
846_colldef=	usr.bin/colldef
847.endif
848
849.if ${BOOTSTRAPPING} < 600017
850_gencat=	usr.bin/gencat
851.endif
852
853.if ${BOOTSTRAPPING} < 600016
854_mklocale=	usr.bin/mklocale
855.endif
856
857.if ${BOOTSTRAPPING} < 700015
858_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
859.endif
860
861.if ${MK_RESCUE} != "no" && \
862    ${BOOTSTRAPPING} < 600008
863_crunchgen=	usr.sbin/crunch/crunchgen
864.endif
865
866.if ${BOOTSTRAPPING} < 600020
867_pwd_mkdb=	usr.sbin/pwd_mkdb
868.endif
869
870bootstrap-tools:
871.for _tool in \
872    ${_strfile} \
873    ${_gperf} \
874    ${_groff} \
875    ${_texinfo} \
876    ${_cap_mkdb} \
877    ${_colldef} \
878    ${_gencat} \
879    usr.bin/lorder \
880    usr.bin/makewhatis \
881    ${_mklocale} \
882    usr.bin/rpcgen \
883    usr.bin/xinstall \
884    ${_gensnmptree} \
885    usr.sbin/config \
886    ${_crunchgen} \
887    ${_pwd_mkdb}
888	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
889		cd ${.CURDIR}/${_tool}; \
890		${MAKE} DIRPRFX=${_tool}/ obj; \
891		${MAKE} DIRPRFX=${_tool}/ depend; \
892		${MAKE} DIRPRFX=${_tool}/ all; \
893		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
894.endfor
895
896#
897# build-tools: Build special purpose build tools
898#
899.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
900_aicasm= sys/modules/aic7xxx/aicasm
901.endif
902
903.if !defined(NO_SHARE)
904_share=	share/syscons/scrnmaps
905.endif
906
907.if ${MK_KERBEROS} != "no"
908_kerberos5_tools= kerberos5/tools
909.endif
910
911.if ${MK_RESCUE} != "no"
912_rescue= rescue/rescue
913.endif
914
915build-tools:
916.for _tool in \
917    bin/csh \
918    bin/sh \
919    ${_rescue} \
920    lib/libncurses \
921    ${_share} \
922    ${_aicasm} \
923    usr.bin/awk \
924    lib/libmagic \
925    usr.sbin/sysinstall
926	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
927		cd ${.CURDIR}/${_tool}; \
928		${MAKE} DIRPRFX=${_tool}/ obj; \
929		${MAKE} DIRPRFX=${_tool}/ build-tools
930.endfor
931.for _tool in \
932    gnu/usr.bin/cc/cc_tools \
933    ${_kerberos5_tools}
934	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
935		cd ${.CURDIR}/${_tool}; \
936		${MAKE} DIRPRFX=${_tool}/ obj; \
937		${MAKE} DIRPRFX=${_tool}/ depend; \
938		${MAKE} DIRPRFX=${_tool}/ all
939.endfor
940
941#
942# cross-tools: Build cross-building tools
943#
944.if ${TARGET_ARCH} != ${MACHINE_ARCH}
945.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
946_btxld=		usr.sbin/btxld
947.endif
948.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
949_crunchide=	usr.sbin/crunch/crunchide
950.endif
951.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
952_kgzip=		usr.sbin/kgzip
953.endif
954.endif
955
956cross-tools:
957.for _tool in \
958    gnu/usr.bin/binutils \
959    gnu/usr.bin/cc \
960    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
961    ${_btxld} \
962    ${_crunchide} \
963    ${_kgzip}
964	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
965		cd ${.CURDIR}/${_tool}; \
966		${MAKE} DIRPRFX=${_tool}/ obj; \
967		${MAKE} DIRPRFX=${_tool}/ depend; \
968		${MAKE} DIRPRFX=${_tool}/ all; \
969		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
970.endfor
971
972#
973# hierarchy - ensure that all the needed directories are present
974#
975hierarchy:
976	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
977
978#
979# libraries - build all libraries, and install them under ${DESTDIR}.
980#
981# The list of libraries with dependents (${_prebuild_libs}) and their
982# interdependencies (__L) are built automatically by the
983# ${.CURDIR}/tools/make_libdeps.sh script.
984#
985libraries:
986	cd ${.CURDIR}; \
987	    ${MAKE} -f Makefile.inc1 _startup_libs; \
988	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
989	    ${MAKE} -f Makefile.inc1 _generic_libs;
990
991# These dependencies are not automatically generated:
992#
993# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
994# shared libraries for ELF.
995#
996_startup_libs=	gnu/lib/csu gnu/lib/libgcc
997.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
998_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
999.else
1000_startup_libs+=	lib/csu/${MACHINE_ARCH}
1001.endif
1002
1003_prebuild_libs=
1004
1005_generic_libs=	gnu/lib
1006
1007.if ${MK_IPX} != "no"
1008_prebuild_libs+= lib/libipx
1009.endif
1010
1011.if ${MK_KERBEROS} != "no"
1012_prebuild_libs+=	kerberos5/lib/libasn1
1013_prebuild_libs+=	kerberos5/lib/libkrb5
1014_prebuild_libs+=	kerberos5/lib/libroken
1015_generic_libs+=	kerberos5/lib
1016.endif
1017
1018_prebuild_libs+= lib/libbz2 lib/libcom_err lib/libcrypt lib/libexpat \
1019		lib/libkiconv lib/libkvm lib/libmd \
1020		lib/libncurses lib/libnetgraph lib/libopie lib/libpam \
1021		lib/libradius \
1022		lib/libsbuf lib/libtacplus lib/libutil \
1023		lib/libz lib/msun lib/libgssapi
1024
1025lib/libopie__L lib/libtacplus__L: lib/libmd__L
1026
1027_generic_libs+=	lib
1028
1029.if ${MK_CRYPT} != "no"
1030.if ${MK_OPENSSL} != "no"
1031_prebuild_libs+=	secure/lib/libcrypto secure/lib/libssl
1032lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1033.if ${MK_OPENSSH} != "no"
1034_prebuild_libs+=	secure/lib/libssh
1035secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1036.if ${MK_KERBEROS} != "no"
1037secure/lib/libssh__L: lib/libgssapi__L
1038.endif
1039.endif
1040.endif
1041_generic_libs+=	secure/lib
1042.endif
1043
1044.if ${MK_OPENSSL} == "no"
1045lib/libradius__L: lib/libmd__L
1046.endif
1047
1048.if ${MK_NIS} != "no"
1049_prebuild_libs+=	lib/libypclnt
1050.endif
1051
1052_generic_libs+=	usr.bin/lex/lib
1053
1054.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1055${_lib}__L: .PHONY
1056.if exists(${.CURDIR}/${_lib})
1057	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1058		cd ${.CURDIR}/${_lib}; \
1059		${MAKE} DIRPRFX=${_lib}/ obj; \
1060		${MAKE} DIRPRFX=${_lib}/ depend; \
1061		${MAKE} DIRPRFX=${_lib}/ all; \
1062		${MAKE} DIRPRFX=${_lib}/ install
1063.endif
1064.endfor
1065
1066# libpam is special: we need to build static PAM modules before
1067# static PAM library, and dynamic PAM library before dynamic PAM
1068# modules.
1069lib/libpam__L: .PHONY
1070	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1071		cd ${.CURDIR}/lib/libpam; \
1072		${MAKE} DIRPRFX=lib/libpam/ obj; \
1073		${MAKE} DIRPRFX=lib/libpam/ depend; \
1074		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1075		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1076
1077_startup_libs: ${_startup_libs:S/$/__L/}
1078_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1079_generic_libs: ${_generic_libs:S/$/__L/}
1080
1081.for __target in all clean cleandepend cleandir depend includes obj
1082.for entry in ${SUBDIR}
1083${entry}.${__target}__D: .PHONY
1084	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1085		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1086		edir=${entry}.${MACHINE_ARCH}; \
1087		cd ${.CURDIR}/$${edir}; \
1088	else \
1089		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1090		edir=${entry}; \
1091		cd ${.CURDIR}/$${edir}; \
1092	fi; \
1093	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1094.endfor
1095par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1096.endfor
1097
1098.include <bsd.subdir.mk>
1099
1100.if make(delete-old) || make(delete-old-libs) || make(check-old)
1101
1102#
1103# check for / delete old files section
1104#
1105
1106.include "ObsoleteFiles.inc"
1107
1108OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1109else you can not start such an application. Consult UPDATING for more \
1110information regarding how to cope with the removal/revision bump of a \
1111specific library."
1112
1113.if !defined(BATCH_DELETE_OLD_FILES)
1114RM_I=-i
1115.else
1116RM_I=-v
1117.endif
1118
1119delete-old-files:
1120	@echo ">>> Removing old files (only deletes safe to delete libs)"
1121.for file in ${OLD_FILES}
1122# Ask for every old file if the user really wants to remove it.
1123# It's annoying, but better safe than sorry.
1124	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1125		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1126		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1127			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1128			chflags noschg "${DESTDIR}/${file}"; \
1129			rm ${RM_I} "${DESTDIR}/${file}"; \
1130		fi; \
1131	fi
1132.endfor
1133# Remove catpages without corresponding manpages.
1134	@3<&0; \
1135	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1136	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1137	while read catpage; do \
1138		read manpage; \
1139		if [ ! -e "$${manpage}" ]; then \
1140			rm ${RM_I} $${catpage} <&3 ; \
1141	        fi; \
1142	done
1143	@echo ">>> Old files removed"
1144
1145check-old-files:
1146	@echo ">>> Checking for old files"
1147.for file in ${OLD_FILES}
1148	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1149		 echo "${DESTDIR}/${file}"; \
1150	fi
1151.endfor
1152# Check for catpages without corresponding manpages.
1153	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1154	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1155	while read catpage; do \
1156		read manpage; \
1157		if [ ! -e "$${manpage}" ]; then \
1158			echo $${catpage} ; \
1159	        fi; \
1160	done
1161
1162delete-old-libs:
1163	@echo ">>> Removing old libraries"
1164	@echo "${OLD_LIBS_MESSAGE}" | fmt
1165.for file in ${OLD_LIBS}
1166	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1167		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1168		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1169			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1170			chflags noschg "${DESTDIR}/${file}"; \
1171			rm ${RM_I} "${DESTDIR}/${file}"; \
1172		fi; \
1173	fi
1174.endfor
1175	@echo ">>> Old libraries removed"
1176
1177check-old-libs:
1178	@echo ">>> Checking for old libraries"
1179.for file in ${OLD_LIBS}
1180	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1181		echo "${DESTDIR}/${file}"; \
1182	fi
1183.endfor
1184
1185delete-old-dirs:
1186	@echo ">>> Removing old directories"
1187.for dir in ${OLD_DIRS}
1188# Don't fail if an old directory isn't empty.
1189	@if [ -d "${DESTDIR}/${dir}" ]; then \
1190		rmdir -v "${DESTDIR}/${dir}" || true; \
1191	else \
1192		if [ -L "${DESTDIR}/${dir}" ]; then \
1193			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1194		fi; \
1195	fi
1196.endfor
1197	@echo ">>> Old directories removed"
1198
1199check-old-dirs:
1200	@echo ">>> Checking for old directories"
1201.for dir in ${OLD_DIRS}
1202	@if [ -d "${DESTDIR}/${dir}" ]; then \
1203		echo "${DESTDIR}/${dir}"; \
1204	else \
1205		if [ -L "${DESTDIR}/${dir}" ]; then \
1206			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1207		fi; \
1208	fi
1209.endfor
1210
1211delete-old: delete-old-files delete-old-dirs
1212	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1213
1214check-old: check-old-files check-old-libs check-old-dirs
1215	@echo "To remove old files and directories run '${MAKE} delete-old'."
1216	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1217
1218.endif
1219
1220#
1221# showconfig - show build configuration.
1222#
1223showconfig:
1224	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1225