xref: /netbsd-src/distrib/common/Makefile.bootcd (revision dd255ccea4286b0c44fa8fd48a9a19a768afe8e1)
1#	$NetBSD: Makefile.bootcd,v 1.22 2013/01/29 19:48:41 christos Exp $
2#
3# Makefile snipped to create a CD/DVD ISO
4#
5
6# XXX TODO:
7# 1) merge with src/distrib/cdrom
8# 2) teach makefs to add data from more than 1 directory (see below)
9
10#
11# Required variables:
12#	CDBASE		Basename of the iso
13#
14# Optional variables:
15#	CDRELEASE	Set to 'true' to include $RELEASEDIR/$MACHINE on the CD
16#	CDRELEASE_NOISOS Excludes installation/cdrom directory if set
17#	CDSOURCE	Set to 'true' to include $RELEASEDIR/source on the CD
18#	CDEXTRA		Set to a list of files or directories containing extra
19#			stuff to put on CD (set by build.sh -C flag)
20#	CDBUILDEXTRA	Set to a list of files or directories containing extra
21#			stuff to put on CD (use in Makefiles)
22#	CDEXTRA_SKIP	A list of file exclusion paths to exclude when copying
23#			directories of extra stuff in CDEXTRA AND CDBUILDEXTRA
24#	BOOT		Defaults to $DESTDIR/usr/mdec/boot
25#	BOOTXX_CD9660	Defaults to $DESTDIR/usr/mdec/bootxx_cd9660
26#	CDBOOTOPTIONS	Options for installboot, eg -o console=com0,speed=9600
27#	CDMAKEFSOPTIONS	Options for makefs, eg bootimage=i386;bootxx,no-emul-boot
28#	CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
29#	CDINSTKERNEL	instkernel directory (relative to ${.CURDIR})
30#	CDKERNELS	couples of the form:
31#				source	name_on_cd
32#	CDRUNTIME	files/directories to copy from $DESTDIR onto the CD
33# source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
34# note that as of yet, bootxx_cd9660 can't load kernel names of more than
35# 8 chars (though they can be in a sub-directory meaning the pathname is
36# longer than 8 chars)
37#
38
39BOOT?=		${DESTDIR}/usr/mdec/boot
40BOOTXX_CD9660?=	${DESTDIR}/usr/mdec/bootxx_cd9660
41CDRELEASE?=	false
42CDSOURCE?=	false
43.if ${CDRELEASE} == false
44CDROMS_RELEASEDIR?=	${MACHINE}/installation/cdrom
45.else
46CDROMS_RELEASEDIR?=	images
47.endif
48.if defined(CDRELEASE_NOISOS)
49CDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
50.endif
51.if !defined(CDRELEASE_LIVEIMAGE)
52CDRELEASE_EXCLUDE+=	-s ',./installation/liveimage.*,,gp'
53.endif
54.if !defined(CDRELEASE_INSTALLIMAGE)
55CDRELEASE_EXCLUDE+=	-s ',./installation/installimage.*,,gp'
56.endif
57
58.include <bsd.sys.mk>		# for HOST_SH
59.include <bsd.own.mk> 		# For PRINTOBJDIR
60.include <bsd.kernobj.mk>	# For KERNSRCDIR
61
62DISTRIBVER!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
63DISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
64ISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
65PUBLISHER?= The_NetBSD_Project
66.if defined(CDMAKEFSOPTIONS)
67_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
68.else
69_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
70.endif
71
72# Stuff that should come from elsewhere - XXX where? - HF
73CP?=		cp
74RM?=		rm
75MKDIR?=		mkdir -p
76CHMOD?=		chmod
77ECHO?=		echo
78
79.if ${CDRELEASE} == false
80CDIMAGE=	${CDBASE}.iso
81.else
82CDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
83.endif
84
85CLEANFILES+=	${CDIMAGE}
86CLEANFILES+=	bootxx.${MACHINE}
87
88
89.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
90
91.if defined(CDINSTKERNEL)
92_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
93.endif
94.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
95.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
96BOOT2=boot.${MACHINE}
97.else
98BOOT2=boot
99.endif
100.endif
101
102prepare:
103	${MKDIR} cdrom
104.if defined(CDKERNELS)
105.for kernel target in ${CDKERNELS}
106	${CP} ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
107.endfor
108.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
109	${RM} -f cdrom/${BOOT2}
110	${CP} ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
111	${RM} -f bootxx.${MACHINE}
112	${CP} ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
113	${CHMOD} +w bootxx.${MACHINE}
114.if defined(CDBOOTOPTIONS)
115	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
116.endif
117.endif
118.endif
119
120# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
121#
122# XXX This could be done a lot easier if makefs(8) could
123# XXX include more than one directory on the image - HF
124#
125copy-releasedir:
126	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
127	if ${CDRELEASE}; then 						\
128		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
129			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
130			exit 1; 					\
131		fi; 							\
132		${MKDIR} cdrom/${MACHINE}; 				\
133		curdir=$$(pwd);						\
134		release_destdir=$$(pwd)/cdrom/${MACHINE}; 		\
135		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
136		echo Copying $$(pwd) to $$release_destdir ...; 		\
137		${TOOL_PAX} 						\
138			-rw -pe -v 					\
139			${CDRELEASE_EXCLUDE}				\
140			. $$release_destdir; 				\
141		cd $$curdir;						\
142	fi
143	if ${CDSOURCE}; then 						\
144		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
145			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
146			exit 1; 					\
147		fi; 							\
148		${MKDIR} cdrom/source; 					\
149		curdir=$$(pwd);						\
150		release_destdir=$$(pwd)/cdrom/source;	 		\
151		cd ${RELEASEDIR}/source; 				\
152		echo Copying $$(pwd) to $$release_destdir ...;		\
153		${TOOL_PAX} 						\
154			-rw -pe -v 					\
155			. $$release_destdir; 				\
156		cd $$curdir;						\
157	fi
158	if [ "X${CDRUNTIME}}" != "X" ]; then				\
159		curdir=$$(pwd);						\
160		release_destdir=$${curdir}/cdrom;			\
161		cd $$release_destdir;					\
162		cd ${DESTDIR};						\
163		for cde in ${CDRUNTIME};				\
164		do							\
165			${TOOL_PAX} -rw -pp -v $${cde} $$release_destdir;\
166		done;							\
167		cd $$curdir;						\
168	fi
169	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
170		curdir=`pwd`;						\
171		skipflag="";						\
172		cdextra_skip="${CDEXTRA_SKIP}";				\
173		if [ "X$${cdextra_skip}" != "X" ]; then			\
174			rm -f cdskip;					\
175			for skip in $${cdextra_skip};			\
176			do						\
177				echo $${skip} >> cdskip;		\
178			done;						\
179			skipflag="-X $${curdir}/cdskip";		\
180		fi;							\
181		cdextra="${CDEXTRA}"; 					\
182		cdbuildextra="${CDBUILDEXTRA}"; 			\
183		for cde in $${cdextra} $${cdbuildextra};		\
184		do							\
185			release_destdir=$${curdir}/cdrom;		\
186			if [ -f $${cde} ]; then				\
187				echo Copying $${cde} to $$release_destdir ...;	\
188				${CP} $${cde} $${release_destdir};	\
189			elif [ -d $${cde} ]; then			\
190				cd $${cde};				\
191				echo Copying $$(pwd) to $$release_destdir ...;	\
192				${TOOL_MTREE} -c $${skipflag} |		\
193					${TOOL_PAX} -rw -pe -v -M	\
194					$$release_destdir; 		\
195			else						\
196				echo "Missing $${cde}, aborting"; 	\
197				exit 1; 				\
198			fi; 						\
199			cd $$curdir;					\
200		done;							\
201	fi
202
203image:
204	${TOOL_MAKEFS} -t cd9660 -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
205
206.if ${CDRELEASE} == false
207release: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
208	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
209	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
210
211iso_image:
212.else
213release:
214
215iso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
216	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
217	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
218.endif
219
220clean:
221	${RM} -fr cdrom
222
223prepare_md_post: .PHONY
224image_md_post: .PHONY
225image_md_pre: .PHONY
226
227.include <bsd.prog.mk>
228