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