Makefile.inc1 revision 162123
1#
2# $FreeBSD: head/Makefile.inc1 162123 2006-09-07 19:36:16Z 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: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
491.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
492
493buildworld_prologue:
494	@echo "--------------------------------------------------------------"
495	@echo ">>> World build started on `LC_ALL=C date`"
496	@echo "--------------------------------------------------------------"
497
498buildworld_epilogue:
499	@echo
500	@echo "--------------------------------------------------------------"
501	@echo ">>> World build completed on `LC_ALL=C date`"
502	@echo "--------------------------------------------------------------"
503
504#
505# We need to have this as a target because the indirection between Makefile
506# and Makefile.inc1 causes the correct PATH to be used, rather than a
507# modification of the current environment's PATH.  In addition, we need
508# to quote multiword values.
509# 
510buildenvvars:
511	@echo ${WMAKEENV:Q}
512
513buildenv:
514	@echo Entering world for ${TARGET_ARCH}:${TARGET}
515	@cd ${.CURDIR} && env ${WMAKEENV} sh || true
516
517TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
518toolchain: ${TOOLCHAIN_TGTS}
519kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
520
521#
522# installcheck
523#
524# Checks to be sure system is ready for installworld/installkernel.
525#
526installcheck:
527
528#
529# Require DESTDIR to be set if installing for a different architecture.
530#
531.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE}
532.if !make(distributeworld)
533installcheck: installcheck_DESTDIR
534installcheck_DESTDIR:
535.if !defined(DESTDIR) || empty(DESTDIR)
536	@echo "ERROR: Please set DESTDIR!"; \
537	false
538.endif
539.endif
540.endif
541
542#
543# Check for missing UIDs/GIDs.
544#
545CHECK_UIDS=
546CHECK_GIDS=	audit
547.if ${MK_SENDMAIL} != "no"
548CHECK_UIDS+=	smmsp
549CHECK_GIDS+=	smmsp
550.endif
551.if ${MK_PF} != "no"
552CHECK_UIDS+=	proxy
553CHECK_GIDS+=	proxy authpf
554.endif
555installcheck: installcheck_UGID
556installcheck_UGID:
557.for uid in ${CHECK_UIDS}
558	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
559		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
560		false; \
561	fi
562.endfor
563.for gid in ${CHECK_GIDS}
564	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
565		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
566		false; \
567	fi
568.endfor
569
570#
571# distributeworld
572#
573# Distributes everything compiled by a `buildworld'.
574#
575# installworld
576#
577# Installs everything compiled by a 'buildworld'.
578#
579distributeworld installworld: installcheck
580	mkdir -p ${INSTALLTMP}
581	for prog in [ awk cap_mkdb cat chflags chmod chown \
582	    date echo egrep find grep install-info \
583	    ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
584	    test true uname wc zic; do \
585		cp `which $$prog` ${INSTALLTMP}; \
586	done
587	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
588	rm -rf ${INSTALLTMP}
589
590#
591# reinstall
592#
593# If you have a build server, you can NFS mount the source and obj directories
594# and do a 'make reinstall' on the *client* to install new binaries from the
595# most recent server build.
596#
597reinstall:
598	@echo "--------------------------------------------------------------"
599	@echo ">>> Making hierarchy"
600	@echo "--------------------------------------------------------------"
601	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
602	@echo
603	@echo "--------------------------------------------------------------"
604	@echo ">>> Installing everything"
605	@echo "--------------------------------------------------------------"
606	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
607.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
608	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
609.endif
610
611redistribute:
612	@echo "--------------------------------------------------------------"
613	@echo ">>> Distributing everything"
614	@echo "--------------------------------------------------------------"
615	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
616.if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
617	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 DISTRIBUTION=lib32
618.endif
619
620distrib-dirs distribution:
621	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET}
622
623#
624# buildkernel and installkernel
625#
626# Which kernels to build and/or install is specified by setting
627# KERNCONF. If not defined a GENERIC kernel is built/installed.
628# Only the existing (depending TARGET) config files are used
629# for building kernels and only the first of these is designated
630# as the one being installed.
631#
632# Note that we have to use TARGET instead of TARGET_ARCH when
633# we're in kernel-land. Since only TARGET_ARCH is (expected) to
634# be set to cross-build, we have to make sure TARGET is set
635# properly.
636
637.if !defined(KERNCONF) && defined(KERNEL)
638KERNCONF=	${KERNEL}
639KERNWARN=
640.else
641KERNCONF?=	GENERIC
642.endif
643INSTKERNNAME?=	kernel
644
645KERNSRCDIR?=	${.CURDIR}/sys
646KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
647KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
648KERNCONFDIR?=	${KRNLCONFDIR}
649
650BUILDKERNELS=
651INSTALLKERNEL=
652.for _kernel in ${KERNCONF}
653.if exists(${KERNCONFDIR}/${_kernel})
654BUILDKERNELS+=	${_kernel}
655.if empty(INSTALLKERNEL)
656INSTALLKERNEL= ${_kernel}
657.endif
658.endif
659.endfor
660
661#
662# buildkernel
663#
664# Builds all kernels defined by BUILDKERNELS.
665#
666buildkernel:
667.if empty(BUILDKERNELS)
668	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
669	false
670.endif
671.if defined(KERNWARN)
672	@echo "--------------------------------------------------------------"
673	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
674	@echo "--------------------------------------------------------------"
675	@sleep 3
676.endif
677	@echo
678.for _kernel in ${BUILDKERNELS}
679	@echo "--------------------------------------------------------------"
680	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
681	@echo "--------------------------------------------------------------"
682	@echo "===> ${_kernel}"
683	mkdir -p ${KRNLOBJDIR}
684.if !defined(NO_KERNELCONFIG)
685	@echo
686	@echo "--------------------------------------------------------------"
687	@echo ">>> stage 1: configuring the kernel"
688	@echo "--------------------------------------------------------------"
689	cd ${KRNLCONFDIR}; \
690		PATH=${TMPPATH} \
691		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
692			${KERNCONFDIR}/${_kernel}
693.endif
694.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
695	@echo
696	@echo "--------------------------------------------------------------"
697	@echo ">>> stage 2.1: cleaning up the object tree"
698	@echo "--------------------------------------------------------------"
699	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
700.endif
701	@echo
702	@echo "--------------------------------------------------------------"
703	@echo ">>> stage 2.2: rebuilding the object tree"
704	@echo "--------------------------------------------------------------"
705	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
706	@echo
707	@echo "--------------------------------------------------------------"
708	@echo ">>> stage 2.3: build tools"
709	@echo "--------------------------------------------------------------"
710	cd ${KRNLOBJDIR}/${_kernel}; \
711	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
712	    ${MAKE} -DNO_CPU_CFLAGS -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
713# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
714.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
715.for target in obj depend all
716	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
717	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
718	    ${MAKE} -DNO_CPU_CFLAGS ${target}
719.endfor
720.endif
721.if !defined(NO_KERNELDEPEND)
722	@echo
723	@echo "--------------------------------------------------------------"
724	@echo ">>> stage 3.1: making dependencies"
725	@echo "--------------------------------------------------------------"
726	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
727.endif
728	@echo
729	@echo "--------------------------------------------------------------"
730	@echo ">>> stage 3.2: building everything"
731	@echo "--------------------------------------------------------------"
732	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
733	@echo "--------------------------------------------------------------"
734	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
735	@echo "--------------------------------------------------------------"
736.endfor
737
738#
739# installkernel, etc.
740#
741# Install the kernel defined by INSTALLKERNEL
742#
743installkernel installkernel.debug \
744reinstallkernel reinstallkernel.debug: installcheck
745.if empty(INSTALLKERNEL)
746	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
747	false
748.endif
749	@echo "--------------------------------------------------------------"
750	@echo ">>> Installing kernel"
751	@echo "--------------------------------------------------------------"
752	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
753	    ${CROSSENV} PATH=${TMPPATH} \
754	    ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
755
756#
757# doxygen
758#
759# Build the API documentation with doxygen
760#
761doxygen:
762	@if [ ! -x `/usr/bin/which doxygen` ]; then \
763		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
764		exit 1; \
765	fi
766	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
767
768#
769# update
770#
771# Update the source tree, by running cvsup and/or running cvs to update to the
772# latest copy.
773#
774update:
775.if defined(SUP_UPDATE)
776	@echo "--------------------------------------------------------------"
777	@echo ">>> Running ${SUP}"
778	@echo "--------------------------------------------------------------"
779.if defined(SUPFILE)
780	@${SUP} ${SUPFLAGS} ${SUPFILE}
781.endif
782.if defined(SUPFILE1)
783	@${SUP} ${SUPFLAGS} ${SUPFILE1}
784.endif
785.if defined(SUPFILE2)
786	@${SUP} ${SUPFLAGS} ${SUPFILE2}
787.endif
788.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
789	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
790.endif
791.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
792	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
793.endif
794.endif
795.if defined(CVS_UPDATE)
796	@echo "--------------------------------------------------------------"
797	@echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT}
798	@echo "--------------------------------------------------------------"
799	cd ${.CURDIR}; ${CVS} -R -q update ${CVSFLAGS}
800.endif
801
802#
803# ------------------------------------------------------------------------
804#
805# From here onwards are utility targets used by the 'make world' and
806# related targets.  If your 'world' breaks, you may like to try to fix
807# the problem and manually run the following targets to attempt to
808# complete the build.  Beware, this is *not* guaranteed to work, you
809# need to have a pretty good grip on the current state of the system
810# to attempt to manually finish it.  If in doubt, 'make world' again.
811#
812
813#
814# legacy: Build compatibility shims for the next three targets
815#
816legacy:
817.if ${BOOTSTRAPPING} < 503000
818	@echo "ERROR: Source upgrades from versions prior to 5.3 not supported."; \
819	false
820.endif
821.for _tool in tools/build
822	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
823	    cd ${.CURDIR}/${_tool}; \
824	    ${MAKE} DIRPRFX=${_tool}/ obj; \
825	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
826	    ${MAKE} DIRPRFX=${_tool}/ depend; \
827	    ${MAKE} DIRPRFX=${_tool}/ all; \
828	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
829.endfor
830
831#
832# bootstrap-tools: Build tools needed for compatibility
833#
834.if ${MK_GAMES} != "no"
835_strfile=	games/fortune/strfile
836.endif
837
838.if ${MK_CXX} != "no"
839_gperf=		gnu/usr.bin/gperf
840.if ${BOOTSTRAPPING} < 700004
841_groff=		gnu/usr.bin/groff
842.else
843_groff=		gnu/usr.bin/groff/tmac
844.endif
845.endif
846
847.if ${BOOTSTRAPPING} < 600029
848_texinfo=	gnu/usr.bin/texinfo
849.endif
850
851.if ${BOOTSTRAPPING} < 600015
852_cap_mkdb=	usr.bin/cap_mkdb
853.endif
854
855.if ${BOOTSTRAPPING} < 600018
856_colldef=	usr.bin/colldef
857.endif
858
859.if ${BOOTSTRAPPING} < 600017
860_gencat=	usr.bin/gencat
861.endif
862
863.if ${BOOTSTRAPPING} < 600016
864_mklocale=	usr.bin/mklocale
865.endif
866
867.if ${BOOTSTRAPPING} < 700015
868_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
869.endif
870
871.if ${MK_RESCUE} != "no" && \
872    ${BOOTSTRAPPING} < 600008
873_crunchgen=	usr.sbin/crunch/crunchgen
874.endif
875
876.if ${BOOTSTRAPPING} < 600020
877_pwd_mkdb=	usr.sbin/pwd_mkdb
878.endif
879
880bootstrap-tools:
881.for _tool in \
882    ${_strfile} \
883    ${_gperf} \
884    ${_groff} \
885    ${_texinfo} \
886    ${_cap_mkdb} \
887    ${_colldef} \
888    ${_gencat} \
889    usr.bin/lorder \
890    usr.bin/makewhatis \
891    ${_mklocale} \
892    usr.bin/rpcgen \
893    usr.bin/xinstall \
894    ${_gensnmptree} \
895    usr.sbin/config \
896    ${_crunchgen} \
897    ${_pwd_mkdb}
898	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
899		cd ${.CURDIR}/${_tool}; \
900		${MAKE} DIRPRFX=${_tool}/ obj; \
901		${MAKE} DIRPRFX=${_tool}/ depend; \
902		${MAKE} DIRPRFX=${_tool}/ all; \
903		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
904.endfor
905
906#
907# build-tools: Build special purpose build tools
908#
909.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
910_aicasm= sys/modules/aic7xxx/aicasm
911.endif
912
913.if !defined(NO_SHARE)
914_share=	share/syscons/scrnmaps
915.endif
916
917.if ${MK_KERBEROS} != "no"
918_kerberos5_tools= kerberos5/tools
919.endif
920
921.if ${MK_RESCUE} != "no"
922_rescue= rescue/rescue
923.endif
924
925build-tools:
926.for _tool in \
927    bin/csh \
928    bin/sh \
929    ${_rescue} \
930    lib/libncurses \
931    ${_share} \
932    ${_aicasm} \
933    usr.bin/awk \
934    lib/libmagic \
935    usr.sbin/sysinstall
936	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
937		cd ${.CURDIR}/${_tool}; \
938		${MAKE} DIRPRFX=${_tool}/ obj; \
939		${MAKE} DIRPRFX=${_tool}/ build-tools
940.endfor
941.for _tool in \
942    gnu/usr.bin/cc/cc_tools \
943    ${_kerberos5_tools}
944	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
945		cd ${.CURDIR}/${_tool}; \
946		${MAKE} DIRPRFX=${_tool}/ obj; \
947		${MAKE} DIRPRFX=${_tool}/ depend; \
948		${MAKE} DIRPRFX=${_tool}/ all
949.endfor
950
951#
952# cross-tools: Build cross-building tools
953#
954.if ${TARGET_ARCH} != ${MACHINE_ARCH}
955.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
956_btxld=		usr.sbin/btxld
957.endif
958.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
959_crunchide=	usr.sbin/crunch/crunchide
960.endif
961.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
962_kgzip=		usr.sbin/kgzip
963.endif
964.endif
965
966cross-tools:
967.for _tool in \
968    gnu/usr.bin/binutils \
969    gnu/usr.bin/cc \
970    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
971    ${_btxld} \
972    ${_crunchide} \
973    ${_kgzip}
974	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
975		cd ${.CURDIR}/${_tool}; \
976		${MAKE} DIRPRFX=${_tool}/ obj; \
977		${MAKE} DIRPRFX=${_tool}/ depend; \
978		${MAKE} DIRPRFX=${_tool}/ all; \
979		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
980.endfor
981
982#
983# hierarchy - ensure that all the needed directories are present
984#
985hierarchy:
986	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
987
988#
989# libraries - build all libraries, and install them under ${DESTDIR}.
990#
991# The list of libraries with dependents (${_prebuild_libs}) and their
992# interdependencies (__L) are built automatically by the
993# ${.CURDIR}/tools/make_libdeps.sh script.
994#
995libraries:
996	cd ${.CURDIR}; \
997	    ${MAKE} -f Makefile.inc1 _startup_libs; \
998	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
999	    ${MAKE} -f Makefile.inc1 _generic_libs;
1000
1001# These dependencies are not automatically generated:
1002#
1003# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
1004# shared libraries for ELF.
1005#
1006_startup_libs=	gnu/lib/csu gnu/lib/libgcc
1007.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1008_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1009.else
1010_startup_libs+=	lib/csu/${MACHINE_ARCH}
1011.endif
1012
1013_prebuild_libs=
1014
1015_generic_libs=	gnu/lib
1016
1017.if ${MK_IPX} != "no"
1018_prebuild_libs+= lib/libipx
1019.endif
1020
1021.if ${MK_KERBEROS} != "no"
1022_prebuild_libs+=	kerberos5/lib/libasn1
1023_prebuild_libs+=	kerberos5/lib/libkrb5
1024_prebuild_libs+=	kerberos5/lib/libroken
1025_generic_libs+=	kerberos5/lib
1026.endif
1027
1028_prebuild_libs+= lib/libbz2 lib/libcom_err lib/libcrypt lib/libexpat \
1029		lib/libkiconv lib/libkvm lib/libmd \
1030		lib/libncurses lib/libnetgraph lib/libopie lib/libpam \
1031		lib/libradius \
1032		lib/libsbuf lib/libtacplus lib/libutil \
1033		lib/libz lib/msun lib/libgssapi
1034
1035lib/libopie__L lib/libtacplus__L: lib/libmd__L
1036
1037_generic_libs+=	lib
1038
1039.if ${MK_CRYPT} != "no"
1040.if ${MK_OPENSSL} != "no"
1041_prebuild_libs+=	secure/lib/libcrypto secure/lib/libssl
1042lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1043.if ${MK_OPENSSH} != "no"
1044_prebuild_libs+=	secure/lib/libssh
1045secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1046.if ${MK_KERBEROS} != "no"
1047secure/lib/libssh__L: lib/libgssapi__L
1048.endif
1049.endif
1050.endif
1051_generic_libs+=	secure/lib
1052.endif
1053
1054.if ${MK_OPENSSL} == "no"
1055lib/libradius__L: lib/libmd__L
1056.endif
1057
1058.if ${MK_NIS} != "no"
1059_prebuild_libs+=	lib/libypclnt
1060.endif
1061
1062_generic_libs+=	usr.bin/lex/lib
1063
1064.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1065${_lib}__L: .PHONY
1066.if exists(${.CURDIR}/${_lib})
1067	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1068		cd ${.CURDIR}/${_lib}; \
1069		${MAKE} DIRPRFX=${_lib}/ obj; \
1070		${MAKE} DIRPRFX=${_lib}/ depend; \
1071		${MAKE} DIRPRFX=${_lib}/ all; \
1072		${MAKE} DIRPRFX=${_lib}/ install
1073.endif
1074.endfor
1075
1076# libpam is special: we need to build static PAM modules before
1077# static PAM library, and dynamic PAM library before dynamic PAM
1078# modules.
1079lib/libpam__L: .PHONY
1080	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1081		cd ${.CURDIR}/lib/libpam; \
1082		${MAKE} DIRPRFX=lib/libpam/ obj; \
1083		${MAKE} DIRPRFX=lib/libpam/ depend; \
1084		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1085		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1086
1087_startup_libs: ${_startup_libs:S/$/__L/}
1088_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1089_generic_libs: ${_generic_libs:S/$/__L/}
1090
1091.for __target in all clean cleandepend cleandir depend includes obj
1092.for entry in ${SUBDIR}
1093${entry}.${__target}__D: .PHONY
1094	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1095		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1096		edir=${entry}.${MACHINE_ARCH}; \
1097		cd ${.CURDIR}/$${edir}; \
1098	else \
1099		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1100		edir=${entry}; \
1101		cd ${.CURDIR}/$${edir}; \
1102	fi; \
1103	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1104.endfor
1105par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1106.endfor
1107
1108.include <bsd.subdir.mk>
1109
1110.if make(delete-old) || make(delete-old-libs) || make(check-old)
1111
1112#
1113# check for / delete old files section
1114#
1115
1116.include "ObsoleteFiles.inc"
1117
1118OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1119else you can not start such an application. Consult UPDATING for more \
1120information regarding how to cope with the removal/revision bump of a \
1121specific library."
1122
1123.if !defined(BATCH_DELETE_OLD_FILES)
1124RM_I=-i
1125.else
1126RM_I=-v
1127.endif
1128
1129delete-old-files:
1130	@echo ">>> Removing old files (only deletes safe to delete libs)"
1131.for file in ${OLD_FILES}
1132# Ask for every old file if the user really wants to remove it.
1133# It's annoying, but better safe than sorry.
1134	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1135		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1136		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1137			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1138			chflags noschg "${DESTDIR}/${file}"; \
1139			rm ${RM_I} "${DESTDIR}/${file}"; \
1140		fi; \
1141	fi
1142.endfor
1143# Remove catpages without corresponding manpages.
1144	@3<&0; \
1145	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1146	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1147	while read catpage; do \
1148		read manpage; \
1149		if [ ! -e "$${manpage}" ]; then \
1150			rm ${RM_I} $${catpage} <&3 ; \
1151	        fi; \
1152	done
1153	@echo ">>> Old files removed"
1154
1155check-old-files:
1156	@echo ">>> Checking for old files"
1157.for file in ${OLD_FILES}
1158	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1159		 echo "${DESTDIR}/${file}"; \
1160	fi
1161.endfor
1162# Check for catpages without corresponding manpages.
1163	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1164	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1165	while read catpage; do \
1166		read manpage; \
1167		if [ ! -e "$${manpage}" ]; then \
1168			echo $${catpage} ; \
1169	        fi; \
1170	done
1171
1172delete-old-libs:
1173	@echo ">>> Removing old libraries"
1174	@echo "${OLD_LIBS_MESSAGE}" | fmt
1175.for file in ${OLD_LIBS}
1176	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1177		rm ${RM_I} "${DESTDIR}/${file}" || true; \
1178		if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then\
1179			echo "Removing schg flag on ${DESTDIR}/${file}"; \
1180			chflags noschg "${DESTDIR}/${file}"; \
1181			rm ${RM_I} "${DESTDIR}/${file}"; \
1182		fi; \
1183	fi
1184.endfor
1185	@echo ">>> Old libraries removed"
1186
1187check-old-libs:
1188	@echo ">>> Checking for old libraries"
1189.for file in ${OLD_LIBS}
1190	@if [ -f "${DESTDIR}/${file}" -o -L "${DESTDIR}/${file}" ]; then \
1191		echo "${DESTDIR}/${file}"; \
1192	fi
1193.endfor
1194
1195delete-old-dirs:
1196	@echo ">>> Removing old directories"
1197.for dir in ${OLD_DIRS}
1198# Don't fail if an old directory isn't empty.
1199	@if [ -d "${DESTDIR}/${dir}" ]; then \
1200		rmdir -v "${DESTDIR}/${dir}" || true; \
1201	else \
1202		if [ -L "${DESTDIR}/${dir}" ]; then \
1203			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1204		fi; \
1205	fi
1206.endfor
1207	@echo ">>> Old directories removed"
1208
1209check-old-dirs:
1210	@echo ">>> Checking for old directories"
1211.for dir in ${OLD_DIRS}
1212	@if [ -d "${DESTDIR}/${dir}" ]; then \
1213		echo "${DESTDIR}/${dir}"; \
1214	else \
1215		if [ -L "${DESTDIR}/${dir}" ]; then \
1216			echo "${DESTDIR}/${dir} is a link, please remove everything manually."; \
1217		fi; \
1218	fi
1219.endfor
1220
1221delete-old: delete-old-files delete-old-dirs
1222	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1223
1224check-old: check-old-files check-old-libs check-old-dirs
1225	@echo "To remove old files and directories run '${MAKE} delete-old'."
1226	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1227
1228.endif
1229
1230#
1231# showconfig - show build configuration.
1232#
1233showconfig:
1234	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1235