xref: /freebsd/release/Makefile (revision 9517e866259191fcd39434a97ad849a9b59b9b9f)
1# $FreeBSD$
2#
3# make release [BUILDNAME=somename] CHROOTDIR=/some/dir CVSROOT=/cvs/dir \
4#     [RELEASETAG=tag]
5#
6# Where "/some/dir" is the pathname of a directory on a some filesystem with
7# at least 1000MB of free space, "somename" is what you want the release to
8# call itself, "/cvs/dir" is where our source repo resides and, optionally,
9# which CVS "tag" name should be used when checking out the sources to build
10# the release (default is HEAD).
11#
12# Please note: the md(4) driver must be present in the kernel
13# (either by being compiled in or available as a kld(4) module),
14# otherwise the target 'release.8' and possibly others will fail.
15#
16# Note: If you add options to this file, please keep release(7) updated!
17#
18# Set these, release builder!
19#
20# Fixed version:
21#BUILDNAME=8.0-CURRENT
22#
23# Automatic SNAP versioning:
24DATE != date +%Y%m%d
25BASE = 8.0
26BUILDNAME?=${BASE}-${DATE}-SNAP
27#
28#CHROOTDIR=/junk/release
29# If this is a -stable snapshot, then set
30#RELEASETAG=RELENG_7
31#
32# To test a release with a source tree containing patches and
33# other work. This tree will get copied instead of getting the
34# src/ tree from a CVS checkout. For "rerelease", this will NOT
35# be copied; cvs update will be used instead.
36#EXTSRCDIR=/usr/src
37#
38# To use a checked-out ports collection directory instead of
39# checking out from a local CVS repository, set this option.
40#EXTPORTSDIR=/usr/ports
41#
42# To use a checked-out doc/ directory instead of
43# checking out from a local CVS repository, set this option.
44#EXTDOCDIR=/usr/doc
45#
46# To add other options to the CVS subcommands (co,up), set
47#CVSCMDARGS="-D '01/01/2002 00:00:00 UTC'"
48#
49# To add other options to the CVS command, set
50#CVSARGS="-lfq"
51#
52# To prefix the cvs command
53#CVSPREFIX="/usr/bin/time"
54#
55# Where the CVS repository is
56#CVSROOT="/home/ncvs"
57#
58# Non-zero if ${RELEASETAG} is in the form "RELENG_ver_RELEASE"; we
59# are building an official release.  Otherwise, we are building for
60# a branch.
61.if defined(RELEASETAG)
62ISRELEASE!=	expr "${RELEASETAG}" : '^RELENG_.*_RELEASE$$' || true
63.if ${ISRELEASE} != 0
64# Convert "RELENG_ver_RELEASE" to "RELEASE_ver" for ports and doc trees.
65AUXRELEASETAG!=	echo ${RELEASETAG} | sed -e 's/^RELENG_/RELEASE_/' -e 's/_RELEASE$$//'
66DOCRELEASETAG?=		${AUXRELEASETAG}
67PORTSRELEASETAG?=	${AUXRELEASETAG}
68.endif
69.endif
70
71# If you want to pass flags to the world build such as -j X, use
72# WORLD_FLAGS.  Similarly, you can specify make flags for kernel
73# builds via KERNEL_FLAGS.
74#WORLD_FLAGS=-j4
75#KERNEL_FLAGS=-j4
76
77TARGET_ARCH?=	${MACHINE_ARCH}
78.if ${TARGET_ARCH} == ${MACHINE_ARCH}
79TARGET?=	${MACHINE}
80.else
81TARGET?=	${TARGET_ARCH}
82.endif
83CROSSENV=	TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}
84CROSSMAKE=	${MAKE} ${CROSSENV}
85NATIVEMAKE=	${MAKE} TARGET_ARCH=${MACHINE_ARCH} TARGET=${MACHINE}
86
87# If you are using a local CVS repository with components stored in
88# non-standard modules, override these on the make commandline or
89# in the environment.
90RELEASESRCMODULE?=	src
91RELEASEDOCMODULE?=	doc
92RELEASEPORTSMODULE?=	ports
93
94# Uncomment this to disable the doc.1 target.  Docs normally require
95# the ports tree, so NOPORTS can be set together with NODOC in order
96# to have neither ports or docs.  If only NOPORTS is set to YES, but
97# docs are still desired, the DOMINIMALDOCPORTS logic below will only
98# install the ports that are minimally required for the release note documentation.  This is
99# intended as a compromise, less disk space is required than for using
100# the entire ports collection (and much less time due to the huge number
101# of directories it would create), but still quite a bit as well as some
102# CPU cycles (some of the programs are C++, and things like ghostscript
103# belong to the required ports nevertheless).
104#
105#NODOC=  YES
106#NOPORTS=  YES
107
108# When retrieving ports using the pkg_add -r method, set your proxies to these.
109# src/release/${arch}/mkisoimages.sh can use these.
110#HTTP_PROXY?=	www.example.com
111#FTP_PROXY?=	ftp.example.com
112
113# When creating ISO images, point ${CD_PACKAGE_TREE} to a directory containing
114# the package split by an earlier invocation of the 'package-split' target.
115#CD_PACKAGE_TREE=	/path/to/pkg
116
117# Extra source tarballs; each argument is a pair of source dir and
118# distribution name.  The dist name should not exceed 7 characters
119# (another "s" for "source" will be prepended).
120#EXTRA_SRC=	games/fortune fortune
121
122# Modify this definition if you want the release notes
123# and other release documentation in a language other than English.
124RELNOTES_LANG?=	en_US.ISO8859-1
125
126# As an alternative to installing the entire ports collection (which
127# can take a huge amount of time, in particular on slower disks),
128# setting ${MINIMALDOCPORTS} allows to install and build just those
129# ports that are really required for getting the docs up & running.
130.if defined(NOPORTS) && !defined(NODOC)
131DOMINIMALDOCPORTS=	YES
132.include "Makefile.inc.docports"
133RELEASEPORTSMODULE=	${MINIMALDOCPORTS} ports/sysutils/cdrtools
134.endif
135
136# Helper variable
137.if defined(NOPORTS)
138.if !defined(DOMINIMALDOCPORTS) || ${DOMINIMALDOCPORTS} != "YES"
139NOPORTSATALL=	YES
140.endif
141.endif
142
143#
144# Doing 'make index' in /usr/ports requires Perl.
145MAKEINDEXPORTS=	lang/perl5.8
146DOCPORTS=	textproc/docproj
147# Set this to wherever the distfiles required by release procedures.
148.if defined(DOCDISTFILES)
149# Respect DOCDISTFILES which is used before.
150RELEASEDISTFILES?=	${DOCDISTFILES}
151.else
152RELEASEDISTFILES?=	${.CURDIR}/../../ports/distfiles
153.endif
154# Set this to 1 if you want -P to be used for automatic keyboard detection
155# on the boot floppy.  WARNING: Breaks on some Athlon (K7) motherboards.
156AUTO_KEYBOARD_DETECT?= 0
157
158.if !defined(NODOC)
159DIST_DOCS_ARCH_INDEP=	hardware readme relnotes errata
160DIST_DOCS_ARCH_DEP=
161.endif
162
163# Things which without too much trouble can be considered variables
164# BASE_DISTS are special in that they get full /etc installation sets.
165#
166OTHER_DISTS?=	catpages manpages games proflibs dict info doc ${ARCH_DISTS}
167BASE_DISTS?=	base
168.if ${TARGET_ARCH} == "amd64"
169ARCH_DISTS?=	lib32
170.endif
171DISTRIBUTIONS?=	${BASE_DISTS} ${OTHER_DISTS}
172
173#
174# Build and package both GENERIC and SMP kernels if the target
175# has both configuration files.  Otherwise only GENERIC is done.
176#
177.if exists(${.CURDIR}/../sys/${TARGET}/conf/SMP)
178KERNELS_BASE?=	GENERIC SMP
179.else
180KERNELS_BASE?=	GENERIC
181.endif
182
183# mountpoint for filesystems.
184MNT=			/mnt
185
186# Various floppy image parameters.
187#
188
189.undef MAKE_FLOPPIES
190.if ${TARGET_ARCH} == "i386"
191MAKE_DVD=
192SEPARATE_LIVEFS=
193SPLIT_MFSROOT=
194.if ${TARGET} == "pc98"
195MAKE_FLOPPIES=		true
196SMALLFLOPPYSIZE=	1200
197SMALLFLOPPYSPLITSIZE=	1152
198SMALLFLOPPYLABEL=	fd1200
199SPLIT_MFSROOT=
200.endif
201FLOPPYSIZE=		1440
202FLOPPYSPLITSIZE=	1392
203FLOPPYINODE=		40000
204FLOPPYLABEL=		fd1440
205BOOTINODE=		80000
206MFSSIZE=		4320
207MFSINODE=		8000
208MFSLABEL=		minimum3
209.elif ${TARGET_ARCH} == "sparc64"
210DISKLABEL=		sunlabel
211MAKE_DVD=
212MFSSIZE=		4096
213MFSINODE=		8192
214MFSLABEL=		auto
215MINIROOT=
216.elif ${TARGET_ARCH} == "ia64"
217DISKLABEL=		""
218MAKE_DVD=
219MFSSIZE=		8192
220MFSINODE=		8192
221MFSLABEL=		auto
222SEPARATE_LIVEFS=
223.elif ${TARGET_ARCH} == "amd64"
224MAKE_DVD=
225FLOPPYSIZE=		1440
226FLOPPYSPLITSIZE=	1392
227FLOPPYINODE=		40000
228FLOPPYLABEL=		fd1440
229BOOTINODE=		80000
230MFSSIZE=		4096
231MFSINODE=		8192
232MFSLABEL=		auto
233SEPARATE_LIVEFS=
234SPLIT_MFSROOT=
235.elif ${TARGET_ARCH} == "powerpc"
236DISKLABEL=		""
237MFSSIZE=		4096
238MFSINODE=		8192
239MFSLABEL=		auto
240SEPARATE_LIVEFS=
241.endif
242.if defined(NO_FLOPPIES)
243.undef MAKE_FLOPPIES
244.endif
245
246.if exists(/sbin/bsdlabel)
247DISKLABEL?=		bsdlabel
248.else
249DISKLABEL?=		disklabel
250.endif
251
252ZIPPER=			gzip -9 --no-name
253ZIPNSPLIT=		${ZIPPER} -c | split -b 1392k -
254
255# Things which may get you into trouble if you change them
256MTREEFILES=		${.CURDIR}/../etc/mtree
257_R?=			/R
258RD=			${_R}/stage
259RND=			${RD}/release.doc
260FD=			${_R}/ftp
261CD=			${_R}/cdrom
262CD_BOOT=		${CD}/bootonly
263CD_DISC1=		${CD}/disc1
264CD_DISC2=		${CD}/disc2
265.if defined(MAKE_DVD)
266CD_DVD1=		${CD}/dvd1
267.endif
268.if !defined(NODOC)
269CD_DOCS=		${CD}/docs
270.endif
271.if defined(SEPARATE_LIVEFS)
272CD_LIVEFS=		${CD}/livefs
273.else
274CD_LIVEFS=		${CD_DISC1}
275.endif
276_MK?=			${CHROOTDIR}/mk
277
278# Where the bootstrap ports (see DOCPORTS) get installed.
279LOCALDIR=		/usr/local/bin
280
281.if ${TARGET} != ${MACHINE} && ${DISKLABEL} == "bsdlabel"
282DOFS_SH=	${.CURDIR}/scripts/doFS.sh ${DISKLABEL} ${TARGET}
283.else
284DOFS_SH=	${.CURDIR}/scripts/doFS.sh ${DISKLABEL} ""
285.endif
286
287CRUNCH_TARGETS=	boot
288.if ${TARGET_ARCH} == "i386"
289CRUNCH_TARGETS+=fixit
290.if ${TARGET} == "pc98"
291CRUNCH_TARGETS+=fixit-small
292.endif
293.endif
294
295.if defined(MAKE_FLOPPIES)
296EXTRAS= floppies.1
297.if ${TARGET_ARCH} == "i386"
298EXTRAS+= floppies.2
299.endif
300EXTRAS+= floppies.3
301.endif
302EXTRAS+= ftp.1
303.if !defined(NOCDROM)
304EXTRAS+= cdrom.1 cdrom.2 cdrom.3
305.if defined(MAKE_ISOS)
306EXTRAS+= iso.1
307.endif
308.if ${TARGET} == "pc98"
309BOOTABLE="-G"
310.else
311BOOTABLE="-b"
312.endif
313.endif
314
315.if !defined(NODOC)
316DOCREL= doc.1 doc.2
317.endif
318
319.if !make(release) && !make(rerelease) && !make(package-split)
320BINMAKE!=	cd ${.CURDIR}/..; ${MAKE} -V BINMAKE
321WMAKEENV!=	cd ${.CURDIR}/..; \
322		${BINMAKE} ${CROSSENV} -f Makefile.inc1 -V WMAKEENV
323WMAKE=		${WMAKEENV} ${BINMAKE}
324.endif
325
326CVS_SRCARGS=	-P
327.if defined(RELEASETAG)
328CVS_SRCARGS+=	-r ${RELEASETAG}
329.endif
330
331CVS_DOCARGS=	-P
332.if defined(DOCRELEASETAG)
333CVS_DOCARGS+=	-r ${DOCRELEASETAG}
334.endif
335
336CVS_PORTSARGS=	-P
337.if defined(PORTSRELEASETAG)
338CVS_PORTSARGS+=	-r ${PORTSRELEASETAG}
339.endif
340
341WORLDDIR?=	${.CURDIR}/..
342
343release rerelease:
344.if !defined(CHROOTDIR) || !defined(BUILDNAME) || !defined(CVSROOT)
345	@echo "To make a release you must set CHROOTDIR, BUILDNAME and CVSROOT" && false
346.endif
347.if defined(NOPORTSATALL) && !defined(NODOC)
348	@echo "Ports are required for building the release docs.  Either set NODOC or"
349	@echo "unset NOPORTS, or set at least DOMINIMALDOCPORTS to YES!"
350	@exit 1
351.endif
352.if defined(LOCAL_PATCHES) && !empty(LOCAL_PATCHES)
353.for p in ${LOCAL_PATCHES}
354.if !exists(${p})
355	@echo "The patch file ${p} does not exist!"
356	@exit 1
357.endif
358.endfor
359.endif
360.if defined(LOCAL_SCRIPT) && !exists(${LOCAL_SCRIPT})
361	@echo "The local script ${LOCAL_SCRIPT} does not exist!"
362	@exit 1
363.endif
364.if make(release)
365.if exists(${CHROOTDIR})
366# The first command will fail on a handful of files that have their schg
367# flags set.  But it greatly speeds up the next two commands.
368	# NB: clear any vestigial devfs mount, just in case
369	-umount ${CHROOTDIR}/dev > /dev/null 2>&1
370	-rm -rf ${CHROOTDIR} 2>/dev/null
371	-chflags -R 0 ${CHROOTDIR}/.
372	-rm -rf ${CHROOTDIR}
373.endif
374	mkdir -p ${CHROOTDIR}
375	@echo ">>> make release for ${TARGET} started on `LC_ALL=C TZ=GMT date`"
376	cd ${WORLDDIR} && ${NATIVEMAKE} -DWITHOUT_GAMES -DWITHOUT_HTML -DWITHOUT_LIB32 \
377	    -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE installworld DESTDIR=${CHROOTDIR}
378	cd ${WORLDDIR} && ${NATIVEMAKE} distribution DESTDIR=${CHROOTDIR}
379	if [ -f /etc/resolv.conf ]; then \
380		cp -p /etc/resolv.conf ${CHROOTDIR}/etc; \
381	fi
382.if defined(EXTLOCALDIR)
383	rm -rf ${CHROOTDIR}/usr/local
384	cd ${CHROOTDIR}/usr && cp -R -H ${EXTLOCALDIR} local
385.endif
386	rm -rf ${CHROOTDIR}/usr/src
387.if defined(EXTSRCDIR)
388	cd ${CHROOTDIR}/usr && \
389	    cp -R -H ${EXTSRCDIR} src
390.else
391	cd ${CHROOTDIR}/usr && \
392	    ${CVSPREFIX} cvs -R ${CVSARGS} -d ${CVSROOT} \
393	    co ${CVSCMDARGS} ${CVS_SRCARGS} ${RELEASESRCMODULE}
394.endif
395.if defined(LOCAL_PATCHES) && !empty(LOCAL_PATCHES)
396.for p in ${LOCAL_PATCHES}
397	patch -d ${CHROOTDIR}/usr/${RELEASESRCMODULE} ${PATCH_FLAGS} < ${p}
398.endfor
399.endif
400.if defined(LOCAL_SCRIPT)
401	cd ${CHROOTDIR} && env CHROOTDIR=${CHROOTDIR} BUILDNAME=${BUILDNAME} \
402	    RELEASETAG=${RELEASETAG} ${LOCAL_SCRIPT}
403.endif
404	rm -rf ${CHROOTDIR}/usr/ports
405.if !defined(NOPORTSATALL)
406.if defined(EXTPORTSDIR)
407	cd ${CHROOTDIR}/usr && cp -R -H ${EXTPORTSDIR} ports
408	# If there are distfiles downloaded removing them
409	rm -rf ports/distfiles/*
410.else
411	cd ${CHROOTDIR}/usr && ${CVSPREFIX} cvs -R ${CVSARGS} -d ${CVSROOT} \
412	    co ${CVSCMDARGS} ${CVS_PORTSARGS} ${RELEASEPORTSMODULE}
413.endif
414.endif
415.if !defined(NODOC)
416	rm -rf ${CHROOTDIR}/usr/doc
417.if defined(EXTDOCDIR)
418	cd ${CHROOTDIR}/usr && cp -R -H ${EXTDOCDIR} doc
419.else
420	cd ${CHROOTDIR}/usr && ${CVSPREFIX} cvs -R ${CVSARGS} -d ${CVSROOT} \
421	    co ${CVSCMDARGS} ${CVS_DOCARGS} ${RELEASEDOCMODULE}
422.endif
423	if [ -d ${RELEASEDISTFILES}/ ]; then \
424		cp -rp ${RELEASEDISTFILES} ${CHROOTDIR}/usr/ports/distfiles; \
425	else \
426		mkdir -p ${CHROOTDIR}/usr/ports/distfiles; \
427	fi
428.if !defined(NO_PREFETCHDISTFILES)
429	@cd ${.CURDIR} && ${MAKE} fetch-distfiles
430.endif
431.endif
432.endif
433.if make(rerelease)
434.if !defined(RELEASENOUPDATE) && !defined(EXTSRCDIR)
435.if !defined(RELEASETAG)
436	cd ${CHROOTDIR}/usr/src && ${CVSPREFIX} cvs -R ${CVSARGS} -q \
437	    update ${CVSCMDARGS} -P -d -A
438.else
439	cd ${CHROOTDIR}/usr/src && ${CVSPREFIX} cvs -R ${CVSARGS} -q \
440	    update ${CVSCMDARGS} -P -d -r ${RELEASETAG}
441.endif
442	rm -f ${CHROOTDIR}/tmp/.world_done
443.if !defined(NOPORTS) && !defined(EXTPORTSDIR)
444	cd ${CHROOTDIR}/usr/ports && ${CVSPREFIX} cvs -R ${CVSARGS} -q \
445	    update ${CVSCMDARGS} -P -d
446	rm -f ${CHROOTDIR}/tmp/.skip_ports_index
447.endif
448.if defined(DOMINIMALDOCPORTS) && ${DOMINIMALDOCPORTS} == "YES"
449	for i in ${MINIMALDOCPORTS}; do \
450	    ( cd ${CHROOTDIR}/usr/$$i && ${CVSPREFIX} cvs -R ${CVSARGS} -q \
451		update ${CVSCMDARGS} -P -d ) ; \
452	done
453.endif
454.if !defined(NODOC)
455	cd ${CHROOTDIR}/usr/doc && ${CVSPREFIX} cvs -R ${CVSARGS} -q \
456	    update ${CVSCMDARGS} -P -d
457.endif
458.endif
459.endif
460	# Add version information to those things that need it.
461	if [ ! -f ${CHROOTDIR}/tmp/.world_done ]; then \
462		cd ${CHROOTDIR}/usr/src/sys/conf && \
463		mv newvers.sh foo && \
464		sed "s/^RELEASE=.*/RELEASE=${BUILDNAME}/" foo > newvers.sh && \
465		rm foo; \
466	fi
467	-test -f install.cfg && cp install.cfg ${CHROOTDIR}/usr/src/release
468	echo "#!/bin/sh"			> ${_MK}
469	echo "set -ex"				>> ${_MK}
470	echo "trap 'umount /dev || true' 0"	>> ${_MK}
471	echo "_RELTARGET=\$${1:-doRELEASE}"	>> ${_MK}
472.for var in \
473	AUTO_KEYBOARD_DETECT \
474	BUILDNAME \
475	CD_PACKAGE_TREE \
476	DISTRIBUTIONS \
477	DOMINIMALDOCPORTS \
478	EXTRA_SRC \
479	FTP_PASSIVE_MODE \
480	FTP_PROXY \
481	HTTP_PROXY \
482	KERNELS \
483	KERNELS_BASE \
484	KERNEL_FLAGS \
485	MAKE_DVD \
486	MAKE_FLOPPIES \
487	MAKE_ISOS \
488	NOCDROM \
489	NODOC \
490	NOPORTS \
491	NO_SHARED \
492	NOSRC \
493	NO_CPU_CFLAGS \
494	NO_CPU_COPTFLAGS \
495	NO_FLOPPIES \
496	RELEASETAG \
497	RELNOTES_LANG \
498	SEPARATE_LIVEFS \
499	TARGET \
500	TARGET_ARCH \
501	WORLD_FLAGS
502.if defined(${var})
503	echo "export ${var}=\"${${var}}\""	>> ${_MK}
504.endif
505.endfor
506	# Don't remove this, or the build will fall over!
507	echo "export RELEASEDIR=${_R}"		>> ${_MK}
508	echo "export PATH=/bin:/usr/bin:/sbin:/usr/sbin:${LOCALDIR}"	>> ${_MK}
509	echo "export MANBUILDCAT=YES"		>> ${_MK}
510	# NB: these may fail if the host is running w/o devfs
511	echo "umount /dev >/dev/null 2>&1 || true" >> ${_MK}
512	echo "mount -t devfs devfs /dev >/dev/null 2>&1 || true"	>> ${_MK}
513	echo "if [ ! -c /dev/null ]; then" >> ${_MK}
514	echo "	echo /dev/null is not a device!" >> ${_MK}
515	echo "	exit 1" >> ${_MK}
516	echo "fi" >> ${_MK}
517	echo "if [ -x /etc/rc.d/ldconfig ]; then" >> ${_MK}
518	echo "	/etc/rc.d/ldconfig start"	>> ${_MK}
519	echo "else"				>> ${_MK}
520	echo "	ldconfig /lib /usr/lib /usr/local/lib || true" >> ${_MK}
521	echo "fi"				>> ${_MK}
522	echo "if [ ! -f /tmp/.world_done ]; then" >> ${_MK}
523	echo "	cd /usr/src"			>> ${_MK}
524	echo "	${CROSSMAKE} ${WORLD_FLAGS} -DNO_CLEAN buildworld && \\" >> ${_MK}
525	echo "	touch /tmp/.world_done || exit 1" >> ${_MK}
526	echo "fi"				>> ${_MK}
527	echo "if [ ! -f /tmp/.skip_ports_index ]; then" >> ${_MK}
528	echo "	echo \">>> make index started on \`LC_ALL=C TZ=GMT date\`\"" >> ${_MK}
529	echo "	for i in ${MAKEINDEXPORTS}"	>> ${_MK}
530	echo "	do"			>> ${_MK}
531	echo "		cd /usr/ports/\$${i}"	>> ${_MK}
532	echo "		env -i FTP_PASSIVE_MODE=$${FTP_PASSIVE_MODE:-no} PATH=$${PATH} \\" >> ${_MK}
533	echo "		make all install clean BATCH=yes FORCE_PKG_REGISTER=yes" >> ${_MK}
534	echo "	done"				>> ${_MK}
535	echo "	cd /usr/ports"			>> ${_MK}
536	echo "	rm -f INDEX*"			>> ${_MK}
537	echo "	make index -DINDEX_PRISTINE"	>> ${_MK}
538	echo "	rm -f INDEX*.tmp"		>> ${_MK}
539	echo "	touch /tmp/.skip_ports_index"	>> ${_MK}
540	echo "	echo \">>> make index finished on \`LC_ALL=C TZ=GMT date\`\"" >> ${_MK}
541	echo "fi"				>> ${_MK}
542	echo "cd /usr/src/release"		>> ${_MK}
543	echo "make obj"				>> ${_MK}
544	echo "make \$${_RELTARGET}"		>> ${_MK}
545	echo "echo \">>> make ${.TARGET} for ${TARGET} finished on \`LC_ALL=C TZ=GMT date\`\"" >> ${_MK}
546	chmod 755 ${_MK}
547.if defined(NOPORTS)
548	touch ${CHROOTDIR}/tmp/.skip_ports_index
549.endif
550	# Ensure md.ko is loaded if md(4) is not statically compiled into
551	# the kernel
552	-mdconfig 2>/dev/null
553	env -i /usr/sbin/chroot `dirname ${_MK}` /`basename ${_MK}`
554
555clean:
556	rm -rf ${CRUNCH_TARGETS:S/$/_crunch/} release.[0-8] ${EXTRAS}
557
558fetch-distfiles:
559	@for i in ${MAKEINDEXPORTS}; do \
560		cd ${CHROOTDIR}/usr/ports/$$i && \
561			make PORTSDIR=${CHROOTDIR}/usr/ports BATCH=yes \
562			checksum-recursive ; \
563	done
564	@for i in ${DOCPORTS}; do \
565		cd ${CHROOTDIR}/usr/ports/$$i && \
566			make PORTSDIR=${CHROOTDIR}/usr/ports BATCH=yes \
567			WITHOUT_X11=yes JADETEX=no WITHOUT_PYTHON=yes \
568			checksum-recursive ; \
569	done
570
571# Clean out ${_R} and make the directory structure.
572release.1:
573	mkdir -p ${_R}
574	-rm -rf ${_R}/* 2> /dev/null
575	-chflags -R noschg ${_R}/.
576	rm -rf ${_R}/*
577	mkdir ${RD}
578.if defined(MAKE_FLOPPIES)
579	mkdir ${RD}/floppies
580.endif
581	mkdir ${RD}/trees
582	for i in ${DISTRIBUTIONS}; do \
583		mkdir ${RD}/trees/$$i && \
584		mtree -deU -f ${MTREEFILES}/BSD.root.dist \
585		    -p ${RD}/trees/$$i > /dev/null && \
586		mtree -deU -f ${MTREEFILES}/BSD.usr.dist \
587		    -p ${RD}/trees/$$i/usr > /dev/null && \
588		mtree -deU -f ${MTREEFILES}/BSD.include.dist \
589		    -p ${RD}/trees/$$i/usr/include > /dev/null && \
590		mtree -deU -f ${MTREEFILES}/BSD.var.dist \
591		    -p ${RD}/trees/$$i/var > /dev/null ; \
592	done
593	mkdir ${RD}/kernels
594	for i in ${KERNELS_BASE} ${KERNELS}; do \
595		mkdir -p ${RD}/kernels/$${i}; \
596	done
597	touch ${.TARGET}
598
599# Install the system into the various distributions.
600release.2:
601	cd ${.CURDIR}/.. && ${CROSSMAKE} distrib-dirs DESTDIR=${RD}/trees/base
602	cd ${.CURDIR}/.. && ${CROSSMAKE} ${WORLD_FLAGS} distributeworld \
603	    DISTDIR=${RD}/trees
604	touch ${.TARGET}
605
606# Make and install the generic kernel(s).
607release.3:
608.for kernel in ${KERNELS_BASE} ${KERNELS}
609	cd ${.CURDIR}/..; \
610	${CROSSMAKE} ${KERNEL_FLAGS} \
611 	    KERNCONF=${kernel} kernel \
612 	    DESTDIR=${RD}/kernels KODIR=/${kernel}
613.endfor
614	touch ${.TARGET}
615
616# Make and install the three crunched binaries which live on the floppies.
617# You are not supposed to like this :-)
618release.4:
619	rm -rf ${RD}/crunch
620	mkdir -p ${RD}/crunch
621.for j in ${CRUNCH_TARGETS}
622.if exists(${.CURDIR}/${TARGET}/${j}_crunch.conf)
623	rm -rf ${j}_crunch
624	mkdir ${j}_crunch
625	cd ${j}_crunch; ${WMAKEENV} MAKEFLAGS="-m ${.CURDIR}/../share/mk" \
626	    NO_WERROR= crunchgen -o \
627	    ${.CURDIR}/${TARGET}/${j}_crunch.conf
628	cd ${j}_crunch; ${WMAKE} -f ${j}_crunch.mk subclean
629	cd ${.CURDIR}/..; ${BINMAKE} -f Makefile.inc1 _build-tools
630	cd ${j}_crunch; CFLAGS="-Os -pipe" ${WMAKE} -f ${j}_crunch.mk \
631	    -DNO_CPU_CFLAGS all
632	${WMAKEENV} strip -R .comment ${j}_crunch/${j}_crunch
633	mv ${j}_crunch/${j}_crunch ${RD}/crunch/${j}
634.endif
635.endfor
636	touch ${.TARGET}
637
638#
639# --==## Fix up the distributions. ##==--
640#
641release.5:
642	# Create any "synthetic dists" now.
643	@for i in ${DISTRIBUTIONS}; do \
644		if [ -f ${.CURDIR}/scripts/$${i}-make.sh ]; then \
645			echo -n "Running $$i dist creation script... "; \
646			env RD=${RD} sh ${.CURDIR}/scripts/$${i}-make.sh || echo "$$i distribution script returned bad status."; \
647			echo "Done."; \
648		fi \
649	done \
650
651	# Remove all the directories we don't need.
652	-cd ${RD}/trees && \
653		(find ${OTHER_DISTS} -path '*/var/empty' | xargs chflags noschg; \
654		find ${OTHER_DISTS} -depth -type d -empty -print | xargs rmdir)
655	touch ${.TARGET}
656
657#
658# --==## Package up the tarballs from assembled trees ##==--
659#
660release.6:
661	rm -rf ${RD}/dists
662	mkdir -p ${RD}/dists
663	@for i in ${DISTRIBUTIONS} ; \
664	do \
665		if [ -d ${RD}/trees/$${i} ] ; then \
666			cd ${.CURDIR} && $(MAKE) doTARBALL \
667				SD=${RD}/trees/$${i} \
668				TN=$$i TD=$$i ARG="." && \
669			echo "$${i} distribution is finished."; \
670		fi ; \
671	done
672	@for i in ${KERNELS_BASE} ${KERNELS} ; \
673	do \
674		if [ -d ${RD}/kernels/$${i} ] ; then \
675			cd ${.CURDIR} && $(MAKE) doTARBALL \
676				SD=${RD}/kernels \
677				TN=$$i TD=kernels ARG="$$i" && \
678			echo "$${i} distribution is finished."; \
679		fi ; \
680	done
681.if !defined(NOPORTS)
682	# XXX: Inline stripped version of doTARBALL
683	@rm -rf ${RD}/dists/ports/ports*
684	@mkdir -p ${RD}/dists/ports
685	@echo rolling ports/ports tarball
686	@tar --exclude CVS --exclude .svn --exclude 'ports/distfiles/*' \
687	  -czf ${RD}/dists/ports/ports.tgz -C /usr ports
688	@cp ${.CURDIR}/scripts/ports-install.sh ${RD}/dists/ports/install.sh
689	@(cd ${RD}/dists/ports; \
690	  rm -f CHECKSUM.MD5 CHECKSUM.SHA256; \
691	  md5 * > .CHECKSUM.MD5; \
692	  sha256 * > .CHECKSUM.SHA256; \
693	  mv .CHECKSUM.MD5 CHECKSUM.MD5; \
694	  mv .CHECKSUM.SHA256 CHECKSUM.SHA256)
695	@echo "ports distribution is finished."
696.endif
697	touch ${.TARGET}
698
699
700#
701# --==## Make source dists ##==--
702#
703release.7:
704.if !defined(NOSRC)
705	@cd ${.CURDIR} && $(MAKE) doTARBALL SD=/usr/src \
706		TD=src TN=sbase ARG="[A-Z]*"
707	@for i in `cd /usr/src && echo [a-z]*` ; do \
708		if [ -d /usr/src/$$i ] ; then \
709			cd ${.CURDIR} && $(MAKE) doTARBALL \
710				TN=`echo s$$i | tr -d '.' | \
711				    sed -e 's/usr/u/' \
712					-e 's/kerberos5/krb5/'` \
713				SD=/usr/src TD=src ARG="$$i" ; \
714		fi ; \
715	done
716.if defined(EXTRA_SRC)
717	@set ${EXTRA_SRC} && \
718	while [ $$# -ge 2 ] ; do \
719		if [ -d /usr/src/$$1 ] ; then \
720			cd ${.CURDIR} && $(MAKE) doTARBALL \
721				SD=/usr/src TN="s$$2" TD=src ARG="$$1" ; \
722		fi && shift && shift ; \
723	done
724.endif
725	(cd ${RD}/dists/src; \
726	  rm -f CHECKSUM.MD5 CHECKSUM.SHA256; \
727	  md5 * > .CHECKSUM.MD5; \
728	  sha256 * > .CHECKSUM.SHA256; \
729	  mv .CHECKSUM.MD5 CHECKSUM.MD5; \
730	  mv .CHECKSUM.SHA256 CHECKSUM.SHA256)
731	@echo "src distribution is finished."
732.endif
733	touch ${.TARGET}
734
735# Build the memory root filesystem.
736release.8:
737	cp ${RD}/trees/base/etc/disktab /etc
738	rm -rf ${RD}/mfsfd
739	mkdir ${RD}/mfsfd
740	cd ${RD}/mfsfd && \
741		mkdir -p etc/defaults dev mnt stand/etc/defaults stand/help \
742		var/empty
743	@cd ${.CURDIR} && $(MAKE) installCRUNCH CRUNCH=boot \
744		DIR=${RD}/mfsfd/stand ZIP=false
745	( cd ${RD}/mfsfd && \
746	  for dir in bin sbin ; do \
747		ln -sf /stand $$dir; \
748	  done )
749	cp ${RD}/trees/base/sbin/dhclient-script ${RD}/mfsfd/stand
750	cp ${.CURDIR}/../etc/master.passwd ${RD}/mfsfd/etc/master.passwd
751	cp ${RD}/trees/base/etc/*pwd.db ${RD}/mfsfd/etc/
752	( for F in defaults/rc.conf netconfig protocols ; do \
753		sed -e '/^#.*$$/d' -e 's/[:space:]*#.*$$//g' \
754		${RD}/trees/base/etc/$$F > ${RD}/mfsfd/stand/etc/$$F ; \
755	  done )
756	grep -E '^(ftp|nameserver|domain|sunrpc|cmd|nfsd)[^-\w]' \
757	    ${RD}/trees/base/etc/services | \
758	    sed -e '/^#.*$$/d' -e 's/[:space:]*#.*$$//g' \
759	    > ${RD}/mfsfd/stand/etc/services
760	grep 'operator' ${RD}/trees/base/etc/group \
761	    > ${RD}/mfsfd/stand/etc/group
762	ln ${RD}/mfsfd/stand/etc/services ${RD}/mfsfd/etc/services
763	ln ${RD}/mfsfd/stand/etc/group ${RD}/mfsfd/etc/group
764	ln ${RD}/mfsfd/stand/etc/netconfig ${RD}/mfsfd/etc/netconfig
765	cp ${RD}/trees/base/COPYRIGHT ${RD}/mfsfd/stand/help/COPYRIGHT.hlp
766.if !defined(NODOC)
767	@for i in ${DIST_DOCS_ARCH_INDEP}; do \
768	  cp ${RND}/${RELNOTES_LANG}/$$i/article.txt \
769	      ${RD}/mfsfd/stand/help/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
770	done
771	@for i in ${DIST_DOCS_ARCH_DEP}; do \
772	  cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.txt \
773	      ${RD}/mfsfd/stand/help/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
774	done
775.endif
776	-test -f ${.CURDIR}/install.cfg \
777	    && cp ${.CURDIR}/install.cfg ${RD}/mfsfd
778	@mkdir -p ${RD}/mfsfd/boot
779.if ${TARGET_ARCH} != "ia64" && ${TARGET_ARCH} != "powerpc"
780	@cp ${RD}/trees/base/boot/boot* ${RD}/mfsfd/boot
781.endif
782.if ${TARGET} == "i386" || ${TARGET_ARCH} == "amd64"
783	@cp ${RD}/trees/base/boot/mbr ${RD}/mfsfd/boot
784.endif
785	@tar --exclude CVS --exclude .svn -cf - \
786		-C ${.CURDIR}/../usr.sbin/sysinstall help | \
787		tar xf - -C ${RD}/mfsfd/stand
788	@mkdir -p ${RD}/mfsroot
789	sh -e ${DOFS_SH} ${RD}/mfsroot/mfsroot ${RD} ${MNT} \
790	    ${MFSSIZE} ${RD}/mfsfd ${MFSINODE} ${MFSLABEL}
791	@${ZIPPER} -fv ${RD}/mfsroot/mfsroot
792	touch ${.TARGET}
793
794KERNFLOPPYSET=		${RD}/floppyset/kern/kernel.gz
795.if defined(SMALLFLOPPYSIZE)
796SMALLKERNFLOPPYSET=	${RD}/floppyset/kern-small/kernel.gz
797.endif
798.if defined(SPLIT_MFSROOT)
799MFSROOTFLOPPYSET=	${RD}/floppyset/mfsroot/mfsroot.gz
800.if defined(SMALLFLOPPYSIZE)
801SMALLMFSROOTFLOPPYSET=	${RD}/floppyset/mfsroot-small/mfsroot.gz
802.endif
803.endif
804
805# Build boot and install floppies.
806floppies.1:
807	@${ZIPPER} -c ${RD}/kernels/GENERIC/kernel > ${RD}/kernels/kernel.gz
808	@echo "Making the kernel boot floppies..."
809	@cd ${.CURDIR} && ${MAKE} makeFloppySet FLOPPYBASE=kern \
810	    FLOPPYDESC="Kernel" SPLITFILE=${RD}/kernels/kernel.gz
811.if defined(SMALLFLOPPYSIZE)
812	@echo "Making the small kernel boot floppies..."
813	@cd ${.CURDIR} && ${MAKE} makeFloppySet FLOPPYBASE=kern-small \
814	    FLOPPYDESC="Kernel" SPLITFILE=${RD}/kernels/kernel.gz \
815	    FDSIZE="SMALL"
816.endif
817.if defined(SPLIT_MFSROOT)
818	@echo "Making the mfsroot boot floppies..."
819	@cd ${.CURDIR} && ${MAKE} makeFloppySet FLOPPYBASE=mfsroot \
820	    FLOPPYDESC="Memory Filesystem" SPLITFILE=${RD}/mfsroot/mfsroot.gz
821.if defined(SMALLFLOPPYSIZE)
822	@echo "Making the small mfsroot boot floppies..."
823	@cd ${.CURDIR} && ${MAKE} makeFloppySet FLOPPYBASE=mfsroot-small \
824	    FLOPPYDESC="Memory Filesystem" SPLITFILE=${RD}/mfsroot/mfsroot.gz \
825	    FDSIZE="SMALL"
826.endif
827	@cd ${.CURDIR} && ${MAKE} buildBootFloppy FSIMAGE="boot" \
828	    KERNFILE="${KERNFLOPPYSET}.split ${KERNFLOPPYSET}.boot" \
829	    MFSROOTFILE="${MFSROOTFLOPPYSET}.split ${MFSROOTFLOPPYSET}.boot"
830.if defined(SMALLFLOPPYSIZE)
831	@cd ${.CURDIR} && ${MAKE} buildBootFloppy FSIMAGE="boot-small" \
832	    KERNFILE="${SMALLKERNFLOPPYSET}.split ${SMALLKERNFLOPPYSET}.boot" \
833	    MFSROOTFILE="${SMALLMFSROOTFLOPPYSET}.split ${SMALLMFSROOTFLOPPYSET}.boot" \
834	    FDSIZE="SMALL"
835.endif
836.else	# !SPLIT_MFSROOT
837	@cd ${.CURDIR} && ${MAKE} buildBootFloppy FSIMAGE="boot" \
838	    KERNFILE="${KERNFLOPPYSET}.split ${KERNFLOPPYSET}.boot" \
839	    MFSROOTFILE=${RD}/mfsroot/mfsroot.gz
840.if defined(SMALLFLOPPYSIZE)
841	@cd ${.CURDIR} && ${MAKE} buildBootFloppy FSIMAGE="boot-small" \
842	    KERNFILE="${SMALLKERNFLOPPYSET}.split ${SMALLKERNFLOPPYSET}.boot" \
843	    MFSROOTFILE=${RD}/mfsroot/mfsroot.gz \
844	    FDSIZE="SMALL"
845.endif
846.endif	# SPLIT_MFSROOT
847	touch ${.TARGET}
848
849# Build fixit floppy.
850floppies.2:
851	@echo "Making fixit floppy."
852	@rm -rf ${RD}/fixitfd
853	@mkdir ${RD}/fixitfd
854	@cd ${RD}/fixitfd && \
855	    mkdir -p dev stand bin sbin etc mnt mnt1 mnt2 mnt3 mnt4 tmp \
856	    usr/share/misc
857	@cp ${RD}/trees/base/etc/spwd.db ${RD}/trees/base/etc/group \
858	    ${RD}/fixitfd/etc
859	@sed -e 's/#.*//' ${RD}/trees/base/etc/protocols \
860	    > ${RD}/fixitfd/etc/protocols
861	@sed -e 's/#.*//' ${RD}/trees/base/usr/share/misc/scsi_modes \
862	    > ${RD}/fixitfd/usr/share/misc/scsi_modes
863	@cp ${.CURDIR}/fixit.profile ${RD}/fixitfd/.profile
864	@cp ${.CURDIR}/fixit.services ${RD}/fixitfd/etc/services
865	@cp ${.CURDIR}/scripts/tar.sh ${RD}/fixitfd/stand/tar
866	@chmod 555 ${RD}/fixitfd/stand/tar
867.if defined(SMALLFLOPPYSIZE)
868	@cd ${.CURDIR} && ${MAKE} installCRUNCH CRUNCH=fixit-small \
869	    DIR=${RD}/fixitfd/stand ZIP=false
870	@sh -e ${DOFS_SH} ${RD}/floppies/fixit-small.flp ${RD} ${MNT} \
871	    ${SMALLFLOPPYSIZE} ${RD}/fixitfd ${FLOPPYINODE} ${SMALLFLOPPYLABEL}
872	@rm -rf ${RD}/fixitfd/stand
873	@mkdir ${RD}/fixitfd/stand
874.endif
875	@cd ${.CURDIR} && ${MAKE} installCRUNCH CRUNCH=fixit \
876	    DIR=${RD}/fixitfd/stand ZIP=false
877	@sh -e ${DOFS_SH} ${RD}/floppies/fixit.flp ${RD} ${MNT} \
878	    ${FLOPPYSIZE} ${RD}/fixitfd ${FLOPPYINODE} ${FLOPPYLABEL}
879	touch ${.TARGET}
880
881# Do our last minute floppies directory setup
882floppies.3:
883	@(cd ${RD}/floppies; md5 *.flp > CHECKSUM.MD5)
884	@(cd ${RD}/floppies; sha256 *.flp > CHECKSUM.SHA256)
885	touch ${.TARGET}
886
887#
888# --==## Setup a suitable ftp-area ##==--
889#
890ftp.1:
891	@echo "Setting up FTP distribution area"
892	@mkdir -p ${FD}
893	-@ln -s . ${FD}/${BUILDNAME}
894.if defined(MAKE_FLOPPIES)
895	@cd ${RD} && find floppies -print | cpio -dumpl ${FD}
896.endif
897	@cd ${RD}/dists && find . -print | cpio -dumpl ${FD}
898.if !defined(NODOC)
899	@for i in ${DIST_DOCS_ARCH_INDEP}; do \
900		cp ${RND}/${RELNOTES_LANG}/$$i/article.txt \
901		    ${FD}/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
902		cp ${RND}/${RELNOTES_LANG}/$$i/article.html \
903		    ${FD}/`echo $${i} | tr 'a-z' 'A-Z'`.HTM; \
904	done
905	@for i in ${DIST_DOCS_ARCH_DEP}; do \
906		cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.txt \
907		    ${FD}/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
908		cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.html \
909		    ${FD}/`echo $${i} | tr 'a-z' 'A-Z'`.HTM; \
910	done
911	@cp ${RND}/${RELNOTES_LANG}/readme/docbook.css ${FD}
912.endif
913	@echo "CD_VERSION = ${BUILDNAME}" > ${FD}/cdrom.inf
914	touch ${.TARGET}
915
916# Build a live filesystem cdrom image
917cdrom.1:
918	@echo "Building CDROM live filesystem image"
919	@mkdir -p ${CD_LIVEFS}
920	@for i in ${DISTRIBUTIONS} ; \
921	do \
922		if [ -d ${RD}/trees/$${i} ] ; then \
923			chflags -R noschg ${RD}/trees/$${i} || true ; \
924			( cd ${RD}/trees/$${i} && \
925			    find . -depth -print | cpio -dumpl ${CD_LIVEFS} ) ; \
926		fi \
927	done
928.if defined(MAKE_DVD)
929	@echo "Building DVD filesystem image as well as CDROM"
930	@mkdir -p ${CD_DVD1}/${BUILDNAME}
931	@for i in ${DISTRIBUTIONS} ; \
932	do \
933		if [ -d ${RD}/trees/$${i} ] ; then \
934			chflags -R noschg ${RD}/trees/$${i} || true ; \
935			( cd ${RD}/trees/$${i} && \
936			    find . -depth -print | cpio -dumpl ${CD_DVD1} ) ; \
937		fi \
938	done
939.endif
940	@echo "Copy GENERIC kernel to boot area"
941	@cp -Rp ${RD}/kernels/GENERIC/ ${CD_LIVEFS}/boot/kernel
942	@rm -f ${CD_LIVEFS}/boot/kernel/*.symbols
943	@rm -f ${CD_LIVEFS}/.profile
944	@cp ${.CURDIR}/fixit.profile ${CD_LIVEFS}/.profile
945	@ln -sf /rescue ${CD_LIVEFS}/stand
946	@echo "Setting up CDROM boot area"
947	@rm -f ${CD_LIVEFS}/boot/loader.conf
948	@cp ${RD}/mfsroot/mfsroot.gz ${CD_LIVEFS}/boot/mfsroot.gz
949	@echo 'mfsroot_load="YES"' > ${CD_LIVEFS}/boot/loader.conf
950	@echo 'mfsroot_type="mfs_root"' >> ${CD_LIVEFS}/boot/loader.conf
951	@echo 'mfsroot_name="/boot/mfsroot"' >> ${CD_LIVEFS}/boot/loader.conf
952.if exists(${RD}/trees/base/boot/device.hints)
953	# Break the link to device.hints so we can modify it
954	@rm -f ${CD_LIVEFS}/boot/device.hints
955	@cp ${RD}/trees/base/boot/device.hints ${CD_LIVEFS}/boot/device.hints
956.endif
957	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_LIVEFS}/cdrom.inf
958.if defined(MAKE_DVD)
959	@cp -Rp ${RD}/kernels/GENERIC/ ${CD_DVD1}/boot/kernel
960	@rm -f ${CD_DVD1}/boot/kernel/*.symbols
961	@rm -f ${CD_DVD1}/.profile
962	@cp ${.CURDIR}/fixit.profile ${CD_DVD1}/.profile
963	@ln -sf /rescue ${CD_DVD1}/stand
964	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_DVD1}/cdrom.inf
965	@rm -f ${CD_DVD1}/boot/loader.conf
966	@cp ${RD}/mfsroot/mfsroot.gz ${CD_DVD1}/boot/mfsroot.gz
967	@echo 'mfsroot_load="YES"' > ${CD_DVD1}/boot/loader.conf
968	@echo 'mfsroot_type="mfs_root"' >> ${CD_DVD1}/boot/loader.conf
969	@echo 'mfsroot_name="/boot/mfsroot"' >> ${CD_DVD1}/boot/loader.conf
970.if exists(${RD}/trees/base/boot/device.hints)
971	@rm -f ${CD_DVD1}/boot/device.hints
972	@cp ${RD}/trees/base/boot/device.hints ${CD_DVD1}/boot/device.hints
973.endif
974.endif
975	touch ${.TARGET}
976
977# Build disc1 and disc2 cdrom images
978cdrom.2:
979	@echo "Building CDROM disc1 filesystem image"
980	@mkdir -p ${CD_DISC1}/${BUILDNAME}
981.if defined(MAKE_FLOPPIES)
982	@cd ${RD} && find floppies -print | cpio -dumpl ${CD_DISC1}
983.endif
984	@cd ${RD}/dists && find . -print | cpio -dumpl ${CD_DISC1}/${BUILDNAME}
985.if !defined(NODOC)
986	@for i in ${DIST_DOCS_ARCH_INDEP}; do \
987	  cp ${RND}/${RELNOTES_LANG}/$$i/article.txt \
988	      ${CD_DISC1}/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
989	  cp ${RND}/${RELNOTES_LANG}/$$i/article.html \
990	      ${CD_DISC1}/`echo $${i} | tr 'a-z' 'A-Z'`.HTM; \
991	done
992	@for i in ${DIST_DOCS_ARCH_DEP}; do \
993	  cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.txt \
994	      ${CD_DISC1}/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
995	  cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.html \
996	      ${CD_DISC1}/`echo $${i} | tr 'a-z' 'A-Z'`.HTM; \
997	done
998	@cp ${RND}/${RELNOTES_LANG}/readme/docbook.css ${CD_DISC1}
999.endif
1000.if defined(SEPARATE_LIVEFS)
1001	@cp -Rp ${CD_LIVEFS}/boot ${CD_DISC1}
1002	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_DISC1}/cdrom.inf
1003.endif
1004	@echo "CD_VOLUME = 1" >> ${CD_DISC1}/cdrom.inf
1005	@echo "Building CDROM disc2 filesystem image"
1006	@mkdir -p ${CD_DISC2}
1007	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_DISC2}/cdrom.inf
1008	@echo "CD_VOLUME = 2" >> ${CD_DISC2}/cdrom.inf
1009.if defined(MAKE_DVD)
1010.if defined(MAKE_FLOPPIES)
1011	@cd ${RD} && find floppies -print | cpio -dumpl ${CD_DVD1}
1012.endif
1013	@cd ${RD}/dists && find . -print | cpio -dumpl ${CD_DVD1}/${BUILDNAME}
1014.if !defined(NODOC)
1015	@for i in ${DIST_DOCS_ARCH_INDEP}; do \
1016	  cp ${RND}/${RELNOTES_LANG}/$$i/article.txt \
1017	      ${CD_DVD1}/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
1018	  cp ${RND}/${RELNOTES_LANG}/$$i/article.html \
1019	      ${CD_DVD1}/`echo $${i} | tr 'a-z' 'A-Z'`.HTM; \
1020	done
1021	@for i in ${DIST_DOCS_ARCH_DEP}; do \
1022	  cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.txt \
1023	      ${CD_DVD1}/`echo $${i} | tr 'a-z' 'A-Z'`.TXT; \
1024	  cp ${RND}/${RELNOTES_LANG}/$$i/${TARGET}/article.html \
1025	      ${CD_DVD1}/`echo $${i} | tr 'a-z' 'A-Z'`.HTM; \
1026	done
1027	@cp ${RND}/${RELNOTES_LANG}/readme/docbook.css ${CD_DVD1}
1028.endif
1029	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_DVD1}/cdrom.inf
1030	@echo "CD_VOLUME = 1" >> ${CD_DVD1}/cdrom.inf
1031.endif
1032.if !defined(NODOC)
1033	@echo "Building CDROM docs filesystem image"
1034	@mkdir -p ${CD_DOCS}
1035	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_DOCS}/cdrom.inf
1036	@echo "CD_VOLUME = 3" >> ${CD_DOCS}/cdrom.inf
1037.endif
1038	touch ${.TARGET}
1039
1040#
1041# --==## Setup a suitable cdrom-area ##==--
1042#
1043cdrom.3:
1044.if defined(CD_BOOT)
1045	@echo "Building bootonly CDROM filesystem image"
1046	@mkdir -p ${CD_BOOT}
1047	@cp -Rp ${CD_LIVEFS}/boot ${CD_BOOT}
1048	@echo "CD_VERSION = ${BUILDNAME}" > ${CD_BOOT}/cdrom.inf
1049.if defined(MINIROOT)
1050	@echo "Building bootonly UFS filesystem image"
1051	@mkdir -p ${FD}/miniroot
1052	@sh -e ${DOFS_SH} ${FD}/miniroot/miniroot.ufs \
1053	    ${RD} ${MNT} 0 ${CD_BOOT} 8192 auto
1054	@${ZIPPER} -v ${FD}/miniroot/miniroot.ufs
1055.endif
1056.endif
1057	touch ${.TARGET}
1058
1059.if make(iso.1)
1060.if defined(CD_PACKAGE_TREE)
1061.if exists(${CD_PACKAGE_TREE}/disc1)
1062CD_DISC1_PKGS=	${CD_PACKAGE_TREE}/disc1
1063.endif
1064.if exists(${CD_PACKAGE_TREE}/disc2)
1065CD_DISC2_PKGS=	${CD_PACKAGE_TREE}/disc2
1066.endif
1067# scripts/package-trees.sh names all discs according to the "discX"
1068# scheme where X is the number of the disc
1069.if exists(${CD_PACKAGE_TREE}/disc3)
1070CD_DOCS_PKGS=	${CD_PACKAGE_TREE}/disc3
1071.endif
1072.if exists(${CD_PACKAGE_TREE}/dvd1)
1073CD_DVD1_PKGS=	${CD_PACKAGE_TREE}/dvd1
1074.endif
1075.endif
1076.endif
1077
1078iso.1:
1079.if exists(${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh)
1080	@echo "Creating ISO images..."
1081.if defined(CD_BOOT)
1082	@sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \
1083	    FreeBSD_bootonly \
1084	    ${CD}/${BUILDNAME}-${TARGET}-bootonly.iso ${CD_BOOT}
1085.endif
1086	@sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \
1087	    FreeBSD_Install \
1088	    ${CD}/${BUILDNAME}-${TARGET}-disc1.iso ${CD_DISC1} \
1089	    ${CD_DISC1_PKGS}
1090	@sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh \
1091	    FreeBSD_Packages \
1092	    ${CD}/${BUILDNAME}-${TARGET}-disc2.iso ${CD_DISC2} \
1093	    ${CD_DISC2_PKGS}
1094.if defined(MAKE_DVD)
1095	@sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \
1096	    FreeBSD_Install \
1097	    ${CD}/${BUILDNAME}-${TARGET}-dvd1.iso ${CD_DVD1} \
1098	    ${CD_DVD1_PKGS}
1099.endif
1100.if !defined(NODOC)
1101	@sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh \
1102	    FreeBSD_Documentation \
1103	    ${CD}/${BUILDNAME}-${TARGET}-disc3.iso ${CD_DOCS} \
1104	    ${CD_DOCS_PKGS}
1105.endif
1106.if defined(SEPARATE_LIVEFS)
1107	@sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \
1108	    FreeBSD_LiveFS \
1109	    ${CD}/${BUILDNAME}-${TARGET}-livefs.iso ${CD_LIVEFS}
1110.endif
1111	@echo "Generating MD5 and SHA256 sums..."
1112	@(cd ${CD} && md5 *.iso > ${BUILDNAME}-${TARGET}-iso.CHECKSUM.MD5)
1113	@(cd ${CD} && sha256 *.iso > ${BUILDNAME}-${TARGET}-iso.CHECKSUM.SHA256)
1114	touch ${.TARGET}
1115.else
1116	@echo "Do not know how to create an ISO for ${TARGET_ARCH}."
1117.endif
1118
1119#
1120# --==## Documentation Project files such as the Handbook and FAQ ##==--
1121#
1122doc.1:
1123	@echo "Making docs..."
1124	@for i in ${DOCPORTS}; do \
1125	    cd /usr/ports/$$i && \
1126	    env -i FTP_PASSIVE_MODE=$${FTP_PASSIVE_MODE:-no} PATH=$${PATH} \
1127		make all install clean BATCH=yes WITHOUT_X11=yes JADETEX=no \
1128		WITHOUT_PYTHON=yes FORCE_PKG_REGISTER=yes; \
1129	done
1130	touch ${.TARGET}
1131
1132#
1133# --==## RELNOTESng:  Next-generation replacements for *.TXT files ##==--
1134#
1135doc.2:
1136	@echo "Making release documentation..."
1137	@cd ${.CURDIR}/doc && make all install clean 'FORMATS=html txt' \
1138	    INSTALL_COMPRESSED='' URLS_ABSOLUTE=YES DOCDIR=${RND}
1139	touch ${.TARGET}
1140
1141# Various "subroutine" and other supporting targets.
1142
1143# RD=
1144# SD=
1145# TD=
1146# ARG=
1147doTARBALL:
1148.if !defined(SD)
1149	@echo "SD undefined in doTARBALL" && exit 1
1150.endif
1151.if !defined(TD)
1152	@echo "TD undefined in doTARBALL" && exit 1
1153.endif
1154.if !defined(ARG)
1155	@echo "ARG undefined in doTARBALL" && exit 1
1156.endif
1157	@rm -rf ${RD}/dists/${TD}/${TN}*
1158	@mkdir -p ${RD}/dists/${TD}
1159	@( cd ${SD} && \
1160		tn=`echo ${TN} | tr 'A-Z' 'a-z'` && \
1161		echo rolling ${TD}/$$tn tarball &&\
1162		tar --exclude CVS --exclude .svn --exclude obj --exclude BOOTMFS -cf - ${ARG} | \
1163		${ZIPNSPLIT} ${RD}/dists/${TD}/$$tn. && \
1164		sh ${.CURDIR}/scripts/info.sh ${RD}/dists/${TD}/$$tn \
1165		    > ${RD}/dists/${TD}/$$tn.inf && \
1166		if [ -f ${.CURDIR}/scripts/$${TD}-install.sh ]; then \
1167			cp -p ${.CURDIR}/scripts/$${TD}-install.sh \
1168			    ${RD}/dists/${TD}/install.sh && \
1169			chmod +x ${RD}/dists/${TD}/install.sh; \
1170		fi && \
1171		if [ "${SD}" != "/usr/src" ]; then \
1172			mtree -c -i -p ${SD}/${ARG} \
1173			  -k gname,md5digest,mode,nlink,uname,size,link,type \
1174			  > ${RD}/dists/${TD}/$$tn.mtree ; \
1175		else \
1176			true; \
1177		fi; \
1178		( cd ${RD}/dists/${TD}; \
1179		rm -f CHECKSUM.MD5 CHECKSUM.SHA256; \
1180		md5 * > .CHECKSUM.MD5; \
1181		sha256 * > .CHECKSUM.SHA256; \
1182		mv .CHECKSUM.MD5 CHECKSUM.MD5; \
1183		mv .CHECKSUM.SHA256 CHECKSUM.SHA256) \
1184	)
1185
1186doRELEASE: release.1 release.2 ${DOCREL} release.3 release.4 \
1187    release.5 release.6 release.7 release.8 ${EXTRAS}
1188	@echo "Release done"
1189
1190floppies:
1191	@rm -f release.4 release.8 floppies.[123]
1192	@cd ${.CURDIR} && ${MAKE} release.4 release.8 floppies.1 floppies.2 \
1193	    floppies.3
1194	@cd ${RD} && find floppies -print | cpio -dumpl ${FD}
1195
1196installCRUNCH:
1197.if !defined(CRUNCH)
1198	@echo "CRUNCH undefined in installCRUNCH" && exit 1
1199.endif
1200.if !defined(DIR)
1201	@echo "DIR undefined in installCRUNCH" && exit 1
1202.endif
1203.if !defined(ZIP)
1204	@echo "ZIP undefined in installCRUNCH" && exit 1
1205.endif
1206	@if ${ZIP} ; then \
1207		${ZIPPER} < ${RD}/crunch/${CRUNCH} > ${DIR}/${CRUNCH}_crunch ; \
1208	else \
1209		ln -f ${RD}/crunch/${CRUNCH} ${DIR}/${CRUNCH}_crunch ; \
1210	fi
1211	@chmod 555 ${DIR}/${CRUNCH}_crunch
1212	@if [ -f ${.CURDIR}/${TARGET}/${CRUNCH}_crunch.conf ] ; then \
1213		for i in `crunchgen -l ${.CURDIR}/${TARGET}/${CRUNCH}_crunch.conf` ; do \
1214			ln -f ${DIR}/${CRUNCH}_crunch ${DIR}/$$i ; \
1215		done \
1216	else \
1217		for i in `crunchgen -l ${.CURDIR}/${CRUNCH}_crunch.conf` ; do \
1218			ln -f ${DIR}/${CRUNCH}_crunch ${DIR}/$$i ; \
1219		done \
1220	fi
1221
1222#
1223# --==## Build a floppy set for a splitfs file ##==--
1224#
1225# FLOPPYBASE - basename of floppy image files
1226# FLOPPYDESC - description of floppy set
1227# SPLITFILE - filename of the file to split
1228# FDSIZE - if specified and "small", small floppy is created
1229
1230.if make(makeFloppySet)
1231SPLITDIR=	${RD}/floppyset/${FLOPPYBASE}
1232.if defined(FDSIZE) && ${FDSIZE} == "SMALL"
1233FLPSPLITSIZE=	${SMALLFLOPPYSPLITSIZE}
1234FLPSIZE=	${SMALLFLOPPYSIZE}
1235FLPLABEL=	${SMALLFLOPPYLABEL}
1236.else
1237FLPSPLITSIZE=	${FLOPPYSPLITSIZE}
1238FLPSIZE=	${FLOPPYSIZE}
1239FLPLABEL=	${FLOPPYLABEL}
1240.endif
1241.endif
1242
1243makeFloppySet:
1244.if !defined(FLOPPYBASE)
1245	@echo "FLOPPYBASE undefined in ${.TARGET}" && exit 1
1246.endif
1247.if !defined(FLOPPYDESC)
1248	@echo "FLOPPYDESC undefined in ${.TARGET}" && exit 1
1249.endif
1250.if !defined(SPLITFILE)
1251	@echo "SPLITFILE undefined in ${.TARGET}" && exit 1
1252.endif
1253	sh ${.CURDIR}/scripts/split-file.sh ${SPLITFILE} \
1254	    ${RD}/floppyset/${FLOPPYBASE} ${FLPSPLITSIZE} "${FLOPPYDESC}"
1255	( splitfile=${SPLITDIR}/`basename ${SPLITFILE}`.split ; \
1256	lines=`cat $${splitfile} | wc -l`; \
1257	lines=$$(($$lines - 1)) ; \
1258	for line in `jot $$lines`; do \
1259		file=`head -n $$(($${line} + 1)) $${splitfile} | tail -1 | cut -f 1 -d ' '` ; \
1260		sh -e ${DOFS_SH} ${RD}/floppies/${FLOPPYBASE}$${line}.flp \
1261		${RD} ${MNT} ${FLPSIZE} ${SPLITDIR}/$${file} \
1262		${BOOTINODE} ${FLPLABEL}; \
1263	done )
1264
1265#
1266# --==## Build a boot floppy ##==--
1267#
1268# FSIMAGE - base floppy image name
1269# FDSIZE - if specified and "small", small floppy is created
1270# KERNFILE - path to kernel split file
1271# MFSROOTFILE - path to mfsroot split file
1272
1273.if make(buildBootFloppy)
1274IMAGEDIR=	${RD}/image.${FSIMAGE}
1275BOOTDIR=	${RD}/trees/base/boot
1276HINTSFILE=	${BOOTDIR}/device.hints
1277ACPI_KO=	${RD}/kernels/GENERIC/acpi.ko
1278IMAGEFILE=	${RD}/floppies/${FSIMAGE}.flp
1279.if defined(FDSIZE) && ${FDSIZE} == "SMALL"
1280FLPSIZE=	${SMALLFLOPPYSIZE}
1281FLPLABEL=	${SMALLFLOPPYLABEL}
1282.else
1283FLPSIZE=	${FLOPPYSIZE}
1284FLPLABEL=	${FLOPPYLABEL}
1285.endif
1286.endif
1287
1288buildBootFloppy:
1289.if !defined(FSIMAGE)
1290	@echo "FSIMAGE undefined in ${.TARGET}" && exit 1
1291.endif
1292.if !defined(KERNFILE)
1293	@echo "KERNFILE undefined in ${.TARGET}" && exit 1
1294.endif
1295.if !defined(MFSROOTFILE)
1296	@echo "MFSROOTFILE undefined in ${.TARGET}" && exit 1
1297.endif
1298	@echo "Running ${.TARGET} for ${FSIMAGE}"
1299	@rm -rf ${IMAGEDIR}
1300	@mkdir ${IMAGEDIR}
1301	@echo "Setting up /boot directory for ${FSIMAGE} floppy"
1302	@mkdir -p ${IMAGEDIR}/boot
1303.if ${TARGET} == "i386"
1304	@${WMAKEENV} kgzip -v -l ${RD}/trees/base/usr/lib/kgzldr.o -o \
1305	    ${IMAGEDIR}/boot/loader ${BOOTDIR}/loader
1306.else
1307	@cp ${BOOTDIR}/loader ${IMAGEDIR}/boot
1308.endif
1309	@cp -Rp ${BOOTDIR}/*.4th ${BOOTDIR}/defaults ${BOOTDIR}/loader.help \
1310	    ${BOOTDIR}/loader.rc ${IMAGEDIR}/boot
1311.if exists(${HINTSFILE})
1312	@cp ${HINTSFILE} ${IMAGEDIR}/boot/device.hints
1313	@${ZIPPER} ${IMAGEDIR}/boot/device.hints
1314.endif
1315	@${ZIPPER} ${IMAGEDIR}/boot/*.4th ${IMAGEDIR}/boot/loader.help \
1316	    ${IMAGEDIR}/boot/defaults/loader.conf
1317	@echo 'bootfile="/kernel"' > ${IMAGEDIR}/boot/loader.conf
1318.if exists(${ACPI_KO})
1319	@${ZIPPER} -c ${ACPI_KO} > ${IMAGEDIR}/acpi.ko.gz
1320	@echo 'acpi_load="YES"' >> ${IMAGEDIR}/boot/loader.conf
1321	@echo 'acpi_name="/acpi.ko"' >> ${IMAGEDIR}/boot/loader.conf
1322	@echo 'acpi_before="read -p \"Insert boot floppy and press Enter\""' >> ${IMAGEDIR}/boot/loader.conf
1323.endif
1324	@echo 'mfsroot_load="YES"' >> ${IMAGEDIR}/boot/loader.conf
1325	@echo 'mfsroot_type="mfs_root"' >> ${IMAGEDIR}/boot/loader.conf
1326	@echo 'mfsroot_name="/mfsroot"' >> ${IMAGEDIR}/boot/loader.conf
1327.if !exists(${ACPI_KO})
1328	@echo 'mfsroot_before="read -p \"Insert boot floppy and press Enter\""' >> ${IMAGEDIR}/boot/loader.conf
1329.endif
1330.if defined(SPLIT_MFSROOT)
1331	@echo 'mfsroot_after="read -p \"Insert boot floppy and press Enter\""' >> ${IMAGEDIR}/boot/loader.conf
1332.endif
1333.if ${TARGET_ARCH} == "i386" || ${TARGET_ARCH} == "amd64"
1334.if ${AUTO_KEYBOARD_DETECT}
1335	@echo "-P" >> ${IMAGEDIR}/boot.config
1336.endif
1337.endif
1338	@rm -f ${IMAGEFILE}
1339	@cp ${KERNFILE} ${MFSROOTFILE} ${IMAGEDIR}
1340	sh -e ${DOFS_SH} ${IMAGEFILE} ${RD} ${MNT} ${FLPSIZE} ${IMAGEDIR} \
1341	    ${BOOTINODE} ${FLPLABEL}
1342	@echo "Created ${RD}/floppies/${FSIMAGE}.flp"
1343
1344.if make(package-split)
1345# Targets related to making a package split
1346#
1347# PKG_COPY instructs the script to copy the actual package files rather than
1348#     make hard links
1349# PKG_TREE is the path to the package tree to be split
1350# PKG_DEST is the path to the destination tree to create the split in
1351# PKG_VERBOSE asks for verbose output of the layout process
1352# PKG_INDEX is the path to the INDEX file. By default ${PKG_TREE}/INDEX.
1353
1354.if defined(PKG_COPY)
1355PKG_DO_COPY=	cp
1356.else
1357PKG_DO_COPY=	ln
1358.endif
1359PKG_WRKIDX=	${PKG_DEST}/INDEX.master
1360PKG_ENV?=
1361.if defined(TARGET_ARCH)
1362PKG_ENV+=	PKG_ARCH=${TARGET_ARCH}
1363.endif
1364.if defined(PKG_VERBOSE)
1365PKG_ENV+=	PKG_VERBOSE=1
1366.endif
1367PKG_INDEX?=	${PKG_TREE}/INDEX
1368
1369package-split:
1370.if !defined(PKG_TREE)
1371	@echo "PKG_TREE must be defined" && exit 1
1372.endif
1373.if !defined(PKG_DEST)
1374	@echo "PKG_DEST must be defined" && exit 1
1375.endif
1376	@env ${PKG_ENV} python ${.CURDIR}/scripts/package-split.py \
1377	    ${PKG_INDEX} ${PKG_WRKIDX}
1378	@env ${PKG_ENV} sh ${.CURDIR}/scripts/package-trees.sh ${PKG_DO_COPY} \
1379	    ${PKG_WRKIDX} ${PKG_TREE} ${PKG_DEST}
1380.endif
1381
1382.include <bsd.obj.mk>
1383