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