Makefile.minirootkmod revision 1.4
11.4Schristos#	$NetBSD: Makefile.minirootkmod,v 1.4 2020/04/04 19:50:53 christos 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.1Sapb# SRCMOD is a skeleton version of miniroot.kmod, without an embedded ramdisk.
291.1Sapb# It should already have been created by "make install" in
301.1Sapb# .../sys/modules/miniroot, and its name includes literal "miniroot",
311.1Sapb# not variable ${MINIROOT}.
321.1Sapb#
331.1Sapb# DSTMOD is a copy of SRCMOD that is modified to include an embedded ramdisk.
341.1Sapb# It will be created by rules in this Makefile.
351.1Sapb#
361.1Sapb# RAMDISKFS is the ramdisk image to be included inside DSTMOD.  It should
371.1Sapb# already have been created by the Makefile in RAMDISKSRCDIR.
381.1Sapb#
391.4Schristos.if ${KERNEL_DIR:U*no} == "yes"
401.4SchristosSRCMOD=		${DESTDIR}/netbsd/modules/miniroot/miniroot.kmod
411.4Schristos.else
421.1SapbSRCMOD=		${DESTDIR}/stand/${MACHINE}/${MODULEVER}/modules/miniroot/miniroot.kmod
431.4Schristos.endif
441.1SapbDSTMOD=		${.OBJDIR}/${MINIROOT}.kmod
451.1SapbRAMDISKSRCDIR=	${.CURDIR}/../ramdisks/${RAMDISK}
461.1SapbRAMDISKOBJDIR!=	cd ${RAMDISKSRCDIR} && ${PRINTOBJDIR}
471.1SapbRAMDISKFS=	${RAMDISKOBJDIR}/${RAMDISK}.fs
481.1Sapb
491.1Sapb${MINIROOT}.kmod:	${RAMDISKFS} ${SRCMOD}
501.1Sapb		${OBJCOPY} --add-section miniroot=${RAMDISKFS} \
511.1Sapb		    --set-section-flags miniroot=alloc,contents,load,data \
521.1Sapb		    ${SRCMOD} ${DSTMOD}.tmp
531.3Sapb		${TOOL_GZIP_N} -9c < ${DSTMOD}.tmp > ${DSTMOD}
541.1Sapb		rm -f ${DSTMOD}.tmp
551.1Sapb
561.1Sapb.include <bsd.prog.mk>
571.1Sapb
581.1Sapbrelease:	${PROG}
591.1Sapb		${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG}  \
601.1Sapb		    ${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/miniroot/
61