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