Makefile revision 1.326
1#	$NetBSD: Makefile,v 1.326 2006/05/30 00:40:22 christos Exp $
2#	from: @(#)Makefile	8.7 (Berkeley) 5/25/95
3
4# Environment variables without default values:
5#   DESTDIR must be set before anything in this file will work.
6#   RELEASEDIR is where the tarred up stuff for a snapshot or
7#	release will be placed.
8#
9# Environment variables with default values:
10#   LOCALTIME will set the default local time for the system you
11#	build; it determines what /etc/localtime is symlink'd to.
12#   KERNSRCDIR points to kernel source; it is set by default to ../sys,
13#	but can be overridden.
14#   KERNOBJDIR is the kernel build directory, it defaults to
15#	${KERNSRCDIR}/arch/${MACHINE}/compile, but can be overridden.
16#   KERNCONFDIR is where the configuration files for kernels are found;
17#	default is ${KERNSRCDIR}/arch/${MACHINE}/conf but can be overridden.
18#   MKCRYPTO; if not `no', install crypto-related configuration
19#   MKPOSTFIX; if not `no', install postfix configuration
20#   MKUNPRIVED; if not `no', allow non-root installs.
21#   MKUPDATE; if not `no', don't do a 'make clean' before kernel compile
22#
23# Targets:
24#    distribution: makes a full NetBSD distribution in DESTDIR. If
25#	INSTALL_DONE is set, it will not do a `make install.'
26#	if DISTRIBUTION_DONE is set, it will not do anything.
27#    distrib-dirs: creates an empty NetBSD directory tree in DESTDIR.
28#	Called by distribution.
29#    snapshot: calls distribution, above, and then tars up the files
30#	into a release(7) format in RELEASEDIR/${RELEASEMACHINEDIR}.
31#	Any port-dependent stuff for this target is found in
32#	etc.${MACHINE}/Makefile.inc.
33#    release: a synonym for `snapshot'
34#
35
36# For MK* vars
37.include <bsd.own.mk>
38
39.include <bsd.sys.mk>		# for HOST_SH
40.include <bsd.kernobj.mk>	# For KERNSRCDIR, KERNOBJDIR, ...
41.include <bsd.endian.mk>	# For TARGET_ENDIANNESS
42
43.MAKEOVERRIDES+=	USETOOLS
44
45TZDIR=		/usr/share/zoneinfo
46LOCALTIME?=	UTC
47CKSUM?=		${TOOL_CKSUM}
48MAKESUMS=	CKSUM=${CKSUM:Q} ${HOST_SH} ${NETBSDSRCDIR}/distrib/sets/makesums
49DISTRIBVER!=	${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh
50
51# Flags for creating ISO CDROM image
52# mkisofs is expected to be in $PATH, install via pkgsrc/sysutils/cdrtools
53# Note: At least mkisofs 2.0 should be used.
54#
55MKISOFS?=	mkisofs
56DISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
57# ISO 9660 volume ID.  Note that this can only contain [A-Z0-9_].
58ISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
59MKISOFS_FLAGS+= -J -l -hide-joliet-trans-tbl -r -T \
60		-V ${ISO_VOLID} \
61		-P "The NetBSD Project" \
62		-m "${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/cdrom"
63.if ${MKISOFS_FLAGS:N-v}
64MKISOFS_FLAGS+=	-quiet
65.endif
66 
67
68# MD Makefile.inc may append MD targets to BIN[123].  Make sure all
69# are empty, to preserve the old semantics of setting them below with "+=".
70#
71BIN1=
72BIN2=
73BIN3=
74
75# Directories to build in ${RELEASEDIR}/${RELEASEMACHINEDIR}.
76# MD Makefile.inc files can add to this.
77# NOTE: Parent directories must be listed before subdirectories.
78#
79INSTALLATION_DIRS=	binary binary/sets binary/kernel installation
80
81.if exists(etc.${RELEASEMACHINE}/Makefile.inc)
82.include "etc.${RELEASEMACHINE}/Makefile.inc"
83.endif
84
85# -rw-r--r--
86BINOWN= root
87BINGRP= wheel
88UTMPGRP= utmp
89BIN1+=	bootptab changelist csh.cshrc csh.login csh.logout daily \
90	daily.conf dm.conf floppytab ftpchroot ftpusers \
91	gettytab group hosts hosts.lpd inetd.conf lkm.conf locate.conf \
92	mailer.conf man.conf monthly monthly.conf mrouted.conf named.conf \
93	netconfig networks newsyslog.conf nsswitch.conf ntp.conf \
94	passwd.conf phones printcap profile protocols \
95	rbootd.conf rc rc.conf rc.lkm rc.local rc.subr rc.shutdown remote rpc \
96	security security.conf services shells sysctl.conf syslog.conf \
97	weekly weekly.conf wscons.conf
98
99# Use machine-specific disktab if it exists, or the MI one otherwise
100.if exists(etc.${MACHINE}/disktab)
101BIN1+=	etc.${MACHINE}/disktab
102.else
103BIN1+=	disktab
104.endif
105
106.if exists(etc.${MACHINE}/ld.so.conf)
107BIN1+=	etc.${MACHINE}/ld.so.conf
108.endif
109
110.if exists(etc.${MACHINE}/ttyaction)
111BIN1+=	etc.${MACHINE}/ttyaction
112.endif
113
114# -rw-rw-r--
115BIN2+=	motd
116
117# -rw-------
118BIN3+=	hosts.equiv
119
120SYSPKG=	etc
121ETC_PKG=-T etc_pkg
122BASE_PKG=-T base_pkg
123ETC_INSTALL_FILE=cd ${.CURDIR} && ${INSTALL_FILE} ${ETC_PKG}
124ETC_INSTALL_OBJ_FILE=cd ${.OBJDIR} && ${INSTALL_FILE} ${ETC_PKG}
125
126.if ${TARGET_ENDIANNESS} == "1234"
127PWD_MKDB_ENDIAN=	-L
128.elif ${TARGET_ENDIANNESS} == "4321"
129PWD_MKDB_ENDIAN=	-B
130.else
131PWD_MKDB_ENDIAN=
132.endif
133
134
135# distribution --
136#	Build a distribution
137#
138distribution: .PHONY .MAKE check_DESTDIR distrib-dirs
139.if !defined(DISTRIBUTION_DONE)
140.if !defined(INSTALL_DONE)
141	${MAKEDIRTARGET} ${NETBSDSRCDIR} include _DISTRIB=
142	${MAKEDIRTARGET} ${NETBSDSRCDIR} install _DISTRIB=
143.endif	# !INSTALL_DONE
144	${MAKEDIRTARGET} . install-etc-files
145.if ${MKX11} != "no"
146	${MAKEDIRTARGET} ${NETBSDSRCDIR}/x11 distribution
147.endif
148	${MAKEDIRTARGET} ${NETBSDSRCDIR}/distrib/sets makesetfiles
149.endif	# !DISTRIBUTION_DONE
150
151
152CLEANFILES+=	MAKEDEV
153MAKEDEV: .EXEC
154	${_MKTARGET_CREATE}
155	MACHINE=${MACHINE:Q} MACHINE_ARCH=${MACHINE_ARCH:Q} \
156	    NETBSDSRCDIR=${NETBSDSRCDIR:Q} \
157	    awk -f ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl > ${.TARGET}
158
159RELEASEVARS=	BSDOBJDIR BSDSRCDIR BUILDID \
160		DESTDIR EXTERNAL_TOOLCHAIN \
161		INSTALLWORLDDIR \
162		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
163		MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
164		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
165		MKBFD MKCATPAGES \
166		MKCRYPTO MKCRYPTO_IDEA MKCRYPTO_MDC2 MKCRYPTO_RC5 MKCVS \
167		MKDOC MKDYNAMICROOT MKGCC MKGCCCMDS MKGDB \
168		MKHESIOD MKHOSTOBJ MKHTML MKIEEEFP MKINET6 MKINFO MKIPFILTER \
169		MKKERBEROS MKLINKLIB MKLINT \
170		MKMAN MKMANZ MKNLS MKOBJ MKOBJDIRS \
171		MKPAM MKPF MKPIC MKPICINSTALL MKPICLIB MKPOSTFIX MKPROFILE \
172		MKSHARE MKSKEY MKSOFTFLOAT MKSTATICLIB \
173		MKUNPRIVED MKUPDATE MKUUCP MKX11 MKYP \
174		NBUILDJOBS NETBSDSRCDIR \
175		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
176		OBJMACHINE \
177		RELEASEDIR TOOLCHAIN_MISSING TOOLDIR \
178		USETOOLS USR_OBJMACHINE \
179		X11SRCDIR
180
181params: .PHONY
182.for var in ${RELEASEVARS}
183.if defined(${var})
184	@printf "%20s = '%-s'\n" ${var} ${${var}:Q}
185.else
186	@printf "%20s = (undefined)\n" ${var}
187.endif
188.endfor
189
190CLEANFILES+=	etc-release
191etc-release: .EXEC .MAKE
192	${_MKTARGET_CREATE}
193	@(	echo "NetBSD ${DISTRIBVER}/${MACHINE}"; \
194		echo ; \
195		cat ${NETBSDSRCDIR}/sys/conf/copyright; \
196		echo ; \
197		echo "Build settings:"; \
198		printf "%20s   %s\n"  "Build date" "$$(date -u)"; \
199		printf "%20s   %s\n"  "Built by" "$${USER-root}@$$(hostname)"; \
200		echo ; \
201		(cd ${.CURDIR}; ${MAKE} ${MFLAGS} -j1 params); \
202	) >${.OBJDIR}/${.TARGET}
203
204install-etc-release: .PHONY etc-release
205	${_MKMSG_INSTALL} etc/release
206	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 444 \
207	    etc-release ${DESTDIR}/etc/release
208
209
210FILESDIR=		/etc
211CONFIGFILES=
212CONFIGSYMLINKS=
213
214.for file in ${BIN1}
215CONFIGFILES+=		${file}
216FILESMODE_${file:T}=	644
217.endfor
218
219.for file in ${BIN2}
220CONFIGFILES+=		${file}
221FILESMODE_${file:T}=	664
222.endfor
223
224.for file in ${BIN3}
225CONFIGFILES+=		${file}
226FILESMODE_${file:T}=	600
227.endfor
228
229CONFIGFILES+=		aliases
230FILESDIR_aliases=	/etc/mail
231FILESMODE_aliases=	644
232
233CONFIGFILES+=		MAKEDEV.local
234FILESDIR_MAKEDEV.local=	/dev
235FILESMODE_MAKEDEV.local=${BINMODE}
236
237CONFIGFILES+=		crontab
238FILESDIR_crontab=	/var/cron/tabs
239FILESNAME_crontab=	root
240FILESMODE_crontab=	600
241
242CONFIGFILES+=		minfree
243FILESDIR_minfree=	/var/crash
244FILESMODE_minfree=	600
245
246CONFIGSYMLINKS+=	${TZDIR}/${LOCALTIME}	/etc/localtime \
247			/usr/sbin/rmt		/etc/rmt
248
249
250# install-etc-files --
251#	Install etc (config) files; not performed by "make build"
252#
253install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV
254	${_MKMSG_INSTALL} ${DESTDIR}/etc/master.passwd
255	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
256	    master.passwd ${DESTDIR}/etc
257	${TOOL_PWD_MKDB} -p ${PWD_MKDB_ENDIAN} -d ${DESTDIR}/ \
258	    ${DESTDIR}/etc/master.passwd
259.if ${MKUNPRIVED} != "no"
260	( \
261		for metaent in passwd pwd.db spwd.db; do \
262	    		echo "./etc/$${metaent} type=file mode=0644 uname=root gname=wheel tags=etc_pkg"; \
263		done; \
264	) | ${METALOG.add}
265.endif	# MKUNPRIVED != no
266	${_MKMSG_INSTALL} ${DESTDIR}/etc/ttys
267	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
268	    ${.CURDIR}/etc.${MACHINE}/ttys ${DESTDIR}/etc
269	${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV
270	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
271	    MAKEDEV ${DESTDIR}/dev
272.for owner group mode file in \
273		${BINOWN} operator	664	/etc/dumpdates  \
274		${BINOWN} ${BINGRP}	644	/etc/mail/local-host-names \
275		${BINOWN} operator	600	/etc/skeykeys \
276		root wheel		600	/var/at/at.deny \
277		nobody ${BINGRP}	664	/var/db/locate.database \
278		uucp dialer		640	/var/log/aculog \
279		${BINOWN} ${BINGRP}	600	/var/log/authlog \
280		root wheel		600	/var/log/cron \
281		${BINOWN} ${UTMPGRP}	664	/var/log/lastlog \
282		${BINOWN} ${UTMPGRP}	664	/var/log/lastlogx \
283		${BINOWN} ${BINGRP}	640	/var/log/lpd-errs \
284		${BINOWN} ${BINGRP}	600	/var/log/maillog \
285		${BINOWN} ${BINGRP}	644	/var/log/messages \
286		${BINOWN} ${BINGRP}	600	/var/log/secure \
287		${BINOWN} ${UTMPGRP}	664	/var/log/wtmp \
288		${BINOWN} ${UTMPGRP}	664	/var/log/wtmpx \
289		${BINOWN} ${BINGRP}	600	/var/log/xferlog \
290		daemon staff		664	/var/msgs/bounds \
291		${BINOWN} ${UTMPGRP}	664	/var/run/utmp \
292		${BINOWN} ${UTMPGRP}	664	/var/run/utmpx \
293		games games		664	/var/games/atc_score \
294		games games		664	/var/games/battlestar.log \
295		games games		664	/var/games/cfscores \
296		games games		664	/var/games/criblog \
297		games games		660	/var/games/hackdir/perm \
298		games games		660	/var/games/hackdir/record \
299		games games		664	/var/games/larn/llog12.0 \
300		games games		664	/var/games/larn/lscore12.0 \
301		games games		664	/var/games/larn/playerids \
302		games games		664	/var/games/robots_roll \
303		games games		664	/var/games/rogue.scores \
304		games games		664	/var/games/saillog \
305		games games		664	/var/games/snakerawscores \
306		games games		664	/var/games/snake.log \
307		games games		664	/var/games/tetris.scores
308	${_MKMSG_INSTALL} ${DESTDIR}${file}
309	${ETC_INSTALL_FILE} -o ${owner} -g ${group} -m ${mode} \
310	    	/dev/null ${DESTDIR}${file}
311.endfor
312.for subdir in . defaults iscsi mtree namedb pam.d powerd rc.d root skel ssh
313	${MAKEDIRTARGET} ${subdir} configinstall
314.endfor
315	${MAKEDIRTARGET} ${NETBSDSRCDIR}/usr.bin/mail configinstall
316.if (${MKPF} != "no")
317	${MAKEDIRTARGET} ${NETBSDSRCDIR}/usr.sbin/pf configinstall
318.endif
319.if (${MKCRYPTO} != "no")
320	${MAKEDIRTARGET} ${NETBSDSRCDIR}/usr.bin/ssh configinstall
321.endif
322.if (${MKPOSTFIX} != "no")
323	${MAKEDIRTARGET} ${NETBSDSRCDIR}/gnu/usr.sbin/postfix configinstall
324.endif
325
326
327# install-obsolete-lists --
328#	Install var/db/obsolete set lists; this is performed by "make build"
329#
330OBSOLETE.dir=		${.OBJDIR}/obsolete.dir
331OBSOLETE.files=		base comp etc games man misc text
332.if ${MKX11} != "no"
333OBSOLETE.files+=	xbase xcomp xetc xfont xserver
334.endif
335
336install-obsolete-lists: .PHONY .MAKE
337	mkdir -p ${OBSOLETE.dir}
338.if ${MKX11} != "no"
339	(cd ${NETBSDSRCDIR}/distrib/sets && \
340	    MAKE=${MAKE:Q} ${HOST_SH} ./makeobsolete -b -t ${OBSOLETE.dir})
341.else
342	(cd ${NETBSDSRCDIR}/distrib/sets && \
343	    MAKE=${MAKE:Q} ${HOST_SH} ./makeobsolete -t ${OBSOLETE.dir})
344.endif
345.for file in ${OBSOLETE.files}
346	${_MKMSG_INSTALL} ${DESTDIR}/var/db/obsolete/${file}
347	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
348	    ${OBSOLETE.dir}/${file} ${DESTDIR}/var/db/obsolete
349.endfor
350
351
352# distrib-dirs --
353#	Populate $DESTDIR with directories needed by NetBSD
354#
355.if ${MKUNPRIVED} == "no"
356TOOL_MTREE.unpriv=
357.else
358TOOL_MTREE.unpriv=	-W
359.endif
360
361distrib-dirs: .PHONY check_DESTDIR
362.if !defined(DISTRIBUTION_DONE)						# {
363# XXX: If METALOG=${DESTDIR}/METALOG (as is normal), and if ${DESTDIR}
364# does not yet exist (as often happens), then the INSTALL_DIR command
365# immediately below will create ${DESTDIR} but will fail to register
366# an entry for "." in the metalog.  We ignore the problem, because the
367# TOOL_MTREE commands a little further below will soon register an entry
368# for "." in the metalog.
369	${INSTALL_DIR} -o root -g wheel -m 755 ${BASE_PKG} ${DESTDIR}
370# XXX: It would be nice if a single mtree invocation could both
371# append to the metalog and do real work.  Instead, we have to
372# repeat the command twice in slightly different ways.
373	${TOOL_MTREE} -def ${.CURDIR}/mtree/NetBSD.dist -N ${.CURDIR} \
374	    -p ${DESTDIR}/ -U ${TOOL_MTREE.unpriv}
375.if ${MKUNPRIVED} != "no"						# {
376	${TOOL_MTREE} -def ${.CURDIR}/mtree/NetBSD.dist -N ${.CURDIR} \
377	    -p ${DESTDIR}/ -C -k all | \
378	    awk '/ optional/ {next} // {print}' | ${METALOG.add}
379.endif	# MKUNPRIVED							# }
380.endif	# DISTRIBUTION_DONE						# }
381
382# release, snapshot --
383#	Build a full distribution including kernels & install media.
384#
385release snapshot: .PHONY .MAKE check_DESTDIR check_RELEASEDIR snap_md_post
386	${MAKEDIRTARGET} ${NETBSDSRCDIR}/distrib/sets sets
387	${MAKESUMS} -A -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets \
388		${KERNEL_SETS:@.SETS.@kern-${.SETS.}.tgz@}
389	${MAKESUMS} -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel '*.gz'
390
391
392# iso-image --
393#	Standalone target to create a CDROM image after the release
394#	was composed.  Should be run after "make release" in src and xsrc.
395#
396#	Note: At least mkisofs 2.0 should be used.
397#
398CDROM_NAME_ADD?=
399CDROM.image=${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/cdrom/netbsd-${MACHINE}${CDROM_NAME_ADD}.iso
400CDROM.dir=	${.OBJDIR}/cdrom.dir
401CDROM.pathlist=	${.OBJDIR}/cdrom.pathlist
402
403iso-image: .PHONY check_DESTDIR check_RELEASEDIR iso-image-md-post
404	${MAKESUMS} -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/cdrom '*.iso'
405	@echo "iso-image created as: ${CDROM.image}"
406
407iso-image-setup: .PHONY check_RELEASEDIR
408	rm -f ${CDROM.pathlist}
409.for extra in README SOURCE_DATE source
410.if exists(${RELEASEDIR}/${extra})
411	echo "${extra}=${RELEASEDIR}/${extra}" >> ${CDROM.pathlist}
412.endif
413.endfor
414	echo "${MACHINE}=${RELEASEDIR}/${RELEASEMACHINEDIR}" >> ${CDROM.pathlist}
415	mkdir -p ${CDROM.dir}
416	mkdir -p ${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/cdrom
417
418# iso-image-mi --
419#	Create the image after the MD operations have completed.
420#
421iso-image-mi: .PHONY check_DESTDIR check_RELEASEDIR iso-image-md-pre
422	@if ! ${MKISOFS} --version; then \
423		echo "install pkgsrc/sysutils/cdrtools and run 'make iso-image'." ; \
424		false; \
425	fi
426	${MKISOFS} ${MKISOFS_FLAGS} -graft-points -path-list ${CDROM.pathlist} \
427	    -o ${CDROM.image} ${CDROM.dir}
428
429# iso-image-md-pre --
430#	Setup ${CDROM.dir} to produce a bootable CD image.
431#	Overridden by etc.$MACHINE/Makefile.inc
432#
433iso-image-md-pre: .PHONY check_DESTDIR check_RELEASEDIR iso-image-setup
434#	(empty -- look in the machine-dependent Makefile.inc)
435
436# iso-image-md-post --
437#	Fixup the CD-image to be bootable.
438#	Overridden by etc.$MACHINE/Makefile.inc
439#
440iso-image-md-post: .PHONY check_DESTDIR check_RELEASEDIR iso-image-mi
441#	(empty -- look in the machine-dependent Makefile.inc)
442
443
444# snap_pre --
445#	Create ${RELEASEDIR} and necessary subdirectories.
446#
447snap_pre: .PHONY check_DESTDIR check_RELEASEDIR distribution
448	${INSTALL} -d -m 755 ${RELEASEDIR}
449.if ${MKUPDATE} == "no"
450# Could be a mount point, ignore the errors
451	-/bin/rm -rf ${RELEASEDIR}/${RELEASEMACHINEDIR}
452.endif
453	${INSTALL} -d -m 755 ${RELEASEDIR}/${RELEASEMACHINEDIR}
454.for dir in ${INSTALLATION_DIRS}
455	${INSTALL} -d -m 755 ${RELEASEDIR}/${RELEASEMACHINEDIR}/${dir}
456.endfor
457
458# snap_post --
459#	Build the install media and notes from distrib
460#
461snap_post: .PHONY .MAKE build_kernelsets build_releasekernels
462.if ${MKUPDATE} == "no"
463	cd ${NETBSDSRCDIR}/distrib && ${MAKE} cleandir
464.endif
465	cd ${NETBSDSRCDIR}/distrib && ${MAKE} depend && ${MAKE} && \
466	    ${MAKE} release
467
468# build kernels --
469#	This target builds the kernels specified by each port.
470#	A port may specify the following kernels:
471#
472#	KERNEL_SETS		The list of kernels that will be
473#				packaged into sets, named
474#				kern-${kernel}.tgz.  These kernels
475#				are also placed in the binary/kernel
476#				area of the release package as
477#				netbsd-${kernel}.gz.
478#
479#	EXTRA_KERNELS		Additional kernels to place in the
480#				binary/kernel area of the release
481#				package as netbsd-${kernel}.gz, but
482#				which are not placed into sets. This
483#				allows a port to provide e.g. a netbootable
484#				installation kernel containing a ramdisk.
485#
486#	BUILD_KERNELS		Additional kernels to build which are
487#				not placed into sets nor into the
488#				binary/kernel area of the release
489#				package.  These are typically kernels
490#				that are built for inclusion only in
491#				installation disk/CD-ROM/tape images.
492#
493#	A port may also specify KERNEL_SUFFIXES, which is an optional list
494#	of filename suffixes for kernels to include in the kernel sets and
495#	in the binary/kernel area of the release package (e.g. "netbsd" vs.
496#	"netbsd.ecoff" and "netbsd.srec").  It is not an error if kernels
497#	with these suffixes do not exist in the kernel build directory.
498#
499#
500# A list of all the kernels to build, which can be overridden from
501# external sources (such as make(1)'s environment or command line)
502#
503ALL_KERNELS?=	${KERNEL_SETS} ${EXTRA_KERNELS} ${BUILD_KERNELS}
504
505GETKERNELAWK=	awk '/^config/ {print $$2; found=1} \
506		END{ if (found == 0) print "netbsd"; }'
507
508build_kernels: .PHONY
509#	Configure & compile kernels listed in ${ALL_KERNELS}
510#
511# The 'sync' is so that all writes during the build are pushed back
512# to the disk.  Not having it causes problems on some host systems
513# (e.g. Linux) when building on NFS.
514#
515.if !defined(KERNELS_DONE)						# {
516.for configfile in ${ALL_KERNELS}					# {
517build_kernels: kern-${configfile}
518kern-${configfile}: .PHONY .MAKE
519	cd ${KERNCONFDIR} && ${TOOL_CONFIG} -s ${KERNSRCDIR} \
520	    -b ${KERNOBJDIR}/${configfile:C/.*\///} ${configfile}
521.if ${MKUPDATE} == "no"
522	cd ${KERNOBJDIR}/${configfile:C/.*\///} && ${MAKE} distclean
523.endif
524	cd ${KERNOBJDIR}/${configfile:C/.*\///} && ${MAKE} depend && ${MAKE}
525	sync
526.endfor	# ALL_KERNELS							# }
527.endif	# KERNELS_DONE							# }
528
529build_kernelsets: .PHONY
530#	Create kernel sets from ${KERNEL_SETS} into
531#	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
532#
533.for configfile in ${KERNEL_SETS}					# {
534build_kernelsets: kernset-${configfile}
535kernset-${configfile}: .PHONY build_kernels snap_pre
536	@ kernlist=`${GETKERNELAWK} ${KERNCONFDIR}/${configfile}`; \
537	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
538	kernsuffixes="${KERNEL_SUFFIXES:S/^/./}"; \
539	kern_tgz=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets/kern-${configfile}.tgz; \
540	pax_cmd="GZIP=-9 ${TOOL_PAX} -O -zw -M -N ${NETBSDSRCDIR}/etc -f $${kern_tgz}"; \
541	cd $${kerndir} && { \
542		kernels=; newest=; \
543		for kernel in $${kernlist}; do \
544			for s in "" $${kernsuffixes}; do \
545				ks="$${kernel}$${s}"; \
546				[ -f $${ks} ] || continue; \
547				kernels="$${kernels} $${ks}"; \
548				[ -z "$${newest}" -o $${ks} -nt "$${newest}" ] && \
549					newest=$${ks}; \
550			done; \
551		done; \
552		[ $${kern_tgz} -nt "$${newest}" ] || { \
553			echo "echo $${kernels} | $${pax_cmd}"; \
554			( echo "/set uname=${BINOWN} gname=${BINGRP}"; \
555			echo ". type=dir optional"; \
556			for kernel in $${kernels}; do \
557				echo "./$${kernel} type=file"; \
558			done ) | eval $${pax_cmd}; \
559		} \
560	}
561.endfor	# KERNEL_SETS							# }
562
563build_releasekernels: .PHONY
564#	Build kernel.gz from ${KERNEL_SETS} ${EXTRA_KERNELS} into
565#	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel
566#
567.for configfile in ${KERNEL_SETS} ${EXTRA_KERNELS}			# {
568build_releasekernels: releasekern-${configfile}
569releasekern-${configfile}: .PHONY build_kernels snap_pre
570	@ kernlist=`${GETKERNELAWK} ${KERNCONFDIR}/${configfile:C/.*\///}`; \
571	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
572	kernsuffixes="${KERNEL_SUFFIXES:S/^/./}"; \
573	cd $${kerndir} && {	\
574		for kernel in $${kernlist}; do \
575			for s in "" $${kernsuffixes}; do \
576				ks="$${kernel}$${s}"; \
577				[ ! -f $${ks} ] && continue; \
578				knl_gz="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel/$${ks}-${configfile:C/.*\///}.gz"; \
579				[ $${knl_gz} -nt $${ks} ] && continue; \
580				echo "gzip -c -9 < $${kerndir}/$${ks} > $${knl_gz}"; \
581				gzip -c -9 < $${ks} > $${knl_gz}; \
582			done; \
583		done; \
584	}
585.endfor	# KERNEL_SETS EXTRA_KERNELS					# }
586
587# snap_md_post --
588#	Machine dependent distribution media operations.
589#	Overridden by etc.$MACHINE/Makefile.inc
590#
591snap_md_post: .PHONY check_DESTDIR check_RELEASEDIR snap_post
592#	(empty -- look in the machine-dependent Makefile.inc)
593
594
595clean:
596	-rm -rf ${CDROM.dir} ${CDROM.pathlist} ${OBSOLETE.dir}
597
598.include <bsd.prog.mk>
599
600test:
601	@echo ${OBSOLETE.files}
602