Makefile.bootcd revision 1.18
11.18Sjmcneill#	$NetBSD: Makefile.bootcd,v 1.18 2012/01/14 22:56:30 jmcneill Exp $
21.1Shubertf#
31.1Shubertf# Makefile snipped to create a CD/DVD ISO
41.1Shubertf#
51.1Shubertf
61.1Shubertf# XXX TODO:
71.1Shubertf# 1) merge with src/distrib/cdrom
81.1Shubertf# 2) teach makefs to add data from more than 1 directory (see below)
91.1Shubertf
101.1Shubertf#
111.1Shubertf# Required variables:
121.1Shubertf#	CDBASE		Basename of the iso
131.1Shubertf#
141.1Shubertf# Optional variables:
151.1Shubertf#	CDRELEASE	Set to 'true' to include $RELEASEDIR/$MACHINE on the CD
161.7Shubertf#	CDRELEASE_NOISOS Excludes installation/cdrom directory if set
171.9Schristos#	CDSOURCE	Set to 'true' to include $RELEASEDIR/source on the CD
181.13Ssborrill#	CDEXTRA		Set to a list of files or directories containing extra
191.13Ssborrill#			stuff to put on CD (set by build.sh -C flag)
201.13Ssborrill#	CDBUILDEXTRA	Set to a list of files or directories containing extra
211.13Ssborrill#			stuff to put on CD (use in Makefiles)
221.13Ssborrill#	CDEXTRA_SKIP	A list of file exclusion paths to exclude when copying
231.13Ssborrill#			directories of extra stuff in CDEXTRA AND CDBUILDEXTRA
241.1Shubertf#	BOOT		Defaults to $DESTDIR/usr/mdec/boot
251.1Shubertf#	BOOTXX_CD9660	Defaults to $DESTDIR/usr/mdec/bootxx_cd9660
261.1Shubertf#	CDBOOTOPTIONS	Options for installboot, eg -o console=com0,speed=9600
271.8Sbouyer#	CDMAKEFSOPTIONS	Options for makefs, eg bootimage=i386;bootxx,no-emul-boot
281.1Shubertf#	CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
291.8Sbouyer#	CDINSTKERNEL	instkernel directory (relative to ${.CURDIR})
301.8Sbouyer#	CDKERNELS	couples of the form:
311.8Sbouyer#				source	name_on_cd
321.15Sad#	CDRUNTIME	files/directories to copy from $DESTDIR onto the CD
331.12Ssborrill# source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
341.12Ssborrill# note that as of yet, bootxx_cd9660 can't load kernel names of more than
351.12Ssborrill# 8 chars (though they can be in a sub-directory meaning the pathname is
361.12Ssborrill# longer than 8 chars)
371.1Shubertf#
381.1Shubertf
391.1ShubertfBOOT?=		${DESTDIR}/usr/mdec/boot
401.1ShubertfBOOTXX_CD9660?=	${DESTDIR}/usr/mdec/bootxx_cd9660
411.1ShubertfCDRELEASE?=	false
421.9SchristosCDSOURCE?=	false
431.8Sbouyer.if ${CDRELEASE} == false
441.8SbouyerCDROMS_RELEASEDIR?=	${MACHINE}/installation/cdrom
451.8Sbouyer.else
461.8SbouyerCDROMS_RELEASEDIR?=	iso
471.8Sbouyer.endif
481.7Shubertf.if defined(CDRELEASE_NOISOS)
491.7ShubertfCDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
501.7Shubertf.endif
511.1Shubertf
521.8Sbouyer.include <bsd.sys.mk>		# for HOST_SH
531.8Sbouyer.include <bsd.own.mk> 		# For PRINTOBJDIR
541.8Sbouyer.include <bsd.kernobj.mk>	# For KERNSRCDIR
551.8Sbouyer
561.18SjmcneillDISTRIBVER!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
571.8SbouyerDISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
581.8SbouyerISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
591.8SbouyerPUBLISHER?= The_NetBSD_Project
601.8Sbouyer.if defined(CDMAKEFSOPTIONS)
611.8Sbouyer_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
621.8Sbouyer.else
631.8Sbouyer_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
641.8Sbouyer.endif
651.8Sbouyer
661.1Shubertf# Stuff that should come from elsewhere - XXX where? - HF
671.1ShubertfCP?=		cp
681.1ShubertfRM?=		rm
691.1ShubertfMKDIR?=		mkdir -p
701.1ShubertfCHMOD?=		chmod
711.17SchristosECHO?=		echo
721.1Shubertf
731.18Sjmcneill.if ${CDRELEASE} == false
741.18SjmcneillCDIMAGE=	${CDBASE}.iso
751.18Sjmcneill.else
761.18SjmcneillCDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
771.18Sjmcneill.endif
781.1Shubertf
791.18SjmcneillCLEANFILES+=	${CDIMAGE}
801.8SbouyerCLEANFILES+=	bootxx.${MACHINE}
811.1Shubertf
821.1Shubertf
831.1Shubertf.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
841.1Shubertf
851.8Sbouyer.if defined(CDINSTKERNEL)
861.8Sbouyer_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
871.8Sbouyer.endif
881.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
891.8Sbouyer.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
901.8SbouyerBOOT2=boot.${MACHINE}
911.8Sbouyer.else
921.8SbouyerBOOT2=boot
931.8Sbouyer.endif
941.8Sbouyer.endif
951.1Shubertf
961.1Shubertfprepare:
971.1Shubertf	${MKDIR} cdrom
981.8Sbouyer.if defined(CDKERNELS)
991.8Sbouyer.for kernel target in ${CDKERNELS}
1001.8Sbouyer	${CP} ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
1011.8Sbouyer.endfor
1021.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1031.8Sbouyer	${RM} -f cdrom/${BOOT2}
1041.8Sbouyer	${CP} ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
1051.8Sbouyer	${RM} -f bootxx.${MACHINE}
1061.8Sbouyer	${CP} ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
1071.8Sbouyer	${CHMOD} +w bootxx.${MACHINE}
1081.8Sbouyer.if defined(CDBOOTOPTIONS)
1091.8Sbouyer	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
1101.8Sbouyer.endif
1111.8Sbouyer.endif
1121.8Sbouyer.endif
1131.1Shubertf
1141.1Shubertf# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
1151.1Shubertf#
1161.1Shubertf# XXX This could be done a lot easier if makefs(8) could
1171.1Shubertf# XXX include more than one directory on the image - HF
1181.1Shubertf#
1191.1Shubertfcopy-releasedir:
1201.18Sjmcneill	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
1211.9Schristos	if ${CDRELEASE}; then 						\
1221.14Smatt		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
1231.14Smatt			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
1241.9Schristos			exit 1; 					\
1251.9Schristos		fi; 							\
1261.9Schristos		${MKDIR} cdrom/${MACHINE}; 				\
1271.10Sjnemeth		curdir=$$(pwd);						\
1281.9Schristos		release_destdir=$$(pwd)/cdrom/${MACHINE}; 		\
1291.15Sad		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
1301.9Schristos		echo Copying $$(pwd) to $$release_destdir ...; 		\
1311.7Shubertf		${TOOL_PAX} 						\
1321.7Shubertf			-rw -pe -v 					\
1331.7Shubertf			${CDRELEASE_EXCLUDE}				\
1341.9Schristos			. $$release_destdir; 				\
1351.10Sjnemeth		cd $$curdir;						\
1361.9Schristos	fi
1371.9Schristos	if ${CDSOURCE}; then 						\
1381.9Schristos		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
1391.9Schristos			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
1401.9Schristos			exit 1; 					\
1411.9Schristos		fi; 							\
1421.9Schristos		${MKDIR} cdrom/source; 					\
1431.10Sjnemeth		curdir=$$(pwd);						\
1441.9Schristos		release_destdir=$$(pwd)/cdrom/source;	 		\
1451.9Schristos		cd ${RELEASEDIR}/source; 				\
1461.9Schristos		echo Copying $$(pwd) to $$release_destdir ...;		\
1471.9Schristos		${TOOL_PAX} 						\
1481.9Schristos			-rw -pe -v 					\
1491.9Schristos			. $$release_destdir; 				\
1501.10Sjnemeth		cd $$curdir;						\
1511.1Shubertf	fi
1521.15Sad	if [ "X${CDRUNTIME}}" != "X" ]; then				\
1531.15Sad		curdir=$$(pwd);						\
1541.15Sad		release_destdir=$${curdir}/cdrom;			\
1551.15Sad		cd $$release_destdir;					\
1561.15Sad		cd ${DESTDIR};						\
1571.15Sad		for cde in ${CDRUNTIME};				\
1581.15Sad		do							\
1591.15Sad			${TOOL_PAX} -rw -pp -v $${cde} $$release_destdir;\
1601.15Sad		done;							\
1611.15Sad		cd $$curdir;						\
1621.15Sad	fi
1631.13Ssborrill	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
1641.16Shubertf		curdir=`pwd`;						\
1651.13Ssborrill		skipflag="";						\
1661.16Shubertf		cdextra_skip="${CDEXTRA_SKIP}";				\
1671.16Shubertf		if [ "X$${cdextra_skip}" != "X" ]; then			\
1681.13Ssborrill			rm -f cdskip;					\
1691.16Shubertf			for skip in $${cdextra_skip};			\
1701.13Ssborrill			do						\
1711.13Ssborrill				echo $${skip} >> cdskip;		\
1721.13Ssborrill			done;						\
1731.13Ssborrill			skipflag="-X $${curdir}/cdskip";		\
1741.13Ssborrill		fi;							\
1751.16Shubertf		cdextra="${CDEXTRA}"; 					\
1761.16Shubertf		cdbuildextra="${CDBUILDEXTRA}"; 			\
1771.16Shubertf		for cde in $${cdextra} $${cdbuildextra};		\
1781.13Ssborrill		do							\
1791.13Ssborrill			release_destdir=$${curdir}/cdrom;		\
1801.13Ssborrill			if [ -f $${cde} ]; then				\
1811.13Ssborrill				echo Copying $${cde} to $$release_destdir ...;	\
1821.13Ssborrill				${CP} $${cde} $${release_destdir};	\
1831.13Ssborrill			elif [ -d $${cde} ]; then			\
1841.13Ssborrill				cd $${cde};				\
1851.13Ssborrill				echo Copying $$(pwd) to $$release_destdir ...;	\
1861.13Ssborrill				${TOOL_MTREE} -c $${skipflag} |		\
1871.13Ssborrill					${TOOL_PAX} -rw -pe -v -M	\
1881.13Ssborrill					$$release_destdir; 		\
1891.13Ssborrill			else						\
1901.13Ssborrill				echo "Missing $${cde}, aborting"; 	\
1911.13Ssborrill				exit 1; 				\
1921.13Ssborrill			fi; 						\
1931.13Ssborrill			cd $$curdir;					\
1941.13Ssborrill		done;							\
1951.11Sjnemeth	fi
1961.1Shubertf
1971.1Shubertfimage:
1981.18Sjmcneill	${TOOL_MAKEFS} -t cd9660 -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
1991.8Sbouyer
2001.8Sbouyer.if ${CDRELEASE} == false
2011.15Sadrelease: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
2021.8Sbouyer	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2031.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2041.1Shubertf
2051.8Sbouyeriso_image:
2061.8Sbouyer.else
2071.1Shubertfrelease:
2081.8Sbouyer
2091.15Sadiso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
2101.8Sbouyer	${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2111.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2121.8Sbouyer.endif
2131.1Shubertf
2141.1Shubertfclean:
2151.1Shubertf	${RM} -fr cdrom
2161.1Shubertf
2171.8Sbouyerprepare_md_post: .PHONY
2181.8Sbouyerimage_md_post: .PHONY
2191.15Sadimage_md_pre: .PHONY
2201.8Sbouyer
2211.1Shubertf.include <bsd.prog.mk>
222