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