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