Makefile.bootcd revision 1.39
11.39Smartin#	$NetBSD: Makefile.bootcd,v 1.39 2017/09/08 09:50:44 martin 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.39Smartin#	CDRELEASE_NODEBUG	Excludes debug sets if set
181.9Schristos#	CDSOURCE	Set to 'true' to include $RELEASEDIR/source on the CD
191.13Ssborrill#	CDEXTRA		Set to a list of files or directories containing extra
201.13Ssborrill#			stuff to put on CD (set by build.sh -C flag)
211.13Ssborrill#	CDBUILDEXTRA	Set to a list of files or directories containing extra
221.13Ssborrill#			stuff to put on CD (use in Makefiles)
231.13Ssborrill#	CDEXTRA_SKIP	A list of file exclusion paths to exclude when copying
241.13Ssborrill#			directories of extra stuff in CDEXTRA AND CDBUILDEXTRA
251.1Shubertf#	BOOT		Defaults to $DESTDIR/usr/mdec/boot
261.1Shubertf#	BOOTXX_CD9660	Defaults to $DESTDIR/usr/mdec/bootxx_cd9660
271.1Shubertf#	CDBOOTOPTIONS	Options for installboot, eg -o console=com0,speed=9600
281.8Sbouyer#	CDMAKEFSOPTIONS	Options for makefs, eg bootimage=i386;bootxx,no-emul-boot
291.25Smartin#	CDMAKEFSEXTRAOPTS additional options for makefs, e.g. -F specfile
301.1Shubertf#	CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
311.8Sbouyer#	CDINSTKERNEL	instkernel directory (relative to ${.CURDIR})
321.8Sbouyer#	CDKERNELS	couples of the form:
331.8Sbouyer#				source	name_on_cd
341.15Sad#	CDRUNTIME	files/directories to copy from $DESTDIR onto the CD
351.28Smartin#	CD_SETS		sets to be extracted onto the CD
361.28Smartin#	SETS_DIR	where the CD_SETS are found (default provided)
371.12Ssborrill# source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
381.12Ssborrill# note that as of yet, bootxx_cd9660 can't load kernel names of more than
391.12Ssborrill# 8 chars (though they can be in a sub-directory meaning the pathname is
401.12Ssborrill# longer than 8 chars)
411.1Shubertf#
421.1Shubertf
431.1ShubertfBOOT?=		${DESTDIR}/usr/mdec/boot
441.1ShubertfBOOTXX_CD9660?=	${DESTDIR}/usr/mdec/bootxx_cd9660
451.1ShubertfCDRELEASE?=	false
461.9SchristosCDSOURCE?=	false
471.8Sbouyer.if ${CDRELEASE} == false
481.8SbouyerCDROMS_RELEASEDIR?=	${MACHINE}/installation/cdrom
491.8Sbouyer.else
501.20SrizCDROMS_RELEASEDIR?=	images
511.8Sbouyer.endif
521.7Shubertf.if defined(CDRELEASE_NOISOS)
531.7ShubertfCDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
541.7Shubertf.endif
551.39Smartin.if defined(CDRELEASE_NODEBUG)
561.39SmartinCDRELEASE_EXCLUDE=+	-s ',./binary/sets/debug.tgz,,gp'	-s ',./binary/sets/xdebug.tgz,,gp'
571.39Smartin.endif
581.19Stsutsui.if !defined(CDRELEASE_LIVEIMAGE)
591.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/liveimage.*,,gp'
601.19Stsutsui.endif
611.19Stsutsui.if !defined(CDRELEASE_INSTALLIMAGE)
621.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/installimage.*,,gp'
631.19Stsutsui.endif
641.1Shubertf
651.28SmartinSETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
661.28Smartin
671.8Sbouyer.include <bsd.own.mk> 		# For PRINTOBJDIR
681.8Sbouyer.include <bsd.kernobj.mk>	# For KERNSRCDIR
691.8Sbouyer
701.18SjmcneillDISTRIBVER!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
711.8SbouyerDISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
721.28SmartinCUROBJDIR!=	cd ${.CURDIR} && ${PRINTOBJDIR}
731.8SbouyerISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
741.8SbouyerPUBLISHER?= The_NetBSD_Project
751.8Sbouyer.if defined(CDMAKEFSOPTIONS)
761.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
771.8Sbouyer.else
781.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
791.8Sbouyer.endif
801.8Sbouyer
811.34Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no"
821.34SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
831.37SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
841.33Schristos.endif
851.33Schristos
861.28Smartin.if ${MKUNPRIVED} == "no"
871.28SmartinCD_METALOG.unpriv=
881.31Smartinmtunpriv=
891.28Smartin.else
901.28SmartinCD_METALOG.unpriv=-M ${METALOG}.sanitised
911.29Smartinmtunpriv="-U"
921.28Smartin.endif
931.28Smartin
941.1Shubertf# Stuff that should come from elsewhere - XXX where? - HF
951.1ShubertfRM?=		rm
961.1ShubertfMKDIR?=		mkdir -p
971.1ShubertfCHMOD?=		chmod
981.17SchristosECHO?=		echo
991.1Shubertf
1001.18Sjmcneill.if ${CDRELEASE} == false
1011.18SjmcneillCDIMAGE=	${CDBASE}.iso
1021.18Sjmcneill.else
1031.18SjmcneillCDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
1041.18Sjmcneill.endif
1051.28SmartinWORKSPEC=	fs.spec
1061.1Shubertf
1071.18SjmcneillCLEANFILES+=	${CDIMAGE}
1081.8SbouyerCLEANFILES+=	bootxx.${MACHINE}
1091.28SmartinCLEANFILES+=	${WORKSPEC}
1101.1Shubertf
1111.28SmartinCDSETSENV=	DESTDIR=${DESTDIR:Q} \
1121.28Smartin		MACHINE=${MACHINE:Q} \
1131.28Smartin		MACHINE_ARCH=${MACHINE_ARCH:Q} \
1141.28Smartin		AWK=${TOOL_AWK:Q} \
1151.28Smartin		CKSUM=${TOOL_CKSUM:Q} \
1161.28Smartin		DB=${TOOL_DB:Q} \
1171.28Smartin		HOST_SH=${HOST_SH:Q} \
1181.28Smartin		MAKE=${MAKE:Q} \
1191.28Smartin		MKTEMP=${TOOL_MKTEMP:Q} \
1201.28Smartin		MTREE=${TOOL_MTREE:Q} \
1211.28Smartin		PAX=${TOOL_PAX:Q} \
1221.28Smartin		COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
1231.28Smartin		GZIP=${GZIP_FLAGS:Q} \
1241.28Smartin		PKG_CREATE=${TOOL_PKG_CREATE:Q} \
1251.28Smartin		SED=${TOOL_SED:Q} \
1261.28Smartin		TSORT=${TSORT:Q} \
1271.28Smartin		MKRUMP=no \
1281.28Smartin		MKCOMPAT=no \
1291.28Smartin		MKDEBUG=no \
1301.28Smartin		MKDEBUGLIB=no
1311.28Smartin
1321.28SmartinCDSETSCMD=	cd ${NETBSDSRCDIR}/distrib/sets && \
1331.28Smartin		${CDSETSENV} \
1341.28Smartin		${HOST_SH}
1351.1Shubertf
1361.1Shubertf.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
1371.1Shubertf
1381.8Sbouyer.if defined(CDINSTKERNEL)
1391.8Sbouyer_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
1401.8Sbouyer.endif
1411.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1421.8Sbouyer.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
1431.8SbouyerBOOT2=boot.${MACHINE}
1441.8Sbouyer.else
1451.8SbouyerBOOT2=boot
1461.8Sbouyer.endif
1471.8Sbouyer.endif
1481.1Shubertf
1491.1Shubertfprepare:
1501.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom"
1511.8Sbouyer.if defined(CDKERNELS)
1521.8Sbouyer.for kernel target in ${CDKERNELS}
1531.36Schristos	${INSTALL} ${COPY} -m 0644 ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
1541.8Sbouyer.endfor
1551.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1561.8Sbouyer	${RM} -f cdrom/${BOOT2}
1571.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
1581.8Sbouyer	${RM} -f bootxx.${MACHINE}
1591.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
1601.8Sbouyer	${CHMOD} +w bootxx.${MACHINE}
1611.8Sbouyer.if defined(CDBOOTOPTIONS)
1621.8Sbouyer	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
1631.8Sbouyer.endif
1641.8Sbouyer.endif
1651.8Sbouyer.endif
1661.1Shubertf
1671.24Sdsl.if ${MAKEVERBOSE} >= 2
1681.24SdslPAX_v?= -v
1691.24Sdsl.else
1701.24SdslPAX_v?=
1711.24Sdsl.endif
1721.24Sdsl
1731.1Shubertf# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
1741.1Shubertf#
1751.1Shubertf# XXX This could be done a lot easier if makefs(8) could
1761.1Shubertf# XXX include more than one directory on the image - HF
1771.1Shubertf#
1781.1Shubertfcopy-releasedir:
1791.18Sjmcneill	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
1801.9Schristos	if ${CDRELEASE}; then 						\
1811.28Smartin		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 	\
1821.14Smatt			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
1831.9Schristos			exit 1; 					\
1841.9Schristos		fi; 							\
1851.36Schristos		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/${MACHINE}"; 	\
1861.28Smartin		release_destdir="${CUROBJDIR}/cdrom/${MACHINE}";	\
1871.15Sad		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
1881.9Schristos		echo Copying $$(pwd) to $$release_destdir ...; 		\
1891.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP}				\
1901.24Sdsl			-rw -pe ${PAX_v}				\
1911.7Shubertf			${CDRELEASE_EXCLUDE}				\
1921.9Schristos			. $$release_destdir; 				\
1931.28Smartin		cd "${CUROBJDIR}";					\
1941.9Schristos	fi
1951.9Schristos	if ${CDSOURCE}; then 						\
1961.9Schristos		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
1971.9Schristos			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
1981.9Schristos			exit 1; 					\
1991.9Schristos		fi; 							\
2001.36Schristos		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/source"; 	\
2011.28Smartin		release_destdir="${CUROBJDIR}/cdrom/source";	 	\
2021.9Schristos		cd ${RELEASEDIR}/source; 				\
2031.9Schristos		echo Copying $$(pwd) to $$release_destdir ...;		\
2041.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP} 				\
2051.24Sdsl			-rw -pe ${PAX_v}				\
2061.9Schristos			. $$release_destdir; 				\
2071.28Smartin		cd "${CUROBJDIR}";					\
2081.1Shubertf	fi
2091.28Smartin	if [ "X${CDRUNTIME}" != "X" ]; then				\
2101.15Sad		release_destdir=$${curdir}/cdrom;			\
2111.15Sad		cd $$release_destdir;					\
2121.15Sad		cd ${DESTDIR};						\
2131.15Sad		for cde in ${CDRUNTIME};				\
2141.15Sad		do							\
2151.37Schristos			${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pp ${PAX_v}	\
2161.37Schristos				$${cde} $$release_destdir;		\
2171.15Sad		done;							\
2181.28Smartin		cd "${CUROBJDIR}";					\
2191.15Sad	fi
2201.13Ssborrill	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
2211.13Ssborrill		skipflag="";						\
2221.16Shubertf		cdextra_skip="${CDEXTRA_SKIP}";				\
2231.16Shubertf		if [ "X$${cdextra_skip}" != "X" ]; then			\
2241.13Ssborrill			rm -f cdskip;					\
2251.16Shubertf			for skip in $${cdextra_skip};			\
2261.13Ssborrill			do						\
2271.13Ssborrill				echo $${skip} >> cdskip;		\
2281.13Ssborrill			done;						\
2291.28Smartin			skipflag="-X ${CUROBJDIR:Q}/cdskip";		\
2301.13Ssborrill		fi;							\
2311.16Shubertf		cdextra="${CDEXTRA}"; 					\
2321.16Shubertf		cdbuildextra="${CDBUILDEXTRA}"; 			\
2331.16Shubertf		for cde in $${cdextra} $${cdbuildextra};		\
2341.13Ssborrill		do							\
2351.28Smartin			release_destdir="${CUROBJDIR}/cdrom";		\
2361.13Ssborrill			if [ -f $${cde} ]; then				\
2371.13Ssborrill				echo Copying $${cde} to $$release_destdir ...;	\
2381.38Schristos				${INSTALL} ${COPY} -m 0644 $${cde} $${release_destdir};	\
2391.13Ssborrill			elif [ -d $${cde} ]; then			\
2401.13Ssborrill				cd $${cde};				\
2411.13Ssborrill				echo Copying $$(pwd) to $$release_destdir ...;	\
2421.13Ssborrill				${TOOL_MTREE} -c $${skipflag} |		\
2431.37Schristos					${TOOL_PAX} ${PAX_TIMESTAMP}	\
2441.37Schristos					-rw -pe ${PAX_v}		\
2451.37Schristos					-M $$release_destdir; 		\
2461.13Ssborrill			else						\
2471.13Ssborrill				echo "Missing $${cde}, aborting"; 	\
2481.13Ssborrill				exit 1; 				\
2491.13Ssborrill			fi; 						\
2501.28Smartin			cd "${CUROBJDIR}";				\
2511.13Ssborrill		done;							\
2521.11Sjnemeth	fi
2531.28Smartin.if !empty(CD_SETS)
2541.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/etc/mtree"
2551.28Smartin.for set in ${CD_SETS}
2561.28Smartin	if [ -f ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set} ]; then	\
2571.28Smartin		${CHMOD} +w ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set};	\
2581.28Smartin	fi;								\
2591.28Smartin	${CDSETSCMD} ./maketars -i "${CUROBJDIR}/cdrom"			\
2601.29Smartin	    ${CD_METALOG.unpriv} ${mtunpriv} -N ${NETBSDSRCDIR}/etc	\
2611.28Smartin	    -F "${CUROBJDIR}/cdrom/etc/mtree"				\
2621.28Smartin	    -d "${DESTDIR:S,^$,/,}" ${set}
2631.28Smartin.endfor
2641.28Smartin	if [ -d "${CUROBJDIR}/cdrom/var/spool/ftp/hidden" ]; then	\
2651.28Smartin		${CHMOD} +r "${CUROBJDIR}/cdrom/var/spool/ftp/hidden";	\
2661.28Smartin	fi
2671.28Smartin.endif
2681.1Shubertf
2691.1Shubertfimage:
2701.28Smartin	@echo Preparing spec files for makefs...
2711.28Smartin	${RM} -f ${WORKSPEC}
2721.31Smartin	if [ -d cdrom/etc/mtree ]; then				\
2731.31Smartin		cat cdrom/etc/mtree/* |				\
2741.31Smartin		    ${TOOL_SED} -e 's/ size=[0-9]*//'		\
2751.31Smartin		     -e '/^\.\/etc\/gettytab/d' > ${WORKSPEC};	\
2761.31Smartin	fi
2771.31Smartin	if [ -r cdrom/dev/MAKEDEV ]; then			\
2781.32Smartin		${HOST_SH} cdrom/dev/MAKEDEV -s init |		\
2791.31Smartin		    ${TOOL_SED} -e '/^\. type=dir/d' 		\
2801.31Smartin			-e 's,^\.,./dev,' >> ${WORKSPEC};	\
2811.31Smartin	fi
2821.28Smartin.if defined(SPEC_IN)
2831.28Smartin	cat ${SPEC_IN} >> ${WORKSPEC}
2841.28Smartin.endif
2851.28Smartin.if defined(SECONDARY_BOOT)
2861.28Smartin	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
2871.28Smartin	    >> ${WORKSPEC}
2881.28Smartin.endif
2891.28Smartin.if defined(SPEC_EXTRA)
2901.28Smartin	cat ${SPEC_EXTRA} >> ${WORKSPEC}
2911.28Smartin.endif
2921.31Smartin	if [ -s ${WORKSPEC} ]; then specarg="-F ${WORKSPEC}"; fi;	\
2931.31Smartin	${TOOL_MAKEFS} -N ${NETBSDSRCDIR}/etc -t cd9660 $${specarg} 	\
2941.34Schristos		${MAKEFS_TIMESTAMP} ${CDMAKEFSEXTRAOPTS} -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
2951.8Sbouyer
2961.8Sbouyer.if ${CDRELEASE} == false
2971.15Sadrelease: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
2981.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2991.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3001.1Shubertf
3011.8Sbouyeriso_image:
3021.8Sbouyer.else
3031.1Shubertfrelease:
3041.8Sbouyer
3051.15Sadiso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
3061.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3071.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3081.8Sbouyer.endif
3091.1Shubertf
3101.1Shubertfclean:
3111.28Smartin	@if [ -d cdrom/var/spool/ftp/hidden ]; then 		\
3121.28Smartin		${CHMOD} +r cdrom/var/spool/ftp/hidden;		\
3131.28Smartin	fi	# XXX
3141.1Shubertf	${RM} -fr cdrom
3151.1Shubertf
3161.8Sbouyerprepare_md_post: .PHONY
3171.8Sbouyerimage_md_post: .PHONY
3181.15Sadimage_md_pre: .PHONY
3191.8Sbouyer
3201.1Shubertf.include <bsd.prog.mk>
321