Makefile.inc1 revision 246096
1#
2# $FreeBSD: head/Makefile.inc1 246096 2013-01-29 21:48:10Z brooks $
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#	-DDB_FROM_SRC use the user/group databases in src/etc instead of
8#	    the system database when installing.
9#	-DNO_SHARE do not go into share subdir
10#	-DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ}
11#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
14#	-DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
15#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
16#	-DNO_ROOT install without using root privilege
17#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
18#	-DNO_CTF do not run the DTrace CTF conversion tools on built objects
19#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
20#	LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
21#	LOCAL_MTREE="list of mtree files" to process to allow local directories
22#	    to be created before files are installed
23#	LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
24#	    list
25#	METALOG="path to metadata log" to write permission and ownership
26#	    when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
27#	TARGET="machine" to crossbuild world for a different machine type
28#	TARGET_ARCH= may be required when a TARGET supports multiple endians
29#	BUILDENV_SHELL= shell to launch for the buildenv target (def:/bin/sh)
30
31#
32# The intended user-driven targets are:
33# buildworld  - rebuild *everything*, including glue to help do upgrades
34# installworld- install everything built by "buildworld"
35# doxygen     - build API documentation of the kernel
36# update      - convenient way to update your source tree (eg: cvsup/cvs)
37#
38# Standard targets (not defined here) are documented in the makefiles in
39# /usr/share/mk.  These include:
40#		obj depend all install clean cleandepend cleanobj
41
42# You are supposed to define both of these when calling Makefile.inc1
43# directly.  However, some old scripts don't.  Cope for the moment, but
44# issue a new warning for a transition period.
45.if defined(TARGET) && !defined(TARGET_ARCH)
46.warning "You must pass both TARGET and TARGET_ARCH to Makefile.inc1.  Setting TARGET_ARCH=${TARGET}."
47TARGET_ARCH=${TARGET}
48.endif
49.if !defined(TARGET) || !defined(TARGET_ARCH)
50.error "Both TARGET and TARGET_ARCH must be defined."
51.endif
52
53.include <bsd.own.mk>
54.include <bsd.arch.inc.mk>
55.include <bsd.compiler.mk>
56
57# We must do share/info early so that installation of info `dir'
58# entries works correctly.  Do it first since it is less likely to
59# grow dependencies on include and lib than vice versa.
60#
61# We must do lib/ and libexec/ before bin/, because if installworld
62# installs a new /bin/sh, the 'make' command will *immediately*
63# use that new version.  And the new (dynamically-linked) /bin/sh
64# will expect to find appropriate libraries in /lib and /libexec.
65#
66SUBDIR=	share/info lib libexec
67SUBDIR+=bin
68.if ${MK_GAMES} != "no"
69SUBDIR+=games
70.endif
71.if ${MK_CDDL} != "no"
72SUBDIR+=cddl
73.endif
74SUBDIR+=gnu include
75.if ${MK_KERBEROS} != "no"
76SUBDIR+=kerberos5
77.endif
78.if ${MK_RESCUE} != "no"
79SUBDIR+=rescue
80.endif
81SUBDIR+=sbin
82.if ${MK_CRYPT} != "no"
83SUBDIR+=secure
84.endif
85.if !defined(NO_SHARE)
86SUBDIR+=share
87.endif
88SUBDIR+=sys usr.bin usr.sbin
89.if ${MK_OFED} != "no"
90SUBDIR+=contrib/ofed
91.endif
92#
93# We must do etc/ last for install/distribute to work.
94#
95SUBDIR+=etc
96
97# These are last, since it is nice to at least get the base system
98# rebuilt before you do them.
99.for _DIR in ${LOCAL_LIB_DIRS} ${LOCAL_DIRS}
100.if exists(${.CURDIR}/${_DIR}/Makefile)
101SUBDIR+= ${_DIR}
102.endif
103.endfor
104
105.if defined(SUBDIR_OVERRIDE)
106SUBDIR=		${SUBDIR_OVERRIDE}
107.endif
108
109.if defined(NOCLEAN)
110NO_CLEAN=	${NOCLEAN}
111.endif
112.if defined(NO_CLEANDIR)
113CLEANDIR=	clean cleandepend
114.else
115CLEANDIR=	cleandir
116.endif
117
118LOCAL_TOOL_DIRS?=
119
120BUILDENV_SHELL?=/bin/sh
121
122CVS?=		cvs
123CVSFLAGS?=	-A -P -d -I!
124SVN?=		svn
125SVNFLAGS?=	-r HEAD
126SUP?=		/usr/bin/csup
127SUPFLAGS?=	-g -L 2
128.if defined(SUPHOST)
129SUPFLAGS+=	-h ${SUPHOST}
130.endif
131
132MAKEOBJDIRPREFIX?=	/usr/obj
133.if !defined(OSRELDATE)
134.if exists(/usr/include/osreldate.h)
135OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
136		/usr/include/osreldate.h
137.else
138OSRELDATE=	0
139.endif
140.endif
141
142.if !defined(VERSION)
143VERSION!=	uname -srp
144VERSION+=	${OSRELDATE}
145.endif
146
147KNOWN_ARCHES?=	amd64 arm armeb/arm armv6/arm armv6eb/arm i386 i386/pc98 ia64 mips mipsel/mips mips64el/mips mips64/mips mipsn32el/mips mipsn32/mips powerpc powerpc64/powerpc sparc64
148.if ${TARGET} == ${TARGET_ARCH}
149_t=		${TARGET}
150.else
151_t=		${TARGET_ARCH}/${TARGET}
152.endif
153.for _t in ${_t}
154.if empty(KNOWN_ARCHES:M${_t})
155.error Unknown target ${TARGET_ARCH}:${TARGET}.
156.endif
157.endfor
158
159.if ${TARGET} == ${MACHINE}
160TARGET_CPUTYPE?=${CPUTYPE}
161.else
162TARGET_CPUTYPE?=
163.endif
164
165.if !empty(TARGET_CPUTYPE)
166_TARGET_CPUTYPE=${TARGET_CPUTYPE}
167.else
168_TARGET_CPUTYPE=dummy
169.endif
170_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
171		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
172.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
173.error CPUTYPE global should be set with ?=.
174.endif
175.if make(buildworld)
176BUILD_ARCH!=	uname -p
177.if ${MACHINE_ARCH} != ${BUILD_ARCH}
178.error To cross-build, set TARGET_ARCH.
179.endif
180.endif
181.if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
182OBJTREE=	${MAKEOBJDIRPREFIX}
183.else
184OBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
185.endif
186WORLDTMP=	${OBJTREE}${.CURDIR}/tmp
187# /usr/games added for fortune which depend on strfile
188BPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
189XPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
190STRICTTMPPATH=	${BPATH}:${XPATH}
191TMPPATH=	${STRICTTMPPATH}:${PATH}
192
193#
194# Avoid running mktemp(1) unless actually needed.
195# It may not be functional, e.g., due to new ABI
196# when in the middle of installing over this system.
197#
198.if make(distributeworld) || make(installworld)
199INSTALLTMP!=	/usr/bin/mktemp -d -u -t install
200.endif
201
202#
203# Building a world goes through the following stages
204#
205# 1. legacy stage [BMAKE]
206#	This stage is responsible for creating compatibility
207#	shims that are needed by the bootstrap-tools,
208#	build-tools and cross-tools stages.
209# 1. bootstrap-tools stage [BMAKE]
210#	This stage is responsible for creating programs that
211#	are needed for backward compatibility reasons. They
212#	are not built as cross-tools.
213# 2. build-tools stage [TMAKE]
214#	This stage is responsible for creating the object
215#	tree and building any tools that are needed during
216#	the build process.
217# 3. cross-tools stage [XMAKE]
218#	This stage is responsible for creating any tools that
219#	are needed for cross-builds. A cross-compiler is one
220#	of them.
221# 4. world stage [WMAKE]
222#	This stage actually builds the world.
223# 5. install stage (optional) [IMAKE]
224#	This stage installs a previously built world.
225#
226
227BOOTSTRAPPING?=	0
228
229# Common environment for world related stages
230CROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
231		MACHINE_ARCH=${TARGET_ARCH} \
232		MACHINE=${TARGET} \
233		CPUTYPE=${TARGET_CPUTYPE}
234.if ${MK_GROFF} != "no"
235CROSSENV+=	GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
236		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
237		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
238.endif
239
240# bootstrap-tools stage
241BMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
242		PATH=${BPATH}:${PATH} \
243		WORLDTMP=${WORLDTMP} \
244		VERSION="${VERSION}" \
245		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
246		COMPILER_TYPE=${COMPILER_TYPE}
247BMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
248		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
249		DESTDIR= \
250		BOOTSTRAPPING=${OSRELDATE} \
251		SSP_CFLAGS= \
252		-DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
253		-DNO_PIC -DNO_PROFILE -DNO_SHARED \
254		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD
255
256# build-tools stage
257TMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
258		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
259		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
260		DESTDIR= \
261		BOOTSTRAPPING=${OSRELDATE} \
262		SSP_CFLAGS= \
263		-DNO_LINT \
264		-DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF -DEARLY_BUILD
265
266# cross-tools stage
267XMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
268		TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
269		-DWITHOUT_GDB
270
271# world stage
272WMAKEENV=	${CROSSENV} \
273		_SHLIBDIRPREFIX=${WORLDTMP} \
274		_LDSCRIPTROOT= \
275		VERSION="${VERSION}" \
276		INSTALL="sh ${.CURDIR}/tools/install.sh" \
277		PATH=${TMPPATH}
278.if ${MK_CDDL} == "no"
279WMAKEENV+=	NO_CTF=1
280.endif
281.if ${CC:T:Mgcc} == "gcc"
282WMAKE_COMPILER_TYPE=	gcc
283.elif ${CC:T:Mclang} == "clang"
284WMAKE_COMPILER_TYPE=	clang
285.elif ${MK_CLANG_IS_CC} == "no"
286WMAKE_COMPILER_TYPE=	gcc
287.else
288WMAKE_COMPILER_TYPE=	clang
289.endif
290WMAKEENV+=	COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
291WMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
292
293.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64"
294# 32 bit world
295LIB32TMP=	${OBJTREE}${.CURDIR}/lib32
296
297.if ${TARGET_ARCH} == "amd64"
298.if empty(TARGET_CPUTYPE)
299LIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
300.else
301LIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
302.endif
303LIB32WMAKEENV=	MACHINE=i386 MACHINE_ARCH=i386 \
304		MACHINE_CPU="i686 mmx sse sse2"
305LIB32WMAKEFLAGS=	\
306		AS="${AS} --32" \
307		LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32"
308
309.elif ${TARGET_ARCH} == "powerpc64"
310.if empty(TARGET_CPUTYPE)
311LIB32CPUFLAGS=	-mcpu=powerpc
312.else
313LIB32CPUFLAGS=	-mcpu=${TARGET_CPUTYPE}
314.endif
315LIB32WMAKEENV=	MACHINE=powerpc MACHINE_ARCH=powerpc
316LIB32WMAKEFLAGS=	\
317		LD="${LD} -m elf32ppc_fbsd"
318.endif
319
320
321LIB32FLAGS=	-m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \
322		-isystem ${LIB32TMP}/usr/include/ \
323		-L${LIB32TMP}/usr/lib32 \
324		-B${LIB32TMP}/usr/lib32
325
326# Yes, the flags are redundant.
327LIB32WMAKEENV+=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
328		_SHLIBDIRPREFIX=${LIB32TMP} \
329		_LDSCRIPTROOT=${LIB32TMP} \
330		VERSION="${VERSION}" \
331		INSTALL="sh ${.CURDIR}/tools/install.sh" \
332		PATH=${TMPPATH} \
333		LIBDIR=/usr/lib32 \
334		SHLIBDIR=/usr/lib32 \
335		COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
336LIB32WMAKEFLAGS+=	\
337		CC="${CC} ${LIB32FLAGS}" \
338		CXX="${CXX} ${LIB32FLAGS}" \
339		DESTDIR=${LIB32TMP} \
340		-DCOMPAT_32BIT \
341		-DLIBRARIES_ONLY \
342		-DNO_CPU_CFLAGS \
343		-DNO_CTF \
344		-DNO_LINT
345
346LIB32WMAKE=	${LIB32WMAKEENV} ${MAKE} ${LIB32WMAKEFLAGS} \
347		-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO -DWITHOUT_HTML
348LIB32IMAKE=	${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} -DNO_INCS \
349		${IMAKE_INSTALL}
350.endif
351
352IMAKEENV=	${CROSSENV:N_LDSCRIPTROOT=*}
353IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1 \
354		${IMAKE_INSTALL} ${IMAKE_MTREE}
355.if empty(.MAKEFLAGS:M-n)
356IMAKEENV+=	PATH=${STRICTTMPPATH}:${INSTALLTMP} \
357		LD_LIBRARY_PATH=${INSTALLTMP} \
358		PATH_LOCALE=${INSTALLTMP}/locale
359IMAKE+=		__MAKE_SHELL=${INSTALLTMP}/sh
360.else
361IMAKEENV+=	PATH=${TMPPATH}:${INSTALLTMP}
362.endif
363.if defined(DB_FROM_SRC)
364INSTALLFLAGS+=	-N ${.CURDIR}/etc
365MTREEFLAGS+=	-N ${.CURDIR}/etc
366.endif
367.if defined(NO_ROOT)
368METALOG?=	${DESTDIR}/${DISTDIR}/METALOG
369IMAKE+=		-DNO_ROOT METALOG=${METALOG}
370INSTALL_DDIR=	${DESTDIR}/${DISTDIR}
371INSTALLFLAGS+=	-U -M ${METALOG} -D ${INSTALL_DDIR:S://:/:g:C:/$::}
372MTREEFLAGS+=	-W
373.endif
374.if defined(DB_FROM_SRC) || defined(NO_ROOT)
375IMAKE_INSTALL=	INSTALL="install ${INSTALLFLAGS}"
376IMAKE_MTREE=	MTREE_CMD="nmtree ${MTREEFLAGS}"
377.endif
378
379# kernel stage
380KMAKEENV=	${WMAKEENV}
381KMAKE=		${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME}
382
383#
384# buildworld
385#
386# Attempt to rebuild the entire system, with reasonable chance of
387# success, regardless of how old your existing system is.
388#
389_worldtmp:
390.if ${.CURDIR:C/[^,]//g} != ""
391#	The m4 build of sendmail files doesn't like it if ',' is used
392#	anywhere in the path of it's files.
393	@echo
394	@echo "*** Error: path to source tree contains a comma ','"
395	@echo
396	false
397.endif
398	@echo
399	@echo "--------------------------------------------------------------"
400	@echo ">>> Rebuilding the temporary build tree"
401	@echo "--------------------------------------------------------------"
402.if !defined(NO_CLEAN)
403	rm -rf ${WORLDTMP}
404.if defined(LIB32TMP)
405	rm -rf ${LIB32TMP}
406.endif
407.else
408	rm -rf ${WORLDTMP}/legacy/usr/include
409#	XXX - These three can depend on any header file.
410	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
411	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
412	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
413.endif
414.for _dir in \
415    lib usr legacy/usr
416	mkdir -p ${WORLDTMP}/${_dir}
417.endfor
418	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
419	    -p ${WORLDTMP}/legacy/usr >/dev/null
420.if ${MK_GROFF} != "no"
421	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
422	    -p ${WORLDTMP}/legacy/usr >/dev/null
423.endif
424	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
425	    -p ${WORLDTMP}/usr >/dev/null
426	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
427	    -p ${WORLDTMP}/usr/include >/dev/null
428	ln -sf ${.CURDIR}/sys ${WORLDTMP}
429.if ${MK_BIND_LIBS} != "no"
430	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
431	    -p ${WORLDTMP}/usr/include >/dev/null
432.endif
433.for _mtree in ${LOCAL_MTREE}
434	mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
435.endfor
436_legacy:
437	@echo
438	@echo "--------------------------------------------------------------"
439	@echo ">>> stage 1.1: legacy release compatibility shims"
440	@echo "--------------------------------------------------------------"
441	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
442_bootstrap-tools:
443	@echo
444	@echo "--------------------------------------------------------------"
445	@echo ">>> stage 1.2: bootstrap tools"
446	@echo "--------------------------------------------------------------"
447	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
448_cleanobj:
449.if !defined(NO_CLEAN)
450	@echo
451	@echo "--------------------------------------------------------------"
452	@echo ">>> stage 2.1: cleaning up the object tree"
453	@echo "--------------------------------------------------------------"
454	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
455.if defined(LIB32TMP)
456	${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
457.endif
458.endif
459_obj:
460	@echo
461	@echo "--------------------------------------------------------------"
462	@echo ">>> stage 2.2: rebuilding the object tree"
463	@echo "--------------------------------------------------------------"
464	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
465_build-tools:
466	@echo
467	@echo "--------------------------------------------------------------"
468	@echo ">>> stage 2.3: build tools"
469	@echo "--------------------------------------------------------------"
470	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
471_cross-tools:
472	@echo
473	@echo "--------------------------------------------------------------"
474	@echo ">>> stage 3: cross tools"
475	@echo "--------------------------------------------------------------"
476	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
477_includes:
478	@echo
479	@echo "--------------------------------------------------------------"
480	@echo ">>> stage 4.1: building includes"
481	@echo "--------------------------------------------------------------"
482	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
483_libraries:
484	@echo
485	@echo "--------------------------------------------------------------"
486	@echo ">>> stage 4.2: building libraries"
487	@echo "--------------------------------------------------------------"
488	${_+_}cd ${.CURDIR}; \
489	    ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
490	    -DWITHOUT_MAN -DNO_PROFILE libraries
491_depend:
492	@echo
493	@echo "--------------------------------------------------------------"
494	@echo ">>> stage 4.3: make dependencies"
495	@echo "--------------------------------------------------------------"
496	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
497everything:
498	@echo
499	@echo "--------------------------------------------------------------"
500	@echo ">>> stage 4.4: building everything"
501	@echo "--------------------------------------------------------------"
502	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
503.if defined(LIB32TMP)
504build32:
505	@echo
506	@echo "--------------------------------------------------------------"
507	@echo ">>> stage 5.1: building 32 bit shim libraries"
508	@echo "--------------------------------------------------------------"
509	mkdir -p ${LIB32TMP}/usr/include
510	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
511	    -p ${LIB32TMP}/usr >/dev/null
512	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
513	    -p ${LIB32TMP}/usr/include >/dev/null
514	mkdir -p ${WORLDTMP}
515	ln -sf ${.CURDIR}/sys ${WORLDTMP}
516.for _t in obj includes
517	cd ${.CURDIR}/include; ${LIB32WMAKE} DIRPRFX=include/ ${_t}
518	cd ${.CURDIR}/lib; ${LIB32WMAKE} DIRPRFX=lib/ ${_t}
519.if ${MK_CDDL} != "no"
520	cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} DIRPRFX=cddl/lib/ ${_t}
521.endif
522	cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} DIRPRFX=gnu/lib/ ${_t}
523.if ${MK_CRYPT} != "no"
524	cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} DIRPRFX=secure/lib/ ${_t}
525.endif
526.if ${MK_KERBEROS} != "no"
527	cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} DIRPRFX=kerberos5/lib ${_t}
528.endif
529.endfor
530.for _dir in usr.bin/lex/lib
531	cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} DIRPRFX=${_dir}/ obj
532.endfor
533.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
534	cd ${.CURDIR}/${_dir}; \
535	    WORLDTMP=${WORLDTMP} \
536	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
537	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \
538	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF \
539	    -DEARLY_BUILD build-tools
540.endfor
541	cd ${.CURDIR}; \
542	    ${LIB32WMAKE} -f Makefile.inc1 libraries
543.for _t in obj depend all
544	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} \
545	    DIRPRFX=libexec/rtld-elf/ ${_t}
546	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} \
547	    DIRPRFX=usr.bin/ldd ${_t}
548.endfor
549
550distribute32 install32:
551	cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
552.if ${MK_CDDL} != "no"
553	cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
554.endif
555	cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
556.if ${MK_CRYPT} != "no"
557	cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
558.endif
559.if ${MK_KERBEROS} != "no"
560	cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
561.endif
562	cd ${.CURDIR}/libexec/rtld-elf; \
563	    PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
564	cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//}
565.endif
566
567WMAKE_TGTS=
568.if !defined(SUBDIR_OVERRIDE)
569WMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
570.endif
571WMAKE_TGTS+=	_cleanobj _obj _build-tools
572.if !defined(SUBDIR_OVERRIDE)
573WMAKE_TGTS+=	_cross-tools
574.endif
575WMAKE_TGTS+=	_includes _libraries _depend everything
576.if defined(LIB32TMP) && ${MK_LIB32} != "no"
577WMAKE_TGTS+=	build32
578.endif
579
580buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
581.ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
582
583buildworld_prologue:
584	@echo "--------------------------------------------------------------"
585	@echo ">>> World build started on `LC_ALL=C date`"
586	@echo "--------------------------------------------------------------"
587
588buildworld_epilogue:
589	@echo
590	@echo "--------------------------------------------------------------"
591	@echo ">>> World build completed on `LC_ALL=C date`"
592	@echo "--------------------------------------------------------------"
593
594#
595# We need to have this as a target because the indirection between Makefile
596# and Makefile.inc1 causes the correct PATH to be used, rather than a
597# modification of the current environment's PATH.  In addition, we need
598# to quote multiword values.
599#
600buildenvvars:
601	@echo ${WMAKEENV:Q}
602
603buildenv:
604	@echo Entering world for ${TARGET_ARCH}:${TARGET}
605	@cd ${.CURDIR} && env ${WMAKEENV} ${BUILDENV_SHELL} || true
606
607TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
608toolchain: ${TOOLCHAIN_TGTS}
609kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
610
611#
612# installcheck
613#
614# Checks to be sure system is ready for installworld/installkernel.
615#
616installcheck:
617
618#
619# Require DESTDIR to be set if installing for a different architecture or
620# using the user/group database in the source tree.
621#
622.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
623    defined(DB_FROM_SRC)
624.if !make(distributeworld)
625installcheck: installcheck_DESTDIR
626installcheck_DESTDIR:
627.if !defined(DESTDIR) || empty(DESTDIR)
628	@echo "ERROR: Please set DESTDIR!"; \
629	false
630.endif
631.endif
632.endif
633
634.if !defined(DB_FROM_SRC)
635#
636# Check for missing UIDs/GIDs.
637#
638CHECK_UIDS=	auditdistd
639CHECK_GIDS=	audit
640.if ${MK_SENDMAIL} != "no"
641CHECK_UIDS+=	smmsp
642CHECK_GIDS+=	smmsp
643.endif
644.if ${MK_PF} != "no"
645CHECK_UIDS+=	proxy
646CHECK_GIDS+=	proxy authpf
647.endif
648installcheck: installcheck_UGID
649installcheck_UGID:
650.for uid in ${CHECK_UIDS}
651	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
652		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
653		false; \
654	fi
655.endfor
656.for gid in ${CHECK_GIDS}
657	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
658		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
659		false; \
660	fi
661.endfor
662.endif
663
664#
665# Required install tools to be saved in a scratch dir for safety.
666#
667.if ${MK_INFO} != "no"
668_install-info=	install-info
669.endif
670.if ${MK_ZONEINFO} != "no"
671_zoneinfo=	zic tzsetup
672.endif
673
674ITOOLS=	[ awk cap_mkdb cat chflags chmod chown \
675	date echo egrep find grep id install ${_install-info} \
676	ln lockf make mkdir mtree ${_nmtree_itools} mv pwd_mkdb \
677	rm sed sh sysctl test true uname wc ${_zoneinfo}
678
679#
680# distributeworld
681#
682# Distributes everything compiled by a `buildworld'.
683#
684# installworld
685#
686# Installs everything compiled by a 'buildworld'.
687#
688
689# Non-base distributions produced by the base system
690EXTRA_DISTRIBUTIONS=	doc
691.if ${MK_GAMES} != "no"
692EXTRA_DISTRIBUTIONS+=	games
693.endif
694.if defined(LIB32TMP) && ${MK_LIB32} != "no"
695EXTRA_DISTRIBUTIONS+=	lib32
696.endif
697
698MTREE_MAGIC?=	mtree 2.0
699
700distributeworld installworld: installcheck
701	mkdir -p ${INSTALLTMP}
702	progs=$$(for prog in ${ITOOLS}; do \
703		if progpath=`which $$prog`; then \
704			echo $$progpath; \
705		else \
706			echo "Required tool $$prog not found in PATH." >&2; \
707			exit 1; \
708		fi; \
709	    done); \
710	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
711	    while read line; do \
712		set -- $$line; \
713		if [ "$$2 $$3" != "not found" ]; then \
714			echo $$2; \
715		else \
716			echo "Required library $$1 not found." >&2; \
717			exit 1; \
718		fi; \
719	    done); \
720	cp $$libs $$progs ${INSTALLTMP}
721	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
722.if defined(NO_ROOT)
723	echo "#${MTREE_MAGIC}" > ${METALOG}
724.endif
725.if make(distributeworld)
726.for dist in ${EXTRA_DISTRIBUTIONS}
727	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
728	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
729	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
730	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
731	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
732	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
733	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
734.if defined(NO_ROOT)
735	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
736	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
737	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
738	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
739	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
740	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
741.endif
742.endfor
743	-mkdir ${DESTDIR}/${DISTDIR}/base
744	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
745	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
746	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
747	    LOCAL_MTREE=${LOCAL_MTREE} distrib-dirs
748.endif
749	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
750	    ${IMAKEENV} rm -rf ${INSTALLTMP}
751.if make(distributeworld)
752.for dist in ${EXTRA_DISTRIBUTIONS}
753	find ${DESTDIR}/${DISTDIR}/${dist} -empty -delete
754.endfor
755.if defined(NO_ROOT)
756.for dist in base ${EXTRA_DISTRIBUTIONS}
757	@# For each file that exists in this dist, print the corresponding
758	@# line from the METALOG.  This relies on the fact that
759	@# a line containing only the filename will sort immediatly before
760	@# the relevant mtree line.
761	cd ${DESTDIR}/${DISTDIR}; \
762	find ./${dist} | sort -u ${METALOG} - | \
763	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
764	${DESTDIR}/${DISTDIR}/${dist}.meta
765.endfor
766.endif
767.endif
768
769packageworld:
770.for dist in base ${EXTRA_DISTRIBUTIONS}
771.if defined(NO_ROOT)
772	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
773	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
774	    @${DESTDIR}/${DISTDIR}/${dist}.meta
775.else
776	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
777	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz .
778.endif
779.endfor
780
781#
782# reinstall
783#
784# If you have a build server, you can NFS mount the source and obj directories
785# and do a 'make reinstall' on the *client* to install new binaries from the
786# most recent server build.
787#
788reinstall:
789	@echo "--------------------------------------------------------------"
790	@echo ">>> Making hierarchy"
791	@echo "--------------------------------------------------------------"
792	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
793	    LOCAL_MTREE=${LOCAL_MTREE} hierarchy
794	@echo
795	@echo "--------------------------------------------------------------"
796	@echo ">>> Installing everything"
797	@echo "--------------------------------------------------------------"
798	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
799.if defined(LIB32TMP) && ${MK_LIB32} != "no"
800	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
801.endif
802
803redistribute:
804	@echo "--------------------------------------------------------------"
805	@echo ">>> Distributing everything"
806	@echo "--------------------------------------------------------------"
807	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
808.if defined(LIB32TMP) && ${MK_LIB32} != "no"
809	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
810	    DISTRIBUTION=lib32
811.endif
812
813distrib-dirs distribution:
814	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
815	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
816
817#
818# buildkernel and installkernel
819#
820# Which kernels to build and/or install is specified by setting
821# KERNCONF. If not defined a GENERIC kernel is built/installed.
822# Only the existing (depending TARGET) config files are used
823# for building kernels and only the first of these is designated
824# as the one being installed.
825#
826# Note that we have to use TARGET instead of TARGET_ARCH when
827# we're in kernel-land. Since only TARGET_ARCH is (expected) to
828# be set to cross-build, we have to make sure TARGET is set
829# properly.
830
831.if defined(KERNFAST)
832NO_KERNELCLEAN=	t
833NO_KERNELCONFIG=	t
834NO_KERNELDEPEND=	t
835NO_KERNELOBJ=		t
836# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
837.if !defined(KERNCONF) && ${KERNFAST} != "1"
838KERNCONF=${KERNFAST}
839.endif
840.endif
841.if !defined(KERNCONF) && defined(KERNEL)
842KERNCONF=	${KERNEL}
843KERNWARN=
844.else
845.if ${TARGET_ARCH} == "powerpc64"
846KERNCONF?=	GENERIC64
847.else
848KERNCONF?=	GENERIC
849.endif
850.endif
851INSTKERNNAME?=	kernel
852
853KERNSRCDIR?=	${.CURDIR}/sys
854KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
855KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
856KERNCONFDIR?=	${KRNLCONFDIR}
857
858BUILDKERNELS=
859INSTALLKERNEL=
860.for _kernel in ${KERNCONF}
861.if exists(${KERNCONFDIR}/${_kernel})
862BUILDKERNELS+=	${_kernel}
863.if empty(INSTALLKERNEL)
864INSTALLKERNEL= ${_kernel}
865.endif
866.endif
867.endfor
868
869#
870# buildkernel
871#
872# Builds all kernels defined by BUILDKERNELS.
873#
874buildkernel:
875.if empty(BUILDKERNELS)
876	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
877	false
878.endif
879.if defined(KERNWARN)
880	@echo "--------------------------------------------------------------"
881	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
882	@echo "--------------------------------------------------------------"
883	@sleep 3
884.endif
885	@echo
886.for _kernel in ${BUILDKERNELS}
887	@echo "--------------------------------------------------------------"
888	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
889	@echo "--------------------------------------------------------------"
890	@echo "===> ${_kernel}"
891	mkdir -p ${KRNLOBJDIR}
892.if !defined(NO_KERNELCONFIG)
893	@echo
894	@echo "--------------------------------------------------------------"
895	@echo ">>> stage 1: configuring the kernel"
896	@echo "--------------------------------------------------------------"
897	cd ${KRNLCONFDIR}; \
898		PATH=${TMPPATH} \
899		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
900			${KERNCONFDIR}/${_kernel}
901.endif
902.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
903	@echo
904	@echo "--------------------------------------------------------------"
905	@echo ">>> stage 2.1: cleaning up the object tree"
906	@echo "--------------------------------------------------------------"
907	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
908.endif
909.if !defined(NO_KERNELOBJ)
910	@echo
911	@echo "--------------------------------------------------------------"
912	@echo ">>> stage 2.2: rebuilding the object tree"
913	@echo "--------------------------------------------------------------"
914	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
915.endif
916	@echo
917	@echo "--------------------------------------------------------------"
918	@echo ">>> stage 2.3: build tools"
919	@echo "--------------------------------------------------------------"
920	cd ${KRNLOBJDIR}/${_kernel}; \
921	    PATH=${BPATH}:${PATH} \
922	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
923	    ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF -DEARLY_BUILD \
924	    -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
925# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
926.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
927.for target in obj depend all
928	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
929	    PATH=${BPATH}:${PATH} \
930	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
931	    ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF -DEARLY_BUILD ${target}
932.endfor
933.endif
934.if !defined(NO_KERNELDEPEND)
935	@echo
936	@echo "--------------------------------------------------------------"
937	@echo ">>> stage 3.1: making dependencies"
938	@echo "--------------------------------------------------------------"
939	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
940.endif
941	@echo
942	@echo "--------------------------------------------------------------"
943	@echo ">>> stage 3.2: building everything"
944	@echo "--------------------------------------------------------------"
945	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
946	@echo "--------------------------------------------------------------"
947	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
948	@echo "--------------------------------------------------------------"
949.endfor
950
951#
952# installkernel, etc.
953#
954# Install the kernel defined by INSTALLKERNEL
955#
956installkernel installkernel.debug \
957reinstallkernel reinstallkernel.debug: installcheck
958.if empty(INSTALLKERNEL)
959	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
960	false
961.endif
962	@echo "--------------------------------------------------------------"
963	@echo ">>> Installing kernel ${INSTALLKERNEL}"
964	@echo "--------------------------------------------------------------"
965	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
966	    ${CROSSENV} PATH=${TMPPATH} \
967	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
968
969distributekernel distributekernel.debug:
970.if empty(INSTALLKERNEL)
971	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
972	false
973.endif
974	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
975	    ${CROSSENV} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
976	    DESTDIR=${DESTDIR}/${DISTDIR}/kernel \
977	    ${.TARGET:S/distributekernel/install/}
978.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
979	cd ${KRNLOBJDIR}/${_kernel}; \
980	    ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
981	    KERNEL=${INSTKERNNAME}.${_kernel} \
982	    DESTDIR=${DESTDIR}/${DISTDIR}/kernel.${_kernel} \
983	    ${.TARGET:S/distributekernel/install/}
984.endfor
985
986packagekernel:
987	cd ${DESTDIR}/${DISTDIR}/kernel; \
988	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz .
989.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
990	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
991	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz .
992.endfor
993
994#
995# doxygen
996#
997# Build the API documentation with doxygen
998#
999doxygen:
1000	@if [ ! -x `/usr/bin/which doxygen` ]; then \
1001		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1002		exit 1; \
1003	fi
1004	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
1005
1006#
1007# update
1008#
1009# Update the source tree(s), by running cvsup/cvs/svn to update to the
1010# latest copy.
1011#
1012update:
1013.if defined(SUP_UPDATE)
1014	@echo "--------------------------------------------------------------"
1015	@echo ">>> Running ${SUP}"
1016	@echo "--------------------------------------------------------------"
1017	@echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!"
1018	@echo "!! Update methods with ${SUP} are deprecated."
1019	@echo "!! Please see http://www.freebsd.org/handbook/svn.html"
1020	@echo "!! and convert your update method to SVN_UPDATE or"
1021	@echo "!! freebsd-update(8)."
1022	@echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!"
1023	@sleep 5
1024.if defined(SUPFILE)
1025	@${SUP} ${SUPFLAGS} ${SUPFILE}
1026.endif
1027.if defined(SUPFILE1)
1028	@${SUP} ${SUPFLAGS} ${SUPFILE1}
1029.endif
1030.if defined(SUPFILE2)
1031	@${SUP} ${SUPFLAGS} ${SUPFILE2}
1032.endif
1033.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
1034	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
1035.endif
1036.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
1037	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
1038.endif
1039.endif
1040.if defined(CVS_UPDATE)
1041	@cd ${.CURDIR} ; \
1042	if [ -d CVS ] ; then \
1043		echo "--------------------------------------------------------------" ; \
1044		echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT} ; \
1045		echo "--------------------------------------------------------------" ; \
1046		echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!" ; \
1047		echo "!! Update methods with CVS are deprecated." ; \
1048		echo "!! Please see http://www.freebsd.org/handbook/svn.html" ; \
1049		echo "!! and convert your update method to SVN_UPDATE or" ; \
1050		echo "!! freebsd-update(8)." ; \
1051		echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!" ; \
1052		sleep 5 ; \
1053		echo ${CVS} -R -q update ${CVSFLAGS} ; \
1054		${CVS} -R -q update ${CVSFLAGS} ; \
1055	fi
1056.endif
1057.if defined(SVN_UPDATE)
1058	@cd ${.CURDIR} ; \
1059	if [ -d .svn ] ; then \
1060		echo "--------------------------------------------------------------" ; \
1061		echo ">>> Updating ${.CURDIR} using Subversion" ; \
1062		echo "--------------------------------------------------------------" ; \
1063		echo ${SVN} update ${SVNFLAGS} ; \
1064		${SVN} update ${SVNFLAGS} ; \
1065	fi
1066.endif
1067
1068#
1069# ------------------------------------------------------------------------
1070#
1071# From here onwards are utility targets used by the 'make world' and
1072# related targets.  If your 'world' breaks, you may like to try to fix
1073# the problem and manually run the following targets to attempt to
1074# complete the build.  Beware, this is *not* guaranteed to work, you
1075# need to have a pretty good grip on the current state of the system
1076# to attempt to manually finish it.  If in doubt, 'make world' again.
1077#
1078
1079#
1080# legacy: Build compatibility shims for the next three targets
1081#
1082legacy:
1083.if ${BOOTSTRAPPING} < 700055 && ${BOOTSTRAPPING} != 0
1084	@echo "ERROR: Source upgrades from versions prior to 7.0 not supported."; \
1085	false
1086.endif
1087.for _tool in tools/build
1088	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
1089	    cd ${.CURDIR}/${_tool}; \
1090	    ${MAKE} DIRPRFX=${_tool}/ obj; \
1091	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
1092	    ${MAKE} DIRPRFX=${_tool}/ depend; \
1093	    ${MAKE} DIRPRFX=${_tool}/ all; \
1094	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1095.endfor
1096
1097#
1098# bootstrap-tools: Build tools needed for compatibility
1099#
1100.if ${MK_GAMES} != "no"
1101_strfile=	games/fortune/strfile
1102.endif
1103
1104.if ${MK_CXX} != "no"
1105_gperf=		gnu/usr.bin/gperf
1106.endif
1107
1108.if ${MK_GROFF} != "no"
1109_groff=		gnu/usr.bin/groff
1110.endif
1111
1112.if ${BOOTSTRAPPING} < 800022
1113_ar=		usr.bin/ar
1114.endif
1115
1116.if ${BOOTSTRAPPING} < 800013
1117_mklocale=	usr.bin/mklocale
1118.endif
1119
1120.if ${BOOTSTRAPPING} < 900002
1121_sed=		usr.bin/sed
1122.endif
1123
1124.if ${BOOTSTRAPPING} < 900006
1125_lex=		usr.bin/lex
1126.endif
1127
1128.if ${BOOTSTRAPPING} < 1000013
1129_yacc=		usr.bin/yacc
1130.endif
1131
1132.if ${BOOTSTRAPPING} < 1000026
1133_nmtree=	lib/libnetbsd \
1134		usr.sbin/nmtree
1135.else
1136_nmtree_itools=	nmtree
1137.endif
1138
1139.if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1140_awk=		usr.bin/awk
1141.endif
1142
1143.if ${MK_BSNMP} != "no" && !exists(/usr/sbin/gensnmptree)
1144_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
1145.endif
1146
1147.if ${MK_CLANG} != "no"
1148_clang_tblgen= \
1149	lib/clang/libllvmsupport \
1150	lib/clang/libllvmtablegen \
1151	usr.bin/clang/tblgen \
1152	usr.bin/clang/clang-tblgen
1153.endif
1154
1155# dtrace tools are required for older bootstrap env and cross-build
1156.if ${MK_CDDL} != "no" && \
1157    ((${BOOTSTRAPPING} < 800038 && \
1158          !(${BOOTSTRAPPING} >= 700112 && ${BOOTSTRAPPING} < 799999)) \
1159      || (${MACHINE} != ${TARGET} || ${MACHINE_ARCH} != ${TARGET_ARCH}))
1160_dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
1161    lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
1162.endif
1163
1164# Default to building the BSDL DTC, but build the GPL one if users explicitly
1165# request it.
1166_dtc= usr.bin/dtc
1167.if ${MK_GPL_DTC} != "no"
1168_dtc= gnu/usr.bin/dtc
1169.endif
1170
1171.if ${MK_KERBEROS} != "no"
1172_kerberos5_bootstrap_tools= \
1173	kerberos5/tools/make-roken \
1174	kerberos5/lib/libroken \
1175	kerberos5/lib/libvers \
1176	kerberos5/tools/asn1_compile \
1177	kerberos5/tools/slc
1178.endif
1179
1180#	Please document (add comment) why something is in 'bootstrap-tools'.
1181#	Try to bound the building of the bootstrap-tool to just the
1182#	FreeBSD versions that need the tool built at this stage of the build.
1183bootstrap-tools:
1184.for _tool in \
1185    ${_clang_tblgen} \
1186    ${_kerberos5_bootstrap_tools} \
1187    ${_dtrace_tools} \
1188    ${_strfile} \
1189    ${_gperf} \
1190    ${_groff} \
1191    ${_ar} \
1192    ${_dtc} \
1193    ${_awk} \
1194    usr.bin/lorder \
1195    usr.bin/makewhatis \
1196    ${_mklocale} \
1197    usr.bin/rpcgen \
1198    ${_sed} \
1199    ${_yacc} \
1200    ${_lex} \
1201    usr.bin/xinstall \
1202    ${_gensnmptree} \
1203    usr.sbin/config \
1204    ${_nmtree}
1205	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1206		cd ${.CURDIR}/${_tool}; \
1207		${MAKE} DIRPRFX=${_tool}/ obj; \
1208		${MAKE} DIRPRFX=${_tool}/ depend; \
1209		${MAKE} DIRPRFX=${_tool}/ all; \
1210		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1211.endfor
1212
1213#
1214# build-tools: Build special purpose build tools
1215#
1216.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
1217_aicasm= sys/modules/aic7xxx/aicasm
1218.endif
1219
1220.if !defined(NO_SHARE)
1221_share=	share/syscons/scrnmaps
1222.endif
1223
1224.if ${MK_GCC} != "no"
1225_gcc_tools= gnu/usr.bin/cc/cc_tools
1226.endif
1227
1228.if ${MK_RESCUE} != "no"
1229_rescue= rescue/rescue
1230.endif
1231
1232build-tools:
1233.for _tool in \
1234    bin/csh \
1235    bin/sh \
1236    ${_rescue} \
1237    ${LOCAL_TOOL_DIRS} \
1238    lib/ncurses/ncurses \
1239    lib/ncurses/ncursesw \
1240    ${_share} \
1241    ${_aicasm} \
1242    usr.bin/awk \
1243    lib/libmagic \
1244    usr.bin/mkesdb_static \
1245    usr.bin/mkcsmapper_static
1246	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1247		cd ${.CURDIR}/${_tool}; \
1248		${MAKE} DIRPRFX=${_tool}/ obj; \
1249		${MAKE} DIRPRFX=${_tool}/ build-tools
1250.endfor
1251.for _tool in \
1252    ${_gcc_tools}
1253	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1254		cd ${.CURDIR}/${_tool}; \
1255		${MAKE} DIRPRFX=${_tool}/ obj; \
1256		${MAKE} DIRPRFX=${_tool}/ depend; \
1257		${MAKE} DIRPRFX=${_tool}/ all
1258.endfor
1259
1260#
1261# cross-tools: Build cross-building tools
1262#
1263.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1264.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1265_btxld=		usr.sbin/btxld
1266.endif
1267.endif
1268.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1269.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1270_crunchide=	usr.sbin/crunch/crunchide
1271.endif
1272.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1273_kgzip=		usr.sbin/kgzip
1274.endif
1275.endif
1276
1277.if ${MK_BINUTILS} != "no"
1278_binutils=	gnu/usr.bin/binutils
1279.endif
1280
1281.if ${MK_CLANG} != "no" && (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang")
1282_clang=		usr.bin/clang
1283_clang_libs=	lib/clang
1284.endif
1285
1286.if ${MK_GCC} != "no" && (${MK_CLANG_IS_CC} == "no" || ${TARGET} == "pc98")
1287_cc=		gnu/usr.bin/cc
1288.endif
1289
1290cross-tools:
1291.for _tool in \
1292    ${_clang_libs} \
1293    ${_clang} \
1294    ${_binutils} \
1295    ${_cc} \
1296    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1297    ${_btxld} \
1298    ${_crunchide} \
1299    ${_kgzip}
1300	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1301		cd ${.CURDIR}/${_tool}; \
1302		${MAKE} DIRPRFX=${_tool}/ obj; \
1303		${MAKE} DIRPRFX=${_tool}/ depend; \
1304		${MAKE} DIRPRFX=${_tool}/ all; \
1305		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1306.endfor
1307
1308#
1309# hierarchy - ensure that all the needed directories are present
1310#
1311hierarchy hier:
1312.if defined(NO_ROOT)
1313	cd ${.CURDIR}/etc; ${MAKE} LOCAL_MTREE=${LOCAL_MTREE} \
1314	    -DNO_ROOT METALOG=${METALOG} distrib-dirs
1315.else
1316	cd ${.CURDIR}/etc; ${MAKE} LOCAL_MTREE=${LOCAL_MTREE} distrib-dirs
1317.endif
1318
1319#
1320# libraries - build all libraries, and install them under ${DESTDIR}.
1321#
1322# The list of libraries with dependents (${_prebuild_libs}) and their
1323# interdependencies (__L) are built automatically by the
1324# ${.CURDIR}/tools/make_libdeps.sh script.
1325#
1326libraries:
1327	cd ${.CURDIR}; \
1328	    ${MAKE} -f Makefile.inc1 _prereq_libs; \
1329	    ${MAKE} -f Makefile.inc1 _startup_libs; \
1330	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1331	    ${MAKE} -f Makefile.inc1 _generic_libs;
1332
1333#
1334# static libgcc.a prerequisite for shared libc
1335#
1336_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1337
1338# These dependencies are not automatically generated:
1339#
1340# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1341# all shared libraries for ELF.
1342#
1343_startup_libs=	gnu/lib/csu
1344.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1345_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1346.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1347_startup_libs+=	lib/csu/${MACHINE_ARCH}
1348.else
1349_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1350.endif
1351_startup_libs+=	gnu/lib/libgcc
1352_startup_libs+=	lib/libcompiler_rt
1353_startup_libs+=	lib/libc
1354.if ${MK_LIBCPLUSPLUS} != "no"
1355_startup_libs+=	lib/libcxxrt
1356.endif
1357
1358gnu/lib/libgcc__L: lib/libc__L
1359.if ${MK_LIBCPLUSPLUS} != "no"
1360lib/libcxxrt__L: gnu/lib/libgcc__L
1361.endif
1362
1363_prebuild_libs=	${_kerberos5_lib_libasn1} \
1364		${_kerberos5_lib_libhdb} \
1365		${_kerberos5_lib_libheimbase} \
1366		${_kerberos5_lib_libheimntlm} \
1367		${_kerberos5_lib_libheimsqlite} \
1368		${_kerberos5_lib_libheimipcc} \
1369		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1370		${_kerberos5_lib_libroken} \
1371		${_kerberos5_lib_libwind} \
1372		${_lib_atf_libatf_c} \
1373		lib/libbz2 ${_libcom_err} lib/libcrypt \
1374		lib/libexpat \
1375		${_lib_libgssapi} ${_lib_libipx} \
1376		lib/libkiconv lib/libkvm lib/liblzma lib/libmd \
1377		lib/ncurses/ncurses lib/ncurses/ncursesw \
1378		lib/libopie lib/libpam ${_lib_libthr} \
1379		lib/libradius lib/libsbuf lib/libtacplus \
1380		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1381		lib/libutil ${_lib_libypclnt} lib/libz lib/msun \
1382		${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1383		${_secure_lib_libssl}
1384
1385.if ${MK_ATF} != "no"
1386_lib_atf_libatf_c=	lib/atf/libatf-c
1387.endif
1388
1389.if ${MK_LIBTHR} != "no"
1390_lib_libthr=	lib/libthr
1391.endif
1392
1393.if ${MK_OFED} != "no"
1394_ofed_lib=	contrib/ofed/usr.lib/
1395.endif
1396
1397_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1398.for _DIR in ${LOCAL_LIB_DIRS}
1399.if exists(${.CURDIR}/${_DIR}/Makefile)
1400_generic_libs+= ${_DIR}
1401.endif
1402.endfor
1403
1404lib/libopie__L lib/libtacplus__L: lib/libmd__L
1405
1406.if ${MK_CDDL} != "no"
1407_cddl_lib_libumem= cddl/lib/libumem
1408_cddl_lib_libnvpair= cddl/lib/libnvpair
1409_cddl_lib= cddl/lib
1410.endif
1411
1412.if ${MK_CRYPT} != "no"
1413.if ${MK_OPENSSL} != "no"
1414_secure_lib_libcrypto= secure/lib/libcrypto
1415_secure_lib_libssl= secure/lib/libssl
1416lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1417.if ${MK_OPENSSH} != "no"
1418_secure_lib_libssh= secure/lib/libssh
1419secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1420.if ${MK_KERBEROS_SUPPORT} != "no"
1421secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1422    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1423    lib/libmd__L kerberos5/lib/libroken__L
1424.endif
1425.endif
1426.endif
1427_secure_lib=	secure/lib
1428.endif
1429
1430.if ${MK_KERBEROS} != "no"
1431kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1432kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1433    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1434    kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L 
1435kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1436    kerberos5/lib/libroken__L lib/libcom_err__L
1437kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1438    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1439kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1440    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1441    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1442    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1443kerberos5/lib/libroken__L: lib/libcrypt__L
1444kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1445kerberos5/lib/libheimbase__L: lib/libthr__L
1446kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1447kerberos5/lib/libheimsqlite__L: lib/libthr__L
1448.endif
1449
1450.if ${MK_GSSAPI} != "no"
1451_lib_libgssapi=	lib/libgssapi
1452.endif
1453
1454.if ${MK_IPX} != "no"
1455_lib_libipx=	lib/libipx
1456.endif
1457
1458.if ${MK_KERBEROS} != "no"
1459_kerberos5_lib=	kerberos5/lib
1460_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1461_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1462_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1463_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1464_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1465_kerberos5_lib_libroken= kerberos5/lib/libroken
1466_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1467_kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1468_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1469_kerberos5_lib_libwind= kerberos5/lib/libwind
1470_libcom_err= lib/libcom_err
1471.endif
1472
1473.if ${MK_NIS} != "no"
1474_lib_libypclnt=	lib/libypclnt
1475.endif
1476
1477.if ${MK_OPENSSL} == "no"
1478lib/libradius__L: lib/libmd__L
1479.endif
1480
1481.for _lib in ${_prereq_libs}
1482${_lib}__PL: .PHONY
1483.if exists(${.CURDIR}/${_lib})
1484	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1485		cd ${.CURDIR}/${_lib}; \
1486		${MAKE} DIRPRFX=${_lib}/ obj; \
1487		${MAKE} DIRPRFX=${_lib}/ depend; \
1488		${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \
1489		${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install
1490.endif
1491.endfor
1492
1493.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1494${_lib}__L: .PHONY
1495.if exists(${.CURDIR}/${_lib})
1496	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1497		cd ${.CURDIR}/${_lib}; \
1498		${MAKE} DIRPRFX=${_lib}/ obj; \
1499		${MAKE} DIRPRFX=${_lib}/ depend; \
1500		${MAKE} DIRPRFX=${_lib}/ all; \
1501		${MAKE} DIRPRFX=${_lib}/ install
1502.endif
1503.endfor
1504
1505# libpam is special: we need to build static PAM modules before
1506# static PAM library, and dynamic PAM library before dynamic PAM
1507# modules.
1508lib/libpam__L: .PHONY
1509	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1510		cd ${.CURDIR}/lib/libpam; \
1511		${MAKE} DIRPRFX=lib/libpam/ obj; \
1512		${MAKE} DIRPRFX=lib/libpam/ depend; \
1513		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1514		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1515
1516_prereq_libs: ${_prereq_libs:S/$/__PL/}
1517_startup_libs: ${_startup_libs:S/$/__L/}
1518_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1519_generic_libs: ${_generic_libs:S/$/__L/}
1520
1521.for __target in all clean cleandepend cleandir depend includes obj
1522.for entry in ${SUBDIR}
1523${entry}.${__target}__D: .PHONY
1524	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1525		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1526		edir=${entry}.${MACHINE_ARCH}; \
1527		cd ${.CURDIR}/$${edir}; \
1528	else \
1529		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1530		edir=${entry}; \
1531		cd ${.CURDIR}/$${edir}; \
1532	fi; \
1533	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1534.endfor
1535par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1536.endfor
1537
1538.include <bsd.subdir.mk>
1539
1540.if make(check-old) || make(check-old-dirs) || \
1541    make(check-old-files) || make(check-old-libs) || \
1542    make(delete-old) || make(delete-old-dirs) || \
1543    make(delete-old-files) || make(delete-old-libs)
1544
1545#
1546# check for / delete old files section
1547#
1548
1549.include "ObsoleteFiles.inc"
1550
1551OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1552else you can not start such an application. Consult UPDATING for more \
1553information regarding how to cope with the removal/revision bump of a \
1554specific library."
1555
1556.if !defined(BATCH_DELETE_OLD_FILES)
1557RM_I=-i
1558.else
1559RM_I=-v
1560.endif
1561
1562delete-old-files:
1563	@echo ">>> Removing old files (only deletes safe to delete libs)"
1564# Ask for every old file if the user really wants to remove it.
1565# It's annoying, but better safe than sorry.
1566# NB: We cannot pass the list of OLD_FILES as a parameter because the
1567# argument list will get too long. Using .for/.endfor make "loops" will make
1568# the Makefile parser segfault.
1569	@exec 3<&0; \
1570	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1571	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1572	while read file; do \
1573		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1574			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1575			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1576		fi; \
1577	done
1578# Remove catpages without corresponding manpages.
1579	@exec 3<&0; \
1580	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1581	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1582	while read catpage; do \
1583		read manpage; \
1584		if [ ! -e "$${manpage}" ]; then \
1585			rm ${RM_I} $${catpage} <&3; \
1586	        fi; \
1587	done
1588	@echo ">>> Old files removed"
1589
1590check-old-files:
1591	@echo ">>> Checking for old files"
1592	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1593	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1594	while read file; do \
1595		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1596		 	echo "${DESTDIR}/$${file}"; \
1597		fi; \
1598	done
1599# Check for catpages without corresponding manpages.
1600	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1601	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1602	while read catpage; do \
1603		read manpage; \
1604		if [ ! -e "$${manpage}" ]; then \
1605			echo $${catpage}; \
1606	        fi; \
1607	done
1608
1609delete-old-libs:
1610	@echo ">>> Removing old libraries"
1611	@echo "${OLD_LIBS_MESSAGE}" | fmt
1612	@exec 3<&0; \
1613	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1614	    -V OLD_LIBS | xargs -n1 | \
1615	while read file; do \
1616		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1617			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1618			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1619		fi; \
1620	done
1621	@echo ">>> Old libraries removed"
1622
1623check-old-libs:
1624	@echo ">>> Checking for old libraries"
1625	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1626	    -V OLD_LIBS | xargs -n1 | \
1627	while read file; do \
1628		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1629			echo "${DESTDIR}/$${file}"; \
1630		fi; \
1631	done
1632
1633delete-old-dirs:
1634	@echo ">>> Removing old directories"
1635	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1636	    -V OLD_DIRS | xargs -n1 | \
1637	while read dir; do \
1638		if [ -d "${DESTDIR}/$${dir}" ]; then \
1639			rmdir -v "${DESTDIR}/$${dir}" || true; \
1640		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1641			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1642		fi; \
1643	done
1644	@echo ">>> Old directories removed"
1645
1646check-old-dirs:
1647	@echo ">>> Checking for old directories"
1648	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1649	    -V OLD_DIRS | xargs -n1 | \
1650	while read dir; do \
1651		if [ -d "${DESTDIR}/$${dir}" ]; then \
1652			echo "${DESTDIR}/$${dir}"; \
1653		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1654			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1655		fi; \
1656	done
1657
1658delete-old: delete-old-files delete-old-dirs
1659	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1660
1661check-old: check-old-files check-old-libs check-old-dirs
1662	@echo "To remove old files and directories run '${MAKE} delete-old'."
1663	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1664
1665.endif
1666
1667#
1668# showconfig - show build configuration.
1669#
1670showconfig:
1671	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 2>&1 | grep ^MK_ | sort
1672
1673.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
1674DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
1675
1676.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
1677.if exists(${KERNCONFDIR}/${KERNCONF})
1678FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
1679	${KERNCONFDIR}/${KERNCONF} ; echo
1680.endif
1681.endif
1682
1683.endif
1684
1685.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
1686DTBOUTPUTPATH= ${.CURDIR}
1687.endif
1688
1689#
1690# Build 'standalone' Device Tree Blob
1691#
1692builddtb:
1693	@if [ "${FDT_DTS_FILE}" = "" ]; then \
1694		echo "ERROR: FDT_DTS_FILE must be specified!"; \
1695		exit 1; \
1696	fi;	\
1697	if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ]; then \
1698		echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \
1699			exist!"; \
1700		exit 1;	\
1701	fi;	\
1702	if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then	\
1703		echo "WARNING: DTB will be placed in the current working \
1704			directory"; \
1705	fi
1706	@PATH=${TMPPATH} \
1707	dtc -O dtb -o \
1708	    ${DTBOUTPUTPATH}/`echo ${FDT_DTS_FILE} | cut -d. -f1`.dtb -b 0 \
1709	    -p 1024 ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE}
1710
1711###############
1712
1713.if defined(XDEV) && defined(XDEV_ARCH)
1714
1715.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
1716XDEV_CPUTYPE?=${CPUTYPE}
1717.else
1718XDEV_CPUTYPE?=${TARGET_CPUTYPE}
1719.endif
1720
1721NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
1722	-DWITHOUT_MAN -DWITHOUT_NLS -DNO_PROFILE \
1723	-DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \
1724	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
1725	CPUTYPE=${XDEV_CPUTYPE}
1726
1727XDDIR=${XDEV_ARCH}-freebsd
1728XDTP=/usr/${XDDIR}
1729CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR}
1730CDENV= ${CDBENV} \
1731	_SHLIBDIRPREFIX=${XDTP} \
1732	TOOLS_PREFIX=${XDTP}
1733CD2ENV=${CDENV} \
1734	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1735
1736CDTMP=	${MAKEOBJDIRPREFIX}/${XDEV}/${.CURDIR}/tmp
1737CDMAKE=${CDENV} ${MAKE} ${NOFUN}
1738CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1739XDDESTDIR=${DESTDIR}${XDTP}
1740.if !defined(OSREL)
1741OSREL!= uname -r | sed -e 's/[-(].*//'
1742.endif
1743
1744.ORDER: xdev-build xdev-install
1745xdev: xdev-build xdev-install
1746
1747.ORDER: _xb-build-tools _xb-cross-tools
1748xdev-build: _xb-build-tools _xb-cross-tools
1749
1750_xb-build-tools:
1751	${_+_}@cd ${.CURDIR}; \
1752	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1753
1754_xb-cross-tools:
1755.for _tool in \
1756    gnu/usr.bin/binutils \
1757    gnu/usr.bin/cc \
1758    usr.bin/ar
1759	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1760	cd ${.CURDIR}/${_tool}; \
1761	${CDMAKE} DIRPRFX=${_tool}/ obj; \
1762	${CDMAKE} DIRPRFX=${_tool}/ depend; \
1763	${CDMAKE} DIRPRFX=${_tool}/ all
1764.endfor
1765
1766_xi-mtree:
1767	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1768	mkdir -p ${XDDESTDIR}
1769	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1770	    -p ${XDDESTDIR} >/dev/null
1771	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1772	    -p ${XDDESTDIR}/usr >/dev/null
1773	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1774	    -p ${XDDESTDIR}/usr/include >/dev/null
1775
1776.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1777xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1778
1779_xi-cross-tools:
1780	@echo "_xi-cross-tools"
1781.for _tool in \
1782    gnu/usr.bin/binutils \
1783    gnu/usr.bin/cc \
1784    usr.bin/ar
1785	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1786	cd ${.CURDIR}/${_tool}; \
1787	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1788.endfor
1789
1790_xi-includes:
1791	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1792		DESTDIR=${XDDESTDIR}
1793
1794_xi-libraries:
1795	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1796		DESTDIR=${XDDESTDIR}
1797
1798_xi-links:
1799	${_+_}cd ${XDDESTDIR}/usr/bin; \
1800		for i in *; do \
1801			ln -sf ../../${XDTP}/usr/bin/$$i \
1802			    ../../../../usr/bin/${XDDIR}-$$i; \
1803			ln -sf ../../${XDTP}/usr/bin/$$i \
1804			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1805		done
1806.else
1807xdev xdev-buil xdev-install:
1808	@echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target"
1809.endif
1810