Makefile.image revision 1.7
1#	$NetBSD: Makefile.image,v 1.7 2002/04/12 01:59:45 lukem Exp $
2#
3# Makefile snippet to build a tree from the provided lists,
4# and make an ffs file system image from that tree
5#
6
7#
8# Required variables:
9#	_SRC_TOP_	top level of src tree (set by <bsd.own.mk>)
10#	CRUNCHBIN	name of crunchgen(1)ed binary
11#	LISTS		list file(s) to use
12#	IMAGE		name of target image
13#	IMAGEDEPENDS	depends for ${IMAGE}
14#	IMAGEENDIAN	endianness of ${IMAGE}
15#	IMAGESIZE	size of ${IMAGE}
16#	MTREECONF	mtree specfiles to use to build a master specfile
17#
18# Optional variables:
19#	DESTDIR		destination directory
20#	MAKEFS_FLAGS	extra options to ${MAKEFS}
21#	PARSELISTENV	environment variables to set for parselist.awk
22#	WORKDIR		directory to build image in to 
23#
24
25WORKDIR?=	work
26WORKSPEC?=	work.spec
27WORKBUILT?=	work.built
28
29.include "${DISTRIBDIR}/common/Makefile.parselist"
30
31PARSELISTENV+=	TARGETDIR=${.OBJDIR}/${WORKDIR:Q}
32
33
34${WORKBUILT}: ${IMAGEDEPENDS} ${WORKSPEC} ${PARSELISTDEP} ${LISTS}
35	@echo "Building tree into ${WORKDIR}"
36	-rm -rf ${WORKDIR} ${WORKBUILT}
37	mkdir -m 755 ${WORKDIR}
38	${MTREE} -def ${WORKSPEC} -p ${WORKDIR}/ -UW
39	${PARSELIST} -v mode=populate ${LISTS} | sh -e ${POPULATE_DEBUG} \
40	&& touch ${WORKBUILT}
41
42${WORKSPEC}: ${MTREECONF} ${LISTS} ${PARSELISTDEP}
43	-rm -f ${.TARGET} ${.TARGET}.tmp
44	( for i in ${MTREECONF}; do	\
45		cat $$i ;		\
46		echo "/unset all" ;	\
47	done ) >> ${.TARGET}.tmp
48	${PARSELIST} -v mode=mtree ${LISTS} >> ${.TARGET}.tmp \
49	&& mv ${.TARGET}.tmp ${.TARGET}
50
51${IMAGE}: ${WORKBUILT} ${WORKSPEC} ${IMAGEDEPENDS}
52	@echo "Creating image into ${.TARGET}..."
53	-rm -f ${.TARGET} ${.TARGET}.tmp
54	${MAKEFS} -t ffs -B ${IMAGEENDIAN} -s ${IMAGESIZE} -F ${WORKSPEC} \
55	    -N ${_SRC_TOP_}/etc -o bsize=4096,fsize=512 \
56	    -o optimization=space,minfree=0,nsectors=1,ntracks=128 \
57	    ${MAKEFS_FLAGS} ${.TARGET}.tmp ${WORKDIR} \
58	&& mv -f ${.TARGET}.tmp ${.TARGET}
59
60CLEANFILES+=	${IMAGE} ${IMAGE}.tmp ${WORKBUILT} ${WORKSPEC} ${WORKSPEC}.tmp
61
62clean cleandir distclean: cleanfsimage
63
64.PHONY: cleanfsimage
65
66cleanfsimage:
67	-rm -rf ${WORKDIR}
68