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