Makefile.bootcd revision 1.15
1#	$NetBSD: Makefile.bootcd,v 1.15 2008/11/21 14:49:45 ad 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?=	iso
47.endif
48.if defined(CDRELEASE_NOISOS)
49CDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
50.endif
51
52.include <bsd.sys.mk>		# for HOST_SH
53.include <bsd.own.mk> 		# For PRINTOBJDIR
54.include <bsd.kernobj.mk>	# For KERNSRCDIR
55
56DISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
57ISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
58PUBLISHER?= The_NetBSD_Project
59.if defined(CDMAKEFSOPTIONS)
60_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
61.else
62_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
63.endif
64
65# Stuff that should come from elsewhere - XXX where? - HF
66CP?=		cp
67RM?=		rm
68MKDIR?=		mkdir -p
69CHMOD?=		chmod
70
71
72CLEANFILES+=	${CDBASE}.iso
73CLEANFILES+=	bootxx.${MACHINE}
74
75
76.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
77
78.if defined(CDINSTKERNEL)
79_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
80.endif
81.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
82.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
83BOOT2=boot.${MACHINE}
84.else
85BOOT2=boot
86.endif
87.endif
88
89prepare:
90	${MKDIR} cdrom
91.if defined(CDKERNELS)
92.for kernel target in ${CDKERNELS}
93	${CP} ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
94.endfor
95.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
96	${RM} -f cdrom/${BOOT2}
97	${CP} ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
98	${RM} -f bootxx.${MACHINE}
99	${CP} ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
100	${CHMOD} +w bootxx.${MACHINE}
101.if defined(CDBOOTOPTIONS)
102	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
103.endif
104.endif
105.endif
106
107# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
108#
109# XXX This could be done a lot easier if makefs(8) could
110# XXX include more than one directory on the image - HF
111#
112copy-releasedir:
113	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDBASE}.iso
114	if ${CDRELEASE}; then 						\
115		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
116			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
117			exit 1; 					\
118		fi; 							\
119		${MKDIR} cdrom/${MACHINE}; 				\
120		curdir=$$(pwd);						\
121		release_destdir=$$(pwd)/cdrom/${MACHINE}; 		\
122		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
123		echo Copying $$(pwd) to $$release_destdir ...; 		\
124		${TOOL_PAX} 						\
125			-rw -pe -v 					\
126			${CDRELEASE_EXCLUDE}				\
127			. $$release_destdir; 				\
128		cd $$curdir;						\
129	fi
130	if ${CDSOURCE}; then 						\
131		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
132			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
133			exit 1; 					\
134		fi; 							\
135		${MKDIR} cdrom/source; 					\
136		curdir=$$(pwd);						\
137		release_destdir=$$(pwd)/cdrom/source;	 		\
138		cd ${RELEASEDIR}/source; 				\
139		echo Copying $$(pwd) to $$release_destdir ...;		\
140		${TOOL_PAX} 						\
141			-rw -pe -v 					\
142			. $$release_destdir; 				\
143		cd $$curdir;						\
144	fi
145	if [ "X${CDRUNTIME}}" != "X" ]; then				\
146		curdir=$$(pwd);						\
147		release_destdir=$${curdir}/cdrom;			\
148		cd $$release_destdir;					\
149		cd ${DESTDIR};						\
150		for cde in ${CDRUNTIME};				\
151		do							\
152			${TOOL_PAX} -rw -pp -v $${cde} $$release_destdir;\
153		done;							\
154		cd $$curdir;						\
155	fi
156	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
157		curdir=$$(pwd);						\
158		skipflag="";						\
159		if [ "X${CDEXTRA_SKIP}" != "X" ]; then			\
160			rm -f cdskip;					\
161			for skip in ${CDEXTRA_SKIP};			\
162			do						\
163				echo $${skip} >> cdskip;		\
164			done;						\
165			skipflag="-X $${curdir}/cdskip";		\
166		fi;							\
167		for cde in ${CDEXTRA} ${CDBUILDEXTRA};			\
168		do							\
169			release_destdir=$${curdir}/cdrom;		\
170			if [ -f $${cde} ]; then				\
171				echo Copying $${cde} to $$release_destdir ...;	\
172				${CP} $${cde} $${release_destdir};	\
173			elif [ -d $${cde} ]; then			\
174				cd $${cde};				\
175				echo Copying $$(pwd) to $$release_destdir ...;	\
176				${TOOL_MTREE} -c $${skipflag} |		\
177					${TOOL_PAX} -rw -pe -v -M	\
178					$$release_destdir; 		\
179			else						\
180				echo "Missing $${cde}, aborting"; 	\
181				exit 1; 				\
182			fi; 						\
183			cd $$curdir;					\
184		done;							\
185	fi
186
187image:
188	${TOOL_MAKEFS} -t cd9660 -o ${_CDMAKEFSOPTIONS:Q} ${CDBASE}.iso cdrom
189
190.if ${CDRELEASE} == false
191release: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
192	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
193	${RELEASE_INSTALL} ${CDBASE}.iso ${RELEASEDIR}/${CDROMS_RELEASEDIR}
194
195iso_image:
196.else
197release:
198
199iso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
200	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
201	${RELEASE_INSTALL} ${CDBASE}.iso ${RELEASEDIR}/${CDROMS_RELEASEDIR}
202.endif
203
204clean:
205	${RM} -fr cdrom
206
207prepare_md_post: .PHONY
208image_md_post: .PHONY
209image_md_pre: .PHONY
210
211.include <bsd.prog.mk>
212