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