Makefile revision 1.268
1#	$NetBSD: Makefile,v 1.268 2004/01/05 00:12:01 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#   MKUPDATE; if not `no', don't do a 'make clean' before kernel compile
19#   NO_SENDMAIL is normally undefined; if defined, it will not do a
20#	`make distribution' in the sendmail config file source directory.
21#
22# Targets:
23#    distribution: makes a full NetBSD distribution in DESTDIR. If
24#	INSTALL_DONE is set, it will not do a `make install.'
25#	if DISTRIBUTION_DONE is set, it will not do anything.
26#    distrib-dirs: creates an empty NetBSD directory tree in DESTDIR.
27#	Called by distribution.
28#    snapshot: calls distribution, above, and then tars up the files
29#	into a release(7) format in RELEASEDIR/${MACHINE}.
30#	Any port-dependent stuff for this target is found in
31#	etc.${MACHINE}/Makefile.inc.
32#    release: a synonym for `snapshot'
33#
34
35# For NO_SENDMAIL, INSTPRIV, MKCRYPTO
36#
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 release-info
150CLEANFILES+=	MAKEDEV release-info
151
152MAKEDEV:
153	${_MKTARGET_CREATE}
154	MACHINE=${MACHINE:Q} MACHINE_ARCH=${MACHINE_ARCH:Q} \
155	    NETBSDSRCDIR=${NETBSDSRCDIR:Q} \
156	    awk -f ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl > ${.TARGET}
157
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		MKCATPAGES MKCRYPTO MKDOC MKHOSTOBJ MKINFO \
166		MKLINT MKMAN MKNLS MKOBJ MKOBJDIRS \
167		MKPIC MKPICINSTALL MKPROFILE MKSHARE \
168		MKUNPRIVED MKUPDATE \
169		NBUILDJOBS \
170		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
171		RELEASEDIR TOOLCHAIN_MISSING TOOLDIR USETOOLS
172
173release-info:
174	${_MKTARGET_CREATE}
175	@(	echo "NetBSD ${DISTRIBVER}/${MACHINE}"; \
176		echo "	$$(date -u)  $${USER-root}@$$(hostname)"; \
177		echo ; \
178		echo "Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004" ; \
179		echo "	The NetBSD Foundation, Inc.  All rights reserved."; \
180		echo "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994"; \
181		echo "	The Regents of the University of California.  All rights reserved."; \
182		echo ; \
183		echo "Build settings:"; \
184	) >${.TARGET}
185.for var in ${RELEASEVARS}
186.if defined(${var})
187	@printf "%20s = '%-s'\n" ${var} ${${var}:Q} >> ${.TARGET}
188.else
189	@printf "%20s = (undefined)\n" ${var} >> ${.TARGET}
190.endif
191.endfor
192
193install-release-info: release-info
194	${_MKMSG_INSTALL} etc/release-info
195	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 444 \
196	    release-info ${DESTDIR}/etc/release
197
198# install-etc-files --
199#	Install etc (config) files; not performed by "make build"
200#
201install-etc-files: check_DESTDIR MAKEDEV
202	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
203	    ${BIN1} ${DESTDIR}/etc
204	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 664 \
205	    ${BIN2} ${DESTDIR}/etc
206	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 \
207	    ${BIN3} ${DESTDIR}/etc
208	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
209	    aliases ${DESTDIR}/etc/mail
210	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
211	    /dev/null ${DESTDIR}/etc/mail/local-host-names
212	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
213	    crontab ${DESTDIR}/var/cron/tabs/root
214	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
215	    master.passwd ${DESTDIR}/etc
216	${TOOL_PWD_MKDB} -p ${PWD_MKDB_ENDIAN} -d ${DESTDIR}/ \
217	    ${DESTDIR}/etc/master.passwd
218.if ${MKUNPRIVED} != "no"
219	( \
220		for metaent in passwd pwd.db spwd.db; do \
221	    		echo "./etc/$${metaent} type=file mode=0644 uname=root gname=wheel tags=etc_pkg"; \
222		done; \
223	) | ${METALOG.add}
224.endif	# MKUNPRIVED != no
225	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
226	    MAKEDEV ${DESTDIR}/dev
227	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
228	    MAKEDEV.local ${DESTDIR}/dev
229	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
230	    minfree ${DESTDIR}/var/crash
231.for file in cshrc login profile shrc
232	${ETC_INSTALL_FILE} -o root -g wheel -m 644 \
233	    root/dot.${file} ${DESTDIR}/root/.${file}
234.endfor
235	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
236	    root/dot.klogin ${DESTDIR}/root/.klogin
237	rm -f ${DESTDIR}/.cshrc ${DESTDIR}/.profile
238	${ETC_INSTALL_LINK} ${DESTDIR}/root/.cshrc ${DESTDIR}/.cshrc
239	${ETC_INSTALL_LINK} ${DESTDIR}/root/.profile ${DESTDIR}/.profile
240	(cd ${.CURDIR}/defaults; ${MAKE} install)
241	(cd ${.CURDIR}/mtree; ${MAKE} install)
242.for file in ${NAMEDB}
243	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
244	    namedb/${file} ${DESTDIR}/etc/namedb
245.endfor
246	(cd ${.CURDIR}/powerd; ${MAKE} install)
247	(cd ${.CURDIR}/rc.d; ${MAKE} install)
248	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
249	    postinstall ${DESTDIR}/etc
250	${ETC_INSTALL_SYMLINK} -o root -g wheel -m 755 \
251	    ${TZDIR}/${LOCALTIME} ${DESTDIR}/etc/localtime
252	${ETC_INSTALL_SYMLINK} -o root -g wheel -m 755 \
253	    /usr/sbin/rmt ${DESTDIR}/etc/rmt
254	${ETC_INSTALL_FILE} -o ${BINOWN} -g operator -m 664 \
255	    /dev/null ${DESTDIR}/etc/dumpdates
256	${ETC_INSTALL_FILE} -o ${BINOWN} -g operator -m 600 \
257	    /dev/null ${DESTDIR}/etc/skeykeys
258	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
259	    /dev/null ${DESTDIR}/var/at/at.deny
260	${ETC_INSTALL_FILE} -o nobody -g ${BINGRP} -m 664 \
261	    /dev/null ${DESTDIR}/var/db/locate.database
262	${ETC_INSTALL_FILE} -o uucp -g dialer -m 640 \
263	    /dev/null ${DESTDIR}/var/log/aculog
264	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 \
265	    /dev/null ${DESTDIR}/var/log/authlog
266	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
267	    /dev/null ${DESTDIR}/var/log/cron
268	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 664 \
269	    /dev/null ${DESTDIR}/var/log/lastlog
270	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 640 \
271	    /dev/null ${DESTDIR}/var/log/lpd-errs
272	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 \
273	    /dev/null ${DESTDIR}/var/log/maillog
274	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
275	    /dev/null ${DESTDIR}/var/log/messages
276	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 \
277	    /dev/null ${DESTDIR}/var/log/secure
278	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
279	    /dev/null ${DESTDIR}/var/log/sendmail.st
280	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
281	    /dev/null ${DESTDIR}/var/log/wtmp
282	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
283	    /dev/null ${DESTDIR}/var/log/wtmpx
284	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 \
285	    /dev/null ${DESTDIR}/var/log/xferlog
286	${ETC_INSTALL_FILE} -o daemon -g staff -m 664 \
287	    /dev/null ${DESTDIR}/var/msgs/bounds
288	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${UTMPGRP} -m 664 \
289	    /dev/null ${DESTDIR}/var/run/utmp
290	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${UTMPGRP} -m 664 \
291	    /dev/null ${DESTDIR}/var/run/utmpx
292	${ETC_INSTALL_FILE} -o games -g games -m 664 \
293	    /dev/null ${DESTDIR}/var/games/atc_score
294	${ETC_INSTALL_FILE} -o games -g games -m 664 \
295	    /dev/null ${DESTDIR}/var/games/battlestar.log
296	${ETC_INSTALL_FILE} -o games -g games -m 664 \
297	    /dev/null ${DESTDIR}/var/games/cfscores
298	${ETC_INSTALL_FILE} -o games -g games -m 664 \
299	    /dev/null ${DESTDIR}/var/games/criblog
300	${ETC_INSTALL_FILE} -o games -g games -m 660 \
301	    /dev/null ${DESTDIR}/var/games/hackdir/perm
302	${ETC_INSTALL_FILE} -o games -g games -m 660 \
303	    /dev/null ${DESTDIR}/var/games/hackdir/record
304	${ETC_INSTALL_FILE} -o games -g games -m 664 \
305	    /dev/null ${DESTDIR}/var/games/larn/llog12.0
306	${ETC_INSTALL_FILE} -o games -g games -m 664 \
307	    /dev/null ${DESTDIR}/var/games/larn/lscore12.0
308	${ETC_INSTALL_FILE} -o games -g games -m 664 \
309	    /dev/null ${DESTDIR}/var/games/larn/playerids
310	${ETC_INSTALL_FILE} -o games -g games -m 664 \
311	    /dev/null ${DESTDIR}/var/games/robots_roll
312	${ETC_INSTALL_FILE} -o games -g games -m 664 \
313	    /dev/null ${DESTDIR}/var/games/rogue.scores
314	${ETC_INSTALL_FILE} -o games -g games -m 664 \
315	    /dev/null ${DESTDIR}/var/games/saillog
316	${ETC_INSTALL_FILE} -o games -g games -m 664 \
317	    /dev/null ${DESTDIR}/var/games/snakerawscores
318	${ETC_INSTALL_FILE} -o games -g games -m 664 \
319	    /dev/null ${DESTDIR}/var/games/snake.log
320	${ETC_INSTALL_FILE} -o games -g games -m 664 \
321	    /dev/null ${DESTDIR}/var/games/tetris.scores
322	(cd ${.CURDIR}/skel; ${MAKE} distribution)
323	(cd ${NETBSDSRCDIR}/usr.bin/mail; ${MAKE} distribution)
324	(cd ${NETBSDSRCDIR}/gnu/usr.sbin/postfix/; ${MAKE} distribution)
325.if (${MKCRYPTO} != "no")
326	(cd ${NETBSDSRCDIR}/usr.bin/ssh; ${MAKE} distribution)
327.endif
328.if !defined(NO_SENDMAIL) || ${NO_SENDMAIL} == "no"
329	(cd ${NETBSDSRCDIR}/gnu/usr.sbin/sendmail/cf/cf; ${MAKE} distribution)
330.endif
331
332
333# install-obsolete-lists --
334#	Install var/db/obsolete set lists; this is performed by "make build"
335#
336OBSOLETE.dir=		${.OBJDIR}/obsolete.dir
337OBSOLETE.files=		base comp etc games man misc text
338
339install-obsolete-lists:
340	mkdir -p ${OBSOLETE.dir}
341	(cd ${NETBSDSRCDIR}/distrib/sets && \
342	    MAKE=${MAKE:Q} ${HOST_SH} ./makeobsolete -t ${OBSOLETE.dir})
343.for file in ${OBSOLETE.files}
344	${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
345	    ${OBSOLETE.dir}/${file} ${DESTDIR}/var/db/obsolete
346.endfor
347
348
349# distrib-dirs --
350#	Populate $DESTDIR with directories needed by NetBSD
351#
352.if ${MKUNPRIVED} == "no"
353TOOL_MTREE.unpriv=
354.else
355TOOL_MTREE.unpriv=	-W
356.endif
357
358distrib-dirs: check_DESTDIR
359.if !defined(DISTRIBUTION_DONE)
360	${INSTALL_DIR} -o root -g wheel -m 755 ${BASE_PKG} ${DESTDIR}
361.endif
362	${TOOL_MTREE} -def ${.CURDIR}/mtree/NetBSD.dist -N ${.CURDIR} \
363	    -p ${DESTDIR}/ -U ${TOOL_MTREE.unpriv}
364
365
366# release, snapshot --
367#	Build a full distribution including kernels & install media.
368#
369release snapshot: check_DESTDIR check_RELEASEDIR .WAIT \
370		    distribution .WAIT \
371		    snap_pre .WAIT snap_kern .WAIT \
372		    snap_post .WAIT snap_md_post
373	(cd ${NETBSDSRCDIR}/distrib/sets; ${MAKE} sets)
374	${MAKESUMS} -t ${RELEASEDIR}/${MACHINE}/binary/kernel '*.gz'
375
376
377# iso-image --
378#	Standalone target to create a CDROM image after the release
379#	was composed.  Should be run after "make release" in src and xsrc.
380#
381#	Note: At least mkisofs 2.0 should be used.
382#
383CDROM.image=${RELEASEDIR}/${MACHINE}/installation/cdrom/netbsd-${MACHINE}.iso
384CDROM.dir=	cdrom.dir
385CDROM.pathlist=	cdrom.pathlist
386
387iso-image: check_DESTDIR check_RELEASEDIR .WAIT iso-image-md-post
388	${MAKESUMS} -t ${RELEASEDIR}/${MACHINE}/installation/cdrom '*.iso'
389	@echo "iso-image created as: ${CDROM.image}"
390
391iso-image-setup: check_RELEASEDIR
392	rm -f ${CDROM.pathlist}
393	echo "${MACHINE}=${RELEASEDIR}/${MACHINE}" >> ${CDROM.pathlist}
394	mkdir -p ${CDROM.dir}
395	mkdir -p ${RELEASEDIR}/${MACHINE}/installation/cdrom
396
397# iso-image-mi --
398#	Create the image after the MD operations have completed.
399#
400iso-image-mi: check_DESTDIR check_RELEASEDIR .WAIT \
401		iso-image-setup .WAIT iso-image-md-pre
402	@if ! ${MKISOFS} --version; then \
403		echo "install pkgsrc/sysutils/cdrecord and run 'make iso-image'." ; \
404		false; \
405	fi
406	${MKISOFS} ${MKISOFS_FLAGS} -graft-points -path-list ${CDROM.pathlist} \
407	    -o ${CDROM.image} ${CDROM.dir}
408
409# iso-image-md-pre --
410#	Setup ${CDROM.dir} to produce a bootable CD image.
411#	Overridden by etc.$MACHINE/Makefile.inc
412#
413iso-image-md-pre: check_DESTDIR check_RELEASEDIR
414#	(empty -- look in the machine-dependent Makefile.inc)
415
416# iso-image-md-post --
417#	Fixup the CD-image to be bootable.
418#	Overridden by etc.$MACHINE/Makefile.inc
419#
420iso-image-md-post: check_DESTDIR check_RELEASEDIR .WAIT iso-image-mi
421#	(empty -- look in the machine-dependent Makefile.inc)
422
423
424# snap_pre --
425#	Create ${RELEASEDIR} and necessary subdirectories.
426#
427snap_pre: check_DESTDIR check_RELEASEDIR
428	${INSTALL} -d -m 755 ${RELEASEDIR}
429.if ${MKUPDATE} == "no"
430# Could be a mount point, ignore the errors
431	-/bin/rm -rf ${RELEASEDIR}/${MACHINE}
432.endif
433	${INSTALL} -d -m 755 ${RELEASEDIR}/${MACHINE}
434.for dir in ${INSTALLATION_DIRS}
435	${INSTALL} -d -m 755 ${RELEASEDIR}/${MACHINE}/${dir}
436.endfor
437
438# snap_post --
439#	Build the install media and notes from distrib
440#
441snap_post: check_DESTDIR check_RELEASEDIR
442.if ${MKUPDATE} == "no"
443	cd ${NETBSDSRCDIR}/distrib && ${MAKE} cleandir
444.endif
445	cd ${NETBSDSRCDIR}/distrib && ${MAKE} depend && ${MAKE} && \
446	    ${MAKE} release
447
448# snap_kern --
449#	This target builds the kernels specified by each port.
450#	A port may specify the following kernels:
451#
452#	KERNEL_SETS		The list of kernels that will be
453#				packaged into sets, named
454#				kern-${kernel}.tgz.  These kernels
455#				are also placed in the binary/kernel
456#				area of the release package as
457#				netbsd-${kernel}.gz.
458#
459#	EXTRA_KERNELS		Additional kernels to place in the
460#				binary/kernel area of the release
461#				package as netbsd-${kernel}.gz, but
462#				which are not placed into sets. This
463#				allows a port to provide e.g. a netbootable
464#				installation kernel containing a ramdisk.
465#
466#	BUILD_KERNELS		Additional kernels to build which are
467#				not placed into sets nor into the
468#				binary/kernel area of the release
469#				package.  These are typically kernels
470#				that are built for inclusion only in
471#				installation disk/CD-ROM/tape images.
472#
473#	A port may also specify KERNEL_SUFFIXES, which is an optional list
474#	of filename suffixes for kernels to include in the kernel sets and
475#	in the binary/kernel area of the release package (e.g. "netbsd" vs.
476#	"netbsd.ecoff" and "netbsd.srec").  It is not an error if kernels
477#	with these suffixes do not exist in the kernel build directory.
478#
479#
480# A list of all the kernels to build, which can be overridden from
481# external sources (such as make(1)'s environment or command line)
482#
483ALL_KERNELS?=	${KERNEL_SETS} ${EXTRA_KERNELS} ${BUILD_KERNELS}
484
485GETKERNELAWK=	awk '/^config/ {print $$2; found=1} \
486		END{ if (found == 0) print "netbsd"; }'
487
488.if !target(snap_kern)						# {
489
490# build_kernels --
491#	Configure & compile kernels listed in ${ALL_KERNELS}
492#
493.if !defined(KERNELS_DONE)						# {
494.for configfile in ${ALL_KERNELS}					# {
495_KERNELS_TO_BUILD+=kern-${configfile}
496kern-${configfile}:
497	cd ${KERNCONFDIR} && ${TOOL_CONFIG} -s ${KERNSRCDIR} \
498	    -b ${KERNOBJDIR}/${configfile:C/.*\///} ${configfile}
499.if ${MKUPDATE} == "no"
500	cd ${KERNOBJDIR}/${configfile:C/.*\///} && ${MAKE} distclean
501.endif
502	cd ${KERNOBJDIR}/${configfile:C/.*\///} && ${MAKE} depend && ${MAKE}
503.endfor	# ALL_KERNELS							# }
504.endif	# KERNELS_DONE							# }
505
506build_kernels: ${_KERNELS_TO_BUILD}
507
508# build_kernelsets --
509#	Create kernel sets from ${KERNEL_SETS} into
510#	${RELEASEDIR}/${MACHINE}/binary/sets
511#
512.for configfile in ${KERNEL_SETS}					# {
513_KERNELSETS_TO_BUILD+=kernset-${configfile}
514kernset-${configfile}:
515	@ kernlist=`${GETKERNELAWK} ${KERNCONFDIR}/${configfile}`; \
516	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
517	kernsuffixes="${KERNEL_SUFFIXES:S/^/./}"; \
518	kern_tgz=${RELEASEDIR}/${MACHINE}/binary/sets/kern-${configfile}.tgz; \
519	pax_cmd="GZIP=-9 ${TOOL_PAX} -O -zw -M -N ${NETBSDSRCDIR}/etc -f $${kern_tgz}"; \
520	cd $${kerndir} && { \
521		kernels=; newest=; \
522		for kernel in $${kernlist}; do \
523			for s in "" $${kernsuffixes}; do \
524				ks="$${kernel}$${s}"; \
525				[ -f $${ks} ] || continue; \
526				kernels="$${kernels} $${ks}"; \
527				[ -z "$${newest}" -o $${ks} -nt "$${newest}" ] && \
528					newest=$${ks}; \
529			done; \
530		done; \
531		[ $${kern_tgz} -nt "$${newest}" ] || { \
532			echo "echo $${kernels} | $${pax_cmd}"; \
533			( echo "/set uname=${BINOWN} gname=${BINGRP}"; \
534			echo ". type=dir optional"; \
535			for kernel in $${kernels}; do \
536				echo "./$${kernel} type=file"; \
537			done ) | eval $${pax_cmd}; \
538		} \
539	}
540.endfor	# KERNEL_SETS							# }
541
542build_kernelsets: ${_KERNELSETS_TO_BUILD}
543
544# build_releasekernels --
545#	Build kernel.gz from ${KERNEL_SETS} ${EXTRA_KERNELS} into
546#	${RELEASEDIR}/${MACHINE}/binary/kernel
547#
548.for configfile in ${KERNEL_SETS} ${EXTRA_KERNELS}			# {
549_RELEASEKERNELS_TO_BUILD+=releasekern-${configfile}
550releasekern-${configfile}:
551	@ kernlist=`${GETKERNELAWK} ${KERNCONFDIR}/${configfile:C/.*\///}`; \
552	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
553	kernsuffixes="${KERNEL_SUFFIXES:S/^/./}"; \
554	cd $${kerndir} && {	\
555		for kernel in $${kernlist}; do \
556			for s in "" $${kernsuffixes}; do \
557				ks="$${kernel}$${s}"; \
558				[ ! -f $${ks} ] && continue; \
559				knl_gz="${RELEASEDIR}/${MACHINE}/binary/kernel/$${ks}-${configfile:C/.*\///}.gz"; \
560				[ $${knl_gz} -nt $${ks} ] && continue; \
561				echo "gzip -c -9 < $${kerndir}/$${ks} > $${knl_gz}"; \
562				gzip -c -9 < $${ks} > $${knl_gz}; \
563			done; \
564		done; \
565	}
566.endfor	# KERNEL_SETS EXTRA_KERNELS					# }
567
568build_releasekernels: ${_RELEASEKERNELS_TO_BUILD}
569
570# snap_kern --
571#	build the kernels, then the sets & release kernels
572#
573snap_kern: check_DESTDIR check_RELEASEDIR .WAIT \
574	    build_kernels .WAIT \
575	    build_kernelsets build_releasekernels
576
577.endif # !target(snap_kern)					# }
578
579
580# snap_md_post --
581#	Machine dependent distribution media operations.
582#	Overridden by etc.$MACHINE/Makefile.inc
583#
584snap_md_post: check_DESTDIR check_RELEASEDIR
585#	(empty -- look in the machine-dependent Makefile.inc)
586
587
588clean:
589	-rm -rf ${CDROM.dir} ${CDROM.pathlist} ${OBSOLETE.dir}
590
591.include <bsd.prog.mk>
592