Makefile.inc1 revision 246315
1#
2# $FreeBSD: head/Makefile.inc1 246315 2013-02-04 09:34:25Z andrew $
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} ${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
676ITOOLS=	[ awk cap_mkdb cat chflags chmod chown \
677	date echo egrep find grep id install ${_install-info} \
678	ln lockf make mkdir mtree ${_nmtree_itools} mv pwd_mkdb \
679	rm sed sh sysctl test true uname wc ${_zoneinfo}
680
681#
682# distributeworld
683#
684# Distributes everything compiled by a `buildworld'.
685#
686# installworld
687#
688# Installs everything compiled by a 'buildworld'.
689#
690
691# Non-base distributions produced by the base system
692EXTRA_DISTRIBUTIONS=	doc
693.if ${MK_GAMES} != "no"
694EXTRA_DISTRIBUTIONS+=	games
695.endif
696.if defined(LIB32TMP) && ${MK_LIB32} != "no"
697EXTRA_DISTRIBUTIONS+=	lib32
698.endif
699
700MTREE_MAGIC?=	mtree 2.0
701
702distributeworld installworld: installcheck
703	mkdir -p ${INSTALLTMP}
704	progs=$$(for prog in ${ITOOLS}; do \
705		if progpath=`which $$prog`; then \
706			echo $$progpath; \
707		else \
708			echo "Required tool $$prog not found in PATH." >&2; \
709			exit 1; \
710		fi; \
711	    done); \
712	libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
713	    while read line; do \
714		set -- $$line; \
715		if [ "$$2 $$3" != "not found" ]; then \
716			echo $$2; \
717		else \
718			echo "Required library $$1 not found." >&2; \
719			exit 1; \
720		fi; \
721	    done); \
722	cp $$libs $$progs ${INSTALLTMP}
723	cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
724.if defined(NO_ROOT)
725	echo "#${MTREE_MAGIC}" > ${METALOG}
726.endif
727.if make(distributeworld)
728.for dist in ${EXTRA_DISTRIBUTIONS}
729	-mkdir ${DESTDIR}/${DISTDIR}/${dist}
730	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
731	    -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
732	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
733	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
734	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
735	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
736.if defined(NO_ROOT)
737	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
738	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}
739	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
740	    sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
741	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
742	    sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
743.endif
744.endfor
745	-mkdir ${DESTDIR}/${DISTDIR}/base
746	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
747	    METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
748	    DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
749	    LOCAL_MTREE=${LOCAL_MTREE} distrib-dirs
750.endif
751	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
752	    ${IMAKEENV} rm -rf ${INSTALLTMP}
753.if make(distributeworld)
754.for dist in ${EXTRA_DISTRIBUTIONS}
755	find ${DESTDIR}/${DISTDIR}/${dist} -empty -delete
756.endfor
757.if defined(NO_ROOT)
758.for dist in base ${EXTRA_DISTRIBUTIONS}
759	@# For each file that exists in this dist, print the corresponding
760	@# line from the METALOG.  This relies on the fact that
761	@# a line containing only the filename will sort immediatly before
762	@# the relevant mtree line.
763	cd ${DESTDIR}/${DISTDIR}; \
764	find ./${dist} | sort -u ${METALOG} - | \
765	awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
766	${DESTDIR}/${DISTDIR}/${dist}.meta
767.endfor
768.endif
769.endif
770
771packageworld:
772.for dist in base ${EXTRA_DISTRIBUTIONS}
773.if defined(NO_ROOT)
774	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
775	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
776	    @${DESTDIR}/${DISTDIR}/${dist}.meta
777.else
778	${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
779	    tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz .
780.endif
781.endfor
782
783#
784# reinstall
785#
786# If you have a build server, you can NFS mount the source and obj directories
787# and do a 'make reinstall' on the *client* to install new binaries from the
788# most recent server build.
789#
790reinstall:
791	@echo "--------------------------------------------------------------"
792	@echo ">>> Making hierarchy"
793	@echo "--------------------------------------------------------------"
794	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
795	    LOCAL_MTREE=${LOCAL_MTREE} hierarchy
796	@echo
797	@echo "--------------------------------------------------------------"
798	@echo ">>> Installing everything"
799	@echo "--------------------------------------------------------------"
800	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
801.if defined(LIB32TMP) && ${MK_LIB32} != "no"
802	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
803.endif
804
805redistribute:
806	@echo "--------------------------------------------------------------"
807	@echo ">>> Distributing everything"
808	@echo "--------------------------------------------------------------"
809	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
810.if defined(LIB32TMP) && ${MK_LIB32} != "no"
811	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
812	    DISTRIBUTION=lib32
813.endif
814
815distrib-dirs distribution:
816	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
817	    ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
818
819#
820# buildkernel and installkernel
821#
822# Which kernels to build and/or install is specified by setting
823# KERNCONF. If not defined a GENERIC kernel is built/installed.
824# Only the existing (depending TARGET) config files are used
825# for building kernels and only the first of these is designated
826# as the one being installed.
827#
828# Note that we have to use TARGET instead of TARGET_ARCH when
829# we're in kernel-land. Since only TARGET_ARCH is (expected) to
830# be set to cross-build, we have to make sure TARGET is set
831# properly.
832
833.if defined(KERNFAST)
834NO_KERNELCLEAN=	t
835NO_KERNELCONFIG=	t
836NO_KERNELDEPEND=	t
837NO_KERNELOBJ=		t
838# Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
839.if !defined(KERNCONF) && ${KERNFAST} != "1"
840KERNCONF=${KERNFAST}
841.endif
842.endif
843.if !defined(KERNCONF) && defined(KERNEL)
844KERNCONF=	${KERNEL}
845KERNWARN=
846.else
847.if ${TARGET_ARCH} == "powerpc64"
848KERNCONF?=	GENERIC64
849.else
850KERNCONF?=	GENERIC
851.endif
852.endif
853INSTKERNNAME?=	kernel
854
855KERNSRCDIR?=	${.CURDIR}/sys
856KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
857KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
858KERNCONFDIR?=	${KRNLCONFDIR}
859
860BUILDKERNELS=
861INSTALLKERNEL=
862.for _kernel in ${KERNCONF}
863.if exists(${KERNCONFDIR}/${_kernel})
864BUILDKERNELS+=	${_kernel}
865.if empty(INSTALLKERNEL)
866INSTALLKERNEL= ${_kernel}
867.endif
868.endif
869.endfor
870
871#
872# buildkernel
873#
874# Builds all kernels defined by BUILDKERNELS.
875#
876buildkernel:
877.if empty(BUILDKERNELS)
878	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
879	false
880.endif
881.if defined(KERNWARN)
882	@echo "--------------------------------------------------------------"
883	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
884	@echo "--------------------------------------------------------------"
885	@sleep 3
886.endif
887	@echo
888.for _kernel in ${BUILDKERNELS}
889	@echo "--------------------------------------------------------------"
890	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
891	@echo "--------------------------------------------------------------"
892	@echo "===> ${_kernel}"
893	mkdir -p ${KRNLOBJDIR}
894.if !defined(NO_KERNELCONFIG)
895	@echo
896	@echo "--------------------------------------------------------------"
897	@echo ">>> stage 1: configuring the kernel"
898	@echo "--------------------------------------------------------------"
899	cd ${KRNLCONFDIR}; \
900		PATH=${TMPPATH} \
901		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
902			${KERNCONFDIR}/${_kernel}
903.endif
904.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
905	@echo
906	@echo "--------------------------------------------------------------"
907	@echo ">>> stage 2.1: cleaning up the object tree"
908	@echo "--------------------------------------------------------------"
909	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
910.endif
911.if !defined(NO_KERNELOBJ)
912	@echo
913	@echo "--------------------------------------------------------------"
914	@echo ">>> stage 2.2: rebuilding the object tree"
915	@echo "--------------------------------------------------------------"
916	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
917.endif
918	@echo
919	@echo "--------------------------------------------------------------"
920	@echo ">>> stage 2.3: build tools"
921	@echo "--------------------------------------------------------------"
922	cd ${KRNLOBJDIR}/${_kernel}; \
923	    PATH=${BPATH}:${PATH} \
924	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
925	    ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF -DEARLY_BUILD \
926	    -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
927# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
928.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
929.for target in obj depend all
930	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
931	    PATH=${BPATH}:${PATH} \
932	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
933	    ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF -DEARLY_BUILD ${target}
934.endfor
935.endif
936.if !defined(NO_KERNELDEPEND)
937	@echo
938	@echo "--------------------------------------------------------------"
939	@echo ">>> stage 3.1: making dependencies"
940	@echo "--------------------------------------------------------------"
941	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
942.endif
943	@echo
944	@echo "--------------------------------------------------------------"
945	@echo ">>> stage 3.2: building everything"
946	@echo "--------------------------------------------------------------"
947	cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
948	@echo "--------------------------------------------------------------"
949	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
950	@echo "--------------------------------------------------------------"
951.endfor
952
953#
954# installkernel, etc.
955#
956# Install the kernel defined by INSTALLKERNEL
957#
958installkernel installkernel.debug \
959reinstallkernel reinstallkernel.debug: installcheck
960.if empty(INSTALLKERNEL)
961	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
962	false
963.endif
964	@echo "--------------------------------------------------------------"
965	@echo ">>> Installing kernel ${INSTALLKERNEL}"
966	@echo "--------------------------------------------------------------"
967	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
968	    ${CROSSENV} PATH=${TMPPATH} \
969	    ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
970
971distributekernel distributekernel.debug:
972.if empty(INSTALLKERNEL)
973	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
974	false
975.endif
976	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
977	    ${CROSSENV} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
978	    DESTDIR=${DESTDIR}/${DISTDIR}/kernel \
979	    ${.TARGET:S/distributekernel/install/}
980.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
981	cd ${KRNLOBJDIR}/${_kernel}; \
982	    ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
983	    KERNEL=${INSTKERNNAME}.${_kernel} \
984	    DESTDIR=${DESTDIR}/${DISTDIR}/kernel.${_kernel} \
985	    ${.TARGET:S/distributekernel/install/}
986.endfor
987
988packagekernel:
989	cd ${DESTDIR}/${DISTDIR}/kernel; \
990	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz .
991.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
992	cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
993	    tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz .
994.endfor
995
996#
997# doxygen
998#
999# Build the API documentation with doxygen
1000#
1001doxygen:
1002	@if [ ! -x `/usr/bin/which doxygen` ]; then \
1003		echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1004		exit 1; \
1005	fi
1006	cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
1007
1008#
1009# update
1010#
1011# Update the source tree(s), by running cvsup/cvs/svn to update to the
1012# latest copy.
1013#
1014update:
1015.if defined(SUP_UPDATE)
1016	@echo "--------------------------------------------------------------"
1017	@echo ">>> Running ${SUP}"
1018	@echo "--------------------------------------------------------------"
1019	@echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!"
1020	@echo "!! Update methods with ${SUP} are deprecated."
1021	@echo "!! Please see http://www.freebsd.org/handbook/svn.html"
1022	@echo "!! and convert your update method to SVN_UPDATE or"
1023	@echo "!! freebsd-update(8)."
1024	@echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!"
1025	@sleep 5
1026.if defined(SUPFILE)
1027	@${SUP} ${SUPFLAGS} ${SUPFILE}
1028.endif
1029.if defined(SUPFILE1)
1030	@${SUP} ${SUPFLAGS} ${SUPFILE1}
1031.endif
1032.if defined(SUPFILE2)
1033	@${SUP} ${SUPFLAGS} ${SUPFILE2}
1034.endif
1035.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
1036	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
1037.endif
1038.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
1039	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
1040.endif
1041.endif
1042.if defined(CVS_UPDATE)
1043	@cd ${.CURDIR} ; \
1044	if [ -d CVS ] ; then \
1045		echo "--------------------------------------------------------------" ; \
1046		echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT} ; \
1047		echo "--------------------------------------------------------------" ; \
1048		echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!" ; \
1049		echo "!! Update methods with CVS are deprecated." ; \
1050		echo "!! Please see http://www.freebsd.org/handbook/svn.html" ; \
1051		echo "!! and convert your update method to SVN_UPDATE or" ; \
1052		echo "!! freebsd-update(8)." ; \
1053		echo "!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!" ; \
1054		sleep 5 ; \
1055		echo ${CVS} -R -q update ${CVSFLAGS} ; \
1056		${CVS} -R -q update ${CVSFLAGS} ; \
1057	fi
1058.endif
1059.if defined(SVN_UPDATE)
1060	@cd ${.CURDIR} ; \
1061	if [ -d .svn ] ; then \
1062		echo "--------------------------------------------------------------" ; \
1063		echo ">>> Updating ${.CURDIR} using Subversion" ; \
1064		echo "--------------------------------------------------------------" ; \
1065		echo ${SVN} update ${SVNFLAGS} ; \
1066		${SVN} update ${SVNFLAGS} ; \
1067	fi
1068.endif
1069
1070#
1071# ------------------------------------------------------------------------
1072#
1073# From here onwards are utility targets used by the 'make world' and
1074# related targets.  If your 'world' breaks, you may like to try to fix
1075# the problem and manually run the following targets to attempt to
1076# complete the build.  Beware, this is *not* guaranteed to work, you
1077# need to have a pretty good grip on the current state of the system
1078# to attempt to manually finish it.  If in doubt, 'make world' again.
1079#
1080
1081#
1082# legacy: Build compatibility shims for the next three targets
1083#
1084legacy:
1085.if ${BOOTSTRAPPING} < 700055 && ${BOOTSTRAPPING} != 0
1086	@echo "ERROR: Source upgrades from versions prior to 7.0 not supported."; \
1087	false
1088.endif
1089.for _tool in tools/build
1090	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
1091	    cd ${.CURDIR}/${_tool}; \
1092	    ${MAKE} DIRPRFX=${_tool}/ obj; \
1093	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
1094	    ${MAKE} DIRPRFX=${_tool}/ depend; \
1095	    ${MAKE} DIRPRFX=${_tool}/ all; \
1096	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1097.endfor
1098
1099#
1100# bootstrap-tools: Build tools needed for compatibility
1101#
1102.if ${MK_GAMES} != "no"
1103_strfile=	games/fortune/strfile
1104.endif
1105
1106.if ${MK_CXX} != "no"
1107_gperf=		gnu/usr.bin/gperf
1108.endif
1109
1110.if ${MK_GROFF} != "no"
1111_groff=		gnu/usr.bin/groff
1112.endif
1113
1114.if ${BOOTSTRAPPING} < 800022
1115_ar=		usr.bin/ar
1116.endif
1117
1118.if ${BOOTSTRAPPING} < 800013
1119_mklocale=	usr.bin/mklocale
1120.endif
1121
1122.if ${BOOTSTRAPPING} < 900002
1123_sed=		usr.bin/sed
1124.endif
1125
1126.if ${BOOTSTRAPPING} < 900006
1127_lex=		usr.bin/lex
1128.endif
1129
1130.if ${BOOTSTRAPPING} < 1000013
1131_yacc=		usr.bin/yacc
1132.endif
1133
1134.if ${BOOTSTRAPPING} < 1000026
1135_nmtree=	lib/libnetbsd \
1136		usr.sbin/nmtree
1137.else
1138_nmtree_itools=	nmtree
1139.endif
1140
1141.if ${BOOTSTRAPPING} < 1000027
1142_cat=		bin/cat
1143.endif
1144
1145.if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1146_awk=		usr.bin/awk
1147.endif
1148
1149.if ${MK_BSNMP} != "no" && !exists(/usr/sbin/gensnmptree)
1150_gensnmptree=	usr.sbin/bsnmpd/gensnmptree
1151.endif
1152
1153.if ${MK_CLANG} != "no"
1154_clang_tblgen= \
1155	lib/clang/libllvmsupport \
1156	lib/clang/libllvmtablegen \
1157	usr.bin/clang/tblgen \
1158	usr.bin/clang/clang-tblgen
1159.endif
1160
1161# dtrace tools are required for older bootstrap env and cross-build
1162.if ${MK_CDDL} != "no" && \
1163    ((${BOOTSTRAPPING} < 800038 && \
1164          !(${BOOTSTRAPPING} >= 700112 && ${BOOTSTRAPPING} < 799999)) \
1165      || (${MACHINE} != ${TARGET} || ${MACHINE_ARCH} != ${TARGET_ARCH}))
1166_dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
1167    lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
1168.endif
1169
1170# Default to building the BSDL DTC, but build the GPL one if users explicitly
1171# request it.
1172_dtc= usr.bin/dtc
1173.if ${MK_GPL_DTC} != "no"
1174_dtc= gnu/usr.bin/dtc
1175.endif
1176
1177.if ${MK_KERBEROS} != "no"
1178_kerberos5_bootstrap_tools= \
1179	kerberos5/tools/make-roken \
1180	kerberos5/lib/libroken \
1181	kerberos5/lib/libvers \
1182	kerberos5/tools/asn1_compile \
1183	kerberos5/tools/slc
1184.endif
1185
1186#	Please document (add comment) why something is in 'bootstrap-tools'.
1187#	Try to bound the building of the bootstrap-tool to just the
1188#	FreeBSD versions that need the tool built at this stage of the build.
1189bootstrap-tools:
1190.for _tool in \
1191    ${_clang_tblgen} \
1192    ${_kerberos5_bootstrap_tools} \
1193    ${_dtrace_tools} \
1194    ${_strfile} \
1195    ${_gperf} \
1196    ${_groff} \
1197    ${_ar} \
1198    ${_dtc} \
1199    ${_awk} \
1200    ${_cat} \
1201    usr.bin/lorder \
1202    usr.bin/makewhatis \
1203    ${_mklocale} \
1204    usr.bin/rpcgen \
1205    ${_sed} \
1206    ${_yacc} \
1207    ${_lex} \
1208    usr.bin/xinstall \
1209    ${_gensnmptree} \
1210    usr.sbin/config \
1211    ${_nmtree}
1212	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1213		cd ${.CURDIR}/${_tool}; \
1214		${MAKE} DIRPRFX=${_tool}/ obj; \
1215		${MAKE} DIRPRFX=${_tool}/ depend; \
1216		${MAKE} DIRPRFX=${_tool}/ all; \
1217		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1218.endfor
1219
1220#
1221# build-tools: Build special purpose build tools
1222#
1223.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
1224_aicasm= sys/modules/aic7xxx/aicasm
1225.endif
1226
1227.if !defined(NO_SHARE)
1228_share=	share/syscons/scrnmaps
1229.endif
1230
1231.if ${MK_GCC} != "no"
1232_gcc_tools= gnu/usr.bin/cc/cc_tools
1233.endif
1234
1235.if ${MK_RESCUE} != "no"
1236_rescue= rescue/rescue
1237.endif
1238
1239build-tools:
1240.for _tool in \
1241    bin/csh \
1242    bin/sh \
1243    ${_rescue} \
1244    ${LOCAL_TOOL_DIRS} \
1245    lib/ncurses/ncurses \
1246    lib/ncurses/ncursesw \
1247    ${_share} \
1248    ${_aicasm} \
1249    usr.bin/awk \
1250    lib/libmagic \
1251    usr.bin/mkesdb_static \
1252    usr.bin/mkcsmapper_static
1253	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1254		cd ${.CURDIR}/${_tool}; \
1255		${MAKE} DIRPRFX=${_tool}/ obj; \
1256		${MAKE} DIRPRFX=${_tool}/ build-tools
1257.endfor
1258.for _tool in \
1259    ${_gcc_tools}
1260	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1261		cd ${.CURDIR}/${_tool}; \
1262		${MAKE} DIRPRFX=${_tool}/ obj; \
1263		${MAKE} DIRPRFX=${_tool}/ depend; \
1264		${MAKE} DIRPRFX=${_tool}/ all
1265.endfor
1266
1267#
1268# cross-tools: Build cross-building tools
1269#
1270.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1271.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1272_btxld=		usr.sbin/btxld
1273.endif
1274.endif
1275.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1276.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1277_crunchide=	usr.sbin/crunch/crunchide
1278.endif
1279.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1280_kgzip=		usr.sbin/kgzip
1281.endif
1282.endif
1283
1284.if ${MK_BINUTILS} != "no"
1285_binutils=	gnu/usr.bin/binutils
1286.endif
1287
1288.if ${MK_CLANG} != "no" && (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang")
1289_clang=		usr.bin/clang
1290_clang_libs=	lib/clang
1291.endif
1292
1293.if ${MK_GCC} != "no" && (${MK_CLANG_IS_CC} == "no" || ${TARGET} == "pc98")
1294_cc=		gnu/usr.bin/cc
1295.endif
1296
1297cross-tools:
1298.for _tool in \
1299    ${_clang_libs} \
1300    ${_clang} \
1301    ${_binutils} \
1302    ${_cc} \
1303    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1304    ${_btxld} \
1305    ${_crunchide} \
1306    ${_kgzip}
1307	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1308		cd ${.CURDIR}/${_tool}; \
1309		${MAKE} DIRPRFX=${_tool}/ obj; \
1310		${MAKE} DIRPRFX=${_tool}/ depend; \
1311		${MAKE} DIRPRFX=${_tool}/ all; \
1312		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1313.endfor
1314
1315#
1316# hierarchy - ensure that all the needed directories are present
1317#
1318hierarchy hier:
1319.if defined(NO_ROOT)
1320	cd ${.CURDIR}/etc; ${MAKE} LOCAL_MTREE=${LOCAL_MTREE} \
1321	    -DNO_ROOT METALOG=${METALOG} distrib-dirs
1322.else
1323	cd ${.CURDIR}/etc; ${MAKE} LOCAL_MTREE=${LOCAL_MTREE} distrib-dirs
1324.endif
1325
1326#
1327# libraries - build all libraries, and install them under ${DESTDIR}.
1328#
1329# The list of libraries with dependents (${_prebuild_libs}) and their
1330# interdependencies (__L) are built automatically by the
1331# ${.CURDIR}/tools/make_libdeps.sh script.
1332#
1333libraries:
1334	cd ${.CURDIR}; \
1335	    ${MAKE} -f Makefile.inc1 _prereq_libs; \
1336	    ${MAKE} -f Makefile.inc1 _startup_libs; \
1337	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1338	    ${MAKE} -f Makefile.inc1 _generic_libs;
1339
1340#
1341# static libgcc.a prerequisite for shared libc
1342#
1343_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1344
1345# These dependencies are not automatically generated:
1346#
1347# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1348# all shared libraries for ELF.
1349#
1350_startup_libs=	gnu/lib/csu
1351.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1352_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1353.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1354_startup_libs+=	lib/csu/${MACHINE_ARCH}
1355.else
1356_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1357.endif
1358_startup_libs+=	gnu/lib/libgcc
1359_startup_libs+=	lib/libcompiler_rt
1360_startup_libs+=	lib/libc
1361.if ${MK_LIBCPLUSPLUS} != "no"
1362_startup_libs+=	lib/libcxxrt
1363.endif
1364
1365gnu/lib/libgcc__L: lib/libc__L
1366.if ${MK_LIBCPLUSPLUS} != "no"
1367lib/libcxxrt__L: gnu/lib/libgcc__L
1368.endif
1369
1370_prebuild_libs=	${_kerberos5_lib_libasn1} \
1371		${_kerberos5_lib_libhdb} \
1372		${_kerberos5_lib_libheimbase} \
1373		${_kerberos5_lib_libheimntlm} \
1374		${_kerberos5_lib_libheimsqlite} \
1375		${_kerberos5_lib_libheimipcc} \
1376		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1377		${_kerberos5_lib_libroken} \
1378		${_kerberos5_lib_libwind} \
1379		${_lib_atf_libatf_c} \
1380		lib/libbz2 ${_libcom_err} lib/libcrypt \
1381		lib/libexpat \
1382		${_lib_libgssapi} ${_lib_libipx} \
1383		lib/libkiconv lib/libkvm lib/liblzma lib/libmd \
1384		lib/ncurses/ncurses lib/ncurses/ncursesw \
1385		lib/libopie lib/libpam ${_lib_libthr} \
1386		lib/libradius lib/libsbuf lib/libtacplus \
1387		${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1388		lib/libutil ${_lib_libypclnt} lib/libz lib/msun \
1389		${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1390		${_secure_lib_libssl}
1391
1392.if ${MK_ATF} != "no"
1393_lib_atf_libatf_c=	lib/atf/libatf-c
1394.endif
1395
1396.if ${MK_LIBTHR} != "no"
1397_lib_libthr=	lib/libthr
1398.endif
1399
1400.if ${MK_OFED} != "no"
1401_ofed_lib=	contrib/ofed/usr.lib/
1402.endif
1403
1404_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1405.for _DIR in ${LOCAL_LIB_DIRS}
1406.if exists(${.CURDIR}/${_DIR}/Makefile)
1407_generic_libs+= ${_DIR}
1408.endif
1409.endfor
1410
1411lib/libopie__L lib/libtacplus__L: lib/libmd__L
1412
1413.if ${MK_CDDL} != "no"
1414_cddl_lib_libumem= cddl/lib/libumem
1415_cddl_lib_libnvpair= cddl/lib/libnvpair
1416_cddl_lib= cddl/lib
1417.endif
1418
1419.if ${MK_CRYPT} != "no"
1420.if ${MK_OPENSSL} != "no"
1421_secure_lib_libcrypto= secure/lib/libcrypto
1422_secure_lib_libssl= secure/lib/libssl
1423lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1424.if ${MK_OPENSSH} != "no"
1425_secure_lib_libssh= secure/lib/libssh
1426secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1427.if ${MK_KERBEROS_SUPPORT} != "no"
1428secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1429    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1430    lib/libmd__L kerberos5/lib/libroken__L
1431.endif
1432.endif
1433.endif
1434_secure_lib=	secure/lib
1435.endif
1436
1437.if ${MK_KERBEROS} != "no"
1438kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1439kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1440    kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1441    kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L 
1442kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1443    kerberos5/lib/libroken__L lib/libcom_err__L
1444kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1445    secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1446kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1447    lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1448    kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1449    kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1450kerberos5/lib/libroken__L: lib/libcrypt__L
1451kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1452kerberos5/lib/libheimbase__L: lib/libthr__L
1453kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1454kerberos5/lib/libheimsqlite__L: lib/libthr__L
1455.endif
1456
1457.if ${MK_GSSAPI} != "no"
1458_lib_libgssapi=	lib/libgssapi
1459.endif
1460
1461.if ${MK_IPX} != "no"
1462_lib_libipx=	lib/libipx
1463.endif
1464
1465.if ${MK_KERBEROS} != "no"
1466_kerberos5_lib=	kerberos5/lib
1467_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1468_kerberos5_lib_libhdb= kerberos5/lib/libhdb
1469_kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1470_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1471_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1472_kerberos5_lib_libroken= kerberos5/lib/libroken
1473_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1474_kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1475_kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1476_kerberos5_lib_libwind= kerberos5/lib/libwind
1477_libcom_err= lib/libcom_err
1478.endif
1479
1480.if ${MK_NIS} != "no"
1481_lib_libypclnt=	lib/libypclnt
1482.endif
1483
1484.if ${MK_OPENSSL} == "no"
1485lib/libradius__L: lib/libmd__L
1486.endif
1487
1488.for _lib in ${_prereq_libs}
1489${_lib}__PL: .PHONY
1490.if exists(${.CURDIR}/${_lib})
1491	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1492		cd ${.CURDIR}/${_lib}; \
1493		${MAKE} DIRPRFX=${_lib}/ obj; \
1494		${MAKE} DIRPRFX=${_lib}/ depend; \
1495		${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \
1496		${MAKE} -DNO_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install
1497.endif
1498.endfor
1499
1500.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1501${_lib}__L: .PHONY
1502.if exists(${.CURDIR}/${_lib})
1503	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1504		cd ${.CURDIR}/${_lib}; \
1505		${MAKE} DIRPRFX=${_lib}/ obj; \
1506		${MAKE} DIRPRFX=${_lib}/ depend; \
1507		${MAKE} DIRPRFX=${_lib}/ all; \
1508		${MAKE} DIRPRFX=${_lib}/ install
1509.endif
1510.endfor
1511
1512# libpam is special: we need to build static PAM modules before
1513# static PAM library, and dynamic PAM library before dynamic PAM
1514# modules.
1515lib/libpam__L: .PHONY
1516	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1517		cd ${.CURDIR}/lib/libpam; \
1518		${MAKE} DIRPRFX=lib/libpam/ obj; \
1519		${MAKE} DIRPRFX=lib/libpam/ depend; \
1520		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1521		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1522
1523_prereq_libs: ${_prereq_libs:S/$/__PL/}
1524_startup_libs: ${_startup_libs:S/$/__L/}
1525_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1526_generic_libs: ${_generic_libs:S/$/__L/}
1527
1528.for __target in all clean cleandepend cleandir depend includes obj
1529.for entry in ${SUBDIR}
1530${entry}.${__target}__D: .PHONY
1531	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1532		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1533		edir=${entry}.${MACHINE_ARCH}; \
1534		cd ${.CURDIR}/$${edir}; \
1535	else \
1536		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1537		edir=${entry}; \
1538		cd ${.CURDIR}/$${edir}; \
1539	fi; \
1540	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1541.endfor
1542par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1543.endfor
1544
1545.include <bsd.subdir.mk>
1546
1547.if make(check-old) || make(check-old-dirs) || \
1548    make(check-old-files) || make(check-old-libs) || \
1549    make(delete-old) || make(delete-old-dirs) || \
1550    make(delete-old-files) || make(delete-old-libs)
1551
1552#
1553# check for / delete old files section
1554#
1555
1556.include "ObsoleteFiles.inc"
1557
1558OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1559else you can not start such an application. Consult UPDATING for more \
1560information regarding how to cope with the removal/revision bump of a \
1561specific library."
1562
1563.if !defined(BATCH_DELETE_OLD_FILES)
1564RM_I=-i
1565.else
1566RM_I=-v
1567.endif
1568
1569delete-old-files:
1570	@echo ">>> Removing old files (only deletes safe to delete libs)"
1571# Ask for every old file if the user really wants to remove it.
1572# It's annoying, but better safe than sorry.
1573# NB: We cannot pass the list of OLD_FILES as a parameter because the
1574# argument list will get too long. Using .for/.endfor make "loops" will make
1575# the Makefile parser segfault.
1576	@exec 3<&0; \
1577	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1578	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1579	while read file; do \
1580		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1581			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1582			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1583		fi; \
1584	done
1585# Remove catpages without corresponding manpages.
1586	@exec 3<&0; \
1587	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1588	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1589	while read catpage; do \
1590		read manpage; \
1591		if [ ! -e "$${manpage}" ]; then \
1592			rm ${RM_I} $${catpage} <&3; \
1593	        fi; \
1594	done
1595	@echo ">>> Old files removed"
1596
1597check-old-files:
1598	@echo ">>> Checking for old files"
1599	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1600	    -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1601	while read file; do \
1602		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1603		 	echo "${DESTDIR}/$${file}"; \
1604		fi; \
1605	done
1606# Check for catpages without corresponding manpages.
1607	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1608	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1609	while read catpage; do \
1610		read manpage; \
1611		if [ ! -e "$${manpage}" ]; then \
1612			echo $${catpage}; \
1613	        fi; \
1614	done
1615
1616delete-old-libs:
1617	@echo ">>> Removing old libraries"
1618	@echo "${OLD_LIBS_MESSAGE}" | fmt
1619	@exec 3<&0; \
1620	${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1621	    -V OLD_LIBS | xargs -n1 | \
1622	while read file; do \
1623		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1624			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1625			rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1626		fi; \
1627	done
1628	@echo ">>> Old libraries removed"
1629
1630check-old-libs:
1631	@echo ">>> Checking for old libraries"
1632	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1633	    -V OLD_LIBS | xargs -n1 | \
1634	while read file; do \
1635		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1636			echo "${DESTDIR}/$${file}"; \
1637		fi; \
1638	done
1639
1640delete-old-dirs:
1641	@echo ">>> Removing old directories"
1642	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1643	    -V OLD_DIRS | xargs -n1 | \
1644	while read dir; do \
1645		if [ -d "${DESTDIR}/$${dir}" ]; then \
1646			rmdir -v "${DESTDIR}/$${dir}" || true; \
1647		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1648			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1649		fi; \
1650	done
1651	@echo ">>> Old directories removed"
1652
1653check-old-dirs:
1654	@echo ">>> Checking for old directories"
1655	@${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1656	    -V OLD_DIRS | xargs -n1 | \
1657	while read dir; do \
1658		if [ -d "${DESTDIR}/$${dir}" ]; then \
1659			echo "${DESTDIR}/$${dir}"; \
1660		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1661			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1662		fi; \
1663	done
1664
1665delete-old: delete-old-files delete-old-dirs
1666	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1667
1668check-old: check-old-files check-old-libs check-old-dirs
1669	@echo "To remove old files and directories run '${MAKE} delete-old'."
1670	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1671
1672.endif
1673
1674#
1675# showconfig - show build configuration.
1676#
1677showconfig:
1678	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 2>&1 | grep ^MK_ | sort
1679
1680.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
1681DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
1682
1683.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
1684.if exists(${KERNCONFDIR}/${KERNCONF})
1685FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
1686	${KERNCONFDIR}/${KERNCONF} ; echo
1687.endif
1688.endif
1689
1690.endif
1691
1692.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
1693DTBOUTPUTPATH= ${.CURDIR}
1694.endif
1695
1696#
1697# Build 'standalone' Device Tree Blob
1698#
1699builddtb:
1700	@if [ "${FDT_DTS_FILE}" = "" ]; then \
1701		echo "ERROR: FDT_DTS_FILE must be specified!"; \
1702		exit 1; \
1703	fi;	\
1704	if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ]; then \
1705		echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \
1706			exist!"; \
1707		exit 1;	\
1708	fi;	\
1709	if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then	\
1710		echo "WARNING: DTB will be placed in the current working \
1711			directory"; \
1712	fi
1713	@PATH=${TMPPATH} \
1714	dtc -O dtb -o \
1715	    ${DTBOUTPUTPATH}/`echo ${FDT_DTS_FILE} | cut -d. -f1`.dtb -b 0 \
1716	    -p 1024 ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE}
1717
1718###############
1719
1720.if defined(XDEV) && defined(XDEV_ARCH)
1721
1722.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
1723XDEV_CPUTYPE?=${CPUTYPE}
1724.else
1725XDEV_CPUTYPE?=${TARGET_CPUTYPE}
1726.endif
1727
1728NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
1729	-DWITHOUT_MAN -DWITHOUT_NLS -DNO_PROFILE \
1730	-DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \
1731	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
1732	CPUTYPE=${XDEV_CPUTYPE}
1733
1734XDDIR=${XDEV_ARCH}-freebsd
1735XDTP=/usr/${XDDIR}
1736CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
1737	INSTALL="sh ${.CURDIR}/tools/install.sh"
1738CDENV= ${CDBENV} \
1739	_SHLIBDIRPREFIX=${XDTP} \
1740	TOOLS_PREFIX=${XDTP}
1741CD2ENV=${CDENV} \
1742	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1743
1744CDTMP=	${MAKEOBJDIRPREFIX}/${XDEV}/${.CURDIR}/tmp
1745CDMAKE=${CDENV} ${MAKE} ${NOFUN}
1746CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1747XDDESTDIR=${DESTDIR}${XDTP}
1748.if !defined(OSREL)
1749OSREL!= uname -r | sed -e 's/[-(].*//'
1750.endif
1751
1752.ORDER: xdev-build xdev-install
1753xdev: xdev-build xdev-install
1754
1755.ORDER: _xb-build-tools _xb-cross-tools
1756xdev-build: _xb-build-tools _xb-cross-tools
1757
1758_xb-build-tools:
1759	${_+_}@cd ${.CURDIR}; \
1760	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1761
1762_xb-cross-tools:
1763.for _tool in \
1764    gnu/usr.bin/binutils \
1765    gnu/usr.bin/cc \
1766    usr.bin/ar
1767	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1768	cd ${.CURDIR}/${_tool}; \
1769	${CDMAKE} DIRPRFX=${_tool}/ obj; \
1770	${CDMAKE} DIRPRFX=${_tool}/ depend; \
1771	${CDMAKE} DIRPRFX=${_tool}/ all
1772.endfor
1773
1774_xi-mtree:
1775	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1776	mkdir -p ${XDDESTDIR}
1777	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1778	    -p ${XDDESTDIR} >/dev/null
1779	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1780	    -p ${XDDESTDIR}/usr >/dev/null
1781	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1782	    -p ${XDDESTDIR}/usr/include >/dev/null
1783
1784.ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1785xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1786
1787_xi-cross-tools:
1788	@echo "_xi-cross-tools"
1789.for _tool in \
1790    gnu/usr.bin/binutils \
1791    gnu/usr.bin/cc \
1792    usr.bin/ar
1793	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1794	cd ${.CURDIR}/${_tool}; \
1795	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1796.endfor
1797
1798_xi-includes:
1799	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1800		DESTDIR=${XDDESTDIR}
1801
1802_xi-libraries:
1803	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1804		DESTDIR=${XDDESTDIR}
1805
1806_xi-links:
1807	${_+_}cd ${XDDESTDIR}/usr/bin; \
1808		for i in *; do \
1809			ln -sf ../../${XDTP}/usr/bin/$$i \
1810			    ../../../../usr/bin/${XDDIR}-$$i; \
1811			ln -sf ../../${XDTP}/usr/bin/$$i \
1812			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1813		done
1814.else
1815xdev xdev-buil xdev-install:
1816	@echo "*** Error: Both XDEV and XDEV_ARCH must be defined for \"${.TARGET}\" target"
1817.endif
1818