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