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