Makefile.inc1 revision 218934
1#
2# $FreeBSD: head/Makefile.inc1 218934 2011-02-22 04:07:15Z 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# You are supposed to define both of these when calling Makefile.inc1
32# directly.  However, some old scripts don't.  Cope for the moment, but
33# issue a new warning for a transition period.
34.if defined(TARGET) && !defined(TARGET_ARCH)
35.warning "You must pass both TARGET and TARGET_ARCH to Makefile.inc1.  Setting TARGET_ARCH=${TARGET}."
36TARGET_ARCH=${TARGET}
37.endif
38.if !defined(TARGET) || !defined(TARGET_ARCH)
39.error "Both TARGET and TARGET_ARCH must be defined."
40.endif
41
42.include <bsd.own.mk>
43.include <bsd.arch.inc.mk>
44
45# Clang is a special case.  We have to use it to bootstrap the target, not
46# where we're building from.
47.if ${TARGET_ARCH} == i386 || ${TARGET_ARCH} == amd64 || \
48    ${TARGET_ARCH} == arm || ${TARGET_ARCH} == powerpc64 || \
49    ${TARGET_ARCH} == powerpc
50.if !defined(WITHOUT_CLANG)
51MK_CLANG=yes
52.endif
53.else
54.if !defined(WITH_CLANG)
55MK_CLANG=no
56.endif
57.endif
58
59# We must do share/info early so that installation of info `dir'
60# entries works correctly.  Do it first since it is less likely to
61# grow dependencies on include and lib than vice versa.
62#
63# We must do lib/ and libexec/ before bin/, because if installworld
64# installs a new /bin/sh, the 'make' command will *immediately*
65# use that new version.  And the new (dynamically-linked) /bin/sh
66# will expect to find appropriate libraries in /lib and /libexec.
67#
68SUBDIR=	share/info lib libexec
69SUBDIR+=bin
70.if ${MK_GAMES} != "no"
71SUBDIR+=games
72.endif
73.if ${MK_CDDL} != "no"
74SUBDIR+=cddl
75.else
76NO_CTF=1
77.endif
78SUBDIR+=gnu include
79.if ${MK_KERBEROS} != "no"
80SUBDIR+=kerberos5
81.endif
82.if ${MK_RESCUE} != "no"
83SUBDIR+=rescue
84.endif
85SUBDIR+=sbin
86.if ${MK_CRYPT} != "no"
87SUBDIR+=secure
88.endif
89.if !defined(NO_SHARE)
90SUBDIR+=share
91.endif
92SUBDIR+=sys usr.bin usr.sbin
93#
94# We must do etc/ last for install/distribute to work.
95#
96SUBDIR+=etc
97
98# These are last, since it is nice to at least get the base system
99# rebuilt before you do them.
100.for _DIR in ${LOCAL_DIRS}
101.if exists(${.CURDIR}/${_DIR}/Makefile)
102SUBDIR+= ${_DIR}
103.endif
104.endfor
105
106.if defined(SUBDIR_OVERRIDE)
107SUBDIR=		${SUBDIR_OVERRIDE}
108.endif
109
110.if defined(NOCLEAN)
111NO_CLEAN=	${NOCLEAN}
112.endif
113.if defined(NO_CLEANDIR)
114CLEANDIR=	clean cleandepend
115.else
116CLEANDIR=	cleandir
117.endif
118
119CVS?=		cvs
120CVSFLAGS?=	-A -P -d -I!
121SVN?=		svn
122SVNFLAGS?=	-r HEAD
123SUP?=		/usr/bin/csup
124SUPFLAGS?=	-g -L 2
125.if defined(SUPHOST)
126SUPFLAGS+=	-h ${SUPHOST}
127.endif
128
129MAKEOBJDIRPREFIX?=	/usr/obj
130.if !defined(OSRELDATE)
131.if exists(/usr/include/osreldate.h)
132OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
133		/usr/include/osreldate.h
134.else
135OSRELDATE=	0
136.endif
137.endif
138
139.if !defined(VERSION)
140VERSION!=	uname -srp
141VERSION+=	${OSRELDATE}
142.endif
143
144KNOWN_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
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 -DNO_LINT 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.if ${MK_CLANG} != "no"
988_clang_tblgen= \
989	lib/clang/libllvmsupport \
990	usr.bin/clang/tblgen
991.endif
992
993.if ${MK_CDDL} != "no"
994_dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
995    lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
996.endif
997
998.if ${MK_FDT} != "no"
999_dtc= gnu/usr.bin/dtc
1000.endif
1001
1002bootstrap-tools:
1003.for _tool in \
1004    ${_clang_tblgen} \
1005    ${_dtrace_tools} \
1006    ${_strfile} \
1007    ${_gperf} \
1008    ${_groff} \
1009    ${_ar} \
1010    ${_dtc} \
1011    usr.bin/lorder \
1012    usr.bin/makewhatis \
1013    ${_mklocale} \
1014    usr.bin/rpcgen \
1015    ${_sed} \
1016    ${_lex} \
1017    ${_yacc} \
1018    usr.bin/xinstall \
1019    ${_gensnmptree} \
1020    usr.sbin/config \
1021    ${_crunchgen}
1022	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1023		cd ${.CURDIR}/${_tool}; \
1024		${MAKE} DIRPRFX=${_tool}/ obj; \
1025		${MAKE} DIRPRFX=${_tool}/ depend; \
1026		${MAKE} DIRPRFX=${_tool}/ all; \
1027		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1028.endfor
1029
1030#
1031# build-tools: Build special purpose build tools
1032#
1033.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
1034_aicasm= sys/modules/aic7xxx/aicasm
1035.endif
1036
1037.if !defined(NO_SHARE)
1038_share=	share/syscons/scrnmaps
1039.endif
1040
1041.if ${MK_KERBEROS} != "no"
1042_kerberos5_tools= kerberos5/tools
1043.endif
1044
1045.if ${MK_RESCUE} != "no"
1046_rescue= rescue/rescue
1047.endif
1048
1049build-tools:
1050.for _tool in \
1051    bin/csh \
1052    bin/sh \
1053    ${_rescue} \
1054    lib/ncurses/ncurses \
1055    lib/ncurses/ncursesw \
1056    ${_share} \
1057    ${_aicasm} \
1058    usr.bin/awk \
1059    lib/libmagic \
1060    usr.sbin/sysinstall
1061	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1062		cd ${.CURDIR}/${_tool}; \
1063		${MAKE} DIRPRFX=${_tool}/ obj; \
1064		${MAKE} DIRPRFX=${_tool}/ build-tools
1065.endfor
1066.for _tool in \
1067    gnu/usr.bin/cc/cc_tools \
1068    ${_kerberos5_tools}
1069	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1070		cd ${.CURDIR}/${_tool}; \
1071		${MAKE} DIRPRFX=${_tool}/ obj; \
1072		${MAKE} DIRPRFX=${_tool}/ depend; \
1073		${MAKE} DIRPRFX=${_tool}/ all
1074.endfor
1075
1076#
1077# cross-tools: Build cross-building tools
1078#
1079.if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1080.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1081_btxld=		usr.sbin/btxld
1082.endif
1083.endif
1084.if ${TARGET_ARCH} != ${MACHINE_ARCH}
1085.if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1086_crunchide=	usr.sbin/crunch/crunchide
1087.endif
1088.if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1089_kgzip=		usr.sbin/kgzip
1090.endif
1091.endif
1092
1093.if ${CC:T:Mclang} == "clang"
1094_clang=		usr.bin/clang
1095_clang_libs=	lib/clang
1096.endif
1097
1098cross-tools:
1099.for _tool in \
1100    ${_clang_libs} \
1101    ${_clang} \
1102    gnu/usr.bin/binutils \
1103    gnu/usr.bin/cc \
1104    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1105    ${_btxld} \
1106    ${_crunchide} \
1107    ${_kgzip}
1108	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1109		cd ${.CURDIR}/${_tool}; \
1110		${MAKE} DIRPRFX=${_tool}/ obj; \
1111		${MAKE} DIRPRFX=${_tool}/ depend; \
1112		${MAKE} DIRPRFX=${_tool}/ all; \
1113		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1114.endfor
1115
1116#
1117# hierarchy - ensure that all the needed directories are present
1118#
1119hierarchy:
1120	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
1121
1122#
1123# libraries - build all libraries, and install them under ${DESTDIR}.
1124#
1125# The list of libraries with dependents (${_prebuild_libs}) and their
1126# interdependencies (__L) are built automatically by the
1127# ${.CURDIR}/tools/make_libdeps.sh script.
1128#
1129libraries:
1130	cd ${.CURDIR}; \
1131	    ${MAKE} -f Makefile.inc1 _prereq_libs; \
1132	    ${MAKE} -f Makefile.inc1 _startup_libs; \
1133	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1134	    ${MAKE} -f Makefile.inc1 _generic_libs;
1135
1136#
1137# static libgcc.a prerequisite for shared libc
1138#
1139_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1140
1141# These dependencies are not automatically generated:
1142#
1143# gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1144# all shared libraries for ELF.
1145#
1146_startup_libs=	gnu/lib/csu
1147.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1148_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
1149.elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1150_startup_libs+=	lib/csu/${MACHINE_ARCH}
1151.else
1152_startup_libs+=	lib/csu/${MACHINE_CPUARCH}
1153.endif
1154_startup_libs+=	gnu/lib/libgcc
1155_startup_libs+=	lib/libcompiler_rt
1156_startup_libs+=	lib/libc
1157
1158gnu/lib/libgcc__L: lib/libc__L
1159
1160_prebuild_libs=	${_kerberos5_lib_libasn1} ${_kerberos5_lib_libheimntlm} \
1161		${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1162		${_kerberos5_lib_libroken} \
1163		lib/libbz2 lib/libcom_err lib/libcrypt \
1164		lib/libexpat lib/libfetch \
1165		${_lib_libgssapi} ${_lib_libipx} \
1166		lib/libkiconv lib/libkvm lib/liblzma lib/libmd \
1167		lib/ncurses/ncurses lib/ncurses/ncursesw \
1168		lib/libopie lib/libpam ${_lib_libthr} \
1169		lib/libradius lib/libsbuf lib/libtacplus \
1170		lib/libutil ${_lib_libypclnt} lib/libz lib/msun \
1171		${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1172		${_secure_lib_libssl}
1173
1174.if ${MK_LIBTHR} != "no"
1175_lib_libthr=	lib/libthr
1176.endif
1177
1178_generic_libs=	${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib
1179
1180lib/libopie__L lib/libtacplus__L: lib/libmd__L
1181
1182.if ${MK_CDDL} != "no"
1183_cddl_lib= cddl/lib
1184.endif
1185
1186.if ${MK_CRYPT} != "no"
1187.if ${MK_OPENSSL} != "no"
1188_secure_lib_libcrypto= secure/lib/libcrypto
1189_secure_lib_libssl= secure/lib/libssl
1190lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1191lib/libfetch__L: secure/lib/libcrypto__L secure/lib/libssl__L lib/libmd__L
1192.if ${MK_OPENSSH} != "no"
1193_secure_lib_libssh= secure/lib/libssh
1194secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1195.if ${MK_KERBEROS_SUPPORT} != "no"
1196secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1197    kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1198    lib/libmd__L kerberos5/lib/libroken__L
1199.endif
1200.endif
1201.endif
1202_secure_lib=	secure/lib
1203.endif
1204
1205.if ${MK_GSSAPI} != "no"
1206_lib_libgssapi=	lib/libgssapi
1207.endif
1208
1209.if ${MK_IPX} != "no"
1210_lib_libipx=	lib/libipx
1211.endif
1212
1213.if ${MK_KERBEROS} != "no"
1214_kerberos5_lib=	kerberos5/lib
1215_kerberos5_lib_libasn1= kerberos5/lib/libasn1
1216_kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1217_kerberos5_lib_libhx509= kerberos5/lib/libhx509
1218_kerberos5_lib_libroken= kerberos5/lib/libroken
1219_kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1220.endif
1221
1222.if ${MK_NIS} != "no"
1223_lib_libypclnt=	lib/libypclnt
1224.endif
1225
1226.if ${MK_OPENSSL} == "no"
1227lib/libfetch__L lib/libradius__L: lib/libmd__L
1228.endif
1229
1230.for _lib in ${_prereq_libs}
1231${_lib}__PL: .PHONY
1232.if exists(${.CURDIR}/${_lib})
1233	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1234		cd ${.CURDIR}/${_lib}; \
1235		${MAKE} DIRPRFX=${_lib}/ obj; \
1236		${MAKE} DIRPRFX=${_lib}/ depend; \
1237		${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \
1238		${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install
1239.endif
1240.endfor
1241
1242.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1243${_lib}__L: .PHONY
1244.if exists(${.CURDIR}/${_lib})
1245	${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1246		cd ${.CURDIR}/${_lib}; \
1247		${MAKE} DIRPRFX=${_lib}/ obj; \
1248		${MAKE} DIRPRFX=${_lib}/ depend; \
1249		${MAKE} DIRPRFX=${_lib}/ all; \
1250		${MAKE} DIRPRFX=${_lib}/ install
1251.endif
1252.endfor
1253
1254# libpam is special: we need to build static PAM modules before
1255# static PAM library, and dynamic PAM library before dynamic PAM
1256# modules.
1257lib/libpam__L: .PHONY
1258	${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1259		cd ${.CURDIR}/lib/libpam; \
1260		${MAKE} DIRPRFX=lib/libpam/ obj; \
1261		${MAKE} DIRPRFX=lib/libpam/ depend; \
1262		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1263		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1264
1265_prereq_libs: ${_prereq_libs:S/$/__PL/}
1266_startup_libs: ${_startup_libs:S/$/__L/}
1267_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1268_generic_libs: ${_generic_libs:S/$/__L/}
1269
1270.for __target in all clean cleandepend cleandir depend includes obj
1271.for entry in ${SUBDIR}
1272${entry}.${__target}__D: .PHONY
1273	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1274		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1275		edir=${entry}.${MACHINE_ARCH}; \
1276		cd ${.CURDIR}/$${edir}; \
1277	else \
1278		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1279		edir=${entry}; \
1280		cd ${.CURDIR}/$${edir}; \
1281	fi; \
1282	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1283.endfor
1284par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1285.endfor
1286
1287.include <bsd.subdir.mk>
1288
1289.if make(check-old) || make(check-old-dirs) || \
1290    make(check-old-files) || make(check-old-libs) || \
1291    make(delete-old) || make(delete-old-dirs) || \
1292    make(delete-old-files) || make(delete-old-libs)
1293
1294#
1295# check for / delete old files section
1296#
1297
1298.include "ObsoleteFiles.inc"
1299
1300OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1301else you can not start such an application. Consult UPDATING for more \
1302information regarding how to cope with the removal/revision bump of a \
1303specific library."
1304
1305.if !defined(BATCH_DELETE_OLD_FILES)
1306RM_I=-i
1307.else
1308RM_I=-v
1309.endif
1310
1311delete-old-files:
1312	@echo ">>> Removing old files (only deletes safe to delete libs)"
1313# Ask for every old file if the user really wants to remove it.
1314# It's annoying, but better safe than sorry.
1315	@for file in ${OLD_FILES} ${OLD_FILES:Musr/share/*.gz:R}; do \
1316		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1317			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1318			rm ${RM_I} "${DESTDIR}/$${file}"; \
1319		fi; \
1320	done
1321# Remove catpages without corresponding manpages.
1322	@exec 3<&0; \
1323	find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1324	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1325	while read catpage; do \
1326		read manpage; \
1327		if [ ! -e "$${manpage}" ]; then \
1328			rm ${RM_I} $${catpage} <&3 ; \
1329	        fi; \
1330	done
1331	@echo ">>> Old files removed"
1332
1333check-old-files:
1334	@echo ">>> Checking for old files"
1335	@for file in ${OLD_FILES} ${OLD_FILES:Musr/share/*.gz:R}; do \
1336		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1337		 	echo "${DESTDIR}/$${file}"; \
1338		fi; \
1339	done
1340# Check for catpages without corresponding manpages.
1341	@find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1342	sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1343	while read catpage; do \
1344		read manpage; \
1345		if [ ! -e "$${manpage}" ]; then \
1346			echo $${catpage} ; \
1347	        fi; \
1348	done
1349
1350delete-old-libs:
1351	@echo ">>> Removing old libraries"
1352	@echo "${OLD_LIBS_MESSAGE}" | fmt
1353	@for file in ${OLD_LIBS}; do \
1354		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1355			chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1356			rm ${RM_I} "${DESTDIR}/$${file}"; \
1357		fi; \
1358	done
1359	@echo ">>> Old libraries removed"
1360
1361check-old-libs:
1362	@echo ">>> Checking for old libraries"
1363	@for file in ${OLD_LIBS}; do \
1364		if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1365			echo "${DESTDIR}/$${file}"; \
1366		fi; \
1367	done
1368
1369delete-old-dirs:
1370	@echo ">>> Removing old directories"
1371	@for dir in ${OLD_DIRS}; do \
1372		if [ -d "${DESTDIR}/$${dir}" ]; then \
1373			rmdir -v "${DESTDIR}/$${dir}" || true; \
1374		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1375			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1376		fi; \
1377	done
1378	@echo ">>> Old directories removed"
1379
1380check-old-dirs:
1381	@echo ">>> Checking for old directories"
1382	@for dir in ${OLD_DIRS}; do \
1383		if [ -d "${DESTDIR}/$${dir}" ]; then \
1384			echo "${DESTDIR}/$${dir}"; \
1385		elif [ -L "${DESTDIR}/$${dir}" ]; then \
1386			echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1387		fi; \
1388	done
1389
1390delete-old: delete-old-files delete-old-dirs
1391	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1392
1393check-old: check-old-files check-old-libs check-old-dirs
1394	@echo "To remove old files and directories run '${MAKE} delete-old'."
1395	@echo "To remove old libraries run '${MAKE} delete-old-libs'."
1396
1397.endif
1398
1399#
1400# showconfig - show build configuration.
1401#
1402showconfig:
1403	@${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1404
1405.if !empty(KRNLOBJDIR) && !empty(KERNCONF)
1406DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
1407
1408.if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
1409.if exists(${KERNCONFDIR}/${KERNCONF})
1410FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
1411	${KERNCONFDIR}/${KERNCONF}
1412.endif
1413.endif
1414
1415.endif
1416
1417.if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
1418DTBOUTPUTPATH= ${.CURDIR}
1419.endif
1420
1421#
1422# Build 'standalone' Device Tree Blob
1423#
1424builddtb:
1425	@if [ "${FDT_DTS_FILE}" = "" ]; then \
1426		echo "ERROR: FDT_DTS_FILE must be specified!"; \
1427		exit 1; \
1428	fi;	\
1429	if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ]; then \
1430		echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \
1431			exist!"; \
1432		exit 1;	\
1433	fi;	\
1434	if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then	\
1435		echo "WARNING: DTB will be placed in the current working \
1436			directory"; \
1437	fi
1438	@PATH=${TMPPATH} \
1439	dtc -O dtb -o \
1440	    ${DTBOUTPUTPATH}/`echo ${FDT_DTS_FILE} | cut -d. -f1`.dtb -b 0 \
1441	    -p 1024 ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE}
1442
1443###############
1444
1445.if defined(XDEV) && defined(XDEV_ARCH)
1446
1447.if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH}
1448XDEV_CPUTYPE?=${CPUTYPE}
1449.else
1450XDEV_CPUTYPE?=${TARGET_CPUTYPE}
1451.endif
1452
1453NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
1454	-DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE \
1455	-DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \
1456	TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \
1457	CPUTYPE=${XDEV_CPUTYPE}
1458
1459XDDIR=${XDEV_ARCH}-freebsd
1460XDTP=/usr/${XDDIR}
1461CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR}
1462CDENV= ${CDBENV} \
1463	_SHLIBDIRPREFIX=${XDTP} \
1464	TOOLS_PREFIX=${XDTP}
1465CD2ENV=${CDENV} \
1466	MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1467
1468CDTMP=	${MAKEOBJDIRPREFIX}/${XDEV}/${.CURDIR}/tmp
1469CDMAKE=${CDENV} ${MAKE} ${NOFUN}
1470CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1471XDDESTDIR=${DESTDIR}${XDTP}
1472.if !defined(OSREL)
1473OSREL!= uname -r | sed -e 's/[-(].*//'
1474.endif
1475
1476.ORDER: xdev-build xdev-install
1477xdev: xdev-build xdev-install
1478
1479.ORDER: _xb-build-tools _xb-cross-tools
1480xdev-build: _xb-build-tools _xb-cross-tools
1481
1482_xb-build-tools:
1483	${_+_}@cd ${.CURDIR}; \
1484	${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1485
1486_xb-cross-tools:
1487.for _tool in \
1488    gnu/usr.bin/binutils \
1489    gnu/usr.bin/cc
1490	${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1491	cd ${.CURDIR}/${_tool}; \
1492	${CDMAKE} DIRPRFX=${_tool}/ obj; \
1493	${CDMAKE} DIRPRFX=${_tool}/ depend; \
1494	${CDMAKE} DIRPRFX=${_tool}/ all
1495.endfor
1496
1497_xi-mtree:
1498	${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1499	mkdir -p ${XDDESTDIR}
1500	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1501	    -p ${XDDESTDIR} >/dev/null
1502	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1503	    -p ${XDDESTDIR}/usr >/dev/null
1504	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1505	    -p ${XDDESTDIR}/usr/include >/dev/null
1506
1507.ORDER: _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1508xdev-install: _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1509
1510_xi-cross-tools:
1511	@echo "_xi-cross-tools"
1512.for _tool in \
1513    gnu/usr.bin/binutils \
1514    gnu/usr.bin/cc
1515	${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1516	cd ${.CURDIR}/${_tool}; \
1517	${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1518.endfor
1519
1520_xi-includes:
1521	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1522		DESTDIR=${XDDESTDIR}
1523
1524_xi-libraries:
1525	${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1526		DESTDIR=${XDDESTDIR}
1527
1528_xi-links:
1529	${_+_}cd ${XDDESTDIR}/usr/bin; \
1530		for i in *; do \
1531			ln -sf ../../${XDTP}/usr/bin/$$i \
1532			    ../../../../usr/bin/${XDDIR}-$$i; \
1533			ln -sf ../../${XDTP}/usr/bin/$$i \
1534			    ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1535		done
1536.endif
1537