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