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