11.5Slukem#	$NetBSD: Makefile.minirootkmod,v 1.5 2020/07/02 08:48:10 lukem Exp $
21.1Sapb#
31.1Sapb# Makefile snippet to build a miniroot kernel module (e.g. miniroot.kmod)
41.1Sapb#
51.1Sapb# Required variables:
61.1Sapb#	NETBSDSRCDIR	top level of src tree (set by <bsd.own.mk>)
71.1Sapb#
81.1Sapb# Optional variables:
91.1Sapb#	MINIROOT	Basename of the kernel module to be created.
101.1Sapb#			".kmod" will be appended to get the file name.
111.1Sapb#			[default: miniroot]
121.1Sapb#	RAMDISK		Basename of the ramdisk to be embedded in the
131.1Sapb#			kernel module.  This is used as both a directory
141.1Sapb#			name (${.CURDIR}/../ramdisks/${RAMDISK}) and
151.1Sapb#			as a file name within the .OBJDIR of that
161.1Sapb#			directory (${RAMDISK}.fs).  [default: ramdisk]
171.1Sapb#
181.1Sapb
191.1SapbMINIROOT?=	miniroot
201.1SapbRAMDISK?=	ramdisk
211.1Sapb
221.1Sapb.include <bsd.own.mk>
231.1Sapb.include "${.PARSEDIR}/Makefile.distrib"
241.1Sapb
251.1SapbMKMAN=		no
261.1SapbPROG=		${MINIROOT}.kmod
271.1Sapb
281.5Slukem# Not a real PROG; doesn't actually have source
291.5SlukemSRCS.${PROG}=
301.5Slukem
311.1Sapb# SRCMOD is a skeleton version of miniroot.kmod, without an embedded ramdisk.
321.1Sapb# It should already have been created by "make install" in
331.1Sapb# .../sys/modules/miniroot, and its name includes literal "miniroot",
341.1Sapb# not variable ${MINIROOT}.
351.1Sapb#
361.1Sapb# DSTMOD is a copy of SRCMOD that is modified to include an embedded ramdisk.
371.1Sapb# It will be created by rules in this Makefile.
381.1Sapb#
391.1Sapb# RAMDISKFS is the ramdisk image to be included inside DSTMOD.  It should
401.1Sapb# already have been created by the Makefile in RAMDISKSRCDIR.
411.1Sapb#
421.4Schristos.if ${KERNEL_DIR:U*no} == "yes"
431.4SchristosSRCMOD=		${DESTDIR}/netbsd/modules/miniroot/miniroot.kmod
441.4Schristos.else
451.1SapbSRCMOD=		${DESTDIR}/stand/${MACHINE}/${MODULEVER}/modules/miniroot/miniroot.kmod
461.4Schristos.endif
471.1SapbDSTMOD=		${.OBJDIR}/${MINIROOT}.kmod
481.1SapbRAMDISKSRCDIR=	${.CURDIR}/../ramdisks/${RAMDISK}
491.1SapbRAMDISKOBJDIR!=	cd ${RAMDISKSRCDIR} && ${PRINTOBJDIR}
501.1SapbRAMDISKFS=	${RAMDISKOBJDIR}/${RAMDISK}.fs
511.1Sapb
521.1Sapb${MINIROOT}.kmod:	${RAMDISKFS} ${SRCMOD}
531.1Sapb		${OBJCOPY} --add-section miniroot=${RAMDISKFS} \
541.1Sapb		    --set-section-flags miniroot=alloc,contents,load,data \
551.1Sapb		    ${SRCMOD} ${DSTMOD}.tmp
561.3Sapb		${TOOL_GZIP_N} -9c < ${DSTMOD}.tmp > ${DSTMOD}
571.1Sapb		rm -f ${DSTMOD}.tmp
581.1Sapb
591.1Sapb.include <bsd.prog.mk>
601.1Sapb
611.1Sapbrelease:	${PROG}
621.1Sapb		${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG}  \
631.1Sapb		    ${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/miniroot/
64