Makefile.bootcd revision 1.37
11.37Schristos#	$NetBSD: Makefile.bootcd,v 1.37 2017/02/11 03:07:06 christos 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.25Smartin#	CDMAKEFSEXTRAOPTS additional options for makefs, e.g. -F specfile
291.1Shubertf#	CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
301.8Sbouyer#	CDINSTKERNEL	instkernel directory (relative to ${.CURDIR})
311.8Sbouyer#	CDKERNELS	couples of the form:
321.8Sbouyer#				source	name_on_cd
331.15Sad#	CDRUNTIME	files/directories to copy from $DESTDIR onto the CD
341.28Smartin#	CD_SETS		sets to be extracted onto the CD
351.28Smartin#	SETS_DIR	where the CD_SETS are found (default provided)
361.12Ssborrill# source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
371.12Ssborrill# note that as of yet, bootxx_cd9660 can't load kernel names of more than
381.12Ssborrill# 8 chars (though they can be in a sub-directory meaning the pathname is
391.12Ssborrill# longer than 8 chars)
401.1Shubertf#
411.1Shubertf
421.1ShubertfBOOT?=		${DESTDIR}/usr/mdec/boot
431.1ShubertfBOOTXX_CD9660?=	${DESTDIR}/usr/mdec/bootxx_cd9660
441.1ShubertfCDRELEASE?=	false
451.9SchristosCDSOURCE?=	false
461.8Sbouyer.if ${CDRELEASE} == false
471.8SbouyerCDROMS_RELEASEDIR?=	${MACHINE}/installation/cdrom
481.8Sbouyer.else
491.20SrizCDROMS_RELEASEDIR?=	images
501.8Sbouyer.endif
511.7Shubertf.if defined(CDRELEASE_NOISOS)
521.7ShubertfCDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
531.7Shubertf.endif
541.19Stsutsui.if !defined(CDRELEASE_LIVEIMAGE)
551.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/liveimage.*,,gp'
561.19Stsutsui.endif
571.19Stsutsui.if !defined(CDRELEASE_INSTALLIMAGE)
581.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/installimage.*,,gp'
591.19Stsutsui.endif
601.1Shubertf
611.28SmartinSETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
621.28Smartin
631.8Sbouyer.include <bsd.own.mk> 		# For PRINTOBJDIR
641.8Sbouyer.include <bsd.kernobj.mk>	# For KERNSRCDIR
651.8Sbouyer
661.18SjmcneillDISTRIBVER!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
671.8SbouyerDISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
681.28SmartinCUROBJDIR!=	cd ${.CURDIR} && ${PRINTOBJDIR}
691.8SbouyerISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
701.8SbouyerPUBLISHER?= The_NetBSD_Project
711.8Sbouyer.if defined(CDMAKEFSOPTIONS)
721.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
731.8Sbouyer.else
741.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
751.8Sbouyer.endif
761.8Sbouyer
771.34Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no"
781.34SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
791.37SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
801.33Schristos.endif
811.33Schristos
821.28Smartin.if ${MKUNPRIVED} == "no"
831.28SmartinCD_METALOG.unpriv=
841.31Smartinmtunpriv=
851.28Smartin.else
861.28SmartinCD_METALOG.unpriv=-M ${METALOG}.sanitised
871.29Smartinmtunpriv="-U"
881.28Smartin.endif
891.28Smartin
901.1Shubertf# Stuff that should come from elsewhere - XXX where? - HF
911.1ShubertfRM?=		rm
921.1ShubertfMKDIR?=		mkdir -p
931.1ShubertfCHMOD?=		chmod
941.17SchristosECHO?=		echo
951.1Shubertf
961.18Sjmcneill.if ${CDRELEASE} == false
971.18SjmcneillCDIMAGE=	${CDBASE}.iso
981.18Sjmcneill.else
991.18SjmcneillCDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
1001.18Sjmcneill.endif
1011.28SmartinWORKSPEC=	fs.spec
1021.1Shubertf
1031.18SjmcneillCLEANFILES+=	${CDIMAGE}
1041.8SbouyerCLEANFILES+=	bootxx.${MACHINE}
1051.28SmartinCLEANFILES+=	${WORKSPEC}
1061.1Shubertf
1071.28SmartinCDSETSENV=	DESTDIR=${DESTDIR:Q} \
1081.28Smartin		MACHINE=${MACHINE:Q} \
1091.28Smartin		MACHINE_ARCH=${MACHINE_ARCH:Q} \
1101.28Smartin		AWK=${TOOL_AWK:Q} \
1111.28Smartin		CKSUM=${TOOL_CKSUM:Q} \
1121.28Smartin		DB=${TOOL_DB:Q} \
1131.28Smartin		HOST_SH=${HOST_SH:Q} \
1141.28Smartin		MAKE=${MAKE:Q} \
1151.28Smartin		MKTEMP=${TOOL_MKTEMP:Q} \
1161.28Smartin		MTREE=${TOOL_MTREE:Q} \
1171.28Smartin		PAX=${TOOL_PAX:Q} \
1181.28Smartin		COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
1191.28Smartin		GZIP=${GZIP_FLAGS:Q} \
1201.28Smartin		PKG_CREATE=${TOOL_PKG_CREATE:Q} \
1211.28Smartin		SED=${TOOL_SED:Q} \
1221.28Smartin		TSORT=${TSORT:Q} \
1231.28Smartin		MKRUMP=no \
1241.28Smartin		MKCOMPAT=no \
1251.28Smartin		MKDEBUG=no \
1261.28Smartin		MKDEBUGLIB=no
1271.28Smartin
1281.28SmartinCDSETSCMD=	cd ${NETBSDSRCDIR}/distrib/sets && \
1291.28Smartin		${CDSETSENV} \
1301.28Smartin		${HOST_SH}
1311.1Shubertf
1321.1Shubertf.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
1331.1Shubertf
1341.8Sbouyer.if defined(CDINSTKERNEL)
1351.8Sbouyer_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
1361.8Sbouyer.endif
1371.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1381.8Sbouyer.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
1391.8SbouyerBOOT2=boot.${MACHINE}
1401.8Sbouyer.else
1411.8SbouyerBOOT2=boot
1421.8Sbouyer.endif
1431.8Sbouyer.endif
1441.1Shubertf
1451.1Shubertfprepare:
1461.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom"
1471.8Sbouyer.if defined(CDKERNELS)
1481.8Sbouyer.for kernel target in ${CDKERNELS}
1491.36Schristos	${INSTALL} ${COPY} -m 0644 ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
1501.8Sbouyer.endfor
1511.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1521.8Sbouyer	${RM} -f cdrom/${BOOT2}
1531.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
1541.8Sbouyer	${RM} -f bootxx.${MACHINE}
1551.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
1561.8Sbouyer	${CHMOD} +w bootxx.${MACHINE}
1571.8Sbouyer.if defined(CDBOOTOPTIONS)
1581.8Sbouyer	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
1591.8Sbouyer.endif
1601.8Sbouyer.endif
1611.8Sbouyer.endif
1621.1Shubertf
1631.24Sdsl.if ${MAKEVERBOSE} >= 2
1641.24SdslPAX_v?= -v
1651.24Sdsl.else
1661.24SdslPAX_v?=
1671.24Sdsl.endif
1681.24Sdsl
1691.1Shubertf# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
1701.1Shubertf#
1711.1Shubertf# XXX This could be done a lot easier if makefs(8) could
1721.1Shubertf# XXX include more than one directory on the image - HF
1731.1Shubertf#
1741.1Shubertfcopy-releasedir:
1751.18Sjmcneill	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
1761.9Schristos	if ${CDRELEASE}; then 						\
1771.28Smartin		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 	\
1781.14Smatt			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
1791.9Schristos			exit 1; 					\
1801.9Schristos		fi; 							\
1811.36Schristos		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/${MACHINE}"; 	\
1821.28Smartin		release_destdir="${CUROBJDIR}/cdrom/${MACHINE}";	\
1831.15Sad		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
1841.9Schristos		echo Copying $$(pwd) to $$release_destdir ...; 		\
1851.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP}				\
1861.24Sdsl			-rw -pe ${PAX_v}				\
1871.7Shubertf			${CDRELEASE_EXCLUDE}				\
1881.9Schristos			. $$release_destdir; 				\
1891.28Smartin		cd "${CUROBJDIR}";					\
1901.9Schristos	fi
1911.9Schristos	if ${CDSOURCE}; then 						\
1921.9Schristos		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
1931.9Schristos			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
1941.9Schristos			exit 1; 					\
1951.9Schristos		fi; 							\
1961.36Schristos		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/source"; 	\
1971.28Smartin		release_destdir="${CUROBJDIR}/cdrom/source";	 	\
1981.9Schristos		cd ${RELEASEDIR}/source; 				\
1991.9Schristos		echo Copying $$(pwd) to $$release_destdir ...;		\
2001.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP} 				\
2011.24Sdsl			-rw -pe ${PAX_v}				\
2021.9Schristos			. $$release_destdir; 				\
2031.28Smartin		cd "${CUROBJDIR}";					\
2041.1Shubertf	fi
2051.28Smartin	if [ "X${CDRUNTIME}" != "X" ]; then				\
2061.15Sad		release_destdir=$${curdir}/cdrom;			\
2071.15Sad		cd $$release_destdir;					\
2081.15Sad		cd ${DESTDIR};						\
2091.15Sad		for cde in ${CDRUNTIME};				\
2101.15Sad		do							\
2111.37Schristos			${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pp ${PAX_v}	\
2121.37Schristos				$${cde} $$release_destdir;		\
2131.15Sad		done;							\
2141.28Smartin		cd "${CUROBJDIR}";					\
2151.15Sad	fi
2161.13Ssborrill	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
2171.13Ssborrill		skipflag="";						\
2181.16Shubertf		cdextra_skip="${CDEXTRA_SKIP}";				\
2191.16Shubertf		if [ "X$${cdextra_skip}" != "X" ]; then			\
2201.13Ssborrill			rm -f cdskip;					\
2211.16Shubertf			for skip in $${cdextra_skip};			\
2221.13Ssborrill			do						\
2231.13Ssborrill				echo $${skip} >> cdskip;		\
2241.13Ssborrill			done;						\
2251.28Smartin			skipflag="-X ${CUROBJDIR:Q}/cdskip";		\
2261.13Ssborrill		fi;							\
2271.16Shubertf		cdextra="${CDEXTRA}"; 					\
2281.16Shubertf		cdbuildextra="${CDBUILDEXTRA}"; 			\
2291.16Shubertf		for cde in $${cdextra} $${cdbuildextra};		\
2301.13Ssborrill		do							\
2311.28Smartin			release_destdir="${CUROBJDIR}/cdrom";		\
2321.13Ssborrill			if [ -f $${cde} ]; then				\
2331.13Ssborrill				echo Copying $${cde} to $$release_destdir ...;	\
2341.36Schristos				${INSTALL} ${COPY} -m 0644 -f $${cde} $${release_destdir};	\
2351.13Ssborrill			elif [ -d $${cde} ]; then			\
2361.13Ssborrill				cd $${cde};				\
2371.13Ssborrill				echo Copying $$(pwd) to $$release_destdir ...;	\
2381.13Ssborrill				${TOOL_MTREE} -c $${skipflag} |		\
2391.37Schristos					${TOOL_PAX} ${PAX_TIMESTAMP}	\
2401.37Schristos					-rw -pe ${PAX_v}		\
2411.37Schristos					-M $$release_destdir; 		\
2421.13Ssborrill			else						\
2431.13Ssborrill				echo "Missing $${cde}, aborting"; 	\
2441.13Ssborrill				exit 1; 				\
2451.13Ssborrill			fi; 						\
2461.28Smartin			cd "${CUROBJDIR}";				\
2471.13Ssborrill		done;							\
2481.11Sjnemeth	fi
2491.28Smartin.if !empty(CD_SETS)
2501.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/etc/mtree"
2511.28Smartin.for set in ${CD_SETS}
2521.28Smartin	if [ -f ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set} ]; then	\
2531.28Smartin		${CHMOD} +w ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set};	\
2541.28Smartin	fi;								\
2551.28Smartin	${CDSETSCMD} ./maketars -i "${CUROBJDIR}/cdrom"			\
2561.29Smartin	    ${CD_METALOG.unpriv} ${mtunpriv} -N ${NETBSDSRCDIR}/etc	\
2571.28Smartin	    -F "${CUROBJDIR}/cdrom/etc/mtree"				\
2581.28Smartin	    -d "${DESTDIR:S,^$,/,}" ${set}
2591.28Smartin.endfor
2601.28Smartin	if [ -d "${CUROBJDIR}/cdrom/var/spool/ftp/hidden" ]; then	\
2611.28Smartin		${CHMOD} +r "${CUROBJDIR}/cdrom/var/spool/ftp/hidden";	\
2621.28Smartin	fi
2631.28Smartin.endif
2641.1Shubertf
2651.1Shubertfimage:
2661.28Smartin	@echo Preparing spec files for makefs...
2671.28Smartin	${RM} -f ${WORKSPEC}
2681.31Smartin	if [ -d cdrom/etc/mtree ]; then				\
2691.31Smartin		cat cdrom/etc/mtree/* |				\
2701.31Smartin		    ${TOOL_SED} -e 's/ size=[0-9]*//'		\
2711.31Smartin		     -e '/^\.\/etc\/gettytab/d' > ${WORKSPEC};	\
2721.31Smartin	fi
2731.31Smartin	if [ -r cdrom/dev/MAKEDEV ]; then			\
2741.32Smartin		${HOST_SH} cdrom/dev/MAKEDEV -s init |		\
2751.31Smartin		    ${TOOL_SED} -e '/^\. type=dir/d' 		\
2761.31Smartin			-e 's,^\.,./dev,' >> ${WORKSPEC};	\
2771.31Smartin	fi
2781.28Smartin.if defined(SPEC_IN)
2791.28Smartin	cat ${SPEC_IN} >> ${WORKSPEC}
2801.28Smartin.endif
2811.28Smartin.if defined(SECONDARY_BOOT)
2821.28Smartin	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
2831.28Smartin	    >> ${WORKSPEC}
2841.28Smartin.endif
2851.28Smartin.if defined(SPEC_EXTRA)
2861.28Smartin	cat ${SPEC_EXTRA} >> ${WORKSPEC}
2871.28Smartin.endif
2881.31Smartin	if [ -s ${WORKSPEC} ]; then specarg="-F ${WORKSPEC}"; fi;	\
2891.31Smartin	${TOOL_MAKEFS} -N ${NETBSDSRCDIR}/etc -t cd9660 $${specarg} 	\
2901.34Schristos		${MAKEFS_TIMESTAMP} ${CDMAKEFSEXTRAOPTS} -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
2911.8Sbouyer
2921.8Sbouyer.if ${CDRELEASE} == false
2931.15Sadrelease: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
2941.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2951.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
2961.1Shubertf
2971.8Sbouyeriso_image:
2981.8Sbouyer.else
2991.1Shubertfrelease:
3001.8Sbouyer
3011.15Sadiso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
3021.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3031.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3041.8Sbouyer.endif
3051.1Shubertf
3061.1Shubertfclean:
3071.28Smartin	@if [ -d cdrom/var/spool/ftp/hidden ]; then 		\
3081.28Smartin		${CHMOD} +r cdrom/var/spool/ftp/hidden;		\
3091.28Smartin	fi	# XXX
3101.1Shubertf	${RM} -fr cdrom
3111.1Shubertf
3121.8Sbouyerprepare_md_post: .PHONY
3131.8Sbouyerimage_md_post: .PHONY
3141.15Sadimage_md_pre: .PHONY
3151.8Sbouyer
3161.1Shubertf.include <bsd.prog.mk>
317