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