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