Makefile.inc1 revision 145781
1#
2# $FreeBSD: head/Makefile.inc1 145781 2005-05-01 17:36:09Z imp $
3#
4# Make command line options:
5#	-DNO_DYNAMICROOT do not link /bin and /sbin dynamically
6#	-DNO_KERBEROS Do not build Heimdal (Kerberos 5)
7#	-DNO_RESCUE do not build rescue binaries
8#	-DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
9#	-DNO_CLEAN do not clean at all
10#	-DNO_CRYPT will prevent building of crypt versions
11#	-DNO_MAN do not build the manual pages
12#	-DNO_NLS do not build Native Language Support files
13#	-DNO_PROFILE do not build profiled libraries
14#	-DNO_GAMES do not go into games subdir
15#	-DNO_SHARE do not go into share subdir
16#	-DNO_INFO do not make or install info files
17#	-DNO_LIBC_R do not build libc_r.
18#	-DNO_FORTRAN do not build g77 and related libraries.
19#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
20#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
21#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
22#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
23#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
24#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
25#	TARGET_ARCH="arch" to crossbuild world to a different arch
26
27#
28# The intended user-driven targets are:
29# buildworld  - rebuild *everything*, including glue to help do upgrades
30# installworld- install everything built by "buildworld"
31# update      - convenient way to update your source tree (eg: cvsup/cvs)
32#
33# Standard targets (not defined here) are documented in the makefiles in
34# /usr/share/mk.  These include:
35#		obj depend all install clean cleandepend cleanobj
36
37# We must do share/info early so that installation of info `dir'
38# entries works correctly.  Do it first since it is less likely to
39# grow dependencies on include and lib than vice versa.
40#
41# We must do lib and libexec before bin, because if installworld
42# installs a new /bin/sh, the 'make' command will *immediately*
43# use that new version.  And the new (dynamically-linked) /bin/sh
44# will expect to find appropriate libraries in /lib and /libexec.
45#
46# We must do etc last for install/distribute to work.
47#
48SUBDIR=	share/info include lib libexec bin
49.if !defined(NO_GAMES)
50SUBDIR+=games
51.endif
52SUBDIR+=gnu
53.if !defined(NO_KERBEROS) && !defined(NO_CRYPT) && !defined(NO_OPENSSL)
54SUBDIR+=kerberos5
55.endif
56.if !defined(NO_RESCUE)
57SUBDIR+=rescue
58.endif
59SUBDIR+=sbin
60.if !defined(NO_CRYPT)
61SUBDIR+=secure
62.endif
63.if !defined(NO_SHARE)
64SUBDIR+=share
65.endif
66SUBDIR+=sys usr.bin usr.sbin etc
67
68# These are last, since it is nice to at least get the base system
69# rebuilt before you do them.
70.for _DIR in ${LOCAL_DIRS}
71.if exists(${.CURDIR}/${_DIR}/Makefile)
72SUBDIR+= ${_DIR}
73.endif
74.endfor
75
76.if defined(SUBDIR_OVERRIDE)
77SUBDIR=		${SUBDIR_OVERRIDE}
78.endif
79
80.if defined(NOCLEAN)
81NO_CLEAN=	${NOCLEAN}
82.endif
83.if defined(NO_CLEANDIR)
84CLEANDIR=	clean cleandepend
85.else
86CLEANDIR=	cleandir
87.endif
88
89CVS?=		cvs
90CVSFLAGS?=	-A -P -d -I!
91SUP?=		/usr/local/bin/cvsup
92SUPFLAGS?=	-g -L 2 -P -
93.if defined(SUPHOST)
94SUPFLAGS+=	-h ${SUPHOST}
95.endif
96
97MAKEOBJDIRPREFIX?=	/usr/obj
98.if !defined(OSRELDATE)
99.if exists(/usr/include/osreldate.h)
100OSRELDATE!=	awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
101		/usr/include/osreldate.h
102.else
103OSRELDATE=	0
104.endif
105.endif
106TARGET_ARCH?=	${MACHINE_ARCH}
107.if ${TARGET_ARCH} == ${MACHINE_ARCH}
108TARGET?=	${MACHINE}
109TARGET_CPUTYPE?=${CPUTYPE}
110.else
111TARGET?=	${TARGET_ARCH}
112TARGET_CPUTYPE?=
113.endif
114.if !empty(TARGET_CPUTYPE)
115_TARGET_CPUTYPE=${TARGET_CPUTYPE}
116.else
117_TARGET_CPUTYPE=dummy
118.endif
119_CPUTYPE!=	MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
120		-f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
121.if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
122.error CPUTYPE global should be set with ?=.
123.endif
124.if make(buildworld)
125BUILD_ARCH!=	sysctl -n hw.machine_arch
126.if ${MACHINE_ARCH} != ${BUILD_ARCH}
127.error To cross-build, set TARGET_ARCH.
128.endif
129.endif
130.if ${MACHINE} == ${TARGET} && !defined(CROSS_BUILD_TESTING)
131OBJTREE=	${MAKEOBJDIRPREFIX}
132.else
133OBJTREE=	${MAKEOBJDIRPREFIX}/${TARGET}
134.endif
135WORLDTMP=	${OBJTREE}${.CURDIR}/tmp
136# /usr/games added for fortune which depend on strfile
137BPATH=		${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
138XPATH=		${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
139STRICTTMPPATH=	${BPATH}:${XPATH}
140TMPPATH=	${STRICTTMPPATH}:${PATH}
141
142INSTALLTMP!=	/usr/bin/mktemp -d -u -t install
143
144#
145# Building a world goes through the following stages
146#
147# 1. legacy stage [BMAKE]
148#	This stage is responsible for creating compatibility
149#	shims that are needed by the bootstrap-tools,
150#	build-tools and cross-tools stages.
151# 1. bootstrap-tools stage [BMAKE]
152#	This stage is responsible for creating programs that
153#	are needed for backward compatibility reasons. They
154#	are not built as cross-tools.
155# 2. build-tools stage [TMAKE]
156#	This stage is responsible for creating the object
157#	tree and building any tools that are needed during
158#	the build process.
159# 3. cross-tools stage [XMAKE]
160#	This stage is responsible for creating any tools that
161#	are needed for cross-builds. A cross-compiler is one
162#	of them.
163# 4. world stage [WMAKE]
164#	This stage actually builds the world.
165# 5. install stage (optional) [IMAKE]
166#	This stage installs a previously built world.
167#
168
169BOOTSTRAPPING?=	0
170
171# Common environment for world related stages
172CROSSENV=	MAKEOBJDIRPREFIX=${OBJTREE} \
173		MACHINE_ARCH=${TARGET_ARCH} \
174		MACHINE=${TARGET} \
175		CPUTYPE=${TARGET_CPUTYPE} \
176		GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
177		GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
178		GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
179
180# bootstrap-tools stage
181BMAKEENV=	INSTALL="sh ${.CURDIR}/tools/install.sh" \
182		PATH=${BPATH}:${PATH} \
183		WORLDTMP=${WORLDTMP} \
184		MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
185BMAKE=		MAKEOBJDIRPREFIX=${WORLDTMP} \
186		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
187		DESTDIR= \
188		BOOTSTRAPPING=${OSRELDATE} \
189		-DNO_HTML -DNO_INFO -DNO_LINT -DNO_MAN -DNO_NLS -DNO_PIC \
190		-DNO_PROFILE -DNO_SHARED -DNO_CPU_CFLAGS -DNO_WARNS
191
192# build-tools stage
193TMAKE=		MAKEOBJDIRPREFIX=${OBJTREE} \
194		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
195		DESTDIR= \
196		BOOTSTRAPPING=${OSRELDATE} -DNO_LINT -DNO_CPU_CFLAGS -DNO_WARNS
197
198# cross-tools stage
199XMAKE=		TOOLS_PREFIX=${WORLDTMP} ${BMAKE} -DNO_FORTRAN -DNO_GDB
200
201# world stage
202WMAKEENV=	${CROSSENV} \
203		_SHLIBDIRPREFIX=${WORLDTMP} \
204		INSTALL="sh ${.CURDIR}/tools/install.sh" \
205		PATH=${TMPPATH}
206WMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
207
208.if ${TARGET_ARCH} == "amd64"
209# 32 bit world
210LIB32TMP=	${OBJTREE}${.CURDIR}/lib32
211
212LIB32PREFLAGS=	-m32 -march=athlon-xp -msse2 -mfancy-math-387 -DCOMPAT_32BIT
213LIB32POSTFLAGS=	-I${LIB32TMP}/usr/include \
214		-L${LIB32TMP}/usr/lib32 \
215		-B${LIB32TMP}/usr/lib32
216LIB32CC=	${LIB32PREFLAGS} \
217		${LIB32POSTFLAGS}
218LIB32CXX=	${LIB32PREFLAGS} -I${LIB32TMP}/usr/include/c++/3.4 \
219		${LIB32POSTFLAGS}
220LIB32OBJC=	${LIB32PREFLAGS} -I${LIB32TMP}/usr/include/objc \
221		${LIB32POSTFLAGS}
222
223# Yes, the flags are redundant.
224LIB32MAKEENV=	MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
225		_SHLIBDIRPREFIX=${LIB32TMP} \
226		MACHINE=i386 \
227		MACHINE_ARCH=i386 \
228		INSTALL="sh ${.CURDIR}/tools/install.sh" \
229		PATH=${TMPPATH} \
230		CC="cc ${LIB32CC}" \
231		CXX="c++ ${LIB32CXX}" \
232		OBJC="cc ${LIB32OBJC}" \
233		LD="ld -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
234		AS="as --32" \
235		LIBDIR=/usr/lib32 \
236		SHLIBDIR=/usr/lib32
237
238LIB32MAKE=	${LIB32MAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
239		-DNO_BIND -DNO_MAN -DNO_NLS -DNO_INFO -DNO_HTML \
240		CC="cc ${LIB32CC}" \
241		CXX="c++ ${LIB32CXX}" \
242		OBJC="cc ${LIB32OBJC}" \
243		LD="ld -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
244		AS="as --32" \
245		LIBDIR=/usr/lib32 \
246		SHLIBDIR=/usr/lib32
247.endif
248
249# install stage
250.if empty(.MAKEFLAGS:M-n)
251IMAKEENV=	${CROSSENV} \
252		PATH=${STRICTTMPPATH}:${INSTALLTMP}
253.else
254IMAKEENV=	${CROSSENV} \
255		PATH=${TMPPATH}:${INSTALLTMP}
256.endif
257IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1
258
259# kernel stage
260KMAKEENV=	${WMAKEENV}
261
262#
263# buildworld
264#
265# Attempt to rebuild the entire system, with reasonable chance of
266# success, regardless of how old your existing system is.
267#
268_worldtmp:
269.if ${.CURDIR:C/[^,]//g} != ""
270#	The m4 build of sendmail files doesn't like it if ',' is used
271#	anywhere in the path of it's files.
272	@echo
273	@echo "*** Error: path to source tree contains a comma ','"
274	@echo
275	false
276.endif
277	@echo
278	@echo "--------------------------------------------------------------"
279	@echo ">>> Rebuilding the temporary build tree"
280	@echo "--------------------------------------------------------------"
281.if !defined(NO_CLEAN)
282	rm -rf ${WORLDTMP}
283.else
284	rm -rf ${WORLDTMP}/legacy/usr/include
285	# XXX - These two can depend on any header file.
286	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
287	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
288.endif
289.for _dir in \
290    usr/bin usr/games usr/include/c++/3.4 usr/include/sys usr/lib \
291    usr/libexec usr/sbin usr/share/dict \
292    usr/share/groff_font/devX100 \
293    usr/share/groff_font/devX100-12 \
294    usr/share/groff_font/devX75 \
295    usr/share/groff_font/devX75-12 \
296    usr/share/groff_font/devascii \
297    usr/share/groff_font/devcp1047 \
298    usr/share/groff_font/devdvi \
299    usr/share/groff_font/devhtml \
300    usr/share/groff_font/devkoi8-r \
301    usr/share/groff_font/devlatin1 \
302    usr/share/groff_font/devlbp \
303    usr/share/groff_font/devlj4 \
304    usr/share/groff_font/devps \
305    usr/share/groff_font/devutf8 \
306    usr/share/tmac/mdoc usr/share/tmac/mm
307	mkdir -p ${WORLDTMP}/legacy/${_dir}
308.endfor
309.for _dir in \
310    lib usr/bin usr/include usr/lib/compat/aout usr/libdata/ldscripts \
311    usr/libexec usr/sbin usr/share/misc \
312    usr/share/snmp/defs usr/share/snmp/mibs
313	mkdir -p ${WORLDTMP}/${_dir}
314.endfor
315	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
316	    -p ${WORLDTMP}/usr/include >/dev/null
317	ln -sf ${.CURDIR}/sys ${WORLDTMP}
318.if defined(WITH_BIND_LIBS) && !defined(NO_BIND)
319	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
320	    -p ${WORLDTMP}/usr/include >/dev/null
321.endif
322_legacy:
323	@echo
324	@echo "--------------------------------------------------------------"
325	@echo ">>> stage 1.1: legacy release compatibility shims"
326	@echo "--------------------------------------------------------------"
327	${_+_}cd ${.CURDIR}; ${BMAKE} legacy
328_bootstrap-tools:
329	@echo
330	@echo "--------------------------------------------------------------"
331	@echo ">>> stage 1.2: bootstrap tools"
332	@echo "--------------------------------------------------------------"
333	${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
334_cleanobj:
335.if !defined(NO_CLEAN)
336	@echo
337	@echo "--------------------------------------------------------------"
338	@echo ">>> stage 2.1: cleaning up the object tree"
339	@echo "--------------------------------------------------------------"
340	${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
341.endif
342_obj:
343	@echo
344	@echo "--------------------------------------------------------------"
345	@echo ">>> stage 2.2: rebuilding the object tree"
346	@echo "--------------------------------------------------------------"
347	${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
348_build-tools:
349	@echo
350	@echo "--------------------------------------------------------------"
351	@echo ">>> stage 2.3: build tools"
352	@echo "--------------------------------------------------------------"
353	${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
354_cross-tools:
355	@echo
356	@echo "--------------------------------------------------------------"
357	@echo ">>> stage 3: cross tools"
358	@echo "--------------------------------------------------------------"
359	${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
360_includes:
361	@echo
362	@echo "--------------------------------------------------------------"
363	@echo ">>> stage 4.1: building includes"
364	@echo "--------------------------------------------------------------"
365	${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
366_libraries:
367	@echo
368	@echo "--------------------------------------------------------------"
369	@echo ">>> stage 4.2: building libraries"
370	@echo "--------------------------------------------------------------"
371	${_+_}cd ${.CURDIR}; \
372	    ${WMAKE} -DNO_FSCHG -DNO_HTML -DNO_INFO -DNO_LINT -DNO_MAN \
373	    -DNO_NLS -DNO_PROFILE libraries
374_depend:
375	@echo
376	@echo "--------------------------------------------------------------"
377	@echo ">>> stage 4.3: make dependencies"
378	@echo "--------------------------------------------------------------"
379	${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
380everything:
381	@echo
382	@echo "--------------------------------------------------------------"
383	@echo ">>> stage 4.4: building everything"
384	@echo "--------------------------------------------------------------"
385	${_+_}cd ${.CURDIR}; ${WMAKE} par-all
386.if ${TARGET_ARCH} == "amd64"
387build32:
388	@echo
389	@echo "--------------------------------------------------------------"
390	@echo ">>> stage 5.1: building 32 bit shim libraries"
391	@echo "--------------------------------------------------------------"
392.for _dir in \
393    lib lib32 usr/bin usr/include usr/lib32 usr/libdata/ldscripts \
394    usr/libexec usr/sbin usr/share/misc \
395    usr/share/snmp/defs usr/share/snmp/mibs
396	mkdir -p ${LIB32TMP}/${_dir}
397.endfor
398	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
399	    -p ${LIB32TMP}/usr/include >/dev/null
400	ln -sf ${.CURDIR}/sys ${WORLDTMP}
401.if !defined(NO_KERBEROS) && !defined(NO_CRYPT) && !defined(NO_OPENSSL)
402.for _t in obj depend all
403	cd ${.CURDIR}/kerberos5/tools; \
404	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= ${_t}
405.endfor
406.endif
407.for _t in obj includes
408	cd ${.CURDIR}/include; \
409	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
410	cd ${.CURDIR}/lib; \
411	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
412	cd ${.CURDIR}/gnu/lib; \
413	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
414.if !defined(NO_CRYPT)
415	cd ${.CURDIR}/secure/lib; \
416	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
417.endif
418.if !defined(NO_KERBEROS) && !defined(NO_CRYPT) && !defined(NO_OPENSSL)
419	cd ${.CURDIR}/kerberos5/lib; \
420	    ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
421.endif
422.endfor
423.for _dir in usr.sbin/pcvt/keycap usr.bin/lex/lib
424	cd ${.CURDIR}/${_dir}; \
425	    ${LIB32MAKE} DESTDIR=${LIB32TMP} obj
426.endfor
427.for _dir in lib/libncurses lib/libmagic
428	cd ${.CURDIR}/${_dir}; \
429	    MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} DESTDIR= build-tools
430.endfor
431	cd ${.CURDIR}; \
432	    ${LIB32MAKE} -f Makefile.inc1 DESTDIR=${LIB32TMP} libraries 
433.for _t in obj depend all
434	cd ${.CURDIR}/libexec/rtld-elf; \
435	    PROG=ld-elf32.so.1 ${LIB32MAKE} DESTDIR=${LIB32TMP} ${_t}
436.endfor
437
438install32:
439	mkdir -p ${DESTDIR}/usr/lib32	# XXX add to mtree
440	cd ${.CURDIR}/lib; ${LIB32MAKE} install
441	cd ${.CURDIR}/gnu/lib; ${LIB32MAKE} install
442.if !defined(NO_CRYPT)
443	cd ${.CURDIR}/secure/lib; ${LIB32MAKE} install
444.endif
445	cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32MAKE} install
446.endif
447
448
449WMAKE_TGTS=
450.if !defined(SUBDIR_OVERRIDE)
451WMAKE_TGTS+=	_worldtmp _legacy _bootstrap-tools
452.endif
453WMAKE_TGTS+=	_cleanobj _obj _build-tools
454.if !defined(SUBDIR_OVERRIDE)
455WMAKE_TGTS+=	_cross-tools
456.endif
457WMAKE_TGTS+=	_includes _libraries _depend everything
458.if ${TARGET_ARCH} == "amd64" && !defined(NO_LIB32)
459WMAKE_TGTS+=	build32
460.endif
461
462buildworld: ${WMAKE_TGTS}
463.ORDER: ${WMAKE_TGTS}
464
465buildenv:
466	@echo Entering world for ${TARGET_ARCH}:${TARGET}
467	@cd ${.CURDIR} && env ${WMAKEENV} sh || true
468
469TOOLCHAIN_TGTS=	${WMAKE_TGTS:N_depend:Neverything}
470toolchain: ${TOOLCHAIN_TGTS}
471kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
472
473#
474# Use this to add checks to installworld/installkernel targets.
475#
476SPECIAL_INSTALLCHECKS=
477
478#
479# installcheck
480#
481# Checks to be sure system is ready for installworld
482#
483CHECK_UIDS=
484CHECK_GIDS=
485.if !defined(NO_SENDMAIL)
486CHECK_UIDS+=	smmsp
487CHECK_GIDS+=	smmsp
488.endif
489.if !defined(NO_PF)
490CHECK_UIDS+=	proxy
491CHECK_GIDS+=	proxy authpf
492.endif
493installcheck: ${SPECIAL_INSTALLCHECKS}
494.for uid in ${CHECK_UIDS}
495	@if ! `id -u ${uid} >/dev/null 2>&1`; then \
496		echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
497		false; \
498	fi
499.endfor
500.for gid in ${CHECK_GIDS}
501	@if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
502		echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
503		false; \
504	fi
505.endfor
506
507#
508# distributeworld
509#
510# Distributes everything compiled by a `buildworld'.
511#
512# installworld
513#
514# Installs everything compiled by a 'buildworld'.
515#
516distributeworld installworld: installcheck
517	mkdir -p ${INSTALLTMP}
518	for prog in [ awk cap_mkdb cat chflags chmod chown \
519	    date echo egrep find grep \
520	    ln make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
521	    test true uname wc zic; do \
522		cp `which $$prog` ${INSTALLTMP}; \
523	done
524	${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
525	rm -rf ${INSTALLTMP}
526
527#
528# reinstall
529#
530# If you have a build server, you can NFS mount the source and obj directories
531# and do a 'make reinstall' on the *client* to install new binaries from the
532# most recent server build.
533#
534reinstall: ${SPECIAL_INSTALLCHECKS}
535	@echo "--------------------------------------------------------------"
536	@echo ">>> Making hierarchy"
537	@echo "--------------------------------------------------------------"
538	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
539	@echo
540	@echo "--------------------------------------------------------------"
541	@echo ">>> Installing everything"
542	@echo "--------------------------------------------------------------"
543	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
544.if ${TARGET_ARCH} == "amd64" && !defined(NO_LIB32)
545	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
546.endif
547
548redistribute:
549	@echo "--------------------------------------------------------------"
550	@echo ">>> Distributing everything"
551	@echo "--------------------------------------------------------------"
552	${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
553
554distribution:
555	cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} distribution
556
557#
558# buildkernel and installkernel
559#
560# Which kernels to build and/or install is specified by setting
561# KERNCONF. If not defined a GENERIC kernel is built/installed.
562# Only the existing (depending TARGET) config files are used
563# for building kernels and only the first of these is designated
564# as the one being installed.
565#
566# Note that we have to use TARGET instead of TARGET_ARCH when
567# we're in kernel-land. Since only TARGET_ARCH is (expected) to
568# be set to cross-build, we have to make sure TARGET is set
569# properly.
570
571.if !defined(KERNCONF) && defined(KERNEL)
572KERNCONF=	${KERNEL}
573KERNWARN=
574.else
575KERNCONF?=	GENERIC
576.endif
577INSTKERNNAME?=	kernel
578
579KERNSRCDIR?=	${.CURDIR}/sys
580KRNLCONFDIR=	${KERNSRCDIR}/${TARGET}/conf
581KRNLOBJDIR=	${OBJTREE}${KERNSRCDIR}
582KERNCONFDIR?=	${KRNLCONFDIR}
583
584BUILDKERNELS=
585INSTALLKERNEL=
586.for _kernel in ${KERNCONF}
587.if exists(${KERNCONFDIR}/${_kernel})
588BUILDKERNELS+=	${_kernel}
589.if empty(INSTALLKERNEL)
590INSTALLKERNEL= ${_kernel}
591.endif
592.endif
593.endfor
594
595#
596# buildkernel
597#
598# Builds all kernels defined by BUILDKERNELS.
599#
600buildkernel:
601.if empty(BUILDKERNELS)
602	@echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
603	false
604.endif
605.if defined(KERNWARN)
606	@echo "--------------------------------------------------------------"
607	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
608	@echo "--------------------------------------------------------------"
609	@sleep 3
610.endif
611	@echo
612.for _kernel in ${BUILDKERNELS}
613	@echo "--------------------------------------------------------------"
614	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
615	@echo "--------------------------------------------------------------"
616	@echo "===> ${_kernel}"
617	mkdir -p ${KRNLOBJDIR}
618.if !defined(NO_KERNELCONFIG)
619	@echo
620	@echo "--------------------------------------------------------------"
621	@echo ">>> stage 1: configuring the kernel"
622	@echo "--------------------------------------------------------------"
623	cd ${KRNLCONFDIR}; \
624		PATH=${TMPPATH} \
625		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
626			${KERNCONFDIR}/${_kernel}
627.endif
628.if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
629	@echo
630	@echo "--------------------------------------------------------------"
631	@echo ">>> stage 2.1: cleaning up the object tree"
632	@echo "--------------------------------------------------------------"
633	cd ${KRNLOBJDIR}/${_kernel}; \
634	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} ${CLEANDIR}
635.endif
636	@echo
637	@echo "--------------------------------------------------------------"
638	@echo ">>> stage 2.2: rebuilding the object tree"
639	@echo "--------------------------------------------------------------"
640	cd ${KRNLOBJDIR}/${_kernel}; \
641	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} obj
642	@echo
643	@echo "--------------------------------------------------------------"
644	@echo ">>> stage 2.3: build tools"
645	@echo "--------------------------------------------------------------"
646	cd ${KRNLOBJDIR}/${_kernel}; \
647	    MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
648	    ${MAKE} -DNO_CPU_CFLAGS -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
649# XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
650.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
651.for target in obj depend all
652	cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
653	    MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
654	    ${MAKE} -DNO_CPU_CFLAGS ${target}
655.endfor
656.endif
657.if !defined(NO_KERNELDEPEND)
658	@echo
659	@echo "--------------------------------------------------------------"
660	@echo ">>> stage 3.1: making dependencies"
661	@echo "--------------------------------------------------------------"
662	cd ${KRNLOBJDIR}/${_kernel}; \
663	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} depend -DNO_MODULES_OBJ
664.endif
665	@echo
666	@echo "--------------------------------------------------------------"
667	@echo ">>> stage 3.2: building everything"
668	@echo "--------------------------------------------------------------"
669	cd ${KRNLOBJDIR}/${_kernel}; \
670	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all -DNO_MODULES_OBJ
671	@echo "--------------------------------------------------------------"
672	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
673	@echo "--------------------------------------------------------------"
674.endfor
675
676#
677# installkernel, etc.
678#
679# Install the kernel defined by INSTALLKERNEL
680#
681installkernel installkernel.debug \
682reinstallkernel reinstallkernel.debug: ${SPECIAL_INSTALLCHECKS}
683.if empty(INSTALLKERNEL)
684	@echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
685	false
686.endif
687	@echo "--------------------------------------------------------------"
688	@echo ">>> Making hierarchy"
689	@echo "--------------------------------------------------------------"
690	cd ${.CURDIR}; \
691	    ${CROSSENV} PATH=${TMPPATH} ${MAKE} -f Makefile.inc1 hierarchy
692	@echo
693	@echo "--------------------------------------------------------------"
694	@echo ">>> Installing kernel"
695	@echo "--------------------------------------------------------------"
696	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
697	    ${CROSSENV} PATH=${TMPPATH} \
698	    ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
699
700#
701# update
702#
703# Update the source tree, by running cvsup and/or running cvs to update to the
704# latest copy.
705#
706update:
707.if defined(SUP_UPDATE)
708	@echo "--------------------------------------------------------------"
709	@echo ">>> Running ${SUP}"
710	@echo "--------------------------------------------------------------"
711.if defined(SUPFILE)
712	@${SUP} ${SUPFLAGS} ${SUPFILE}
713.endif
714.if defined(SUPFILE1)
715	@${SUP} ${SUPFLAGS} ${SUPFILE1}
716.endif
717.if defined(SUPFILE2)
718	@${SUP} ${SUPFLAGS} ${SUPFILE2}
719.endif
720.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
721	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
722.endif
723.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
724	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
725.endif
726.endif
727.if defined(CVS_UPDATE)
728	@echo "--------------------------------------------------------------"
729	@echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT}
730	@echo "--------------------------------------------------------------"
731	cd ${.CURDIR}; ${CVS} -R -q update ${CVSFLAGS}
732.endif
733
734#
735# ------------------------------------------------------------------------
736#
737# From here onwards are utility targets used by the 'make world' and
738# related targets.  If your 'world' breaks, you may like to try to fix
739# the problem and manually run the following targets to attempt to
740# complete the build.  Beware, this is *not* guaranteed to work, you
741# need to have a pretty good grip on the current state of the system
742# to attempt to manually finish it.  If in doubt, 'make world' again.
743#
744
745#
746# legacy: Build compatibility shims for the next three targets
747#
748legacy:
749.if ${BOOTSTRAPPING} < 503000
750	@echo "ERROR: Source upgrades from versions prior to 5.3 not supported."; \
751	false
752.endif
753.for _tool in tools/build
754	${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
755	    cd ${.CURDIR}/${_tool}; \
756	    ${MAKE} DIRPRFX=${_tool}/ obj; \
757	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
758	    ${MAKE} DIRPRFX=${_tool}/ depend; \
759	    ${MAKE} DIRPRFX=${_tool}/ all; \
760	    ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
761.endfor
762
763#
764# bootstrap-tools: Build tools needed for compatibility
765#
766.if !defined(NO_GAMES)
767_strfile=	games/fortune/strfile
768.endif
769
770.if !defined(NO_CXX)
771_gperf=		gnu/usr.bin/gperf
772.if ${BOOTSTRAPPING} < 500113
773_groff=		gnu/usr.bin/groff
774.else
775_groff=		gnu/usr.bin/groff/tmac
776.endif
777.endif
778
779.if ${BOOTSTRAPPING} < 600015
780_cap_mkdb=	usr.bin/cap_mkdb
781.endif
782
783.if ${BOOTSTRAPPING} < 600018
784_colldef=	usr.bin/colldef
785.endif
786
787.if ${BOOTSTRAPPING} < 600017
788_gencat=	usr.bin/gencat
789.endif
790
791.if ${BOOTSTRAPPING} < 600016
792_mklocale=	usr.bin/mklocale
793.endif
794
795.if !defined(NO_RESCUE) && \
796    ${BOOTSTRAPPING} < 600008
797_crunchgen=	usr.sbin/crunch/crunchgen
798.endif
799
800.if ${BOOTSTRAPPING} < 600020
801_pwd_mkdb=	usr.sbin/pwd_mkdb
802.endif
803
804bootstrap-tools:
805.for _tool in \
806    ${_strfile} \
807    ${_gperf} \
808    ${_groff} \
809    gnu/usr.bin/texinfo \
810    ${_cap_mkdb} \
811    ${_colldef} \
812    ${_gencat} \
813    usr.bin/lorder \
814    usr.bin/makewhatis \
815    ${_mklocale} \
816    usr.bin/rpcgen \
817    usr.bin/xinstall \
818    usr.sbin/config \
819    ${_crunchgen} \
820    ${_pwd_mkdb}
821	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
822		cd ${.CURDIR}/${_tool}; \
823		${MAKE} DIRPRFX=${_tool}/ obj; \
824		${MAKE} DIRPRFX=${_tool}/ depend; \
825		${MAKE} DIRPRFX=${_tool}/ all; \
826		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
827.endfor
828
829#
830# build-tools: Build special purpose build tools
831#
832.if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
833_aicasm= sys/modules/aic7xxx/aicasm
834.endif
835
836.if !defined(NO_SHARE)
837_share=	share/syscons/scrnmaps
838.endif
839
840.if !defined(NO_KERBEROS) && !defined(NO_CRYPT) && !defined(NO_OPENSSL)
841_kerberos5_tools= kerberos5/tools
842.endif
843
844.if !defined(NO_RESCUE)
845_rescue= rescue/rescue
846.endif
847
848build-tools:
849.for _tool in \
850    bin/csh \
851    bin/sh \
852    ${_rescue} \
853    lib/libncurses \
854    ${_share} \
855    ${_aicasm} \
856    usr.bin/awk \
857    lib/libmagic \
858    usr.sbin/sysinstall
859	${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
860		cd ${.CURDIR}/${_tool}; \
861		${MAKE} DIRPRFX=${_tool}/ obj; \
862		${MAKE} DIRPRFX=${_tool}/ build-tools
863.endfor
864.for _tool in \
865    gnu/usr.bin/cc/cc_tools \
866    ${_kerberos5_tools}
867	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
868		cd ${.CURDIR}/${_tool}; \
869		${MAKE} DIRPRFX=${_tool}/ obj; \
870		${MAKE} DIRPRFX=${_tool}/ depend; \
871		${MAKE} DIRPRFX=${_tool}/ all
872.endfor
873
874#
875# cross-tools: Build cross-building tools
876#
877.if (${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386") && \
878    ${TARGET_ARCH} != ${MACHINE_ARCH}
879_btxld=		usr.sbin/btxld
880.endif
881
882.if (!defined(NO_RESCUE) || defined(RELEASEDIR)) && \
883    ${TARGET_ARCH} != ${MACHINE_ARCH}
884_crunchide=	usr.sbin/crunch/crunchide
885.endif
886
887.if ${TARGET_ARCH} == "alpha" && ${TARGET_ARCH} != ${MACHINE_ARCH}
888_elf2exe=	usr.sbin/elf2exe
889.endif
890
891.if ${TARGET_ARCH} == "i386" && ${TARGET_ARCH} != ${MACHINE_ARCH} && \
892    defined(RELEASEDIR)
893_kgzip=		usr.sbin/kgzip
894.endif
895
896cross-tools:
897.for _tool in \
898    gnu/usr.bin/binutils \
899    gnu/usr.bin/cc \
900    usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
901    ${_btxld} \
902    ${_crunchide} \
903    ${_elf2exe} \
904    ${_kgzip}
905	${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
906		cd ${.CURDIR}/${_tool}; \
907		${MAKE} DIRPRFX=${_tool}/ obj; \
908		${MAKE} DIRPRFX=${_tool}/ depend; \
909		${MAKE} DIRPRFX=${_tool}/ all; \
910		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
911.endfor
912
913#
914# hierarchy - ensure that all the needed directories are present
915#
916hierarchy:
917	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
918
919#
920# libraries - build all libraries, and install them under ${DESTDIR}.
921#
922# The list of libraries with dependents (${_prebuild_libs}) and their
923# interdependencies (__L) are built automatically by the
924# ${.CURDIR}/tools/make_libdeps.sh script.
925#
926libraries:
927	cd ${.CURDIR}; \
928	    ${MAKE} -f Makefile.inc1 _startup_libs; \
929	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
930	    ${MAKE} -f Makefile.inc1 _generic_libs;
931
932# These dependencies are not automatically generated:
933#
934# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
935# shared libraries for ELF.
936#
937_startup_libs=	gnu/lib/csu gnu/lib/libgcc
938.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
939_startup_libs+=	lib/csu/${MACHINE_ARCH}-elf
940.else
941_startup_libs+=	lib/csu/${MACHINE_ARCH}
942.endif
943
944_prebuild_libs=
945
946_generic_libs=	gnu/lib
947
948.if !defined(NO_KERBEROS) && !defined(NO_CRYPT) && !defined(NO_OPENSSL)
949_prebuild_libs+=	kerberos5/lib/libasn1
950_prebuild_libs+=	kerberos5/lib/libgssapi
951_prebuild_libs+=	kerberos5/lib/libkrb5
952_prebuild_libs+=	kerberos5/lib/libroken
953_generic_libs+=	kerberos5/lib
954.endif
955
956_prebuild_libs+= lib/libcom_err lib/libcrypt lib/libexpat \
957		lib/libkvm lib/libmd \
958		lib/libncurses lib/libnetgraph lib/libopie lib/libpam \
959		lib/libradius \
960		lib/libsbuf lib/libtacplus lib/libutil \
961		lib/libz lib/msun
962
963lib/libopie__L lib/libtacplus__L: lib/libmd__L
964
965.if !defined(NO_BIND)
966.if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "sparc64"
967_prebuild_libs+= lib/libc_r
968.else
969_prebuild_libs+= lib/libpthread
970.endif
971.endif
972
973_generic_libs+=	lib
974
975.if !defined(NO_CRYPT)
976.if !defined(NO_OPENSSL)
977_prebuild_libs+=	secure/lib/libcrypto secure/lib/libssl
978lib/libradius__L: secure/lib/libssl__L
979secure/lib/libssl__L: secure/lib/libcrypto__L
980.if !defined(NO_OPENSSH)
981_prebuild_libs+=	secure/lib/libssh
982secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
983.if !defined(NO_KERBEROS)
984secure/lib/libssh__L: kerberos5/lib/libgssapi__L kerberos5/lib/libkrb5__L \
985    kerberos5/lib/libasn1__L lib/libcom_err__L lib/libmd__L \
986    kerberos5/lib/libroken__L
987.endif
988.endif
989.endif
990_generic_libs+=	secure/lib
991.endif
992
993.if defined(NO_CRYPT) || defined(NO_OPENSSL)
994lib/libradius__L: lib/libmd__L
995.endif
996
997.if !defined(NO_NIS)
998_prebuild_libs+=	lib/libypclnt
999.endif
1000
1001_generic_libs+=	usr.bin/lex/lib
1002
1003.if ${MACHINE_ARCH} == "i386"
1004_generic_libs+=	usr.sbin/pcvt/keycap
1005.endif
1006
1007.for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1008${_lib}__L: .PHONY
1009.if exists(${.CURDIR}/${_lib})
1010	${_+_}@${ECHODIR} "===> ${_lib} (depend,all,install)"; \
1011		cd ${.CURDIR}/${_lib}; \
1012		${MAKE} DIRPRFX=${_lib}/ depend; \
1013		${MAKE} DIRPRFX=${_lib}/ all; \
1014		${MAKE} DIRPRFX=${_lib}/ install
1015.endif
1016.endfor
1017
1018# libpam is special: we need to build static PAM modules before
1019# static PAM library, and dynamic PAM library before dynamic PAM
1020# modules.
1021lib/libpam__L: .PHONY
1022	${_+_}@${ECHODIR} "===> lib/libpam (depend,all,install)"; \
1023		cd ${.CURDIR}/lib/libpam; \
1024		${MAKE} DIRPRFX=lib/libpam/ depend; \
1025		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1026		${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1027
1028_startup_libs: ${_startup_libs:S/$/__L/}
1029_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1030_generic_libs: ${_generic_libs:S/$/__L/}
1031
1032.for __target in all clean cleandepend cleandir depend includes obj
1033.for entry in ${SUBDIR}
1034${entry}.${__target}__D: .PHONY
1035	${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1036		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1037		edir=${entry}.${MACHINE_ARCH}; \
1038		cd ${.CURDIR}/$${edir}; \
1039	else \
1040		${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1041		edir=${entry}; \
1042		cd ${.CURDIR}/$${edir}; \
1043	fi; \
1044	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1045.endfor
1046par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1047.endfor
1048
1049.include <bsd.subdir.mk>
1050