xref: /netbsd-src/distrib/common/Makefile.bootcd (revision 80d9064ac03cbb6a4174695f0d5b237c8766d3d0)
1#	$NetBSD: Makefile.bootcd,v 1.25 2014/05/31 10:18:47 martin 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#	CDMAKEFSEXTRAOPTS additional options for makefs, e.g. -F specfile
29#	CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
30#	CDINSTKERNEL	instkernel directory (relative to ${.CURDIR})
31#	CDKERNELS	couples of the form:
32#				source	name_on_cd
33#	CDRUNTIME	files/directories to copy from $DESTDIR onto the CD
34# source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
35# note that as of yet, bootxx_cd9660 can't load kernel names of more than
36# 8 chars (though they can be in a sub-directory meaning the pathname is
37# longer than 8 chars)
38#
39
40BOOT?=		${DESTDIR}/usr/mdec/boot
41BOOTXX_CD9660?=	${DESTDIR}/usr/mdec/bootxx_cd9660
42CDRELEASE?=	false
43CDSOURCE?=	false
44.if ${CDRELEASE} == false
45CDROMS_RELEASEDIR?=	${MACHINE}/installation/cdrom
46.else
47CDROMS_RELEASEDIR?=	images
48.endif
49.if defined(CDRELEASE_NOISOS)
50CDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
51.endif
52.if !defined(CDRELEASE_LIVEIMAGE)
53CDRELEASE_EXCLUDE+=	-s ',./installation/liveimage.*,,gp'
54.endif
55.if !defined(CDRELEASE_INSTALLIMAGE)
56CDRELEASE_EXCLUDE+=	-s ',./installation/installimage.*,,gp'
57.endif
58
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.if ${MAKEVERBOSE} >= 2
121PAX_v?= -v
122.else
123PAX_v?=
124.endif
125
126# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
127#
128# XXX This could be done a lot easier if makefs(8) could
129# XXX include more than one directory on the image - HF
130#
131copy-releasedir:
132	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
133	if ${CDRELEASE}; then 						\
134		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
135			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
136			exit 1; 					\
137		fi; 							\
138		${MKDIR} cdrom/${MACHINE}; 				\
139		curdir=$$(pwd);						\
140		release_destdir=$$(pwd)/cdrom/${MACHINE}; 		\
141		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
142		echo Copying $$(pwd) to $$release_destdir ...; 		\
143		${TOOL_PAX} 						\
144			-rw -pe ${PAX_v}				\
145			${CDRELEASE_EXCLUDE}				\
146			. $$release_destdir; 				\
147		cd $$curdir;						\
148	fi
149	if ${CDSOURCE}; then 						\
150		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
151			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
152			exit 1; 					\
153		fi; 							\
154		${MKDIR} cdrom/source; 					\
155		curdir=$$(pwd);						\
156		release_destdir=$$(pwd)/cdrom/source;	 		\
157		cd ${RELEASEDIR}/source; 				\
158		echo Copying $$(pwd) to $$release_destdir ...;		\
159		${TOOL_PAX} 						\
160			-rw -pe ${PAX_v}				\
161			. $$release_destdir; 				\
162		cd $$curdir;						\
163	fi
164	if [ "X${CDRUNTIME}}" != "X" ]; then				\
165		curdir=$$(pwd);						\
166		release_destdir=$${curdir}/cdrom;			\
167		cd $$release_destdir;					\
168		cd ${DESTDIR};						\
169		for cde in ${CDRUNTIME};				\
170		do							\
171			${TOOL_PAX} -rw -pp ${PAX_v} $${cde} $$release_destdir;\
172		done;							\
173		cd $$curdir;						\
174	fi
175	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
176		curdir=`pwd`;						\
177		skipflag="";						\
178		cdextra_skip="${CDEXTRA_SKIP}";				\
179		if [ "X$${cdextra_skip}" != "X" ]; then			\
180			rm -f cdskip;					\
181			for skip in $${cdextra_skip};			\
182			do						\
183				echo $${skip} >> cdskip;		\
184			done;						\
185			skipflag="-X $${curdir}/cdskip";		\
186		fi;							\
187		cdextra="${CDEXTRA}"; 					\
188		cdbuildextra="${CDBUILDEXTRA}"; 			\
189		for cde in $${cdextra} $${cdbuildextra};		\
190		do							\
191			release_destdir=$${curdir}/cdrom;		\
192			if [ -f $${cde} ]; then				\
193				echo Copying $${cde} to $$release_destdir ...;	\
194				${CP} $${cde} $${release_destdir};	\
195			elif [ -d $${cde} ]; then			\
196				cd $${cde};				\
197				echo Copying $$(pwd) to $$release_destdir ...;	\
198				${TOOL_MTREE} -c $${skipflag} |		\
199					${TOOL_PAX} -rw -pe ${PAX_v} -M	\
200					$$release_destdir; 		\
201			else						\
202				echo "Missing $${cde}, aborting"; 	\
203				exit 1; 				\
204			fi; 						\
205			cd $$curdir;					\
206		done;							\
207	fi
208
209image:
210	${TOOL_MAKEFS} -t cd9660 ${CDMAKEFSEXTRAOPTS} -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
211
212.if ${CDRELEASE} == false
213release: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
214	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
215	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
216
217iso_image:
218.else
219release:
220
221iso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
222	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
223	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
224.endif
225
226clean:
227	${RM} -fr cdrom
228
229prepare_md_post: .PHONY
230image_md_post: .PHONY
231image_md_pre: .PHONY
232
233.include <bsd.prog.mk>
234