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