Makefile.bootcd revision 1.45
11.45Snia#	$NetBSD: Makefile.bootcd,v 1.45 2024/04/23 12:25:57 nia 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.42Schristos#	CDRELEASE	Set to 'true' to include $RELEASEDIR/$RELEASEMACHINEDIR 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.43Smartin#	CDDEV_POPULATE	Set to 'true' to fully populate /dev on the CD (and
261.43Smartin#			safe a tmpfs union mount)
271.1Shubertf#	BOOT		Defaults to $DESTDIR/usr/mdec/boot
281.1Shubertf#	BOOTXX_CD9660	Defaults to $DESTDIR/usr/mdec/bootxx_cd9660
291.1Shubertf#	CDBOOTOPTIONS	Options for installboot, eg -o console=com0,speed=9600
301.8Sbouyer#	CDMAKEFSOPTIONS	Options for makefs, eg bootimage=i386;bootxx,no-emul-boot
311.25Smartin#	CDMAKEFSEXTRAOPTS additional options for makefs, e.g. -F specfile
321.1Shubertf#	CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
331.8Sbouyer#	CDINSTKERNEL	instkernel directory (relative to ${.CURDIR})
341.8Sbouyer#	CDKERNELS	couples of the form:
351.8Sbouyer#				source	name_on_cd
361.15Sad#	CDRUNTIME	files/directories to copy from $DESTDIR onto the CD
371.28Smartin#	CD_SETS		sets to be extracted onto the CD
381.28Smartin#	SETS_DIR	where the CD_SETS are found (default provided)
391.12Ssborrill# source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
401.12Ssborrill# note that as of yet, bootxx_cd9660 can't load kernel names of more than
411.12Ssborrill# 8 chars (though they can be in a sub-directory meaning the pathname is
421.12Ssborrill# longer than 8 chars)
431.1Shubertf#
441.1Shubertf
451.1ShubertfBOOT?=		${DESTDIR}/usr/mdec/boot
461.1ShubertfBOOTXX_CD9660?=	${DESTDIR}/usr/mdec/bootxx_cd9660
471.1ShubertfCDRELEASE?=	false
481.9SchristosCDSOURCE?=	false
491.43SmartinCDDEV_POPULATE?=false
501.8Sbouyer.if ${CDRELEASE} == false
511.8SbouyerCDROMS_RELEASEDIR?=	${MACHINE}/installation/cdrom
521.8Sbouyer.else
531.20SrizCDROMS_RELEASEDIR?=	images
541.8Sbouyer.endif
551.7Shubertf.if defined(CDRELEASE_NOISOS)
561.7ShubertfCDRELEASE_EXCLUDE=	-s ',./installation/cdrom.*,,gp'
571.7Shubertf.endif
581.45Snia.if defined(CDRELEASE_NOCOMPAT)
591.45Snia.  for sufx in tgz tar.xz
601.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/base32.${sufx},,gp'
611.45Snia.  endfor
621.45Snia.endif
631.39Smartin.if defined(CDRELEASE_NODEBUG)
641.45Snia.  for sufx in tgz tar.xz
651.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/debug.${sufx},,gp'
661.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/debug32.${sufx},,gp'
671.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/debug64.${sufx},,gp'
681.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/xdebug.${sufx},,gp'
691.45Snia.  endfor
701.39Smartin.endif
711.19Stsutsui.if !defined(CDRELEASE_LIVEIMAGE)
721.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/liveimage.*,,gp'
731.19Stsutsui.endif
741.19Stsutsui.if !defined(CDRELEASE_INSTALLIMAGE)
751.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/installimage.*,,gp'
761.19Stsutsui.endif
771.1Shubertf
781.28SmartinSETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
791.28Smartin
801.8Sbouyer.include <bsd.own.mk> 		# For PRINTOBJDIR
811.8Sbouyer.include <bsd.kernobj.mk>	# For KERNSRCDIR
821.8Sbouyer
831.18SjmcneillDISTRIBVER!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
841.8SbouyerDISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
851.28SmartinCUROBJDIR!=	cd ${.CURDIR} && ${PRINTOBJDIR}
861.8SbouyerISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
871.8SbouyerPUBLISHER?= The_NetBSD_Project
881.8Sbouyer.if defined(CDMAKEFSOPTIONS)
891.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
901.8Sbouyer.else
911.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
921.8Sbouyer.endif
931.8Sbouyer
941.34Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no"
951.34SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
961.37SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
971.33Schristos.endif
981.33Schristos
991.28Smartin.if ${MKUNPRIVED} == "no"
1001.28SmartinCD_METALOG.unpriv=
1011.31Smartinmtunpriv=
1021.28Smartin.else
1031.28SmartinCD_METALOG.unpriv=-M ${METALOG}.sanitised
1041.29Smartinmtunpriv="-U"
1051.28Smartin.endif
1061.28Smartin
1071.1Shubertf# Stuff that should come from elsewhere - XXX where? - HF
1081.1ShubertfRM?=		rm
1091.1ShubertfMKDIR?=		mkdir -p
1101.1ShubertfCHMOD?=		chmod
1111.17SchristosECHO?=		echo
1121.1Shubertf
1131.18Sjmcneill.if ${CDRELEASE} == false
1141.18SjmcneillCDIMAGE=	${CDBASE}.iso
1151.18Sjmcneill.else
1161.18SjmcneillCDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
1171.18Sjmcneill.endif
1181.28SmartinWORKSPEC=	fs.spec
1191.1Shubertf
1201.18SjmcneillCLEANFILES+=	${CDIMAGE}
1211.8SbouyerCLEANFILES+=	bootxx.${MACHINE}
1221.28SmartinCLEANFILES+=	${WORKSPEC}
1231.1Shubertf
1241.28SmartinCDSETSENV=	DESTDIR=${DESTDIR:Q} \
1251.28Smartin		MACHINE=${MACHINE:Q} \
1261.28Smartin		MACHINE_ARCH=${MACHINE_ARCH:Q} \
1271.28Smartin		AWK=${TOOL_AWK:Q} \
1281.28Smartin		CKSUM=${TOOL_CKSUM:Q} \
1291.28Smartin		DB=${TOOL_DB:Q} \
1301.28Smartin		HOST_SH=${HOST_SH:Q} \
1311.28Smartin		MAKE=${MAKE:Q} \
1321.28Smartin		MKTEMP=${TOOL_MKTEMP:Q} \
1331.28Smartin		MTREE=${TOOL_MTREE:Q} \
1341.28Smartin		PAX=${TOOL_PAX:Q} \
1351.28Smartin		COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
1361.28Smartin		GZIP=${GZIP_FLAGS:Q} \
1371.28Smartin		PKG_CREATE=${TOOL_PKG_CREATE:Q} \
1381.28Smartin		SED=${TOOL_SED:Q} \
1391.28Smartin		TSORT=${TSORT:Q} \
1401.28Smartin		MKRUMP=no \
1411.28Smartin		MKCOMPAT=no \
1421.28Smartin		MKDEBUG=no \
1431.28Smartin		MKDEBUGLIB=no
1441.28Smartin
1451.28SmartinCDSETSCMD=	cd ${NETBSDSRCDIR}/distrib/sets && \
1461.28Smartin		${CDSETSENV} \
1471.28Smartin		${HOST_SH}
1481.1Shubertf
1491.1Shubertf.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
1501.1Shubertf
1511.8Sbouyer.if defined(CDINSTKERNEL)
1521.8Sbouyer_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
1531.8Sbouyer.endif
1541.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1551.8Sbouyer.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
1561.8SbouyerBOOT2=boot.${MACHINE}
1571.8Sbouyer.else
1581.8SbouyerBOOT2=boot
1591.8Sbouyer.endif
1601.8Sbouyer.endif
1611.1Shubertf
1621.1Shubertfprepare:
1631.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom"
1641.8Sbouyer.if defined(CDKERNELS)
1651.8Sbouyer.for kernel target in ${CDKERNELS}
1661.36Schristos	${INSTALL} ${COPY} -m 0644 ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
1671.8Sbouyer.endfor
1681.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1691.8Sbouyer	${RM} -f cdrom/${BOOT2}
1701.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
1711.8Sbouyer	${RM} -f bootxx.${MACHINE}
1721.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
1731.8Sbouyer	${CHMOD} +w bootxx.${MACHINE}
1741.8Sbouyer.if defined(CDBOOTOPTIONS)
1751.8Sbouyer	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
1761.8Sbouyer.endif
1771.8Sbouyer.endif
1781.8Sbouyer.endif
1791.1Shubertf
1801.24Sdsl.if ${MAKEVERBOSE} >= 2
1811.24SdslPAX_v?= -v
1821.24Sdsl.else
1831.24SdslPAX_v?=
1841.24Sdsl.endif
1851.24Sdsl
1861.1Shubertf# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
1871.1Shubertf#
1881.1Shubertf# XXX This could be done a lot easier if makefs(8) could
1891.1Shubertf# XXX include more than one directory on the image - HF
1901.1Shubertf#
1911.1Shubertfcopy-releasedir:
1921.18Sjmcneill	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
1931.9Schristos	if ${CDRELEASE}; then 						\
1941.28Smartin		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 	\
1951.14Smatt			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
1961.9Schristos			exit 1; 					\
1971.9Schristos		fi; 							\
1981.44Sjmcneill		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/${RELEASEMACHINEDIR}"; 	\
1991.44Sjmcneill		release_destdir="${CUROBJDIR}/cdrom/${RELEASEMACHINEDIR}";	\
2001.15Sad		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
2011.9Schristos		echo Copying $$(pwd) to $$release_destdir ...; 		\
2021.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP}				\
2031.24Sdsl			-rw -pe ${PAX_v}				\
2041.7Shubertf			${CDRELEASE_EXCLUDE}				\
2051.9Schristos			. $$release_destdir; 				\
2061.28Smartin		cd "${CUROBJDIR}";					\
2071.9Schristos	fi
2081.9Schristos	if ${CDSOURCE}; then 						\
2091.9Schristos		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
2101.9Schristos			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
2111.9Schristos			exit 1; 					\
2121.9Schristos		fi; 							\
2131.36Schristos		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/source"; 	\
2141.28Smartin		release_destdir="${CUROBJDIR}/cdrom/source";	 	\
2151.9Schristos		cd ${RELEASEDIR}/source; 				\
2161.9Schristos		echo Copying $$(pwd) to $$release_destdir ...;		\
2171.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP} 				\
2181.24Sdsl			-rw -pe ${PAX_v}				\
2191.9Schristos			. $$release_destdir; 				\
2201.28Smartin		cd "${CUROBJDIR}";					\
2211.1Shubertf	fi
2221.28Smartin	if [ "X${CDRUNTIME}" != "X" ]; then				\
2231.15Sad		release_destdir=$${curdir}/cdrom;			\
2241.15Sad		cd $$release_destdir;					\
2251.15Sad		cd ${DESTDIR};						\
2261.15Sad		for cde in ${CDRUNTIME};				\
2271.15Sad		do							\
2281.37Schristos			${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pp ${PAX_v}	\
2291.37Schristos				$${cde} $$release_destdir;		\
2301.15Sad		done;							\
2311.28Smartin		cd "${CUROBJDIR}";					\
2321.15Sad	fi
2331.13Ssborrill	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
2341.13Ssborrill		skipflag="";						\
2351.16Shubertf		cdextra_skip="${CDEXTRA_SKIP}";				\
2361.16Shubertf		if [ "X$${cdextra_skip}" != "X" ]; then			\
2371.13Ssborrill			rm -f cdskip;					\
2381.16Shubertf			for skip in $${cdextra_skip};			\
2391.13Ssborrill			do						\
2401.13Ssborrill				echo $${skip} >> cdskip;		\
2411.13Ssborrill			done;						\
2421.28Smartin			skipflag="-X ${CUROBJDIR:Q}/cdskip";		\
2431.13Ssborrill		fi;							\
2441.16Shubertf		cdextra="${CDEXTRA}"; 					\
2451.16Shubertf		cdbuildextra="${CDBUILDEXTRA}"; 			\
2461.16Shubertf		for cde in $${cdextra} $${cdbuildextra};		\
2471.13Ssborrill		do							\
2481.28Smartin			release_destdir="${CUROBJDIR}/cdrom";		\
2491.13Ssborrill			if [ -f $${cde} ]; then				\
2501.13Ssborrill				echo Copying $${cde} to $$release_destdir ...;	\
2511.38Schristos				${INSTALL} ${COPY} -m 0644 $${cde} $${release_destdir};	\
2521.13Ssborrill			elif [ -d $${cde} ]; then			\
2531.13Ssborrill				cd $${cde};				\
2541.13Ssborrill				echo Copying $$(pwd) to $$release_destdir ...;	\
2551.13Ssborrill				${TOOL_MTREE} -c $${skipflag} |		\
2561.37Schristos					${TOOL_PAX} ${PAX_TIMESTAMP}	\
2571.37Schristos					-rw -pe ${PAX_v}		\
2581.37Schristos					-M $$release_destdir; 		\
2591.13Ssborrill			else						\
2601.13Ssborrill				echo "Missing $${cde}, aborting"; 	\
2611.13Ssborrill				exit 1; 				\
2621.13Ssborrill			fi; 						\
2631.28Smartin			cd "${CUROBJDIR}";				\
2641.13Ssborrill		done;							\
2651.11Sjnemeth	fi
2661.28Smartin.if !empty(CD_SETS)
2671.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/etc/mtree"
2681.28Smartin.for set in ${CD_SETS}
2691.28Smartin	if [ -f ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set} ]; then	\
2701.28Smartin		${CHMOD} +w ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set};	\
2711.28Smartin	fi;								\
2721.28Smartin	${CDSETSCMD} ./maketars -i "${CUROBJDIR}/cdrom"			\
2731.29Smartin	    ${CD_METALOG.unpriv} ${mtunpriv} -N ${NETBSDSRCDIR}/etc	\
2741.28Smartin	    -F "${CUROBJDIR}/cdrom/etc/mtree"				\
2751.28Smartin	    -d "${DESTDIR:S,^$,/,}" ${set}
2761.28Smartin.endfor
2771.28Smartin	if [ -d "${CUROBJDIR}/cdrom/var/spool/ftp/hidden" ]; then	\
2781.28Smartin		${CHMOD} +r "${CUROBJDIR}/cdrom/var/spool/ftp/hidden";	\
2791.28Smartin	fi
2801.28Smartin.endif
2811.1Shubertf
2821.43Smartin.if ${CDDEV_POPULATE} != true
2831.43SmartinDELDEV=-e '/^\.\/dev\/.*type=char/d'
2841.43Smartin.endif
2851.43Smartin
2861.1Shubertfimage:
2871.28Smartin	@echo Preparing spec files for makefs...
2881.28Smartin	${RM} -f ${WORKSPEC}
2891.31Smartin	if [ -d cdrom/etc/mtree ]; then				\
2901.31Smartin		cat cdrom/etc/mtree/* |				\
2911.31Smartin		    ${TOOL_SED} -e 's/ size=[0-9]*//'		\
2921.43Smartin		     ${DELDEV}					\
2931.31Smartin		     -e '/^\.\/etc\/gettytab/d' > ${WORKSPEC};	\
2941.31Smartin	fi
2951.43Smartin	if [ -r cdrom/dev/MAKEDEV ] &&				\
2961.43Smartin		 ${CDDEV_POPULATE} == true; then		\
2971.32Smartin		${HOST_SH} cdrom/dev/MAKEDEV -s init |		\
2981.31Smartin		    ${TOOL_SED} -e '/^\. type=dir/d' 		\
2991.31Smartin			-e 's,^\.,./dev,' >> ${WORKSPEC};	\
3001.31Smartin	fi
3011.28Smartin.if defined(SPEC_IN)
3021.28Smartin	cat ${SPEC_IN} >> ${WORKSPEC}
3031.28Smartin.endif
3041.28Smartin.if defined(SECONDARY_BOOT)
3051.28Smartin	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
3061.28Smartin	    >> ${WORKSPEC}
3071.28Smartin.endif
3081.28Smartin.if defined(SPEC_EXTRA)
3091.28Smartin	cat ${SPEC_EXTRA} >> ${WORKSPEC}
3101.28Smartin.endif
3111.31Smartin	if [ -s ${WORKSPEC} ]; then specarg="-F ${WORKSPEC}"; fi;	\
3121.31Smartin	${TOOL_MAKEFS} -N ${NETBSDSRCDIR}/etc -t cd9660 $${specarg} 	\
3131.34Schristos		${MAKEFS_TIMESTAMP} ${CDMAKEFSEXTRAOPTS} -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
3141.8Sbouyer
3151.8Sbouyer.if ${CDRELEASE} == false
3161.15Sadrelease: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
3171.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3181.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3191.1Shubertf
3201.8Sbouyeriso_image:
3211.8Sbouyer.else
3221.1Shubertfrelease:
3231.8Sbouyer
3241.15Sadiso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
3251.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3261.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3271.8Sbouyer.endif
3281.1Shubertf
3291.1Shubertfclean:
3301.28Smartin	@if [ -d cdrom/var/spool/ftp/hidden ]; then 		\
3311.28Smartin		${CHMOD} +r cdrom/var/spool/ftp/hidden;		\
3321.28Smartin	fi	# XXX
3331.1Shubertf	${RM} -fr cdrom
3341.1Shubertf
3351.8Sbouyerprepare_md_post: .PHONY
3361.8Sbouyerimage_md_post: .PHONY
3371.15Sadimage_md_pre: .PHONY
3381.8Sbouyer
3391.1Shubertf.include <bsd.prog.mk>
340