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