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