Makefile revision 1.451
1#	$NetBSD: Makefile,v 1.451 2021/09/25 08:54:30 maya 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#   MKPOSTFIX; if not `no', install postfix configuration
19#   MKUNPRIVED; if not `no', allow non-root installs.
20#   MKUPDATE; if not `no', don't do a 'make clean' before kernel compile
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/${RELEASEMACHINEDIR}.
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 MK* vars
36.include <bsd.own.mk>
37
38.include <bsd.kernobj.mk>	# For KERNSRCDIR, KERNOBJDIR, ...
39.include <bsd.endian.mk>	# For TARGET_ENDIANNESS
40
41.MAKEOVERRIDES+=	USETOOLS
42
43TZDIR=		/usr/share/zoneinfo
44LOCALTIME?=	UTC
45CKSUM?=		${TOOL_CKSUM}
46MAKESUMS=	MAKE=${MAKE:Q} CKSUM=${CKSUM:Q} ${HOST_SH} ${NETBSDSRCDIR}/distrib/sets/makesums
47DISTRIBVER!=	${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh
48
49GZIP_FLAGS= -9 ${GZIP_N_FLAG}
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#
55.if !defined(MKISOFS)
56MKISOFS!=       (which mkisofs || echo true) 2>/dev/null
57.endif
58DISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
59# ISO 9660 volume ID.  Note that this can only contain [A-Z0-9_].
60ISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
61MKISOFS_FLAGS+= -J -l -hide-joliet-trans-tbl -r -T \
62		-V ${ISO_VOLID} \
63		-publisher "The NetBSD Project" \
64		-m "${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/cdrom"
65.if ${MKISOFS_FLAGS:N-v}
66MKISOFS_FLAGS+=	-quiet
67.endif
68 
69# Reproducible build parameters
70.if ${MKREPRO:Uno} == "no"
71BUILDER!=	echo $${USER-root}@$$(hostname)
72.else
73BUILDER=	builder@localhost.NetBSD.org
74.endif
75.if ${MKREPRO_TIMESTAMP:Uno} == "no"
76PAX_TIMESTAMP=
77BUILD_DATE!=	date -u
78.else
79PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
80BUILD_DATE!=	${TOOL_DATE} -u -r "${MKREPRO_TIMESTAMP}"
81.endif
82
83# MD Makefile.inc may append MD targets to BIN[123].  Make sure all
84# are empty, to preserve the old semantics of setting them below with "+=".
85#
86BIN1=
87BIN2=
88BIN3=
89
90# Directories to build in ${RELEASEDIR}/${RELEASEMACHINEDIR}.
91# MD Makefile.inc files can add to this.
92# NOTE: Parent directories must be listed before subdirectories.
93#
94INSTALLATION_DIRS=	binary binary/sets binary/kernel installation
95
96.if exists(etc.${RELEASEMACHINE}/Makefile.inc)
97.include "etc.${RELEASEMACHINE}/Makefile.inc"
98.endif
99
100# -rw-r--r--
101BINOWN= root
102BINGRP= wheel
103UTMPGRP= utmp
104BIN1+=	auto_master bootptab changelist csh.cshrc csh.login \
105	csh.logout daily daily.conf dm.conf envsys.conf floppytab ftpchroot \
106	ftpusers gettytab gpio.conf group hosts hosts.lpd inetd.conf \
107	locate.conf login.conf mailer.conf man.conf monthly monthly.conf \
108	mrouted.conf named.conf netconfig networks newsyslog.conf \
109	nsswitch.conf ntp.conf passwd.conf pkgpath.conf phones printcap \
110	profile protocols rbootd.conf rc rc.conf rc.local rc.subr \
111	rc.shutdown remote rpc security security.conf services shells \
112	shrc sysctl.conf syslog.conf weekly weekly.conf wscons.conf
113
114# Use machine-specific disktab if it exists, or the MI one otherwise
115.if exists(etc.${MACHINE}/disktab)
116BIN1+=	etc.${MACHINE}/disktab
117.else
118BIN1+=	disktab
119.endif
120
121.if exists(etc.${MACHINE}/ld.so.conf) && \
122    empty(MACHINE_ARCH:M*arm*hf*) && empty(MACHINE_ARCH:Maarch64*)
123BIN1+=	etc.${MACHINE}/ld.so.conf
124.endif
125
126.if exists(etc.${MACHINE}/ttyaction)
127BIN1+=	etc.${MACHINE}/ttyaction
128.endif
129
130# -rw-rw-r--
131BIN2+=	motd
132FILESBUILD_motd=	YES
133
134# -rw-------
135BIN3+=	hosts.equiv wpa_supplicant.conf
136
137SYSPKG=	etc
138ETC_PKG=-T etc_pkg
139BASE_PKG=-T base_pkg
140ETC_INSTALL_FILE=cd ${.CURDIR} && ${INSTALL_FILE} ${ETC_PKG}
141ETC_INSTALL_OBJ_FILE=cd ${.OBJDIR} && ${INSTALL_FILE} ${ETC_PKG}
142
143.if ${TARGET_ENDIANNESS} == "1234"
144PWD_MKDB_ENDIAN=	-L
145.elif ${TARGET_ENDIANNESS} == "4321"
146PWD_MKDB_ENDIAN=	-B
147.else
148PWD_MKDB_ENDIAN=
149.endif
150
151
152# distribution --
153#	Build a distribution
154#
155distribution: .PHONY .MAKE check_DESTDIR distrib-dirs
156.if !defined(DISTRIBUTION_DONE)
157.if !defined(INSTALL_DONE)
158	${MAKEDIRTARGET} ${NETBSDSRCDIR} include _DISTRIB=
159	${MAKEDIRTARGET} ${NETBSDSRCDIR} install _DISTRIB=
160.endif	# !INSTALL_DONE
161	${MAKEDIRTARGET} . install-etc-files
162. if ${MKX11} != "no"
163	${MAKEDIRTARGET} ${NETBSDSRCDIR}/external/mit/xorg distribution
164. endif
165. if ${MKEXTSRC} != "no"
166	${MAKEDIRTARGET} ${NETBSDSRCDIR}/extsrc distribution
167. endif
168	${MAKEDIRTARGET} ${NETBSDSRCDIR}/distrib/sets makesetfiles
169.endif	# !DISTRIBUTION_DONE
170
171
172# motd is copied from a different ${MOTD_SOURCE} depending on DISTRIBVER
173#
174.if !empty(DISTRIBVER:M*.99.*)
175MOTD_SOURCE=	motd.current
176.elif !empty(DISTRIBVER:M*BETA*)
177MOTD_SOURCE=	motd.beta
178.elif !empty(DISTRIBVER:M*RC*)
179MOTD_SOURCE=	motd.rc
180.else
181MOTD_SOURCE=	motd.default
182.endif
183CLEANFILES+= motd
184motd: ${.CURDIR}/${MOTD_SOURCE} ${_NETBSD_VERSION_DEPENDS}
185	${_MKTARGET_CREATE}
186	${HOST_INSTALL_FILE} ${.CURDIR}/${MOTD_SOURCE} ${.TARGET}
187
188CLEANFILES+=	MAKEDEV
189MAKEDEV_MACHINE=${"${MACHINE_CPU}" == "aarch64":?${MACHINE_CPU}:${MACHINE}}
190MAKEDEV: ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl \
191    ${.CURDIR}/etc.${MAKEDEV_MACHINE}/MAKEDEV.conf
192	${_MKTARGET_CREATE}
193	MACHINE=${MAKEDEV_MACHINE:Q} MACHINE_ARCH=${MACHINE_ARCH:Q} \
194	    NETBSDSRCDIR=${NETBSDSRCDIR:Q} \
195	    ${TOOL_AWK} -f ${.CURDIR}/MAKEDEV.awk ${.CURDIR}/MAKEDEV.tmpl \
196	    > ${.TARGET}
197
198.include "${NETBSDSRCDIR}/etc/Makefile.params"
199
200CLEANFILES+=	etc-release
201etc-release: .EXEC .MAKE
202	${_MKTARGET_CREATE}
203	@(	echo "NetBSD ${DISTRIBVER}/${MACHINE}"; \
204		echo ; \
205		cat ${NETBSDSRCDIR}/sys/conf/copyright; \
206		echo ; \
207		echo "Build information:"; \
208		printf "%20s   %s\n" "Build date" "${BUILD_DATE}"; \
209		printf "%20s   %s\n"  "Built by" "${BUILDER}"; \
210		if [ -n "${BUILDID}" ]; then \
211		    printf "%20s   %s\n"  "Build ID" "${BUILDID}" ; \
212		fi ; \
213		if [ -n "${BUILDINFO}" ]; then \
214		    echo ; \
215		    info="$$(printf "%b" ${BUILDINFO:Q})" ; \
216		    printf "%s\n" "$${info}" \
217		    | ${TOOL_SED} -e 's/^/        /' ; \
218		fi ; \
219		echo ; \
220		echo "Build settings:"; \
221		echo ; \
222		${PRINT_PARAMS} ; \
223	) >${.OBJDIR}/${.TARGET}
224
225install-etc-release: .PHONY etc-release
226	${_MKMSG_INSTALL} etc/release
227	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 444 \
228	    etc-release ${DESTDIR}/etc/release
229
230
231FILESDIR=		/etc
232CONFIGFILES=
233CONFIGSYMLINKS=
234
235.for file in ${BIN1}
236CONFIGFILES+=		${file}
237FILESMODE_${file:T}=	644
238.endfor
239
240.for file in ${BIN2}
241CONFIGFILES+=		${file}
242FILESMODE_${file:T}=	664
243.endfor
244
245.for file in ${BIN3}
246CONFIGFILES+=		${file}
247FILESMODE_${file:T}=	600
248.endfor
249
250.if (${MKPOSTFIX} != "no")
251CONFIGFILES+=		aliases
252FILESDIR_aliases=	/etc/mail
253FILESMODE_aliases=	644
254.endif
255
256CONFIGFILES+=		MAKEDEV.local
257FILESDIR_MAKEDEV.local=	/dev
258FILESMODE_MAKEDEV.local=${BINMODE}
259
260CONFIGFILES+=		crontab
261FILESDIR_crontab=	/var/cron/tabs
262FILESNAME_crontab=	root
263FILESMODE_crontab=	600
264
265CONFIGFILES+=		minfree
266FILESDIR_minfree=	/var/crash
267FILESMODE_minfree=	600
268
269CONFIGSYMLINKS+=	${TZDIR}/${LOCALTIME}	/etc/localtime \
270			/usr/sbin/rmt		/etc/rmt
271
272
273# install-etc-files --
274#	Install etc (config) files; not performed by "make build"
275#
276install-etc-files: .PHONY .MAKE check_DESTDIR MAKEDEV
277	${_MKMSG_INSTALL} ${DESTDIR}/etc/master.passwd
278	${ETC_INSTALL_FILE} -o root -g wheel -m 600 \
279	    master.passwd ${DESTDIR}/etc
280	${TOOL_PWD_MKDB} -p ${PWD_MKDB_ENDIAN} -d ${DESTDIR}/ \
281	    ${DESTDIR}/etc/master.passwd
282.if ${MKUNPRIVED} != "no"
283	( \
284		mode=0600; \
285		for metaent in spwd.db passwd pwd.db; do \
286	    		echo "./etc/$${metaent} type=file mode=$${mode} uname=root gname=wheel tags=etc_pkg"; \
287			mode=0644; \
288		done; \
289	) | ${METALOG.add}
290.endif	# MKUNPRIVED != no
291	${_MKMSG_INSTALL} ${DESTDIR}/etc/ttys
292.if exists(${.CURDIR}/etc.${MACHINE}/ttys)
293	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
294	    ${.CURDIR}/etc.${MACHINE}/ttys ${DESTDIR}/etc
295.else
296	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
297	    ${.CURDIR}/etc.${MACHINE_CPU}/ttys ${DESTDIR}/etc
298.endif
299.if exists(etc.${MACHINE}/boot.cfg)
300	${_MKMSG_INSTALL} ${DESTDIR}/boot.cfg
301	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
302	    ${.CURDIR}/etc.${MACHINE}/boot.cfg ${DESTDIR}/
303.endif
304	${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV
305	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
306	    MAKEDEV ${DESTDIR}/dev
307.for owner group mode file in \
308		${BINOWN} operator	664	/etc/dumpdates  \
309		${BINOWN} operator	600	/etc/skeykeys \
310		root wheel		600	/var/at/at.deny \
311		root wheel		644	/var/db/locate.database \
312		${BINOWN} ${BINGRP}	600	/var/log/authlog \
313		root wheel		600	/var/log/cron \
314		${BINOWN} ${UTMPGRP}	664	/var/log/lastlog \
315		${BINOWN} ${UTMPGRP}	664	/var/log/lastlogx \
316		${BINOWN} ${BINGRP}	640	/var/log/lpd-errs \
317		${BINOWN} ${BINGRP}	600	/var/log/maillog \
318		${BINOWN} ${BINGRP}	644	/var/log/messages \
319		${BINOWN} ${BINGRP}	600	/var/log/secure \
320		${BINOWN} ${UTMPGRP}	664	/var/log/wtmp \
321		${BINOWN} ${UTMPGRP}	664	/var/log/wtmpx \
322		${BINOWN} ${BINGRP}	600	/var/log/xferlog \
323		daemon staff		664	/var/msgs/bounds \
324		${BINOWN} ${UTMPGRP}	664	/var/run/utmp \
325		${BINOWN} ${UTMPGRP}	664	/var/run/utmpx \
326		games games		664	/var/games/atc_score \
327		games games		664	/var/games/battlestar.log \
328		games games		664	/var/games/cfscores \
329		games games		664	/var/games/criblog \
330		games games		660	/var/games/hackdir/perm \
331		games games		660	/var/games/hackdir/record \
332		games games		664	/var/games/larn/llog12.0 \
333		games games		664	/var/games/larn/lscore12.0 \
334		games games		664	/var/games/larn/playerids \
335		games games		664	/var/games/robots_roll \
336		games games		664	/var/games/rogue.scores \
337		games games		664	/var/games/saillog \
338		games games		664	/var/games/snakerawscores \
339		games games		664	/var/games/snake.log \
340		games games		664	/var/games/tetris.scores
341	${_MKMSG_INSTALL} ${DESTDIR}${file}
342	if [ ! -e ${DESTDIR}${file} -o -s ${DESTDIR}${file} ]; then \
343		${ETC_INSTALL_FILE} -o ${owner} -g ${group} -m ${mode} \
344			/dev/null ${DESTDIR}${file}; \
345	else true; fi
346.endfor
347.for subdir in . defaults autofs bluetooth iscsi mtree namedb pam.d powerd rc.d root skel ssh
348	${MAKEDIRTARGET} ${subdir} configinstall
349.endfor
350	${MAKEDIRTARGET} ${NETBSDSRCDIR}/external/bsd/dhcpcd/sbin/dhcpcd configinstall
351	${MAKEDIRTARGET} ${NETBSDSRCDIR}/usr.bin/mail configinstall
352.if (${MKPF} != "no")
353	${MAKEDIRTARGET} ${NETBSDSRCDIR}/usr.sbin/pf configinstall
354.endif
355	${MAKEDIRTARGET} ${NETBSDSRCDIR}/crypto/external/bsd/openssh/bin configinstall
356.if (${MKPOSTFIX} != "no")
357	${MAKEDIRTARGET} ${NETBSDSRCDIR}/external/ibm-public/postfix configinstall
358.endif
359.if (${MKATF} != "no")
360	${MAKEDIRTARGET} ${NETBSDSRCDIR}/external/bsd/atf/etc/atf configinstall
361.endif
362.if (${MKKYUA} != "no")
363	${MAKEDIRTARGET} ${NETBSDSRCDIR}/external/bsd/kyua-cli/etc/kyua configinstall
364.endif
365
366
367# install-obsolete-lists --
368#	Install var/db/obsolete set lists; this is performed by "make build"
369#
370OBSOLETE.dir=		${.OBJDIR}/obsolete.dir
371OBSOLETE.files=		base comp etc games man misc rescue text
372.if ${MKDEBUG} != "no"
373OBSOLETE.files+=	debug
374.endif
375.if ${MKDTB} != "no"
376OBSOLETE.files+=	dtb
377.endif
378.if ${MKGPUFIRMWARE} != "no"
379OBSOLETE.files+=	gpufw
380.endif
381.if ${MKKMOD} != "no"
382OBSOLETE.files+=	modules
383.endif
384.if ${MKATF} != "no"
385OBSOLETE.files+=	tests
386.endif
387.if ${MKX11} != "no"
388OBSOLETE.files+=	xbase xcomp xetc xfont xserver
389.if ${MKDEBUG} != "no"
390OBSOLETE.files+=	xdebug
391.endif
392.endif
393
394# XXX make "makeobsolete" set wise; then generate files respectively
395install-obsolete-lists: .PHONY .MAKE
396	mkdir -p ${OBSOLETE.dir}
397.if ${MKX11} != "no"
398	(cd ${NETBSDSRCDIR}/distrib/sets && \
399	    AWK=${TOOL_AWK:Q} MAKE=${MAKE:Q} ${HOST_SH} ./makeobsolete -b -t ${OBSOLETE.dir})
400.else
401	(cd ${NETBSDSRCDIR}/distrib/sets && \
402	    AWK=${TOOL_AWK:Q} MAKE=${MAKE:Q} ${HOST_SH} ./makeobsolete -t ${OBSOLETE.dir})
403.endif
404.for file in ${OBSOLETE.files}
405	${_MKMSG_INSTALL} ${DESTDIR}/var/db/obsolete/${file}
406	if [ ! -e ${DESTDIR}/var/db/obsolete/${file} ] || \
407	    ! cmp -s ${OBSOLETE.dir}/${file} ${DESTDIR}/var/db/obsolete/${file}; then \
408		${ETC_INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
409		    ${OBSOLETE.dir}/${file} ${DESTDIR}/var/db/obsolete; \
410	else true; fi
411.endfor
412
413
414# distrib-dirs --
415#	Populate $DESTDIR with directories needed by NetBSD
416#
417distrib-dirs: .PHONY check_DESTDIR
418	cd ${NETBSDSRCDIR}/etc/mtree && ${MAKE} distrib-dirs
419
420COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
421XZ_OPT=-9
422TAR_SUFF=${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
423
424# release, snapshot --
425#	Build a full distribution including kernels & install media.
426#
427release snapshot: .PHONY .MAKE check_DESTDIR check_RELEASEDIR snap_md_post
428	${MAKEDIRTARGET} ${NETBSDSRCDIR}/distrib/sets sets
429	${MAKESUMS} -A -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets \
430		${KERNEL_SETS:@.SETS.@kern-${.SETS.}.${TAR_SUFF}@}
431	${MAKESUMS} -t ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel '*.gz'
432
433
434# iso-image --
435#	Standalone target to create a CDROM image after the release
436#	was composed.  Should be run after "make release" in src and xsrc.
437#	The do-iso-image is to be called from etc.$MACHINE/Makefile.inc
438#
439#	Note: At least mkisofs 2.0 should be used.
440#
441CDROM_NAME_ADD?=
442CDROM_IMAGE?=${RELEASEDIR}/images/NetBSD-${DISTRIBVER}-${MACHINE}.iso
443CDROM.dir=	${.OBJDIR}/cdrom.dir
444CDROM.pathlist=	${.OBJDIR}/cdrom.pathlist
445
446iso-image:
447
448.if ${MKISOFS} != true
449do-iso-image: .PHONY check_DESTDIR check_RELEASEDIR iso-image-md-post
450	${MAKESUMS} -t ${RELEASEDIR}/images/ '*.iso'
451	@echo "iso-image created as: ${CDROM_IMAGE}"
452.else
453do-iso-image:
454	@echo iso-image: mkisofs not found
455.endif
456
457iso-image-setup: .PHONY check_RELEASEDIR
458	rm -f ${CDROM.pathlist}
459.for extra in README SOURCE_DATE source
460.if exists(${RELEASEDIR}/${extra})
461	echo "${extra}=${RELEASEDIR}/${extra}" >> ${CDROM.pathlist}
462.endif
463.endfor
464	echo "${MACHINE}/=${RELEASEDIR}/${RELEASEMACHINEDIR}/" >> ${CDROM.pathlist}
465	mkdir -p ${CDROM.dir}
466
467check_imagedir:
468	mkdir -p ${RELEASEDIR}/images
469
470# iso-image-mi --
471#	Create the image after the MD operations have completed.
472#
473iso-image-mi: .PHONY check_DESTDIR check_RELEASEDIR iso-image-md-pre check_imagedir
474	@if ! ${MKISOFS} --version; then \
475		echo "install pkgsrc/sysutils/cdrtools and run 'make iso-image'." ; \
476		false; \
477	fi
478	${MKISOFS} ${MKISOFS_FLAGS} -graft-points -path-list ${CDROM.pathlist} \
479	    -o ${CDROM_IMAGE} ${CDROM.dir}
480
481# iso-image-md-pre --
482#	Setup ${CDROM.dir} to produce a bootable CD image.
483#	Overridden by etc.$MACHINE/Makefile.inc
484#
485iso-image-md-pre: .PHONY check_DESTDIR check_RELEASEDIR iso-image-setup
486#	(empty -- look in the machine-dependent Makefile.inc)
487
488# iso-image-md-post --
489#	Fixup the CD-image to be bootable.
490#	Overridden by etc.$MACHINE/Makefile.inc
491#
492iso-image-md-post: .PHONY check_DESTDIR check_RELEASEDIR iso-image-mi
493#	(empty -- look in the machine-dependent Makefile.inc)
494
495
496# live-image --
497#	Standalone target to create live images after the release was composed.
498#	Should be run after "make release" in src and xsrc.
499#	LIVEIMG_RELEASEDIR specifies where to install live images and
500#	it can be set in MD etc.${MACHINE}/Makefile.inc.
501#
502LIVEIMG_RELEASEDIR?= ${RELEASEDIR}/images
503
504live-image: .PHONY check_DESTDIR check_RELEASEDIR
505	${MAKEDIRTARGET} ${NETBSDSRCDIR}/distrib live_image \
506	    LIVEIMG_RELEASEDIR=${LIVEIMG_RELEASEDIR}
507	${MAKESUMS} -t ${LIVEIMG_RELEASEDIR} '*.img.gz'
508
509# install-image --
510#	Standalone target to create installation images
511#	after the release was composed.
512#	Should be run after "make release" in src and xsrc.
513#	INSTIMG_RELEASEDIR specifies where to install live images and
514#	it can be set in MD etc.${MACHINE}/Makefile.inc.
515#
516INSTIMG_RELEASEDIR?= ${RELEASEDIR}/images
517
518install-image: .PHONY check_DESTDIR check_RELEASEDIR
519	${MAKEDIRTARGET} ${NETBSDSRCDIR}/distrib install_image \
520	    INSTIMG_RELEASEDIR=${INSTIMG_RELEASEDIR}
521	${MAKESUMS} -t ${INSTIMG_RELEASEDIR} '*.img.gz'
522
523# snap_pre --
524#	Create ${RELEASEDIR} and necessary subdirectories.
525#
526snap_pre: .PHONY check_DESTDIR check_RELEASEDIR distribution
527	${INSTALL} -d -m 755 ${RELEASEDIR}
528.if ${MKUPDATE} == "no"
529# Could be a mount point, ignore the errors
530	-/bin/rm -rf ${RELEASEDIR}/${RELEASEMACHINEDIR}
531.endif
532	${INSTALL} -d -m 755 ${RELEASEDIR}/${RELEASEMACHINEDIR}
533.for dir in ${INSTALLATION_DIRS}
534	${INSTALL} -d -m 755 ${RELEASEDIR}/${RELEASEMACHINEDIR}/${dir}
535.endfor
536
537# snap_post --
538#	Build the install media and notes from distrib
539#
540snap_post: .PHONY .MAKE build_kernelsets build_releasekernels
541.if ${MKUPDATE} == "no"
542	cd ${NETBSDSRCDIR}/distrib && ${MAKE} cleandir
543.endif
544	cd ${NETBSDSRCDIR}/distrib && ${MAKE} depend && ${MAKE} && \
545	    ${MAKE} release
546
547# build kernels --
548#	This target builds the kernels specified by each port.
549#	A port may specify the following kernels:
550#
551#	KERNEL_SETS		The list of kernels that will be
552#				packaged into sets, named
553#				kern-${kernel}.tgz (or .tar.xz).
554#				These kernels are also placed in the
555#				binary/kernel area of the release package
556#				as netbsd-${kernel}.gz.
557#
558#	EXTRA_KERNELS		Additional kernels to place in the
559#				binary/kernel area of the release
560#				package as netbsd-${kernel}.gz, but
561#				which are not placed into sets. This
562#				allows a port to provide e.g. a netbootable
563#				installation kernel containing a ramdisk.
564#
565#	BUILD_KERNELS		Additional kernels to build which are
566#				not placed into sets nor into the
567#				binary/kernel area of the release
568#				package.  These are typically kernels
569#				that are built for inclusion only in
570#				installation disk/CD-ROM/tape images.
571#
572#	A port may also specify KERNEL_SUFFIXES, which is an optional list
573#	of filename suffixes for kernels to include in the kernel sets and
574#	in the binary/kernel area of the release package (e.g. "netbsd" vs.
575#	"netbsd.ecoff" and "netbsd.srec").  It is not an error if kernels
576#	with these suffixes do not exist in the kernel build directory.
577#
578#
579# A list of all the kernels to build, which can be overridden from
580# external sources (such as make(1)'s environment or command line)
581#
582ALL_KERNELS?=	${KERNEL_SETS} ${EXTRA_KERNELS} ${BUILD_KERNELS}
583.export ALL_KERNELS
584
585GETKERNELAWK=	${TOOL_AWK} '/^config/ {print $$2; found=1} \
586		END{ if (found == 0) print "netbsd"; }'
587
588build_kernels: .PHONY
589#	Configure & compile kernels listed in ${ALL_KERNELS}
590#
591.if !defined(KERNELS_DONE)						# {
592.for configfile in ${ALL_KERNELS:O:u}					# {
593build_kernels: kern-${configfile}
594kern-${configfile}: .PHONY .MAKE
595	cd ${KERNCONFDIR} && ${TOOL_CONFIG} ${CONFIGOPTS} -s ${KERNSRCDIR} \
596	    -b ${KERNOBJDIR}/${configfile:C/.*\///} ${configfile}
597.if ${MKUPDATE} == "no"
598	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} distclean
599.endif
600	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} depend && \
601	${MAKE} -C ${KERNOBJDIR}/${configfile:C/.*\///} 
602.endfor	# ALL_KERNELS							# }
603.endif	# KERNELS_DONE							# }
604
605build_kernelsets: .PHONY
606#	Create kernel sets from ${KERNEL_SETS} into
607#	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
608#
609.for configfile in ${KERNEL_SETS:O:u}					# {
610.for configsel in ${ALL_KERNELS:O:u}
611.if ${configfile} == ${configsel}
612build_kernelsets: kernset-${configfile}
613kernset-${configfile}: .PHONY build_kernels snap_pre
614	@kernlist=$$(${GETKERNELAWK} ${KERNCONFDIR}/${configfile}); \
615	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
616	kernsuffixes="${KERNEL_SUFFIXES:S/^/./}"; \
617	kern_tgz=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets/kern-${configfile}.${TAR_SUFF}; \
618	pax_cmd="GZIP=${GZIP_FLAGS:Q} XZ_OPT=${XZ_OPT:Q} ${TOOL_PAX} ${PAX_TIMESTAMP} --use-compress-program ${COMPRESS_PROGRAM:Q} -O -w -M -N ${NETBSDSRCDIR}/etc -f $${kern_tgz}"; \
619	cd $${kerndir} && { \
620		kernels=; newest=; \
621		for kernel in $${kernlist}; do \
622			for s in "" $${kernsuffixes}; do \
623				ks="$${kernel}$${s}"; \
624				[ -f $${ks} ] || continue; \
625				kernels="$${kernels} $${ks}"; \
626				[ -z "$${newest}" -o $${ks} \
627				    -nt "$${newest}" ] && newest=$${ks}; \
628			done; \
629		done; \
630		[ $${kern_tgz} -nt "$${newest}" ] || { \
631			echo "echo $${kernels} | $${pax_cmd}"; \
632			if [ ${KERNEL_DIR} = "yes" ]; then \
633				tmpdir=kernel$$; \
634				trap "rm -fr $${tmpdir}" 0 1 2 3 15; \
635				mkdir -p $${tmpdir}/netbsd; \
636				d=./netbsd; \
637				cd $${tmpdir}; \
638			else \
639				d=.; \
640			fi; \
641			( echo "/set uname=${BINOWN} gname=${BINGRP}"; \
642			echo ". type=dir optional"; \
643			if [ ${KERNEL_DIR} = "yes" ]; then \
644				echo "./netbsd type=dir optional"; \
645			fi; \
646			for kernel in $${kernels}; do \
647				if [ ${KERNEL_DIR} = "yes" ]; then \
648					newname=$$(echo $${kernel} | \
649					    ${TOOL_SED} -e s/netbsd/kernel/); \
650					ln ../$${kernel} ./netbsd/$${newname}; \
651				else \
652					newname=$${kernel}; \
653				fi; \
654				echo "$${d}/$${newname} type=file"; \
655			done ) | eval $${pax_cmd}; \
656			if [ ${KERNEL_DIR} = "yes" ]; then \
657				mv $${kern_tgz} ..; \
658			fi; \
659		} \
660	}
661.endif
662.endfor
663.endfor	# KERNEL_SETS							# }
664
665build_releasekernels: .PHONY
666#	Build kernel.gz from ${KERNEL_SETS} ${EXTRA_KERNELS} into
667#	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel
668#
669.for configfile in ${KERNEL_SETS:O:u} ${EXTRA_KERNELS:O:u}		# {
670.for configsel in ${ALL_KERNELS:O:u}
671.if ${configfile} == ${configsel}
672build_releasekernels: releasekern-${configfile}
673releasekern-${configfile}: .PHONY build_kernels snap_pre
674	@kernlist=$$(${GETKERNELAWK} ${KERNCONFDIR}/${configfile:C/.*\///}); \
675	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
676	kernsuffixes="${KERNEL_SUFFIXES:S/^/./}"; \
677	dest="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"; \
678	cd $${kerndir} && {	\
679		for kernel in $${kernlist}; do \
680			for s in "" $${kernsuffixes}; do \
681				ks="$${kernel}$${s}"; \
682				[ ! -f $${ks} ] && continue; \
683				knl_gz="$${dest}/$${kernel}-${configfile:C/.*\///}$${s}.gz"; \
684				[ $${knl_gz} -nt $${ks} ] && continue; \
685				rm -f $${knl_gz}; \
686				echo "${TOOL_GZIP} ${GZIP_FLAGS} -c < $${kerndir}/$${ks} > $${knl_gz}"; \
687				${TOOL_GZIP} ${GZIP_FLAGS} -c < $${ks} > $${knl_gz}; \
688			done; \
689		done; \
690	}
691.endif
692.endfor
693.endfor	# KERNEL_SETS EXTRA_KERNELS					# }
694
695# snap_md_post --
696#	Machine dependent distribution media operations.
697#	Overridden by etc.$MACHINE/Makefile.inc
698#
699snap_md_post: .PHONY check_DESTDIR check_RELEASEDIR snap_post
700#	(empty -- look in the machine-dependent Makefile.inc)
701
702
703clean:
704	-rm -rf ${CDROM.dir} ${CDROM.pathlist} ${OBSOLETE.dir}
705
706SUBDIR=	defaults rc.d mtree
707
708.include <bsd.prog.mk>
709.include <bsd.subdir.mk>
710
711test:
712	@echo ${OBSOLETE.files}
713