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