Makefile.bootcd revision 1.49
11.49Schristos#	$NetBSD: Makefile.bootcd,v 1.49 2024/05/07 20:33:20 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.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.48SniaCDRELEASE_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.46SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/base64.${sufx},,gp'
621.45Snia.  endfor
631.45Snia.endif
641.39Smartin.if defined(CDRELEASE_NODEBUG)
651.45Snia.  for sufx in tgz tar.xz
661.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/debug.${sufx},,gp'
671.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/debug32.${sufx},,gp'
681.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/debug64.${sufx},,gp'
691.45SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/xdebug.${sufx},,gp'
701.45Snia.  endfor
711.39Smartin.endif
721.46Snia.if defined(CDRELEASE_NOHTML)
731.46Snia.  for sufx in tgz tar.xz
741.46SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/manhtml.${sufx},,gp'
751.46Snia.  endfor
761.46Snia.endif
771.46Snia.if defined(CDRELEASE_NOTESTS)
781.46Snia.  for sufx in tgz tar.xz
791.46SniaCDRELEASE_EXCLUDE+=	-s ',./binary/sets/tests.${sufx},,gp'
801.46Snia.  endfor
811.46Snia.endif
821.19Stsutsui.if !defined(CDRELEASE_LIVEIMAGE)
831.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/liveimage.*,,gp'
841.19Stsutsui.endif
851.19Stsutsui.if !defined(CDRELEASE_INSTALLIMAGE)
861.19StsutsuiCDRELEASE_EXCLUDE+=	-s ',./installation/installimage.*,,gp'
871.19Stsutsui.endif
881.1Shubertf
891.28SmartinSETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
901.28Smartin
911.8Sbouyer.include <bsd.own.mk> 		# For PRINTOBJDIR
921.8Sbouyer.include <bsd.kernobj.mk>	# For KERNSRCDIR
931.8Sbouyer
941.18SjmcneillDISTRIBVER!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
951.8SbouyerDISTRIBREV!=	${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
961.28SmartinCUROBJDIR!=	cd ${.CURDIR} && ${PRINTOBJDIR}
971.8SbouyerISO_VOLID!=	echo NETBSD_${DISTRIBREV} | tr a-z A-Z
981.8SbouyerPUBLISHER?= The_NetBSD_Project
991.8Sbouyer.if defined(CDMAKEFSOPTIONS)
1001.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
1011.8Sbouyer.else
1021.22Schristos_CDMAKEFSOPTIONS=	rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
1031.8Sbouyer.endif
1041.8Sbouyer
1051.34Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no"
1061.34SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
1071.37SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
1081.33Schristos.endif
1091.49SchristosMAKESPEC=	${HOST_SH} ${NETBSDSRCDIR}/etc/makespec
1101.33Schristos
1111.28Smartin.if ${MKUNPRIVED} == "no"
1121.28SmartinCD_METALOG.unpriv=
1131.31Smartinmtunpriv=
1141.28Smartin.else
1151.28SmartinCD_METALOG.unpriv=-M ${METALOG}.sanitised
1161.29Smartinmtunpriv="-U"
1171.28Smartin.endif
1181.28Smartin
1191.1Shubertf# Stuff that should come from elsewhere - XXX where? - HF
1201.1ShubertfRM?=		rm
1211.1ShubertfMKDIR?=		mkdir -p
1221.1ShubertfCHMOD?=		chmod
1231.17SchristosECHO?=		echo
1241.1Shubertf
1251.18Sjmcneill.if ${CDRELEASE} == false
1261.18SjmcneillCDIMAGE=	${CDBASE}.iso
1271.47Snia.elif ${CDBASE:M*dvd}
1281.47SniaCDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/dvd$//}-dvd.iso
1291.18Sjmcneill.else
1301.18SjmcneillCDIMAGE=	NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
1311.18Sjmcneill.endif
1321.28SmartinWORKSPEC=	fs.spec
1331.1Shubertf
1341.18SjmcneillCLEANFILES+=	${CDIMAGE}
1351.8SbouyerCLEANFILES+=	bootxx.${MACHINE}
1361.28SmartinCLEANFILES+=	${WORKSPEC}
1371.1Shubertf
1381.28SmartinCDSETSENV=	DESTDIR=${DESTDIR:Q} \
1391.28Smartin		MACHINE=${MACHINE:Q} \
1401.28Smartin		MACHINE_ARCH=${MACHINE_ARCH:Q} \
1411.28Smartin		AWK=${TOOL_AWK:Q} \
1421.28Smartin		CKSUM=${TOOL_CKSUM:Q} \
1431.28Smartin		DB=${TOOL_DB:Q} \
1441.28Smartin		HOST_SH=${HOST_SH:Q} \
1451.28Smartin		MAKE=${MAKE:Q} \
1461.28Smartin		MKTEMP=${TOOL_MKTEMP:Q} \
1471.28Smartin		MTREE=${TOOL_MTREE:Q} \
1481.28Smartin		PAX=${TOOL_PAX:Q} \
1491.28Smartin		COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
1501.28Smartin		GZIP=${GZIP_FLAGS:Q} \
1511.28Smartin		PKG_CREATE=${TOOL_PKG_CREATE:Q} \
1521.28Smartin		SED=${TOOL_SED:Q} \
1531.28Smartin		TSORT=${TSORT:Q} \
1541.28Smartin		MKRUMP=no \
1551.28Smartin		MKCOMPAT=no \
1561.28Smartin		MKDEBUG=no \
1571.28Smartin		MKDEBUGLIB=no
1581.28Smartin
1591.28SmartinCDSETSCMD=	cd ${NETBSDSRCDIR}/distrib/sets && \
1601.28Smartin		${CDSETSENV} \
1611.28Smartin		${HOST_SH}
1621.1Shubertf
1631.1Shubertf.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
1641.1Shubertf
1651.8Sbouyer.if defined(CDINSTKERNEL)
1661.8Sbouyer_INSTKERNELNOBJDIR!=	cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
1671.8Sbouyer.endif
1681.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1691.8Sbouyer.if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
1701.8SbouyerBOOT2=boot.${MACHINE}
1711.8Sbouyer.else
1721.8SbouyerBOOT2=boot
1731.8Sbouyer.endif
1741.8Sbouyer.endif
1751.1Shubertf
1761.1Shubertfprepare:
1771.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom"
1781.8Sbouyer.if defined(CDKERNELS)
1791.8Sbouyer.for kernel target in ${CDKERNELS}
1801.36Schristos	${INSTALL} ${COPY} -m 0644 ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
1811.8Sbouyer.endfor
1821.8Sbouyer.if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
1831.8Sbouyer	${RM} -f cdrom/${BOOT2}
1841.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
1851.8Sbouyer	${RM} -f bootxx.${MACHINE}
1861.36Schristos	${INSTALL} ${COPY} -m 0644 ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
1871.8Sbouyer	${CHMOD} +w bootxx.${MACHINE}
1881.8Sbouyer.if defined(CDBOOTOPTIONS)
1891.8Sbouyer	${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
1901.8Sbouyer.endif
1911.8Sbouyer.endif
1921.8Sbouyer.endif
1931.1Shubertf
1941.24Sdsl.if ${MAKEVERBOSE} >= 2
1951.24SdslPAX_v?= -v
1961.24Sdsl.else
1971.24SdslPAX_v?=
1981.24Sdsl.endif
1991.24Sdsl
2001.1Shubertf# Copy $RELEASEDIR/${MACHINE} in the CDROM dir
2011.1Shubertf#
2021.1Shubertf# XXX This could be done a lot easier if makefs(8) could
2031.1Shubertf# XXX include more than one directory on the image - HF
2041.1Shubertf#
2051.1Shubertfcopy-releasedir:
2061.18Sjmcneill	${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
2071.9Schristos	if ${CDRELEASE}; then 						\
2081.28Smartin		if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 	\
2091.14Smatt			echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
2101.9Schristos			exit 1; 					\
2111.9Schristos		fi; 							\
2121.44Sjmcneill		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/${RELEASEMACHINEDIR}"; 	\
2131.44Sjmcneill		release_destdir="${CUROBJDIR}/cdrom/${RELEASEMACHINEDIR}";	\
2141.15Sad		cd ${RELEASEDIR}/${RELEASEMACHINEDIR}; 			\
2151.9Schristos		echo Copying $$(pwd) to $$release_destdir ...; 		\
2161.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP}				\
2171.24Sdsl			-rw -pe ${PAX_v}				\
2181.7Shubertf			${CDRELEASE_EXCLUDE}				\
2191.9Schristos			. $$release_destdir; 				\
2201.28Smartin		cd "${CUROBJDIR}";					\
2211.9Schristos	fi
2221.9Schristos	if ${CDSOURCE}; then 						\
2231.9Schristos		if [ ! -d ${RELEASEDIR}/source ]; then	 		\
2241.9Schristos			echo "Missing ${RELEASEDIR}/source, aborting"; 	\
2251.9Schristos			exit 1; 					\
2261.9Schristos		fi; 							\
2271.36Schristos		${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/source"; 	\
2281.28Smartin		release_destdir="${CUROBJDIR}/cdrom/source";	 	\
2291.9Schristos		cd ${RELEASEDIR}/source; 				\
2301.9Schristos		echo Copying $$(pwd) to $$release_destdir ...;		\
2311.37Schristos		${TOOL_PAX} ${PAX_TIMESTAMP} 				\
2321.24Sdsl			-rw -pe ${PAX_v}				\
2331.9Schristos			. $$release_destdir; 				\
2341.28Smartin		cd "${CUROBJDIR}";					\
2351.1Shubertf	fi
2361.28Smartin	if [ "X${CDRUNTIME}" != "X" ]; then				\
2371.15Sad		release_destdir=$${curdir}/cdrom;			\
2381.15Sad		cd $$release_destdir;					\
2391.15Sad		cd ${DESTDIR};						\
2401.15Sad		for cde in ${CDRUNTIME};				\
2411.15Sad		do							\
2421.37Schristos			${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pp ${PAX_v}	\
2431.37Schristos				$${cde} $$release_destdir;		\
2441.15Sad		done;							\
2451.28Smartin		cd "${CUROBJDIR}";					\
2461.15Sad	fi
2471.13Ssborrill	if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then		\
2481.13Ssborrill		skipflag="";						\
2491.16Shubertf		cdextra_skip="${CDEXTRA_SKIP}";				\
2501.16Shubertf		if [ "X$${cdextra_skip}" != "X" ]; then			\
2511.13Ssborrill			rm -f cdskip;					\
2521.16Shubertf			for skip in $${cdextra_skip};			\
2531.13Ssborrill			do						\
2541.13Ssborrill				echo $${skip} >> cdskip;		\
2551.13Ssborrill			done;						\
2561.28Smartin			skipflag="-X ${CUROBJDIR:Q}/cdskip";		\
2571.13Ssborrill		fi;							\
2581.16Shubertf		cdextra="${CDEXTRA}"; 					\
2591.16Shubertf		cdbuildextra="${CDBUILDEXTRA}"; 			\
2601.16Shubertf		for cde in $${cdextra} $${cdbuildextra};		\
2611.13Ssborrill		do							\
2621.28Smartin			release_destdir="${CUROBJDIR}/cdrom";		\
2631.13Ssborrill			if [ -f $${cde} ]; then				\
2641.13Ssborrill				echo Copying $${cde} to $$release_destdir ...;	\
2651.38Schristos				${INSTALL} ${COPY} -m 0644 $${cde} $${release_destdir};	\
2661.13Ssborrill			elif [ -d $${cde} ]; then			\
2671.13Ssborrill				cd $${cde};				\
2681.13Ssborrill				echo Copying $$(pwd) to $$release_destdir ...;	\
2691.13Ssborrill				${TOOL_MTREE} -c $${skipflag} |		\
2701.37Schristos					${TOOL_PAX} ${PAX_TIMESTAMP}	\
2711.37Schristos					-rw -pe ${PAX_v}		\
2721.37Schristos					-M $$release_destdir; 		\
2731.13Ssborrill			else						\
2741.13Ssborrill				echo "Missing $${cde}, aborting"; 	\
2751.13Ssborrill				exit 1; 				\
2761.13Ssborrill			fi; 						\
2771.28Smartin			cd "${CUROBJDIR}";				\
2781.13Ssborrill		done;							\
2791.11Sjnemeth	fi
2801.28Smartin.if !empty(CD_SETS)
2811.36Schristos	${MKDIR} ${MKDIRPERM} "${CUROBJDIR}/cdrom/etc/mtree"
2821.28Smartin.for set in ${CD_SETS}
2831.28Smartin	if [ -f ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set} ]; then	\
2841.28Smartin		${CHMOD} +w ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set};	\
2851.28Smartin	fi;								\
2861.28Smartin	${CDSETSCMD} ./maketars -i "${CUROBJDIR}/cdrom"			\
2871.29Smartin	    ${CD_METALOG.unpriv} ${mtunpriv} -N ${NETBSDSRCDIR}/etc	\
2881.28Smartin	    -F "${CUROBJDIR}/cdrom/etc/mtree"				\
2891.28Smartin	    -d "${DESTDIR:S,^$,/,}" ${set}
2901.28Smartin.endfor
2911.28Smartin	if [ -d "${CUROBJDIR}/cdrom/var/spool/ftp/hidden" ]; then	\
2921.28Smartin		${CHMOD} +r "${CUROBJDIR}/cdrom/var/spool/ftp/hidden";	\
2931.28Smartin	fi
2941.28Smartin.endif
2951.1Shubertf
2961.43Smartin.if ${CDDEV_POPULATE} != true
2971.43SmartinDELDEV=-e '/^\.\/dev\/.*type=char/d'
2981.43Smartin.endif
2991.43Smartin
3001.1Shubertfimage:
3011.28Smartin	@echo Preparing spec files for makefs...
3021.28Smartin	${RM} -f ${WORKSPEC}
3031.31Smartin	if [ -d cdrom/etc/mtree ]; then				\
3041.31Smartin		cat cdrom/etc/mtree/* |				\
3051.31Smartin		    ${TOOL_SED} -e 's/ size=[0-9]*//'		\
3061.43Smartin		     ${DELDEV}					\
3071.31Smartin		     -e '/^\.\/etc\/gettytab/d' > ${WORKSPEC};	\
3081.31Smartin	fi
3091.43Smartin	if [ -r cdrom/dev/MAKEDEV ] &&				\
3101.43Smartin		 ${CDDEV_POPULATE} == true; then		\
3111.32Smartin		${HOST_SH} cdrom/dev/MAKEDEV -s init |		\
3121.31Smartin		    ${TOOL_SED} -e '/^\. type=dir/d' 		\
3131.31Smartin			-e 's,^\.,./dev,' >> ${WORKSPEC};	\
3141.31Smartin	fi
3151.28Smartin.if defined(SPEC_IN)
3161.28Smartin	cat ${SPEC_IN} >> ${WORKSPEC}
3171.28Smartin.endif
3181.28Smartin.if defined(SECONDARY_BOOT)
3191.28Smartin	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
3201.28Smartin	    >> ${WORKSPEC}
3211.28Smartin.endif
3221.28Smartin.if defined(SPEC_EXTRA)
3231.28Smartin	cat ${SPEC_EXTRA} >> ${WORKSPEC}
3241.28Smartin.endif
3251.49Schristos	if [ ! -s ${WORKSPEC} ]; then ${MAKESPEC} cdrom > ${WORKSPEC}; fi
3261.49Schristos	${TOOL_MAKEFS} -N ${NETBSDSRCDIR}/etc -t cd9660 -F ${WORKSPEC} 	\
3271.34Schristos		${MAKEFS_TIMESTAMP} ${CDMAKEFSEXTRAOPTS} -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
3281.8Sbouyer
3291.8Sbouyer.if ${CDRELEASE} == false
3301.15Sadrelease: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
3311.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3321.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3331.1Shubertf
3341.8Sbouyeriso_image:
3351.8Sbouyer.else
3361.1Shubertfrelease:
3371.8Sbouyer
3381.15Sadiso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
3391.36Schristos	${MKDIR} ${MKDIRPERM} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3401.18Sjmcneill	${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
3411.8Sbouyer.endif
3421.1Shubertf
3431.1Shubertfclean:
3441.28Smartin	@if [ -d cdrom/var/spool/ftp/hidden ]; then 		\
3451.28Smartin		${CHMOD} +r cdrom/var/spool/ftp/hidden;		\
3461.28Smartin	fi	# XXX
3471.1Shubertf	${RM} -fr cdrom
3481.1Shubertf
3491.8Sbouyerprepare_md_post: .PHONY
3501.8Sbouyerimage_md_post: .PHONY
3511.15Sadimage_md_pre: .PHONY
3521.8Sbouyer
3531.1Shubertf.include <bsd.prog.mk>
354